@anvia/react-ui 1.0.0-rc.1 → 1.0.0-rc.10
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 +52 -39
- package/dist/attachment/index.d.ts +5 -5
- package/dist/attachment/index.js +4 -4
- package/dist/{attachment-BP597fV3.d.ts → attachment-mbjsroli.d.ts} +1 -1
- package/dist/chat/index.d.ts +13 -12
- package/dist/chat/index.js +11 -9
- package/dist/chat-tfA570mg.d.ts +86 -0
- package/dist/{chunk-7RMRM7W3.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-CKA4CE26.js +25 -0
- package/dist/chunk-CKA4CE26.js.map +1 -0
- package/dist/{chunk-JWZDNM5D.js → chunk-CRXNFZRW.js} +145 -125
- package/dist/chunk-CRXNFZRW.js.map +1 -0
- package/dist/{chunk-7HR34SOF.js → chunk-CVXLQCDI.js} +13 -21
- package/dist/chunk-CVXLQCDI.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-FABSIZZ7.js → chunk-HWJIMLHC.js} +97 -90
- package/dist/chunk-HWJIMLHC.js.map +1 -0
- package/dist/{chunk-SBYUKODG.js → chunk-MISX4WUT.js} +10 -15
- package/dist/chunk-MISX4WUT.js.map +1 -0
- package/dist/{chunk-R3NA6BWW.js → chunk-OQE6SHZE.js} +54 -56
- package/dist/chunk-OQE6SHZE.js.map +1 -0
- package/dist/{chunk-VEYJNQVW.js → chunk-S4XLE2RN.js} +11 -16
- package/dist/chunk-S4XLE2RN.js.map +1 -0
- package/dist/{chunk-43U2XQP2.js → chunk-SOG2GVE4.js} +69 -25
- package/dist/chunk-SOG2GVE4.js.map +1 -0
- package/dist/{chunk-56CV6S76.js → chunk-UCBAG42A.js} +9 -21
- package/dist/chunk-UCBAG42A.js.map +1 -0
- package/dist/completion/index.d.ts +4 -3
- package/dist/completion/index.js +4 -4
- package/dist/completion-input-DHlwrhxB.d.ts +24 -0
- package/dist/{composer-CzsbDFPt.d.ts → composer-CigccTLT.d.ts} +19 -7
- package/dist/human-input/index.d.ts +10 -8
- package/dist/human-input/index.js +5 -4
- package/dist/human-input-D7jgYsfM.d.ts +27 -0
- package/dist/image/index.d.ts +6 -6
- package/dist/image/index.js +4 -4
- package/dist/{image-DanUxcl2.d.ts → image-VZv6Ddsn.d.ts} +1 -1
- package/dist/index.d.ts +19 -18
- package/dist/index.js +60 -64
- package/dist/index.js.map +1 -1
- package/dist/message/index.d.ts +12 -11
- package/dist/message/index.js +8 -6
- package/dist/{message-CkEnKhAn.d.ts → message-CNRnZQwU.d.ts} +1 -1
- package/dist/selection-toolbar/index.d.ts +2 -2
- package/dist/selection-toolbar/index.js +5 -4
- package/dist/shared.d.ts +9 -8
- 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 +17 -17
- package/dist/chat-B3kucz1w.d.ts +0 -13
- package/dist/chunk-43U2XQP2.js.map +0 -1
- package/dist/chunk-56CV6S76.js.map +0 -1
- package/dist/chunk-7HR34SOF.js.map +0 -1
- package/dist/chunk-7RMRM7W3.js.map +0 -1
- package/dist/chunk-FABSIZZ7.js.map +0 -1
- package/dist/chunk-JWZDNM5D.js.map +0 -1
- package/dist/chunk-R3NA6BWW.js.map +0 -1
- package/dist/chunk-SBYUKODG.js.map +0 -1
- package/dist/chunk-ULGJLLZE.js.map +0 -1
- package/dist/chunk-VEYJNQVW.js.map +0 -1
- package/dist/completion-input-WjK6kUyG.d.ts +0 -23
- package/dist/human-input-CydeYm_7.d.ts +0 -20
- package/dist/stream/styles.css +0 -17
- package/dist/styles.css +0 -130
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stringifyValue
|
|
3
|
+
} from "./chunk-CKA4CE26.js";
|
|
1
4
|
import {
|
|
2
5
|
renderPrimitive
|
|
3
6
|
} from "./chunk-T3ZFZ3NP.js";
|
|
@@ -10,7 +13,7 @@ import {
|
|
|
10
13
|
useHumanInput,
|
|
11
14
|
useQuestion,
|
|
12
15
|
useQuestionPrompt
|
|
13
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-SOG2GVE4.js";
|
|
14
17
|
|
|
15
18
|
// src/human-input/approvals.tsx
|
|
16
19
|
import { forwardRef, useCallback } from "react";
|
|
@@ -24,9 +27,7 @@ var HumanInputStatus = forwardRef(
|
|
|
24
27
|
"div",
|
|
25
28
|
{
|
|
26
29
|
...props,
|
|
27
|
-
children: renderedChildren ?? `${pendingCount} pending
|
|
28
|
-
"data-anvia-human-input-status": "",
|
|
29
|
-
"data-pending": String(pendingCount)
|
|
30
|
+
children: renderedChildren ?? `${pendingCount} pending`
|
|
30
31
|
},
|
|
31
32
|
ref
|
|
32
33
|
);
|
|
@@ -44,9 +45,8 @@ var HumanInputApprovals = forwardRef(
|
|
|
44
45
|
"div",
|
|
45
46
|
{
|
|
46
47
|
...props,
|
|
47
|
-
children: approvals.map((approval) => /* @__PURE__ */ jsx(InternalApprovalProvider, { approval, children: typeof children === "function" ? children(approval) : children ?? /* @__PURE__ */ jsx(HumanInputApproval, {}) }, approval.id)),
|
|
48
|
-
"data-
|
|
49
|
-
"data-empty": empty ? "" : void 0
|
|
48
|
+
children: approvals.map((approval) => /* @__PURE__ */ jsx(InternalApprovalProvider, { approval, children: typeof children === "function" ? children(approval) : children ?? /* @__PURE__ */ jsx(HumanInputApproval, {}) }, approval.request.id)),
|
|
49
|
+
"data-state": empty ? "empty" : "populated"
|
|
50
50
|
},
|
|
51
51
|
ref
|
|
52
52
|
);
|
|
@@ -61,7 +61,6 @@ var HumanInputApproval = forwardRef(
|
|
|
61
61
|
{
|
|
62
62
|
...props,
|
|
63
63
|
children: renderedChildren,
|
|
64
|
-
"data-anvia-approval": "",
|
|
65
64
|
"data-state": approval.status
|
|
66
65
|
},
|
|
67
66
|
ref
|
|
@@ -72,7 +71,7 @@ var HumanInputApprove = forwardRef(
|
|
|
72
71
|
function HumanInputApprove2({ onClick, ...props }, ref) {
|
|
73
72
|
const chat = useChatContext();
|
|
74
73
|
const { approval, reason } = useApproval();
|
|
75
|
-
const disabled = props.disabled ?? (approval.status !== "pending" || chat.
|
|
74
|
+
const disabled = props.disabled ?? (approval.status !== "pending" || chat.respondingInteractions.has(approval.request.id));
|
|
76
75
|
const handleClick = useCallback(
|
|
77
76
|
(event) => {
|
|
78
77
|
onClick?.(event);
|
|
@@ -80,9 +79,14 @@ var HumanInputApprove = forwardRef(
|
|
|
80
79
|
return;
|
|
81
80
|
}
|
|
82
81
|
const decisionReason = reason.trim().length > 0 ? reason : void 0;
|
|
83
|
-
|
|
82
|
+
const response = { type: "tool-approval", approved: true };
|
|
83
|
+
if (decisionReason !== void 0) Object.assign(response, { reason: decisionReason });
|
|
84
|
+
void chat.respondToInteraction({
|
|
85
|
+
interactionId: approval.request.id,
|
|
86
|
+
response
|
|
87
|
+
});
|
|
84
88
|
},
|
|
85
|
-
[approval.id, chat, disabled, onClick, reason]
|
|
89
|
+
[approval.request.id, chat, disabled, onClick, reason]
|
|
86
90
|
);
|
|
87
91
|
return renderPrimitive(
|
|
88
92
|
"button",
|
|
@@ -92,7 +96,6 @@ var HumanInputApprove = forwardRef(
|
|
|
92
96
|
disabled,
|
|
93
97
|
onClick: handleClick,
|
|
94
98
|
type: props.type ?? "button",
|
|
95
|
-
"data-anvia-approve": "",
|
|
96
99
|
"data-state": disabled ? "disabled" : "enabled"
|
|
97
100
|
},
|
|
98
101
|
ref
|
|
@@ -103,7 +106,7 @@ var HumanInputReject = forwardRef(
|
|
|
103
106
|
function HumanInputReject2({ onClick, ...props }, ref) {
|
|
104
107
|
const chat = useChatContext();
|
|
105
108
|
const { approval, reason } = useApproval();
|
|
106
|
-
const disabled = props.disabled ?? (approval.status !== "pending" || chat.
|
|
109
|
+
const disabled = props.disabled ?? (approval.status !== "pending" || chat.respondingInteractions.has(approval.request.id));
|
|
107
110
|
const handleClick = useCallback(
|
|
108
111
|
(event) => {
|
|
109
112
|
onClick?.(event);
|
|
@@ -111,9 +114,14 @@ var HumanInputReject = forwardRef(
|
|
|
111
114
|
return;
|
|
112
115
|
}
|
|
113
116
|
const decisionReason = reason.trim().length > 0 ? reason : void 0;
|
|
114
|
-
|
|
117
|
+
const response = { type: "tool-approval", approved: false };
|
|
118
|
+
if (decisionReason !== void 0) Object.assign(response, { reason: decisionReason });
|
|
119
|
+
void chat.respondToInteraction({
|
|
120
|
+
interactionId: approval.request.id,
|
|
121
|
+
response
|
|
122
|
+
});
|
|
115
123
|
},
|
|
116
|
-
[approval.id, chat, disabled, onClick, reason]
|
|
124
|
+
[approval.request.id, chat, disabled, onClick, reason]
|
|
117
125
|
);
|
|
118
126
|
return renderPrimitive(
|
|
119
127
|
"button",
|
|
@@ -123,7 +131,6 @@ var HumanInputReject = forwardRef(
|
|
|
123
131
|
disabled,
|
|
124
132
|
onClick: handleClick,
|
|
125
133
|
type: props.type ?? "button",
|
|
126
|
-
"data-anvia-reject": "",
|
|
127
134
|
"data-state": disabled ? "disabled" : "enabled"
|
|
128
135
|
},
|
|
129
136
|
ref
|
|
@@ -148,8 +155,7 @@ var HumanInputApprovalReason = forwardRef(
|
|
|
148
155
|
...props,
|
|
149
156
|
"aria-label": props["aria-label"] ?? "Approval reason",
|
|
150
157
|
onChange: handleChange,
|
|
151
|
-
value: approval.reason
|
|
152
|
-
"data-anvia-approval-reason": ""
|
|
158
|
+
value: approval.reason
|
|
153
159
|
},
|
|
154
160
|
ref
|
|
155
161
|
);
|
|
@@ -157,8 +163,8 @@ var HumanInputApprovalReason = forwardRef(
|
|
|
157
163
|
);
|
|
158
164
|
function defaultApprovalContent(approval) {
|
|
159
165
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
160
|
-
/* @__PURE__ */ jsx("div", {
|
|
161
|
-
approval.
|
|
166
|
+
/* @__PURE__ */ jsx("div", { children: approval.request.toolName }),
|
|
167
|
+
approval.request.input !== void 0 ? /* @__PURE__ */ jsx("pre", { children: stringifyValue(approval.request.input) }) : null,
|
|
162
168
|
/* @__PURE__ */ jsx(HumanInputApprovalReason, {}),
|
|
163
169
|
/* @__PURE__ */ jsx(HumanInputApprove, {}),
|
|
164
170
|
/* @__PURE__ */ jsx(HumanInputReject, {})
|
|
@@ -188,9 +194,8 @@ var HumanInputQuestions = forwardRef2(
|
|
|
188
194
|
"div",
|
|
189
195
|
{
|
|
190
196
|
...props,
|
|
191
|
-
children: questions.map((question) => /* @__PURE__ */ jsx2(QuestionProvider, { question, children: typeof children === "function" ? children(question) : children ?? /* @__PURE__ */ jsx2(HumanInputQuestion, {}) }, question.id)),
|
|
192
|
-
"data-
|
|
193
|
-
"data-empty": empty ? "" : void 0
|
|
197
|
+
children: questions.map((question) => /* @__PURE__ */ jsx2(QuestionProvider, { question, children: typeof children === "function" ? children(question) : children ?? /* @__PURE__ */ jsx2(HumanInputQuestion, {}) }, question.request.id)),
|
|
198
|
+
"data-state": empty ? "empty" : "populated"
|
|
194
199
|
},
|
|
195
200
|
ref
|
|
196
201
|
);
|
|
@@ -205,7 +210,6 @@ var HumanInputQuestion = forwardRef2(
|
|
|
205
210
|
{
|
|
206
211
|
...props,
|
|
207
212
|
children: renderedChildren,
|
|
208
|
-
"data-anvia-question": "",
|
|
209
213
|
"data-state": question.status
|
|
210
214
|
},
|
|
211
215
|
ref
|
|
@@ -215,7 +219,7 @@ var HumanInputQuestion = forwardRef2(
|
|
|
215
219
|
var HumanInputQuestionPrompt = forwardRef2(
|
|
216
220
|
function HumanInputQuestionPrompt2({ promptId, ...props }, ref) {
|
|
217
221
|
const { question } = useQuestion();
|
|
218
|
-
const prompt = question.questions.find((item) => item.id === promptId) ?? question.questions[0];
|
|
222
|
+
const prompt = question.request.questions.find((item) => item.id === promptId) ?? question.request.questions[0];
|
|
219
223
|
if (prompt === void 0) {
|
|
220
224
|
return null;
|
|
221
225
|
}
|
|
@@ -223,8 +227,7 @@ var HumanInputQuestionPrompt = forwardRef2(
|
|
|
223
227
|
"div",
|
|
224
228
|
{
|
|
225
229
|
...props,
|
|
226
|
-
children: props.children ?? defaultQuestionPrompt(prompt)
|
|
227
|
-
"data-anvia-question-prompt": ""
|
|
230
|
+
children: props.children ?? defaultQuestionPrompt(prompt)
|
|
228
231
|
},
|
|
229
232
|
ref
|
|
230
233
|
) });
|
|
@@ -234,9 +237,9 @@ var HumanInputQuestionChoice = forwardRef2(
|
|
|
234
237
|
function HumanInputQuestionChoice2({ answer, custom = false, onClick, value, ...props }, ref) {
|
|
235
238
|
const { prompt } = useQuestionPrompt();
|
|
236
239
|
const question = useQuestion();
|
|
237
|
-
const choiceValue = value ?? prompt.choices[0]?.value ?? "";
|
|
238
|
-
const choice = prompt.choices
|
|
239
|
-
const selected = question.answers[prompt.id]?.
|
|
240
|
+
const choiceValue = value ?? prompt.choices?.[0]?.value ?? "";
|
|
241
|
+
const choice = prompt.choices?.find((item) => item.value === choiceValue);
|
|
242
|
+
const selected = question.answers[prompt.id]?.value === choiceValue;
|
|
240
243
|
const handleClick = useCallback2(
|
|
241
244
|
(event) => {
|
|
242
245
|
onClick?.(event);
|
|
@@ -245,10 +248,8 @@ var HumanInputQuestionChoice = forwardRef2(
|
|
|
245
248
|
}
|
|
246
249
|
const nextAnswer = {
|
|
247
250
|
questionId: prompt.id,
|
|
248
|
-
|
|
249
|
-
choice: choiceValue
|
|
251
|
+
value: custom ? answer ?? choice?.label ?? choiceValue : choiceValue
|
|
250
252
|
};
|
|
251
|
-
if (custom) nextAnswer.custom = true;
|
|
252
253
|
question.setAnswer(prompt, nextAnswer);
|
|
253
254
|
},
|
|
254
255
|
[answer, choice?.label, choiceValue, custom, onClick, prompt, question]
|
|
@@ -260,7 +261,6 @@ var HumanInputQuestionChoice = forwardRef2(
|
|
|
260
261
|
children: props.children ?? choice?.label ?? choiceValue,
|
|
261
262
|
onClick: handleClick,
|
|
262
263
|
type: props.type ?? "button",
|
|
263
|
-
"data-anvia-question-choice": "",
|
|
264
264
|
"data-state": selected ? "selected" : "idle"
|
|
265
265
|
},
|
|
266
266
|
ref
|
|
@@ -271,7 +271,7 @@ var HumanInputQuestionTextAnswer = forwardRef2(
|
|
|
271
271
|
function HumanInputQuestionTextAnswer2({ onChange, ...props }, ref) {
|
|
272
272
|
const { prompt } = useQuestionPrompt();
|
|
273
273
|
const question = useQuestion();
|
|
274
|
-
const value = question.answers[prompt.id]?.
|
|
274
|
+
const value = question.answers[prompt.id]?.value ?? "";
|
|
275
275
|
const handleChange = useCallback2(
|
|
276
276
|
(event) => {
|
|
277
277
|
onChange?.(event);
|
|
@@ -281,8 +281,7 @@ var HumanInputQuestionTextAnswer = forwardRef2(
|
|
|
281
281
|
const answer = event.currentTarget.value;
|
|
282
282
|
question.setAnswer(prompt, {
|
|
283
283
|
questionId: prompt.id,
|
|
284
|
-
answer
|
|
285
|
-
custom: true
|
|
284
|
+
value: answer
|
|
286
285
|
});
|
|
287
286
|
},
|
|
288
287
|
[onChange, prompt, question]
|
|
@@ -291,10 +290,9 @@ var HumanInputQuestionTextAnswer = forwardRef2(
|
|
|
291
290
|
"textarea",
|
|
292
291
|
{
|
|
293
292
|
...props,
|
|
294
|
-
"aria-label": props["aria-label"] ?? prompt.
|
|
293
|
+
"aria-label": props["aria-label"] ?? prompt.text,
|
|
295
294
|
onChange: handleChange,
|
|
296
|
-
value
|
|
297
|
-
"data-anvia-question-text-answer": ""
|
|
295
|
+
value
|
|
298
296
|
},
|
|
299
297
|
ref
|
|
300
298
|
);
|
|
@@ -305,22 +303,25 @@ var HumanInputQuestionSubmit = forwardRef2(
|
|
|
305
303
|
const chat = useChatContext();
|
|
306
304
|
const question = useQuestion();
|
|
307
305
|
const answers = useMemo(
|
|
308
|
-
() => question.question.questions.flatMap((prompt) => {
|
|
306
|
+
() => question.question.request.questions.flatMap((prompt) => {
|
|
309
307
|
const answer = question.answers[prompt.id];
|
|
310
|
-
return answer === void 0 || answer.
|
|
308
|
+
return answer === void 0 || answer.value.trim().length === 0 ? [] : [answer];
|
|
311
309
|
}),
|
|
312
310
|
[question]
|
|
313
311
|
);
|
|
314
|
-
const disabled = props.disabled ?? (question.question.status !== "pending" || chat.
|
|
312
|
+
const disabled = props.disabled ?? (question.question.status !== "pending" || chat.respondingInteractions.has(question.question.request.id) || answers.length !== question.question.request.questions.length);
|
|
315
313
|
const handleClick = useCallback2(
|
|
316
314
|
(event) => {
|
|
317
315
|
onClick?.(event);
|
|
318
316
|
if (event.defaultPrevented || disabled) {
|
|
319
317
|
return;
|
|
320
318
|
}
|
|
321
|
-
void chat.
|
|
319
|
+
void chat.respondToInteraction({
|
|
320
|
+
interactionId: question.question.request.id,
|
|
321
|
+
response: { type: "tool-question", answers }
|
|
322
|
+
});
|
|
322
323
|
},
|
|
323
|
-
[answers, chat, disabled, onClick, question.question.id]
|
|
324
|
+
[answers, chat, disabled, onClick, question.question.request.id]
|
|
324
325
|
);
|
|
325
326
|
return renderPrimitive(
|
|
326
327
|
"button",
|
|
@@ -330,7 +331,6 @@ var HumanInputQuestionSubmit = forwardRef2(
|
|
|
330
331
|
disabled,
|
|
331
332
|
onClick: handleClick,
|
|
332
333
|
type: props.type ?? "button",
|
|
333
|
-
"data-anvia-question-submit": "",
|
|
334
334
|
"data-state": disabled ? "disabled" : "enabled"
|
|
335
335
|
},
|
|
336
336
|
ref
|
|
@@ -353,16 +353,15 @@ function QuestionProvider({
|
|
|
353
353
|
}
|
|
354
354
|
function defaultQuestionContent(question) {
|
|
355
355
|
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
356
|
-
/* @__PURE__ */ jsx2("div", {
|
|
357
|
-
question.
|
|
358
|
-
question.questions.map((prompt) => /* @__PURE__ */ jsx2(HumanInputQuestionPrompt, { promptId: prompt.id }, prompt.id)),
|
|
356
|
+
/* @__PURE__ */ jsx2("div", { children: question.request.toolName }),
|
|
357
|
+
question.request.questions.map((prompt) => /* @__PURE__ */ jsx2(HumanInputQuestionPrompt, { promptId: prompt.id }, prompt.id)),
|
|
359
358
|
/* @__PURE__ */ jsx2(HumanInputQuestionSubmit, {})
|
|
360
359
|
] });
|
|
361
360
|
}
|
|
362
361
|
function defaultQuestionPrompt(prompt) {
|
|
363
362
|
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
364
|
-
/* @__PURE__ */ jsx2("div", {
|
|
365
|
-
prompt.choices
|
|
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, {})
|
|
366
365
|
] });
|
|
367
366
|
}
|
|
368
367
|
|
|
@@ -382,15 +381,14 @@ var HumanInputPanel = forwardRef3(function HumanInputPanel2({ children, filter =
|
|
|
382
381
|
children: children ?? /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
383
382
|
/* @__PURE__ */ jsx3(HumanInputApprovals, { filter }),
|
|
384
383
|
/* @__PURE__ */ jsx3(HumanInputQuestions, { filter })
|
|
385
|
-
] })
|
|
386
|
-
"data-anvia-human-input-panel": ""
|
|
384
|
+
] })
|
|
387
385
|
},
|
|
388
386
|
ref
|
|
389
387
|
);
|
|
390
388
|
});
|
|
391
389
|
|
|
392
390
|
// src/human-input/index.ts
|
|
393
|
-
var
|
|
391
|
+
var HumanInputPrimitive = {
|
|
394
392
|
Panel: HumanInputPanel,
|
|
395
393
|
Status: HumanInputStatus,
|
|
396
394
|
Approvals: HumanInputApprovals,
|
|
@@ -407,6 +405,6 @@ var HumanInput = {
|
|
|
407
405
|
};
|
|
408
406
|
|
|
409
407
|
export {
|
|
410
|
-
|
|
408
|
+
HumanInputPrimitive
|
|
411
409
|
};
|
|
412
|
-
//# 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,KA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A,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 {
|
|
@@ -16,13 +16,14 @@ import {
|
|
|
16
16
|
import { jsx } from "react/jsx-runtime";
|
|
17
17
|
var CompletionForm = forwardRef(function CompletionForm2({ onSubmit, ...props }, ref) {
|
|
18
18
|
const completion = useCompletionContext();
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const active = completion.status === "submitted" || completion.status === "streaming";
|
|
20
|
+
const canSubmit = completion.input.trim().length > 0 && !active;
|
|
21
|
+
const canStop = active;
|
|
21
22
|
const submit = useCallback(async () => {
|
|
22
23
|
if (!canSubmit) {
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
|
-
await completion.
|
|
26
|
+
await completion.submit();
|
|
26
27
|
}, [canSubmit, completion]);
|
|
27
28
|
const value = useMemo(
|
|
28
29
|
() => ({
|
|
@@ -60,7 +61,6 @@ var CompletionForm = forwardRef(function CompletionForm2({ onSubmit, ...props },
|
|
|
60
61
|
{
|
|
61
62
|
...props,
|
|
62
63
|
onSubmit: handleSubmit,
|
|
63
|
-
"data-anvia-completion-form": "",
|
|
64
64
|
"data-state": completion.status
|
|
65
65
|
},
|
|
66
66
|
ref
|
|
@@ -94,11 +94,10 @@ var CompletionInput = forwardRef(
|
|
|
94
94
|
{
|
|
95
95
|
...props,
|
|
96
96
|
"aria-label": props["aria-label"] ?? "Prompt",
|
|
97
|
-
disabled: props.disabled ?? input.status === "streaming",
|
|
97
|
+
disabled: props.disabled ?? (input.status === "submitted" || input.status === "streaming"),
|
|
98
98
|
onChange: handleChange,
|
|
99
99
|
onKeyDown: handleKeyDown,
|
|
100
|
-
value: input.input
|
|
101
|
-
"data-anvia-completion-input": ""
|
|
100
|
+
value: input.input
|
|
102
101
|
},
|
|
103
102
|
ref
|
|
104
103
|
);
|
|
@@ -115,7 +114,6 @@ var CompletionSubmit = forwardRef(
|
|
|
115
114
|
children: props.children ?? "Complete",
|
|
116
115
|
disabled,
|
|
117
116
|
type: props.type ?? "submit",
|
|
118
|
-
"data-anvia-completion-submit": "",
|
|
119
117
|
"data-state": disabled ? "disabled" : "enabled"
|
|
120
118
|
},
|
|
121
119
|
ref
|
|
@@ -144,7 +142,6 @@ var CompletionStop = forwardRef(
|
|
|
144
142
|
disabled,
|
|
145
143
|
onClick: handleClick,
|
|
146
144
|
type: props.type ?? "button",
|
|
147
|
-
"data-anvia-completion-stop": "",
|
|
148
145
|
"data-state": disabled ? "disabled" : "enabled"
|
|
149
146
|
},
|
|
150
147
|
ref
|
|
@@ -161,7 +158,6 @@ var CompletionRoot = forwardRef2(
|
|
|
161
158
|
"div",
|
|
162
159
|
{
|
|
163
160
|
...props,
|
|
164
|
-
"data-anvia-completion": "",
|
|
165
161
|
"data-state": completion.status
|
|
166
162
|
},
|
|
167
163
|
ref
|
|
@@ -176,8 +172,7 @@ var CompletionOutput = forwardRef2(
|
|
|
176
172
|
"div",
|
|
177
173
|
{
|
|
178
174
|
...props,
|
|
179
|
-
children: renderedChildren ?? completion.completion
|
|
180
|
-
"data-anvia-completion-output": ""
|
|
175
|
+
children: renderedChildren ?? completion.completion
|
|
181
176
|
},
|
|
182
177
|
ref
|
|
183
178
|
);
|
|
@@ -185,7 +180,7 @@ var CompletionOutput = forwardRef2(
|
|
|
185
180
|
);
|
|
186
181
|
|
|
187
182
|
// src/completion/index.ts
|
|
188
|
-
var
|
|
183
|
+
var CompletionPrimitive = {
|
|
189
184
|
Root: CompletionRoot,
|
|
190
185
|
Output: CompletionOutput,
|
|
191
186
|
Form: CompletionForm,
|
|
@@ -195,6 +190,6 @@ var Completion = {
|
|
|
195
190
|
};
|
|
196
191
|
|
|
197
192
|
export {
|
|
198
|
-
|
|
193
|
+
CompletionPrimitive
|
|
199
194
|
};
|
|
200
|
-
//# 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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MAAM,GAAG,KAAK;AAClD,UAAM,QAAQ,mBAAmB;AACjC,UAAM,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"]}
|