@agents24/chat-react 0.5.36 → 0.5.37
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/dist/{chunk-INO5DSSJ.js → chunk-DWDHK4FZ.js} +3 -4
- package/dist/chunk-DWDHK4FZ.js.map +1 -0
- package/dist/generated/delegation-types.d.ts +3 -2
- package/dist/generated/run-usage.d.ts +11 -0
- package/dist/registry/agents24-chat.json +13 -13
- package/dist/runtime/index.cjs +25 -9
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +24 -7
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/input-contract.d.ts +1 -1
- package/dist/runtime/use-agent-chat-hitl.d.ts +2 -2
- package/dist/runtime/use-agent-chat-runtime.d.ts +4 -6
- package/dist/scaffold/app.d.ts +2 -2
- package/dist/scaffold/components/chat/chat-composer.d.ts +2 -1
- package/dist/scaffold/components/chat/chat-message.d.ts +2 -2
- package/dist/scaffold/components/chat/message-parts.d.ts +2 -2
- package/dist/scaffold/index.cjs +17 -13
- package/dist/scaffold/index.cjs.map +1 -1
- package/dist/scaffold/index.js +11 -7
- package/dist/scaffold/index.js.map +1 -1
- package/dist/styles.css +7 -0
- package/dist/ui/agent-chat-composer.d.ts +2 -1
- package/dist/ui/agent-chat-message.d.ts +6 -2
- package/dist/ui/agent-response-timeline.d.ts +11 -3
- package/dist/ui/ask-user-interaction.d.ts +5 -1
- package/dist/ui/hitl-submission-status.d.ts +22 -0
- package/dist/ui/index.cjs +514 -337
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.js +510 -335
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/use-agent-chat-composer.d.ts +17 -2
- package/dist/ui/use-audio-recorder.d.ts +15 -2
- package/package.json +3 -3
- package/scaffold/src/app.tsx +2 -1
- package/scaffold/src/components/chat/chat-composer.tsx +5 -3
- package/scaffold/src/components/chat/chat-message.tsx +3 -3
- package/scaffold/src/components/chat/chat-shell.tsx +2 -1
- package/scaffold/src/components/chat/message-parts.tsx +6 -6
- package/dist/chunk-INO5DSSJ.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/use-agent-chat-runtime.ts","../../src/runtime/use-agent-chat-hitl.ts","../../src/runtime/use-delegation-tasks.ts"],"sourcesContent":["import type {\n AgentClient,\n Agents24ClientError,\n ClientBootstrap,\n EffectiveResourcePolicy,\n HitlResponse,\n PortableUpload,\n} from \"@agents24/client\";\nimport type { ContextCompression, ContextWindow } from \"@agents24/client/protocol\";\nimport {\n type AgentChatController,\n type ChatAttachment,\n type ChatHitlPart,\n useAgentAttachments,\n useAgentChat,\n} from \"@agents24/react\";\nimport * as React from \"react\";\n\nimport { useAgentChatHitl } from \"./use-agent-chat-hitl\";\nimport type { ChatMcpOauthCompletion } from \"../types\";\nimport { validateAgentChatSubmission } from \"./input-contract\";\n\nexport type AgentChatRuntimeAgent = {\n name: string;\n description?: string | null;\n handle?: string | null;\n avatarUrl?: string | null;\n};\n\nexport type AgentChatRuntimeModel = {\n id: string;\n label: string;\n};\n\nexport type AgentChatRuntimeAgentOption = { id: string; label: string };\n\nexport type AgentChatRuntimeViewState =\n | \"ready\"\n | \"loading\"\n | \"uploading\"\n | \"streaming\"\n | \"reconnecting\"\n | \"paused\"\n | \"cancelling\"\n | \"cancelled\"\n | \"offline\"\n | \"denied\"\n | \"quota\"\n | \"failed\"\n | \"expired\";\n\nexport type AgentChatRuntimeConnectionState =\n | \"connected\"\n | \"connecting\"\n | \"reconnecting\"\n | \"offline\"\n | \"expired\";\n\nexport type AgentChatThreadChangeReason = \"created\" | \"opened\" | \"new\" | \"deleted\";\n\nexport type AgentChatActiveThreadChange = {\n threadId: string | null;\n reason: AgentChatThreadChangeReason;\n};\n\nexport type AgentChatActiveThreadChangeHandler = (\n change: AgentChatActiveThreadChange,\n) => void;\n\nexport type AgentChatMcpAuthorizationCompletion = (input: {\n completion: ChatMcpOauthCompletion;\n codeVerifier: string;\n serverId: string;\n}) => Promise<void>;\n\nexport type AgentChatRuntimeSubmit = {\n text: string;\n files?: readonly PortableUpload[];\n attachments?: ChatAttachment[];\n attachmentIds?: readonly string[];\n};\n\nexport type AgentChatRuntimeHitlActionState = {\n action: string;\n error?: string | null;\n status: \"connecting\" | \"resuming\" | \"error\";\n};\n\nexport type UseAgentChatRuntimeOptions = {\n activeThreadId?: string | null;\n agent?: AgentChatRuntimeAgent;\n client: AgentClient;\n completeMcpAuthorization?: AgentChatMcpAuthorizationCompletion;\n mcpRedirectUri?: string;\n modelId?: string | null;\n onActiveThreadIdChange?: AgentChatActiveThreadChangeHandler;\n onModelChange?: (modelId: string) => void;\n};\n\nexport type AgentChatRuntime = {\n agent: AgentChatRuntimeAgent;\n inputContract: ClientBootstrap[\"features\"][\"inputs\"] | null;\n allowFeedback: boolean;\n backgroundError: unknown;\n bootstrap: ClientBootstrap | null;\n capabilities: readonly string[];\n agentId: string | null;\n agents: AgentChatRuntimeAgentOption[];\n changeAgent(agentId: string): Promise<void>;\n changeModel(modelId: string): void;\n clearOperationError(): void;\n connectionState: AgentChatRuntimeConnectionState;\n contextWindow: ContextWindow | null;\n contextCompression: ContextCompression | null;\n controller: AgentChatController;\n deleteThread(threadId: string): Promise<void>;\n errorMessage: string | null;\n fatalError: unknown;\n getHitlActionState(part: ChatHitlPart): AgentChatRuntimeHitlActionState | undefined;\n isBootstrapping: boolean;\n isChangingAgent: boolean;\n isSubmitting: boolean;\n isUploading: boolean;\n modelId: string | null;\n models: AgentChatRuntimeModel[];\n newThread(): void;\n onHitlAction(part: ChatHitlPart, response: HitlResponse): Promise<void>;\n openThread(threadId: string): Promise<void>;\n operationError: unknown;\n retryBootstrap(): Promise<void>;\n resolveAttachmentContent(\n attachment: ChatAttachment,\n signal: AbortSignal,\n ): Promise<{ url: string; validUntil: string | null }>;\n state: AgentChatRuntimeViewState;\n submit(input: AgentChatRuntimeSubmit): Promise<void>;\n};\n\ntype PendingThreadTransition = {\n reason: \"opened\" | \"deleted\";\n value: string | null;\n};\n\nexport function agentChatRuntimeStateFromError(error: unknown): AgentChatRuntimeViewState {\n const typed = error as Partial<Agents24ClientError> | null;\n if (typed?.kind === \"authentication\") return \"expired\";\n if (typed?.kind === \"authorization\") return \"denied\";\n if (typed?.kind === \"quota\" || typed?.kind === \"rate_limit\") return \"quota\";\n if (typed?.kind === \"network\") return \"offline\";\n return \"failed\";\n}\n\nexport function agentChatRuntimeErrorMessage(error: unknown): string | null {\n if (!error) return null;\n return error instanceof Error ? error.message : String(error);\n}\n\nexport function canChangeAgentRuntime(\n runState: AgentChatController[\"runState\"],\n activeRunId: string | null,\n): boolean {\n return !activeRunId && ![\"uploading\", \"streaming\", \"reconnecting\", \"paused\", \"cancelling\"].includes(runState);\n}\n\nexport function agentIdFromBootstrap(\n bootstrap: ClientBootstrap,\n requestedAgentId: string | null,\n): string | null {\n const feature = bootstrap.features.agents;\n if (!feature) return null;\n return feature.options.some((item) => item.id === requestedAgentId)\n ? requestedAgentId\n : feature.default_id || null;\n}\n\nexport function modelsFromAgentChatBootstrap(bootstrap: ClientBootstrap): {\n defaultModelId: string | null;\n models: AgentChatRuntimeModel[];\n} {\n const modelFeatures = bootstrap.features.models;\n const selectable = bootstrap.capabilities.includes(\"models.select\") && modelFeatures?.selectable === true;\n if (!selectable) return { defaultModelId: null, models: [] };\n const models = Array.isArray(modelFeatures.options)\n ? modelFeatures.options.flatMap((option) => (\n typeof option?.id === \"string\" && option.id.trim()\n ? [{ id: option.id, label: typeof option.label === \"string\" && option.label.trim() ? option.label : option.id }]\n : []\n ))\n : [];\n const configuredDefault = models.some((model) => model.id === modelFeatures.default_id)\n ? modelFeatures.default_id\n : null;\n return {\n defaultModelId: configuredDefault,\n models,\n };\n}\n\nfunction modelsFromEffectivePolicy(policy: EffectiveResourcePolicy): {\n defaultModelId: string | null;\n models: AgentChatRuntimeModel[];\n} {\n const models = policy.model_selection.selectable\n ? policy.model_selection.options.map((option) => ({ id: option.id, label: option.label }))\n : [];\n return {\n defaultModelId: models.some((model) => model.id === policy.model_selection.default_id)\n ? policy.model_selection.default_id\n : null,\n models,\n };\n}\n\nexport function useAgentChatRuntime(options: UseAgentChatRuntimeOptions): AgentChatRuntime {\n const {\n activeThreadId,\n agent: agentOverride,\n client,\n completeMcpAuthorization,\n mcpRedirectUri,\n modelId,\n onActiveThreadIdChange,\n onModelChange,\n } = options;\n const controller = useAgentChat(\n activeThreadId === undefined ? { client } : { activeThreadId, client },\n );\n const attachments = useAgentAttachments();\n const [bootstrap, setBootstrap] = React.useState<ClientBootstrap | null>(null);\n const bootstrapRef = React.useRef<ClientBootstrap | null>(bootstrap);\n bootstrapRef.current = bootstrap;\n const [effectivePolicy, setEffectivePolicy] = React.useState<EffectiveResourcePolicy | null>(null);\n const [isBootstrapping, setIsBootstrapping] = React.useState(true);\n const [bootstrapError, setBootstrapError] = React.useState<unknown>(null);\n const [localOperationError, setLocalOperationError] = React.useState<unknown>(null);\n const [selectedModelId, setSelectedModelId] = React.useState<string | null>(modelId ?? null);\n const selectedModelIdRef = React.useRef<string | null>(selectedModelId);\n selectedModelIdRef.current = selectedModelId;\n const [selectedAgentId, setSelectedAgentId] = React.useState<string | null>(null);\n const selectedAgentIdRef = React.useRef<string | null>(null);\n selectedAgentIdRef.current = selectedAgentId;\n const [isChangingAgent, setIsChangingAgent] = React.useState(false);\n const agentChangePromiseRef = React.useRef<Promise<void> | null>(null);\n const [isSubmitting, setIsSubmitting] = React.useState(false);\n const submitPromiseRef = React.useRef<Promise<void> | null>(null);\n\n const mountedRef = React.useRef(true);\n const clientRef = React.useRef(client);\n clientRef.current = client;\n const bootstrapPromiseRef = React.useRef<{ client: AgentClient; promise: Promise<void> } | null>(null);\n React.useEffect(() => {\n mountedRef.current = true;\n return () => { mountedRef.current = false; };\n }, []);\n\n const previousControlledThreadRef = React.useRef(activeThreadId);\n const threadSelectionGenerationRef = React.useRef(0);\n const controlledSyncTargetRef = React.useRef<{ value: string | null } | null>(null);\n const previousControllerThreadRef = React.useRef(controller.activeThreadId);\n const pendingThreadTransitionRef = React.useRef<PendingThreadTransition | null>(null);\n const lastReportedThreadRef = React.useRef<string | null>(activeThreadId ?? controller.activeThreadId);\n if (activeThreadId !== previousControlledThreadRef.current) {\n threadSelectionGenerationRef.current += 1;\n previousControlledThreadRef.current = activeThreadId;\n if (activeThreadId !== undefined) {\n controlledSyncTargetRef.current = { value: activeThreadId };\n lastReportedThreadRef.current = activeThreadId;\n }\n }\n\n const reportActiveThread = React.useCallback((\n threadId: string | null,\n reason: AgentChatThreadChangeReason,\n ) => {\n if (lastReportedThreadRef.current === threadId) return;\n lastReportedThreadRef.current = threadId;\n onActiveThreadIdChange?.({ threadId, reason });\n }, [onActiveThreadIdChange]);\n\n const retryBootstrap = React.useCallback((): Promise<void> => {\n if (bootstrapPromiseRef.current?.client === client) return bootstrapPromiseRef.current.promise;\n const requestClient = client;\n const request = (async () => {\n if (mountedRef.current) {\n setIsBootstrapping(true);\n setBootstrapError(null);\n setBootstrap(null);\n setEffectivePolicy(null);\n }\n try {\n const requestedAgentId = selectedAgentIdRef.current;\n const result = await requestClient.bootstrap({ agentId: requestedAgentId || undefined });\n if (!mountedRef.current || clientRef.current !== requestClient) return;\n setBootstrap(result);\n const agentFeature = result.features.agents;\n const resolvedAgentId = agentIdFromBootstrap(result, requestedAgentId);\n setSelectedAgentId(resolvedAgentId);\n const entitlement = agentFeature ? null : await requestClient.resourcePolicies.getEffective();\n if (!mountedRef.current || clientRef.current !== requestClient) return;\n setEffectivePolicy(entitlement);\n const availableModels = entitlement ? modelsFromEffectivePolicy(entitlement) : modelsFromAgentChatBootstrap(result);\n if (modelId === undefined) {\n setSelectedModelId((current) => availableModels.models.some((item) => item.id === current)\n ? current\n : availableModels.defaultModelId);\n }\n await controller.refreshThreads().catch(() => undefined);\n } catch (error) {\n if (mountedRef.current && clientRef.current === requestClient) setBootstrapError(error);\n } finally {\n if (mountedRef.current && clientRef.current === requestClient) setIsBootstrapping(false);\n }\n })();\n bootstrapPromiseRef.current = { client: requestClient, promise: request };\n void request.finally(() => {\n if (bootstrapPromiseRef.current?.promise === request) bootstrapPromiseRef.current = null;\n });\n return request;\n }, [client, controller.refreshThreads, modelId]);\n\n const refreshEffectivePolicy = React.useCallback(async () => {\n if (bootstrap?.features.agents) {\n const refreshed = await client.bootstrap({ agentId: selectedAgentIdRef.current || undefined });\n if (!mountedRef.current || clientRef.current !== client) return;\n setBootstrap(refreshed);\n const available = modelsFromAgentChatBootstrap(refreshed);\n setSelectedModelId((current) => available.models.some((item) => item.id === current)\n ? current\n : available.defaultModelId);\n return;\n }\n const entitlement = await client.resourcePolicies.getEffective();\n if (!mountedRef.current || clientRef.current !== client) return;\n setEffectivePolicy(entitlement);\n if (modelId === undefined) {\n const available = modelsFromEffectivePolicy(entitlement);\n setSelectedModelId((current) => available.models.some((item) => item.id === current)\n ? current\n : available.defaultModelId);\n }\n }, [bootstrap, client, modelId]);\n\n React.useEffect(() => {\n void retryBootstrap();\n }, [retryBootstrap]);\n\n React.useEffect(() => {\n if (modelId !== undefined) setSelectedModelId(modelId);\n }, [modelId]);\n\n React.useEffect(() => {\n if (controlledSyncTargetRef.current?.value === null && controller.activeThreadId) {\n controller.startNewThread();\n }\n }, [activeThreadId, controller.activeThreadId, controller.startNewThread]);\n\n React.useEffect(() => {\n const previous = previousControllerThreadRef.current;\n const current = controller.activeThreadId;\n previousControllerThreadRef.current = current;\n const controlledTarget = controlledSyncTargetRef.current;\n if (controlledTarget) {\n if (current === controlledTarget.value) controlledSyncTargetRef.current = null;\n return;\n }\n const pendingTransition = pendingThreadTransitionRef.current;\n if (pendingTransition && current === pendingTransition.value) return;\n if (previous === null && current !== null) reportActiveThread(current, \"created\");\n }, [activeThreadId, controller.activeThreadId, reportActiveThread]);\n\n const clearOperationError = React.useCallback(() => {\n setLocalOperationError(null);\n controller.clearOperationError();\n }, [controller.clearOperationError]);\n\n const submit = React.useCallback((input: AgentChatRuntimeSubmit): Promise<void> => {\n if (submitPromiseRef.current) return submitPromiseRef.current;\n clearOperationError();\n setIsSubmitting(true);\n const request = (async () => {\n try {\n await agentChangePromiseRef.current;\n const activeBootstrap = bootstrapRef.current;\n if (!activeBootstrap) throw new Error(\"The agent input contract is unavailable.\");\n const retained = (input.attachments || []).filter((attachment) => input.attachmentIds?.includes(attachment.id || \"\"));\n const inputError = validateAgentChatSubmission(activeBootstrap.features.inputs, input.text, [\n ...(input.files || []),\n ...retained.map((attachment) => ({ data: new Uint8Array(), mediaType: attachment.mediaType || \"application/octet-stream\" })),\n ]);\n if (inputError) throw new Error(inputError);\n await controller.submit({\n text: input.text,\n attachments: input.attachments,\n uploads: input.files,\n attachmentIds: input.attachmentIds,\n requestedModelId: selectedModelIdRef.current || undefined,\n requestedAgentId: selectedAgentIdRef.current || undefined,\n });\n } catch (error) {\n setLocalOperationError(error);\n const typed = error as Partial<Agents24ClientError>;\n if (typed.kind === \"quota\" || typed.kind === \"authorization\") {\n await refreshEffectivePolicy().catch(() => undefined);\n }\n throw error;\n } finally {\n setIsSubmitting(false);\n }\n })();\n submitPromiseRef.current = request;\n const clearRequest = () => {\n if (submitPromiseRef.current === request) submitPromiseRef.current = null;\n };\n void request.then(clearRequest, clearRequest);\n return request;\n }, [bootstrap, clearOperationError, controller.activeThreadId, controller.submit, refreshEffectivePolicy]);\n\n const { onHitlAction, getHitlActionState } = useAgentChatHitl({\n client, bootstrap, controller, selectionGeneration: threadSelectionGenerationRef,\n completeMcpAuthorization, mcpRedirectUri, clearOperationError, onError: setLocalOperationError,\n });\n\n const newThread = React.useCallback(() => {\n threadSelectionGenerationRef.current += 1;\n clearOperationError();\n pendingThreadTransitionRef.current = null;\n reportActiveThread(null, \"new\");\n controller.startNewThread();\n }, [clearOperationError, controller.startNewThread, reportActiveThread]);\n\n const openThread = React.useCallback(async (threadId: string) => {\n const requestGeneration = ++threadSelectionGenerationRef.current;\n clearOperationError();\n pendingThreadTransitionRef.current = { reason: \"opened\", value: threadId };\n try {\n const detail = await client.threads.get({ threadId });\n if (requestGeneration !== threadSelectionGenerationRef.current) return;\n const preferredAgentId = detail.runtime_selection?.agent_alias || detail.runtime_selection?.agent_id || null;\n if (preferredAgentId) {\n const result = await client.bootstrap({ agentId: preferredAgentId });\n if (requestGeneration !== threadSelectionGenerationRef.current) return;\n const resolvedAgentId = agentIdFromBootstrap(result, preferredAgentId);\n setBootstrap(result);\n setEffectivePolicy(null);\n setSelectedAgentId(resolvedAgentId);\n const available = modelsFromAgentChatBootstrap(result);\n const preferredModelId = detail.runtime_selection?.model_id || null;\n setSelectedModelId(available.models.some((item) => item.id === preferredModelId)\n ? preferredModelId\n : available.defaultModelId);\n }\n await controller.openThread(threadId);\n if (requestGeneration !== threadSelectionGenerationRef.current) return;\n reportActiveThread(threadId, \"opened\");\n } catch (error) {\n if (requestGeneration !== threadSelectionGenerationRef.current) return;\n setLocalOperationError(error);\n throw error;\n } finally {\n if (requestGeneration === threadSelectionGenerationRef.current) pendingThreadTransitionRef.current = null;\n }\n }, [clearOperationError, client, controller.openThread, reportActiveThread]);\n\n const deleteThread = React.useCallback(async (threadId: string) => {\n clearOperationError();\n const wasActive = controller.activeThreadId === threadId;\n if (wasActive) threadSelectionGenerationRef.current += 1;\n if (wasActive) pendingThreadTransitionRef.current = { reason: \"deleted\", value: null };\n try {\n await controller.deleteThread(threadId);\n if (wasActive) reportActiveThread(null, \"deleted\");\n } catch (error) {\n setLocalOperationError(error);\n throw error;\n } finally {\n if (wasActive && pendingThreadTransitionRef.current?.reason === \"deleted\") {\n pendingThreadTransitionRef.current = null;\n }\n }\n }, [clearOperationError, controller.activeThreadId, controller.deleteThread, reportActiveThread]);\n\n const changeModel = React.useCallback((nextModelId: string) => {\n if (modelId === undefined) setSelectedModelId(nextModelId);\n onModelChange?.(nextModelId);\n if (controller.activeThreadId && selectedAgentId && client.threads.setRuntimeSelection) {\n void client.threads.setRuntimeSelection({\n threadId: controller.activeThreadId,\n preferredAgentId: selectedAgentId,\n preferredModelId: nextModelId,\n }).catch(setLocalOperationError);\n }\n }, [client.threads, controller.activeThreadId, modelId, onModelChange, selectedAgentId]);\n\n const resolveAttachmentContent = React.useCallback(async (\n attachment: ChatAttachment,\n signal: AbortSignal,\n ) => {\n const attachmentId = typeof attachment.id === \"string\" ? attachment.id.trim() : \"\";\n if (!attachmentId) throw new Error(\"Attachment content identity is unavailable.\");\n const access = await attachments.createContentAccess({\n attachmentId,\n disposition: \"inline\",\n signal,\n });\n return { url: access.url, validUntil: access.valid_until || null };\n }, [attachments.createContentAccess]);\n\n const changeAgent = React.useCallback((nextAgentId: string): Promise<void> => {\n if (agentChangePromiseRef.current) return agentChangePromiseRef.current;\n if (\n nextAgentId === selectedAgentIdRef.current\n || !canChangeAgentRuntime(controller.runState, controller.activeRunId)\n ) return Promise.resolve();\n clearOperationError();\n setIsChangingAgent(true);\n const request = (async () => {\n try {\n const result = await client.bootstrap({ agentId: nextAgentId });\n const resolvedAgentId = agentIdFromBootstrap(result, nextAgentId);\n if (!resolvedAgentId) throw new Error(\"The requested Agent is no longer available.\");\n const available = modelsFromAgentChatBootstrap(result);\n const currentModelId = selectedModelIdRef.current;\n const nextModelId = available.models.some((item) => item.id === currentModelId)\n ? currentModelId\n : available.defaultModelId;\n if (controller.activeThreadId && client.threads.setRuntimeSelection) {\n const persisted = await client.threads.setRuntimeSelection({\n threadId: controller.activeThreadId,\n preferredAgentId: resolvedAgentId,\n preferredModelId: nextModelId,\n });\n selectedModelIdRef.current = persisted.runtime_selection.model_id;\n setSelectedModelId(persisted.runtime_selection.model_id);\n } else {\n selectedModelIdRef.current = nextModelId;\n setSelectedModelId(nextModelId);\n }\n selectedAgentIdRef.current = resolvedAgentId;\n bootstrapRef.current = result;\n setSelectedAgentId(resolvedAgentId);\n setBootstrap(result);\n setEffectivePolicy(null);\n } catch (error) {\n setLocalOperationError(error);\n throw error;\n }\n })();\n agentChangePromiseRef.current = request;\n const clearRequest = () => {\n if (agentChangePromiseRef.current === request) agentChangePromiseRef.current = null;\n if (mountedRef.current) setIsChangingAgent(false);\n };\n void request.then(clearRequest, clearRequest);\n return request;\n }, [clearOperationError, client, controller.activeRunId, controller.activeThreadId, controller.runState]);\n\n const modelOptions = effectivePolicy\n ? modelsFromEffectivePolicy(effectivePolicy).models\n : bootstrap\n ? modelsFromAgentChatBootstrap(bootstrap).models\n : [];\n const fatalError = bootstrapError || controller.error;\n const operationError = localOperationError || controller.operationError?.cause;\n const state: AgentChatRuntimeViewState = isBootstrapping\n ? \"loading\"\n : fatalError\n ? agentChatRuntimeStateFromError(fatalError)\n : controller.runState === \"uploading\"\n ? \"uploading\"\n : controller.runState === \"streaming\"\n ? \"streaming\"\n : controller.runState === \"reconnecting\"\n ? \"reconnecting\"\n : controller.runState === \"paused\"\n ? \"paused\"\n : controller.runState === \"cancelling\"\n ? \"cancelling\"\n : controller.runState === \"cancelled\"\n ? \"cancelled\"\n : \"ready\";\n const connectionState: AgentChatRuntimeConnectionState = state === \"offline\"\n ? \"offline\"\n : state === \"expired\"\n ? \"expired\"\n : state === \"reconnecting\"\n ? \"reconnecting\"\n : isBootstrapping\n ? \"connecting\"\n : \"connected\";\n return {\n agent: agentOverride || { name: bootstrap?.deployment.name || \"Agent\" },\n inputContract: bootstrap?.features.inputs || null,\n allowFeedback: Boolean(bootstrap?.capabilities.includes(\"feedback.write\")),\n backgroundError: controller.backgroundError?.cause || null,\n bootstrap,\n capabilities: bootstrap?.capabilities || [],\n agentId: selectedAgentId,\n agents: bootstrap?.features.agents?.options.map((item) => ({ id: item.id, label: item.label })) || [],\n changeAgent,\n changeModel,\n clearOperationError,\n connectionState,\n contextWindow: controller.contextWindow,\n contextCompression: controller.contextCompression,\n controller,\n deleteThread,\n errorMessage: agentChatRuntimeErrorMessage(fatalError || operationError),\n fatalError,\n getHitlActionState,\n isBootstrapping,\n isChangingAgent,\n isSubmitting: isSubmitting || controller.isSubmitting,\n isUploading: attachments.isUploading || controller.runState === \"uploading\",\n modelId: selectedModelId,\n models: modelOptions,\n newThread,\n onHitlAction,\n openThread,\n operationError,\n retryBootstrap,\n resolveAttachmentContent,\n state,\n submit,\n };\n}\n","import type { AgentClient, ClientBootstrap, HitlResponse } from \"@agents24/client\";\nimport { type AgentChatController, type ChatHitlPart, useAgentMcp } from \"@agents24/react\";\nimport * as React from \"react\";\nimport { browserChatCrypto, createMcpPkceProof, validateMcpCallbackResult, waitForMcpOauthComplete } from \"../mcp-oauth\";\nimport type { AgentChatMcpAuthorizationCompletion, AgentChatRuntimeHitlActionState } from \"./use-agent-chat-runtime\";\n\ntype HitlOptions = {\n client: AgentClient;\n bootstrap: ClientBootstrap | null;\n controller: AgentChatController;\n selectionGeneration: React.MutableRefObject<number>;\n completeMcpAuthorization?: AgentChatMcpAuthorizationCompletion;\n mcpRedirectUri?: string;\n clearOperationError(): void;\n onError(error: unknown): void;\n};\n\ntype HitlOperation = {\n abort: AbortController;\n isCurrent(): boolean;\n phase: \"connecting\" | \"resuming\";\n popup?: Window;\n};\n\nfunction detach(operation: HitlOperation) {\n operation.abort.abort();\n operation.popup?.close();\n}\n\nexport function useAgentChatHitl(options: HitlOptions) {\n const mcp = useAgentMcp();\n const latest = React.useRef(options);\n latest.current = options;\n const mounted = React.useRef(true);\n const operations = React.useRef(new Map<string, HitlOperation>());\n const [states, setStates] = React.useState<Record<string, AgentChatRuntimeHitlActionState>>({});\n\n React.useEffect(() => {\n mounted.current = true;\n const active = operations.current;\n return () => {\n mounted.current = false;\n for (const operation of active.values()) detach(operation);\n active.clear();\n };\n }, []);\n React.useEffect(() => {\n for (const [key, operation] of operations.current) {\n if (operation.isCurrent()) continue;\n detach(operation);\n operations.current.delete(key);\n setStates((current) => {\n const next = { ...current };\n delete next[key];\n return next;\n });\n }\n });\n React.useEffect(() => { setStates({}); }, [options.client, options.controller.activeThreadId]);\n\n const onHitlAction = React.useCallback(async (part: ChatHitlPart, response: HitlResponse) => {\n const captured = latest.current;\n const { controller, client, bootstrap, selectionGeneration } = captured;\n const key = part.interruptId || part.id;\n if (operations.current.has(key)) return;\n const generation = selectionGeneration.current;\n const threadId = controller.activeThreadId;\n const runId = controller.messages.find((message) => message.parts.includes(part))?.runId || controller.activeRunId;\n const operation: HitlOperation = {\n abort: new AbortController(),\n phase: part.hitlKind === \"mcp_auth\" && response.action === \"connect\" ? \"connecting\" : \"resuming\",\n isCurrent() {\n const current = latest.current;\n return mounted.current && !operation.abort.signal.aborted\n && current.client === client && current.selectionGeneration.current === generation\n && current.controller.activeThreadId === threadId\n && (!current.controller.activeRunId || current.controller.activeRunId === runId)\n && ![\"cancelling\", \"cancelled\", \"failed\", \"completed\"].includes(current.controller.runState)\n && (operation.phase === \"resuming\" || current.controller.messages.some((message) =>\n message.runId === runId && message.parts.some((candidate) => candidate.type === \"hitl\"\n && candidate.interruptId === part.interruptId && candidate.status === \"pending\")));\n },\n };\n if (!operation.isCurrent()) return;\n captured.clearOperationError();\n operations.current.set(key, operation);\n setStates((current) => ({ ...current, [key]: { action: response.action, status: operation.phase } }));\n try {\n if (operation.phase === \"connecting\") {\n if (!runId) throw new Error(\"MCP authorization is missing its paused run.\");\n if (!bootstrap) throw new Error(\"MCP authorization requires runtime bootstrap.\");\n if (!captured.mcpRedirectUri) throw new Error(\"mcpRedirectUri is required for MCP Connect.\");\n const serverId = String(part.presentation.server_id || \"\").trim();\n if (!serverId) throw new Error(\"MCP authorization is missing its server identity.\");\n const serverEmbed = bootstrap.authentication.modes.includes(\"server_embed\");\n const popupNonce = browserChatCrypto().randomUUID();\n // Open within the click before awaiting crypto or the network.\n const popup = window.open(\"about:blank\", \"agents24-mcp\", \"popup,width=560,height=720\");\n if (!popup) throw new Error(\"Allow popups to connect this MCP account.\");\n operation.popup = popup;\n popup.document.title = \"Connecting to MCP\";\n popup.document.body.textContent = \"Opening secure connection…\";\n const proof = await createMcpPkceProof();\n if (!operation.isCurrent()) return;\n const started = await mcp.startAuthorization({\n runId, serverId, interruptId: part.interruptId, redirectUri: captured.mcpRedirectUri,\n popupNonce, codeChallenge: proof.challenge, signal: operation.abort.signal,\n });\n if (!operation.isCurrent()) return;\n if (!started.callback_origin) throw new Error(\"MCP authorization did not return a callback origin.\");\n const completionPromise = waitForMcpOauthComplete({\n popup, callbackOrigin: started.callback_origin, popupNonce, serverId,\n runId, interruptId: part.interruptId, signal: operation.abort.signal,\n requireConnectionId: serverEmbed || Boolean(captured.completeMcpAuthorization),\n });\n // Ensure a navigation exception cannot leave a rejected waiter unobserved.\n void completionPromise.catch(() => undefined);\n popup.location.replace(started.authorization_url);\n const completion = await completionPromise;\n if (!operation.isCurrent()) return;\n if (captured.completeMcpAuthorization) {\n await captured.completeMcpAuthorization({ completion, codeVerifier: proof.verifier, serverId });\n } else if (serverEmbed) {\n validateMcpCallbackResult({ server_id: completion.serverId, connection_id: completion.connectionId || \"\" }, serverId);\n } else {\n const redeemed = await mcp.redeemCallback({\n code: completion.code, codeVerifier: proof.verifier, signal: operation.abort.signal,\n });\n if (!operation.isCurrent()) return;\n validateMcpCallbackResult(redeemed, serverId);\n }\n popup.close();\n }\n if (!operation.isCurrent()) return;\n operation.phase = \"resuming\";\n setStates((current) => ({ ...current, [key]: { action: response.action, status: \"resuming\" } }));\n await controller.resumeHitl(part, response);\n } catch (error) {\n if (!operation.isCurrent()) return;\n captured.onError(error);\n setStates((current) => ({ ...current, [key]: {\n action: response.action, status: \"error\", error: error instanceof Error ? error.message : String(error),\n } }));\n throw error;\n } finally {\n const ownsState = operation.isCurrent();\n // Abort the waiter and any in-flight transport, and always release the popup.\n detach(operation);\n if (operations.current.get(key) === operation) {\n operations.current.delete(key);\n if (ownsState) setStates((current) => {\n if (current[key]?.status === \"error\") return current;\n const next = { ...current };\n delete next[key];\n return next;\n });\n }\n }\n }, [mcp]);\n\n return { onHitlAction, getHitlActionState: (part: ChatHitlPart) => states[part.interruptId || part.id] };\n}\n","import * as React from \"react\";\nimport type { DelegationEvents, DelegationTask } from \"../generated/delegation-types\";\n\nexport type DelegationTaskSource = {\n events(input: { threadId: string; after: number; signal: AbortSignal }): Promise<DelegationEvents>;\n};\n\n/** Authoritative snapshots keep task discovery alive after the run stream ends. */\nexport function useDelegationTasks({ threadId, source, pollIntervalMs = 2000 }: {\n threadId: string | null;\n source: DelegationTaskSource;\n pollIntervalMs?: number;\n}) {\n const [state, setState] = React.useState<{\n threadId: string | null; tasks: DelegationTask[]; error: unknown; loading: boolean;\n }>({ threadId: null, tasks: [], error: null, loading: false });\n const [revision, refresh] = React.useReducer((value: number) => value + 1, 0);\n React.useEffect(() => {\n if (!threadId) {\n setState({ threadId: null, tasks: [], error: null, loading: false });\n return;\n }\n const controller = new AbortController();\n let cursor = 0;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let failures = 0;\n setState((previous) => ({ threadId, tasks: previous.threadId === threadId ? previous.tasks : [],\n error: null, loading: true }));\n const poll = async () => {\n try {\n const result = await source.events({ threadId, after: cursor, signal: controller.signal });\n if (controller.signal.aborted) return;\n cursor = result.cursor;\n failures = 0;\n setState({ threadId, tasks: result.snapshot, error: null, loading: false });\n } catch (error) {\n if (controller.signal.aborted) return;\n failures += 1;\n setState((previous) => ({ ...previous, error, loading: false }));\n }\n if (!controller.signal.aborted) {\n timer = setTimeout(poll, Math.min(30000, Math.max(250, pollIntervalMs) * 2 ** Math.min(failures, 4)));\n }\n };\n void poll();\n return () => {\n controller.abort();\n if (timer) clearTimeout(timer);\n };\n }, [threadId, source, pollIntervalMs, revision]);\n return { tasks: state.threadId === threadId ? state.tasks : [],\n error: state.threadId === threadId ? state.error : null,\n loading: Boolean(threadId) && (state.threadId !== threadId || state.loading), refresh };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AASA;AAAA,EAIE;AAAA,EACA;AAAA,OACK;AACP,YAAYA,YAAW;;;ACfvB,SAAsD,mBAAmB;AACzE,YAAY,WAAW;AAsBvB,SAAS,OAAO,WAA0B;AACxC,YAAU,MAAM,MAAM;AACtB,YAAU,OAAO,MAAM;AACzB;AAEO,SAAS,iBAAi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,MAAM,SAAS,MAAM,CAAC;AAAA,MAC5E,SAAS,OAAO;AACd,YAAI,WAAW,OAAO,QAAS;AAC/B,oBAAY;AACZ,iBAAS,CAAC,cAAc,EAAE,GAAG,UAAU,OAAO,SAAS,MAAM,EAAE;AAAA,MACjE;AACA,UAAI,CAAC,WAAW,OAAO,SAAS;AAC9B,gBAAQ,WAAW,MAAM,KAAK,IAAI,KAAO,KAAK,IAAI,KAAK,cAAc,IAAI,KAAK,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC;AAAA,MACtG;AAAA,IACF;AACA,SAAK,KAAK;AACV,WAAO,MAAM;AACX,iBAAW,MAAM;AACjB,UAAI,MAAO,cAAa,KAAK;AAAA,IAC/B;AAAA,EACF,GAAG,CAAC,UAAU,QAAQ,gBAAgB,QAAQ,CAAC;AAC/C,SAAO;AAAA,IAAE,OAAO,MAAM,aAAa,WAAW,MAAM,QAAQ,CAAC;AAAA,IAC3D,OAAO,MAAM,aAAa,WAAW,MAAM,QAAQ;AAAA,IACnD,SAAS,QAAQ,QAAQ,MAAM,MAAM,aAAa,YAAY,MAAM;AAAA,IAAU;AAAA,EAAQ;AAC1F;","names":["React","React"]}
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/use-agent-chat-runtime.ts","../../src/runtime/use-agent-chat-hitl.ts","../../src/runtime/use-delegation-tasks.ts"],"sourcesContent":["import type {\n AgentClient,\n Agents24ClientError,\n ClientBootstrap,\n EffectiveResourcePolicy,\n HitlResponse,\n PortableUpload,\n} from \"@agents24/client\";\nimport type { ContextCompression, ContextWindow } from \"@agents24/client/protocol\";\nimport {\n type AgentChatController,\n type ChatAttachment,\n type ChatHitlPart,\n type HitlSubmissionOptions,\n type HitlSubmissionState,\n useAgentAttachments,\n useAgentChat,\n} from \"@agents24/react\";\nimport * as React from \"react\";\n\nimport { useAgentChatHitl } from \"./use-agent-chat-hitl\";\nimport type { ChatMcpOauthCompletion } from \"../types\";\nimport { validateAgentChatSubmission } from \"./input-contract\";\n\nexport type AgentChatRuntimeAgent = {\n name: string;\n description?: string | null;\n handle?: string | null;\n avatarUrl?: string | null;\n};\n\nexport type AgentChatRuntimeModel = {\n id: string;\n label: string;\n};\n\nexport type AgentChatRuntimeAgentOption = { id: string; label: string };\n\nexport type AgentChatRuntimeViewState =\n | \"ready\"\n | \"loading\"\n | \"uploading\"\n | \"streaming\"\n | \"reconnecting\"\n | \"paused\"\n | \"cancelling\"\n | \"cancelled\"\n | \"offline\"\n | \"denied\"\n | \"quota\"\n | \"failed\"\n | \"expired\";\n\nexport type AgentChatRuntimeConnectionState =\n | \"connected\"\n | \"connecting\"\n | \"reconnecting\"\n | \"offline\"\n | \"expired\";\n\nexport type AgentChatThreadChangeReason = \"created\" | \"opened\" | \"new\" | \"deleted\";\n\nexport type AgentChatActiveThreadChange = {\n threadId: string | null;\n reason: AgentChatThreadChangeReason;\n};\n\nexport type AgentChatActiveThreadChangeHandler = (\n change: AgentChatActiveThreadChange,\n) => void;\n\nexport type AgentChatMcpAuthorizationCompletion = (input: {\n completion: ChatMcpOauthCompletion;\n codeVerifier: string;\n serverId: string;\n}) => Promise<void>;\n\nexport type AgentChatRuntimeSubmit = {\n text: string;\n files?: readonly PortableUpload[];\n attachments?: ChatAttachment[];\n attachmentIds?: readonly string[];\n};\n\nexport type AgentChatRuntimeHitlActionState = Omit<HitlSubmissionState, \"status\"> & {\n status: HitlSubmissionState[\"status\"] | \"connecting\" | \"resuming\";\n};\n\nexport type UseAgentChatRuntimeOptions = {\n activeThreadId?: string | null;\n agent?: AgentChatRuntimeAgent;\n client: AgentClient;\n completeMcpAuthorization?: AgentChatMcpAuthorizationCompletion;\n mcpRedirectUri?: string;\n modelId?: string | null;\n onActiveThreadIdChange?: AgentChatActiveThreadChangeHandler;\n onModelChange?: (modelId: string) => void;\n};\n\nexport type AgentChatRuntime = {\n agent: AgentChatRuntimeAgent;\n inputContract: ClientBootstrap[\"features\"][\"inputs\"] | null;\n allowFeedback: boolean;\n backgroundError: unknown;\n bootstrap: ClientBootstrap | null;\n capabilities: readonly string[];\n agentId: string | null;\n agents: AgentChatRuntimeAgentOption[];\n changeAgent(agentId: string): Promise<void>;\n changeModel(modelId: string): void;\n clearOperationError(): void;\n connectionState: AgentChatRuntimeConnectionState;\n contextWindow: ContextWindow | null;\n contextCompression: ContextCompression | null;\n controller: AgentChatController;\n deleteThread(threadId: string): Promise<void>;\n errorMessage: string | null;\n fatalError: unknown;\n getHitlActionState(part: ChatHitlPart): AgentChatRuntimeHitlActionState | undefined;\n isBootstrapping: boolean;\n isChangingAgent: boolean;\n isSubmitting: boolean;\n isUploading: boolean;\n modelId: string | null;\n models: AgentChatRuntimeModel[];\n newThread(): void;\n onHitlAction(part: ChatHitlPart, response: HitlResponse, options?: HitlSubmissionOptions): Promise<void>;\n openThread(threadId: string): Promise<void>;\n operationError: unknown;\n retryBootstrap(): Promise<void>;\n resolveAttachmentContent(\n attachment: ChatAttachment,\n signal: AbortSignal,\n ): Promise<{ url: string; validUntil: string | null }>;\n state: AgentChatRuntimeViewState;\n submit(input: AgentChatRuntimeSubmit): Promise<void>;\n};\n\ntype PendingThreadTransition = {\n reason: \"opened\" | \"deleted\";\n value: string | null;\n};\n\nexport function agentChatRuntimeStateFromError(error: unknown): AgentChatRuntimeViewState {\n const typed = error as Partial<Agents24ClientError> | null;\n if (typed?.kind === \"authentication\") return \"expired\";\n if (typed?.kind === \"authorization\") return \"denied\";\n if (typed?.kind === \"quota\" || typed?.kind === \"rate_limit\") return \"quota\";\n if (typed?.kind === \"network\") return \"offline\";\n return \"failed\";\n}\n\nexport function agentChatRuntimeErrorMessage(error: unknown): string | null {\n if (!error) return null;\n return error instanceof Error ? error.message : String(error);\n}\n\nexport function canChangeAgentRuntime(\n runState: AgentChatController[\"runState\"],\n activeRunId: string | null,\n): boolean {\n return !activeRunId && ![\"uploading\", \"streaming\", \"reconnecting\", \"paused\", \"cancelling\"].includes(runState);\n}\n\nexport function agentIdFromBootstrap(\n bootstrap: ClientBootstrap,\n requestedAgentId: string | null,\n): string | null {\n const feature = bootstrap.features.agents;\n if (!feature) return null;\n return feature.options.some((item) => item.id === requestedAgentId)\n ? requestedAgentId\n : feature.default_id || null;\n}\n\nexport function modelsFromAgentChatBootstrap(bootstrap: ClientBootstrap): {\n defaultModelId: string | null;\n models: AgentChatRuntimeModel[];\n} {\n const modelFeatures = bootstrap.features.models;\n const selectable = bootstrap.capabilities.includes(\"models.select\") && modelFeatures?.selectable === true;\n if (!selectable) return { defaultModelId: null, models: [] };\n const models = Array.isArray(modelFeatures.options)\n ? modelFeatures.options.flatMap((option) => (\n typeof option?.id === \"string\" && option.id.trim()\n ? [{ id: option.id, label: typeof option.label === \"string\" && option.label.trim() ? option.label : option.id }]\n : []\n ))\n : [];\n const configuredDefault = models.some((model) => model.id === modelFeatures.default_id)\n ? modelFeatures.default_id\n : null;\n return {\n defaultModelId: configuredDefault,\n models,\n };\n}\n\nfunction modelsFromEffectivePolicy(policy: EffectiveResourcePolicy): {\n defaultModelId: string | null;\n models: AgentChatRuntimeModel[];\n} {\n const models = policy.model_selection.selectable\n ? policy.model_selection.options.map((option) => ({ id: option.id, label: option.label }))\n : [];\n return {\n defaultModelId: models.some((model) => model.id === policy.model_selection.default_id)\n ? policy.model_selection.default_id\n : null,\n models,\n };\n}\n\nexport function useAgentChatRuntime(options: UseAgentChatRuntimeOptions): AgentChatRuntime {\n const {\n activeThreadId,\n agent: agentOverride,\n client,\n completeMcpAuthorization,\n mcpRedirectUri,\n modelId,\n onActiveThreadIdChange,\n onModelChange,\n } = options;\n const controller = useAgentChat(\n activeThreadId === undefined ? { client } : { activeThreadId, client },\n );\n const attachments = useAgentAttachments();\n const [bootstrap, setBootstrap] = React.useState<ClientBootstrap | null>(null);\n const bootstrapRef = React.useRef<ClientBootstrap | null>(bootstrap);\n bootstrapRef.current = bootstrap;\n const [effectivePolicy, setEffectivePolicy] = React.useState<EffectiveResourcePolicy | null>(null);\n const [isBootstrapping, setIsBootstrapping] = React.useState(true);\n const [bootstrapError, setBootstrapError] = React.useState<unknown>(null);\n const [localOperationError, setLocalOperationError] = React.useState<unknown>(null);\n const [selectedModelId, setSelectedModelId] = React.useState<string | null>(modelId ?? null);\n const selectedModelIdRef = React.useRef<string | null>(selectedModelId);\n selectedModelIdRef.current = selectedModelId;\n const [selectedAgentId, setSelectedAgentId] = React.useState<string | null>(null);\n const selectedAgentIdRef = React.useRef<string | null>(null);\n selectedAgentIdRef.current = selectedAgentId;\n const [isChangingAgent, setIsChangingAgent] = React.useState(false);\n const agentChangePromiseRef = React.useRef<Promise<void> | null>(null);\n const [isSubmitting, setIsSubmitting] = React.useState(false);\n const submitPromiseRef = React.useRef<Promise<void> | null>(null);\n\n const mountedRef = React.useRef(true);\n const clientRef = React.useRef(client);\n clientRef.current = client;\n const bootstrapPromiseRef = React.useRef<{ client: AgentClient; promise: Promise<void> } | null>(null);\n React.useEffect(() => {\n mountedRef.current = true;\n return () => { mountedRef.current = false; };\n }, []);\n\n const previousControlledThreadRef = React.useRef(activeThreadId);\n const threadSelectionGenerationRef = React.useRef(0);\n const controlledSyncTargetRef = React.useRef<{ value: string | null } | null>(null);\n const previousControllerThreadRef = React.useRef(controller.activeThreadId);\n const pendingThreadTransitionRef = React.useRef<PendingThreadTransition | null>(null);\n const lastReportedThreadRef = React.useRef<string | null>(activeThreadId ?? controller.activeThreadId);\n if (activeThreadId !== previousControlledThreadRef.current) {\n threadSelectionGenerationRef.current += 1;\n previousControlledThreadRef.current = activeThreadId;\n if (activeThreadId !== undefined) {\n controlledSyncTargetRef.current = { value: activeThreadId };\n lastReportedThreadRef.current = activeThreadId;\n }\n }\n\n const reportActiveThread = React.useCallback((\n threadId: string | null,\n reason: AgentChatThreadChangeReason,\n ) => {\n if (lastReportedThreadRef.current === threadId) return;\n lastReportedThreadRef.current = threadId;\n onActiveThreadIdChange?.({ threadId, reason });\n }, [onActiveThreadIdChange]);\n\n const retryBootstrap = React.useCallback((): Promise<void> => {\n if (bootstrapPromiseRef.current?.client === client) return bootstrapPromiseRef.current.promise;\n const requestClient = client;\n const request = (async () => {\n if (mountedRef.current) {\n setIsBootstrapping(true);\n setBootstrapError(null);\n setBootstrap(null);\n setEffectivePolicy(null);\n }\n try {\n const requestedAgentId = selectedAgentIdRef.current;\n const result = await requestClient.bootstrap({ agentId: requestedAgentId || undefined });\n if (!mountedRef.current || clientRef.current !== requestClient) return;\n setBootstrap(result);\n const agentFeature = result.features.agents;\n const resolvedAgentId = agentIdFromBootstrap(result, requestedAgentId);\n setSelectedAgentId(resolvedAgentId);\n const entitlement = agentFeature ? null : await requestClient.resourcePolicies.getEffective();\n if (!mountedRef.current || clientRef.current !== requestClient) return;\n setEffectivePolicy(entitlement);\n const availableModels = entitlement ? modelsFromEffectivePolicy(entitlement) : modelsFromAgentChatBootstrap(result);\n if (modelId === undefined) {\n setSelectedModelId((current) => availableModels.models.some((item) => item.id === current)\n ? current\n : availableModels.defaultModelId);\n }\n await controller.refreshThreads().catch(() => undefined);\n } catch (error) {\n if (mountedRef.current && clientRef.current === requestClient) setBootstrapError(error);\n } finally {\n if (mountedRef.current && clientRef.current === requestClient) setIsBootstrapping(false);\n }\n })();\n bootstrapPromiseRef.current = { client: requestClient, promise: request };\n void request.finally(() => {\n if (bootstrapPromiseRef.current?.promise === request) bootstrapPromiseRef.current = null;\n });\n return request;\n }, [client, controller.refreshThreads, modelId]);\n\n const refreshEffectivePolicy = React.useCallback(async () => {\n if (bootstrap?.features.agents) {\n const refreshed = await client.bootstrap({ agentId: selectedAgentIdRef.current || undefined });\n if (!mountedRef.current || clientRef.current !== client) return;\n setBootstrap(refreshed);\n const available = modelsFromAgentChatBootstrap(refreshed);\n setSelectedModelId((current) => available.models.some((item) => item.id === current)\n ? current\n : available.defaultModelId);\n return;\n }\n const entitlement = await client.resourcePolicies.getEffective();\n if (!mountedRef.current || clientRef.current !== client) return;\n setEffectivePolicy(entitlement);\n if (modelId === undefined) {\n const available = modelsFromEffectivePolicy(entitlement);\n setSelectedModelId((current) => available.models.some((item) => item.id === current)\n ? current\n : available.defaultModelId);\n }\n }, [bootstrap, client, modelId]);\n\n React.useEffect(() => {\n void retryBootstrap();\n }, [retryBootstrap]);\n\n React.useEffect(() => {\n if (modelId !== undefined) setSelectedModelId(modelId);\n }, [modelId]);\n\n React.useEffect(() => {\n if (controlledSyncTargetRef.current?.value === null && controller.activeThreadId) {\n controller.startNewThread();\n }\n }, [activeThreadId, controller.activeThreadId, controller.startNewThread]);\n\n React.useEffect(() => {\n const previous = previousControllerThreadRef.current;\n const current = controller.activeThreadId;\n previousControllerThreadRef.current = current;\n const controlledTarget = controlledSyncTargetRef.current;\n if (controlledTarget) {\n if (current === controlledTarget.value) controlledSyncTargetRef.current = null;\n return;\n }\n const pendingTransition = pendingThreadTransitionRef.current;\n if (pendingTransition && current === pendingTransition.value) return;\n if (previous === null && current !== null) reportActiveThread(current, \"created\");\n }, [activeThreadId, controller.activeThreadId, reportActiveThread]);\n\n const clearOperationError = React.useCallback(() => {\n setLocalOperationError(null);\n controller.clearOperationError();\n }, [controller.clearOperationError]);\n\n const submit = React.useCallback((input: AgentChatRuntimeSubmit): Promise<void> => {\n if (submitPromiseRef.current) return submitPromiseRef.current;\n clearOperationError();\n setIsSubmitting(true);\n const request = (async () => {\n try {\n await agentChangePromiseRef.current;\n const activeBootstrap = bootstrapRef.current;\n if (!activeBootstrap) throw new Error(\"The agent input contract is unavailable.\");\n const retained = (input.attachments || []).filter((attachment) => input.attachmentIds?.includes(attachment.id || \"\"));\n const inputError = validateAgentChatSubmission(activeBootstrap.features.inputs, input.text, [\n ...(input.files || []),\n ...retained.map((attachment) => ({ data: new Uint8Array(), mediaType: attachment.mediaType || \"application/octet-stream\" })),\n ]);\n if (inputError) throw new Error(inputError);\n await controller.submit({\n text: input.text,\n attachments: input.attachments,\n uploads: input.files,\n attachmentIds: input.attachmentIds,\n requestedModelId: selectedModelIdRef.current || undefined,\n requestedAgentId: selectedAgentIdRef.current || undefined,\n });\n } catch (error) {\n setLocalOperationError(error);\n const typed = error as Partial<Agents24ClientError>;\n if (typed.kind === \"quota\" || typed.kind === \"authorization\") {\n await refreshEffectivePolicy().catch(() => undefined);\n }\n throw error;\n } finally {\n setIsSubmitting(false);\n }\n })();\n submitPromiseRef.current = request;\n const clearRequest = () => {\n if (submitPromiseRef.current === request) submitPromiseRef.current = null;\n };\n void request.then(clearRequest, clearRequest);\n return request;\n }, [bootstrap, clearOperationError, controller.activeThreadId, controller.submit, refreshEffectivePolicy]);\n\n const { onHitlAction, getHitlActionState } = useAgentChatHitl({\n client, bootstrap, controller, selectionGeneration: threadSelectionGenerationRef,\n completeMcpAuthorization, mcpRedirectUri, clearOperationError, onError: setLocalOperationError,\n });\n\n const newThread = React.useCallback(() => {\n threadSelectionGenerationRef.current += 1;\n clearOperationError();\n pendingThreadTransitionRef.current = null;\n reportActiveThread(null, \"new\");\n controller.startNewThread();\n }, [clearOperationError, controller.startNewThread, reportActiveThread]);\n\n const openThread = React.useCallback(async (threadId: string) => {\n const requestGeneration = ++threadSelectionGenerationRef.current;\n clearOperationError();\n pendingThreadTransitionRef.current = { reason: \"opened\", value: threadId };\n try {\n const detail = await client.threads.get({ threadId });\n if (requestGeneration !== threadSelectionGenerationRef.current) return;\n const preferredAgentId = detail.runtime_selection?.agent_alias || detail.runtime_selection?.agent_id || null;\n if (preferredAgentId) {\n const result = await client.bootstrap({ agentId: preferredAgentId });\n if (requestGeneration !== threadSelectionGenerationRef.current) return;\n const resolvedAgentId = agentIdFromBootstrap(result, preferredAgentId);\n setBootstrap(result);\n setEffectivePolicy(null);\n setSelectedAgentId(resolvedAgentId);\n const available = modelsFromAgentChatBootstrap(result);\n const preferredModelId = detail.runtime_selection?.model_id || null;\n setSelectedModelId(available.models.some((item) => item.id === preferredModelId)\n ? preferredModelId\n : available.defaultModelId);\n }\n await controller.openThread(threadId);\n if (requestGeneration !== threadSelectionGenerationRef.current) return;\n reportActiveThread(threadId, \"opened\");\n } catch (error) {\n if (requestGeneration !== threadSelectionGenerationRef.current) return;\n setLocalOperationError(error);\n throw error;\n } finally {\n if (requestGeneration === threadSelectionGenerationRef.current) pendingThreadTransitionRef.current = null;\n }\n }, [clearOperationError, client, controller.openThread, reportActiveThread]);\n\n const deleteThread = React.useCallback(async (threadId: string) => {\n clearOperationError();\n const wasActive = controller.activeThreadId === threadId;\n if (wasActive) threadSelectionGenerationRef.current += 1;\n if (wasActive) pendingThreadTransitionRef.current = { reason: \"deleted\", value: null };\n try {\n await controller.deleteThread(threadId);\n if (wasActive) reportActiveThread(null, \"deleted\");\n } catch (error) {\n setLocalOperationError(error);\n throw error;\n } finally {\n if (wasActive && pendingThreadTransitionRef.current?.reason === \"deleted\") {\n pendingThreadTransitionRef.current = null;\n }\n }\n }, [clearOperationError, controller.activeThreadId, controller.deleteThread, reportActiveThread]);\n\n const changeModel = React.useCallback((nextModelId: string) => {\n if (modelId === undefined) setSelectedModelId(nextModelId);\n onModelChange?.(nextModelId);\n if (controller.activeThreadId && selectedAgentId && client.threads.setRuntimeSelection) {\n void client.threads.setRuntimeSelection({\n threadId: controller.activeThreadId,\n preferredAgentId: selectedAgentId,\n preferredModelId: nextModelId,\n }).catch(setLocalOperationError);\n }\n }, [client.threads, controller.activeThreadId, modelId, onModelChange, selectedAgentId]);\n\n const resolveAttachmentContent = React.useCallback(async (\n attachment: ChatAttachment,\n signal: AbortSignal,\n ) => {\n const attachmentId = typeof attachment.id === \"string\" ? attachment.id.trim() : \"\";\n if (!attachmentId) throw new Error(\"Attachment content identity is unavailable.\");\n const access = await attachments.createContentAccess({\n attachmentId,\n disposition: \"inline\",\n signal,\n });\n return { url: access.url, validUntil: access.valid_until || null };\n }, [attachments.createContentAccess]);\n\n const changeAgent = React.useCallback((nextAgentId: string): Promise<void> => {\n if (agentChangePromiseRef.current) return agentChangePromiseRef.current;\n if (\n nextAgentId === selectedAgentIdRef.current\n || !canChangeAgentRuntime(controller.runState, controller.activeRunId)\n ) return Promise.resolve();\n clearOperationError();\n setIsChangingAgent(true);\n const request = (async () => {\n try {\n const result = await client.bootstrap({ agentId: nextAgentId });\n const resolvedAgentId = agentIdFromBootstrap(result, nextAgentId);\n if (!resolvedAgentId) throw new Error(\"The requested Agent is no longer available.\");\n const available = modelsFromAgentChatBootstrap(result);\n const currentModelId = selectedModelIdRef.current;\n const nextModelId = available.models.some((item) => item.id === currentModelId)\n ? currentModelId\n : available.defaultModelId;\n if (controller.activeThreadId && client.threads.setRuntimeSelection) {\n const persisted = await client.threads.setRuntimeSelection({\n threadId: controller.activeThreadId,\n preferredAgentId: resolvedAgentId,\n preferredModelId: nextModelId,\n });\n selectedModelIdRef.current = persisted.runtime_selection.model_id;\n setSelectedModelId(persisted.runtime_selection.model_id);\n } else {\n selectedModelIdRef.current = nextModelId;\n setSelectedModelId(nextModelId);\n }\n selectedAgentIdRef.current = resolvedAgentId;\n bootstrapRef.current = result;\n setSelectedAgentId(resolvedAgentId);\n setBootstrap(result);\n setEffectivePolicy(null);\n } catch (error) {\n setLocalOperationError(error);\n throw error;\n }\n })();\n agentChangePromiseRef.current = request;\n const clearRequest = () => {\n if (agentChangePromiseRef.current === request) agentChangePromiseRef.current = null;\n if (mountedRef.current) setIsChangingAgent(false);\n };\n void request.then(clearRequest, clearRequest);\n return request;\n }, [clearOperationError, client, controller.activeRunId, controller.activeThreadId, controller.runState]);\n\n const modelOptions = effectivePolicy\n ? modelsFromEffectivePolicy(effectivePolicy).models\n : bootstrap\n ? modelsFromAgentChatBootstrap(bootstrap).models\n : [];\n const fatalError = bootstrapError || controller.error;\n const operationError = localOperationError || controller.operationError?.cause;\n const state: AgentChatRuntimeViewState = isBootstrapping\n ? \"loading\"\n : fatalError\n ? agentChatRuntimeStateFromError(fatalError)\n : controller.runState === \"uploading\"\n ? \"uploading\"\n : controller.runState === \"streaming\"\n ? \"streaming\"\n : controller.runState === \"reconnecting\"\n ? \"reconnecting\"\n : controller.runState === \"paused\"\n ? \"paused\"\n : controller.runState === \"cancelling\"\n ? \"cancelling\"\n : controller.runState === \"cancelled\"\n ? \"cancelled\"\n : \"ready\";\n const connectionState: AgentChatRuntimeConnectionState = state === \"offline\"\n ? \"offline\"\n : state === \"expired\"\n ? \"expired\"\n : state === \"reconnecting\"\n ? \"reconnecting\"\n : isBootstrapping\n ? \"connecting\"\n : \"connected\";\n return {\n agent: agentOverride || { name: bootstrap?.deployment.name || \"Agent\" },\n inputContract: bootstrap?.features.inputs || null,\n allowFeedback: Boolean(bootstrap?.capabilities.includes(\"feedback.write\")),\n backgroundError: controller.backgroundError?.cause || null,\n bootstrap,\n capabilities: bootstrap?.capabilities || [],\n agentId: selectedAgentId,\n agents: bootstrap?.features.agents?.options.map((item) => ({ id: item.id, label: item.label })) || [],\n changeAgent,\n changeModel,\n clearOperationError,\n connectionState,\n contextWindow: controller.contextWindow,\n contextCompression: controller.contextCompression,\n controller,\n deleteThread,\n errorMessage: agentChatRuntimeErrorMessage(fatalError || operationError),\n fatalError,\n getHitlActionState,\n isBootstrapping,\n isChangingAgent,\n isSubmitting: isSubmitting || controller.isSubmitting,\n isUploading: attachments.isUploading || controller.runState === \"uploading\",\n modelId: selectedModelId,\n models: modelOptions,\n newThread,\n onHitlAction,\n openThread,\n operationError,\n retryBootstrap,\n resolveAttachmentContent,\n state,\n submit,\n };\n}\n","import type { AgentClient, ClientBootstrap, HitlResponse } from \"@agents24/client\";\nimport { type AgentChatController, type ChatHitlPart, type HitlSubmissionOptions, useAgentMcp } from \"@agents24/react\";\nimport * as React from \"react\";\nimport { browserChatCrypto, createMcpPkceProof, validateMcpCallbackResult, waitForMcpOauthComplete } from \"../mcp-oauth\";\nimport type { AgentChatMcpAuthorizationCompletion, AgentChatRuntimeHitlActionState } from \"./use-agent-chat-runtime\";\n\ntype HitlOptions = {\n client: AgentClient;\n bootstrap: ClientBootstrap | null;\n controller: AgentChatController;\n selectionGeneration: React.MutableRefObject<number>;\n completeMcpAuthorization?: AgentChatMcpAuthorizationCompletion;\n mcpRedirectUri?: string;\n clearOperationError(): void;\n onError(error: unknown): void;\n};\n\ntype HitlOperation = {\n abort: AbortController;\n isCurrent(): boolean;\n phase: \"connecting\" | \"resuming\";\n popup?: Window;\n};\n\nfunction detach(operation: HitlOperation) {\n operation.abort.abort();\n operation.popup?.close();\n}\n\nexport function useAgentChatHitl(options: HitlOptions) {\n const mcp = useAgentMcp();\n const latest = React.useRef(options);\n latest.current = options;\n const mounted = React.useRef(true);\n const operations = React.useRef(new Map<string, HitlOperation>());\n const [states, setStates] = React.useState<Record<string, AgentChatRuntimeHitlActionState>>({});\n\n React.useEffect(() => {\n mounted.current = true;\n const active = operations.current;\n return () => {\n mounted.current = false;\n for (const operation of active.values()) detach(operation);\n active.clear();\n };\n }, []);\n React.useEffect(() => {\n for (const [key, operation] of operations.current) {\n if (operation.isCurrent()) continue;\n detach(operation);\n operations.current.delete(key);\n setStates((current) => {\n const next = { ...current };\n delete next[key];\n return next;\n });\n }\n });\n React.useEffect(() => { setStates({}); }, [options.client, options.controller.activeThreadId]);\n\n const onHitlAction = React.useCallback(async (part: ChatHitlPart, response: HitlResponse, submission?: HitlSubmissionOptions) => {\n const captured = latest.current;\n const { controller, client, bootstrap, selectionGeneration } = captured;\n const generation = selectionGeneration.current;\n const threadId = controller.activeThreadId;\n const runId = part.runId || controller.messages.find((message) => message.parts.some(candidate => candidate.id === part.id))?.runId || controller.activeRunId;\n const key = `${generation}:${threadId}:${runId}:${part.interruptId || part.id}`;\n if (part.hitlKind !== \"mcp_auth\" || response.action !== \"connect\") {\n captured.clearOperationError();\n // All normal decisions, including host preparation, have one headless owner.\n return controller.resumeHitl(part, response, submission).catch(error => {\n const current = latest.current;\n if (mounted.current && current.client === client && current.selectionGeneration.current === generation\n && current.controller.activeThreadId === threadId) captured.onError(error);\n throw error;\n });\n }\n const previous = operations.current.get(key);\n if (previous?.isCurrent()) return;\n if (previous) { detach(previous); operations.current.delete(key); }\n const operation: HitlOperation = {\n abort: new AbortController(),\n phase: part.hitlKind === \"mcp_auth\" && response.action === \"connect\" ? \"connecting\" : \"resuming\",\n isCurrent() {\n const current = latest.current;\n return mounted.current && !operation.abort.signal.aborted\n && current.client === client && current.selectionGeneration.current === generation\n && current.controller.activeThreadId === threadId\n && (!current.controller.activeRunId || current.controller.activeRunId === runId)\n && ![\"cancelling\", \"cancelled\", \"failed\", \"completed\"].includes(current.controller.runState)\n && (operation.phase === \"resuming\" || current.controller.messages.some((message) =>\n message.runId === runId && message.parts.some((candidate) => candidate.type === \"hitl\"\n && candidate.interruptId === part.interruptId && candidate.status === \"pending\")));\n },\n };\n if (!operation.isCurrent()) return;\n captured.clearOperationError();\n operations.current.set(key, operation);\n setStates((current) => ({ ...current, [key]: { action: response.action, status: operation.phase } }));\n try {\n if (operation.phase === \"connecting\") {\n if (!runId) throw new Error(\"MCP authorization is missing its paused run.\");\n if (!bootstrap) throw new Error(\"MCP authorization requires runtime bootstrap.\");\n if (!captured.mcpRedirectUri) throw new Error(\"mcpRedirectUri is required for MCP Connect.\");\n const serverId = String(part.presentation.server_id || \"\").trim();\n if (!serverId) throw new Error(\"MCP authorization is missing its server identity.\");\n const serverEmbed = bootstrap.authentication.modes.includes(\"server_embed\");\n const popupNonce = browserChatCrypto().randomUUID();\n // Open within the click before awaiting crypto or the network.\n const popup = window.open(\"about:blank\", \"agents24-mcp\", \"popup,width=560,height=720\");\n if (!popup) throw new Error(\"Allow popups to connect this MCP account.\");\n operation.popup = popup;\n popup.document.title = \"Connecting to MCP\";\n popup.document.body.textContent = \"Opening secure connection…\";\n const proof = await createMcpPkceProof();\n if (!operation.isCurrent()) return;\n const started = await mcp.startAuthorization({\n runId, serverId, interruptId: part.interruptId, redirectUri: captured.mcpRedirectUri,\n popupNonce, codeChallenge: proof.challenge, signal: operation.abort.signal,\n });\n if (!operation.isCurrent()) return;\n if (!started.callback_origin) throw new Error(\"MCP authorization did not return a callback origin.\");\n const completionPromise = waitForMcpOauthComplete({\n popup, callbackOrigin: started.callback_origin, popupNonce, serverId,\n runId, interruptId: part.interruptId, signal: operation.abort.signal,\n requireConnectionId: serverEmbed || Boolean(captured.completeMcpAuthorization),\n });\n // Ensure a navigation exception cannot leave a rejected waiter unobserved.\n void completionPromise.catch(() => undefined);\n popup.location.replace(started.authorization_url);\n const completion = await completionPromise;\n if (!operation.isCurrent()) return;\n if (captured.completeMcpAuthorization) {\n await captured.completeMcpAuthorization({ completion, codeVerifier: proof.verifier, serverId });\n } else if (serverEmbed) {\n validateMcpCallbackResult({ server_id: completion.serverId, connection_id: completion.connectionId || \"\" }, serverId);\n } else {\n const redeemed = await mcp.redeemCallback({\n code: completion.code, codeVerifier: proof.verifier, signal: operation.abort.signal,\n });\n if (!operation.isCurrent()) return;\n validateMcpCallbackResult(redeemed, serverId);\n }\n popup.close();\n }\n if (!operation.isCurrent()) return;\n operation.phase = \"resuming\";\n setStates((current) => ({ ...current, [key]: { action: response.action, status: \"resuming\" } }));\n await controller.resumeHitl(part, response, submission);\n } catch (error) {\n if (!operation.isCurrent()) return;\n captured.onError(error);\n setStates((current) => ({ ...current, [key]: {\n action: response.action, status: \"error\", error: error instanceof Error ? error.message : String(error),\n } }));\n throw error;\n } finally {\n const ownsState = operation.isCurrent();\n // Abort the waiter and any in-flight transport, and always release the popup.\n detach(operation);\n if (operations.current.get(key) === operation) {\n operations.current.delete(key);\n if (ownsState) setStates((current) => {\n if (current[key]?.status === \"error\") return current;\n const next = { ...current };\n delete next[key];\n return next;\n });\n }\n }\n }, [mcp]);\n\n return { onHitlAction, getHitlActionState: (part: ChatHitlPart) => {\n const { controller, selectionGeneration } = latest.current;\n const runId = part.runId || controller.messages.find(message => message.parts.some(candidate => candidate.id === part.id))?.runId || controller.activeRunId;\n return controller.getHitlSubmissionState(part)\n || states[`${selectionGeneration.current}:${controller.activeThreadId}:${runId}:${part.interruptId || part.id}`];\n } };\n}\n","import * as React from \"react\";\nimport type { DelegationEvents, DelegationTask } from \"../generated/delegation-types\";\n\nexport type DelegationTaskSource = {\n events(input: { threadId: string; after: number; signal: AbortSignal }): Promise<DelegationEvents>;\n};\n\n/** Authoritative snapshots keep task discovery alive after the run stream ends. */\nexport function useDelegationTasks({ threadId, source, pollIntervalMs = 2000 }: {\n threadId: string | null;\n source: DelegationTaskSource;\n pollIntervalMs?: number;\n}) {\n const [state, setState] = React.useState<{\n threadId: string | null; tasks: DelegationTask[]; error: unknown; loading: boolean;\n }>({ threadId: null, tasks: [], error: null, loading: false });\n const [revision, refresh] = React.useReducer((value: number) => value + 1, 0);\n React.useEffect(() => {\n if (!threadId) {\n setState({ threadId: null, tasks: [], error: null, loading: false });\n return;\n }\n const controller = new AbortController();\n let cursor = 0;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let failures = 0;\n setState((previous) => ({ threadId, tasks: previous.threadId === threadId ? previous.tasks : [],\n error: null, loading: true }));\n const poll = async () => {\n try {\n const result = await source.events({ threadId, after: cursor, signal: controller.signal });\n if (controller.signal.aborted) return;\n cursor = result.cursor;\n failures = 0;\n setState({ threadId, tasks: result.snapshot, error: null, loading: false });\n } catch (error) {\n if (controller.signal.aborted) return;\n failures += 1;\n setState((previous) => ({ ...previous, error, loading: false }));\n }\n if (!controller.signal.aborted) {\n timer = setTimeout(poll, Math.min(30000, Math.max(250, pollIntervalMs) * 2 ** Math.min(failures, 4)));\n }\n };\n void poll();\n return () => {\n controller.abort();\n if (timer) clearTimeout(timer);\n };\n }, [threadId, source, pollIntervalMs, revision]);\n return { tasks: state.threadId === threadId ? state.tasks : [],\n error: state.threadId === threadId ? state.error : null,\n loading: Boolean(threadId) && (state.threadId !== threadId || state.loading), refresh };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AASA;AAAA,EAME;AAAA,EACA;AAAA,OACK;AACP,YAAYA,YAAW;;;ACjBvB,SAAkF,mBAAmB;AACrG,YAAY,WAAW;AAsBvB,SAAS,OAAO,WAA0B;AACxC,YAAU,MAAM,MAAM;AACtB,YAAU,OAAO,MAAM;AACzB;AAEO,SAAS,iBAAiB,SAAsB;AACrD,QAAM,MAAM,YAAY;AACxB,QAAM,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C,UAAU,QAAQ,gBAAgB,QAAQ,CAAC;AAC/C,SAAO;AAAA,IAAE,OAAO,MAAM,aAAa,WAAW,MAAM,QAAQ,CAAC;AAAA,IAC3D,OAAO,MAAM,aAAa,WAAW,MAAM,QAAQ;AAAA,IACnD,SAAS,QAAQ,QAAQ,MAAM,MAAM,aAAa,YAAY,MAAM;AAAA,IAAU;AAAA,EAAQ;AAC1F;","names":["React","React"]}
|
|
@@ -2,7 +2,7 @@ import { normalizeAttachmentMimeType, type ClientInputFeature, type PortableUplo
|
|
|
2
2
|
export { attachmentFileAccept, normalizeAttachmentMimeType } from "@agents24/client";
|
|
3
3
|
export type AgentChatInputContract = ClientInputFeature;
|
|
4
4
|
export declare const SUPPORTED_INPUT_MIME_TYPES: {
|
|
5
|
-
readonly files: readonly ["application/pdf", "text/plain", "text/markdown", "text/csv", "application/json"];
|
|
5
|
+
readonly files: readonly ["application/pdf", "text/plain", "text/markdown", "text/csv", "application/json", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"];
|
|
6
6
|
readonly images: readonly ["image/png", "image/jpeg", "image/webp"];
|
|
7
7
|
readonly audio: readonly ["audio/wav", "audio/mpeg", "audio/webm", "audio/mp4"];
|
|
8
8
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentClient, ClientBootstrap, HitlResponse } from "@agents24/client";
|
|
2
|
-
import { type AgentChatController, type ChatHitlPart } from "@agents24/react";
|
|
2
|
+
import { type AgentChatController, type ChatHitlPart, type HitlSubmissionOptions } from "@agents24/react";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import type { AgentChatMcpAuthorizationCompletion, AgentChatRuntimeHitlActionState } from "./use-agent-chat-runtime";
|
|
5
5
|
type HitlOptions = {
|
|
@@ -13,7 +13,7 @@ type HitlOptions = {
|
|
|
13
13
|
onError(error: unknown): void;
|
|
14
14
|
};
|
|
15
15
|
export declare function useAgentChatHitl(options: HitlOptions): {
|
|
16
|
-
onHitlAction: (part: ChatHitlPart, response: HitlResponse) => Promise<void>;
|
|
16
|
+
onHitlAction: (part: ChatHitlPart, response: HitlResponse, submission?: HitlSubmissionOptions) => Promise<void>;
|
|
17
17
|
getHitlActionState: (part: ChatHitlPart) => AgentChatRuntimeHitlActionState;
|
|
18
18
|
};
|
|
19
19
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentClient, ClientBootstrap, HitlResponse, PortableUpload } from "@agents24/client";
|
|
2
2
|
import type { ContextCompression, ContextWindow } from "@agents24/client/protocol";
|
|
3
|
-
import { type AgentChatController, type ChatAttachment, type ChatHitlPart } from "@agents24/react";
|
|
3
|
+
import { type AgentChatController, type ChatAttachment, type ChatHitlPart, type HitlSubmissionOptions, type HitlSubmissionState } from "@agents24/react";
|
|
4
4
|
import type { ChatMcpOauthCompletion } from "../types";
|
|
5
5
|
export type AgentChatRuntimeAgent = {
|
|
6
6
|
name: string;
|
|
@@ -35,10 +35,8 @@ export type AgentChatRuntimeSubmit = {
|
|
|
35
35
|
attachments?: ChatAttachment[];
|
|
36
36
|
attachmentIds?: readonly string[];
|
|
37
37
|
};
|
|
38
|
-
export type AgentChatRuntimeHitlActionState = {
|
|
39
|
-
|
|
40
|
-
error?: string | null;
|
|
41
|
-
status: "connecting" | "resuming" | "error";
|
|
38
|
+
export type AgentChatRuntimeHitlActionState = Omit<HitlSubmissionState, "status"> & {
|
|
39
|
+
status: HitlSubmissionState["status"] | "connecting" | "resuming";
|
|
42
40
|
};
|
|
43
41
|
export type UseAgentChatRuntimeOptions = {
|
|
44
42
|
activeThreadId?: string | null;
|
|
@@ -77,7 +75,7 @@ export type AgentChatRuntime = {
|
|
|
77
75
|
modelId: string | null;
|
|
78
76
|
models: AgentChatRuntimeModel[];
|
|
79
77
|
newThread(): void;
|
|
80
|
-
onHitlAction(part: ChatHitlPart, response: HitlResponse): Promise<void>;
|
|
78
|
+
onHitlAction(part: ChatHitlPart, response: HitlResponse, options?: HitlSubmissionOptions): Promise<void>;
|
|
81
79
|
openThread(threadId: string): Promise<void>;
|
|
82
80
|
operationError: unknown;
|
|
83
81
|
retryBootstrap(): Promise<void>;
|
package/dist/scaffold/app.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentClient, HitlResponse } from "@agents24/client";
|
|
2
2
|
import { type AgentChatActiveThreadChangeHandler, type AgentChatMcpAuthorizationCompletion, type AgentChatRuntimeAgent } from "@agents24/chat-react/runtime";
|
|
3
3
|
import type { HitlActionState } from "@agents24/chat-react/ui";
|
|
4
|
-
import { type ChatHitlPart, type ChatMessage, type ChatPart } from "@agents24/react";
|
|
4
|
+
import { type ChatHitlPart, type HitlSubmissionOptions, type ChatMessage, type ChatPart } from "@agents24/react";
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import type { Agents24ChatComposerProps } from "./components/chat/chat-composer";
|
|
7
7
|
import { type Agents24ChatIdentity } from "./identity";
|
|
@@ -29,6 +29,6 @@ export type Agents24ChatTimelineSlotProps = {
|
|
|
29
29
|
parts: readonly ChatPart[];
|
|
30
30
|
isLoading: boolean;
|
|
31
31
|
getHitlActionState: (part: ChatHitlPart) => HitlActionState | undefined;
|
|
32
|
-
onHitlAction: (part: ChatHitlPart, response: ChatHitlResponse) => void;
|
|
32
|
+
onHitlAction: (part: ChatHitlPart, response: ChatHitlResponse, options?: HitlSubmissionOptions) => void;
|
|
33
33
|
};
|
|
34
34
|
export declare function App(props: Agents24ChatAppProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -8,6 +8,7 @@ export type Agents24ChatComposerProps = {
|
|
|
8
8
|
inputContract: AgentChatInputContract;
|
|
9
9
|
disabled?: boolean;
|
|
10
10
|
contextWindow?: ContextWindow | null;
|
|
11
|
+
scopeKey?: string | null;
|
|
11
12
|
focusKey?: string | null;
|
|
12
13
|
forceExpanded?: boolean;
|
|
13
14
|
isCancelling?: boolean;
|
|
@@ -33,4 +34,4 @@ export type Agents24ChatComposerProps = {
|
|
|
33
34
|
} | null;
|
|
34
35
|
utilityRow?: "inline" | "below";
|
|
35
36
|
};
|
|
36
|
-
export declare function ChatComposer({ inputContract, queue, onRecordingStreamChange, disabled, contextWindow, focusKey, forceExpanded, isCancelling, isRunning, agentId, agents, modelId, models, onModelChange, onAgentChange, onStop, onSubmit, restoredDraft, utilityRow, }: Agents24ChatComposerProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export declare function ChatComposer({ inputContract, queue, onRecordingStreamChange, disabled, contextWindow, focusKey, scopeKey, forceExpanded, isCancelling, isRunning, agentId, agents, modelId, models, onModelChange, onAgentChange, onStop, onSubmit, restoredDraft, utilityRow, }: Agents24ChatComposerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatHitlPart, ChatMessage as ChatMessageModel } from "@agents24/react";
|
|
1
|
+
import type { ChatHitlPart, HitlSubmissionOptions, ChatMessage as ChatMessageModel } from "@agents24/react";
|
|
2
2
|
import type { FeedbackReason, HitlResponse } from "@agents24/client";
|
|
3
3
|
import type { AgentChatRuntimeHitlActionState } from "@agents24/chat-react/runtime";
|
|
4
4
|
import { type ChatAttachmentContentResolver } from "@agents24/chat-react/ui";
|
|
@@ -9,7 +9,7 @@ type Props = {
|
|
|
9
9
|
message: ChatMessageModel;
|
|
10
10
|
getHitlActionState: (part: ChatHitlPart) => AgentChatRuntimeHitlActionState | undefined;
|
|
11
11
|
isLoading: boolean;
|
|
12
|
-
onHitlAction: (part: ChatHitlPart, response: HitlResponse) => Promise<void>;
|
|
12
|
+
onHitlAction: (part: ChatHitlPart, response: HitlResponse, options?: HitlSubmissionOptions) => Promise<void>;
|
|
13
13
|
onRegenerate: () => Promise<void>;
|
|
14
14
|
allowFeedback: boolean;
|
|
15
15
|
onSetFeedback: (input: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatHitlPart, ChatMessage } from "@agents24/react";
|
|
1
|
+
import type { ChatHitlPart, HitlSubmissionOptions, ChatMessage } from "@agents24/react";
|
|
2
2
|
import type { HitlResponse } from "@agents24/client";
|
|
3
3
|
import type { AgentChatRuntimeHitlActionState } from "@agents24/chat-react/runtime";
|
|
4
4
|
import * as React from "react";
|
|
@@ -7,6 +7,6 @@ export declare function MessageParts({ message, getHitlActionState, isLoading, o
|
|
|
7
7
|
message: ChatMessage;
|
|
8
8
|
getHitlActionState: (part: ChatHitlPart) => AgentChatRuntimeHitlActionState | undefined;
|
|
9
9
|
isLoading: boolean;
|
|
10
|
-
onHitlAction: (part: ChatHitlPart, response: HitlResponse) => Promise<void>;
|
|
10
|
+
onHitlAction: (part: ChatHitlPart, response: HitlResponse, options?: HitlSubmissionOptions) => Promise<void>;
|
|
11
11
|
Timeline?: React.ComponentType<Agents24ChatTimelineSlotProps>;
|
|
12
12
|
}): import("react/jsx-runtime").JSX.Element;
|
package/dist/scaffold/index.cjs
CHANGED
|
@@ -41,11 +41,11 @@ module.exports = __toCommonJS(src_exports);
|
|
|
41
41
|
|
|
42
42
|
// scaffold/src/app.tsx
|
|
43
43
|
var import_browser = require("@agents24/client/browser");
|
|
44
|
-
var
|
|
44
|
+
var import_runtime4 = require("@agents24/chat-react/runtime");
|
|
45
45
|
var import_react3 = require("@agents24/react");
|
|
46
46
|
|
|
47
47
|
// scaffold/src/components/chat/chat-shell.tsx
|
|
48
|
-
var
|
|
48
|
+
var import_runtime3 = require("@agents24/chat-react/runtime");
|
|
49
49
|
var import_ui5 = require("@agents24/chat-react/ui");
|
|
50
50
|
var import_lucide_react11 = require("lucide-react");
|
|
51
51
|
var React9 = __toESM(require("react"), 1);
|
|
@@ -54,6 +54,7 @@ var React9 = __toESM(require("react"), 1);
|
|
|
54
54
|
var import_lucide_react3 = require("lucide-react");
|
|
55
55
|
var React2 = __toESM(require("react"), 1);
|
|
56
56
|
var import_ui = require("@agents24/chat-react/ui");
|
|
57
|
+
var import_runtime = require("@agents24/chat-react/runtime");
|
|
57
58
|
|
|
58
59
|
// scaffold/src/components/ui/button.tsx
|
|
59
60
|
var import_class_variance_authority = require("class-variance-authority");
|
|
@@ -520,6 +521,7 @@ function ChatComposer({
|
|
|
520
521
|
disabled,
|
|
521
522
|
contextWindow,
|
|
522
523
|
focusKey,
|
|
524
|
+
scopeKey,
|
|
523
525
|
forceExpanded = false,
|
|
524
526
|
isCancelling = false,
|
|
525
527
|
isRunning,
|
|
@@ -555,6 +557,7 @@ function ChatComposer({
|
|
|
555
557
|
} = (0, import_ui.useAgentChatComposer)({
|
|
556
558
|
inputContract,
|
|
557
559
|
disabled,
|
|
560
|
+
scopeKey,
|
|
558
561
|
focusKey,
|
|
559
562
|
forceExpanded,
|
|
560
563
|
isCancelling,
|
|
@@ -639,7 +642,7 @@ function ChatComposer({
|
|
|
639
642
|
className: "sr-only",
|
|
640
643
|
type: "file",
|
|
641
644
|
multiple: true,
|
|
642
|
-
accept:
|
|
645
|
+
accept: (0, import_runtime.attachmentFileAccept)(attachmentMimeTypes),
|
|
643
646
|
onChange: (event) => {
|
|
644
647
|
addFiles(Array.from(event.target.files ?? []));
|
|
645
648
|
event.currentTarget.value = "";
|
|
@@ -969,8 +972,8 @@ function MessageParts({
|
|
|
969
972
|
getHitlActionState,
|
|
970
973
|
isLoading,
|
|
971
974
|
message,
|
|
972
|
-
onHitlAction: (part, response) => {
|
|
973
|
-
void onHitlAction(part, response).catch(() => void 0);
|
|
975
|
+
onHitlAction: (part, response, options2) => {
|
|
976
|
+
void onHitlAction(part, response, options2).catch(() => void 0);
|
|
974
977
|
},
|
|
975
978
|
parts: message.parts
|
|
976
979
|
}
|
|
@@ -984,8 +987,8 @@ function MessageParts({
|
|
|
984
987
|
{
|
|
985
988
|
getHitlActionState,
|
|
986
989
|
message,
|
|
987
|
-
onHitlAction: (hitlPart, response) => {
|
|
988
|
-
void onHitlAction(hitlPart, response).catch(() => void 0);
|
|
990
|
+
onHitlAction: (hitlPart, response, options2) => {
|
|
991
|
+
void onHitlAction(hitlPart, response, options2).catch(() => void 0);
|
|
989
992
|
},
|
|
990
993
|
part
|
|
991
994
|
},
|
|
@@ -1167,7 +1170,7 @@ function ChatMessage({
|
|
|
1167
1170
|
message
|
|
1168
1171
|
}
|
|
1169
1172
|
) }),
|
|
1170
|
-
showCompletionActions && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageFooter, { className: "
|
|
1173
|
+
showCompletionActions && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageFooter, { className: "a24-chat-message-action-row--assistant gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1171
1174
|
import_ui3.AgentChatDefaultActions,
|
|
1172
1175
|
{
|
|
1173
1176
|
animateCompletion: animateCompletionActions,
|
|
@@ -1189,12 +1192,12 @@ function ChatMessage({
|
|
|
1189
1192
|
var React5 = __toESM(require("react"), 1);
|
|
1190
1193
|
var import_react = require("@agents24/react");
|
|
1191
1194
|
var import_ui4 = require("@agents24/chat-react/ui");
|
|
1192
|
-
var
|
|
1195
|
+
var import_runtime2 = require("@agents24/chat-react/runtime");
|
|
1193
1196
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1194
1197
|
function SubagentTasks({ threadId }) {
|
|
1195
1198
|
const client = (0, import_react.useAgentClient)();
|
|
1196
1199
|
const source = React5.useMemo(() => ({ events: (input) => client.threads.delegations.events(input) }), [client]);
|
|
1197
|
-
const { tasks, error, refresh } = (0,
|
|
1200
|
+
const { tasks, error, refresh } = (0, import_runtime2.useDelegationTasks)({ threadId, source });
|
|
1198
1201
|
const [selection, setSelection] = React5.useState({ threadId: null, handle: null });
|
|
1199
1202
|
const selected = selection.threadId === threadId ? selection.handle : null;
|
|
1200
1203
|
if (!threadId || !tasks.length && !error) return null;
|
|
@@ -2140,7 +2143,7 @@ function isScaffoldTimelineLoading({
|
|
|
2140
2143
|
var import_chat_react2 = require("@agents24/chat-react");
|
|
2141
2144
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
2142
2145
|
var LOADING_INPUT_CONTRACT = {
|
|
2143
|
-
version: "agents24.runtime-inputs.
|
|
2146
|
+
version: "agents24.runtime-inputs.v3",
|
|
2144
2147
|
modalities: {
|
|
2145
2148
|
text: { enabled: false, required: false },
|
|
2146
2149
|
files: { enabled: false, required: false, allowed_mime_types: [] },
|
|
@@ -2167,7 +2170,7 @@ function OperationErrorNotice({ runtime }) {
|
|
|
2167
2170
|
if (!error) return null;
|
|
2168
2171
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "pointer-events-none absolute inset-x-0 top-3 z-40 flex justify-center px-4", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "pointer-events-auto flex max-w-lg items-start gap-2 rounded-lg border border-destructive/20 bg-background px-3 py-2 text-sm shadow-md", role: "alert", children: [
|
|
2169
2172
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_lucide_react11.CircleAlert, { className: "mt-0.5 size-4 shrink-0 text-destructive" }),
|
|
2170
|
-
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "min-w-0 flex-1 wrap-break-word", children: (0,
|
|
2173
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "min-w-0 flex-1 wrap-break-word", children: (0, import_runtime3.agentChatRuntimeErrorMessage)(error) || "The chat could not complete that action." }),
|
|
2171
2174
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
2172
2175
|
Button,
|
|
2173
2176
|
{
|
|
@@ -2348,6 +2351,7 @@ function ChatShell({
|
|
|
2348
2351
|
inputContract: runtime.inputContract || LOADING_INPUT_CONTRACT,
|
|
2349
2352
|
contextWindow: runtime.contextWindow,
|
|
2350
2353
|
disabled: runtime.isBootstrapping || runtime.isChangingAgent || isUploading || hasBlockingError,
|
|
2354
|
+
scopeKey: controller.activeThreadId,
|
|
2351
2355
|
focusKey: controller.activeThreadId,
|
|
2352
2356
|
forceExpanded: isEmptyState,
|
|
2353
2357
|
isCancelling,
|
|
@@ -2401,7 +2405,7 @@ function RuntimeChat({
|
|
|
2401
2405
|
identity = GUEST_CHAT_IDENTITY,
|
|
2402
2406
|
...props
|
|
2403
2407
|
}) {
|
|
2404
|
-
const runtime = (0,
|
|
2408
|
+
const runtime = (0, import_runtime4.useAgentChatRuntime)({
|
|
2405
2409
|
...props,
|
|
2406
2410
|
mcpRedirectUri: props.mcpRedirectUri || (typeof window === "undefined" ? void 0 : window.location.href)
|
|
2407
2411
|
});
|