@humain/ui 2.1.63 → 2.1.65

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 (160) hide show
  1. package/dist/components/organisms/ai/AIToolCall/AIToolCall.d.ts +9 -3
  2. package/dist/components/organisms/ai/AIToolRun/index.d.ts +1 -1
  3. package/dist/components/organisms/ai/AIToolRun/validation.d.ts +24 -3
  4. package/dist/components/organisms/ai/_shared/format-ai-duration.d.ts +1 -0
  5. package/dist/components/organisms/ai/_shared/workflow-step-renderer.d.ts +1 -0
  6. package/dist/index.js +52 -52
  7. package/dist/index151.js +1 -1
  8. package/dist/index174.js +7 -339
  9. package/dist/index174.js.map +1 -1
  10. package/dist/index175.js +310 -137
  11. package/dist/index175.js.map +1 -1
  12. package/dist/index176.js +148 -174
  13. package/dist/index176.js.map +1 -1
  14. package/dist/index177.js +186 -78
  15. package/dist/index177.js.map +1 -1
  16. package/dist/index178.js +74 -124
  17. package/dist/index178.js.map +1 -1
  18. package/dist/index179.js +133 -1
  19. package/dist/index179.js.map +1 -0
  20. package/dist/index180.js +2 -201
  21. package/dist/index181.js +201 -0
  22. package/dist/{index180.js.map → index181.js.map} +1 -1
  23. package/dist/index183.js +130 -166
  24. package/dist/index183.js.map +1 -1
  25. package/dist/index184.js +195 -983
  26. package/dist/index184.js.map +1 -1
  27. package/dist/index185.js +1069 -369
  28. package/dist/index185.js.map +1 -1
  29. package/dist/index186.js +395 -197
  30. package/dist/index186.js.map +1 -1
  31. package/dist/index187.js +198 -243
  32. package/dist/index187.js.map +1 -1
  33. package/dist/index188.js +263 -3
  34. package/dist/index188.js.map +1 -1
  35. package/dist/index189.js +3 -209
  36. package/dist/index189.js.map +1 -1
  37. package/dist/index190.js +190 -777
  38. package/dist/index190.js.map +1 -1
  39. package/dist/index191.js +771 -252
  40. package/dist/index191.js.map +1 -1
  41. package/dist/index192.js +250 -65
  42. package/dist/index192.js.map +1 -1
  43. package/dist/index193.js +72 -523
  44. package/dist/index193.js.map +1 -1
  45. package/dist/index194.js +537 -144
  46. package/dist/index194.js.map +1 -1
  47. package/dist/index195.js +139 -720
  48. package/dist/index195.js.map +1 -1
  49. package/dist/index196.js +707 -167
  50. package/dist/index196.js.map +1 -1
  51. package/dist/index197.js +175 -151
  52. package/dist/index197.js.map +1 -1
  53. package/dist/index198.js +152 -487
  54. package/dist/index198.js.map +1 -1
  55. package/dist/index199.js +472 -225
  56. package/dist/index199.js.map +1 -1
  57. package/dist/index200.js +236 -260
  58. package/dist/index200.js.map +1 -1
  59. package/dist/index201.js +265 -215
  60. package/dist/index201.js.map +1 -1
  61. package/dist/index202.js +207 -307
  62. package/dist/index202.js.map +1 -1
  63. package/dist/index203.js +302 -135
  64. package/dist/index203.js.map +1 -1
  65. package/dist/index204.js +140 -271
  66. package/dist/index204.js.map +1 -1
  67. package/dist/index205.js +263 -253
  68. package/dist/index205.js.map +1 -1
  69. package/dist/index206.js +244 -137
  70. package/dist/index206.js.map +1 -1
  71. package/dist/index207.js +100 -238
  72. package/dist/index207.js.map +1 -1
  73. package/dist/index208.js +278 -74
  74. package/dist/index208.js.map +1 -1
  75. package/dist/index209.js +56 -97
  76. package/dist/index209.js.map +1 -1
  77. package/dist/index210.js +142 -47
  78. package/dist/index210.js.map +1 -1
  79. package/dist/index211.js +38 -84
  80. package/dist/index211.js.map +1 -1
  81. package/dist/index212.js +72 -252
  82. package/dist/index212.js.map +1 -1
  83. package/dist/index213.js +274 -26
  84. package/dist/index213.js.map +1 -1
  85. package/dist/index214.js +29 -94
  86. package/dist/index214.js.map +1 -1
  87. package/dist/index215.js +98 -25
  88. package/dist/index215.js.map +1 -1
  89. package/dist/index216.js +20 -565
  90. package/dist/index216.js.map +1 -1
  91. package/dist/index217.js +564 -17
  92. package/dist/index217.js.map +1 -1
  93. package/dist/index218.js +20 -23
  94. package/dist/index218.js.map +1 -1
  95. package/dist/index219.js +20 -95
  96. package/dist/index219.js.map +1 -1
  97. package/dist/index220.js +92 -88
  98. package/dist/index220.js.map +1 -1
  99. package/dist/index221.js +97 -29
  100. package/dist/index221.js.map +1 -1
  101. package/dist/index222.js +24 -470
  102. package/dist/index222.js.map +1 -1
  103. package/dist/index223.js +446 -196
  104. package/dist/index223.js.map +1 -1
  105. package/dist/index224.js +199 -729
  106. package/dist/index224.js.map +1 -1
  107. package/dist/index225.js +750 -61
  108. package/dist/index225.js.map +1 -1
  109. package/dist/index226.js +58 -181
  110. package/dist/index226.js.map +1 -1
  111. package/dist/index227.js +175 -259
  112. package/dist/index227.js.map +1 -1
  113. package/dist/index228.js +246 -172
  114. package/dist/index228.js.map +1 -1
  115. package/dist/index229.js +195 -32
  116. package/dist/index229.js.map +1 -1
  117. package/dist/index230.js +12 -40
  118. package/dist/index230.js.map +1 -1
  119. package/dist/index231.js +23 -26
  120. package/dist/index231.js.map +1 -1
  121. package/dist/index232.js +45 -22
  122. package/dist/index232.js.map +1 -1
  123. package/dist/index233.js +27 -48
  124. package/dist/index233.js.map +1 -1
  125. package/dist/index234.js +52 -26
  126. package/dist/index234.js.map +1 -1
  127. package/dist/index235.js +40 -225
  128. package/dist/index235.js.map +1 -1
  129. package/dist/index236.js +217 -39
  130. package/dist/index236.js.map +1 -1
  131. package/dist/index237.js +50 -0
  132. package/dist/index237.js.map +1 -0
  133. package/dist/styles.css +1 -1
  134. package/dist/wc/AIToolCall.js +218 -0
  135. package/dist/wc/AIToolCall.js.map +1 -0
  136. package/dist/wc/hf-ai-tool-call.js +34 -219
  137. package/dist/wc/hf-ai-tool-call.js.map +1 -1
  138. package/dist/wc/hf-ai-tool-run.js +673 -576
  139. package/dist/wc/hf-ai-tool-run.js.map +1 -1
  140. package/dist/wc/workflow-step-renderer.js +79 -78
  141. package/dist/wc/workflow-step-renderer.js.map +1 -1
  142. package/dist/wc-react/AIToolCall.js +218 -0
  143. package/dist/wc-react/AIToolCall.js.map +1 -0
  144. package/dist/wc-react/hf-ai-tool-call.js +32 -217
  145. package/dist/wc-react/hf-ai-tool-call.js.map +1 -1
  146. package/dist/wc-react/hf-ai-tool-run.js +698 -601
  147. package/dist/wc-react/hf-ai-tool-run.js.map +1 -1
  148. package/dist/wc-react/workflow-step-renderer.js +58 -57
  149. package/dist/wc-react/workflow-step-renderer.js.map +1 -1
  150. package/package.json +1 -1
  151. package/skills/humain-ui/SKILL.md +1 -1
  152. package/skills/humain-ui-wc/SKILL.md +1 -1
  153. package/skills/humain-ui-wc.skill +0 -0
  154. package/skills/humain-ui.skill +0 -0
  155. package/dist/index182.js +0 -143
  156. package/dist/index182.js.map +0 -1
  157. package/dist/wc/wrench.js +0 -10
  158. package/dist/wc/wrench.js.map +0 -1
  159. package/dist/wc-react/wrench.js +0 -10
  160. package/dist/wc-react/wrench.js.map +0 -1
