Skip to content

Commit 856c549

Browse files
authored
Merge pull request #401 from objectstack-ai/copilot/unify-ai-cost-tracking
2 parents 68cce49 + a4deb27 commit 856c549

39 files changed

Lines changed: 1282 additions & 121 deletions

content/docs/references/ai/conversation.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const result = ConversationAnalyticsSchema.parse(data);
7777
| **toolCallId** | `string` | optional | Tool call ID this message responds to |
7878
| **name** | `string` | optional | Name of the function/user |
7979
| **tokens** | `object` | optional | Token usage for this message |
80+
| **cost** | `number` | optional | Cost for this message in USD |
8081
| **pinned** | `boolean` | optional | Prevent removal during pruning |
8182
| **importance** | `number` | optional | Importance score for pruning |
8283
| **embedding** | `number[]` | optional | Vector embedding for semantic search |
@@ -97,6 +98,8 @@ const result = ConversationAnalyticsSchema.parse(data);
9798
| **tokenBudget** | `object` || |
9899
| **messages** | `object[]` | optional | |
99100
| **tokens** | `object` | optional | |
101+
| **totalTokens** | `object` | optional | Total tokens across all messages |
102+
| **totalCost** | `number` | optional | Total cost for this session in USD |
100103
| **status** | `Enum<'active' \| 'paused' \| 'completed' \| 'archived'>` | optional | |
101104
| **createdAt** | `string` || ISO 8601 timestamp |
102105
| **updatedAt** | `string` || ISO 8601 timestamp |

content/docs/references/ai/cost.mdx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,32 @@ description: Cost protocol schemas
1212
## TypeScript Usage
1313

1414
```typescript
15-
import { BillingPeriodSchema, BudgetLimitSchema, BudgetStatusSchema, BudgetTypeSchema, CostAlertSchema, CostAlertTypeSchema, CostAnalyticsSchema, CostBreakdownDimensionSchema, CostBreakdownEntrySchema, CostEntrySchema, CostMetricTypeSchema, CostOptimizationRecommendationSchema, CostQueryFiltersSchema, CostReportSchema } from '@objectstack/spec/ai';
16-
import type { BillingPeriod, BudgetLimit, BudgetStatus, BudgetType, CostAlert, CostAlertType, CostAnalytics, CostBreakdownDimension, CostBreakdownEntry, CostEntry, CostMetricType, CostOptimizationRecommendation, CostQueryFilters, CostReport } from '@objectstack/spec/ai';
15+
import { AIOperationCostSchema, BillingPeriodSchema, BudgetLimitSchema, BudgetStatusSchema, BudgetTypeSchema, CostAlertSchema, CostAlertTypeSchema, CostAnalyticsSchema, CostBreakdownDimensionSchema, CostBreakdownEntrySchema, CostEntrySchema, CostMetricTypeSchema, CostOptimizationRecommendationSchema, CostQueryFiltersSchema, CostReportSchema, TokenUsageSchema } from '@objectstack/spec/ai';
16+
import type { AIOperationCost, BillingPeriod, BudgetLimit, BudgetStatus, BudgetType, CostAlert, CostAlertType, CostAnalytics, CostBreakdownDimension, CostBreakdownEntry, CostEntry, CostMetricType, CostOptimizationRecommendation, CostQueryFilters, CostReport, TokenUsage } from '@objectstack/spec/ai';
1717

1818
// Validate data
19-
const result = BillingPeriodSchema.parse(data);
19+
const result = AIOperationCostSchema.parse(data);
2020
```
2121

2222
---
2323

24+
## AIOperationCost
25+
26+
### Properties
27+
28+
| Property | Type | Required | Description |
29+
| :--- | :--- | :--- | :--- |
30+
| **operationId** | `string` || |
31+
| **operationType** | `Enum<'conversation' \| 'orchestration' \| 'prediction' \| 'rag' \| 'nlq'>` || |
32+
| **agentName** | `string` | optional | Agent that performed the operation |
33+
| **modelId** | `string` || |
34+
| **tokens** | `object` || |
35+
| **cost** | `number` || Cost in USD |
36+
| **timestamp** | `string` || |
37+
| **metadata** | `Record<string, any>` | optional | |
38+
39+
---
40+
2441
## BillingPeriod
2542

2643
### Allowed Values
@@ -316,3 +333,15 @@ const result = BillingPeriodSchema.parse(data);
316333
| **format** | `Enum<'summary' \| 'detailed' \| 'executive'>` | optional | |
317334
| **currency** | `string` | optional | |
318335

