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

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 (166) 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/dist/cli-core.js +25 -1
  5. package/dist/mcp-capability-provider.js +1 -1
  6. package/dist/onboarding-catalog.js +3 -5
  7. package/dist/pi-transcript.js +21 -17
  8. package/dist/pi-tui-layout.js +4 -2
  9. package/dist/pi-tui-mcp-status.js +44 -130
  10. package/dist/pi-tui-pickers.js +11 -5
  11. package/dist/pi-tui-runner.js +133 -102
  12. package/dist/runtime-host-cli.js +150 -4
  13. package/dist/runtime-host-lifecycle-transaction.js +5 -2
  14. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  15. package/dist/runtime-host-onboarding.js +12 -16
  16. package/dist/runtime-host-peer-management-command.js +16 -4
  17. package/dist/runtime-host-plugin-command.js +101 -0
  18. package/dist/runtime-host-run-command.js +5 -1
  19. package/dist/runtime-host-service-management-command.js +2 -1
  20. package/dist/runtime-host-setup-command.js +1 -0
  21. package/dist/runtime-host-task-readiness.js +2 -3
  22. package/dist/runtime-host-tui-command.js +1 -1
  23. package/dist/runtime-host-tui-context.js +18 -5
  24. package/dist/runtime-host-update-command.js +13 -5
  25. package/dist/runtime-host-update-discovery.js +1 -0
  26. package/dist/tui-clipboard.js +86 -0
  27. package/dist/tui-copy-catalog.js +246 -0
  28. package/dist/tui-copy-command.js +103 -0
  29. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  30. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  31. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  32. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  33. package/node_modules/@maka/core/dist/attachments.js +80 -1
  34. package/node_modules/@maka/core/dist/bounded-response.js +71 -0
  35. package/node_modules/@maka/core/dist/chat-model-choice.js +8 -33
  36. package/node_modules/@maka/core/dist/client-capability-grant.js +149 -0
  37. package/node_modules/@maka/core/dist/connection-readiness.js +3 -31
  38. package/node_modules/@maka/core/dist/deep-research.js +1 -20
  39. package/node_modules/@maka/core/dist/events.js +22 -1
  40. package/node_modules/@maka/core/dist/foreign-session.js +2 -2
  41. package/node_modules/@maka/core/dist/interaction.js +49 -2
  42. package/node_modules/@maka/core/dist/llm-connections.js +74 -82
  43. package/node_modules/@maka/core/dist/model-catalog.js +221 -315
  44. package/node_modules/@maka/core/dist/model-facts.js +13 -19
  45. package/node_modules/@maka/core/dist/model-metadata.generated.js +1907 -1872
  46. package/node_modules/@maka/core/dist/model-metadata.js +184 -199
  47. package/node_modules/@maka/core/dist/model-thinking.js +1 -1
  48. package/node_modules/@maka/core/dist/models-dev-projection.js +302 -0
  49. package/node_modules/@maka/core/dist/models-dev-refresh.js +55 -0
  50. package/node_modules/@maka/core/dist/onboarding.js +2 -1
  51. package/node_modules/@maka/core/dist/provider-auth.js +47 -291
  52. package/node_modules/@maka/core/dist/provider-registry.js +68 -357
  53. package/node_modules/@maka/core/dist/runtime-event.js +4 -0
  54. package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +34 -18
  55. package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +75 -0
  56. package/node_modules/@maka/core/dist/runtime-policy.js +2 -1
  57. package/node_modules/@maka/core/dist/session-send-projection.js +2 -1
  58. package/node_modules/@maka/core/dist/session-start-mode.js +42 -0
  59. package/node_modules/@maka/core/dist/session.js +119 -5
  60. package/node_modules/@maka/core/dist/slash-command-catalog.js +1 -0
  61. package/node_modules/@maka/core/dist/task-submission-readiness.js +2 -1
  62. package/node_modules/@maka/core/dist/workhub-creation-intent.js +896 -0
  63. package/node_modules/@maka/core/package.json +6 -1
  64. package/node_modules/@maka/runtime/dist/agent-run.js +7 -0
  65. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +3 -2
  66. package/node_modules/@maka/runtime/dist/image-file.js +5 -20
  67. package/node_modules/@maka/runtime/dist/local-web-fetch.js +2 -43
  68. package/node_modules/@maka/runtime/dist/mcp-tools.js +28 -0
  69. package/node_modules/@maka/runtime/dist/model-fetcher.js +15 -8
  70. package/node_modules/@maka/runtime/dist/model-history.js +18 -1
  71. package/node_modules/@maka/runtime/dist/model-runtime.js +2 -2
  72. package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +173 -20
  73. package/node_modules/@maka/runtime/dist/plugin-runtime.js +219 -0
  74. package/node_modules/@maka/runtime/dist/quiescent-session-snapshot.js +78 -0
  75. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +3 -0
  76. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +1 -0
  77. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +8 -4
  78. package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +93 -83
  79. package/node_modules/@maka/runtime/dist/test-connection.js +6 -6
  80. package/node_modules/@maka/runtime/dist/tool-runtime.js +50 -6
  81. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +39 -16
  82. package/node_modules/@maka/runtime/package.json +1 -0
  83. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +10 -0
  84. package/node_modules/@maka/runtime-host/dist/client/catalog-reader.js +19 -5
  85. package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +3 -2
  86. package/node_modules/@maka/runtime-host/dist/client/connection.js +22 -0
  87. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +1 -0
  88. package/node_modules/@maka/runtime-host/dist/client/index.js +1 -0
  89. package/node_modules/@maka/runtime-host/dist/client/oauth-presentation.js +1 -1
  90. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +4 -0
  91. package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +8 -0
  92. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  93. package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +2 -0
  94. package/node_modules/@maka/runtime-host/dist/operator/peer-management-frame.js +2 -0
  95. package/node_modules/@maka/runtime-host/dist/operator/service-management-frame.js +2 -0
  96. package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +1 -0
  97. package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +22 -1
  98. package/node_modules/@maka/{storage/dist/task-ledger-store-internal.js → runtime-host/dist/protocol/connection-catalog-change.js} +7 -13
  99. package/node_modules/@maka/runtime-host/dist/protocol/index.js +33 -1
  100. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +3 -1
  101. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +512 -0
  102. package/node_modules/@maka/runtime-host/dist/protocol/runtime-policy.js +25 -61
  103. package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
  104. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +4 -1
  105. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +92 -4
  106. package/node_modules/@maka/runtime-host/dist/server/access-authority.js +15 -13
  107. package/node_modules/@maka/runtime-host/dist/server/access-credential-metadata.js +4 -2
  108. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +119 -47
  109. package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +10 -4
  110. package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +192 -18
  111. package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +122 -48
  112. package/node_modules/@maka/runtime-host/dist/server/client-capability-provider-id.js +31 -0
  113. package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +5 -5
  114. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +1 -0
  115. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +117 -4
  116. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +2 -2
  117. package/node_modules/@maka/runtime-host/dist/server/extension-bundle.js +249 -0
  118. package/node_modules/@maka/runtime-host/dist/server/extension-package-manifest.js +262 -0
  119. package/node_modules/@maka/runtime-host/dist/server/host-change-feed.js +11 -0
  120. package/node_modules/@maka/runtime-host/dist/server/index.js +5 -0
  121. package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +181 -13
  122. package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +6 -0
  123. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +88 -22
  124. package/node_modules/@maka/runtime-host/dist/server/model-metadata-refresh.js +96 -0
  125. package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +43 -118
  126. package/node_modules/@maka/runtime-host/dist/server/plugin-composition-patch.js +58 -0
  127. package/node_modules/@maka/runtime-host/dist/server/plugin-composition-store.js +141 -0
  128. package/node_modules/@maka/runtime-host/dist/server/plugin-package-loader.js +130 -0
  129. package/node_modules/@maka/runtime-host/dist/server/plugin-package-store.js +528 -0
  130. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +249 -0
  131. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +1130 -0
  132. package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +4 -0
  133. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +24 -5
  134. package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +29 -4
  135. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +2 -1
  136. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +10 -2
  137. package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +1 -1
  138. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +276 -3
  139. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +101 -1
  140. package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +1 -0
  141. package/node_modules/@maka/runtime-host/dist/webrtc-stun-policy.js +114 -0
  142. package/node_modules/@maka/runtime-host/package.json +2 -0
  143. package/node_modules/@maka/storage/dist/agent-run-store.js +4 -0
  144. package/node_modules/@maka/storage/dist/artifact-store.js +7 -23
  145. package/node_modules/@maka/storage/dist/conversation-operational-state.js +3 -0
  146. package/node_modules/@maka/storage/dist/execution-stores.js +3 -0
  147. package/node_modules/@maka/storage/dist/interaction-store-public.js +1 -1
  148. package/node_modules/@maka/storage/dist/interaction-store.js +173 -0
  149. package/node_modules/@maka/storage/dist/production-session-snapshot.js +761 -0
  150. package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1 -1
  151. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +19 -22
  152. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +16 -36
  153. package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +2 -2
  154. package/node_modules/@maka/storage/dist/runtime-policy-stores.js +1 -1
  155. package/node_modules/@maka/storage/dist/session-message-projection.js +1 -1
  156. package/node_modules/@maka/storage/dist/session-store.js +32 -6
  157. package/node_modules/@maka/storage/dist/session-todo-store.js +6 -68
  158. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +19 -0
  159. package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +10 -1
  160. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +73 -3
  161. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +2 -10
  162. package/node_modules/@maka/storage/package.json +2 -0
  163. package/package.json +1 -1
  164. package/node_modules/@maka/core/dist/task-ledger.js +0 -669
  165. package/node_modules/@maka/storage/dist/task-ledger-authority.js +0 -121
  166. package/node_modules/@maka/storage/dist/task-ledger-store.js +0 -663
