@athenaintel/react 0.30.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/README.md +160 -9
  2. package/dist/agent-runtime/src/athena-asset-drag.cjs +44 -0
  3. package/dist/agent-runtime/src/athena-asset-drag.cjs.map +1 -0
  4. package/dist/agent-runtime/src/athena-asset-drag.js +44 -0
  5. package/dist/agent-runtime/src/athena-asset-drag.js.map +1 -0
  6. package/dist/agent-runtime/src/composer-markdown.cjs.map +1 -1
  7. package/dist/agent-runtime/src/composer-markdown.js.map +1 -1
  8. package/dist/agent-runtime/src/config-mutations.cjs +59 -0
  9. package/dist/agent-runtime/src/config-mutations.cjs.map +1 -0
  10. package/dist/agent-runtime/src/config-mutations.js +59 -0
  11. package/dist/agent-runtime/src/config-mutations.js.map +1 -0
  12. package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs +2 -3
  13. package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs.map +1 -1
  14. package/dist/agent-runtime/src/deep-agent-transport-recipe.js +3 -4
  15. package/dist/agent-runtime/src/deep-agent-transport-recipe.js.map +1 -1
  16. package/dist/agent-runtime/src/edit-command.cjs.map +1 -1
  17. package/dist/agent-runtime/src/edit-command.js.map +1 -1
  18. package/dist/agent-runtime/src/generated/runconfig-contract.cjs +6 -0
  19. package/dist/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
  20. package/dist/agent-runtime/src/generated/runconfig-contract.js +6 -0
  21. package/dist/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
  22. package/dist/agent-runtime/src/messages.cjs +57 -2
  23. package/dist/agent-runtime/src/messages.cjs.map +1 -1
  24. package/dist/agent-runtime/src/messages.js +57 -2
  25. package/dist/agent-runtime/src/messages.js.map +1 -1
  26. package/dist/agent-runtime/src/quota-safe-local-storage-session.cjs +72 -3
  27. package/dist/agent-runtime/src/quota-safe-local-storage-session.cjs.map +1 -1
  28. package/dist/agent-runtime/src/quota-safe-local-storage-session.js +73 -4
  29. package/dist/agent-runtime/src/quota-safe-local-storage-session.js.map +1 -1
  30. package/dist/agent-runtime/src/statewire-transport.cjs +4 -13
  31. package/dist/agent-runtime/src/statewire-transport.cjs.map +1 -1
  32. package/dist/agent-runtime/src/statewire-transport.js +5 -14
  33. package/dist/agent-runtime/src/statewire-transport.js.map +1 -1
  34. package/dist/agent-runtime/src/tool-metadata.cjs +26 -7
  35. package/dist/agent-runtime/src/tool-metadata.cjs.map +1 -1
  36. package/dist/agent-runtime/src/tool-metadata.js +26 -7
  37. package/dist/agent-runtime/src/tool-metadata.js.map +1 -1
  38. package/dist/agent-runtime/src/use-deep-agent-config.cjs +117 -1
  39. package/dist/agent-runtime/src/use-deep-agent-config.cjs.map +1 -1
  40. package/dist/agent-runtime/src/use-deep-agent-config.js +118 -2
  41. package/dist/agent-runtime/src/use-deep-agent-config.js.map +1 -1
  42. package/dist/agent-runtime/src/use-deep-agent-thread.cjs.map +1 -1
  43. package/dist/agent-runtime/src/use-deep-agent-thread.js.map +1 -1
  44. package/dist/assets/AthenaAssetEmbed.cjs +9 -2
  45. package/dist/assets/AthenaAssetEmbed.cjs.map +1 -1
  46. package/dist/assets/AthenaAssetEmbed.d.ts +9 -0
  47. package/dist/assets/AthenaAssetEmbed.js +11 -4
  48. package/dist/assets/AthenaAssetEmbed.js.map +1 -1
  49. package/dist/assets/asset-embed-messages.cjs +6 -0
  50. package/dist/assets/asset-embed-messages.cjs.map +1 -1
  51. package/dist/assets/asset-embed-messages.d.ts +7 -0
  52. package/dist/assets/asset-embed-messages.js +6 -0
  53. package/dist/assets/asset-embed-messages.js.map +1 -1
  54. package/dist/assets/use-asset-embed.cjs +71 -71
  55. package/dist/assets/use-asset-embed.cjs.map +1 -1
  56. package/dist/assets/use-asset-embed.d.ts +20 -7
  57. package/dist/assets/use-asset-embed.js +72 -72
  58. package/dist/assets/use-asset-embed.js.map +1 -1
  59. package/dist/catalog/agent-model-options.cjs +122 -0
  60. package/dist/catalog/agent-model-options.cjs.map +1 -0
  61. package/dist/catalog/agent-model-options.d.ts +115 -0
  62. package/dist/catalog/agent-model-options.js +122 -0
  63. package/dist/catalog/agent-model-options.js.map +1 -0
  64. package/dist/catalog/chat-pickers.cjs +184 -4
  65. package/dist/catalog/chat-pickers.cjs.map +1 -1
  66. package/dist/catalog/chat-pickers.d.ts +27 -3
  67. package/dist/catalog/chat-pickers.js +187 -7
  68. package/dist/catalog/chat-pickers.js.map +1 -1
  69. package/dist/catalog/runtime-catalog.cjs +117 -3
  70. package/dist/catalog/runtime-catalog.cjs.map +1 -1
  71. package/dist/catalog/runtime-catalog.d.ts +104 -0
  72. package/dist/catalog/runtime-catalog.js +119 -5
  73. package/dist/catalog/runtime-catalog.js.map +1 -1
  74. package/dist/chat/AthenaChat.cjs +41 -26
  75. package/dist/chat/AthenaChat.cjs.map +1 -1
  76. package/dist/chat/AthenaChat.d.ts +8 -7
  77. package/dist/chat/AthenaChat.js +41 -26
  78. package/dist/chat/AthenaChat.js.map +1 -1
  79. package/dist/chat/super-grouping/SuperGroupingCard.cjs +61 -14
  80. package/dist/chat/super-grouping/SuperGroupingCard.cjs.map +1 -1
  81. package/dist/chat/super-grouping/SuperGroupingCard.d.ts +26 -12
  82. package/dist/chat/super-grouping/SuperGroupingCard.js +63 -16
  83. package/dist/chat/super-grouping/SuperGroupingCard.js.map +1 -1
  84. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs +80 -53
  85. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs.map +1 -1
  86. package/dist/chat/super-grouping/SuperGroupingTranscript.d.ts +10 -10
  87. package/dist/chat/super-grouping/SuperGroupingTranscript.js +81 -54
  88. package/dist/chat/super-grouping/SuperGroupingTranscript.js.map +1 -1
  89. package/dist/chat/super-grouping/activity-timeline.cjs +19 -4
  90. package/dist/chat/super-grouping/activity-timeline.cjs.map +1 -1
  91. package/dist/chat/super-grouping/activity-timeline.d.ts +24 -5
  92. package/dist/chat/super-grouping/activity-timeline.js +19 -4
  93. package/dist/chat/super-grouping/activity-timeline.js.map +1 -1
  94. package/dist/chat/super-grouping/index.cjs +2 -0
  95. package/dist/chat/super-grouping/index.cjs.map +1 -1
  96. package/dist/chat/super-grouping/index.d.ts +7 -6
  97. package/dist/chat/super-grouping/index.js +3 -1
  98. package/dist/chat/super-grouping/toolkit-map.cjs +4 -1
  99. package/dist/chat/super-grouping/toolkit-map.cjs.map +1 -1
  100. package/dist/chat/super-grouping/toolkit-map.js +4 -1
  101. package/dist/chat/super-grouping/toolkit-map.js.map +1 -1
  102. package/dist/chat-ui/composer/tiptap-composer.cjs +40 -4
  103. package/dist/chat-ui/composer/tiptap-composer.cjs.map +1 -1
  104. package/dist/chat-ui/composer/tiptap-composer.js +40 -4
  105. package/dist/chat-ui/composer/tiptap-composer.js.map +1 -1
  106. package/dist/chat-ui/index.cjs +1 -0
  107. package/dist/chat-ui/index.cjs.map +1 -1
  108. package/dist/chat-ui/index.d.ts +1 -1
  109. package/dist/chat-ui/index.js +2 -1
  110. package/dist/chat-ui/mentions/mention-chip.cjs +29 -2
  111. package/dist/chat-ui/mentions/mention-chip.cjs.map +1 -1
  112. package/dist/chat-ui/mentions/mention-chip.d.ts +2 -5
  113. package/dist/chat-ui/mentions/mention-chip.js +30 -3
  114. package/dist/chat-ui/mentions/mention-chip.js.map +1 -1
  115. package/dist/chat-ui/mentions/mention-extension.cjs +1 -1
  116. package/dist/chat-ui/mentions/mention-extension.cjs.map +1 -1
  117. package/dist/chat-ui/mentions/mention-extension.js +1 -1
  118. package/dist/chat-ui/mentions/mention-extension.js.map +1 -1
  119. package/dist/chat-ui/mentions/suggestions/data/api-client.cjs +33 -2
  120. package/dist/chat-ui/mentions/suggestions/data/api-client.cjs.map +1 -1
  121. package/dist/chat-ui/mentions/suggestions/data/api-client.d.ts +14 -0
  122. package/dist/chat-ui/mentions/suggestions/data/api-client.js +33 -2
  123. package/dist/chat-ui/mentions/suggestions/data/api-client.js.map +1 -1
  124. package/dist/chat-ui/mentions/use-account-workspace-id.cjs +61 -0
  125. package/dist/chat-ui/mentions/use-account-workspace-id.cjs.map +1 -0
  126. package/dist/chat-ui/mentions/use-account-workspace-id.d.ts +3 -0
  127. package/dist/chat-ui/mentions/use-account-workspace-id.js +61 -0
  128. package/dist/chat-ui/mentions/use-account-workspace-id.js.map +1 -0
  129. package/dist/chat-ui/mentions/use-member-avatar.cjs +75 -0
  130. package/dist/chat-ui/mentions/use-member-avatar.cjs.map +1 -0
  131. package/dist/chat-ui/mentions/use-member-avatar.d.ts +2 -0
  132. package/dist/chat-ui/mentions/use-member-avatar.js +75 -0
  133. package/dist/chat-ui/mentions/use-member-avatar.js.map +1 -0
  134. package/dist/collab/client.cjs +80 -19
  135. package/dist/collab/client.cjs.map +1 -1
  136. package/dist/collab/client.d.ts +22 -0
  137. package/dist/collab/client.js +80 -19
  138. package/dist/collab/client.js.map +1 -1
  139. package/dist/diagnostics/athena-diagnostics.cjs.map +1 -1
  140. package/dist/diagnostics/athena-diagnostics.d.ts +3 -1
  141. package/dist/diagnostics/athena-diagnostics.js.map +1 -1
  142. package/dist/index.cjs +5 -0
  143. package/dist/index.cjs.map +1 -1
  144. package/dist/index.d.ts +6 -3
  145. package/dist/index.js +7 -2
  146. package/dist/index.js.map +1 -1
  147. package/dist/lib/use-athena-rest-query.cjs +4 -0
  148. package/dist/lib/use-athena-rest-query.cjs.map +1 -1
  149. package/dist/lib/use-athena-rest-query.d.ts +6 -0
  150. package/dist/lib/use-athena-rest-query.js +4 -0
  151. package/dist/lib/use-athena-rest-query.js.map +1 -1
  152. package/dist/provider/AthenaProvider.cjs +57 -6
  153. package/dist/provider/AthenaProvider.cjs.map +1 -1
  154. package/dist/provider/AthenaProvider.d.ts +21 -5
  155. package/dist/provider/AthenaProvider.js +59 -8
  156. package/dist/provider/AthenaProvider.js.map +1 -1
  157. package/dist/provider/agent-selection-context.cjs +6 -0
  158. package/dist/provider/agent-selection-context.cjs.map +1 -0
  159. package/dist/provider/agent-selection-context.d.ts +14 -0
  160. package/dist/provider/agent-selection-context.js +6 -0
  161. package/dist/provider/agent-selection-context.js.map +1 -0
  162. package/dist/react/package.json.cjs +1 -1
  163. package/dist/react/package.json.js +1 -1
  164. package/dist/runtime/StatewireThreadConfigLaneSync.cjs +125 -0
  165. package/dist/runtime/StatewireThreadConfigLaneSync.cjs.map +1 -0
  166. package/dist/runtime/StatewireThreadConfigLaneSync.d.ts +54 -0
  167. package/dist/runtime/StatewireThreadConfigLaneSync.js +125 -0
  168. package/dist/runtime/StatewireThreadConfigLaneSync.js.map +1 -0
  169. package/dist/runtime/statewire-lifecycle.cjs +5 -2
  170. package/dist/runtime/statewire-lifecycle.cjs.map +1 -1
  171. package/dist/runtime/statewire-lifecycle.d.ts +5 -0
  172. package/dist/runtime/statewire-lifecycle.js +5 -2
  173. package/dist/runtime/statewire-lifecycle.js.map +1 -1
  174. package/dist/runtime/statewire-model-lane.cjs +16 -0
  175. package/dist/runtime/statewire-model-lane.cjs.map +1 -0
  176. package/dist/runtime/statewire-model-lane.d.ts +66 -0
  177. package/dist/runtime/statewire-model-lane.js +16 -0
  178. package/dist/runtime/statewire-model-lane.js.map +1 -0
  179. package/dist/runtime/statewire-run-config.cjs +16 -2
  180. package/dist/runtime/statewire-run-config.cjs.map +1 -1
  181. package/dist/runtime/statewire-run-config.d.ts +10 -0
  182. package/dist/runtime/statewire-run-config.js +16 -2
  183. package/dist/runtime/statewire-run-config.js.map +1 -1
  184. package/dist/runtime/statewire-server-lane-context.cjs +24 -0
  185. package/dist/runtime/statewire-server-lane-context.cjs.map +1 -0
  186. package/dist/runtime/statewire-server-lane-context.d.ts +30 -0
  187. package/dist/runtime/statewire-server-lane-context.js +24 -0
  188. package/dist/runtime/statewire-server-lane-context.js.map +1 -0
  189. package/dist/runtime/statewire-thread-config-lane.cjs +84 -0
  190. package/dist/runtime/statewire-thread-config-lane.cjs.map +1 -0
  191. package/dist/runtime/statewire-thread-config-lane.d.ts +94 -0
  192. package/dist/runtime/statewire-thread-config-lane.js +84 -0
  193. package/dist/runtime/statewire-thread-config-lane.js.map +1 -0
  194. package/dist/runtime/useAthenaStatewireRuntime.cjs +38 -18
  195. package/dist/runtime/useAthenaStatewireRuntime.cjs.map +1 -1
  196. package/dist/runtime/useAthenaStatewireRuntime.d.ts +8 -1
  197. package/dist/runtime/useAthenaStatewireRuntime.js +39 -19
  198. package/dist/runtime/useAthenaStatewireRuntime.js.map +1 -1
  199. package/dist/styles.css +1 -1
  200. package/dist/threads/api.cjs +2 -1
  201. package/dist/threads/api.cjs.map +1 -1
  202. package/dist/threads/api.d.ts +1 -0
  203. package/dist/threads/api.js +2 -1
  204. package/dist/threads/api.js.map +1 -1
  205. package/dist/threads/use-athena-thread-model.cjs +22 -0
  206. package/dist/threads/use-athena-thread-model.cjs.map +1 -0
  207. package/dist/threads/use-athena-thread-model.d.ts +27 -0
  208. package/dist/threads/use-athena-thread-model.js +22 -0
  209. package/dist/threads/use-athena-thread-model.js.map +1 -0
  210. package/package.json +4 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatewireThreadConfigLaneSync.cjs","sources":["../../src/runtime/StatewireThreadConfigLaneSync.tsx"],"sourcesContent":["import { useStatewireSendCommand } from '@assistant-ui/react-statewire';\nimport {\n type DeepAgentConfigControllerInputs,\n isConfigSyncUnavailableRejection,\n isConfigWriteForbiddenRejection,\n statewireTransportOutcome,\n useDeepAgentConfigController,\n} from '@athenaintel/agent-runtime';\nimport { useEffect, useRef, useState } from 'react';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport type { AthenaStatewireServerLane } from './statewire-server-lane-context';\nimport {\n decideThreadConfigLanePatch,\n PROVIDER_THREAD_CONFIG_KEYS,\n type ProviderThreadConfig,\n type ProviderThreadConfigKey,\n type ProviderThreadConfigPatch,\n patchedThreadConfigKeys,\n sameThreadConfigValue,\n} from './statewire-thread-config-lane';\n\n/** Writes of one change, the first included, before the sync gives up on it. */\nconst MAX_PATCH_ATTEMPTS_PER_CHANGE = 3;\n\n/** Wait before re-writing a change the channel dropped: 1 s, then 4 s. */\nconst RETRY_BACKOFF_MS = [1_000, 4_000] as const;\n\n/**\n * What a `statewire.config` event says about a write: the thread, the model it\n * set (`null`: unset), and the other provider-owned keys it set\n * (`config_keys`), never their values (a system prompt is the host's text).\n */\nfunction configWriteData({\n threadId,\n patch,\n}: {\n threadId: string;\n patch: ProviderThreadConfigPatch;\n}): Record<string, unknown> {\n const otherKeys = patchedThreadConfigKeys(patch).filter((key) => key !== 'model');\n return {\n thread_id: threadId,\n ...(Object.hasOwn(patch, 'model') && { model: patch.model }),\n ...(otherKeys.length > 0 && { config_keys: otherKeys }),\n };\n}\n\n/**\n * Writes the provider-owned thread-config keys to the thread's server config\n * lane when the host changes the props that feed them during an attach:\n * `model`, `systemPrompt` (`system_prompt`), `tools` and `frontendTools`\n * (`enabled_tools`), `workbench` and `knowledgeBase` (`knowledge_base`).\n *\n * Once a thread has a lane (version > 0), agora composes every run from the\n * lane and drops the thread-config keys a send carries, so a model, prompt,\n * tool list or asset list changed after the thread's first turn would never\n * apply. A change of such a prop therefore becomes one `config/patch`\n * carrying exactly the changed keys, each with the value the send would carry\n * (`null` when the send carries none: the key is unset, so the collab agent's\n * own value, or the default, applies). An empty tool or asset list is `null`,\n * as the send omits it.\n *\n * Only a CHANGE is written. A prop's value when the attach starts is never\n * written, even when the lane holds another value: that value is another\n * client's (or an earlier session's) choice for this thread, and an SDK app's\n * global setting must not overwrite it just by opening the thread. Hosts that\n * want the picker to follow the thread read `useAthenaThreadModel`.\n *\n * Decisions read the lane the host itself sent on this attach (`lane`, from\n * the transport), never the rendered thread state: before the attach snapshot\n * lands that state is a placeholder without a lane, or a remembered snapshot\n * with an older one, and comparing a change against either would write over\n * the session's real config. A change made before the snapshot lands waits\n * for it.\n *\n * A version-0 thread needs no write: the next send carries the values and\n * agora's deferral seed persists them. A change stays pending until the lane\n * exists, so a lane an earlier send seeds with the previous values is\n * corrected when it lands. A refusal that can never succeed (a view-only\n * collaborator, a workspace without server config) stops the sync for the\n * attach and is reported on the diagnostics bus. A write the channel dropped\n * (a lost stream, the host's expired verdict) stays pending and is written\n * again after a backoff once the channel is live, at most\n * {@link MAX_PATCH_ATTEMPTS_PER_CHANGE} times per change.\n *\n * The writes go through the `config/*` command family, which agora gates on\n * EDIT on the thread's session asset (`_authorize_config_write`).\n *\n * Mounted under the runtime's `AuiProvider`, keyed by the thread, so each\n * attach starts with nothing pending.\n */\nexport function StatewireThreadConfigLaneSync({\n threadId,\n config,\n lane,\n channelLive,\n}: {\n threadId: string;\n /** The values this thread's sends carry, published with the thread (see the provider). */\n config: ProviderThreadConfig;\n lane: AthenaStatewireServerLane;\n /** Whether the channel can take a command now; writes wait for it. */\n channelLive: boolean;\n}): null {\n const send = useStatewireSendCommand();\n const sendCommand: DeepAgentConfigControllerInputs['sendCommand'] = (command) =>\n Promise.resolve(send(command));\n const { configVersion, custom, patchConfig } = useDeepAgentConfigController({\n serverConfig: lane.config,\n sendCommand,\n });\n\n const seenRef = useRef(config);\n const pendingRef = useRef(new Set<ProviderThreadConfigKey>());\n const attemptsRef = useRef(new Map<ProviderThreadConfigKey, number>());\n const closedRef = useRef(false);\n const patchConfigRef = useRef(patchConfig);\n patchConfigRef.current = patchConfig;\n // Bumped (after a backoff) to re-run the effect for a write the channel dropped.\n const [retryTick, setRetryTick] = useState(0);\n const retryTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n useEffect(\n () => () => {\n if (retryTimerRef.current !== null) clearTimeout(retryTimerRef.current);\n },\n [],\n );\n const landed = lane.landed;\n\n useEffect(() => {\n const pending = pendingRef.current;\n const attempts = attemptsRef.current;\n for (const key of PROVIDER_THREAD_CONFIG_KEYS) {\n if (sameThreadConfigValue(config[key], seenRef.current[key])) continue;\n pending.add(key);\n attempts.set(key, 0);\n }\n seenRef.current = config;\n if (pending.size === 0 || closedRef.current || !channelLive) return;\n const decision = decideThreadConfigLanePatch({\n desired: config,\n keys: pending,\n landed,\n configVersion,\n custom,\n });\n if (decision.kind === 'wait') return;\n pending.clear();\n if (decision.kind === 'done') return;\n\n const { patch } = decision;\n const patchKeys = patchedThreadConfigKeys(patch);\n for (const key of patchKeys) attempts.set(key, (attempts.get(key) ?? 0) + 1);\n const modelOnly = patchKeys.length === 1 && patchKeys[0] === 'model';\n patchConfigRef.current(patch).catch((error: unknown) => {\n const data = configWriteData({ threadId, patch });\n if (isConfigWriteForbiddenRejection(error) || isConfigSyncUnavailableRejection(error)) {\n closedRef.current = true;\n athenaDiagnostics.emit('statewire.config', {\n level: 'warn',\n data: {\n ...data,\n reason: isConfigWriteForbiddenRejection(error)\n ? 'config_write_forbidden'\n : 'config_sync_unavailable',\n },\n });\n return;\n }\n const outcome = statewireTransportOutcome(error);\n if (outcome !== null) {\n // Channel weather (a dropped stream, the host's expired verdict): keep\n // each change pending and write it again after a backoff, once the\n // channel is live, unless its prop has moved on or the attach is gone.\n athenaDiagnostics.emit('statewire.config', {\n level: 'debug',\n data: { ...data, outcome },\n });\n if (outcome === 'unmount') return;\n const retryKeys = patchKeys.filter(\n (key) =>\n sameThreadConfigValue(seenRef.current[key], patch[key] ?? null) &&\n (attempts.get(key) ?? 0) < MAX_PATCH_ATTEMPTS_PER_CHANGE,\n );\n if (retryKeys.length === 0) return;\n for (const key of retryKeys) pendingRef.current.add(key);\n const written = Math.max(...retryKeys.map((key) => attempts.get(key) ?? 1));\n const delay = RETRY_BACKOFF_MS[Math.min(written - 1, RETRY_BACKOFF_MS.length - 1)];\n retryTimerRef.current = setTimeout(() => {\n retryTimerRef.current = null;\n setRetryTick((tick) => tick + 1);\n }, delay);\n return;\n }\n athenaDiagnostics.error(\n 'statewire.config',\n error,\n modelOnly\n ? {\n code: 'statewire_rejected',\n message: 'The statewire host refused the model change',\n hint: 'Inspect error.detail: agora rejections carry a structured {code, message}. The thread keeps running with the model its server config holds.',\n }\n : {\n code: 'statewire_rejected',\n message: 'The statewire host refused the thread config change',\n hint: 'Inspect error.detail: agora rejections carry a structured {code, message}. The thread keeps running with the config its server config holds.',\n },\n data,\n );\n });\n }, [config, landed, configVersion, custom, channelLive, retryTick, threadId]);\n\n return null;\n}\n"],"names":["patchedThreadConfigKeys","useStatewireSendCommand","useDeepAgentConfigController","useRef","useState","useEffect","PROVIDER_THREAD_CONFIG_KEYS","sameThreadConfigValue","decideThreadConfigLanePatch","isConfigWriteForbiddenRejection","isConfigSyncUnavailableRejection","athenaDiagnostics","statewireTransportOutcome"],"mappings":"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"}
@@ -0,0 +1,54 @@
1
+ import type { AthenaStatewireServerLane } from './statewire-server-lane-context';
2
+ import { type ProviderThreadConfig } from './statewire-thread-config-lane';
3
+ /**
4
+ * Writes the provider-owned thread-config keys to the thread's server config
5
+ * lane when the host changes the props that feed them during an attach:
6
+ * `model`, `systemPrompt` (`system_prompt`), `tools` and `frontendTools`
7
+ * (`enabled_tools`), `workbench` and `knowledgeBase` (`knowledge_base`).
8
+ *
9
+ * Once a thread has a lane (version > 0), agora composes every run from the
10
+ * lane and drops the thread-config keys a send carries, so a model, prompt,
11
+ * tool list or asset list changed after the thread's first turn would never
12
+ * apply. A change of such a prop therefore becomes one `config/patch`
13
+ * carrying exactly the changed keys, each with the value the send would carry
14
+ * (`null` when the send carries none: the key is unset, so the collab agent's
15
+ * own value, or the default, applies). An empty tool or asset list is `null`,
16
+ * as the send omits it.
17
+ *
18
+ * Only a CHANGE is written. A prop's value when the attach starts is never
19
+ * written, even when the lane holds another value: that value is another
20
+ * client's (or an earlier session's) choice for this thread, and an SDK app's
21
+ * global setting must not overwrite it just by opening the thread. Hosts that
22
+ * want the picker to follow the thread read `useAthenaThreadModel`.
23
+ *
24
+ * Decisions read the lane the host itself sent on this attach (`lane`, from
25
+ * the transport), never the rendered thread state: before the attach snapshot
26
+ * lands that state is a placeholder without a lane, or a remembered snapshot
27
+ * with an older one, and comparing a change against either would write over
28
+ * the session's real config. A change made before the snapshot lands waits
29
+ * for it.
30
+ *
31
+ * A version-0 thread needs no write: the next send carries the values and
32
+ * agora's deferral seed persists them. A change stays pending until the lane
33
+ * exists, so a lane an earlier send seeds with the previous values is
34
+ * corrected when it lands. A refusal that can never succeed (a view-only
35
+ * collaborator, a workspace without server config) stops the sync for the
36
+ * attach and is reported on the diagnostics bus. A write the channel dropped
37
+ * (a lost stream, the host's expired verdict) stays pending and is written
38
+ * again after a backoff once the channel is live, at most
39
+ * {@link MAX_PATCH_ATTEMPTS_PER_CHANGE} times per change.
40
+ *
41
+ * The writes go through the `config/*` command family, which agora gates on
42
+ * EDIT on the thread's session asset (`_authorize_config_write`).
43
+ *
44
+ * Mounted under the runtime's `AuiProvider`, keyed by the thread, so each
45
+ * attach starts with nothing pending.
46
+ */
47
+ export declare function StatewireThreadConfigLaneSync({ threadId, config, lane, channelLive, }: {
48
+ threadId: string;
49
+ /** The values this thread's sends carry, published with the thread (see the provider). */
50
+ config: ProviderThreadConfig;
51
+ lane: AthenaStatewireServerLane;
52
+ /** Whether the channel can take a command now; writes wait for it. */
53
+ channelLive: boolean;
54
+ }): null;
@@ -0,0 +1,125 @@
1
+ import { useStatewireSendCommand } from "@assistant-ui/react-statewire";
2
+ import { useRef, useState, useEffect } from "react";
3
+ import { athenaDiagnostics } from "../diagnostics/athena-diagnostics.js";
4
+ import { PROVIDER_THREAD_CONFIG_KEYS, sameThreadConfigValue, decideThreadConfigLanePatch, patchedThreadConfigKeys } from "./statewire-thread-config-lane.js";
5
+ import { useDeepAgentConfigController, isConfigWriteForbiddenRejection, isConfigSyncUnavailableRejection } from "../agent-runtime/src/use-deep-agent-config.js";
6
+ import { statewireTransportOutcome } from "../agent-runtime/src/errors.js";
7
+ const MAX_PATCH_ATTEMPTS_PER_CHANGE = 3;
8
+ const RETRY_BACKOFF_MS = [1e3, 4e3];
9
+ function configWriteData({
10
+ threadId,
11
+ patch
12
+ }) {
13
+ const otherKeys = patchedThreadConfigKeys(patch).filter((key) => key !== "model");
14
+ return {
15
+ thread_id: threadId,
16
+ ...Object.hasOwn(patch, "model") && { model: patch.model },
17
+ ...otherKeys.length > 0 && { config_keys: otherKeys }
18
+ };
19
+ }
20
+ function StatewireThreadConfigLaneSync({
21
+ threadId,
22
+ config,
23
+ lane,
24
+ channelLive
25
+ }) {
26
+ const send = useStatewireSendCommand();
27
+ const sendCommand = (command) => Promise.resolve(send(command));
28
+ const { configVersion, custom, patchConfig } = useDeepAgentConfigController({
29
+ serverConfig: lane.config,
30
+ sendCommand
31
+ });
32
+ const seenRef = useRef(config);
33
+ const pendingRef = useRef(/* @__PURE__ */ new Set());
34
+ const attemptsRef = useRef(/* @__PURE__ */ new Map());
35
+ const closedRef = useRef(false);
36
+ const patchConfigRef = useRef(patchConfig);
37
+ patchConfigRef.current = patchConfig;
38
+ const [retryTick, setRetryTick] = useState(0);
39
+ const retryTimerRef = useRef(null);
40
+ useEffect(
41
+ () => () => {
42
+ if (retryTimerRef.current !== null) clearTimeout(retryTimerRef.current);
43
+ },
44
+ []
45
+ );
46
+ const landed = lane.landed;
47
+ useEffect(() => {
48
+ const pending = pendingRef.current;
49
+ const attempts = attemptsRef.current;
50
+ for (const key of PROVIDER_THREAD_CONFIG_KEYS) {
51
+ if (sameThreadConfigValue(config[key], seenRef.current[key])) continue;
52
+ pending.add(key);
53
+ attempts.set(key, 0);
54
+ }
55
+ seenRef.current = config;
56
+ if (pending.size === 0 || closedRef.current || !channelLive) return;
57
+ const decision = decideThreadConfigLanePatch({
58
+ desired: config,
59
+ keys: pending,
60
+ landed,
61
+ configVersion,
62
+ custom
63
+ });
64
+ if (decision.kind === "wait") return;
65
+ pending.clear();
66
+ if (decision.kind === "done") return;
67
+ const { patch } = decision;
68
+ const patchKeys = patchedThreadConfigKeys(patch);
69
+ for (const key of patchKeys) attempts.set(key, (attempts.get(key) ?? 0) + 1);
70
+ const modelOnly = patchKeys.length === 1 && patchKeys[0] === "model";
71
+ patchConfigRef.current(patch).catch((error) => {
72
+ const data = configWriteData({ threadId, patch });
73
+ if (isConfigWriteForbiddenRejection(error) || isConfigSyncUnavailableRejection(error)) {
74
+ closedRef.current = true;
75
+ athenaDiagnostics.emit("statewire.config", {
76
+ level: "warn",
77
+ data: {
78
+ ...data,
79
+ reason: isConfigWriteForbiddenRejection(error) ? "config_write_forbidden" : "config_sync_unavailable"
80
+ }
81
+ });
82
+ return;
83
+ }
84
+ const outcome = statewireTransportOutcome(error);
85
+ if (outcome !== null) {
86
+ athenaDiagnostics.emit("statewire.config", {
87
+ level: "debug",
88
+ data: { ...data, outcome }
89
+ });
90
+ if (outcome === "unmount") return;
91
+ const retryKeys = patchKeys.filter(
92
+ (key) => sameThreadConfigValue(seenRef.current[key], patch[key] ?? null) && (attempts.get(key) ?? 0) < MAX_PATCH_ATTEMPTS_PER_CHANGE
93
+ );
94
+ if (retryKeys.length === 0) return;
95
+ for (const key of retryKeys) pendingRef.current.add(key);
96
+ const written = Math.max(...retryKeys.map((key) => attempts.get(key) ?? 1));
97
+ const delay = RETRY_BACKOFF_MS[Math.min(written - 1, RETRY_BACKOFF_MS.length - 1)];
98
+ retryTimerRef.current = setTimeout(() => {
99
+ retryTimerRef.current = null;
100
+ setRetryTick((tick) => tick + 1);
101
+ }, delay);
102
+ return;
103
+ }
104
+ athenaDiagnostics.error(
105
+ "statewire.config",
106
+ error,
107
+ modelOnly ? {
108
+ code: "statewire_rejected",
109
+ message: "The statewire host refused the model change",
110
+ hint: "Inspect error.detail: agora rejections carry a structured {code, message}. The thread keeps running with the model its server config holds."
111
+ } : {
112
+ code: "statewire_rejected",
113
+ message: "The statewire host refused the thread config change",
114
+ hint: "Inspect error.detail: agora rejections carry a structured {code, message}. The thread keeps running with the config its server config holds."
115
+ },
116
+ data
117
+ );
118
+ });
119
+ }, [config, landed, configVersion, custom, channelLive, retryTick, threadId]);
120
+ return null;
121
+ }
122
+ export {
123
+ StatewireThreadConfigLaneSync
124
+ };
125
+ //# sourceMappingURL=StatewireThreadConfigLaneSync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatewireThreadConfigLaneSync.js","sources":["../../src/runtime/StatewireThreadConfigLaneSync.tsx"],"sourcesContent":["import { useStatewireSendCommand } from '@assistant-ui/react-statewire';\nimport {\n type DeepAgentConfigControllerInputs,\n isConfigSyncUnavailableRejection,\n isConfigWriteForbiddenRejection,\n statewireTransportOutcome,\n useDeepAgentConfigController,\n} from '@athenaintel/agent-runtime';\nimport { useEffect, useRef, useState } from 'react';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport type { AthenaStatewireServerLane } from './statewire-server-lane-context';\nimport {\n decideThreadConfigLanePatch,\n PROVIDER_THREAD_CONFIG_KEYS,\n type ProviderThreadConfig,\n type ProviderThreadConfigKey,\n type ProviderThreadConfigPatch,\n patchedThreadConfigKeys,\n sameThreadConfigValue,\n} from './statewire-thread-config-lane';\n\n/** Writes of one change, the first included, before the sync gives up on it. */\nconst MAX_PATCH_ATTEMPTS_PER_CHANGE = 3;\n\n/** Wait before re-writing a change the channel dropped: 1 s, then 4 s. */\nconst RETRY_BACKOFF_MS = [1_000, 4_000] as const;\n\n/**\n * What a `statewire.config` event says about a write: the thread, the model it\n * set (`null`: unset), and the other provider-owned keys it set\n * (`config_keys`), never their values (a system prompt is the host's text).\n */\nfunction configWriteData({\n threadId,\n patch,\n}: {\n threadId: string;\n patch: ProviderThreadConfigPatch;\n}): Record<string, unknown> {\n const otherKeys = patchedThreadConfigKeys(patch).filter((key) => key !== 'model');\n return {\n thread_id: threadId,\n ...(Object.hasOwn(patch, 'model') && { model: patch.model }),\n ...(otherKeys.length > 0 && { config_keys: otherKeys }),\n };\n}\n\n/**\n * Writes the provider-owned thread-config keys to the thread's server config\n * lane when the host changes the props that feed them during an attach:\n * `model`, `systemPrompt` (`system_prompt`), `tools` and `frontendTools`\n * (`enabled_tools`), `workbench` and `knowledgeBase` (`knowledge_base`).\n *\n * Once a thread has a lane (version > 0), agora composes every run from the\n * lane and drops the thread-config keys a send carries, so a model, prompt,\n * tool list or asset list changed after the thread's first turn would never\n * apply. A change of such a prop therefore becomes one `config/patch`\n * carrying exactly the changed keys, each with the value the send would carry\n * (`null` when the send carries none: the key is unset, so the collab agent's\n * own value, or the default, applies). An empty tool or asset list is `null`,\n * as the send omits it.\n *\n * Only a CHANGE is written. A prop's value when the attach starts is never\n * written, even when the lane holds another value: that value is another\n * client's (or an earlier session's) choice for this thread, and an SDK app's\n * global setting must not overwrite it just by opening the thread. Hosts that\n * want the picker to follow the thread read `useAthenaThreadModel`.\n *\n * Decisions read the lane the host itself sent on this attach (`lane`, from\n * the transport), never the rendered thread state: before the attach snapshot\n * lands that state is a placeholder without a lane, or a remembered snapshot\n * with an older one, and comparing a change against either would write over\n * the session's real config. A change made before the snapshot lands waits\n * for it.\n *\n * A version-0 thread needs no write: the next send carries the values and\n * agora's deferral seed persists them. A change stays pending until the lane\n * exists, so a lane an earlier send seeds with the previous values is\n * corrected when it lands. A refusal that can never succeed (a view-only\n * collaborator, a workspace without server config) stops the sync for the\n * attach and is reported on the diagnostics bus. A write the channel dropped\n * (a lost stream, the host's expired verdict) stays pending and is written\n * again after a backoff once the channel is live, at most\n * {@link MAX_PATCH_ATTEMPTS_PER_CHANGE} times per change.\n *\n * The writes go through the `config/*` command family, which agora gates on\n * EDIT on the thread's session asset (`_authorize_config_write`).\n *\n * Mounted under the runtime's `AuiProvider`, keyed by the thread, so each\n * attach starts with nothing pending.\n */\nexport function StatewireThreadConfigLaneSync({\n threadId,\n config,\n lane,\n channelLive,\n}: {\n threadId: string;\n /** The values this thread's sends carry, published with the thread (see the provider). */\n config: ProviderThreadConfig;\n lane: AthenaStatewireServerLane;\n /** Whether the channel can take a command now; writes wait for it. */\n channelLive: boolean;\n}): null {\n const send = useStatewireSendCommand();\n const sendCommand: DeepAgentConfigControllerInputs['sendCommand'] = (command) =>\n Promise.resolve(send(command));\n const { configVersion, custom, patchConfig } = useDeepAgentConfigController({\n serverConfig: lane.config,\n sendCommand,\n });\n\n const seenRef = useRef(config);\n const pendingRef = useRef(new Set<ProviderThreadConfigKey>());\n const attemptsRef = useRef(new Map<ProviderThreadConfigKey, number>());\n const closedRef = useRef(false);\n const patchConfigRef = useRef(patchConfig);\n patchConfigRef.current = patchConfig;\n // Bumped (after a backoff) to re-run the effect for a write the channel dropped.\n const [retryTick, setRetryTick] = useState(0);\n const retryTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n useEffect(\n () => () => {\n if (retryTimerRef.current !== null) clearTimeout(retryTimerRef.current);\n },\n [],\n );\n const landed = lane.landed;\n\n useEffect(() => {\n const pending = pendingRef.current;\n const attempts = attemptsRef.current;\n for (const key of PROVIDER_THREAD_CONFIG_KEYS) {\n if (sameThreadConfigValue(config[key], seenRef.current[key])) continue;\n pending.add(key);\n attempts.set(key, 0);\n }\n seenRef.current = config;\n if (pending.size === 0 || closedRef.current || !channelLive) return;\n const decision = decideThreadConfigLanePatch({\n desired: config,\n keys: pending,\n landed,\n configVersion,\n custom,\n });\n if (decision.kind === 'wait') return;\n pending.clear();\n if (decision.kind === 'done') return;\n\n const { patch } = decision;\n const patchKeys = patchedThreadConfigKeys(patch);\n for (const key of patchKeys) attempts.set(key, (attempts.get(key) ?? 0) + 1);\n const modelOnly = patchKeys.length === 1 && patchKeys[0] === 'model';\n patchConfigRef.current(patch).catch((error: unknown) => {\n const data = configWriteData({ threadId, patch });\n if (isConfigWriteForbiddenRejection(error) || isConfigSyncUnavailableRejection(error)) {\n closedRef.current = true;\n athenaDiagnostics.emit('statewire.config', {\n level: 'warn',\n data: {\n ...data,\n reason: isConfigWriteForbiddenRejection(error)\n ? 'config_write_forbidden'\n : 'config_sync_unavailable',\n },\n });\n return;\n }\n const outcome = statewireTransportOutcome(error);\n if (outcome !== null) {\n // Channel weather (a dropped stream, the host's expired verdict): keep\n // each change pending and write it again after a backoff, once the\n // channel is live, unless its prop has moved on or the attach is gone.\n athenaDiagnostics.emit('statewire.config', {\n level: 'debug',\n data: { ...data, outcome },\n });\n if (outcome === 'unmount') return;\n const retryKeys = patchKeys.filter(\n (key) =>\n sameThreadConfigValue(seenRef.current[key], patch[key] ?? null) &&\n (attempts.get(key) ?? 0) < MAX_PATCH_ATTEMPTS_PER_CHANGE,\n );\n if (retryKeys.length === 0) return;\n for (const key of retryKeys) pendingRef.current.add(key);\n const written = Math.max(...retryKeys.map((key) => attempts.get(key) ?? 1));\n const delay = RETRY_BACKOFF_MS[Math.min(written - 1, RETRY_BACKOFF_MS.length - 1)];\n retryTimerRef.current = setTimeout(() => {\n retryTimerRef.current = null;\n setRetryTick((tick) => tick + 1);\n }, delay);\n return;\n }\n athenaDiagnostics.error(\n 'statewire.config',\n error,\n modelOnly\n ? {\n code: 'statewire_rejected',\n message: 'The statewire host refused the model change',\n hint: 'Inspect error.detail: agora rejections carry a structured {code, message}. The thread keeps running with the model its server config holds.',\n }\n : {\n code: 'statewire_rejected',\n message: 'The statewire host refused the thread config change',\n hint: 'Inspect error.detail: agora rejections carry a structured {code, message}. The thread keeps running with the config its server config holds.',\n },\n data,\n );\n });\n }, [config, landed, configVersion, custom, channelLive, retryTick, threadId]);\n\n return null;\n}\n"],"names":[],"mappings":";;;;;;AAsBA,MAAM,gCAAgC;AAGtC,MAAM,mBAAmB,CAAC,KAAO,GAAK;AAOtC,SAAS,gBAAgB;AAAA,EACvB;AAAA,EACA;AACF,GAG4B;AAC1B,QAAM,YAAY,wBAAwB,KAAK,EAAE,OAAO,CAAC,QAAQ,QAAQ,OAAO;AAChF,SAAO;AAAA,IACL,WAAW;AAAA,IACX,GAAI,OAAO,OAAO,OAAO,OAAO,KAAK,EAAE,OAAO,MAAM,MAAA;AAAA,IACpD,GAAI,UAAU,SAAS,KAAK,EAAE,aAAa,UAAA;AAAA,EAAU;AAEzD;AA8CO,SAAS,8BAA8B;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAOS;AACP,QAAM,OAAO,wBAAA;AACb,QAAM,cAA8D,CAAC,YACnE,QAAQ,QAAQ,KAAK,OAAO,CAAC;AAC/B,QAAM,EAAE,eAAe,QAAQ,YAAA,IAAgB,6BAA6B;AAAA,IAC1E,cAAc,KAAK;AAAA,IACnB;AAAA,EAAA,CACD;AAED,QAAM,UAAU,OAAO,MAAM;AAC7B,QAAM,aAAa,OAAO,oBAAI,KAA8B;AAC5D,QAAM,cAAc,OAAO,oBAAI,KAAsC;AACrE,QAAM,YAAY,OAAO,KAAK;AAC9B,QAAM,iBAAiB,OAAO,WAAW;AACzC,iBAAe,UAAU;AAEzB,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,CAAC;AAC5C,QAAM,gBAAgB,OAA6C,IAAI;AACvE;AAAA,IACE,MAAM,MAAM;AACV,UAAI,cAAc,YAAY,KAAM,cAAa,cAAc,OAAO;AAAA,IACxE;AAAA,IACA,CAAA;AAAA,EAAC;AAEH,QAAM,SAAS,KAAK;AAEpB,YAAU,MAAM;AACd,UAAM,UAAU,WAAW;AAC3B,UAAM,WAAW,YAAY;AAC7B,eAAW,OAAO,6BAA6B;AAC7C,UAAI,sBAAsB,OAAO,GAAG,GAAG,QAAQ,QAAQ,GAAG,CAAC,EAAG;AAC9D,cAAQ,IAAI,GAAG;AACf,eAAS,IAAI,KAAK,CAAC;AAAA,IACrB;AACA,YAAQ,UAAU;AAClB,QAAI,QAAQ,SAAS,KAAK,UAAU,WAAW,CAAC,YAAa;AAC7D,UAAM,WAAW,4BAA4B;AAAA,MAC3C,SAAS;AAAA,MACT,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AACD,QAAI,SAAS,SAAS,OAAQ;AAC9B,YAAQ,MAAA;AACR,QAAI,SAAS,SAAS,OAAQ;AAE9B,UAAM,EAAE,UAAU;AAClB,UAAM,YAAY,wBAAwB,KAAK;AAC/C,eAAW,OAAO,UAAW,UAAS,IAAI,MAAM,SAAS,IAAI,GAAG,KAAK,KAAK,CAAC;AAC3E,UAAM,YAAY,UAAU,WAAW,KAAK,UAAU,CAAC,MAAM;AAC7D,mBAAe,QAAQ,KAAK,EAAE,MAAM,CAAC,UAAmB;AACtD,YAAM,OAAO,gBAAgB,EAAE,UAAU,OAAO;AAChD,UAAI,gCAAgC,KAAK,KAAK,iCAAiC,KAAK,GAAG;AACrF,kBAAU,UAAU;AACpB,0BAAkB,KAAK,oBAAoB;AAAA,UACzC,OAAO;AAAA,UACP,MAAM;AAAA,YACJ,GAAG;AAAA,YACH,QAAQ,gCAAgC,KAAK,IACzC,2BACA;AAAA,UAAA;AAAA,QACN,CACD;AACD;AAAA,MACF;AACA,YAAM,UAAU,0BAA0B,KAAK;AAC/C,UAAI,YAAY,MAAM;AAIpB,0BAAkB,KAAK,oBAAoB;AAAA,UACzC,OAAO;AAAA,UACP,MAAM,EAAE,GAAG,MAAM,QAAA;AAAA,QAAQ,CAC1B;AACD,YAAI,YAAY,UAAW;AAC3B,cAAM,YAAY,UAAU;AAAA,UAC1B,CAAC,QACC,sBAAsB,QAAQ,QAAQ,GAAG,GAAG,MAAM,GAAG,KAAK,IAAI,MAC7D,SAAS,IAAI,GAAG,KAAK,KAAK;AAAA,QAAA;AAE/B,YAAI,UAAU,WAAW,EAAG;AAC5B,mBAAW,OAAO,UAAW,YAAW,QAAQ,IAAI,GAAG;AACvD,cAAM,UAAU,KAAK,IAAI,GAAG,UAAU,IAAI,CAAC,QAAQ,SAAS,IAAI,GAAG,KAAK,CAAC,CAAC;AAC1E,cAAM,QAAQ,iBAAiB,KAAK,IAAI,UAAU,GAAG,iBAAiB,SAAS,CAAC,CAAC;AACjF,sBAAc,UAAU,WAAW,MAAM;AACvC,wBAAc,UAAU;AACxB,uBAAa,CAAC,SAAS,OAAO,CAAC;AAAA,QACjC,GAAG,KAAK;AACR;AAAA,MACF;AACA,wBAAkB;AAAA,QAChB;AAAA,QACA;AAAA,QACA,YACI;AAAA,UACE,MAAM;AAAA,UACN,SAAS;AAAA,UACT,MAAM;AAAA,QAAA,IAER;AAAA,UACE,MAAM;AAAA,UACN,SAAS;AAAA,UACT,MAAM;AAAA,QAAA;AAAA,QAEZ;AAAA,MAAA;AAAA,IAEJ,CAAC;AAAA,EACH,GAAG,CAAC,QAAQ,QAAQ,eAAe,QAAQ,aAAa,WAAW,QAAQ,CAAC;AAE5E,SAAO;AACT;"}
@@ -42,11 +42,13 @@ const initialStatewireLifecycle = {
42
42
  error: null,
43
43
  reconnect: null
44
44
  };
45
+ function isStatewireChannelLive(connection) {
46
+ return (connection == null ? void 0 : connection.status) === "connected" || (connection == null ? void 0 : connection.status) === "standby";
47
+ }
45
48
  function statewireLifecycleReducer(state, action) {
46
- var _a, _b;
47
49
  switch (action.type) {
48
50
  case "connection": {
49
- const healthy = ((_a = action.connection) == null ? void 0 : _a.status) === "connected" || ((_b = action.connection) == null ? void 0 : _b.status) === "standby";
51
+ const healthy = isStatewireChannelLive(action.connection);
50
52
  return {
51
53
  ...state,
52
54
  connection: action.connection,
@@ -61,5 +63,6 @@ function statewireLifecycleReducer(state, action) {
61
63
  }
62
64
  exports.athenaStatewireErrorNotice = athenaStatewireErrorNotice;
63
65
  exports.initialStatewireLifecycle = initialStatewireLifecycle;
66
+ exports.isStatewireChannelLive = isStatewireChannelLive;
64
67
  exports.statewireLifecycleReducer = statewireLifecycleReducer;
65
68
  //# sourceMappingURL=statewire-lifecycle.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"statewire-lifecycle.cjs","sources":["../../src/runtime/statewire-lifecycle.ts"],"sourcesContent":["import {\n COLLAB_AGENT_CHANNEL_SESSION_MISMATCH,\n isLegacyThreadReadOnlyRejection,\n isStatewireChannelTeardown,\n statewireRejectionCode,\n statewireRejectionDetailMessage,\n statewireRejectionPayload,\n} from '@athenaintel/agent-runtime';\nimport type { DeepAgentConnectionState } from '@athenaintel/agent-runtime';\n\n/** A user-visible notice mapped from a statewire transport error. */\nexport interface AthenaStatewireErrorNotice {\n kind: 'paywall' | 'read-only' | 'command';\n title: string;\n message: string;\n /**\n * The server's structured `detail.code` (`collab_agent_channel_session_mismatch`,\n * `legacy_thread_read_only`, …), when the rejection carried one — what a\n * host matches on to offer the right next step.\n */\n code?: string;\n}\n\n/**\n * Map the statewire failure envelope to a concise, actionable notice.\n * Returns null for expected channel teardowns (thread switch, unmount),\n * which must not surface as errors.\n */\nexport function athenaStatewireErrorNotice(\n error: unknown,\n): AthenaStatewireErrorNotice | null {\n if (isStatewireChannelTeardown(error)) return null;\n const rejection = statewireRejectionPayload(error);\n // The server's own detail names the actionable reason; the Error message is\n // generic client-side text like `command rejected (500)`.\n const detail = statewireRejectionDetailMessage(error);\n\n if (rejection?.status === 402) {\n return {\n kind: 'paywall',\n title: 'Usage limit reached',\n message:\n detail ?? 'Athena could not start this run. Review usage or billing to continue.',\n };\n }\n\n const code = statewireRejectionCode(error);\n const withCode = code === null ? {} : { code };\n\n // Legacy-thread dispatch fence: an out-of-band run is writing this\n // pre-cutover thread (or its adoption failed). A per-send failure, not a\n // standing state — the server's detail names the actionable reason (wait\n // for the run vs. start a new chat).\n if (isLegacyThreadReadOnlyRejection(error)) {\n return {\n kind: 'read-only',\n title: 'Message was not sent',\n message:\n detail ??\n 'This conversation cannot take new messages right now. Try again shortly, or start a new chat.',\n ...withCode,\n };\n }\n\n // A session keeps the collab-agent channel (the app's mode) it started on:\n // the send asked for another one. Nothing about the chat is broken — the\n // way on is a new session — so it reads as the amber \"not sent\", not red.\n if (code === COLLAB_AGENT_CHANNEL_SESSION_MISMATCH) {\n return {\n kind: 'read-only',\n title: 'Message was not sent',\n message: detail ?? 'This session runs in another mode. Start a new session to use this one.',\n code,\n };\n }\n\n return {\n kind: 'command',\n title: 'Message was not sent',\n message:\n detail ??\n (error instanceof Error && error.message.length > 0\n ? error.message\n : 'The chat runtime rejected the command. Please try again.'),\n ...withCode,\n };\n}\n\n/** Shared lifecycle state for the statewire transport, provided by\n * `AthenaProvider` in statewire mode and read by the chat banners. */\nexport interface AthenaStatewireLifecycleState {\n connection: DeepAgentConnectionState | null;\n error: AthenaStatewireErrorNotice | null;\n reconnect: (() => void) | null;\n dismissError: () => void;\n}\n\n/** The provider's reducer state behind {@link AthenaStatewireLifecycleState}. */\nexport interface StatewireLifecycleReducerState {\n connection: DeepAgentConnectionState | null;\n error: AthenaStatewireErrorNotice | null;\n reconnect: (() => void) | null;\n}\n\nexport type StatewireLifecycleAction =\n | { type: 'connection'; connection: DeepAgentConnectionState | null }\n | { type: 'error'; error: AthenaStatewireErrorNotice | null }\n | { type: 'raw-connection'; reconnect: () => void };\n\nexport const initialStatewireLifecycle: StatewireLifecycleReducerState = {\n connection: null,\n error: null,\n reconnect: null,\n};\n\n/**\n * Folds the runtime's lifecycle observations into the banner state. A healthy\n * channel — connected, or disconnected only because the instance is quiet\n * (`idle`) or the chat has not sent yet (`deferred`) — clears a stale\n * send/transport error: leaving it up tells the user the chat is broken after\n * it has come back.\n */\nexport function statewireLifecycleReducer(\n state: StatewireLifecycleReducerState,\n action: StatewireLifecycleAction,\n): StatewireLifecycleReducerState {\n switch (action.type) {\n case 'connection': {\n const healthy =\n action.connection?.status === 'connected' ||\n action.connection?.status === 'standby';\n return {\n ...state,\n connection: action.connection,\n error: healthy ? null : state.error,\n };\n }\n case 'error':\n return { ...state, error: action.error };\n case 'raw-connection':\n return { ...state, reconnect: action.reconnect };\n }\n}\n"],"names":["isStatewireChannelTeardown","statewireRejectionPayload","statewireRejectionDetailMessage","statewireRejectionCode","isLegacyThreadReadOnlyRejection","COLLAB_AGENT_CHANNEL_SESSION_MISMATCH"],"mappings":";;;AA4BO,SAAS,2BACd,OACmC;AACnC,MAAIA,OAAAA,2BAA2B,KAAK,EAAG,QAAO;AAC9C,QAAM,YAAYC,OAAAA,0BAA0B,KAAK;AAGjD,QAAM,SAASC,OAAAA,gCAAgC,KAAK;AAEpD,OAAI,uCAAW,YAAW,KAAK;AAC7B,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SACE,UAAU;AAAA,IAAA;AAAA,EAEhB;AAEA,QAAM,OAAOC,OAAAA,uBAAuB,KAAK;AACzC,QAAM,WAAW,SAAS,OAAO,CAAA,IAAK,EAAE,KAAA;AAMxC,MAAIC,OAAAA,gCAAgC,KAAK,GAAG;AAC1C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SACE,UACA;AAAA,MACF,GAAG;AAAA,IAAA;AAAA,EAEP;AAKA,MAAI,SAASC,OAAAA,uCAAuC;AAClD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS,UAAU;AAAA,MACnB;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SACE,WACC,iBAAiB,SAAS,MAAM,QAAQ,SAAS,IAC9C,MAAM,UACN;AAAA,IACN,GAAG;AAAA,EAAA;AAEP;AAuBO,MAAM,4BAA4D;AAAA,EACvE,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,WAAW;AACb;AASO,SAAS,0BACd,OACA,QACgC;;AAChC,UAAQ,OAAO,MAAA;AAAA,IACb,KAAK,cAAc;AACjB,YAAM,YACJ,YAAO,eAAP,mBAAmB,YAAW,iBAC9B,YAAO,eAAP,mBAAmB,YAAW;AAChC,aAAO;AAAA,QACL,GAAG;AAAA,QACH,YAAY,OAAO;AAAA,QACnB,OAAO,UAAU,OAAO,MAAM;AAAA,MAAA;AAAA,IAElC;AAAA,IACA,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,OAAO,OAAO,MAAA;AAAA,IACnC,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,WAAW,OAAO,UAAA;AAAA,EAAU;AAErD;;;;"}
1
+ {"version":3,"file":"statewire-lifecycle.cjs","sources":["../../src/runtime/statewire-lifecycle.ts"],"sourcesContent":["import {\n COLLAB_AGENT_CHANNEL_SESSION_MISMATCH,\n isLegacyThreadReadOnlyRejection,\n isStatewireChannelTeardown,\n statewireRejectionCode,\n statewireRejectionDetailMessage,\n statewireRejectionPayload,\n} from '@athenaintel/agent-runtime';\nimport type { DeepAgentConnectionState } from '@athenaintel/agent-runtime';\n\n/** A user-visible notice mapped from a statewire transport error. */\nexport interface AthenaStatewireErrorNotice {\n kind: 'paywall' | 'read-only' | 'command';\n title: string;\n message: string;\n /**\n * The server's structured `detail.code` (`collab_agent_channel_session_mismatch`,\n * `legacy_thread_read_only`, …), when the rejection carried one — what a\n * host matches on to offer the right next step.\n */\n code?: string;\n}\n\n/**\n * Map the statewire failure envelope to a concise, actionable notice.\n * Returns null for expected channel teardowns (thread switch, unmount),\n * which must not surface as errors.\n */\nexport function athenaStatewireErrorNotice(\n error: unknown,\n): AthenaStatewireErrorNotice | null {\n if (isStatewireChannelTeardown(error)) return null;\n const rejection = statewireRejectionPayload(error);\n // The server's own detail names the actionable reason; the Error message is\n // generic client-side text like `command rejected (500)`.\n const detail = statewireRejectionDetailMessage(error);\n\n if (rejection?.status === 402) {\n return {\n kind: 'paywall',\n title: 'Usage limit reached',\n message:\n detail ?? 'Athena could not start this run. Review usage or billing to continue.',\n };\n }\n\n const code = statewireRejectionCode(error);\n const withCode = code === null ? {} : { code };\n\n // Legacy-thread dispatch fence: an out-of-band run is writing this\n // pre-cutover thread (or its adoption failed). A per-send failure, not a\n // standing state — the server's detail names the actionable reason (wait\n // for the run vs. start a new chat).\n if (isLegacyThreadReadOnlyRejection(error)) {\n return {\n kind: 'read-only',\n title: 'Message was not sent',\n message:\n detail ??\n 'This conversation cannot take new messages right now. Try again shortly, or start a new chat.',\n ...withCode,\n };\n }\n\n // A session keeps the collab-agent channel (the app's mode) it started on:\n // the send asked for another one. Nothing about the chat is broken — the\n // way on is a new session — so it reads as the amber \"not sent\", not red.\n if (code === COLLAB_AGENT_CHANNEL_SESSION_MISMATCH) {\n return {\n kind: 'read-only',\n title: 'Message was not sent',\n message: detail ?? 'This session runs in another mode. Start a new session to use this one.',\n code,\n };\n }\n\n return {\n kind: 'command',\n title: 'Message was not sent',\n message:\n detail ??\n (error instanceof Error && error.message.length > 0\n ? error.message\n : 'The chat runtime rejected the command. Please try again.'),\n ...withCode,\n };\n}\n\n/** Shared lifecycle state for the statewire transport, provided by\n * `AthenaProvider` in statewire mode and read by the chat banners. */\nexport interface AthenaStatewireLifecycleState {\n connection: DeepAgentConnectionState | null;\n error: AthenaStatewireErrorNotice | null;\n reconnect: (() => void) | null;\n dismissError: () => void;\n}\n\n/** The provider's reducer state behind {@link AthenaStatewireLifecycleState}. */\nexport interface StatewireLifecycleReducerState {\n connection: DeepAgentConnectionState | null;\n error: AthenaStatewireErrorNotice | null;\n reconnect: (() => void) | null;\n}\n\nexport type StatewireLifecycleAction =\n | { type: 'connection'; connection: DeepAgentConnectionState | null }\n | { type: 'error'; error: AthenaStatewireErrorNotice | null }\n | { type: 'raw-connection'; reconnect: () => void };\n\nexport const initialStatewireLifecycle: StatewireLifecycleReducerState = {\n connection: null,\n error: null,\n reconnect: null,\n};\n\n/**\n * Folds the runtime's lifecycle observations into the banner state. A healthy\n * channel — connected, or disconnected only because the instance is quiet\n * (`idle`) or the chat has not sent yet (`deferred`) — clears a stale\n * send/transport error: leaving it up tells the user the chat is broken after\n * it has come back.\n */\n/**\n * Whether the statewire channel can take a command now: connected, or on\n * standby (attached and idle). `null` (no connection observed yet) is not.\n */\nexport function isStatewireChannelLive(connection: DeepAgentConnectionState | null): boolean {\n return connection?.status === 'connected' || connection?.status === 'standby';\n}\n\nexport function statewireLifecycleReducer(\n state: StatewireLifecycleReducerState,\n action: StatewireLifecycleAction,\n): StatewireLifecycleReducerState {\n switch (action.type) {\n case 'connection': {\n const healthy = isStatewireChannelLive(action.connection);\n return {\n ...state,\n connection: action.connection,\n error: healthy ? null : state.error,\n };\n }\n case 'error':\n return { ...state, error: action.error };\n case 'raw-connection':\n return { ...state, reconnect: action.reconnect };\n }\n}\n"],"names":["isStatewireChannelTeardown","statewireRejectionPayload","statewireRejectionDetailMessage","statewireRejectionCode","isLegacyThreadReadOnlyRejection","COLLAB_AGENT_CHANNEL_SESSION_MISMATCH"],"mappings":";;;AA4BO,SAAS,2BACd,OACmC;AACnC,MAAIA,OAAAA,2BAA2B,KAAK,EAAG,QAAO;AAC9C,QAAM,YAAYC,OAAAA,0BAA0B,KAAK;AAGjD,QAAM,SAASC,OAAAA,gCAAgC,KAAK;AAEpD,OAAI,uCAAW,YAAW,KAAK;AAC7B,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SACE,UAAU;AAAA,IAAA;AAAA,EAEhB;AAEA,QAAM,OAAOC,OAAAA,uBAAuB,KAAK;AACzC,QAAM,WAAW,SAAS,OAAO,CAAA,IAAK,EAAE,KAAA;AAMxC,MAAIC,OAAAA,gCAAgC,KAAK,GAAG;AAC1C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SACE,UACA;AAAA,MACF,GAAG;AAAA,IAAA;AAAA,EAEP;AAKA,MAAI,SAASC,OAAAA,uCAAuC;AAClD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS,UAAU;AAAA,MACnB;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SACE,WACC,iBAAiB,SAAS,MAAM,QAAQ,SAAS,IAC9C,MAAM,UACN;AAAA,IACN,GAAG;AAAA,EAAA;AAEP;AAuBO,MAAM,4BAA4D;AAAA,EACvE,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,WAAW;AACb;AAaO,SAAS,uBAAuB,YAAsD;AAC3F,UAAO,yCAAY,YAAW,gBAAe,yCAAY,YAAW;AACtE;AAEO,SAAS,0BACd,OACA,QACgC;AAChC,UAAQ,OAAO,MAAA;AAAA,IACb,KAAK,cAAc;AACjB,YAAM,UAAU,uBAAuB,OAAO,UAAU;AACxD,aAAO;AAAA,QACL,GAAG;AAAA,QACH,YAAY,OAAO;AAAA,QACnB,OAAO,UAAU,OAAO,MAAM;AAAA,MAAA;AAAA,IAElC;AAAA,IACA,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,OAAO,OAAO,MAAA;AAAA,IACnC,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,WAAW,OAAO,UAAA;AAAA,EAAU;AAErD;;;;;"}
@@ -49,4 +49,9 @@ export declare const initialStatewireLifecycle: StatewireLifecycleReducerState;
49
49
  * send/transport error: leaving it up tells the user the chat is broken after
50
50
  * it has come back.
51
51
  */
52
+ /**
53
+ * Whether the statewire channel can take a command now: connected, or on
54
+ * standby (attached and idle). `null` (no connection observed yet) is not.
55
+ */
56
+ export declare function isStatewireChannelLive(connection: DeepAgentConnectionState | null): boolean;
52
57
  export declare function statewireLifecycleReducer(state: StatewireLifecycleReducerState, action: StatewireLifecycleAction): StatewireLifecycleReducerState;
@@ -40,11 +40,13 @@ const initialStatewireLifecycle = {
40
40
  error: null,
41
41
  reconnect: null
42
42
  };
43
+ function isStatewireChannelLive(connection) {
44
+ return (connection == null ? void 0 : connection.status) === "connected" || (connection == null ? void 0 : connection.status) === "standby";
45
+ }
43
46
  function statewireLifecycleReducer(state, action) {
44
- var _a, _b;
45
47
  switch (action.type) {
46
48
  case "connection": {
47
- const healthy = ((_a = action.connection) == null ? void 0 : _a.status) === "connected" || ((_b = action.connection) == null ? void 0 : _b.status) === "standby";
49
+ const healthy = isStatewireChannelLive(action.connection);
48
50
  return {
49
51
  ...state,
50
52
  connection: action.connection,
@@ -60,6 +62,7 @@ function statewireLifecycleReducer(state, action) {
60
62
  export {
61
63
  athenaStatewireErrorNotice,
62
64
  initialStatewireLifecycle,
65
+ isStatewireChannelLive,
63
66
  statewireLifecycleReducer
64
67
  };
65
68
  //# sourceMappingURL=statewire-lifecycle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"statewire-lifecycle.js","sources":["../../src/runtime/statewire-lifecycle.ts"],"sourcesContent":["import {\n COLLAB_AGENT_CHANNEL_SESSION_MISMATCH,\n isLegacyThreadReadOnlyRejection,\n isStatewireChannelTeardown,\n statewireRejectionCode,\n statewireRejectionDetailMessage,\n statewireRejectionPayload,\n} from '@athenaintel/agent-runtime';\nimport type { DeepAgentConnectionState } from '@athenaintel/agent-runtime';\n\n/** A user-visible notice mapped from a statewire transport error. */\nexport interface AthenaStatewireErrorNotice {\n kind: 'paywall' | 'read-only' | 'command';\n title: string;\n message: string;\n /**\n * The server's structured `detail.code` (`collab_agent_channel_session_mismatch`,\n * `legacy_thread_read_only`, …), when the rejection carried one — what a\n * host matches on to offer the right next step.\n */\n code?: string;\n}\n\n/**\n * Map the statewire failure envelope to a concise, actionable notice.\n * Returns null for expected channel teardowns (thread switch, unmount),\n * which must not surface as errors.\n */\nexport function athenaStatewireErrorNotice(\n error: unknown,\n): AthenaStatewireErrorNotice | null {\n if (isStatewireChannelTeardown(error)) return null;\n const rejection = statewireRejectionPayload(error);\n // The server's own detail names the actionable reason; the Error message is\n // generic client-side text like `command rejected (500)`.\n const detail = statewireRejectionDetailMessage(error);\n\n if (rejection?.status === 402) {\n return {\n kind: 'paywall',\n title: 'Usage limit reached',\n message:\n detail ?? 'Athena could not start this run. Review usage or billing to continue.',\n };\n }\n\n const code = statewireRejectionCode(error);\n const withCode = code === null ? {} : { code };\n\n // Legacy-thread dispatch fence: an out-of-band run is writing this\n // pre-cutover thread (or its adoption failed). A per-send failure, not a\n // standing state — the server's detail names the actionable reason (wait\n // for the run vs. start a new chat).\n if (isLegacyThreadReadOnlyRejection(error)) {\n return {\n kind: 'read-only',\n title: 'Message was not sent',\n message:\n detail ??\n 'This conversation cannot take new messages right now. Try again shortly, or start a new chat.',\n ...withCode,\n };\n }\n\n // A session keeps the collab-agent channel (the app's mode) it started on:\n // the send asked for another one. Nothing about the chat is broken — the\n // way on is a new session — so it reads as the amber \"not sent\", not red.\n if (code === COLLAB_AGENT_CHANNEL_SESSION_MISMATCH) {\n return {\n kind: 'read-only',\n title: 'Message was not sent',\n message: detail ?? 'This session runs in another mode. Start a new session to use this one.',\n code,\n };\n }\n\n return {\n kind: 'command',\n title: 'Message was not sent',\n message:\n detail ??\n (error instanceof Error && error.message.length > 0\n ? error.message\n : 'The chat runtime rejected the command. Please try again.'),\n ...withCode,\n };\n}\n\n/** Shared lifecycle state for the statewire transport, provided by\n * `AthenaProvider` in statewire mode and read by the chat banners. */\nexport interface AthenaStatewireLifecycleState {\n connection: DeepAgentConnectionState | null;\n error: AthenaStatewireErrorNotice | null;\n reconnect: (() => void) | null;\n dismissError: () => void;\n}\n\n/** The provider's reducer state behind {@link AthenaStatewireLifecycleState}. */\nexport interface StatewireLifecycleReducerState {\n connection: DeepAgentConnectionState | null;\n error: AthenaStatewireErrorNotice | null;\n reconnect: (() => void) | null;\n}\n\nexport type StatewireLifecycleAction =\n | { type: 'connection'; connection: DeepAgentConnectionState | null }\n | { type: 'error'; error: AthenaStatewireErrorNotice | null }\n | { type: 'raw-connection'; reconnect: () => void };\n\nexport const initialStatewireLifecycle: StatewireLifecycleReducerState = {\n connection: null,\n error: null,\n reconnect: null,\n};\n\n/**\n * Folds the runtime's lifecycle observations into the banner state. A healthy\n * channel — connected, or disconnected only because the instance is quiet\n * (`idle`) or the chat has not sent yet (`deferred`) — clears a stale\n * send/transport error: leaving it up tells the user the chat is broken after\n * it has come back.\n */\nexport function statewireLifecycleReducer(\n state: StatewireLifecycleReducerState,\n action: StatewireLifecycleAction,\n): StatewireLifecycleReducerState {\n switch (action.type) {\n case 'connection': {\n const healthy =\n action.connection?.status === 'connected' ||\n action.connection?.status === 'standby';\n return {\n ...state,\n connection: action.connection,\n error: healthy ? null : state.error,\n };\n }\n case 'error':\n return { ...state, error: action.error };\n case 'raw-connection':\n return { ...state, reconnect: action.reconnect };\n }\n}\n"],"names":[],"mappings":";AA4BO,SAAS,2BACd,OACmC;AACnC,MAAI,2BAA2B,KAAK,EAAG,QAAO;AAC9C,QAAM,YAAY,0BAA0B,KAAK;AAGjD,QAAM,SAAS,gCAAgC,KAAK;AAEpD,OAAI,uCAAW,YAAW,KAAK;AAC7B,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SACE,UAAU;AAAA,IAAA;AAAA,EAEhB;AAEA,QAAM,OAAO,uBAAuB,KAAK;AACzC,QAAM,WAAW,SAAS,OAAO,CAAA,IAAK,EAAE,KAAA;AAMxC,MAAI,gCAAgC,KAAK,GAAG;AAC1C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SACE,UACA;AAAA,MACF,GAAG;AAAA,IAAA;AAAA,EAEP;AAKA,MAAI,SAAS,uCAAuC;AAClD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS,UAAU;AAAA,MACnB;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SACE,WACC,iBAAiB,SAAS,MAAM,QAAQ,SAAS,IAC9C,MAAM,UACN;AAAA,IACN,GAAG;AAAA,EAAA;AAEP;AAuBO,MAAM,4BAA4D;AAAA,EACvE,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,WAAW;AACb;AASO,SAAS,0BACd,OACA,QACgC;;AAChC,UAAQ,OAAO,MAAA;AAAA,IACb,KAAK,cAAc;AACjB,YAAM,YACJ,YAAO,eAAP,mBAAmB,YAAW,iBAC9B,YAAO,eAAP,mBAAmB,YAAW;AAChC,aAAO;AAAA,QACL,GAAG;AAAA,QACH,YAAY,OAAO;AAAA,QACnB,OAAO,UAAU,OAAO,MAAM;AAAA,MAAA;AAAA,IAElC;AAAA,IACA,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,OAAO,OAAO,MAAA;AAAA,IACnC,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,WAAW,OAAO,UAAA;AAAA,EAAU;AAErD;"}
1
+ {"version":3,"file":"statewire-lifecycle.js","sources":["../../src/runtime/statewire-lifecycle.ts"],"sourcesContent":["import {\n COLLAB_AGENT_CHANNEL_SESSION_MISMATCH,\n isLegacyThreadReadOnlyRejection,\n isStatewireChannelTeardown,\n statewireRejectionCode,\n statewireRejectionDetailMessage,\n statewireRejectionPayload,\n} from '@athenaintel/agent-runtime';\nimport type { DeepAgentConnectionState } from '@athenaintel/agent-runtime';\n\n/** A user-visible notice mapped from a statewire transport error. */\nexport interface AthenaStatewireErrorNotice {\n kind: 'paywall' | 'read-only' | 'command';\n title: string;\n message: string;\n /**\n * The server's structured `detail.code` (`collab_agent_channel_session_mismatch`,\n * `legacy_thread_read_only`, …), when the rejection carried one — what a\n * host matches on to offer the right next step.\n */\n code?: string;\n}\n\n/**\n * Map the statewire failure envelope to a concise, actionable notice.\n * Returns null for expected channel teardowns (thread switch, unmount),\n * which must not surface as errors.\n */\nexport function athenaStatewireErrorNotice(\n error: unknown,\n): AthenaStatewireErrorNotice | null {\n if (isStatewireChannelTeardown(error)) return null;\n const rejection = statewireRejectionPayload(error);\n // The server's own detail names the actionable reason; the Error message is\n // generic client-side text like `command rejected (500)`.\n const detail = statewireRejectionDetailMessage(error);\n\n if (rejection?.status === 402) {\n return {\n kind: 'paywall',\n title: 'Usage limit reached',\n message:\n detail ?? 'Athena could not start this run. Review usage or billing to continue.',\n };\n }\n\n const code = statewireRejectionCode(error);\n const withCode = code === null ? {} : { code };\n\n // Legacy-thread dispatch fence: an out-of-band run is writing this\n // pre-cutover thread (or its adoption failed). A per-send failure, not a\n // standing state — the server's detail names the actionable reason (wait\n // for the run vs. start a new chat).\n if (isLegacyThreadReadOnlyRejection(error)) {\n return {\n kind: 'read-only',\n title: 'Message was not sent',\n message:\n detail ??\n 'This conversation cannot take new messages right now. Try again shortly, or start a new chat.',\n ...withCode,\n };\n }\n\n // A session keeps the collab-agent channel (the app's mode) it started on:\n // the send asked for another one. Nothing about the chat is broken — the\n // way on is a new session — so it reads as the amber \"not sent\", not red.\n if (code === COLLAB_AGENT_CHANNEL_SESSION_MISMATCH) {\n return {\n kind: 'read-only',\n title: 'Message was not sent',\n message: detail ?? 'This session runs in another mode. Start a new session to use this one.',\n code,\n };\n }\n\n return {\n kind: 'command',\n title: 'Message was not sent',\n message:\n detail ??\n (error instanceof Error && error.message.length > 0\n ? error.message\n : 'The chat runtime rejected the command. Please try again.'),\n ...withCode,\n };\n}\n\n/** Shared lifecycle state for the statewire transport, provided by\n * `AthenaProvider` in statewire mode and read by the chat banners. */\nexport interface AthenaStatewireLifecycleState {\n connection: DeepAgentConnectionState | null;\n error: AthenaStatewireErrorNotice | null;\n reconnect: (() => void) | null;\n dismissError: () => void;\n}\n\n/** The provider's reducer state behind {@link AthenaStatewireLifecycleState}. */\nexport interface StatewireLifecycleReducerState {\n connection: DeepAgentConnectionState | null;\n error: AthenaStatewireErrorNotice | null;\n reconnect: (() => void) | null;\n}\n\nexport type StatewireLifecycleAction =\n | { type: 'connection'; connection: DeepAgentConnectionState | null }\n | { type: 'error'; error: AthenaStatewireErrorNotice | null }\n | { type: 'raw-connection'; reconnect: () => void };\n\nexport const initialStatewireLifecycle: StatewireLifecycleReducerState = {\n connection: null,\n error: null,\n reconnect: null,\n};\n\n/**\n * Folds the runtime's lifecycle observations into the banner state. A healthy\n * channel — connected, or disconnected only because the instance is quiet\n * (`idle`) or the chat has not sent yet (`deferred`) — clears a stale\n * send/transport error: leaving it up tells the user the chat is broken after\n * it has come back.\n */\n/**\n * Whether the statewire channel can take a command now: connected, or on\n * standby (attached and idle). `null` (no connection observed yet) is not.\n */\nexport function isStatewireChannelLive(connection: DeepAgentConnectionState | null): boolean {\n return connection?.status === 'connected' || connection?.status === 'standby';\n}\n\nexport function statewireLifecycleReducer(\n state: StatewireLifecycleReducerState,\n action: StatewireLifecycleAction,\n): StatewireLifecycleReducerState {\n switch (action.type) {\n case 'connection': {\n const healthy = isStatewireChannelLive(action.connection);\n return {\n ...state,\n connection: action.connection,\n error: healthy ? null : state.error,\n };\n }\n case 'error':\n return { ...state, error: action.error };\n case 'raw-connection':\n return { ...state, reconnect: action.reconnect };\n }\n}\n"],"names":[],"mappings":";AA4BO,SAAS,2BACd,OACmC;AACnC,MAAI,2BAA2B,KAAK,EAAG,QAAO;AAC9C,QAAM,YAAY,0BAA0B,KAAK;AAGjD,QAAM,SAAS,gCAAgC,KAAK;AAEpD,OAAI,uCAAW,YAAW,KAAK;AAC7B,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SACE,UAAU;AAAA,IAAA;AAAA,EAEhB;AAEA,QAAM,OAAO,uBAAuB,KAAK;AACzC,QAAM,WAAW,SAAS,OAAO,CAAA,IAAK,EAAE,KAAA;AAMxC,MAAI,gCAAgC,KAAK,GAAG;AAC1C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SACE,UACA;AAAA,MACF,GAAG;AAAA,IAAA;AAAA,EAEP;AAKA,MAAI,SAAS,uCAAuC;AAClD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS,UAAU;AAAA,MACnB;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SACE,WACC,iBAAiB,SAAS,MAAM,QAAQ,SAAS,IAC9C,MAAM,UACN;AAAA,IACN,GAAG;AAAA,EAAA;AAEP;AAuBO,MAAM,4BAA4D;AAAA,EACvE,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,WAAW;AACb;AAaO,SAAS,uBAAuB,YAAsD;AAC3F,UAAO,yCAAY,YAAW,gBAAe,yCAAY,YAAW;AACtE;AAEO,SAAS,0BACd,OACA,QACgC;AAChC,UAAQ,OAAO,MAAA;AAAA,IACb,KAAK,cAAc;AACjB,YAAM,UAAU,uBAAuB,OAAO,UAAU;AACxD,aAAO;AAAA,QACL,GAAG;AAAA,QACH,YAAY,OAAO;AAAA,QACnB,OAAO,UAAU,OAAO,MAAM;AAAA,MAAA;AAAA,IAElC;AAAA,IACA,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,OAAO,OAAO,MAAA;AAAA,IACnC,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,WAAW,OAAO,UAAA;AAAA,EAAU;AAErD;"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function readLaneModel(custom) {
4
+ const model = custom.model;
5
+ return typeof model === "string" && model !== "" ? model : null;
6
+ }
7
+ function threadModelFromLane({
8
+ lane,
9
+ ready
10
+ }) {
11
+ if (!ready || lane === null) return { model: null, configured: false, ready };
12
+ return { model: readLaneModel(lane.custom), configured: true, ready };
13
+ }
14
+ exports.readLaneModel = readLaneModel;
15
+ exports.threadModelFromLane = threadModelFromLane;
16
+ //# sourceMappingURL=statewire-model-lane.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statewire-model-lane.cjs","sources":["../../src/runtime/statewire-model-lane.ts"],"sourcesContent":["import type { DeepAgentServerConfig, ThreadConfigCustom } from '@athenaintel/agent-runtime';\nimport { decideThreadConfigLanePatch } from './statewire-thread-config-lane';\n\n/**\n * The model a thread's server config lane (`state.config.custom`) pins, as the\n * host app should read it, plus whether there is a lane at all.\n *\n * Once a thread has a lane (version > 0), agora runs every turn with the lane's\n * thread-config keys and drops the ones a send carries, `model` included: the\n * lane, not the provider's `model` prop, decides which model a turn uses.\n */\nexport interface AthenaThreadModel {\n /**\n * The model the lane pins, or `null` when it pins none: the run then uses the\n * selected collab agent's own model, or the deployment default.\n */\n model: string | null;\n /** `true` once the thread has a server config lane (version > 0). */\n configured: boolean;\n /**\n * `true` once the statewire host's snapshot of this thread has arrived (the\n * placeholder or remembered snapshot a thread shows while it loads does not\n * count: it may carry no lane, or an older one). Before that `model` is\n * `null` and `configured` is `false` whatever the thread holds, so wait for\n * `ready` before treating \"no model\" as an answer.\n */\n ready: boolean;\n}\n\n/** The lane's `model` key, or `null` when it carries none (or a non-string). */\nexport function readLaneModel(custom: ThreadConfigCustom): string | null {\n const model = custom.model;\n return typeof model === 'string' && model !== '' ? model : null;\n}\n\n/** {@link AthenaThreadModel} from the lane and the landed flag. Pure. */\nexport function threadModelFromLane({\n lane,\n ready,\n}: {\n lane: DeepAgentServerConfig | null;\n ready: boolean;\n}): AthenaThreadModel {\n if (!ready || lane === null) return { model: null, configured: false, ready };\n return { model: readLaneModel(lane.custom), configured: true, ready };\n}\n\n/**\n * What to do with a `model` prop change the host made during an attach (the\n * `model` key of {@link decideThreadConfigLanePatch}, which decides every\n * provider-owned key the same way):\n *\n * - `wait`: keep the change pending. The thread's snapshot has not landed, or\n * the thread has no lane yet (version 0). A version-0 thread needs nothing:\n * the next send carries the model and agora's deferral seed persists it. The\n * change stays pending only so that a lane an EARLIER send seeds (with the\n * previous model) is corrected once it lands.\n * - `done`: the lane already holds the model (this client's own unacknowledged\n * writes folded over); nothing to write.\n * - `patch`: issue `config/patch {model}`; `null` unsets the lane's model so\n * the agent's own model (or the deployment default) applies.\n */\nexport type ModelLaneDecision =\n | { kind: 'wait' }\n | { kind: 'done' }\n | { kind: 'patch'; patch: { model: string | null } };\n\nexport function decideModelLanePatch({\n desiredModel,\n landed,\n configVersion,\n custom,\n}: {\n /** The provider's `model` prop after the change (`undefined` = no explicit model). */\n desiredModel: string | undefined;\n landed: boolean;\n configVersion: number;\n /** The effective lane: the server config with this client's pending writes folded over. */\n custom: ThreadConfigCustom;\n}): ModelLaneDecision {\n const desired = desiredModel === undefined || desiredModel === '' ? null : desiredModel;\n const decision = decideThreadConfigLanePatch({\n desired: {\n model: desired,\n system_prompt: null,\n enabled_tools: null,\n workbench: null,\n knowledge_base: null,\n },\n keys: ['model'],\n landed,\n configVersion,\n custom,\n });\n if (decision.kind !== 'patch') return decision;\n return { kind: 'patch', patch: { model: desired } };\n}\n"],"names":[],"mappings":";;AA8BO,SAAS,cAAc,QAA2C;AACvE,QAAM,QAAQ,OAAO;AACrB,SAAO,OAAO,UAAU,YAAY,UAAU,KAAK,QAAQ;AAC7D;AAGO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AACF,GAGsB;AACpB,MAAI,CAAC,SAAS,SAAS,KAAM,QAAO,EAAE,OAAO,MAAM,YAAY,OAAO,MAAA;AACtE,SAAO,EAAE,OAAO,cAAc,KAAK,MAAM,GAAG,YAAY,MAAM,MAAA;AAChE;;;"}
@@ -0,0 +1,66 @@
1
+ import type { DeepAgentServerConfig, ThreadConfigCustom } from '@athenaintel/agent-runtime';
2
+ /**
3
+ * The model a thread's server config lane (`state.config.custom`) pins, as the
4
+ * host app should read it, plus whether there is a lane at all.
5
+ *
6
+ * Once a thread has a lane (version > 0), agora runs every turn with the lane's
7
+ * thread-config keys and drops the ones a send carries, `model` included: the
8
+ * lane, not the provider's `model` prop, decides which model a turn uses.
9
+ */
10
+ export interface AthenaThreadModel {
11
+ /**
12
+ * The model the lane pins, or `null` when it pins none: the run then uses the
13
+ * selected collab agent's own model, or the deployment default.
14
+ */
15
+ model: string | null;
16
+ /** `true` once the thread has a server config lane (version > 0). */
17
+ configured: boolean;
18
+ /**
19
+ * `true` once the statewire host's snapshot of this thread has arrived (the
20
+ * placeholder or remembered snapshot a thread shows while it loads does not
21
+ * count: it may carry no lane, or an older one). Before that `model` is
22
+ * `null` and `configured` is `false` whatever the thread holds, so wait for
23
+ * `ready` before treating "no model" as an answer.
24
+ */
25
+ ready: boolean;
26
+ }
27
+ /** The lane's `model` key, or `null` when it carries none (or a non-string). */
28
+ export declare function readLaneModel(custom: ThreadConfigCustom): string | null;
29
+ /** {@link AthenaThreadModel} from the lane and the landed flag. Pure. */
30
+ export declare function threadModelFromLane({ lane, ready, }: {
31
+ lane: DeepAgentServerConfig | null;
32
+ ready: boolean;
33
+ }): AthenaThreadModel;
34
+ /**
35
+ * What to do with a `model` prop change the host made during an attach (the
36
+ * `model` key of {@link decideThreadConfigLanePatch}, which decides every
37
+ * provider-owned key the same way):
38
+ *
39
+ * - `wait`: keep the change pending. The thread's snapshot has not landed, or
40
+ * the thread has no lane yet (version 0). A version-0 thread needs nothing:
41
+ * the next send carries the model and agora's deferral seed persists it. The
42
+ * change stays pending only so that a lane an EARLIER send seeds (with the
43
+ * previous model) is corrected once it lands.
44
+ * - `done`: the lane already holds the model (this client's own unacknowledged
45
+ * writes folded over); nothing to write.
46
+ * - `patch`: issue `config/patch {model}`; `null` unsets the lane's model so
47
+ * the agent's own model (or the deployment default) applies.
48
+ */
49
+ export type ModelLaneDecision = {
50
+ kind: 'wait';
51
+ } | {
52
+ kind: 'done';
53
+ } | {
54
+ kind: 'patch';
55
+ patch: {
56
+ model: string | null;
57
+ };
58
+ };
59
+ export declare function decideModelLanePatch({ desiredModel, landed, configVersion, custom, }: {
60
+ /** The provider's `model` prop after the change (`undefined` = no explicit model). */
61
+ desiredModel: string | undefined;
62
+ landed: boolean;
63
+ configVersion: number;
64
+ /** The effective lane: the server config with this client's pending writes folded over. */
65
+ custom: ThreadConfigCustom;
66
+ }): ModelLaneDecision;
@@ -0,0 +1,16 @@
1
+ function readLaneModel(custom) {
2
+ const model = custom.model;
3
+ return typeof model === "string" && model !== "" ? model : null;
4
+ }
5
+ function threadModelFromLane({
6
+ lane,
7
+ ready
8
+ }) {
9
+ if (!ready || lane === null) return { model: null, configured: false, ready };
10
+ return { model: readLaneModel(lane.custom), configured: true, ready };
11
+ }
12
+ export {
13
+ readLaneModel,
14
+ threadModelFromLane
15
+ };
16
+ //# sourceMappingURL=statewire-model-lane.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statewire-model-lane.js","sources":["../../src/runtime/statewire-model-lane.ts"],"sourcesContent":["import type { DeepAgentServerConfig, ThreadConfigCustom } from '@athenaintel/agent-runtime';\nimport { decideThreadConfigLanePatch } from './statewire-thread-config-lane';\n\n/**\n * The model a thread's server config lane (`state.config.custom`) pins, as the\n * host app should read it, plus whether there is a lane at all.\n *\n * Once a thread has a lane (version > 0), agora runs every turn with the lane's\n * thread-config keys and drops the ones a send carries, `model` included: the\n * lane, not the provider's `model` prop, decides which model a turn uses.\n */\nexport interface AthenaThreadModel {\n /**\n * The model the lane pins, or `null` when it pins none: the run then uses the\n * selected collab agent's own model, or the deployment default.\n */\n model: string | null;\n /** `true` once the thread has a server config lane (version > 0). */\n configured: boolean;\n /**\n * `true` once the statewire host's snapshot of this thread has arrived (the\n * placeholder or remembered snapshot a thread shows while it loads does not\n * count: it may carry no lane, or an older one). Before that `model` is\n * `null` and `configured` is `false` whatever the thread holds, so wait for\n * `ready` before treating \"no model\" as an answer.\n */\n ready: boolean;\n}\n\n/** The lane's `model` key, or `null` when it carries none (or a non-string). */\nexport function readLaneModel(custom: ThreadConfigCustom): string | null {\n const model = custom.model;\n return typeof model === 'string' && model !== '' ? model : null;\n}\n\n/** {@link AthenaThreadModel} from the lane and the landed flag. Pure. */\nexport function threadModelFromLane({\n lane,\n ready,\n}: {\n lane: DeepAgentServerConfig | null;\n ready: boolean;\n}): AthenaThreadModel {\n if (!ready || lane === null) return { model: null, configured: false, ready };\n return { model: readLaneModel(lane.custom), configured: true, ready };\n}\n\n/**\n * What to do with a `model` prop change the host made during an attach (the\n * `model` key of {@link decideThreadConfigLanePatch}, which decides every\n * provider-owned key the same way):\n *\n * - `wait`: keep the change pending. The thread's snapshot has not landed, or\n * the thread has no lane yet (version 0). A version-0 thread needs nothing:\n * the next send carries the model and agora's deferral seed persists it. The\n * change stays pending only so that a lane an EARLIER send seeds (with the\n * previous model) is corrected once it lands.\n * - `done`: the lane already holds the model (this client's own unacknowledged\n * writes folded over); nothing to write.\n * - `patch`: issue `config/patch {model}`; `null` unsets the lane's model so\n * the agent's own model (or the deployment default) applies.\n */\nexport type ModelLaneDecision =\n | { kind: 'wait' }\n | { kind: 'done' }\n | { kind: 'patch'; patch: { model: string | null } };\n\nexport function decideModelLanePatch({\n desiredModel,\n landed,\n configVersion,\n custom,\n}: {\n /** The provider's `model` prop after the change (`undefined` = no explicit model). */\n desiredModel: string | undefined;\n landed: boolean;\n configVersion: number;\n /** The effective lane: the server config with this client's pending writes folded over. */\n custom: ThreadConfigCustom;\n}): ModelLaneDecision {\n const desired = desiredModel === undefined || desiredModel === '' ? null : desiredModel;\n const decision = decideThreadConfigLanePatch({\n desired: {\n model: desired,\n system_prompt: null,\n enabled_tools: null,\n workbench: null,\n knowledge_base: null,\n },\n keys: ['model'],\n landed,\n configVersion,\n custom,\n });\n if (decision.kind !== 'patch') return decision;\n return { kind: 'patch', patch: { model: desired } };\n}\n"],"names":[],"mappings":"AA8BO,SAAS,cAAc,QAA2C;AACvE,QAAM,QAAQ,OAAO;AACrB,SAAO,OAAO,UAAU,YAAY,UAAU,KAAK,QAAQ;AAC7D;AAGO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AACF,GAGsB;AACpB,MAAI,CAAC,SAAS,SAAS,KAAM,QAAO,EAAE,OAAO,MAAM,YAAY,OAAO,MAAA;AACtE,SAAO,EAAE,OAAO,cAAc,KAAK,MAAM,GAAG,YAAY,MAAM,MAAA;AAChE;"}
@@ -19,12 +19,21 @@ function resolveAgentProp({ agent }) {
19
19
  `[AthenaSDK] Unsupported \`agent\` prop ${JSON.stringify(agent)}. The only accepted shape is '${COLLAB_AGENT_REF_SHAPE}' (the asset id of a published collab agent). Named agents are not supported — the statewire host always runs the Athena deep agent; omit \`agent\` to use it.`
20
20
  );
21
21
  }
22
+ function effectiveStatewireModel({
23
+ model,
24
+ extraRunConfig
25
+ }) {
26
+ if (extraRunConfig !== void 0 && Object.hasOwn(extraRunConfig, "model")) {
27
+ const override = extraRunConfig.model;
28
+ return typeof override === "string" && override !== "" ? override : void 0;
29
+ }
30
+ return model === "" ? void 0 : model;
31
+ }
22
32
  function buildStatewireRunConfig(options = {}) {
23
33
  var _a, _b, _c, _d, _e;
24
34
  const collabAgentId = resolveAgentProp({ agent: options.agent });
25
35
  const collabChannelId = collabAgentId && ((_a = options.channel) == null ? void 0 : _a.trim()) ? options.channel.trim() : void 0;
26
36
  const model = options.model ?? (collabAgentId ? void 0 : DEFAULT_STATEWIRE_MODEL);
27
- const panelModel = model ?? DEFAULT_STATEWIRE_MODEL;
28
37
  const enabledTools = Array.from(
29
38
  /* @__PURE__ */ new Set([...options.tools ?? [], ...options.frontendToolIds ?? []])
30
39
  );
@@ -43,7 +52,11 @@ function buildStatewireRunConfig(options = {}) {
43
52
  // agent's configured tools. Omit it when empty.
44
53
  ...enabledTools.length > 0 ? { enabled_tools: enabledTools } : {},
45
54
  panel_config: {
46
- model: panelModel,
55
+ // A collab agent's thread with no explicit model names none here
56
+ // either: agora stores this panel on the thread's first run and
57
+ // replays it to every client, and a stored SDK default would show as
58
+ // the session's model while the agent's own model runs.
59
+ ...model ? { model } : {},
47
60
  enabled_tools: enabledTools,
48
61
  system_prompt: systemPrompt,
49
62
  run_label: STATEWIRE_RUN_LABEL
@@ -63,6 +76,7 @@ exports.COLLAB_AGENT_REF_PREFIX = COLLAB_AGENT_REF_PREFIX;
63
76
  exports.COLLAB_AGENT_REF_SHAPE = COLLAB_AGENT_REF_SHAPE;
64
77
  exports.DEFAULT_STATEWIRE_MODEL = DEFAULT_STATEWIRE_MODEL;
65
78
  exports.buildStatewireRunConfig = buildStatewireRunConfig;
79
+ exports.effectiveStatewireModel = effectiveStatewireModel;
66
80
  exports.parseCollabAgentRef = parseCollabAgentRef;
67
81
  exports.resolveAgentProp = resolveAgentProp;
68
82
  //# sourceMappingURL=statewire-run-config.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"statewire-run-config.cjs","sources":["../../src/runtime/statewire-run-config.ts"],"sourcesContent":["/** Runtime marker the deep-agent session substrate stamps on sessions. */\nconst DEEP_AGENT_RUNTIME_MARKER = 'athena_deep_agent';\n\n/** Session-origin channel. The backend clamps unknown values to 'web', which\n * is how every SDK-started session has always classified. */\nconst STATEWIRE_START_CHANNEL = 'web';\n\n/** Session label persisted in the thread's panel config (mirrors\n * 'Athena Chrome' / 'Athena mobile' in the sibling statewire hosts). */\nconst STATEWIRE_RUN_LABEL = 'Athena SDK';\n\n/** Deep-agent default model — matches the Olympus and mobile statewire hosts. */\nexport const DEFAULT_STATEWIRE_MODEL = 'claude-sonnet-5-5';\n\n/** Agent-id namespace for collab agents (`collab_agent:<asset_id>`). */\nexport const COLLAB_AGENT_REF_PREFIX = 'collab_agent:';\n\n/** The only shape the `agent` prop accepts, for error messages and docs. */\nexport const COLLAB_AGENT_REF_SHAPE = 'collab_agent:<asset_id>';\n\n/** The asset id when `agent` is a `collab_agent:<asset_id>` ref, else null. */\nexport function parseCollabAgentRef(agent: string | undefined | null): string | null {\n if (typeof agent !== 'string' || !agent.startsWith(COLLAB_AGENT_REF_PREFIX)) return null;\n const assetId = agent.slice(COLLAB_AGENT_REF_PREFIX.length).trim();\n return assetId || null;\n}\n\n/**\n * Resolve the provider's `agent` prop to a collab-agent asset id.\n *\n * An omitted or blank `agent` means \"no agent selected\" — the thread runs the\n * Athena deep agent — and resolves to `null`. A `collab_agent:<asset_id>` ref\n * resolves to the asset id. Any other non-blank value throws: the statewire\n * host cannot honour it, and a selector that is silently dropped would let a\n * misconfigured deployment ship answers from the wrong agent.\n */\nexport function resolveAgentProp({ agent }: { agent: string | undefined | null }): string | null {\n if (agent === undefined || agent === null || agent.trim() === '') return null;\n const assetId = parseCollabAgentRef(agent.trim());\n if (assetId) return assetId;\n throw new Error(\n `[AthenaSDK] Unsupported \\`agent\\` prop ${JSON.stringify(agent)}. The only accepted shape is '${COLLAB_AGENT_REF_SHAPE}' (the asset id of a published collab agent). Named agents are not supported — the statewire host always runs the Athena deep agent; omit \\`agent\\` to use it.`,\n );\n}\n\nexport interface StatewireRunConfigOptions {\n /** LLM model identifier. Defaults to the deep-agent default model — unless a\n * collab agent is selected and its author set one (the backend overlay\n * applies the agent's model when the run sends none), in which case no\n * model is sent so the agent's choice wins. */\n model?: string;\n /** Agent selector. Only the `collab_agent:<asset_id>` shape is accepted: the\n * run executes AS that published collab agent (prompt, tools, model\n * default). Any other non-empty value throws (see {@link resolveAgentProp}). */\n agent?: string;\n /** Collab-agent channel id (built-in like `email`/`sms`, or a user-defined\n * custom channel id) selecting that channel's configuration overrides.\n * Sent as `collab_channel_id`; only meaningful with a collab `agent`. */\n channel?: string;\n /** Backend toolkit IDs to enable. */\n tools?: string[];\n /** Frontend tool IDs to include in enabled_tools. */\n frontendToolIds?: string[];\n /** Asset IDs to include in the workbench. */\n workbench?: string[];\n /** Knowledge base IDs for RAG context. */\n knowledgeBase?: string[];\n /** System prompt override. */\n systemPrompt?: string;\n /** Client app identifier, passed through as app_id. */\n appId?: string;\n /** Client-executed tool declarations, passed through as client_tools. The\n * deep-agent runtime binds each as an interrupt-backed tool the client\n * answers via the statewire client-tool bridge. */\n clientTools?: Record<string, unknown>[];\n /** Additional fields merged into runConfig.custom. */\n extraRunConfig?: Record<string, unknown>;\n}\n\n/**\n * Build the `runConfig` a deep-agent statewire run is driven by. Commands\n * travel bare on the statewire channel, so this payload rides the ambient\n * model context (`config.runConfig`) instead of the request body.\n *\n * The flattened `custom` fields drive the run, while `panel_config` carries a\n * minimal panel state the backend persists per thread and replays on the\n * statewire snapshot — so a session started from the SDK stays configured\n * when reopened elsewhere.\n */\nexport function buildStatewireRunConfig(\n options: StatewireRunConfigOptions = {},\n): Record<string, unknown> {\n const collabAgentId = resolveAgentProp({ agent: options.agent });\n const collabChannelId =\n collabAgentId && options.channel?.trim() ? options.channel.trim() : undefined;\n // With a collab agent selected and no explicit model, send NO model: the\n // backend overlay then applies the model the agent's author configured\n // instead of the SDK default overriding it.\n const model = options.model ?? (collabAgentId ? undefined : DEFAULT_STATEWIRE_MODEL);\n const panelModel = model ?? DEFAULT_STATEWIRE_MODEL;\n const enabledTools = Array.from(\n new Set([...(options.tools ?? []), ...(options.frontendToolIds ?? [])]),\n );\n const systemPrompt = options.systemPrompt?.trim() ?? '';\n\n return {\n custom: {\n runtime: DEEP_AGENT_RUNTIME_MARKER,\n // With a collab channel selected, omit the SDK's own 'web' stamp: the\n // request's explicit start_channel would win over the backend overlay's\n // kind-mapped provenance (a custom SMS channel must stamp 'sms').\n ...(collabChannelId ? {} : { start_channel: STATEWIRE_START_CHANNEL }),\n ...(model ? { model } : {}),\n // An empty list is behavior-identical to an absent key for the parser\n // (both coerce to []), but the collab-agent overlay merges request keys\n // OVER the agent definition — so an explicit empty list would erase the\n // agent's configured tools. Omit it when empty.\n ...(enabledTools.length > 0 ? { enabled_tools: enabledTools } : {}),\n panel_config: {\n model: panelModel,\n enabled_tools: enabledTools,\n system_prompt: systemPrompt,\n run_label: STATEWIRE_RUN_LABEL,\n },\n ...(collabAgentId ? { collab_agent_id: collabAgentId } : {}),\n ...(collabChannelId ? { collab_channel_id: collabChannelId } : {}),\n ...(systemPrompt ? { system_prompt: systemPrompt } : {}),\n ...(options.workbench?.length ? { workbench: options.workbench } : {}),\n ...(options.knowledgeBase?.length\n ? { knowledge_base: options.knowledgeBase }\n : {}),\n ...(options.appId ? { app_id: options.appId } : {}),\n ...(options.clientTools?.length ? { client_tools: options.clientTools } : {}),\n ...(options.extraRunConfig ?? {}),\n },\n };\n}\n"],"names":[],"mappings":";;AACA,MAAM,4BAA4B;AAIlC,MAAM,0BAA0B;AAIhC,MAAM,sBAAsB;AAGrB,MAAM,0BAA0B;AAGhC,MAAM,0BAA0B;AAGhC,MAAM,yBAAyB;AAG/B,SAAS,oBAAoB,OAAiD;AACnF,MAAI,OAAO,UAAU,YAAY,CAAC,MAAM,WAAW,uBAAuB,EAAG,QAAO;AACpF,QAAM,UAAU,MAAM,MAAM,wBAAwB,MAAM,EAAE,KAAA;AAC5D,SAAO,WAAW;AACpB;AAWO,SAAS,iBAAiB,EAAE,SAA8D;AAC/F,MAAI,UAAU,UAAa,UAAU,QAAQ,MAAM,KAAA,MAAW,GAAI,QAAO;AACzE,QAAM,UAAU,oBAAoB,MAAM,KAAA,CAAM;AAChD,MAAI,QAAS,QAAO;AACpB,QAAM,IAAI;AAAA,IACR,0CAA0C,KAAK,UAAU,KAAK,CAAC,iCAAiC,sBAAsB;AAAA,EAAA;AAE1H;AA8CO,SAAS,wBACd,UAAqC,IACZ;;AACzB,QAAM,gBAAgB,iBAAiB,EAAE,OAAO,QAAQ,OAAO;AAC/D,QAAM,kBACJ,mBAAiB,aAAQ,YAAR,mBAAiB,UAAS,QAAQ,QAAQ,KAAA,IAAS;AAItE,QAAM,QAAQ,QAAQ,UAAU,gBAAgB,SAAY;AAC5D,QAAM,aAAa,SAAS;AAC5B,QAAM,eAAe,MAAM;AAAA,IACzB,oBAAI,IAAI,CAAC,GAAI,QAAQ,SAAS,CAAA,GAAK,GAAI,QAAQ,mBAAmB,EAAG,CAAC;AAAA,EAAA;AAExE,QAAM,iBAAe,aAAQ,iBAAR,mBAAsB,WAAU;AAErD,SAAO;AAAA,IACL,QAAQ;AAAA,MACN,SAAS;AAAA;AAAA;AAAA;AAAA,MAIT,GAAI,kBAAkB,CAAA,IAAK,EAAE,eAAe,wBAAA;AAAA,MAC5C,GAAI,QAAQ,EAAE,MAAA,IAAU,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAKxB,GAAI,aAAa,SAAS,IAAI,EAAE,eAAe,aAAA,IAAiB,CAAA;AAAA,MAChE,cAAc;AAAA,QACZ,OAAO;AAAA,QACP,eAAe;AAAA,QACf,eAAe;AAAA,QACf,WAAW;AAAA,MAAA;AAAA,MAEb,GAAI,gBAAgB,EAAE,iBAAiB,cAAA,IAAkB,CAAA;AAAA,MACzD,GAAI,kBAAkB,EAAE,mBAAmB,gBAAA,IAAoB,CAAA;AAAA,MAC/D,GAAI,eAAe,EAAE,eAAe,aAAA,IAAiB,CAAA;AAAA,MACrD,KAAI,aAAQ,cAAR,mBAAmB,UAAS,EAAE,WAAW,QAAQ,UAAA,IAAc,CAAA;AAAA,MACnE,KAAI,aAAQ,kBAAR,mBAAuB,UACvB,EAAE,gBAAgB,QAAQ,cAAA,IAC1B,CAAA;AAAA,MACJ,GAAI,QAAQ,QAAQ,EAAE,QAAQ,QAAQ,MAAA,IAAU,CAAA;AAAA,MAChD,KAAI,aAAQ,gBAAR,mBAAqB,UAAS,EAAE,cAAc,QAAQ,YAAA,IAAgB,CAAA;AAAA,MAC1E,GAAI,QAAQ,kBAAkB,CAAA;AAAA,IAAC;AAAA,EACjC;AAEJ;;;;;;;"}
1
+ {"version":3,"file":"statewire-run-config.cjs","sources":["../../src/runtime/statewire-run-config.ts"],"sourcesContent":["/** Runtime marker the deep-agent session substrate stamps on sessions. */\nconst DEEP_AGENT_RUNTIME_MARKER = 'athena_deep_agent';\n\n/** Session-origin channel. The backend clamps unknown values to 'web', which\n * is how every SDK-started session has always classified. */\nconst STATEWIRE_START_CHANNEL = 'web';\n\n/** Session label persisted in the thread's panel config (mirrors\n * 'Athena Chrome' / 'Athena mobile' in the sibling statewire hosts). */\nconst STATEWIRE_RUN_LABEL = 'Athena SDK';\n\n/** Deep-agent default model — matches the Olympus and mobile statewire hosts. */\nexport const DEFAULT_STATEWIRE_MODEL = 'claude-sonnet-5-5';\n\n/** Agent-id namespace for collab agents (`collab_agent:<asset_id>`). */\nexport const COLLAB_AGENT_REF_PREFIX = 'collab_agent:';\n\n/** The only shape the `agent` prop accepts, for error messages and docs. */\nexport const COLLAB_AGENT_REF_SHAPE = 'collab_agent:<asset_id>';\n\n/** The asset id when `agent` is a `collab_agent:<asset_id>` ref, else null. */\nexport function parseCollabAgentRef(agent: string | undefined | null): string | null {\n if (typeof agent !== 'string' || !agent.startsWith(COLLAB_AGENT_REF_PREFIX)) return null;\n const assetId = agent.slice(COLLAB_AGENT_REF_PREFIX.length).trim();\n return assetId || null;\n}\n\n/**\n * Resolve the provider's `agent` prop to a collab-agent asset id.\n *\n * An omitted or blank `agent` means \"no agent selected\" — the thread runs the\n * Athena deep agent — and resolves to `null`. A `collab_agent:<asset_id>` ref\n * resolves to the asset id. Any other non-blank value throws: the statewire\n * host cannot honour it, and a selector that is silently dropped would let a\n * misconfigured deployment ship answers from the wrong agent.\n */\nexport function resolveAgentProp({ agent }: { agent: string | undefined | null }): string | null {\n if (agent === undefined || agent === null || agent.trim() === '') return null;\n const assetId = parseCollabAgentRef(agent.trim());\n if (assetId) return assetId;\n throw new Error(\n `[AthenaSDK] Unsupported \\`agent\\` prop ${JSON.stringify(agent)}. The only accepted shape is '${COLLAB_AGENT_REF_SHAPE}' (the asset id of a published collab agent). Named agents are not supported — the statewire host always runs the Athena deep agent; omit \\`agent\\` to use it.`,\n );\n}\n\nexport interface StatewireRunConfigOptions {\n /** LLM model identifier. Defaults to the deep-agent default model — unless a\n * collab agent is selected and its author set one (the backend overlay\n * applies the agent's model when the run sends none), in which case no\n * model is sent so the agent's choice wins. */\n model?: string;\n /** Agent selector. Only the `collab_agent:<asset_id>` shape is accepted: the\n * run executes AS that published collab agent (prompt, tools, model\n * default). Any other non-empty value throws (see {@link resolveAgentProp}). */\n agent?: string;\n /** Collab-agent channel id (built-in like `email`/`sms`, or a user-defined\n * custom channel id) selecting that channel's configuration overrides.\n * Sent as `collab_channel_id`; only meaningful with a collab `agent`. */\n channel?: string;\n /** Backend toolkit IDs to enable. */\n tools?: string[];\n /** Frontend tool IDs to include in enabled_tools. */\n frontendToolIds?: string[];\n /** Asset IDs to include in the workbench. */\n workbench?: string[];\n /** Knowledge base IDs for RAG context. */\n knowledgeBase?: string[];\n /** System prompt override. */\n systemPrompt?: string;\n /** Client app identifier, passed through as app_id. */\n appId?: string;\n /** Client-executed tool declarations, passed through as client_tools. The\n * deep-agent runtime binds each as an interrupt-backed tool the client\n * answers via the statewire client-tool bridge. */\n clientTools?: Record<string, unknown>[];\n /** Additional fields merged into runConfig.custom. */\n extraRunConfig?: Record<string, unknown>;\n}\n\n/**\n * The model a send carries for the host's `model` and `extraRunConfig`, with\n * the precedence {@link buildStatewireRunConfig} applies: `extraRunConfig` is\n * merged last, so its `model` key (when it has one) wins over the `model`\n * prop. `undefined` when the send carries no explicit model.\n */\nexport function effectiveStatewireModel({\n model,\n extraRunConfig,\n}: {\n model: string | undefined;\n extraRunConfig: Record<string, unknown> | undefined;\n}): string | undefined {\n if (extraRunConfig !== undefined && Object.hasOwn(extraRunConfig, 'model')) {\n const override = extraRunConfig.model;\n return typeof override === 'string' && override !== '' ? override : undefined;\n }\n return model === '' ? undefined : model;\n}\n\n/**\n * Build the `runConfig` a deep-agent statewire run is driven by. Commands\n * travel bare on the statewire channel, so this payload rides the ambient\n * model context (`config.runConfig`) instead of the request body.\n *\n * The flattened `custom` fields drive the run, while `panel_config` carries a\n * minimal panel state the backend persists per thread and replays on the\n * statewire snapshot — so a session started from the SDK stays configured\n * when reopened elsewhere.\n */\nexport function buildStatewireRunConfig(\n options: StatewireRunConfigOptions = {},\n): Record<string, unknown> {\n const collabAgentId = resolveAgentProp({ agent: options.agent });\n const collabChannelId =\n collabAgentId && options.channel?.trim() ? options.channel.trim() : undefined;\n // With a collab agent selected and no explicit model, send NO model: the\n // backend overlay then applies the model the agent's author configured\n // instead of the SDK default overriding it.\n const model = options.model ?? (collabAgentId ? undefined : DEFAULT_STATEWIRE_MODEL);\n const enabledTools = Array.from(\n new Set([...(options.tools ?? []), ...(options.frontendToolIds ?? [])]),\n );\n const systemPrompt = options.systemPrompt?.trim() ?? '';\n\n return {\n custom: {\n runtime: DEEP_AGENT_RUNTIME_MARKER,\n // With a collab channel selected, omit the SDK's own 'web' stamp: the\n // request's explicit start_channel would win over the backend overlay's\n // kind-mapped provenance (a custom SMS channel must stamp 'sms').\n ...(collabChannelId ? {} : { start_channel: STATEWIRE_START_CHANNEL }),\n ...(model ? { model } : {}),\n // An empty list is behavior-identical to an absent key for the parser\n // (both coerce to []), but the collab-agent overlay merges request keys\n // OVER the agent definition — so an explicit empty list would erase the\n // agent's configured tools. Omit it when empty.\n ...(enabledTools.length > 0 ? { enabled_tools: enabledTools } : {}),\n panel_config: {\n // A collab agent's thread with no explicit model names none here\n // either: agora stores this panel on the thread's first run and\n // replays it to every client, and a stored SDK default would show as\n // the session's model while the agent's own model runs.\n ...(model ? { model } : {}),\n enabled_tools: enabledTools,\n system_prompt: systemPrompt,\n run_label: STATEWIRE_RUN_LABEL,\n },\n ...(collabAgentId ? { collab_agent_id: collabAgentId } : {}),\n ...(collabChannelId ? { collab_channel_id: collabChannelId } : {}),\n ...(systemPrompt ? { system_prompt: systemPrompt } : {}),\n ...(options.workbench?.length ? { workbench: options.workbench } : {}),\n ...(options.knowledgeBase?.length\n ? { knowledge_base: options.knowledgeBase }\n : {}),\n ...(options.appId ? { app_id: options.appId } : {}),\n ...(options.clientTools?.length ? { client_tools: options.clientTools } : {}),\n ...(options.extraRunConfig ?? {}),\n },\n };\n}\n"],"names":[],"mappings":";;AACA,MAAM,4BAA4B;AAIlC,MAAM,0BAA0B;AAIhC,MAAM,sBAAsB;AAGrB,MAAM,0BAA0B;AAGhC,MAAM,0BAA0B;AAGhC,MAAM,yBAAyB;AAG/B,SAAS,oBAAoB,OAAiD;AACnF,MAAI,OAAO,UAAU,YAAY,CAAC,MAAM,WAAW,uBAAuB,EAAG,QAAO;AACpF,QAAM,UAAU,MAAM,MAAM,wBAAwB,MAAM,EAAE,KAAA;AAC5D,SAAO,WAAW;AACpB;AAWO,SAAS,iBAAiB,EAAE,SAA8D;AAC/F,MAAI,UAAU,UAAa,UAAU,QAAQ,MAAM,KAAA,MAAW,GAAI,QAAO;AACzE,QAAM,UAAU,oBAAoB,MAAM,KAAA,CAAM;AAChD,MAAI,QAAS,QAAO;AACpB,QAAM,IAAI;AAAA,IACR,0CAA0C,KAAK,UAAU,KAAK,CAAC,iCAAiC,sBAAsB;AAAA,EAAA;AAE1H;AA0CO,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AACF,GAGuB;AACrB,MAAI,mBAAmB,UAAa,OAAO,OAAO,gBAAgB,OAAO,GAAG;AAC1E,UAAM,WAAW,eAAe;AAChC,WAAO,OAAO,aAAa,YAAY,aAAa,KAAK,WAAW;AAAA,EACtE;AACA,SAAO,UAAU,KAAK,SAAY;AACpC;AAYO,SAAS,wBACd,UAAqC,IACZ;;AACzB,QAAM,gBAAgB,iBAAiB,EAAE,OAAO,QAAQ,OAAO;AAC/D,QAAM,kBACJ,mBAAiB,aAAQ,YAAR,mBAAiB,UAAS,QAAQ,QAAQ,KAAA,IAAS;AAItE,QAAM,QAAQ,QAAQ,UAAU,gBAAgB,SAAY;AAC5D,QAAM,eAAe,MAAM;AAAA,IACzB,oBAAI,IAAI,CAAC,GAAI,QAAQ,SAAS,CAAA,GAAK,GAAI,QAAQ,mBAAmB,EAAG,CAAC;AAAA,EAAA;AAExE,QAAM,iBAAe,aAAQ,iBAAR,mBAAsB,WAAU;AAErD,SAAO;AAAA,IACL,QAAQ;AAAA,MACN,SAAS;AAAA;AAAA;AAAA;AAAA,MAIT,GAAI,kBAAkB,CAAA,IAAK,EAAE,eAAe,wBAAA;AAAA,MAC5C,GAAI,QAAQ,EAAE,MAAA,IAAU,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAKxB,GAAI,aAAa,SAAS,IAAI,EAAE,eAAe,aAAA,IAAiB,CAAA;AAAA,MAChE,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA,QAKZ,GAAI,QAAQ,EAAE,MAAA,IAAU,CAAA;AAAA,QACxB,eAAe;AAAA,QACf,eAAe;AAAA,QACf,WAAW;AAAA,MAAA;AAAA,MAEb,GAAI,gBAAgB,EAAE,iBAAiB,cAAA,IAAkB,CAAA;AAAA,MACzD,GAAI,kBAAkB,EAAE,mBAAmB,gBAAA,IAAoB,CAAA;AAAA,MAC/D,GAAI,eAAe,EAAE,eAAe,aAAA,IAAiB,CAAA;AAAA,MACrD,KAAI,aAAQ,cAAR,mBAAmB,UAAS,EAAE,WAAW,QAAQ,UAAA,IAAc,CAAA;AAAA,MACnE,KAAI,aAAQ,kBAAR,mBAAuB,UACvB,EAAE,gBAAgB,QAAQ,cAAA,IAC1B,CAAA;AAAA,MACJ,GAAI,QAAQ,QAAQ,EAAE,QAAQ,QAAQ,MAAA,IAAU,CAAA;AAAA,MAChD,KAAI,aAAQ,gBAAR,mBAAqB,UAAS,EAAE,cAAc,QAAQ,YAAA,IAAgB,CAAA;AAAA,MAC1E,GAAI,QAAQ,kBAAkB,CAAA;AAAA,IAAC;AAAA,EACjC;AAEJ;;;;;;;;"}
@@ -51,6 +51,16 @@ export interface StatewireRunConfigOptions {
51
51
  /** Additional fields merged into runConfig.custom. */
52
52
  extraRunConfig?: Record<string, unknown>;
53
53
  }
54
+ /**
55
+ * The model a send carries for the host's `model` and `extraRunConfig`, with
56
+ * the precedence {@link buildStatewireRunConfig} applies: `extraRunConfig` is
57
+ * merged last, so its `model` key (when it has one) wins over the `model`
58
+ * prop. `undefined` when the send carries no explicit model.
59
+ */
60
+ export declare function effectiveStatewireModel({ model, extraRunConfig, }: {
61
+ model: string | undefined;
62
+ extraRunConfig: Record<string, unknown> | undefined;
63
+ }): string | undefined;
54
64
  /**
55
65
  * Build the `runConfig` a deep-agent statewire run is driven by. Commands
56
66
  * travel bare on the statewire channel, so this payload rides the ambient