336+
---
337+
338+
## TokenUsage
339+
340+
### Properties
341+
342+
| Property | Type | Required | Description |
343+
| :--- | :--- | :--- | :--- |
344+
| **prompt** | `integer` || Input tokens |
345+
| **completion** | `integer` || Output tokens |
346+
| **total** | `integer` || Total tokens |
347+

content/docs/references/ai/nlq.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ const result = EntitySchema.parse(data);
152152
| **totalCount** | `integer` | optional | |
153153
| **executionTime** | `number` | optional | Execution time in milliseconds |
154154
| **needsClarification** | `boolean` || Whether query needs clarification |
155+
| **tokens** | `object` | optional | Token usage for this query |
156+
| **cost** | `number` | optional | Cost for this query in USD |
155157
| **suggestions** | `string[]` | optional | Query refinement suggestions |
156158

157159
---

content/docs/references/ai/orchestration.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const result = AIOrchestrationSchema.parse(data);
6969
| **tasksSucceeded** | `integer` || Number of tasks succeeded |
7070
| **tasksFailed** | `integer` || Number of tasks failed |
7171
| **taskResults** | `object[]` | optional | |
72+
| **tokens** | `object` | optional | Total token usage for this execution |
73+
| **cost** | `number` | optional | Total cost for this execution in USD |
7274
| **error** | `string` | optional | |
7375
| **startedAt** | `string` || ISO timestamp |
7476
| **completedAt** | `string` | optional | ISO timestamp |

content/docs/references/ai/predictive.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ const result = EvaluationMetricsSchema.parse(data);
131131
| **confidence** | `number` | optional | Confidence score (0-1) |
132132
| **probabilities** | `Record<string, number>` | optional | Class probabilities (for classification) |
133133
| **explanation** | `object` | optional | |
134+
| **tokens** | `object` | optional | Token usage for this prediction (if AI-powered) |
135+
| **cost** | `number` | optional | Cost for this prediction in USD |
134136
| **metadata** | `object` | optional | |
135137

136138
---

content/docs/references/ai/rag-pipeline.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ const result = ChunkingStrategySchema.parse(data);
157157
| **query** | `string` || |
158158
| **results** | `object[]` || |
159159
| **context** | `string` || Assembled context for LLM |
160-
| **tokensUsed** | `integer` | optional | |
160+
| **tokens** | `object` | optional | Token usage for this query |
161+
| **cost** | `number` | optional | Cost for this query in USD |
162+
| **tokensUsed** | `integer` | optional | Deprecated: use tokens.total instead |
161163
| **retrievalTime** | `number` | optional | Retrieval time in milliseconds |
162164

163165
---
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Chart
3+
description: Chart protocol schemas
4+
---
5+
6+
# Chart
7+
8+
<Callout type="info">
9+
**Source:** `packages/spec/src/ui/chart.zod.ts`
10+
</Callout>
11+
12+
## TypeScript Usage
13+
14+
```typescript
15+
import { ChartConfigSchema, ChartTypeSchema } from '@objectstack/spec/ui';
16+
import type { ChartConfig, ChartType } from '@objectstack/spec/ui';
17+
18+
// Validate data
19+
const result = ChartConfigSchema.parse(data);
20+
```
21+
22+
---
23+
24+
## ChartConfig
25+
26+
### Properties
27+
28+
| Property | Type | Required | Description |
29+
| :--- | :--- | :--- | :--- |
30+
| **type** | `Enum<'bar' \| 'horizontal-bar' \| 'column' \| 'grouped-bar' \| 'stacked-bar' \| 'line' \| 'area' \| 'stacked-area' \| 'step-line' \| 'pie' \| 'donut' \| 'funnel' \| 'scatter' \| 'bubble' \| 'treemap' \| 'sunburst' \| 'sankey' \| 'gauge' \| 'metric' \| 'kpi' \| 'choropleth' \| 'bubble-map' \| 'heatmap' \| 'radar' \| 'waterfall' \| 'box-plot' \| 'violin' \| 'table' \| 'pivot'>` || |
31+
| **title** | `string` | optional | Chart title |
32+
| **description** | `string` | optional | Chart description |
33+
| **showLegend** | `boolean` | optional | Display legend |
34+
| **showDataLabels** | `boolean` | optional | Display data labels on chart |
35+
| **colors** | `string[]` | optional | Custom color palette |
36+
37+
---
38+
39+
## ChartType
40+
41+
### Allowed Values
42+
43+
* `bar`
44+
* `horizontal-bar`
45+
* `column`
46+
* `grouped-bar`
47+
* `stacked-bar`
48+
* `line`
49+
* `area`
50+
* `stacked-area`
51+
* `step-line`
52+
* `pie`
53+
* `donut`
54+
* `funnel`
55+
* `scatter`
56+
* `bubble`
57+
* `treemap`
58+
* `sunburst`
59+
* `sankey`
60+
* `gauge`
61+
* `metric`
62+
* `kpi`
63+
* `choropleth`
64+
* `bubble-map`
65+
* `heatmap`
66+
* `radar`
67+
* `waterfall`
68+
* `box-plot`
69+
* `violin`
70+
* `table`
71+
* `pivot`
72+

