@anvia/core 1.14.0 → 1.16.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.
Files changed (154) hide show
  1. package/dist/agent/agent-tool.js +6 -6
  2. package/dist/agent/agent.js +20 -20
  3. package/dist/agent/index.d.ts +9 -9
  4. package/dist/agent/index.js +24 -24
  5. package/dist/agent/resolve-options.js +7 -7
  6. package/dist/agent/resolved-agent.js +21 -21
  7. package/dist/agent/team/agent-team.js +24 -24
  8. package/dist/agent/team/index.js +24 -24
  9. package/dist/agent/tool-catalog.js +7 -7
  10. package/dist/{agent-DdkrgyW0.d.ts → agent-CIM7noas.d.ts} +6 -6
  11. package/dist/chunk-2O3MLES7.js +82 -0
  12. package/dist/chunk-2O3MLES7.js.map +1 -0
  13. package/dist/{chunk-MIPBH5S7.js → chunk-3VIMLOWJ.js} +2 -1
  14. package/dist/{chunk-MIPBH5S7.js.map → chunk-3VIMLOWJ.js.map} +1 -1
  15. package/dist/{chunk-KL652GO5.js → chunk-3XUUNNCS.js} +18 -15
  16. package/dist/{chunk-KL652GO5.js.map → chunk-3XUUNNCS.js.map} +1 -1
  17. package/dist/{chunk-UWWWCH4M.js → chunk-4BGJBGJU.js} +12 -8
  18. package/dist/chunk-4BGJBGJU.js.map +1 -0
  19. package/dist/{chunk-3YN5B5UW.js → chunk-4FSGJEFT.js} +3 -3
  20. package/dist/{chunk-EKZRAWBP.js → chunk-4HO6VPC7.js} +2 -2
  21. package/dist/{chunk-3F6ZY63S.js → chunk-54WSIN4Q.js} +3 -3
  22. package/dist/{chunk-6Q5VOKBO.js → chunk-6NQXLSCZ.js} +12 -9
  23. package/dist/chunk-6NQXLSCZ.js.map +1 -0
  24. package/dist/{chunk-WCJRGYF7.js → chunk-6YYZ7VJQ.js} +5 -5
  25. package/dist/{chunk-VTYFF2AM.js → chunk-BJ4LJGSI.js} +21 -13
  26. package/dist/chunk-BJ4LJGSI.js.map +1 -0
  27. package/dist/{chunk-6QOBVCJH.js → chunk-BX52ILPM.js} +2 -2
  28. package/dist/{chunk-E5MIZ6Z5.js → chunk-C6YE3JXV.js} +2 -2
  29. package/dist/{chunk-ETYB5JO6.js → chunk-EM4F5SRB.js} +5 -3
  30. package/dist/chunk-EM4F5SRB.js.map +1 -0
  31. package/dist/{chunk-OBM7JJCK.js → chunk-GRGD4ZCM.js} +2 -2
  32. package/dist/{chunk-LGPXCJJO.js → chunk-GULOODEA.js} +2 -2
  33. package/dist/{chunk-XQRMPPTC.js → chunk-HG3GHZVY.js} +108 -23
  34. package/dist/chunk-HG3GHZVY.js.map +1 -0
  35. package/dist/{chunk-ZWYMXBGB.js → chunk-I3O362NF.js} +2 -2
  36. package/dist/{chunk-PIAPGY6O.js → chunk-I4AOH75W.js} +2 -2
  37. package/dist/{chunk-V5KBSXAJ.js → chunk-I5XFFO4W.js} +2 -2
  38. package/dist/{chunk-4EBIM3LP.js → chunk-JLSNI3DV.js} +2 -2
  39. package/dist/{chunk-UFE7JTII.js → chunk-L2UPWQQZ.js} +27 -7
  40. package/dist/chunk-L2UPWQQZ.js.map +1 -0
  41. package/dist/{chunk-MG7JYQN2.js → chunk-LC23KCUN.js} +1 -1
  42. package/dist/chunk-LC23KCUN.js.map +1 -0
  43. package/dist/{chunk-JG3RXXDW.js → chunk-NSG2CIGM.js} +5 -5
  44. package/dist/{chunk-7YWEVTDM.js → chunk-ONFVTMN3.js} +8 -8
  45. package/dist/{chunk-PNNBUO57.js → chunk-OSS2VGRW.js} +3 -3
  46. package/dist/{chunk-R4AJ2EE3.js → chunk-PIBFPEK3.js} +2 -2
  47. package/dist/{chunk-NVPLMNFA.js → chunk-QNNDKCZG.js} +2 -2
  48. package/dist/{chunk-AGOZCYFP.js → chunk-ROUJCOAN.js} +2 -2
  49. package/dist/{chunk-VCOGUS3Q.js → chunk-T5FMJJKQ.js} +2 -2
  50. package/dist/{chunk-VHPT2C4P.js → chunk-TMSWHXYQ.js} +2 -1
  51. package/dist/{chunk-VHPT2C4P.js.map → chunk-TMSWHXYQ.js.map} +1 -1
  52. package/dist/{chunk-ZMAF3I4H.js → chunk-WACXVXGU.js} +2 -2
  53. package/dist/{chunk-V3FFZWF3.js → chunk-YKGIOXTR.js} +38 -19
  54. package/dist/chunk-YKGIOXTR.js.map +1 -0
  55. package/dist/{chunk-JU3RX364.js → chunk-Z5WMW4NP.js} +2 -2
  56. package/dist/{chunk-MKSTANFV.js → chunk-ZQC5V2AM.js} +2 -2
  57. package/dist/{chunk-SXMYOVBL.js → chunk-ZXSAPGWJ.js} +3 -3
  58. package/dist/completion/generate-completion.js +2 -2
  59. package/dist/completion/index.js +2 -2
  60. package/dist/completion/stream-accumulator.js +1 -1
  61. package/dist/decision/index.d.ts +6 -119
  62. package/dist/{dynamic-tools-B3OjYyhC.d.ts → dynamic-tools-BtvhcGIC.d.ts} +2 -2
  63. package/dist/evals/advanced-metrics.js +5 -5
  64. package/dist/evals/cli.js +3 -3
  65. package/dist/evals/index.d.ts +2 -2
  66. package/dist/evals/index.js +7 -7
  67. package/dist/evals/judge.js +4 -4
  68. package/dist/evals/metrics.js +4 -4
  69. package/dist/evals/runner.js +2 -2
  70. package/dist/extractor/extractor.js +3 -3
  71. package/dist/extractor/index.js +3 -3
  72. package/dist/index.d.ts +10 -9
  73. package/dist/index.js +30 -30
  74. package/dist/internal/agent-runtime/agent-run.js +16 -16
  75. package/dist/internal/agent-runtime/continuation-state.js +2 -2
  76. package/dist/internal/agent-runtime/execution.js +1 -1
  77. package/dist/internal/agent-runtime/interaction-suspension.js +2 -2
  78. package/dist/internal/agent-runtime/loop-context.js +4 -4
  79. package/dist/internal/agent-runtime/memory.js +5 -5
  80. package/dist/internal/agent-runtime/prepared-tool-call.js +2 -2
  81. package/dist/internal/agent-runtime/retrieval.js +5 -5
  82. package/dist/internal/agent-runtime/tool-execution.js +12 -12
  83. package/dist/internal/agent.d.ts +25 -9
  84. package/dist/internal/agent.js +22 -22
  85. package/dist/internal/team-runtime/member.js +2 -2
  86. package/dist/internal/team-runtime/run.js +23 -23
  87. package/dist/internal/team-runtime/tools.js +4 -4
  88. package/dist/mcp/index.d.ts +3 -3
  89. package/dist/memory/compaction.js +3 -3
  90. package/dist/memory/index.js +3 -3
  91. package/dist/{middleware-rxi6GI2B.d.ts → middleware-CDQQr_PM.d.ts} +1 -1
  92. package/dist/observability/group.js +2 -2
  93. package/dist/observability/index.d.ts +2 -2
  94. package/dist/observability/index.js +2 -2
  95. package/dist/pipeline/graph.js +5 -7
  96. package/dist/pipeline/index.d.ts +45 -11
  97. package/dist/pipeline/index.js +11 -7
  98. package/dist/pipeline/observability.js +1 -1
  99. package/dist/pipeline/pipeline.js +11 -7
  100. package/dist/pipeline/runtime.js +2 -2
  101. package/dist/skills/index.d.ts +3 -3
  102. package/dist/skills/index.js +11 -11
  103. package/dist/skills/load.js +11 -11
  104. package/dist/skills/tools.js +10 -10
  105. package/dist/{think-tool-CTuagAtn.d.ts → think-tool-vmLIfQik.d.ts} +1 -1
  106. package/dist/tool/create-tool.js +3 -3
  107. package/dist/tool/dynamic-tools.js +6 -6
  108. package/dist/tool/index.d.ts +5 -5
  109. package/dist/tool/index.js +16 -16
  110. package/dist/tool/question-tool.js +4 -4
  111. package/dist/tool/think-tool.js +4 -4
  112. package/dist/tool/tool.js +1 -1
  113. package/dist/{tool-W1cAPuRF.d.ts → tool-B6meo2AE.d.ts} +4 -1
  114. package/dist/{types-94Q2mPRa.d.ts → types-BOxOjkbS.d.ts} +1 -1
  115. package/dist/types-Bt19cjEr.d.ts +119 -0
  116. package/dist/{types-ChyQISt-.d.ts → types-CmdZOpKi.d.ts} +23 -3
  117. package/dist/{types-CIG2loIE.d.ts → types-jVXFDum8.d.ts} +1 -1
  118. package/dist/vector-store/filter.js +1 -1
  119. package/dist/vector-store/index.d.ts +24 -6
  120. package/dist/vector-store/index.js +5 -5
  121. package/package.json +1 -1
  122. package/dist/chunk-5WLIHNNJ.js +0 -56
  123. package/dist/chunk-5WLIHNNJ.js.map +0 -1
  124. package/dist/chunk-6Q5VOKBO.js.map +0 -1
  125. package/dist/chunk-ETYB5JO6.js.map +0 -1
  126. package/dist/chunk-MG7JYQN2.js.map +0 -1
  127. package/dist/chunk-UFE7JTII.js.map +0 -1
  128. package/dist/chunk-UWWWCH4M.js.map +0 -1
  129. package/dist/chunk-V3FFZWF3.js.map +0 -1
  130. package/dist/chunk-VTYFF2AM.js.map +0 -1
  131. package/dist/chunk-XQRMPPTC.js.map +0 -1
  132. /package/dist/{chunk-3YN5B5UW.js.map → chunk-4FSGJEFT.js.map} +0 -0
  133. /package/dist/{chunk-EKZRAWBP.js.map → chunk-4HO6VPC7.js.map} +0 -0
  134. /package/dist/{chunk-3F6ZY63S.js.map → chunk-54WSIN4Q.js.map} +0 -0
  135. /package/dist/{chunk-WCJRGYF7.js.map → chunk-6YYZ7VJQ.js.map} +0 -0
  136. /package/dist/{chunk-6QOBVCJH.js.map → chunk-BX52ILPM.js.map} +0 -0
  137. /package/dist/{chunk-E5MIZ6Z5.js.map → chunk-C6YE3JXV.js.map} +0 -0
  138. /package/dist/{chunk-OBM7JJCK.js.map → chunk-GRGD4ZCM.js.map} +0 -0
  139. /package/dist/{chunk-LGPXCJJO.js.map → chunk-GULOODEA.js.map} +0 -0
  140. /package/dist/{chunk-ZWYMXBGB.js.map → chunk-I3O362NF.js.map} +0 -0
  141. /package/dist/{chunk-PIAPGY6O.js.map → chunk-I4AOH75W.js.map} +0 -0
  142. /package/dist/{chunk-V5KBSXAJ.js.map → chunk-I5XFFO4W.js.map} +0 -0
  143. /package/dist/{chunk-4EBIM3LP.js.map → chunk-JLSNI3DV.js.map} +0 -0
  144. /package/dist/{chunk-JG3RXXDW.js.map → chunk-NSG2CIGM.js.map} +0 -0
  145. /package/dist/{chunk-7YWEVTDM.js.map → chunk-ONFVTMN3.js.map} +0 -0
  146. /package/dist/{chunk-PNNBUO57.js.map → chunk-OSS2VGRW.js.map} +0 -0
  147. /package/dist/{chunk-R4AJ2EE3.js.map → chunk-PIBFPEK3.js.map} +0 -0
  148. /package/dist/{chunk-NVPLMNFA.js.map → chunk-QNNDKCZG.js.map} +0 -0
  149. /package/dist/{chunk-AGOZCYFP.js.map → chunk-ROUJCOAN.js.map} +0 -0
  150. /package/dist/{chunk-VCOGUS3Q.js.map → chunk-T5FMJJKQ.js.map} +0 -0
  151. /package/dist/{chunk-ZMAF3I4H.js.map → chunk-WACXVXGU.js.map} +0 -0
  152. /package/dist/{chunk-JU3RX364.js.map → chunk-Z5WMW4NP.js.map} +0 -0
  153. /package/dist/{chunk-MKSTANFV.js.map → chunk-ZQC5V2AM.js.map} +0 -0
  154. /package/dist/{chunk-SXMYOVBL.js.map → chunk-ZXSAPGWJ.js.map} +0 -0
@@ -1,16 +1,16 @@
1
1
  import { b as RetrySetting } from './retry-CjvSlKGW.js';
2
2
  import { D as Document, d as CompletionModel, P as ProviderTool, J as JsonObject, C as CompletionControlValues, f as CompletionModelControlsOf, z as ToolChoice } from './types-DYqZKDA8.js';
3
3
  import { d as GuardrailPolicyInput, c as GuardrailPolicy } from './types-CqiX-4_C.js';
4
- import { a as McpServer } from './types-94Q2mPRa.js';
4
+ import { a as McpServer } from './types-BOxOjkbS.js';
5
5
  import { F as MemoryStore, A as MemorySavePolicy, G as MemoryTokenCounter, o as MemoryCompactor, d as MemoryCompactionConflictRetryOptions, z as MemoryOptions, k as MemoryCompactionResult } from './types-CWh9AQrq.js';
6
- import { h as AgentLifecycle, P as AgentObservabilityOptions, k as AgentMiddleware, o as AgentRunOptions, l as AgentOutcome, p as AgentRunSettings, u as AgentStream, j as AgentMemoryCompactionOptions } from './middleware-rxi6GI2B.js';
6
+ import { h as AgentLifecycle, P as AgentObservabilityOptions, k as AgentMiddleware, o as AgentRunOptions, l as AgentOutcome, p as AgentRunSettings, u as AgentStream, j as AgentMemoryCompactionOptions } from './middleware-CDQQr_PM.js';
7
7
  import { Z as ZodSchema } from './zod-schema-C7F4clpm.js';
8
- import { A as AnyTool, T as Tool, c as ToolCallContext, N as NormalizedToolOutput } from './tool-W1cAPuRF.js';
8
+ import { A as AnyTool, T as Tool, c as ToolCallContext, N as NormalizedToolOutput } from './tool-B6meo2AE.js';
9
9
  import { AgentContinuation, AgentInteractionResponse } from './agent/interactions/index.js';
10
- import { a as SkillSet } from './types-CIG2loIE.js';
11
- import { T as ToolIndex } from './dynamic-tools-B3OjYyhC.js';
10
+ import { a as SkillSet } from './types-jVXFDum8.js';
11
+ import { T as ToolIndex } from './dynamic-tools-BtvhcGIC.js';
12
12
  import { E as EmbeddingModel, c as SparseEmbeddingModel } from './types-Cr4uiYo5.js';
13
- import { V as VectorFilter, a as VectorSearchResult, d as VectorStore, H as HybridVectorStore, e as VectorFusion } from './types-ChyQISt-.js';
13
+ import { V as VectorFilter, a as VectorSearchResult, d as VectorStore, H as HybridVectorStore, e as VectorFusion } from './types-CmdZOpKi.js';
14
14
 