@@ -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
  }
@@ -0,0 +1,149 @@
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 { defineObjectShape, hasExactShape } from './record-schema.js';
20
+ const SAFE_ID = /^[A-Za-z0-9_-]{1,128}$/;
21
+ const GRANT_SHAPE = defineObjectShape()([
22
+ 'version',
23
+ 'sessionId',
24
+ 'providerId',
25
+ 'contractId',
26
+ 'serverId',
27
+ 'toolName',
28
+ 'capability',
29
+ 'scope',
30
+ 'grantedAt',
31
+ ], []);
32
+ const BROWSER_ORIGIN_SCOPE_SHAPE = defineObjectShape()(['kind', 'origin'], []);
33
+ const CAPABILITY_SCOPE_SHAPE = defineObjectShape()(['kind'], []);
34
+ const MCP_TOOL_SCOPE_SHAPE = defineObjectShape()(['kind', 'serverId', 'toolName'], []);
35
+ export function decodeClientCapabilitySessionGrantKey(value) {
36
+ const record = plainRecord(value, 'Client Capability Session Grant key');
37
+ return deepFreeze({
38
+ sessionId: safeId(record.sessionId, 'sessionId'),
39
+ ...decodeClientCapabilityGrantTarget(record),
40
+ });
41
+ }
42
+ export function decodeClientCapabilityGrantTarget(value) {
43
+ const record = plainRecord(value, 'Client Capability Grant target');
44
+ const capability = oneOf(record.capability, ['browser', 'computer_use', 'desktop_mcp'], 'capability');
45
+ const scope = decodeClientCapabilityGrantScope(record.scope);
46
+ if ((capability === 'browser' && scope.kind !== 'browser_origin') ||
47
+ (capability === 'computer_use' && scope.kind !== 'capability') ||
48
+ (capability === 'desktop_mcp' && scope.kind !== 'mcp_tool')) {
49
+ throw new Error('Client Capability Session Grant scope does not match capability');
50
+ }
51
+ return deepFreeze({
52
+ providerId: safeId(record.providerId, 'providerId'),
53
+ contractId: safeId(record.contractId, 'contractId'),
54
+ serverId: safeId(record.serverId, 'serverId'),
55
+ toolName: safeId(record.toolName, 'toolName'),
56
+ capability,
57
+ scope,
58
+ });
59
+ }
60
+ export function decodeClientCapabilitySessionGrant(value) {
61
+ const record = plainRecord(value, 'Client Capability Session Grant');
62
+ if (!hasExactShape(record, GRANT_SHAPE)) {
63
+ throw new Error('Invalid Client Capability Session Grant fields');
64
+ }
65
+ if (record.version !== 1)
66
+ throw new Error('Invalid Client Capability Session Grant version');
67
+ if (typeof record.grantedAt !== 'number' ||
68
+ !Number.isSafeInteger(record.grantedAt) ||
69
+ record.grantedAt < 0) {
70
+ throw new Error('Invalid Client Capability Session Grant timestamp');
71
+ }
72
+ return deepFreeze({
73
+ version: 1,
74
+ ...decodeClientCapabilitySessionGrantKey(record),
75
+ grantedAt: record.grantedAt,
76
+ });
77
+ }
78
+ export function clientCapabilityScopeIdentity(scope) {
79
+ switch (scope.kind) {
80
+ case 'browser_origin':
81
+ return scope.origin;
82
+ case 'capability':
83
+ return '*';
84
+ case 'mcp_tool':
85
+ return `${scope.serverId}\0${scope.toolName}`;
86
+ }
87
+ }
88
+ function decodeClientCapabilityGrantScope(value) {
89
+ const record = plainRecord(value, 'Client Capability Session Grant scope');
90
+ switch (record.kind) {
91
+ case 'browser_origin': {
92
+ if (!hasExactShape(record, BROWSER_ORIGIN_SCOPE_SHAPE)) {
93
+ throw new Error('Invalid Browser origin scope fields');
94
+ }
95
+ if (typeof record.origin !== 'string' || record.origin.length > 16_384) {
96
+ throw new Error('Invalid Browser origin scope');
97
+ }
98
+ const url = new URL(record.origin);
99
+ if ((url.protocol !== 'http:' && url.protocol !== 'https:') || url.origin !== record.origin) {
100
+ throw new Error('Browser origin scope must be a canonical HTTP origin');
101
+ }
102
+ return deepFreeze({ kind: 'browser_origin', origin: record.origin });
103
+ }
104
+ case 'capability':
105
+ if (!hasExactShape(record, CAPABILITY_SCOPE_SHAPE)) {
106
+ throw new Error('Invalid capability scope fields');
107
+ }
108
+ return Object.freeze({ kind: 'capability' });
109
+ case 'mcp_tool':
110
+ if (!hasExactShape(record, MCP_TOOL_SCOPE_SHAPE)) {
111
+ throw new Error('Invalid MCP tool scope fields');
112
+ }
113
+ return Object.freeze({
114
+ kind: 'mcp_tool',
115
+ serverId: safeId(record.serverId, 'scope.serverId'),
116
+ toolName: safeId(record.toolName, 'scope.toolName'),
117
+ });
118
+ default:
119
+ throw new Error('Invalid Client Capability Session Grant scope kind');
120
+ }
121
+ }
122
+ function plainRecord(value, label) {
123
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
124
+ throw new Error(`${label} must be a plain record`);
125
+ }
126
+ const prototype = Object.getPrototypeOf(value);
127
+ if (prototype !== Object.prototype && prototype !== null) {
128
+ throw new Error(`${label} must be a plain record`);
129
+ }
130
+ return value;
131
+ }
132
+ function safeId(value, label) {
133
+ if (typeof value !== 'string' || !SAFE_ID.test(value))
134
+ throw new Error(`Invalid ${label}`);
135
+ return value;
136
+ }
137
+ function oneOf(value, values, label) {
138
+ if (!values.includes(value))
139
+ throw new Error(`Invalid ${label}`);
140
+ return value;
141
+ }
142
+ function deepFreeze(value) {
143
+ if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
144
+ for (const nested of Object.values(value))
145
+ deepFreeze(nested);
146
+ Object.freeze(value);
147
+ }
148
+ return value;
149
+ }
@@ -39,7 +39,7 @@
39
39
  * Product readiness projections must call this helper rather than
