@uns-kit/assistant-workflow 2.0.72

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 (295) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/dist/clarification-policy.d.ts +64 -0
  4. package/dist/clarification-policy.d.ts.map +1 -0
  5. package/dist/clarification-policy.js +174 -0
  6. package/dist/clarification-policy.js.map +1 -0
  7. package/dist/decision.d.ts +37 -0
  8. package/dist/decision.d.ts.map +1 -0
  9. package/dist/decision.js +100 -0
  10. package/dist/decision.js.map +1 -0
  11. package/dist/definition-catalog-replay.d.ts +25 -0
  12. package/dist/definition-catalog-replay.d.ts.map +1 -0
  13. package/dist/definition-catalog-replay.js +54 -0
  14. package/dist/definition-catalog-replay.js.map +1 -0
  15. package/dist/definition-catalog.d.ts +45 -0
  16. package/dist/definition-catalog.d.ts.map +1 -0
  17. package/dist/definition-catalog.js +97 -0
  18. package/dist/definition-catalog.js.map +1 -0
  19. package/dist/definition-diagnostics.d.ts +17 -0
  20. package/dist/definition-diagnostics.d.ts.map +1 -0
  21. package/dist/definition-diagnostics.js +353 -0
  22. package/dist/definition-diagnostics.js.map +1 -0
  23. package/dist/definition-diff.d.ts +51 -0
  24. package/dist/definition-diff.d.ts.map +1 -0
  25. package/dist/definition-diff.js +172 -0
  26. package/dist/definition-diff.js.map +1 -0
  27. package/dist/definition-json.d.ts +53 -0
  28. package/dist/definition-json.d.ts.map +1 -0
  29. package/dist/definition-json.js +186 -0
  30. package/dist/definition-json.js.map +1 -0
  31. package/dist/definition-manifest.d.ts +41 -0
  32. package/dist/definition-manifest.d.ts.map +1 -0
  33. package/dist/definition-manifest.js +119 -0
  34. package/dist/definition-manifest.js.map +1 -0
  35. package/dist/definition-package-execution-json.d.ts +64 -0
  36. package/dist/definition-package-execution-json.d.ts.map +1 -0
  37. package/dist/definition-package-execution-json.js +245 -0
  38. package/dist/definition-package-execution-json.js.map +1 -0
  39. package/dist/definition-package-execution-replay.d.ts +14 -0
  40. package/dist/definition-package-execution-replay.d.ts.map +1 -0
  41. package/dist/definition-package-execution-replay.js +47 -0
  42. package/dist/definition-package-execution-replay.js.map +1 -0
  43. package/dist/definition-package-executor.d.ts +52 -0
  44. package/dist/definition-package-executor.d.ts.map +1 -0
  45. package/dist/definition-package-executor.js +70 -0
  46. package/dist/definition-package-executor.js.map +1 -0
  47. package/dist/definition-package-loader.d.ts +36 -0
  48. package/dist/definition-package-loader.d.ts.map +1 -0
  49. package/dist/definition-package-loader.js +56 -0
  50. package/dist/definition-package-loader.js.map +1 -0
  51. package/dist/definition-package-replay.d.ts +28 -0
  52. package/dist/definition-package-replay.d.ts.map +1 -0
  53. package/dist/definition-package-replay.js +74 -0
  54. package/dist/definition-package-replay.js.map +1 -0
  55. package/dist/definition-package-resolver.d.ts +31 -0
  56. package/dist/definition-package-resolver.d.ts.map +1 -0
  57. package/dist/definition-package-resolver.js +60 -0
  58. package/dist/definition-package-resolver.js.map +1 -0
  59. package/dist/definition-package-review.d.ts +29 -0
  60. package/dist/definition-package-review.d.ts.map +1 -0
  61. package/dist/definition-package-review.js +74 -0
  62. package/dist/definition-package-review.js.map +1 -0
  63. package/dist/definition-package-run-report.d.ts +25 -0
  64. package/dist/definition-package-run-report.d.ts.map +1 -0
  65. package/dist/definition-package-run-report.js +37 -0
  66. package/dist/definition-package-run-report.js.map +1 -0
  67. package/dist/definition-package-run.d.ts +20 -0
  68. package/dist/definition-package-run.d.ts.map +1 -0
  69. package/dist/definition-package-run.js +41 -0
  70. package/dist/definition-package-run.js.map +1 -0
  71. package/dist/definition-package-selection.d.ts +29 -0
  72. package/dist/definition-package-selection.d.ts.map +1 -0
  73. package/dist/definition-package-selection.js +68 -0
  74. package/dist/definition-package-selection.js.map +1 -0
  75. package/dist/definition-package-smoke.d.ts +74 -0
  76. package/dist/definition-package-smoke.d.ts.map +1 -0
  77. package/dist/definition-package-smoke.js +184 -0
  78. package/dist/definition-package-smoke.js.map +1 -0
  79. package/dist/definition-package.d.ts +36 -0
  80. package/dist/definition-package.d.ts.map +1 -0
  81. package/dist/definition-package.js +114 -0
  82. package/dist/definition-package.js.map +1 -0
  83. package/dist/definition-tuning-approval.d.ts +39 -0
  84. package/dist/definition-tuning-approval.d.ts.map +1 -0
  85. package/dist/definition-tuning-approval.js +207 -0
  86. package/dist/definition-tuning-approval.js.map +1 -0
  87. package/dist/definition-tuning-json.d.ts +58 -0
  88. package/dist/definition-tuning-json.d.ts.map +1 -0
  89. package/dist/definition-tuning-json.js +276 -0
  90. package/dist/definition-tuning-json.js.map +1 -0
  91. package/dist/definition-tuning-promotion.d.ts +120 -0
  92. package/dist/definition-tuning-promotion.d.ts.map +1 -0
  93. package/dist/definition-tuning-promotion.js +460 -0
  94. package/dist/definition-tuning-promotion.js.map +1 -0
  95. package/dist/definition-tuning-replay.d.ts +14 -0
  96. package/dist/definition-tuning-replay.d.ts.map +1 -0
  97. package/dist/definition-tuning-replay.js +50 -0
  98. package/dist/definition-tuning-replay.js.map +1 -0
  99. package/dist/definition-tuning-review-artifact.d.ts +56 -0
  100. package/dist/definition-tuning-review-artifact.d.ts.map +1 -0
  101. package/dist/definition-tuning-review-artifact.js +302 -0
  102. package/dist/definition-tuning-review-artifact.js.map +1 -0
  103. package/dist/definition-tuning-review.d.ts +59 -0
  104. package/dist/definition-tuning-review.d.ts.map +1 -0
  105. package/dist/definition-tuning-review.js +213 -0
  106. package/dist/definition-tuning-review.js.map +1 -0
  107. package/dist/definition-tuning-source-patch.d.ts +43 -0
  108. package/dist/definition-tuning-source-patch.d.ts.map +1 -0
  109. package/dist/definition-tuning-source-patch.js +214 -0
  110. package/dist/definition-tuning-source-patch.js.map +1 -0
  111. package/dist/definition-tuning.d.ts +73 -0
  112. package/dist/definition-tuning.d.ts.map +1 -0
  113. package/dist/definition-tuning.js +426 -0
  114. package/dist/definition-tuning.js.map +1 -0
  115. package/dist/definition.d.ts +189 -0
  116. package/dist/definition.d.ts.map +1 -0
  117. package/dist/definition.js +494 -0
  118. package/dist/definition.js.map +1 -0
  119. package/dist/direct-route-invocation.d.ts +132 -0
  120. package/dist/direct-route-invocation.d.ts.map +1 -0
  121. package/dist/direct-route-invocation.js +325 -0
  122. package/dist/direct-route-invocation.js.map +1 -0
  123. package/dist/direct-route-policy.d.ts +25 -0
  124. package/dist/direct-route-policy.d.ts.map +1 -0
  125. package/dist/direct-route-policy.js +106 -0
  126. package/dist/direct-route-policy.js.map +1 -0
  127. package/dist/eval-case.d.ts +85 -0
  128. package/dist/eval-case.d.ts.map +1 -0
  129. package/dist/eval-case.js +366 -0
  130. package/dist/eval-case.js.map +1 -0
  131. package/dist/eval-replay.d.ts +18 -0
  132. package/dist/eval-replay.d.ts.map +1 -0
  133. package/dist/eval-replay.js +41 -0
  134. package/dist/eval-replay.js.map +1 -0
  135. package/dist/eval-result.d.ts +46 -0
  136. package/dist/eval-result.d.ts.map +1 -0
  137. package/dist/eval-result.js +183 -0
  138. package/dist/eval-result.js.map +1 -0
  139. package/dist/eval-runner.d.ts +30 -0
  140. package/dist/eval-runner.d.ts.map +1 -0
  141. package/dist/eval-runner.js +57 -0
  142. package/dist/eval-runner.js.map +1 -0
  143. package/dist/eval-suite.d.ts +43 -0
  144. package/dist/eval-suite.d.ts.map +1 -0
  145. package/dist/eval-suite.js +101 -0
  146. package/dist/eval-suite.js.map +1 -0
  147. package/dist/execution-plan.d.ts +43 -0
  148. package/dist/execution-plan.d.ts.map +1 -0
  149. package/dist/execution-plan.js +187 -0
  150. package/dist/execution-plan.js.map +1 -0
  151. package/dist/hosted-tool-policy.d.ts +70 -0
  152. package/dist/hosted-tool-policy.d.ts.map +1 -0
  153. package/dist/hosted-tool-policy.js +228 -0
  154. package/dist/hosted-tool-policy.js.map +1 -0
  155. package/dist/index.d.ts +73 -0
  156. package/dist/index.d.ts.map +1 -0
  157. package/dist/index.js +73 -0
  158. package/dist/index.js.map +1 -0
  159. package/dist/memory-policy.d.ts +55 -0
  160. package/dist/memory-policy.d.ts.map +1 -0
  161. package/dist/memory-policy.js +187 -0
  162. package/dist/memory-policy.js.map +1 -0
  163. package/dist/memory-updates.d.ts +39 -0
  164. package/dist/memory-updates.d.ts.map +1 -0
  165. package/dist/memory-updates.js +110 -0
  166. package/dist/memory-updates.js.map +1 -0
  167. package/dist/outcome-trace.d.ts +79 -0
  168. package/dist/outcome-trace.d.ts.map +1 -0
  169. package/dist/outcome-trace.js +117 -0
  170. package/dist/outcome-trace.js.map +1 -0
  171. package/dist/outcome.d.ts +97 -0
  172. package/dist/outcome.d.ts.map +1 -0
  173. package/dist/outcome.js +160 -0
  174. package/dist/outcome.js.map +1 -0
  175. package/dist/planner-compiler.d.ts +14 -0
  176. package/dist/planner-compiler.d.ts.map +1 -0
  177. package/dist/planner-compiler.js +26 -0
  178. package/dist/planner-compiler.js.map +1 -0
  179. package/dist/planning.d.ts +36 -0
  180. package/dist/planning.d.ts.map +1 -0
  181. package/dist/planning.js +141 -0
  182. package/dist/planning.js.map +1 -0
  183. package/dist/policy-resolution.d.ts +10 -0
  184. package/dist/policy-resolution.d.ts.map +1 -0
  185. package/dist/policy-resolution.js +30 -0
  186. package/dist/policy-resolution.js.map +1 -0
  187. package/dist/run-evaluation.d.ts +29 -0
  188. package/dist/run-evaluation.d.ts.map +1 -0
  189. package/dist/run-evaluation.js +128 -0
  190. package/dist/run-evaluation.js.map +1 -0
  191. package/dist/run-parity.d.ts +24 -0
  192. package/dist/run-parity.d.ts.map +1 -0
  193. package/dist/run-parity.js +36 -0
  194. package/dist/run-parity.js.map +1 -0
  195. package/dist/run-report-batch.d.ts +150 -0
  196. package/dist/run-report-batch.d.ts.map +1 -0
  197. package/dist/run-report-batch.js +391 -0
  198. package/dist/run-report-batch.js.map +1 -0
  199. package/dist/run-report-json.d.ts +76 -0
  200. package/dist/run-report-json.d.ts.map +1 -0
  201. package/dist/run-report-json.js +451 -0
  202. package/dist/run-report-json.js.map +1 -0
  203. package/dist/run-report.d.ts +22 -0
  204. package/dist/run-report.d.ts.map +1 -0
  205. package/dist/run-report.js +46 -0
  206. package/dist/run-report.js.map +1 -0
  207. package/dist/run.d.ts +20 -0
  208. package/dist/run.d.ts.map +1 -0
  209. package/dist/run.js +36 -0
  210. package/dist/run.js.map +1 -0
  211. package/dist/tool-bindings.d.ts +42 -0
  212. package/dist/tool-bindings.d.ts.map +1 -0
  213. package/dist/tool-bindings.js +124 -0
  214. package/dist/tool-bindings.js.map +1 -0
  215. package/dist/tool-capabilities.d.ts +37 -0
  216. package/dist/tool-capabilities.d.ts.map +1 -0
  217. package/dist/tool-capabilities.js +91 -0
  218. package/dist/tool-capabilities.js.map +1 -0
  219. package/dist/tool-executor.d.ts +63 -0
  220. package/dist/tool-executor.d.ts.map +1 -0
  221. package/dist/tool-executor.js +176 -0
  222. package/dist/tool-executor.js.map +1 -0
  223. package/dist/tool-fixtures.d.ts +18 -0
  224. package/dist/tool-fixtures.d.ts.map +1 -0
  225. package/dist/tool-fixtures.js +52 -0
  226. package/dist/tool-fixtures.js.map +1 -0
  227. package/dist/tool-invocations.d.ts +31 -0
  228. package/dist/tool-invocations.d.ts.map +1 -0
  229. package/dist/tool-invocations.js +79 -0
  230. package/dist/tool-invocations.js.map +1 -0
  231. package/dist/tool-provider-executors.d.ts +43 -0
  232. package/dist/tool-provider-executors.d.ts.map +1 -0
  233. package/dist/tool-provider-executors.js +59 -0
  234. package/dist/tool-provider-executors.js.map +1 -0
  235. package/dist/tool-result-cache.d.ts +37 -0
  236. package/dist/tool-result-cache.d.ts.map +1 -0
  237. package/dist/tool-result-cache.js +173 -0
  238. package/dist/tool-result-cache.js.map +1 -0
  239. package/dist/tool-results.d.ts +41 -0
  240. package/dist/tool-results.d.ts.map +1 -0
  241. package/dist/tool-results.js +137 -0
  242. package/dist/tool-results.js.map +1 -0
  243. package/dist/tool-runtime.d.ts +46 -0
  244. package/dist/tool-runtime.d.ts.map +1 -0
  245. package/dist/tool-runtime.js +163 -0
  246. package/dist/tool-runtime.js.map +1 -0
  247. package/dist/tool-selection-evaluation.d.ts +214 -0
  248. package/dist/tool-selection-evaluation.d.ts.map +1 -0
  249. package/dist/tool-selection-evaluation.js +773 -0
  250. package/dist/tool-selection-evaluation.js.map +1 -0
  251. package/dist/tool-selection-json.d.ts +71 -0
  252. package/dist/tool-selection-json.d.ts.map +1 -0
  253. package/dist/tool-selection-json.js +284 -0
  254. package/dist/tool-selection-json.js.map +1 -0
  255. package/dist/tool-selection-policy.d.ts +81 -0
  256. package/dist/tool-selection-policy.d.ts.map +1 -0
  257. package/dist/tool-selection-policy.js +376 -0
  258. package/dist/tool-selection-policy.js.map +1 -0
  259. package/dist/tool-selection-replay.d.ts +26 -0
  260. package/dist/tool-selection-replay.d.ts.map +1 -0
  261. package/dist/tool-selection-replay.js +88 -0
  262. package/dist/tool-selection-replay.js.map +1 -0
  263. package/dist/tool-selection-rules.d.ts +46 -0
  264. package/dist/tool-selection-rules.d.ts.map +1 -0
  265. package/dist/tool-selection-rules.js +183 -0
  266. package/dist/tool-selection-rules.js.map +1 -0
  267. package/dist/tool-selection-trace-export.d.ts +37 -0
  268. package/dist/tool-selection-trace-export.d.ts.map +1 -0
  269. package/dist/tool-selection-trace-export.js +324 -0
  270. package/dist/tool-selection-trace-export.js.map +1 -0
  271. package/dist/trace-events.d.ts +14 -0
  272. package/dist/trace-events.d.ts.map +1 -0
  273. package/dist/trace-events.js +65 -0
  274. package/dist/trace-events.js.map +1 -0
  275. package/dist/trace-payload.d.ts +24 -0
  276. package/dist/trace-payload.d.ts.map +1 -0
  277. package/dist/trace-payload.js +113 -0
  278. package/dist/trace-payload.js.map +1 -0
  279. package/dist/trace-replay.d.ts +276 -0
  280. package/dist/trace-replay.d.ts.map +1 -0
  281. package/dist/trace-replay.js +685 -0
  282. package/dist/trace-replay.js.map +1 -0
  283. package/dist/trace-report.d.ts +320 -0
  284. package/dist/trace-report.d.ts.map +1 -0
  285. package/dist/trace-report.js +1394 -0
  286. package/dist/trace-report.js.map +1 -0
  287. package/dist/trace-stages.d.ts +70 -0
  288. package/dist/trace-stages.d.ts.map +1 -0
  289. package/dist/trace-stages.js +103 -0
  290. package/dist/trace-stages.js.map +1 -0
  291. package/dist/value-readers.d.ts +20 -0
  292. package/dist/value-readers.d.ts.map +1 -0
  293. package/dist/value-readers.js +82 -0
  294. package/dist/value-readers.js.map +1 -0
  295. package/package.json +341 -0
