@linnlabs/linnkit 0.9.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +168 -0
- package/bin/linnkit.cjs +7 -0
- package/dist/{agent-invocation-BHcNfrBV.d.cts → agent-invocation-CAlm9qOw.d.cts} +1 -1
- package/dist/{agent-invocation-BznDaXDs.d.ts → agent-invocation-DKoEDLkl.d.ts} +1 -1
- package/dist/{ai-engine.types-vZRnQcJa.d.ts → ai-engine.types-CeLoM624.d.cts} +9 -1
- package/dist/{ai-engine.types-BpeU_XQG.d.cts → ai-engine.types-LqmnfR2W.d.ts} +9 -1
- package/dist/{audit-CtcfART1.d.ts → audit-BuWHoMEr.d.ts} +4 -2
- package/dist/{audit-LeOrm2hX.d.cts → audit-DnzNQzwq.d.cts} +4 -2
- package/dist/cli.cjs +682 -258
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +682 -258
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +823 -57
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.d.cts +132 -18
- package/dist/context-manager.d.ts +132 -18
- package/dist/context-manager.js +823 -58
- package/dist/context-manager.js.map +1 -1
- package/dist/{context-trace-HE2qY5Q-.d.cts → context-trace-DrtvKac4.d.cts} +37 -4
- package/dist/{context-trace-DRi5M4lX.d.ts → context-trace-WV1HAZeB.d.ts} +37 -4
- package/dist/contracts.cjs +225 -2
- package/dist/contracts.cjs.map +1 -1
- package/dist/contracts.d.cts +6 -4
- package/dist/contracts.d.ts +6 -4
- package/dist/contracts.js +205 -3
- package/dist/contracts.js.map +1 -1
- package/dist/{defaultGraphExecutor-BIjJj7WF.d.cts → defaultGraphExecutor-L1ri3oij.d.cts} +48 -19
- package/dist/{defaultGraphExecutor-BBswR8wn.d.ts → defaultGraphExecutor-QzzdudLQ.d.ts} +48 -19
- package/dist/{index-BanRABEt.d.cts → index-BeQO0rx2.d.cts} +345 -268
- package/dist/{index-Cvr23YCl.d.cts → index-CDofGr_4.d.ts} +24 -6
- package/dist/{index-Dl5PLgAv.d.cts → index-Crl5E4eF.d.cts} +27 -4
- package/dist/{index-CJeWHopy.d.ts → index-DWGKvssS.d.ts} +3 -3
- package/dist/{index-CHqwkvGp.d.ts → index-X5lYU1Lj.d.ts} +27 -4
- package/dist/{index-DDzuSb0n.d.ts → index-uCNCpJBg.d.cts} +24 -6
- package/dist/{index-Z8NXKNwI.d.ts → index-wOZD-p2-.d.ts} +345 -268
- package/dist/{index-DO4dQgf2.d.cts → index-wXVAHZ0D.d.cts} +3 -3
- package/dist/index.cjs +1011 -329
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -16
- package/dist/index.d.ts +19 -16
- package/dist/index.js +1011 -329
- package/dist/index.js.map +1 -1
- package/dist/{messages-XthmnHZ3.d.cts → messages-Br5SiLD3.d.cts} +706 -1
- package/dist/{messages-XthmnHZ3.d.ts → messages-Br5SiLD3.d.ts} +706 -1
- package/dist/{ports-DnLuKfpE.d.ts → ports-Dugizzje.d.cts} +6 -2
- package/dist/{ports-DaatKJXp.d.cts → ports-fhp84x_C.d.ts} +6 -2
- package/dist/ports.d.cts +8 -5
- package/dist/ports.d.ts +8 -5
- package/dist/quickstart.cjs +683 -258
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.d.cts +11 -10
- package/dist/quickstart.d.ts +11 -10
- package/dist/quickstart.js +683 -258
- package/dist/quickstart.js.map +1 -1
- package/dist/{runAgent-CPj_9e58.d.ts → runAgent-BmMSju8I.d.ts} +6 -6
- package/dist/{runAgent-HYKlXbVr.d.cts → runAgent-CKgcRSRH.d.cts} +6 -6
- package/dist/{runHandle-D3gPsD7B.d.cts → runHandle-DH4VmQx6.d.cts} +6 -4
- package/dist/{runHandle-CyXvzgzk.d.ts → runHandle-o3p06Nva.d.ts} +6 -4
- package/dist/runtime-kernel/events.cjs +202 -1
- package/dist/runtime-kernel/events.cjs.map +1 -1
- package/dist/runtime-kernel/events.d.cts +5 -5
- package/dist/runtime-kernel/events.d.ts +5 -5
- package/dist/runtime-kernel/events.js +202 -1
- package/dist/runtime-kernel/events.js.map +1 -1
- package/dist/runtime-kernel.cjs +999 -340
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.d.cts +16 -14
- package/dist/runtime-kernel.d.ts +16 -14
- package/dist/runtime-kernel.js +990 -341
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +1003 -321
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.d.cts +16 -14
- package/dist/testkit.d.ts +16 -14
- package/dist/testkit.js +1003 -321
- package/dist/testkit.js.map +1 -1
- package/dist/{todo-B1PmDlp3.d.cts → todo-Ca8llpRQ.d.cts} +1 -1
- package/dist/{todo-B1PmDlp3.d.ts → todo-Ca8llpRQ.d.ts} +1 -1
- package/dist/{agentSpec-EkmviZjy.d.cts → token-accounting-CwpSPg4y.d.cts} +1280 -1
- package/dist/{agentSpec-EkmviZjy.d.ts → token-accounting-CwpSPg4y.d.ts} +1280 -1
- package/dist/token-calibration-Cxv6dDYF.d.cts +327 -0
- package/dist/token-calibration-Cxv6dDYF.d.ts +327 -0
- package/dist/token-counter-CFfP8PQb.d.cts +26 -0
- package/dist/token-counter-SFyyTeaG.d.ts +26 -0
- package/dist/token-usage-CqwT7-5K.d.cts +133 -0
- package/dist/token-usage-CqwT7-5K.d.ts +133 -0
- package/dist/{tokenizer-DFL4I7-I.d.ts → tokenizer-BFJNCHFX.d.ts} +1 -1
- package/dist/{tokenizer-DH_JXv-H.d.cts → tokenizer-DoGsBE3A.d.cts} +1 -1
- package/dist/{toolContracts-CLkQmhTG.d.cts → toolContracts-Bm3EZ1UM.d.cts} +13 -2
- package/dist/{toolContracts-Blll0241.d.ts → toolContracts-f8lzZBNa.d.ts} +13 -2
- package/docs/README.md +1 -1
- package/docs/integration/README.md +3 -3
- package/docs/integration/agent-registration-guide.md +3 -1
- package/docs/integration/child-runs.md +4 -1
- package/docs/integration/context-engineering.md +83 -16
- package/docs/integration/context-fences.md +44 -3
- package/docs/integration/llm-provider.md +1 -1
- package/docs/integration/persistence.md +1 -0
- package/docs/integration/run-supervisor.md +3 -0
- package/docs/integration/tool-development-guide.md +7 -5
- package/docs/integration/tool-history.md +43 -17
- package/package.json +4 -3
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { A as AgentAiEngine } from './audit-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { B as BaseTool,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { A as AgentAiEngine } from './audit-BuWHoMEr.js';
|
|
2
|
+
import { h as AgentSpecContextPolicyInput, f as AgentSpec } from './token-accounting-CwpSPg4y.js';
|
|
3
|
+
import { R as RuntimeEvent } from './todo-Ca8llpRQ.js';
|
|
4
|
+
import { B as BaseTool, T as ToolArgs, O as OpenAIToolSchema, a as ToolExecutionContext } from './toolContracts-f8lzZBNa.js';
|
|
5
|
+
import { T as ToolRuntimeDefinition, a as ToolExecutionResult } from './ports-fhp84x_C.js';
|
|
6
|
+
import { R as RunCost$1 } from './runHandle-o3p06Nva.js';
|
|
7
7
|
|
|
8
8
|
interface DefinedAgent {
|
|
9
9
|
readonly spec: AgentSpec;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { A as AgentAiEngine } from './audit-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { B as BaseTool,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { A as AgentAiEngine } from './audit-DnzNQzwq.cjs';
|
|
2
|
+
import { h as AgentSpecContextPolicyInput, f as AgentSpec } from './token-accounting-CwpSPg4y.cjs';
|
|
3
|
+
import { R as RuntimeEvent } from './todo-Ca8llpRQ.cjs';
|
|
4
|
+
import { B as BaseTool, T as ToolArgs, O as OpenAIToolSchema, a as ToolExecutionContext } from './toolContracts-Bm3EZ1UM.cjs';
|
|
5
|
+
import { T as ToolRuntimeDefinition, a as ToolExecutionResult } from './ports-Dugizzje.cjs';
|
|
6
|
+
import { R as RunCost$1 } from './runHandle-DH4VmQx6.cjs';
|
|
7
7
|
|
|
8
8
|
interface DefinedAgent {
|
|
9
9
|
readonly spec: AgentSpec;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { b as AuditPort } from './audit-
|
|
1
|
+
import { R as RunTokenUsageAggregate, f as AgentSpec } from './token-accounting-CwpSPg4y.cjs';
|
|
2
|
+
import { R as RuntimeEvent } from './todo-Ca8llpRQ.cjs';
|
|
3
|
+
import { b as AuditPort } from './audit-DnzNQzwq.cjs';
|
|
4
4
|
import { E as EventEnvelope } from './execution-CAIypb41.cjs';
|
|
5
5
|
|
|
6
6
|
type PersistedEvent = {
|
|
@@ -126,6 +126,8 @@ interface CancelOpts {
|
|
|
126
126
|
interface RunCost {
|
|
127
127
|
tokensInput: number;
|
|
128
128
|
tokensOutput: number;
|
|
129
|
+
tokenUsage?: RunTokenUsageAggregate;
|
|
130
|
+
tokenLedgerEntryIds?: string[];
|
|
129
131
|
totalCostUsd?: number;
|
|
130
132
|
latencyMs?: number;
|
|
131
133
|
childrenTotal?: RunCost;
|
|
@@ -236,4 +238,4 @@ declare class DefaultRunHandle<TRequest extends RunRequestSnapshot = RunRequestS
|
|
|
236
238
|
}
|
|
237
239
|
declare function runMetaFromRecord(record: RunRecord): RunMeta;
|
|
238
240
|
|
|
239
|
-
export { type CancelOpts as C, DefaultRunHandle as D, type EventRangeOptions as E, type ListRunsFilter as L, type PersistedEvent as P, type
|
|
241
|
+
export { type CancelOpts as C, DefaultRunHandle as D, type EventRangeOptions as E, type ListRunsFilter as L, type PersistedEvent as P, type RunCost as R, type EventStore as a, EventBus as b, createMonotonicEventIdFactory as c, type DefaultRunHandleOptions as d, type RunAwaitingUserPatch as e, type RunCostCollector as f, type RunFailureInfo as g, type RunHandle as h, type RunLifecyclePatch as i, type RunMeta as j, type RunObserveFilter as k, type RunRecord as l, type RunRegistryStore as m, type RunRequestSnapshot as n, type RunStatus as o, runMetaFromRecord as r };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { b as AuditPort } from './audit-
|
|
1
|
+
import { R as RunTokenUsageAggregate, f as AgentSpec } from './token-accounting-CwpSPg4y.js';
|
|
2
|
+
import { R as RuntimeEvent } from './todo-Ca8llpRQ.js';
|
|
3
|
+
import { b as AuditPort } from './audit-BuWHoMEr.js';
|
|
4
4
|
import { E as EventEnvelope } from './execution-CAIypb41.js';
|
|
5
5
|
|
|
6
6
|
type PersistedEvent = {
|
|
@@ -126,6 +126,8 @@ interface CancelOpts {
|
|
|
126
126
|
interface RunCost {
|
|
127
127
|
tokensInput: number;
|
|
128
128
|
tokensOutput: number;
|
|
129
|
+
tokenUsage?: RunTokenUsageAggregate;
|
|
130
|
+
tokenLedgerEntryIds?: string[];
|
|
129
131
|
totalCostUsd?: number;
|
|
130
132
|
latencyMs?: number;
|
|
131
133
|
childrenTotal?: RunCost;
|
|
@@ -236,4 +238,4 @@ declare class DefaultRunHandle<TRequest extends RunRequestSnapshot = RunRequestS
|
|
|
236
238
|
}
|
|
237
239
|
declare function runMetaFromRecord(record: RunRecord): RunMeta;
|
|
238
240
|
|
|
239
|
-
export { type CancelOpts as C, DefaultRunHandle as D, type EventRangeOptions as E, type ListRunsFilter as L, type PersistedEvent as P, type
|
|
241
|
+
export { type CancelOpts as C, DefaultRunHandle as D, type EventRangeOptions as E, type ListRunsFilter as L, type PersistedEvent as P, type RunCost as R, type EventStore as a, EventBus as b, createMonotonicEventIdFactory as c, type DefaultRunHandleOptions as d, type RunAwaitingUserPatch as e, type RunCostCollector as f, type RunFailureInfo as g, type RunHandle as h, type RunLifecyclePatch as i, type RunMeta as j, type RunObserveFilter as k, type RunRecord as l, type RunRegistryStore as m, type RunRequestSnapshot as n, type RunStatus as o, runMetaFromRecord as r };
|
|
@@ -58,6 +58,12 @@ zod.z.object({
|
|
|
58
58
|
args: zod.z.record(zod.z.unknown()).optional(),
|
|
59
59
|
tool_call_id: zod.z.string()
|
|
60
60
|
});
|
|
61
|
+
var ObservationTruncationMeta = zod.z.object({
|
|
62
|
+
originalChars: zod.z.number().int().nonnegative(),
|
|
63
|
+
previewChars: zod.z.number().int().nonnegative(),
|
|
64
|
+
originalLines: zod.z.number().int().nonnegative().optional(),
|
|
65
|
+
previewLines: zod.z.number().int().nonnegative().optional()
|
|
66
|
+
});
|
|
61
67
|
var ImageInfoMeta = zod.z.object({
|
|
62
68
|
url: zod.z.string().optional(),
|
|
63
69
|
width: zod.z.number().int().positive().optional(),
|
|
@@ -89,6 +95,7 @@ var PersistentMetadata = zod.z.object({
|
|
|
89
95
|
tool_name: zod.z.string().optional(),
|
|
90
96
|
args: zod.z.record(zod.z.unknown()).optional(),
|
|
91
97
|
tool_call_id: zod.z.string().optional(),
|
|
98
|
+
observationTruncation: ObservationTruncationMeta.optional(),
|
|
92
99
|
raw_output: zod.z.string().optional(),
|
|
93
100
|
image_info: ImageInfoMeta.optional(),
|
|
94
101
|
taskType: zod.z.string().optional(),
|
|
@@ -182,6 +189,7 @@ var AgentSpecBudgetPolicy = zod.z.object({
|
|
|
182
189
|
});
|
|
183
190
|
var AgentSpecToolHistoryPolicy = zod.z.object({
|
|
184
191
|
strategy: zod.z.enum(["per-pair", "per-run", "none"]).optional(),
|
|
192
|
+
retentionMode: zod.z.enum(["drop", "compress"]).optional(),
|
|
185
193
|
keepLatestToolPairs: zod.z.number().int().nonnegative().optional(),
|
|
186
194
|
keepLatestRuns: zod.z.number().int().nonnegative().optional(),
|
|
187
195
|
maxInteractionGroups: zod.z.number().int().nonnegative().optional(),
|
|
@@ -234,7 +242,17 @@ var AgentSpecReasoningRetentionPolicy = zod.z.object({
|
|
|
234
242
|
var AgentSpecTokenEstimationPolicy = zod.z.object({
|
|
235
243
|
encoding: zod.z.string().min(1).optional(),
|
|
236
244
|
avgCharsPerToken: zod.z.number().positive().optional(),
|
|
237
|
-
toolCallOverhead: zod.z.number().int().nonnegative().optional()
|
|
245
|
+
toolCallOverhead: zod.z.number().int().nonnegative().optional(),
|
|
246
|
+
calibration: zod.z.object({
|
|
247
|
+
enabled: zod.z.boolean().optional(),
|
|
248
|
+
minSamples: zod.z.number().int().positive().optional(),
|
|
249
|
+
minCoefficient: zod.z.number().positive().optional(),
|
|
250
|
+
maxCoefficient: zod.z.number().positive().optional()
|
|
251
|
+
}).optional(),
|
|
252
|
+
remoteCount: zod.z.object({
|
|
253
|
+
enabled: zod.z.boolean().optional(),
|
|
254
|
+
failureBehavior: zod.z.enum(["use-local-estimate", "fail-fast"]).optional()
|
|
255
|
+
}).optional()
|
|
238
256
|
});
|
|
239
257
|
var AgentSpecSystemReminderTrigger = zod.z.object({
|
|
240
258
|
kind: zod.z.string().min(1),
|
|
@@ -890,6 +908,189 @@ var createSSEErrorEvent = (id, conversationId, turnId, error, options = {}) => (
|
|
|
890
908
|
error,
|
|
891
909
|
...options
|
|
892
910
|
});
|
|
911
|
+
var TokenCountSource = zod.z.enum([
|
|
912
|
+
"local-estimate",
|
|
913
|
+
"provider-preflight-count",
|
|
914
|
+
"provider-response-usage",
|
|
915
|
+
"host-supplied",
|
|
916
|
+
"test-fixture"
|
|
917
|
+
]);
|
|
918
|
+
var TokenCountConfidence = zod.z.enum([
|
|
919
|
+
"estimate",
|
|
920
|
+
"provider-estimate",
|
|
921
|
+
"actual"
|
|
922
|
+
]);
|
|
923
|
+
var TokenRouteCapabilities = zod.z.object({
|
|
924
|
+
supportsRemoteTokenCount: zod.z.boolean().optional(),
|
|
925
|
+
supportsResponseUsage: zod.z.boolean().optional(),
|
|
926
|
+
supportsImageInput: zod.z.boolean().optional(),
|
|
927
|
+
supportsCachedInputBilling: zod.z.boolean().optional(),
|
|
928
|
+
supportsReasoningTokens: zod.z.boolean().optional()
|
|
929
|
+
});
|
|
930
|
+
var TokenRoute = zod.z.object({
|
|
931
|
+
providerId: zod.z.string().describe("host \u4FA7 provider \u6807\u8BC6\uFF1Aopenai / anthropic / openrouter / siliconflow / zai ..."),
|
|
932
|
+
baseURL: zod.z.string().optional().describe("\u4E2D\u8F6C\u5E73\u53F0\u6216\u79C1\u6709 endpoint\uFF1B\u7528\u4E8E\u533A\u5206\u540C\u540D\u6A21\u578B\u7684\u4E0D\u540C route"),
|
|
933
|
+
modelId: zod.z.string().describe("host \u4FA7\u6A21\u578B id"),
|
|
934
|
+
providerModelId: zod.z.string().optional().describe("provider \u5B9E\u9645\u6A21\u578B\u540D\uFF08\u4E0E host modelId \u53EF\u80FD\u4E0D\u540C\uFF09"),
|
|
935
|
+
capabilities: TokenRouteCapabilities.optional()
|
|
936
|
+
});
|
|
937
|
+
var tokenCount = zod.z.number().int().nonnegative();
|
|
938
|
+
var CanonicalLlmUsage = zod.z.object({
|
|
939
|
+
inputTokens: tokenCount.describe("\u975E\u7F13\u5B58\u666E\u901A\u8F93\u5165 token"),
|
|
940
|
+
outputTokens: tokenCount.describe("\u8F93\u51FA token"),
|
|
941
|
+
reasoningTokens: tokenCount.optional().describe("\u63A8\u7406 token\uFF1Bundefined=\u672A\u5355\u5217\uFF0C0=\u62A5\u544A\u4E3A 0"),
|
|
942
|
+
cacheReadTokens: tokenCount.optional().describe("\u7F13\u5B58\u547D\u4E2D\u8BFB\u53D6 token"),
|
|
943
|
+
cacheWriteTokens: tokenCount.optional().describe("\u7F13\u5B58\u5199\u5165 token"),
|
|
944
|
+
totalTokens: tokenCount.optional().describe("provider \u62A5\u544A\u7684\u603B\u91CF\uFF1B\u53EF\u7F3A\u5931\uFF0C\u4E14\u4E0D\u4FDD\u8BC1\u7B49\u4E8E\u5404\u9879\u4E4B\u548C"),
|
|
945
|
+
source: TokenCountSource,
|
|
946
|
+
confidence: TokenCountConfidence,
|
|
947
|
+
rawUsage: zod.z.unknown().optional().describe("\u539F\u59CB provider usage\uFF0C\u4EC5\u4F9B\u5BA1\u8BA1")
|
|
948
|
+
});
|
|
949
|
+
var tokenCount2 = zod.z.number().int().nonnegative();
|
|
950
|
+
var tokenPrice = zod.z.number().finite().nonnegative();
|
|
951
|
+
zod.z.enum([
|
|
952
|
+
"llm-usage",
|
|
953
|
+
"context-component"
|
|
954
|
+
]);
|
|
955
|
+
var ContextTokenComponentKind = zod.z.enum([
|
|
956
|
+
"system",
|
|
957
|
+
"user",
|
|
958
|
+
"assistant",
|
|
959
|
+
"tool",
|
|
960
|
+
"context-injection",
|
|
961
|
+
"history-summary",
|
|
962
|
+
"working-memory",
|
|
963
|
+
"fence",
|
|
964
|
+
"system-reminder",
|
|
965
|
+
"other"
|
|
966
|
+
]);
|
|
967
|
+
var TokenUsageTotals = zod.z.object({
|
|
968
|
+
inputTokens: tokenCount2,
|
|
969
|
+
outputTokens: tokenCount2,
|
|
970
|
+
reasoningTokens: tokenCount2.optional(),
|
|
971
|
+
cacheReadTokens: tokenCount2.optional(),
|
|
972
|
+
cacheWriteTokens: tokenCount2.optional(),
|
|
973
|
+
totalTokens: tokenCount2.optional(),
|
|
974
|
+
usageCount: zod.z.number().int().nonnegative()
|
|
975
|
+
});
|
|
976
|
+
var ContextTokenComponent = zod.z.object({
|
|
977
|
+
componentId: zod.z.string().min(1),
|
|
978
|
+
kind: ContextTokenComponentKind,
|
|
979
|
+
tokens: tokenCount2,
|
|
980
|
+
source: TokenCountSource,
|
|
981
|
+
confidence: TokenCountConfidence,
|
|
982
|
+
label: zod.z.string().optional(),
|
|
983
|
+
messageId: zod.z.string().optional(),
|
|
984
|
+
role: zod.z.string().optional(),
|
|
985
|
+
action: zod.z.string().optional(),
|
|
986
|
+
kept: zod.z.boolean().optional(),
|
|
987
|
+
truncatedAtExecution: zod.z.boolean().optional(),
|
|
988
|
+
originalTokensEstimate: tokenCount2.optional(),
|
|
989
|
+
droppedTokensEstimate: tokenCount2.optional()
|
|
990
|
+
});
|
|
991
|
+
var TokenLedgerEntryBase = zod.z.object({
|
|
992
|
+
id: zod.z.string().min(1),
|
|
993
|
+
runId: zod.z.string().optional(),
|
|
994
|
+
parentRunId: zod.z.string().optional(),
|
|
995
|
+
conversationId: zod.z.string().optional(),
|
|
996
|
+
turnId: zod.z.string().optional(),
|
|
997
|
+
stepId: zod.z.string().optional(),
|
|
998
|
+
route: TokenRoute.optional(),
|
|
999
|
+
createdAt: zod.z.number().int().nonnegative().optional()
|
|
1000
|
+
});
|
|
1001
|
+
var LlmUsageTokenLedgerEntry = TokenLedgerEntryBase.extend({
|
|
1002
|
+
kind: zod.z.literal("llm-usage"),
|
|
1003
|
+
modelId: zod.z.string().optional(),
|
|
1004
|
+
usage: CanonicalLlmUsage
|
|
1005
|
+
});
|
|
1006
|
+
var ContextComponentTokenLedgerEntry = TokenLedgerEntryBase.extend({
|
|
1007
|
+
kind: zod.z.literal("context-component"),
|
|
1008
|
+
components: zod.z.array(ContextTokenComponent),
|
|
1009
|
+
totalTokens: tokenCount2
|
|
1010
|
+
});
|
|
1011
|
+
zod.z.discriminatedUnion("kind", [
|
|
1012
|
+
LlmUsageTokenLedgerEntry,
|
|
1013
|
+
ContextComponentTokenLedgerEntry
|
|
1014
|
+
]);
|
|
1015
|
+
var TokenLedgerAggregate = zod.z.object({
|
|
1016
|
+
llmUsage: TokenUsageTotals.optional(),
|
|
1017
|
+
contextTokens: tokenCount2,
|
|
1018
|
+
entryCount: zod.z.number().int().nonnegative(),
|
|
1019
|
+
llmCallCount: zod.z.number().int().nonnegative(),
|
|
1020
|
+
contextComponentCount: zod.z.number().int().nonnegative()
|
|
1021
|
+
});
|
|
1022
|
+
zod.z.object({
|
|
1023
|
+
/**
|
|
1024
|
+
* 父 run 自己产生的 usage;子 run 必须放到 children,避免展示或计费时重复相加。
|
|
1025
|
+
*/
|
|
1026
|
+
own: TokenLedgerAggregate,
|
|
1027
|
+
children: TokenLedgerAggregate.optional()
|
|
1028
|
+
});
|
|
1029
|
+
var TokenCostComponent = zod.z.enum([
|
|
1030
|
+
"input",
|
|
1031
|
+
"output",
|
|
1032
|
+
"reasoning",
|
|
1033
|
+
"cacheRead",
|
|
1034
|
+
"cacheWrite"
|
|
1035
|
+
]);
|
|
1036
|
+
zod.z.object({
|
|
1037
|
+
currency: zod.z.string().min(1),
|
|
1038
|
+
unit: zod.z.literal("per_1m_tokens"),
|
|
1039
|
+
input: tokenPrice.optional(),
|
|
1040
|
+
output: tokenPrice.optional(),
|
|
1041
|
+
reasoning: tokenPrice.optional(),
|
|
1042
|
+
cacheRead: tokenPrice.optional(),
|
|
1043
|
+
cacheWrite: tokenPrice.optional()
|
|
1044
|
+
});
|
|
1045
|
+
zod.z.object({
|
|
1046
|
+
status: zod.z.enum(["computed", "unknown"]),
|
|
1047
|
+
currency: zod.z.string().optional(),
|
|
1048
|
+
inputCost: tokenPrice.optional(),
|
|
1049
|
+
outputCost: tokenPrice.optional(),
|
|
1050
|
+
reasoningCost: tokenPrice.optional(),
|
|
1051
|
+
cacheReadCost: tokenPrice.optional(),
|
|
1052
|
+
cacheWriteCost: tokenPrice.optional(),
|
|
1053
|
+
totalCost: tokenPrice.optional(),
|
|
1054
|
+
missingPriceComponents: zod.z.array(TokenCostComponent).optional()
|
|
1055
|
+
});
|
|
1056
|
+
var tokenCount3 = zod.z.number().int().nonnegative();
|
|
1057
|
+
var actualCalibrationSource = zod.z.enum([
|
|
1058
|
+
"provider-response-usage",
|
|
1059
|
+
"host-supplied",
|
|
1060
|
+
"test-fixture"
|
|
1061
|
+
]);
|
|
1062
|
+
zod.z.object({
|
|
1063
|
+
route: TokenRoute,
|
|
1064
|
+
localEstimateTokens: tokenCount3,
|
|
1065
|
+
actualInputTokens: tokenCount3,
|
|
1066
|
+
source: actualCalibrationSource,
|
|
1067
|
+
confidence: zod.z.literal("actual"),
|
|
1068
|
+
observedAt: zod.z.number().int().nonnegative().optional(),
|
|
1069
|
+
runId: zod.z.string().optional(),
|
|
1070
|
+
ledgerEntryId: zod.z.string().optional()
|
|
1071
|
+
});
|
|
1072
|
+
zod.z.object({
|
|
1073
|
+
enabled: zod.z.boolean(),
|
|
1074
|
+
applied: zod.z.boolean(),
|
|
1075
|
+
route: TokenRoute.optional(),
|
|
1076
|
+
sampleCount: zod.z.number().int().nonnegative(),
|
|
1077
|
+
coefficient: zod.z.number().positive().optional(),
|
|
1078
|
+
minSamples: zod.z.number().int().positive().optional(),
|
|
1079
|
+
minCoefficient: zod.z.number().positive().optional(),
|
|
1080
|
+
maxCoefficient: zod.z.number().positive().optional(),
|
|
1081
|
+
localEstimateTokens: tokenCount3.optional(),
|
|
1082
|
+
calibratedEstimateTokens: tokenCount3.optional(),
|
|
1083
|
+
deltaTokens: zod.z.number().int().optional(),
|
|
1084
|
+
sampleLedgerEntryIds: zod.z.array(zod.z.string()).optional()
|
|
1085
|
+
});
|
|
1086
|
+
zod.z.object({
|
|
1087
|
+
route: TokenRoute.optional(),
|
|
1088
|
+
localEstimateTokens: tokenCount3,
|
|
1089
|
+
calibratedEstimateTokens: tokenCount3,
|
|
1090
|
+
finalTokens: tokenCount3,
|
|
1091
|
+
source: zod.z.literal("local-estimate"),
|
|
1092
|
+
confidence: zod.z.literal("estimate")
|
|
1093
|
+
});
|
|
893
1094
|
|
|
894
1095
|
// src/shared/ids.ts
|
|
895
1096
|
function isoRandomUUID() {
|