@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
@@ -17,12 +17,21 @@ function resolveAgentProp({ agent }) {
17
17
  `[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.`
18
18
  );
19
19
  }
20
+ function effectiveStatewireModel({
21
+ model,
22
+ extraRunConfig
23
+ }) {
24
+ if (extraRunConfig !== void 0 && Object.hasOwn(extraRunConfig, "model")) {
25
+ const override = extraRunConfig.model;
26
+ return typeof override === "string" && override !== "" ? override : void 0;
27
+ }
28
+ return model === "" ? void 0 : model;
29
+ }
20
30
  function buildStatewireRunConfig(options = {}) {
21
31
  var _a, _b, _c, _d, _e;
22
32
  const collabAgentId = resolveAgentProp({ agent: options.agent });
23
33
  const collabChannelId = collabAgentId && ((_a = options.channel) == null ? void 0 : _a.trim()) ? options.channel.trim() : void 0;
24
34
  const model = options.model ?? (collabAgentId ? void 0 : DEFAULT_STATEWIRE_MODEL);
25
- const panelModel = model ?? DEFAULT_STATEWIRE_MODEL;
26
35
  const enabledTools = Array.from(
27
36
  /* @__PURE__ */ new Set([...options.tools ?? [], ...options.frontendToolIds ?? []])
28
37
  );
@@ -41,7 +50,11 @@ function buildStatewireRunConfig(options = {}) {
41
50
  // agent's configured tools. Omit it when empty.
42
51
  ...enabledTools.length > 0 ? { enabled_tools: enabledTools } : {},
43
52
  panel_config: {
44
- model: panelModel,
53
+ // A collab agent's thread with no explicit model names none here
54
+ // either: agora stores this panel on the thread's first run and
55
+ // replays it to every client, and a stored SDK default would show as
56
+ // the session's model while the agent's own model runs.
57
+ ...model ? { model } : {},
45
58
  enabled_tools: enabledTools,
46
59
  system_prompt: systemPrompt,
47
60
  run_label: STATEWIRE_RUN_LABEL
@@ -62,6 +75,7 @@ export {
62
75
  COLLAB_AGENT_REF_SHAPE,
63
76
  DEFAULT_STATEWIRE_MODEL,
64
77
  buildStatewireRunConfig,
78
+ effectiveStatewireModel,
65
79
  parseCollabAgentRef,
66
80
  resolveAgentProp
67
81
  };
@@ -1 +1 @@
1
- {"version":3,"file":"statewire-run-config.js","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;AA1F3B;AA2FE,QAAM,gBAAgB,iBAAiB,EAAE,OAAO,QAAQ,OAAO;AAC/D,QAAM,kBACJ,mBAAiB,aAAQ,YAAR,mBAAiB,UAAS,QAAQ,QAAQ,KAAA,IAA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ources":["../../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;AA9G3B;AA+GE,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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+ const react = require("react");
4
+ const STATEWIRE_SERVER_LANE_PENDING = Object.freeze({
5
+ landed: false,
6
+ config: null
7
+ });
8
+ const AthenaStatewireServerLaneContext = react.createContext(
9
+ null
10
+ );
11
+ function nextServerLane({
12
+ previous,
13
+ config
14
+ }) {
15
+ var _a;
16
+ if (previous.landed && (((_a = previous.config) == null ? void 0 : _a.version) ?? 0) === ((config == null ? void 0 : config.version) ?? 0)) {
17
+ return previous;
18
+ }
19
+ return { landed: true, config };
20
+ }
21
+ exports.AthenaStatewireServerLaneContext = AthenaStatewireServerLaneContext;
22
+ exports.STATEWIRE_SERVER_LANE_PENDING = STATEWIRE_SERVER_LANE_PENDING;
23
+ exports.nextServerLane = nextServerLane;
24
+ //# sourceMappingURL=statewire-server-lane-context.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statewire-server-lane-context.cjs","sources":["../../src/runtime/statewire-server-lane-context.ts"],"sourcesContent":["import type { DeepAgentServerConfig } from '@athenaintel/agent-runtime';\nimport { createContext } from 'react';\n\n/**\n * The thread's server config lane as the statewire host last sent it on this\n * attach, read off the transport's own state (`onStateChange`) rather than the\n * thread state the chat renders.\n *\n * The rendered state starts as a placeholder (or a remembered snapshot) before\n * the attach snapshot lands, and neither says what the server holds: a\n * placeholder has no lane at all and a remembered snapshot may carry an older\n * one. Anything that decides from the lane (`useAthenaThreadModel`, the\n * thread-config writes in `StatewireThreadConfigLaneSync`) waits for `landed`.\n */\nexport interface AthenaStatewireServerLane {\n /** `true` once this attach's snapshot from the host has arrived. */\n landed: boolean;\n /** The lane in that snapshot (and every later host frame), `null` at version 0. */\n config: DeepAgentServerConfig | null;\n}\n\nexport const STATEWIRE_SERVER_LANE_PENDING: AthenaStatewireServerLane = Object.freeze({\n landed: false,\n config: null,\n});\n\n/** Provided by `AthenaProvider` around the host's children, per attached thread. */\nexport const AthenaStatewireServerLaneContext = createContext<AthenaStatewireServerLane | null>(\n null,\n);\n\n/**\n * The next lane value for a host frame: the same object while the lane's\n * version is unchanged, so a frame that moved only messages (every streamed\n * token) re-renders nothing.\n */\nexport function nextServerLane({\n previous,\n config,\n}: {\n previous: AthenaStatewireServerLane;\n config: DeepAgentServerConfig | null;\n}): AthenaStatewireServerLane {\n if (previous.landed && (previous.config?.version ?? 0) === (config?.version ?? 0)) {\n return previous;\n }\n return { landed: true, config };\n}\n"],"names":["createContext"],"mappings":";;;AAqBO,MAAM,gCAA2D,OAAO,OAAO;AAAA,EACpF,QAAQ;AAAA,EACR,QAAQ;AACV,CAAC;AAGM,MAAM,mCAAmCA,MAAAA;AAAAA,EAC9C;AACF;AAOO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAG8B;;AAC5B,MAAI,SAAS,aAAW,cAAS,WAAT,mBAAiB,YAAW,SAAQ,iCAAQ,YAAW,IAAI;AACjF,WAAO;AAAA,EACT;AACA,SAAO,EAAE,QAAQ,MAAM,OAAA;AACzB;;;;"}
@@ -0,0 +1,30 @@
1
+ import type { DeepAgentServerConfig } from '@athenaintel/agent-runtime';
2
+ /**
3
+ * The thread's server config lane as the statewire host last sent it on this
4
+ * attach, read off the transport's own state (`onStateChange`) rather than the
5
+ * thread state the chat renders.
6
+ *
7
+ * The rendered state starts as a placeholder (or a remembered snapshot) before
8
+ * the attach snapshot lands, and neither says what the server holds: a
9
+ * placeholder has no lane at all and a remembered snapshot may carry an older
10
+ * one. Anything that decides from the lane (`useAthenaThreadModel`, the
11
+ * thread-config writes in `StatewireThreadConfigLaneSync`) waits for `landed`.
12
+ */
13
+ export interface AthenaStatewireServerLane {
14
+ /** `true` once this attach's snapshot from the host has arrived. */
15
+ landed: boolean;
16
+ /** The lane in that snapshot (and every later host frame), `null` at version 0. */
17
+ config: DeepAgentServerConfig | null;
18
+ }
19
+ export declare const STATEWIRE_SERVER_LANE_PENDING: AthenaStatewireServerLane;
20
+ /** Provided by `AthenaProvider` around the host's children, per attached thread. */
21
+ export declare const AthenaStatewireServerLaneContext: import("react").Context<AthenaStatewireServerLane | null>;
22
+ /**
23
+ * The next lane value for a host frame: the same object while the lane's
24
+ * version is unchanged, so a frame that moved only messages (every streamed
25
+ * token) re-renders nothing.
26
+ */
27
+ export declare function nextServerLane({ previous, config, }: {
28
+ previous: AthenaStatewireServerLane;
29
+ config: DeepAgentServerConfig | null;
30
+ }): AthenaStatewireServerLane;
@@ -0,0 +1,24 @@
1
+ import { createContext } from "react";
2
+ const STATEWIRE_SERVER_LANE_PENDING = Object.freeze({
3
+ landed: false,
4
+ config: null
5
+ });
6
+ const AthenaStatewireServerLaneContext = createContext(
7
+ null
8
+ );
9
+ function nextServerLane({
10
+ previous,
11
+ config
12
+ }) {
13
+ var _a;
14
+ if (previous.landed && (((_a = previous.config) == null ? void 0 : _a.version) ?? 0) === ((config == null ? void 0 : config.version) ?? 0)) {
15
+ return previous;
16
+ }
17
+ return { landed: true, config };
18
+ }
19
+ export {
20
+ AthenaStatewireServerLaneContext,
21
+ STATEWIRE_SERVER_LANE_PENDING,
22
+ nextServerLane
23
+ };
24
+ //# sourceMappingURL=statewire-server-lane-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statewire-server-lane-context.js","sources":["../../src/runtime/statewire-server-lane-context.ts"],"sourcesContent":["import type { DeepAgentServerConfig } from '@athenaintel/agent-runtime';\nimport { createContext } from 'react';\n\n/**\n * The thread's server config lane as the statewire host last sent it on this\n * attach, read off the transport's own state (`onStateChange`) rather than the\n * thread state the chat renders.\n *\n * The rendered state starts as a placeholder (or a remembered snapshot) before\n * the attach snapshot lands, and neither says what the server holds: a\n * placeholder has no lane at all and a remembered snapshot may carry an older\n * one. Anything that decides from the lane (`useAthenaThreadModel`, the\n * thread-config writes in `StatewireThreadConfigLaneSync`) waits for `landed`.\n */\nexport interface AthenaStatewireServerLane {\n /** `true` once this attach's snapshot from the host has arrived. */\n landed: boolean;\n /** The lane in that snapshot (and every later host frame), `null` at version 0. */\n config: DeepAgentServerConfig | null;\n}\n\nexport const STATEWIRE_SERVER_LANE_PENDING: AthenaStatewireServerLane = Object.freeze({\n landed: false,\n config: null,\n});\n\n/** Provided by `AthenaProvider` around the host's children, per attached thread. */\nexport const AthenaStatewireServerLaneContext = createContext<AthenaStatewireServerLane | null>(\n null,\n);\n\n/**\n * The next lane value for a host frame: the same object while the lane's\n * version is unchanged, so a frame that moved only messages (every streamed\n * token) re-renders nothing.\n */\nexport function nextServerLane({\n previous,\n config,\n}: {\n previous: AthenaStatewireServerLane;\n config: DeepAgentServerConfig | null;\n}): AthenaStatewireServerLane {\n if (previous.landed && (previous.config?.version ?? 0) === (config?.version ?? 0)) {\n return previous;\n }\n return { landed: true, config };\n}\n"],"names":[],"mappings":";AAqBO,MAAM,gCAA2D,OAAO,OAAO;AAAA,EACpF,QAAQ;AAAA,EACR,QAAQ;AACV,CAAC;AAGM,MAAM,mCAAmC;AAAA,EAC9C;AACF;AAOO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAG8B;;AAC5B,MAAI,SAAS,aAAW,cAAS,WAAT,mBAAiB,YAAW,SAAQ,iCAAQ,YAAW,IAAI;AACjF,WAAO;AAAA,EACT;AACA,SAAO,EAAE,QAAQ,MAAM,OAAA;AACzB;"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const statewireRunConfig = require("./statewire-run-config.cjs");
4
+ const PROVIDER_THREAD_CONFIG_KEYS = [
5
+ "model",
6
+ "system_prompt",
7
+ "enabled_tools",
8
+ "workbench",
9
+ "knowledge_base"
10
+ ];
11
+ const nonBlankString = (value) => typeof value === "string" && value.trim() !== "" ? value : null;
12
+ const stringItems = (value) => value.filter((item) => typeof item === "string");
13
+ const propList = (value) => value !== void 0 && value.length > 0 ? value : null;
14
+ const extraList = (value) => Array.isArray(value) ? stringItems(value) : null;
15
+ function providerThreadConfig({
16
+ model,
17
+ systemPrompt,
18
+ tools,
19
+ frontendToolIds,
20
+ workbench,
21
+ knowledgeBase,
22
+ extraRunConfig
23
+ }) {
24
+ const extra = extraRunConfig ?? {};
25
+ const overrides = (key) => Object.hasOwn(extra, key);
26
+ const enabledTools = Array.from(/* @__PURE__ */ new Set([...tools ?? [], ...frontendToolIds ?? []]));
27
+ const trimmedPrompt = (systemPrompt == null ? void 0 : systemPrompt.trim()) ?? "";
28
+ return {
29
+ model: statewireRunConfig.effectiveStatewireModel({ model, extraRunConfig }) ?? null,
30
+ system_prompt: overrides("system_prompt") ? nonBlankString(extra.system_prompt) : trimmedPrompt === "" ? null : trimmedPrompt,
31
+ enabled_tools: overrides("enabled_tools") ? extraList(extra.enabled_tools) : propList(enabledTools),
32
+ workbench: overrides("workbench") ? extraList(extra.workbench) : propList(workbench),
33
+ knowledge_base: overrides("knowledge_base") ? extraList(extra.knowledge_base) : propList(knowledgeBase)
34
+ };
35
+ }
36
+ function readLaneThreadConfigValue({
37
+ custom,
38
+ key
39
+ }) {
40
+ const value = custom[key];
41
+ if (key === "model") return typeof value === "string" && value !== "" ? value : null;
42
+ if (key === "system_prompt") return nonBlankString(value);
43
+ return Array.isArray(value) ? stringItems(value) : null;
44
+ }
45
+ function sameThreadConfigValue(left, right) {
46
+ if (left === right) return true;
47
+ if (!Array.isArray(left) || !Array.isArray(right)) return false;
48
+ return left.length === right.length && left.every((item, index) => item === right[index]);
49
+ }
50
+ function decideThreadConfigLanePatch({
51
+ desired,
52
+ keys,
53
+ landed,
54
+ configVersion,
55
+ custom
56
+ }) {
57
+ if (!landed || configVersion <= 0) return { kind: "wait" };
58
+ const pending = new Set(keys);
59
+ const patch = {};
60
+ for (const key of PROVIDER_THREAD_CONFIG_KEYS) {
61
+ if (!pending.has(key)) continue;
62
+ if (!sameThreadConfigValue(readLaneThreadConfigValue({ custom, key }), desired[key])) {
63
+ copyThreadConfigKey({ target: patch, source: desired, key });
64
+ }
65
+ }
66
+ return patchedThreadConfigKeys(patch).length === 0 ? { kind: "done" } : { kind: "patch", patch };
67
+ }
68
+ function copyThreadConfigKey({
69
+ target,
70
+ source,
71
+ key
72
+ }) {
73
+ target[key] = source[key];
74
+ }
75
+ function patchedThreadConfigKeys(patch) {
76
+ return PROVIDER_THREAD_CONFIG_KEYS.filter((key) => Object.hasOwn(patch, key));
77
+ }
78
+ exports.PROVIDER_THREAD_CONFIG_KEYS = PROVIDER_THREAD_CONFIG_KEYS;
79
+ exports.decideThreadConfigLanePatch = decideThreadConfigLanePatch;
80
+ exports.patchedThreadConfigKeys = patchedThreadConfigKeys;
81
+ exports.providerThreadConfig = providerThreadConfig;
82
+ exports.readLaneThreadConfigValue = readLaneThreadConfigValue;
83
+ exports.sameThreadConfigValue = sameThreadConfigValue;
84
+ //# sourceMappingURL=statewire-thread-config-lane.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statewire-thread-config-lane.cjs","sources":["../../src/runtime/statewire-thread-config-lane.ts"],"sourcesContent":["import type { ThreadConfigCustom } from '@athenaintel/agent-runtime';\nimport { effectiveStatewireModel } from './statewire-run-config';\n\n/**\n * The thread-config keys the provider's props own, in the order a\n * `config/patch` lists them.\n *\n * Once a thread has a server config lane (version > 0), agora composes every\n * run from the lane and drops these keys from a send\n * (`merge_custom_over_server_config`), so a change of the prop that feeds one\n * is written to the lane instead (see `StatewireThreadConfigLaneSync`).\n */\nexport const PROVIDER_THREAD_CONFIG_KEYS = [\n 'model',\n 'system_prompt',\n 'enabled_tools',\n 'workbench',\n 'knowledge_base',\n] as const;\n\nexport type ProviderThreadConfigKey = (typeof PROVIDER_THREAD_CONFIG_KEYS)[number];\n\n/**\n * The provider-owned thread-config values as a send carries them and as the\n * lane stores them; `null` is \"the send carries none\": written to the lane it\n * unsets the key, so the collab agent's own value (or the default) applies.\n */\nexport interface ProviderThreadConfig {\n model: string | null;\n system_prompt: string | null;\n enabled_tools: readonly string[] | null;\n workbench: readonly string[] | null;\n knowledge_base: readonly string[] | null;\n}\n\n/** A `config/patch` payload over provider-owned keys: exactly the keys to change. */\nexport type ProviderThreadConfigPatch = Partial<ProviderThreadConfig>;\n\nconst nonBlankString = (value: unknown): string | null =>\n typeof value === 'string' && value.trim() !== '' ? value : null;\n\nconst stringItems = (value: readonly unknown[]): string[] =>\n value.filter((item): item is string => typeof item === 'string');\n\n/** A list prop as the send carries it: omitted (`null`) when empty, as `buildStatewireRunConfig` does. */\nconst propList = (value: readonly string[] | undefined): readonly string[] | null =>\n value !== undefined && value.length > 0 ? value : null;\n\n/**\n * An `extraRunConfig` list as the send carries it: `buildStatewireRunConfig`\n * merges `extraRunConfig` last and verbatim, so an explicit list (an empty one\n * included) is what the send holds.\n */\nconst extraList = (value: unknown): readonly string[] | null =>\n Array.isArray(value) ? stringItems(value) : null;\n\n/**\n * The provider-owned thread-config values a send built from these props\n * carries, with `buildStatewireRunConfig`'s precedence: `extraRunConfig` is\n * merged last, so a key it holds wins over the prop that feeds it.\n *\n * - `model`: the explicit model only (`effectiveStatewireModel`); the SDK's\n * own default is never a choice to write.\n * - `system_prompt`: the trimmed prompt, `null` when blank.\n * - `enabled_tools`: `tools` ∪ `frontendToolIds`; `null` when empty, since the\n * send omits an empty list (it would erase a collab agent's own tools).\n * - `workbench`, `knowledge_base`: the list, `null` when empty.\n *\n * Pure.\n */\nexport function providerThreadConfig({\n model,\n systemPrompt,\n tools,\n frontendToolIds,\n workbench,\n knowledgeBase,\n extraRunConfig,\n}: {\n model: string | undefined;\n systemPrompt: string | undefined;\n tools: readonly string[] | undefined;\n frontendToolIds: readonly string[] | undefined;\n workbench: readonly string[] | undefined;\n knowledgeBase: readonly string[] | undefined;\n extraRunConfig: Record<string, unknown> | undefined;\n}): ProviderThreadConfig {\n const extra = extraRunConfig ?? {};\n const overrides = (key: ProviderThreadConfigKey) => Object.hasOwn(extra, key);\n const enabledTools = Array.from(new Set([...(tools ?? []), ...(frontendToolIds ?? [])]));\n const trimmedPrompt = systemPrompt?.trim() ?? '';\n return {\n model: effectiveStatewireModel({ model, extraRunConfig }) ?? null,\n system_prompt: overrides('system_prompt')\n ? nonBlankString(extra.system_prompt)\n : trimmedPrompt === ''\n ? null\n : trimmedPrompt,\n enabled_tools: overrides('enabled_tools')\n ? extraList(extra.enabled_tools)\n : propList(enabledTools),\n workbench: overrides('workbench') ? extraList(extra.workbench) : propList(workbench),\n knowledge_base: overrides('knowledge_base')\n ? extraList(extra.knowledge_base)\n : propList(knowledgeBase),\n };\n}\n\n/**\n * A key of the lane (`state.config.custom`) read as a provider-owned value:\n * a text key is its non-blank string, a list key its string items (an\n * explicit empty list included), anything else `null` (unset).\n */\nexport function readLaneThreadConfigValue({\n custom,\n key,\n}: {\n custom: ThreadConfigCustom;\n key: ProviderThreadConfigKey;\n}): string | readonly string[] | null {\n const value = custom[key];\n // `model` keeps `readLaneModel`'s reading: any non-empty string.\n if (key === 'model') return typeof value === 'string' && value !== '' ? value : null;\n if (key === 'system_prompt') return nonBlankString(value);\n return Array.isArray(value) ? stringItems(value) : null;\n}\n\n/** Whether two provider-owned values are the same (lists compared item by item, in order). */\nexport function sameThreadConfigValue(\n left: string | readonly string[] | null,\n right: string | readonly string[] | null,\n): boolean {\n if (left === right) return true;\n if (!Array.isArray(left) || !Array.isArray(right)) return false;\n return left.length === right.length && left.every((item, index) => item === right[index]);\n}\n\n/**\n * What to do with the pending changes of provider-owned keys:\n *\n * - `wait`: keep them pending. The thread's snapshot has not landed, or the\n * thread has no lane yet (version 0): the next send carries the values and\n * agora's deferral seed persists the ones it keeps. They stay pending so that\n * a lane an EARLIER send seeds (with the previous values) is corrected once\n * it lands.\n * - `done`: the lane already holds every one of them (this client's own\n * unacknowledged writes folded over); nothing to write.\n * - `patch`: issue one `config/patch` carrying exactly the keys whose lane\n * value differs; `null` unsets a key so the agent's own value (or the\n * default) applies.\n */\nexport type ThreadConfigLaneDecision =\n | { kind: 'wait' }\n | { kind: 'done' }\n | { kind: 'patch'; patch: ProviderThreadConfigPatch };\n\nexport function decideThreadConfigLanePatch({\n desired,\n keys,\n landed,\n configVersion,\n custom,\n}: {\n /** The provider's values after the changes. */\n desired: ProviderThreadConfig;\n /** The keys whose prop changed during this attach and is not yet written. */\n keys: Iterable<ProviderThreadConfigKey>;\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}): ThreadConfigLaneDecision {\n if (!landed || configVersion <= 0) return { kind: 'wait' };\n const pending = new Set(keys);\n const patch: ProviderThreadConfigPatch = {};\n for (const key of PROVIDER_THREAD_CONFIG_KEYS) {\n if (!pending.has(key)) continue;\n if (!sameThreadConfigValue(readLaneThreadConfigValue({ custom, key }), desired[key])) {\n copyThreadConfigKey({ target: patch, source: desired, key });\n }\n }\n return patchedThreadConfigKeys(patch).length === 0 ? { kind: 'done' } : { kind: 'patch', patch };\n}\n\nfunction copyThreadConfigKey<K extends ProviderThreadConfigKey>({\n target,\n source,\n key,\n}: {\n target: ProviderThreadConfigPatch;\n source: ProviderThreadConfig;\n key: K;\n}): void {\n target[key] = source[key];\n}\n\n/** The keys a patch carries, in {@link PROVIDER_THREAD_CONFIG_KEYS} order. */\nexport function patchedThreadConfigKeys(patch: ProviderThreadConfigPatch): ProviderThreadConfigKey[] {\n return PROVIDER_THREAD_CONFIG_KEYS.filter((key) => Object.hasOwn(patch, key));\n}\n"],"names":["effectiveStatewireModel"],"mappings":";;;AAYO,MAAM,8BAA8B;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAoBA,MAAM,iBAAiB,CAAC,UACtB,OAAO,UAAU,YAAY,MAAM,KAAA,MAAW,KAAK,QAAQ;AAE7D,MAAM,cAAc,CAAC,UACnB,MAAM,OAAO,CAAC,SAAyB,OAAO,SAAS,QAAQ;AAGjE,MAAM,WAAW,CAAC,UAChB,UAAU,UAAa,MAAM,SAAS,IAAI,QAAQ;AAOpD,MAAM,YAAY,CAAC,UACjB,MAAM,QAAQ,KAAK,IAAI,YAAY,KAAK,IAAI;AAgBvC,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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A,EACA;AAAA,EACA;AACF,GAS6B;AAC3B,MAAI,CAAC,UAAU,iBAAiB,EAAG,QAAO,EAAE,MAAM,OAAA;AAClD,QAAM,UAAU,IAAI,IAAI,IAAI;AAC5B,QAAM,QAAmC,CAAA;AACzC,aAAW,OAAO,6BAA6B;AAC7C,QAAI,CAAC,QAAQ,IAAI,GAAG,EAAG;AACvB,QAAI,CAAC,sBAAsB,0BAA0B,EAAE,QAAQ,IAAA,CAAK,GAAG,QAAQ,GAAG,CAAC,GAAG;AACpF,0BAAoB,EAAE,QAAQ,OAAO,QAAQ,SAAS,KAAK;AAAA,IAC7D;AAAA,EACF;AACA,SAAO,wBAAwB,KAAK,EAAE,WAAW,IAAI,EAAE,MAAM,WAAW,EAAE,MAAM,SAAS,MAAA;AAC3F;AAEA,SAAS,oBAAuD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AACF,GAIS;AACP,SAAO,GAAG,IAAI,OAAO,GAAG;AAC1B;AAGO,SAAS,wBAAwB,OAA6D;AACnG,SAAO,4BAA4B,OAAO,CAAC,QAAQ,OAAO,OAAO,OAAO,GAAG,CAAC;AAC9E;;;;;;;"}
@@ -0,0 +1,94 @@
1
+ import type { ThreadConfigCustom } from '@athenaintel/agent-runtime';
2
+ /**
3
+ * The thread-config keys the provider's props own, in the order a
4
+ * `config/patch` lists them.
5
+ *
6
+ * Once a thread has a server config lane (version > 0), agora composes every
7
+ * run from the lane and drops these keys from a send
8
+ * (`merge_custom_over_server_config`), so a change of the prop that feeds one
9
+ * is written to the lane instead (see `StatewireThreadConfigLaneSync`).
10
+ */
11
+ export declare const PROVIDER_THREAD_CONFIG_KEYS: readonly ['model', 'system_prompt', 'enabled_tools', 'workbench', 'knowledge_base'];
12
+ export type ProviderThreadConfigKey = (typeof PROVIDER_THREAD_CONFIG_KEYS)[number];
13
+ /**
14
+ * The provider-owned thread-config values as a send carries them and as the
15
+ * lane stores them; `null` is "the send carries none": written to the lane it
16
+ * unsets the key, so the collab agent's own value (or the default) applies.
17
+ */
18
+ export interface ProviderThreadConfig {
19
+ model: string | null;
20
+ system_prompt: string | null;
21
+ enabled_tools: readonly string[] | null;
22
+ workbench: readonly string[] | null;
23
+ knowledge_base: readonly string[] | null;
24
+ }
25
+ /** A `config/patch` payload over provider-owned keys: exactly the keys to change. */
26
+ export type ProviderThreadConfigPatch = Partial<ProviderThreadConfig>;
27
+ /**
28
+ * The provider-owned thread-config values a send built from these props
29
+ * carries, with `buildStatewireRunConfig`'s precedence: `extraRunConfig` is
30
+ * merged last, so a key it holds wins over the prop that feeds it.
31
+ *
32
+ * - `model`: the explicit model only (`effectiveStatewireModel`); the SDK's
33
+ * own default is never a choice to write.
34
+ * - `system_prompt`: the trimmed prompt, `null` when blank.
35
+ * - `enabled_tools`: `tools` ∪ `frontendToolIds`; `null` when empty, since the
36
+ * send omits an empty list (it would erase a collab agent's own tools).
37
+ * - `workbench`, `knowledge_base`: the list, `null` when empty.
38
+ *
39
+ * Pure.
40
+ */
41
+ export declare function providerThreadConfig({ model, systemPrompt, tools, frontendToolIds, workbench, knowledgeBase, extraRunConfig, }: {
42
+ model: string | undefined;
43
+ systemPrompt: string | undefined;
44
+ tools: readonly string[] | undefined;
45
+ frontendToolIds: readonly string[] | undefined;
46
+ workbench: readonly string[] | undefined;
47
+ knowledgeBase: readonly string[] | undefined;
48
+ extraRunConfig: Record<string, unknown> | undefined;
49
+ }): ProviderThreadConfig;
50
+ /**
51
+ * A key of the lane (`state.config.custom`) read as a provider-owned value:
52
+ * a text key is its non-blank string, a list key its string items (an
53
+ * explicit empty list included), anything else `null` (unset).
54
+ */
55
+ export declare function readLaneThreadConfigValue({ custom, key, }: {
56
+ custom: ThreadConfigCustom;
57
+ key: ProviderThreadConfigKey;
58
+ }): string | readonly string[] | null;
59
+ /** Whether two provider-owned values are the same (lists compared item by item, in order). */
60
+ export declare function sameThreadConfigValue(left: string | readonly string[] | null, right: string | readonly string[] | null): boolean;
61
+ /**
62
+ * What to do with the pending changes of provider-owned keys:
63
+ *
64
+ * - `wait`: keep them pending. The thread's snapshot has not landed, or the
65
+ * thread has no lane yet (version 0): the next send carries the values and
66
+ * agora's deferral seed persists the ones it keeps. They stay pending so that
67
+ * a lane an EARLIER send seeds (with the previous values) is corrected once
68
+ * it lands.
69
+ * - `done`: the lane already holds every one of them (this client's own
70
+ * unacknowledged writes folded over); nothing to write.
71
+ * - `patch`: issue one `config/patch` carrying exactly the keys whose lane
72
+ * value differs; `null` unsets a key so the agent's own value (or the
73
+ * default) applies.
74
+ */
75
+ export type ThreadConfigLaneDecision = {
76
+ kind: 'wait';
77
+ } | {
78
+ kind: 'done';
79
+ } | {
80
+ kind: 'patch';
81
+ patch: ProviderThreadConfigPatch;
82
+ };
83
+ export declare function decideThreadConfigLanePatch({ desired, keys, landed, configVersion, custom, }: {
84
+ /** The provider's values after the changes. */
85
+ desired: ProviderThreadConfig;
86
+ /** The keys whose prop changed during this attach and is not yet written. */
87
+ keys: Iterable<ProviderThreadConfigKey>;
88
+ landed: boolean;
89
+ configVersion: number;
90
+ /** The effective lane: the server config with this client's pending writes folded over. */
91
+ custom: ThreadConfigCustom;
92
+ }): ThreadConfigLaneDecision;
93
+ /** The keys a patch carries, in {@link PROVIDER_THREAD_CONFIG_KEYS} order. */
94
+ export declare function patchedThreadConfigKeys(patch: ProviderThreadConfigPatch): ProviderThreadConfigKey[];
@@ -0,0 +1,84 @@
1
+ import { effectiveStatewireModel } from "./statewire-run-config.js";
2
+ const PROVIDER_THREAD_CONFIG_KEYS = [
3
+ "model",
4
+ "system_prompt",
5
+ "enabled_tools",
6
+ "workbench",
7
+ "knowledge_base"
8
+ ];
9
+ const nonBlankString = (value) => typeof value === "string" && value.trim() !== "" ? value : null;
10
+ const stringItems = (value) => value.filter((item) => typeof item === "string");
11
+ const propList = (value) => value !== void 0 && value.length > 0 ? value : null;
12
+ const extraList = (value) => Array.isArray(value) ? stringItems(value) : null;
13
+ function providerThreadConfig({
14
+ model,
15
+ systemPrompt,
16
+ tools,
17
+ frontendToolIds,
18
+ workbench,
19
+ knowledgeBase,
20
+ extraRunConfig
21
+ }) {
22
+ const extra = extraRunConfig ?? {};
23
+ const overrides = (key) => Object.hasOwn(extra, key);
24
+ const enabledTools = Array.from(/* @__PURE__ */ new Set([...tools ?? [], ...frontendToolIds ?? []]));
25
+ const trimmedPrompt = (systemPrompt == null ? void 0 : systemPrompt.trim()) ?? "";
26
+ return {
27
+ model: effectiveStatewireModel({ model, extraRunConfig }) ?? null,
28
+ system_prompt: overrides("system_prompt") ? nonBlankString(extra.system_prompt) : trimmedPrompt === "" ? null : trimmedPrompt,
29
+ enabled_tools: overrides("enabled_tools") ? extraList(extra.enabled_tools) : propList(enabledTools),
30
+ workbench: overrides("workbench") ? extraList(extra.workbench) : propList(workbench),
31
+ knowledge_base: overrides("knowledge_base") ? extraList(extra.knowledge_base) : propList(knowledgeBase)
32
+ };
33
+ }
34
+ function readLaneThreadConfigValue({
35
+ custom,
36
+ key
37
+ }) {
38
+ const value = custom[key];
39
+ if (key === "model") return typeof value === "string" && value !== "" ? value : null;
40
+ if (key === "system_prompt") return nonBlankString(value);
41
+ return Array.isArray(value) ? stringItems(value) : null;
42
+ }
43
+ function sameThreadConfigValue(left, right) {
44
+ if (left === right) return true;
45
+ if (!Array.isArray(left) || !Array.isArray(right)) return false;
46
+ return left.length === right.length && left.every((item, index) => item === right[index]);
47
+ }
48
+ function decideThreadConfigLanePatch({
49
+ desired,
50
+ keys,
51
+ landed,
52
+ configVersion,
53
+ custom
54
+ }) {
55
+ if (!landed || configVersion <= 0) return { kind: "wait" };
56
+ const pending = new Set(keys);
57
+ const patch = {};
58
+ for (const key of PROVIDER_THREAD_CONFIG_KEYS) {
59
+ if (!pending.has(key)) continue;
60
+ if (!sameThreadConfigValue(readLaneThreadConfigValue({ custom, key }), desired[key])) {
61
+ copyThreadConfigKey({ target: patch, source: desired, key });
62
+ }
63
+ }
64
+ return patchedThreadConfigKeys(patch).length === 0 ? { kind: "done" } : { kind: "patch", patch };
65
+ }
66
+ function copyThreadConfigKey({
67
+ target,
68
+ source,
69
+ key
70
+ }) {
71
+ target[key] = source[key];
72
+ }
73
+ function patchedThreadConfigKeys(patch) {
74
+ return PROVIDER_THREAD_CONFIG_KEYS.filter((key) => Object.hasOwn(patch, key));
75
+ }
76
+ export {
77
+ PROVIDER_THREAD_CONFIG_KEYS,
78
+ decideThreadConfigLanePatch,
79
+ patchedThreadConfigKeys,
80
+ providerThreadConfig,
81
+ readLaneThreadConfigValue,
82
+ sameThreadConfigValue
83
+ };
84
+ //# sourceMappingURL=statewire-thread-config-lane.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statewire-thread-config-lane.js","sources":["../../src/runtime/statewire-thread-config-lane.ts"],"sourcesContent":["import type { ThreadConfigCustom } from '@athenaintel/agent-runtime';\nimport { effectiveStatewireModel } from './statewire-run-config';\n\n/**\n * The thread-config keys the provider's props own, in the order a\n * `config/patch` lists them.\n *\n * Once a thread has a server config lane (version > 0), agora composes every\n * run from the lane and drops these keys from a send\n * (`merge_custom_over_server_config`), so a change of the prop that feeds one\n * is written to the lane instead (see `StatewireThreadConfigLaneSync`).\n */\nexport const PROVIDER_THREAD_CONFIG_KEYS = [\n 'model',\n 'system_prompt',\n 'enabled_tools',\n 'workbench',\n 'knowledge_base',\n] as const;\n\nexport type ProviderThreadConfigKey = (typeof PROVIDER_THREAD_CONFIG_KEYS)[number];\n\n/**\n * The provider-owned thread-config values as a send carries them and as the\n * lane stores them; `null` is \"the send carries none\": written to the lane it\n * unsets the key, so the collab agent's own value (or the default) applies.\n */\nexport interface ProviderThreadConfig {\n model: string | null;\n system_prompt: string | null;\n enabled_tools: readonly string[] | null;\n workbench: readonly string[] | null;\n knowledge_base: readonly string[] | null;\n}\n\n/** A `config/patch` payload over provider-owned keys: exactly the keys to change. */\nexport type ProviderThreadConfigPatch = Partial<ProviderThreadConfig>;\n\nconst nonBlankString = (value: unknown): string | null =>\n typeof value === 'string' && value.trim() !== '' ? value : null;\n\nconst stringItems = (value: readonly unknown[]): string[] =>\n value.filter((item): item is string => typeof item === 'string');\n\n/** A list prop as the send carries it: omitted (`null`) when empty, as `buildStatewireRunConfig` does. */\nconst propList = (value: readonly string[] | undefined): readonly string[] | null =>\n value !== undefined && value.length > 0 ? value : null;\n\n/**\n * An `extraRunConfig` list as the send carries it: `buildStatewireRunConfig`\n * merges `extraRunConfig` last and verbatim, so an explicit list (an empty one\n * included) is what the send holds.\n */\nconst extraList = (value: unknown): readonly string[] | null =>\n Array.isArray(value) ? stringItems(value) : null;\n\n/**\n * The provider-owned thread-config values a send built from these props\n * carries, with `buildStatewireRunConfig`'s precedence: `extraRunConfig` is\n * merged last, so a key it holds wins over the prop that feeds it.\n *\n * - `model`: the explicit model only (`effectiveStatewireModel`); the SDK's\n * own default is never a choice to write.\n * - `system_prompt`: the trimmed prompt, `null` when blank.\n * - `enabled_tools`: `tools` ∪ `frontendToolIds`; `null` when empty, since the\n * send omits an empty list (it would erase a collab agent's own tools).\n * - `workbench`, `knowledge_base`: the list, `null` when empty.\n *\n * Pure.\n */\nexport function providerThreadConfig({\n model,\n systemPrompt,\n tools,\n frontendToolIds,\n workbench,\n knowledgeBase,\n extraRunConfig,\n}: {\n model: string | undefined;\n systemPrompt: string | undefined;\n tools: readonly string[] | undefined;\n frontendToolIds: readonly string[] | undefined;\n workbench: readonly string[] | undefined;\n knowledgeBase: readonly string[] | undefined;\n extraRunConfig: Record<string, unknown> | undefined;\n}): ProviderThreadConfig {\n const extra = extraRunConfig ?? {};\n const overrides = (key: ProviderThreadConfigKey) => Object.hasOwn(extra, key);\n const enabledTools = Array.from(new Set([...(tools ?? []), ...(frontendToolIds ?? [])]));\n const trimmedPrompt = systemPrompt?.trim() ?? '';\n return {\n model: effectiveStatewireModel({ model, extraRunConfig }) ?? null,\n system_prompt: overrides('system_prompt')\n ? nonBlankString(extra.system_prompt)\n : trimmedPrompt === ''\n ? null\n : trimmedPrompt,\n enabled_tools: overrides('enabled_tools')\n ? extraList(extra.enabled_tools)\n : propList(enabledTools),\n workbench: overrides('workbench') ? extraList(extra.workbench) : propList(workbench),\n knowledge_base: overrides('knowledge_base')\n ? extraList(extra.knowledge_base)\n : propList(knowledgeBase),\n };\n}\n\n/**\n * A key of the lane (`state.config.custom`) read as a provider-owned value:\n * a text key is its non-blank string, a list key its string items (an\n * explicit empty list included), anything else `null` (unset).\n */\nexport function readLaneThreadConfigValue({\n custom,\n key,\n}: {\n custom: ThreadConfigCustom;\n key: ProviderThreadConfigKey;\n}): string | readonly string[] | null {\n const value = custom[key];\n // `model` keeps `readLaneModel`'s reading: any non-empty string.\n if (key === 'model') return typeof value === 'string' && value !== '' ? value : null;\n if (key === 'system_prompt') return nonBlankString(value);\n return Array.isArray(value) ? stringItems(value) : null;\n}\n\n/** Whether two provider-owned values are the same (lists compared item by item, in order). */\nexport function sameThreadConfigValue(\n left: string | readonly string[] | null,\n right: string | readonly string[] | null,\n): boolean {\n if (left === right) return true;\n if (!Array.isArray(left) || !Array.isArray(right)) return false;\n return left.length === right.length && left.every((item, index) => item === right[index]);\n}\n\n/**\n * What to do with the pending changes of provider-owned keys:\n *\n * - `wait`: keep them pending. The thread's snapshot has not landed, or the\n * thread has no lane yet (version 0): the next send carries the values and\n * agora's deferral seed persists the ones it keeps. They stay pending so that\n * a lane an EARLIER send seeds (with the previous values) is corrected once\n * it lands.\n * - `done`: the lane already holds every one of them (this client's own\n * unacknowledged writes folded over); nothing to write.\n * - `patch`: issue one `config/patch` carrying exactly the keys whose lane\n * value differs; `null` unsets a key so the agent's own value (or the\n * default) applies.\n */\nexport type ThreadConfigLaneDecision =\n | { kind: 'wait' }\n | { kind: 'done' }\n | { kind: 'patch'; patch: ProviderThreadConfigPatch };\n\nexport function decideThreadConfigLanePatch({\n desired,\n keys,\n landed,\n configVersion,\n custom,\n}: {\n /** The provider's values after the changes. */\n desired: ProviderThreadConfig;\n /** The keys whose prop changed during this attach and is not yet written. */\n keys: Iterable<ProviderThreadConfigKey>;\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}): ThreadConfigLaneDecision {\n if (!landed || configVersion <= 0) return { kind: 'wait' };\n const pending = new Set(keys);\n const patch: ProviderThreadConfigPatch = {};\n for (const key of PROVIDER_THREAD_CONFIG_KEYS) {\n if (!pending.has(key)) continue;\n if (!sameThreadConfigValue(readLaneThreadConfigValue({ custom, key }), desired[key])) {\n copyThreadConfigKey({ target: patch, source: desired, key });\n }\n }\n return patchedThreadConfigKeys(patch).length === 0 ? { kind: 'done' } : { kind: 'patch', patch };\n}\n\nfunction copyThreadConfigKey<K extends ProviderThreadConfigKey>({\n target,\n source,\n key,\n}: {\n target: ProviderThreadConfigPatch;\n source: ProviderThreadConfig;\n key: K;\n}): void {\n target[key] = source[key];\n}\n\n/** The keys a patch carries, in {@link PROVIDER_THREAD_CONFIG_KEYS} order. */\nexport function patchedThreadConfigKeys(patch: ProviderThreadConfigPatch): ProviderThreadConfigKey[] {\n return PROVIDER_THREAD_CONFIG_KEYS.filter((key) => Object.hasOwn(patch, key));\n}\n"],"names":[],"mappings":";AAYO,MAAM,8BAA8B;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAoBA,MAAM,iBAAiB,CAAC,UACtB,OAAO,UAAU,YAAY,MAAM,KAAA,MAAW,KAAK,QAAQ;AAE7D,MAAM,cAAc,CAAC,UACnB,MAAM,OAAO,CAAC,SAAyB,OAAO,SAAS,QAAQ;AAGjE,MAAM,WAAW,CAAC,UAChB,UAAU,UAAa,MAAM,SAAS,IAAI,QAAQ;AAOpD,MAAM,YAAY,CAAC,UACjB,MAAM,QAAQ,KAAK,IAAI,YAAY,KAAK,IAAI;AAgBvC,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAQyB;AACvB,QAAM,QAAQ,kBAAkB,CAAA;AAChC,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AA;AAClD,QAAM,UAAU,IAAI,IAAI,IAAI;AAC5B,QAAM,QAAmC,CAAA;AACzC,aAAW,OAAO,6BAA6B;AAC7C,QAAI,CAAC,QAAQ,IAAI,GAAG,EAAG;AACvB,QAAI,CAAC,sBAAsB,0BAA0B,EAAE,QAAQ,IAAA,CAAK,GAAG,QAAQ,GAAG,CAAC,GAAG;AACpF,0BAAoB,EAAE,QAAQ,OAAO,QAAQ,SAAS,KAAK;AAAA,IAC7D;AAAA,EACF;AACA,SAAO,wBAAwB,KAAK,EAAE,WAAW,IAAI,EAAE,MAAM,WAAW,EAAE,MAAM,SAAS,MAAA;AAC3F;AAEA,SAAS,oBAAuD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AACF,GAIS;AACP,SAAO,GAAG,IAAI,OAAO,GAAG;AAC1B;AAGO,SAAS,wBAAwB,OAA6D;AACnG,SAAO,4BAA4B,OAAO,CAAC,QAAQ,OAAO,OAAO,OAAO,GAAG,CAAC;AAC9E;"}
@@ -11,6 +11,7 @@ const statewireRunConfig = require("./statewire-run-config.cjs");
11
11
  const runconfigContract = require("../agent-runtime/src/generated/runconfig-contract.cjs");
12
12
  const useDeepAgentRuntime = require("../agent-runtime/src/use-deep-agent-runtime.cjs");
13
13
  const errors = require("../agent-runtime/src/errors.cjs");
14
+ const statewireState = require("../agent-runtime/src/statewire-state.cjs");
14
15
  const composerMarkdown = require("../agent-runtime/src/composer-markdown.cjs");
15
16
  const ATHENA_SDK_MESSAGE_WINDOW = {
16
17
  size: runconfigContract.DEEP_AGENT_DEFAULT_MESSAGE_WINDOW
@@ -49,7 +50,8 @@ function useAthenaStatewireRuntime(config) {
49
50
  onError,
50
51
  onConnectionChange,
51
52
  onRawConnectionChange,
52
- onRunningChange
53
+ onRunningChange,
54
+ onServerState
53
55
  } = config;
54
56
  statewireRunConfig.resolveAgentProp({ agent });
55
57
  const clientTools = useStatewireClientTools(frontendToolkit);
@@ -65,6 +67,22 @@ function useAthenaStatewireRuntime(config) {
65
67
  { thread_id: threadId, is_new_chat: isNewChat }
66
68
  );
67
69
  }
70
+ const runConfigValue = statewireRunConfig.buildStatewireRunConfig({
71
+ model,
72
+ agent,
73
+ channel,
74
+ tools,
75
+ frontendToolIds,
76
+ workbench,
77
+ knowledgeBase,
78
+ systemPrompt,
79
+ appId,
80
+ extraRunConfig,
81
+ clientTools: statewireClientTools.statewireClientToolWireEntries(clientTools)
82
+ });
83
+ const runConfigKey = JSON.stringify(runConfigValue);
84
+ const lastStateRef = react.useRef(null);
85
+ const helloLandedRef = react.useRef(false);
68
86
  const auiTools = react.useMemo(() => react$1.Tools({ toolkit: frontendToolkit }), [frontendToolkit]);
69
87
  const useSdkClient = (thread) => react$1.useAui({ thread, tools: auiTools });
70
88
  return useDeepAgentRuntime.useDeepAgentRuntime({
@@ -102,12 +120,15 @@ function useAthenaStatewireRuntime(config) {
102
120
  // shows the text exactly as typed (`UserMessageText`).
103
121
  getMessageMetadata: composerMarkdown.withStagedComposerMarkdown({ threadId }),
104
122
  useClient: useSdkClient,
105
- onStateChange: () => {
123
+ onStateChange: (state) => {
106
124
  const endSpan = attachSpanRef.current;
107
125
  if (endSpan) {
108
126
  attachSpanRef.current = null;
109
127
  endSpan("statewire.snapshot", { data: { thread_id: threadId } });
110
128
  }
129
+ if (!statewireState.isDeepAgentStateHydrated(state)) return;
130
+ lastStateRef.current = state;
131
+ if (helloLandedRef.current) onServerState == null ? void 0 : onServerState(state);
111
132
  },
112
133
  onConnectionChange: (connection) => {
113
134
  athenaDiagnostics.athenaDiagnostics.gauge("statewire.connection", (connection == null ? void 0 : connection.status) ?? null);
@@ -123,25 +144,24 @@ function useAthenaStatewireRuntime(config) {
123
144
  }
124
145
  onConnectionChange == null ? void 0 : onConnectionChange(connection);
125
146
  },
126
- onRawConnectionChange,
147
+ onRawConnectionChange: (connection) => {
148
+ if (connection.status === "connected" && !helloLandedRef.current) {
149
+ helloLandedRef.current = true;
150
+ const helloState = lastStateRef.current;
151
+ if (helloState) onServerState == null ? void 0 : onServerState(helloState);
152
+ }
153
+ onRawConnectionChange == null ? void 0 : onRawConnectionChange(connection);
154
+ },
127
155
  onRunningChange,
128
156
  // Each model-context notification pulls the latest getter through the
129
- // core's per-render ref. Consumers commonly pass fresh array literals per
130
- // render, which must not thrash registration (no `key`: once per client).
157
+ // core's per-render ref; the value-stable key re-registers (and so
158
+ // notifies) only when the built runConfig actually changed. On a thread
159
+ // with a server config lane, agora keeps only the per-send keys of what
160
+ // this carries; `StatewireThreadConfigLaneSync` writes a changed model,
161
+ // system prompt, tool list, workbench or knowledge base to the lane itself.
131
162
  runConfig: {
132
- get: () => statewireRunConfig.buildStatewireRunConfig({
133
- model,
134
- agent,
135
- channel,
136
- tools,
137
- frontendToolIds,
138
- workbench,
139
- knowledgeBase,
140
- systemPrompt,
141
- appId,
142
- extraRunConfig,
143
- clientTools: statewireClientTools.statewireClientToolWireEntries(clientTools)
144
- })
163
+ get: () => runConfigValue,
164
+ key: runConfigKey
145
165
  },
146
166
  onError: (error) => {
147
167
  if (!errors.isStatewireChannelTeardown(error)) {