@anvia/react-ui 1.0.0-rc.1 → 1.0.0-rc.3
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 +4 -1
- package/dist/attachment/index.d.ts +3 -3
- package/dist/attachment/index.js +2 -2
- package/dist/{attachment-BP597fV3.d.ts → attachment-mbjsroli.d.ts} +1 -1
- package/dist/chat/index.d.ts +9 -8
- package/dist/chat/index.js +5 -4
- package/dist/chat-BRVgYE68.d.ts +86 -0
- package/dist/{chunk-SBYUKODG.js → chunk-B5JX33SC.js} +2 -2
- package/dist/chunk-B5JX33SC.js.map +1 -0
- package/dist/{chunk-JWZDNM5D.js → chunk-BZZ7MJNM.js} +29 -38
- package/dist/chunk-BZZ7MJNM.js.map +1 -0
- package/dist/chunk-CKA4CE26.js +25 -0
- package/dist/chunk-CKA4CE26.js.map +1 -0
- package/dist/{chunk-43U2XQP2.js → chunk-JMGFSYCR.js} +25 -11
- package/dist/chunk-JMGFSYCR.js.map +1 -0
- package/dist/{chunk-7RMRM7W3.js → chunk-JNPCYX4Z.js} +2 -2
- package/dist/{chunk-56CV6S76.js → chunk-MF7RWETT.js} +2 -2
- package/dist/{chunk-R3NA6BWW.js → chunk-QHOLI3OZ.js} +45 -33
- package/dist/chunk-QHOLI3OZ.js.map +1 -0
- package/dist/{chunk-VEYJNQVW.js → chunk-URQROKGZ.js} +7 -6
- package/dist/chunk-URQROKGZ.js.map +1 -0
- package/dist/{chunk-FABSIZZ7.js → chunk-XZUF27QY.js} +18 -17
- package/dist/chunk-XZUF27QY.js.map +1 -0
- package/dist/{chunk-7HR34SOF.js → chunk-YJNTXNVL.js} +2 -2
- package/dist/chunk-YJNTXNVL.js.map +1 -0
- package/dist/completion/index.d.ts +2 -1
- package/dist/completion/index.js +2 -2
- package/dist/completion-input-DHlwrhxB.d.ts +24 -0
- package/dist/{composer-CzsbDFPt.d.ts → composer-BTT2vzYF.d.ts} +2 -2
- package/dist/human-input/index.d.ts +8 -6
- package/dist/human-input/index.js +3 -2
- package/dist/human-input-DOBCZgqw.d.ts +27 -0
- package/dist/image/index.d.ts +4 -4
- package/dist/image/index.js +2 -2
- package/dist/{image-DanUxcl2.d.ts → image-VZv6Ddsn.d.ts} +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +18 -17
- package/dist/index.js.map +1 -1
- package/dist/message/index.d.ts +10 -9
- package/dist/message/index.js +4 -3
- package/dist/{message-CkEnKhAn.d.ts → message-CNRnZQwU.d.ts} +1 -1
- package/dist/selection-toolbar/index.js +2 -2
- package/dist/shared.d.ts +8 -7
- package/dist/shared.js +1 -1
- package/dist/thread-list/index.js +2 -2
- package/package.json +15 -13
- package/dist/chat-B3kucz1w.d.ts +0 -13
- package/dist/chunk-43U2XQP2.js.map +0 -1
- package/dist/chunk-7HR34SOF.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-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/{chunk-7RMRM7W3.js.map → chunk-JNPCYX4Z.js.map} +0 -0
- /package/dist/{chunk-56CV6S76.js.map → chunk-MF7RWETT.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/contexts/attachment.tsx","../src/contexts/chat.tsx","../src/contexts/completion.tsx","../src/contexts/completion-input.tsx","../src/contexts/composer.tsx","../src/contexts/human-input.tsx","../src/contexts/image.tsx","../src/contexts/message.tsx","../src/contexts/selection-toolbar.tsx","../src/contexts/thread.tsx","../src/contexts/thread-list.tsx"],"sourcesContent":["import type { UIAttachment } from \"@anvia/client\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type AttachmentContextValue = {\n attachment: UIAttachment;\n remove?(): void;\n};\n\nconst AttachmentContext = createContext<AttachmentContextValue | undefined>(undefined);\n\nexport function InternalAttachmentProvider({\n value,\n children,\n}: {\n value: AttachmentContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(AttachmentContext.Provider, { value }, children);\n}\n\nexport function useAttachment(): AttachmentContextValue {\n const value = useContext(AttachmentContext);\n if (value === undefined) {\n throw new Error(\"Attachment primitives must be used inside Attachment.Root.\");\n }\n return value;\n}\n\nexport function useOptionalAttachment(): AttachmentContextValue | undefined {\n return useContext(AttachmentContext);\n}\n","import type {\n ClientDataMap,\n ClientMetadata,\n ClientStreamRequest,\n ClientTransport,\n} from \"@anvia/client\";\nimport type { AgentToolApprovalRequest, AgentToolQuestionRequest } from \"@anvia/core/agent\";\nimport type { UseChatResult } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type ChatController<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n> = UseChatResult<ClientTransport<ClientStreamRequest, Data, Metadata>>;\n\nexport type ChatProviderProps<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n> = {\n controller: ChatController<Metadata, Data>;\n children?: ReactNode;\n};\n\nconst ChatContext = createContext<ChatController | undefined>(undefined);\n\nexport function ChatProvider<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n>({ controller, children }: ChatProviderProps<Metadata, Data>): ReactElement {\n return createElement(\n ChatContext.Provider,\n { value: controller as unknown as ChatController },\n children,\n );\n}\n\nexport function useChatContext<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n>(): ChatController<Metadata, Data> {\n const value = useContext(ChatContext);\n if (value === undefined) {\n throw new Error(\"Anvia chat primitives must be used inside ChatProvider.\");\n }\n return value as unknown as ChatController<Metadata, Data>;\n}\n\nexport function useHumanInput() {\n const interactions = useChatContext().interactions;\n const approvals = interactions.all.filter(\n (item): item is typeof item & { request: AgentToolApprovalRequest } =>\n item.request.type === \"tool-approval\",\n );\n const questions = interactions.all.filter(\n (item): item is typeof item & { request: AgentToolQuestionRequest } =>\n item.request.type === \"tool-question\",\n );\n return {\n approvals: {\n all: approvals,\n pending: approvals.filter((item) => item.status === \"pending\"),\n },\n questions: {\n all: questions,\n pending: questions.filter((item) => item.status === \"pending\"),\n },\n };\n}\n","import type { ClientDataMap, ClientMetadata } from \"@anvia/client\";\nimport type { UseCompletionResult } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type CompletionController<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n> = UseCompletionResult<Metadata, Data>;\n\nexport type CompletionProviderProps<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n> = {\n controller: CompletionController<Metadata, Data>;\n children?: ReactNode;\n};\n\nconst CompletionContext = createContext<CompletionController | undefined>(undefined);\n\nexport function CompletionProvider<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n>({ controller, children }: CompletionProviderProps<Metadata, Data>): ReactElement {\n return createElement(\n CompletionContext.Provider,\n { value: controller as unknown as CompletionController },\n children,\n );\n}\n\nexport function useCompletionContext<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n>(): CompletionController<Metadata, Data> {\n const value = useContext(CompletionContext);\n if (value === undefined) {\n throw new Error(\"Anvia completion primitives must be used inside CompletionProvider.\");\n }\n return value as unknown as CompletionController<Metadata, Data>;\n}\n","import { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nimport type { CompletionController } from \"./completion\";\n\nexport type CompletionInputContextValue = {\n input: string;\n setInput(input: string): void;\n submit(): Promise<void>;\n stop(): void;\n status: CompletionController[\"status\"];\n canSubmit: boolean;\n canStop: boolean;\n};\n\nconst CompletionInputContext = createContext<CompletionInputContextValue | undefined>(undefined);\n\nexport function InternalCompletionInputProvider({\n value,\n children,\n}: {\n value: CompletionInputContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(CompletionInputContext.Provider, { value }, children);\n}\n\nexport function useCompletionInput(): CompletionInputContextValue {\n const value = useContext(CompletionInputContext);\n if (value === undefined) {\n throw new Error(\"Completion input primitives must be used inside Completion.Form.\");\n }\n return value;\n}\n","import type { CreateUIAttachment, UIAttachment } from \"@anvia/client\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\nimport type { ChatController } from \"./chat\";\n\nexport type ComposerEntityData =\n | string\n | number\n | boolean\n | null\n | ComposerEntityData[]\n | { [key: string]: ComposerEntityData | undefined };\n\nexport type ComposerAttachmentInput = File | CreateUIAttachment;\nexport type ComposerAttachmentsUpdate =\n | UIAttachment[]\n | ((attachments: UIAttachment[]) => UIAttachment[]);\nexport type ComposerEntitiesUpdate =\n | ComposerEntity[]\n | ((entities: ComposerEntity[]) => ComposerEntity[]);\nexport type ComposerQuote = {\n text: string;\n messageId: string;\n};\nexport type ComposerTriggerItem = {\n id: string;\n label: string;\n text?: string | undefined;\n detail?: ReactNode | undefined;\n data?: ComposerEntityData | undefined;\n disabled?: boolean | undefined;\n};\nexport type ComposerTriggerItemsArgs = {\n trigger: ComposerTriggerDefinition;\n query: string;\n input: string;\n entities: ComposerEntity[];\n signal: AbortSignal;\n};\nexport type ComposerTriggerItems =\n | ComposerTriggerItem[]\n | ((args: ComposerTriggerItemsArgs) => ComposerTriggerItem[] | Promise<ComposerTriggerItem[]>);\nexport type ComposerTriggerDefinition = {\n id: string;\n char: string;\n items: ComposerTriggerItems;\n minQueryLength?: number | undefined;\n allowedPrefixes?: string[] | null | undefined;\n startOfLine?: boolean | undefined;\n allowSpaces?: boolean | undefined;\n};\nexport type ComposerEntity = {\n id: string;\n triggerId: string;\n trigger: string;\n label: string;\n text: string;\n range: {\n from: number;\n to: number;\n };\n data?: ComposerEntityData | undefined;\n};\nexport type ComposerMessageMetadata = {\n composer: {\n entities: ComposerEntity[];\n };\n};\nexport type ComposerTriggerState = {\n trigger: ComposerTriggerDefinition;\n query: string;\n items: ComposerTriggerItem[];\n loading: boolean;\n selectedIndex: number;\n rect?: {\n top: number;\n right: number;\n bottom: number;\n left: number;\n width: number;\n height: number;\n };\n selectItem(item: ComposerTriggerItem): void;\n setSelectedIndex(index: number): void;\n};\nexport type ComposerTriggerStateUpdate =\n | ComposerTriggerState\n | undefined\n | ((state: ComposerTriggerState | undefined) => ComposerTriggerState | undefined);\n\nexport type ComposerContextValue = {\n input: string;\n setInput(input: string): void;\n attachments: UIAttachment[];\n setAttachments(update: ComposerAttachmentsUpdate): void;\n addAttachment(attachment: ComposerAttachmentInput): Promise<void>;\n removeAttachment(id: string): void;\n clearAttachments(): void;\n entities: ComposerEntity[];\n setEntities(update: ComposerEntitiesUpdate): void;\n quote?: ComposerQuote | undefined;\n setQuote(quote: ComposerQuote | undefined): void;\n clearQuote(): void;\n triggers: ComposerTriggerDefinition[];\n activeTrigger?: ComposerTriggerState | undefined;\n setActiveTrigger(update: ComposerTriggerStateUpdate): void;\n submit(): Promise<void>;\n stop(): void;\n status: ChatController[\"status\"];\n canSubmit: boolean;\n canStop: boolean;\n};\n\nconst ComposerContext = createContext<ComposerContextValue | undefined>(undefined);\n\nexport function InternalComposerProvider({\n value,\n children,\n}: {\n value: ComposerContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ComposerContext.Provider, { value }, children);\n}\n\nexport function useComposer(): ComposerContextValue {\n const value = useContext(ComposerContext);\n if (value === undefined) {\n throw new Error(\"Composer primitives must be used inside Composer.Root.\");\n }\n return value;\n}\n","import type { ClientInteraction } from \"@anvia/client\";\nimport type {\n AgentQuestionAnswer,\n AgentQuestionPrompt,\n AgentToolApprovalRequest,\n AgentToolQuestionRequest,\n} from \"@anvia/core/agent\";\nimport {\n createContext,\n createElement,\n type ReactElement,\n type ReactNode,\n useContext,\n useMemo,\n useState,\n} from \"react\";\n\nexport type ApprovalContextValue = {\n approval: ApprovalInteraction;\n reason: string;\n setReason(reason: string): void;\n};\n\nexport type QuestionContextValue = {\n question: QuestionInteraction;\n answers: Record<string, AgentQuestionAnswer>;\n setAnswer(prompt: AgentQuestionPrompt, answer: AgentQuestionAnswer): void;\n};\n\nexport type QuestionPromptContextValue = {\n prompt: AgentQuestionPrompt;\n};\n\nexport type ApprovalInteraction = ClientInteraction & { request: AgentToolApprovalRequest };\nexport type QuestionInteraction = ClientInteraction & { request: AgentToolQuestionRequest };\n\nconst ApprovalContext = createContext<ApprovalContextValue | undefined>(undefined);\nconst QuestionContext = createContext<QuestionContextValue | undefined>(undefined);\nconst QuestionPromptContext = createContext<QuestionPromptContextValue | undefined>(undefined);\n\nexport function InternalApprovalProvider({\n approval,\n children,\n}: {\n approval: ApprovalInteraction;\n children?: ReactNode;\n}): ReactElement {\n const [reason, setReason] = useState(\"\");\n const value = useMemo<ApprovalContextValue>(\n () => ({ approval, reason, setReason }),\n [approval, reason],\n );\n\n return createElement(ApprovalContext.Provider, { value }, children);\n}\n\nexport function InternalQuestionProvider({\n value,\n children,\n}: {\n value: QuestionContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(QuestionContext.Provider, { value }, children);\n}\n\nexport function InternalQuestionPromptProvider({\n prompt,\n children,\n}: {\n prompt: AgentQuestionPrompt;\n children?: ReactNode;\n}): ReactElement {\n return createElement(QuestionPromptContext.Provider, { value: { prompt } }, children);\n}\n\nexport function useApproval(): ApprovalContextValue {\n const value = useContext(ApprovalContext);\n if (value === undefined) {\n throw new Error(\"Approval primitives must be used inside HumanInput.Approval.\");\n }\n return value;\n}\n\nexport function useQuestion(): QuestionContextValue {\n const value = useContext(QuestionContext);\n if (value === undefined) {\n throw new Error(\"Question primitives must be used inside HumanInput.Question.\");\n }\n return value;\n}\n\nexport function useQuestionPrompt(): QuestionPromptContextValue {\n const value = useContext(QuestionPromptContext);\n if (value === undefined) {\n throw new Error(\"Question choice primitives must be used inside HumanInput.QuestionPrompt.\");\n }\n return value;\n}\n","import type { UIAttachment } from \"@anvia/client\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type ImageContextValue = {\n attachment: UIAttachment;\n src?: string;\n name?: string;\n mediaType?: string;\n isImage: boolean;\n zoomOpen: boolean;\n setZoomOpen(open: boolean): void;\n};\n\nconst ImageContext = createContext<ImageContextValue | undefined>(undefined);\n\nexport function InternalImageProvider({\n value,\n children,\n}: {\n value: ImageContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ImageContext.Provider, { value }, children);\n}\n\nexport function useImage(): ImageContextValue {\n const value = useContext(ImageContext);\n if (value === undefined) {\n throw new Error(\"Image primitives must be used inside Image.Root.\");\n }\n return value;\n}\n","import type { UIMessage, UIMessagePart } from \"@anvia/client\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type MessageContextValue = {\n message: UIMessage;\n};\n\nexport type MessagePartContextValue = {\n isLive: boolean;\n part: UIMessagePart;\n streamControlled: boolean;\n};\n\nconst MessageContext = createContext<MessageContextValue | undefined>(undefined);\nconst MessagePartContext = createContext<MessagePartContextValue | undefined>(undefined);\n\nexport function InternalMessageProvider({\n message,\n children,\n}: {\n message: UIMessage;\n children?: ReactNode;\n}): ReactElement {\n return createElement(MessageContext.Provider, { value: { message } }, children);\n}\n\nexport function InternalMessagePartProvider({\n part,\n isLive = false,\n streamControlled = false,\n children,\n}: {\n part: UIMessagePart;\n isLive?: boolean;\n streamControlled?: boolean;\n children?: ReactNode;\n}): ReactElement {\n return createElement(\n MessagePartContext.Provider,\n { value: { isLive, part, streamControlled } },\n children,\n );\n}\n\nexport function useMessage(): MessageContextValue {\n const value = useContext(MessageContext);\n if (value === undefined) {\n throw new Error(\"Message primitives must be used inside Message.Root or Thread.Messages.\");\n }\n return value;\n}\n\nexport function useMessagePart(): MessagePartContextValue {\n const value = useContext(MessagePartContext);\n if (value === undefined) {\n throw new Error(\"Message part primitives must be used inside Message.Parts or Message.Part.\");\n }\n return value;\n}\n\nexport function useOptionalMessagePart(): MessagePartContextValue | undefined {\n return useContext(MessagePartContext);\n}\n","import { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type SelectionToolbarSelection = {\n text: string;\n messageId: string;\n rect: DOMRect;\n};\n\nexport type SelectionToolbarContextValue = {\n selection?: SelectionToolbarSelection;\n quote(): void;\n copy(): Promise<void>;\n clear(): void;\n};\n\nconst SelectionToolbarContext = createContext<SelectionToolbarContextValue | undefined>(undefined);\n\nexport function InternalSelectionToolbarProvider({\n value,\n children,\n}: {\n value: SelectionToolbarContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(SelectionToolbarContext.Provider, { value }, children);\n}\n\nexport function useSelectionToolbar(): SelectionToolbarContextValue {\n const value = useContext(SelectionToolbarContext);\n if (value === undefined) {\n throw new Error(\"SelectionToolbar primitives must be used inside SelectionToolbar.Root.\");\n }\n return value;\n}\n","import {\n createContext,\n createElement,\n type MutableRefObject,\n type ReactElement,\n type ReactNode,\n useContext,\n} from \"react\";\n\nexport type ThreadContextValue = {\n viewportRef: MutableRefObject<HTMLElement | null>;\n atBottom: boolean;\n setAtBottom(atBottom: boolean): void;\n scrollToBottom(behavior?: ScrollBehavior): void;\n};\n\nconst ThreadContext = createContext<ThreadContextValue | undefined>(undefined);\n\nexport function InternalThreadProvider({\n value,\n children,\n}: {\n value: ThreadContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ThreadContext.Provider, { value }, children);\n}\n\nexport function useThread(): ThreadContextValue {\n const value = useContext(ThreadContext);\n if (value === undefined) {\n throw new Error(\"Thread primitives must be used inside Thread.Root.\");\n }\n return value;\n}\n","import { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type ThreadListRecord = {\n id: string;\n title?: string;\n createdAt?: string | Date;\n updatedAt?: string | Date;\n archived?: boolean;\n metadata?: unknown;\n};\n\nexport type ThreadListController = {\n threads: ThreadListRecord[];\n activeThreadId?: string;\n status?: \"idle\" | \"loading\" | \"error\";\n error?: unknown;\n createThread(): Promise<void> | void;\n switchThread(threadId: string): Promise<void> | void;\n archiveThread?(threadId: string): Promise<void> | void;\n unarchiveThread?(threadId: string): Promise<void> | void;\n deleteThread?(threadId: string): Promise<void> | void;\n};\n\nexport type ThreadListItemContextValue = {\n thread: ThreadListRecord;\n active: boolean;\n};\n\nexport type ThreadListProviderProps = {\n controller: ThreadListController;\n children?: ReactNode;\n};\n\nconst ThreadListContext = createContext<ThreadListController | undefined>(undefined);\nconst ThreadListItemContext = createContext<ThreadListItemContextValue | undefined>(undefined);\n\nexport function ThreadListProvider({\n controller,\n children,\n}: ThreadListProviderProps): ReactElement {\n return createElement(ThreadListContext.Provider, { value: controller }, children);\n}\n\nexport function InternalThreadListItemProvider({\n value,\n children,\n}: {\n value: ThreadListItemContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ThreadListItemContext.Provider, { value }, children);\n}\n\nexport function useThreadList(): ThreadListController {\n const value = useContext(ThreadListContext);\n if (value === undefined) {\n throw new Error(\"ThreadList primitives must be used inside ThreadListProvider.\");\n }\n return value;\n}\n\nexport function useThreadListItem(): ThreadListItemContextValue {\n const value = useContext(ThreadListItemContext);\n if (value === undefined) {\n throw new Error(\"ThreadListItem primitives must be used inside ThreadList.Items.\");\n }\n return value;\n}\n"],"mappings":";AACA,SAAS,eAAe,eAAkD,kBAAkB;AAO5F,IAAM,oBAAoB,cAAkD,MAAS;AAE9E,SAAS,2BAA2B;AAAA,EACzC;AAAA,EACA;AACF,GAGiB;AACf,SAAO,cAAc,kBAAkB,UAAU,EAAE,MAAM,GAAG,QAAQ;AACtE;AAEO,SAAS,gBAAwC;AACtD,QAAM,QAAQ,WAAW,iBAAiB;AAC1C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,4DAA4D;AAAA,EAC9E;AACA,SAAO;AACT;AAEO,SAAS,wBAA4D;AAC1E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AAU,QAAW;AACvB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;;;AClCA,SAAS,iBAAAC,iBAAe,iBAAAC,iBAAkD,cAAAC,oBAAkB;AAiC5F,IAAM,oBAAoBF,gBAAgD,MAAS;AACnF,IAAM,wBAAwBA,gBAAsD,MAAS;AAEtF,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AACF,GAA0C;AACxC,SAAOC,gBAAc,kBAAkB,UAAU,EAAE,OAAO,WAAW,GAAG,QAAQ;AAClF;AAEO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAGiB;AACf,SAAOA,gBAAc,sBAAsB,UAAU,EAAE,MAAM,GAAG,QAAQ;AAC1E;AAEO,SAAS,gBAAsC;AACpD,QAAM,QAAQC,aAAW,iBAAiB;AAC1C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,+DAA+D;AAAA,EACjF;AACA,SAAO;AACT;AAEO,SAAS,oBAAgD;AAC9D,QAAM,QAAQA,aAAW,qBAAqB;AAC9C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,iEAAiE;AAAA,EACnF;AACA,SAAO;AACT;","names":["createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext"]}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
InternalThreadListItemProvider,
|
|
6
6
|
useThreadList,
|
|
7
7
|
useThreadListItem
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-JMGFSYCR.js";
|
|
9
9
|
|
|
10
10
|
// src/thread-list/parts.tsx
|
|
11
11
|
import {
|
|
@@ -288,4 +288,4 @@ export {
|
|
|
288
288
|
ThreadList,
|
|
289
289
|
ThreadListItem
|
|
290
290
|
};
|
|
291
|
-
//# sourceMappingURL=chunk-
|
|
291
|
+
//# sourceMappingURL=chunk-JNPCYX4Z.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
InternalSelectionToolbarProvider,
|
|
6
6
|
useSelectionToolbar
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-JMGFSYCR.js";
|
|
8
8
|
|
|
9
9
|
// src/selection-toolbar/parts.tsx
|
|
10
10
|
import {
|
|
@@ -229,4 +229,4 @@ var SelectionToolbar = {
|
|
|
229
229
|
export {
|
|
230
230
|
SelectionToolbar
|
|
231
231
|
};
|
|
232
|
-
//# sourceMappingURL=chunk-
|
|
232
|
+
//# sourceMappingURL=chunk-MF7RWETT.js.map
|
|
@@ -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-JMGFSYCR.js";
|
|
14
17
|
|
|
15
18
|
// src/human-input/approvals.tsx
|
|
16
19
|
import { forwardRef, useCallback } from "react";
|
|
@@ -44,7 +47,7 @@ var HumanInputApprovals = forwardRef(
|
|
|
44
47
|
"div",
|
|
45
48
|
{
|
|
46
49
|
...props,
|
|
47
|
-
children: approvals.map((approval) => /* @__PURE__ */ jsx(InternalApprovalProvider, { approval, children: typeof children === "function" ? children(approval) : children ?? /* @__PURE__ */ jsx(HumanInputApproval, {}) }, approval.id)),
|
|
50
|
+
children: approvals.map((approval) => /* @__PURE__ */ jsx(InternalApprovalProvider, { approval, children: typeof children === "function" ? children(approval) : children ?? /* @__PURE__ */ jsx(HumanInputApproval, {}) }, approval.request.id)),
|
|
48
51
|
"data-anvia-approvals": "",
|
|
49
52
|
"data-empty": empty ? "" : void 0
|
|
50
53
|
},
|
|
@@ -72,7 +75,7 @@ var HumanInputApprove = forwardRef(
|
|
|
72
75
|
function HumanInputApprove2({ onClick, ...props }, ref) {
|
|
73
76
|
const chat = useChatContext();
|
|
74
77
|
const { approval, reason } = useApproval();
|
|
75
|
-
const disabled = props.disabled ?? (approval.status !== "pending" || chat.
|
|
78
|
+
const disabled = props.disabled ?? (approval.status !== "pending" || chat.respondingInteractions.has(approval.request.id));
|
|
76
79
|
const handleClick = useCallback(
|
|
77
80
|
(event) => {
|
|
78
81
|
onClick?.(event);
|
|
@@ -80,9 +83,14 @@ var HumanInputApprove = forwardRef(
|
|
|
80
83
|
return;
|
|
81
84
|
}
|
|
82
85
|
const decisionReason = reason.trim().length > 0 ? reason : void 0;
|
|
83
|
-
|
|
86
|
+
const response = { type: "tool-approval", approved: true };
|
|
87
|
+
if (decisionReason !== void 0) Object.assign(response, { reason: decisionReason });
|
|
88
|
+
void chat.respondToInteraction({
|
|
89
|
+
interactionId: approval.request.id,
|
|
90
|
+
response
|
|
91
|
+
});
|
|
84
92
|
},
|
|
85
|
-
[approval.id, chat, disabled, onClick, reason]
|
|
93
|
+
[approval.request.id, chat, disabled, onClick, reason]
|
|
86
94
|
);
|
|
87
95
|
return renderPrimitive(
|
|
88
96
|
"button",
|
|
@@ -103,7 +111,7 @@ var HumanInputReject = forwardRef(
|
|
|
103
111
|
function HumanInputReject2({ onClick, ...props }, ref) {
|
|
104
112
|
const chat = useChatContext();
|
|
105
113
|
const { approval, reason } = useApproval();
|
|
106
|
-
const disabled = props.disabled ?? (approval.status !== "pending" || chat.
|
|
114
|
+
const disabled = props.disabled ?? (approval.status !== "pending" || chat.respondingInteractions.has(approval.request.id));
|
|
107
115
|
const handleClick = useCallback(
|
|
108
116
|
(event) => {
|
|
109
117
|
onClick?.(event);
|
|
@@ -111,9 +119,14 @@ var HumanInputReject = forwardRef(
|
|
|
111
119
|
return;
|
|
112
120
|
}
|
|
113
121
|
const decisionReason = reason.trim().length > 0 ? reason : void 0;
|
|
114
|
-
|
|
122
|
+
const response = { type: "tool-approval", approved: false };
|
|
123
|
+
if (decisionReason !== void 0) Object.assign(response, { reason: decisionReason });
|
|
124
|
+
void chat.respondToInteraction({
|
|
125
|
+
interactionId: approval.request.id,
|
|
126
|
+
response
|
|
127
|
+
});
|
|
115
128
|
},
|
|
116
|
-
[approval.id, chat, disabled, onClick, reason]
|
|
129
|
+
[approval.request.id, chat, disabled, onClick, reason]
|
|
117
130
|
);
|
|
118
131
|
return renderPrimitive(
|
|
119
132
|
"button",
|
|
@@ -157,8 +170,8 @@ var HumanInputApprovalReason = forwardRef(
|
|
|
157
170
|
);
|
|
158
171
|
function defaultApprovalContent(approval) {
|
|
159
172
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
160
|
-
/* @__PURE__ */ jsx("div", { "data-anvia-approval-tool": "", children: approval.toolName }),
|
|
161
|
-
approval.
|
|
173
|
+
/* @__PURE__ */ jsx("div", { "data-anvia-approval-tool": "", children: approval.request.toolName }),
|
|
174
|
+
approval.request.input !== void 0 ? /* @__PURE__ */ jsx("pre", { "data-anvia-approval-args": "", children: stringifyValue(approval.request.input) }) : null,
|
|
162
175
|
/* @__PURE__ */ jsx(HumanInputApprovalReason, {}),
|
|
163
176
|
/* @__PURE__ */ jsx(HumanInputApprove, {}),
|
|
164
177
|
/* @__PURE__ */ jsx(HumanInputReject, {})
|
|
@@ -188,7 +201,7 @@ var HumanInputQuestions = forwardRef2(
|
|
|
188
201
|
"div",
|
|
189
202
|
{
|
|
190
203
|
...props,
|
|
191
|
-
children: questions.map((question) => /* @__PURE__ */ jsx2(QuestionProvider, { question, children: typeof children === "function" ? children(question) : children ?? /* @__PURE__ */ jsx2(HumanInputQuestion, {}) }, question.id)),
|
|
204
|
+
children: questions.map((question) => /* @__PURE__ */ jsx2(QuestionProvider, { question, children: typeof children === "function" ? children(question) : children ?? /* @__PURE__ */ jsx2(HumanInputQuestion, {}) }, question.request.id)),
|
|
192
205
|
"data-anvia-questions": "",
|
|
193
206
|
"data-empty": empty ? "" : void 0
|
|
194
207
|
},
|
|
@@ -215,7 +228,7 @@ var HumanInputQuestion = forwardRef2(
|
|
|
215
228
|
var HumanInputQuestionPrompt = forwardRef2(
|
|
216
229
|
function HumanInputQuestionPrompt2({ promptId, ...props }, ref) {
|
|
217
230
|
const { question } = useQuestion();
|
|
218
|
-
const prompt = question.questions.find((item) => item.id === promptId) ?? question.questions[0];
|
|
231
|
+
const prompt = question.request.questions.find((item) => item.id === promptId) ?? question.request.questions[0];
|
|
219
232
|
if (prompt === void 0) {
|
|
220
233
|
return null;
|
|
221
234
|
}
|
|
@@ -234,9 +247,9 @@ var HumanInputQuestionChoice = forwardRef2(
|
|
|
234
247
|
function HumanInputQuestionChoice2({ answer, custom = false, onClick, value, ...props }, ref) {
|
|
235
248
|
const { prompt } = useQuestionPrompt();
|
|
236
249
|
const question = useQuestion();
|
|
237
|
-
const choiceValue = value ?? prompt.choices[0]?.value ?? "";
|
|
238
|
-
const choice = prompt.choices
|
|
239
|
-
const selected = question.answers[prompt.id]?.
|
|
250
|
+
const choiceValue = value ?? prompt.choices?.[0]?.value ?? "";
|
|
251
|
+
const choice = prompt.choices?.find((item) => item.value === choiceValue);
|
|
252
|
+
const selected = question.answers[prompt.id]?.value === choiceValue;
|
|
240
253
|
const handleClick = useCallback2(
|
|
241
254
|
(event) => {
|
|
242
255
|
onClick?.(event);
|
|
@@ -245,10 +258,8 @@ var HumanInputQuestionChoice = forwardRef2(
|
|
|
245
258
|
}
|
|
246
259
|
const nextAnswer = {
|
|
247
260
|
questionId: prompt.id,
|
|
248
|
-
|
|
249
|
-
choice: choiceValue
|
|
261
|
+
value: custom ? answer ?? choice?.label ?? choiceValue : choiceValue
|
|
250
262
|
};
|
|
251
|
-
if (custom) nextAnswer.custom = true;
|
|
252
263
|
question.setAnswer(prompt, nextAnswer);
|
|
253
264
|
},
|
|
254
265
|
[answer, choice?.label, choiceValue, custom, onClick, prompt, question]
|
|
@@ -271,7 +282,7 @@ var HumanInputQuestionTextAnswer = forwardRef2(
|
|
|
271
282
|
function HumanInputQuestionTextAnswer2({ onChange, ...props }, ref) {
|
|
272
283
|
const { prompt } = useQuestionPrompt();
|
|
273
284
|
const question = useQuestion();
|
|
274
|
-
const value = question.answers[prompt.id]?.
|
|
285
|
+
const value = question.answers[prompt.id]?.value ?? "";
|
|
275
286
|
const handleChange = useCallback2(
|
|
276
287
|
(event) => {
|
|
277
288
|
onChange?.(event);
|
|
@@ -281,8 +292,7 @@ var HumanInputQuestionTextAnswer = forwardRef2(
|
|
|
281
292
|
const answer = event.currentTarget.value;
|
|
282
293
|
question.setAnswer(prompt, {
|
|
283
294
|
questionId: prompt.id,
|
|
284
|
-
answer
|
|
285
|
-
custom: true
|
|
295
|
+
value: answer
|
|
286
296
|
});
|
|
287
297
|
},
|
|
288
298
|
[onChange, prompt, question]
|
|
@@ -291,7 +301,7 @@ var HumanInputQuestionTextAnswer = forwardRef2(
|
|
|
291
301
|
"textarea",
|
|
292
302
|
{
|
|
293
303
|
...props,
|
|
294
|
-
"aria-label": props["aria-label"] ?? prompt.
|
|
304
|
+
"aria-label": props["aria-label"] ?? prompt.text,
|
|
295
305
|
onChange: handleChange,
|
|
296
306
|
value,
|
|
297
307
|
"data-anvia-question-text-answer": ""
|
|
@@ -305,22 +315,25 @@ var HumanInputQuestionSubmit = forwardRef2(
|
|
|
305
315
|
const chat = useChatContext();
|
|
306
316
|
const question = useQuestion();
|
|
307
317
|
const answers = useMemo(
|
|
308
|
-
() => question.question.questions.flatMap((prompt) => {
|
|
318
|
+
() => question.question.request.questions.flatMap((prompt) => {
|
|
309
319
|
const answer = question.answers[prompt.id];
|
|
310
|
-
return answer === void 0 || answer.
|
|
320
|
+
return answer === void 0 || answer.value.trim().length === 0 ? [] : [answer];
|
|
311
321
|
}),
|
|
312
322
|
[question]
|
|
313
323
|
);
|
|
314
|
-
const disabled = props.disabled ?? (question.question.status !== "pending" || chat.
|
|
324
|
+
const disabled = props.disabled ?? (question.question.status !== "pending" || chat.respondingInteractions.has(question.question.request.id) || answers.length !== question.question.request.questions.length);
|
|
315
325
|
const handleClick = useCallback2(
|
|
316
326
|
(event) => {
|
|
317
327
|
onClick?.(event);
|
|
318
328
|
if (event.defaultPrevented || disabled) {
|
|
319
329
|
return;
|
|
320
330
|
}
|
|
321
|
-
void chat.
|
|
331
|
+
void chat.respondToInteraction({
|
|
332
|
+
interactionId: question.question.request.id,
|
|
333
|
+
response: { type: "tool-question", answers }
|
|
334
|
+
});
|
|
322
335
|
},
|
|
323
|
-
[answers, chat, disabled, onClick, question.question.id]
|
|
336
|
+
[answers, chat, disabled, onClick, question.question.request.id]
|
|
324
337
|
);
|
|
325
338
|
return renderPrimitive(
|
|
326
339
|
"button",
|
|
@@ -353,16 +366,15 @@ function QuestionProvider({
|
|
|
353
366
|
}
|
|
354
367
|
function defaultQuestionContent(question) {
|
|
355
368
|
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
356
|
-
/* @__PURE__ */ jsx2("div", { "data-anvia-question-tool": "", children: question.toolName }),
|
|
357
|
-
question.
|
|
358
|
-
question.questions.map((prompt) => /* @__PURE__ */ jsx2(HumanInputQuestionPrompt, { promptId: prompt.id }, prompt.id)),
|
|
369
|
+
/* @__PURE__ */ jsx2("div", { "data-anvia-question-tool": "", children: question.request.toolName }),
|
|
370
|
+
question.request.questions.map((prompt) => /* @__PURE__ */ jsx2(HumanInputQuestionPrompt, { promptId: prompt.id }, prompt.id)),
|
|
359
371
|
/* @__PURE__ */ jsx2(HumanInputQuestionSubmit, {})
|
|
360
372
|
] });
|
|
361
373
|
}
|
|
362
374
|
function defaultQuestionPrompt(prompt) {
|
|
363
375
|
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
364
|
-
/* @__PURE__ */ jsx2("div", { "data-anvia-question-text": "", children: prompt.
|
|
365
|
-
prompt.choices
|
|
376
|
+
/* @__PURE__ */ jsx2("div", { "data-anvia-question-text": "", children: prompt.text }),
|
|
377
|
+
(prompt.choices?.length ?? 0) > 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, {})
|
|
366
378
|
] });
|
|
367
379
|
}
|
|
368
380
|
|
|
@@ -409,4 +421,4 @@ var HumanInput = {
|
|
|
409
421
|
export {
|
|
410
422
|
HumanInput
|
|
411
423
|
};
|
|
412
|
-
//# sourceMappingURL=chunk-
|
|
424
|
+
//# sourceMappingURL=chunk-QHOLI3OZ.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 \"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.request.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 ??\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-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 ??\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-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: ApprovalInteraction): ReactNode {\n return (\n <>\n <div data-anvia-approval-tool=\"\">{approval.request.toolName}</div>\n {approval.request.input !== undefined ? (\n <pre data-anvia-approval-args=\"\">{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 \"data-anvia-human-input-panel\": \"\",\n } as PrimitiveProps<\"div\">,\n ref,\n );\n});\n\nexport { HumanInputPanel };\n","import type { AgentQuestionAnswer, AgentQuestionPrompt } from \"@anvia/core/agent\";\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-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 =\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 \"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]?.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-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]?.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 \"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.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-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: 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 data-anvia-question-tool=\"\">{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 data-anvia-question-text=\"\">{prompt.text}</div>\n {(prompt.choices?.length ?? 0) > 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":";;;;;;;;;;;;;;;;;;AAAA,SAA2B,YAA6C,mBAAmB;AAgE9D,SAoJzB,UApJyB,KAoJzB,YApJyB;AA7C7B,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,QAC7C,iCAAiC;AAAA,QACjC,gBAAgB,OAAO,YAAY;AAAA,MACrC;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;A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C,SAAI,+BAA4B,IAC9B,iBAAO,SAAS,IAAI,CAAC,WACpB,gBAAAA,KAAC,4BAA4C,OAAO,OAAO,OACxD,iBAAO,SADqB,OAAO,KAEtC,CACD,GACH,IAEA,gBAAAA,KAAC,gCAA6B;AAAA,KAElC;AAEJ;;;AD1QQ,qBAAAU,WACE,OAAAC,MADF,QAAAC,aAAA;AAhBR,IAAM,kBAAkBC,YAAiD,SAASC,iBAChF,EAAE,UAAU,SAAS,WAAW,GAAG,MAAM,GACzC,KACA;AACA,QAAM,aAAa,cAAc;AACjC,QAAM,YAAY,WAAW,QAAQ,WAAW,UAAU,MAAM,WAAW,UAAU;AACrF,QAAM,YAAY,WAAW,QAAQ,WAAW,UAAU,MAAM,WAAW,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,MAEF,gCAAgC;AAAA,IAClC;AAAA,IACA;AAAA,EACF;AACF,CAAC;;;AElBM,IAAM,aAAa;AAAA,EACxB,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-JMGFSYCR.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
|
() => ({
|
|
@@ -94,7 +95,7 @@ var CompletionInput = forwardRef(
|
|
|
94
95
|
{
|
|
95
96
|
...props,
|
|
96
97
|
"aria-label": props["aria-label"] ?? "Prompt",
|
|
97
|
-
disabled: props.disabled ?? input.status === "streaming",
|
|
98
|
+
disabled: props.disabled ?? (input.status === "submitted" || input.status === "streaming"),
|
|
98
99
|
onChange: handleChange,
|
|
99
100
|
onKeyDown: handleKeyDown,
|
|
100
101
|
value: input.input,
|
|
@@ -197,4 +198,4 @@ var Completion = {
|
|
|
197
198
|
export {
|
|
198
199
|
Completion
|
|
199
200
|
};
|
|
200
|
-
//# sourceMappingURL=chunk-
|
|
201
|
+
//# sourceMappingURL=chunk-URQROKGZ.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-anvia-completion-form\": \"\",\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 \"data-anvia-completion-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-anvia-completion-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-anvia-completion-stop\": \"\",\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-anvia-completion\": \"\",\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 \"data-anvia-completion-output\": \"\",\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 Completion = {\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,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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,8BAA8B;AAAA,QAC9B,cAAc,WAAW,aAAa;AAAA,MACxC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;;;ACpLA,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,yBAAyB;AAAA,QACzB,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,QACzC,gCAAgC;AAAA,MAClC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;;;ACvCO,IAAM,aAAa;AAAA,EACxB,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"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Message,
|
|
3
3
|
shiftComposerEntityRanges
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-BZZ7MJNM.js";
|
|
5
5
|
import {
|
|
6
6
|
Attachment
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-B5JX33SC.js";
|
|
8
8
|
import {
|
|
9
9
|
composeRefs,
|
|
10
10
|
renderPrimitive
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
useChatContext,
|
|
18
18
|
useComposer,
|
|
19
19
|
useThread
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-JMGFSYCR.js";
|
|
21
21
|
|
|
22
22
|
// src/chat/composer.tsx
|
|
23
23
|
import { mergeAttributes } from "@tiptap/core";
|
|
@@ -89,8 +89,9 @@ var ComposerRoot = forwardRef(function ComposerRoot2({
|
|
|
89
89
|
const entitiesControlled = entitiesProp !== void 0;
|
|
90
90
|
const quoteControlled = quoteProp !== void 0;
|
|
91
91
|
const hasMessageContent = input.trim().length > 0 || attachments.length > 0 || entities.length > 0 || quote !== void 0;
|
|
92
|
-
const
|
|
93
|
-
const
|
|
92
|
+
const active = chat.status === "submitted" || chat.status === "streaming";
|
|
93
|
+
const canSubmit = hasMessageContent && !active;
|
|
94
|
+
const canStop = active;
|
|
94
95
|
const setInput = useCallback(
|
|
95
96
|
(nextInput) => {
|
|
96
97
|
if (!inputControlled) {
|
|
@@ -160,7 +161,7 @@ var ComposerRoot = forwardRef(function ComposerRoot2({
|
|
|
160
161
|
}, [clearQuote, setAttachments, setEntities, setInput]);
|
|
161
162
|
const submit = useCallback(async () => {
|
|
162
163
|
const prompt = input;
|
|
163
|
-
if (prompt.trim().length === 0 && attachments.length === 0 && entities.length === 0 && quote === void 0 || chat.status === "streaming") {
|
|
164
|
+
if (prompt.trim().length === 0 && attachments.length === 0 && entities.length === 0 && quote === void 0 || chat.status === "submitted" || chat.status === "streaming") {
|
|
164
165
|
return;
|
|
165
166
|
}
|
|
166
167
|
if (submitMessage !== void 0) {
|
|
@@ -188,7 +189,7 @@ var ComposerRoot = forwardRef(function ComposerRoot2({
|
|
|
188
189
|
const metadata = composerSubmitMetadata(submittedQuote, submittedEntities);
|
|
189
190
|
let payload;
|
|
190
191
|
if (submittedAttachments.length === 0) {
|
|
191
|
-
payload = metadata === void 0 ?
|
|
192
|
+
payload = metadata === void 0 ? { text: submittedText } : { text: submittedText, metadata };
|
|
192
193
|
} else {
|
|
193
194
|
const attachmentPayload = {
|
|
194
195
|
text: submittedText,
|
|
@@ -356,7 +357,7 @@ var ComposerInput = forwardRef(function ComposerInput2({
|
|
|
356
357
|
{
|
|
357
358
|
extensions,
|
|
358
359
|
content: plainTextToComposerContent(composer.input),
|
|
359
|
-
editable: composer.status !== "streaming",
|
|
360
|
+
editable: composer.status !== "submitted" && composer.status !== "streaming",
|
|
360
361
|
editorProps: {
|
|
361
362
|
attributes: {
|
|
362
363
|
"aria-label": props["aria-label"] ?? "Message",
|
|
@@ -383,7 +384,7 @@ var ComposerInput = forwardRef(function ComposerInput2({
|
|
|
383
384
|
[extensions]
|
|
384
385
|
);
|
|
385
386
|
const ariaDisabled = props["aria-disabled"] === true || props["aria-disabled"] === "true";
|
|
386
|
-
const composerDisabled = disabled === true || ariaDisabled || composer.status === "streaming";
|
|
387
|
+
const composerDisabled = disabled === true || ariaDisabled || composer.status === "submitted" || composer.status === "streaming";
|
|
387
388
|
const inputStyle = useMemo(() => {
|
|
388
389
|
if (!autoResize) {
|
|
389
390
|
return style;
|
|
@@ -510,7 +511,7 @@ var ComposerTextareaInput = forwardRef(
|
|
|
510
511
|
{
|
|
511
512
|
...props,
|
|
512
513
|
"aria-label": props["aria-label"] ?? "Message",
|
|
513
|
-
disabled: props.disabled ?? composer.status === "streaming",
|
|
514
|
+
disabled: props.disabled ?? (composer.status === "submitted" || composer.status === "streaming"),
|
|
514
515
|
onChange: handleChange,
|
|
515
516
|
onKeyDown: handleKeyDown,
|
|
516
517
|
rows: autoResize ? minRows : rows,
|
|
@@ -1090,7 +1091,7 @@ var ComposerAttachments = forwardRef(
|
|
|
1090
1091
|
var ComposerAttachmentInput = forwardRef(
|
|
1091
1092
|
function ComposerAttachmentInput2({ onChange, ...props }, ref) {
|
|
1092
1093
|
const composer = useComposer();
|
|
1093
|
-
const disabled = props.disabled ?? composer.status === "streaming";
|
|
1094
|
+
const disabled = props.disabled ?? (composer.status === "submitted" || composer.status === "streaming");
|
|
1094
1095
|
const handleChange = useCallback(
|
|
1095
1096
|
async (event) => {
|
|
1096
1097
|
onChange?.(event);
|
|
@@ -1125,7 +1126,7 @@ var ComposerAddAttachment = forwardRef(
|
|
|
1125
1126
|
function ComposerAddAttachment2({ accept, multiple = false, onClick, ...props }, ref) {
|
|
1126
1127
|
const composer = useComposer();
|
|
1127
1128
|
const inputRef = useRef(null);
|
|
1128
|
-
const disabled = props.disabled ?? composer.status === "streaming";
|
|
1129
|
+
const disabled = props.disabled ?? (composer.status === "submitted" || composer.status === "streaming");
|
|
1129
1130
|
const handleClick = useCallback(
|
|
1130
1131
|
(event) => {
|
|
1131
1132
|
onClick?.(event);
|
|
@@ -1168,7 +1169,7 @@ var ComposerAttachmentDropzone = forwardRef(
|
|
|
1168
1169
|
function ComposerAttachmentDropzone2({ disabled: disabledProp = false, onDragLeave, onDragOver, onDrop, ...props }, ref) {
|
|
1169
1170
|
const composer = useComposer();
|
|
1170
1171
|
const [dragging, setDragging] = useState(false);
|
|
1171
|
-
const disabled = disabledProp || composer.status === "streaming";
|
|
1172
|
+
const disabled = disabledProp || composer.status === "submitted" || composer.status === "streaming";
|
|
1172
1173
|
const handleDragOver = useCallback(
|
|
1173
1174
|
(event) => {
|
|
1174
1175
|
onDragOver?.(event);
|
|
@@ -1410,7 +1411,7 @@ var ThreadStatus = forwardRef2(function ThreadStatus2({ children, ...props }, re
|
|
|
1410
1411
|
var ThreadLoading = forwardRef2(
|
|
1411
1412
|
function ThreadLoading2(props, ref) {
|
|
1412
1413
|
const chat = useChatContext();
|
|
1413
|
-
if (chat.status !== "streaming") {
|
|
1414
|
+
if (chat.status !== "submitted" && chat.status !== "streaming") {
|
|
1414
1415
|
return null;
|
|
1415
1416
|
}
|
|
1416
1417
|
return renderPrimitive(
|
|
@@ -1484,14 +1485,14 @@ var ThreadSuggestion = forwardRef2(
|
|
|
1484
1485
|
function ThreadSuggestion2({ onClick, prompt, suggestion, ...props }, ref) {
|
|
1485
1486
|
const chat = useChatContext();
|
|
1486
1487
|
const suggestionPrompt = prompt ?? suggestion?.prompt ?? "";
|
|
1487
|
-
const disabled = props.disabled ?? (suggestionPrompt.length === 0 || chat.status === "streaming");
|
|
1488
|
+
const disabled = props.disabled ?? (suggestionPrompt.length === 0 || chat.status === "submitted" || chat.status === "streaming");
|
|
1488
1489
|
const handleClick = useCallback2(
|
|
1489
1490
|
(event) => {
|
|
1490
1491
|
onClick?.(event);
|
|
1491
1492
|
if (event.defaultPrevented || disabled) {
|
|
1492
1493
|
return;
|
|
1493
1494
|
}
|
|
1494
|
-
void chat.sendMessage(suggestionPrompt);
|
|
1495
|
+
void chat.sendMessage({ text: suggestionPrompt });
|
|
1495
1496
|
},
|
|
1496
1497
|
[chat, disabled, onClick, suggestionPrompt]
|
|
1497
1498
|
);
|
|
@@ -1572,4 +1573,4 @@ export {
|
|
|
1572
1573
|
Composer,
|
|
1573
1574
|
Thread
|
|
1574
1575
|
};
|
|
1575
|
-
//# sourceMappingURL=chunk-
|
|
1576
|
+
//# sourceMappingURL=chunk-XZUF27QY.js.map
|