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
@@ -29,7 +29,7 @@ import { isJSONArray, } from '@ai-sdk/provider';
29
29
  import { lookupModelMetadata } from '@maka/core/model-metadata';
30
30
  import { resolveThinkingLevel, supportsRelayFastServiceTier, thinkingOptionsForModel, thinkingVariantsForConnection, } from '@maka/core/model-thinking';
31
31
  import { createOpenAiChatReasoningTransport, createOpenAiChatReasoningTransportState, } from './openai-chat-reasoning-transport.js';
32
- import { anthropicV1BaseUrl, googleV1BetaBaseUrl, openAiResponsesBaseUrl, openResponsesUrl, } from './provider-urls.js';
32
+ import { openResponsesUrl } from './provider-urls.js';
33
33
  import { createOpenResponsesCompatibilityFinalizer } from './open-responses-compatibility.js';
34
34
  import { resolveModelRuntime } from './model-runtime.js';
35
35
  import { runtimeProviderName } from './provider-runtime-policy.js';
@@ -51,22 +51,14 @@ export function getAIModel(input) {
51
51
  bodyOverlay: connection.requestBodyOverlay,
52
52
  };
53
53
  const requestFetch = createRequestCustomizationFetch(baseFetch, requestCustomization);
54
- if (adapter.kind === 'google' && adapter.normalizeBaseUrl === false) {
55
- return createGoogle({ apiKey, baseURL, fetch: requestFetch }).chat(modelId);
56
- }
57
54
  switch (adapter.kind) {
58
55
  case 'anthropic':
59
56
  return createAnthropic({
60
57
  ...(adapter.auth === 'bearer' ? { authToken: apiKey } : { apiKey }),
61
- baseURL: adapter.normalizeBaseUrl ? anthropicV1BaseUrl(baseURL) : baseURL,
58
+ baseURL,
62
59
  fetch: requestFetch,
63
- headers: { 'anthropic-beta': ANTHROPIC_BETA },
60
+ headers: adapter.includeBetaHeaders === false ? undefined : { 'anthropic-beta': ANTHROPIC_BETA },
64
61
  }).chat(modelId);
65
- case 'unavailable':
66
- // A retired provider must never reach model construction. The pickers
67
- // filter it out and `resolveModelRuntime` refuses earlier; this is the
68
- // backstop that keeps a stored connection from silently sending.
69
- throw new Error('This provider is retired and can no longer be used to send.');
70
62
  case 'openai-codex':
71
63
  return createOpenAI({
72
64
  apiKey,
@@ -76,36 +68,10 @@ export function getAIModel(input) {
76
68
  : requestFetch,
77
69
  headers: openAiCodexHeaders(apiKey),
78
70
  }).responses(modelId);
79
- case 'github-copilot': {
80
- if (wire === 'openai-responses') {
81
- return createOpenAI({ apiKey, baseURL, fetch: requestFetch }).responses(modelId);
82
- }
83
- if (wire === 'anthropic-messages') {
84
- return createAnthropic({
85
- authToken: apiKey,
86
- baseURL: anthropicV1BaseUrl(baseURL),
87
- fetch: requestFetch,
88
- }).chat(modelId);
89
- }
90
- if (reasoningReplay.kind !== 'openai-chat-plaintext') {
91
- throw new Error('Copilot OpenAI Chat wire requires plaintext reasoning replay');
92
- }
93
- const reasoningTransport = createOpenAiChatReasoningTransport(requestFetch, openAiChatReasoningTransportState ??
94
- createOpenAiChatReasoningTransportState(reasoningReplay.requestField));
95
- return createOpenAICompatible({
96
- name: 'github-copilot',
97
- apiKey,
98
- baseURL,
99
- fetch: reasoningTransport.fetch,
100
- transformRequestBody: reasoningTransport.transformRequestBody,
101
- }).chatModel(modelId);
102
- }
103
71
  case 'openai': {
104
72
  const openai = createOpenAI({
105
73
  apiKey,
106
- // The native adapter appends `/responses`; reduce endpoint-form
107
- // overrides back to their base so probe-approved relay URLs work.
108
- baseURL: wire === 'openai-responses' && baseURL ? openAiResponsesBaseUrl(baseURL) : baseURL,
74
+ baseURL,
109
75
  fetch: !hasRequestCustomization && openAiResponsesTransportState
110
76
  ? openAiResponsesTransportState.wrapFetch(requestFetch)
111
77
  : requestFetch,
@@ -115,7 +81,7 @@ export function getAIModel(input) {
115
81
  case 'google':
116
82
  return createGoogle({
117
83
  apiKey,
118
- baseURL: googleV1BetaBaseUrl(baseURL),
84
+ baseURL,
119
85
  fetch: requestFetch,
120
86
  }).chat(modelId);
121
87
  case 'cohere':
@@ -125,9 +91,6 @@ export function getAIModel(input) {
125
91
  throw new Error(`${connection.providerType} connection ${connection.slug} requires a base URL`);
126
92
  }
127
93
  if (wire === 'openai-responses') {
128
- if (reasoningReplay.kind !== 'responses') {
129
- throw new Error('Responses wire requires a Responses continuation contract');
130
- }
131
94
  if (reasoningReplay.contract.adapter === 'open-responses') {
132
95
  const finalizeBody = createOpenResponsesCompatibilityFinalizer(reasoningReplay.contract.compatibility);
133
96
  // Request customization is applied first; provider compatibility is
@@ -148,9 +111,7 @@ export function getAIModel(input) {
148
111
  }
149
112
  return createOpenAI({
150
113
  apiKey,
151
- // Endpoint-form overrides (`…/responses`) probe successfully; the
152
- // native adapter appends `/responses` itself, so pass the base.
153
- baseURL: baseURL ? openAiResponsesBaseUrl(baseURL) : baseURL,
114
+ baseURL,
154
115
  fetch: requestFetch,
155
116
  }).responses(modelId);
156
117
  }
@@ -158,7 +119,7 @@ export function getAIModel(input) {
158
119
  throw new Error('OpenAI-compatible Chat wire requires plaintext reasoning replay');
159
120
  }
160
121
  const reasoningTransport = createOpenAiChatReasoningTransport(requestFetch, openAiChatReasoningTransportState ??
161
- createOpenAiChatReasoningTransportState(reasoningReplay.requestField), connection.providerType === 'kimi-coding-plan');
122
+ createOpenAiChatReasoningTransportState(reasoningReplay.requestField), adapter.normalizeUsage);
162
123
  const transformRequestBody = adapter.replayAssistantReasoningDetails
163
124
  ? composeRequestTransforms(reasoningTransport.transformRequestBody, replayAssistantReasoning('reasoning', true))
164
125
  : reasoningTransport.transformRequestBody;
@@ -378,10 +339,10 @@ function claudeThinkingMode(providerType, modelId, thinkingOptions) {
378
339
  ? 'adaptive'
379
340
  : 'legacy';
380
341
  }
381
- export function buildProviderOptions(connection, modelId, thinkingLevel) {
382
- return withParallelToolCallOptions(connection, modelId, buildThinkingProviderOptions(connection, modelId, thinkingLevel));
342
+ export function buildProviderOptions(connection, modelId, thinkingLevel, runtime = resolveModelRuntime(connection, modelId)) {
343
+ return withParallelToolCallOptions(connection, modelId, buildThinkingProviderOptions(connection, modelId, thinkingLevel, runtime), runtime);
383
344
  }
384
- function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
345
+ function buildThinkingProviderOptions(connection, modelId, thinkingLevel, runtime = resolveModelRuntime(connection, modelId)) {
385
346
  const thinkingOptions = thinkingOptionsForModel(connection.providerType, modelId);
386
347
  const level = resolveThinkingLevel(connection, modelId, thinkingLevel);
387
348
  switch (connection.providerType) {
@@ -396,7 +357,7 @@ function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
396
357
  if (thinkingLevel === 'off')
397
358
  return {};
398
359
  const effort = level ?? 'max';
399
- if (connection.models?.find((model) => model.id === modelId)?.apiProtocol === 'openai-chat') {
360
+ if (runtime.wire === 'openai-chat') {
400
361
  // The kimiCodingPlan provider-options namespace is the
401
362
  // openai-compatible adapter name; ai-sdk resolves its camelCase
402
363
  // alias to the kimi-coding-plan schema key (reasoning_effort).
@@ -471,7 +432,7 @@ function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
471
432
  };
472
433
  }
473
434
  case 'openai': {
474
- const usesResponses = resolveModelRuntime(connection, modelId).wire === 'openai-responses';
435
+ const usesResponses = runtime.wire === 'openai-responses';
475
436
  const reasoningEffort = level === 'off'
476
437
  ? 'none'
477
438
  : (level ??
@@ -493,9 +454,7 @@ function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
493
454
  };
494
455
  case 'xai':
495
456
  case 'xai-oauth':
496
- // Only grok-4.5 needs the Responses reasoning extras; every other xAI
497
- // model serves the plain OpenAI-compatible chat wire handled below.
498
- if (modelId === 'grok-4.5') {
457
+ if (runtime.wire === 'openai-responses') {
499
458
  return {
500
459
  openai: {
501
460
  store: false,
@@ -506,7 +465,7 @@ function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
506
465
  },
507
466
  };
508
467
  }
509
- return buildFamilyWire(connection, modelId, level, thinkingOptions, thinkingLevel);
468
+ return buildFamilyWire(connection, modelId, level, thinkingOptions, thinkingLevel, runtime);
510
469
  case 'volcengine-ark':
511
470
  return {
512
471
  [toCamelCase(connection.providerType)]: {
@@ -550,11 +509,10 @@ function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
550
509
  // above (level is defined only when metadata declares it) is what makes
551
510
  // this safe to generalize: undeclared models never reach the wire.
552
511
  default:
553
- return buildFamilyWire(connection, modelId, level, thinkingOptions, thinkingLevel);
512
+ return buildFamilyWire(connection, modelId, level, thinkingOptions, thinkingLevel, runtime);
554
513
  }
555
514
  }
556
- function withParallelToolCallOptions(connection, modelId, options) {
557
- const runtime = resolveModelRuntime(connection, modelId);
515
+ function withParallelToolCallOptions(connection, modelId, options, runtime) {
558
516
  if (runtime.parallelToolCalls === undefined)
559
517
  return options;
560
518
  let providerKey;
@@ -563,16 +521,9 @@ function withParallelToolCallOptions(connection, modelId, options) {
563
521
  providerKey = 'openai';
564
522
  optionKey = 'parallelToolCalls';
565
523
  }
566
- else if (runtime.adapter.kind === 'github-copilot') {
567
- if (runtime.wire === 'anthropic-messages')
568
- return options;
569
- providerKey = runtime.wire === 'openai-responses' ? 'openai' : 'githubCopilot';
570
- optionKey = runtime.wire === 'openai-responses' ? 'parallelToolCalls' : 'parallel_tool_calls';
571
- }
572
524
  else if (runtime.adapter.kind === 'openai-compatible') {
573
525
  if (runtime.wire === 'openai-responses') {
574
- if (runtime.reasoningReplay.kind !== 'responses' ||
575
- runtime.reasoningReplay.contract.adapter !== 'openai') {
526
+ if (runtime.reasoningReplay.contract.adapter !== 'openai') {
576
527
  return options;
577
528
  }
578
529
  providerKey = 'openai';
@@ -595,8 +546,8 @@ function withParallelToolCallOptions(connection, modelId, options) {
595
546
  },
596
547
  };
597
548
  }
598
- function buildFamilyWire(connection, modelId, level, thinkingOptions, requestedLevel) {
599
- const { adapter, wire, reasoningReplay } = resolveModelRuntime(connection, modelId);
549
+ function buildFamilyWire(connection, modelId, level, thinkingOptions, requestedLevel, runtime) {
550
+ const { adapter, wire, reasoningReplay } = runtime;
600
551
  const explicitReasoningEffort = level ? (level === 'off' ? 'none' : level) : undefined;
601
552
  const serviceTier = wire === 'openai-responses' &&
602
553
  reasoningReplay.kind === 'responses' &&
@@ -609,9 +560,6 @@ function buildFamilyWire(connection, modelId, level, thinkingOptions, requestedL
609
560
  // consumes a provider-native reasoningEffort through the same namespace,
610
561
  // keyed by the provider name getAIModel passes to createOpenResponses.
611
562
  if (wire === 'openai-responses') {
612
- if (reasoningReplay.kind !== 'responses') {
613
- throw new Error('Responses wire requires a Responses continuation contract');
614
- }
615
563
  // Connection-aware: a relay model's declared variants count too.
616
564
  const reasons = thinkingVariantsForConnection(connection, modelId).length > 0;
617
565
  if (reasoningReplay.contract.adapter === 'open-responses') {
@@ -687,16 +635,6 @@ function buildFamilyWire(connection, modelId, level, thinkingOptions, requestedL
687
635
  ? { thinking: { type: 'disabled' } }
688
636
  : {},
689
637
  };
690
- case 'github-copilot': {
691
- // Copilot routes per account-declared model protocol (mirrors the
692
- // getAIModel case), defaulting to its OpenAI-compatible chat wire. Its
693
- // Responses protocol is answered by the wire branch above.
694
- const copilotProtocol = connection.models?.find((model) => model.id === modelId)?.apiProtocol;
695
- if (copilotProtocol === 'anthropic-messages') {
696
- return level !== 'off' ? { anthropic: { effort: level } } : {};
697
- }
698
- return { githubCopilot: { reasoningEffort: explicitReasoningEffort } };
699
- }
700
638
  default:
701
639
  return {};
702
640
  }
@@ -149,6 +149,13 @@ async function fetchProviderModelsStrict(connection, apiKey, fetchFn) {
149
149
  .filter((model) => discovery.filter !== 'language-models' || model.type === 'language')
150
150
  .map(toModelInfo)
151
151
  .filter((model) => model !== null);
152
+ if (discovery.modelProtocols === 'commandcode') {
153
+ for (const model of models) {
154
+ if (/^(?:anthropic\/)?claude-/i.test(model.id)) {
155
+ model.apiProtocol = 'anthropic-messages';
156
+ }
157
+ }
158
+ }
152
159
  return filterDiscoveredModels(models, discovery.filter);
153
160
  }
154
161
  case 'google': {
@@ -250,6 +257,12 @@ function normalizeConnectionEffectModels(models) {
250
257
  });
251
258
  }
252
259
  }
260
+ export class GitHubCopilotModelPolicyError extends Error {
261
+ constructor() {
262
+ super('GitHub Copilot model policy is not enabled');
263
+ this.name = 'GitHubCopilotModelPolicyError';
264
+ }
265
+ }
253
266
  export async function fetchGitHubCopilotModels(baseUrl, accessToken, fetchFn) {
254
267
  const response = await fetchForConnectionEffect(fetchFn, `${stripTrailing(baseUrl)}/models`, {
255
268
  headers: {
@@ -265,7 +278,12 @@ export async function fetchGitHubCopilotModels(baseUrl, accessToken, fetchFn) {
265
278
  throw new ConnectionEffectHttpError(response.status);
266
279
  }
267
280
  const payload = await readProviderJson(response);
268
- return providerObjectArray(payload.data, 'GitHub Copilot models', true).flatMap(toGitHubCopilotModelInfo);
281
+ const rawModels = providerObjectArray(payload.data, 'GitHub Copilot models', true);
282
+ const models = rawModels.flatMap(toGitHubCopilotModelInfo);
283
+ if (models.length === 0 && rawModels.some(isGitHubCopilotModelBlockedByPolicy)) {
284
+ throw new GitHubCopilotModelPolicyError();
285
+ }
286
+ return models;
269
287
  }
270
288
  /**
271
289
  * Discovery error carrying the HTTP status, so callers (syncOpenAiCodexConnection)
@@ -340,7 +358,12 @@ function toGitHubCopilotModelInfo(model) {
340
358
  if (typeof model.id !== 'string' ||
341
359
  !model.id ||
342
360
  model.model_picker_enabled !== true ||
343
- model.policy?.state === 'disabled' ||
361
+ // GitHub historically returned enabled/disabled/unconfigured policy gates.
362
+ // A policy-free model needs no acknowledgement; when the gate is present,
363
+ // Maka can use the model only after another client has enabled it. Maka has
364
+ // no policy-acceptance flow, so fail closed over unconfigured and unknown
365
+ // states instead of advertising a model that inference will reject.
366
+ !isGitHubCopilotModelPolicyEnabled(model.policy) ||
344
367
  model.capabilities?.supports?.tool_calls !== true)
345
368
  return [];
346
369
  assertOptionalArray(model.supported_endpoints, 'model supported_endpoints');
@@ -378,6 +401,28 @@ function toGitHubCopilotModelInfo(model) {
378
401
  },
379
402
  ];
380
403
  }
404
+ function isGitHubCopilotModelPolicyEnabled(policy) {
405
+ if (policy === undefined)
406
+ return true;
407
+ if (!policy || typeof policy !== 'object' || Array.isArray(policy))
408
+ return false;
409
+ return policy.state === 'enabled';
410
+ }
411
+ function isGitHubCopilotModelBlockedByPolicy(model) {
412
+ if (typeof model.id !== 'string' ||
413
+ !model.id ||
414
+ model.model_picker_enabled !== true ||
415
+ model.capabilities?.supports?.tool_calls !== true ||
416
+ !Array.isArray(model.supported_endpoints) ||
417
+ !model.supported_endpoints.some((endpoint) => ['/v1/messages', '/responses', '/chat/completions'].includes(endpoint))) {
418
+ return false;
419
+ }
420
+ if (!model.policy || typeof model.policy !== 'object' || Array.isArray(model.policy)) {
421
+ return false;
422
+ }
423
+ const state = model.policy.state;
424
+ return state === 'disabled' || state === 'unconfigured';
425
+ }
381
426
  async function fetchCohereModels(baseUrl, apiKey, fetchFn) {
382
427
  const root = stripTrailing(baseUrl).replace(/\/v2$/, '');
383
428
  const models = [];
@@ -648,6 +693,8 @@ function nextProviderPageToken(value) {
648
693
  return value;
649
694
  }
650
695
  function classifyDiscoveryError(error) {
696
+ if (error instanceof GitHubCopilotModelPolicyError)
697
+ return { kind: 'auth' };
651
698
  if (error instanceof ConnectionEffectFetchError)
652
699
  return { kind: error.kind };
653
700
  if (error instanceof ConnectionEffectHttpError) {
@@ -278,56 +278,6 @@ export function buildRuntimeEventReplayTimeline(items) {
278
278
  function replayToolIdentity(invocationId, toolCallId) {
279
279
  return JSON.stringify([invocationId, toolCallId]);
280
280
  }
281
- // ============================================================================
282
- // Projection
283
- // ============================================================================
284
- /**
285
- * Build the model-visible history from a RuntimeEvent stream.
286
- *
287
- * Events SHOULD be supplied in causal order; the projection preserves
288
- * input order. Partial events are always excluded — callers MUST NOT
289
- * replay transient streaming chunks into the next model call.
290
- *
291
- * The default options match the durable-history policy: user/model text
292
- * and tool calls/responses are kept; thinking, system notes, token usage,
293
- * permission acks, and diagnostics are dropped.
294
- */
295
- export function buildModelHistoryFromRuntimeEvents(events, options = {}) {
296
- const includeToolEvents = options.includeToolEvents ?? true;
297
- const includeSystemEvents = options.includeSystemEvents ?? false;
298
- const includeThinking = options.includeThinking ?? false;
299
- const out = [];
300
- for (const event of events) {
301
- // 1. Never replay transient streaming chunks.
302
- if (isPartialRuntimeEvent(event))
303
- continue;
304
- // 2. Only model-visible content kinds (text/thinking/function_*).
305
- if (!runtimeEventHasModelVisibleContent(event))
306
- continue;
307
- const content = event.content;
308
- if (!content)
309
- continue;
310
- // 3. System-role events are UI notes by default; opt in for
311
- // model-injected system instructions.
312
- if (event.role === 'system' && !includeSystemEvents)
313
- continue;
314
- // 4. Thinking replay is provider-specific; opt in.
315
- if (content.kind === 'thinking' && !includeThinking)
316
- continue;
317
- // 5. Tool function_call / function_response; opt out for text-only.
318
- if (!includeToolEvents &&
319
- (content.kind === 'function_call' || content.kind === 'function_response')) {
320
- continue;
321
- }
322
- out.push({
323
- role: event.role,
324
- content,
325
- ts: event.ts,
326
- eventId: event.id,
327
- });
328
- }
329
- return out;
330
- }
331
281
  /**
332
282
  * Collect the turn ids that contain tool activity (function_call /
333
283
  * function_response) from a RuntimeEvent ledger. Pass the result as
@@ -645,46 +595,6 @@ export function buildRuntimeEventModelReplayPlan(events, options = {}) {
645
595
  semanticKinds.includes('tool_result'),
646
596
  };
647
597
  }
648
- /**
649
- * Convert projected RuntimeEvent history into the current AI SDK text-only
650
- * message shape. Tool/function and thinking entries are intentionally skipped.
651
- */
652
- export function buildTextModelMessagesFromRuntimeEvents(events, options = {}) {
653
- const history = buildModelHistoryFromRuntimeEvents(events, {
654
- includeToolEvents: false,
655
- includeSystemEvents: options.includeSystemEvents ?? false,
656
- includeThinking: false,
657
- });
658
- const out = [];
659
- for (const entry of history) {
660
- if (entry.content.kind !== 'text')
661
- continue;
662
- if (entry.role === 'tool')
663
- continue;
664
- if (entry.role === 'system' && !options.includeSystemEvents)
665
- continue;
666
- const role = entry.role === 'model'
667
- ? 'assistant'
668
- : entry.role === 'user'
669
- ? 'user'
670
- : entry.role === 'system'
671
- ? 'system'
672
- : undefined;
673
- if (!role)
674
- continue;
675
- const steering = entry.content.steering === true && role === 'user';
676
- out.push({
677
- role,
678
- content: steering
679
- ? buildSteeringEnvelope(formatTextWithInlineRefs(entry.content))
680
- : formatTextWithInlineRefs(entry.content),
681
- // Keep the structured identity even in the text-only shape: dedupe
682
- // against the live injection set works by ledger event id.
683
- ...(steering ? { providerOptions: steeringProviderOptions(entry.eventId) } : {}),
684
- });
685
- }
686
- return out;
687
- }
688
598
  function modelTextRole(role) {
689
599
  switch (role) {
690
600
  case 'user':
@@ -770,28 +680,6 @@ export function steeringMessagesMissingFromBase(injected, baseMessages) {
770
680
  return eventId === undefined || !present.has(eventId);
771
681
  });
772
682
  }
773
- /**
774
- * The messages with THIS TURN'S injected steering removed (transport-retry
775
- * base). Only the injected set may be stripped: the retry attempt's own
776
- * request projection re-appends exactly that accumulator, while a historical,
777
- * ledger-replayed steering message (same marker, different event id) is part
778
- * of the base that nothing re-appends — stripping it would erase it from
779
- * every post-retry request.
780
- */
781
- export function stripSteeringMessages(messages, injected) {
782
- const ids = new Set();
783
- for (const message of injected) {
784
- const eventId = steeringEventIdOf(message);
785
- if (eventId !== undefined)
786
- ids.add(eventId);
787
- }
788
- if (ids.size === 0)
789
- return [...messages];
790
- return messages.filter((message) => {
791
- const eventId = steeringEventIdOf(message);
792
- return eventId === undefined || !ids.has(eventId);
793
- });
794
- }
795
683
  /**
796
684
  * Fold a user turn's inline references into its model-facing text. Attachments
797
685
  * render as a name/type block with exact Read instructions when the reference