maka-agent 0.2.0-dev.23.20260906 → 0.2.0-dev.25.20260908

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 (215) hide show
  1. package/README.md +38 -19
  2. package/README.zh-CN.md +34 -19
  3. package/dist/acp/maka-acp-agent.js +2 -1
  4. package/dist/acp/session-configuration.js +143 -0
  5. package/dist/acp/session-registry.js +90 -4
  6. package/dist/cli-core.js +2 -0
  7. package/dist/pi-transcript-tools.js +6 -0
  8. package/dist/pi-transcript.js +5 -12
  9. package/dist/pi-tui-layout.js +56 -10
  10. package/dist/pi-tui-pickers.js +102 -1
  11. package/dist/pi-tui-runner.js +230 -46
  12. package/dist/pi-tui-todo.js +221 -0
  13. package/dist/pi-tui-transcript-viewer.js +134 -7
  14. package/dist/runtime-host-cli-context.js +224 -78
  15. package/dist/runtime-host-cli-installation.js +8 -2
  16. package/dist/runtime-host-cli.js +31 -1
  17. package/dist/runtime-host-handoff-surface.js +106 -0
  18. package/dist/runtime-host-installed-update-bootstrap.js +13 -0
  19. package/dist/runtime-host-installed-update-coordinator.js +33 -0
  20. package/dist/runtime-host-lifecycle-transaction.js +9 -1
  21. package/dist/runtime-host-local-handoff.js +48 -5
  22. package/dist/runtime-host-local-managed-activation.js +84 -0
  23. package/dist/runtime-host-local-source-retirement.js +18 -2
  24. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  25. package/dist/runtime-host-operator-retirement.js +50 -0
  26. package/dist/runtime-host-service-manager.js +3 -3
  27. package/dist/runtime-host-session-channel.js +13 -0
  28. package/dist/runtime-host-session-driver.js +46 -26
  29. package/dist/runtime-host-session-update.js +62 -0
  30. package/dist/runtime-host-tui-command.js +38 -73
  31. package/dist/runtime-host-tui-context.js +1 -0
  32. package/dist/runtime-host-tui-owner.js +226 -0
  33. package/dist/tui-copy-catalog.js +219 -6
  34. package/dist/tui-host-owner-copy.js +24 -0
  35. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  36. package/node_modules/@maka/core/dist/agent-run.js +1 -0
  37. package/node_modules/@maka/core/dist/attachments.js +3 -0
  38. package/node_modules/@maka/core/dist/canonical-json.js +27 -0
  39. package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
  40. package/node_modules/@maka/core/dist/capabilities.js +35 -0
  41. package/node_modules/@maka/core/dist/computer-use.js +0 -1
  42. package/node_modules/@maka/core/dist/display-redaction.js +18 -0
  43. package/node_modules/@maka/core/dist/llm-connections.js +13 -0
  44. package/node_modules/@maka/core/dist/model-call-attempt.js +2 -0
  45. package/node_modules/@maka/core/dist/model-failure.js +40 -0
  46. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
  47. package/node_modules/@maka/core/dist/model-metadata.js +7 -3
  48. package/node_modules/@maka/core/dist/model-web-search.js +5 -4
  49. package/node_modules/@maka/core/dist/provider-registry.js +45 -4
  50. package/node_modules/@maka/core/dist/record-schema.js +9 -2
  51. package/node_modules/@maka/core/dist/redaction.js +35 -0
  52. package/node_modules/@maka/core/dist/run-composition.js +77 -2
  53. package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
  54. package/node_modules/@maka/core/dist/runtime-event.js +37 -6
  55. package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
  56. package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
  57. package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
  58. package/node_modules/@maka/core/dist/session.js +84 -56
  59. package/node_modules/@maka/core/dist/slash-command-catalog.js +3 -0
  60. package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
  61. package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
  62. package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
  63. package/node_modules/@maka/core/package.json +5 -0
  64. package/node_modules/@maka/eval/dist/experiment-directory.js +4 -13
  65. package/node_modules/@maka/mcp/dist/index.js +131 -1
  66. package/node_modules/@maka/runtime/dist/agent-run-inspect.js +0 -13
  67. package/node_modules/@maka/runtime/dist/agent-run.js +351 -105
  68. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +29 -13
  69. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
  70. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +184 -183
  71. package/node_modules/@maka/runtime/dist/archive-read-tool.js +2 -2
  72. package/node_modules/@maka/runtime/dist/context-budget-helpers.js +0 -16
  73. package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
  74. package/node_modules/@maka/runtime/dist/conversation-copy.js +158 -15
  75. package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +3 -3
  76. package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
  77. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
  78. package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
  79. package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
  80. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +174 -0
  81. package/node_modules/@maka/runtime/dist/mcp-tools.js +7 -2
  82. package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
  83. package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
  84. package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
  85. package/node_modules/@maka/runtime/dist/model-fetcher.js +49 -2
  86. package/node_modules/@maka/runtime/dist/model-history.js +0 -112
  87. package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
  88. package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
  89. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
  90. package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
  91. package/node_modules/@maka/runtime/dist/plugin-runtime.js +20 -10
  92. package/node_modules/@maka/runtime/dist/plugin-tool-service.js +205 -0
  93. package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
  94. package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +76 -109
  95. package/node_modules/@maka/runtime/dist/request-shape.js +23 -0
  96. package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
  97. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +83 -55
  98. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +121 -159
  99. package/node_modules/@maka/runtime/dist/runtime-kernel.js +157 -112
  100. package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
  101. package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
  102. package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
  103. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
  104. package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
  105. package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
  106. package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +21 -0
  107. package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -5
  108. package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
  109. package/node_modules/@maka/runtime/dist/test-connection.js +16 -17
  110. package/node_modules/@maka/runtime/dist/tool-activation-identity.js +41 -0
  111. package/node_modules/@maka/runtime/dist/tool-availability.js +11 -1
  112. package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
  113. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +63 -1
  114. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +42 -12
  115. package/node_modules/@maka/runtime/dist/tool-result-archive.js +27 -4
  116. package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
  117. package/node_modules/@maka/runtime/package.json +2 -0
  118. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
  119. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
  120. package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
  121. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +179 -0
  122. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +275 -0
  123. package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
  124. package/node_modules/@maka/runtime-host/dist/client/index.js +2 -0
  125. package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
  126. package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
  127. package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +46 -5
  128. package/node_modules/@maka/runtime-host/dist/control/endpoint.js +1 -3
  129. package/node_modules/@maka/runtime-host/dist/node-error.js +22 -0
  130. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  131. package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +1 -3
  132. package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
  133. package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +0 -1
  134. package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +1 -1
  135. package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +1 -3
  136. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +21 -12
  137. package/node_modules/@maka/runtime-host/dist/protocol/index.js +29 -1
  138. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
  139. package/node_modules/@maka/runtime-host/dist/protocol/plan.js +1 -0
  140. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +27 -5
  141. package/node_modules/@maka/runtime-host/dist/protocol/project-catalog.js +2 -2
  142. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
  143. package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
  144. package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
  145. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
  146. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +31 -2
  147. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
  148. package/node_modules/@maka/runtime-host/dist/server/agent-graph-coordinator.js +0 -3
  149. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
  150. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
  151. package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +32 -32
  152. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +144 -33
  153. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
  154. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +45 -16
  155. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
  156. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +96 -17
  157. package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
  158. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
  159. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
  160. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +47 -22
  161. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +76 -6
  162. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
  163. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
  164. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +325 -73
  165. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
  166. package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
  167. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +50 -7
  168. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
  169. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +5 -2
  170. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +12 -55
  171. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
  172. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
  173. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
  174. package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
  175. package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
  176. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +20 -2
  177. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +13 -4
  178. package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +46 -0
  179. package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
  180. package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
  181. package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -5
  182. package/node_modules/@maka/storage/dist/codex-session-adapter.js +284 -198
  183. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
  184. package/node_modules/@maka/storage/dist/execution-stores.js +9 -7
  185. package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
  186. package/node_modules/@maka/storage/dist/git-exec.js +61 -0
  187. package/node_modules/@maka/storage/dist/git-worktree-child-executor.js +8 -35
  188. package/node_modules/@maka/storage/dist/goal-authority.js +2 -2
  189. package/node_modules/@maka/storage/dist/interaction-store.js +2 -2
  190. package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
  191. package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
  192. package/node_modules/@maka/storage/dist/project-catalog.js +2 -23
  193. package/node_modules/@maka/storage/dist/runtime-event-invariants.js +2 -2
  194. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  195. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +8 -3
  196. package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
  197. package/node_modules/@maka/storage/dist/scheduled-task-store.js +249 -283
  198. package/node_modules/@maka/storage/dist/session-bundle-manifest.js +5 -17
  199. package/node_modules/@maka/storage/dist/session-bundle-policy.js +26 -5
  200. package/node_modules/@maka/storage/dist/session-copy-cleanup.js +2 -1
  201. package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
  202. package/node_modules/@maka/storage/dist/session-repository.js +767 -0
  203. package/node_modules/@maka/storage/dist/session-store.js +25 -99
  204. package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
  205. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
  206. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +7 -1
  207. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
  208. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +130 -27
  209. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
  210. package/node_modules/@maka/storage/dist/storage-id.js +28 -0
  211. package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +138 -0
  212. package/node_modules/@maka/storage/dist/workspace-identity.js +2 -15
  213. package/node_modules/@maka/storage/dist/workspace-version-authority-internal.js +1 -8
  214. package/node_modules/@maka/storage/package.json +2 -0
  215. package/package.json +1 -1