40
40
  * reimplementing the criteria.
41
41
  */
42
- import { CODEX_SUBSCRIPTION_UNSUPPORTED_CHATGPT_MODELS, PROVIDER_DEFAULTS, connectionEnabledModelIds, providerAuthRequiresSecret, providerDefaultsOf, authorizeConnectionModel, } from './llm-connections.js';
42
+ import { connectionEnabledModelIds, providerAuthRequiresSecret, providerDefaultsOf, authorizeConnectionModel, } from './llm-connections.js';
43
43
  import { isModelExplicitlyUnsupportedForChat } from './model-catalog.js';
44
44
  import { isRetiredProvider } from './provider-registry.js';
45
45
  /**
@@ -64,7 +64,7 @@ import { isRetiredProvider } from './provider-registry.js';
64
64
  */
65
65
  export function isConnectionReady(input) {
66
66
  const { connection, hasSecret, requestedModel } = input;
67
- if (!isKnownProvider(connection)) {
67
+ if (!isRealConnection(connection)) {
68
68
  return { ready: false, reason: 'fake_backend' };
69
69
  }
70
70
  // Ahead of every other check: a retired provider has no Runtime adapter, so
@@ -99,38 +99,13 @@ export function isConnectionReady(input) {
99
99
  }
100
100
  return { ready: true, model };
101
101
  }
102
- /**
103
- * Pre-readiness normalization for ChatGPT-subscription (Codex)
104
- * connections: models the subscription cannot serve are filtered out of
105
- * the enabled list and the default falls back to the first servable
106
- * model, so the readiness gate below judges the models that would
107
- * actually be used. Pure; returns the input unchanged for non-Codex
108
- * providers. Moved from the former desktop send gate (#1038) so onboarding
109
- * and the session compatibility projection share one normalization.
110
- */
111
- export function normalizeOpenAiCodexConnection(connection) {
112
- if (connection.providerType !== 'openai-codex')
113
- return connection;
114
- const fallbackModels = PROVIDER_DEFAULTS['openai-codex'].fallbackModels;
115
- const safeModels = (connection.models ?? []).filter((entry) => entry.id && !CODEX_SUBSCRIPTION_UNSUPPORTED_CHATGPT_MODELS.has(entry.id));
116
- const models = safeModels.length ? safeModels : fallbackModels.map((id) => ({ id }));
117
- const enabledModelIds = new Set(models.map((entry) => entry.id));
118
- const defaultModel = connection.defaultModel &&
119
- !CODEX_SUBSCRIPTION_UNSUPPORTED_CHATGPT_MODELS.has(connection.defaultModel) &&
120
- enabledModelIds.has(connection.defaultModel)
121
- ? connection.defaultModel
122
- : (models[0]?.id ?? fallbackModels[0] ?? connection.defaultModel);
123
- if (models === connection.models && defaultModel === connection.defaultModel)
124
- return connection;
125
- return { ...connection, defaultModel, models };
126
- }
127
102
  /**
128
103
  * Whether a connection is backed by a real LLM provider.
129
104
  *
130
105
  * Since the in-process `fake` backend was retired (#3211) every registered
131
106
  * provider runs on `ai-sdk`, so this is exactly "is this `providerType` one
132
107
  * the build knows". An unknown one (legacy seed, future provider not yet in
133
- * PROVIDER_DEFAULTS) is treated as non-real — onboarding then routes the user
108
+ * PROVIDER_REGISTRY) is treated as non-real — onboarding then routes the user
134
109
  * to the add-provider flow which will rebuild a real connection.
135
110
  *
136
111
  * @kenji PR110a review gate: telemetry / lastTestStatus must NOT
@@ -138,8 +113,5 @@ export function normalizeOpenAiCodexConnection(connection) {
138
113
  * still unusable when it happens to carry `lastTestStatus: 'verified'`.
139
114
  */
140
115
  export function isRealConnection(connection) {
141
- return isKnownProvider(connection);
142
- }
143
- function isKnownProvider(connection) {
144
116
  return providerDefaultsOf(connection.providerType) !== undefined;
145
117
  }
@@ -16,26 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- export const SESSION_START_MODE_SPECS = {
20
- deep_research: {
21
- name: 'Deep Research',
22
- labels: ['mode:deep_research'],
23
- permissionMode: 'explore',
24
- },
25
- };
26
- export const SESSION_START_MODES = Object.keys(SESSION_START_MODE_SPECS);
27
- export const SESSION_START_MODE_LABELS = [
28
- ...new Set(Object.values(SESSION_START_MODE_SPECS).flatMap((spec) => spec.labels)),
29
- ];
30
- export function isSessionStartMode(value) {
31
- return typeof value === 'string' && Object.hasOwn(SESSION_START_MODE_SPECS, value);
32
- }
33
- export function sessionStartModeSpec(mode) {
34
- return SESSION_START_MODE_SPECS[mode];
35
- }
36
- export function isSessionStartModeLabel(value) {
37
- return typeof value === 'string' && SESSION_START_MODE_LABELS.includes(value);
38
- }
19
+ import { SESSION_START_MODE_SPECS } from './session-start-mode.js';
39
20
  export const DEEP_RESEARCH_SESSION_NAME = SESSION_START_MODE_SPECS.deep_research.name;
40
21
  export const DEEP_RESEARCH_SESSION_LABEL = SESSION_START_MODE_SPECS.deep_research.labels[0];
41
22
  export const DEEP_RESEARCH_WORKFLOW_STEPS = [
@@ -46,7 +46,17 @@ export const TOOL_ACTIVITY_KINDS = [
46
46
  'browser',
47
47
  'tool',
48
48
  ];
49
- const MESSAGE_CONTENT_SHAPE = defineObjectShape()(['text'], ['displayText', 'attachments', 'quotes', 'inlineReferences']);
49
+ export const DIRECTORY_REFERENCE_MAX_COUNT = 4;
50
+ export function isDirectoryReference(value) {
51
+ return (isRecord(value) &&
52
+ Object.keys(value).length === 2 &&
53
+ typeof value.hostId === 'string' &&
54
+ /^[A-Za-z0-9_-]{1,128}$/.test(value.hostId) &&
55
+ typeof value.path === 'string' &&
56
+ value.path.length <= 4096 &&
57
+ isCanonicalAbsolutePath(value.path));
58
+ }
59
+ const MESSAGE_CONTENT_SHAPE = defineObjectShape()(['text'], ['displayText', 'attachments', 'directoryReferences', 'quotes', 'inlineReferences']);
50
60
  const ATTACHMENT_REF_SHAPE = defineObjectShape()(['kind', 'name', 'mimeType', 'bytes', 'ref'], []);
51
61
  const QUOTE_REF_SHAPE = defineObjectShape()(['text'], ['label', 'sourceTurnId']);
52
62
  const INLINE_REFERENCE_SHAPE = defineObjectShape()(['kind', 'value', 'label', 'start'], []);
@@ -61,6 +71,9 @@ const EXTERNAL_FILE_REF_SHAPE = defineObjectShape()(['kind', 'absolutePath'], []
61
71
  export function normalizeMessageContent(content) {
62
72
  return {
63
73
  text: content.text,
74
+ ...(content.directoryReferences?.length
75
+ ? { directoryReferences: content.directoryReferences.map((ref) => ({ ...ref })) }
76
+ : {}),
64
77
  ...(content.displayText !== undefined && content.displayText !== content.text
65
78
  ? { displayText: content.displayText }
66
79
  : {}),
@@ -93,6 +106,7 @@ export function aggregateMessageContents(contents) {
93
106
  const text = contents.map((content) => content.text).join('\n\n');
94
107
  const displayText = contents.map((content) => content.displayText ?? content.text).join('\n\n');
95
108
  const attachments = contents.flatMap((content) => content.attachments ?? []);
109
+ const directoryReferences = contents.flatMap((content) => content.directoryReferences ?? []);
96
110
  const quotes = contents.flatMap((content) => content.quotes ?? []);
97
111
  const inlineReferences = [];
98
112
  const hasInlineReferenceMarker = contents.some((content) => content.inlineReferences !== undefined);
@@ -109,6 +123,7 @@ export function aggregateMessageContents(contents) {
109
123
  text,
110
124
  ...(displayText !== text ? { displayText } : {}),
111
125
  ...(attachments.length > 0 ? { attachments } : {}),
126
+ ...(directoryReferences.length > 0 ? { directoryReferences } : {}),
112
127
  ...(quotes.length > 0 ? { quotes } : {}),
113
128
  ...(hasInlineReferenceMarker ? { inlineReferences } : {}),
114
129
  });
@@ -122,6 +137,9 @@ export function isMessageContent(value) {
122
137
  return (isRecord(value) &&
123
138
  hasExactShape(value, MESSAGE_CONTENT_SHAPE) &&
124
139
  typeof value.text === 'string' &&
140
+ (value.directoryReferences === undefined ||
141
+ (Array.isArray(value.directoryReferences) &&
142
+ value.directoryReferences.every(isDirectoryReference))) &&
125
143
  (value.displayText === undefined || typeof value.displayText === 'string') &&
126
144
  (value.attachments === undefined ||
127
145
  (Array.isArray(value.attachments) && value.attachments.every(isAttachmentRef))) &&
@@ -256,6 +274,9 @@ export function messageContentsEqual(left, right) {
256
274
  const rightInlineReferences = right.inlineReferences;
257
275
  return (left.text === right.text &&
258
276
  leftDisplayText === rightDisplayText &&
277
+ (left.directoryReferences?.length ?? 0) === (right.directoryReferences?.length ?? 0) &&
278
+ (left.directoryReferences ?? []).every((ref, index) => ref.hostId === right.directoryReferences?.[index]?.hostId &&
279
+ ref.path === right.directoryReferences?.[index]?.path) &&
259
280
  ((leftAttachments === undefined && rightAttachments === undefined) ||
260
281
  (leftAttachments !== undefined &&
261
282
  rightAttachments !== undefined &&
@@ -524,8 +524,8 @@ export function stripEnvelopeTags(text) {
524
524
  * regardless of how the digest was built — sanitizing (NFC, control/bidi/
525
525
  * zero-width) and redacting secrets, then stripping envelope tags (to a
526
526
  * fixpoint) and JSON-stringifying so the value stays a quoted, break-out-proof
527
- * scalar (cf. renderSafeTaskLedgerText). This covers the fields that reach the
528
- * digest less filtered than messages do — `cwd`, `gitBranch`, and file paths.
527
+ * scalar. This covers the fields that reach the digest less filtered than
528
+ * messages do — `cwd`, `gitBranch`, and file paths.
529
529
  * `source` and `updated_at` are the only unquoted fields; both are
530
530
  * Maka-controlled enums/timestamps.
531
531
  */
@@ -20,6 +20,7 @@ import { APPROVALS_REVIEWERS, APPROVAL_RISK_LEVELS, } from './permission.js';
20
20
  import { defineObjectShape, hasExactShape } from './record-schema.js';
21
21
  import { InteractionPermissionProjectionError, decodeInteractionPermissionPrompt, projectInteractionReviewText, projectInteractionPermissionPrompt, } from './interaction-permission-review.js';
22
22
  import { SANDBOX_BOUNDARY_REQUEST_STATUSES, validateSandboxBoundaryExpansion, } from './sandbox-boundary.js';
23
+ import { decodeClientCapabilityGrantTarget, } from './client-capability-grant.js';
23
24
  export * from './interaction-permission-review.js';
24
25
  export const INTERACTION_MIN_QUESTIONS = 1;
25
26
  export const INTERACTION_MAX_QUESTIONS = 3;
@@ -40,17 +41,21 @@ export const INTERACTION_CLOSURE_REASONS = [
40
41
  'turn_terminal',
41
42
  'timed_out',
42
43
  'host_restarted',
44
+ 'provider_disconnected',
43
45
  ];
44
46
  const UTF8 = new TextEncoder();
45
47
  const PERMISSION_REQUEST_SHAPE = defineObjectShape()(['kind', 'toolUseId', 'prompt'], []);
46
48
  const QUESTION_REQUEST_SHAPE = defineObjectShape()(['kind', 'toolUseId', 'questions'], []);
47
49
  const SANDBOX_BOUNDARY_REQUEST_SHAPE = defineObjectShape()(['kind', 'expansion', 'justification'], []);
50
+ const CLIENT_CAPABILITY_REQUEST_SHAPE = defineObjectShape()(['kind', 'toolUseId', 'target'], []);
48
51
  const PERMISSION_ANSWER_SHAPE = defineObjectShape()(['kind', 'decision', 'rememberForTurn'], []);
49
52
  const QUESTION_ANSWER_SHAPE = defineObjectShape()(['kind', 'answers'], []);
50
53
  const SANDBOX_BOUNDARY_ANSWER_SHAPE = defineObjectShape()(['kind', 'decision'], []);
54
+ const CLIENT_CAPABILITY_ANSWER_SHAPE = defineObjectShape()(['kind', 'decision'], []);
51
55
  const PERMISSION_OUTCOME_SHAPE = defineObjectShape()(['kind', 'reviewer', 'committedAt', 'decision', 'rememberForTurn'], ['rationale', 'riskLevel']);
52
56
  const QUESTION_OUTCOME_SHAPE = defineObjectShape()(['kind', 'answers', 'committedAt'], []);
53
57
  const SANDBOX_BOUNDARY_OUTCOME_SHAPE = defineObjectShape()(['kind', 'decision', 'status', 'committedAt'], []);
58
+ const CLIENT_CAPABILITY_OUTCOME_SHAPE = defineObjectShape()(['kind', 'decision', 'committedAt'], []);
54
59
  const CLOSURE_OUTCOME_SHAPE = defineObjectShape()(['kind', 'reason', 'committedAt'], []);
55
60
  const QUESTION_SHAPE = defineObjectShape()(['question', 'options'], []);
56
61
  const OPTION_SHAPE = defineObjectShape()(['label'], ['description']);
@@ -84,6 +89,14 @@ export function decodeInteractionRequest(value) {
84
89
  justification: boundedCharacterString(record.justification, 'sandbox boundary justification', INTERACTION_SANDBOX_BOUNDARY_JUSTIFICATION_MAX_CHARS),
85
90
  };
86
91
  }
92
+ else if (record.kind === 'client_capability') {
93
+ exact(record, CLIENT_CAPABILITY_REQUEST_SHAPE, 'Client Capability request');
94
+ request = {
95
+ kind: 'client_capability',
96
+ toolUseId: boundedString(record.toolUseId, 'toolUseId', INTERACTION_ID_MAX_BYTES),
97
+ target: decodeClientCapabilityGrantTarget(record.target),
98
+ };
99
+ }
87
100
  else {
88
101
  throw new Error('Invalid Interaction request kind');
89
102
  }
@@ -117,6 +130,13 @@ export function decodeInteractionAnswer(value) {
117
130
  decision: oneOf(record.decision, ['allow', 'deny'], 'decision'),
118
131
  };
119
132
  }
133
+ else if (record.kind === 'client_capability') {
134
+ exact(record, CLIENT_CAPABILITY_ANSWER_SHAPE, 'Client Capability answer');
135
+ answer = {
136
+ kind: 'client_capability',
137
+ decision: oneOf(record.decision, ['allow', 'deny'], 'decision'),
138
+ };
139
+ }
120
140
  else {
121
141
  throw new Error('Invalid Interaction answer kind');
122
142
  }
@@ -180,6 +200,14 @@ export function decodeInteractionCanonicalOutcome(value) {
180
200
  committedAt: safeInteger(record.committedAt, 'committedAt', false),
181
201
  };
182
202
  }
203
+ else if (record.kind === 'client_capability_decision') {
204
+ exact(record, CLIENT_CAPABILITY_OUTCOME_SHAPE, 'Client Capability outcome');
205
+ outcome = {
206
+ kind: 'client_capability_decision',
207
+ decision: oneOf(record.decision, ['allow', 'deny'], 'decision'),
208
+ committedAt: safeInteger(record.committedAt, 'committedAt', false),
209
+ };
210
+ }
183
211
  else if (record.kind === 'closure') {
184
212
  exact(record, CLOSURE_OUTCOME_SHAPE, 'closure outcome');
185
213
  outcome = {
@@ -250,6 +278,13 @@ export function projectInteractionSandboxBoundaryRequest(input) {
250
278
  justification: input.justification,
251
279
  });
252
280
  }
281
+ export function projectInteractionClientCapabilityRequest(input) {
282
+ return decodeInteractionRequest({
283
+ kind: 'client_capability',
284
+ toolUseId: input.toolUseId,
285
+ target: input.target,
286
+ });
287
+ }
253
288
  export function interactionAnswerMatchesRequestKind(request, answer) {
254
289
  return request.kind === answer.kind;
255
290
  }
@@ -259,7 +294,9 @@ export function interactionOutcomeMatchesRequestKind(request, outcome) {
259
294
  ? outcome.kind === 'permission_answer'
260
295
  : request.kind === 'question'
261
296
  ? outcome.kind === 'question_answer'
262
- : outcome.kind === 'sandbox_boundary_decision'));
297
+ : request.kind === 'sandbox_boundary'
298
+ ? outcome.kind === 'sandbox_boundary_decision'
299
+ : outcome.kind === 'client_capability_decision'));
263
300
  }
264
301
  export function interactionQuestionAnswerCountMatchesRequest(request, answers) {
265
302
  return request.questions.length === answers.length;
@@ -282,13 +319,17 @@ export function isInteractionAnswerValidForRequest(request, answer) {
282
319
  }
283
320
  if (answer.kind === 'sandbox_boundary')
284
321
  return request.kind === 'sandbox_boundary';
322
+ if (answer.kind === 'client_capability')
323
+ return request.kind === 'client_capability';
285
324
  return interactionRememberForTurnIsEligible(request, answer);
286
325
  }
287
326
  export function isInteractionCanonicalOutcomeValidForRequest(request, outcome) {
288
327
  if (!interactionOutcomeMatchesRequestKind(request, outcome))
289
328
  return false;
290
329
  if (outcome.kind === 'closure')
291
- return request.kind === 'permission' || outcome.reason !== 'timed_out';
330
+ return (request.kind === 'permission' ||
331
+ request.kind === 'client_capability' ||
332
+ outcome.reason !== 'timed_out');
292
333
  if (outcome.kind === 'permission_answer') {
293
334
  return interactionRememberForTurnIsEligible(request, outcome);
294
335
  }
@@ -296,6 +337,9 @@ export function isInteractionCanonicalOutcomeValidForRequest(request, outcome) {
296
337
  return (request.kind === 'question' &&
297
338
  interactionQuestionAnswerCountMatchesRequest(request, outcome.answers));
298
339
  }
340
+ if (outcome.kind === 'client_capability_decision') {
341
+ return request.kind === 'client_capability';
342
+ }
299
343
  return request.kind === 'sandbox_boundary';
300
344
  }
301
345
  export function interactionCanonicalOutcomesEquivalent(left, right) {
@@ -308,6 +352,9 @@ export function interactionCanonicalOutcomesEquivalent(left, right) {
308
352
  if (left.kind === 'sandbox_boundary_decision' && right.kind === 'sandbox_boundary_decision') {
309
353
  return left.decision === right.decision && left.status === right.status;
310
354
  }
355
+ if (left.kind === 'client_capability_decision' && right.kind === 'client_capability_decision') {
356
+ return left.decision === right.decision;
357
+ }
311
358
  return left.kind === 'closure' && right.kind === 'closure' && left.reason === right.reason;
312
359
  }
313
360
  function decodeQuestion(value) {