maka-agent 0.2.0-dev.14.20260902 → 0.2.0-dev.16.20260903
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/dist/cli-core.js +0 -1
- package/dist/pi-transcript.js +48 -0
- package/dist/pi-tui-form-interaction.js +497 -0
- package/dist/pi-tui-pickers.js +256 -55
- package/dist/pi-tui-runner.js +215 -12
- package/dist/runtime-host-cli.js +17 -42
- package/dist/runtime-host-lifecycle-transaction.js +31 -13
- package/dist/runtime-host-managed-lifecycle-manager.js +1 -1
- package/dist/runtime-host-onboarding.js +3 -1
- package/dist/runtime-host-openrc-service.js +469 -0
- package/dist/runtime-host-run-command.js +6 -2
- package/dist/runtime-host-service-command.js +3 -3
- package/dist/runtime-host-service-management-command.js +43 -15
- package/dist/runtime-host-session-channel.js +3 -0
- package/dist/runtime-host-session-driver.js +21 -6
- package/dist/runtime-host-setup-command.js +30 -31
- package/dist/tui-context-refresh.js +103 -0
- package/dist/tui-copy-catalog.js +73 -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/chat-model-choice.js +4 -0
- package/node_modules/@maka/core/dist/computer-use.js +27 -92
- package/node_modules/@maka/core/dist/interaction.js +577 -3
- package/node_modules/@maka/core/dist/llm-connections.js +4 -0
- package/node_modules/@maka/core/dist/local-memory.js +2 -2
- package/node_modules/@maka/core/dist/model-call-usage-projection.js +3 -0
- package/node_modules/@maka/core/dist/model-metadata.js +26 -7
- package/node_modules/@maka/core/dist/model-thinking.js +17 -0
- package/node_modules/@maka/core/dist/provider-registry.js +1 -0
- package/node_modules/@maka/core/dist/runtime-event.js +23 -1
- package/node_modules/@maka/core/dist/scheduled-task.js +4 -0
- package/node_modules/@maka/core/dist/session.js +95 -2
- package/node_modules/@maka/core/dist/text-sanitize.js +19 -0
- package/node_modules/@maka/core/dist/usage-ledger-merge.js +3 -0
- package/node_modules/@maka/core/dist/usage-record-schema.js +11 -5
- package/node_modules/@maka/core/dist/workhub-creation-intent.js +75 -9
- package/node_modules/@maka/core/dist/workhub-session-resolver.js +50 -0
- package/node_modules/@maka/core/package.json +2 -0
- package/node_modules/@maka/eval/dist/harbor-external-subject.js +2 -1
- package/node_modules/@maka/eval/dist/harness-executor.js +3 -2
- package/node_modules/@maka/eval/dist/install-preflight.js +39 -10
- package/node_modules/@maka/eval/dist/process-termination.js +83 -0
- package/node_modules/@maka/mcp/dist/sep-2243.js +3 -3
- package/node_modules/@maka/runtime/dist/agent-run.js +6 -3
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +332 -118
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction-contract.js +6 -1
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +171 -341
- package/node_modules/@maka/runtime/dist/bots/telegram-bridge.js +3 -26
- package/node_modules/@maka/runtime/dist/bundled-skill-catalog.generated.js +1 -1
- package/node_modules/@maka/runtime/dist/computer-use-codec.js +1 -141
- package/node_modules/@maka/runtime/dist/computer-use-tools.js +23 -105
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +20 -26
- package/node_modules/@maka/runtime/dist/context-budget.js +18 -20
- package/node_modules/@maka/runtime/dist/conversation-copy.js +23 -19
- package/node_modules/@maka/runtime/dist/cua-frame-state.js +1 -69
- package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +267 -0
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +6 -9
- package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +67 -23
- package/node_modules/@maka/runtime/dist/history-compact-summary-validation.js +11 -18
- package/node_modules/@maka/runtime/dist/history-compaction.js +66 -73
- package/node_modules/@maka/runtime/dist/interaction-authority.js +69 -0
- package/node_modules/@maka/runtime/dist/mcp-tools.js +13 -1
- package/node_modules/@maka/runtime/dist/memory-extraction.js +11 -11
- package/node_modules/@maka/runtime/dist/model-adapter.js +24 -6
- package/node_modules/@maka/runtime/dist/model-factory.js +14 -5
- package/node_modules/@maka/runtime/dist/oauth-provider-contracts.js +28 -1
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +7 -6
- package/node_modules/@maka/runtime/dist/opencode-session-header.js +29 -0
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +11 -1
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +12 -11
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +51 -13
- package/node_modules/@maka/runtime/dist/scheduled-task-tools.js +3 -0
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +26 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +1 -0
- package/node_modules/@maka/runtime/dist/session-projection-helpers.js +16 -1
- package/node_modules/@maka/runtime/dist/stream-graph-projection.js +6 -0
- package/node_modules/@maka/runtime/dist/stream-graph-read-model.js +5 -0
- package/node_modules/@maka/runtime/dist/stream-usage-fallback-fetch.js +74 -0
- package/node_modules/@maka/runtime/dist/subscription-credentials.js +51 -4
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +47 -3
- package/node_modules/@maka/runtime/dist/system-prompt/main-session-prompt.js +20 -1
- package/node_modules/@maka/runtime/dist/test-connection.js +18 -11
- package/node_modules/@maka/runtime/dist/tool-runtime.js +183 -0
- package/node_modules/@maka/runtime/package.json +1 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +14 -0
- package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +84 -1
- package/node_modules/@maka/runtime-host/dist/client/host-profile.js +68 -51
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/owner-connection-code.js +8 -5
- package/node_modules/@maka/runtime-host/dist/client/peer-client.js +342 -36
- package/node_modules/@maka/runtime-host/dist/client/reconnect-lifecycle.js +60 -4
- package/node_modules/@maka/runtime-host/dist/peer-mesh/index.js +3 -3
- package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +1 -1
- package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +48 -60
- package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +847 -431
- package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +33 -74
- package/node_modules/@maka/runtime-host/dist/peer-mesh/store.js +82 -69
- package/node_modules/@maka/runtime-host/dist/peer-reachability/index.js +21 -0
- package/node_modules/@maka/runtime-host/dist/peer-reachability/model.js +202 -0
- package/node_modules/@maka/runtime-host/dist/peer-reachability/owner.js +119 -0
- package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +245 -0
- package/node_modules/@maka/runtime-host/dist/protocol/agent-graph.js +4 -1
- package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +68 -0
- package/node_modules/@maka/runtime-host/dist/protocol/connection-effects.js +15 -8
- package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +7 -23
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +47 -1
- package/node_modules/@maka/runtime-host/dist/protocol/oauth.js +25 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/peer-mesh.js +14 -31
- package/node_modules/@maka/runtime-host/dist/protocol/scheduled-task.js +19 -6
- package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +36 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-revision.js +11 -2
- package/node_modules/@maka/runtime-host/dist/protocol/usage-pricing.js +16 -2
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +51 -2
- package/node_modules/@maka/runtime-host/dist/server/access-authority.js +35 -2
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +12 -10
- package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +163 -30
- package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +38 -14
- package/node_modules/@maka/runtime-host/dist/server/daily-review-coordinator.js +45 -22
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +78 -20
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +4 -2
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +2 -1
- package/node_modules/@maka/runtime-host/dist/server/execution-service.js +49 -28
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +3 -6
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +130 -27
- package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +30 -1
- package/node_modules/@maka/runtime-host/dist/server/listener-set.js +2 -4
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +16 -3
- package/node_modules/@maka/runtime-host/dist/server/oauth-coordinator.js +66 -3
- package/node_modules/@maka/runtime-host/dist/server/oauth-execution-authority.js +20 -3
- package/node_modules/@maka/runtime-host/dist/server/peer-listener.js +8 -21
- package/node_modules/@maka/runtime-host/dist/server/peer-mesh-authority.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +6 -3
- package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +72 -12
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +48 -18
- package/node_modules/@maka/runtime-host/dist/server/session-turn-access-request-coordinator.js +43 -26
- package/node_modules/@maka/runtime-host/dist/server/usage-pricing-coordinator.js +15 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +229 -4
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +146 -8
- package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +32 -6
- package/node_modules/@maka/runtime-host/package.json +1 -0
- package/node_modules/@maka/storage/dist/agent-run-store.js +18 -5
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +14 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +5 -0
- package/node_modules/@maka/storage/dist/interaction-store.js +13 -1
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +9 -3
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +49 -19
- package/node_modules/@maka/storage/dist/runtime-policy/oauth-login-receipt-document.js +3 -1
- package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +13 -5
- package/node_modules/@maka/storage/dist/session-copy-cleanup.js +4 -2
- package/node_modules/@maka/storage/dist/session-store.js +39 -6
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +16 -9
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +30 -3
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +117 -0
- package/node_modules/@maka/storage/dist/sqlite-usage-store.js +29 -6
- package/node_modules/@maka/storage/dist/usage-stores.js +3 -1
- package/package.json +1 -1
|
@@ -59,6 +59,7 @@ export function extractOAuthSubscriptionAccessToken(raw) {
|
|
|
59
59
|
return parseOAuthSubscriptionTokens(raw)?.access_token ?? null;
|
|
60
60
|
}
|
|
61
61
|
const CODEX = OAUTH_PROVIDER_CONTRACTS['openai-codex'];
|
|
62
|
+
const COPILOT = OAUTH_PROVIDER_CONTRACTS['github-copilot'];
|
|
62
63
|
const XAI = OAUTH_PROVIDER_CONTRACTS['xai-oauth'];
|
|
63
64
|
const OAUTH_REFRESH_LEASE_MS = 30_000;
|
|
64
65
|
const OAUTH_REFRESH_REQUEST_TIMEOUT_MS = 20_000;
|
|
@@ -324,7 +325,7 @@ export async function refreshOAuthSubscriptionTokens(input) {
|
|
|
324
325
|
case 'openai-codex':
|
|
325
326
|
return refreshOpenAiCodexTokens(input.tokens, now, fetchFn, input.signal);
|
|
326
327
|
case 'github-copilot':
|
|
327
|
-
return input.tokens;
|
|
328
|
+
return refreshGitHubCopilotTokens(input.tokens, now, fetchFn, input.signal);
|
|
328
329
|
case 'xai-oauth':
|
|
329
330
|
return refreshXaiOAuthTokens(input.tokens, now, fetchFn, input.signal);
|
|
330
331
|
}
|
|
@@ -337,11 +338,19 @@ export const GITHUB_COPILOT_COMPAT_HEADERS = {
|
|
|
337
338
|
'Editor-Plugin-Version': 'copilot-chat/0.35.0',
|
|
338
339
|
'Copilot-Integration-Id': 'vscode-chat',
|
|
339
340
|
};
|
|
340
|
-
|
|
341
|
+
/**
|
|
342
|
+
* A GitHub account token GitHub declared no lifetime for. Recorded as an
|
|
343
|
+
* explicit sentinel because it is the one thing that distinguishes a
|
|
344
|
+
* non-refreshable record from one carrying a real `expires_in`.
|
|
345
|
+
*/
|
|
346
|
+
export const GITHUB_COPILOT_NON_EXPIRING_AT = Number.MAX_SAFE_INTEGER;
|
|
347
|
+
export function createGitHubCopilotAccountTokens(githubToken, lifetime) {
|
|
341
348
|
return {
|
|
342
349
|
access_token: githubToken,
|
|
343
|
-
|
|
344
|
-
expires_at
|
|
350
|
+
// A non-expiring token has no refresh grant behind it, so it stands in as
|
|
351
|
+
// its own refresh token; `expires_at` is what tells the two records apart.
|
|
352
|
+
refresh_token: lifetime?.refreshToken ?? githubToken,
|
|
353
|
+
expires_at: lifetime?.expiresAt ?? GITHUB_COPILOT_NON_EXPIRING_AT,
|
|
345
354
|
token_type: 'Bearer',
|
|
346
355
|
base_url: GITHUB_COPILOT_DEFAULT_API_ENDPOINT,
|
|
347
356
|
};
|
|
@@ -395,6 +404,44 @@ async function refreshOpenAiCodexTokens(tokens, now, fetchFn, signal) {
|
|
|
395
404
|
account_id: tokens.account_id,
|
|
396
405
|
};
|
|
397
406
|
}
|
|
407
|
+
async function refreshGitHubCopilotTokens(tokens, now, fetchFn, signal) {
|
|
408
|
+
// A non-expiring account token is its own authority: GitHub issues no
|
|
409
|
+
// refresh grant for it, so returning it unchanged IS the refresh.
|
|
410
|
+
if (tokens.expires_at === GITHUB_COPILOT_NON_EXPIRING_AT)
|
|
411
|
+
return tokens;
|
|
412
|
+
const response = await fetchFn(COPILOT.tokenEndpoint, {
|
|
413
|
+
method: 'POST',
|
|
414
|
+
headers: {
|
|
415
|
+
Accept: 'application/json',
|
|
416
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
417
|
+
},
|
|
418
|
+
body: new URLSearchParams({
|
|
419
|
+
grant_type: 'refresh_token',
|
|
420
|
+
client_id: COPILOT.clientId,
|
|
421
|
+
refresh_token: tokens.refresh_token,
|
|
422
|
+
}).toString(),
|
|
423
|
+
signal,
|
|
424
|
+
});
|
|
425
|
+
if (!response.ok) {
|
|
426
|
+
throw new Error(`GitHub Copilot OAuth token refresh failed (${response.status}).`);
|
|
427
|
+
}
|
|
428
|
+
const payload = requireOAuthDataRecord(await response.json());
|
|
429
|
+
// GitHub reports a rejected refresh as HTTP 200 with an `error` body, so an
|
|
430
|
+
// ok status alone must not be allowed to replace the stored authority.
|
|
431
|
+
if (typeof payload.error === 'string') {
|
|
432
|
+
throw new Error('GitHub Copilot OAuth token refresh was rejected.');
|
|
433
|
+
}
|
|
434
|
+
const { record, accessToken, expiresInSeconds } = requireRefreshedTokenFields(payload);
|
|
435
|
+
if (!isSupportedGitHubCopilotAccountToken(accessToken)) {
|
|
436
|
+
throw new Error('GitHub Copilot OAuth token refresh returned an unsupported token.');
|
|
437
|
+
}
|
|
438
|
+
return {
|
|
439
|
+
...tokens,
|
|
440
|
+
access_token: accessToken,
|
|
441
|
+
refresh_token: nextRefreshToken(record.refresh_token, tokens.refresh_token),
|
|
442
|
+
expires_at: oauthExpiresAt(now(), expiresInSeconds),
|
|
443
|
+
};
|
|
444
|
+
}
|
|
398
445
|
async function refreshXaiOAuthTokens(tokens, now, fetchFn, signal) {
|
|
399
446
|
const response = await fetchFn(XAI.tokenEndpoint, {
|
|
400
447
|
method: 'POST',
|
|
@@ -24,7 +24,12 @@ export function buildSubscriptionModelFetch(input) {
|
|
|
24
24
|
return buildOpenAiCodexFetch(input.sessionId, input.fetchFn ?? fetch, input.refreshOAuthAccessToken);
|
|
25
25
|
}
|
|
26
26
|
if (input.connection.providerType === 'github-copilot') {
|
|
27
|
-
|
|
27
|
+
const copilotFetch = buildGitHubCopilotFetch(input.fetchFn ?? fetch);
|
|
28
|
+
// The editor headers stay innermost so a replayed request carries them
|
|
29
|
+
// exactly as the first attempt did.
|
|
30
|
+
return input.refreshOAuthAccessToken
|
|
31
|
+
? buildOAuth401ReplayFetch(copilotFetch, input.refreshOAuthAccessToken)
|
|
32
|
+
: copilotFetch;
|
|
28
33
|
}
|
|
29
34
|
if (input.connection.providerType === 'xai-oauth' && input.refreshOAuthAccessToken) {
|
|
30
35
|
return buildOAuth401ReplayFetch(input.fetchFn ?? fetch, input.refreshOAuthAccessToken);
|
|
@@ -156,7 +161,20 @@ async function checkedOpenAiCodexFetch(fetchFn, url, init, refreshOAuthAccessTok
|
|
|
156
161
|
refreshOAuthAccessToken &&
|
|
157
162
|
isReplayableOpenAiCodexRequest(url, requestInit)) {
|
|
158
163
|
authorizationReplayUsed = true;
|
|
159
|
-
const
|
|
164
|
+
const refreshSignal = effectiveOpenAiCodexRequestSignal(url, requestInit);
|
|
165
|
+
let accessToken;
|
|
166
|
+
try {
|
|
167
|
+
accessToken = await refreshOAuthAccessToken(refreshSignal);
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
// Same rule as the shared replay path: an abandoned turn is cancelled,
|
|
171
|
+
// not reported as a provider rejection.
|
|
172
|
+
if (refreshSignal?.aborted)
|
|
173
|
+
await abandonForCaller(response, refreshSignal);
|
|
174
|
+
accessToken = null;
|
|
175
|
+
}
|
|
176
|
+
if (refreshSignal?.aborted)
|
|
177
|
+
await abandonForCaller(response, refreshSignal);
|
|
160
178
|
if (accessToken) {
|
|
161
179
|
await response.body?.cancel().catch(() => undefined);
|
|
162
180
|
requestInit = withRefreshedOAuthAuthorization(requestInit, accessToken, true);
|
|
@@ -179,13 +197,39 @@ function buildOAuth401ReplayFetch(fetchFn, refreshOAuthAccessToken) {
|
|
|
179
197
|
const response = await fetchFn(url, init);
|
|
180
198
|
if (response.status !== 401 || !isReplayableOpenAiCodexRequest(url, init))
|
|
181
199
|
return response;
|
|
182
|
-
const
|
|
200
|
+
const signal = effectiveOpenAiCodexRequestSignal(url, init);
|
|
201
|
+
// A caller who gave up is cancelled, not told their credential was
|
|
202
|
+
// rejected: once the turn is abandoned the 401 answers nothing, and
|
|
203
|
+
// reporting it would read as an auth failure the user has to act on.
|
|
204
|
+
if (signal?.aborted)
|
|
205
|
+
await abandonForCaller(response, signal);
|
|
206
|
+
let accessToken;
|
|
207
|
+
try {
|
|
208
|
+
accessToken = await refreshOAuthAccessToken(signal);
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
if (signal?.aborted)
|
|
212
|
+
await abandonForCaller(response, signal);
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
if (signal?.aborted)
|
|
216
|
+
await abandonForCaller(response, signal);
|
|
183
217
|
if (!accessToken)
|
|
184
218
|
return response;
|
|
185
219
|
await response.body?.cancel().catch(() => undefined);
|
|
186
220
|
return fetchFn(url, withRefreshedOAuthAuthorization(init, accessToken, false));
|
|
187
221
|
};
|
|
188
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Ends a request the caller abandoned: releases the provider body, then throws
|
|
225
|
+
* the abort reason so the turn settles as cancelled rather than as whatever
|
|
226
|
+
* status happened to be in flight.
|
|
227
|
+
*/
|
|
228
|
+
async function abandonForCaller(response, signal) {
|
|
229
|
+
await response.body?.cancel().catch(() => undefined);
|
|
230
|
+
signal.throwIfAborted();
|
|
231
|
+
throw new DOMException('Request aborted', 'AbortError');
|
|
232
|
+
}
|
|
189
233
|
function withRefreshedOAuthAuthorization(init, accessToken, codex) {
|
|
190
234
|
const headers = new Headers(init?.headers);
|
|
191
235
|
headers.set('Authorization', `Bearer ${accessToken}`);
|
|
@@ -51,8 +51,27 @@ Use fenced code blocks for multiline code and backticks for inline commands, pat
|
|
|
51
51
|
Prefer descriptive link text for external sources when it is available.
|
|
52
52
|
Follow a more specific format requested by the user or task.`;
|
|
53
53
|
}
|
|
54
|
+
function buildProgressUpdatesPromptFragment() {
|
|
55
|
+
return `## Progress updates
|
|
56
|
+
|
|
57
|
+
For tasks that require tools or multiple steps, send a brief user-facing progress update before the first non-trivial tool call.
|
|
58
|
+
The opening update should name the concrete area you will inspect or change and what you expect to learn or accomplish.
|
|
59
|
+
Send another update only when you reach a meaningful phase change, discover information that changes the plan, finish a long-running operation, or have completed several non-trivial tool calls without any user-visible update.
|
|
60
|
+
Later updates should state a concrete finding or completed milestone and the next action when more work remains.
|
|
61
|
+
When more work remains, put the progress update before the next tool call in the same response. Do not end a response after merely saying what you will do.
|
|
62
|
+
Keep most updates to one concise sentence and never more than two short sentences.
|
|
63
|
+
Avoid empty narration such as "I will take a look", "Working on it", "Continuing", or announcing a routine tool choice. Describe useful intent, findings, decisions, or changed direction instead.
|
|
64
|
+
Do not expose hidden reasoning or repeat commands, tool names, counts, durations, or other raw activity that the interface already shows.
|
|
65
|
+
Skip progress updates only when no tool is needed or exactly one obvious, quick tool call answers the whole request.
|
|
66
|
+
End the turn with a distinct final answer that states the outcome.`;
|
|
67
|
+
}
|
|
54
68
|
export function assembleMainSessionSystemPrompt(fragments) {
|
|
55
|
-
return [
|
|
69
|
+
return [
|
|
70
|
+
buildIdentityPromptFragment(),
|
|
71
|
+
buildResponseFormatPromptFragment(),
|
|
72
|
+
buildProgressUpdatesPromptFragment(),
|
|
73
|
+
...fragments,
|
|
74
|
+
]
|
|
56
75
|
.filter((fragment) => Boolean(fragment?.trim()))
|
|
57
76
|
.join('\n\n');
|
|
58
77
|
}
|
|
@@ -16,12 +16,14 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { randomUUID } from 'node:crypto';
|
|
19
20
|
import { PROVIDER_REGISTRY, providerDefaultsOf, providerFallbackModelIds, connectionModelsEnumerateAccount, connectionEnabledModelIds, } from '@maka/core/llm-connections';
|
|
20
21
|
import { anthropicV1Url, googleApiUrl, openResponsesUrl } from './provider-urls.js';
|
|
21
22
|
import { resolveModelRuntime } from './model-runtime.js';
|
|
22
23
|
import { fetchGitHubCopilotModels } from './model-fetcher.js';
|
|
23
24
|
import { CONNECTION_EFFECT_ERROR_BODY_MAX_BYTES, ConnectionEffectFetchError, fetchForConnectionEffect, } from './connection-effect-fetch.js';
|
|
24
25
|
import { ConnectionEffectHttpError, ConnectionEffectInvalidResponseError, classifyConnectionEffectStatus, } from './connection-effect-outcome.js';
|
|
26
|
+
import { withOpenCodeSessionHeader } from './opencode-session-header.js';
|
|
25
27
|
const CONNECTION_TEST_TIMEOUT_MS = 15_000;
|
|
26
28
|
/**
|
|
27
29
|
* Prefer an explicit model, then a still-live configured model. Legacy
|
|
@@ -103,6 +105,7 @@ async function testConnectionStrict(connection, apiKey, model, fetchFn, t0, time
|
|
|
103
105
|
if (!defaults) {
|
|
104
106
|
return { ok: false, errorMessage: `Unknown provider type "${connection.providerType}"` };
|
|
105
107
|
}
|
|
108
|
+
const sessionId = connection.providerType === 'opencode-go' ? randomUUID() : undefined;
|
|
106
109
|
const auth = defaults.authKind;
|
|
107
110
|
const secret = auth === 'none' ? '' : apiKey;
|
|
108
111
|
const testModel = resolveConnectionTestModel(connection, model, providerFallbackModelIds(defaults));
|
|
@@ -123,7 +126,7 @@ async function testConnectionStrict(connection, apiKey, model, fetchFn, t0, time
|
|
|
123
126
|
const remainingCandidates = candidates.length - index;
|
|
124
127
|
const attemptTimeoutMs = Math.max(1, Math.floor(remainingMs / remainingCandidates));
|
|
125
128
|
try {
|
|
126
|
-
const result = await testConnectionModel(connection, secret, candidate, fetchFn, t0, attemptTimeoutMs);
|
|
129
|
+
const result = await testConnectionModel(connection, secret, candidate, fetchFn, t0, attemptTimeoutMs, sessionId);
|
|
127
130
|
if (result.ok)
|
|
128
131
|
return result;
|
|
129
132
|
lastFailure = result;
|
|
@@ -134,9 +137,9 @@ async function testConnectionStrict(connection, apiKey, model, fetchFn, t0, time
|
|
|
134
137
|
}
|
|
135
138
|
return lastFailure ?? connectionTestFailure(new ConnectionEffectFetchError('timeout'), t0);
|
|
136
139
|
}
|
|
137
|
-
return await testConnectionModel(connection, secret, testModel, fetchFn, t0, timeoutMs);
|
|
140
|
+
return await testConnectionModel(connection, secret, testModel, fetchFn, t0, timeoutMs, sessionId);
|
|
138
141
|
}
|
|
139
|
-
async function testConnectionModel(connection, secret, testModel, fetchFn, t0, timeoutMs = CONNECTION_TEST_TIMEOUT_MS) {
|
|
142
|
+
async function testConnectionModel(connection, secret, testModel, fetchFn, t0, timeoutMs = CONNECTION_TEST_TIMEOUT_MS, sessionId) {
|
|
140
143
|
// Ahead of `resolveModelRuntime`, which throws for an adapter it cannot name.
|
|
141
144
|
// A stored connection can still be opened long after its provider stopped
|
|
142
145
|
// being offered, and the caller renders this result — so a retired provider
|
|
@@ -145,23 +148,24 @@ async function testConnectionModel(connection, secret, testModel, fetchFn, t0, t
|
|
|
145
148
|
return retiredProviderTestResult(connection.providerType);
|
|
146
149
|
}
|
|
147
150
|
const { adapter, baseUrl, wire } = resolveModelRuntime(connection, testModel);
|
|
151
|
+
const requestHeaders = withOpenCodeSessionHeader(connection.providerType, sessionId);
|
|
148
152
|
switch (adapter.kind) {
|
|
149
153
|
case 'anthropic':
|
|
150
|
-
return await probeAnthropic(connection, baseUrl, secret, testModel, t0, fetchFn);
|
|
154
|
+
return await probeAnthropic(connection, baseUrl, secret, testModel, t0, fetchFn, requestHeaders);
|
|
151
155
|
case 'unavailable':
|
|
152
156
|
// Unreachable: the guard above returns first. The arm keeps the switch
|
|
153
157
|
// exhaustive so a newly retired provider cannot slip past it.
|
|
154
158
|
return retiredProviderTestResult(connection.providerType);
|
|
155
159
|
case 'openai':
|
|
156
160
|
return wire === 'openai-responses'
|
|
157
|
-
? await probeOpenAIResponses(baseUrl, secret, testModel, t0, fetchFn)
|
|
158
|
-
: await probeOpenAI(connection, baseUrl, secret, testModel, t0, fetchFn, timeoutMs);
|
|
161
|
+
? await probeOpenAIResponses(baseUrl, secret, testModel, t0, fetchFn, requestHeaders)
|
|
162
|
+
: await probeOpenAI(connection, baseUrl, secret, testModel, t0, fetchFn, timeoutMs, requestHeaders);
|
|
159
163
|
case 'openai-codex':
|
|
160
164
|
return await probeOpenAI(connection, baseUrl, secret, testModel, t0, fetchFn, timeoutMs);
|
|
161
165
|
case 'openai-compatible':
|
|
162
166
|
return wire === 'openai-responses'
|
|
163
|
-
? await probeOpenAIResponses(baseUrl, secret, testModel, t0, fetchFn)
|
|
164
|
-
: await probeOpenAI(connection, baseUrl, secret, testModel, t0, fetchFn, timeoutMs);
|
|
167
|
+
? await probeOpenAIResponses(baseUrl, secret, testModel, t0, fetchFn, requestHeaders)
|
|
168
|
+
: await probeOpenAI(connection, baseUrl, secret, testModel, t0, fetchFn, timeoutMs, requestHeaders);
|
|
165
169
|
case 'github-copilot':
|
|
166
170
|
return await probeGitHubCopilot(baseUrl, secret, testModel, t0, fetchFn);
|
|
167
171
|
case 'google':
|
|
@@ -180,10 +184,11 @@ async function probeGitHubCopilot(baseUrl, apiKey, model, t0, fetchFn) {
|
|
|
180
184
|
}
|
|
181
185
|
return { ok: true, latencyMs: Date.now() - t0, modelTested: model };
|
|
182
186
|
}
|
|
183
|
-
async function probeOpenAIResponses(baseUrl, apiKey, model, t0, fetchFn) {
|
|
187
|
+
async function probeOpenAIResponses(baseUrl, apiKey, model, t0, fetchFn, requestHeaders) {
|
|
184
188
|
const r = await fetchForConnectionEffect(fetchFn, openResponsesUrl(baseUrl), {
|
|
185
189
|
method: 'POST',
|
|
186
190
|
headers: {
|
|
191
|
+
...requestHeaders,
|
|
187
192
|
authorization: `Bearer ${apiKey}`,
|
|
188
193
|
'content-type': 'application/json',
|
|
189
194
|
},
|
|
@@ -222,8 +227,9 @@ async function probeCohere(baseUrl, apiKey, model, t0, fetchFn) {
|
|
|
222
227
|
function retiredProviderTestResult(providerType) {
|
|
223
228
|
return { ok: false, errorMessage: `"${providerType}" is retired and can no longer be used.` };
|
|
224
229
|
}
|
|
225
|
-
async function probeAnthropic(connection, baseUrl, secret, model, t0, fetchFn) {
|
|
230
|
+
async function probeAnthropic(connection, baseUrl, secret, model, t0, fetchFn, requestHeaders) {
|
|
226
231
|
const headers = {
|
|
232
|
+
...requestHeaders,
|
|
227
233
|
'x-api-key': secret,
|
|
228
234
|
'anthropic-version': '2023-06-01',
|
|
229
235
|
'content-type': 'application/json',
|
|
@@ -243,7 +249,7 @@ async function probeAnthropic(connection, baseUrl, secret, model, t0, fetchFn) {
|
|
|
243
249
|
await r.cancel();
|
|
244
250
|
return { ok: true, latencyMs: Date.now() - t0, modelTested: model };
|
|
245
251
|
}
|
|
246
|
-
async function probeOpenAI(connection, baseUrl, apiKey, model, t0, fetchFn, timeoutMs = CONNECTION_TEST_TIMEOUT_MS) {
|
|
252
|
+
async function probeOpenAI(connection, baseUrl, apiKey, model, t0, fetchFn, timeoutMs = CONNECTION_TEST_TIMEOUT_MS, requestHeaders) {
|
|
247
253
|
if (connection.providerType === 'openai-codex') {
|
|
248
254
|
// Codex Subscription credentials are ChatGPT account-scoped OAuth
|
|
249
255
|
// tokens. A live `/responses` probe is not a stable readiness test:
|
|
@@ -257,6 +263,7 @@ async function probeOpenAI(connection, baseUrl, apiKey, model, t0, fetchFn, time
|
|
|
257
263
|
const r = await fetchForConnectionEffect(fetchFn, `${stripTrailing(baseUrl)}/chat/completions`, {
|
|
258
264
|
method: 'POST',
|
|
259
265
|
headers: {
|
|
266
|
+
...requestHeaders,
|
|
260
267
|
...(apiKey ? { authorization: `Bearer ${apiKey}` } : {}),
|
|
261
268
|
'content-type': 'application/json',
|
|
262
269
|
},
|
|
@@ -21,6 +21,7 @@ import { projectAgentSwarmResult } from '@maka/core/agent-swarm';
|
|
|
21
21
|
import { projectToolActivityArgs } from '@maka/core/tool-activity-args';
|
|
22
22
|
import { serializedByteLength } from '@maka/core/serialized-byte-length';
|
|
23
23
|
import { encodeToolStepProgress, ToolOutcomeUnknownError } from '@maka/core/events';
|
|
24
|
+
import { isInteractionAnswerValidForRequest, projectInteractionFormRequest, } from '@maka/core/interaction';
|
|
24
25
|
import { computerUseModelCallArgs } from '@maka/core/computer-use';
|
|
25
26
|
import { redactSecrets } from '@maka/core/redaction';
|
|
26
27
|
import { decodeRuntimeEvent, MANAGED_MUTATION_EXECUTION_PROFILE_V1_DIGEST, MANAGED_MUTATION_EXECUTION_PROFILE_V1_SPEC, TOOL_BOUNDARY_PROTOCOL_V1, } from '@maka/core/runtime-event';
|
|
@@ -91,10 +92,12 @@ export class ToolRuntime {
|
|
|
91
92
|
input;
|
|
92
93
|
sandboxBoundaryRequests = new AwaitRegistry();
|
|
93
94
|
userQuestions = new AwaitRegistry();
|
|
95
|
+
userForms = new AwaitRegistry();
|
|
94
96
|
turnId;
|
|
95
97
|
hostedInteraction;
|
|
96
98
|
sandboxBoundaryClosureDeferred = false;
|
|
97
99
|
questionClosureDeferred = false;
|
|
100
|
+
formClosureDeferred = false;
|
|
98
101
|
activeSubagentToolCount = 0;
|
|
99
102
|
childAgentRunLimiter = new AdmissionLimiter(MAX_ACTIVE_CHILD_AGENT_RUNS_PER_TURN);
|
|
100
103
|
/**
|
|
@@ -171,6 +174,7 @@ export class ToolRuntime {
|
|
|
171
174
|
}
|
|
172
175
|
}
|
|
173
176
|
const hasHostedPending = this.userQuestions.entries().some(([, question]) => question.hosted);
|
|
177
|
+
const hasHostedFormPending = this.userForms.entries().some(([, form]) => form.hosted);
|
|
174
178
|
if (hasHostedBoundaryPending) {
|
|
175
179
|
this.sandboxBoundaryClosureDeferred = true;
|
|
176
180
|
this.finishDeferredSandboxBoundaryTurnClosure();
|
|
@@ -187,6 +191,14 @@ export class ToolRuntime {
|
|
|
187
191
|
this.userQuestions.close((requestId) => new Error(`Turn ${turnId} ${reason} before user question ${requestId} was answered`));
|
|
188
192
|
this.questionClosureDeferred = false;
|
|
189
193
|
}
|
|
194
|
+
if (hasHostedFormPending) {
|
|
195
|
+
this.formClosureDeferred = true;
|
|
196
|
+
this.finishDeferredFormTurnClosure();
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
this.userForms.close((requestId) => new Error(`Turn ${turnId} ${reason} before user form ${requestId} was answered`));
|
|
200
|
+
this.formClosureDeferred = false;
|
|
201
|
+
}
|
|
190
202
|
this.resetTurnState();
|
|
191
203
|
// The stop path settles the run's terminal fact right after the
|
|
192
204
|
// backend's stop resolves, and that stop awaits this method. Unwinds
|
|
@@ -215,6 +227,20 @@ export class ToolRuntime {
|
|
|
215
227
|
}
|
|
216
228
|
return this.settleUserQuestionAnswer(turnId, response, pending);
|
|
217
229
|
}
|
|
230
|
+
respondToUserForm(response) {
|
|
231
|
+
if (!response || typeof response.requestId !== 'string') {
|
|
232
|
+
throw new Error('Invalid user form response');
|
|
233
|
+
}
|
|
234
|
+
const pending = this.userForms
|
|
235
|
+
.entries()
|
|
236
|
+
.find(([requestId]) => requestId === response.requestId)?.[1];
|
|
237
|
+
if (!pending)
|
|
238
|
+
return false;
|
|
239
|
+
if (pending.hosted) {
|
|
240
|
+
throw new RuntimeInteractionInvariantError(`Hosted form ${response.requestId} must settle through its captured continuation`);
|
|
241
|
+
}
|
|
242
|
+
return this.settleUserFormAnswer(response, pending);
|
|
243
|
+
}
|
|
218
244
|
async respondToSandboxBoundaryResponse(response) {
|
|
219
245
|
if (!this.sandboxBoundaryRequests.has(response.requestId))
|
|
220
246
|
return false;
|
|
@@ -250,15 +276,35 @@ export class ToolRuntime {
|
|
|
250
276
|
this.finishDeferredQuestionTurnClosure();
|
|
251
277
|
return resolved;
|
|
252
278
|
}
|
|
279
|
+
settleUserFormAnswer(response, pending) {
|
|
280
|
+
const answer = response.action === 'accept'
|
|
281
|
+
? { kind: 'form', action: 'accept', values: response.values }
|
|
282
|
+
: { kind: 'form', action: response.action };
|
|
283
|
+
if (!isInteractionAnswerValidForRequest(pending.request, answer)) {
|
|
284
|
+
throw new Error('Invalid user form response');
|
|
285
|
+
}
|
|
286
|
+
const resolved = this.userForms.resolve(response.requestId, response) !== null;
|
|
287
|
+
this.finishDeferredFormTurnClosure();
|
|
288
|
+
return resolved;
|
|
289
|
+
}
|
|
253
290
|
closeUserQuestion(turnId, requestId, reason) {
|
|
254
291
|
const closed = this.userQuestions.reject(requestId, new RuntimeInteractionClosedError(requestId, reason)) !==
|
|
255
292
|
null;
|
|
256
293
|
this.finishDeferredQuestionTurnClosure();
|
|
257
294
|
return closed;
|
|
258
295
|
}
|
|
296
|
+
closeUserForm(requestId, reason) {
|
|
297
|
+
const closed = this.userForms.reject(requestId, new RuntimeInteractionClosedError(requestId, reason)) !==
|
|
298
|
+
null;
|
|
299
|
+
this.finishDeferredFormTurnClosure();
|
|
300
|
+
return closed;
|
|
301
|
+
}
|
|
259
302
|
pendingUserQuestionCount() {
|
|
260
303
|
return this.userQuestions.pendingCount();
|
|
261
304
|
}
|
|
305
|
+
pendingUserFormCount() {
|
|
306
|
+
return this.userForms.pendingCount();
|
|
307
|
+
}
|
|
262
308
|
/**
|
|
263
309
|
* Settle one resolved Maka tool call. Tool/business failures resolve with a
|
|
264
310
|
* provider-facing error output; durable runtime commit failures still reject.
|
|
@@ -1020,6 +1066,7 @@ export class ToolRuntime {
|
|
|
1020
1066
|
activityIdentity,
|
|
1021
1067
|
}),
|
|
1022
1068
|
askUserQuestion: (questions) => this.askUserQuestion(turnId, toolUseId, questions, ctx.abortSignal, queue),
|
|
1069
|
+
requestUserForm: (form, options) => this.requestUserForm(turnId, toolUseId, form, ctx.abortSignal, queue, options?.cancellationSignal),
|
|
1023
1070
|
requestSandboxBoundary: (expansion, justification) => this.requestSandboxBoundary(turnId, toolUseId, expansion, justification, ctx.abortSignal, queue),
|
|
1024
1071
|
};
|
|
1025
1072
|
const invokeTool = () => preparedExecution
|
|
@@ -1775,6 +1822,112 @@ export class ToolRuntime {
|
|
|
1775
1822
|
: {}),
|
|
1776
1823
|
};
|
|
1777
1824
|
}
|
|
1825
|
+
async requestUserForm(turnId, toolUseId, form, abortSignal, queue, producerCancellationSignal) {
|
|
1826
|
+
const interactionSignal = composeChildAbortSignal(abortSignal, producerCancellationSignal);
|
|
1827
|
+
throwIfAborted(interactionSignal);
|
|
1828
|
+
const hostedRun = this.interactionRun();
|
|
1829
|
+
const requestId = this.input.newId();
|
|
1830
|
+
const request = projectInteractionFormRequest({ toolUseId, ...form });
|
|
1831
|
+
const parked = this.userForms.park(requestId, {
|
|
1832
|
+
toolUseId,
|
|
1833
|
+
request,
|
|
1834
|
+
hosted: hostedRun !== undefined,
|
|
1835
|
+
});
|
|
1836
|
+
const onAbort = () => {
|
|
1837
|
+
if (hostedRun)
|
|
1838
|
+
return;
|
|
1839
|
+
this.userForms.reject(requestId, abortErrorFromSignal(abortSignal));
|
|
1840
|
+
this.finishDeferredFormTurnClosure();
|
|
1841
|
+
};
|
|
1842
|
+
let hostedAdmission;
|
|
1843
|
+
let producerWithdrawal;
|
|
1844
|
+
const onProducerCancellation = () => {
|
|
1845
|
+
if (abortSignal.aborted)
|
|
1846
|
+
return;
|
|
1847
|
+
if (hostedRun) {
|
|
1848
|
+
producerWithdrawal ??= Promise.resolve().then(async () => {
|
|
1849
|
+
try {
|
|
1850
|
+
await hostedAdmission;
|
|
1851
|
+
}
|
|
1852
|
+
catch {
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
await hostedRun.withdrawFormRequest(requestId);
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
else if (producerCancellationSignal) {
|
|
1859
|
+
this.userForms.reject(requestId, abortErrorFromSignal(producerCancellationSignal));
|
|
1860
|
+
this.finishDeferredFormTurnClosure();
|
|
1861
|
+
}
|
|
1862
|
+
};
|
|
1863
|
+
abortSignal.addEventListener('abort', onAbort, { once: true });
|
|
1864
|
+
producerCancellationSignal?.addEventListener('abort', onProducerCancellation, { once: true });
|
|
1865
|
+
if (hostedRun)
|
|
1866
|
+
void parked.catch(() => undefined);
|
|
1867
|
+
try {
|
|
1868
|
+
const requestEvent = {
|
|
1869
|
+
type: 'form_request',
|
|
1870
|
+
id: this.input.newId(),
|
|
1871
|
+
turnId,
|
|
1872
|
+
ts: this.input.now(),
|
|
1873
|
+
requestId,
|
|
1874
|
+
toolUseId,
|
|
1875
|
+
message: request.message,
|
|
1876
|
+
requester: request.requester,
|
|
1877
|
+
fields: request.fields,
|
|
1878
|
+
};
|
|
1879
|
+
if (hostedRun) {
|
|
1880
|
+
const settlement = this.createFormSettlement(turnId, requestId);
|
|
1881
|
+
const admission = Promise.resolve().then(() => hostedRun.admitFormRequest({ request: requestEvent, settlement }));
|
|
1882
|
+
hostedAdmission = admission;
|
|
1883
|
+
try {
|
|
1884
|
+
await racePromiseWithAbort(admission, interactionSignal);
|
|
1885
|
+
}
|
|
1886
|
+
catch (error) {
|
|
1887
|
+
if (interactionSignal.aborted) {
|
|
1888
|
+
void admission.catch((admissionError) => {
|
|
1889
|
+
this.userForms.reject(requestId, admissionError instanceof Error
|
|
1890
|
+
? admissionError
|
|
1891
|
+
: new RuntimeInteractionFailStopError(`Could not confirm admission for form ${requestId}`, admissionError));
|
|
1892
|
+
this.finishDeferredFormTurnClosure();
|
|
1893
|
+
});
|
|
1894
|
+
throw abortErrorFromSignal(interactionSignal);
|
|
1895
|
+
}
|
|
1896
|
+
this.userForms.reject(requestId, error instanceof Error
|
|
1897
|
+
? error
|
|
1898
|
+
: new RuntimeInteractionFailStopError(`Could not confirm admission for form ${requestId}`, error));
|
|
1899
|
+
this.finishDeferredFormTurnClosure();
|
|
1900
|
+
await parked.catch(() => undefined);
|
|
1901
|
+
throw interactionAuthorityError(`Could not confirm admission for form ${requestId}`, error);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
throwIfAborted(interactionSignal);
|
|
1905
|
+
queue.push(requestEvent);
|
|
1906
|
+
const response = await racePromiseWithAbort(parked, interactionSignal);
|
|
1907
|
+
throwIfAborted(interactionSignal);
|
|
1908
|
+
const answerAck = {
|
|
1909
|
+
type: 'form_answer_ack',
|
|
1910
|
+
id: this.input.newId(),
|
|
1911
|
+
turnId,
|
|
1912
|
+
ts: this.input.now(),
|
|
1913
|
+
requestId,
|
|
1914
|
+
toolUseId,
|
|
1915
|
+
};
|
|
1916
|
+
if (hostedRun)
|
|
1917
|
+
await this.publishHostedSettlementAck(queue, answerAck);
|
|
1918
|
+
else
|
|
1919
|
+
queue.push(answerAck);
|
|
1920
|
+
return response.action === 'accept'
|
|
1921
|
+
? { action: 'accept', values: response.values }
|
|
1922
|
+
: { action: response.action };
|
|
1923
|
+
}
|
|
1924
|
+
finally {
|
|
1925
|
+
abortSignal.removeEventListener('abort', onAbort);
|
|
1926
|
+
producerCancellationSignal?.removeEventListener('abort', onProducerCancellation);
|
|
1927
|
+
if (producerWithdrawal)
|
|
1928
|
+
await producerWithdrawal;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1778
1931
|
async askUserQuestion(turnId, toolUseId, questions, abortSignal, queue) {
|
|
1779
1932
|
throwIfAborted(abortSignal);
|
|
1780
1933
|
const hostedRun = this.interactionRun();
|
|
@@ -2084,6 +2237,13 @@ export class ToolRuntime {
|
|
|
2084
2237
|
this.questionClosureDeferred = false;
|
|
2085
2238
|
this.userQuestions.close((requestId) => new RuntimeInteractionInvariantError(`Hosted question ${requestId} escaped exact Run closure`));
|
|
2086
2239
|
}
|
|
2240
|
+
finishDeferredFormTurnClosure() {
|
|
2241
|
+
const turnId = this.turnId;
|
|
2242
|
+
if (!this.formClosureDeferred || this.userForms.pendingCount() !== 0)
|
|
2243
|
+
return;
|
|
2244
|
+
this.formClosureDeferred = false;
|
|
2245
|
+
this.userForms.close((requestId) => new RuntimeInteractionInvariantError(`Hosted form ${requestId} escaped exact Run closure for turn ${turnId}`));
|
|
2246
|
+
}
|
|
2087
2247
|
finishDeferredSandboxBoundaryTurnClosure() {
|
|
2088
2248
|
const turnId = this.turnId;
|
|
2089
2249
|
if (!this.sandboxBoundaryClosureDeferred || this.sandboxBoundaryRequests.pendingCount() !== 0) {
|
|
@@ -2133,6 +2293,29 @@ export class ToolRuntime {
|
|
|
2133
2293
|
},
|
|
2134
2294
|
});
|
|
2135
2295
|
}
|
|
2296
|
+
createFormSettlement(turnId, requestId) {
|
|
2297
|
+
return Object.freeze({
|
|
2298
|
+
applyAnswer: async (answer) => {
|
|
2299
|
+
if (Object.hasOwn(answer, 'requestId')) {
|
|
2300
|
+
throw new RuntimeInteractionInvariantError(`Form settlement ${requestId} received a routed answer`);
|
|
2301
|
+
}
|
|
2302
|
+
const pending = this.userForms
|
|
2303
|
+
.entries()
|
|
2304
|
+
.find(([candidateId]) => candidateId === requestId)?.[1];
|
|
2305
|
+
const response = answer.action === 'accept'
|
|
2306
|
+
? { requestId, action: 'accept', values: answer.values }
|
|
2307
|
+
: { requestId, action: answer.action };
|
|
2308
|
+
if (!pending || !this.settleUserFormAnswer(response, pending)) {
|
|
2309
|
+
throw new RuntimeInteractionInvariantError(`Form settlement did not take ${requestId} from turn ${turnId}`);
|
|
2310
|
+
}
|
|
2311
|
+
},
|
|
2312
|
+
applyClosure: async (reason) => {
|
|
2313
|
+
if (!this.closeUserForm(requestId, reason)) {
|
|
2314
|
+
throw new RuntimeInteractionInvariantError(`Form closure did not take ${requestId} from turn ${turnId}`);
|
|
2315
|
+
}
|
|
2316
|
+
},
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2136
2319
|
}
|
|
2137
2320
|
async function validateDeclaredToolArgs(parameters, args) {
|
|
2138
2321
|
if (!parameters || (typeof parameters !== 'object' && typeof parameters !== 'function')) {
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"./conversation-copy": "./dist/conversation-copy.js",
|
|
53
53
|
"./cua-frame-state": "./dist/cua-frame-state.js",
|
|
54
54
|
"./execution-inspect": "./dist/execution-inspect.js",
|
|
55
|
+
"./github-copilot-oauth-enrollment": "./dist/github-copilot-oauth-enrollment.js",
|
|
55
56
|
"./goal-continuation": "./dist/goal-continuation.js",
|
|
56
57
|
"./goal-evaluator": "./dist/goal-evaluator.js",
|
|
57
58
|
"./goal-state": "./dist/goal-state.js",
|
|
@@ -399,6 +399,9 @@ export class RuntimeHostSessionProjector {
|
|
|
399
399
|
turnId: root.turnId,
|
|
400
400
|
ts: this.#now(),
|
|
401
401
|
stopReason: 'end_turn',
|
|
402
|
+
...(root.contextCompactionOutcome
|
|
403
|
+
? { contextCompactionOutcome: root.contextCompactionOutcome }
|
|
404
|
+
: {}),
|
|
402
405
|
});
|
|
403
406
|
}
|
|
404
407
|
else if (root.status === 'failed') {
|
|
@@ -475,6 +478,17 @@ export function projectRuntimeHostInteractionRequest(interaction, now) {
|
|
|
475
478
|
},
|
|
476
479
|
];
|
|
477
480
|
}
|
|
481
|
+
if (interaction.request.kind === 'form') {
|
|
482
|
+
return [
|
|
483
|
+
{
|
|
484
|
+
type: 'form_request',
|
|
485
|
+
...base,
|
|
486
|
+
message: interaction.request.message,
|
|
487
|
+
requester: structuredClone(interaction.request.requester),
|
|
488
|
+
fields: structuredClone(interaction.request.fields),
|
|
489
|
+
},
|
|
490
|
+
];
|
|
491
|
+
}
|
|
478
492
|
if (interaction.request.kind === 'sandbox_boundary') {
|
|
479
493
|
return [
|
|
480
494
|
{
|