@@ -17,59 +17,54 @@
17
17
  * under the License.
18
18
  */
19
19
  import { PROVIDER_REGISTRY, effectiveBaseUrl, } from '@maka/core/llm-connections';
20
- import { lookupModelMetadata, lookupModelProviderOverride, openAiAdapterApiProtocol, } from '@maka/core/model-metadata';
20
+ import { lookupModelMetadata, lookupModelRuntimeOverride, openAiAdapterApiProtocol, } from '@maka/core/model-metadata';
21
21
  import { isRetiredProvider } from '@maka/core/provider-registry';
22
+ import { anthropicV1BaseUrl, googleV1BetaBaseUrl, openAiResponsesBaseUrl, } from './provider-urls.js';
22
23
  import { resolveApplyPatchProfile } from './apply-patch-profile.js';
23
24
  import { resolveRuntimeProviderAdapter, runtimeProviderName, } from './provider-runtime-policy.js';
24
25
  export function resolveModelRuntime(connection, modelId) {
25
- // Ahead of the override lookup: an override builds its own active adapter,
26
- // so consulting it first would let a per-model entry hand a retired provider
27
- // a working adapter and skip the `unavailable` refusal below entirely. No
28
- // such entry exists today, but that table is generated from an external
29
- // source — one row should not be able to undo a retirement.
26
+ // Model metadata cannot reactivate a retired provider.
30
27
  if (isRetiredProvider(connection.providerType)) {
31
28
  throw new Error(`"${connection.providerType}" is retired and can no longer resolve a model runtime.`);
32
29
  }
33
- const override = lookupModelProviderOverride(connection.providerType, modelId);
30
+ const override = lookupModelRuntimeOverride(connection.providerType, modelId);
34
31
  const defaults = PROVIDER_REGISTRY[connection.providerType];
35
- // Unknown providerType with no per-model override → can't resolve an adapter.
36
- // Throw a clear error rather than crashing on `.runtimeAdapter`. Mirrors
37
- // `isRealConnection` in @maka/core/connection-readiness.ts.
38
32
  if (!override && !defaults) {
39
33
  throw new Error(`Unknown provider type "${connection.providerType}"; cannot resolve model runtime.`);
40
34
  }
41
35
  const apiProtocol = connection.models?.find((model) => model.id === modelId)?.apiProtocol;
42
- if (connection.providerType === 'kimi-coding-plan' &&
43
- apiProtocol !== undefined &&
44
- apiProtocol !== 'anthropic-messages' &&
45
- apiProtocol !== 'openai-chat') {
46
- throw new Error(`Kimi Coding Plan protocol must be openai-chat or anthropic-messages, received ${apiProtocol}`);
47
- }
48
- const baseAdapter = connection.providerType === 'kimi-coding-plan' && apiProtocol === 'openai-chat'
49
- ? {
50
- kind: 'openai-compatible',
51
- name: 'provider',
52
- includeUsage: true,
53
- }
54
- : override
55
- ? runtimeAdapterOverride(override.npm)
56
- : defaults.runtimeAdapter;
57
- const adapter = resolveRuntimeProviderAdapter(baseAdapter);
36
+ const baseAdapter = resolveRuntimeProviderAdapter(override?.adapter ?? defaults.runtimeAdapter);
37
+ const calls = adapterCalls(baseAdapter);
38
+ const preferred = openAiAdapterApiProtocol(modelId, connection.providerType);
39
+ const defaultCall = calls.find((call) => call.wire === preferred) ?? calls[0];
40
+ const declared = apiProtocol ? defaults.protocolAdapters?.[apiProtocol] : undefined;
41
+ const call = apiProtocol === undefined
42
+ ? defaultCall
43
+ : (calls.find((candidate) => candidate.wire === apiProtocol) ??
44
+ (declared
45
+ ? adapterCalls(resolveRuntimeProviderAdapter(declared)).find((candidate) => candidate.wire === apiProtocol)
46
+ : undefined) ??
47
+ adapterCalls(resolveRuntimeProviderAdapter(defaults.runtimeAdapter)).find((candidate) => candidate.wire === apiProtocol));
48
+ if (!call)
49
+ throw new Error(`${defaults.label} does not support ${apiProtocol} for model ${modelId}`);
50
+ const { adapter, wire, reasoningReplay: replay } = call;
58
51
  const configuredBaseUrl = connection.baseUrl?.trim();
59
52
  const resolvedBaseUrl = configuredBaseUrl
60
53
  ? effectiveBaseUrl(connection)
61
- : (override?.api ?? effectiveBaseUrl(connection));
62
- const wire = resolveModelRuntimeWire(connection.providerType, modelId, adapter, apiProtocol);
63
- const parallelToolCalls = resolveParallelToolCalls(connection, modelId, adapter);
64
- const replay = reasoningReplayContract(adapter, wire);
54
+ : ((calls.includes(call) ? override?.baseUrl : undefined) ?? effectiveBaseUrl(connection));
55
+ const baseUrl = adapter.kind === 'anthropic' && adapter.normalizeBaseUrl
56
+ ? anthropicV1BaseUrl(resolvedBaseUrl)
57
+ : adapter.kind === 'google' && adapter.normalizeBaseUrl !== false
58
+ ? googleV1BetaBaseUrl(resolvedBaseUrl)
59
+ : adapter.kind === 'openai-compatible' && adapter.normalizeBaseUrl
60
+ ? anthropicV1BaseUrl(resolvedBaseUrl)
61
+ : wire === 'openai-responses' && resolvedBaseUrl
62
+ ? openAiResponsesBaseUrl(resolvedBaseUrl)
63
+ : resolvedBaseUrl;
64
+ const parallelToolCalls = resolveParallelToolCalls(connection, modelId, baseAdapter);
65
65
  return {
66
- adapter,
67
- baseUrl: connection.providerType === 'kimi-coding-plan' && apiProtocol === 'openai-chat'
68
- ? kimiOpenAiBaseUrl(resolvedBaseUrl)
69
- : resolvedBaseUrl,
70
- ...(apiProtocol ? { apiProtocol } : {}),
71
- wire,
72
- reasoningReplay: replay,
66
+ ...call,
67
+ baseUrl,
73
68
  ...(parallelToolCalls === undefined ? {} : { parallelToolCalls }),
74
69
  ...(replay.kind === 'responses' &&
75
70
  replay.contract.adapter === 'open-responses' &&
@@ -99,88 +94,67 @@ function resolveParallelToolCalls(connection, modelId, adapter) {
99
94
  // they require an explicit model declaration instead of inheriting this.
100
95
  return adapter.kind === 'openai' || adapter.kind === 'openai-codex' ? true : undefined;
101
96
  }
102
- export function modelUsesAnthropicMessages(connection, modelId) {
103
- return resolveModelRuntime(connection, modelId).wire === 'anthropic-messages';
104
- }
105
97
  /** Native OpenAI lanes keep mutable continuation state inside ModelAdapter. */
106
98
  export function modelUsesNativeOpenAiResponses(connection, modelId) {
107
99
  return (connection.providerType === 'openai' &&
108
100
  resolveModelRuntime(connection, modelId).wire === 'openai-responses');
109
101
  }
110
- function resolveModelRuntimeWire(providerType, modelId, adapter, apiProtocol) {
102
+ function adapterCalls(adapter) {
111
103
  switch (adapter.kind) {
112
104
  case 'anthropic':
113
- return 'anthropic-messages';
114
- case 'unavailable':
115
- // Reached only if something selected a retired provider despite the
116
- // pickers filtering it out; failing here beats sending on a wire we
117
- // cannot name.
118
- throw new Error('This provider has no Runtime adapter and cannot resolve a wire.');
119
- case 'openai-codex':
120
- return 'openai-responses';
121
- case 'github-copilot':
122
- return apiProtocol === 'anthropic-messages'
123
- ? 'anthropic-messages'
124
- : apiProtocol === 'openai-responses'
125
- ? 'openai-responses'
126
- : 'openai-chat';
127
- case 'openai':
128
- return (adapter.apiProtocol ??
129
- apiProtocol ??
130
- openAiAdapterApiProtocol(modelId, providerType)) === 'openai-responses'
131
- ? 'openai-responses'
132
- : 'openai-chat';
133
- case 'openai-compatible':
134
- return adapter.responses !== undefined &&
135
- (apiProtocol ?? openAiAdapterApiProtocol(modelId, providerType)) === 'openai-responses'
136
- ? 'openai-responses'
137
- : 'openai-chat';
105
+ return [
106
+ { adapter, wire: 'anthropic-messages', reasoningReplay: { kind: 'anthropic-signed' } },
107
+ ];
138
108
  case 'google':
139
- return 'google-generate';
109
+ return [{ adapter, wire: 'google-generate', reasoningReplay: { kind: 'none' } }];
140
110
  case 'cohere':
141
- return 'cohere-v2';
142
- }
143
- }
144
- function reasoningReplayContract(adapter, wire) {
145
- switch (wire) {
146
- case 'anthropic-messages':
147
- return { kind: 'anthropic-signed' };
148
- case 'openai-responses':
149
- return { kind: 'responses', contract: responsesContract(adapter) };
150
- case 'openai-chat':
151
- return adapter.kind === 'openai-compatible' || adapter.kind === 'github-copilot'
152
- ? {
153
- kind: 'openai-chat-plaintext',
154
- requestField: adapter.kind === 'openai-compatible' &&
155
- adapter.replayAssistantReasoningAs === 'reasoning'
156
- ? 'reasoning'
157
- : 'observed',
158
- }
159
- : { kind: 'none' };
160
- case 'google-generate':
161
- case 'cohere-v2':
162
- return { kind: 'none' };
163
- }
164
- }
165
- function responsesContract(adapter) {
166
- if (adapter.kind === 'openai-compatible' && adapter.responses)
167
- return adapter.responses;
168
- return { adapter: 'openai', reasoningReplay: 'encrypted-content' };
169
- }
170
- function kimiOpenAiBaseUrl(baseUrl) {
171
- return `${baseUrl.replace(/\/+$/, '').replace(/\/v1$/i, '')}/v1`;
172
- }
173
- function runtimeAdapterOverride(packageName) {
174
- switch (packageName) {
175
- case '@ai-sdk/anthropic':
176
- return { kind: 'anthropic', auth: 'api-key', normalizeBaseUrl: true };
177
- case '@ai-sdk/google':
178
- return { kind: 'google', normalizeBaseUrl: false };
179
- case '@ai-sdk/openai':
180
- return { kind: 'openai' };
181
- case '@ai-sdk/openai-compatible':
182
- return { kind: 'openai-compatible', name: 'provider' };
183
- default:
184
- throw new Error(`models.dev model runtime package ${packageName} is unsupported`);
111
+ return [{ adapter, wire: 'cohere-v2', reasoningReplay: { kind: 'none' } }];
112
+ case 'openai-codex':
113
+ return [
114
+ {
115
+ adapter,
116
+ wire: 'openai-responses',
117
+ reasoningReplay: {
118
+ kind: 'responses',
119
+ contract: { adapter: 'openai', reasoningReplay: 'encrypted-content' },
120
+ },
121
+ },
122
+ ];
123
+ case 'openai': {
124
+ const calls = [];
125
+ if (adapter.apiProtocol !== 'openai-responses')
126
+ calls.push({ adapter, wire: 'openai-chat', reasoningReplay: { kind: 'none' } });
127
+ if (adapter.apiProtocol !== 'openai-chat')
128
+ calls.push({
129
+ adapter,
130
+ wire: 'openai-responses',
131
+ reasoningReplay: {
132
+ kind: 'responses',
133
+ contract: { adapter: 'openai', reasoningReplay: 'encrypted-content' },
134
+ },
135
+ });
136
+ return calls;
137
+ }
138
+ case 'openai-compatible': {
139
+ const calls = [
140
+ {
141
+ adapter,
142
+ wire: 'openai-chat',
143
+ reasoningReplay: {
144
+ kind: 'openai-chat-plaintext',
145
+ requestField: adapter.replayAssistantReasoningAs ?? 'observed',
146
+ },
147
+ },
148
+ ];
149
+ if (adapter.responses)
150
+ calls.push({
151
+ adapter,
152
+ wire: 'openai-responses',
153
+ reasoningReplay: { kind: 'responses', contract: adapter.responses },
154
+ });
155
+ return calls;
156
+ }
157
+ case 'unavailable':
158
+ throw new Error('This provider has no Runtime adapter and cannot resolve a wire.');
185
159
  }
186
160
  }
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import { z } from 'zod';
20
20
  import { resolveHostedWebSearchCapability } from '@maka/core/model-web-search';
21
+ import { resolveModelRuntime } from './model-runtime.js';
21
22
  export const NATIVE_WEB_SEARCH_TOOL_NAME = 'WebSearch';
22
23
  /**
23
24
  * Provider-executed search descriptor. AI SDK compiles this into the selected
@@ -61,7 +62,7 @@ export function routeWebSearchTools(input) {
61
62
  : undefined;
62
63
  }
63
64
  else {
64
- const capability = resolveHostedWebSearchCapability(input.connection.providerType, input.connection.models, input.model);
65
+ const capability = resolveHostedWebSearchCapability(input.connection.providerType, input.connection.models, input.model, resolveModelRuntime(input.connection, input.model).wire);
65
66
  if ((firstSearchIndex >= 0 || input.allowAddNative === true) &&
66
67
  capability?.implemented === true &&
67
68
  capability.adapter === 'openai-responses') {
@@ -91,7 +91,7 @@ export function buildOpenAiCodexHistoryCompactor(options) {
91
91
  catch (error) {
92
92
  if (error instanceof HistoryCompactSummarizerError)
93
93
  throw error;
94
- if (classifyError(error) === 'ContextLength') {
94
+ if (classifyError(error) === 'context_overflow') {
95
95
  throw new HistoryCompactSummarizerError('input_too_large', { cause: error });
96
96
  }
97
97
  throw new HistoryCompactSummarizerError('provider_error', { cause: error });
@@ -126,7 +126,7 @@ export function shouldFallbackFromOpenAiCodexHistoryCompaction(error, abortSigna
126
126
  if (error.reason !== 'provider_error')
127
127
  return false;
128
128
  const diagnostic = providerFailureDiagnostic(error);
129
- return diagnostic.errorClass === 'RequestRejected' && !diagnostic.retryable;
129
+ return diagnostic.errorClass === 'request_rejected' && !diagnostic.retryable;
130
130
  }
131
131
  function hasAbortCause(error) {
132
132
  const seen = new Set();
@@ -17,11 +17,13 @@
17
17
  * under the License.
18
18
  */
19
19
  export const OPENCODE_SESSION_HEADER = 'x-opencode-session';
20
- /** Adds OpenCode Go's session identity without overriding an explicit header. */
20
+ /** Adds OpenCode Go/Free session identity without overriding an explicit header. */
21
21
  export function withOpenCodeSessionHeader(providerType, sessionId, headers) {
22
22
  const normalizedSessionId = sessionId?.trim();
23
- if (providerType !== 'opencode-go' || !normalizedSessionId)
23
+ if ((providerType !== 'opencode-go' && providerType !== 'opencode-free') ||
24
+ !normalizedSessionId) {
24
25
  return headers;
26
+ }
25
27
  if (Object.keys(headers ?? {}).some((name) => name.toLowerCase() === OPENCODE_SESSION_HEADER)) {
26
28
  return headers;
27
29
  }
@@ -269,10 +269,9 @@ function registerPluginEffect(ctx, label, register) {
269
269
  }
270
270
  export function registerPluginContribution(ctx, label, register) {
271
271
  if (ctx.makaTransaction) {
272
- ctx.makaTransaction.stage(label, register, ctx);
273
- return;
272
+ return ctx.makaTransaction.stage(label, register, ctx);
274
273
  }
275
- registerPluginEffect(ctx, label, register);
274
+ return registerPluginEffect(ctx, label, register);
276
275
  }
277
276
  export class MakaPluginTransactionBuffer {
278
277
  context;
@@ -283,13 +282,22 @@ export class MakaPluginTransactionBuffer {
283
282
  }
284
283
  stage(label, register, owner = this.context) {
285
284
  if (this.#state === 'committed') {
286
- registerPluginEffect(owner, label, register);
287
- return;
285
+ return registerPluginEffect(owner, label, register);
288
286
  }
289
287
  if (this.#state === 'rolled_back') {
290
288
  throw new MakaPluginRuntimeError('activation_failed', `Cannot stage contribution after transaction is ${this.#state}`);
291
289
  }
292
- this.#registrations.push({ label, register, owner });
290
+ const item = {
291
+ label,
292
+ register,
293
+ owner,
294
+ cancelled: false,
295
+ };
296
+ this.#registrations.push(item);
297
+ return async () => {
298
+ item.cancelled = true;
299
+ await item.release?.();
300
+ };
293
301
  }
294
302
  async commit() {
295
303
  if (this.#state === 'committed')
@@ -300,7 +308,10 @@ export class MakaPluginTransactionBuffer {
300
308
  const registered = [];
301
309
  try {
302
310
  for (const item of this.#registrations) {
303
- registered.push(registerPluginEffect(item.owner, item.label, item.register));
311
+ if (item.cancelled)
312
+ continue;
313
+ item.release = registerPluginEffect(item.owner, item.label, item.register);
314
+ registered.push(item.release);
304
315
  }
305
316
  this.#state = 'committed';
306
317
  this.#registrations.length = 0;
@@ -333,10 +344,9 @@ export class MakaPluginTransactionBuffer {
333
344
  export function fiberStateName(state) {
334
345
  return ['pending', 'loading', 'active', 'failed', 'disposed', 'unloading'][state];
335
346
  }
336
- export function isCanonicalPluginId(value) {
347
+ export function isCanonicalExtensionId(value) {
337
348
  return typeof value === 'string' && value.length <= 128 && ID_PATTERN.test(value);
338
349
  }
339
- export const isCanonicalExtensionId = isCanonicalPluginId;
340
350
  function cloneCompositionEntry(entry) {
341
351
  return {
342
352
  ...entry,
@@ -384,7 +394,7 @@ export function isCanonicalExtensionScopeId(value) {
384
394
  return (typeof value === 'string' && value.length <= 128 && /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u.test(value));
385
395
  }
386
396
  function validatePluginId(value, label) {
387
- if (!isCanonicalPluginId(value)) {
397
+ if (!isCanonicalExtensionId(value)) {
388
398
  throw new MakaPluginRuntimeError('invalid_entry', `Invalid ${label}`);
389
399
  }
390
400
  }
@@ -0,0 +1,205 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ import { REQUEST_COMPOSITION_MAX_TOOL_DESCRIPTION_LENGTH } from '@maka/core/run-composition';
20
+ import { Service } from './plugin-kernel.js';
21
+ import { MakaPluginRuntimeError, pluginIdentity, registerPluginContribution, } from './plugin-runtime.js';
22
+ import { bindToolActivationIdentity } from './tool-activation-identity.js';
23
+ import { TOOL_SEARCH_NAME, TOOL_SEARCH_PROVIDER_NAME } from './tool-availability.js';
24
+ /**
25
+ * Context-scoped Tool contribution registry for trusted Host plugins.
26
+ *
27
+ * Registration is staged by the Plugin Platform transaction and owned by the
28
+ * registering Fiber. Profile registrations are inherited by Session roots;
29
+ * an exact Session registration shadows the Profile registration. Core tools
30
+ * remain Host-owned and cannot be shadowed.
31
+ */
32
+ export class PluginToolService extends Service {
33
+ layers = new Map();
34
+ onChanged;
35
+ constructor(ctx, options = {}) {
36
+ super(ctx, 'tools');
37
+ this.onChanged = options.onChanged;
38
+ }
39
+ register(definition) {
40
+ const identity = pluginIdentity(this.ctx);
41
+ if (identity.scopeId === 'desktop-ui') {
42
+ throw new MakaPluginRuntimeError('activation_failed', 'desktop-ui plugins cannot register Host tools');
43
+ }
44
+ validateTool(definition);
45
+ return registerPluginContribution(this.ctx, `tools.register(${JSON.stringify(definition.name)})`, () => this.publish(identity, definition));
46
+ }
47
+ resolve(sessionId, coreTools) {
48
+ const contributions = this.resolveContributions(sessionId, coreTools);
49
+ return Object.freeze({
50
+ tools: Object.freeze([...coreTools, ...contributions.tools]),
51
+ });
52
+ }
53
+ /** Resolve only Plugin-owned additions after validating them against the Host binding. */
54
+ resolveContributions(sessionId, coreTools) {
55
+ if (!sessionId || /[\r\n\0]/u.test(sessionId))
56
+ throw new Error('Invalid Tool Session scope');
57
+ const visible = new Map();
58
+ for (const entry of this.layers.get('profile')?.values() ?? []) {
59
+ visible.set(entry.definition.name, entry);
60
+ }
61
+ const sessionRoot = `session:${sessionId}`;
62
+ for (const entry of this.layers.get(sessionRoot)?.values() ?? []) {
63
+ visible.set(entry.definition.name, entry);
64
+ }
65
+ const coreNames = new Set(coreTools.map(({ name }) => name));
66
+ for (const name of visible.keys()) {
67
+ if (coreNames.has(name)) {
68
+ throw new MakaPluginRuntimeError('activation_failed', `Plugin Tool ${JSON.stringify(name)} conflicts with a Host-owned Tool`);
69
+ }
70
+ }
71
+ const entries = [...visible.values()].sort(compareRegistration);
72
+ return Object.freeze({
73
+ tools: Object.freeze(entries.map(({ exposed }) => exposed)),
74
+ });
75
+ }
76
+ inspect(rootId) {
77
+ const layers = rootId
78
+ ? [[rootId, this.layers.get(rootId)]]
79
+ : [...this.layers.entries()];
80
+ return Object.freeze(layers
81
+ .flatMap(([, layer]) => [...(layer?.values() ?? [])])
82
+ .sort(compareRegistration)
83
+ .map((entry) => Object.freeze({
84
+ entryId: entry.entryId,
85
+ scopeId: entry.scopeId,
86
+ extensionId: entry.extensionId,
87
+ generation: entry.generation,
88
+ toolName: entry.definition.name,
89
+ activeCalls: entry.activeCalls,
90
+ retired: entry.retired,
91
+ })));
92
+ }
93
+ publish(identity, definition) {
94
+ const rootId = identity.scopeId;
95
+ let layer = this.layers.get(rootId);
96
+ if (!layer) {
97
+ layer = new Map();
98
+ this.layers.set(rootId, layer);
99
+ }
100
+ const existing = layer.get(definition.name);
101
+ if (existing && existing.entryId !== identity.entryId) {
102
+ throw new MakaPluginRuntimeError('activation_failed', `Plugin Tool ${JSON.stringify(definition.name)} is already registered by ${existing.entryId}`);
103
+ }
104
+ let entry;
105
+ const exposed = bindToolActivationIdentity({
106
+ ...definition,
107
+ impl: async (args, context) => {
108
+ if (entry.retired) {
109
+ throw new Error(`Plugin Tool ${JSON.stringify(definition.name)} is no longer active`);
110
+ }
111
+ entry.activeCalls += 1;
112
+ try {
113
+ return await definition.impl(args, context);
114
+ }
115
+ finally {
116
+ entry.activeCalls -= 1;
117
+ if (entry.activeCalls === 0) {
118
+ for (const resolve of entry.drainWaiters)
119
+ resolve();
120
+ entry.drainWaiters.clear();
121
+ }
122
+ }
123
+ },
124
+ }, {
125
+ kind: 'plugin',
126
+ scopeId: identity.scopeId,
127
+ entryId: identity.entryId,
128
+ extensionId: identity.extensionId,
129
+ generation: identity.generation,
130
+ toolName: definition.name,
131
+ });
132
+ entry = {
133
+ ...identity,
134
+ definition,
135
+ exposed,
136
+ token: Symbol(definition.name),
137
+ activeCalls: 0,
138
+ retired: false,
139
+ drainWaiters: new Set(),
140
+ };
141
+ layer.set(definition.name, entry);
142
+ try {
143
+ this.notifyChanged(rootId);
144
+ }
145
+ catch (error) {
146
+ if (existing)
147
+ layer.set(definition.name, existing);
148
+ else
149
+ layer.delete(definition.name);
150
+ if (layer.size === 0)
151
+ this.layers.delete(rootId);
152
+ throw error;
153
+ }
154
+ return async () => {
155
+ entry.retired = true;
156
+ const currentLayer = this.layers.get(rootId);
157
+ if (currentLayer?.get(definition.name)?.token === entry.token) {
158
+ if (existing && !existing.retired)
159
+ currentLayer.set(definition.name, existing);
160
+ else
161
+ currentLayer.delete(definition.name);
162
+ if (currentLayer.size === 0)
163
+ this.layers.delete(rootId);
164
+ this.notifyChanged(rootId);
165
+ }
166
+ if (entry.activeCalls > 0) {
167
+ await new Promise((resolve) => entry.drainWaiters.add(resolve));
168
+ }
169
+ };
170
+ }
171
+ notifyChanged(rootId) {
172
+ this.ctx.emit('tools/change');
173
+ this.onChanged?.(rootId);
174
+ }
175
+ }
176
+ function validateTool(tool) {
177
+ if (!tool || typeof tool !== 'object')
178
+ throw new TypeError('Tool definition is required');
179
+ if (typeof tool.name !== 'string' ||
180
+ tool.name.length === 0 ||
181
+ tool.name.length > 128 ||
182
+ /[\r\n\0]/u.test(tool.name)) {
183
+ throw new TypeError('Tool requires a valid name');
184
+ }
185
+ if (typeof tool.description !== 'string' ||
186
+ tool.description.length === 0 ||
187
+ tool.description.length > REQUEST_COMPOSITION_MAX_TOOL_DESCRIPTION_LENGTH ||
188
+ typeof tool.impl !== 'function') {
189
+ throw new TypeError(`Tool ${JSON.stringify(tool.name)} requires a description of at most ${REQUEST_COMPOSITION_MAX_TOOL_DESCRIPTION_LENGTH} characters and an implementation`);
190
+ }
191
+ if (tool.parameters === undefined) {
192
+ throw new TypeError(`Tool ${JSON.stringify(tool.name)} requires an input schema`);
193
+ }
194
+ if (tool.providerTool) {
195
+ throw new TypeError(`Plugin Tool ${JSON.stringify(tool.name)} cannot claim a provider protocol`);
196
+ }
197
+ if (tool.name === TOOL_SEARCH_NAME || tool.name === TOOL_SEARCH_PROVIDER_NAME) {
198
+ throw new TypeError(`Plugin Tool name ${JSON.stringify(tool.name)} is reserved by Runtime`);
199
+ }
200
+ }
201
+ function compareRegistration(left, right) {
202
+ return (left.definition.name.localeCompare(right.definition.name) ||
203
+ left.scopeId.localeCompare(right.scopeId) ||
204
+ left.entryId.localeCompare(right.entryId));
205
+ }