maka-agent 0.2.0-dev.11.20260831 → 0.2.0-dev.14.20260902

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 (226) hide show
  1. package/LICENSE +2 -2
  2. package/RUNTIME_HOST_PEER_DEPENDENCIES.rust.tsv +70 -0
  3. package/RUNTIME_HOST_PEER_THIRD_PARTY_NOTICES.txt +1839 -140
  4. package/THIRD_PARTY_NOTICES.txt +2 -2
  5. package/dist/acp/maka-acp-agent.js +6 -3
  6. package/dist/acp/session-registry.js +307 -0
  7. package/dist/acp/stdio-server.js +20 -1
  8. package/dist/cli-core.js +40 -3
  9. package/dist/mcp-capability-provider.js +1 -1
  10. package/dist/onboarding-catalog.js +3 -5
  11. package/dist/pi-transcript.js +21 -17
  12. package/dist/pi-tui-layout.js +4 -2
  13. package/dist/pi-tui-mcp-status.js +44 -130
  14. package/dist/pi-tui-pickers.js +11 -5
  15. package/dist/pi-tui-runner.js +133 -102
  16. package/dist/runtime-host-access-command.js +37 -4
  17. package/dist/runtime-host-capability-provider-command.js +16 -2
  18. package/dist/runtime-host-cli-context.js +73 -3
  19. package/dist/runtime-host-cli.js +187 -10
  20. package/dist/runtime-host-lifecycle-transaction.js +5 -2
  21. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  22. package/dist/runtime-host-onboarding.js +12 -16
  23. package/dist/runtime-host-peer-management-command.js +16 -4
  24. package/dist/runtime-host-plugin-command.js +101 -0
  25. package/dist/runtime-host-run-command.js +8 -2
  26. package/dist/runtime-host-service-management-command.js +2 -1
  27. package/dist/runtime-host-setup-command.js +1 -0
  28. package/dist/runtime-host-task-readiness.js +2 -3
  29. package/dist/runtime-host-tui-command.js +1 -1
  30. package/dist/runtime-host-tui-context.js +18 -5
  31. package/dist/runtime-host-update-command.js +71 -35
  32. package/dist/runtime-host-update-discovery.js +1 -0
  33. package/dist/tui-clipboard.js +86 -0
  34. package/dist/tui-copy-catalog.js +248 -0
  35. package/dist/tui-copy-command.js +103 -0
  36. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  37. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  38. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  39. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  40. package/node_modules/@maka/core/dist/attachments.js +92 -1
  41. package/node_modules/@maka/core/dist/bounded-response.js +71 -0
  42. package/node_modules/@maka/core/dist/chat-model-choice.js +8 -33
  43. package/node_modules/@maka/core/dist/client-capability-grant.js +149 -0
  44. package/node_modules/@maka/core/dist/connection-error-copy.js +17 -34
  45. package/node_modules/@maka/core/dist/connection-readiness.js +3 -31
  46. package/node_modules/@maka/core/dist/deep-research.js +1 -20
  47. package/node_modules/@maka/core/dist/events.js +22 -14
  48. package/node_modules/@maka/core/dist/foreign-session.js +2 -2
  49. package/node_modules/@maka/core/dist/interaction.js +49 -2
  50. package/node_modules/@maka/core/dist/llm-connections.js +74 -82
  51. package/node_modules/@maka/core/dist/maka-wordmark.js +23 -0
  52. package/node_modules/@maka/core/dist/model-catalog.js +242 -315
  53. package/node_modules/@maka/core/dist/model-facts.js +13 -19
  54. package/node_modules/@maka/core/dist/model-metadata.generated.js +1907 -1872
  55. package/node_modules/@maka/core/dist/model-metadata.js +184 -199
  56. package/node_modules/@maka/core/dist/model-thinking.js +1 -1
  57. package/node_modules/@maka/core/dist/models-dev-projection.js +302 -0
  58. package/node_modules/@maka/core/dist/models-dev-refresh.js +55 -0
  59. package/node_modules/@maka/core/dist/onboarding.js +2 -1
  60. package/node_modules/@maka/core/dist/provider-auth.js +47 -291
  61. package/node_modules/@maka/core/dist/provider-registry.js +68 -357
  62. package/node_modules/@maka/core/dist/runtime-event.js +5 -0
  63. package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +83 -18
  64. package/node_modules/@maka/core/dist/runtime-policy/credential-vault-codec.js +9 -1
  65. package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +84 -0
  66. package/node_modules/@maka/core/dist/runtime-policy/policy-codec.js +75 -0
  67. package/node_modules/@maka/core/dist/runtime-policy.js +5 -2
  68. package/node_modules/@maka/core/dist/session-send-projection.js +2 -1
  69. package/node_modules/@maka/core/dist/session-start-mode.js +42 -0
  70. package/node_modules/@maka/core/dist/session.js +120 -5
  71. package/node_modules/@maka/core/dist/settings.js +10 -2
  72. package/node_modules/@maka/core/dist/slash-command-catalog.js +1 -0
  73. package/node_modules/@maka/core/dist/task-submission-readiness.js +2 -1
  74. package/node_modules/@maka/core/dist/usage-record-schema.js +11 -1
  75. package/node_modules/@maka/core/dist/workhub-creation-intent.js +896 -0
  76. package/node_modules/@maka/core/package.json +8 -2
  77. package/node_modules/@maka/mcp/dist/index.js +1 -0
  78. package/node_modules/@maka/runtime/dist/agent-run.js +7 -0
  79. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +55 -82
  80. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +178 -140
  81. package/node_modules/@maka/runtime/dist/archive-read-tool.js +26 -5
  82. package/node_modules/@maka/runtime/dist/builtin-tools.js +27 -2
  83. package/node_modules/@maka/runtime/dist/context-budget-policy.js +0 -12
  84. package/node_modules/@maka/runtime/dist/conversation-copy.js +66 -43
  85. package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +31 -0
  86. package/node_modules/@maka/runtime/dist/history-compact-error.js +10 -2
  87. package/node_modules/@maka/runtime/dist/history-compact-input-fit.js +7 -1
  88. package/node_modules/@maka/runtime/dist/history-compaction.js +13 -22
  89. package/node_modules/@maka/runtime/dist/image-file.js +5 -20
  90. package/node_modules/@maka/runtime/dist/local-web-fetch.js +2 -43
  91. package/node_modules/@maka/runtime/dist/mcp-tools.js +28 -0
  92. package/node_modules/@maka/runtime/dist/model-fetcher.js +15 -8
  93. package/node_modules/@maka/runtime/dist/model-history.js +59 -17
  94. package/node_modules/@maka/runtime/dist/model-runtime.js +2 -2
  95. package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +173 -20
  96. package/node_modules/@maka/runtime/dist/plugin-runtime.js +219 -0
  97. package/node_modules/@maka/runtime/dist/provider-image-overflow-recovery.js +12 -31
  98. package/node_modules/@maka/runtime/dist/quiescent-session-snapshot.js +78 -0
  99. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +6 -0
  100. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +14 -2
  101. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +11 -10
  102. package/node_modules/@maka/runtime/dist/shell-tools.js +77 -1
  103. package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +93 -83
  104. package/node_modules/@maka/runtime/dist/test-connection.js +6 -6
  105. package/node_modules/@maka/runtime/dist/tool-availability.js +74 -5
  106. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +333 -52
  107. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +34 -3
  108. package/node_modules/@maka/runtime/dist/tool-runtime.js +62 -6
  109. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +39 -16
  110. package/node_modules/@maka/runtime/package.json +1 -0
  111. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +10 -3
  112. package/node_modules/@maka/runtime-host/dist/client/catalog-reader.js +59 -18
  113. package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +3 -2
  114. package/node_modules/@maka/runtime-host/dist/client/connection.js +72 -31
  115. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +49 -4
  116. package/node_modules/@maka/runtime-host/dist/client/index.js +3 -2
  117. package/node_modules/@maka/runtime-host/dist/client/oauth-presentation.js +1 -1
  118. package/node_modules/@maka/runtime-host/dist/client/owner-connection-code.js +32 -1
  119. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +26 -4
  120. package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +8 -0
  121. package/node_modules/@maka/runtime-host/dist/operator/access-management-frame.js +10 -1
  122. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  123. package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +2 -0
  124. package/node_modules/@maka/runtime-host/dist/operator/peer-management-frame.js +2 -0
  125. package/node_modules/@maka/runtime-host/dist/operator/service-management-frame.js +2 -0
  126. package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +56 -12
  127. package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +4 -0
  128. package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +22 -1
  129. package/node_modules/@maka/runtime-host/dist/protocol/configuration.js +55 -9
  130. package/node_modules/@maka/{storage/dist/task-ledger-store-internal.js → runtime-host/dist/protocol/connection-catalog-change.js} +7 -13
  131. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +37 -0
  132. package/node_modules/@maka/runtime-host/dist/protocol/index.js +49 -1
  133. package/node_modules/@maka/runtime-host/dist/protocol/network-proxy.js +1 -7
  134. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +5 -1
  135. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +512 -0
  136. package/node_modules/@maka/runtime-host/dist/protocol/runtime-policy.js +72 -61
  137. package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
  138. package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +4 -2
  139. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +5 -12
  140. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +92 -4
  141. package/node_modules/@maka/runtime-host/dist/server/access-authority.js +17 -14
  142. package/node_modules/@maka/runtime-host/dist/server/access-credential-metadata.js +4 -2
  143. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +119 -47
  144. package/node_modules/@maka/runtime-host/dist/server/agent-graph-execution-coordinator.js +1 -2
  145. package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +10 -4
  146. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +0 -9
  147. package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +192 -18
  148. package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +122 -48
  149. package/node_modules/@maka/runtime-host/dist/server/client-capability-provider-id.js +31 -0
  150. package/node_modules/@maka/runtime-host/dist/server/configuration-coordinator.js +20 -1
  151. package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +5 -5
  152. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +1 -0
  153. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +163 -28
  154. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +2 -2
  155. package/node_modules/@maka/runtime-host/dist/server/execution-service.js +4 -1
  156. package/node_modules/@maka/runtime-host/dist/server/extension-bundle.js +249 -0
  157. package/node_modules/@maka/runtime-host/dist/server/extension-package-manifest.js +262 -0
  158. package/node_modules/@maka/runtime-host/dist/server/host-change-feed.js +11 -0
  159. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +15 -0
  160. package/node_modules/@maka/runtime-host/dist/server/index.js +5 -0
  161. package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +181 -13
  162. package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +6 -0
  163. package/node_modules/@maka/runtime-host/dist/server/listener-set.js +8 -4
  164. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +88 -22
  165. package/node_modules/@maka/runtime-host/dist/server/model-metadata-refresh.js +96 -0
  166. package/node_modules/@maka/runtime-host/dist/server/network-proxy-coordinator.js +0 -1
  167. package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +43 -118
  168. package/node_modules/@maka/runtime-host/dist/server/peer-listener.js +3 -0
  169. package/node_modules/@maka/runtime-host/dist/server/plugin-composition-patch.js +58 -0
  170. package/node_modules/@maka/runtime-host/dist/server/plugin-composition-store.js +141 -0
  171. package/node_modules/@maka/runtime-host/dist/server/plugin-package-loader.js +130 -0
  172. package/node_modules/@maka/runtime-host/dist/server/plugin-package-store.js +528 -0
  173. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +249 -0
  174. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +1130 -0
  175. package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +4 -0
  176. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +24 -5
  177. package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +57 -5
  178. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +2 -1
  179. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +3 -3
  180. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +35 -3
  181. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +16 -0
  182. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +10 -2
  183. package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +1 -1
  184. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +276 -3
  185. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +101 -1
  186. package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +1 -0
  187. package/node_modules/@maka/runtime-host/dist/webrtc-stun-policy.js +114 -0
  188. package/node_modules/@maka/runtime-host/package.json +2 -0
  189. package/node_modules/@maka/storage/dist/agent-run-store.js +4 -0
  190. package/node_modules/@maka/storage/dist/artifact-store.js +7 -23
  191. package/node_modules/@maka/storage/dist/conversation-operational-state.js +3 -0
  192. package/node_modules/@maka/storage/dist/execution-stores.js +3 -0
  193. package/node_modules/@maka/storage/dist/interaction-store-public.js +1 -1
  194. package/node_modules/@maka/storage/dist/interaction-store.js +173 -0
  195. package/node_modules/@maka/storage/dist/production-session-snapshot.js +761 -0
  196. package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1 -1
  197. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +19 -22
  198. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +205 -42
  199. package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +2 -2
  200. package/node_modules/@maka/storage/dist/runtime-policy-stores.js +5 -2
  201. package/node_modules/@maka/storage/dist/session-message-projection.js +1 -1
  202. package/node_modules/@maka/storage/dist/session-store.js +32 -6
  203. package/node_modules/@maka/storage/dist/session-todo-store.js +6 -68
  204. package/node_modules/@maka/storage/dist/settings-store.js +16 -25
  205. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +19 -0
  206. package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +10 -1
  207. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +73 -3
  208. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +2 -10
  209. package/node_modules/@maka/storage/package.json +2 -0
  210. package/node_modules/fast-uri/index.js +215 -47
  211. package/node_modules/fast-uri/lib/schemes.js +9 -4
  212. package/node_modules/fast-uri/lib/utils.js +396 -92
  213. package/node_modules/fast-uri/package.json +1 -1
  214. package/node_modules/qs/.github/THREAT_MODEL.md +3 -3
  215. package/node_modules/qs/CHANGELOG.md +15 -0
  216. package/node_modules/qs/README.md +19 -1
  217. package/node_modules/qs/dist/qs.js +21 -21
  218. package/node_modules/qs/eslint.config.mjs +1 -1
  219. package/node_modules/qs/lib/parse.js +3 -4
  220. package/node_modules/qs/lib/stringify.js +23 -8
  221. package/node_modules/qs/lib/utils.js +10 -3
  222. package/node_modules/qs/package.json +4 -4
  223. package/package.json +1 -1
  224. package/node_modules/@maka/core/dist/task-ledger.js +0 -669
  225. package/node_modules/@maka/storage/dist/task-ledger-authority.js +0 -121
  226. package/node_modules/@maka/storage/dist/task-ledger-store.js +0 -663
