@anvia/react-ui 1.0.0-rc.9 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -37
- package/dist/attachment/index.d.ts +2 -2
- package/dist/attachment/index.js +4 -4
- package/dist/chat/index.d.ts +4 -4
- package/dist/chat/index.js +10 -9
- package/dist/{chunk-OINUOCTO.js → chunk-647LAYRV.js} +90 -65
- package/dist/chunk-647LAYRV.js.map +1 -0
- package/dist/chunk-6XOJFLX4.js +22 -0
- package/dist/chunk-6XOJFLX4.js.map +1 -0
- package/dist/{chunk-JBKSJG5W.js → chunk-CRXNFZRW.js} +45 -80
- package/dist/chunk-CRXNFZRW.js.map +1 -0
- package/dist/{chunk-ULGJLLZE.js → chunk-F6AKBUO3.js} +12 -12
- package/dist/chunk-F6AKBUO3.js.map +1 -0
- package/dist/{chunk-XAQA3JIG.js → chunk-HWJIMLHC.js} +41 -70
- package/dist/chunk-HWJIMLHC.js.map +1 -0
- package/dist/{chunk-BU4ZPDHQ.js → chunk-MISX4WUT.js} +10 -15
- package/dist/chunk-MISX4WUT.js.map +1 -0
- package/dist/{chunk-PSU4V23X.js → chunk-OQE6SHZE.js} +16 -30
- package/dist/chunk-OQE6SHZE.js.map +1 -0
- package/dist/{chunk-E5UNQCGM.js → chunk-S4XLE2RN.js} +6 -12
- package/dist/chunk-S4XLE2RN.js.map +1 -0
- package/dist/{chunk-F76H3VMN.js → chunk-SOG2GVE4.js} +45 -15
- package/dist/chunk-SOG2GVE4.js.map +1 -0
- package/dist/{chunk-ZPNAX4SA.js → chunk-UCBAG42A.js} +9 -21
- package/dist/chunk-UCBAG42A.js.map +1 -0
- package/dist/{chunk-EWIHRMU6.js → chunk-XC7K4XYM.js} +21 -28
- package/dist/chunk-XC7K4XYM.js.map +1 -0
- package/dist/completion/index.d.ts +2 -2
- package/dist/completion/index.js +4 -4
- package/dist/human-input/index.d.ts +2 -2
- package/dist/human-input/index.js +4 -4
- package/dist/image/index.d.ts +2 -2
- package/dist/image/index.js +4 -4
- package/dist/index.d.ts +11 -11
- package/dist/index.js +58 -63
- package/dist/index.js.map +1 -1
- package/dist/message/index.d.ts +2 -2
- package/dist/message/index.js +7 -6
- package/dist/selection-toolbar/index.d.ts +2 -2
- package/dist/selection-toolbar/index.js +5 -4
- package/dist/shared.d.ts +1 -1
- package/dist/shared.js +1 -1
- package/dist/stream/index.d.ts +2 -0
- package/dist/stream/index.js +1 -1
- package/dist/{thread-uEm8hH0s.d.ts → thread-Bz6-1zaJ.d.ts} +1 -0
- package/dist/thread-list/index.d.ts +3 -3
- package/dist/thread-list/index.js +6 -6
- package/package.json +18 -20
- package/dist/chunk-BU4ZPDHQ.js.map +0 -1
- package/dist/chunk-E5UNQCGM.js.map +0 -1
- package/dist/chunk-EWIHRMU6.js.map +0 -1
- package/dist/chunk-F76H3VMN.js.map +0 -1
- package/dist/chunk-JBKSJG5W.js.map +0 -1
- package/dist/chunk-OINUOCTO.js.map +0 -1
- package/dist/chunk-PSU4V23X.js.map +0 -1
- package/dist/chunk-ULGJLLZE.js.map +0 -1
- package/dist/chunk-XAQA3JIG.js.map +0 -1
- package/dist/chunk-ZPNAX4SA.js.map +0 -1
- package/dist/stream/styles.css +0 -17
- package/dist/styles.css +0 -130
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-T3ZFZ3NP.js";
|
|
4
4
|
import {
|
|
5
5
|
useAttachment
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SOG2GVE4.js";
|
|
7
7
|
|
|
8
8
|
// src/attachment/parts.tsx
|
|
9
9
|
import { forwardRef, useCallback } from "react";
|
|
@@ -15,9 +15,7 @@ var AttachmentRoot = forwardRef(function AttachmentRoot2({ children, ...props },
|
|
|
15
15
|
"div",
|
|
16
16
|
{
|
|
17
17
|
...props,
|
|
18
|
-
children: renderedChildren
|
|
19
|
-
"data-anvia-attachment": "",
|
|
20
|
-
"data-type": attachment.type
|
|
18
|
+
children: renderedChildren
|
|
21
19
|
},
|
|
22
20
|
ref
|
|
23
21
|
);
|
|
@@ -29,8 +27,7 @@ var AttachmentName = forwardRef(
|
|
|
29
27
|
"span",
|
|
30
28
|
{
|
|
31
29
|
...props,
|
|
32
|
-
children: props.children ?? attachmentLabel(attachment)
|
|
33
|
-
"data-anvia-attachment-name": ""
|
|
30
|
+
children: props.children ?? attachmentLabel(attachment)
|
|
34
31
|
},
|
|
35
32
|
ref
|
|
36
33
|
);
|
|
@@ -43,8 +40,7 @@ var AttachmentPreview = forwardRef(
|
|
|
43
40
|
"div",
|
|
44
41
|
{
|
|
45
42
|
...props,
|
|
46
|
-
children: props.children ?? defaultPreview(attachment)
|
|
47
|
-
"data-anvia-attachment-preview": ""
|
|
43
|
+
children: props.children ?? defaultPreview(attachment)
|
|
48
44
|
},
|
|
49
45
|
ref
|
|
50
46
|
);
|
|
@@ -72,7 +68,6 @@ var AttachmentRemove = forwardRef(
|
|
|
72
68
|
disabled,
|
|
73
69
|
onClick: handleClick,
|
|
74
70
|
type: props.type ?? "button",
|
|
75
|
-
"data-anvia-attachment-remove": "",
|
|
76
71
|
"data-state": disabled ? "disabled" : "enabled"
|
|
77
72
|
},
|
|
78
73
|
ref
|
|
@@ -90,13 +85,13 @@ function defaultPreview(attachment) {
|
|
|
90
85
|
if (isImageAttachment(attachment)) {
|
|
91
86
|
const source = attachment.url ?? attachmentDataUrl(attachment);
|
|
92
87
|
if (source !== void 0) {
|
|
93
|
-
return /* @__PURE__ */ jsx("img", { alt: attachment.name ?? "Attachment",
|
|
88
|
+
return /* @__PURE__ */ jsx("img", { alt: attachment.name ?? "Attachment", src: source });
|
|
94
89
|
}
|
|
95
90
|
}
|
|
96
91
|
if (attachment.url !== void 0) {
|
|
97
|
-
return /* @__PURE__ */ jsx("a", {
|
|
92
|
+
return /* @__PURE__ */ jsx("a", { href: attachment.url, children: attachmentLabel(attachment) });
|
|
98
93
|
}
|
|
99
|
-
return /* @__PURE__ */ jsx("span", {
|
|
94
|
+
return /* @__PURE__ */ jsx("span", { children: attachment.mediaType ?? attachment.type });
|
|
100
95
|
}
|
|
101
96
|
function attachmentLabel(attachment) {
|
|
102
97
|
return attachment.name ?? attachment.mediaType ?? attachment.type;
|
|
@@ -112,7 +107,7 @@ function attachmentDataUrl(attachment) {
|
|
|
112
107
|
}
|
|
113
108
|
|
|
114
109
|
// src/attachment/index.ts
|
|
115
|
-
var
|
|
110
|
+
var AttachmentPrimitive = {
|
|
116
111
|
Root: AttachmentRoot,
|
|
117
112
|
Name: AttachmentName,
|
|
118
113
|
Preview: AttachmentPreview,
|
|
@@ -120,6 +115,6 @@ var Attachment = {
|
|
|
120
115
|
};
|
|
121
116
|
|
|
122
117
|
export {
|
|
123
|
-
|
|
118
|
+
AttachmentPrimitive
|
|
124
119
|
};
|
|
125
|
-
//# sourceMappingURL=chunk-
|
|
120
|
+
//# sourceMappingURL=chunk-MISX4WUT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/attachment/parts.tsx","../src/attachment/index.ts"],"sourcesContent":["import type { UIAttachment } from \"@anvia/client\";\nimport { forwardRef, type MouseEvent, type ReactNode, useCallback } from \"react\";\n\nimport { useAttachment } from \"../contexts\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\n\ntype AttachmentChildren = ReactNode | ((attachment: UIAttachment) => ReactNode);\n\ntype AttachmentRootProps = Omit<PrimitiveProps<\"div\">, \"children\"> & {\n children?: AttachmentChildren;\n};\n\nconst AttachmentRoot = forwardRef<HTMLDivElement, AttachmentRootProps>(function AttachmentRoot(\n { children, ...props },\n ref,\n) {\n const { attachment, remove } = useAttachment();\n const renderedChildren =\n typeof children === \"function\" ? children(attachment) : (children ?? defaultAttachment(remove));\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderedChildren,\n } as PrimitiveProps<\"div\">,\n ref,\n );\n});\n\nconst AttachmentName = forwardRef<HTMLSpanElement, PrimitiveProps<\"span\">>(\n function AttachmentName(props, ref) {\n const { attachment } = useAttachment();\n\n return renderPrimitive(\n \"span\",\n {\n ...props,\n children: props.children ?? attachmentLabel(attachment),\n } as PrimitiveProps<\"span\">,\n ref,\n );\n },\n);\n\nconst AttachmentPreview = forwardRef<HTMLDivElement, PrimitiveProps<\"div\">>(\n function AttachmentPreview(props, ref) {\n const { attachment } = useAttachment();\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: props.children ?? defaultPreview(attachment),\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\nconst AttachmentRemove = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(\n function AttachmentRemove({ onClick, ...props }, ref) {\n const { remove } = useAttachment();\n const disabled = props.disabled ?? remove === undefined;\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled) {\n return;\n }\n remove?.();\n },\n [disabled, onClick, remove],\n );\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Remove\",\n disabled,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": disabled ? \"disabled\" : \"enabled\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\nfunction defaultAttachment(remove: (() => void) | undefined): ReactNode {\n return (\n <>\n <AttachmentPreview />\n <AttachmentName />\n {remove === undefined ? null : <AttachmentRemove />}\n </>\n );\n}\n\nfunction defaultPreview(attachment: UIAttachment): ReactNode {\n if (isImageAttachment(attachment)) {\n const source = attachment.url ?? attachmentDataUrl(attachment);\n if (source !== undefined) {\n return <img alt={attachment.name ?? \"Attachment\"} src={source} />;\n }\n }\n\n if (attachment.url !== undefined) {\n return <a href={attachment.url}>{attachmentLabel(attachment)}</a>;\n }\n\n return <span>{attachment.mediaType ?? attachment.type}</span>;\n}\n\nfunction attachmentLabel(attachment: UIAttachment): string {\n return attachment.name ?? attachment.mediaType ?? attachment.type;\n}\n\nfunction isImageAttachment(attachment: UIAttachment): boolean {\n return attachment.type === \"image\" || attachment.mediaType?.startsWith(\"image/\") === true;\n}\n\nfunction attachmentDataUrl(attachment: UIAttachment): string | undefined {\n if (attachment.data === undefined || attachment.mediaType === undefined) {\n return undefined;\n }\n return `data:${attachment.mediaType};base64,${attachment.data}`;\n}\n\nexport { AttachmentName, AttachmentPreview, AttachmentRemove, AttachmentRoot };\n","import { AttachmentName, AttachmentPreview, AttachmentRemove, AttachmentRoot } from \"./parts\";\n\nexport const AttachmentPrimitive = {\n Root: AttachmentRoot,\n Name: AttachmentName,\n Preview: AttachmentPreview,\n Remove: AttachmentRemove,\n} as const;\n\nexport type { AttachmentContextValue } from \"../contexts\";\nexport { useAttachment } from \"../contexts\";\n"],"mappings":";;;;;;;;AACA,SAAS,YAA6C,mBAAmB;AA4FrE,mBACE,KADF;AAjFJ,IAAM,iBAAiB,WAAgD,SAASA,gBAC9E,EAAE,UAAU,GAAG,MAAM,GACrB,KACA;AACA,QAAM,EAAE,YAAY,OAAO,IAAI,cAAc;AAC7C,QAAM,mBACJ,OAAO,aAAa,aAAa,SAAS,UAAU,IAAK,YAAY,kBAAkB,MAAM;AAE/F,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,GAAG;AAAA,MACH,UAAU;AAAA,IACZ;AAAA,IACA;AAAA,EACF;AACF,CAAC;AAED,IAAM,iBAAiB;AAAA,EACrB,SAASC,gBAAe,OAAO,KAAK;AAClC,UAAM,EAAE,WAAW,IAAI,cAAc;AAErC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH,UAAU,MAAM,YAAY,gBAAgB,UAAU;AAAA,MACxD;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAM,oBAAoB;AAAA,EACxB,SAASC,mBAAkB,OAAO,KAAK;AACrC,UAAM,EAAE,WAAW,IAAI,cAAc;AAErC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH,UAAU,MAAM,YAAY,e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AAEA,SAAS,kBAAkB,YAAmC;AAC5D,SAAO,WAAW,SAAS,WAAW,WAAW,WAAW,WAAW,QAAQ,MAAM;AACvF;AAEA,SAAS,kBAAkB,YAA8C;AACvE,MAAI,WAAW,SAAS,UAAa,WAAW,cAAc,QAAW;AACvE,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,WAAW,SAAS,WAAW,WAAW,IAAI;AAC/D;;;AC/HO,IAAM,sBAAsB;AAAA,EACjC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AACV;","names":["AttachmentRoot","AttachmentName","AttachmentPreview","AttachmentRemove"]}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
useHumanInput,
|
|
14
14
|
useQuestion,
|
|
15
15
|
useQuestionPrompt
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-SOG2GVE4.js";
|
|
17
17
|
|
|
18
18
|
// src/human-input/approvals.tsx
|
|
19
19
|
import { forwardRef, useCallback } from "react";
|
|
@@ -27,9 +27,7 @@ var HumanInputStatus = forwardRef(
|
|
|
27
27
|
"div",
|
|
28
28
|
{
|
|
29
29
|
...props,
|
|
30
|
-
children: renderedChildren ?? `${pendingCount} pending
|
|
31
|
-
"data-anvia-human-input-status": "",
|
|
32
|
-
"data-pending": String(pendingCount)
|
|
30
|
+
children: renderedChildren ?? `${pendingCount} pending`
|
|
33
31
|
},
|
|
34
32
|
ref
|
|
35
33
|
);
|
|
@@ -48,8 +46,7 @@ var HumanInputApprovals = forwardRef(
|
|
|
48
46
|
{
|
|
49
47
|
...props,
|
|
50
48
|
children: approvals.map((approval) => /* @__PURE__ */ jsx(InternalApprovalProvider, { approval, children: typeof children === "function" ? children(approval) : children ?? /* @__PURE__ */ jsx(HumanInputApproval, {}) }, approval.request.id)),
|
|
51
|
-
"data-
|
|
52
|
-
"data-empty": empty ? "" : void 0
|
|
49
|
+
"data-state": empty ? "empty" : "populated"
|
|
53
50
|
},
|
|
54
51
|
ref
|
|
55
52
|
);
|
|
@@ -64,7 +61,6 @@ var HumanInputApproval = forwardRef(
|
|
|
64
61
|
{
|
|
65
62
|
...props,
|
|
66
63
|
children: renderedChildren,
|
|
67
|
-
"data-anvia-approval": "",
|
|
68
64
|
"data-state": approval.status
|
|
69
65
|
},
|
|
70
66
|
ref
|
|
@@ -100,7 +96,6 @@ var HumanInputApprove = forwardRef(
|
|
|
100
96
|
disabled,
|
|
101
97
|
onClick: handleClick,
|
|
102
98
|
type: props.type ?? "button",
|
|
103
|
-
"data-anvia-approve": "",
|
|
104
99
|
"data-state": disabled ? "disabled" : "enabled"
|
|
105
100
|
},
|
|
106
101
|
ref
|
|
@@ -136,7 +131,6 @@ var HumanInputReject = forwardRef(
|
|
|
136
131
|
disabled,
|
|
137
132
|
onClick: handleClick,
|
|
138
133
|
type: props.type ?? "button",
|
|
139
|
-
"data-anvia-reject": "",
|
|
140
134
|
"data-state": disabled ? "disabled" : "enabled"
|
|
141
135
|
},
|
|
142
136
|
ref
|
|
@@ -161,8 +155,7 @@ var HumanInputApprovalReason = forwardRef(
|
|
|
161
155
|
...props,
|
|
162
156
|
"aria-label": props["aria-label"] ?? "Approval reason",
|
|
163
157
|
onChange: handleChange,
|
|
164
|
-
value: approval.reason
|
|
165
|
-
"data-anvia-approval-reason": ""
|
|
158
|
+
value: approval.reason
|
|
166
159
|
},
|
|
167
160
|
ref
|
|
168
161
|
);
|
|
@@ -170,8 +163,8 @@ var HumanInputApprovalReason = forwardRef(
|
|
|
170
163
|
);
|
|
171
164
|
function defaultApprovalContent(approval) {
|
|
172
165
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
173
|
-
/* @__PURE__ */ jsx("div", {
|
|
174
|
-
approval.request.input !== void 0 ? /* @__PURE__ */ jsx("pre", {
|
|
166
|
+
/* @__PURE__ */ jsx("div", { children: approval.request.toolName }),
|
|
167
|
+
approval.request.input !== void 0 ? /* @__PURE__ */ jsx("pre", { children: stringifyValue(approval.request.input) }) : null,
|
|
175
168
|
/* @__PURE__ */ jsx(HumanInputApprovalReason, {}),
|
|
176
169
|
/* @__PURE__ */ jsx(HumanInputApprove, {}),
|
|
177
170
|
/* @__PURE__ */ jsx(HumanInputReject, {})
|
|
@@ -202,8 +195,7 @@ var HumanInputQuestions = forwardRef2(
|
|
|
202
195
|
{
|
|
203
196
|
...props,
|
|
204
197
|
children: questions.map((question) => /* @__PURE__ */ jsx2(QuestionProvider, { question, children: typeof children === "function" ? children(question) : children ?? /* @__PURE__ */ jsx2(HumanInputQuestion, {}) }, question.request.id)),
|
|
205
|
-
"data-
|
|
206
|
-
"data-empty": empty ? "" : void 0
|
|
198
|
+
"data-state": empty ? "empty" : "populated"
|
|
207
199
|
},
|
|
208
200
|
ref
|
|
209
201
|
);
|
|
@@ -218,7 +210,6 @@ var HumanInputQuestion = forwardRef2(
|
|
|
218
210
|
{
|
|
219
211
|
...props,
|
|
220
212
|
children: renderedChildren,
|
|
221
|
-
"data-anvia-question": "",
|
|
222
213
|
"data-state": question.status
|
|
223
214
|
},
|
|
224
215
|
ref
|
|
@@ -236,8 +227,7 @@ var HumanInputQuestionPrompt = forwardRef2(
|
|
|
236
227
|
"div",
|
|
237
228
|
{
|
|
238
229
|
...props,
|
|
239
|
-
children: props.children ?? defaultQuestionPrompt(prompt)
|
|
240
|
-
"data-anvia-question-prompt": ""
|
|
230
|
+
children: props.children ?? defaultQuestionPrompt(prompt)
|
|
241
231
|
},
|
|
242
232
|
ref
|
|
243
233
|
) });
|
|
@@ -271,7 +261,6 @@ var HumanInputQuestionChoice = forwardRef2(
|
|
|
271
261
|
children: props.children ?? choice?.label ?? choiceValue,
|
|
272
262
|
onClick: handleClick,
|
|
273
263
|
type: props.type ?? "button",
|
|
274
|
-
"data-anvia-question-choice": "",
|
|
275
264
|
"data-state": selected ? "selected" : "idle"
|
|
276
265
|
},
|
|
277
266
|
ref
|
|
@@ -303,8 +292,7 @@ var HumanInputQuestionTextAnswer = forwardRef2(
|
|
|
303
292
|
...props,
|
|
304
293
|
"aria-label": props["aria-label"] ?? prompt.text,
|
|
305
294
|
onChange: handleChange,
|
|
306
|
-
value
|
|
307
|
-
"data-anvia-question-text-answer": ""
|
|
295
|
+
value
|
|
308
296
|
},
|
|
309
297
|
ref
|
|
310
298
|
);
|
|
@@ -343,7 +331,6 @@ var HumanInputQuestionSubmit = forwardRef2(
|
|
|
343
331
|
disabled,
|
|
344
332
|
onClick: handleClick,
|
|
345
333
|
type: props.type ?? "button",
|
|
346
|
-
"data-anvia-question-submit": "",
|
|
347
334
|
"data-state": disabled ? "disabled" : "enabled"
|
|
348
335
|
},
|
|
349
336
|
ref
|
|
@@ -366,15 +353,15 @@ function QuestionProvider({
|
|
|
366
353
|
}
|
|
367
354
|
function defaultQuestionContent(question) {
|
|
368
355
|
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
369
|
-
/* @__PURE__ */ jsx2("div", {
|
|
356
|
+
/* @__PURE__ */ jsx2("div", { children: question.request.toolName }),
|
|
370
357
|
question.request.questions.map((prompt) => /* @__PURE__ */ jsx2(HumanInputQuestionPrompt, { promptId: prompt.id }, prompt.id)),
|
|
371
358
|
/* @__PURE__ */ jsx2(HumanInputQuestionSubmit, {})
|
|
372
359
|
] });
|
|
373
360
|
}
|
|
374
361
|
function defaultQuestionPrompt(prompt) {
|
|
375
362
|
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
376
|
-
/* @__PURE__ */ jsx2("div", {
|
|
377
|
-
(prompt.choices?.length ?? 0) > 0 ? /* @__PURE__ */ jsx2("div", {
|
|
363
|
+
/* @__PURE__ */ jsx2("div", { children: prompt.text }),
|
|
364
|
+
(prompt.choices?.length ?? 0) > 0 ? /* @__PURE__ */ jsx2("div", { children: prompt.choices?.map((choice) => /* @__PURE__ */ jsx2(HumanInputQuestionChoice, { value: choice.value, children: choice.label }, choice.value)) }) : /* @__PURE__ */ jsx2(HumanInputQuestionTextAnswer, {})
|
|
378
365
|
] });
|
|
379
366
|
}
|
|
380
367
|
|
|
@@ -394,15 +381,14 @@ var HumanInputPanel = forwardRef3(function HumanInputPanel2({ children, filter =
|
|
|
394
381
|
children: children ?? /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
395
382
|
/* @__PURE__ */ jsx3(HumanInputApprovals, { filter }),
|
|
396
383
|
/* @__PURE__ */ jsx3(HumanInputQuestions, { filter })
|
|
397
|
-
] })
|
|
398
|
-
"data-anvia-human-input-panel": ""
|
|
384
|
+
] })
|
|
399
385
|
},
|
|
400
386
|
ref
|
|
401
387
|
);
|
|
402
388
|
});
|
|
403
389
|
|
|
404
390
|
// src/human-input/index.ts
|
|
405
|
-
var
|
|
391
|
+
var HumanInputPrimitive = {
|
|
406
392
|
Panel: HumanInputPanel,
|
|
407
393
|
Status: HumanInputStatus,
|
|
408
394
|
Approvals: HumanInputApprovals,
|
|
@@ -419,6 +405,6 @@ var HumanInput = {
|
|
|
419
405
|
};
|
|
420
406
|
|
|
421
407
|
export {
|
|
422
|
-
|
|
408
|
+
HumanInputPrimitive
|
|
423
409
|
};
|
|
424
|
-
//# sourceMappingURL=chunk-
|
|
410
|
+
//# sourceMappingURL=chunk-OQE6SHZE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/human-input/approvals.tsx","../src/human-input/panel.tsx","../src/human-input/questions.tsx","../src/human-input/index.ts"],"sourcesContent":["import { type ChangeEvent, forwardRef, type MouseEvent, type ReactNode, useCallback } from \"react\";\n\nimport {\n type ApprovalInteraction,\n InternalApprovalProvider,\n useApproval,\n useChatContext,\n useHumanInput,\n} from \"../contexts\";\nimport { stringifyValue } from \"../format\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\n\ntype ApprovalChildren = ReactNode | ((approval: ApprovalInteraction) => ReactNode);\ntype HumanInputFilter = \"pending\" | \"all\";\n\ntype HumanInputStatusProps = Omit<PrimitiveProps<\"div\">, \"children\"> & {\n children?: ReactNode | ((state: ReturnType<typeof useHumanInput>) => ReactNode);\n};\n\nconst HumanInputStatus = forwardRef<HTMLDivElement, HumanInputStatusProps>(\n function HumanInputStatus({ children, ...props }, ref) {\n const humanInput = useHumanInput();\n const renderedChildren = typeof children === \"function\" ? children(humanInput) : children;\n const pendingCount = humanInput.approvals.pending.length + humanInput.questions.pending.length;\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderedChildren ?? `${pendingCount} pending`,\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\ntype HumanInputApprovalsProps = PrimitiveProps<\"div\"> & {\n filter?: HumanInputFilter;\n keepMounted?: boolean;\n children?: ApprovalChildren;\n};\n\nconst HumanInputApprovals = forwardRef<HTMLDivElement, HumanInputApprovalsProps>(\n function HumanInputApprovals(\n { children, filter = \"pending\", keepMounted = false, ...props },\n ref,\n ) {\n const humanInput = useHumanInput();\n const approvals = filter === \"all\" ? humanInput.approvals.all : humanInput.approvals.pending;\n const empty = approvals.length === 0;\n if (empty && !keepMounted) {\n return null;\n }\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: approvals.map((approval) => (\n <InternalApprovalProvider key={approval.request.id} approval={approval}>\n {typeof children === \"function\"\n ? children(approval)\n : (children ?? <HumanInputApproval />)}\n </InternalApprovalProvider>\n )),\n \"data-state\": empty ? \"empty\" : \"populated\",\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\ntype HumanInputApprovalProps = PrimitiveProps<\"div\"> & {\n children?: ApprovalChildren;\n};\n\nconst HumanInputApproval = forwardRef<HTMLDivElement, HumanInputApprovalProps>(\n function HumanInputApproval({ children, ...props }, ref) {\n const { approval } = useApproval();\n const renderedChildren =\n typeof children === \"function\"\n ? children(approval)\n : (children ?? defaultApprovalContent(approval));\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderedChildren,\n \"data-state\": approval.status,\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\nconst HumanInputApprove = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(\n function HumanInputApprove({ onClick, ...props }, ref) {\n const chat = useChatContext();\n const { approval, reason } = useApproval();\n const disabled =\n props.disabled ??\n (approval.status !== \"pending\" || chat.respondingInteractions.has(approval.request.id));\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled) {\n return;\n }\n const decisionReason = reason.trim().length > 0 ? reason : undefined;\n const response = { type: \"tool-approval\" as const, approved: true };\n if (decisionReason !== undefined) Object.assign(response, { reason: decisionReason });\n void chat.respondToInteraction({\n interactionId: approval.request.id,\n response,\n });\n },\n [approval.request.id, chat, disabled, onClick, reason],\n );\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Approve\",\n disabled,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": disabled ? \"disabled\" : \"enabled\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\nconst HumanInputReject = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(\n function HumanInputReject({ onClick, ...props }, ref) {\n const chat = useChatContext();\n const { approval, reason } = useApproval();\n const disabled =\n props.disabled ??\n (approval.status !== \"pending\" || chat.respondingInteractions.has(approval.request.id));\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled) {\n return;\n }\n const decisionReason = reason.trim().length > 0 ? reason : undefined;\n const response = { type: \"tool-approval\" as const, approved: false };\n if (decisionReason !== undefined) Object.assign(response, { reason: decisionReason });\n void chat.respondToInteraction({\n interactionId: approval.request.id,\n response,\n });\n },\n [approval.request.id, chat, disabled, onClick, reason],\n );\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Reject\",\n disabled,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": disabled ? \"disabled\" : \"enabled\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\nconst HumanInputApprovalReason = forwardRef<HTMLTextAreaElement, PrimitiveProps<\"textarea\">>(\n function HumanInputApprovalReason({ onChange, ...props }, ref) {\n const approval = useApproval();\n\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLTextAreaElement>) => {\n onChange?.(event);\n if (!event.defaultPrevented) {\n approval.setReason(event.currentTarget.value);\n }\n },\n [approval, onChange],\n );\n\n return renderPrimitive(\n \"textarea\",\n {\n ...props,\n \"aria-label\": props[\"aria-label\"] ?? \"Approval reason\",\n onChange: handleChange,\n value: approval.reason,\n } as PrimitiveProps<\"textarea\">,\n ref,\n );\n },\n);\n\nfunction defaultApprovalContent(approval: ApprovalInteraction): ReactNode {\n return (\n <>\n <div>{approval.request.toolName}</div>\n {approval.request.input !== undefined ? (\n <pre>{stringifyValue(approval.request.input)}</pre>\n ) : null}\n <HumanInputApprovalReason />\n <HumanInputApprove />\n <HumanInputReject />\n </>\n );\n}\n\nexport type { ApprovalChildren, HumanInputFilter };\nexport {\n HumanInputApproval,\n HumanInputApprovalReason,\n HumanInputApprovals,\n HumanInputApprove,\n HumanInputReject,\n HumanInputStatus,\n};\n","import { forwardRef } from \"react\";\n\nimport { useHumanInput } from \"../contexts\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\nimport { HumanInputApprovals, type HumanInputFilter } from \"./approvals\";\nimport { HumanInputQuestions } from \"./questions\";\n\ntype HumanInputPanelProps = PrimitiveProps<\"div\"> & {\n filter?: HumanInputFilter;\n};\n\nconst HumanInputPanel = forwardRef<HTMLDivElement, HumanInputPanelProps>(function HumanInputPanel(\n { children, filter = \"pending\", ...props },\n ref,\n) {\n const humanInput = useHumanInput();\n const approvals = filter === \"all\" ? humanInput.approvals.all : humanInput.approvals.pending;\n const questions = filter === \"all\" ? humanInput.questions.all : humanInput.questions.pending;\n if (approvals.length === 0 && questions.length === 0) {\n return null;\n }\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: children ?? (\n <>\n <HumanInputApprovals filter={filter} />\n <HumanInputQuestions filter={filter} />\n </>\n ),\n } as PrimitiveProps<\"div\">,\n ref,\n );\n});\n\nexport { HumanInputPanel };\n","import type { AgentQuestionAnswer, AgentQuestionPrompt } from \"@anvia/core/agent/interactions\";\nimport {\n type ChangeEvent,\n forwardRef,\n type MouseEvent,\n type ReactNode,\n useCallback,\n useMemo,\n useState,\n} from \"react\";\n\nimport {\n InternalQuestionPromptProvider,\n InternalQuestionProvider,\n type QuestionContextValue,\n type QuestionInteraction,\n useChatContext,\n useHumanInput,\n useQuestion,\n useQuestionPrompt,\n} from \"../contexts\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\nimport type { HumanInputFilter } from \"./approvals\";\n\ntype QuestionChildren = ReactNode | ((question: QuestionInteraction) => ReactNode);\n\ntype HumanInputQuestionsProps = PrimitiveProps<\"div\"> & {\n filter?: HumanInputFilter;\n keepMounted?: boolean;\n children?: QuestionChildren;\n};\n\nconst HumanInputQuestions = forwardRef<HTMLDivElement, HumanInputQuestionsProps>(\n function HumanInputQuestions(\n { children, filter = \"pending\", keepMounted = false, ...props },\n ref,\n ) {\n const humanInput = useHumanInput();\n const questions = filter === \"all\" ? humanInput.questions.all : humanInput.questions.pending;\n const empty = questions.length === 0;\n if (empty && !keepMounted) {\n return null;\n }\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: questions.map((question) => (\n <QuestionProvider key={question.request.id} question={question}>\n {typeof children === \"function\"\n ? children(question)\n : (children ?? <HumanInputQuestion />)}\n </QuestionProvider>\n )),\n \"data-state\": empty ? \"empty\" : \"populated\",\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\ntype HumanInputQuestionProps = PrimitiveProps<\"div\"> & {\n children?: QuestionChildren;\n};\n\nconst HumanInputQuestion = forwardRef<HTMLDivElement, HumanInputQuestionProps>(\n function HumanInputQuestion({ children, ...props }, ref) {\n const { question } = useQuestion();\n const renderedChildren =\n typeof children === \"function\"\n ? children(question)\n : (children ?? defaultQuestionContent(question));\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderedChildren,\n \"data-state\": question.status,\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\ntype HumanInputQuestionPromptProps = PrimitiveProps<\"div\"> & {\n promptId?: string;\n};\n\nconst HumanInputQuestionPrompt = forwardRef<HTMLDivElement, HumanInputQuestionPromptProps>(\n function HumanInputQuestionPrompt({ promptId, ...props }, ref) {\n const { question } = useQuestion();\n const prompt =\n question.request.questions.find((item) => item.id === promptId) ??\n question.request.questions[0];\n if (prompt === undefined) {\n return null;\n }\n\n return (\n <InternalQuestionPromptProvider prompt={prompt}>\n {renderPrimitive(\n \"div\",\n {\n ...props,\n children: props.children ?? defaultQuestionPrompt(prompt),\n } as PrimitiveProps<\"div\">,\n ref,\n )}\n </InternalQuestionPromptProvider>\n );\n },\n);\n\ntype HumanInputQuestionChoiceProps = PrimitiveProps<\"button\"> & {\n value?: string;\n answer?: string;\n custom?: boolean;\n};\n\nconst HumanInputQuestionChoice = forwardRef<HTMLButtonElement, HumanInputQuestionChoiceProps>(\n function HumanInputQuestionChoice({ answer, custom = false, onClick, value, ...props }, ref) {\n const { prompt } = useQuestionPrompt();\n const question = useQuestion();\n const choiceValue = value ?? prompt.choices?.[0]?.value ?? \"\";\n const choice = prompt.choices?.find((item) => item.value === choiceValue);\n const selected = question.answers[prompt.id]?.value === choiceValue;\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || choiceValue.length === 0) {\n return;\n }\n const nextAnswer: AgentQuestionAnswer = {\n questionId: prompt.id,\n value: custom ? (answer ?? choice?.label ?? choiceValue) : choiceValue,\n };\n question.setAnswer(prompt, nextAnswer);\n },\n [answer, choice?.label, choiceValue, custom, onClick, prompt, question],\n );\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? choice?.label ?? choiceValue,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": selected ? \"selected\" : \"idle\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\nconst HumanInputQuestionTextAnswer = forwardRef<HTMLTextAreaElement, PrimitiveProps<\"textarea\">>(\n function HumanInputQuestionTextAnswer({ onChange, ...props }, ref) {\n const { prompt } = useQuestionPrompt();\n const question = useQuestion();\n const value = question.answers[prompt.id]?.value ?? \"\";\n\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLTextAreaElement>) => {\n onChange?.(event);\n if (event.defaultPrevented) {\n return;\n }\n const answer = event.currentTarget.value;\n question.setAnswer(prompt, {\n questionId: prompt.id,\n value: answer,\n });\n },\n [onChange, prompt, question],\n );\n\n return renderPrimitive(\n \"textarea\",\n {\n ...props,\n \"aria-label\": props[\"aria-label\"] ?? prompt.text,\n onChange: handleChange,\n value,\n } as PrimitiveProps<\"textarea\">,\n ref,\n );\n },\n);\n\nconst HumanInputQuestionSubmit = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(\n function HumanInputQuestionSubmit({ onClick, ...props }, ref) {\n const chat = useChatContext();\n const question = useQuestion();\n const answers = useMemo(\n () =>\n question.question.request.questions.flatMap((prompt) => {\n const answer = question.answers[prompt.id];\n return answer === undefined || answer.value.trim().length === 0 ? [] : [answer];\n }),\n [question],\n );\n const disabled =\n props.disabled ??\n (question.question.status !== \"pending\" ||\n chat.respondingInteractions.has(question.question.request.id) ||\n answers.length !== question.question.request.questions.length);\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled) {\n return;\n }\n void chat.respondToInteraction({\n interactionId: question.question.request.id,\n response: { type: \"tool-question\", answers },\n });\n },\n [answers, chat, disabled, onClick, question.question.request.id],\n );\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Submit\",\n disabled,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": disabled ? \"disabled\" : \"enabled\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\nfunction QuestionProvider({\n question,\n children,\n}: {\n question: QuestionInteraction;\n children?: ReactNode;\n}) {\n const [answers, setAnswers] = useState<Record<string, AgentQuestionAnswer>>({});\n const setAnswer = useCallback((prompt: AgentQuestionPrompt, answer: AgentQuestionAnswer) => {\n setAnswers((current) => ({ ...current, [prompt.id]: answer }));\n }, []);\n const value = useMemo<QuestionContextValue>(\n () => ({ question, answers, setAnswer }),\n [answers, question, setAnswer],\n );\n\n return <InternalQuestionProvider value={value}>{children}</InternalQuestionProvider>;\n}\n\nfunction defaultQuestionContent(question: QuestionInteraction): ReactNode {\n return (\n <>\n <div>{question.request.toolName}</div>\n {question.request.questions.map((prompt) => (\n <HumanInputQuestionPrompt key={prompt.id} promptId={prompt.id} />\n ))}\n <HumanInputQuestionSubmit />\n </>\n );\n}\n\nfunction defaultQuestionPrompt(prompt: AgentQuestionPrompt): ReactNode {\n return (\n <>\n <div>{prompt.text}</div>\n {(prompt.choices?.length ?? 0) > 0 ? (\n <div>\n {prompt.choices?.map((choice) => (\n <HumanInputQuestionChoice key={choice.value} value={choice.value}>\n {choice.label}\n </HumanInputQuestionChoice>\n ))}\n </div>\n ) : (\n <HumanInputQuestionTextAnswer />\n )}\n </>\n );\n}\n\nexport type { QuestionChildren };\nexport {\n HumanInputQuestion,\n HumanInputQuestionChoice,\n HumanInputQuestionPrompt,\n HumanInputQuestionSubmit,\n HumanInputQuestions,\n HumanInputQuestionTextAnswer,\n};\n","import {\n HumanInputApproval,\n HumanInputApprovalReason,\n HumanInputApprovals,\n HumanInputApprove,\n HumanInputReject,\n HumanInputStatus,\n} from \"./approvals\";\nimport { HumanInputPanel } from \"./panel\";\nimport {\n HumanInputQuestion,\n HumanInputQuestionChoice,\n HumanInputQuestionPrompt,\n HumanInputQuestionSubmit,\n HumanInputQuestions,\n HumanInputQuestionTextAnswer,\n} from \"./questions\";\n\nexport const HumanInputPrimitive = {\n Panel: HumanInputPanel,\n Status: HumanInputStatus,\n Approvals: HumanInputApprovals,\n Approval: HumanInputApproval,\n ApprovalReason: HumanInputApprovalReason,\n Approve: HumanInputApprove,\n Reject: HumanInputReject,\n Questions: HumanInputQuestions,\n Question: HumanInputQuestion,\n QuestionPrompt: HumanInputQuestionPrompt,\n QuestionChoice: HumanInputQuestionChoice,\n QuestionTextAnswer: HumanInputQuestionTextAnswer,\n QuestionSubmit: HumanInputQuestionSubmit,\n} as const;\n\nexport type {\n ApprovalContextValue,\n QuestionContextValue,\n QuestionPromptContextValue,\n} from \"../contexts\";\nexport {\n useApproval,\n useChatContext,\n useHumanInput,\n useQuestion,\n useQuestionPrompt,\n} from \"../contexts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAA2B,YAA6C,mBAAmB;AA8D9D,SA+IzB,UA/IyB,KA+IzB,YA/IyB;AA3C7B,IAAM,mBAAmB;AAAA,EACvB,SAASA,kBAAiB,EAAE,UAAU,GAAG,MAAM,GAAG,KAAK;AACrD,UAAM,aAAa,cAAc;AACjC,UAAM,mBAAmB,OAAO,aAAa,aAAa,SAAS,UAAU,IAAI;AACjF,UAAM,eAAe,WAAW,UAAU,QAAQ,SAAS,WAAW,UAAU,QAAQ;AAExF,WAAO;AAAA,MACL;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH,UAAU,oBAAoB,GAAG,YAAY;AAAA,MAC/C;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAQA,IAAM,sBAAsB;AAAA,EAC1B,SAASC,qBACP,EAAE,UAAU,SAAS,WAAW,cAAc,OAAO,GAAG,MAAM,GAC9D,KACA;AACA,UAAM,aAAa,cAAc;AACjC,UAAM,YAAY,WAAW,QAAQ,WAAW,UAAU,MAAM,WAAW,UAAU;AACrF,UAAM,QAAQ,UAAU,WAAW;AACnC,QAAI,SAAS,CAAC,aAAa;AACzB,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH,UAAU,UAAU,IAAI,CAAC,aACvB,oBAAC,4BAAmD,UACjD,iBAAO,aAAa,aACjB,SA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UAAU;AACrF,MAAI,UAAU,WAAW,KAAK,UAAU,WAAW,GAAG;AACpD,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,GAAG;AAAA,MACH,UAAU,YACR,gBAAAF,MAAAF,WAAA,EACE;AAAA,wBAAAC,KAAC,uBAAoB,QAAgB;AAAA,QACrC,gBAAAA,KAAC,uBAAoB,QAAgB;AAAA,SACvC;AAAA,IAEJ;AAAA,IACA;AAAA,EACF;AACF,CAAC;;;AEjBM,IAAM,sBAAsB;AAAA,EACjC,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,gBAAgB;AAClB;","names":["HumanInputStatus","HumanInputApprovals","HumanInputApproval","HumanInputApprove","HumanInputReject","HumanInputApprovalReason","forwardRef","forwardRef","useCallback","Fragment","jsx","jsxs","forwardRef","HumanInputQuestions","HumanInputQuestion","HumanInputQuestionPrompt","HumanInputQuestionChoice","useCallback","HumanInputQuestionTextAnswer","HumanInputQuestionSubmit","Fragment","jsx","jsxs","forwardRef","HumanInputPanel"]}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
InternalCompletionInputProvider,
|
|
6
6
|
useCompletionContext,
|
|
7
7
|
useCompletionInput
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-SOG2GVE4.js";
|
|
9
9
|
|
|
10
10
|
// src/completion/form.tsx
|
|
11
11
|
import {
|
|
@@ -61,7 +61,6 @@ var CompletionForm = forwardRef(function CompletionForm2({ onSubmit, ...props },
|
|
|
61
61
|
{
|
|
62
62
|
...props,
|
|
63
63
|
onSubmit: handleSubmit,
|
|
64
|
-
"data-anvia-completion-form": "",
|
|
65
64
|
"data-state": completion.status
|
|
66
65
|
},
|
|
67
66
|
ref
|
|
@@ -98,8 +97,7 @@ var CompletionInput = forwardRef(
|
|
|
98
97
|
disabled: props.disabled ?? (input.status === "submitted" || input.status === "streaming"),
|
|
99
98
|
onChange: handleChange,
|
|
100
99
|
onKeyDown: handleKeyDown,
|
|
101
|
-
value: input.input
|
|
102
|
-
"data-anvia-completion-input": ""
|
|
100
|
+
value: input.input
|
|
103
101
|
},
|
|
104
102
|
ref
|
|
105
103
|
);
|
|
@@ -116,7 +114,6 @@ var CompletionSubmit = forwardRef(
|
|
|
116
114
|
children: props.children ?? "Complete",
|
|
117
115
|
disabled,
|
|
118
116
|
type: props.type ?? "submit",
|
|
119
|
-
"data-anvia-completion-submit": "",
|
|
120
117
|
"data-state": disabled ? "disabled" : "enabled"
|
|
121
118
|
},
|
|
122
119
|
ref
|
|
@@ -145,7 +142,6 @@ var CompletionStop = forwardRef(
|
|
|
145
142
|
disabled,
|
|
146
143
|
onClick: handleClick,
|
|
147
144
|
type: props.type ?? "button",
|
|
148
|
-
"data-anvia-completion-stop": "",
|
|
149
145
|
"data-state": disabled ? "disabled" : "enabled"
|
|
150
146
|
},
|
|
151
147
|
ref
|
|
@@ -162,7 +158,6 @@ var CompletionRoot = forwardRef2(
|
|
|
162
158
|
"div",
|
|
163
159
|
{
|
|
164
160
|
...props,
|
|
165
|
-
"data-anvia-completion": "",
|
|
166
161
|
"data-state": completion.status
|
|
167
162
|
},
|
|
168
163
|
ref
|
|
@@ -177,8 +172,7 @@ var CompletionOutput = forwardRef2(
|
|
|
177
172
|
"div",
|
|
178
173
|
{
|
|
179
174
|
...props,
|
|
180
|
-
children: renderedChildren ?? completion.completion
|
|
181
|
-
"data-anvia-completion-output": ""
|
|
175
|
+
children: renderedChildren ?? completion.completion
|
|
182
176
|
},
|
|
183
177
|
ref
|
|
184
178
|
);
|
|
@@ -186,7 +180,7 @@ var CompletionOutput = forwardRef2(
|
|
|
186
180
|
);
|
|
187
181
|
|
|
188
182
|
// src/completion/index.ts
|
|
189
|
-
var
|
|
183
|
+
var CompletionPrimitive = {
|
|
190
184
|
Root: CompletionRoot,
|
|
191
185
|
Output: CompletionOutput,
|
|
192
186
|
Form: CompletionForm,
|
|
@@ -196,6 +190,6 @@ var Completion = {
|
|
|
196
190
|
};
|
|
197
191
|
|
|
198
192
|
export {
|
|
199
|
-
|
|
193
|
+
CompletionPrimitive
|
|
200
194
|
};
|
|
201
|
-
//# sourceMappingURL=chunk-
|
|
195
|
+
//# sourceMappingURL=chunk-S4XLE2RN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/completion/form.tsx","../src/completion/root.tsx","../src/completion/index.ts"],"sourcesContent":["import {\n type ChangeEvent,\n type FormEvent,\n forwardRef,\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useMemo,\n} from \"react\";\n\nimport {\n type CompletionInputContextValue,\n InternalCompletionInputProvider,\n useCompletionContext,\n useCompletionInput,\n} from \"../contexts\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\n\nconst CompletionForm = forwardRef<HTMLFormElement, PrimitiveProps<\"form\">>(function CompletionForm(\n { onSubmit, ...props },\n ref,\n) {\n const completion = useCompletionContext();\n const active = completion.status === \"submitted\" || completion.status === \"streaming\";\n const canSubmit = completion.input.trim().length > 0 && !active;\n const canStop = active;\n\n const submit = useCallback(async () => {\n if (!canSubmit) {\n return;\n }\n await completion.submit();\n }, [canSubmit, completion]);\n\n const value = useMemo<CompletionInputContextValue>(\n () => ({\n input: completion.input,\n setInput: completion.setInput,\n submit,\n stop: completion.stop,\n status: completion.status,\n canSubmit,\n canStop,\n }),\n [\n canStop,\n canSubmit,\n completion.input,\n completion.setInput,\n completion.status,\n completion.stop,\n submit,\n ],\n );\n\n const handleSubmit = useCallback(\n (event: FormEvent<HTMLFormElement>) => {\n (onSubmit as ((event: FormEvent<HTMLFormElement>) => void) | undefined)?.(event);\n if (event.defaultPrevented) {\n return;\n }\n event.preventDefault();\n void submit();\n },\n [onSubmit, submit],\n );\n\n return (\n <InternalCompletionInputProvider value={value}>\n {renderPrimitive(\n \"form\",\n {\n ...props,\n onSubmit: handleSubmit,\n \"data-state\": completion.status,\n } as PrimitiveProps<\"form\">,\n ref,\n )}\n </InternalCompletionInputProvider>\n );\n});\n\nconst CompletionInput = forwardRef<HTMLTextAreaElement, PrimitiveProps<\"textarea\">>(\n function CompletionInput({ onChange, onKeyDown, ...props }, ref) {\n const input = useCompletionInput();\n\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLTextAreaElement>) => {\n onChange?.(event);\n if (!event.defaultPrevented) {\n input.setInput(event.currentTarget.value);\n }\n },\n [input, onChange],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLTextAreaElement>) => {\n onKeyDown?.(event);\n if (\n event.defaultPrevented ||\n event.key !== \"Enter\" ||\n event.shiftKey ||\n event.nativeEvent.isComposing\n ) {\n return;\n }\n event.preventDefault();\n void input.submit();\n },\n [input, onKeyDown],\n );\n\n return renderPrimitive(\n \"textarea\",\n {\n ...props,\n \"aria-label\": props[\"aria-label\"] ?? \"Prompt\",\n disabled: props.disabled ?? (input.status === \"submitted\" || input.status === \"streaming\"),\n onChange: handleChange,\n onKeyDown: handleKeyDown,\n value: input.input,\n } as PrimitiveProps<\"textarea\">,\n ref,\n );\n },\n);\n\nconst CompletionSubmit = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(\n function CompletionSubmit(props, ref) {\n const input = useCompletionInput();\n const disabled = props.disabled ?? !input.canSubmit;\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Complete\",\n disabled,\n type: props.type ?? \"submit\",\n \"data-state\": disabled ? \"disabled\" : \"enabled\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\nconst CompletionStop = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(\n function CompletionStop({ onClick, ...props }, ref) {\n const input = useCompletionInput();\n const disabled = props.disabled ?? !input.canStop;\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled) {\n return;\n }\n input.stop();\n },\n [disabled, input, onClick],\n );\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Stop\",\n disabled,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": disabled ? \"disabled\" : \"enabled\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\nexport { CompletionForm, CompletionInput, CompletionStop, CompletionSubmit };\n","import { forwardRef, type ReactNode } from \"react\";\n\nimport { useCompletionContext } from \"../contexts\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\n\ntype CompletionOutputChildren = ReactNode | ((completion: string) => ReactNode);\n\nconst CompletionRoot = forwardRef<HTMLDivElement, PrimitiveProps<\"div\">>(\n function CompletionRoot(props, ref) {\n const completion = useCompletionContext();\n return renderPrimitive(\n \"div\",\n {\n ...props,\n \"data-state\": completion.status,\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\ntype CompletionOutputProps = PrimitiveProps<\"div\"> & {\n children?: CompletionOutputChildren;\n};\n\nconst CompletionOutput = forwardRef<HTMLDivElement, CompletionOutputProps>(\n function CompletionOutput({ children, ...props }, ref) {\n const completion = useCompletionContext();\n const renderedChildren =\n typeof children === \"function\" ? children(completion.completion) : children;\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderedChildren ?? completion.completion,\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\nexport { CompletionOutput, CompletionRoot };\n","import { CompletionForm, CompletionInput, CompletionStop, CompletionSubmit } from \"./form\";\nimport { CompletionOutput, CompletionRoot } from \"./root\";\n\nexport const CompletionPrimitive = {\n Root: CompletionRoot,\n Output: CompletionOutput,\n Form: CompletionForm,\n Input: CompletionInput,\n Submit: CompletionSubmit,\n Stop: CompletionStop,\n} as const;\n\nexport type {\n CompletionController,\n CompletionInputContextValue,\n CompletionProviderProps,\n} from \"../contexts\";\nexport { CompletionProvider, useCompletionContext, useCompletionInput } from \"../contexts\";\n"],"mappings":";;;;;;;;;;AAAA;AAAA,EAGE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AA4DH;AAlDJ,IAAM,iBAAiB,WAAoD,SAASA,gBAClF,EAAE,UAAU,GAAG,MAAM,GACrB,KACA;AACA,QAAM,aAAa,qBAAqB;AACxC,QAAM,SAAS,WAAW,WAAW,eAAe,WAAW,WAAW;AAC1E,QAAM,YAAY,WAAW,MAAM,KAAK,EAAE,SAAS,KAAK,CAAC;AACzD,QAAM,UAAU;AAEhB,QAAM,SAAS,YAAY,YAAY;AACrC,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AACA,UAAM,WAAW,OAAO;AAAA,EAC1B,GAAG,CAAC,WAAW,UAAU,CAAC;AAE1B,QAAM,QAAQ;AAAA,IACZ,OAAO;AAAA,MACL,OAAO,WAAW;AAAA,MAClB,UAAU,WAAW;AAAA,MACrB;AAAA,MACA,MAAM,WAAW;AAAA,MACjB,QAAQ,WAAW;AAAA,MACnB;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MACX,WAAW;AAAA,MACX,WAAW;AAAA,MACX,WAAW;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAEA,QAAM,eAAe;AAAA,IACnB,CAAC,UAAsC;AACrC,MAAC,WAAyE,KAAK;AAC/E,UAAI,MAAM,kBAAkB;AAC1B;AAAA,MACF;AACA,YAAM,eAAe;AACrB,WAAK,OAAO;AAAA,IACd;AAAA,IACA,CAAC,UAAU,MAAM;AAAA,EACnB;AAEA,SACE,oBAAC,mCAAgC,OAC9B;AAAA,IACC;AAAA,IACA;AAAA,MACE,GAAG;AAAA,MACH,UAAU;AAAA,MACV,cAAc,WAAW;AAAA,IAC3B;AAAA,IACA;AAAA,EACF,GACF;AAEJ,CAAC;AAED,IAAM,kBAAkB;AAAA,EACtB,SAAS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AM,WAAW,MAAM,YAAY,CAAC,MAAM;AAE1C,UAAM,cAAc;AAAA,MAClB,CAAC,UAAyC;AACxC,kBAAU,KAAK;AACf,YAAI,MAAM,oBAAoB,UAAU;AACtC;AAAA,QACF;AACA,cAAM,KAAK;AAAA,MACb;AAAA,MACA,CAAC,UAAU,OAAO,OAAO;AAAA,IAC3B;AAEA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH,UAAU,MAAM,YAAY;AAAA,QAC5B;AAAA,QACA,SAAS;AAAA,QACT,MAAM,MAAM,QAAQ;AAAA,QACpB,cAAc,WAAW,aAAa;AAAA,MACxC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;;;AChLA,SAAS,cAAAC,mBAAkC;AAO3C,IAAM,iBAAiBC;AAAA,EACrB,SAASC,gBAAe,OAAO,KAAK;AAClC,UAAM,aAAa,qBAAqB;AACxC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH,cAAc,WAAW;AAAA,MAC3B;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAMA,IAAM,mBAAmBD;AAAA,EACvB,SAASE,kBAAiB,EAAE,UAAU,GAAG,MAAM,GAAG,KAAK;AACrD,UAAM,aAAa,qBAAqB;AACxC,UAAM,mBACJ,OAAO,aAAa,aAAa,SAAS,WAAW,UAAU,IAAI;AAErE,WAAO;AAAA,MACL;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH,UAAU,oBAAoB,WAAW;AAAA,MAC3C;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;;;ACrCO,IAAM,sBAAsB;AAAA,EACjC,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AACR;","names":["CompletionForm","CompletionInput","CompletionSubmit","CompletionStop","forwardRef","forwardRef","CompletionRoot","CompletionOutput"]}
|
|
@@ -10,7 +10,7 @@ function InternalAttachmentProvider({
|
|
|
10
10
|
function useAttachment() {
|
|
11
11
|
const value = useContext(AttachmentContext);
|
|
12
12
|
if (value === void 0) {
|
|
13
|
-
throw new Error("Attachment primitives must be used inside
|
|
13
|
+
throw new Error("Attachment primitives must be used inside AttachmentPrimitive.Root.");
|
|
14
14
|
}
|
|
15
15
|
return value;
|
|
16
16
|
}
|
|
@@ -85,7 +85,7 @@ function InternalCompletionInputProvider({
|
|
|
85
85
|
function useCompletionInput() {
|
|
86
86
|
const value = useContext4(CompletionInputContext);
|
|
87
87
|
if (value === void 0) {
|
|
88
|
-
throw new Error("Completion input primitives must be used inside
|
|
88
|
+
throw new Error("Completion input primitives must be used inside CompletionPrimitive.Form.");
|
|
89
89
|
}
|
|
90
90
|
return value;
|
|
91
91
|
}
|
|
@@ -102,7 +102,7 @@ function InternalComposerProvider({
|
|
|
102
102
|
function useComposer() {
|
|
103
103
|
const value = useContext5(ComposerContext);
|
|
104
104
|
if (value === void 0) {
|
|
105
|
-
throw new Error("Composer primitives must be used inside
|
|
105
|
+
throw new Error("Composer primitives must be used inside ComposerPrimitive.Root.");
|
|
106
106
|
}
|
|
107
107
|
return value;
|
|
108
108
|
}
|
|
@@ -144,21 +144,23 @@ function InternalQuestionPromptProvider({
|
|
|
144
144
|
function useApproval() {
|
|
145
145
|
const value = useContext6(ApprovalContext);
|
|
146
146
|
if (value === void 0) {
|
|
147
|
-
throw new Error("Approval primitives must be used inside
|
|
147
|
+
throw new Error("Approval primitives must be used inside HumanInputPrimitive.Approval.");
|
|
148
148
|
}
|
|
149
149
|
return value;
|
|
150
150
|
}
|
|
151
151
|
function useQuestion() {
|
|
152
152
|
const value = useContext6(QuestionContext);
|
|
153
153
|
if (value === void 0) {
|
|
154
|
-
throw new Error("Question primitives must be used inside
|
|
154
|
+
throw new Error("Question primitives must be used inside HumanInputPrimitive.Question.");
|
|
155
155
|
}
|
|
156
156
|
return value;
|
|
157
157
|
}
|
|
158
158
|
function useQuestionPrompt() {
|
|
159
159
|
const value = useContext6(QuestionPromptContext);
|
|
160
160
|
if (value === void 0) {
|
|
161
|
-
throw new Error(
|
|
161
|
+
throw new Error(
|
|
162
|
+
"Question choice primitives must be used inside HumanInputPrimitive.QuestionPrompt."
|
|
163
|
+
);
|
|
162
164
|
}
|
|
163
165
|
return value;
|
|
164
166
|
}
|
|
@@ -175,7 +177,7 @@ function InternalImageProvider({
|
|
|
175
177
|
function useImage() {
|
|
176
178
|
const value = useContext7(ImageContext);
|
|
177
179
|
if (value === void 0) {
|
|
178
|
-
throw new Error("Image primitives must be used inside
|
|
180
|
+
throw new Error("Image primitives must be used inside ImagePrimitive.Root.");
|
|
179
181
|
}
|
|
180
182
|
return value;
|
|
181
183
|
}
|
|
@@ -205,14 +207,18 @@ function InternalMessagePartProvider({
|
|
|
205
207
|
function useMessage() {
|
|
206
208
|
const value = useContext8(MessageContext);
|
|
207
209
|
if (value === void 0) {
|
|
208
|
-
throw new Error(
|
|
210
|
+
throw new Error(
|
|
211
|
+
"Message primitives must be used inside MessagePrimitive.Root or ThreadPrimitive.Messages."
|
|
212
|
+
);
|
|
209
213
|
}
|
|
210
214
|
return value;
|
|
211
215
|
}
|
|
212
216
|
function useMessagePart() {
|
|
213
217
|
const value = useContext8(MessagePartContext);
|
|
214
218
|
if (value === void 0) {
|
|
215
|
-
throw new Error(
|
|
219
|
+
throw new Error(
|
|
220
|
+
"Message part primitives must be used inside MessagePrimitive.Parts or MessagePrimitive.Part."
|
|
221
|
+
);
|
|
216
222
|
}
|
|
217
223
|
return value;
|
|
218
224
|
}
|
|
@@ -232,7 +238,9 @@ function InternalSelectionToolbarProvider({
|
|
|
232
238
|
function useSelectionToolbar() {
|
|
233
239
|
const value = useContext9(SelectionToolbarContext);
|
|
234
240
|
if (value === void 0) {
|
|
235
|
-
throw new Error(
|
|
241
|
+
throw new Error(
|
|
242
|
+
"SelectionToolbar primitives must be used inside SelectionToolbarPrimitive.Root."
|
|
243
|
+
);
|
|
236
244
|
}
|
|
237
245
|
return value;
|
|
238
246
|
}
|
|
@@ -253,15 +261,22 @@ function InternalThreadProvider({
|
|
|
253
261
|
function useThread() {
|
|
254
262
|
const value = useContext10(ThreadContext);
|
|
255
263
|
if (value === void 0) {
|
|
256
|
-
throw new Error("Thread primitives must be used inside
|
|
264
|
+
throw new Error("Thread primitives must be used inside ThreadPrimitive.Root.");
|
|
257
265
|
}
|
|
258
266
|
return value;
|
|
259
267
|
}
|
|
260
268
|
|
|
261
269
|
// src/contexts/thread-list.tsx
|
|
262
|
-
import {
|
|
270
|
+
import {
|
|
271
|
+
createContext as createContext11,
|
|
272
|
+
createElement as createElement11,
|
|
273
|
+
useContext as useContext11
|
|
274
|
+
} from "react";
|
|
263
275
|
var ThreadListContext = createContext11(void 0);
|
|
264
276
|
var ThreadListItemContext = createContext11(void 0);
|
|
277
|
+
var ThreadListRootContext = createContext11(
|
|
278
|
+
void 0
|
|
279
|
+
);
|
|
265
280
|
function ThreadListProvider({
|
|
266
281
|
controller,
|
|
267
282
|
children
|
|
@@ -274,6 +289,12 @@ function InternalThreadListItemProvider({
|
|
|
274
289
|
}) {
|
|
275
290
|
return createElement11(ThreadListItemContext.Provider, { value }, children);
|
|
276
291
|
}
|
|
292
|
+
function InternalThreadListRootProvider({
|
|
293
|
+
value,
|
|
294
|
+
children
|
|
295
|
+
}) {
|
|
296
|
+
return createElement11(ThreadListRootContext.Provider, { value }, children);
|
|
297
|
+
}
|
|
277
298
|
function useThreadList() {
|
|
278
299
|
const value = useContext11(ThreadListContext);
|
|
279
300
|
if (value === void 0) {
|
|
@@ -284,7 +305,14 @@ function useThreadList() {
|
|
|
284
305
|
function useThreadListItem() {
|
|
285
306
|
const value = useContext11(ThreadListItemContext);
|
|
286
307
|
if (value === void 0) {
|
|
287
|
-
throw new Error("ThreadListItem primitives must be used inside
|
|
308
|
+
throw new Error("ThreadListItem primitives must be used inside ThreadListPrimitive.Items.");
|
|
309
|
+
}
|
|
310
|
+
return value;
|
|
311
|
+
}
|
|
312
|
+
function useInternalThreadListRoot() {
|
|
313
|
+
const value = useContext11(ThreadListRootContext);
|
|
314
|
+
if (value === void 0) {
|
|
315
|
+
throw new Error("Thread-list primitives must be used inside ThreadListPrimitive.Root.");
|
|
288
316
|
}
|
|
289
317
|
return value;
|
|
290
318
|
}
|
|
@@ -321,7 +349,9 @@ export {
|
|
|
321
349
|
useThread,
|
|
322
350
|
ThreadListProvider,
|
|
323
351
|
InternalThreadListItemProvider,
|
|
352
|
+
InternalThreadListRootProvider,
|
|
324
353
|
useThreadList,
|
|
325
|
-
useThreadListItem
|
|
354
|
+
useThreadListItem,
|
|
355
|
+
useInternalThreadListRoot
|
|
326
356
|
};
|
|
327
|
-
//# sourceMappingURL=chunk-
|
|
357
|
+
//# sourceMappingURL=chunk-SOG2GVE4.js.map
|