@@ -0,0 +1,173 @@
1
+ const TTL_LIVE_MS = 30_000;
2
+ const TTL_RECENT_MS = 5 * 60_000;
3
+ const TTL_DAY_MS = 30 * 60_000;
4
+ const TTL_HISTORICAL_MS = 2 * 60 * 60_000;
5
+ const TTL_NO_RANGE_MS = 15 * 60_000;
6
+ export function chooseAssistantWorkflowToolResultCacheTtlMs(args, nowMs) {
7
+ const toMs = parseIsoMs(args["to"]);
8
+ if (toMs === null)
9
+ return TTL_NO_RANGE_MS;
10
+ const ageMs = nowMs - toMs;
11
+ if (ageMs < 5 * 60_000)
12
+ return TTL_LIVE_MS;
13
+ if (ageMs < 60 * 60_000)
14
+ return TTL_RECENT_MS;
15
+ if (ageMs < 24 * 60 * 60_000)
16
+ return TTL_DAY_MS;
17
+ return TTL_HISTORICAL_MS;
18
+ }
19
+ export function buildAssistantWorkflowToolResultCacheKey(scopeId, toolName, args, options = {}) {
20
+ const sortArrayArgKeys = new Set(options.sortArrayArgKeys ?? []);
21
+ const normalizedArgs = {};
22
+ for (const [key, value] of Object.entries(args)) {
23
+ if (sortArrayArgKeys.has(key) && Array.isArray(value)) {
24
+ normalizedArgs[key] = [...value]
25
+ .filter((entry) => typeof entry === "string")
26
+ .sort();
27
+ }
28
+ else {
29
+ normalizedArgs[key] = value;
30
+ }
31
+ }
32
+ return JSON.stringify({
33
+ t: scopeId,
34
+ n: toolName,
35
+ a: normalizeToolResultCacheValue(normalizedArgs),
36
+ });
37
+ }
38
+ export function normalizeToolResultCacheValue(value) {
39
+ if (value === undefined || value === null)
40
+ return null;
41
+ if (typeof value === "string") {
42
+ const parsed = Date.parse(value);
43
+ if (Number.isFinite(parsed) && /\d{4}-\d{2}-\d{2}T/.test(value)) {
44
+ return { __ts: parsed };
45
+ }
46
+ return value;
47
+ }
48
+ if (typeof value === "number" && Number.isFinite(value))
49
+ return value;
50
+ if (typeof value === "boolean")
51
+ return value;
52
+ if (Array.isArray(value)) {
53
+ return value.map(normalizeToolResultCacheValue);
54
+ }
55
+ if (typeof value === "object") {
56
+ const record = value;
57
+ const out = {};
58
+ const keys = Object.keys(record).sort();
59
+ for (const key of keys) {
60
+ const normalized = normalizeToolResultCacheValue(record[key]);
61
+ if (normalized !== null)
62
+ out[key] = normalized;
63
+ }
64
+ return out;
65
+ }
66
+ return String(value);
67
+ }
68
+ export class AssistantWorkflowToolResultCache {
69
+ cache = new Map();
70
+ maxEntries;
71
+ cacheableToolNames;
72
+ isCacheableToolFn;
73
+ sortArrayArgKeys;
74
+ chooseTtlMsFn;
75
+ shouldCacheValueFn;
76
+ stats = {
77
+ hits: 0,
78
+ misses: 0,
79
+ evictions: 0,
80
+ expirations: 0,
81
+ size: 0,
82
+ };
83
+ constructor(options = {}) {
84
+ this.maxEntries = Math.max(1, options.maxEntries ?? 500);
85
+ this.cacheableToolNames = options.cacheableToolNames
86
+ ? new Set(options.cacheableToolNames)
87
+ : null;
88
+ this.isCacheableToolFn = options.isCacheableTool ?? null;
89
+ this.sortArrayArgKeys = [...(options.sortArrayArgKeys ?? [])];
90
+ this.chooseTtlMsFn = options.chooseTtlMs ?? chooseAssistantWorkflowToolResultCacheTtlMs;
91
+ this.shouldCacheValueFn = options.shouldCacheValue ?? defaultShouldCacheToolResultValue;
92
+ }
93
+ isCacheableTool(toolName) {
94
+ if (this.isCacheableToolFn)
95
+ return this.isCacheableToolFn(toolName);
96
+ if (!this.cacheableToolNames)
97
+ return true;
98
+ return this.cacheableToolNames.has(toolName);
99
+ }
100
+ get(scopeId, toolName, args, nowMs) {
101
+ if (!this.isCacheableTool(toolName))
102
+ return null;
103
+ const key = this.buildKey(scopeId, toolName, args);
104
+ const entry = this.cache.get(key);
105
+ if (!entry) {
106
+ this.stats.misses += 1;
107
+ return null;
108
+ }
109
+ if (entry.expiresAt <= nowMs) {
110
+ this.cache.delete(key);
111
+ this.stats.expirations += 1;
112
+ this.stats.misses += 1;
113
+ this.stats.size = this.cache.size;
114
+ return null;
115
+ }
116
+ this.cache.delete(key);
117
+ this.cache.set(key, entry);
118
+ this.stats.hits += 1;
119
+ return entry.value;
120
+ }
121
+ set(scopeId, toolName, args, value, nowMs) {
122
+ if (!this.isCacheableTool(toolName))
123
+ return;
124
+ if (!this.shouldCacheValueFn(value))
125
+ return;
126
+ const key = this.buildKey(scopeId, toolName, args);
127
+ const ttlMs = this.chooseTtlMsFn(args, nowMs);
128
+ const expiresAt = nowMs + ttlMs;
129
+ if (this.cache.has(key)) {
130
+ this.cache.delete(key);
131
+ }
132
+ else if (this.cache.size >= this.maxEntries) {
133
+ const oldestKey = this.cache.keys().next().value;
134
+ if (typeof oldestKey === "string") {
135
+ this.cache.delete(oldestKey);
136
+ this.stats.evictions += 1;
137
+ }
138
+ }
139
+ this.cache.set(key, { value, expiresAt, key });
140
+ this.stats.size = this.cache.size;
141
+ }
142
+ clearScope(scopeId) {
143
+ const prefix = JSON.stringify({ t: scopeId }).slice(0, -1);
144
+ for (const [key] of this.cache) {
145
+ if (key.startsWith(prefix)) {
146
+ this.cache.delete(key);
147
+ }
148
+ }
149
+ this.stats.size = this.cache.size;
150
+ }
151
+ clear() {
152
+ this.cache.clear();
153
+ this.stats.size = 0;
154
+ }
155
+ getStats() {
156
+ return { ...this.stats };
157
+ }
158
+ buildKey(scopeId, toolName, args) {
159
+ return buildAssistantWorkflowToolResultCacheKey(scopeId, toolName, args, {
160
+ sortArrayArgKeys: this.sortArrayArgKeys,
161
+ });
162
+ }
163
+ }
164
+ function defaultShouldCacheToolResultValue(value) {
165
+ return typeof value === "string" && value.length > 0 && !value.startsWith("Error:");
166
+ }
167
+ function parseIsoMs(value) {
168
+ if (typeof value !== "string")
169
+ return null;
170
+ const parsed = Date.parse(value);
171
+ return Number.isFinite(parsed) ? parsed : null;
172
+ }
173
+ //# sourceMappingURL=tool-result-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-result-cache.js","sourceRoot":"","sources":["../src/tool-result-cache.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,MAAM,aAAa,GAAG,CAAC,GAAG,MAAM,CAAC;AACjC,MAAM,UAAU,GAAG,EAAE,GAAG,MAAM,CAAC;AAC/B,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC;AAC1C,MAAM,eAAe,GAAG,EAAE,GAAG,MAAM,CAAC;AAEpC,MAAM,UAAU,2CAA2C,CACzD,IAA6B,EAC7B,KAAa;IAEb,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACpC,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,eAAe,CAAC;IAC1C,MAAM,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC;IAC3B,IAAI,KAAK,GAAG,CAAC,GAAG,MAAM;QAAE,OAAO,WAAW,CAAC;IAC3C,IAAI,KAAK,GAAG,EAAE,GAAG,MAAM;QAAE,OAAO,aAAa,CAAC;IAC9C,IAAI,KAAK,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM;QAAE,OAAO,UAAU,CAAC;IAChD,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,wCAAwC,CACtD,OAAe,EACf,QAAgB,EAChB,IAA6B,EAC7B,UAA6E,EAAE;IAE/E,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;IACjE,MAAM,cAAc,GAA4B,EAAE,CAAC;IACnD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,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ED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACjD,CAAC","sourcesContent":["export type AssistantWorkflowToolResultCacheStats = {\n hits: number;\n misses: number;\n evictions: number;\n expirations: number;\n size: number;\n};\n\nexport type AssistantWorkflowToolResultCacheOptions = {\n maxEntries?: number;\n cacheableToolNames?: ReadonlySet<string> | readonly string[] | null;\n isCacheableTool?: (toolName: string) => boolean;\n sortArrayArgKeys?: readonly string[];\n chooseTtlMs?: (args: Record<string, unknown>, nowMs: number) => number;\n shouldCacheValue?: (value: string) => boolean;\n};\n\ntype CacheEntry = {\n value: string;\n expiresAt: number;\n key: string;\n};\n\nconst TTL_LIVE_MS = 30_000;\nconst TTL_RECENT_MS = 5 * 60_000;\nconst TTL_DAY_MS = 30 * 60_000;\nconst TTL_HISTORICAL_MS = 2 * 60 * 60_000;\nconst TTL_NO_RANGE_MS = 15 * 60_000;\n\nexport function chooseAssistantWorkflowToolResultCacheTtlMs(\n args: Record<string, unknown>,\n nowMs: number,\n): number {\n const toMs = parseIsoMs(args[\"to\"]);\n if (toMs === null) return TTL_NO_RANGE_MS;\n const ageMs = nowMs - toMs;\n if (ageMs < 5 * 60_000) return TTL_LIVE_MS;\n if (ageMs < 60 * 60_000) return TTL_RECENT_MS;\n if (ageMs < 24 * 60 * 60_000) return TTL_DAY_MS;\n return TTL_HISTORICAL_MS;\n}\n\nexport function buildAssistantWorkflowToolResultCacheKey(\n scopeId: string,\n toolName: string,\n args: Record<string, unknown>,\n options: Pick<AssistantWorkflowToolResultCacheOptions, \"sortArrayArgKeys\"> = {},\n): string {\n const sortArrayArgKeys = new Set(options.sortArrayArgKeys ?? []);\n const normalizedArgs: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(args)) {\n if (sortArrayArgKeys.has(key) && Array.isArray(value)) {\n normalizedArgs[key] = [...value]\n .filter((entry): entry is string => typeof entry === \"string\")\n .sort();\n } else {\n normalizedArgs[key] = value;\n }\n }\n return JSON.stringify({\n t: scopeId,\n n: toolName,\n a: normalizeToolResultCacheValue(normalizedArgs),\n });\n}\n\nexport function normalizeToolResultCacheValue(value: unknown): unknown {\n if (value === undefined || value === null) return null;\n if (typeof value === \"string\") {\n const parsed = Date.parse(value);\n if (Number.isFinite(parsed) && /\\d{4}-\\d{2}-\\d{2}T/.test(value)) {\n return { __ts: parsed };\n }\n return value;\n }\n if (typeof value === \"number\" && Number.isFinite(value)) return value;\n if (typeof value === \"boolean\") return value;\n if (Array.isArray(value)) {\n return value.map(normalizeToolResultCacheValue);\n }\n if (typeof value === \"object\") {\n const record = value as Record<string, unknown>;\n const out: Record<string, unknown> = {};\n const keys = Object.keys(record).sort();\n for (const key of keys) {\n const normalized = normalizeToolResultCacheValue(record[key]);\n if (normalized !== null) out[key] = normalized;\n }\n return out;\n }\n return String(value);\n}\n\nexport class AssistantWorkflowToolResultCache {\n private readonly cache = new Map<string, CacheEntry>();\n private readonly maxEntries: number;\n private readonly cacheableToolNames: ReadonlySet<string> | null;\n private readonly isCacheableToolFn: ((toolName: string) => boolean) | null;\n private readonly sortArrayArgKeys: readonly string[];\n private readonly chooseTtlMsFn: (args: Record<string, unknown>, nowMs: number) => number;\n private readonly shouldCacheValueFn: (value: string) => boolean;\n private stats: AssistantWorkflowToolResultCacheStats = {\n hits: 0,\n misses: 0,\n evictions: 0,\n expirations: 0,\n size: 0,\n };\n\n constructor(options: AssistantWorkflowToolResultCacheOptions = {}) {\n this.maxEntries = Math.max(1, options.maxEntries ?? 500);\n this.cacheableToolNames = options.cacheableToolNames\n ? new Set(options.cacheableToolNames)\n : null;\n this.isCacheableToolFn = options.isCacheableTool ?? null;\n this.sortArrayArgKeys = [...(options.sortArrayArgKeys ?? [])];\n this.chooseTtlMsFn = options.chooseTtlMs ?? chooseAssistantWorkflowToolResultCacheTtlMs;\n this.shouldCacheValueFn = options.shouldCacheValue ?? defaultShouldCacheToolResultValue;\n }\n\n isCacheableTool(toolName: string): boolean {\n if (this.isCacheableToolFn) return this.isCacheableToolFn(toolName);\n if (!this.cacheableToolNames) return true;\n return this.cacheableToolNames.has(toolName);\n }\n\n get(\n scopeId: string,\n toolName: string,\n args: Record<string, unknown>,\n nowMs: number,\n ): string | null {\n if (!this.isCacheableTool(toolName)) return null;\n const key = this.buildKey(scopeId, toolName, args);\n const entry = this.cache.get(key);\n if (!entry) {\n this.stats.misses += 1;\n return null;\n }\n if (entry.expiresAt <= nowMs) {\n this.cache.delete(key);\n this.stats.expirations += 1;\n this.stats.misses += 1;\n this.stats.size = this.cache.size;\n return null;\n }\n this.cache.delete(key);\n this.cache.set(key, entry);\n this.stats.hits += 1;\n return entry.value;\n }\n\n set(\n scopeId: string,\n toolName: string,\n args: Record<string, unknown>,\n value: string,\n nowMs: number,\n ): void {\n if (!this.isCacheableTool(toolName)) return;\n if (!this.shouldCacheValueFn(value)) return;\n const key = this.buildKey(scopeId, toolName, args);\n const ttlMs = this.chooseTtlMsFn(args, nowMs);\n const expiresAt = nowMs + ttlMs;\n if (this.cache.has(key)) {\n this.cache.delete(key);\n } else if (this.cache.size >= this.maxEntries) {\n const oldestKey = this.cache.keys().next().value;\n if (typeof oldestKey === \"string\") {\n this.cache.delete(oldestKey);\n this.stats.evictions += 1;\n }\n }\n this.cache.set(key, { value, expiresAt, key });\n this.stats.size = this.cache.size;\n }\n\n clearScope(scopeId: string): void {\n const prefix = JSON.stringify({ t: scopeId }).slice(0, -1);\n for (const [key] of this.cache) {\n if (key.startsWith(prefix)) {\n this.cache.delete(key);\n }\n }\n this.stats.size = this.cache.size;\n }\n\n clear(): void {\n this.cache.clear();\n this.stats.size = 0;\n }\n\n getStats(): AssistantWorkflowToolResultCacheStats {\n return { ...this.stats };\n }\n\n private buildKey(\n scopeId: string,\n toolName: string,\n args: Record<string, unknown>,\n ): string {\n return buildAssistantWorkflowToolResultCacheKey(scopeId, toolName, args, {\n sortArrayArgKeys: this.sortArrayArgKeys,\n });\n }\n}\n\nfunction defaultShouldCacheToolResultValue(value: string): boolean {\n return typeof value === \"string\" && value.length > 0 && !value.startsWith(\"Error:\");\n}\n\nfunction parseIsoMs(value: unknown): number | null {\n if (typeof value !== \"string\") return null;\n const parsed = Date.parse(value);\n return Number.isFinite(parsed) ? parsed : null;\n}\n"]}
@@ -0,0 +1,41 @@
1
+ import type { AssistantWorkflowToolProvider } from "./definition.js";
2
+ import type { AssistantWorkflowToolInvocationQueue } from "./tool-invocations.js";
3
+ export type AssistantWorkflowToolResultStatus = "success" | "error" | "skipped";
4
+ export type AssistantWorkflowToolResult = {
5
+ invocationId: string;
6
+ toolName: string;
7
+ stepId: string;
8
+ provider: AssistantWorkflowToolProvider;
9
+ status: AssistantWorkflowToolResultStatus;
10
+ output?: unknown;
11
+ errorMessage?: string;
12
+ retryable?: boolean;
13
+ durationMs?: number;
14
+ };
15
+ export type AssistantWorkflowToolResultSummaryStatus = "complete" | "partial" | "failed" | "empty";
16
+ export type AssistantWorkflowToolResultSummary = {
17
+ status: AssistantWorkflowToolResultSummaryStatus;
18
+ totalInvocations: number;
19
+ resultCount: number;
20
+ successCount: number;
21
+ errorCount: number;
22
+ skippedCount: number;
23
+ retryableErrorCount: number;
24
+ providerSummaries: AssistantWorkflowToolResultProviderSummary[];
25
+ missingResultInvocationIds: string[];
26
+ unexpectedResultInvocationIds: string[];
27
+ };
28
+ export type AssistantWorkflowToolResultProviderSummary = {
29
+ provider: AssistantWorkflowToolProvider;
30
+ resultCount: number;
31
+ successCount: number;
32
+ errorCount: number;
33
+ skippedCount: number;
34
+ };
35
+ export declare function assistantWorkflowToolSuccess(input: Omit<AssistantWorkflowToolResult, "status" | "errorMessage" | "retryable">): AssistantWorkflowToolResult;
36
+ export declare function assistantWorkflowToolError(input: Omit<AssistantWorkflowToolResult, "status" | "output">): AssistantWorkflowToolResult;
37
+ export declare function assistantWorkflowToolSkipped(input: Omit<AssistantWorkflowToolResult, "status" | "output" | "retryable">): AssistantWorkflowToolResult;
38
+ export declare function summarizeAssistantWorkflowToolResults(queue: AssistantWorkflowToolInvocationQueue, results: readonly AssistantWorkflowToolResult[]): AssistantWorkflowToolResultSummary;
39
+ export declare function buildAssistantWorkflowToolResultsTracePayload(queue: AssistantWorkflowToolInvocationQueue, results: readonly AssistantWorkflowToolResult[]): Record<string, unknown>;
40
+ export declare function summarizeAssistantWorkflowToolResultProviders(results: readonly AssistantWorkflowToolResult[]): AssistantWorkflowToolResultProviderSummary[];
41
+ //# sourceMappingURL=tool-results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-results.d.ts","sourceRoot":"","sources":["../src/tool-results.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,uBAAuB,CAAC;AAElF,MAAM,MAAM,iCAAiC,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAEhF,MAAM,MAAM,2BAA2B,GAAG;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,6BAA6B,CAAC;IACxC,MAAM,EAAE,iCAAiC,CAAC;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,wCAAwC,GAChD,UAAU,GACV,SAAS,GACT,QAAQ,GACR,OAAO,CAAC;AAEZ,MAAM,MAAM,kCAAkC,GAAG;IAC/C,MAAM,EAAE,w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,CAiB9C"}
@@ -0,0 +1,137 @@
1
+ export function assistantWorkflowToolSuccess(input) {
2
+ return {
3
+ invocationId: normalizeRequiredString(input.invocationId, "invocationId"),
4
+ toolName: normalizeRequiredString(input.toolName, "toolName"),
5
+ stepId: normalizeRequiredString(input.stepId, "stepId"),
6
+ provider: normalizeToolProvider(input.provider),
7
+ status: "success",
8
+ ...(input.output !== undefined ? { output: input.output } : {}),
9
+ ...(typeof input.durationMs === "number" && Number.isFinite(input.durationMs)
10
+ ? { durationMs: Math.max(0, Math.floor(input.durationMs)) }
11
+ : {}),
12
+ };
13
+ }
14
+ export function assistantWorkflowToolError(input) {
15
+ return {
16
+ invocationId: normalizeRequiredString(input.invocationId, "invocationId"),
17
+ toolName: normalizeRequiredString(input.toolName, "toolName"),
18
+ stepId: normalizeRequiredString(input.stepId, "stepId"),
19
+ provider: normalizeToolProvider(input.provider),
20
+ status: "error",
21
+ errorMessage: normalizeRequiredString(input.errorMessage ?? "", "errorMessage"),
22
+ ...(typeof input.retryable === "boolean" ? { retryable: input.retryable } : {}),
23
+ ...(typeof input.durationMs === "number" && Number.isFinite(input.durationMs)
24
+ ? { durationMs: Math.max(0, Math.floor(input.durationMs)) }
25
+ : {}),
26
+ };
27
+ }
28
+ export function assistantWorkflowToolSkipped(input) {
29
+ return {
30
+ invocationId: normalizeRequiredString(input.invocationId, "invocationId"),
31
+ toolName: normalizeRequiredString(input.toolName, "toolName"),
32
+ stepId: normalizeRequiredString(input.stepId, "stepId"),
33
+ provider: normalizeToolProvider(input.provider),
34
+ status: "skipped",
35
+ errorMessage: normalizeRequiredString(input.errorMessage ?? "", "errorMessage"),
36
+ ...(typeof input.durationMs === "number" && Number.isFinite(input.durationMs)
37
+ ? { durationMs: Math.max(0, Math.floor(input.durationMs)) }
38
+ : {}),
39
+ };
40
+ }
41
+ export function summarizeAssistantWorkflowToolResults(queue, results) {
42
+ const invocationIds = queue.invocations.map((invocation) => invocation.id);
43
+ const invocationIdSet = new Set(invocationIds);
44
+ const resultIdSet = new Set(results.map((result) => result.invocationId));
45
+ const missingResultInvocationIds = invocationIds.filter((id) => !resultIdSet.has(id));
46
+ const unexpectedResultInvocationIds = results
47
+ .map((result) => result.invocationId)
48
+ .filter((id) => !invocationIdSet.has(id));
49
+ const successCount = results.filter((result) => result.status === "success").length;
50
+ const errorCount = results.filter((result) => result.status === "error").length;
51
+ const skippedCount = results.filter((result) => result.status === "skipped").length;
52
+ const retryableErrorCount = results
53
+ .filter((result) => result.status === "error" && result.retryable === true)
54
+ .length;
55
+ return {
56
+ status: resolveToolResultSummaryStatus({
57
+ totalInvocations: queue.invocations.length,
58
+ errorCount,
59
+ missingResultInvocationIds,
60
+ unexpectedResultInvocationIds,
61
+ }),
62
+ totalInvocations: queue.invocations.length,
63
+ resultCount: results.length,
64
+ successCount,
65
+ errorCount,
66
+ skippedCount,
67
+ retryableErrorCount,
68
+ providerSummaries: summarizeAssistantWorkflowToolResultProviders(results),
69
+ missingResultInvocationIds,
70
+ unexpectedResultInvocationIds,
71
+ };
72
+ }
73
+ export function buildAssistantWorkflowToolResultsTracePayload(queue, results) {
74
+ return {
75
+ ...summarizeAssistantWorkflowToolResults(queue, results),
76
+ results: results.map((result) => ({
77
+ invocationId: result.invocationId,
78
+ toolName: result.toolName,
79
+ stepId: result.stepId,
80
+ provider: result.provider,
81
+ status: result.status,
82
+ hasOutput: result.output !== undefined,
83
+ errorMessage: result.errorMessage ?? null,
84
+ retryable: result.retryable ?? null,
85
+ durationMs: result.durationMs ?? null,
86
+ })),
87
+ };
88
+ }
89
+ export function summarizeAssistantWorkflowToolResultProviders(results) {
90
+ const summaries = new Map();
91
+ for (const result of results) {
92
+ const summary = summaries.get(result.provider) ?? {
93
+ provider: result.provider,
94
+ resultCount: 0,
95
+ successCount: 0,
96
+ errorCount: 0,
97
+ skippedCount: 0,
98
+ };
99
+ summary.resultCount += 1;
100
+ if (result.status === "success")
101
+ summary.successCount += 1;
102
+ if (result.status === "error")
103
+ summary.errorCount += 1;
104
+ if (result.status === "skipped")
105
+ summary.skippedCount += 1;
106
+ summaries.set(result.provider, summary);
107
+ }
108
+ return [...summaries.values()].sort((left, right) => left.provider.localeCompare(right.provider));
109
+ }
110
+ function resolveToolResultSummaryStatus(input) {
111
+ if (input.totalInvocations === 0)
112
+ return "empty";
113
+ if (input.errorCount > 0)
114
+ return "failed";
115
+ if (input.missingResultInvocationIds.length > 0 || input.unexpectedResultInvocationIds.length > 0) {
116
+ return "partial";
117
+ }
118
+ return "complete";
119
+ }
120
+ function normalizeRequiredString(value, fieldName) {
121
+ const trimmed = value.trim();
122
+ if (!trimmed.length) {
123
+ throw new Error(`Assistant workflow tool result ${fieldName} is required.`);
124
+ }
125
+ return trimmed;
126
+ }
127
+ function normalizeToolProvider(value) {
128
+ if (value === "local-function" ||
129
+ value === "http" ||
130
+ value === "mcp" ||
131
+ value === "openai-hosted" ||
132
+ value === "repl") {
133
+ return value;
134
+ }
135
+ throw new Error("Assistant workflow tool result provider is invalid.");
136
+ }
137
+ //# sourceMappingURL=tool-results.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-results.js","sourceRoot":"","sources":["../src/tool-results.ts"],"names":[],"mappings":"AA4CA,MAAM,UAAU,4BAA4B,CAC1C,KAAiF;IAEjF,OAAO;QACL,YAAY,EAAE,uBAAuB,CAAC,KAAK,CAAC,YAAY,EAAE,cAAc,CAAC;QACzE,QAAQ,EAAE,uBAAuB,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC7D,MAAM,EAAE,uBAAuB,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC;QACvD,QAAQ,EAAE,qBAAqB,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC/C,MAAM,EAAE,SAAS;QACjB,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,G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O,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;AACpG,CAAC;AAED,SAAS,8BAA8B,CAAC,KAKvC;IACC,IAAI,KAAK,CAAC,gBAAgB,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACjD,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC1C,IAAI,KAAK,CAAC,0BAA0B,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,6BAA6B,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClG,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAa,EAAE,SAAiB;IAC/D,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,kCAAkC,SAAS,eAAe,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAoC;IACjE,IACE,KAAK,KAAK,gBAAgB;QAC1B,KAAK,KAAK,MAAM;QAChB,KAAK,KAAK,KAAK;QACf,KAAK,KAAK,eAAe;QACzB,KAAK,KAAK,MAAM,EAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import type { AssistantWorkflowToolProvider } from \"./definition.js\";\nimport type { AssistantWorkflowToolInvocationQueue } from \"./tool-invocations.js\";\n\nexport type AssistantWorkflowToolResultStatus = \"success\" | \"error\" | \"skipped\";\n\nexport type AssistantWorkflowToolResult = {\n invocationId: string;\n toolName: string;\n stepId: string;\n provider: AssistantWorkflowToolProvider;\n status: AssistantWorkflowToolResultStatus;\n output?: unknown;\n errorMessage?: string;\n retryable?: boolean;\n durationMs?: number;\n};\n\nexport type AssistantWorkflowToolResultSummaryStatus =\n | \"complete\"\n | \"partial\"\n | \"failed\"\n | \"empty\";\n\nexport type AssistantWorkflowToolResultSummary = {\n status: AssistantWorkflowToolResultSummaryStatus;\n totalInvocations: number;\n resultCount: number;\n successCount: number;\n errorCount: number;\n skippedCount: number;\n retryableErrorCount: number;\n providerSummaries: AssistantWorkflowToolResultProviderSummary[];\n missingResultInvocationIds: string[];\n unexpectedResultInvocationIds: string[];\n};\n\nexport type AssistantWorkflowToolResultProviderSummary = {\n provider: AssistantWorkflowToolProvider;\n resultCount: number;\n successCount: number;\n errorCount: number;\n skippedCount: number;\n};\n\nexport function assistantWorkflowToolSuccess(\n input: Omit<AssistantWorkflowToolResult, \"status\" | \"errorMessage\" | \"retryable\">,\n): AssistantWorkflowToolResult {\n return {\n invocationId: normalizeRequiredString(input.invocationId, \"invocationId\"),\n toolName: normalizeRequiredString(input.toolName, \"toolName\"),\n stepId: normalizeRequiredString(input.stepId, \"stepId\"),\n provider: normalizeToolProvider(input.provider),\n status: \"success\",\n ...(input.output !== undefined ? { output: input.output } : {}),\n ...(typeof input.durationMs === \"number\" && Number.isFinite(input.durationMs)\n ? { durationMs: Math.max(0, Math.floor(input.durationMs)) }\n : {}),\n };\n}\n\nexport function assistantWorkflowToolError(\n input: Omit<AssistantWorkflowToolResult, \"status\" | \"output\">,\n): AssistantWorkflowToolResult {\n return {\n invocationId: normalizeRequiredString(input.invocationId, \"invocationId\"),\n toolName: normalizeRequiredString(input.toolName, \"toolName\"),\n stepId: normalizeRequiredString(input.stepId, \"stepId\"),\n provider: normalizeToolProvider(input.provider),\n status: \"error\",\n errorMessage: normalizeRequiredString(input.errorMessage ?? \"\", \"errorMessage\"),\n ...(typeof input.retryable === \"boolean\" ? { retryable: input.retryable } : {}),\n ...(typeof input.durationMs === \"number\" && Number.isFinite(input.durationMs)\n ? { durationMs: Math.max(0, Math.floor(input.durationMs)) }\n : {}),\n };\n}\n\nexport function assistantWorkflowToolSkipped(\n input: Omit<AssistantWorkflowToolResult, \"status\" | \"output\" | \"retryable\">,\n): AssistantWorkflowToolResult {\n return {\n invocationId: normalizeRequiredString(input.invocationId, \"invocationId\"),\n toolName: normalizeRequiredString(input.toolName, \"toolName\"),\n stepId: normalizeRequiredString(input.stepId, \"stepId\"),\n provider: normalizeToolProvider(input.provider),\n status: \"skipped\",\n errorMessage: normalizeRequiredString(input.errorMessage ?? \"\", \"errorMessage\"),\n ...(typeof input.durationMs === \"number\" && Number.isFinite(input.durationMs)\n ? { durationMs: Math.max(0, Math.floor(input.durationMs)) }\n : {}),\n };\n}\n\nexport function summarizeAssistantWorkflowToolResults(\n queue: AssistantWorkflowToolInvocationQueue,\n results: readonly AssistantWorkflowToolResult[],\n): AssistantWorkflowToolResultSummary {\n const invocationIds = queue.invocations.map((invocation) => invocation.id);\n const invocationIdSet = new Set(invocationIds);\n const resultIdSet = new Set(results.map((result) => result.invocationId));\n const missingResultInvocationIds = invocationIds.filter((id) => !resultIdSet.has(id));\n const unexpectedResultInvocationIds = results\n .map((result) => result.invocationId)\n .filter((id) => !invocationIdSet.has(id));\n const successCount = results.filter((result) => result.status === \"success\").length;\n const errorCount = results.filter((result) => result.status === \"error\").length;\n const skippedCount = results.filter((result) => result.status === \"skipped\").length;\n const retryableErrorCount = results\n .filter((result) => result.status === \"error\" && result.retryable === true)\n .length;\n\n return {\n status: resolveToolResultSummaryStatus({\n totalInvocations: queue.invocations.length,\n errorCount,\n missingResultInvocationIds,\n unexpectedResultInvocationIds,\n }),\n totalInvocations: queue.invocations.length,\n resultCount: results.length,\n successCount,\n errorCount,\n skippedCount,\n retryableErrorCount,\n providerSummaries: summarizeAssistantWorkflowToolResultProviders(results),\n missingResultInvocationIds,\n unexpectedResultInvocationIds,\n };\n}\n\nexport function buildAssistantWorkflowToolResultsTracePayload(\n queue: AssistantWorkflowToolInvocationQueue,\n results: readonly AssistantWorkflowToolResult[],\n): Record<string, unknown> {\n return {\n ...summarizeAssistantWorkflowToolResults(queue, results),\n results: results.map((result) => ({\n invocationId: result.invocationId,\n toolName: result.toolName,\n stepId: result.stepId,\n provider: result.provider,\n status: result.status,\n hasOutput: result.output !== undefined,\n errorMessage: result.errorMessage ?? null,\n retryable: result.retryable ?? null,\n durationMs: result.durationMs ?? null,\n })),\n };\n}\n\nexport function summarizeAssistantWorkflowToolResultProviders(\n results: readonly AssistantWorkflowToolResult[],\n): AssistantWorkflowToolResultProviderSummary[] {\n const summaries = new Map<AssistantWorkflowToolProvider, AssistantWorkflowToolResultProviderSummary>();\n for (const result of results) {\n const summary = summaries.get(result.provider) ?? {\n provider: result.provider,\n resultCount: 0,\n successCount: 0,\n errorCount: 0,\n skippedCount: 0,\n };\n summary.resultCount += 1;\n if (result.status === \"success\") summary.successCount += 1;\n if (result.status === \"error\") summary.errorCount += 1;\n if (result.status === \"skipped\") summary.skippedCount += 1;\n summaries.set(result.provider, summary);\n }\n return [...summaries.values()].sort((left, right) => left.provider.localeCompare(right.provider));\n}\n\nfunction resolveToolResultSummaryStatus(input: {\n totalInvocations: number;\n errorCount: number;\n missingResultInvocationIds: readonly string[];\n unexpectedResultInvocationIds: readonly string[];\n}): AssistantWorkflowToolResultSummaryStatus {\n if (input.totalInvocations === 0) return \"empty\";\n if (input.errorCount > 0) return \"failed\";\n if (input.missingResultInvocationIds.length > 0 || input.unexpectedResultInvocationIds.length > 0) {\n return \"partial\";\n }\n return \"complete\";\n}\n\nfunction normalizeRequiredString(value: string, fieldName: string): string {\n const trimmed = value.trim();\n if (!trimmed.length) {\n throw new Error(`Assistant workflow tool result ${fieldName} is required.`);\n }\n return trimmed;\n}\n\nfunction normalizeToolProvider(value: AssistantWorkflowToolProvider): AssistantWorkflowToolProvider {\n if (\n value === \"local-function\" ||\n value === \"http\" ||\n value === \"mcp\" ||\n value === \"openai-hosted\" ||\n value === \"repl\"\n ) {\n return value;\n }\n throw new Error(\"Assistant workflow tool result provider is invalid.\");\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import { type AssistantWorkflowDefinition, type AssistantWorkflowToolBindingDefinition, type AssistantWorkflowToolCapabilityDefinition } from "./definition.js";
2
+ import { type AssistantWorkflowToolPolicyRecommendation } from "./tool-capabilities.js";
3
+ import { type AssistantWorkflowToolResolutionStatus } from "./tool-bindings.js";
4
+ export type AssistantWorkflowToolRuntimeRegistration = {
5
+ name: string;
6
+ enabled: boolean;
7
+ assistantVisible: boolean;
8
+ schemaAssistantVisible: boolean;
9
+ explicitCallAllowed: boolean;
10
+ supportsAssistantVisibility?: boolean;
11
+ supportsSchemaAssistantVisibility?: boolean;
12
+ supportsExplicitCall?: boolean;
13
+ adapterId?: string | null;
14
+ };
15
+ export type AssistantWorkflowToolRuntimePolicyField = "enabled" | "assistantVisible" | "schemaAssistantVisible" | "explicitCallAllowed";
16
+ export type AssistantWorkflowToolRuntimePolicyMismatch = {
17
+ field: AssistantWorkflowToolRuntimePolicyField;
18
+ expected: boolean;
19
+ actual: boolean;
20
+ };
21
+ export type AssistantWorkflowToolRuntimeResolutionStatus = AssistantWorkflowToolResolutionStatus | "missing-runtime-registration" | "policy-drift";
22
+ export type AssistantWorkflowToolRuntimeResolution = {
23
+ toolName: string;
24
+ status: AssistantWorkflowToolRuntimeResolutionStatus;
25
+ capability: AssistantWorkflowToolCapabilityDefinition | null;
26
+ binding: AssistantWorkflowToolBindingDefinition | null;
27
+ registration: AssistantWorkflowToolRuntimeRegistration | null;
28
+ recommendation: AssistantWorkflowToolPolicyRecommendation | null;
29
+ policyMismatches: AssistantWorkflowToolRuntimePolicyMismatch[];
30
+ };
31
+ export type AssistantWorkflowToolRuntimeAudit = {
32
+ resolutions: AssistantWorkflowToolRuntimeResolution[];
33
+ registeredToolNames: string[];
34
+ readyToolNames: string[];
35
+ policyDriftToolNames: string[];
36
+ missingRuntimeRegistrationNames: string[];
37
+ runtimeToolWithoutCapabilityNames: string[];
38
+ missingBindingNames: string[];
39
+ providerMismatchNames: string[];
40
+ duplicateRuntimeRegistrationNames: string[];
41
+ };
42
+ export declare function resolveAssistantWorkflowToolRuntime(workflow: AssistantWorkflowDefinition<string, string, string, string>, registrations: readonly AssistantWorkflowToolRuntimeRegistration[], toolName: unknown): AssistantWorkflowToolRuntimeResolution;
43
+ export declare function buildAssistantWorkflowToolRuntimeAudit(workflow: AssistantWorkflowDefinition<string, string, string, string>, registrations: readonly AssistantWorkflowToolRuntimeRegistration[]): AssistantWorkflowToolRuntimeAudit;
44
+ export declare function buildAssistantWorkflowToolRuntimeResolutionTracePayload(resolution: AssistantWorkflowToolRuntimeResolution): Record<string, unknown>;
45
+ export declare function buildAssistantWorkflowToolRuntimeAuditTracePayload(audit: AssistantWorkflowToolRuntimeAudit): Record<string, unknown>;
46
+ //# sourceMappingURL=tool-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-runtime.d.ts","sourceRoot":"","sources":["../src/tool-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,2BAA2B,EAChC,KAAK,sCAAsC,EAC3C,KAAK,yCAAyC,EAC/C,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,KAAK,yCAAyC,EAC/C,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,KAAK,qCAAqC,EAC3C,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,sBAAsB,EAAE,OAAO,CAAC;IAChC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC,iCAAiC,CAAC,EAAE,OAAO,CAAC;IAC5C,oBAAoB,CAAC,EAAE,OAAO,C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wC,EAAE,EAClE,QAAQ,EAAE,OAAO,GAChB,sCAAsC,CAwDxC;AAED,wBAAgB,sCAAsC,CACpD,QAAQ,EAAE,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACrE,aAAa,EAAE,SAAS,wCAAwC,EAAE,GACjE,iCAAiC,CA+BnC;AAED,wBAAgB,uDAAuD,CACrE,UAAU,EAAE,sCAAsC,GACjD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzB;AAED,wBAAgB,kDAAkD,CAChE,KAAK,EAAE,iCAAiC,GACvC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAWzB"}
@@ -0,0 +1,163 @@
1
+ import { normalizeAssistantWorkflowId, } from "./definition.js";
2
+ import { buildAssistantWorkflowToolPolicyRecommendation, } from "./tool-capabilities.js";
3
+ import { resolveAssistantWorkflowTools, } from "./tool-bindings.js";
4
+ export function resolveAssistantWorkflowToolRuntime(workflow, registrations, toolName) {
5
+ const normalizedToolName = normalizeAssistantWorkflowId(toolName) ?? "";
6
+ const staticResolution = resolveAssistantWorkflowTools(workflow, [normalizedToolName]).resolutions[0] ?? null;
7
+ const registration = findAssistantWorkflowToolRuntimeRegistration(registrations, normalizedToolName);
8
+ const capability = staticResolution?.capability ?? null;
9
+ const binding = staticResolution?.binding ?? null;
10
+ const recommendation = capability
11
+ ? buildAssistantWorkflowToolPolicyRecommendation(capability)
12
+ : null;
13
+ if (!staticResolution) {
14
+ return {
15
+ toolName: normalizedToolName,
16
+ status: "missing-capability",
17
+ capability,
18
+ binding,
19
+ registration,
20
+ recommendation,
21
+ policyMismatches: [],
22
+ };
23
+ }
24
+ if (staticResolution.status !== "ready") {
25
+ return {
26
+ toolName: normalizedToolName,
27
+ status: staticResolution.status,
28
+ capability,
29
+ binding,
30
+ registration,
31
+ recommendation,
32
+ policyMismatches: [],
33
+ };
34
+ }
35
+ if (!registration) {
36
+ return {
37
+ toolName: normalizedToolName,
38
+ status: "missing-runtime-registration",
39
+ capability,
40
+ binding,
41
+ registration: null,
42
+ recommendation,
43
+ policyMismatches: [],
44
+ };
45
+ }
46
+ const policyMismatches = recommendation
47
+ ? buildPolicyMismatches(recommendation, registration)
48
+ : [];
49
+ return {
50
+ toolName: normalizedToolName,
51
+ status: policyMismatches.length ? "policy-drift" : "ready",
52
+ capability,
53
+ binding,
54
+ registration,
55
+ recommendation,
56
+ policyMismatches,
57
+ };
58
+ }
59
+ export function buildAssistantWorkflowToolRuntimeAudit(workflow, registrations) {
60
+ const normalizedRegistrations = normalizeRuntimeRegistrations(registrations);
61
+ const resolutions = (workflow.tools ?? []).map((tool) => resolveAssistantWorkflowToolRuntime(workflow, normalizedRegistrations.registrations, tool.name));
62
+ const workflowToolNames = new Set((workflow.tools ?? []).map((tool) => tool.name));
63
+ const runtimeToolWithoutCapabilityNames = normalizedRegistrations.registrations
64
+ .map((registration) => registration.name)
65
+ .filter((toolName) => !workflowToolNames.has(toolName));
66
+ return {
67
+ resolutions,
68
+ registeredToolNames: normalizedRegistrations.registrations.map((registration) => registration.name),
69
+ readyToolNames: resolutions
70
+ .filter((resolution) => resolution.status === "ready")
71
+ .map((resolution) => resolution.toolName),
72
+ policyDriftToolNames: resolutions
73
+ .filter((resolution) => resolution.status === "policy-drift")
74
+ .map((resolution) => resolution.toolName),
75
+ missingRuntimeRegistrationNames: (workflow.tools ?? [])
76
+ .map((tool) => tool.name)
77
+ .filter((toolName) => !normalizedRegistrations.registrations.some((registration) => registration.name === toolName)),
78
+ runtimeToolWithoutCapabilityNames,
79
+ missingBindingNames: resolutions
80
+ .filter((resolution) => resolution.status === "missing-binding")
81
+ .map((resolution) => resolution.toolName),
82
+ providerMismatchNames: resolutions
83
+ .filter((resolution) => resolution.status === "provider-mismatch")
84
+ .map((resolution) => resolution.toolName),
85
+ duplicateRuntimeRegistrationNames: normalizedRegistrations.duplicateNames,
86
+ };
87
+ }
88
+ export function buildAssistantWorkflowToolRuntimeResolutionTracePayload(resolution) {
89
+ return {
90
+ toolName: resolution.toolName,
91
+ status: resolution.status,
92
+ capabilityProvider: resolution.capability?.provider ?? null,
93
+ bindingProvider: resolution.binding?.provider ?? null,
94
+ runtimeAdapterId: resolution.registration?.adapterId ?? null,
95
+ policyMismatches: resolution.policyMismatches,
96
+ };
97
+ }
98
+ export function buildAssistantWorkflowToolRuntimeAuditTracePayload(audit) {
99
+ return {
100
+ registeredToolCount: audit.registeredToolNames.length,
101
+ readyToolNames: audit.readyToolNames,
102
+ policyDriftToolNames: audit.policyDriftToolNames,
103
+ missingRuntimeRegistrationNames: audit.missingRuntimeRegistrationNames,
104
+ runtimeToolWithoutCapabilityNames: audit.runtimeToolWithoutCapabilityNames,
105
+ missingBindingNames: audit.missingBindingNames,
106
+ providerMismatchNames: audit.providerMismatchNames,
107
+ duplicateRuntimeRegistrationNames: audit.duplicateRuntimeRegistrationNames,
108
+ };
109
+ }
110
+ function findAssistantWorkflowToolRuntimeRegistration(registrations, toolName) {
111
+ if (!toolName)
112
+ return null;
113
+ return normalizeRuntimeRegistrations(registrations).registrations
114
+ .find((registration) => registration.name === toolName) ?? null;
115
+ }
116
+ function normalizeRuntimeRegistrations(registrations) {
117
+ const normalized = [];
118
+ const seen = new Set();
119
+ const duplicateNames = [];
120
+ for (const registration of registrations) {
121
+ const name = normalizeAssistantWorkflowId(registration.name);
122
+ if (!name)
123
+ continue;
124
+ if (seen.has(name)) {
125
+ duplicateNames.push(name);
126
+ continue;
127
+ }
128
+ seen.add(name);
129
+ normalized.push({
130
+ name,
131
+ enabled: registration.enabled === true,
132
+ assistantVisible: registration.assistantVisible === true,
133
+ schemaAssistantVisible: registration.schemaAssistantVisible === true,
134
+ explicitCallAllowed: registration.explicitCallAllowed === true,
135
+ supportsAssistantVisibility: registration.supportsAssistantVisibility !== false,
136
+ supportsSchemaAssistantVisibility: registration.supportsSchemaAssistantVisibility !== false,
137
+ supportsExplicitCall: registration.supportsExplicitCall !== false,
138
+ adapterId: normalizeNullableString(registration.adapterId),
139
+ });
140
+ }
141
+ return { registrations: normalized, duplicateNames };
142
+ }
143
+ function buildPolicyMismatches(recommendation, registration) {
144
+ const expected = {
145
+ enabled: recommendation.enabledByDefault,
146
+ assistantVisible: recommendation.assistantVisibleByDefault && registration.supportsAssistantVisibility !== false,
147
+ schemaAssistantVisible: recommendation.schemaAssistantVisibleByDefault && registration.supportsSchemaAssistantVisibility !== false,
148
+ explicitCallAllowed: recommendation.explicitCallAllowedByDefault && registration.supportsExplicitCall !== false,
149
+ };
150
+ const actual = {
151
+ enabled: registration.enabled,
152
+ assistantVisible: registration.assistantVisible,
153
+ schemaAssistantVisible: registration.schemaAssistantVisible,
154
+ explicitCallAllowed: registration.explicitCallAllowed,
155
+ };
156
+ return Object.keys(expected)
157
+ .filter((field) => expected[field] !== actual[field])
158
+ .map((field) => ({ field, expected: expected[field], actual: actual[field] }));
159
+ }
160
+ function normalizeNullableString(value) {
161
+ return typeof value === "string" && value.trim().length ? value.trim() : null;
162
+ }
163
+ //# sourceMappingURL=tool-runtime.js.map