@anvia/react-ui 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -0
  3. package/dist/attachment/index.d.ts +21 -0
  4. package/dist/attachment/index.js +12 -0
  5. package/dist/attachment/index.js.map +1 -0
  6. package/dist/attachment-BP597fV3.d.ts +9 -0
  7. package/dist/chat/index.d.ts +106 -0
  8. package/dist/chat/index.js +22 -0
  9. package/dist/chat/index.js.map +1 -0
  10. package/dist/chat-B3kucz1w.d.ts +13 -0
  11. package/dist/chunk-7AS6R7BB.js +230 -0
  12. package/dist/chunk-7AS6R7BB.js.map +1 -0
  13. package/dist/chunk-AOZN3SWB.js +529 -0
  14. package/dist/chunk-AOZN3SWB.js.map +1 -0
  15. package/dist/chunk-AXZB6JSE.js +813 -0
  16. package/dist/chunk-AXZB6JSE.js.map +1 -0
  17. package/dist/chunk-LSHD67YK.js +200 -0
  18. package/dist/chunk-LSHD67YK.js.map +1 -0
  19. package/dist/chunk-RRINF6FN.js +125 -0
  20. package/dist/chunk-RRINF6FN.js.map +1 -0
  21. package/dist/chunk-T3ZFZ3NP.js +30 -0
  22. package/dist/chunk-T3ZFZ3NP.js.map +1 -0
  23. package/dist/chunk-WK33ER4Q.js +411 -0
  24. package/dist/chunk-WK33ER4Q.js.map +1 -0
  25. package/dist/completion/index.d.ts +28 -0
  26. package/dist/completion/index.js +16 -0
  27. package/dist/completion/index.js.map +1 -0
  28. package/dist/completion-input-WjK6kUyG.d.ts +23 -0
  29. package/dist/human-input/index.d.ts +76 -0
  30. package/dist/human-input/index.js +20 -0
  31. package/dist/human-input/index.js.map +1 -0
  32. package/dist/human-input-CydeYm_7.d.ts +20 -0
  33. package/dist/index.d.ts +15 -0
  34. package/dist/index.js +56 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/message/index.d.ts +87 -0
  37. package/dist/message/index.js +17 -0
  38. package/dist/message/index.js.map +1 -0
  39. package/dist/message-Beb4ZLNU.d.ts +12 -0
  40. package/dist/render-CRKWam2v.d.ts +8 -0
  41. package/dist/shared.d.ts +9 -0
  42. package/dist/shared.js +33 -0
  43. package/dist/shared.js.map +1 -0
  44. package/dist/styles.css +47 -0
  45. package/dist/thread-CluT3m5k.d.ts +31 -0
  46. package/package.json +82 -0