@@ -457,7 +457,7 @@ function decodeWorkspaceEntry(entry) {
457
457
  }
458
458
  const bundlePath = `workspace/${entry.relativePath}${entry.kind === 'directory' ? '/' : ''}`;
459
459
  if (!isSessionBundleUstarPathV1(bundlePath)) {
460
- return { kind: 'reject', category: 'unsafe_path' };
460
+ return { kind: 'reject', category: 'unsupported_portable_path' };
461
461
  }
462
462
  return { kind: 'valid', segments, basename: segments.at(-1) };
463
463
  }
@@ -19,7 +19,7 @@
19
19
  import { randomUUID } from 'node:crypto';
20
20
  import { isDeepStrictEqual } from 'node:util';
21
21
  import { CONNECTION_CATALOG_MAX_CONNECTIONS, decodeCanonicalConnectionCatalogEntry, decodeConnectionSlug, decodeConnectionTarget, decodeConnectionTestSummary, decodeProviderType, decodeRuntimePolicyEntityId, normalizeConnectionCatalogEntryUpdateForProvider, normalizeConnectionModelDiscoveryResult, normalizeCreateCatalogConnectionInput, normalizeRemoveCatalogConnectionInput, normalizeSetDefaultConnectionTargetInput, normalizeUpdateCatalogConnectionInput, } from '@maka/core/runtime-policy';