package/dist/index184.js CHANGED
@@ -1,995 +1,207 @@
1
- import { assertNever } from "./index2.js";
2
- //#region src/components/organisms/ai/AIToolRun/validation.ts
3
- var ROOT_KEYS = /* @__PURE__ */ new Set([
4
- "runId",
5
- "status",
6
- "header",
7
- "steps",
8
- "sources",
9
- "actions",
10
- "progress",
11
- "activeStepId",
12
- "error"
13
- ]);
14
- var HEADER_KEYS = /* @__PURE__ */ new Set([
15
- "title",
16
- "description",
17
- "metadata"
18
- ]);
19
- var METADATA_KEYS = /* @__PURE__ */ new Set(["label", "value"]);
20
- var PROGRESS_KEYS = /* @__PURE__ */ new Set([
21
- "value",
22
- "label",
23
- "meta"
24
- ]);
25
- var ROOT_ERROR_KEYS = /* @__PURE__ */ new Set(["message"]);
26
- var SOURCE_KEYS = /* @__PURE__ */ new Set([
27
- "id",
28
- "url",
29
- "title",
30
- "description",
31
- "favicon",
32
- "siteName"
33
- ]);
34
- var ACTION_KEYS = /* @__PURE__ */ new Set([
35
- "id",
36
- "kind",
37
- "label",
38
- "disabled",
39
- "loading"
40
- ]);
41
- var STEP_KEYS = /* @__PURE__ */ new Set([
42
- "toolCall",
43
- "title",
44
- "description",
45
- "progress",
46
- "sourceIds",
47
- "currentSourceId",
48
- "durationMs"
49
- ]);
50
- var TOOL_CALL_KEYS = /* @__PURE__ */ new Set([
51
- "toolCallId",
52
- "toolName",
53
- "status",
54
- "error"
55
- ]);
56
- var TOOL_STATUSES = {
57
- error: true,
58
- pending: true,
59
- running: true,
60
- success: true
61
- };
62
- var RUN_STATUSES = {
63
- completed: true,
64
- error: true,
65
- paused: true,
66
- ready: true,
67
- running: true
68
- };
69
- var ACTION_KINDS = {
70
- custom: true,
71
- dismiss: true,
72
- pause: true,
73
- resume: true,
74
- retry: true,
75
- start: true
76
- };
77
- var ACTIONS_BY_STATUS = {
78
- ready: [
79
- "start",
80
- "dismiss",
81
- "custom"
82
- ],
83
- running: [
84
- "pause",
85
- "dismiss",
86
- "custom"
87
- ],
88
- paused: [
89
- "resume",
90
- "dismiss",
91
- "custom"
92
- ],
93
- completed: ["dismiss", "custom"],
94
- error: [
95
- "retry",
96
- "dismiss",
97
- "custom"
98
- ]
99
- };
100
- var STEP_KEYS_BY_STATUS = {
101
- pending: /* @__PURE__ */ new Set([
102
- "toolCall",
103
- "title",
104
- "description"
105
- ]),
106
- running: /* @__PURE__ */ new Set([
107
- "toolCall",
108
- "title",
109
- "description",
110
- "progress",
111
- "sourceIds",
112
- "currentSourceId"
113
- ]),
114
- success: /* @__PURE__ */ new Set([
115
- "toolCall",
116
- "title",
117
- "description",
118
- "durationMs",
119
- "sourceIds"
120
- ]),
121
- error: /* @__PURE__ */ new Set([
122
- "toolCall",
123
- "title",
124
- "description",
125
- "sourceIds"
126
- ])
127
- };
128
- var TOOL_CALL_KEYS_BY_STATUS = {
129
- pending: /* @__PURE__ */ new Set([
130
- "toolCallId",
131
- "toolName",
132
- "status"
133
- ]),
134
- running: /* @__PURE__ */ new Set([
135
- "toolCallId",
136
- "toolName",
137
- "status"
138
- ]),
139
- success: /* @__PURE__ */ new Set([
140
- "toolCallId",
141
- "toolName",
142
- "status"
143
- ]),
144
- error: /* @__PURE__ */ new Set([
145
- "toolCallId",
146
- "toolName",
147
- "status",
148
- "error"
149
- ])
150
- };
151
- var MAX_JSON_DEPTH = 100;
152
- var MAX_JSON_NODES = 1e4;
153
- var MAX_VALIDATION_ISSUES = 100;
154
- var INSPECTION_FAILURE_MESSAGE = "Value could not be inspected safely";
155
- var INVALID_FIELD = Symbol("invalid-shape-field");
156
- function addIssue(issues, path, message) {
157
- if (issues.length < MAX_VALIDATION_ISSUES) issues.push({
158
- path,
159
- message
1
+ import { cn } from "./index2.js";
2
+ import { useControllableState } from "./index12.js";
3
+ import { AICodeBlock } from "./index146.js";
4
+ import { cva } from "class-variance-authority";
5
+ import { AlertCircle, Check, ChevronDown, ChevronRight, Clock, Code, Wrench } from "lucide-react";
6
+ import * as React from "react";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import { AnimatePresence, motion } from "motion/react";
9
+ //#region src/components/organisms/ai/AIToolCall/AIToolCall.tsx
10
+ var toolCallVariants = cva("overflow-hidden rounded-xl border transition-colors", {
11
+ variants: { status: {
12
+ pending: "border-border bg-muted",
13
+ running: "border-primary bg-primary/10",
14
+ success: "border-success/50 bg-success/10",
15
+ error: "border-destructive/50 bg-destructive/10"
16
+ } },
17
+ defaultVariants: { status: "pending" }
18
+ });
19
+ var statusIconVariants = cva("size-4", {
20
+ variants: { status: {
21
+ pending: "text-muted-foreground",
22
+ running: "text-primary animate-spin motion-reduce:animate-none",
23
+ success: "text-success",
24
+ error: "text-destructive"
25
+ } },
26
+ defaultVariants: { status: "pending" }
27
+ });
28
+ function StatusIcon({ status, className }) {
29
+ const iconClass = cn(statusIconVariants({ status }), className);
30
+ switch (status) {
31
+ case "running": return /* @__PURE__ */ jsx(Clock, { className: iconClass });
32
+ case "success": return /* @__PURE__ */ jsx(Check, { className: cn(iconClass, "delight-check-bounce motion-reduce:!animate-none") });
33
+ case "error": return /* @__PURE__ */ jsx(AlertCircle, { className: cn(iconClass, "delight-shake motion-reduce:!animate-none") });
34
+ default: return /* @__PURE__ */ jsx(Wrench, { className: iconClass });
35
+ }
36
+ }
37
+ StatusIcon.displayName = "StatusIcon";
38
+ function AIToolCallHeader({ toolName, status, isOpen, onToggle, className }) {
39
+ return /* @__PURE__ */ jsxs("button", {
40
+ type: "button",
41
+ onClick: onToggle,
42
+ "aria-expanded": isOpen,
43
+ className: cn("flex items-center justify-between w-full px-4 py-3 transition-colors hover:bg-foreground/5 focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-ring", className),
44
+ children: [/* @__PURE__ */ jsxs("div", {
45
+ className: "flex items-center gap-3",
46
+ children: [/* @__PURE__ */ jsx(StatusIcon, {
47
+ status,
48
+ "aria-hidden": "true"
49
+ }), /* @__PURE__ */ jsxs("div", {
50
+ className: "flex flex-col items-start",
51
+ children: [/* @__PURE__ */ jsx("span", {
52
+ className: "text-sm font-medium text-foreground",
53
+ children: toolName
54
+ }), /* @__PURE__ */ jsx("span", {
55
+ className: "text-xs text-text-quaternary",
56
+ children: {
57
+ pending: "Pending",
58
+ running: "Running...",
59
+ success: "Completed",
60
+ error: "Failed"
61
+ }[status]
62
+ })]
63
+ })]
64
+ }), isOpen ? /* @__PURE__ */ jsx(ChevronDown, {
65
+ className: "size-4 text-muted-foreground",
66
+ "aria-hidden": "true"
67
+ }) : /* @__PURE__ */ jsx(ChevronRight, {
68
+ className: "size-4 text-muted-foreground rtl:rotate-180",
69
+ "aria-hidden": "true"
70
+ })]
160
71
  });
161
72
  }
162
- function hasIssuesSince(issues, issueCount) {
163
- return issues.length > issueCount || issues.length >= MAX_VALIDATION_ISSUES;
164
- }
165
- function addInspectionIssue(issues, path) {
166
- addIssue(issues, path, INSPECTION_FAILURE_MESSAGE);
167
- }
168
- function getContainerKind(value, path, issues) {
169
- if (value === null || typeof value !== "object") return "other";
170
- try {
171
- const prototype = Reflect.getPrototypeOf(value);
172
- if (Array.isArray(value)) return prototype === Array.prototype ? "array" : "other";
173
- return prototype === Object.prototype || prototype === null ? "record" : "other";
174
- } catch {
175
- addInspectionIssue(issues, path);
176
- return "uninspectable";
177
- }
178
- }
179
- function getOwnKeys(value, path, issues) {
180
- try {
181
- return Reflect.ownKeys(value);
182
- } catch {
183
- addInspectionIssue(issues, path);
184
- return;
185
- }
186
- }
187
- function getOwnPropertyDescriptor(value, key, path, issues) {
188
- try {
189
- return Reflect.getOwnPropertyDescriptor(value, key);
190
- } catch {
191
- addInspectionIssue(issues, path);
192
- return null;
193
- }
194
- }
195
- function readEnumerableDataDescriptor(_value, _key, descriptor, path, issues) {
196
- if (!descriptor.enumerable || !Object.hasOwn(descriptor, "value")) {
197
- addIssue(issues, path, "Value must be an own enumerable data property");
198
- return { valid: false };
199
- }
200
- return {
201
- valid: true,
202
- value: descriptor.value
203
- };
73
+ AIToolCallHeader.displayName = "AIToolCallHeader";
74
+ function ToolCallSection({ title, icon, children, className }) {
75
+ return /* @__PURE__ */ jsxs("div", {
76
+ className: cn("space-y-2", className),
77
+ children: [/* @__PURE__ */ jsxs("div", {
78
+ className: "flex items-center gap-2 text-xs font-medium text-text-quaternary uppercase tracking-wide",
79
+ children: [icon, title]
80
+ }), children]
81
+ });
204
82
  }
205
- function findReflectedPropertyDescriptor(value, key, path, issues) {
206
- const visited = /* @__PURE__ */ new Set();
207
- let current = value;
208
- let isOwn = true;
209
- while (current !== null) {
210
- if (visited.has(current)) {
211
- addInspectionIssue(issues, path);
212
- return null;
213
- }
214
- visited.add(current);
215
- const descriptor = getOwnPropertyDescriptor(current, key, path, issues);
216
- if (descriptor === null) return null;
217
- if (descriptor !== void 0) {
218
- if (isOwn) {
219
- const ownKeys = getOwnKeys(value, path, issues);
220
- if (!ownKeys) return null;
221
- if (!ownKeys.includes(key)) {
222
- addIssue(issues, path, "Own property must be exposed by Reflect.ownKeys");
223
- return null;
224
- }
225
- }
226
- return {
227
- descriptor,
228
- isOwn
229
- };
230
- }
231
- try {
232
- current = Reflect.getPrototypeOf(current);
233
- } catch {
234
- addInspectionIssue(issues, path);
235
- return null;
236
- }
237
- isOwn = false;
238
- }
83
+ ToolCallSection.displayName = "ToolCallSection";
84
+ function formatValue(value) {
85
+ if (typeof value === "string") return value;
86
+ return JSON.stringify(value, null, 2);
239
87
  }
240
- function inspectProperty(value, key, path, issues) {
241
- const descriptor = findReflectedPropertyDescriptor(value, key, path, issues);
242
- if (descriptor === null) return void 0;
243
- if (descriptor !== void 0) return {
244
- kind: "descriptor",
245
- ...descriptor
88
+ function AIToolCall({ toolPart, defaultOpen = false, open: controlledOpen, onOpenChange, className }) {
89
+ const [isOpen, setIsOpen] = useControllableState({
90
+ value: controlledOpen,
91
+ defaultValue: defaultOpen,
92
+ onChange: onOpenChange
93
+ });
94
+ const status = toolPart.status || "pending";
95
+ const handleToggle = () => {
96
+ setIsOpen(!isOpen);
246
97
  };
247
- let present;
248
- try {
249
- present = Reflect.has(value, key);
250
- } catch {
251
- addInspectionIssue(issues, path);
252
- return;
253
- }
254
- if (present) return { kind: "synthetic" };
255
- let visibleValue;
256
- try {
257
- visibleValue = Reflect.get(value, key);
258
- } catch {
259
- addInspectionIssue(issues, path);
260
- return;
261
- }
262
- return present || visibleValue !== void 0 ? { kind: "synthetic" } : { kind: "absent" };
263
- }
264
- function readShapeField(value, key, path, issues) {
265
- const inspection = inspectProperty(value, key, path, issues);
266
- if (!inspection) return INVALID_FIELD;
267
- if (inspection.kind === "absent") return;
268
- if (inspection.kind === "synthetic" || !inspection.isOwn) {
269
- addIssue(issues, path, "Value must be an own enumerable data property");
270
- return INVALID_FIELD;
271
- }
272
- const field = readEnumerableDataDescriptor(value, key, inspection.descriptor, path, issues);
273
- return field.valid ? field.value : INVALID_FIELD;
274
- }
275
- function readRequiredField(value, key, path, issues) {
276
- return readShapeField(value, key, path, issues);
277
- }
278
- function readOptionalField(value, key, path, issues) {
279
- return readShapeField(value, key, path, issues);
280
- }
281
- function isInvalidField(value) {
282
- return value === INVALID_FIELD;
283
- }
284
- function getOwnEnumerableDataKeys(value, path, issues) {
285
- const keys = getOwnKeys(value, path, issues);
286
- if (!keys) return void 0;
287
- if (keys.length > MAX_JSON_NODES) {
288
- addIssue(issues, path, "Value exceeds the maximum JSON node limit");
289
- return;
290
- }
291
- const stringKeys = [];
292
- for (const key of keys) {
293
- const keyPath = typeof key === "string" ? `${path}.${key}` : path;
294
- const descriptor = getOwnPropertyDescriptor(value, key, keyPath, issues);
295
- if (descriptor === null) return void 0;
296
- if (descriptor === void 0) {
297
- addInspectionIssue(issues, keyPath);
298
- return;
299
- }
300
- if (typeof key !== "string") {
301
- addIssue(issues, path, "Symbol keys are not JSON-safe");
302
- continue;
303
- }
304
- if (!readEnumerableDataDescriptor(value, key, descriptor, keyPath, issues).valid) continue;
305
- stringKeys.push(key);
306
- }
307
- return stringKeys;
308
- }
309
- function isArrayIndexKey(key) {
310
- const index = Number(key);
311
- if (!Number.isInteger(index) || index < 0 || index >= 2 ** 32 - 1 || String(index) !== key) return;
312
- return index;
313
- }
314
- function readArrayLength(_value, descriptor, path, issues) {
315
- if (descriptor.enumerable || !Object.hasOwn(descriptor, "value") || typeof descriptor.value !== "number" || !Number.isInteger(descriptor.value) || descriptor.value < 0 || descriptor.value > 2 ** 32 - 1) {
316
- addIssue(issues, path, "Array length must be a valid data property");
317
- return;
318
- }
319
- return descriptor.value;
320
- }
321
- function readArrayItems(value, path, issues) {
322
- const issueCount = issues.length;
323
- const keys = getOwnKeys(value, path, issues);
324
- if (!keys) return void 0;
325
- if (keys.length > 10001) {
326
- addIssue(issues, path, "Value exceeds the maximum JSON node limit");
327
- return;
328
- }
329
- let length;
330
- const items = /* @__PURE__ */ new Map();
331
- for (const key of keys) {
332
- const keyPath = typeof key === "string" ? `${path}.${key}` : path;
333
- const descriptor = getOwnPropertyDescriptor(value, key, keyPath, issues);
334
- if (descriptor === null) return void 0;
335
- if (descriptor === void 0) {
336
- addInspectionIssue(issues, keyPath);
337
- return;
338
- }
339
- if (typeof key !== "string") {
340
- addIssue(issues, path, "Symbol keys are not JSON-safe");
341
- continue;
342
- }
343
- if (key === "length") {
344
- length = readArrayLength(value, descriptor, path, issues);
345
- continue;
346
- }
347
- const index = isArrayIndexKey(key);
348
- if (index === void 0) {
349
- addIssue(issues, keyPath, "Arrays must not contain custom properties");
350
- continue;
351
- }
352
- const item = readEnumerableDataDescriptor(value, key, descriptor, `${path}[${index}]`, issues);
353
- if (item.valid) items.set(index, item.value);
354
- }
355
- if (length === void 0) {
356
- if (!hasIssuesSince(issues, issueCount)) addInspectionIssue(issues, path);
357
- return;
358
- }
359
- if (length > MAX_JSON_NODES) {
360
- addIssue(issues, path, "Array length exceeds the maximum JSON node limit");
361
- return;
362
- }
363
- const orderedItems = [...items.entries()].sort(([left], [right]) => left - right);
364
- let expectedIndex = 0;
365
- for (const [index] of orderedItems) {
366
- if (index !== expectedIndex) {
367
- addIssue(issues, `${path}[${expectedIndex}]`, "Array holes are not JSON-safe");
368
- return;
369
- }
370
- expectedIndex += 1;
371
- }
372
- if (expectedIndex !== length) {
373
- addIssue(issues, `${path}[${expectedIndex}]`, "Array holes are not JSON-safe");
374
- return;
375
- }
376
- if (hasIssuesSince(issues, issueCount)) return void 0;
377
- return orderedItems.map(([index, item]) => ({
378
- index,
379
- value: item
380
- }));
381
- }
382
- function readObjectChildren(value, path, issues) {
383
- const issueCount = issues.length;
384
- const keys = getOwnKeys(value, path, issues);
385
- if (!keys) return void 0;
386
- if (keys.length > MAX_JSON_NODES) {
387
- addIssue(issues, path, "Value exceeds the maximum JSON node limit");
388
- return;
389
- }
390
- const children = [];
391
- for (const key of keys) {
392
- const keyPath = typeof key === "string" ? `${path}.${key}` : path;
393
- const descriptor = getOwnPropertyDescriptor(value, key, keyPath, issues);
394
- if (descriptor === null) return void 0;
395
- if (descriptor === void 0) {
396
- addInspectionIssue(issues, keyPath);
397
- return;
398
- }
399
- if (typeof key !== "string") {
400
- addIssue(issues, path, "Symbol keys are not JSON-safe");
401
- continue;
402
- }
403
- const child = readEnumerableDataDescriptor(value, key, descriptor, keyPath, issues);
404
- if (child.valid) children.push({
405
- path: keyPath,
406
- value: child.value
407
- });
408
- }
409
- return hasIssuesSince(issues, issueCount) ? void 0 : children;
410
- }
411
- function rejectUnknownKeys(value, allowed, path, issues) {
412
- const keys = getOwnEnumerableDataKeys(value, path, issues);
413
- if (!keys) return;
414
- for (const key of keys) if (!allowed.has(key)) addIssue(issues, `${path}.${key}`, `Unknown key "${key}"`);
415
- }
416
- function rejectDisallowedKeys(value, known, allowed, path, issues) {
417
- for (const key of known) if (!allowed.has(key)) {
418
- const inspection = inspectProperty(value, key, `${path}.${key}`, issues);
419
- if (!inspection) return;
420
- if (inspection.kind === "absent") continue;
421
- addIssue(issues, `${path}.${key}`, "Field is not allowed for this status");
422
- }
423
- }
424
- function rejectPresentKeys(value, keys, path, issues) {
425
- for (const key of keys) {
426
- const inspection = inspectProperty(value, key, `${path}.${key}`, issues);
427
- if (!inspection) return;
428
- if (inspection.kind === "absent") continue;
429
- addIssue(issues, `${path}.${key}`, "Field is not allowed for this status");
430
- }
431
- }
432
- function isFiniteNumber(value) {
433
- return typeof value === "number" && Number.isFinite(value);
434
- }
435
- function hasSafeToJSON(value, path, issues) {
436
- const descriptor = findReflectedPropertyDescriptor(value, "toJSON", path, issues);
437
- if (descriptor === null) return false;
438
- if (descriptor !== void 0) {
439
- addIssue(issues, path, "Value must not define toJSON");
440
- return false;
441
- }
442
- return true;
98
+ return /* @__PURE__ */ jsxs("div", {
99
+ "data-slot": "ai-tool-call",
100
+ className: cn(toolCallVariants({ status }), className),
101
+ children: [/* @__PURE__ */ jsx(AIToolCallHeader, {
102
+ toolName: toolPart.toolName,
103
+ status,
104
+ isOpen,
105
+ onToggle: handleToggle
106
+ }), /* @__PURE__ */ jsx(AnimatePresence, { children: isOpen && /* @__PURE__ */ jsx(motion.div, {
107
+ initial: {
108
+ height: 0,
109
+ opacity: 0
110
+ },
111
+ animate: {
112
+ height: "auto",
113
+ opacity: 1
114
+ },
115
+ exit: {
116
+ height: 0,
117
+ opacity: 0
118
+ },
119
+ transition: { duration: .2 },
120
+ className: "overflow-hidden",
121
+ children: /* @__PURE__ */ jsxs("div", {
122
+ className: "px-4 pb-4 space-y-4",
123
+ children: [
124
+ /* @__PURE__ */ jsxs("div", {
125
+ className: "text-xs text-muted-foreground font-mono",
126
+ children: ["ID: ", toolPart.toolCallId]
127
+ }),
128
+ toolPart.args && Object.keys(toolPart.args).length > 0 && /* @__PURE__ */ jsx(ToolCallSection, {
129
+ title: "Input",
130
+ icon: /* @__PURE__ */ jsx(Code, { className: "size-3" }),
131
+ children: /* @__PURE__ */ jsx(AICodeBlock, {
132
+ code: formatValue(toolPart.args),
133
+ language: "json",
134
+ showHeader: false,
135
+ showCopyButton: true,
136
+ size: "sm"
137
+ })
138
+ }),
139
+ toolPart.result !== void 0 && /* @__PURE__ */ jsx(ToolCallSection, {
140
+ title: "Output",
141
+ icon: /* @__PURE__ */ jsx(Code, { className: "size-3" }),
142
+ children: /* @__PURE__ */ jsx(AICodeBlock, {
143
+ code: formatValue(toolPart.result),
144
+ language: "json",
145
+ showHeader: false,
146
+ showCopyButton: true,
147
+ size: "sm"
148
+ })
149
+ }),
150
+ toolPart.error && /* @__PURE__ */ jsx("div", {
151
+ className: "p-3 rounded-lg bg-destructive/20 border border-destructive/50",
152
+ children: /* @__PURE__ */ jsxs("div", {
153
+ className: "flex items-start gap-2",
154
+ children: [/* @__PURE__ */ jsx(AlertCircle, { className: "size-4 text-destructive mt-0.5 shrink-0" }), /* @__PURE__ */ jsx("p", {
155
+ className: "text-sm text-destructive",
156
+ children: toolPart.error
157
+ })]
158
+ })
159
+ })
160
+ ]
161
+ })
162
+ }) })]
163
+ });
443
164
  }
444
- function validateJsonSafe(value, path, issues) {
445
- const ancestors = /* @__PURE__ */ new Set();
446
- const stack = [{
447
- kind: "visit",
448
- value,
449
- path,
450
- depth: 0
451
- }];
452
- let nodeCount = 0;
453
- while (stack.length > 0 && issues.length < MAX_VALIDATION_ISSUES) {
454
- const frame = stack.pop();
455
- if (!frame) break;
456
- if (frame.kind === "leave") {
457
- ancestors.delete(frame.value);
458
- continue;
459
- }
460
- if (frame.depth > MAX_JSON_DEPTH) {
461
- addIssue(issues, frame.path, "Value exceeds the maximum JSON depth limit");
462
- continue;
463
- }
464
- nodeCount += 1;
465
- if (nodeCount > MAX_JSON_NODES) {
466
- addIssue(issues, frame.path, "Value exceeds the maximum JSON node limit");
467
- break;
468
- }
469
- const currentValue = frame.value;
470
- if (currentValue === void 0 || typeof currentValue === "function" || typeof currentValue === "symbol" || typeof currentValue === "bigint") {
471
- addIssue(issues, frame.path, "Value must be JSON-safe");
472
- continue;
473
- }
474
- if (typeof currentValue === "number" && !isFiniteNumber(currentValue)) {
475
- addIssue(issues, frame.path, "Number must be finite");
476
- continue;
477
- }
478
- if (currentValue === null || typeof currentValue !== "object") continue;
479
- if (ancestors.has(currentValue)) {
480
- addIssue(issues, frame.path, "Value must not contain cycles");
481
- continue;
482
- }
483
- const containerKind = getContainerKind(currentValue, frame.path, issues);
484
- if (containerKind === "uninspectable") continue;
485
- if (containerKind === "other") {
486
- addIssue(issues, frame.path, "Value must contain only plain objects and arrays");
487
- continue;
488
- }
489
- if (!hasSafeToJSON(currentValue, frame.path, issues)) continue;
490
- ancestors.add(currentValue);
491
- stack.push({
492
- kind: "leave",
493
- value: currentValue
165
+ AIToolCall.displayName = "AIToolCall";
166
+ function normalizeOpenToolCallIds(ids, toolCalls) {
167
+ const requested = new Set(ids);
168
+ return toolCalls.flatMap((toolCall) => requested.has(toolCall.toolCallId) ? [toolCall.toolCallId] : []);
169
+ }
170
+ function areToolCallIdsEqual(left, right) {
171
+ return left.length === right.length && left.every((id, index) => id === right[index]);
172
+ }
173
+ function AIToolCallList({ toolCalls, defaultAllOpen = false, defaultOpenToolCallIds = [], openToolCallIds: controlledOpenToolCallIds, onOpenToolCallIdsChange, className }) {
174
+ const isControlled = controlledOpenToolCallIds !== void 0;
175
+ const [uncontrolledOpenToolCallIds, setUncontrolledOpenToolCallIds] = React.useState(() => normalizeOpenToolCallIds(defaultAllOpen ? toolCalls.map((toolCall) => toolCall.toolCallId) : defaultOpenToolCallIds, toolCalls));
176
+ const visibleOpenToolCallIds = normalizeOpenToolCallIds(isControlled ? controlledOpenToolCallIds : uncontrolledOpenToolCallIds, toolCalls);
177
+ const openSet = new Set(visibleOpenToolCallIds);
178
+ React.useLayoutEffect(() => {
179
+ if (isControlled) return;
180
+ setUncontrolledOpenToolCallIds((current) => {
181
+ const normalized = normalizeOpenToolCallIds(current, toolCalls);
182
+ return areToolCallIdsEqual(current, normalized) ? current : normalized;
494
183
  });
495
- if (containerKind === "array") {
496
- const children = readArrayItems(currentValue, frame.path, issues);
497
- if (!children) continue;
498
- for (let index = children.length - 1; index >= 0; index -= 1) {
499
- const child = children[index];
500
- stack.push({
501
- kind: "visit",
502
- value: child.value,
503
- path: `${frame.path}[${child.index}]`,
504
- depth: frame.depth + 1
505
- });
506
- }
507
- continue;
508
- }
509
- const children = readObjectChildren(currentValue, frame.path, issues);
510
- if (!children) continue;
511
- for (let index = children.length - 1; index >= 0; index -= 1) {
512
- const child = children[index];
513
- stack.push({
514
- kind: "visit",
515
- value: child.value,
516
- path: child.path,
517
- depth: frame.depth + 1
518
- });
519
- }
520
- }
521
- }
522
- var INVALID_JSON_SNAPSHOT = Symbol("invalid-json-snapshot");
523
- function captureJsonSnapshot(value, path, issues) {
524
- const ancestors = /* @__PURE__ */ new Set();
525
- const snapshots = /* @__PURE__ */ new Map();
526
- let nodeCount = 0;
527
- function capture(currentValue, currentPath, depth) {
528
- if (issues.length >= MAX_VALIDATION_ISSUES) return INVALID_JSON_SNAPSHOT;
529
- if (depth > MAX_JSON_DEPTH) {
530
- addIssue(issues, currentPath, "Value exceeds the maximum JSON depth limit");
531
- return INVALID_JSON_SNAPSHOT;
532
- }
533
- nodeCount += 1;
534
- if (nodeCount > MAX_JSON_NODES) {
535
- addIssue(issues, currentPath, "Value exceeds the maximum JSON node limit");
536
- return INVALID_JSON_SNAPSHOT;
537
- }
538
- if (currentValue === void 0 || typeof currentValue === "function" || typeof currentValue === "symbol" || typeof currentValue === "bigint") {
539
- addIssue(issues, currentPath, "Value must be JSON-safe");
540
- return INVALID_JSON_SNAPSHOT;
541
- }
542
- if (typeof currentValue === "number" && !isFiniteNumber(currentValue)) {
543
- addIssue(issues, currentPath, "Number must be finite");
544
- return INVALID_JSON_SNAPSHOT;
545
- }
546
- if (currentValue === null || typeof currentValue !== "object") return currentValue;
547
- if (ancestors.has(currentValue)) {
548
- addIssue(issues, currentPath, "Value must not contain cycles");
549
- return INVALID_JSON_SNAPSHOT;
550
- }
551
- const containerKind = getContainerKind(currentValue, currentPath, issues);
552
- if (containerKind === "uninspectable") return INVALID_JSON_SNAPSHOT;
553
- if (containerKind === "other") {
554
- addIssue(issues, currentPath, "Value must contain only plain objects and arrays");
555
- return INVALID_JSON_SNAPSHOT;
556
- }
557
- if (!hasSafeToJSON(currentValue, currentPath, issues)) return INVALID_JSON_SNAPSHOT;
558
- const existingSnapshot = snapshots.get(currentValue);
559
- if (existingSnapshot !== void 0) return existingSnapshot;
560
- ancestors.add(currentValue);
561
- try {
562
- if (containerKind === "array") {
563
- const items = readArrayItems(currentValue, currentPath, issues);
564
- if (!items) return INVALID_JSON_SNAPSHOT;
565
- const snapshot = new Array(items.length);
566
- snapshots.set(currentValue, snapshot);
567
- for (const item of items) {
568
- const capturedItem = capture(item.value, `${currentPath}[${item.index}]`, depth + 1);
569
- if (capturedItem === INVALID_JSON_SNAPSHOT) return INVALID_JSON_SNAPSHOT;
570
- snapshot[item.index] = capturedItem;
571
- }
572
- return snapshot;
573
- }
574
- const children = readObjectChildren(currentValue, currentPath, issues);
575
- if (!children) return INVALID_JSON_SNAPSHOT;
576
- const snapshot = Object.create(null);
577
- snapshots.set(currentValue, snapshot);
578
- for (const child of children) {
579
- const key = child.path.slice(currentPath.length + 1);
580
- const capturedChild = capture(child.value, child.path, depth + 1);
581
- if (capturedChild === INVALID_JSON_SNAPSHOT) return INVALID_JSON_SNAPSHOT;
582
- Object.defineProperty(snapshot, key, {
583
- configurable: true,
584
- enumerable: true,
585
- value: capturedChild,
586
- writable: true
587
- });
588
- }
589
- return snapshot;
590
- } finally {
591
- ancestors.delete(currentValue);
592
- }
593
- }
594
- return capture(value, path, 0);
595
- }
596
- function requireRecord(value, path, issues) {
597
- if (isInvalidField(value)) return void 0;
598
- const containerKind = getContainerKind(value, path, issues);
599
- if (containerKind !== "record") {
600
- if (containerKind !== "uninspectable") addIssue(issues, path, "Value must be a plain object");
601
- return;
602
- }
603
- return value;
604
- }
605
- function requireString(value, path, issues) {
606
- if (isInvalidField(value)) return void 0;
607
- if (typeof value !== "string") {
608
- addIssue(issues, path, "Value must be a string");
609
- return;
610
- }
611
- return value;
612
- }
613
- function requireNonEmptyString(value, path, issues) {
614
- const stringValue = requireString(value, path, issues);
615
- if (stringValue !== void 0 && stringValue.length === 0) {
616
- addIssue(issues, path, "Value must not be empty");
617
- return;
618
- }
619
- return stringValue;
620
- }
621
- function requireNonWhitespaceString(value, path, issues) {
622
- const stringValue = requireString(value, path, issues);
623
- if (stringValue !== void 0 && stringValue.trim().length === 0) {
624
- addIssue(issues, path, "Value must be non-whitespace");
625
- return;
626
- }
627
- return stringValue;
628
- }
629
- function requireBoolean(value, path, issues) {
630
- if (isInvalidField(value)) return void 0;
631
- if (typeof value !== "boolean") {
632
- addIssue(issues, path, "Value must be a boolean");
633
- return;
634
- }
635
- return value;
636
- }
637
- function requireNumber(value, path, issues) {
638
- if (isInvalidField(value)) return void 0;
639
- if (typeof value !== "number") {
640
- addIssue(issues, path, "Value must be a number");
641
- return;
642
- }
643
- return value;
644
- }
645
- function requireArray(value, path, issues) {
646
- if (isInvalidField(value)) return void 0;
647
- try {
648
- if (Array.isArray(value)) return value;
649
- } catch {
650
- addInspectionIssue(issues, path);
651
- return;
652
- }
653
- addIssue(issues, path, "Value must be an array");
654
- }
655
- function requireRunStatus(value, path, issues) {
656
- if (isInvalidField(value)) return void 0;
657
- if (typeof value !== "string" || !Object.hasOwn(RUN_STATUSES, value)) {
658
- addIssue(issues, path, "Value must be a supported run status");
659
- return;
660
- }
661
- return value;
662
- }
663
- function requireToolStatus(value, path, issues) {
664
- if (isInvalidField(value)) return void 0;
665
- if (typeof value !== "string" || !Object.hasOwn(TOOL_STATUSES, value)) {
666
- addIssue(issues, path, "Value is not allowed as a tool status");
667
- return;
668
- }
669
- return value;
670
- }
671
- function requireActionKind(value, path, issues) {
672
- if (isInvalidField(value)) return void 0;
673
- if (typeof value !== "string" || !Object.hasOwn(ACTION_KINDS, value)) {
674
- addIssue(issues, path, "Value must be an allowed action kind");
675
- return;
676
- }
677
- return value;
678
- }
679
- function validateProgress(value, path, issues) {
680
- const progress = requireRecord(value, path, issues);
681
- if (!progress) return;
682
- rejectUnknownKeys(progress, PROGRESS_KEYS, path, issues);
683
- const progressValue = requireNumber(readRequiredField(progress, "value", `${path}.value`, issues), `${path}.value`, issues);
684
- if (progressValue !== void 0 && (progressValue < 0 || progressValue > 100)) addIssue(issues, `${path}.value`, "Value must be between 0 and 100");
685
- const label = readOptionalField(progress, "label", `${path}.label`, issues);
686
- if (label !== void 0 && !isInvalidField(label)) requireNonWhitespaceString(label, `${path}.label`, issues);
687
- const meta = readOptionalField(progress, "meta", `${path}.meta`, issues);
688
- if (meta !== void 0 && !isInvalidField(meta)) requireString(meta, `${path}.meta`, issues);
689
- }
690
- function validateStringArray(value, path, issues) {
691
- const issueCount = issues.length;
692
- const values = requireArray(value, path, issues);
693
- if (!values) return void 0;
694
- const items = readArrayItems(values, path, issues);
695
- if (!items) return void 0;
696
- const strings = [];
697
- for (const item of items) {
698
- const stringValue = requireString(item.value, `${path}[${item.index}]`, issues);
699
- if (stringValue !== void 0) strings.push(stringValue);
700
- }
701
- return hasIssuesSince(issues, issueCount) ? void 0 : strings;
702
- }
703
- function validateToolCall(value, path, issues) {
704
- const issueCount = issues.length;
705
- const toolCall = requireRecord(value, path, issues);
706
- if (!toolCall) return void 0;
707
- rejectUnknownKeys(toolCall, TOOL_CALL_KEYS, path, issues);
708
- const toolCallId = requireNonEmptyString(readRequiredField(toolCall, "toolCallId", `${path}.toolCallId`, issues), `${path}.toolCallId`, issues);
709
- requireNonWhitespaceString(readRequiredField(toolCall, "toolName", `${path}.toolName`, issues), `${path}.toolName`, issues);
710
- const status = requireToolStatus(readRequiredField(toolCall, "status", `${path}.status`, issues), `${path}.status`, issues);
711
- if (!status) return void 0;
712
- rejectDisallowedKeys(toolCall, TOOL_CALL_KEYS, TOOL_CALL_KEYS_BY_STATUS[status], path, issues);
713
- if (status === "error") {
714
- const error = readRequiredField(toolCall, "error", `${path}.error`, issues);
715
- if (error === void 0) addIssue(issues, `${path}.error`, "Value is required for error tool calls");
716
- else if (!isInvalidField(error)) requireNonWhitespaceString(error, `${path}.error`, issues);
717
- }
718
- if (hasIssuesSince(issues, issueCount) || !toolCallId) return void 0;
719
- return {
720
- toolCallId,
721
- status
722
- };
723
- }
724
- function validateStep(value, path, issues) {
725
- const issueCount = issues.length;
726
- const step = requireRecord(value, path, issues);
727
- if (!step) return void 0;
728
- rejectUnknownKeys(step, STEP_KEYS, path, issues);
729
- const title = readOptionalField(step, "title", `${path}.title`, issues);
730
- if (title !== void 0 && !isInvalidField(title)) requireString(title, `${path}.title`, issues);
731
- const description = readOptionalField(step, "description", `${path}.description`, issues);
732
- if (description !== void 0 && !isInvalidField(description)) requireString(description, `${path}.description`, issues);
733
- const toolCall = validateToolCall(readRequiredField(step, "toolCall", `${path}.toolCall`, issues), `${path}.toolCall`, issues);
734
- if (!toolCall) return void 0;
735
- const { status } = toolCall;
736
- rejectDisallowedKeys(step, STEP_KEYS, STEP_KEYS_BY_STATUS[status], path, issues);
737
- const progress = readOptionalField(step, "progress", `${path}.progress`, issues);
738
- if (progress !== void 0 && !isInvalidField(progress)) validateProgress(progress, `${path}.progress`, issues);
739
- const sourceIdsField = readOptionalField(step, "sourceIds", `${path}.sourceIds`, issues);
740
- const sourceIds = sourceIdsField === void 0 || isInvalidField(sourceIdsField) ? void 0 : validateStringArray(sourceIdsField, `${path}.sourceIds`, issues);
741
- const currentSourceIdField = readOptionalField(step, "currentSourceId", `${path}.currentSourceId`, issues);
742
- const currentSourceId = currentSourceIdField === void 0 || isInvalidField(currentSourceIdField) ? void 0 : requireString(currentSourceIdField, `${path}.currentSourceId`, issues);
743
- const durationMsField = readOptionalField(step, "durationMs", `${path}.durationMs`, issues);
744
- if (durationMsField !== void 0 && !isInvalidField(durationMsField)) {
745
- const durationMs = requireNumber(durationMsField, `${path}.durationMs`, issues);
746
- if (durationMs !== void 0 && durationMs < 0) addIssue(issues, `${path}.durationMs`, "Value must be non-negative");
747
- }
748
- if (hasIssuesSince(issues, issueCount)) return void 0;
749
- return {
750
- toolCall,
751
- ...sourceIds === void 0 ? {} : { sourceIds },
752
- ...currentSourceId === void 0 ? {} : { currentSourceId }
184
+ }, [isControlled, toolCalls]);
185
+ const setToolCallOpen = (toolCallId, open) => {
186
+ const next = new Set(visibleOpenToolCallIds);
187
+ if (open) next.add(toolCallId);
188
+ else next.delete(toolCallId);
189
+ const normalized = normalizeOpenToolCallIds([...next], toolCalls);
190
+ if (!isControlled) setUncontrolledOpenToolCallIds(normalized);
191
+ onOpenToolCallIdsChange?.([...normalized]);
753
192
  };
193
+ return /* @__PURE__ */ jsx("div", {
194
+ "data-slot": "ai-tool-call-list",
195
+ className: cn("space-y-2", className),
196
+ children: toolCalls.map((toolCall) => /* @__PURE__ */ jsx(AIToolCall, {
197
+ toolPart: toolCall,
198
+ open: openSet.has(toolCall.toolCallId),
199
+ onOpenChange: (open) => setToolCallOpen(toolCall.toolCallId, open)
200
+ }, toolCall.toolCallId))
201
+ });
754
202
  }
755
- function validateSource(value, path, issues) {
756
- const issueCount = issues.length;
757
- const source = requireRecord(value, path, issues);
758
- if (!source) return void 0;
759
- rejectUnknownKeys(source, SOURCE_KEYS, path, issues);
760
- const id = requireNonEmptyString(readRequiredField(source, "id", `${path}.id`, issues), `${path}.id`, issues);
761
- requireNonWhitespaceString(readRequiredField(source, "url", `${path}.url`, issues), `${path}.url`, issues);
762
- for (const key of [
763
- "title",
764
- "description",
765
- "favicon",
766
- "siteName"
767
- ]) {
768
- const field = readOptionalField(source, key, `${path}.${key}`, issues);
769
- if (field !== void 0 && !isInvalidField(field)) requireString(field, `${path}.${key}`, issues);
770
- }
771
- return hasIssuesSince(issues, issueCount) || !id ? void 0 : id;
772
- }
773
- function validateSources(value, path, issues) {
774
- const sourceIds = /* @__PURE__ */ new Set();
775
- const sources = requireArray(value, path, issues);
776
- if (!sources) return sourceIds;
777
- const sourceItems = readArrayItems(sources, path, issues);
778
- if (!sourceItems) return sourceIds;
779
- for (const item of sourceItems) {
780
- const sourcePath = `${path}[${item.index}]`;
781
- const sourceId = validateSource(item.value, sourcePath, issues);
782
- if (!sourceId) continue;
783
- if (sourceIds.has(sourceId)) {
784
- addIssue(issues, `${sourcePath}.id`, "duplicate source ID");
785
- continue;
786
- }
787
- sourceIds.add(sourceId);
788
- }
789
- return sourceIds;
790
- }
791
- function validateAction(value, path, issues) {
792
- const issueCount = issues.length;
793
- const action = requireRecord(value, path, issues);
794
- if (!action) return void 0;
795
- rejectUnknownKeys(action, ACTION_KEYS, path, issues);
796
- const id = requireNonEmptyString(readRequiredField(action, "id", `${path}.id`, issues), `${path}.id`, issues);
797
- const kind = requireActionKind(readRequiredField(action, "kind", `${path}.kind`, issues), `${path}.kind`, issues);
798
- if (!kind) return void 0;
799
- const label = kind === "custom" ? readRequiredField(action, "label", `${path}.label`, issues) : readOptionalField(action, "label", `${path}.label`, issues);
800
- if (kind === "custom" && label === void 0) addIssue(issues, `${path}.label`, "Value is required for custom actions");
801
- else if (label !== void 0 && !isInvalidField(label)) requireNonWhitespaceString(label, `${path}.label`, issues);
802
- const disabled = readOptionalField(action, "disabled", `${path}.disabled`, issues);
803
- if (disabled !== void 0 && !isInvalidField(disabled)) requireBoolean(disabled, `${path}.disabled`, issues);
804
- const loading = readOptionalField(action, "loading", `${path}.loading`, issues);
805
- if (loading !== void 0 && !isInvalidField(loading)) requireBoolean(loading, `${path}.loading`, issues);
806
- return hasIssuesSince(issues, issueCount) || !id ? void 0 : {
807
- id,
808
- kind
809
- };
810
- }
811
- function validateActions(value, path, status, issues) {
812
- const actions = requireArray(value, path, issues);
813
- if (!actions) return;
814
- const actionItems = readArrayItems(actions, path, issues);
815
- if (!actionItems) return;
816
- const actionIds = /* @__PURE__ */ new Set();
817
- for (const item of actionItems) {
818
- const actionPath = `${path}[${item.index}]`;
819
- const action = validateAction(item.value, actionPath, issues);
820
- if (!action) continue;
821
- if (actionIds.has(action.id)) addIssue(issues, `${actionPath}.id`, "duplicate action ID");
822
- else actionIds.add(action.id);
823
- if (status && !ACTIONS_BY_STATUS[status].includes(action.kind)) addIssue(issues, `${actionPath}.kind`, `Action kind "${action.kind}" is not allowed for ${status} runs`);
824
- }
825
- }
826
- function validateLifecycle(status, steps, issues) {
827
- const statuses = steps.map((step) => step.toolCall.status);
828
- switch (status) {
829
- case "ready":
830
- if (statuses.some((stepStatus) => stepStatus !== "pending")) addIssue(issues, "$.steps", "Ready runs allow pending steps only");
831
- return;
832
- case "running":
833
- case "paused":
834
- if (statuses.some((stepStatus) => stepStatus !== "pending" && stepStatus !== "running" && stepStatus !== "success") || !statuses.includes("running")) addIssue(issues, "$.steps", `${status} runs require at least one running step and allow pending, running, or success only`);
835
- return;
836
- case "completed":
837
- if (steps.length === 0 || statuses.some((stepStatus) => stepStatus !== "success")) addIssue(issues, "$.steps", "Completed runs require a non-empty all-success step list");
838
- return;
839
- case "error":
840
- if (statuses.some((stepStatus) => stepStatus !== "pending" && stepStatus !== "success" && stepStatus !== "error")) addIssue(issues, "$.steps", "Error runs allow pending, success, or error steps only");
841
- return;
842
- default: assertNever(status);
843
- }
844
- }
845
- function validateSourceReferences(steps, sourceIds, issues) {
846
- for (const [stepIndex, step] of steps.entries()) {
847
- const sourceIdPath = `$.steps[${stepIndex}].sourceIds`;
848
- const stepSourceIds = step.sourceIds;
849
- if (stepSourceIds) {
850
- for (const [sourceIndex, sourceId] of stepSourceIds.entries()) if (!sourceIds.has(sourceId)) addIssue(issues, `${sourceIdPath}[${sourceIndex}]`, "Unknown source reference");
851
- }
852
- const currentSourceId = step.currentSourceId;
853
- if (currentSourceId === void 0) continue;
854
- const currentSourcePath = `$.steps[${stepIndex}].currentSourceId`;
855
- if (!sourceIds.has(currentSourceId)) addIssue(issues, currentSourcePath, "Unknown current source reference");
856
- else if (!stepSourceIds?.includes(currentSourceId)) addIssue(issues, currentSourcePath, "Current source ID must be included in sourceIds");
857
- }
858
- }
859
- function validateActiveStepReference(status, activeStepId, steps, issues) {
860
- if (status !== "running" && status !== "paused" || activeStepId === void 0) return;
861
- if (!steps.some((step) => step.toolCall.status === "running" && step.toolCall.toolCallId === activeStepId)) addIssue(issues, "$.activeStepId", "Active step ID must reference a running step");
862
- }
863
- function validateMetadata(value, path, issues) {
864
- const metadata = requireArray(value, path, issues);
865
- if (!metadata) return;
866
- const metadataItems = readArrayItems(metadata, path, issues);
867
- if (!metadataItems) return;
868
- for (const item of metadataItems) {
869
- const itemPath = `${path}[${item.index}]`;
870
- const record = requireRecord(item.value, itemPath, issues);
871
- if (!record) continue;
872
- rejectUnknownKeys(record, METADATA_KEYS, itemPath, issues);
873
- requireNonWhitespaceString(readRequiredField(record, "label", `${itemPath}.label`, issues), `${itemPath}.label`, issues);
874
- requireString(readRequiredField(record, "value", `${itemPath}.value`, issues), `${itemPath}.value`, issues);
875
- }
876
- }
877
- function validateHeader(value, path, issues) {
878
- const header = requireRecord(value, path, issues);
879
- if (!header) return;
880
- rejectUnknownKeys(header, HEADER_KEYS, path, issues);
881
- requireNonWhitespaceString(readRequiredField(header, "title", `${path}.title`, issues), `${path}.title`, issues);
882
- const description = readOptionalField(header, "description", `${path}.description`, issues);
883
- if (description !== void 0 && !isInvalidField(description)) requireString(description, `${path}.description`, issues);
884
- const metadata = readOptionalField(header, "metadata", `${path}.metadata`, issues);
885
- if (metadata !== void 0 && !isInvalidField(metadata)) validateMetadata(metadata, `${path}.metadata`, issues);
886
- }
887
- function validateStateFields(status, snapshot, issues) {
888
- switch (status) {
889
- case "ready":
890
- case "completed":
891
- rejectPresentKeys(snapshot, [
892
- "progress",
893
- "activeStepId",
894
- "error"
895
- ], "$", issues);
896
- return;
897
- case "running":
898
- case "paused": {
899
- rejectPresentKeys(snapshot, ["error"], "$", issues);
900
- const progress = readOptionalField(snapshot, "progress", "$.progress", issues);
901
- if (progress !== void 0 && !isInvalidField(progress)) validateProgress(progress, "$.progress", issues);
902
- const activeStepId = readOptionalField(snapshot, "activeStepId", "$.activeStepId", issues);
903
- return activeStepId === void 0 || isInvalidField(activeStepId) ? void 0 : requireString(activeStepId, "$.activeStepId", issues);
904
- }
905
- case "error": {
906
- rejectPresentKeys(snapshot, ["activeStepId"], "$", issues);
907
- const progress = readOptionalField(snapshot, "progress", "$.progress", issues);
908
- if (progress !== void 0 && !isInvalidField(progress)) validateProgress(progress, "$.progress", issues);
909
- const error = requireRecord(readRequiredField(snapshot, "error", "$.error", issues), "$.error", issues);
910
- if (!error) return void 0;
911
- rejectUnknownKeys(error, ROOT_ERROR_KEYS, "$.error", issues);
912
- requireNonWhitespaceString(readRequiredField(error, "message", "$.error.message", issues), "$.error.message", issues);
913
- return;
914
- }
915
- default: assertNever(status);
916
- }
917
- }
918
- function validateAIToolRunSnapshot(value) {
919
- const issues = [];
920
- try {
921
- const capturedValue = captureJsonSnapshot(value, "$", issues);
922
- if (issues.length > 0) return {
923
- valid: false,
924
- issues
925
- };
926
- if (capturedValue === INVALID_JSON_SNAPSHOT) return {
927
- valid: false,
928
- issues: [{
929
- path: "$",
930
- message: INSPECTION_FAILURE_MESSAGE
931
- }]
932
- };
933
- validateJsonSafe(capturedValue, "$", issues);
934
- if (issues.length > 0) return {
935
- valid: false,
936
- issues
937
- };
938
- const snapshot = requireRecord(capturedValue, "$", issues);
939
- if (!snapshot) return {
940
- valid: false,
941
- issues
942
- };
943
- rejectUnknownKeys(snapshot, ROOT_KEYS, "$", issues);
944
- const status = requireRunStatus(readRequiredField(snapshot, "status", "$.status", issues), "$.status", issues);
945
- const activeStepId = status ? validateStateFields(status, snapshot, issues) : void 0;
946
- requireNonEmptyString(readRequiredField(snapshot, "runId", "$.runId", issues), "$.runId", issues);
947
- validateHeader(readRequiredField(snapshot, "header", "$.header", issues), "$.header", issues);
948
- const steps = requireArray(readRequiredField(snapshot, "steps", "$.steps", issues), "$.steps", issues);
949
- const validatedSteps = [];
950
- let stepsAreValid = false;
951
- if (steps) {
952
- const stepItems = readArrayItems(steps, "$.steps", issues);
953
- if (stepItems) {
954
- const toolCallIds = /* @__PURE__ */ new Set();
955
- for (const item of stepItems) {
956
- const validatedStep = validateStep(item.value, `$.steps[${item.index}]`, issues);
957
- if (!validatedStep) continue;
958
- if (toolCallIds.has(validatedStep.toolCall.toolCallId)) addIssue(issues, `$.steps[${item.index}].toolCall.toolCallId`, "duplicate tool-call ID");
959
- else toolCallIds.add(validatedStep.toolCall.toolCallId);
960
- validatedSteps.push(validatedStep);
961
- }
962
- stepsAreValid = validatedSteps.length === stepItems.length;
963
- if (status && stepsAreValid) validateLifecycle(status, validatedSteps, issues);
964
- }
965
- }
966
- const sources = readOptionalField(snapshot, "sources", "$.sources", issues);
967
- const sourceIds = sources === void 0 || isInvalidField(sources) ? /* @__PURE__ */ new Set() : validateSources(sources, "$.sources", issues);
968
- if (stepsAreValid) {
969
- validateSourceReferences(validatedSteps, sourceIds, issues);
970
- validateActiveStepReference(status, activeStepId, validatedSteps, issues);
971
- }
972
- const actions = readOptionalField(snapshot, "actions", "$.actions", issues);
973
- if (actions !== void 0 && !isInvalidField(actions)) validateActions(actions, "$.actions", status, issues);
974
- if (issues.length > 0) return {
975
- valid: false,
976
- issues
977
- };
978
- return {
979
- valid: true,
980
- value: capturedValue
981
- };
982
- } catch {
983
- return {
984
- valid: false,
985
- issues: [{
986
- path: "$",
987
- message: INSPECTION_FAILURE_MESSAGE
988
- }]
989
- };
990
- }
991
- }
203
+ AIToolCallList.displayName = "AIToolCallList";
992
204
  //#endregion
993
- export { validateAIToolRunSnapshot };
205
+ export { AIToolCall, AIToolCallHeader, AIToolCallList, StatusIcon, ToolCallSection, statusIconVariants, toolCallVariants };
994
206
 
995
207
  //# sourceMappingURL=index184.js.map