maka-agent 0.2.0-dev.10.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.
- package/LICENSE +49 -2
- package/RUNTIME_HOST_PEER_DEPENDENCIES.rust.tsv +70 -0
- package/RUNTIME_HOST_PEER_THIRD_PARTY_NOTICES.txt +1839 -140
- package/dist/cli-core.js +25 -1
- package/dist/mcp-capability-provider.js +1 -1
- package/dist/onboarding-catalog.js +3 -5
- package/dist/pi-transcript.js +21 -17
- package/dist/pi-tui-layout.js +4 -2
- package/dist/pi-tui-mcp-status.js +115 -122
- package/dist/pi-tui-pickers.js +11 -5
- package/dist/pi-tui-runner.js +133 -102
- package/dist/runtime-host-cli-context.js +4 -0
- package/dist/runtime-host-cli.js +150 -4
- package/dist/runtime-host-lifecycle-transaction.js +5 -2
- package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
- package/dist/runtime-host-onboarding.js +12 -16
- package/dist/runtime-host-peer-management-command.js +16 -4
- package/dist/runtime-host-plugin-command.js +101 -0
- package/dist/runtime-host-run-command.js +5 -1
- package/dist/runtime-host-service-management-command.js +2 -1
- package/dist/runtime-host-setup-command.js +1 -0
- package/dist/runtime-host-task-readiness.js +2 -3
- package/dist/runtime-host-tui-command.js +1 -1
- package/dist/runtime-host-tui-context.js +34 -6
- package/dist/runtime-host-update-command.js +13 -5
- package/dist/runtime-host-update-discovery.js +1 -0
- package/dist/tui-clipboard.js +86 -0
- package/dist/tui-copy-catalog.js +256 -0
- package/dist/tui-copy-command.js +103 -0
- package/dist/tui-mcp-control.js +46 -4
- package/dist/tui-mcp-remote-publication.js +395 -0
- package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
- package/node_modules/@maka/core/dist/agent-run.js +5 -0
- package/node_modules/@maka/core/dist/attachments.js +80 -1
- package/node_modules/@maka/core/dist/bounded-response.js +71 -0
- package/node_modules/@maka/core/dist/chat-model-choice.js +8 -31
- package/node_modules/@maka/core/dist/client-capability-grant.js +149 -0
- package/node_modules/@maka/core/dist/connection-readiness.js +3 -31
- package/node_modules/@maka/core/dist/deep-research.js +1 -20
- package/node_modules/@maka/core/dist/events.js +22 -1
- package/node_modules/@maka/core/dist/execution-inspect.js +3 -1
- package/node_modules/@maka/core/dist/foreign-session.js +2 -2
- package/node_modules/@maka/core/dist/interaction.js +49 -2
- package/node_modules/@maka/core/dist/llm-connections.js +74 -82
- package/node_modules/@maka/core/dist/model-call-attempt.js +66 -0
- package/node_modules/@maka/core/dist/model-catalog.js +238 -313
- package/node_modules/@maka/core/dist/model-facts.js +280 -0
- package/node_modules/@maka/core/dist/model-metadata.generated.js +1907 -1872
- package/node_modules/@maka/core/dist/model-metadata.js +184 -199
- package/node_modules/@maka/core/dist/model-projection-transition.js +145 -0
- package/node_modules/@maka/core/dist/model-thinking.js +1 -1
- package/node_modules/@maka/core/dist/models-dev-projection.js +302 -0
- package/node_modules/@maka/core/dist/models-dev-refresh.js +55 -0
- package/node_modules/@maka/core/dist/onboarding.js +2 -1
- package/node_modules/@maka/core/dist/provider-auth.js +47 -291
- package/node_modules/@maka/core/dist/provider-registry.js +68 -357
- package/node_modules/@maka/core/dist/runtime-boundary.js +2 -2
- package/node_modules/@maka/core/dist/runtime-event.js +5 -1
- package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +82 -5
- package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +75 -0
- package/node_modules/@maka/core/dist/runtime-policy.js +2 -1
- package/node_modules/@maka/core/dist/session-send-projection.js +2 -1
- package/node_modules/@maka/core/dist/session-start-mode.js +42 -0
- package/node_modules/@maka/core/dist/session-todo.js +101 -0
- package/node_modules/@maka/core/dist/session.js +119 -5
- package/node_modules/@maka/core/dist/slash-command-catalog.js +1 -0
- package/node_modules/@maka/core/dist/task-submission-readiness.js +2 -1
- package/node_modules/@maka/core/dist/tool-activity-args.js +4 -0
- package/node_modules/@maka/core/dist/tool-quiet-preview.js +5 -5
- package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
- package/node_modules/@maka/core/dist/workhub-creation-intent.js +896 -0
- package/node_modules/@maka/core/package.json +9 -1
- package/node_modules/@maka/runtime/dist/active-tool-result-prune.js +45 -131
- package/node_modules/@maka/runtime/dist/agent-run.js +58 -44
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +146 -201
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +235 -69
- package/node_modules/@maka/runtime/dist/context-budget-helpers.js +4 -41
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +8 -1
- package/node_modules/@maka/runtime/dist/context-budget.js +9 -81
- package/node_modules/@maka/runtime/dist/context-diagnostics.js +63 -27
- package/node_modules/@maka/runtime/dist/continuation-replay.js +19 -11
- package/node_modules/@maka/runtime/dist/conversation-copy.js +179 -16
- package/node_modules/@maka/runtime/dist/deep-research-tools.js +2 -3
- package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +21 -0
- package/node_modules/@maka/runtime/dist/execution-inspect.js +13 -3
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +58 -7
- package/node_modules/@maka/runtime/dist/history-compact-ledger.js +9 -1
- package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +2 -2
- package/node_modules/@maka/runtime/dist/history-compact-summary-validation.js +2 -1
- package/node_modules/@maka/runtime/dist/history-compaction.js +2 -1
- package/node_modules/@maka/runtime/dist/image-file.js +5 -20
- package/node_modules/@maka/runtime/dist/latest-context-snapshot.js +114 -20
- package/node_modules/@maka/runtime/dist/local-web-fetch.js +2 -43
- package/node_modules/@maka/runtime/dist/mcp-tools.js +28 -0
- package/node_modules/@maka/runtime/dist/model-adapter.js +47 -15
- package/node_modules/@maka/runtime/dist/model-factory.js +7 -1
- package/node_modules/@maka/runtime/dist/model-fetcher.js +15 -8
- package/node_modules/@maka/runtime/dist/model-history.js +125 -3
- package/node_modules/@maka/runtime/dist/model-projection-transition-ledger.js +207 -0
- package/node_modules/@maka/runtime/dist/model-runtime.js +7 -4
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +12 -14
- package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +173 -20
- package/node_modules/@maka/runtime/dist/plugin-runtime.js +219 -0
- package/node_modules/@maka/runtime/dist/prompt-composition.js +33 -21
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +35 -74
- package/node_modules/@maka/runtime/dist/quiescent-session-snapshot.js +78 -0
- package/node_modules/@maka/runtime/dist/request-shape.js +256 -343
- package/node_modules/@maka/runtime/dist/run-trace.js +2 -24
- package/node_modules/@maka/runtime/dist/runtime-continuation-admission.js +1 -1
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +3 -0
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +1 -0
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +77 -23
- package/node_modules/@maka/runtime/dist/runtime-resume.js +20 -11
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +8 -4
- package/node_modules/@maka/runtime/dist/session-manager.js +45 -9
- package/node_modules/@maka/runtime/dist/session-recap.js +2 -1
- package/node_modules/@maka/runtime/dist/session-todo-tools.js +67 -0
- package/node_modules/@maka/runtime/dist/subagent-tools.js +2 -77
- package/node_modules/@maka/runtime/dist/system-prompt/main-session-prompt.js +1 -1
- package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +93 -83
- package/node_modules/@maka/runtime/dist/test-connection.js +6 -6
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +227 -0
- package/node_modules/@maka/runtime/dist/tool-result-archive.js +40 -168
- package/node_modules/@maka/runtime/dist/tool-runtime.js +50 -6
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +39 -16
- package/node_modules/@maka/runtime/package.json +2 -1
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +10 -0
- package/node_modules/@maka/runtime-host/dist/client/catalog-reader.js +19 -5
- package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +3 -2
- package/node_modules/@maka/runtime-host/dist/client/connection.js +22 -0
- package/node_modules/@maka/runtime-host/dist/client/host-profile.js +222 -19
- package/node_modules/@maka/runtime-host/dist/client/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/client/oauth-presentation.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/peer-client.js +4 -0
- package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +8 -0
- package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +2 -0
- package/node_modules/@maka/runtime-host/dist/operator/peer-management-frame.js +2 -0
- package/node_modules/@maka/runtime-host/dist/operator/service-management-frame.js +2 -0
- package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +22 -1
- package/node_modules/@maka/{storage/dist/task-ledger-store-internal.js → runtime-host/dist/protocol/connection-catalog-change.js} +7 -13
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +43 -2
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +7 -3
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +512 -0
- package/node_modules/@maka/runtime-host/dist/protocol/runtime-policy.js +24 -12
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-retirement.js +30 -3
- package/node_modules/@maka/runtime-host/dist/protocol/session-todo.js +53 -0
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +4 -1
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +92 -4
- package/node_modules/@maka/runtime-host/dist/server/access-authority.js +15 -13
- package/node_modules/@maka/runtime-host/dist/server/access-credential-metadata.js +4 -2
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +119 -47
- package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +10 -4
- package/node_modules/@maka/runtime-host/dist/server/child-agent-composition.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +192 -18
- package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +122 -48
- package/node_modules/@maka/runtime-host/dist/server/client-capability-provider-id.js +31 -0
- package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +6 -5
- package/node_modules/@maka/runtime-host/dist/server/connection-session.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/deep-research-coordinator.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +163 -66
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +27 -9
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +38 -43
- package/node_modules/@maka/runtime-host/dist/server/extension-bundle.js +249 -0
- package/node_modules/@maka/runtime-host/dist/server/extension-package-manifest.js +262 -0
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +0 -23
- package/node_modules/@maka/runtime-host/dist/server/host-change-feed.js +11 -0
- package/node_modules/@maka/runtime-host/dist/server/index.js +5 -0
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +181 -13
- package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +7 -9
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +88 -22
- package/node_modules/@maka/runtime-host/dist/server/model-metadata-refresh.js +96 -0
- package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +43 -118
- package/node_modules/@maka/runtime-host/dist/server/plugin-composition-patch.js +58 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-composition-store.js +141 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-package-loader.js +130 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-package-store.js +528 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +249 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +1130 -0
- package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +24 -5
- package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +31 -2
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +2 -1
- package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +58 -9
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +30 -13
- package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/session-todo-coordinator.js +77 -0
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +10 -2
- package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +276 -3
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +101 -1
- package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +1 -0
- package/node_modules/@maka/runtime-host/dist/webrtc-stun-policy.js +114 -0
- package/node_modules/@maka/runtime-host/package.json +2 -0
- package/node_modules/@maka/storage/dist/agent-run-store.js +80 -15
- package/node_modules/@maka/storage/dist/artifact-attachments.js +29 -6
- package/node_modules/@maka/storage/dist/artifact-store.js +7 -23
- package/node_modules/@maka/storage/dist/artifact-stores.js +13 -2
- package/node_modules/@maka/storage/dist/conversation-operational-state.js +3 -0
- package/node_modules/@maka/storage/dist/credential-store.js +3 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +4 -0
- package/node_modules/@maka/storage/dist/file-lifetime-owner.js +30 -2
- package/node_modules/@maka/storage/dist/interaction-store-public.js +1 -1
- package/node_modules/@maka/storage/dist/interaction-store.js +173 -0
- package/node_modules/@maka/storage/dist/model-facts-store.js +79 -0
- package/node_modules/@maka/storage/dist/production-session-snapshot.js +761 -0
- package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1 -1
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +26 -26
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +114 -56
- package/node_modules/@maka/storage/dist/runtime-policy/document-io.js +22 -16
- package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +2 -2
- package/node_modules/@maka/storage/dist/runtime-policy-stores.js +1 -1
- package/node_modules/@maka/storage/dist/session-message-projection.js +1 -1
- package/node_modules/@maka/storage/dist/session-store.js +32 -6
- package/node_modules/@maka/storage/dist/{task-ledger-authority.js → session-todo-authority.js} +13 -28
- package/node_modules/@maka/storage/dist/session-todo-store.js +169 -0
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +19 -0
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +42 -1
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +10 -1
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +73 -3
- package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +5 -8
- package/node_modules/@maka/storage/dist/storage-writer-composition.js +3 -3
- package/node_modules/@maka/storage/package.json +3 -1
- package/package.json +1 -1
- package/node_modules/@maka/core/dist/task-ledger.js +0 -669
- package/node_modules/@maka/runtime/dist/task-ledger-tools.js +0 -244
- package/node_modules/@maka/runtime/dist/test-helpers.js +0 -61
- package/node_modules/@maka/runtime-host/dist/protocol/task-ledger.js +0 -321
- package/node_modules/@maka/runtime-host/dist/server/task-ledger-coordinator.js +0 -154
- 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,50 +16,27 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
20
|
-
import { buildConnectionModelCatalogEntries } from './model-catalog.js';
|
|
21
|
-
import { thinkingVariantsForConnection } from './model-thinking.js';
|
|
22
|
-
import { CODEX_SUBSCRIPTION_UNSUPPORTED_CHATGPT_MODELS, connectionEnabledModelIds, providerDefaultsOf, } from './llm-connections.js';
|
|
23
|
-
const MODEL_MENU_PROVIDER_LABELS = {
|
|
24
|
-
anthropic: 'Anthropic',
|
|
25
|
-
openai: 'OpenAI',
|
|
26
|
-
google: 'Google',
|
|
27
|
-
deepseek: 'DeepSeek',
|
|
28
|
-
moonshot: 'Moonshot',
|
|
29
|
-
ollama: 'Ollama',
|
|
30
|
-
'kimi-coding-plan': 'Kimi',
|
|
31
|
-
'zai-coding-plan': 'Z.AI',
|
|
32
|
-
MiniMax: 'MiniMax',
|
|
33
|
-
'openai-codex': 'OpenAI OAuth',
|
|
34
|
-
};
|
|
19
|
+
import { offerableCatalogEntries, providerDefaultsOf, providerMenuLabel, } from './llm-connections.js';
|
|
35
20
|
export function buildChatModelChoices(connections) {
|
|
36
21
|
const choices = [];
|
|
37
|
-
for (const
|
|
38
|
-
const connection = normalizeOpenAiCodexConnection(rawConnection);
|
|
22
|
+
for (const connection of connections) {
|
|
39
23
|
const provider = providerDefaultsOf(connection.providerType);
|
|
40
|
-
if (!
|
|
24
|
+
if (!provider)
|
|
41
25
|
continue;
|
|
42
|
-
|
|
43
|
-
const enabledModelIds = new Set(connectionEnabledModelIds(connection));
|
|
44
|
-
for (const entry of buildConnectionModelCatalogEntries({ connection })) {
|
|
45
|
-
if (!entry.canUseAsChatDefault ||
|
|
46
|
-
!enabledModelIds.has(entry.id) ||
|
|
47
|
-
(connection.providerType === 'openai-codex' &&
|
|
48
|
-
CODEX_SUBSCRIPTION_UNSUPPORTED_CHATGPT_MODELS.has(entry.id.trim()))) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
26
|
+
for (const entry of offerableCatalogEntries(connection)) {
|
|
51
27
|
choices.push({
|
|
52
|
-
connectionId:
|
|
28
|
+
connectionId: connection.connectionId,
|
|
53
29
|
connectionSlug: connection.slug,
|
|
54
30
|
providerType: connection.providerType,
|
|
55
|
-
providerLabel:
|
|
31
|
+
providerLabel: providerMenuLabel(connection.providerType) ?? connection.providerType,
|
|
56
32
|
model: entry.id,
|
|
57
33
|
label: entry.displayName?.trim() || entry.id,
|
|
58
34
|
...(entry.description !== undefined ? { description: entry.description } : {}),
|
|
59
35
|
...(entry.knowledgeCutoff !== undefined ? { knowledgeCutoff: entry.knowledgeCutoff } : {}),
|
|
60
36
|
...(provider.authKind === 'oauth_token' ? {} : { connectionName: connection.name }),
|
|
61
37
|
isDefault: entry.isDefault,
|
|
62
|
-
thinkingLevels:
|
|
38
|
+
thinkingLevels: entry.thinkingLevels,
|
|
39
|
+
supportsVision: entry.supportsVision,
|
|
63
40
|
});
|
|
64
41
|
}
|
|
65
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 {
|
|
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 (!
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
|
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 &&
|
|
@@ -141,7 +141,9 @@ function isToolFact(value) {
|
|
|
141
141
|
function isCompactionCheckpoint(value) {
|
|
142
142
|
return (hasShape(value, ['eventId', 'validation'], ['checkpointId', 'policyVersion', 'sourceCoverage']) &&
|
|
143
143
|
typeof value.eventId === 'string' &&
|
|
144
|
-
(value.validation === 'shape_valid' ||
|
|
144
|
+
(value.validation === 'shape_valid' ||
|
|
145
|
+
value.validation === 'invalid' ||
|
|
146
|
+
value.validation === 'superseded') &&
|
|
145
147
|
isOptionalString(value.checkpointId) &&
|
|
146
148
|
isOptionalString(value.policyVersion) &&
|
|
147
149
|
(value.sourceCoverage === undefined || isCoverage(value.sourceCoverage)));
|
|
@@ -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
|
|
528
|
-
*
|
|
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
|
-
:
|
|
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' ||
|
|
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) {
|