15
15
  type VectorContextBaseOptions<T = unknown> = {
16
16
  topK: number;
@@ -0,0 +1,82 @@
1
+ // src/vector-store/filter.ts
2
+ var vectorFilter = {
3
+ eq(key, value) {
4
+ return { type: "eq", key, value };
5
+ },
6
+ ne(key, value) {
7
+ return { type: "ne", key, value };
8
+ },
9
+ gt(key, value) {
10
+ return { type: "gt", key, value };
11
+ },
12
+ gte(key, value) {
13
+ return { type: "gte", key, value };
14
+ },
15
+ lt(key, value) {
16
+ return { type: "lt", key, value };
17
+ },
18
+ lte(key, value) {
19
+ return { type: "lte", key, value };
20
+ },
21
+ in(key, values) {
22
+ return { type: "in", key, values: [...values] };
23
+ },
24
+ and(...filters) {
25
+ return { type: "and", filters };
26
+ },
27
+ or(...filters) {
28
+ return { type: "or", filters };
29
+ }
30
+ };
31
+ function matchesVectorFilter(metadata, filter) {
32
+ if (filter === void 0) {
33
+ return true;
34
+ }
35
+ if (metadata === void 0) {
36
+ return false;
37
+ }
38
+ switch (filter.type) {
39
+ case "eq":
40
+ return metadata[filter.key] === filter.value;
41
+ case "ne":
42
+ return metadata[filter.key] !== filter.value;
43
+ case "gt":
44
+ return (compare(metadata[filter.key], filter.value) ?? 0) > 0;
45
+ case "gte": {
46
+ const result = compare(metadata[filter.key], filter.value);
47
+ return result !== void 0 && result >= 0;
48
+ }
49
+ case "lt":
50
+ return (compare(metadata[filter.key], filter.value) ?? 0) < 0;
51
+ case "lte": {
52
+ const result = compare(metadata[filter.key], filter.value);
53
+ return result !== void 0 && result <= 0;
54
+ }
55
+ case "in": {
56
+ const value = metadata[filter.key];
57
+ return value !== void 0 && filter.values.includes(value);
58
+ }
59
+ case "and":
60
+ return filter.filters.every((child) => matchesVectorFilter(metadata, child));
61
+ case "or":
62
+ return filter.filters.some((child) => matchesVectorFilter(metadata, child));
63
+ }
64
+ }
65
+ function compare(left, right) {
66
+ if (typeof left === "number" && typeof right === "number") {
67
+ return left - right;
68
+ }
69
+ if (typeof left === "string" && typeof right === "string") {
70
+ return left.localeCompare(right);
71
+ }
72
+ if (typeof left === "boolean" && typeof right === "boolean") {
73
+ return Number(left) - Number(right);
74
+ }
75
+ return void 0;
76
+ }
77
+
78
+ export {
79
+ vectorFilter,
80
+ matchesVectorFilter
81
+ };
82
+ //# sourceMappingURL=chunk-2O3MLES7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vector-store/filter.ts"],"sourcesContent":["import type { VectorMetadata, VectorMetadataValue } from \"../embeddings\";\nimport type { VectorFilter, VectorFilterList } from \"./types\";\n\nexport type {\n VectorFilter,\n VectorFilterComparisonOperator,\n VectorFilterList,\n VectorFilterOperator,\n} from \"./types\";\n\nexport const vectorFilter = {\n eq(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"eq\", key, value };\n },\n ne(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"ne\", key, value };\n },\n gt(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"gt\", key, value };\n },\n gte(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"gte\", key, value };\n },\n lt(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"lt\", key, value };\n },\n lte(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"lte\", key, value };\n },\n in(key: string, values: readonly VectorMetadataValue[]): VectorFilter {\n return { type: \"in\", key, values: [...values] };\n },\n and(...filters: VectorFilterList): VectorFilter {\n return { type: \"and\", filters };\n },\n or(...filters: VectorFilterList): VectorFilter {\n return { type: \"or\", filters };\n },\n};\n\nexport function matchesVectorFilter(\n metadata: VectorMetadata | undefined,\n filter: VectorFilter | undefined,\n): boolean {\n if (filter === undefined) {\n return true;\n }\n if (metadata === undefined) {\n return false;\n }\n\n switch (filter.type) {\n case \"eq\":\n return metadata[filter.key] === filter.value;\n case \"ne\":\n return metadata[filter.key] !== filter.value;\n case \"gt\":\n return (compare(metadata[filter.key], filter.value) ?? 0) > 0;\n case \"gte\": {\n const result = compare(metadata[filter.key], filter.value);\n return result !== undefined && result >= 0;\n }\n case \"lt\":\n return (compare(metadata[filter.key], filter.value) ?? 0) < 0;\n case \"lte\": {\n const result = compare(metadata[filter.key], filter.value);\n return result !== undefined && result <= 0;\n }\n case \"in\": {\n const value = metadata[filter.key];\n return value !== undefined && filter.values.includes(value);\n }\n case \"and\":\n return filter.filters.every((child) => matchesVectorFilter(metadata, child));\n case \"or\":\n return filter.filters.some((child) => matchesVectorFilter(metadata, child));\n }\n}\n\nfunction compare(\n left: VectorMetadataValue | undefined,\n right: VectorMetadataValue,\n): number | undefined {\n if (typeof left === \"number\" && typeof right === \"number\") {\n return left - right;\n }\n if (typeof left === \"string\" && typeof right === \"string\") {\n return left.localeCompare(right);\n }\n if (typeof left === \"boolean\" && typeof right === \"boolean\") {\n return Number(left) - Number(right);\n }\n return undefined;\n}\n"],"mappings":";AAUO,IAAM,eAAe;AAAA,EAC1B,GAAG,KAAa,OAA0C;AACxD,WAAO,EAAE,MAAM,MAAM,KAAK,MAAM;AAAA,EAClC;AAAA,EACA,GAAG,KAAa,OAA0C;AACxD,WAAO,EAAE,MAAM,MAAM,KAAK,MAAM;AAAA,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AAG,GAAG,OAAO,KAAK;AACzD,aAAO,WAAW,UAAa,UAAU;AAAA,IAC3C;AAAA,IACA,KAAK,MAAM;AACT,YAAM,QAAQ,SAAS,OAAO,GAAG;AACjC,aAAO,UAAU,UAAa,OAAO,OAAO,SAAS,KAAK;AAAA,IAC5D;AAAA,IACA,KAAK;AACH,aAAO,OAAO,QAAQ,MAAM,CAAC,UAAU,oBAAoB,UAAU,KAAK,CAAC;AAAA,IAC7E,KAAK;AACH,aAAO,OAAO,QAAQ,KAAK,CAAC,UAAU,oBAAoB,UAAU,KAAK,CAAC;AAAA,EAC9E;AACF;AAEA,SAAS,QACP,MACA,OACoB;AACpB,MAAI,OAAO,SAAS,YAAY,OAAO,UAAU,UAAU;AACzD,WAAO,OAAO;AAAA,EAChB;AACA,MAAI,OAAO,SAAS,YAAY,OAAO,UAAU,UAAU;AACzD,WAAO,KAAK,cAAc,KAAK;AAAA,EACjC;AACA,MAAI,OAAO,SAAS,aAAa,OAAO,UAAU,WAAW;AAC3D,WAAO,OAAO,IAAI,IAAI,OAAO,KAAK;AAAA,EACpC;AACA,SAAO;AACT;","names":[]}
@@ -554,6 +554,7 @@ function reasoningDeltaEvent(event) {
554
554
  return mapped;
555
555
  }
556
556
  function parseToolArguments(toolCallId, text) {
557
+ if (text.trim() === "") return {};
557
558
  let value;
558
559
  try {
559
560
  value = JSON.parse(text);
@@ -670,4 +671,4 @@ function isReasoningContentType(value) {
670
671
  export {
671
672
  CompletionStreamAccumulator
672
673
  };
673
- //# sourceMappingURL=chunk-MIPBH5S7.js.map
674
+ //# sourceMappingURL=chunk-3VIMLOWJ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/completion/stream-accumulator.ts"],"sourcesContent":["import { isJsonValue } from \"./json\";\nimport { CompletionProviderOutputError } from \"./provider-output-error\";\nimport type {\n AssistantContentPart,\n CompletionModelStreamEvent,\n CompletionResponse,\n CompletionSource,\n CompletionStreamPart,\n JsonValue,\n ProviderToolCall,\n ReasoningDetail,\n ReasoningPart,\n ToolCallPart,\n} from \"./types\";\nimport { Usage } from \"./types\";\n\ntype AccumulatedStreamEvent = Exclude<\n CompletionStreamPart,\n { type: \"tool_call_delta\" } | { type: \"message_id\" }\n>;\n\ntype ReasoningState = {\n id?: string;\n text: string;\n details?: ReasoningDetail[];\n};\n\ntype PartialToolCall = {\n id: string;\n callId?: string;\n name: string;\n argumentsText: string;\n argumentsSnapshotSeen: boolean;\n signature?: string;\n fullCallSeen: boolean;\n};\n\ntype OrderedPartRef =\n | { type: \"text\"; key: string }\n | { type: \"reasoning\"; key: string }\n | { type: \"tool_call\"; key: string };\n\nexport class CompletionStreamAccumulator<RawResponse = unknown> {\n private orderedParts: OrderedPartRef[] = [];\n private textParts = new Map<string, string>();\n private reasoningByKey = new Map<string, ReasoningState>();\n private reasoningKeyById = new Map<string, string>();\n private toolCalls = new Map<string, PartialToolCall>();\n private sources = new Map<string, CompletionSource>();\n private providerToolCalls = new Map<string, ProviderToolCall>();\n private finalResponse: CompletionResponse<RawResponse> | undefined;\n private messageId: string | undefined;\n private nextTextKey = 0;\n private nextReasoningKey = 0;\n\n accept(event: CompletionModelStreamEvent<RawResponse>): AccumulatedStreamEvent | undefined {\n if (event.type === \"text_delta\") {\n if (typeof event.delta !== \"string\") {\n throw new CompletionProviderOutputError({ kind: \"invalid-stream-event\" });\n }\n this.appendText(event.delta);\n return { type: \"text_delta\", delta: event.delta };\n }\n\n if (event.type === \"reasoning_delta\") {\n if (\n typeof event.delta !== \"string\" ||\n (event.id !== undefined && !isNonblankString(event.id)) ||\n (event.signature !== undefined && !isNonblankString(event.signature)) ||\n (event.contentType !== undefined && !isReasoningContentType(event.contentType))\n ) {\n throw new CompletionProviderOutputError({ kind: \"invalid-stream-event\" });\n }\n const reasoning = this.reasoningStateForEvent(event);\n this.appendReasoning(reasoning, event);\n return reasoningDeltaEvent(event);\n }\n\n if (event.type === \"tool_call_delta\") {\n if (!isNonblankString(event.id)) {\n throw new CompletionProviderOutputError({ kind: \"invalid-tool-call\" });\n }\n const toolCall = this.toolCallStateForId(event.id);\n if (toolCall.fullCallSeen) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n if (event.callId !== undefined) {\n if (!isNonblankString(event.callId)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n if (toolCall.callId !== undefined && toolCall.callId !== event.callId) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n toolCall.callId = event.callId;\n }\n if (event.name !== undefined) {\n if (!isNonblankString(event.name)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n if (toolCall.name.length > 0 && toolCall.name !== event.name) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n toolCall.name = event.name;\n }\n if (event.signature !== undefined) {\n if (\n !isNonblankString(event.signature) ||\n (toolCall.signature !== undefined && toolCall.signature !== event.signature)\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n toolCall.signature = event.signature;\n }\n if (\n event.argumentsMode !== undefined &&\n event.argumentsMode !== \"append\" &&\n event.argumentsMode !== \"replace\"\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-stream-event\",\n toolCallId: toolCall.id,\n });\n }\n if (event.argumentsMode !== undefined && event.argumentsDelta === undefined) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-stream-event\",\n toolCallId: toolCall.id,\n });\n }\n if (event.argumentsDelta !== undefined) {\n if (typeof event.argumentsDelta !== \"string\") {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-arguments\",\n toolCallId: toolCall.id,\n });\n }\n if (event.argumentsMode === \"replace\") {\n if (\n toolCall.argumentsText.length > 0 &&\n toolCall.argumentsText !== event.argumentsDelta &&\n (toolCall.argumentsSnapshotSeen ||\n !event.argumentsDelta.startsWith(toolCall.argumentsText))\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n toolCall.argumentsText = event.argumentsDelta;\n toolCall.argumentsSnapshotSeen = true;\n } else {\n if (toolCall.argumentsSnapshotSeen) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n toolCall.argumentsText += event.argumentsDelta;\n }\n }\n return undefined;\n }\n\n if (event.type === \"tool_call\") {\n this.upsertToolCall(event.toolCall);\n return { type: \"tool_call\", toolCall: event.toolCall };\n }\n\n if (event.type === \"source\") {\n this.sources.set(sourceKey(event.source), event.source);\n return { type: \"source\", source: event.source };\n }\n\n if (event.type === \"provider_tool_call\") {\n this.providerToolCalls.set(event.toolCall.id, event.toolCall);\n return { type: \"provider_tool_call\", toolCall: event.toolCall };\n }\n\n if (event.type === \"message_id\") {\n if (!isNonblankString(event.id)) {\n throw new CompletionProviderOutputError({ kind: \"invalid-stream-event\" });\n }\n this.messageId = event.id;\n return undefined;\n }\n\n if (event.type === \"final\") {\n this.finalResponse = event.response;\n return undefined;\n }\n\n return undefined;\n }\n\n response(): CompletionResponse<RawResponse> {\n this.assertAccumulatedFinishReason();\n let accumulatedResponse: CompletionResponse<RawResponse>;\n try {\n accumulatedResponse = this.buildAccumulatedResponse();\n } catch (error) {\n if (error instanceof CompletionProviderOutputError && this.finalResponse !== undefined) {\n throw providerOutputErrorWithUsage(error, this.finalResponse.usage);\n }\n throw error;\n }\n if (this.finalResponse !== undefined) {\n if (accumulatedResponse.choice.length === 0) {\n return this.withAccumulatedArtifacts(this.finalResponse, accumulatedResponse);\n }\n return this.mergeFinalResponse(accumulatedResponse, this.finalResponse);\n }\n\n return accumulatedResponse;\n }\n\n private assertAccumulatedFinishReason(): void {\n if (this.finalResponse === undefined) {\n if (this.toolCalls.size === 0) {\n throw new CompletionProviderOutputError({ kind: \"incomplete-stream\" });\n }\n const toolCallId = this.toolCalls.size === 1 ? this.toolCalls.keys().next().value : undefined;\n throw new CompletionProviderOutputError({\n kind: \"incomplete-tool-call\",\n toolCallId,\n });\n }\n if (this.toolCalls.size === 0) return;\n const finishReason = this.finalResponse.finishReason;\n if (finishReason === \"length\") {\n throw new CompletionProviderOutputError({\n kind: \"truncated-tool-call\",\n finishReason,\n usage: this.finalResponse.usage,\n });\n }\n if (finishReason === \"content-filter\") {\n throw new CompletionProviderOutputError({\n kind: \"filtered-tool-call\",\n finishReason,\n usage: this.finalResponse.usage,\n });\n }\n if (finishReason !== undefined && finishReason !== \"stop\" && finishReason !== \"tool-calls\") {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n usage: this.finalResponse.usage,\n });\n }\n }\n\n private buildAccumulatedResponse(): CompletionResponse<RawResponse> {\n const choice: AssistantContentPart[] = [];\n\n for (const part of this.orderedParts) {\n if (part.type === \"text\") {\n const text = this.textParts.get(part.key) ?? \"\";\n if (text.length > 0) {\n choice.push({ type: \"text\", text });\n }\n continue;\n }\n\n if (part.type === \"reasoning\") {\n const reasoning = this.reasoningByKey.get(part.key);\n if (reasoning !== undefined) {\n choice.push(reasoningContent(reasoning));\n }\n continue;\n }\n\n const toolCall = this.toolCalls.get(part.key);\n if (toolCall !== undefined) {\n choice.push(toolCallContent(toolCall));\n }\n }\n\n const response: CompletionResponse<RawResponse> = {\n choice,\n usage: Usage.empty(),\n rawResponse: undefined as RawResponse,\n };\n if (this.messageId !== undefined) {\n response.messageId = this.messageId;\n }\n const sources = [...this.sources.values()];\n if (sources.length > 0) {\n response.sources = sources;\n }\n const providerToolCalls = [...this.providerToolCalls.values()];\n if (providerToolCalls.length > 0) {\n response.providerToolCalls = providerToolCalls;\n }\n return response;\n }\n\n private upsertToolCall(toolCall: ToolCallPart): void {\n if (\n !isNonblankString(toolCall.toolCallId) ||\n !isNonblankString(toolCall.toolName) ||\n (toolCall.callId !== undefined && !isNonblankString(toolCall.callId)) ||\n (toolCall.signature !== undefined && !isNonblankString(toolCall.signature))\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: isNonblankString(toolCall.toolCallId) ? toolCall.toolCallId : undefined,\n });\n }\n if (!isJsonValue(toolCall.input)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-arguments\",\n toolCallId: toolCall.toolCallId,\n });\n }\n const existing = this.toolCalls.get(toolCall.toolCallId);\n if (existing !== undefined) {\n if (existing.fullCallSeen) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.toolCallId,\n });\n }\n if (\n (existing.name.length > 0 && existing.name !== toolCall.toolName) ||\n (existing.callId !== undefined && existing.callId !== toolCall.callId) ||\n (existing.signature !== undefined &&\n toolCall.signature !== undefined &&\n existing.signature !== toolCall.signature)\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.toolCallId,\n });\n }\n if (existing.argumentsText.length > 0) {\n const accumulatedInput = parseToolArguments(existing.id, existing.argumentsText);\n if (!jsonValuesEqual(accumulatedInput, toolCall.input)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.toolCallId,\n });\n }\n }\n }\n if (!this.toolCalls.has(toolCall.toolCallId)) {\n this.orderedParts.push({ type: \"tool_call\", key: toolCall.toolCallId });\n }\n const partial: PartialToolCall = {\n id: toolCall.toolCallId,\n name: toolCall.toolName,\n argumentsText: JSON.stringify(toolCall.input),\n argumentsSnapshotSeen: true,\n fullCallSeen: true,\n };\n if (toolCall.callId !== undefined) {\n partial.callId = toolCall.callId;\n }\n const signature = toolCall.signature ?? existing?.signature;\n if (signature !== undefined) {\n partial.signature = signature;\n }\n this.toolCalls.set(toolCall.toolCallId, partial);\n }\n\n private mergeFinalResponse(\n accumulatedResponse: CompletionResponse<RawResponse>,\n finalResponse: CompletionResponse<RawResponse>,\n ): CompletionResponse<RawResponse> {\n if (finalResponse.choice.length === 0) {\n const mergedResponse: CompletionResponse<RawResponse> = {\n ...finalResponse,\n choice: accumulatedResponse.choice,\n };\n return this.withAccumulatedArtifacts(mergedResponse, accumulatedResponse);\n }\n\n const accumulatedNonTool = accumulatedResponse.choice.filter(\n (content) => content.type !== \"tool-call\",\n );\n const finalNonTool = finalResponse.choice.filter((content) => content.type !== \"tool-call\");\n if (\n accumulatedNonTool.length > 0 &&\n !nonToolPartsMatchFinal(accumulatedNonTool, finalNonTool)\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-stream-event\",\n usage: finalResponse.usage,\n });\n }\n\n const accumulatedById = new Map<string, ToolCallPart>();\n const accumulatedByCallId = new Map<string, ToolCallPart>();\n for (const content of accumulatedResponse.choice) {\n if (content.type !== \"tool-call\") continue;\n accumulatedById.set(content.toolCallId, content);\n if (content.callId !== undefined) accumulatedByCallId.set(content.callId, content);\n }\n\n const matchedAccumulatedToolCalls = new Set<ToolCallPart>();\n const choice = finalResponse.choice.map((content) => {\n if (content.type !== \"tool-call\") return content;\n const accumulated = accumulatedById.get(content.toolCallId);\n if (accumulated === undefined) {\n const changedIdentity =\n content.callId === undefined ? undefined : accumulatedByCallId.get(content.callId);\n if (changedIdentity !== undefined) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: changedIdentity.toolCallId,\n usage: finalResponse.usage,\n });\n }\n return content;\n }\n matchedAccumulatedToolCalls.add(accumulated);\n return mergeFinalToolCall(accumulated, content, finalResponse.usage);\n });\n\n for (const accumulated of accumulatedById.values()) {\n if (!matchedAccumulatedToolCalls.has(accumulated)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: accumulated.toolCallId,\n usage: finalResponse.usage,\n });\n }\n }\n\n return this.withAccumulatedArtifacts({ ...finalResponse, choice }, accumulatedResponse);\n }\n\n private appendText(delta: string): void {\n const lastPart = this.orderedParts.at(-1);\n const key = lastPart?.type === \"text\" ? lastPart.key : this.createTextKey();\n if (lastPart?.type !== \"text\") {\n this.orderedParts.push({ type: \"text\", key });\n }\n this.textParts.set(key, `${this.textParts.get(key) ?? \"\"}${delta}`);\n }\n\n private reasoningStateForEvent(\n event: Extract<CompletionModelStreamEvent<RawResponse>, { type: \"reasoning_delta\" }>,\n ): ReasoningState {\n if (event.id !== undefined) {\n const existingKey = this.reasoningKeyById.get(event.id);\n if (existingKey !== undefined) {\n const existing = this.reasoningByKey.get(existingKey);\n if (existing !== undefined) {\n return existing;\n }\n }\n\n const key = this.createReasoningKey();\n const reasoning: ReasoningState = { id: event.id, text: \"\" };\n this.reasoningKeyById.set(event.id, key);\n this.reasoningByKey.set(key, reasoning);\n this.orderedParts.push({ type: \"reasoning\", key });\n return reasoning;\n }\n\n const lastPart = this.orderedParts.at(-1);\n if (lastPart?.type === \"reasoning\") {\n const lastReasoning = this.reasoningByKey.get(lastPart.key);\n if (lastReasoning !== undefined && lastReasoning.id === undefined) {\n return lastReasoning;\n }\n }\n\n const key = this.createReasoningKey();\n const reasoning: ReasoningState = { text: \"\" };\n this.reasoningByKey.set(key, reasoning);\n this.orderedParts.push({ type: \"reasoning\", key });\n return reasoning;\n }\n\n private toolCallStateForId(id: string): PartialToolCall {\n const existing = this.toolCalls.get(id);\n if (existing !== undefined) {\n return existing;\n }\n\n const toolCall: PartialToolCall = {\n id,\n name: \"\",\n argumentsText: \"\",\n argumentsSnapshotSeen: false,\n fullCallSeen: false,\n };\n this.toolCalls.set(id, toolCall);\n this.orderedParts.push({ type: \"tool_call\", key: id });\n return toolCall;\n }\n\n private withMessageIdFallback(\n response: CompletionResponse<RawResponse>,\n accumulatedResponse: CompletionResponse<RawResponse>,\n ): CompletionResponse<RawResponse> {\n if (response.messageId !== undefined || accumulatedResponse.messageId === undefined) {\n return response;\n }\n return { ...response, messageId: accumulatedResponse.messageId };\n }\n\n private withAccumulatedArtifacts(\n response: CompletionResponse<RawResponse>,\n accumulatedResponse: CompletionResponse<RawResponse>,\n ): CompletionResponse<RawResponse> {\n const withMessageId = this.withMessageIdFallback(response, accumulatedResponse);\n const sources = mergeSources(accumulatedResponse.sources, response.sources);\n const providerToolCalls = mergeProviderToolCalls(\n accumulatedResponse.providerToolCalls,\n response.providerToolCalls,\n );\n let accumulated: CompletionResponse<RawResponse> = { ...withMessageId };\n if (sources.length > 0) accumulated = { ...accumulated, sources };\n if (providerToolCalls.length > 0) {\n accumulated = { ...accumulated, providerToolCalls };\n }\n return accumulated;\n }\n\n private createTextKey(): string {\n this.nextTextKey += 1;\n return `text_${this.nextTextKey.toString()}`;\n }\n\n private createReasoningKey(): string {\n this.nextReasoningKey += 1;\n return `reasoning_${this.nextReasoningKey.toString()}`;\n }\n\n private appendReasoning(\n reasoning: ReasoningState,\n event: Extract<CompletionModelStreamEvent<RawResponse>, { type: \"reasoning_delta\" }>,\n ): void {\n const contentType = event.contentType ?? \"text\";\n if (contentType === \"text\" || contentType === \"summary\") {\n reasoning.text += event.delta;\n }\n\n if (event.contentType === undefined && event.signature === undefined) {\n return;\n }\n\n reasoning.details ??= [];\n const last = reasoning.details.at(-1);\n if (contentType === \"text\") {\n if (last?.type === \"text\") {\n let detail: ReasoningDetail = {\n ...last,\n text: `${last.text}${event.delta}`,\n };\n if (event.signature !== undefined) detail = { ...detail, signature: event.signature };\n reasoning.details[reasoning.details.length - 1] = detail;\n } else {\n reasoning.details.push(\n event.signature === undefined\n ? { type: \"text\", text: event.delta }\n : { type: \"text\", text: event.delta, signature: event.signature },\n );\n }\n return;\n }\n\n if (contentType === \"summary\") {\n if (last?.type === \"summary\") {\n reasoning.details[reasoning.details.length - 1] = {\n ...last,\n text: `${last.text}${event.delta}`,\n };\n } else {\n reasoning.details.push({ type: \"summary\", text: event.delta });\n }\n return;\n }\n\n if (contentType === \"encrypted\") {\n reasoning.details.push({ type: \"encrypted\", data: event.delta });\n return;\n }\n\n reasoning.details.push({ type: \"redacted\", data: event.delta });\n }\n}\n\nfunction sourceKey(source: CompletionSource): string {\n return `${source.url}\\u0000${source.startIndex ?? \"\"}\\u0000${source.endIndex ?? \"\"}`;\n}\n\nfunction mergeSources(\n accumulated: CompletionSource[] | undefined,\n final: CompletionSource[] | undefined,\n): CompletionSource[] {\n const sources = new Map<string, CompletionSource>();\n for (const source of [...(accumulated ?? []), ...(final ?? [])]) {\n sources.set(sourceKey(source), source);\n }\n return [...sources.values()];\n}\n\nfunction mergeProviderToolCalls(\n accumulated: ProviderToolCall[] | undefined,\n final: ProviderToolCall[] | undefined,\n): ProviderToolCall[] {\n const toolCalls = new Map<string, ProviderToolCall>();\n for (const toolCall of [...(accumulated ?? []), ...(final ?? [])]) {\n toolCalls.set(toolCall.id, toolCall);\n }\n return [...toolCalls.values()];\n}\n\nfunction reasoningContent(reasoning: ReasoningState): AssistantContentPart {\n const content =\n reasoning.details === undefined\n ? { type: \"reasoning\" as const, text: reasoning.text }\n : { type: \"reasoning\" as const, text: reasoning.text, details: reasoning.details };\n return reasoning.id === undefined ? content : { ...content, id: reasoning.id };\n}\n\nfunction toolCallContent(toolCall: PartialToolCall): ToolCallPart {\n const argumentsValue = parseToolArguments(toolCall.id, toolCall.argumentsText);\n let content: ToolCallPart = {\n type: \"tool-call\",\n toolCallId: toolCall.id,\n toolName: toolCall.name,\n input: argumentsValue,\n };\n if (toolCall.callId !== undefined) content = { ...content, callId: toolCall.callId };\n if (toolCall.signature !== undefined) content = { ...content, signature: toolCall.signature };\n return content;\n}\n\nfunction mergeFinalToolCall(\n accumulated: ToolCallPart,\n finalToolCall: ToolCallPart,\n usage: CompletionResponse[\"usage\"],\n): ToolCallPart {\n if (\n finalToolCall.toolCallId !== accumulated.toolCallId ||\n finalToolCall.toolName !== accumulated.toolName ||\n (accumulated.callId !== undefined && finalToolCall.callId !== accumulated.callId) ||\n (accumulated.signature !== undefined &&\n finalToolCall.signature !== undefined &&\n finalToolCall.signature !== accumulated.signature)\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: accumulated.toolCallId,\n usage,\n });\n }\n if (!isJsonValue(finalToolCall.input)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-arguments\",\n toolCallId: accumulated.toolCallId,\n usage,\n });\n }\n if (!jsonValuesEqual(accumulated.input, finalToolCall.input)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: accumulated.toolCallId,\n usage,\n });\n }\n let merged: ToolCallPart = {\n type: \"tool-call\",\n toolCallId: finalToolCall.toolCallId,\n toolName: finalToolCall.toolName,\n input: accumulated.input,\n };\n const callId = finalToolCall.callId ?? accumulated.callId;\n if (callId !== undefined) merged = { ...merged, callId };\n const signature = finalToolCall.signature ?? accumulated.signature;\n if (signature !== undefined) merged = { ...merged, signature };\n return merged;\n}\n\nfunction reasoningDeltaEvent(\n event: Extract<CompletionModelStreamEvent, { type: \"reasoning_delta\" }>,\n): AccumulatedStreamEvent {\n const mapped: AccumulatedStreamEvent = { type: \"reasoning_delta\", delta: event.delta };\n if (event.id !== undefined) mapped.id = event.id;\n if (event.contentType !== undefined) mapped.contentType = event.contentType;\n if (event.signature !== undefined) mapped.signature = event.signature;\n return mapped;\n}\n\nfunction parseToolArguments(toolCallId: string, text: string): JsonValue {\n let value: unknown;\n try {\n value = JSON.parse(text);\n } catch {\n throw new CompletionProviderOutputError({\n kind: \"malformed-tool-arguments\",\n toolCallId,\n });\n }\n if (!isJsonValue(value)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-arguments\",\n toolCallId,\n });\n }\n return value;\n}\n\nfunction jsonValuesEqual(left: JsonValue, right: JsonValue): boolean {\n if (left === right) {\n return true;\n }\n if (left === null || right === null || typeof left !== \"object\" || typeof right !== \"object\") {\n return false;\n }\n if (isJsonArray(left) || isJsonArray(right)) {\n if (!isJsonArray(left) || !isJsonArray(right) || left.length !== right.length) {\n return false;\n }\n return left.every((value, index) => {\n const rightValue = right[index];\n return rightValue !== undefined && jsonValuesEqual(value, rightValue);\n });\n }\n\n const leftKeys = Object.keys(left);\n const rightKeys = Object.keys(right);\n if (leftKeys.length !== rightKeys.length) {\n return false;\n }\n for (const key of leftKeys) {\n if (!Object.hasOwn(right, key)) {\n return false;\n }\n const leftValue = left[key];\n const rightValue = right[key];\n if (\n leftValue === undefined ||\n rightValue === undefined ||\n !jsonValuesEqual(leftValue, rightValue)\n ) {\n return false;\n }\n }\n return true;\n}\n\nfunction nonToolPartsMatchFinal(\n accumulated: readonly AssistantContentPart[],\n final: readonly AssistantContentPart[],\n): boolean {\n if (!isJsonValue(accumulated) || !isJsonValue(final)) return false;\n const unmatched = [...final];\n for (const part of accumulated) {\n let index = unmatched.findIndex((candidate) => jsonValuesEqual(part, candidate));\n if (index < 0 && part.type === \"reasoning\") {\n index = unmatched.findIndex(\n (candidate) => candidate.type === \"reasoning\" && reasoningMatchesFinal(part, candidate),\n );\n }\n if (index < 0) return false;\n unmatched.splice(index, 1);\n }\n // Responses may expose replayable reasoning only in the terminal snapshot.\n // It has no displayable delta, so it must not change text/tool validation.\n return unmatched.every(\n (part) =>\n part.type === \"reasoning\" &&\n part.text === \"\" &&\n (part.details === undefined ||\n part.details.every(\n (detail) =>\n detail.type === \"encrypted\" ||\n ((detail.type === \"text\" || detail.type === \"summary\") && detail.text === \"\"),\n )),\n );\n}\n\nfunction reasoningMatchesFinal(accumulated: ReasoningPart, final: ReasoningPart): boolean {\n // Only allow final-only encryption to enrich an otherwise identical part.\n // Already streamed encryption, summaries, IDs and signatures must still agree.\n if (accumulated.details?.some((detail) => detail.type === \"encrypted\")) return false;\n if (!final.details?.some((detail) => detail.type === \"encrypted\")) return false;\n const { details, ...base } = final;\n const streamedDetails = details.filter((detail) => detail.type !== \"encrypted\");\n const comparable = streamedDetails.length === 0 ? base : { ...base, details: streamedDetails };\n return (\n isJsonValue(accumulated) && isJsonValue(comparable) && jsonValuesEqual(accumulated, comparable)\n );\n}\n\nfunction isJsonArray(value: JsonValue): value is readonly JsonValue[] {\n return Array.isArray(value);\n}\n\nfunction providerOutputErrorWithUsage(\n error: CompletionProviderOutputError,\n usage: CompletionResponse[\"usage\"],\n): CompletionProviderOutputError {\n const shared: { toolCallId?: string; usage: CompletionResponse[\"usage\"] } = { usage };\n if (error.toolCallId !== undefined) shared.toolCallId = error.toolCallId;\n if (error.kind === \"truncated-tool-call\") {\n return new CompletionProviderOutputError({\n ...shared,\n kind: error.kind,\n finishReason: \"length\",\n });\n }\n if (error.kind === \"filtered-tool-call\") {\n return new CompletionProviderOutputError({\n ...shared,\n kind: error.kind,\n finishReason: \"content-filter\",\n });\n }\n if (error.finishReason === \"length\" || error.finishReason === \"content-filter\") {\n throw error;\n }\n return new CompletionProviderOutputError({\n ...shared,\n kind: error.kind,\n finishReason: error.finishReason,\n });\n}\n\nfunction isNonblankString(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\nfunction isReasoningContentType(value: unknown): boolean {\n return value === \"text\" || value === \"summary\" || value === \"encrypted\" || value === \"redacted\";\n}\n"],"mappings":";;;;;;;;;;;AA0CO,IAAM,8BAAN,MAAyD;AAAA,EACtD,eAAiC,CAAC;AAAA,EAClC,YAAY,oBAAI,IAAoB;AAAA,EACpC,iBAAiB,oBAAI,IAA4B;AAAA,EACjD,mBAAmB,oBAAI,IAAoB;AAAA,EAC3C,YAAY,oBAAI,IAA6B;AAAA,EAC7C,UAAU,oBAAI,IAA8B;AAAA,EAC5C,oBAAoB,oBAAI,IAA8B;AAAA,EACtD;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,mBAAmB;AAAA,EAE3B,OAAO,OAAoF;AACzF,QAAI,MAAM,SAAS,cAAc;AAC/B,UAAI,OAAO,MAAM,UAAU,UAAU;AACnC,cAAM,IAAI,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AAAA,MAC1E;AACA,WAAK,WAAW,MAAM,KAAK;AAC3B,aAAO,EAAE,MAAM,cAAc,OAAO,MAAM,MAAM;AAAA,IAClD;AAEA,QAAI,MAAM,SAAS,mBAAmB;AACpC,UACE,OAAO,MAAM,UAAU,YACtB,MAAM,OAA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,KAAK;AAC5B;AAEA,SAAS,6BACP,OACA,OAC+B;AAC/B,QAAM,SAAsE,EAAE,MAAM;AACpF,MAAI,MAAM,eAAe,OAAW,QAAO,aAAa,MAAM;AAC9D,MAAI,MAAM,SAAS,uBAAuB;AACxC,WAAO,IAAI,8BAA8B;AAAA,MACvC,GAAG;AAAA,MACH,MAAM,MAAM;AAAA,MACZ,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AACA,MAAI,MAAM,SAAS,sBAAsB;AACvC,WAAO,IAAI,8BAA8B;AAAA,MACvC,GAAG;AAAA,MACH,MAAM,MAAM;AAAA,MACZ,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AACA,MAAI,MAAM,iBAAiB,YAAY,MAAM,iBAAiB,kBAAkB;AAC9E,UAAM;AAAA,EACR;AACA,SAAO,IAAI,8BAA8B;AAAA,IACvC,GAAG;AAAA,IACH,MAAM,MAAM;AAAA,IACZ,cAAc,MAAM;AAAA,EACtB,CAAC;AACH;AAEA,SAAS,iBAAiB,OAAiC;AACzD,SAAO,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,SAAS;AAC5D;AAEA,SAAS,uBAAuB,OAAyB;AACvD,SAAO,UAAU,UAAU,UAAU,aAAa,UAAU,eAAe,UAAU;AACvF;","names":["key","reasoning"]}
1
+ {"version":3,"sources":["../src/completion/stream-accumulator.ts"],"sourcesContent":["import { isJsonValue } from \"./json\";\nimport { CompletionProviderOutputError } from \"./provider-output-error\";\nimport type {\n AssistantContentPart,\n CompletionModelStreamEvent,\n CompletionResponse,\n CompletionSource,\n CompletionStreamPart,\n JsonValue,\n ProviderToolCall,\n ReasoningDetail,\n ReasoningPart,\n ToolCallPart,\n} from \"./types\";\nimport { Usage } from \"./types\";\n\ntype AccumulatedStreamEvent = Exclude<\n CompletionStreamPart,\n { type: \"tool_call_delta\" } | { type: \"message_id\" }\n>;\n\ntype ReasoningState = {\n id?: string;\n text: string;\n details?: ReasoningDetail[];\n};\n\ntype PartialToolCall = {\n id: string;\n callId?: string;\n name: string;\n argumentsText: string;\n argumentsSnapshotSeen: boolean;\n signature?: string;\n fullCallSeen: boolean;\n};\n\ntype OrderedPartRef =\n | { type: \"text\"; key: string }\n | { type: \"reasoning\"; key: string }\n | { type: \"tool_call\"; key: string };\n\nexport class CompletionStreamAccumulator<RawResponse = unknown> {\n private orderedParts: OrderedPartRef[] = [];\n private textParts = new Map<string, string>();\n private reasoningByKey = new Map<string, ReasoningState>();\n private reasoningKeyById = new Map<string, string>();\n private toolCalls = new Map<string, PartialToolCall>();\n private sources = new Map<string, CompletionSource>();\n private providerToolCalls = new Map<string, ProviderToolCall>();\n private finalResponse: CompletionResponse<RawResponse> | undefined;\n private messageId: string | undefined;\n private nextTextKey = 0;\n private nextReasoningKey = 0;\n\n accept(event: CompletionModelStreamEvent<RawResponse>): AccumulatedStreamEvent | undefined {\n if (event.type === \"text_delta\") {\n if (typeof event.delta !== \"string\") {\n throw new CompletionProviderOutputError({ kind: \"invalid-stream-event\" });\n }\n this.appendText(event.delta);\n return { type: \"text_delta\", delta: event.delta };\n }\n\n if (event.type === \"reasoning_delta\") {\n if (\n typeof event.delta !== \"string\" ||\n (event.id !== undefined && !isNonblankString(event.id)) ||\n (event.signature !== undefined && !isNonblankString(event.signature)) ||\n (event.contentType !== undefined && !isReasoningContentType(event.contentType))\n ) {\n throw new CompletionProviderOutputError({ kind: \"invalid-stream-event\" });\n }\n const reasoning = this.reasoningStateForEvent(event);\n this.appendReasoning(reasoning, event);\n return reasoningDeltaEvent(event);\n }\n\n if (event.type === \"tool_call_delta\") {\n if (!isNonblankString(event.id)) {\n throw new CompletionProviderOutputError({ kind: \"invalid-tool-call\" });\n }\n const toolCall = this.toolCallStateForId(event.id);\n if (toolCall.fullCallSeen) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n if (event.callId !== undefined) {\n if (!isNonblankString(event.callId)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n if (toolCall.callId !== undefined && toolCall.callId !== event.callId) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n toolCall.callId = event.callId;\n }\n if (event.name !== undefined) {\n if (!isNonblankString(event.name)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n if (toolCall.name.length > 0 && toolCall.name !== event.name) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n toolCall.name = event.name;\n }\n if (event.signature !== undefined) {\n if (\n !isNonblankString(event.signature) ||\n (toolCall.signature !== undefined && toolCall.signature !== event.signature)\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n toolCall.signature = event.signature;\n }\n if (\n event.argumentsMode !== undefined &&\n event.argumentsMode !== \"append\" &&\n event.argumentsMode !== \"replace\"\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-stream-event\",\n toolCallId: toolCall.id,\n });\n }\n if (event.argumentsMode !== undefined && event.argumentsDelta === undefined) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-stream-event\",\n toolCallId: toolCall.id,\n });\n }\n if (event.argumentsDelta !== undefined) {\n if (typeof event.argumentsDelta !== \"string\") {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-arguments\",\n toolCallId: toolCall.id,\n });\n }\n if (event.argumentsMode === \"replace\") {\n if (\n toolCall.argumentsText.length > 0 &&\n toolCall.argumentsText !== event.argumentsDelta &&\n (toolCall.argumentsSnapshotSeen ||\n !event.argumentsDelta.startsWith(toolCall.argumentsText))\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n toolCall.argumentsText = event.argumentsDelta;\n toolCall.argumentsSnapshotSeen = true;\n } else {\n if (toolCall.argumentsSnapshotSeen) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.id,\n });\n }\n toolCall.argumentsText += event.argumentsDelta;\n }\n }\n return undefined;\n }\n\n if (event.type === \"tool_call\") {\n this.upsertToolCall(event.toolCall);\n return { type: \"tool_call\", toolCall: event.toolCall };\n }\n\n if (event.type === \"source\") {\n this.sources.set(sourceKey(event.source), event.source);\n return { type: \"source\", source: event.source };\n }\n\n if (event.type === \"provider_tool_call\") {\n this.providerToolCalls.set(event.toolCall.id, event.toolCall);\n return { type: \"provider_tool_call\", toolCall: event.toolCall };\n }\n\n if (event.type === \"message_id\") {\n if (!isNonblankString(event.id)) {\n throw new CompletionProviderOutputError({ kind: \"invalid-stream-event\" });\n }\n this.messageId = event.id;\n return undefined;\n }\n\n if (event.type === \"final\") {\n this.finalResponse = event.response;\n return undefined;\n }\n\n return undefined;\n }\n\n response(): CompletionResponse<RawResponse> {\n this.assertAccumulatedFinishReason();\n let accumulatedResponse: CompletionResponse<RawResponse>;\n try {\n accumulatedResponse = this.buildAccumulatedResponse();\n } catch (error) {\n if (error instanceof CompletionProviderOutputError && this.finalResponse !== undefined) {\n throw providerOutputErrorWithUsage(error, this.finalResponse.usage);\n }\n throw error;\n }\n if (this.finalResponse !== undefined) {\n if (accumulatedResponse.choice.length === 0) {\n return this.withAccumulatedArtifacts(this.finalResponse, accumulatedResponse);\n }\n return this.mergeFinalResponse(accumulatedResponse, this.finalResponse);\n }\n\n return accumulatedResponse;\n }\n\n private assertAccumulatedFinishReason(): void {\n if (this.finalResponse === undefined) {\n if (this.toolCalls.size === 0) {\n throw new CompletionProviderOutputError({ kind: \"incomplete-stream\" });\n }\n const toolCallId = this.toolCalls.size === 1 ? this.toolCalls.keys().next().value : undefined;\n throw new CompletionProviderOutputError({\n kind: \"incomplete-tool-call\",\n toolCallId,\n });\n }\n if (this.toolCalls.size === 0) return;\n const finishReason = this.finalResponse.finishReason;\n if (finishReason === \"length\") {\n throw new CompletionProviderOutputError({\n kind: \"truncated-tool-call\",\n finishReason,\n usage: this.finalResponse.usage,\n });\n }\n if (finishReason === \"content-filter\") {\n throw new CompletionProviderOutputError({\n kind: \"filtered-tool-call\",\n finishReason,\n usage: this.finalResponse.usage,\n });\n }\n if (finishReason !== undefined && finishReason !== \"stop\" && finishReason !== \"tool-calls\") {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n usage: this.finalResponse.usage,\n });\n }\n }\n\n private buildAccumulatedResponse(): CompletionResponse<RawResponse> {\n const choice: AssistantContentPart[] = [];\n\n for (const part of this.orderedParts) {\n if (part.type === \"text\") {\n const text = this.textParts.get(part.key) ?? \"\";\n if (text.length > 0) {\n choice.push({ type: \"text\", text });\n }\n continue;\n }\n\n if (part.type === \"reasoning\") {\n const reasoning = this.reasoningByKey.get(part.key);\n if (reasoning !== undefined) {\n choice.push(reasoningContent(reasoning));\n }\n continue;\n }\n\n const toolCall = this.toolCalls.get(part.key);\n if (toolCall !== undefined) {\n choice.push(toolCallContent(toolCall));\n }\n }\n\n const response: CompletionResponse<RawResponse> = {\n choice,\n usage: Usage.empty(),\n rawResponse: undefined as RawResponse,\n };\n if (this.messageId !== undefined) {\n response.messageId = this.messageId;\n }\n const sources = [...this.sources.values()];\n if (sources.length > 0) {\n response.sources = sources;\n }\n const providerToolCalls = [...this.providerToolCalls.values()];\n if (providerToolCalls.length > 0) {\n response.providerToolCalls = providerToolCalls;\n }\n return response;\n }\n\n private upsertToolCall(toolCall: ToolCallPart): void {\n if (\n !isNonblankString(toolCall.toolCallId) ||\n !isNonblankString(toolCall.toolName) ||\n (toolCall.callId !== undefined && !isNonblankString(toolCall.callId)) ||\n (toolCall.signature !== undefined && !isNonblankString(toolCall.signature))\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: isNonblankString(toolCall.toolCallId) ? toolCall.toolCallId : undefined,\n });\n }\n if (!isJsonValue(toolCall.input)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-arguments\",\n toolCallId: toolCall.toolCallId,\n });\n }\n const existing = this.toolCalls.get(toolCall.toolCallId);\n if (existing !== undefined) {\n if (existing.fullCallSeen) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.toolCallId,\n });\n }\n if (\n (existing.name.length > 0 && existing.name !== toolCall.toolName) ||\n (existing.callId !== undefined && existing.callId !== toolCall.callId) ||\n (existing.signature !== undefined &&\n toolCall.signature !== undefined &&\n existing.signature !== toolCall.signature)\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.toolCallId,\n });\n }\n if (existing.argumentsText.length > 0) {\n const accumulatedInput = parseToolArguments(existing.id, existing.argumentsText);\n if (!jsonValuesEqual(accumulatedInput, toolCall.input)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: toolCall.toolCallId,\n });\n }\n }\n }\n if (!this.toolCalls.has(toolCall.toolCallId)) {\n this.orderedParts.push({ type: \"tool_call\", key: toolCall.toolCallId });\n }\n const partial: PartialToolCall = {\n id: toolCall.toolCallId,\n name: toolCall.toolName,\n argumentsText: JSON.stringify(toolCall.input),\n argumentsSnapshotSeen: true,\n fullCallSeen: true,\n };\n if (toolCall.callId !== undefined) {\n partial.callId = toolCall.callId;\n }\n const signature = toolCall.signature ?? existing?.signature;\n if (signature !== undefined) {\n partial.signature = signature;\n }\n this.toolCalls.set(toolCall.toolCallId, partial);\n }\n\n private mergeFinalResponse(\n accumulatedResponse: CompletionResponse<RawResponse>,\n finalResponse: CompletionResponse<RawResponse>,\n ): CompletionResponse<RawResponse> {\n if (finalResponse.choice.length === 0) {\n const mergedResponse: CompletionResponse<RawResponse> = {\n ...finalResponse,\n choice: accumulatedResponse.choice,\n };\n return this.withAccumulatedArtifacts(mergedResponse, accumulatedResponse);\n }\n\n const accumulatedNonTool = accumulatedResponse.choice.filter(\n (content) => content.type !== \"tool-call\",\n );\n const finalNonTool = finalResponse.choice.filter((content) => content.type !== \"tool-call\");\n if (\n accumulatedNonTool.length > 0 &&\n !nonToolPartsMatchFinal(accumulatedNonTool, finalNonTool)\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-stream-event\",\n usage: finalResponse.usage,\n });\n }\n\n const accumulatedById = new Map<string, ToolCallPart>();\n const accumulatedByCallId = new Map<string, ToolCallPart>();\n for (const content of accumulatedResponse.choice) {\n if (content.type !== \"tool-call\") continue;\n accumulatedById.set(content.toolCallId, content);\n if (content.callId !== undefined) accumulatedByCallId.set(content.callId, content);\n }\n\n const matchedAccumulatedToolCalls = new Set<ToolCallPart>();\n const choice = finalResponse.choice.map((content) => {\n if (content.type !== \"tool-call\") return content;\n const accumulated = accumulatedById.get(content.toolCallId);\n if (accumulated === undefined) {\n const changedIdentity =\n content.callId === undefined ? undefined : accumulatedByCallId.get(content.callId);\n if (changedIdentity !== undefined) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: changedIdentity.toolCallId,\n usage: finalResponse.usage,\n });\n }\n return content;\n }\n matchedAccumulatedToolCalls.add(accumulated);\n return mergeFinalToolCall(accumulated, content, finalResponse.usage);\n });\n\n for (const accumulated of accumulatedById.values()) {\n if (!matchedAccumulatedToolCalls.has(accumulated)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: accumulated.toolCallId,\n usage: finalResponse.usage,\n });\n }\n }\n\n return this.withAccumulatedArtifacts({ ...finalResponse, choice }, accumulatedResponse);\n }\n\n private appendText(delta: string): void {\n const lastPart = this.orderedParts.at(-1);\n const key = lastPart?.type === \"text\" ? lastPart.key : this.createTextKey();\n if (lastPart?.type !== \"text\") {\n this.orderedParts.push({ type: \"text\", key });\n }\n this.textParts.set(key, `${this.textParts.get(key) ?? \"\"}${delta}`);\n }\n\n private reasoningStateForEvent(\n event: Extract<CompletionModelStreamEvent<RawResponse>, { type: \"reasoning_delta\" }>,\n ): ReasoningState {\n if (event.id !== undefined) {\n const existingKey = this.reasoningKeyById.get(event.id);\n if (existingKey !== undefined) {\n const existing = this.reasoningByKey.get(existingKey);\n if (existing !== undefined) {\n return existing;\n }\n }\n\n const key = this.createReasoningKey();\n const reasoning: ReasoningState = { id: event.id, text: \"\" };\n this.reasoningKeyById.set(event.id, key);\n this.reasoningByKey.set(key, reasoning);\n this.orderedParts.push({ type: \"reasoning\", key });\n return reasoning;\n }\n\n const lastPart = this.orderedParts.at(-1);\n if (lastPart?.type === \"reasoning\") {\n const lastReasoning = this.reasoningByKey.get(lastPart.key);\n if (lastReasoning !== undefined && lastReasoning.id === undefined) {\n return lastReasoning;\n }\n }\n\n const key = this.createReasoningKey();\n const reasoning: ReasoningState = { text: \"\" };\n this.reasoningByKey.set(key, reasoning);\n this.orderedParts.push({ type: \"reasoning\", key });\n return reasoning;\n }\n\n private toolCallStateForId(id: string): PartialToolCall {\n const existing = this.toolCalls.get(id);\n if (existing !== undefined) {\n return existing;\n }\n\n const toolCall: PartialToolCall = {\n id,\n name: \"\",\n argumentsText: \"\",\n argumentsSnapshotSeen: false,\n fullCallSeen: false,\n };\n this.toolCalls.set(id, toolCall);\n this.orderedParts.push({ type: \"tool_call\", key: id });\n return toolCall;\n }\n\n private withMessageIdFallback(\n response: CompletionResponse<RawResponse>,\n accumulatedResponse: CompletionResponse<RawResponse>,\n ): CompletionResponse<RawResponse> {\n if (response.messageId !== undefined || accumulatedResponse.messageId === undefined) {\n return response;\n }\n return { ...response, messageId: accumulatedResponse.messageId };\n }\n\n private withAccumulatedArtifacts(\n response: CompletionResponse<RawResponse>,\n accumulatedResponse: CompletionResponse<RawResponse>,\n ): CompletionResponse<RawResponse> {\n const withMessageId = this.withMessageIdFallback(response, accumulatedResponse);\n const sources = mergeSources(accumulatedResponse.sources, response.sources);\n const providerToolCalls = mergeProviderToolCalls(\n accumulatedResponse.providerToolCalls,\n response.providerToolCalls,\n );\n let accumulated: CompletionResponse<RawResponse> = { ...withMessageId };\n if (sources.length > 0) accumulated = { ...accumulated, sources };\n if (providerToolCalls.length > 0) {\n accumulated = { ...accumulated, providerToolCalls };\n }\n return accumulated;\n }\n\n private createTextKey(): string {\n this.nextTextKey += 1;\n return `text_${this.nextTextKey.toString()}`;\n }\n\n private createReasoningKey(): string {\n this.nextReasoningKey += 1;\n return `reasoning_${this.nextReasoningKey.toString()}`;\n }\n\n private appendReasoning(\n reasoning: ReasoningState,\n event: Extract<CompletionModelStreamEvent<RawResponse>, { type: \"reasoning_delta\" }>,\n ): void {\n const contentType = event.contentType ?? \"text\";\n if (contentType === \"text\" || contentType === \"summary\") {\n reasoning.text += event.delta;\n }\n\n if (event.contentType === undefined && event.signature === undefined) {\n return;\n }\n\n reasoning.details ??= [];\n const last = reasoning.details.at(-1);\n if (contentType === \"text\") {\n if (last?.type === \"text\") {\n let detail: ReasoningDetail = {\n ...last,\n text: `${last.text}${event.delta}`,\n };\n if (event.signature !== undefined) detail = { ...detail, signature: event.signature };\n reasoning.details[reasoning.details.length - 1] = detail;\n } else {\n reasoning.details.push(\n event.signature === undefined\n ? { type: \"text\", text: event.delta }\n : { type: \"text\", text: event.delta, signature: event.signature },\n );\n }\n return;\n }\n\n if (contentType === \"summary\") {\n if (last?.type === \"summary\") {\n reasoning.details[reasoning.details.length - 1] = {\n ...last,\n text: `${last.text}${event.delta}`,\n };\n } else {\n reasoning.details.push({ type: \"summary\", text: event.delta });\n }\n return;\n }\n\n if (contentType === \"encrypted\") {\n reasoning.details.push({ type: \"encrypted\", data: event.delta });\n return;\n }\n\n reasoning.details.push({ type: \"redacted\", data: event.delta });\n }\n}\n\nfunction sourceKey(source: CompletionSource): string {\n return `${source.url}\\u0000${source.startIndex ?? \"\"}\\u0000${source.endIndex ?? \"\"}`;\n}\n\nfunction mergeSources(\n accumulated: CompletionSource[] | undefined,\n final: CompletionSource[] | undefined,\n): CompletionSource[] {\n const sources = new Map<string, CompletionSource>();\n for (const source of [...(accumulated ?? []), ...(final ?? [])]) {\n sources.set(sourceKey(source), source);\n }\n return [...sources.values()];\n}\n\nfunction mergeProviderToolCalls(\n accumulated: ProviderToolCall[] | undefined,\n final: ProviderToolCall[] | undefined,\n): ProviderToolCall[] {\n const toolCalls = new Map<string, ProviderToolCall>();\n for (const toolCall of [...(accumulated ?? []), ...(final ?? [])]) {\n toolCalls.set(toolCall.id, toolCall);\n }\n return [...toolCalls.values()];\n}\n\nfunction reasoningContent(reasoning: ReasoningState): AssistantContentPart {\n const content =\n reasoning.details === undefined\n ? { type: \"reasoning\" as const, text: reasoning.text }\n : { type: \"reasoning\" as const, text: reasoning.text, details: reasoning.details };\n return reasoning.id === undefined ? content : { ...content, id: reasoning.id };\n}\n\nfunction toolCallContent(toolCall: PartialToolCall): ToolCallPart {\n const argumentsValue = parseToolArguments(toolCall.id, toolCall.argumentsText);\n let content: ToolCallPart = {\n type: \"tool-call\",\n toolCallId: toolCall.id,\n toolName: toolCall.name,\n input: argumentsValue,\n };\n if (toolCall.callId !== undefined) content = { ...content, callId: toolCall.callId };\n if (toolCall.signature !== undefined) content = { ...content, signature: toolCall.signature };\n return content;\n}\n\nfunction mergeFinalToolCall(\n accumulated: ToolCallPart,\n finalToolCall: ToolCallPart,\n usage: CompletionResponse[\"usage\"],\n): ToolCallPart {\n if (\n finalToolCall.toolCallId !== accumulated.toolCallId ||\n finalToolCall.toolName !== accumulated.toolName ||\n (accumulated.callId !== undefined && finalToolCall.callId !== accumulated.callId) ||\n (accumulated.signature !== undefined &&\n finalToolCall.signature !== undefined &&\n finalToolCall.signature !== accumulated.signature)\n ) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: accumulated.toolCallId,\n usage,\n });\n }\n if (!isJsonValue(finalToolCall.input)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-arguments\",\n toolCallId: accumulated.toolCallId,\n usage,\n });\n }\n if (!jsonValuesEqual(accumulated.input, finalToolCall.input)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-call\",\n toolCallId: accumulated.toolCallId,\n usage,\n });\n }\n let merged: ToolCallPart = {\n type: \"tool-call\",\n toolCallId: finalToolCall.toolCallId,\n toolName: finalToolCall.toolName,\n input: accumulated.input,\n };\n const callId = finalToolCall.callId ?? accumulated.callId;\n if (callId !== undefined) merged = { ...merged, callId };\n const signature = finalToolCall.signature ?? accumulated.signature;\n if (signature !== undefined) merged = { ...merged, signature };\n return merged;\n}\n\nfunction reasoningDeltaEvent(\n event: Extract<CompletionModelStreamEvent, { type: \"reasoning_delta\" }>,\n): AccumulatedStreamEvent {\n const mapped: AccumulatedStreamEvent = { type: \"reasoning_delta\", delta: event.delta };\n if (event.id !== undefined) mapped.id = event.id;\n if (event.contentType !== undefined) mapped.contentType = event.contentType;\n if (event.signature !== undefined) mapped.signature = event.signature;\n return mapped;\n}\n\nfunction parseToolArguments(toolCallId: string, text: string): JsonValue {\n // Some OpenAI-compatible backends send \"\" for zero-argument tool calls.\n if (text.trim() === \"\") return {};\n let value: unknown;\n try {\n value = JSON.parse(text);\n } catch {\n throw new CompletionProviderOutputError({\n kind: \"malformed-tool-arguments\",\n toolCallId,\n });\n }\n if (!isJsonValue(value)) {\n throw new CompletionProviderOutputError({\n kind: \"invalid-tool-arguments\",\n toolCallId,\n });\n }\n return value;\n}\n\nfunction jsonValuesEqual(left: JsonValue, right: JsonValue): boolean {\n if (left === right) {\n return true;\n }\n if (left === null || right === null || typeof left !== \"object\" || typeof right !== \"object\") {\n return false;\n }\n if (isJsonArray(left) || isJsonArray(right)) {\n if (!isJsonArray(left) || !isJsonArray(right) || left.length !== right.length) {\n return false;\n }\n return left.every((value, index) => {\n const rightValue = right[index];\n return rightValue !== undefined && jsonValuesEqual(value, rightValue);\n });\n }\n\n const leftKeys = Object.keys(left);\n const rightKeys = Object.keys(right);\n if (leftKeys.length !== rightKeys.length) {\n return false;\n }\n for (const key of leftKeys) {\n if (!Object.hasOwn(right, key)) {\n return false;\n }\n const leftValue = left[key];\n const rightValue = right[key];\n if (\n leftValue === undefined ||\n rightValue === undefined ||\n !jsonValuesEqual(leftValue, rightValue)\n ) {\n return false;\n }\n }\n return true;\n}\n\nfunction nonToolPartsMatchFinal(\n accumulated: readonly AssistantContentPart[],\n final: readonly AssistantContentPart[],\n): boolean {\n if (!isJsonValue(accumulated) || !isJsonValue(final)) return false;\n const unmatched = [...final];\n for (const part of accumulated) {\n let index = unmatched.findIndex((candidate) => jsonValuesEqual(part, candidate));\n if (index < 0 && part.type === \"reasoning\") {\n index = unmatched.findIndex(\n (candidate) => candidate.type === \"reasoning\" && reasoningMatchesFinal(part, candidate),\n );\n }\n if (index < 0) return false;\n unmatched.splice(index, 1);\n }\n // Responses may expose replayable reasoning only in the terminal snapshot.\n // It has no displayable delta, so it must not change text/tool validation.\n return unmatched.every(\n (part) =>\n part.type === \"reasoning\" &&\n part.text === \"\" &&\n (part.details === undefined ||\n part.details.every(\n (detail) =>\n detail.type === \"encrypted\" ||\n ((detail.type === \"text\" || detail.type === \"summary\") && detail.text === \"\"),\n )),\n );\n}\n\nfunction reasoningMatchesFinal(accumulated: ReasoningPart, final: ReasoningPart): boolean {\n // Only allow final-only encryption to enrich an otherwise identical part.\n // Already streamed encryption, summaries, IDs and signatures must still agree.\n if (accumulated.details?.some((detail) => detail.type === \"encrypted\")) return false;\n if (!final.details?.some((detail) => detail.type === \"encrypted\")) return false;\n const { details, ...base } = final;\n const streamedDetails = details.filter((detail) => detail.type !== \"encrypted\");\n const comparable = streamedDetails.length === 0 ? base : { ...base, details: streamedDetails };\n return (\n isJsonValue(accumulated) && isJsonValue(comparable) && jsonValuesEqual(accumulated, comparable)\n );\n}\n\nfunction isJsonArray(value: JsonValue): value is readonly JsonValue[] {\n return Array.isArray(value);\n}\n\nfunction providerOutputErrorWithUsage(\n error: CompletionProviderOutputError,\n usage: CompletionResponse[\"usage\"],\n): CompletionProviderOutputError {\n const shared: { toolCallId?: string; usage: CompletionResponse[\"usage\"] } = { usage };\n if (error.toolCallId !== undefined) shared.toolCallId = error.toolCallId;\n if (error.kind === \"truncated-tool-call\") {\n return new CompletionProviderOutputError({\n ...shared,\n kind: error.kind,\n finishReason: \"length\",\n });\n }\n if (error.kind === \"filtered-tool-call\") {\n return new CompletionProviderOutputError({\n ...shared,\n kind: error.kind,\n finishReason: \"content-filter\",\n });\n }\n if (error.finishReason === \"length\" || error.finishReason === \"content-filter\") {\n throw error;\n }\n return new CompletionProviderOutputError({\n ...shared,\n kind: error.kind,\n finishReason: error.finishReason,\n });\n}\n\nfunction isNonblankString(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\nfunction isReasoningContentType(value: unknown): boolean {\n return value === \"text\" || value === \"summary\" || value === \"encrypted\" || value === \"redacted\";\n}\n"],"mappings":";;;;;;;;;;;AA0CO,IAAM,8BAAN,MAAyD;AAAA,EACtD,eAAiC,CAAC;AAAA,EAClC,YAAY,oBAAI,IAAoB;AAAA,EACpC,iBAAiB,oBAAI,IAA4B;AAAA,EACjD,mBAAmB,oBAAI,IAAoB;AAAA,EAC3C,YAAY,oBAAI,IAA6B;AAAA,EAC7C,UAAU,oBAAI,IAA8B;AAAA,EAC5C,oBAAoB,oBAAI,IAA8B;AAAA,EACtD;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,mBAAmB;AAAA,EAE3B,OAAO,OAAoF;AACzF,QAAI,MAAM,SAAS,cAAc;AAC/B,UAAI,OAAO,MAAM,UAAU,UAAU;AACnC,cAAM,IAAI,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AAAA,MAC1E;AACA,WAAK,WAAW,MAAM,KAAK;AAC3B,aAAO,EAAE,MAAM,cAAc,OAAO,MAAM,MAAM;AAAA,IAClD;AAEA,QAAI,MAAM,SAAS,mBAAmB;AACpC,UACE,OAAO,MAAM,UAAU,YACtB,MAAM,OAAO,UAAa,CAAC,iBAAiB,MAAM,EAAE,KACpD,MAAM,cAAc,UAAa,CAAC,iBAAiB,MAAM,SAAS,KAClE,MAAM,gBAAgB,UAAa,CAAC,uBAAuB,MAAM,WAAW,GAC7E;AACA,cAAM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,QAAO,aAAa,MAAM;AAC9D,MAAI,MAAM,SAAS,uBAAuB;AACxC,WAAO,IAAI,8BAA8B;AAAA,MACvC,GAAG;AAAA,MACH,MAAM,MAAM;AAAA,MACZ,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AACA,MAAI,MAAM,SAAS,sBAAsB;AACvC,WAAO,IAAI,8BAA8B;AAAA,MACvC,GAAG;AAAA,MACH,MAAM,MAAM;AAAA,MACZ,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AACA,MAAI,MAAM,iBAAiB,YAAY,MAAM,iBAAiB,kBAAkB;AAC9E,UAAM;AAAA,EACR;AACA,SAAO,IAAI,8BAA8B;AAAA,IACvC,GAAG;AAAA,IACH,MAAM,MAAM;AAAA,IACZ,cAAc,MAAM;AAAA,EACtB,CAAC;AACH;AAEA,SAAS,iBAAiB,OAAiC;AACzD,SAAO,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,SAAS;AAC5D;AAEA,SAAS,uBAAuB,OAAyB;AACvD,SAAO,UAAU,UAAU,UAAU,aAAa,UAAU,eAAe,UAAU;AACvF;","names":["key","reasoning"]}
@@ -321,20 +321,23 @@ function redactJsonResult(result, options) {
321
321
  };
322
322
  }
323
323
  function redactOutcome(outcome, options, caseId, metricName) {
324
- return {
325
- ...outcome,
326
- ...outcome.score === void 0 ? {} : { score: redact(outcome.score, options, { kind: "score", caseId, metricName }) },
327
- ...outcome.comment === void 0 ? {} : { comment: redact(outcome.comment, options, { kind: "comment", caseId, metricName }) },
328
- ...!("reason" in outcome) || outcome.reason === void 0 ? {} : { reason: redact(outcome.reason, options, { kind: "comment", caseId, metricName }) },
329
- ...outcome.metadata === void 0 ? {} : {
330
- metadata: redact(outcome.metadata, options, {
331
- kind: "metadata",
332
- caseId,
333
- metricName
334
- })
335
- },
336
- ...!("error" in outcome) || outcome.error === void 0 ? {} : { error: redact(outcome.error, options, { kind: "error", caseId, metricName }) }
337
- };
324
+ const redacted = { ...outcome };
325
+ if (outcome.score !== void 0) {
326
+ redacted.score = redact(outcome.score, options, { kind: "score", caseId, metricName });
327
+ }
328
+ if (outcome.comment !== void 0) {
329
+ redacted.comment = redact(outcome.comment, options, { kind: "comment", caseId, metricName });
330
+ }
331
+ if ("reason" in outcome && outcome.reason !== void 0) {
332
+ redacted.reason = redact(outcome.reason, options, { kind: "comment", caseId, metricName });
333
+ }
334
+ if (outcome.metadata !== void 0) {
335
+ redacted.metadata = redact(outcome.metadata, options, { kind: "metadata", caseId, metricName });
336
+ }
337
+ if ("error" in outcome && outcome.error !== void 0) {
338
+ redacted.error = redact(outcome.error, options, { kind: "error", caseId, metricName });
339
+ }
340
+ return redacted;
338
341
  }
339
342
  function validatePrintOptions(options) {
340
343
  if (options.maxValueLength !== void 0 && (!Number.isSafeInteger(options.maxValueLength) || options.maxValueLength < 1)) {
@@ -352,4 +355,4 @@ export {
352
355
  assertEvalOutcomes,
353
356
  runEvalCli
354
357
  };
355
- //# sourceMappingURL=chunk-KL652GO5.js.map
358
+ //# sourceMappingURL=chunk-3XUUNNCS.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/evals/cli.ts"],"sourcesContent":["import { runEvalSuite } from \"./runner\";\nimport type {\n EvalMetric,\n EvalOutcomeStatus,\n EvalSuiteResult,\n EvalTotals,\n RunEvalSuiteOptions,\n} from \"./types\";\n\nexport type EvalOutputFormat = \"pretty\" | \"json\" | \"quiet\";\n\nexport type EvalExpectedTotals = Partial<EvalTotals> & {\n metrics?: Partial<EvalTotals> | undefined;\n cases?: Partial<EvalTotals> | undefined;\n};\n\nexport type EvalExpectedOutcomes = Record<string, Record<string, EvalOutcomeStatus>>;\n\nexport type EvalExpectations = {\n totals?: EvalExpectedTotals | undefined;\n outcomes?: EvalExpectedOutcomes | undefined;\n};\n\nexport type EvalOutputWriters = {\n stdout?(text: string): void;\n stderr?(text: string): void;\n};\n\nexport type EvalRedactionContext = {\n kind:\n | \"input\"\n | \"expected\"\n | \"context\"\n | \"retrievalContext\"\n | \"output\"\n | \"score\"\n | \"comment\"\n | \"metadata\"\n | \"error\";\n caseId?: string | undefined;\n metricName?: string | undefined;\n};\n\nexport type EvalRedactor = (value: unknown, context: EvalRedactionContext) => unknown;\n\nexport type PrintEvalResultOptions = {\n format?: EvalOutputFormat | undefined;\n output?: EvalOutputWriters | undefined;\n maxValueLength?: number | undefined;\n redact?: EvalRedactor | undefined;\n};\n\ntype EvalSuiteShape = {\n cases: readonly { id: string }[];\n metrics: readonly { name: string }[];\n};\n\nexport type EvalExpectedOutcomesFor<Suite extends EvalSuiteShape> = Partial<\n Record<\n Suite[\"cases\"][number][\"id\"],\n Partial<Record<Suite[\"metrics\"][number][\"name\"], EvalOutcomeStatus>>\n >\n>;\n\nexport type EvalExpectationsFor<Suite extends EvalSuiteShape> = Omit<\n EvalExpectations,\n \"outcomes\"\n> & {\n outcomes?: EvalExpectedOutcomesFor<Suite> | undefined;\n};\n\nexport type RunEvalCliOptions<\n Input,\n Output,\n Expected = unknown,\n Metrics extends readonly EvalMetric<\n NoInfer<Input>,\n NoInfer<Output>,\n unknown,\n NoInfer<Expected>,\n string\n >[] = readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[],\n> = RunEvalSuiteOptions<Input, Output, Expected, Metrics> & {\n format?: EvalOutputFormat | undefined;\n exitCode?: boolean | undefined;\n expectations?: EvalExpectations | undefined;\n output?: EvalOutputWriters | undefined;\n maxValueLength?: number | undefined;\n redact?: EvalRedactor | undefined;\n};\n\nexport class EvalAssertionError extends Error {\n readonly mismatches: string[];\n\n constructor(message: string, mismatches: string[]) {\n super(`${message}\\n${mismatches.map((mismatch) => `- ${mismatch}`).join(\"\\n\")}`);\n this.name = \"EvalAssertionError\";\n this.mismatches = mismatches;\n }\n}\n\nexport function defineEvalExpectations<const Suite extends EvalSuiteShape>(\n _suite: Suite,\n expectations: EvalExpectationsFor<NoInfer<Suite>>,\n): EvalExpectationsFor<Suite> {\n return expectations;\n}\n\nexport function formatEvalResult(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n options: Omit<PrintEvalResultOptions, \"output\"> = {},\n): string {\n const format = options.format ?? \"pretty\";\n if (format === \"quiet\") return \"\";\n validatePrintOptions(options);\n return format === \"json\" ? jsonResult(result, options) : prettyResult(result, options);\n}\n\nexport function printEvalResult(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n options: PrintEvalResultOptions = {},\n): void {\n const format = options.format ?? \"pretty\";\n if (format === \"quiet\") return;\n const write = options.output?.stdout ?? ((text: string) => process.stdout.write(text));\n write(`${formatEvalResult(result, options)}\\n`);\n}\n\nexport function evalExitCode(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expectations?: EvalExpectations,\n): 0 | 1 | 2 {\n const hasExpectations =\n expectations?.totals !== undefined || expectations?.outcomes !== undefined;\n const mismatches = hasExpectations ? expectationMismatches(result, expectations) : [];\n if (hasExpectations && mismatches.length === 0) return 0;\n if (hasExpectations && hasUnexpectedInvalid(result, expectations)) return 2;\n if (hasExpectations) return 1;\n if (requiredMetricCount(result, \"invalid\") > 0) return 2;\n return requiredMetricCount(result, \"fail\") > 0 ? 1 : 0;\n}\n\nexport function assertEvalTotals(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expected: EvalExpectedTotals,\n): void {\n const mismatches = totalMismatches(result, expected);\n if (mismatches.length > 0) {\n throw new EvalAssertionError(\"Evaluation totals did not match expectations.\", mismatches);\n }\n}\n\nexport function assertEvalOutcomes(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expected: EvalExpectedOutcomes,\n): void {\n const mismatches = outcomeMismatches(result, expected);\n if (mismatches.length > 0) {\n throw new EvalAssertionError(\"Evaluation outcomes did not match expectations.\", mismatches);\n }\n}\n\nexport async function runEvalCli<\n Input,\n Output,\n Expected = unknown,\n const Metrics extends readonly EvalMetric<\n NoInfer<Input>,\n NoInfer<Output>,\n unknown,\n NoInfer<Expected>,\n string\n >[] = readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[],\n>(\n options: RunEvalCliOptions<Input, Output, Expected, Metrics>,\n): Promise<EvalSuiteResult<Input, Output, Expected, Metrics>> {\n const { format, exitCode, expectations, output, maxValueLength, redact, ...suiteOptions } =\n options;\n const result = await runEvalSuite(\n suiteOptions as RunEvalSuiteOptions<Input, Output, Expected, Metrics>,\n );\n printEvalResult(result, { format, output, maxValueLength, redact });\n const code = evalExitCode(result, expectations);\n const mismatches = expectationMismatches(result, expectations);\n if (mismatches.length > 0 && format !== \"quiet\") {\n const write = output?.stderr ?? ((text: string) => process.stderr.write(text));\n write(\n `Evaluation expectation mismatches:\\n${mismatches.map((value) => `- ${value}`).join(\"\\n\")}\\n`,\n );\n }\n const currentExitCode =\n typeof process.exitCode === \"number\" ? process.exitCode : Number(process.exitCode ?? 0);\n if (exitCode === true && code > currentExitCode) process.exitCode = code;\n return result;\n}\n\nfunction prettyResult(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n options: Omit<PrintEvalResultOptions, \"output\">,\n): string {\n const lines = [\n `${result.name} (${result.run.id})`,\n `Cases: ${totalsText(result.cases)}`,\n `Metrics: ${totalsText(result.metrics)}`,\n ];\n for (const caseResult of result.results) {\n lines.push(``, `[${caseResult.outcome.toUpperCase()}] ${caseResult.case.id}`);\n if (caseResult.targetStatus === \"succeeded\") {\n lines.push(\n ` output: ${displayValue(\n redact(caseResult.output, options, { kind: \"output\", caseId: caseResult.case.id }),\n options.maxValueLength,\n )}`,\n );\n }\n if (caseResult.targetStatus === \"failed\") {\n lines.push(\n ` target error: ${errorText(\n redact(caseResult.targetError, options, { kind: \"error\", caseId: caseResult.case.id }),\n options.maxValueLength,\n )}`,\n );\n }\n for (const metric of caseResult.metrics) {\n const parts = [` - ${metric.metricName}: ${metric.outcome.outcome}`];\n if (metric.outcome.score !== undefined) {\n parts.push(\n `score=${displayValue(\n redact(metric.outcome.score, options, {\n kind: \"score\",\n caseId: caseResult.case.id,\n metricName: metric.metricName,\n }),\n options.maxValueLength,\n )}`,\n );\n }\n if (metric.threshold !== undefined) parts.push(`threshold=${metric.threshold}`);\n if (metric.direction !== undefined) parts.push(`direction=${metric.direction}`);\n if (!metric.required) parts.push(\"optional\");\n lines.push(parts.join(\" | \"));\n const explanation =\n metric.outcome.comment ??\n (metric.outcome.outcome === \"invalid\" ? metric.outcome.reason : undefined);\n if (explanation !== undefined) {\n lines.push(\n ` ${displayValue(\n redact(explanation, options, {\n kind: \"comment\",\n caseId: caseResult.case.id,\n metricName: metric.metricName,\n }),\n options.maxValueLength,\n )}`,\n );\n }\n }\n }\n lines.push(\n ``,\n `Usage: target=${result.usage.target.totalTokens} evaluation=${result.usage.evaluation.totalTokens} total=${result.usage.total.totalTokens} tokens`,\n );\n if (result.cost !== undefined) {\n lines.push(\n `Cost: target=${result.cost.target} evaluation=${result.cost.evaluation} total=${result.cost.total} ${result.cost.currency}`,\n );\n }\n lines.push(`Duration: ${result.durationMs}ms`);\n return lines.join(\"\\n\");\n}\n\nfunction jsonResult(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n options: Omit<PrintEvalResultOptions, \"output\">,\n): string {\n return JSON.stringify(\n redactJsonResult(result, options),\n (_key, value: unknown) => {\n if (value instanceof Error) {\n return { name: value.name, message: value.message, stack: value.stack };\n }\n if (value instanceof RegExp) return String(value);\n if (typeof value === \"string\") return truncate(value, options.maxValueLength);\n return value;\n },\n 2,\n );\n}\n\nfunction expectationMismatches(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expectations?: EvalExpectations,\n): string[] {\n if (expectations === undefined) return [];\n const mismatches: string[] = [];\n if (expectations.totals !== undefined) {\n mismatches.push(...totalMismatches(result, expectations.totals));\n }\n if (expectations.outcomes !== undefined) {\n mismatches.push(...outcomeMismatches(result, expectations.outcomes));\n }\n return mismatches;\n}\n\nfunction totalMismatches(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expected: EvalExpectedTotals,\n): string[] {\n const directMetrics: Partial<EvalTotals> = {};\n if (expected.total !== undefined) directMetrics.total = expected.total;\n if (expected.passed !== undefined) directMetrics.passed = expected.passed;\n if (expected.failed !== undefined) directMetrics.failed = expected.failed;\n if (expected.invalid !== undefined) directMetrics.invalid = expected.invalid;\n return [\n ...totalsGroupMismatches(\"metrics\", result.metrics, {\n ...directMetrics,\n ...expected.metrics,\n }),\n ...totalsGroupMismatches(\"cases\", result.cases, expected.cases),\n ];\n}\n\nfunction totalsGroupMismatches(\n label: string,\n actual: EvalTotals,\n expected: Partial<EvalTotals> | undefined,\n): string[] {\n if (expected === undefined) return [];\n const mismatches: string[] = [];\n for (const key of [\"total\", \"passed\", \"failed\", \"invalid\"] as const) {\n if (expected[key] !== undefined && actual[key] !== expected[key]) {\n mismatches.push(`${label}.${key}: expected ${expected[key]}, received ${actual[key]}`);\n }\n }\n return mismatches;\n}\n\nfunction outcomeMismatches(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expected: EvalExpectedOutcomes,\n): string[] {\n const mismatches: string[] = [];\n const actualCases = new Map(result.results.map((caseResult) => [caseResult.case.id, caseResult]));\n for (const [caseId, metrics] of Object.entries(expected)) {\n const caseResult = actualCases.get(caseId);\n if (caseResult === undefined) {\n mismatches.push(`${caseId}: expected case was not present`);\n continue;\n }\n for (const [metricName, expectedOutcome] of Object.entries(metrics)) {\n const metric = caseResult.metrics.find((candidate) => candidate.metricName === metricName);\n if (metric === undefined) {\n mismatches.push(`${caseId}.${metricName}: expected metric was not present`);\n } else if (metric.outcome.outcome !== expectedOutcome) {\n mismatches.push(\n `${caseId}.${metricName}: expected ${expectedOutcome}, received ${metric.outcome.outcome}`,\n );\n }\n }\n }\n for (const caseResult of result.results) {\n for (const metric of caseResult.metrics) {\n if (!metric.required) continue;\n const expectedOutcome = expected[caseResult.case.id]?.[metric.metricName] ?? \"pass\";\n if (metric.outcome.outcome !== expectedOutcome) {\n const message = `${caseResult.case.id}.${metric.metricName}: expected ${expectedOutcome}, received ${metric.outcome.outcome}`;\n if (!mismatches.includes(message)) mismatches.push(message);\n }\n }\n }\n return mismatches;\n}\n\nfunction hasUnexpectedInvalid(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expectations: EvalExpectations | undefined,\n): boolean {\n if (expectations?.outcomes !== undefined) {\n return result.results.some((caseResult) =>\n caseResult.metrics.some(\n (metric) =>\n metric.required &&\n metric.outcome.outcome === \"invalid\" &&\n expectations.outcomes?.[caseResult.case.id]?.[metric.metricName] !== \"invalid\",\n ),\n );\n }\n const expectedInvalid = expectations?.totals?.metrics?.invalid ?? expectations?.totals?.invalid;\n return result.metrics.invalid > (expectedInvalid ?? 0);\n}\n\nfunction requiredMetricCount(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n status: \"fail\" | \"invalid\",\n): number {\n return result.results.reduce(\n (total, caseResult) =>\n total +\n caseResult.metrics.filter((metric) => metric.required && metric.outcome.outcome === status)\n .length,\n 0,\n );\n}\n\nfunction totalsText(totals: EvalTotals): string {\n return `${totals.total} total / ${totals.passed} pass / ${totals.failed} fail / ${totals.invalid} invalid`;\n}\n\nfunction displayValue(value: unknown, maxValueLength?: number): string {\n let text: string;\n if (typeof value === \"string\") text = value;\n else {\n try {\n text = JSON.stringify(value) ?? String(value);\n } catch {\n text = String(value);\n }\n }\n return truncate(text, maxValueLength);\n}\n\nfunction errorText(error: unknown, maxValueLength?: number): string {\n return truncate(error instanceof Error ? error.message : displayValue(error), maxValueLength);\n}\n\nfunction truncate(value: string, maxValueLength: number | undefined): string {\n return maxValueLength !== undefined && value.length > maxValueLength\n ? `${value.slice(0, maxValueLength)}…`\n : value;\n}\n\nfunction redact(\n value: unknown,\n options: Omit<PrintEvalResultOptions, \"output\">,\n context: EvalRedactionContext,\n): unknown {\n return options.redact === undefined ? value : options.redact(value, context);\n}\n\nfunction redactJsonResult(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n options: Omit<PrintEvalResultOptions, \"output\">,\n): unknown {\n return {\n ...result,\n run: {\n ...result.run,\n metadata:\n result.run.metadata === undefined\n ? undefined\n : (redact(result.run.metadata, options, {\n kind: \"metadata\",\n }) as typeof result.run.metadata),\n },\n results: result.results.map((caseResult) => ({\n ...caseResult,\n case: {\n ...caseResult.case,\n input: redact(caseResult.case.input, options, {\n kind: \"input\",\n caseId: caseResult.case.id,\n }),\n expected: redact(caseResult.case.expected, options, {\n kind: \"expected\",\n caseId: caseResult.case.id,\n }),\n context: redact(caseResult.case.context, options, {\n kind: \"context\",\n caseId: caseResult.case.id,\n }),\n retrievalContext: redact(caseResult.case.retrievalContext, options, {\n kind: \"retrievalContext\",\n caseId: caseResult.case.id,\n }),\n metadata:\n caseResult.case.metadata === undefined\n ? undefined\n : (redact(caseResult.case.metadata, options, {\n kind: \"metadata\",\n caseId: caseResult.case.id,\n }) as typeof caseResult.case.metadata),\n },\n output:\n caseResult.targetStatus === \"succeeded\"\n ? redact(caseResult.output, options, { kind: \"output\", caseId: caseResult.case.id })\n : undefined,\n targetError:\n caseResult.targetStatus === \"failed\"\n ? redact(caseResult.targetError, options, {\n kind: \"error\",\n caseId: caseResult.case.id,\n })\n : undefined,\n metrics: caseResult.metrics.map((metric) => ({\n ...metric,\n reporterErrors: metric.reporterErrors.map((error) =>\n redact(error, options, {\n kind: \"error\",\n caseId: caseResult.case.id,\n metricName: metric.metricName,\n }),\n ),\n outcome: redactOutcome(metric.outcome, options, caseResult.case.id, metric.metricName),\n })),\n scores: Object.fromEntries(\n caseResult.metrics.map((metric) => [\n metric.metricName,\n redactOutcome(metric.outcome, options, caseResult.case.id, metric.metricName),\n ]),\n ),\n })),\n reporterErrors: result.reporterErrors.map((error) => redact(error, options, { kind: \"error\" })),\n };\n}\n\nfunction redactOutcome(\n outcome: EvalSuiteResult<\n unknown,\n unknown,\n unknown\n >[\"results\"][number][\"metrics\"][number][\"outcome\"],\n options: Omit<PrintEvalResultOptions, \"output\">,\n caseId: string,\n metricName: string,\n): unknown {\n return {\n ...outcome,\n ...(outcome.score === undefined\n ? {}\n : { score: redact(outcome.score, options, { kind: \"score\", caseId, metricName }) }),\n ...(outcome.comment === undefined\n ? {}\n : { comment: redact(outcome.comment, options, { kind: \"comment\", caseId, metricName }) }),\n ...(!(\"reason\" in outcome) || outcome.reason === undefined\n ? {}\n : { reason: redact(outcome.reason, options, { kind: \"comment\", caseId, metricName }) }),\n ...(outcome.metadata === undefined\n ? {}\n : {\n metadata: redact(outcome.metadata, options, {\n kind: \"metadata\",\n caseId,\n metricName,\n }),\n }),\n ...(!(\"error\" in outcome) || outcome.error === undefined\n ? {}\n : { error: redact(outcome.error, options, { kind: \"error\", caseId, metricName }) }),\n };\n}\n\nfunction validatePrintOptions(options: Omit<PrintEvalResultOptions, \"output\">): void {\n if (\n options.maxValueLength !== undefined &&\n (!Number.isSafeInteger(options.maxValueLength) || options.maxValueLength < 1)\n ) {\n throw new RangeError(\"Evaluation maxValueLength must be a positive integer.\");\n }\n}\n"],"mappings":";;;;;AA2FO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACnC;AAAA,EAET,YAAY,SAAiB,YAAsB;AACjD,UAAM,GAAG,OAAO;AAAA,EAAK,WAAW,IAAI,CAAC,aAAa,KAAK,QAAQ,EAAE,EAAE,KAAK,IAAI,CAAC,EAAE;AAC/E,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,SAAS,uBACd,QACA,cAC4B;AAC5B,SAAO;AACT;AAEO,SAAS,iBACd,QACA,UAAkD,CAAC,GAC3C;AACR,QAAM,SAAS,QAAQ,UAAU;AACjC,MAAI,WAAW,QAAS,QAAO;AAC/B,uBAAqB,OAAO;AAC5B,SAAO,WAAW,SAAS,WAAW,QAAQ,OAAO,IAAI,aAAa,QAAQ,OAAO;AACvF;AAEO,SAAS,gBACd,QACA,UAAkC,CAAC,GAC7B;AACN,QAAM,SAAS,QAAQ,UAAU;AACjC,MAAI,WAAW,QAAS;AACxB,QAAM,QAAQ,QAAQ,QAAQ,WAAW,CAAC,SAAiB,QAAQ,OAAO,MAAM,IAAI;AACpF,QAAM,GAAG,iBAAiB,QAAQ,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IACD,EAAE,OAAO,OAAO,QAAQ,OAAO,SAAS,EAAE,MAAM,SAAS,QAAQ,WAAW,CAAC,EAAE;AAAA,EACrF;AACF;AAEA,SAAS,qBAAqB,SAAuD;AACnF,MACE,QAAQ,mBAAmB,WAC1B,CAAC,OAAO,cAAc,QAAQ,cAAc,KAAK,QAAQ,iBAAiB,IAC3E;AACA,UAAM,IAAI,WAAW,uDAAuD;AAAA,EAC9E;AACF;","names":["redact"]}
1
+ {"version":3,"sources":["../src/evals/cli.ts"],"sourcesContent":["import { runEvalSuite } from \"./runner\";\nimport type {\n EvalMetric,\n EvalOutcomeStatus,\n EvalSuiteResult,\n EvalTotals,\n RunEvalSuiteOptions,\n} from \"./types\";\n\nexport type EvalOutputFormat = \"pretty\" | \"json\" | \"quiet\";\n\nexport type EvalExpectedTotals = Partial<EvalTotals> & {\n metrics?: Partial<EvalTotals> | undefined;\n cases?: Partial<EvalTotals> | undefined;\n};\n\nexport type EvalExpectedOutcomes = Record<string, Record<string, EvalOutcomeStatus>>;\n\nexport type EvalExpectations = {\n totals?: EvalExpectedTotals | undefined;\n outcomes?: EvalExpectedOutcomes | undefined;\n};\n\nexport type EvalOutputWriters = {\n stdout?(text: string): void;\n stderr?(text: string): void;\n};\n\nexport type EvalRedactionContext = {\n kind:\n | \"input\"\n | \"expected\"\n | \"context\"\n | \"retrievalContext\"\n | \"output\"\n | \"score\"\n | \"comment\"\n | \"metadata\"\n | \"error\";\n caseId?: string | undefined;\n metricName?: string | undefined;\n};\n\nexport type EvalRedactor = (value: unknown, context: EvalRedactionContext) => unknown;\n\nexport type PrintEvalResultOptions = {\n format?: EvalOutputFormat | undefined;\n output?: EvalOutputWriters | undefined;\n maxValueLength?: number | undefined;\n redact?: EvalRedactor | undefined;\n};\n\ntype EvalSuiteShape = {\n cases: readonly { id: string }[];\n metrics: readonly { name: string }[];\n};\n\nexport type EvalExpectedOutcomesFor<Suite extends EvalSuiteShape> = Partial<\n Record<\n Suite[\"cases\"][number][\"id\"],\n Partial<Record<Suite[\"metrics\"][number][\"name\"], EvalOutcomeStatus>>\n >\n>;\n\nexport type EvalExpectationsFor<Suite extends EvalSuiteShape> = Omit<\n EvalExpectations,\n \"outcomes\"\n> & {\n outcomes?: EvalExpectedOutcomesFor<Suite> | undefined;\n};\n\nexport type RunEvalCliOptions<\n Input,\n Output,\n Expected = unknown,\n Metrics extends readonly EvalMetric<\n NoInfer<Input>,\n NoInfer<Output>,\n unknown,\n NoInfer<Expected>,\n string\n >[] = readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[],\n> = RunEvalSuiteOptions<Input, Output, Expected, Metrics> & {\n format?: EvalOutputFormat | undefined;\n exitCode?: boolean | undefined;\n expectations?: EvalExpectations | undefined;\n output?: EvalOutputWriters | undefined;\n maxValueLength?: number | undefined;\n redact?: EvalRedactor | undefined;\n};\n\nexport class EvalAssertionError extends Error {\n readonly mismatches: string[];\n\n constructor(message: string, mismatches: string[]) {\n super(`${message}\\n${mismatches.map((mismatch) => `- ${mismatch}`).join(\"\\n\")}`);\n this.name = \"EvalAssertionError\";\n this.mismatches = mismatches;\n }\n}\n\nexport function defineEvalExpectations<const Suite extends EvalSuiteShape>(\n _suite: Suite,\n expectations: EvalExpectationsFor<NoInfer<Suite>>,\n): EvalExpectationsFor<Suite> {\n return expectations;\n}\n\nexport function formatEvalResult(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n options: Omit<PrintEvalResultOptions, \"output\"> = {},\n): string {\n const format = options.format ?? \"pretty\";\n if (format === \"quiet\") return \"\";\n validatePrintOptions(options);\n return format === \"json\" ? jsonResult(result, options) : prettyResult(result, options);\n}\n\nexport function printEvalResult(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n options: PrintEvalResultOptions = {},\n): void {\n const format = options.format ?? \"pretty\";\n if (format === \"quiet\") return;\n const write = options.output?.stdout ?? ((text: string) => process.stdout.write(text));\n write(`${formatEvalResult(result, options)}\\n`);\n}\n\nexport function evalExitCode(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expectations?: EvalExpectations,\n): 0 | 1 | 2 {\n const hasExpectations =\n expectations?.totals !== undefined || expectations?.outcomes !== undefined;\n const mismatches = hasExpectations ? expectationMismatches(result, expectations) : [];\n if (hasExpectations && mismatches.length === 0) return 0;\n if (hasExpectations && hasUnexpectedInvalid(result, expectations)) return 2;\n if (hasExpectations) return 1;\n if (requiredMetricCount(result, \"invalid\") > 0) return 2;\n return requiredMetricCount(result, \"fail\") > 0 ? 1 : 0;\n}\n\nexport function assertEvalTotals(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expected: EvalExpectedTotals,\n): void {\n const mismatches = totalMismatches(result, expected);\n if (mismatches.length > 0) {\n throw new EvalAssertionError(\"Evaluation totals did not match expectations.\", mismatches);\n }\n}\n\nexport function assertEvalOutcomes(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expected: EvalExpectedOutcomes,\n): void {\n const mismatches = outcomeMismatches(result, expected);\n if (mismatches.length > 0) {\n throw new EvalAssertionError(\"Evaluation outcomes did not match expectations.\", mismatches);\n }\n}\n\nexport async function runEvalCli<\n Input,\n Output,\n Expected = unknown,\n const Metrics extends readonly EvalMetric<\n NoInfer<Input>,\n NoInfer<Output>,\n unknown,\n NoInfer<Expected>,\n string\n >[] = readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[],\n>(\n options: RunEvalCliOptions<Input, Output, Expected, Metrics>,\n): Promise<EvalSuiteResult<Input, Output, Expected, Metrics>> {\n const { format, exitCode, expectations, output, maxValueLength, redact, ...suiteOptions } =\n options;\n const result = await runEvalSuite(\n suiteOptions as RunEvalSuiteOptions<Input, Output, Expected, Metrics>,\n );\n printEvalResult(result, { format, output, maxValueLength, redact });\n const code = evalExitCode(result, expectations);\n const mismatches = expectationMismatches(result, expectations);\n if (mismatches.length > 0 && format !== \"quiet\") {\n const write = output?.stderr ?? ((text: string) => process.stderr.write(text));\n write(\n `Evaluation expectation mismatches:\\n${mismatches.map((value) => `- ${value}`).join(\"\\n\")}\\n`,\n );\n }\n const currentExitCode =\n typeof process.exitCode === \"number\" ? process.exitCode : Number(process.exitCode ?? 0);\n if (exitCode === true && code > currentExitCode) process.exitCode = code;\n return result;\n}\n\nfunction prettyResult(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n options: Omit<PrintEvalResultOptions, \"output\">,\n): string {\n const lines = [\n `${result.name} (${result.run.id})`,\n `Cases: ${totalsText(result.cases)}`,\n `Metrics: ${totalsText(result.metrics)}`,\n ];\n for (const caseResult of result.results) {\n lines.push(``, `[${caseResult.outcome.toUpperCase()}] ${caseResult.case.id}`);\n if (caseResult.targetStatus === \"succeeded\") {\n lines.push(\n ` output: ${displayValue(\n redact(caseResult.output, options, { kind: \"output\", caseId: caseResult.case.id }),\n options.maxValueLength,\n )}`,\n );\n }\n if (caseResult.targetStatus === \"failed\") {\n lines.push(\n ` target error: ${errorText(\n redact(caseResult.targetError, options, { kind: \"error\", caseId: caseResult.case.id }),\n options.maxValueLength,\n )}`,\n );\n }\n for (const metric of caseResult.metrics) {\n const parts = [` - ${metric.metricName}: ${metric.outcome.outcome}`];\n if (metric.outcome.score !== undefined) {\n parts.push(\n `score=${displayValue(\n redact(metric.outcome.score, options, {\n kind: \"score\",\n caseId: caseResult.case.id,\n metricName: metric.metricName,\n }),\n options.maxValueLength,\n )}`,\n );\n }\n if (metric.threshold !== undefined) parts.push(`threshold=${metric.threshold}`);\n if (metric.direction !== undefined) parts.push(`direction=${metric.direction}`);\n if (!metric.required) parts.push(\"optional\");\n lines.push(parts.join(\" | \"));\n const explanation =\n metric.outcome.comment ??\n (metric.outcome.outcome === \"invalid\" ? metric.outcome.reason : undefined);\n if (explanation !== undefined) {\n lines.push(\n ` ${displayValue(\n redact(explanation, options, {\n kind: \"comment\",\n caseId: caseResult.case.id,\n metricName: metric.metricName,\n }),\n options.maxValueLength,\n )}`,\n );\n }\n }\n }\n lines.push(\n ``,\n `Usage: target=${result.usage.target.totalTokens} evaluation=${result.usage.evaluation.totalTokens} total=${result.usage.total.totalTokens} tokens`,\n );\n if (result.cost !== undefined) {\n lines.push(\n `Cost: target=${result.cost.target} evaluation=${result.cost.evaluation} total=${result.cost.total} ${result.cost.currency}`,\n );\n }\n lines.push(`Duration: ${result.durationMs}ms`);\n return lines.join(\"\\n\");\n}\n\nfunction jsonResult(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n options: Omit<PrintEvalResultOptions, \"output\">,\n): string {\n return JSON.stringify(\n redactJsonResult(result, options),\n (_key, value: unknown) => {\n if (value instanceof Error) {\n return { name: value.name, message: value.message, stack: value.stack };\n }\n if (value instanceof RegExp) return String(value);\n if (typeof value === \"string\") return truncate(value, options.maxValueLength);\n return value;\n },\n 2,\n );\n}\n\nfunction expectationMismatches(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expectations?: EvalExpectations,\n): string[] {\n if (expectations === undefined) return [];\n const mismatches: string[] = [];\n if (expectations.totals !== undefined) {\n mismatches.push(...totalMismatches(result, expectations.totals));\n }\n if (expectations.outcomes !== undefined) {\n mismatches.push(...outcomeMismatches(result, expectations.outcomes));\n }\n return mismatches;\n}\n\nfunction totalMismatches(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expected: EvalExpectedTotals,\n): string[] {\n const directMetrics: Partial<EvalTotals> = {};\n if (expected.total !== undefined) directMetrics.total = expected.total;\n if (expected.passed !== undefined) directMetrics.passed = expected.passed;\n if (expected.failed !== undefined) directMetrics.failed = expected.failed;\n if (expected.invalid !== undefined) directMetrics.invalid = expected.invalid;\n return [\n ...totalsGroupMismatches(\"metrics\", result.metrics, {\n ...directMetrics,\n ...expected.metrics,\n }),\n ...totalsGroupMismatches(\"cases\", result.cases, expected.cases),\n ];\n}\n\nfunction totalsGroupMismatches(\n label: string,\n actual: EvalTotals,\n expected: Partial<EvalTotals> | undefined,\n): string[] {\n if (expected === undefined) return [];\n const mismatches: string[] = [];\n for (const key of [\"total\", \"passed\", \"failed\", \"invalid\"] as const) {\n if (expected[key] !== undefined && actual[key] !== expected[key]) {\n mismatches.push(`${label}.${key}: expected ${expected[key]}, received ${actual[key]}`);\n }\n }\n return mismatches;\n}\n\nfunction outcomeMismatches(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expected: EvalExpectedOutcomes,\n): string[] {\n const mismatches: string[] = [];\n const actualCases = new Map(result.results.map((caseResult) => [caseResult.case.id, caseResult]));\n for (const [caseId, metrics] of Object.entries(expected)) {\n const caseResult = actualCases.get(caseId);\n if (caseResult === undefined) {\n mismatches.push(`${caseId}: expected case was not present`);\n continue;\n }\n for (const [metricName, expectedOutcome] of Object.entries(metrics)) {\n const metric = caseResult.metrics.find((candidate) => candidate.metricName === metricName);\n if (metric === undefined) {\n mismatches.push(`${caseId}.${metricName}: expected metric was not present`);\n } else if (metric.outcome.outcome !== expectedOutcome) {\n mismatches.push(\n `${caseId}.${metricName}: expected ${expectedOutcome}, received ${metric.outcome.outcome}`,\n );\n }\n }\n }\n for (const caseResult of result.results) {\n for (const metric of caseResult.metrics) {\n if (!metric.required) continue;\n const expectedOutcome = expected[caseResult.case.id]?.[metric.metricName] ?? \"pass\";\n if (metric.outcome.outcome !== expectedOutcome) {\n const message = `${caseResult.case.id}.${metric.metricName}: expected ${expectedOutcome}, received ${metric.outcome.outcome}`;\n if (!mismatches.includes(message)) mismatches.push(message);\n }\n }\n }\n return mismatches;\n}\n\nfunction hasUnexpectedInvalid(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n expectations: EvalExpectations | undefined,\n): boolean {\n if (expectations?.outcomes !== undefined) {\n return result.results.some((caseResult) =>\n caseResult.metrics.some(\n (metric) =>\n metric.required &&\n metric.outcome.outcome === \"invalid\" &&\n expectations.outcomes?.[caseResult.case.id]?.[metric.metricName] !== \"invalid\",\n ),\n );\n }\n const expectedInvalid = expectations?.totals?.metrics?.invalid ?? expectations?.totals?.invalid;\n return result.metrics.invalid > (expectedInvalid ?? 0);\n}\n\nfunction requiredMetricCount(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n status: \"fail\" | \"invalid\",\n): number {\n return result.results.reduce(\n (total, caseResult) =>\n total +\n caseResult.metrics.filter((metric) => metric.required && metric.outcome.outcome === status)\n .length,\n 0,\n );\n}\n\nfunction totalsText(totals: EvalTotals): string {\n return `${totals.total} total / ${totals.passed} pass / ${totals.failed} fail / ${totals.invalid} invalid`;\n}\n\nfunction displayValue(value: unknown, maxValueLength?: number): string {\n let text: string;\n if (typeof value === \"string\") text = value;\n else {\n try {\n text = JSON.stringify(value) ?? String(value);\n } catch {\n text = String(value);\n }\n }\n return truncate(text, maxValueLength);\n}\n\nfunction errorText(error: unknown, maxValueLength?: number): string {\n return truncate(error instanceof Error ? error.message : displayValue(error), maxValueLength);\n}\n\nfunction truncate(value: string, maxValueLength: number | undefined): string {\n return maxValueLength !== undefined && value.length > maxValueLength\n ? `${value.slice(0, maxValueLength)}…`\n : value;\n}\n\nfunction redact(\n value: unknown,\n options: Omit<PrintEvalResultOptions, \"output\">,\n context: EvalRedactionContext,\n): unknown {\n return options.redact === undefined ? value : options.redact(value, context);\n}\n\nfunction redactJsonResult(\n result: EvalSuiteResult<unknown, unknown, unknown>,\n options: Omit<PrintEvalResultOptions, \"output\">,\n): unknown {\n return {\n ...result,\n run: {\n ...result.run,\n metadata:\n result.run.metadata === undefined\n ? undefined\n : (redact(result.run.metadata, options, {\n kind: \"metadata\",\n }) as typeof result.run.metadata),\n },\n results: result.results.map((caseResult) => ({\n ...caseResult,\n case: {\n ...caseResult.case,\n input: redact(caseResult.case.input, options, {\n kind: \"input\",\n caseId: caseResult.case.id,\n }),\n expected: redact(caseResult.case.expected, options, {\n kind: \"expected\",\n caseId: caseResult.case.id,\n }),\n context: redact(caseResult.case.context, options, {\n kind: \"context\",\n caseId: caseResult.case.id,\n }),\n retrievalContext: redact(caseResult.case.retrievalContext, options, {\n kind: \"retrievalContext\",\n caseId: caseResult.case.id,\n }),\n metadata:\n caseResult.case.metadata === undefined\n ? undefined\n : (redact(caseResult.case.metadata, options, {\n kind: \"metadata\",\n caseId: caseResult.case.id,\n }) as typeof caseResult.case.metadata),\n },\n output:\n caseResult.targetStatus === \"succeeded\"\n ? redact(caseResult.output, options, { kind: \"output\", caseId: caseResult.case.id })\n : undefined,\n targetError:\n caseResult.targetStatus === \"failed\"\n ? redact(caseResult.targetError, options, {\n kind: \"error\",\n caseId: caseResult.case.id,\n })\n : undefined,\n metrics: caseResult.metrics.map((metric) => ({\n ...metric,\n reporterErrors: metric.reporterErrors.map((error) =>\n redact(error, options, {\n kind: \"error\",\n caseId: caseResult.case.id,\n metricName: metric.metricName,\n }),\n ),\n outcome: redactOutcome(metric.outcome, options, caseResult.case.id, metric.metricName),\n })),\n scores: Object.fromEntries(\n caseResult.metrics.map((metric) => [\n metric.metricName,\n redactOutcome(metric.outcome, options, caseResult.case.id, metric.metricName),\n ]),\n ),\n })),\n reporterErrors: result.reporterErrors.map((error) => redact(error, options, { kind: \"error\" })),\n };\n}\n\nfunction redactOutcome(\n outcome: EvalSuiteResult<\n unknown,\n unknown,\n unknown\n >[\"results\"][number][\"metrics\"][number][\"outcome\"],\n options: Omit<PrintEvalResultOptions, \"output\">,\n caseId: string,\n metricName: string,\n): unknown {\n const redacted: Record<string, unknown> = { ...outcome };\n\n if (outcome.score !== undefined) {\n redacted.score = redact(outcome.score, options, { kind: \"score\", caseId, metricName });\n }\n\n if (outcome.comment !== undefined) {\n redacted.comment = redact(outcome.comment, options, { kind: \"comment\", caseId, metricName });\n }\n\n if (\"reason\" in outcome && outcome.reason !== undefined) {\n redacted.reason = redact(outcome.reason, options, { kind: \"comment\", caseId, metricName });\n }\n\n if (outcome.metadata !== undefined) {\n redacted.metadata = redact(outcome.metadata, options, { kind: \"metadata\", caseId, metricName });\n }\n\n if (\"error\" in outcome && outcome.error !== undefined) {\n redacted.error = redact(outcome.error, options, { kind: \"error\", caseId, metricName });\n }\n\n return redacted;\n}\n\nfunction validatePrintOptions(options: Omit<PrintEvalResultOptions, \"output\">): void {\n if (\n options.maxValueLength !== undefined &&\n (!Number.isSafeInteger(options.maxValueLength) || options.maxValueLength < 1)\n ) {\n throw new RangeError(\"Evaluation maxValueLength must be a positive integer.\");\n }\n}\n"],"mappings":";;;;;AA2FO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACnC;AAAA,EAET,YAAY,SAAiB,YAAsB;AACjD,UAAM,GAAG,OAAO;AAAA,EAAK,WAAW,IAAI,CAAC,aAAa,KAAK,QAAQ,EAAE,EAAE,KAAK,IAAI,CAAC,EAAE;AAC/E,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,SAAS,uBACd,QACA,cAC4B;AAC5B,SAAO;AACT;AAEO,SAAS,iBACd,QACA,UAAkD,CAAC,GAC3C;AACR,QAAM,SAAS,QAAQ,UAAU;AACjC,MAAI,WAAW,QAAS,QAAO;AAC/B,uBAAqB,OAAO;AAC5B,SAAO,WAAW,SAAS,WAAW,QAAQ,OAAO,IAAI,aAAa,QAAQ,OAAO;AACvF;AAEO,SAAS,gBACd,QACA,UAAkC,CAAC,GAC7B;AACN,QAAM,SAAS,QAAQ,UAAU;AACjC,MAAI,WAAW,QAAS;AACxB,QAAM,QAAQ,QAAQ,QAAQ,WAAW,CAAC,SAAiB,QAAQ,OAAO,MAAM,IAAI;AACpF,QAAM,GAAG,iBAAiB,QAAQ,OAAO,CAAC;AAAA,CAAI;AAChD;AAEO,SAAS,aACd,QACA,cACW;AACX,QAAM,kBACJ,cAAc,WAAW,UAAa,cAAc,aAAa;AACnE,QAAM,aAAa,kBAAkB,sBAAsB,QAAQ,YAAY,IAAI,CAAC;AACpF,MAAI,mBAAmB,WAAW,WAAW,EAAG,QAAO;AACvD,MAAI,mBAAmB,qBAAqB,QAAQ,YAAY,EAAG,QAAO;AAC1E,MAAI,gBAAiB,QAAO;AAC5B,MAAI,oBAAoB,QAAQ,SAAS,IAAI,EAAG,QAAO;AACvD,SAAO,oBAAoB,QAAQ,MAAM,IAAI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
9
6
  isSkillTool
10
7
  } from "./chunk-2NLINXRF.js";
8
+ import {
9
+ isQuestionTool
10
+ } from "./chunk-BX52ILPM.js";
11
11
  import {
12
12
  runControl,
13
13
  toolCallControl
@@ -30,7 +30,7 @@ import {
30
30
  import {
31
31
  prepareToolCall,
32
32
  prepareToolCallFromInput
33
- } from "./chunk-WCJRGYF7.js";
33
+ } from "./chunk-6YYZ7VJQ.js";
34
34
  import {
35
35
  assertToolApprovalRequirement,
36
36
  toolMayRequireApproval
@@ -40,7 +40,7 @@ import {
40
40
  normalizeToolResultOutput,
41
41
  parseToolArgs,
42
42
  toolResultContentToText
43
- } from "./chunk-VHPT2C4P.js";
43
+ } from "./chunk-TMSWHXYQ.js";
44
44
  import {
45
45
  Usage
46
46
  } from "./chunk-HJ6KTQTZ.js";
@@ -125,7 +125,7 @@ var ToolCallExecutor = class {
125
125
  }
126
126
  if (toolDefinition !== void 0) toolStartArgs = { ...toolStartArgs, toolDefinition };
127
127
  if (toolMetadata !== void 0) toolStartArgs = { ...toolStartArgs, toolMetadata };
128
- const toolObservers = await observation?.runObservers.startTool(toolStartArgs);
128
+ const toolObservers = this.replayed(toolCall) ? void 0 : await observation?.runObservers.startTool(toolStartArgs);
129
129
  const toolObservation = new ToolObserverScope(toolObservers);
130
130
  let output;
131
131
  let skipped = false;
@@ -399,7 +399,7 @@ var ToolCallExecutor = class {
399
399
  }
400
400
  if (toolDefinition !== void 0) toolStartArgs = { ...toolStartArgs, toolDefinition };
401
401
  if (toolMetadata !== void 0) toolStartArgs = { ...toolStartArgs, toolMetadata };
402
- const observers = await observation?.runObservers.startTool(toolStartArgs);
402
+ const observers = this.replayed(toolCall) ? void 0 : await observation?.runObservers.startTool(toolStartArgs);
403
403
  const toolObservation = new ToolObserverScope(observers);
404
404
  let output;
405
405
  let failed = false;
@@ -610,6 +610,10 @@ var ToolCallExecutor = class {
610
610
  throw error;
611
611
  }
612
612
  }
613
+ /** A restored result was observed when the tool ran; observing it again duplicates it. */
614
+ replayed(toolCall) {
615
+ return this.execution?.replayed?.({ kind: "tool", toolCall }) === true;
616
+ }
613
617
  runApprovedToolCall(prepared, toolCall, hookArgs, effectiveArgs, toolObservation, observation, onStreamEvent) {
614
618
  const execute = (context) => this.runUncachedToolCall(
615
619
  prepared,
@@ -967,4 +971,4 @@ function agentToolEventPayload(toolCall, internalCallId, event) {
967
971
  export {
968
972
  ToolCallExecutor
969
973
  };
970
- //# sourceMappingURL=chunk-UWWWCH4M.js.map
974
+ //# sourceMappingURL=chunk-4BGJBGJU.js.map