@@ -0,0 +1,411 @@
1
+ import {
2
+ renderPrimitive
3
+ } from "./chunk-T3ZFZ3NP.js";
4
+ import {
5
+ InternalApprovalProvider,
6
+ InternalQuestionPromptProvider,
7
+ InternalQuestionProvider,
8
+ useApproval,
9
+ useChatContext,
10
+ useHumanInput,
11
+ useQuestion,
12
+ useQuestionPrompt
13
+ } from "./chunk-7AS6R7BB.js";
14
+
15
+ // src/human-input/approvals.tsx
16
+ import { forwardRef, useCallback } from "react";
17
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
18
+ var HumanInputStatus = forwardRef(
19
+ function HumanInputStatus2({ children, ...props }, ref) {
20
+ const humanInput = useHumanInput();
21
+ const renderedChildren = typeof children === "function" ? children(humanInput) : children;
22
+ const pendingCount = humanInput.approvals.pending.length + humanInput.questions.pending.length;
23
+ return renderPrimitive(
24
+ "div",
25
+ {
26
+ ...props,
27
+ children: renderedChildren ?? `${pendingCount} pending`,
28
+ "data-anvia-human-input-status": "",
29
+ "data-pending": String(pendingCount)
30
+ },
31
+ ref
32
+ );
33
+ }
34
+ );
35
+ var HumanInputApprovals = forwardRef(
36
+ function HumanInputApprovals2({ children, filter = "pending", keepMounted = false, ...props }, ref) {
37
+ const humanInput = useHumanInput();
38
+ const approvals = filter === "all" ? humanInput.approvals.all : humanInput.approvals.pending;
39
+ const empty = approvals.length === 0;
40
+ if (empty && !keepMounted) {
41
+ return null;
42
+ }
43
+ return renderPrimitive(
44
+ "div",
45
+ {
46
+ ...props,
47
+ children: approvals.map((approval) => /* @__PURE__ */ jsx(InternalApprovalProvider, { approval, children: typeof children === "function" ? children(approval) : children ?? /* @__PURE__ */ jsx(HumanInputApproval, {}) }, approval.id)),
48
+ "data-anvia-approvals": "",
49
+ "data-empty": empty ? "" : void 0
50
+ },
51
+ ref
52
+ );
53
+ }
54
+ );
55
+ var HumanInputApproval = forwardRef(
56
+ function HumanInputApproval2({ children, ...props }, ref) {
57
+ const { approval } = useApproval();
58
+ const renderedChildren = typeof children === "function" ? children(approval) : children ?? defaultApprovalContent(approval);
59
+ return renderPrimitive(
60
+ "div",
61
+ {
62
+ ...props,
63
+ children: renderedChildren,
64
+ "data-anvia-approval": "",
65
+ "data-state": approval.status
66
+ },
67
+ ref
68
+ );
69
+ }
70
+ );
71
+ var HumanInputApprove = forwardRef(
72
+ function HumanInputApprove2({ onClick, ...props }, ref) {
73
+ const chat = useChatContext();
74
+ const { approval, reason } = useApproval();
75
+ const disabled = props.disabled ?? (approval.status !== "pending" || chat.decidingApprovals.has(approval.id));
76
+ const handleClick = useCallback(
77
+ (event) => {
78
+ onClick?.(event);
79
+ if (event.defaultPrevented || disabled) {
80
+ return;
81
+ }
82
+ const decisionReason = reason.trim().length > 0 ? reason : void 0;
83
+ void (decisionReason === void 0 ? chat.approveTool(approval.id) : chat.approveTool(approval.id, decisionReason));
84
+ },
85
+ [approval.id, chat, disabled, onClick, reason]
86
+ );
87
+ return renderPrimitive(
88
+ "button",
89
+ {
90
+ ...props,
91
+ children: props.children ?? "Approve",
92
+ disabled,
93
+ onClick: handleClick,
94
+ type: props.type ?? "button",
95
+ "data-anvia-approve": "",
96
+ "data-state": disabled ? "disabled" : "enabled"
97
+ },
98
+ ref
99
+ );
100
+ }
101
+ );
102
+ var HumanInputReject = forwardRef(
103
+ function HumanInputReject2({ onClick, ...props }, ref) {
104
+ const chat = useChatContext();
105
+ const { approval, reason } = useApproval();
106
+ const disabled = props.disabled ?? (approval.status !== "pending" || chat.decidingApprovals.has(approval.id));
107
+ const handleClick = useCallback(
108
+ (event) => {
109
+ onClick?.(event);
110
+ if (event.defaultPrevented || disabled) {
111
+ return;
112
+ }
113
+ const decisionReason = reason.trim().length > 0 ? reason : void 0;
114
+ void (decisionReason === void 0 ? chat.rejectTool(approval.id) : chat.rejectTool(approval.id, decisionReason));
115
+ },
116
+ [approval.id, chat, disabled, onClick, reason]
117
+ );
118
+ return renderPrimitive(
119
+ "button",
120
+ {
121
+ ...props,
122
+ children: props.children ?? "Reject",
123
+ disabled,
124
+ onClick: handleClick,
125
+ type: props.type ?? "button",
126
+ "data-anvia-reject": "",
127
+ "data-state": disabled ? "disabled" : "enabled"
128
+ },
129
+ ref
130
+ );
131
+ }
132
+ );
133
+ var HumanInputApprovalReason = forwardRef(
134
+ function HumanInputApprovalReason2({ onChange, ...props }, ref) {
135
+ const approval = useApproval();
136
+ const handleChange = useCallback(
137
+ (event) => {
138
+ onChange?.(event);
139
+ if (!event.defaultPrevented) {
140
+ approval.setReason(event.currentTarget.value);
141
+ }
142
+ },
143
+ [approval, onChange]
144
+ );
145
+ return renderPrimitive(
146
+ "textarea",
147
+ {
148
+ ...props,
149
+ "aria-label": props["aria-label"] ?? "Approval reason",
150
+ onChange: handleChange,
151
+ value: approval.reason,
152
+ "data-anvia-approval-reason": ""
153
+ },
154
+ ref
155
+ );
156
+ }
157
+ );
158
+ function defaultApprovalContent(approval) {
159
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
160
+ /* @__PURE__ */ jsx("div", { "data-anvia-approval-tool": "", children: approval.toolName }),
161
+ approval.args !== void 0 ? /* @__PURE__ */ jsx("pre", { "data-anvia-approval-args": "", children: approval.args }) : null,
162
+ /* @__PURE__ */ jsx(HumanInputApprovalReason, {}),
163
+ /* @__PURE__ */ jsx(HumanInputApprove, {}),
164
+ /* @__PURE__ */ jsx(HumanInputReject, {})
165
+ ] });
166
+ }
167
+
168
+ // src/human-input/panel.tsx
169
+ import { forwardRef as forwardRef3 } from "react";
170
+
171
+ // src/human-input/questions.tsx
172
+ import {
173
+ forwardRef as forwardRef2,
174
+ useCallback as useCallback2,
175
+ useMemo,
176
+ useState
177
+ } from "react";
178
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
179
+ var HumanInputQuestions = forwardRef2(
180
+ function HumanInputQuestions2({ children, filter = "pending", keepMounted = false, ...props }, ref) {
181
+ const humanInput = useHumanInput();
182
+ const questions = filter === "all" ? humanInput.questions.all : humanInput.questions.pending;
183
+ const empty = questions.length === 0;
184
+ if (empty && !keepMounted) {
185
+ return null;
186
+ }
187
+ return renderPrimitive(
188
+ "div",
189
+ {
190
+ ...props,
191
+ children: questions.map((question) => /* @__PURE__ */ jsx2(QuestionProvider, { question, children: typeof children === "function" ? children(question) : children ?? /* @__PURE__ */ jsx2(HumanInputQuestion, {}) }, question.id)),
192
+ "data-anvia-questions": "",
193
+ "data-empty": empty ? "" : void 0
194
+ },
195
+ ref
196
+ );
197
+ }
198
+ );
199
+ var HumanInputQuestion = forwardRef2(
200
+ function HumanInputQuestion2({ children, ...props }, ref) {
201
+ const { question } = useQuestion();
202
+ const renderedChildren = typeof children === "function" ? children(question) : children ?? defaultQuestionContent(question);
203
+ return renderPrimitive(
204
+ "div",
205
+ {
206
+ ...props,
207
+ children: renderedChildren,
208
+ "data-anvia-question": "",
209
+ "data-state": question.status
210
+ },
211
+ ref
212
+ );
213
+ }
214
+ );
215
+ var HumanInputQuestionPrompt = forwardRef2(
216
+ function HumanInputQuestionPrompt2({ promptId, ...props }, ref) {
217
+ const { question } = useQuestion();
218
+ const prompt = question.questions.find((item) => item.id === promptId) ?? question.questions[0];
219
+ if (prompt === void 0) {
220
+ return null;
221
+ }
222
+ return /* @__PURE__ */ jsx2(InternalQuestionPromptProvider, { prompt, children: renderPrimitive(
223
+ "div",
224
+ {
225
+ ...props,
226
+ children: props.children ?? defaultQuestionPrompt(prompt),
227
+ "data-anvia-question-prompt": ""
228
+ },
229
+ ref
230
+ ) });
231
+ }
232
+ );
233
+ var HumanInputQuestionChoice = forwardRef2(
234
+ function HumanInputQuestionChoice2({ answer, custom = false, onClick, value, ...props }, ref) {
235
+ const { prompt } = useQuestionPrompt();
236
+ const question = useQuestion();
237
+ const choiceValue = value ?? prompt.choices[0]?.value ?? "";
238
+ const choice = prompt.choices.find((item) => item.value === choiceValue);
239
+ const selected = question.answers[prompt.id]?.choice === choiceValue;
240
+ const handleClick = useCallback2(
241
+ (event) => {
242
+ onClick?.(event);
243
+ if (event.defaultPrevented || choiceValue.length === 0) {
244
+ return;
245
+ }
246
+ question.setAnswer(prompt, {
247
+ questionId: prompt.id,
248
+ answer: answer ?? choice?.label ?? choiceValue,
249
+ choice: choiceValue,
250
+ ...custom ? { custom: true } : {}
251
+ });
252
+ },
253
+ [answer, choice?.label, choiceValue, custom, onClick, prompt, question]
254
+ );
255
+ return renderPrimitive(
256
+ "button",
257
+ {
258
+ ...props,
259
+ children: props.children ?? choice?.label ?? choiceValue,
260
+ onClick: handleClick,
261
+ type: props.type ?? "button",
262
+ "data-anvia-question-choice": "",
263
+ "data-state": selected ? "selected" : "idle"
264
+ },
265
+ ref
266
+ );
267
+ }
268
+ );
269
+ var HumanInputQuestionTextAnswer = forwardRef2(
270
+ function HumanInputQuestionTextAnswer2({ onChange, ...props }, ref) {
271
+ const { prompt } = useQuestionPrompt();
272
+ const question = useQuestion();
273
+ const value = question.answers[prompt.id]?.answer ?? "";
274
+ const handleChange = useCallback2(
275
+ (event) => {
276
+ onChange?.(event);
277
+ if (event.defaultPrevented) {
278
+ return;
279
+ }
280
+ const answer = event.currentTarget.value;
281
+ question.setAnswer(prompt, {
282
+ questionId: prompt.id,
283
+ answer,
284
+ custom: true
285
+ });
286
+ },
287
+ [onChange, prompt, question]
288
+ );
289
+ return renderPrimitive(
290
+ "textarea",
291
+ {
292
+ ...props,
293
+ "aria-label": props["aria-label"] ?? prompt.question,
294
+ onChange: handleChange,
295
+ value,
296
+ "data-anvia-question-text-answer": ""
297
+ },
298
+ ref
299
+ );
300
+ }
301
+ );
302
+ var HumanInputQuestionSubmit = forwardRef2(
303
+ function HumanInputQuestionSubmit2({ onClick, ...props }, ref) {
304
+ const chat = useChatContext();
305
+ const question = useQuestion();
306
+ const answers = useMemo(
307
+ () => question.question.questions.flatMap((prompt) => {
308
+ const answer = question.answers[prompt.id];
309
+ return answer === void 0 || answer.answer.trim().length === 0 ? [] : [answer];
310
+ }),
311
+ [question]
312
+ );
313
+ const disabled = props.disabled ?? (question.question.status !== "pending" || chat.answeringQuestions.has(question.question.id) || answers.length === 0);
314
+ const handleClick = useCallback2(
315
+ (event) => {
316
+ onClick?.(event);
317
+ if (event.defaultPrevented || disabled) {
318
+ return;
319
+ }
320
+ void chat.answerToolQuestion(question.question.id, answers);
321
+ },
322
+ [answers, chat, disabled, onClick, question.question.id]
323
+ );
324
+ return renderPrimitive(
325
+ "button",
326
+ {
327
+ ...props,
328
+ children: props.children ?? "Submit",
329
+ disabled,
330
+ onClick: handleClick,
331
+ type: props.type ?? "button",
332
+ "data-anvia-question-submit": "",
333
+ "data-state": disabled ? "disabled" : "enabled"
334
+ },
335
+ ref
336
+ );
337
+ }
338
+ );
339
+ function QuestionProvider({
340
+ question,
341
+ children
342
+ }) {
343
+ const [answers, setAnswers] = useState({});
344
+ const setAnswer = useCallback2((prompt, answer) => {
345
+ setAnswers((current) => ({ ...current, [prompt.id]: answer }));
346
+ }, []);
347
+ const value = useMemo(
348
+ () => ({ question, answers, setAnswer }),
349
+ [answers, question, setAnswer]
350
+ );
351
+ return /* @__PURE__ */ jsx2(InternalQuestionProvider, { value, children });
352
+ }
353
+ function defaultQuestionContent(question) {
354
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
355
+ /* @__PURE__ */ jsx2("div", { "data-anvia-question-tool": "", children: question.toolName }),
356
+ question.args !== void 0 ? /* @__PURE__ */ jsx2("pre", { "data-anvia-question-args": "", children: question.args }) : null,
357
+ question.questions.map((prompt) => /* @__PURE__ */ jsx2(HumanInputQuestionPrompt, { promptId: prompt.id }, prompt.id)),
358
+ /* @__PURE__ */ jsx2(HumanInputQuestionSubmit, {})
359
+ ] });
360
+ }
361
+ function defaultQuestionPrompt(prompt) {
362
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
363
+ /* @__PURE__ */ jsx2("div", { "data-anvia-question-text": "", children: prompt.question }),
364
+ prompt.choices.length > 0 ? /* @__PURE__ */ jsx2("div", { "data-anvia-question-choices": "", children: prompt.choices.map((choice) => /* @__PURE__ */ jsx2(HumanInputQuestionChoice, { value: choice.value, children: choice.label }, choice.value)) }) : /* @__PURE__ */ jsx2(HumanInputQuestionTextAnswer, {})
365
+ ] });
366
+ }
367
+
368
+ // src/human-input/panel.tsx
369
+ import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
370
+ var HumanInputPanel = forwardRef3(function HumanInputPanel2({ children, filter = "pending", ...props }, ref) {
371
+ const humanInput = useHumanInput();
372
+ const approvals = filter === "all" ? humanInput.approvals.all : humanInput.approvals.pending;
373
+ const questions = filter === "all" ? humanInput.questions.all : humanInput.questions.pending;
374
+ if (approvals.length === 0 && questions.length === 0) {
375
+ return null;
376
+ }
377
+ return renderPrimitive(
378
+ "div",
379
+ {
380
+ ...props,
381
+ children: children ?? /* @__PURE__ */ jsxs3(Fragment3, { children: [
382
+ /* @__PURE__ */ jsx3(HumanInputApprovals, { filter }),
383
+ /* @__PURE__ */ jsx3(HumanInputQuestions, { filter })
384
+ ] }),
385
+ "data-anvia-human-input-panel": ""
386
+ },
387
+ ref
388
+ );
389
+ });
390
+
391
+ // src/human-input/index.ts
392
+ var HumanInput = {
393
+ Panel: HumanInputPanel,
394
+ Status: HumanInputStatus,
395
+ Approvals: HumanInputApprovals,
396
+ Approval: HumanInputApproval,
397
+ ApprovalReason: HumanInputApprovalReason,
398
+ Approve: HumanInputApprove,
399
+ Reject: HumanInputReject,
400
+ Questions: HumanInputQuestions,
401
+ Question: HumanInputQuestion,
402
+ QuestionPrompt: HumanInputQuestionPrompt,
403
+ QuestionChoice: HumanInputQuestionChoice,
404
+ QuestionTextAnswer: HumanInputQuestionTextAnswer,
405
+ QuestionSubmit: HumanInputQuestionSubmit
406
+ };
407
+
408
+ export {
409
+ HumanInput
410
+ };
411
+ //# sourceMappingURL=chunk-WK33ER4Q.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 { ToolApproval } from \"@anvia/react\";\nimport { type ChangeEvent, forwardRef, type MouseEvent, type ReactNode, useCallback } from \"react\";\n\nimport { InternalApprovalProvider, useApproval, useChatContext, useHumanInput } from \"../contexts\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\n\ntype ApprovalChildren = ReactNode | ((approval: ToolApproval) => 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 \"data-anvia-human-input-status\": \"\",\n \"data-pending\": String(pendingCount),\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.id} approval={approval}>\n {typeof children === \"function\"\n ? children(approval)\n : (children ?? <HumanInputApproval />)}\n </InternalApprovalProvider>\n )),\n \"data-anvia-approvals\": \"\",\n \"data-empty\": empty ? \"\" : undefined,\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-anvia-approval\": \"\",\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 ?? (approval.status !== \"pending\" || chat.decidingApprovals.has(approval.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 void (decisionReason === undefined\n ? chat.approveTool(approval.id)\n : chat.approveTool(approval.id, decisionReason));\n },\n [approval.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-anvia-approve\": \"\",\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 ?? (approval.status !== \"pending\" || chat.decidingApprovals.has(approval.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 void (decisionReason === undefined\n ? chat.rejectTool(approval.id)\n : chat.rejectTool(approval.id, decisionReason));\n },\n [approval.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-anvia-reject\": \"\",\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 \"data-anvia-approval-reason\": \"\",\n } as PrimitiveProps<\"textarea\">,\n ref,\n );\n },\n);\n\nfunction defaultApprovalContent(approval: ToolApproval): ReactNode {\n return (\n <>\n <div data-anvia-approval-tool=\"\">{approval.toolName}</div>\n {approval.args !== undefined ? <pre data-anvia-approval-args=\"\">{approval.args}</pre> : 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 \"data-anvia-human-input-panel\": \"\",\n } as PrimitiveProps<\"div\">,\n ref,\n );\n});\n\nexport { HumanInputPanel };\n","import type { ToolQuestion, ToolQuestionAnswer, ToolQuestionPrompt } from \"@anvia/react\";\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 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: ToolQuestion) => 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.id} question={question}>\n {typeof children === \"function\"\n ? children(question)\n : (children ?? <HumanInputQuestion />)}\n </QuestionProvider>\n )),\n \"data-anvia-questions\": \"\",\n \"data-empty\": empty ? \"\" : undefined,\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-anvia-question\": \"\",\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 = question.questions.find((item) => item.id === promptId) ?? question.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 \"data-anvia-question-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]?.choice === choiceValue;\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || choiceValue.length === 0) {\n return;\n }\n question.setAnswer(prompt, {\n questionId: prompt.id,\n answer: answer ?? choice?.label ?? choiceValue,\n choice: choiceValue,\n ...(custom ? { custom: true } : {}),\n });\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-anvia-question-choice\": \"\",\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]?.answer ?? \"\";\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 answer,\n custom: true,\n });\n },\n [onChange, prompt, question],\n );\n\n return renderPrimitive(\n \"textarea\",\n {\n ...props,\n \"aria-label\": props[\"aria-label\"] ?? prompt.question,\n onChange: handleChange,\n value,\n \"data-anvia-question-text-answer\": \"\",\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.questions.flatMap((prompt) => {\n const answer = question.answers[prompt.id];\n return answer === undefined || answer.answer.trim().length === 0 ? [] : [answer];\n }),\n [question],\n );\n const disabled =\n props.disabled ??\n (question.question.status !== \"pending\" ||\n chat.answeringQuestions.has(question.question.id) ||\n answers.length === 0);\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled) {\n return;\n }\n void chat.answerToolQuestion(question.question.id, answers);\n },\n [answers, chat, disabled, onClick, question.question.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-anvia-question-submit\": \"\",\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: ToolQuestion;\n children?: ReactNode;\n}) {\n const [answers, setAnswers] = useState<Record<string, ToolQuestionAnswer>>({});\n const setAnswer = useCallback((prompt: ToolQuestionPrompt, answer: ToolQuestionAnswer) => {\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: ToolQuestion): ReactNode {\n return (\n <>\n <div data-anvia-question-tool=\"\">{question.toolName}</div>\n {question.args !== undefined ? <pre data-anvia-question-args=\"\">{question.args}</pre> : null}\n {question.questions.map((prompt) => (\n <HumanInputQuestionPrompt key={prompt.id} promptId={prompt.id} />\n ))}\n <HumanInputQuestionSubmit />\n </>\n );\n}\n\nfunction defaultQuestionPrompt(prompt: ToolQuestionPrompt): ReactNode {\n return (\n <>\n <div data-anvia-question-text=\"\">{prompt.question}</div>\n {prompt.choices.length > 0 ? (\n <div data-anvia-question-choices=\"\">\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 HumanInput = {\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":";;;;;;;;;;;;;;;AACA,SAA2B,YAA6C,mBAAmB;AAyD9D,SA4IzB,UA5IyB,KA4Iz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,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"]}
@@ -0,0 +1,28 @@
1
+ import * as react from 'react';
2
+ export { C as CompletionController, a as CompletionInputContextValue, b as CompletionProvider, c as CompletionProviderProps, u as useCompletionContext, d as useCompletionInput } from '../completion-input-WjK6kUyG.js';
3
+ import '@anvia/react';
4
+
5
+ declare const Completion: {
6
+ readonly Root: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
7
+ asChild?: boolean;
8
+ } & react.RefAttributes<HTMLDivElement>>;
9
+ readonly Output: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
10
+ asChild?: boolean;
11
+ } & {
12
+ children?: react.ReactNode | ((completion: string) => react.ReactNode);
13
+ } & react.RefAttributes<HTMLDivElement>>;
14
+ readonly Form: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref">, "asChild"> & {
15
+ asChild?: boolean;
16
+ } & react.RefAttributes<HTMLFormElement>>;
17
+ readonly Input: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref">, "asChild"> & {
18
+ asChild?: boolean;
19
+ } & react.RefAttributes<HTMLTextAreaElement>>;
20
+ readonly Submit: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
21
+ asChild?: boolean;
22
+ } & react.RefAttributes<HTMLButtonElement>>;
23
+ readonly Stop: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
24
+ asChild?: boolean;
25
+ } & react.RefAttributes<HTMLButtonElement>>;
26
+ };
27
+
28
+ export { Completion };
@@ -0,0 +1,16 @@
1
+ import {
2
+ Completion
3
+ } from "../chunk-LSHD67YK.js";
4
+ import "../chunk-T3ZFZ3NP.js";
5
+ import {
6
+ CompletionProvider,
7
+ useCompletionContext,
8
+ useCompletionInput
9
+ } from "../chunk-7AS6R7BB.js";
10
+ export {
11
+ Completion,
12
+ CompletionProvider,
13
+ useCompletionContext,
14
+ useCompletionInput
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,23 @@
1
+ import { UseCompletionResult } from '@anvia/react';
2
+ import { ReactNode, ReactElement } from 'react';
3
+
4
+ type CompletionController<TEvent = unknown> = UseCompletionResult<TEvent>;
5
+ type CompletionProviderProps<TEvent = unknown> = {
6
+ controller: CompletionController<TEvent>;
7
+ children?: ReactNode;
8
+ };
9
+ declare function CompletionProvider<TEvent = unknown>({ controller, children, }: CompletionProviderProps<TEvent>): ReactElement;
10
+ declare function useCompletionContext<TEvent = unknown>(): CompletionController<TEvent>;
11
+
12
+ type CompletionInputContextValue = {
13
+ input: string;
14
+ setInput(input: string): void;
15
+ submit(): Promise<void>;
16
+ stop(): void;
17
+ status: CompletionController["status"];
18
+ canSubmit: boolean;
19
+ canStop: boolean;
20
+ };
21
+ declare function useCompletionInput(): CompletionInputContextValue;
22
+
23
+ export { type CompletionController as C, type CompletionInputContextValue as a, CompletionProvider as b, type CompletionProviderProps as c, useCompletionInput as d, useCompletionContext as u };
@@ -0,0 +1,76 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { ToolApproval, ToolQuestion } from '@anvia/react';
4
+ import { c as useHumanInput } from '../chat-B3kucz1w.js';
5
+ export { u as useChatContext } from '../chat-B3kucz1w.js';
6
+ export { A as ApprovalContextValue, Q as QuestionContextValue, a as QuestionPromptContextValue, u as useApproval, b as useQuestion, c as useQuestionPrompt } from '../human-input-CydeYm_7.js';
7
+ import { P as PrimitiveProps } from '../render-CRKWam2v.js';
8
+
9
+ type ApprovalChildren = ReactNode | ((approval: ToolApproval) => ReactNode);
10
+ type HumanInputFilter = "pending" | "all";
11
+
12
+ type QuestionChildren = ReactNode | ((question: ToolQuestion) => ReactNode);
13
+
14
+ declare const HumanInput: {
15
+ readonly Panel: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
16
+ asChild?: boolean;
17
+ } & {
18
+ filter?: HumanInputFilter;
19
+ } & react.RefAttributes<HTMLDivElement>>;
20
+ readonly Status: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"div">, "children"> & {
21
+ children?: react.ReactNode | ((state: ReturnType<typeof useHumanInput>) => react.ReactNode);
22
+ } & react.RefAttributes<HTMLDivElement>>;
23
+ readonly Approvals: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
24
+ asChild?: boolean;
25
+ } & {
26
+ filter?: HumanInputFilter;
27
+ keepMounted?: boolean;
28
+ children?: ApprovalChildren;
29
+ } & react.RefAttributes<HTMLDivElement>>;
30
+ readonly Approval: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
31
+ asChild?: boolean;
32
+ } & {
33
+ children?: ApprovalChildren;
34
+ } & react.RefAttributes<HTMLDivElement>>;
35
+ readonly ApprovalReason: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref">, "asChild"> & {
36
+ asChild?: boolean;
37
+ } & react.RefAttributes<HTMLTextAreaElement>>;
38
+ readonly Approve: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
39
+ asChild?: boolean;
40
+ } & react.RefAttributes<HTMLButtonElement>>;
41
+ readonly Reject: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
42
+ asChild?: boolean;
43
+ } & react.RefAttributes<HTMLButtonElement>>;
44
+ readonly Questions: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
45
+ asChild?: boolean;
46
+ } & {
47
+ filter?: HumanInputFilter;
48
+ keepMounted?: boolean;
49
+ children?: QuestionChildren;
50
+ } & react.RefAttributes<HTMLDivElement>>;
51
+ readonly Question: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
52
+ asChild?: boolean;
53
+ } & {
54
+ children?: QuestionChildren;
55
+ } & react.RefAttributes<HTMLDivElement>>;
56
+ readonly QuestionPrompt: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
57
+ asChild?: boolean;
58
+ } & {
59
+ promptId?: string;
60
+ } & react.RefAttributes<HTMLDivElement>>;
61
+ readonly QuestionChoice: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
62
+ asChild?: boolean;
63
+ } & {
64
+ value?: string;
65
+ answer?: string;
66
+ custom?: boolean;
67
+ } & react.RefAttributes<HTMLButtonElement>>;
68
+ readonly QuestionTextAnswer: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref">, "asChild"> & {
69
+ asChild?: boolean;
70
+ } & react.RefAttributes<HTMLTextAreaElement>>;
71
+ readonly QuestionSubmit: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
72
+ asChild?: boolean;
73
+ } & react.RefAttributes<HTMLButtonElement>>;
74
+ };
75
+
76
+ export { HumanInput, useHumanInput };
@@ -0,0 +1,20 @@
1
+ import {
2
+ HumanInput
3
+ } from "../chunk-WK33ER4Q.js";
4
+ import "../chunk-T3ZFZ3NP.js";
5
+ import {
6
+ useApproval,
7
+ useChatContext,
8
+ useHumanInput,
9
+ useQuestion,
10
+ useQuestionPrompt
11
+ } from "../chunk-7AS6R7BB.js";
12
+ export {
13
+ HumanInput,
14
+ useApproval,
15
+ useChatContext,
16
+ useHumanInput,
17
+ useQuestion,
18
+ useQuestionPrompt
19
+ };
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}