content/docs/references/ui/dashboard.mdx

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,15 @@ description: Dashboard protocol schemas
1212
## TypeScript Usage
1313

1414
```typescript
15-
import { ChartTypeSchema, DashboardSchema, DashboardWidgetSchema } from '@objectstack/spec/ui';
16-
import type { ChartType, Dashboard, DashboardWidget } from '@objectstack/spec/ui';
15+
import { DashboardSchema, DashboardWidgetSchema } from '@objectstack/spec/ui';
16+
import type { Dashboard, DashboardWidget } from '@objectstack/spec/ui';
1717

1818
// Validate data
19-
const result = ChartTypeSchema.parse(data);
19+
const result = DashboardSchema.parse(data);
2020
```
2121

2222
---
2323

24-
## ChartType
25-
26-
### Allowed Values
27-
28-
* `metric`
29-
* `bar`
30-
* `line`
31-
* `pie`
32-
* `donut`
33-
* `gauge`
34-
* `funnel`
35-
* `radar`
36-
* `scatter`
37-
* `heatmap`
38-
* `pivot`
39-
* `table`
40-
* `list`
41-
* `text`
42-
* `image`
43-
* `frame`
44-
45-
---
46-
4724
## Dashboard
4825

4926
### Properties
@@ -64,7 +41,8 @@ const result = ChartTypeSchema.parse(data);
6441
| Property | Type | Required | Description |
6542
| :--- | :--- | :--- | :--- |
6643
| **title** | `string` | optional | Widget title |
67-
| **type** | `Enum<'metric' \| 'bar' \| 'line' \| 'pie' \| 'donut' \| 'gauge' \| 'funnel' \| 'radar' \| 'scatter' \| 'heatmap' \| 'pivot' \| 'table' \| 'list' \| 'text' \| 'image' \| 'frame'>` | optional | Visualization type |
44+
| **type** | `Enum<'bar' \| 'horizontal-bar' \| 'column' \| 'grouped-bar' \| 'stacked-bar' \| 'line' \| 'area' \| 'stacked-area' \| 'step-line' \| 'pie' \| 'donut' \| 'funnel' \| 'scatter' \| 'bubble' \| 'treemap' \| 'sunburst' \| 'sankey' \| 'gauge' \| 'metric' \| 'kpi' \| 'choropleth' \| 'bubble-map' \| 'heatmap' \| 'radar' \| 'waterfall' \| 'box-plot' \| 'violin' \| 'table' \| 'pivot'>` | optional | Visualization type |
45+
| **chartConfig** | `object` | optional | Chart visualization configuration |
6846
| **object** | `string` | optional | Data source object name |
6947
| **filter** | `any` | optional | Data filter criteria |
7048
| **categoryField** | `string` | optional | Field for grouping (X-Axis) |

content/docs/references/ui/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This section contains all protocol schemas for the ui layer of ObjectStack.
1010
<Cards>
1111
<Card href="./action" title="Action" description="Source: packages/spec/src/ui/action.zod.ts" />
1212
<Card href="./app" title="App" description="Source: packages/spec/src/ui/app.zod.ts" />
13+
<Card href="./chart" title="Chart" description="Source: packages/spec/src/ui/chart.zod.ts" />
1314
<Card href="./component" title="Component" description="Source: packages/spec/src/ui/component.zod.ts" />
1415
<Card href="./dashboard" title="Dashboard" description="Source: packages/spec/src/ui/dashboard.zod.ts" />
1516
<Card href="./page" title="Page" description="Source: packages/spec/src/ui/page.zod.ts" />

content/docs/references/ui/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"pages": [
44
"action",
55
"app",
6+
"chart",
67
"component",
78
"dashboard",
89
"page",

0 commit comments

Comments
 (0)