22
- import { PROVIDER_DEFAULTS, reconcileConnectionAfterModelFetch } from '@maka/core/llm-connections';
22
+ import { PROVIDER_REGISTRY, reconcileConnectionAfterModelFetch } from '@maka/core/llm-connections';
23
23
  import { modelIdAliasesForProvider } from '@maka/core/model-metadata';
24
24
  import { isRetiredProvider } from '@maka/core/provider-registry';
25
25
  import { pruneRelayModelProfiles } from '@maka/core/model-thinking';
@@ -111,17 +111,19 @@ export class ConnectionCatalogDocumentOwner {
111
111
  if (current.connections.length >= CONNECTION_CATALOG_MAX_CONNECTIONS) {
112
112
  throw codecError('invalid_connection_input', `Connection catalog cannot exceed ${CONNECTION_CATALOG_MAX_CONNECTIONS} entries`);
113
113
  }
114
- const fallbackModels = fallbackInventory(input.connection.providerType);
115
114
  const next = this.nextDocument(current, [
116
115
  ...current.connections,
117
116
  {
118
117
  ...input.connection,
119
118
  connectionId: randomUUID(),
120
119
  revision: 1,
121
- models: fallbackModels,
122
- ...(fallbackModels.length > 0
123
- ? { modelSource: 'fallback', modelsFetchedAt: 0 }
124
- : {}),
120
+ // A provider with no model-list endpoint ships its inventory in the
121
+ // registry, and the resolver prepends it to whatever the connection
122
+ // stores. Copying it in here as well persisted a build-time constant
123
+ // as if it were connection state: a second authority for the same
124
+ // fact, frozen at the moment the row was written, that a build
125
+ // shipping a new model could no longer correct.
126
+ models: [],
125
127
  },
126
128
  ]);
127
129
  await this.write(root, next);
@@ -246,9 +248,12 @@ export class ConnectionCatalogDocumentOwner {
246
248
  if (!previous || (!isLegacySeed && !hasRetiredModels)) {
247
249
  return committed(current);
248
250
  }
249
- const fallbackModels = isLegacySeed
250
- ? fallbackInventory(previous.providerType)
251
- : previous.models.filter((model) => !retired.has(model.id));
251
+ // A legacy seed's stored inventory was the registry's shipped list copied
252
+ // in at write time. Clearing it is the migration: the resolver prepends
253
+ // that list from the current build, so the row stops carrying a stale
254
+ // second copy of it. Any other row keeps its own inventory, minus the
255
+ // retired ids.
256
+ const models = isLegacySeed ? [] : previous.models.filter((model) => !retired.has(model.id));
252
257
  const { lastTest: _lastTest, modelSource: _modelSource, modelsFetchedAt: _modelsFetchedAt, ...retained } = previous;
253
258
  const migratedEnabledModelIds = isLegacySeed
254
259
  ? [...input.enabledModelIds]
@@ -259,12 +264,10 @@ export class ConnectionCatalogDocumentOwner {
259
264
  ...retained,
260
265
  revision: nextRevision(previous.revision),
261
266
  enabledModelIds: migratedEnabledModelIds,
262
- models: fallbackModels,
263
- ...(isLegacySeed && fallbackModels.length > 0
264
- ? { modelSource: 'fallback', modelsFetchedAt: 0 }
265
- : previous.modelSource === undefined
266
- ? {}
267
- : { modelSource: previous.modelSource, modelsFetchedAt: previous.modelsFetchedAt }),
267
+ models,
268
+ ...(isLegacySeed || previous.modelSource === undefined
269
+ ? {}
270
+ : { modelSource: previous.modelSource, modelsFetchedAt: previous.modelsFetchedAt }),
268
271
  ...(relayModelProfiles === undefined ? {} : { relayModelProfiles }),
269
272
  };
270
273
  const target = current.defaultTarget;
@@ -355,7 +358,7 @@ export class ConnectionCatalogDocumentOwner {
355
358
  const connectionId = decodeConnectionInput(() => decodeRuntimePolicyEntityId(rawConnectionId));
356
359
  const slug = decodeConnectionInput(() => decodeConnectionSlug(rawSlug));
357
360
  const providerType = decodeConnectionInput(() => decodeProviderType(rawProviderType));
358
- const definition = PROVIDER_DEFAULTS[providerType];
361
+ const definition = PROVIDER_REGISTRY[providerType];
359
362
  // Identity first: the intent's connectionId names the connection being
360
363
  // edited, whatever slug it lives under — a relay created in Desktop under
361
364
  // a custom slug is updated in place, never duplicated at the canonical
@@ -589,12 +592,6 @@ export class ConnectionCatalogDocumentOwner {
589
592
  }
590
593
  }
591
594
  }
592
- function fallbackInventory(providerType) {
593
- const provider = PROVIDER_DEFAULTS[providerType];
594
- return provider.modelDiscovery.kind === 'fallback'
595
- ? provider.fallbackModels.map((id) => ({ id }))
596
- : [];
597
- }
598
595
  export function catalogSnapshot(document) {
599
596
  return deepFreeze({
600
597
  revision: document.revision,
@@ -17,16 +17,17 @@
17
17
  * under the License.
18
18
  */
19
19
  import { randomUUID } from 'node:crypto';
20
- import { CONNECTION_CATALOG_MAX_CONNECTIONS, decodeConnectionModelId, decodeConnectionSlug, decodeProviderType, decodeRuntimePolicyEntityId, decodeCredentialLocator, normalizeDeleteCredentialInput, normalizeRemoveCatalogConnectionInput, normalizeRequestHeaderUpdates, normalizeRequestHeaders, normalizeSetCredentialInput, parseRequestHeaders, serializeRequestHeaders, RequestCustomizationValidationError, normalizeCredentialSecret, normalizeCatalogConnectionBaseUrl, } from '@maka/core/runtime-policy';
20
+ import { isDeepStrictEqual } from 'node:util';
21
+ import { CONNECTION_CATALOG_MAX_CONNECTIONS, decodeConnectionModelId, connectionCredentialTarget, decodeConnectionCredentialTarget, decodeConnectionSlug, decodeProviderType, decodeRuntimePolicyEntityId, decodeCredentialLocator, normalizeDeleteCredentialInput, normalizeRemoveCatalogConnectionInput, normalizeRequestHeaderUpdates, normalizeRequestHeaders, normalizeSetCredentialInput, parseRequestHeaders, serializeRequestHeaders, RequestCustomizationValidationError, normalizeCredentialSecret, normalizeCatalogConnectionBaseUrl, normalizeNetworkProxyUpdate, networkProxyCredentialTarget, } from '@maka/core/runtime-policy';
21
22
  import { applyModelFactOverridesToConnection, applyModelFactOverridesToCatalogSnapshot, } from '@maka/core/model-facts';
22
23
  import { deriveProviderAuthContract } from '@maka/core/provider-auth';
23
24
  import { isRetiredProvider } from '@maka/core/provider-registry';
24
- import { deriveConnectionSlug, deriveInteractiveOAuthConnectionSlug, effectiveBaseUrl, PROVIDER_DEFAULTS, providerAuthSupportsApiKey, } from '@maka/core/llm-connections';
25
+ import { deriveConnectionSlug, deriveInteractiveOAuthConnectionSlug, effectiveBaseUrl, PROVIDER_REGISTRY, providerFallbackModelIds, providerAuthRequiresSecret, providerAuthSupportsApiKey, } from '@maka/core/llm-connections';
25
26
  import { deepFreeze, nextRevision } from './codec.js';
26
27
  import { catalogSnapshot, connectionBasis, ConnectionCatalogDocumentOwner, connectionTestModelBasis, findConnection, sameConnectionTestModelBasis, } from './connection-catalog-document.js';
27
28
  import { credentialMaterial, credentialBasis, credentialStatus, CredentialVaultDocumentOwner, findCredential, sameCredentialBasis, vaultSnapshot, } from './credential-vault-document.js';
28
29
  import { cleanupRuntimePolicyDocumentTemps } from './document-io.js';
29
- import { codecError, commitOutcomeUnknown, decodeConnectionInput, decodeCredentialInput, RuntimePolicyStoreError, } from './errors.js';
30
+ import { codecError, commitOutcomeUnknown, decodeConnectionInput, decodeCredentialInput, decodePolicyInput, RuntimePolicyStoreError, } from './errors.js';
30
31
  import { connectionCredentialLocator, connectionRequestHeadersLocator, } from './operations.js';
31
32
  import { clearConnectionOnboardingIntent, prepareConnectionOnboardingIntent, prepareInteractiveOAuthEnrollmentIntent, readConnectionOnboardingIntent, writeConnectionOnboardingIntent, } from './onboarding-transaction.js';
32
33
  import { findInteractiveOAuthLoginReceipt, readInteractiveOAuthLoginReceipts, sameInteractiveOAuthLoginTarget, upsertInteractiveOAuthLoginReceipt, } from './oauth-login-receipt-document.js';
@@ -100,6 +101,62 @@ export class RuntimePolicyCoordinator {
100
101
  }
101
102
  });
102
103
  }
104
+ updateNetworkProxy(rawInput) {
105
+ return this.inLane(async (root) => {
106
+ const input = decodePolicyInput(() => normalizeNetworkProxyUpdate(rawInput));
107
+ const policy = await this.policy.read(root);
108
+ const preparedPolicy = this.policy.prepareMutation(policy, {
109
+ expectedRevision: input.expectedPolicyRevision,
110
+ operation: { kind: 'set_network_proxy', value: input.networkProxy },
111
+ });
112
+ if (preparedPolicy.kind !== 'ready')
113
+ return preparedPolicy;
114
+ if (input.credential.kind === 'replace' &&
115
+ input.credential.expectedTarget &&
116
+ !isDeepStrictEqual(networkProxyCredentialTarget(policy.policy.networkProxy), input.credential.expectedTarget)) {
117
+ return deepFreeze({
118
+ kind: 'proxy_target_mismatch',
119
+ expected: input.credential.expectedTarget,
120
+ actual: networkProxyCredentialTarget(policy.policy.networkProxy),
121
+ });
122
+ }
123
+ const vault = await this.vault.read(root);
124
+ const existing = findCredential(vault, networkProxyCredentialLocator());
125
+ if (!matchesCredentialExpectation(existing, input.expectedCredential)) {
126
+ return deepFreeze({
127
+ kind: 'credential_stale',
128
+ expected: input.expectedCredential,
129
+ actual: existing ? credentialBasis(existing) : null,
130
+ });
131
+ }
132
+ // Preflight every document before publishing either side of the compound update.
133
+ if (input.credential.kind === 'replace' && existing?.secret !== input.credential.secret) {
134
+ const prepared = this.vault.prepareSet(vault, {
135
+ locator: networkProxyCredentialLocator(),
136
+ expected: existing
137
+ ? { credentialId: existing.credentialId, revision: existing.revision }
138
+ : null,
139
+ secret: input.credential.secret,
140
+ });
141
+ if (prepared.kind !== 'ready') {
142
+ if (prepared.kind === 'credential_stale')
143
+ return prepared;
144
+ throw codecError('invalid_credential_input', 'Network proxy credential is invalid');
145
+ }
146
+ }
147
+ else if (input.credential.kind === 'delete' && existing) {
148
+ const prepared = this.vault.prepareDelete(vault, {
149
+ expected: credentialBasis(existing),
150
+ });
151
+ if (prepared.kind !== 'ready') {
152
+ if (prepared.kind === 'credential_stale')
153
+ return prepared;
154
+ throw codecError('invalid_credential_input', 'Network proxy credential is invalid');
155
+ }
156
+ }
157
+ return this.applyNetworkProxyUpdate(root, input);
158
+ });
159
+ }
103
160
  createConnection(input) {
104
161
  return this.inLane(async (root) => this.projectCatalogMutation(root, await this.catalog.create(root, input)));
105
162
  }
@@ -164,8 +221,19 @@ export class RuntimePolicyCoordinator {
164
221
  if (!connection) {
165
222
  return deepFreeze({ kind: 'connection_not_found' });
166
223
  }
224
+ if (input.expectedConnection &&
225
+ !isDeepStrictEqual(connectionCredentialTarget(connection), input.expectedConnection)) {
226
+ return deepFreeze({
227
+ kind: 'connection_stale',
228
+ expected: {
229
+ connectionId: input.expectedConnection.connectionId,
230
+ revision: input.expectedConnection.revision,
231
+ },
232
+ actual: connectionBasis(connection),
233
+ });
234
+ }
167
235
  assertConnectionIsWritable(connection);
168
- const required = connectionCredentialLocator(connection.connectionId, PROVIDER_DEFAULTS[connection.providerType].authKind);
236
+ const required = connectionCredentialLocator(connection.connectionId, PROVIDER_REGISTRY[connection.providerType].authKind);
169
237
  if (locator.kind !== 'request_headers' && (!required || required.kind !== locator.kind)) {
170
238
  throw codecError('invalid_credential_input', 'Connection credential kind does not match the provider auth contract');
171
239
  }
@@ -212,7 +280,7 @@ export class RuntimePolicyCoordinator {
212
280
  // reaches it today (execution resolution refuses first), which is
213
281
  // exactly why it would have stayed open.
214
282
  assertConnectionIsWritable(connection);
215
- if (PROVIDER_DEFAULTS[connection.providerType].authKind !== 'oauth_token') {
283
+ if (PROVIDER_REGISTRY[connection.providerType].authKind !== 'oauth_token') {
216
284
  throw codecError('invalid_credential_input', 'OAuth refresh credential does not match the provider auth contract');
217
285
  }
218
286
  const prepared = this.vault.prepareSet(await this.vault.read(root), input);
@@ -255,32 +323,21 @@ export class RuntimePolicyCoordinator {
255
323
  if (!existing)
256
324
  return deepFreeze({ kind: 'connection_not_found' });
257
325
  if (!isInteractiveOAuthLoginProvider(existing.providerType)) {
258
- return deepFreeze({
259
- kind: 'provider_action_unavailable',
260
- availability: 'hidden',
261
- });
326
+ return deepFreeze({ kind: 'provider_action_unavailable' });
262
327
  }
263
328
  connectionBefore = structuredClone(existing);
264
329
  connectionAfter = reenabledInteractiveOAuthConnection(existing);
265
330
  }
266
331
  const connection = connectionBefore ?? connectionAfter;
267
332
  if (!isInteractiveOAuthLoginProvider(connection.providerType)) {
268
- return deepFreeze({
269
- kind: 'provider_action_unavailable',
270
- availability: 'hidden',
271
- });
333
+ return deepFreeze({ kind: 'provider_action_unavailable' });
272
334
  }
273
335
  const contract = deriveProviderAuthContract({
274
336
  providerType: connection.providerType,
275
- enabled: true,
276
337
  hasSecret: false,
277
- lastTestStatus: connection.lastTest?.status,
278
338
  });
279
- if (contract.actionAvailability.start_oauth !== 'available') {
280
- return deepFreeze({
281
- kind: 'provider_action_unavailable',
282
- availability: contract.actionAvailability.start_oauth,
283
- });
339
+ if (!contract.actionAvailability.start_oauth) {
340
+ return deepFreeze({ kind: 'provider_action_unavailable' });
284
341
  }
285
342
  const prepared = await this.prepareConnectionMaterial(root, connection, false);
286
343
  if (prepared.kind !== 'ready')
@@ -435,13 +492,7 @@ export class RuntimePolicyCoordinator {
435
492
  if (isRetiredProvider(connection.providerType)) {
436
493
  return deepFreeze({ kind: 'provider_retired' });
437
494
  }
438
- const contract = deriveProviderAuthContract({
439
- providerType: connection.providerType,
440
- enabled: true,
441
- hasSecret: true,
442
- lastTestStatus: connection.lastTest?.status,
443
- });
444
- const prepared = await this.prepareConnectionMaterial(root, connection, contract.requiresSecret);
495
+ const prepared = await this.prepareConnectionMaterial(root, connection, providerAuthRequiresSecret(connection.providerType));
445
496
  if (prepared.kind !== 'ready')
446
497
  return prepared;
447
498
  return deepFreeze({
@@ -452,16 +503,48 @@ export class RuntimePolicyCoordinator {
452
503
  });
453
504
  });
454
505
  }
455
- exportCredentialMaterial(rawLocator) {
506
+ exportCredentialMaterial(rawLocator, rawExpectedConnection) {
456
507
  return this.inLane(async (root) => {
457
508
  const locator = decodeCredentialInput(() => decodeCredentialLocator(rawLocator));
509
+ const expectedConnection = rawExpectedConnection
510
+ ? decodeConnectionInput(() => decodeConnectionCredentialTarget(rawExpectedConnection))
511
+ : undefined;
512
+ if (expectedConnection && locator.scope !== 'connection') {
513
+ throw codecError('invalid_credential_input', 'Only connection credentials accept a connection target basis');
514
+ }
458
515
  if (locator.scope === 'connection') {
459
516
  const catalog = await this.catalog.read(root);
460
- if (!this.validateConnectionCredentialLocator(catalog, locator))
461
- return null;
517
+ const connection = findConnection(catalog, locator);
518
+ if (expectedConnection &&
519
+ (!connection ||
520
+ !isDeepStrictEqual(connectionCredentialTarget(connection), expectedConnection))) {
521
+ return deepFreeze({
522
+ kind: 'connection_stale',
523
+ expected: {
524
+ connectionId: expectedConnection.connectionId,
525
+ revision: expectedConnection.revision,
526
+ },
527
+ actual: connection ? connectionBasis(connection) : null,
528
+ });
529
+ }
530
+ if (!this.validateConnectionCredentialLocator(catalog, locator)) {
531
+ return expectedConnection
532
+ ? deepFreeze({ kind: 'exported', material: null })
533
+ : null;
534
+ }
462
535
  }
463
536
  const credential = findCredential(await this.vault.read(root), locator);
464
- return credential ? credentialMaterial(credential) : null;
537
+ const material = credential
538
+ ? {
539
+ ...credentialMaterial(credential),
540
+ ...(locator.scope === 'network_proxy'
541
+ ? {
542
+ proxyTarget: networkProxyCredentialTarget((await this.policy.read(root)).policy.networkProxy),
543
+ }
544
+ : {}),
545
+ }
546
+ : null;
547
+ return expectedConnection ? deepFreeze({ kind: 'exported', material }) : material;
465
548
  });
466
549
  }
467
550
  getConnectionRequestHeaders(rawConnectionId) {
@@ -641,7 +724,7 @@ export class RuntimePolicyCoordinator {
641
724
  });
642
725
  });
643
726
  }
644
- resolveWebFetchExecution() {
727
+ resolveHostOutboundExecution() {
645
728
  return this.inLane(async (root) => {
646
729
  const policy = (await this.policy.read(root)).policy;
647
730
  if (policy.privacy.incognitoActive) {
@@ -759,7 +842,7 @@ export class RuntimePolicyCoordinator {
759
842
  let storedSecret = null;
760
843
  let requestHeadersCredential = null;
761
844
  let requestHeadersSecret = null;
762
- const locator = connectionCredentialLocator(target.candidate.connectionId, PROVIDER_DEFAULTS[providerType].authKind);
845
+ const locator = connectionCredentialLocator(target.candidate.connectionId, PROVIDER_REGISTRY[providerType].authKind);
763
846
  if (locator) {
764
847
  credential = credentialStatus(vault, locator);
765
848
  if (existing) {
@@ -1000,18 +1083,15 @@ export class RuntimePolicyCoordinator {
1000
1083
  return deepFreeze({ kind: 'connection_disabled' });
1001
1084
  const contract = deriveProviderAuthContract({
1002
1085
  providerType: connection.providerType,
1003
- enabled: true,
1004
1086
  hasSecret: true,
1005
- lastTestStatus: connection.lastTest?.status,
1006
1087
  });
1007
- const availability = contract.actionAvailability[action];
1008
- if (availability !== 'available') {
1009
- return deepFreeze({ kind: 'provider_action_unavailable', availability });
1088
+ if (!contract.actionAvailability[action]) {
1089
+ return deepFreeze({ kind: 'provider_action_unavailable' });
1010
1090
  }
1011
1091
  return this.prepareConnectionMaterial(root, connection, contract.requiresSecret);
1012
1092
  }
1013
1093
  async prepareConnectionMaterial(root, connection, requiresConnectionSecret) {
1014
- const authKind = PROVIDER_DEFAULTS[connection.providerType].authKind;
1094
+ const authKind = PROVIDER_REGISTRY[connection.providerType].authKind;
1015
1095
  const locator = connectionCredentialLocator(connection.connectionId, authKind);
1016
1096
  const policy = await this.policy.read(root);
1017
1097
  const networkProxy = structuredClone(policy.policy.networkProxy);
@@ -1075,7 +1155,7 @@ export class RuntimePolicyCoordinator {
1075
1155
  return false;
1076
1156
  if (locator.kind === 'request_headers')
1077
1157
  return true;
1078
- const required = connectionCredentialLocator(connection.connectionId, PROVIDER_DEFAULTS[connection.providerType].authKind);
1158
+ const required = connectionCredentialLocator(connection.connectionId, PROVIDER_REGISTRY[connection.providerType].authKind);
1079
1159
  if (!required || required.kind !== locator.kind) {
1080
1160
  throw codecError('invalid_credential_input', 'Connection credential kind does not match the provider auth contract');
1081
1161
  }
@@ -1207,6 +1287,86 @@ export class RuntimePolicyCoordinator {
1207
1287
  throw commitOutcomeUnknown('Connection onboarding recovery did not converge', error);
1208
1288
  }
1209
1289
  }
1290
+ async applyNetworkProxyUpdate(root, input) {
1291
+ const policy = await this.policy.read(root);
1292
+ const vault = await this.vault.read(root);
1293
+ const locator = networkProxyCredentialLocator();
1294
+ const existing = findCredential(vault, locator);
1295
+ const credentialChanged = input.credential.kind === 'replace'
1296
+ ? existing?.secret !== input.credential.secret
1297
+ : input.credential.kind === 'delete' && existing !== undefined;
1298
+ const proxyChanged = !isDeepStrictEqual(policy.policy.networkProxy, input.networkProxy);
1299
+ const effectiveProxyChanged = !sameEffectiveProxyConfiguration(effectiveProxyConfigurationBasis(policy.policy.networkProxy), effectiveProxyConfigurationBasis(input.networkProxy));
1300
+ const cleared = credentialChanged || effectiveProxyChanged
1301
+ ? await this.catalog.clearAllConnectionLastTests(root, await this.catalog.read(root))
1302
+ : false;
1303
+ let durableChange = cleared;
1304
+ let snapshot = policySnapshot(policy);
1305
+ try {
1306
+ const commitCredential = async () => {
1307
+ if (input.credential.kind === 'replace' && credentialChanged) {
1308
+ const prepared = this.vault.prepareSet(vault, {
1309
+ locator,
1310
+ expected: existing
1311
+ ? { credentialId: existing.credentialId, revision: existing.revision }
1312
+ : null,
1313
+ secret: input.credential.secret,
1314
+ });
1315
+ if (prepared.kind !== 'ready') {
1316
+ throw codecError('invalid_document', 'Network proxy credential update became stale');
1317
+ }
1318
+ await this.vault.commitSet(root, prepared);
1319
+ durableChange = true;
1320
+ }
1321
+ else if (input.credential.kind === 'delete' && existing) {
1322
+ const prepared = this.vault.prepareDelete(vault, {
1323
+ expected: credentialBasis(existing),
1324
+ });
1325
+ if (prepared.kind !== 'ready') {
1326
+ throw codecError('invalid_document', 'Network proxy credential deletion became stale');
1327
+ }
1328
+ await this.vault.commitDelete(root, prepared);
1329
+ durableChange = true;
1330
+ }
1331
+ };
1332
+ const commitPolicy = async () => {
1333
+ if (!proxyChanged)
1334
+ return;
1335
+ const prepared = this.policy.prepareMutation(policy, {
1336
+ expectedRevision: policy.revision,
1337
+ operation: { kind: 'set_network_proxy', value: input.networkProxy },
1338
+ });
1339
+ if (prepared.kind !== 'ready') {
1340
+ throw codecError('invalid_document', 'Network proxy policy update became stale');
1341
+ }
1342
+ snapshot = (await this.policy.commitMutation(root, prepared)).snapshot;
1343
+ durableChange = true;
1344
+ };
1345
+ // Never leave an enabled policy pointing at an absent credential: publish a
1346
+ // replacement before enabling its use, and retire credential use before deletion.
1347
+ if (input.credential.kind === 'delete' &&
1348
+ !requiresNetworkProxyCredential(input.networkProxy)) {
1349
+ await commitPolicy();
1350
+ await commitCredential();
1351
+ }
1352
+ else {
1353
+ await commitCredential();
1354
+ await commitPolicy();
1355
+ }
1356
+ }
1357
+ catch (error) {
1358
+ if (durableChange && !isCommitOutcomeUnknown(error)) {
1359
+ throw commitOutcomeUnknown('Network proxy update committed only some effects', error);
1360
+ }
1361
+ throw error;
1362
+ }
1363
+ const finalVault = await this.vault.read(root);
1364
+ return deepFreeze({
1365
+ kind: 'committed',
1366
+ snapshot,
1367
+ credentialStatus: credentialStatus(finalVault, locator),
1368
+ });
1369
+ }
1210
1370
  async applyInteractiveOAuthEnrollment(root, intent) {
1211
1371
  const existingReceipt = findInteractiveOAuthLoginReceipt(await readInteractiveOAuthLoginReceipts(root), intent.attemptId);
1212
1372
  const intendedIdentity = interactiveOAuthConnectionIdentity(intent.connectionAfter);
@@ -1381,6 +1541,9 @@ function hideStaleModelFactsVerification(projected, persisted, document, owner)
1381
1541
  }),
1382
1542
  };
1383
1543
  }
1544
+ function matchesCredentialExpectation(actual, expected) {
1545
+ return expected === null ? actual === undefined : sameCredentialBasis(actual, expected);
1546
+ }
1384
1547
  function isCommitOutcomeUnknown(error) {
1385
1548
  return error instanceof RuntimePolicyStoreError && error.code === 'commit_outcome_unknown';
1386
1549
  }
@@ -1557,7 +1720,7 @@ function normalizeInteractiveOAuthLoginInput(input) {
1557
1720
  throw codecError('invalid_connection_input', 'Unknown interactive OAuth login target');
1558
1721
  }
1559
1722
  function newInteractiveOAuthConnection(connectionId, slug, providerType) {
1560
- const defaults = PROVIDER_DEFAULTS[providerType];
1723
+ const defaults = PROVIDER_REGISTRY[providerType];
1561
1724
  return {
1562
1725
  connectionId,
1563
1726
  revision: 1,
@@ -1565,7 +1728,7 @@ function newInteractiveOAuthConnection(connectionId, slug, providerType) {
1565
1728
  name: defaults.label,
1566
1729
  providerType,
1567
1730
  enabled: true,
1568
- enabledModelIds: [...defaults.fallbackModels],
1731
+ enabledModelIds: providerFallbackModelIds(defaults),
1569
1732
  models: [],
1570
1733
  };
1571
1734
  }
@@ -19,7 +19,7 @@
19
19
  import { unlink } from 'node:fs/promises';
20
20
  import { join } from 'node:path';
21
21
  import { decodeProviderType, decodeCanonicalConnectionCatalogEntry, decodeCredentialVersionBasis, decodeConnectionSlug, decodeRuntimePolicyEntityId, normalizeCatalogConnectionBaseUrl, normalizeConnectionCatalogEntryUpdateForProvider, normalizeConnectionModelDiscoveryResult, normalizeCredentialSecret, } from '@maka/core/runtime-policy';
22
- import { deriveConnectionSlug, PROVIDER_DEFAULTS, providerAuthSupportsApiKey, } from '@maka/core/llm-connections';
22
+ import { deriveConnectionSlug, PROVIDER_REGISTRY, providerAuthSupportsApiKey, } from '@maka/core/llm-connections';
23
23
  import { syncDirectory } from '../stable-storage.js';
24
24
  import { record } from './codec.js';
25
25
  import { codecError, commitOutcomeUnknown, decodeConnectionInput, decodeCredentialInput, decodePersistedDomain, ioFailed, } from './errors.js';
@@ -34,7 +34,7 @@ export function prepareConnectionOnboardingIntent(input, source = 'input') {
34
34
  if (!providerAuthSupportsApiKey(providerType)) {
35
35
  throw codecError(source === 'persisted' ? 'invalid_document' : 'invalid_connection_input', 'Onboarding requires an API-key provider');
36
36
  }
37
- const definition = PROVIDER_DEFAULTS[providerType];
37
+ const definition = PROVIDER_REGISTRY[providerType];
38
38
  const discovery = decode(() => normalizeConnectionModelDiscoveryResult(input.discovery));
39
39
  // Non-empty is the requirement; `source` is write provenance, not a
40
40
  // quality bar. A provider without a model-list endpoint runs discovery by
@@ -106,12 +106,15 @@ function createWriterFacade(coordinator) {
106
106
  delete: (input) => coordinator.deleteCredential(input),
107
107
  },
108
108
  operations: {
109
- exportCredentialMaterial: (locator) => coordinator.exportCredentialMaterial(locator),
109
+ updateNetworkProxy: (input) => coordinator.updateNetworkProxy(input),
110
+ exportCredentialMaterial: ((locator, expectedConnection) => expectedConnection
111
+ ? coordinator.exportCredentialMaterial(locator, expectedConnection)
112
+ : coordinator.exportCredentialMaterial(locator)),
110
113
  getConnectionRequestHeaders: (connectionId) => coordinator.getConnectionRequestHeaders(connectionId),
111
114
  replaceConnectionRequestHeaders: (connectionId, updates) => coordinator.replaceConnectionRequestHeaders(connectionId, updates),
112
115
  resolveExecutionConnection: (ref) => coordinator.resolveExecutionConnection(ref),
113
116
  resolveWebSearchExecution: (input) => coordinator.resolveWebSearchExecution(input),
114
- resolveWebFetchExecution: () => coordinator.resolveWebFetchExecution(),
117
+ resolveHostOutboundExecution: () => coordinator.resolveHostOutboundExecution(),
115
118
  resolveNetworkProxyExecution: (input) => coordinator.resolveNetworkProxyExecution(input),
116
119
  compareAndSetOAuthCredential: (input) => coordinator.compareAndSetOAuthCredential(input),
117
120
  importConnectionCredential: (input) => coordinator.importConnectionCredential(input),
@@ -58,7 +58,7 @@ export function lastMessagePreviewForMessages(messages) {
58
58
  return truncatePreview(text);
59
59
  }
60
60
  if (message.type === 'workhub_coordination') {
61
- const text = normalizePreviewText(message.userText);
61
+ const text = 'userText' in message ? normalizePreviewText(message.userText) : '';
62
62
  if (text)
63
63
  return truncatePreview(text);
64
64
  }
@@ -178,6 +178,7 @@ class SqliteSessionStore {
178
178
  assignment: request.assignment,
179
179
  admission: request.admission,
180
180
  projection: projectSessionCatalogMessages([request.assignment]),
181
+ ...(request.supersession ? { supersession: request.supersession } : {}),
181
182
  ...(create
182
183
  ? {
183
184
  create: {
@@ -195,21 +196,43 @@ class SqliteSessionStore {
195
196
  return result;
196
197
  }
197
198
  async readWorkHubAssignment(actionId) {
199
+ const message = await this.readWorkHubCoordinationMessage(`wha_${workHubIdentitySuffix(actionId)}`);
200
+ return message?.type === 'workhub_coordination' && message.kind === 'delegation_assigned'
201
+ ? message
202
+ : undefined;
203
+ }
204
+ async readWorkHubReplacement(delegationId) {
205
+ const message = await this.readWorkHubCoordinationMessage(`whp_${workHubIdentitySuffix(delegationId)}`);
206
+ return message?.type === 'workhub_coordination' &&
207
+ message.kind === 'delegation_replacement_requested'
208
+ ? message
209
+ : undefined;
210
+ }
211
+ async readWorkHubReplacementAbort(delegationId) {
212
+ const message = await this.readWorkHubCoordinationMessage(`whb_${workHubIdentitySuffix(delegationId)}`);
213
+ return message?.type === 'workhub_coordination' &&
214
+ message.kind === 'delegation_replacement_aborted'
215
+ ? message
216
+ : undefined;
217
+ }
218
+ async readWorkHubSupersession(delegationId) {
219
+ const message = await this.readWorkHubCoordinationMessage(`whx_${workHubIdentitySuffix(delegationId)}`);
220
+ return message?.type === 'workhub_coordination' && message.kind === 'delegation_superseded'
221
+ ? message
222
+ : undefined;
223
+ }
224
+ async readWorkHubCoordinationMessage(messageId) {
198
225
  await this.ensureReady();
199
- const suffix = createHash('sha256').update(actionId, 'utf8').digest('hex').slice(0, 48);
200
226
  const throughSequence = await this.metadata.readTranscriptHighWater(WORKHUB_COORDINATION_SESSION_ID);
201
227
  if (throughSequence === null)
202
228
  return undefined;
203
229
  const messages = await this.metadata.readTranscriptMessages(WORKHUB_COORDINATION_SESSION_ID, {
204
- messageIds: [`wha_${suffix}`],
230
+ messageIds: [messageId],
205
231
  throughSequence,
206
232
  maxMessages: 1,
207
233
  maxBytes: 768 * 1024,
208
234
  });
209
- const message = messages[0];
210
- return message?.type === 'workhub_coordination' && message.kind === 'delegation_assigned'
211
- ? message
212
- : undefined;
235
+ return messages[0];
213
236
  }
214
237
  async discardStableConversationCopy(sessionId, requestFingerprint) {
215
238
  await this.ensureReady();
@@ -570,6 +593,9 @@ class SqliteSessionStore {
570
593
  await this.ensureReady();
571
594
  }
572
595
  }
596
+ function workHubIdentitySuffix(value) {
597
+ return createHash('sha256').update(value, 'utf8').digest('hex').slice(0, 48);
598
+ }
573
599
  /**
574
600
  * The reserved identity and the reserved role are one fact, and the invariant
575
601
  * belongs to every creator that builds a header — subagents and Agent Graph