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
@@ -17,6 +17,30 @@
17
17
  * under the License.
18
18
  */
19
19
  export const TUI_COPY_RESOURCES = {
20
+ copy: {
21
+ en: {
22
+ copiedLast: 'Sent the last reply to the terminal via OSC 52 · {count, plural, one {# char} other {# chars}} — it reaches the clipboard only if your terminal (and tmux, if used) allows OSC 52 writes.',
23
+ copiedAll: 'Sent the conversation to the terminal via OSC 52 · {count, plural, one {# char} other {# chars}} — it reaches the clipboard only if your terminal (and tmux, if used) allows OSC 52 writes.',
24
+ tooLarge: 'Too large to copy over OSC 52 · {bytes} bytes exceeds the {limit}-byte limit; a larger payload is silently dropped by the terminal.',
25
+ nothingToCopy: 'Nothing to copy yet.',
26
+ usage: 'Usage: /copy [all]',
27
+ roleUser: 'You:',
28
+ roleAssistant: 'Maka:',
29
+ roleGoalContinuation: 'Goal continuation (autonomous):',
30
+ roleLegacyAutomation: 'Legacy automation (history only):',
31
+ },
32
+ zh: {
33
+ copiedLast: '已将最后一条回复发送到终端 · {count} 个字符——仅当终端(以及 tmux,如使用)允许写入剪贴板时才会真正复制。',
34
+ copiedAll: '已将整段对话发送到终端 · {count} 个字符——仅当终端(以及 tmux,如使用)允许写入剪贴板时才会真正复制。',
35
+ tooLarge: '内容过大,无法复制 · {bytes} 字节超过 {limit} 字节上限;更大的内容会被终端静默丢弃。',
36
+ nothingToCopy: '暂无可复制的内容。',
37
+ usage: '用法:/copy [all]',
38
+ roleUser: '你:',
39
+ roleAssistant: 'Maka:',
40
+ roleGoalContinuation: '目标续跑(自主):',
41
+ roleLegacyAutomation: '旧版自动化(仅历史):',
42
+ },
43
+ },
20
44
  'mcp-status': {
21
45
  en: {
22
46
  title: 'MCP SERVERS',
@@ -54,6 +78,66 @@ export const TUI_COPY_RESOURCES = {
54
78
  configuredOnly: 'configured only',
55
79
  configPending: 'config pending',
56
80
  toolCount: '{count, plural, one {# tool} other {# tools}}',
81
+ editor: {
82
+ addTitle: 'Add MCP server',
83
+ transportTitle: 'Transport',
84
+ protocolTitle: 'Protocol preference',
85
+ confirmAddTitle: 'Add this MCP server?',
86
+ confirmImportTitle: 'Import MCP servers?',
87
+ confirmRemoveTitle: 'Remove {serverId}?',
88
+ confirmRemoveCredentialTitle: 'Remove the remote provider credential?',
89
+ confirmRemoveCredentialDetail: 'This stops publishing MCP tools to the selected Runtime Host.',
90
+ confirmHint: 'y Confirm · Esc cancel',
91
+ synchronizing: 'Configuration is synchronizing…',
92
+ outOfSync: 'Durable configuration and MCP Manager are out of sync.',
93
+ action: {
94
+ test: 'Testing MCP server…',
95
+ reconnect: 'Reconnecting MCP server…',
96
+ apply: 'Applying MCP configuration…',
97
+ },
98
+ inputLabels: {
99
+ server_id: 'Server ID',
100
+ command: 'Command',
101
+ args: 'Arguments',
102
+ url: 'Streamable HTTP URL',
103
+ cwd: 'Working directory',
104
+ env: 'Environment',
105
+ headers: 'Request headers',
106
+ edit: 'Edit server JSON',
107
+ import: 'Paste MCP JSON',
108
+ publication_credential: 'Provider credential',
109
+ },
110
+ hints: {
111
+ args: 'JSON string array, optional',
112
+ map: 'JSON string map, optional',
113
+ optional: 'optional',
114
+ submit: 'Enter submit · Esc back',
115
+ credential: 'Stored only in the local credential store; never written to profiles, arguments, or chat · Enter submit · Esc back',
116
+ },
117
+ results: {
118
+ exists: 'That server ID already exists.',
119
+ stale_config: 'MCP configuration changed; retry the action.',
120
+ stale_edit: 'This server changed; reopen it before editing.',
121
+ stale_import: 'An imported entry changed; preview the import again.',
122
+ missing: 'That server no longer exists.',
123
+ closed: 'The MCP controller is closed.',
124
+ 'invalid-config': 'The server configuration is invalid.',
125
+ 'credential-cleanup-failed': 'Stored credentials could not be removed; the configuration was not changed.',
126
+ 'publication-credential-failed': 'The provider credential could not be stored or applied.',
127
+ 'persist-failed': 'The configuration could not be saved.',
128
+ 'manager-failed': 'The MCP connection action failed.',
129
+ turn_active: 'MCP cannot be changed while a turn or another control action is running.',
130
+ invalid: 'Check the value and try again.',
131
+ published: 'Configuration saved and tools refreshed.',
132
+ pending_host: 'Configuration saved; publication is waiting for Runtime Host.',
133
+ sync_failed: 'Configuration saved, but the MCP manager is out of sync.',
134
+ publication_failed: 'Configuration saved, but capability publication failed.',
135
+ test_ok: 'Connection test passed.',
136
+ test_failed: 'Connection test failed.',
137
+ test_publication_failed: 'Connection test passed, but capability publication failed.',
138
+ test_pending_host: 'Connection test passed; publication is waiting for Runtime Host.',
139
+ },
140
+ },
57
141
  },
58
142
  zh: {
59
143
  title: 'MCP 服务器',
@@ -91,6 +175,66 @@ export const TUI_COPY_RESOURCES = {
91
175
  configuredOnly: '仅已配置',
92
176
  configPending: '配置待同步',
93
177
  toolCount: '{count} 个工具',
178
+ editor: {
179
+ addTitle: '添加 MCP 服务器',
180
+ transportTitle: '传输方式',
181
+ protocolTitle: '协议偏好',
182
+ confirmAddTitle: '添加该 MCP 服务器?',
183
+ confirmImportTitle: '导入 MCP 服务器?',
184
+ confirmRemoveTitle: '删除 {serverId}?',
185
+ confirmRemoveCredentialTitle: '删除远程 Provider 凭据?',
186
+ confirmRemoveCredentialDetail: '这会停止向所选 Runtime Host 发布 MCP 工具。',
187
+ confirmHint: 'y 确认 · Esc 取消',
188
+ synchronizing: '配置同步中…',
189
+ outOfSync: '持久化配置与 MCP Manager 尚未同步。',
190
+ action: {
191
+ test: '正在测试 MCP 服务器…',
192
+ reconnect: '正在重连 MCP 服务器…',
193
+ apply: '正在应用 MCP 配置…',
194
+ },
195
+ inputLabels: {
196
+ server_id: '服务器 ID',
197
+ command: '命令',
198
+ args: '参数',
199
+ url: 'Streamable HTTP URL',
200
+ cwd: '工作目录',
201
+ env: '环境变量',
202
+ headers: '请求头',
203
+ edit: '编辑服务器 JSON',
204
+ import: '粘贴 MCP JSON',
205
+ publication_credential: 'Provider 凭据',
206
+ },
207
+ hints: {
208
+ args: 'JSON string array, 可留空',
209
+ map: 'JSON string map, 可留空',
210
+ optional: '可留空',
211
+ submit: 'Enter 提交 · Esc 返回',
212
+ credential: '仅保存到本机凭据存储;不会写入 profile、参数或对话 · Enter 提交 · Esc 返回',
213
+ },
214
+ results: {
215
+ exists: '该服务器 ID 已存在。',
216
+ stale_config: 'MCP 配置已变化,请重试。',
217
+ stale_edit: '该服务器已变化,请重新打开后编辑。',
218
+ stale_import: '导入项已变化,请重新预览。',
219
+ missing: '该服务器已不存在。',
220
+ closed: 'MCP 控制器已关闭。',
221
+ 'invalid-config': '服务器配置无效。',
222
+ 'credential-cleanup-failed': '无法删除旧凭据,配置未修改。',
223
+ 'publication-credential-failed': '无法保存或应用 Provider 凭据。',
224
+ 'persist-failed': '无法保存配置。',
225
+ 'manager-failed': 'MCP 连接操作失败。',
226
+ turn_active: 'Turn 或其他控制操作运行期间不能修改 MCP。',
227
+ invalid: '请检查输入后重试。',
228
+ published: '配置已保存,工具已刷新。',
229
+ pending_host: '配置已保存,正等待 Runtime Host 发布。',
230
+ sync_failed: '配置已保存,但 MCP Manager 尚未同步。',
231
+ publication_failed: '配置已保存,但 capability 发布失败。',
232
+ test_ok: '连接测试通过。',
233
+ test_failed: '连接测试失败。',
234
+ test_publication_failed: '连接测试通过,但 capability 发布失败。',
235
+ test_pending_host: '连接测试通过,正等待 Runtime Host 发布。',
236
+ },
237
+ },
94
238
  },
95
239
  },
96
240
  pickers: {
@@ -267,6 +411,7 @@ export const TUI_COPY_RESOURCES = {
267
411
  commands: {
268
412
  compact: 'Compact session context',
269
413
  context: 'Show latest request context usage',
414
+ copy: 'Copy the last reply (or /copy all) to the clipboard',
270
415
  exit: 'Exit Maka',
271
416
  goal: 'Show autonomous goal status',
272
417
  graph: 'Show, enable, disable, or run one Graph turn',
@@ -317,6 +462,7 @@ export const TUI_COPY_RESOURCES = {
317
462
  commands: {
318
463
  compact: '压缩会话上下文',
319
464
  context: '查看最近一次请求的上下文用量',
465
+ copy: '复制最后一条回复(或 /copy all)到剪贴板',
320
466
  exit: '退出 Maka',
321
467
  goal: '查看自主目标状态',
322
468
  graph: '查看、启用、停用 Graph 模式,或执行一次 Graph 任务',
@@ -357,6 +503,108 @@ export const TUI_COPY_RESOURCES = {
357
503
  },
358
504
  },
359
505
  },
506
+ rewind: {
507
+ en: {
508
+ pickerTitle: 'Rewind',
509
+ pending: 'Rewinding to before this turn…',
510
+ doneRefilled: 'Rewound to before this turn (branched into a new task; the original task is kept). The turn’s prompt was refilled into the input box — edit it and send again.',
511
+ doneKeptDraft: 'Rewound to before this turn (branched into a new task; the original task is kept). The input box already had unsent content and was left untouched; the turn’s prompt was saved to input history — press ↑ to recall it.',
512
+ noTargets: 'No turns to rewind to.',
513
+ busy: 'Cannot rewind: another action is in progress — wait for it to finish, or interrupt (Esc) and retry.',
514
+ pickerHint: 'Return to before the selected turn (discards it and later turns; the prompt refills the input box) · enter select / esc cancel',
515
+ },
516
+ zh: {
517
+ pickerTitle: '回退',
518
+ pending: '正在回退到该轮之前…',
519
+ doneRefilled: '已回退到该轮之前(分支为新任务,原任务保留),该轮 prompt 已回填输入框,可修改后重新发送。',
520
+ doneKeptDraft: '已回退到该轮之前(分支为新任务,原任务保留)。输入框已有未发送内容,未覆盖;该轮 prompt 已存入输入历史,可按 ↑ 找回。',
521
+ noTargets: '没有可回退的轮次。',
522
+ busy: '无法回退:当前有正在进行的操作 — 请等待其完成,或中断(Esc)后重试。',
523
+ pickerHint: '回到选定轮次之前(丢弃该轮及之后,prompt 回填输入框) · enter 选择 / esc 取消',
524
+ },
525
+ },
526
+ skills: {
527
+ en: {
528
+ pickerTitle: 'Invoke Skill',
529
+ usage: 'Usage: /skill, or type /skill:<name> inline in a message',
530
+ noneAvailable: 'No skills are available to invoke right now.',
531
+ loaded: 'Skills loaded: {names}',
532
+ loadFailed: 'Could not load skills {failures}; {outcome}',
533
+ outcomeNoRequest: 'no model request was made.',
534
+ outcomeMarkersNotSent: 'the failed invocation markers were not sent to the model.',
535
+ failedItem: '/skill:{request} ({reason})',
536
+ tooManyRequestsItem: 'more than the {limit}-request limit ({reason})',
537
+ listSeparator: ', ',
538
+ failureReasons: {
539
+ invalid_name: 'invalid name',
540
+ not_found: 'not found',
541
+ disabled: 'disabled',
542
+ host_incompatible: 'the current host is missing a tool it depends on',
543
+ resolution_failed: 'resolution failed',
544
+ too_many_requests: 'too many requests',
545
+ },
546
+ },
547
+ zh: {
548
+ pickerTitle: '调用技能',
549
+ usage: 'Usage: /skill,或直接在消息中输入 /skill:<name>',
550
+ noneAvailable: '当前没有可调用的技能。',
551
+ loaded: '已加载技能:{names}',
552
+ loadFailed: '未能加载技能 {failures};{outcome}',
553
+ outcomeNoRequest: '未发起模型请求。',
554
+ outcomeMarkersNotSent: '失败的调用标记未发送给模型。',
555
+ failedItem: '/skill:{request}({reason})',
556
+ tooManyRequestsItem: '请求超过 {limit} 个上限({reason})',
557
+ listSeparator: '、',
558
+ failureReasons: {
559
+ invalid_name: '名称无效',
560
+ not_found: '未找到',
561
+ disabled: '已禁用',
562
+ host_incompatible: '当前主机缺少其依赖的工具',
563
+ resolution_failed: '解析失败',
564
+ too_many_requests: '调用请求过多',
565
+ },
566
+ },
567
+ },
568
+ 'connection-identity': {
569
+ en: {
570
+ withRecovery: '{notice} {recovery}',
571
+ emptyChoiceRecovery: 'If /model has no choices, add or enable a connection first (run /setup for API-key connections).',
572
+ confirmAccount: 'This task comes from an older version and needs a one-time account confirmation. Run /model and choose an existing account and model.',
573
+ accountDeleted: 'The original account was deleted. Run /model and choose a new account and model to continue.',
574
+ identityMismatch: 'The saved account identity no longer matches its connection. Run /model and choose an account and model again.',
575
+ accountDisabled: 'The original account is disabled. Enable it, or run /model and choose a new account and model.',
576
+ },
577
+ zh: {
578
+ withRecovery: '{notice}{recovery}',
579
+ emptyChoiceRecovery: '如果 /model 没有可选项,请先添加或启用连接(API Key 连接可运行 /setup)。',
580
+ confirmAccount: '此任务来自旧版本,需要确认一次账号。运行 /model 选择现有账号和模型。',
581
+ accountDeleted: '原账号已删除;运行 /model 选择新账号和模型后继续。',
582
+ identityMismatch: '任务保存的账号身份与当前连接不一致;运行 /model 重新选择账号和模型。',
583
+ accountDisabled: '原账号已停用;请启用该账号,或运行 /model 选择新账号和模型。',
584
+ },
585
+ },
586
+ 'session-actions': {
587
+ en: {
588
+ foreignScanFailed: 'Could not read external conversations: {detail}',
589
+ newSessionFailed: 'Could not start a new session: a local command could not be stopped. Press Ctrl+C to stop it, then try again.',
590
+ },
591
+ zh: {
592
+ foreignScanFailed: '读取外部对话失败:{detail}',
593
+ newSessionFailed: '无法开始新会话:无法停止本地命令。请按 Ctrl+C 停止命令后重试。',
594
+ },
595
+ },
596
+ 'pending-queue': {
597
+ en: {
598
+ steeringLabel: 'Steering:',
599
+ queuedLabel: 'Queued:',
600
+ requeueHint: 'Alt+↑ take queued messages back to re-edit',
601
+ },
602
+ zh: {
603
+ steeringLabel: '注入:',
604
+ queuedLabel: '已排队:',
605
+ requeueHint: 'Alt+↑ 取回队列以重新编辑',
606
+ },
607
+ },
360
608
  'session-status': {
361
609
  en: {
362
610
  running: 'running',
@@ -0,0 +1,103 @@
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
+ /**
20
+ * Text extraction and localized copy for the `/copy` slash command.
21
+ *
22
+ * The transcript's user/assistant entries already hold plain markdown text (no
23
+ * ANSI), so copy pulls straight from `state.entries` rather than stripping the
24
+ * rendered projection. See `MakaPiTranscriptEntry` in `pi-transcript.ts`.
25
+ */
26
+ import { defineUiMessageCatalog, resolveUiMessageCatalog, } from '@maka/core/ui-locale';
27
+ import { TUI_COPY_RESOURCES } from './tui-copy-catalog.js';
28
+ const TUI_COPY_COMMAND_COPY = resolveUiMessageCatalog(defineUiMessageCatalog()(TUI_COPY_RESOURCES.copy));
29
+ export function getTuiCopyCopy(locale) {
30
+ return TUI_COPY_COMMAND_COPY[locale];
31
+ }
32
+ /**
33
+ * The last assistant reply's plain text, or undefined if there is none yet.
34
+ *
35
+ * Empty assistant entries are skipped: a tool-only or aborted turn — and
36
+ * durable recovery, which materializes an assistant entry per stored message
37
+ * regardless of text — can leave a text-less entry at the tail that would
38
+ * otherwise mask an earlier real reply.
39
+ */
40
+ export function lastAssistantText(state) {
41
+ for (let i = state.entries.length - 1; i >= 0; i -= 1) {
42
+ const entry = state.entries[i];
43
+ if (entry?.kind === 'assistant' && entry.text.trim() !== '')
44
+ return entry.text;
45
+ }
46
+ return undefined;
47
+ }
48
+ /**
49
+ * Serialize the whole conversation to plain text with role labels, in order.
50
+ * Thinking, tool calls, and notices are omitted so the copy reads as the
51
+ * conversation, not the machinery around it.
52
+ *
53
+ * `goal_continuation` and `legacy_automation` are non-user-triggered driving
54
+ * turns (see `TurnOrigin` in `turn-origin.ts`) that the TUI renders with their
55
+ * own provenance headers, so they carry distinct labels here rather than the
56
+ * user label: relabeling them `You:` would misattribute autonomous prompts to
57
+ * the human, and dropping them would both erase the prompts that drove a run and
58
+ * merge the assistant turns on either side into one answer.
59
+ *
60
+ * Only *consecutive assistant* entries collapse under one label, so an assistant
61
+ * turn whose text is split across several internal steps (e.g. text before and
62
+ * after a tool call) reads as one `Maka:` block. Every non-assistant turn opens
63
+ * its own block — two queued user messages, or two turns separated only by a
64
+ * skipped text-less assistant entry, must not merge. Empty assistant steps are
65
+ * dropped, and because a new block only ever opens for a non-assistant turn or a
66
+ * fresh assistant run, that skip never joins the blocks around it.
67
+ */
68
+ export function serializeTranscriptText(state, labels) {
69
+ const blocks = [];
70
+ for (const entry of state.entries) {
71
+ let role;
72
+ let label;
73
+ switch (entry.kind) {
74
+ case 'user':
75
+ role = 'user';
76
+ label = labels.user;
77
+ break;
78
+ case 'goal_continuation':
79
+ role = 'goal_continuation';
80
+ label = labels.goalContinuation;
81
+ break;
82
+ case 'legacy_automation':
83
+ role = 'legacy_automation';
84
+ label = labels.legacyAutomation;
85
+ break;
86
+ case 'assistant':
87
+ if (entry.text.trim() === '')
88
+ continue;
89
+ role = 'assistant';
90
+ label = labels.assistant;
91
+ break;
92
+ default:
93
+ continue;
94
+ }
95
+ const last = blocks[blocks.length - 1];
96
+ // Collapse only a running assistant turn's steps; every other turn is its own.
97
+ if (role === 'assistant' && last?.role === 'assistant')
98
+ last.text += `\n\n${entry.text}`;
99
+ else
100
+ blocks.push({ role, label, text: entry.text });
101
+ }
102
+ return blocks.map((block) => `${block.label}\n${block.text}`).join('\n\n');
103
+ }
@@ -61,6 +61,18 @@ export const MAX_ATTACHMENT_BYTES = 50 * 1024 * 1024;
61
61
  export const MAX_READ_IMAGE_BYTES = 5 * 1024 * 1024;
62
62
  export const MAX_MODEL_IMAGE_EDGE = 2000;
63
63
  export const READ_IMAGE_TOO_LARGE_MESSAGE = `Image exceeds the ${MAX_READ_IMAGE_BYTES / 1024 / 1024}MB model input limit; downscale it and try again.`;
64
+ /**
65
+ * What one image costs the request once materialization rehydrates it.
66
+ *
67
+ * A flat per-modality constant, because no character count answers this: both
68
+ * an artifact part and a legacy image result reduce to a one-line reference,
69
+ * and providers price an image by the area they resize it to. It sits above
70
+ * Anthropic's ~1,600-token ceiling for an image up to 1.15 megapixels and in
71
+ * the same range as the constants other agents use (opencode 1,500, Codex
72
+ * 1,844). Erring high is the safe direction: every consumer is reversible, so
73
+ * the worst an over-count buys is one compaction that was not needed.
74
+ */
75
+ export const MATERIALIZED_IMAGE_TOKENS = 2_000;
64
76
  /** Leaves room for Base64 expansion, text, and tool schemas under provider request limits. */
65
77
  export const MAX_PROVIDER_IMAGE_REQUEST_BYTES = 12 * 1024 * 1024;
66
78
  export const PROVIDER_IMAGE_BUDGET_EXCEEDED_MESSAGE = `Image was read, but the per-request image budget (${MAX_PROVIDER_IMAGE_REQUEST_BYTES / 1024 / 1024}MB across all images this turn) was exceeded; earlier images were sent and this one was omitted. Read fewer or smaller images.`;
@@ -70,7 +82,6 @@ const MIME_BY_EXTENSION = {
70
82
  jpeg: 'image/jpeg',
71
83
  gif: 'image/gif',
72
84
  webp: 'image/webp',
73
- bmp: 'image/bmp',
74
85
  pdf: 'application/pdf',
75
86
  docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
76
87
  xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
@@ -79,6 +90,62 @@ const MIME_BY_EXTENSION = {
79
90
  xls: 'application/vnd.ms-excel',
80
91
  ppt: 'application/vnd.ms-powerpoint',
81
92
  };
93
+ export const ATTACHMENT_MIME_SNIFF_BYTES = 16;
94
+ /**
95
+ * PDF permits arbitrary bytes before the `%PDF-` header and readers
96
+ * conventionally scan roughly the first kilobyte for it. Searching that window
97
+ * keeps a PDF with a preamble from sniffing as nothing — which downstream would
98
+ * otherwise decode as UTF-8 text — while staying bounded so sniffing never
99
+ * becomes an unbounded read. Only the PDF header needs it: image signatures are
100
+ * valid solely at their fixed offset within {@link ATTACHMENT_MIME_SNIFF_BYTES}.
101
+ */
102
+ export const PDF_HEADER_SCAN_BYTES = 1024;
103
+ /**
104
+ * Identify the attachment formats whose bytes affect how Maka processes them.
105
+ * Image signatures are read from the fixed {@link ATTACHMENT_MIME_SNIFF_BYTES}
106
+ * prefix at their required offset; the PDF header may sit behind a short
107
+ * preamble, so it is searched across the first {@link PDF_HEADER_SCAN_BYTES}.
108
+ * Both bounds are fixed, so callers can apply this before handing untrusted
109
+ * input to an image decoder without turning sniffing into an unbounded read.
110
+ */
111
+ export function sniffAttachmentMimeType(bytes) {
112
+ const prefix = bytes.subarray(0, ATTACHMENT_MIME_SNIFF_BYTES);
113
+ if (startsWithBytes(prefix, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) {
114
+ return 'image/png';
115
+ }
116
+ if (startsWithBytes(prefix, [0xff, 0xd8, 0xff]))
117
+ return 'image/jpeg';
118
+ if (startsWithAscii(prefix, 'GIF87a') || startsWithAscii(prefix, 'GIF89a'))
119
+ return 'image/gif';
120
+ if (startsWithAscii(prefix, 'RIFF') && startsWithAscii(prefix, 'WEBP', 8))
121
+ return 'image/webp';
122
+ if (containsAscii(bytes.subarray(0, PDF_HEADER_SCAN_BYTES), '%PDF-'))
123
+ return 'application/pdf';
124
+ return undefined;
125
+ }
126
+ function startsWithBytes(bytes, signature, offset = 0) {
127
+ return (bytes.length >= offset + signature.length &&
128
+ signature.every((value, index) => bytes[offset + index] === value));
129
+ }
130
+ function startsWithAscii(bytes, signature, offset = 0) {
131
+ if (bytes.length < offset + signature.length)
132
+ return false;
133
+ for (let index = 0; index < signature.length; index += 1) {
134
+ if (bytes[offset + index] !== signature.charCodeAt(index))
135
+ return false;
136
+ }
137
+ return true;
138
+ }
139
+ /** True if `signature` appears anywhere in `bytes` (bounded by the caller's
140
+ * slice), for headers a format allows to sit behind a preamble. */
141
+ function containsAscii(bytes, signature) {
142
+ const lastOffset = bytes.length - signature.length;
143
+ for (let offset = 0; offset <= lastOffset; offset += 1) {
144
+ if (startsWithAscii(bytes, signature, offset))
145
+ return true;
146
+ }
147
+ return false;
148
+ }
82
149
  /**
83
150
  * Best-effort MIME from a file name, used when the picker gives no MIME
84
151
  * (Electron's openDialog only returns paths). Falls back to
@@ -91,6 +158,30 @@ export function guessMimeFromName(fileName) {
91
158
  const ext = fileName.slice(dot + 1).toLowerCase();
92
159
  return MIME_BY_EXTENSION[ext] ?? 'application/octet-stream';
93
160
  }
161
+ /**
162
+ * Decide an attachment's MIME with content taking precedence over the name and
163
+ * any renderer-supplied MIME, so a spoofed extension cannot steer routing.
164
+ * Sniffed bytes win outright. When nothing sniffs, a *claimed* image/PDF MIME
165
+ * (from the name or the renderer) is downgraded to `application/octet-stream`
166
+ * so unverified bytes never enter the image or PDF path; any other claim is
167
+ * kept so genuine document kinds still resolve. `bytes` may be a prefix rather
168
+ * than the whole file: image signatures resolve from the
169
+ * {@link ATTACHMENT_MIME_SNIFF_BYTES} prefix, while a PDF header behind a
170
+ * preamble is only found within the first {@link PDF_HEADER_SCAN_BYTES} — the
171
+ * send path passes the full bytes, pick-time staging passes the short prefix.
172
+ */
173
+ export function resolveAttachmentMimeType(bytes, suppliedMimeType, fileName) {
174
+ const sniffed = sniffAttachmentMimeType(bytes);
175
+ if (sniffed)
176
+ return sniffed;
177
+ const fallback = suppliedMimeType && suppliedMimeType.length > 0
178
+ ? suppliedMimeType
179
+ : guessMimeFromName(fileName);
180
+ const normalized = fallback.toLowerCase();
181
+ return normalized.startsWith('image/') || normalized === 'application/pdf'
182
+ ? 'application/octet-stream'
183
+ : fallback;
184
+ }
94
185
  /**
95
186
  * Route a MIME type to an {@link AttachmentRef} kind. The runtime
96
187
  * consumption split is image vs. everything-else (images become provider
@@ -0,0 +1,71 @@
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
+ /**
20
+ * Reading a response body without letting the far end decide how much memory
21
+ * we spend. Every outbound fetch whose peer is not us belongs here.
22
+ *
23
+ * The bound is enforced twice because either check alone is a hole: the
24
+ * declared `content-length` refuses an oversized body before a byte arrives,
25
+ * and the running byte count refuses one that never declared a length or lied
26
+ * about it. Buffering first and measuring afterwards is not a bound at all,
27
+ * and `String.length` is not a byte count — a multi-byte body passes a limit
28
+ * it exceeds by up to three times.
29
+ */
30
+ export async function readBoundedResponseText(response, maxBytes, overflow) {
31
+ const contentLength = Number(response.headers.get('content-length'));
32
+ if (Number.isFinite(contentLength) && contentLength > maxBytes) {
33
+ await response.body?.cancel();
34
+ throw overflow();
35
+ }
36
+ if (!response.body)
37
+ return '';
38
+ const reader = response.body.getReader();
39
+ const decoder = responseTextDecoder(response);
40
+ let bytes = 0;
41
+ let text = '';
42
+ try {
43
+ while (true) {
44
+ const { done, value } = await reader.read();
45
+ if (done)
46
+ break;
47
+ bytes += value.byteLength;
48
+ if (bytes > maxBytes) {
49
+ await reader.cancel();
50
+ throw overflow();
51
+ }
52
+ text += decoder.decode(value, { stream: true });
53
+ }
54
+ return text + decoder.decode();
55
+ }
56
+ finally {
57
+ reader.releaseLock();
58
+ }
59
+ }
60
+ function responseTextDecoder(response) {
61
+ const contentType = response.headers.get('content-type') ?? '';
62
+ const charset = /(?:^|;)\s*charset\s*=\s*"?([^;"\s]+)/i.exec(contentType)?.[1];
63
+ if (!charset)
64
+ return new TextDecoder();
65
+ try {
66
+ return new TextDecoder(charset);
67
+ }
68
+ catch {
69
+ return new TextDecoder();
70
+ }
71
+ }
@@ -16,52 +16,27 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { normalizeOpenAiCodexConnection } from './connection-readiness.js';
20
- import { buildConnectionModelCatalogEntries } from './model-catalog.js';
21
- import { resolveModelVisionSupport } from './model-metadata.js';
22
- import { relayModelProfile, thinkingVariantsForConnection, } from './model-thinking.js';
23
- import { CODEX_SUBSCRIPTION_UNSUPPORTED_CHATGPT_MODELS, connectionEnabledModelIds, providerDefaultsOf, } from './llm-connections.js';
24
- const MODEL_MENU_PROVIDER_LABELS = {
25
- anthropic: 'Anthropic',
26
- openai: 'OpenAI',
27
- google: 'Google',
28
- deepseek: 'DeepSeek',
29
- moonshot: 'Moonshot',
30
- ollama: 'Ollama',
31
- 'kimi-coding-plan': 'Kimi',
32
- 'zai-coding-plan': 'Z.AI',
33
- MiniMax: 'MiniMax',
34
- 'openai-codex': 'OpenAI OAuth',
35
- };
19
+ import { offerableCatalogEntries, providerDefaultsOf, providerMenuLabel, } from './llm-connections.js';
36
20
  export function buildChatModelChoices(connections) {
37
21
  const choices = [];
38
- for (const rawConnection of connections) {
39
- const connection = normalizeOpenAiCodexConnection(rawConnection);
22
+ for (const connection of connections) {
40
23
  const provider = providerDefaultsOf(connection.providerType);
41
- if (!connection.enabled || !provider) {
24
+ if (!provider)
42
25
  continue;
43
- }
44
- const enabledModelIds = new Set(connectionEnabledModelIds(connection));
45
- for (const entry of buildConnectionModelCatalogEntries({ connection })) {
46
- if (!entry.canUseAsChatDefault ||
47
- !enabledModelIds.has(entry.id) ||
48
- (connection.providerType === 'openai-codex' &&
49
- CODEX_SUBSCRIPTION_UNSUPPORTED_CHATGPT_MODELS.has(entry.id.trim()))) {
50
- continue;
51
- }
26
+ for (const entry of offerableCatalogEntries(connection)) {
52
27
  choices.push({
53
- connectionId: rawConnection.connectionId,
28
+ connectionId: connection.connectionId,
54
29
  connectionSlug: connection.slug,
55
30
  providerType: connection.providerType,
56
- providerLabel: MODEL_MENU_PROVIDER_LABELS[connection.providerType] ?? provider.label,
31
+ providerLabel: providerMenuLabel(connection.providerType) ?? connection.providerType,
57
32
  model: entry.id,
58
33
  label: entry.displayName?.trim() || entry.id,
59
34
  ...(entry.description !== undefined ? { description: entry.description } : {}),
60
35
  ...(entry.knowledgeCutoff !== undefined ? { knowledgeCutoff: entry.knowledgeCutoff } : {}),
61
36
  ...(provider.authKind === 'oauth_token' ? {} : { connectionName: connection.name }),
62
37
  isDefault: entry.isDefault,
63
- thinkingLevels: thinkingVariantsForConnection(connection, entry.id),
64
- supportsVision: resolveModelVisionSupport(connection.providerType, connection.models, entry.id, relayModelProfile(connection, entry.id)?.vision),
38
+ thinkingLevels: entry.thinkingLevels,
39
+ supportsVision: entry.supportsVision,
65
40
  });
66
41
  }
67
42
  }