@athenaintel/react 0.38.0 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -2
- package/dist/agent-runtime/src/messages.cjs +27 -1
- package/dist/agent-runtime/src/messages.cjs.map +1 -1
- package/dist/agent-runtime/src/messages.js +27 -1
- package/dist/agent-runtime/src/messages.js.map +1 -1
- package/dist/agent-runtime/src/queue.cjs +4 -0
- package/dist/agent-runtime/src/queue.cjs.map +1 -1
- package/dist/agent-runtime/src/queue.js +4 -0
- package/dist/agent-runtime/src/queue.js.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-config.cjs +2 -1
- package/dist/agent-runtime/src/use-deep-agent-config.cjs.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-config.js +2 -1
- package/dist/agent-runtime/src/use-deep-agent-config.js.map +1 -1
- package/dist/chat/AthenaChat.cjs +1 -1
- package/dist/chat/AthenaChat.cjs.map +1 -1
- package/dist/chat/AthenaChat.js +1 -1
- package/dist/chat/AthenaChat.js.map +1 -1
- package/dist/chat/StatewireQueuedMessages.cjs +18 -0
- package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
- package/dist/chat/StatewireQueuedMessages.d.ts +19 -1
- package/dist/chat/StatewireQueuedMessages.js +20 -2
- package/dist/chat/StatewireQueuedMessages.js.map +1 -1
- package/dist/chat-ui/thread/statewire-history-edge.cjs +13 -0
- package/dist/chat-ui/thread/statewire-history-edge.cjs.map +1 -1
- package/dist/chat-ui/thread/statewire-history-edge.js +13 -0
- package/dist/chat-ui/thread/statewire-history-edge.js.map +1 -1
- package/dist/diagnostics/errors.cjs +5 -0
- package/dist/diagnostics/errors.cjs.map +1 -1
- package/dist/diagnostics/errors.d.ts +5 -0
- package/dist/diagnostics/errors.js +5 -0
- package/dist/diagnostics/errors.js.map +1 -1
- package/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/provider/AthenaProvider.cjs +5 -2
- package/dist/provider/AthenaProvider.cjs.map +1 -1
- package/dist/provider/AthenaProvider.js +5 -2
- package/dist/provider/AthenaProvider.js.map +1 -1
- package/dist/provider/statewire-history-context.cjs +48 -0
- package/dist/provider/statewire-history-context.cjs.map +1 -0
- package/dist/provider/statewire-history-context.d.ts +36 -0
- package/dist/provider/statewire-history-context.js +48 -0
- package/dist/provider/statewire-history-context.js.map +1 -0
- package/dist/react/package.json.cjs +1 -1
- package/dist/react/package.json.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/workbench/ComputerLiveDesktop.cjs +287 -0
- package/dist/workbench/ComputerLiveDesktop.cjs.map +1 -0
- package/dist/workbench/ComputerLiveDesktop.d.ts +27 -0
- package/dist/workbench/ComputerLiveDesktop.js +287 -0
- package/dist/workbench/ComputerLiveDesktop.js.map +1 -0
- package/dist/workbench/SessionWorkbench.cjs +2 -2
- package/dist/workbench/SessionWorkbench.cjs.map +1 -1
- package/dist/workbench/SessionWorkbench.js +2 -2
- package/dist/workbench/SessionWorkbench.js.map +1 -1
- package/dist/workbench/live-desktop-api.cjs +139 -0
- package/dist/workbench/live-desktop-api.cjs.map +1 -0
- package/dist/workbench/live-desktop-api.d.ts +69 -0
- package/dist/workbench/live-desktop-api.js +139 -0
- package/dist/workbench/live-desktop-api.js.map +1 -0
- package/dist/workbench/session-workbench-context.cjs.map +1 -1
- package/dist/workbench/session-workbench-context.d.ts +7 -0
- package/dist/workbench/session-workbench-context.js.map +1 -1
- package/dist/workbench/session-workbench-panes.cjs +38 -2
- package/dist/workbench/session-workbench-panes.cjs.map +1 -1
- package/dist/workbench/session-workbench-panes.js +38 -2
- package/dist/workbench/session-workbench-panes.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-deep-agent-config.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-config.ts"],"sourcesContent":["import { useStatewireSendCommand, useStatewireState } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n applyConfigPatch,\n applyToolsDisable,\n applyToolsEnable,\n type ThreadConfigCustom,\n type ThreadConfigPatch,\n} from './config-mutations';\nimport { statewireRejectionPayload } from './errors';\nimport { DEEP_AGENT_CONFIG_COMMANDS } from './generated/runconfig-contract';\nimport { readDeepAgentStateThreadId } from './statewire-state';\n\ndeclare module '@assistant-ui/core' {\n namespace Assistant {\n interface Commands {\n /** Set / unset top-level keys of the thread's server config (`null` unsets). */\n configPatch: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch;\n patch: Record<string, unknown>;\n };\n /** Append ids to the thread's `enabled_tools`. */\n configToolsEnable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable;\n toolIds: string[];\n };\n /** Remove ids from the thread's `enabled_tools`. */\n configToolsDisable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable;\n toolIds: string[];\n };\n }\n }\n}\n\n/**\n * The replicated `state.config` lane of a thread with server-authoritative\n * run config. Absent — and `readServerConfig` returns `null` — while the\n * thread has never been configured (version 0: a brand-new thread, or one\n * created by a client predating the lane).\n */\nexport interface DeepAgentServerConfig {\n /** Monotonic server-incremented version; always >= 1 when the lane exists. */\n version: number;\n /** The thread-config keys every run on this thread uses as its base. */\n custom: ThreadConfigCustom;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * Read the server-config lane off a raw statewire state.\n *\n * Identity-preserving (returns the raw `state.config` reference), so it is\n * safe as a `useStatewireState` selector: the reference only changes when the\n * server writes the lane.\n */\nexport function readServerConfig(state: unknown): DeepAgentServerConfig | null {\n const config = (state as { config?: unknown } | null | undefined)?.config;\n if (!isRecord(config)) return null;\n const version = config.version;\n if (typeof version !== 'number' || !Number.isInteger(version) || version <= 0) return null;\n if (!isRecord(config.custom)) return null;\n return config as unknown as DeepAgentServerConfig;\n}\n\n/** The thread's server config version: 0 while the thread has never been configured. */\nexport function readConfigVersion(state: unknown): number {\n return readServerConfig(state)?.version ?? 0;\n}\n\n/**\n * {@link readServerConfig}, but only from a state `threadId`'s own attach\n * produced (`readDeepAgentStateThreadId`); any other state reads as\n * unconfigured. With no `threadId` it is {@link readServerConfig} unchanged.\n *\n * Identity-preserving like {@link readServerConfig}, so it is safe as a\n * `useStatewireState` selector.\n */\nexport function readThreadServerConfig({\n state,\n threadId,\n}: {\n state: unknown;\n threadId: string | undefined;\n}): DeepAgentServerConfig | null {\n if (threadId !== undefined && readDeepAgentStateThreadId(state) !== threadId) return null;\n return readServerConfig(state);\n}\n\n/**\n * The 403 rejection codes a view-only collaborator's `config/*` write can\n * come back with: `config_write_forbidden` from the config host's own gate,\n * or `thread_write_forbidden` from the host-wide mutation gate that runs\n * ahead of it and refuses every thread-mutating command on a view grant.\n */\nconst CONFIG_WRITE_FORBIDDEN_CODES: ReadonlySet<string> = new Set([\n 'config_write_forbidden',\n 'thread_write_forbidden',\n]);\n\n/**\n * Whether a rejected `config/*` command was refused because the submitter\n * only has view access to the session. The write is not retriable by that\n * user; hosts disable their config controls.\n */\nexport function isConfigWriteForbiddenRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n if (payload?.status !== 403) return false;\n const detail = payload.detail as { code?: unknown } | undefined;\n return typeof detail?.code === 'string' && CONFIG_WRITE_FORBIDDEN_CODES.has(detail.code);\n}\n\n/**\n * Whether a rejected `config/*` command was refused because the thread's\n * workspace cannot hold server config at all (`config_sync_unavailable`, a\n * regionally-pinned workspace). No write will ever succeed on the thread;\n * hosts stop issuing them and send their full config per run instead.\n */\nexport function isConfigSyncUnavailableRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n if (payload?.status !== 400) return false;\n const detail = payload.detail as { code?: unknown } | undefined;\n return detail?.code === 'config_sync_unavailable';\n}\n\n/** The settled result of a `config/*` command: the new server config. */\nexport interface DeepAgentConfigWriteResult {\n version: number;\n custom: ThreadConfigCustom;\n}\n\n/** An observed server-config version, delivered to the host callback. */\nexport interface DeepAgentServerConfigEvent {\n version: number;\n /** The server config with this client's still-pending writes folded over. */\n custom: ThreadConfigCustom;\n}\n\ninterface PendingOp {\n id: number;\n apply: (custom: ThreadConfigCustom) => ThreadConfigCustom;\n /** The version the server assigned this op; retired once the lane reaches it. */\n settledVersion: number | null;\n}\n\n/**\n * Fold the pending optimistic ops over the server config — the effective\n * config a client shows and sends against. Pure, for the tests.\n */\nexport function foldPendingConfigOps(\n serverConfig: DeepAgentServerConfig | null,\n ops: readonly Pick<PendingOp, 'apply' | 'settledVersion'>[]\n): ThreadConfigCustom {\n const version = serverConfig?.version ?? 0;\n let custom: ThreadConfigCustom = serverConfig?.custom ?? {};\n for (const op of ops) {\n if (op.settledVersion !== null && op.settledVersion <= version) continue;\n custom = op.apply(custom);\n }\n return custom;\n}\n\nexport interface UseDeepAgentConfigOptions {\n /**\n * Fired whenever the server writes a new version of the lane (another\n * device, the seed, or the echo of our own command), with this client's\n * still-pending writes folded over — hosts mirror it into their local\n * store; nothing is ever clobbered because pending edits stay on top.\n */\n onServerConfig?: (event: DeepAgentServerConfigEvent) => void;\n /**\n * The thread this binding serves. When set, the lane is read only from a\n * state that thread's own attach produced ({@link readThreadServerConfig}):\n * for the first render after a thread switch the client still projects the\n * previous thread's state, and adopting its lane would report the previous\n * thread's config and version as this thread's.\n */\n threadId?: string;\n}\n\nexport interface UseDeepAgentConfigResult {\n /** Reactive server config version (0 while the thread has never been configured). */\n configVersion: number;\n /** Reactive server-config lane, or `null` at version 0. */\n serverConfig: DeepAgentServerConfig | null;\n /**\n * The effective thread config: the server lane with this client's pending\n * writes folded over. `{}` at version 0 with nothing pending.\n */\n custom: ThreadConfigCustom;\n /** `true` while at least one `config/*` command is unacknowledged by the server. */\n hasPendingWrites: boolean;\n /** `config/patch` — set / unset top-level keys; `null` unsets. */\n patchConfig: (patch: ThreadConfigPatch) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/enable`. */\n enableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/disable`. */\n disableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n}\n\ntype ConfigCommand =\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch; patch: Record<string, unknown> }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable; toolIds: string[] }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable; toolIds: string[] };\n\n/**\n * The server-authoritative thread config of a deep-agent thread.\n *\n * Every capability a run depends on — model, agent binding, enabled tools,\n * sandbox, environment, … — lives on the thread's server config lane and is\n * changed only through the `config/*` commands. Sends carry per-send keys\n * only (`pickPerSendCustom`). The commands are applied optimistically: each\n * one folds its transform over the server config the moment it is issued\n * (`custom`), and retires once the lane reaches the version the server\n * assigned it; a rejection drops it, so the UI snaps back to the truth.\n *\n * Must be mounted under the thread's statewire context (an `AuiProvider`\n * holding `useDeepAgentThread`'s element), keyed by the thread identity so a\n * thread switch remounts it with an empty pending set. A binding that persists\n * what it reads per thread passes `threadId`, so the render that still sees\n * the previous thread's state after a switch reads no lane at all.\n */\nexport function useDeepAgentConfig({\n threadId,\n ...options\n}: UseDeepAgentConfigOptions = {}): UseDeepAgentConfigResult {\n const sendCommand = useStatewireSendCommand();\n const selectServerConfig = useCallback(\n (state: unknown) => readThreadServerConfig({ state, threadId }),\n [threadId]\n );\n const serverConfig = useStatewireState(selectServerConfig);\n return useDeepAgentConfigController({\n serverConfig,\n sendCommand: (command) => Promise.resolve(sendCommand(command as never)),\n ...options,\n });\n}\n\nexport interface DeepAgentConfigControllerInputs extends UseDeepAgentConfigOptions {\n serverConfig: DeepAgentServerConfig | null;\n sendCommand: (command: ConfigCommand) => Promise<unknown>;\n}\n\n/**\n * The transport-agnostic body of {@link useDeepAgentConfig}, with the reactive\n * inputs injected — so the optimistic-overlay behavior is testable without a\n * statewire session.\n */\nexport function useDeepAgentConfigController({\n serverConfig,\n sendCommand,\n onServerConfig,\n}: DeepAgentConfigControllerInputs): UseDeepAgentConfigResult {\n const [ops, setOps] = useState<readonly PendingOp[]>([]);\n const nextOpIdRef = useRef(1);\n const sendCommandRef = useRef(sendCommand);\n sendCommandRef.current = sendCommand;\n const onServerConfigRef = useRef(onServerConfig);\n onServerConfigRef.current = onServerConfig;\n\n const custom = useMemo(() => foldPendingConfigOps(serverConfig, ops), [serverConfig, ops]);\n\n // Retire ops the lane has caught up with (their transform is now part of\n // the server config itself).\n const serverVersion = serverConfig?.version ?? 0;\n const serverVersionRef = useRef(serverVersion);\n serverVersionRef.current = serverVersion;\n useEffect(() => {\n setOps((current) => {\n const kept = current.filter(\n (op) => op.settledVersion === null || op.settledVersion > serverVersion\n );\n return kept.length === current.length ? current : kept;\n });\n }, [serverVersion]);\n\n const lastNotifiedRef = useRef<DeepAgentServerConfig | null>(null);\n useEffect(() => {\n if (serverConfig === null || serverConfig === lastNotifiedRef.current) return;\n lastNotifiedRef.current = serverConfig;\n onServerConfigRef.current?.({ version: serverConfig.version, custom });\n }, [serverConfig, custom]);\n\n const run = useCallback(\n async (\n command: ConfigCommand,\n apply: PendingOp['apply']\n ): Promise<DeepAgentConfigWriteResult> => {\n const id = nextOpIdRef.current++;\n setOps((current) => [...current, { id, apply, settledVersion: null }]);\n try {\n const raw = (await sendCommandRef.current(command)) as\n | { version?: unknown; custom?: unknown }\n | null\n | undefined;\n const version = typeof raw?.version === 'number' ? raw.version : Number.POSITIVE_INFINITY;\n // The lane echo may have landed before the acknowledgement: retire\n // now if so, otherwise stamp the version for the retire effect.\n setOps((current) =>\n version <= serverVersionRef.current\n ? current.filter((op) => op.id !== id)\n : current.map((op) => (op.id === id ? { ...op, settledVersion: version } : op))\n );\n return {\n version: Number.isFinite(version) ? version : 0,\n custom: isRecord(raw?.custom) ? raw.custom : apply({}),\n };\n } catch (error) {\n setOps((current) => current.filter((op) => op.id !== id));\n throw error;\n }\n },\n []\n );\n\n const patchConfig = useCallback(\n (patch: ThreadConfigPatch) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.patch, patch }, (base) =>\n applyConfigPatch(base, patch)\n ),\n [run]\n );\n const enableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsEnable, toolIds: [...toolIds] }, (base) =>\n applyToolsEnable(base, toolIds)\n ),\n [run]\n );\n const disableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsDisable, toolIds: [...toolIds] }, (base) =>\n applyToolsDisable(base, toolIds)\n ),\n [run]\n );\n\n return {\n configVersion: serverVersion,\n serverConfig,\n custom,\n hasPendingWrites: ops.some((op) => op.settledVersion === null),\n patchConfig,\n enableTools,\n disableTools,\n };\n}\n"],"names":["statewireRejectionPayload","useState","useRef","useMemo","useEffect","useCallback","DEEP_AGENT_CONFIG_COMMANDS","applyConfigPatch","applyToolsEnable","applyToolsDisable"],"mappings":";;;;;;;AAgDA,MAAM,WAAW,CAAC,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAS9D,SAAS,iBAAiB,OAA8C;AAC7E,QAAM,SAAU,+BAAmD;AACnE,MAAI,CAAC,SAAS,MAAM,EAAG,QAAO;AAC9B,QAAM,UAAU,OAAO;AACvB,MAAI,OAAO,YAAY,YAAY,CAAC,OAAO,UAAU,OAAO,KAAK,WAAW,EAAG,QAAO;AACtF,MAAI,CAAC,SAAS,OAAO,MAAM,EAAG,QAAO;AACrC,SAAO;AACT;AAgCA,MAAM,mDAAwD,IAAI;AAAA,EAChE;AAAA,EACA;AACF,CAAC;AAOM,SAAS,gCAAgC,OAAyB;AACvE,QAAM,UAAUA,OAAAA,0BAA0B,KAAK;AAC/C,OAAI,mCAAS,YAAW,IAAK,QAAO;AACpC,QAAM,SAAS,QAAQ;AACvB,SAAO,QAAO,iCAA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,MAAMC,kBAAAA,2BAA2B,aAAa,SAAS,CAAC,GAAG,OAAO,EAAA;AAAA,MAAK,CAAC,SAC5EE,iCAAiB,MAAM,OAAO;AAAA,IAAA;AAAA,IAElC,CAAC,GAAG;AAAA,EAAA;AAEN,QAAM,eAAeH,MAAAA;AAAAA,IACnB,CAAC,YACC;AAAA,MAAI,EAAE,MAAMC,kBAAAA,2BAA2B,cAAc,SAAS,CAAC,GAAG,OAAO,EAAA;AAAA,MAAK,CAAC,SAC7EG,kCAAkB,MAAM,OAAO;AAAA,IAAA;AAAA,IAEnC,CAAC,GAAG;AAAA,EAAA;AAGN,SAAO;AAAA,IACL,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,kBAAkB,IAAI,KAAK,CAAC,OAAO,GAAG,mBAAmB,IAAI;AAAA,IAC7D;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;;;;;;"}
|
|
1
|
+
{"version":3,"file":"use-deep-agent-config.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-config.ts"],"sourcesContent":["import { useStatewireSendCommand, useStatewireState } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n applyConfigPatch,\n applyToolsDisable,\n applyToolsEnable,\n type ThreadConfigCustom,\n type ThreadConfigPatch,\n} from './config-mutations';\nimport { statewireRejectionPayload } from './errors';\nimport { DEEP_AGENT_CONFIG_COMMANDS } from './generated/runconfig-contract';\nimport { readDeepAgentStateThreadId } from './statewire-state';\n\ndeclare module '@assistant-ui/core' {\n namespace Assistant {\n interface Commands {\n /** Set / unset top-level keys of the thread's server config (`null` unsets). */\n configPatch: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch;\n patch: Record<string, unknown>;\n };\n /** Append ids to the thread's `enabled_tools`. */\n configToolsEnable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable;\n toolIds: string[];\n };\n /** Remove ids from the thread's `enabled_tools`. */\n configToolsDisable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable;\n toolIds: string[];\n };\n }\n }\n}\n\n/**\n * The replicated `state.config` lane of a thread with server-authoritative\n * run config. Absent — and `readServerConfig` returns `null` — while the\n * thread has never been configured (version 0: a brand-new thread, or one\n * created by a client predating the lane).\n */\nexport interface DeepAgentServerConfig {\n /** Monotonic server-incremented version; always >= 1 when the lane exists. */\n version: number;\n /** The thread-config keys every run on this thread uses as its base. */\n custom: ThreadConfigCustom;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * Read the server-config lane off a raw statewire state.\n *\n * Identity-preserving (returns the raw `state.config` reference), so it is\n * safe as a `useStatewireState` selector: the reference only changes when the\n * server writes the lane.\n */\nexport function readServerConfig(state: unknown): DeepAgentServerConfig | null {\n const config = (state as { config?: unknown } | null | undefined)?.config;\n if (!isRecord(config)) return null;\n const version = config.version;\n if (typeof version !== 'number' || !Number.isInteger(version) || version <= 0) return null;\n if (!isRecord(config.custom)) return null;\n return config as unknown as DeepAgentServerConfig;\n}\n\n/** The thread's server config version: 0 while the thread has never been configured. */\nexport function readConfigVersion(state: unknown): number {\n return readServerConfig(state)?.version ?? 0;\n}\n\n/**\n * {@link readServerConfig}, but only from a state `threadId`'s own attach\n * produced (`readDeepAgentStateThreadId`); any other state reads as\n * unconfigured. With no `threadId` it is {@link readServerConfig} unchanged.\n *\n * Identity-preserving like {@link readServerConfig}, so it is safe as a\n * `useStatewireState` selector.\n */\nexport function readThreadServerConfig({\n state,\n threadId,\n}: {\n state: unknown;\n threadId: string | undefined;\n}): DeepAgentServerConfig | null {\n if (threadId !== undefined && readDeepAgentStateThreadId(state) !== threadId) return null;\n return readServerConfig(state);\n}\n\n/**\n * The 403 rejection codes a view-only collaborator's `config/*` write can\n * come back with: `config_write_forbidden` from the config host's own gate,\n * or `thread_write_forbidden` from the host-wide mutation gate that runs\n * ahead of it and refuses every thread-mutating command on a view grant.\n */\nconst CONFIG_WRITE_FORBIDDEN_CODES: ReadonlySet<string> = new Set([\n 'config_write_forbidden',\n 'thread_write_forbidden',\n]);\n\n/**\n * Whether a rejected `config/*` command was refused because the submitter\n * only has view access to the session, or because the conversation is\n * archived (`conversation_archived`, a 409: read-only until it is restored).\n * The write is not retriable by that user; hosts disable their config\n * controls.\n */\nexport function isConfigWriteForbiddenRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n const detail = payload?.detail as { code?: unknown } | undefined;\n if (payload?.status === 409) return detail?.code === 'conversation_archived';\n if (payload?.status !== 403) return false;\n return typeof detail?.code === 'string' && CONFIG_WRITE_FORBIDDEN_CODES.has(detail.code);\n}\n\n/**\n * Whether a rejected `config/*` command was refused because the thread's\n * workspace cannot hold server config at all (`config_sync_unavailable`, a\n * regionally-pinned workspace). No write will ever succeed on the thread;\n * hosts stop issuing them and send their full config per run instead.\n */\nexport function isConfigSyncUnavailableRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n if (payload?.status !== 400) return false;\n const detail = payload.detail as { code?: unknown } | undefined;\n return detail?.code === 'config_sync_unavailable';\n}\n\n/** The settled result of a `config/*` command: the new server config. */\nexport interface DeepAgentConfigWriteResult {\n version: number;\n custom: ThreadConfigCustom;\n}\n\n/** An observed server-config version, delivered to the host callback. */\nexport interface DeepAgentServerConfigEvent {\n version: number;\n /** The server config with this client's still-pending writes folded over. */\n custom: ThreadConfigCustom;\n}\n\ninterface PendingOp {\n id: number;\n apply: (custom: ThreadConfigCustom) => ThreadConfigCustom;\n /** The version the server assigned this op; retired once the lane reaches it. */\n settledVersion: number | null;\n}\n\n/**\n * Fold the pending optimistic ops over the server config — the effective\n * config a client shows and sends against. Pure, for the tests.\n */\nexport function foldPendingConfigOps(\n serverConfig: DeepAgentServerConfig | null,\n ops: readonly Pick<PendingOp, 'apply' | 'settledVersion'>[]\n): ThreadConfigCustom {\n const version = serverConfig?.version ?? 0;\n let custom: ThreadConfigCustom = serverConfig?.custom ?? {};\n for (const op of ops) {\n if (op.settledVersion !== null && op.settledVersion <= version) continue;\n custom = op.apply(custom);\n }\n return custom;\n}\n\nexport interface UseDeepAgentConfigOptions {\n /**\n * Fired whenever the server writes a new version of the lane (another\n * device, the seed, or the echo of our own command), with this client's\n * still-pending writes folded over — hosts mirror it into their local\n * store; nothing is ever clobbered because pending edits stay on top.\n */\n onServerConfig?: (event: DeepAgentServerConfigEvent) => void;\n /**\n * The thread this binding serves. When set, the lane is read only from a\n * state that thread's own attach produced ({@link readThreadServerConfig}):\n * for the first render after a thread switch the client still projects the\n * previous thread's state, and adopting its lane would report the previous\n * thread's config and version as this thread's.\n */\n threadId?: string;\n}\n\nexport interface UseDeepAgentConfigResult {\n /** Reactive server config version (0 while the thread has never been configured). */\n configVersion: number;\n /** Reactive server-config lane, or `null` at version 0. */\n serverConfig: DeepAgentServerConfig | null;\n /**\n * The effective thread config: the server lane with this client's pending\n * writes folded over. `{}` at version 0 with nothing pending.\n */\n custom: ThreadConfigCustom;\n /** `true` while at least one `config/*` command is unacknowledged by the server. */\n hasPendingWrites: boolean;\n /** `config/patch` — set / unset top-level keys; `null` unsets. */\n patchConfig: (patch: ThreadConfigPatch) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/enable`. */\n enableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/disable`. */\n disableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n}\n\ntype ConfigCommand =\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch; patch: Record<string, unknown> }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable; toolIds: string[] }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable; toolIds: string[] };\n\n/**\n * The server-authoritative thread config of a deep-agent thread.\n *\n * Every capability a run depends on — model, agent binding, enabled tools,\n * sandbox, environment, … — lives on the thread's server config lane and is\n * changed only through the `config/*` commands. Sends carry per-send keys\n * only (`pickPerSendCustom`). The commands are applied optimistically: each\n * one folds its transform over the server config the moment it is issued\n * (`custom`), and retires once the lane reaches the version the server\n * assigned it; a rejection drops it, so the UI snaps back to the truth.\n *\n * Must be mounted under the thread's statewire context (an `AuiProvider`\n * holding `useDeepAgentThread`'s element), keyed by the thread identity so a\n * thread switch remounts it with an empty pending set. A binding that persists\n * what it reads per thread passes `threadId`, so the render that still sees\n * the previous thread's state after a switch reads no lane at all.\n */\nexport function useDeepAgentConfig({\n threadId,\n ...options\n}: UseDeepAgentConfigOptions = {}): UseDeepAgentConfigResult {\n const sendCommand = useStatewireSendCommand();\n const selectServerConfig = useCallback(\n (state: unknown) => readThreadServerConfig({ state, threadId }),\n [threadId]\n );\n const serverConfig = useStatewireState(selectServerConfig);\n return useDeepAgentConfigController({\n serverConfig,\n sendCommand: (command) => Promise.resolve(sendCommand(command as never)),\n ...options,\n });\n}\n\nexport interface DeepAgentConfigControllerInputs extends UseDeepAgentConfigOptions {\n serverConfig: DeepAgentServerConfig | null;\n sendCommand: (command: ConfigCommand) => Promise<unknown>;\n}\n\n/**\n * The transport-agnostic body of {@link useDeepAgentConfig}, with the reactive\n * inputs injected — so the optimistic-overlay behavior is testable without a\n * statewire session.\n */\nexport function useDeepAgentConfigController({\n serverConfig,\n sendCommand,\n onServerConfig,\n}: DeepAgentConfigControllerInputs): UseDeepAgentConfigResult {\n const [ops, setOps] = useState<readonly PendingOp[]>([]);\n const nextOpIdRef = useRef(1);\n const sendCommandRef = useRef(sendCommand);\n sendCommandRef.current = sendCommand;\n const onServerConfigRef = useRef(onServerConfig);\n onServerConfigRef.current = onServerConfig;\n\n const custom = useMemo(() => foldPendingConfigOps(serverConfig, ops), [serverConfig, ops]);\n\n // Retire ops the lane has caught up with (their transform is now part of\n // the server config itself).\n const serverVersion = serverConfig?.version ?? 0;\n const serverVersionRef = useRef(serverVersion);\n serverVersionRef.current = serverVersion;\n useEffect(() => {\n setOps((current) => {\n const kept = current.filter(\n (op) => op.settledVersion === null || op.settledVersion > serverVersion\n );\n return kept.length === current.length ? current : kept;\n });\n }, [serverVersion]);\n\n const lastNotifiedRef = useRef<DeepAgentServerConfig | null>(null);\n useEffect(() => {\n if (serverConfig === null || serverConfig === lastNotifiedRef.current) return;\n lastNotifiedRef.current = serverConfig;\n onServerConfigRef.current?.({ version: serverConfig.version, custom });\n }, [serverConfig, custom]);\n\n const run = useCallback(\n async (\n command: ConfigCommand,\n apply: PendingOp['apply']\n ): Promise<DeepAgentConfigWriteResult> => {\n const id = nextOpIdRef.current++;\n setOps((current) => [...current, { id, apply, settledVersion: null }]);\n try {\n const raw = (await sendCommandRef.current(command)) as\n | { version?: unknown; custom?: unknown }\n | null\n | undefined;\n const version = typeof raw?.version === 'number' ? raw.version : Number.POSITIVE_INFINITY;\n // The lane echo may have landed before the acknowledgement: retire\n // now if so, otherwise stamp the version for the retire effect.\n setOps((current) =>\n version <= serverVersionRef.current\n ? current.filter((op) => op.id !== id)\n : current.map((op) => (op.id === id ? { ...op, settledVersion: version } : op))\n );\n return {\n version: Number.isFinite(version) ? version : 0,\n custom: isRecord(raw?.custom) ? raw.custom : apply({}),\n };\n } catch (error) {\n setOps((current) => current.filter((op) => op.id !== id));\n throw error;\n }\n },\n []\n );\n\n const patchConfig = useCallback(\n (patch: ThreadConfigPatch) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.patch, patch }, (base) =>\n applyConfigPatch(base, patch)\n ),\n [run]\n );\n const enableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsEnable, toolIds: [...toolIds] }, (base) =>\n applyToolsEnable(base, toolIds)\n ),\n [run]\n );\n const disableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsDisable, toolIds: [...toolIds] }, (base) =>\n applyToolsDisable(base, toolIds)\n ),\n [run]\n );\n\n return {\n configVersion: serverVersion,\n serverConfig,\n custom,\n hasPendingWrites: ops.some((op) => op.settledVersion === null),\n patchConfig,\n enableTools,\n disableTools,\n };\n}\n"],"names":["statewireRejectionPayload","useState","useRef","useMemo","useEffect","useCallback","DEEP_AGENT_CONFIG_COMMANDS","applyConfigPatch","applyToolsEnable","applyToolsDisable"],"mappings":";;;;;;;AAgDA,MAAM,WAAW,CAAC,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAS9D,SAAS,iBAAiB,OAA8C;AAC7E,QAAM,SAAU,+BAAmD;AACnE,MAAI,CAAC,SAAS,MAAM,EAAG,QAAO;AAC9B,QAAM,UAAU,OAAO;AACvB,MAAI,OAAO,YAAY,YAAY,CAAC,OAAO,UAAU,OAAO,KAAK,WAAW,EAAG,QAAO;AACtF,MAAI,CAAC,SAAS,OAAO,MAAM,EAAG,QAAO;AACrC,SAAO;AACT;AAgCA,MAAM,mDAAwD,IAAI;AAAA,EAChE;AAAA,EACA;AACF,CAAC;AASM,SAAS,gCAAgC,OAAyB;AACvE,QAAM,UAAUA,OAAAA,0BAA0B,KAAK;AAC/C,QAAM,SAAS,mCAAS;AACxB,OAAI,mCAAS,YAAW,IAAK,SAAO,iCAAQ,UAAS;AACrD,OAAI,mCAAS,YAAW,IAAK,QAAO;AACpC,SAAO,QAAO,iCAAQ,UAAS,YAAY,6BAA6B,IAAI,OAAO,IAAI;AACzF;AAQO,SAAS,iCAAiC,OAAyB;AACxE,QAAM,UAAUA,OAAAA,0BAA0B,KAAK;AAC/C,OAAI,mCAAS,YAAW,IAAK,QAAO;AACpC,QAAM,SAAS,QAAQ;AACvB,UAAO,iCAAQ,UAAS;AAC1B;AA0BO,SAAS,qBACd,cACA,KACoB;AACpB,QAAM,WAAU,6CAAc,YAAW;AACzC,MAAI,UAA6B,6CAAc,WAAU,CAAA;AACzD,aAAW,MAAM,KAAK;AACpB,QAAI,GAAG,mBAAmB,QAAQ,GAAG,kBAAkB,QAAS;AAChE,aAAS,GAAG,MAAM,MAAM;AAAA,EAC1B;AACA,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A,kBAAkB,IAAI,KAAK,CAAC,OAAO,GAAG,mBAAmB,IAAI;AAAA,IAC7D;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;;;;;;"}
|
|
@@ -18,8 +18,9 @@ const CONFIG_WRITE_FORBIDDEN_CODES = /* @__PURE__ */ new Set([
|
|
|
18
18
|
]);
|
|
19
19
|
function isConfigWriteForbiddenRejection(error) {
|
|
20
20
|
const payload = statewireRejectionPayload(error);
|
|
21
|
+
const detail = payload == null ? void 0 : payload.detail;
|
|
22
|
+
if ((payload == null ? void 0 : payload.status) === 409) return (detail == null ? void 0 : detail.code) === "conversation_archived";
|
|
21
23
|
if ((payload == null ? void 0 : payload.status) !== 403) return false;
|
|
22
|
-
const detail = payload.detail;
|
|
23
24
|
return typeof (detail == null ? void 0 : detail.code) === "string" && CONFIG_WRITE_FORBIDDEN_CODES.has(detail.code);
|
|
24
25
|
}
|
|
25
26
|
function isConfigSyncUnavailableRejection(error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-deep-agent-config.js","sources":["../../../../agent-runtime/src/use-deep-agent-config.ts"],"sourcesContent":["import { useStatewireSendCommand, useStatewireState } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n applyConfigPatch,\n applyToolsDisable,\n applyToolsEnable,\n type ThreadConfigCustom,\n type ThreadConfigPatch,\n} from './config-mutations';\nimport { statewireRejectionPayload } from './errors';\nimport { DEEP_AGENT_CONFIG_COMMANDS } from './generated/runconfig-contract';\nimport { readDeepAgentStateThreadId } from './statewire-state';\n\ndeclare module '@assistant-ui/core' {\n namespace Assistant {\n interface Commands {\n /** Set / unset top-level keys of the thread's server config (`null` unsets). */\n configPatch: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch;\n patch: Record<string, unknown>;\n };\n /** Append ids to the thread's `enabled_tools`. */\n configToolsEnable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable;\n toolIds: string[];\n };\n /** Remove ids from the thread's `enabled_tools`. */\n configToolsDisable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable;\n toolIds: string[];\n };\n }\n }\n}\n\n/**\n * The replicated `state.config` lane of a thread with server-authoritative\n * run config. Absent — and `readServerConfig` returns `null` — while the\n * thread has never been configured (version 0: a brand-new thread, or one\n * created by a client predating the lane).\n */\nexport interface DeepAgentServerConfig {\n /** Monotonic server-incremented version; always >= 1 when the lane exists. */\n version: number;\n /** The thread-config keys every run on this thread uses as its base. */\n custom: ThreadConfigCustom;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * Read the server-config lane off a raw statewire state.\n *\n * Identity-preserving (returns the raw `state.config` reference), so it is\n * safe as a `useStatewireState` selector: the reference only changes when the\n * server writes the lane.\n */\nexport function readServerConfig(state: unknown): DeepAgentServerConfig | null {\n const config = (state as { config?: unknown } | null | undefined)?.config;\n if (!isRecord(config)) return null;\n const version = config.version;\n if (typeof version !== 'number' || !Number.isInteger(version) || version <= 0) return null;\n if (!isRecord(config.custom)) return null;\n return config as unknown as DeepAgentServerConfig;\n}\n\n/** The thread's server config version: 0 while the thread has never been configured. */\nexport function readConfigVersion(state: unknown): number {\n return readServerConfig(state)?.version ?? 0;\n}\n\n/**\n * {@link readServerConfig}, but only from a state `threadId`'s own attach\n * produced (`readDeepAgentStateThreadId`); any other state reads as\n * unconfigured. With no `threadId` it is {@link readServerConfig} unchanged.\n *\n * Identity-preserving like {@link readServerConfig}, so it is safe as a\n * `useStatewireState` selector.\n */\nexport function readThreadServerConfig({\n state,\n threadId,\n}: {\n state: unknown;\n threadId: string | undefined;\n}): DeepAgentServerConfig | null {\n if (threadId !== undefined && readDeepAgentStateThreadId(state) !== threadId) return null;\n return readServerConfig(state);\n}\n\n/**\n * The 403 rejection codes a view-only collaborator's `config/*` write can\n * come back with: `config_write_forbidden` from the config host's own gate,\n * or `thread_write_forbidden` from the host-wide mutation gate that runs\n * ahead of it and refuses every thread-mutating command on a view grant.\n */\nconst CONFIG_WRITE_FORBIDDEN_CODES: ReadonlySet<string> = new Set([\n 'config_write_forbidden',\n 'thread_write_forbidden',\n]);\n\n/**\n * Whether a rejected `config/*` command was refused because the submitter\n * only has view access to the session. The write is not retriable by that\n * user; hosts disable their config controls.\n */\nexport function isConfigWriteForbiddenRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n if (payload?.status !== 403) return false;\n const detail = payload.detail as { code?: unknown } | undefined;\n return typeof detail?.code === 'string' && CONFIG_WRITE_FORBIDDEN_CODES.has(detail.code);\n}\n\n/**\n * Whether a rejected `config/*` command was refused because the thread's\n * workspace cannot hold server config at all (`config_sync_unavailable`, a\n * regionally-pinned workspace). No write will ever succeed on the thread;\n * hosts stop issuing them and send their full config per run instead.\n */\nexport function isConfigSyncUnavailableRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n if (payload?.status !== 400) return false;\n const detail = payload.detail as { code?: unknown } | undefined;\n return detail?.code === 'config_sync_unavailable';\n}\n\n/** The settled result of a `config/*` command: the new server config. */\nexport interface DeepAgentConfigWriteResult {\n version: number;\n custom: ThreadConfigCustom;\n}\n\n/** An observed server-config version, delivered to the host callback. */\nexport interface DeepAgentServerConfigEvent {\n version: number;\n /** The server config with this client's still-pending writes folded over. */\n custom: ThreadConfigCustom;\n}\n\ninterface PendingOp {\n id: number;\n apply: (custom: ThreadConfigCustom) => ThreadConfigCustom;\n /** The version the server assigned this op; retired once the lane reaches it. */\n settledVersion: number | null;\n}\n\n/**\n * Fold the pending optimistic ops over the server config — the effective\n * config a client shows and sends against. Pure, for the tests.\n */\nexport function foldPendingConfigOps(\n serverConfig: DeepAgentServerConfig | null,\n ops: readonly Pick<PendingOp, 'apply' | 'settledVersion'>[]\n): ThreadConfigCustom {\n const version = serverConfig?.version ?? 0;\n let custom: ThreadConfigCustom = serverConfig?.custom ?? {};\n for (const op of ops) {\n if (op.settledVersion !== null && op.settledVersion <= version) continue;\n custom = op.apply(custom);\n }\n return custom;\n}\n\nexport interface UseDeepAgentConfigOptions {\n /**\n * Fired whenever the server writes a new version of the lane (another\n * device, the seed, or the echo of our own command), with this client's\n * still-pending writes folded over — hosts mirror it into their local\n * store; nothing is ever clobbered because pending edits stay on top.\n */\n onServerConfig?: (event: DeepAgentServerConfigEvent) => void;\n /**\n * The thread this binding serves. When set, the lane is read only from a\n * state that thread's own attach produced ({@link readThreadServerConfig}):\n * for the first render after a thread switch the client still projects the\n * previous thread's state, and adopting its lane would report the previous\n * thread's config and version as this thread's.\n */\n threadId?: string;\n}\n\nexport interface UseDeepAgentConfigResult {\n /** Reactive server config version (0 while the thread has never been configured). */\n configVersion: number;\n /** Reactive server-config lane, or `null` at version 0. */\n serverConfig: DeepAgentServerConfig | null;\n /**\n * The effective thread config: the server lane with this client's pending\n * writes folded over. `{}` at version 0 with nothing pending.\n */\n custom: ThreadConfigCustom;\n /** `true` while at least one `config/*` command is unacknowledged by the server. */\n hasPendingWrites: boolean;\n /** `config/patch` — set / unset top-level keys; `null` unsets. */\n patchConfig: (patch: ThreadConfigPatch) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/enable`. */\n enableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/disable`. */\n disableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n}\n\ntype ConfigCommand =\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch; patch: Record<string, unknown> }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable; toolIds: string[] }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable; toolIds: string[] };\n\n/**\n * The server-authoritative thread config of a deep-agent thread.\n *\n * Every capability a run depends on — model, agent binding, enabled tools,\n * sandbox, environment, … — lives on the thread's server config lane and is\n * changed only through the `config/*` commands. Sends carry per-send keys\n * only (`pickPerSendCustom`). The commands are applied optimistically: each\n * one folds its transform over the server config the moment it is issued\n * (`custom`), and retires once the lane reaches the version the server\n * assigned it; a rejection drops it, so the UI snaps back to the truth.\n *\n * Must be mounted under the thread's statewire context (an `AuiProvider`\n * holding `useDeepAgentThread`'s element), keyed by the thread identity so a\n * thread switch remounts it with an empty pending set. A binding that persists\n * what it reads per thread passes `threadId`, so the render that still sees\n * the previous thread's state after a switch reads no lane at all.\n */\nexport function useDeepAgentConfig({\n threadId,\n ...options\n}: UseDeepAgentConfigOptions = {}): UseDeepAgentConfigResult {\n const sendCommand = useStatewireSendCommand();\n const selectServerConfig = useCallback(\n (state: unknown) => readThreadServerConfig({ state, threadId }),\n [threadId]\n );\n const serverConfig = useStatewireState(selectServerConfig);\n return useDeepAgentConfigController({\n serverConfig,\n sendCommand: (command) => Promise.resolve(sendCommand(command as never)),\n ...options,\n });\n}\n\nexport interface DeepAgentConfigControllerInputs extends UseDeepAgentConfigOptions {\n serverConfig: DeepAgentServerConfig | null;\n sendCommand: (command: ConfigCommand) => Promise<unknown>;\n}\n\n/**\n * The transport-agnostic body of {@link useDeepAgentConfig}, with the reactive\n * inputs injected — so the optimistic-overlay behavior is testable without a\n * statewire session.\n */\nexport function useDeepAgentConfigController({\n serverConfig,\n sendCommand,\n onServerConfig,\n}: DeepAgentConfigControllerInputs): UseDeepAgentConfigResult {\n const [ops, setOps] = useState<readonly PendingOp[]>([]);\n const nextOpIdRef = useRef(1);\n const sendCommandRef = useRef(sendCommand);\n sendCommandRef.current = sendCommand;\n const onServerConfigRef = useRef(onServerConfig);\n onServerConfigRef.current = onServerConfig;\n\n const custom = useMemo(() => foldPendingConfigOps(serverConfig, ops), [serverConfig, ops]);\n\n // Retire ops the lane has caught up with (their transform is now part of\n // the server config itself).\n const serverVersion = serverConfig?.version ?? 0;\n const serverVersionRef = useRef(serverVersion);\n serverVersionRef.current = serverVersion;\n useEffect(() => {\n setOps((current) => {\n const kept = current.filter(\n (op) => op.settledVersion === null || op.settledVersion > serverVersion\n );\n return kept.length === current.length ? current : kept;\n });\n }, [serverVersion]);\n\n const lastNotifiedRef = useRef<DeepAgentServerConfig | null>(null);\n useEffect(() => {\n if (serverConfig === null || serverConfig === lastNotifiedRef.current) return;\n lastNotifiedRef.current = serverConfig;\n onServerConfigRef.current?.({ version: serverConfig.version, custom });\n }, [serverConfig, custom]);\n\n const run = useCallback(\n async (\n command: ConfigCommand,\n apply: PendingOp['apply']\n ): Promise<DeepAgentConfigWriteResult> => {\n const id = nextOpIdRef.current++;\n setOps((current) => [...current, { id, apply, settledVersion: null }]);\n try {\n const raw = (await sendCommandRef.current(command)) as\n | { version?: unknown; custom?: unknown }\n | null\n | undefined;\n const version = typeof raw?.version === 'number' ? raw.version : Number.POSITIVE_INFINITY;\n // The lane echo may have landed before the acknowledgement: retire\n // now if so, otherwise stamp the version for the retire effect.\n setOps((current) =>\n version <= serverVersionRef.current\n ? current.filter((op) => op.id !== id)\n : current.map((op) => (op.id === id ? { ...op, settledVersion: version } : op))\n );\n return {\n version: Number.isFinite(version) ? version : 0,\n custom: isRecord(raw?.custom) ? raw.custom : apply({}),\n };\n } catch (error) {\n setOps((current) => current.filter((op) => op.id !== id));\n throw error;\n }\n },\n []\n );\n\n const patchConfig = useCallback(\n (patch: ThreadConfigPatch) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.patch, patch }, (base) =>\n applyConfigPatch(base, patch)\n ),\n [run]\n );\n const enableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsEnable, toolIds: [...toolIds] }, (base) =>\n applyToolsEnable(base, toolIds)\n ),\n [run]\n );\n const disableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsDisable, toolIds: [...toolIds] }, (base) =>\n applyToolsDisable(base, toolIds)\n ),\n [run]\n );\n\n return {\n configVersion: serverVersion,\n serverConfig,\n custom,\n hasPendingWrites: ops.some((op) => op.settledVersion === null),\n patchConfig,\n en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UAAU;AAAA,UAC9C,QAAQ,SAAS,2BAAK,MAAM,IAAI,IAAI,SAAS,MAAM,CAAA,CAAE;AAAA,QAAA;AAAA,MAEzD,SAAS,OAAO;AACd,eAAO,CAAC,YAAY,QAAQ,OAAO,CAAC,OAAO,GAAG,OAAO,EAAE,CAAC;AACxD,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,CAAA;AAAA,EAAC;AAGH,QAAM,cAAc;AAAA,IAClB,CAAC,UACC;AAAA,MAAI,EAAE,MAAM,2BAA2B,OAAO,MAAA;AAAA,MAAS,CAAC,SACtD,iBAAiB,MAAM,KAAK;AAAA,IAAA;AAAA,IAEhC,CAAC,GAAG;AAAA,EAAA;AAEN,QAAM,cAAc;AAAA,IAClB,CAAC,YACC;AAAA,MAAI,EAAE,MAAM,2BAA2B,aAAa,SAAS,CAAC,GAAG,OAAO,EAAA;AAAA,MAAK,CAAC,SAC5E,iBAAiB,MAAM,OAAO;AAAA,IAAA;AAAA,IAElC,CAAC,GAAG;AAAA,EAAA;AAEN,QAAM,eAAe;AAAA,IACnB,CAAC,YACC;AAAA,MAAI,EAAE,MAAM,2BAA2B,cAAc,SAAS,CAAC,GAAG,OAAO,EAAA;AAAA,MAAK,CAAC,SAC7E,kBAAkB,MAAM,OAAO;AAAA,IAAA;AAAA,IAEnC,CAAC,GAAG;AAAA,EAAA;AAGN,SAAO;AAAA,IACL,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,kBAAkB,IAAI,KAAK,CAAC,OAAO,GAAG,mBAAmB,IAAI;AAAA,IAC7D;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"use-deep-agent-config.js","sources":["../../../../agent-runtime/src/use-deep-agent-config.ts"],"sourcesContent":["import { useStatewireSendCommand, useStatewireState } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n applyConfigPatch,\n applyToolsDisable,\n applyToolsEnable,\n type ThreadConfigCustom,\n type ThreadConfigPatch,\n} from './config-mutations';\nimport { statewireRejectionPayload } from './errors';\nimport { DEEP_AGENT_CONFIG_COMMANDS } from './generated/runconfig-contract';\nimport { readDeepAgentStateThreadId } from './statewire-state';\n\ndeclare module '@assistant-ui/core' {\n namespace Assistant {\n interface Commands {\n /** Set / unset top-level keys of the thread's server config (`null` unsets). */\n configPatch: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch;\n patch: Record<string, unknown>;\n };\n /** Append ids to the thread's `enabled_tools`. */\n configToolsEnable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable;\n toolIds: string[];\n };\n /** Remove ids from the thread's `enabled_tools`. */\n configToolsDisable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable;\n toolIds: string[];\n };\n }\n }\n}\n\n/**\n * The replicated `state.config` lane of a thread with server-authoritative\n * run config. Absent — and `readServerConfig` returns `null` — while the\n * thread has never been configured (version 0: a brand-new thread, or one\n * created by a client predating the lane).\n */\nexport interface DeepAgentServerConfig {\n /** Monotonic server-incremented version; always >= 1 when the lane exists. */\n version: number;\n /** The thread-config keys every run on this thread uses as its base. */\n custom: ThreadConfigCustom;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * Read the server-config lane off a raw statewire state.\n *\n * Identity-preserving (returns the raw `state.config` reference), so it is\n * safe as a `useStatewireState` selector: the reference only changes when the\n * server writes the lane.\n */\nexport function readServerConfig(state: unknown): DeepAgentServerConfig | null {\n const config = (state as { config?: unknown } | null | undefined)?.config;\n if (!isRecord(config)) return null;\n const version = config.version;\n if (typeof version !== 'number' || !Number.isInteger(version) || version <= 0) return null;\n if (!isRecord(config.custom)) return null;\n return config as unknown as DeepAgentServerConfig;\n}\n\n/** The thread's server config version: 0 while the thread has never been configured. */\nexport function readConfigVersion(state: unknown): number {\n return readServerConfig(state)?.version ?? 0;\n}\n\n/**\n * {@link readServerConfig}, but only from a state `threadId`'s own attach\n * produced (`readDeepAgentStateThreadId`); any other state reads as\n * unconfigured. With no `threadId` it is {@link readServerConfig} unchanged.\n *\n * Identity-preserving like {@link readServerConfig}, so it is safe as a\n * `useStatewireState` selector.\n */\nexport function readThreadServerConfig({\n state,\n threadId,\n}: {\n state: unknown;\n threadId: string | undefined;\n}): DeepAgentServerConfig | null {\n if (threadId !== undefined && readDeepAgentStateThreadId(state) !== threadId) return null;\n return readServerConfig(state);\n}\n\n/**\n * The 403 rejection codes a view-only collaborator's `config/*` write can\n * come back with: `config_write_forbidden` from the config host's own gate,\n * or `thread_write_forbidden` from the host-wide mutation gate that runs\n * ahead of it and refuses every thread-mutating command on a view grant.\n */\nconst CONFIG_WRITE_FORBIDDEN_CODES: ReadonlySet<string> = new Set([\n 'config_write_forbidden',\n 'thread_write_forbidden',\n]);\n\n/**\n * Whether a rejected `config/*` command was refused because the submitter\n * only has view access to the session, or because the conversation is\n * archived (`conversation_archived`, a 409: read-only until it is restored).\n * The write is not retriable by that user; hosts disable their config\n * controls.\n */\nexport function isConfigWriteForbiddenRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n const detail = payload?.detail as { code?: unknown } | undefined;\n if (payload?.status === 409) return detail?.code === 'conversation_archived';\n if (payload?.status !== 403) return false;\n return typeof detail?.code === 'string' && CONFIG_WRITE_FORBIDDEN_CODES.has(detail.code);\n}\n\n/**\n * Whether a rejected `config/*` command was refused because the thread's\n * workspace cannot hold server config at all (`config_sync_unavailable`, a\n * regionally-pinned workspace). No write will ever succeed on the thread;\n * hosts stop issuing them and send their full config per run instead.\n */\nexport function isConfigSyncUnavailableRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n if (payload?.status !== 400) return false;\n const detail = payload.detail as { code?: unknown } | undefined;\n return detail?.code === 'config_sync_unavailable';\n}\n\n/** The settled result of a `config/*` command: the new server config. */\nexport interface DeepAgentConfigWriteResult {\n version: number;\n custom: ThreadConfigCustom;\n}\n\n/** An observed server-config version, delivered to the host callback. */\nexport interface DeepAgentServerConfigEvent {\n version: number;\n /** The server config with this client's still-pending writes folded over. */\n custom: ThreadConfigCustom;\n}\n\ninterface PendingOp {\n id: number;\n apply: (custom: ThreadConfigCustom) => ThreadConfigCustom;\n /** The version the server assigned this op; retired once the lane reaches it. */\n settledVersion: number | null;\n}\n\n/**\n * Fold the pending optimistic ops over the server config — the effective\n * config a client shows and sends against. Pure, for the tests.\n */\nexport function foldPendingConfigOps(\n serverConfig: DeepAgentServerConfig | null,\n ops: readonly Pick<PendingOp, 'apply' | 'settledVersion'>[]\n): ThreadConfigCustom {\n const version = serverConfig?.version ?? 0;\n let custom: ThreadConfigCustom = serverConfig?.custom ?? {};\n for (const op of ops) {\n if (op.settledVersion !== null && op.settledVersion <= version) continue;\n custom = op.apply(custom);\n }\n return custom;\n}\n\nexport interface UseDeepAgentConfigOptions {\n /**\n * Fired whenever the server writes a new version of the lane (another\n * device, the seed, or the echo of our own command), with this client's\n * still-pending writes folded over — hosts mirror it into their local\n * store; nothing is ever clobbered because pending edits stay on top.\n */\n onServerConfig?: (event: DeepAgentServerConfigEvent) => void;\n /**\n * The thread this binding serves. When set, the lane is read only from a\n * state that thread's own attach produced ({@link readThreadServerConfig}):\n * for the first render after a thread switch the client still projects the\n * previous thread's state, and adopting its lane would report the previous\n * thread's config and version as this thread's.\n */\n threadId?: string;\n}\n\nexport interface UseDeepAgentConfigResult {\n /** Reactive server config version (0 while the thread has never been configured). */\n configVersion: number;\n /** Reactive server-config lane, or `null` at version 0. */\n serverConfig: DeepAgentServerConfig | null;\n /**\n * The effective thread config: the server lane with this client's pending\n * writes folded over. `{}` at version 0 with nothing pending.\n */\n custom: ThreadConfigCustom;\n /** `true` while at least one `config/*` command is unacknowledged by the server. */\n hasPendingWrites: boolean;\n /** `config/patch` — set / unset top-level keys; `null` unsets. */\n patchConfig: (patch: ThreadConfigPatch) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/enable`. */\n enableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/disable`. */\n disableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n}\n\ntype ConfigCommand =\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch; patch: Record<string, unknown> }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable; toolIds: string[] }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable; toolIds: string[] };\n\n/**\n * The server-authoritative thread config of a deep-agent thread.\n *\n * Every capability a run depends on — model, agent binding, enabled tools,\n * sandbox, environment, … — lives on the thread's server config lane and is\n * changed only through the `config/*` commands. Sends carry per-send keys\n * only (`pickPerSendCustom`). The commands are applied optimistically: each\n * one folds its transform over the server config the moment it is issued\n * (`custom`), and retires once the lane reaches the version the server\n * assigned it; a rejection drops it, so the UI snaps back to the truth.\n *\n * Must be mounted under the thread's statewire context (an `AuiProvider`\n * holding `useDeepAgentThread`'s element), keyed by the thread identity so a\n * thread switch remounts it with an empty pending set. A binding that persists\n * what it reads per thread passes `threadId`, so the render that still sees\n * the previous thread's state after a switch reads no lane at all.\n */\nexport function useDeepAgentConfig({\n threadId,\n ...options\n}: UseDeepAgentConfigOptions = {}): UseDeepAgentConfigResult {\n const sendCommand = useStatewireSendCommand();\n const selectServerConfig = useCallback(\n (state: unknown) => readThreadServerConfig({ state, threadId }),\n [threadId]\n );\n const serverConfig = useStatewireState(selectServerConfig);\n return useDeepAgentConfigController({\n serverConfig,\n sendCommand: (command) => Promise.resolve(sendCommand(command as never)),\n ...options,\n });\n}\n\nexport interface DeepAgentConfigControllerInputs extends UseDeepAgentConfigOptions {\n serverConfig: DeepAgentServerConfig | null;\n sendCommand: (command: ConfigCommand) => Promise<unknown>;\n}\n\n/**\n * The transport-agnostic body of {@link useDeepAgentConfig}, with the reactive\n * inputs injected — so the optimistic-overlay behavior is testable without a\n * statewire session.\n */\nexport function useDeepAgentConfigController({\n serverConfig,\n sendCommand,\n onServerConfig,\n}: DeepAgentConfigControllerInputs): UseDeepAgentConfigResult {\n const [ops, setOps] = useState<readonly PendingOp[]>([]);\n const nextOpIdRef = useRef(1);\n const sendCommandRef = useRef(sendCommand);\n sendCommandRef.current = sendCommand;\n const onServerConfigRef = useRef(onServerConfig);\n onServerConfigRef.current = onServerConfig;\n\n const custom = useMemo(() => foldPendingConfigOps(serverConfig, ops), [serverConfig, ops]);\n\n // Retire ops the lane has caught up with (their transform is now part of\n // the server config itself).\n const serverVersion = serverConfig?.version ?? 0;\n const serverVersionRef = useRef(serverVersion);\n serverVersionRef.current = serverVersion;\n useEffect(() => {\n setOps((current) => {\n const kept = current.filter(\n (op) => op.settledVersion === null || op.settledVersion > serverVersion\n );\n return kept.length === current.length ? current : kept;\n });\n }, [serverVersion]);\n\n const lastNotifiedRef = useRef<DeepAgentServerConfig | null>(null);\n useEffect(() => {\n if (serverConfig === null || serverConfig === lastNotifiedRef.current) return;\n lastNotifiedRef.current = serverConfig;\n onServerConfigRef.current?.({ version: serverConfig.version, custom });\n }, [serverConfig, custom]);\n\n const run = useCallback(\n async (\n command: ConfigCommand,\n apply: PendingOp['apply']\n ): Promise<DeepAgentConfigWriteResult> => {\n const id = nextOpIdRef.current++;\n setOps((current) => [...current, { id, apply, settledVersion: null }]);\n try {\n const raw = (await sendCommandRef.current(command)) as\n | { version?: unknown; custom?: unknown }\n | null\n | undefined;\n const version = typeof raw?.version === 'number' ? raw.version : Number.POSITIVE_INFINITY;\n // The lane echo may have landed before the acknowledgement: retire\n // now if so, otherwise stamp the version for the retire effect.\n setOps((current) =>\n version <= serverVersionRef.current\n ? current.filter((op) => op.id !== id)\n : current.map((op) => (op.id === id ? { ...op, settledVersion: version } : op))\n );\n return {\n version: Number.isFinite(version) ? version : 0,\n custom: isRecord(raw?.custom) ? raw.custom : apply({}),\n };\n } catch (error) {\n setOps((current) => current.filter((op) => op.id !== id));\n throw error;\n }\n },\n []\n );\n\n const patchConfig = useCallback(\n (patch: ThreadConfigPatch) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.patch, patch }, (base) =>\n applyConfigPatch(base, patch)\n ),\n [run]\n );\n const enableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsEnable, toolIds: [...toolIds] }, (base) =>\n applyToolsEnable(base, toolIds)\n ),\n [run]\n );\n const disableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsDisable, toolIds: [...toolIds] }, (base) =>\n applyToolsDisable(base, toolIds)\n ),\n [run]\n );\n\n return {\n configVersion: serverVersion,\n serverConfig,\n custom,\n hasPendingWrites: ops.some((op) => op.settledVersion === null),\n patchConfig,\n enableTools,\n disableTools,\n };\n}\n"],"names":[],"mappings":";;;;;AAgDA,MAAM,WAAW,CAAC,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAS9D,SAAS,iBAAiB,OAA8C;AAC7E,QAAM,SAAU,+BAAmD;AACnE,MAAI,CAAC,SAAS,MAAM,EAAG,QAAO;AAC9B,QAAM,UAAU,OAAO;AACvB,MAAI,OAAO,YAAY,YAAY,CAAC,OAAO,UAAU,OAAO,KAAK,WAAW,EAAG,QAAO;AACtF,MAAI,CAAC,SAAS,OAAO,MAAM,EAAG,QAAO;AACrC,SAAO;AACT;AAgCA,MAAM,mDAAwD,IAAI;AAAA,EAChE;AAAA,EACA;AACF,CAAC;AASM,SAAS,gCAAgC,OAAyB;AACvE,QAAM,UAAU,0BAA0B,KAAK;AAC/C,QAAM,SAAS,mCAAS;AACxB,OAAI,mCAAS,YAAW,IAAK,SAAO,iCAAQ,UAAS;AACrD,OAAI,mCAAS,YAAW,IAAK,QAAO;AACpC,SAAO,QAAO,iCAAQ,UAAS,YAAY,6BAA6B,IAAI,OAAO,IAAI;AACzF;AAQO,SAAS,iCAAiC,OAAyB;AACxE,QAAM,UAAU,0BAA0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2B,cAAc,SAAS,CAAC,GAAG,OAAO,EAAA;AAAA,MAAK,CAAC,SAC7E,kBAAkB,MAAM,OAAO;AAAA,IAAA;AAAA,IAEnC,CAAC,GAAG;AAAA,EAAA;AAGN,SAAO;AAAA,IACL,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,kBAAkB,IAAI,KAAK,CAAC,OAAO,GAAG,mBAAmB,IAAI;AAAA,IAC7D;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
package/dist/chat/AthenaChat.cjs
CHANGED
|
@@ -261,7 +261,7 @@ const AthenaChat = ({
|
|
|
261
261
|
turnAnchor,
|
|
262
262
|
readOnly,
|
|
263
263
|
banners: /* @__PURE__ */ jsxRuntime.jsx(WaitingOnYouBanner.WaitingOnYouBanner, { className: "px-4 pt-3" }),
|
|
264
|
-
viewportClassName: "aui-thread-viewport relative flex flex-1 flex-col overflow-x-
|
|
264
|
+
viewportClassName: "aui-thread-viewport relative flex flex-1 flex-col overflow-x-hidden overflow-y-scroll overscroll-y-none scroll-smooth px-4 pt-4",
|
|
265
265
|
contentClassName: "flex w-full flex-1 flex-col",
|
|
266
266
|
viewportOverlay: /* @__PURE__ */ jsxRuntime.jsx(ThreadScrollToTop, {}),
|
|
267
267
|
welcome: /* @__PURE__ */ jsxRuntime.jsx(athenaChatWelcome.AthenaChatWelcome, { welcomeMessage, welcomeSubtext }),
|