@andorra-labs/code 0.1.13 → 0.1.14
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/src/account-presentation.js +4 -1
- package/dist/src/agent-execution.js +300 -140
- package/dist/src/agent-mcp.js +2 -2
- package/dist/src/andorra/endpoint.d.ts +7 -0
- package/dist/src/andorra/endpoint.js +46 -0
- package/dist/src/andorra/entry.d.ts +21 -0
- package/dist/src/andorra/entry.js +100 -0
- package/dist/src/andorra/errors.d.ts +2 -0
- package/dist/src/andorra/errors.js +39 -0
- package/dist/src/andorra/hosted.d.ts +52 -0
- package/dist/src/andorra/hosted.js +126 -0
- package/dist/src/andorra/monitor.d.ts +151 -0
- package/dist/src/andorra/monitor.js +393 -0
- package/dist/src/andorra/notices.d.ts +7 -0
- package/dist/src/andorra/notices.js +15 -0
- package/dist/src/andorra/opt-in.d.ts +58 -0
- package/dist/src/andorra/opt-in.js +112 -0
- package/dist/src/andorra/request-watch.d.ts +6 -0
- package/dist/src/andorra/request-watch.js +10 -0
- package/dist/src/andorra/state.d.ts +86 -0
- package/dist/src/andorra/state.js +238 -0
- package/dist/src/andorra/terminal.d.ts +68 -0
- package/dist/src/andorra/terminal.js +125 -0
- package/dist/src/andorra/usage-format.d.ts +9 -0
- package/dist/src/andorra/usage-format.js +19 -0
- package/dist/src/anthropic-credentials.js +9 -1
- package/dist/src/app-server/protocol.d.ts +6 -2
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server.d.ts +27 -0
- package/dist/src/app-server.js +292 -85
- package/dist/src/auth/AuthManager.d.ts +9 -0
- package/dist/src/auth/AuthManager.js +161 -21
- package/dist/src/auth/deployment.d.ts +1 -0
- package/dist/src/auth/deployment.js +1 -0
- package/dist/src/auth/index.d.ts +1 -1
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/store.d.ts +26 -0
- package/dist/src/auth/store.js +34 -1
- package/dist/src/browser-runner.js +1 -1
- package/dist/src/browser-stealth.d.ts +19 -1
- package/dist/src/browser-stealth.js +23 -3
- package/dist/src/browser-ui/tokens.css +4 -4
- package/dist/src/browser-view.d.ts +65 -0
- package/dist/src/browser-view.js +229 -16
- package/dist/src/cli.js +43 -26
- package/dist/src/command-screens.d.ts +17 -1
- package/dist/src/command-screens.js +192 -21
- package/dist/src/commands.d.ts +7 -1
- package/dist/src/commands.js +78 -27
- package/dist/src/config.d.ts +6 -1
- package/dist/src/config.js +86 -3
- package/dist/src/dashboard-view.d.ts +2 -0
- package/dist/src/dashboard-view.js +11 -2
- package/dist/src/decision/PreparedSteps.js +1 -1
- package/dist/src/decision/applyToolMenu.js +1 -1
- package/dist/src/decision/toolFamilies.js +1 -1
- package/dist/src/decision/types.d.ts +1 -0
- package/dist/src/graph-health.d.ts +11 -0
- package/dist/src/graph-health.js +36 -4
- package/dist/src/graph-manager-chat.d.ts +33 -0
- package/dist/src/graph-manager-chat.js +159 -5
- package/dist/src/graph-runner.js +27 -0
- package/dist/src/graph-selection.js +2 -1
- package/dist/src/graph-ui/app.js +25 -2
- package/dist/src/graph-ui/manager.js +40 -5
- package/dist/src/graph-ui/style.css +5 -2
- package/dist/src/graph-ui/tokens.css +4 -4
- package/dist/src/graphs.js +1 -3
- package/dist/src/hardened-runtime.js +1 -1
- package/dist/src/membership-errors.js +1 -1
- package/dist/src/membership.d.ts +10 -2
- package/dist/src/membership.js +20 -6
- package/dist/src/model-context-windows.d.ts +2 -0
- package/dist/src/model-context-windows.js +24 -0
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +1 -0
- package/dist/src/model-metadata.js +40 -3
- package/dist/src/palette.d.ts +1 -0
- package/dist/src/palette.js +1 -1
- package/dist/src/permissions.js +17 -4
- package/dist/src/provider-connection.js +15 -0
- package/dist/src/provider-settings.d.ts +16 -1
- package/dist/src/provider-settings.js +36 -20
- package/dist/src/providers.d.ts +14 -2
- package/dist/src/providers.js +69 -11
- package/dist/src/react-runtime.js +12 -7
- package/dist/src/remote/engine-pool.js +5 -4
- package/dist/src/run-control.d.ts +2 -2
- package/dist/src/run-control.js +9 -6
- package/dist/src/runtime.d.ts +2 -0
- package/dist/src/runtime.js +2 -1
- package/dist/src/sessions.d.ts +1 -0
- package/dist/src/sessions.js +4 -2
- package/dist/src/skills/bundled/graph-manager/errors.md +1 -1
- package/dist/src/skills/bundled/provenance.json +738 -738
- package/dist/src/subagent-run.d.ts +2 -0
- package/dist/src/subagent-run.js +14 -3
- package/dist/src/telemetry/schema.d.ts +1 -1
- package/dist/src/telemetry/schema.js +2 -2
- package/dist/src/terminal-ui.d.ts +21 -0
- package/dist/src/terminal-ui.js +73 -10
- package/dist/src/transcript.js +3 -0
- package/dist/src/types.d.ts +3 -0
- package/dist/src/workspace-instructions.js +1 -1
- package/package.json +12 -1
package/dist/src/app-server.js
CHANGED
|
@@ -30,7 +30,7 @@ import { blockingHealthFailures, checkGraphModelHealth, formatGraphHealthFailure
|
|
|
30
30
|
import { bindPortableGraphProviders, GraphProviderUnavailableError } from './graph-provider-portability.js';
|
|
31
31
|
import { applyModelOverride, applyNodeModelOverrides } from './model-override.js';
|
|
32
32
|
import { freeTierGraphViolation, readGraphQuota } from './graph-quota.js';
|
|
33
|
-
import {
|
|
33
|
+
import { RETIRED_ANDORRA_SELECTION, SOFTWARE_ENGINEER_HARNESS, currentGraphSelection, getMembership, loadAccessibleGraph } from './membership.js';
|
|
34
34
|
import { loadProfile, saveProfile, ProfileAccountError, ProfileTextError } from './profile.js';
|
|
35
35
|
import { hostedDecisionPolicy } from './decision/hostedPolicy.js';
|
|
36
36
|
import { createAccountPresentationReader, publishableMembership } from './account-presentation.js';
|
|
@@ -44,7 +44,7 @@ import { writePendingAgentInteraction, removePendingAgentInteraction } from './s
|
|
|
44
44
|
import { summarizeSessionPrompt, titleRequestSupported } from './session-summary.js';
|
|
45
45
|
import { createTools } from './tools.js';
|
|
46
46
|
import { TimerRegistry, WAKE_RETRY_MS } from './timers.js';
|
|
47
|
-
import { confirmAutoFixWake, isFinishedPullRequest, markAutoFixDelivered, withoutPendingFix, newPullRequest, parsePullRequestUrl, PullRequestCreateDetector, pullRequestNeedsWatch, pullRequestSettings, PullRequestWatcher, readPullRequest, removePullRequest, runGh, applyPullRequestSettingsAsReadableAccount, noAccountMessage, readPullRequestAsAnyAccount, withPullRequest, writePullRequest } from './pull-requests.js';
|
|
47
|
+
import { confirmAutoFixWake, isFinishedPullRequest, markAutoFixDelivered, withoutPendingFix, newPullRequest, parsePullRequestUrl, PullRequestCreateDetector, pullRequestNeedsWatch, pullRequestSettings, PullRequestWatcher, listPullRequests, readPullRequest, removePullRequest, runGh, applyPullRequestSettingsAsReadableAccount, noAccountMessage, readPullRequestAsAnyAccount, withPullRequest, writePullRequest } from './pull-requests.js';
|
|
48
48
|
import { AutomationStore } from './automations.js';
|
|
49
49
|
import { executeAutomation } from './automation-runner.js';
|
|
50
50
|
import { automationService, automationServiceRunning, reconcileAutomationService } from './automation-service.js';
|
|
@@ -93,6 +93,13 @@ import { checkoutBranch, gitDiff, gitStatus, listBranches, listExtensions, listR
|
|
|
93
93
|
import { withReasoningEvents } from './app-server/reasoning.js';
|
|
94
94
|
import { APP_SERVER_PROTOCOL_VERSION, APP_SERVER_CAPABILITIES, } from './app-server/protocol.js';
|
|
95
95
|
import { RemotePeerError } from './remote/errors.js';
|
|
96
|
+
import { fallbackProviderId, hasAndorraEntry, virtualAndorraEntry } from './andorra/entry.js';
|
|
97
|
+
import { ANDORRA_CHANGED_MESSAGE, ANDORRA_UNAVAILABLE_MESSAGE } from './andorra/endpoint.js';
|
|
98
|
+
import { ANDORRA_ANNOUNCEMENT } from './andorra/notices.js';
|
|
99
|
+
import { ANDORRA_REMOVE_FAILED, recordAndorraRemoved, removingAndorraEntry } from './andorra/state.js';
|
|
100
|
+
import { addAndorraEntry, saveAndorraAnswer } from './andorra/opt-in.js';
|
|
101
|
+
import { HostedMonitor } from './andorra/monitor.js';
|
|
102
|
+
import { watchRequests } from './andorra/request-watch.js';
|
|
96
103
|
const SELECTION_HEALTH_TIMEOUT_MS = 60_000;
|
|
97
104
|
class AppServerError extends Error {
|
|
98
105
|
code;
|
|
@@ -367,6 +374,7 @@ function providerView(provider, providers) {
|
|
|
367
374
|
...(provider.apiKeyEnv === undefined ? {} : { apiKeyEnv: provider.apiKeyEnv }),
|
|
368
375
|
...(provider.models === undefined ? {} : { models: [...provider.models] }),
|
|
369
376
|
...(provider.modelContextWindows === undefined ? {} : { modelContextWindows: { ...provider.modelContextWindows } }),
|
|
377
|
+
...(provider.type !== 'andorra' || provider.modelNames === undefined ? {} : { modelNames: { ...provider.modelNames } }),
|
|
370
378
|
...(provider.contextWindow === undefined ? {} : { contextWindow: provider.contextWindow }),
|
|
371
379
|
...(provider.reasoningEffort === undefined ? {} : { reasoningEffort: provider.reasoningEffort }),
|
|
372
380
|
...(provider.requestTimeoutMs === undefined ? {} : { requestTimeoutMs: provider.requestTimeoutMs }),
|
|
@@ -510,6 +518,9 @@ export function mergeProviderSecrets(stored, incoming) {
|
|
|
510
518
|
if (previousEntry?.modelContextWindows !== undefined)
|
|
511
519
|
provider.modelContextWindows = previousEntry.modelContextWindows;
|
|
512
520
|
}
|
|
521
|
+
// The engine keeps an Andorra entry's display names from the router; a client never sets them.
|
|
522
|
+
if (provider.type === 'andorra' && previousEntry?.type === 'andorra' && previousEntry.modelNames !== undefined)
|
|
523
|
+
provider.modelNames = { ...previousEntry.modelNames };
|
|
513
524
|
if (source.name === null)
|
|
514
525
|
delete provider.name;
|
|
515
526
|
else if (source.name === undefined) {
|
|
@@ -580,6 +591,7 @@ function sessionSummary(record) {
|
|
|
580
591
|
...(record.parentId === undefined ? {} : { parentId: record.parentId }),
|
|
581
592
|
...(record.projectId === undefined ? {} : { projectId: record.projectId }),
|
|
582
593
|
...(record.archived === undefined ? {} : { archived: record.archived }),
|
|
594
|
+
...(record.jevEnabled === undefined ? {} : { jevEnabled: record.jevEnabled }),
|
|
583
595
|
...(record.history?.length ? { lastTask: record.history[record.history.length - 1].direction ?? record.history[record.history.length - 1].task } : {}),
|
|
584
596
|
...(finished === undefined ? {} : { lastTurnStatus: finished }),
|
|
585
597
|
usage: { inputTokens: record.usage.inputTokens, outputTokens: record.usage.outputTokens, requests: record.usage.requests, ...(record.usage.cacheRead === undefined ? {} : { cacheRead: record.usage.cacheRead }), ...(record.usage.cacheWrite === undefined ? {} : { cacheWrite: record.usage.cacheWrite }),
|
|
@@ -728,6 +740,7 @@ export class AppServer {
|
|
|
728
740
|
slotWrites = new Map();
|
|
729
741
|
runTask;
|
|
730
742
|
titleReleases = new Map();
|
|
743
|
+
titleAnswered = new Set(); // runs whose model has answered at least once
|
|
731
744
|
sessionTitles = new Map();
|
|
732
745
|
workGeneration = 0;
|
|
733
746
|
operations = new Set();
|
|
@@ -743,6 +756,8 @@ export class AppServer {
|
|
|
743
756
|
remoteOps = Promise.resolve();
|
|
744
757
|
closed = false;
|
|
745
758
|
emitsStopped = false;
|
|
759
|
+
hosted;
|
|
760
|
+
hostedStarted = false;
|
|
746
761
|
telemetrySettle = Promise.resolve();
|
|
747
762
|
onStop;
|
|
748
763
|
constructor(options) {
|
|
@@ -792,6 +807,17 @@ export class AppServer {
|
|
|
792
807
|
return { key, directory: join(this.directory, 'browser-profiles', key) };
|
|
793
808
|
},
|
|
794
809
|
});
|
|
810
|
+
this.hosted = new HostedMonitor({
|
|
811
|
+
surface: 'desktop', home: this.directory,
|
|
812
|
+
...(options.hostedCheck === undefined ? {} : { check: options.hostedCheck }),
|
|
813
|
+
...(options.hostedNow === undefined ? {} : { now: options.hostedNow }),
|
|
814
|
+
applyEntry: answer => this.applyHostedEntry(answer),
|
|
815
|
+
hasEntry: async () => hasAndorraEntry(await loadConfig(this.directory)),
|
|
816
|
+
onChange: () => { void this.hostedStatus().then(payload => { if (!this.closed)
|
|
817
|
+
this.emit('andorra.status', payload); }, () => { }); },
|
|
818
|
+
onAnnounce: ({ promotionId }) => this.emit('andorra.announce', { message: ANDORRA_ANNOUNCEMENT, promotionId }),
|
|
819
|
+
onNotice: () => this.emit('andorra.notice', { message: ANDORRA_CHANGED_MESSAGE }),
|
|
820
|
+
});
|
|
795
821
|
this.timers.onDue = () => this.checkTimers();
|
|
796
822
|
this.timers.onArmed = timer => {
|
|
797
823
|
if (timer.owner === undefined)
|
|
@@ -914,6 +940,84 @@ export class AppServer {
|
|
|
914
940
|
this.autoArchiveCheck.unref();
|
|
915
941
|
void this.reapSessions();
|
|
916
942
|
}
|
|
943
|
+
// One monitor per engine; an automation worker shares the home with the desktop engine and checks nothing.
|
|
944
|
+
if (process.env.ANDORRA_AUTOMATION_WORKER !== '1' && !this.closed && !this.hostedStarted) {
|
|
945
|
+
this.hostedStarted = true;
|
|
946
|
+
void this.hosted.start();
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Keeps the Andorra entry current from an enabled answer. A missing entry is created only when the user added
|
|
951
|
+
* Andorra: that decision is read inside this engine's queue of config writes and inside the cross-process
|
|
952
|
+
* config lock, so an add or a removal recorded just before, here or in another process, is the one that counts.
|
|
953
|
+
*/
|
|
954
|
+
async applyHostedEntry(answer) {
|
|
955
|
+
const saved = await this.serializeConfig(async () => this.closed ? undefined : saveAndorraAnswer(this.directory, answer));
|
|
956
|
+
if (saved)
|
|
957
|
+
this.emit('config.changed', { config: await this.analyticsConfigView(saved) });
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* What clients are told about Andorra: its availability, whether it can be added, and, while it is offered and
|
|
961
|
+
* the user has not removed it, the entry to LIST: a provider view built from the hosted answer that is not in
|
|
962
|
+
* the saved config (`listed`). A client shows it as an ordinary provider and saves it with `andorra.add` the
|
|
963
|
+
* first time the user picks it. `usage`, when known, is what to show for the hosted models (HostedMonitor.usage).
|
|
964
|
+
*/
|
|
965
|
+
async hostedStatus() {
|
|
966
|
+
const status = this.hosted.availability();
|
|
967
|
+
const offered = this.hosted.offered();
|
|
968
|
+
const usage = this.hosted.usage();
|
|
969
|
+
const base = { status, offered, ...(usage === undefined ? {} : { usage }) };
|
|
970
|
+
const answer = this.hosted.listed() ? this.hosted.enabledAnswer() : undefined;
|
|
971
|
+
if (!answer)
|
|
972
|
+
return base;
|
|
973
|
+
const config = await loadConfig(this.directory).catch(() => undefined);
|
|
974
|
+
const entry = config && virtualAndorraEntry(config, answer);
|
|
975
|
+
return entry ? { ...base, listed: providerView(entry, [entry, ...config.providers]) } : base;
|
|
976
|
+
}
|
|
977
|
+
/** The user removed the listed, never-saved Andorra: it is no longer listed (Add Provider still offers it). */
|
|
978
|
+
async hideListedEntry() {
|
|
979
|
+
if (hasAndorraEntry(await loadConfig(this.directory)))
|
|
980
|
+
throw new AppServerError('invalid-params', 'Andorra is a saved provider: remove it with providers.update');
|
|
981
|
+
// A removal that could not be recorded removed nothing: the entry stays listed and the window is told.
|
|
982
|
+
if (!await this.serializeConfig(() => recordAndorraRemoved(this.directory)))
|
|
983
|
+
throw new Error(ANDORRA_REMOVE_FAILED);
|
|
984
|
+
await this.hosted.entryChanged();
|
|
985
|
+
return { removed: true };
|
|
986
|
+
}
|
|
987
|
+
/** Saves the Andorra provider because the user asked for it; with `select`, it becomes the active provider in the same write. */
|
|
988
|
+
async addHostedEntry(select, model) {
|
|
989
|
+
if (this.closed)
|
|
990
|
+
return { added: false, message: ANDORRA_UNAVAILABLE_MESSAGE };
|
|
991
|
+
let saved;
|
|
992
|
+
let result;
|
|
993
|
+
try {
|
|
994
|
+
result = await addAndorraEntry({
|
|
995
|
+
home: this.directory,
|
|
996
|
+
monitor: this.hosted,
|
|
997
|
+
...(select === undefined ? {} : { select }),
|
|
998
|
+
...(model === undefined ? {} : { model }),
|
|
999
|
+
serialize: body => this.serializeConfig(body),
|
|
1000
|
+
change: async (update) => {
|
|
1001
|
+
if (update(await loadConfig(this.directory)) === undefined)
|
|
1002
|
+
return;
|
|
1003
|
+
let wrote = false;
|
|
1004
|
+
const next = await changeConfigFile(this.directory, current => {
|
|
1005
|
+
const updated = update(current);
|
|
1006
|
+
wrote = updated !== undefined;
|
|
1007
|
+
return updated ?? current;
|
|
1008
|
+
});
|
|
1009
|
+
if (wrote)
|
|
1010
|
+
saved = next;
|
|
1011
|
+
},
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
catch (error) {
|
|
1015
|
+
throw error instanceof ConfigConflictError ? new AppServerError('busy', message(error)) : new AppServerError('invalid-params', message(error));
|
|
1016
|
+
}
|
|
1017
|
+
if (saved)
|
|
1018
|
+
this.emit('config.changed', { config: await this.analyticsConfigView(saved) });
|
|
1019
|
+
await this.hosted.entryChanged();
|
|
1020
|
+
return result;
|
|
917
1021
|
}
|
|
918
1022
|
reapSessions() {
|
|
919
1023
|
const next = this.autoArchivePass.then(() => this.autoArchiveSessions())
|
|
@@ -1065,6 +1169,22 @@ export class AppServer {
|
|
|
1065
1169
|
return { providers: providerViews(config.providers), active: config.provider };
|
|
1066
1170
|
}
|
|
1067
1171
|
case 'providers.update': return this.updateProviders(params);
|
|
1172
|
+
case 'andorra.status': {
|
|
1173
|
+
if (params.check !== undefined && typeof params.check !== 'boolean')
|
|
1174
|
+
throw new AppServerError('invalid-params', 'check must be a boolean');
|
|
1175
|
+
if (params.check === true && !this.closed)
|
|
1176
|
+
await this.hosted.check('open');
|
|
1177
|
+
return this.hostedStatus();
|
|
1178
|
+
}
|
|
1179
|
+
case 'andorra.add': {
|
|
1180
|
+
if (params.model !== undefined && typeof params.model !== 'string')
|
|
1181
|
+
throw new AppServerError('invalid-params', 'model must be a string');
|
|
1182
|
+
if (params.select !== undefined && typeof params.select !== 'boolean')
|
|
1183
|
+
throw new AppServerError('invalid-params', 'select must be a boolean');
|
|
1184
|
+
// `model` without `select`: the window selects it itself afterwards, and is told when it is not served.
|
|
1185
|
+
return this.addHostedEntry(params.select === true ? { ...(typeof params.model === 'string' ? { model: params.model } : {}) } : undefined, typeof params.model === 'string' ? params.model : undefined);
|
|
1186
|
+
}
|
|
1187
|
+
case 'andorra.remove': return this.hideListedEntry();
|
|
1068
1188
|
case 'providers.discover': return this.discoverModels(params);
|
|
1069
1189
|
case 'providers.test': return this.testProviderEndpoint(params);
|
|
1070
1190
|
case 'providers.detectSignIns': return this.detectProviderSignIns(params);
|
|
@@ -1101,9 +1221,11 @@ export class AppServer {
|
|
|
1101
1221
|
const { session, goal, text: notice, changed } = await this.setSessionGoal(params);
|
|
1102
1222
|
return { session: this.summary(session), goal: goal ?? null, text: notice, changed };
|
|
1103
1223
|
}
|
|
1224
|
+
case 'sessions.setJev': return { session: this.summary(await this.setSessionJev(params)) };
|
|
1104
1225
|
case 'sessions.setArchived': return { session: this.summary(await this.setSessionArchived(params)) };
|
|
1105
1226
|
case 'sessions.delete': return this.deleteSession(params);
|
|
1106
1227
|
case 'sessions.pullRequest.get': return { pullRequest: pullRequestForClients(await readPullRequest(this.directory, identifier(params.id, 'id'))) };
|
|
1228
|
+
case 'sessions.pullRequest.list': return { pullRequests: (await listPullRequests(this.directory)).map(entry => ({ sessionId: entry.sessionId, pullRequest: pullRequestForClients(entry.pullRequest) })) };
|
|
1107
1229
|
case 'sessions.pullRequest.update': {
|
|
1108
1230
|
let settings;
|
|
1109
1231
|
try {
|
|
@@ -1214,6 +1336,16 @@ export class AppServer {
|
|
|
1214
1336
|
await this.browserViews.closeTab(sessionId, optionalIdentifier(params.tabId, 'tabId'));
|
|
1215
1337
|
return { ok: true };
|
|
1216
1338
|
}
|
|
1339
|
+
case 'browser.view.show': {
|
|
1340
|
+
const sessionId = identifier(params.sessionId, 'sessionId');
|
|
1341
|
+
await this.browserViews.showWindow(sessionId);
|
|
1342
|
+
return { ok: true };
|
|
1343
|
+
}
|
|
1344
|
+
case 'browser.view.hide': {
|
|
1345
|
+
const sessionId = identifier(params.sessionId, 'sessionId');
|
|
1346
|
+
await this.browserViews.hideWindow(sessionId);
|
|
1347
|
+
return { ok: true };
|
|
1348
|
+
}
|
|
1217
1349
|
case 'browser.view.stream': {
|
|
1218
1350
|
const sessionId = identifier(params.sessionId, 'sessionId');
|
|
1219
1351
|
if (typeof params.enabled !== 'boolean')
|
|
@@ -1886,46 +2018,55 @@ export class AppServer {
|
|
|
1886
2018
|
const removedSlots = [];
|
|
1887
2019
|
const removedAnthropic = [];
|
|
1888
2020
|
const saved = await this.serializeConfig(async () => {
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
if (
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
2021
|
+
const save = async () => {
|
|
2022
|
+
try {
|
|
2023
|
+
const next = await changeConfigFile(this.directory, current => {
|
|
2024
|
+
let providers;
|
|
2025
|
+
if (upsert !== undefined) {
|
|
2026
|
+
if (!upsert || typeof upsert !== 'object' || Array.isArray(upsert))
|
|
2027
|
+
throw new AppServerError('invalid-params', 'A provider to upsert must be an object');
|
|
2028
|
+
if (previous !== undefined && !sameProvider(storedEntry(current.providers, String(upsert.id ?? '')), previous)) {
|
|
2029
|
+
throw new AppServerError('busy', 'That provider changed elsewhere. Reload it and try again.');
|
|
2030
|
+
}
|
|
2031
|
+
const [entry] = mergeProviderSecrets(current.providers, [upsert]);
|
|
2032
|
+
const index = current.providers.findIndex(item => item.id === entry.id);
|
|
2033
|
+
providers = index < 0 ? [...current.providers, entry] : current.providers.map((item, at) => at === index ? entry : item);
|
|
2034
|
+
providers = allocateCodexAccountSlots(current.providers, providers);
|
|
2035
|
+
removedSlots.length = 0;
|
|
2036
|
+
removedSlots.push(...droppedCodexSlots(current.providers, providers));
|
|
2037
|
+
removedAnthropic.length = 0;
|
|
2038
|
+
removedAnthropic.push(...droppedAnthropicAccounts(current.providers, providers));
|
|
1897
2039
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
throw error instanceof ConfigConflictError ? new AppServerError('busy', message(error)) : new AppServerError('invalid-params', message(error));
|
|
1927
|
-
}
|
|
2040
|
+
else if (remove !== undefined) {
|
|
2041
|
+
removedSlots.length = 0;
|
|
2042
|
+
providers = current.providers.filter(item => item.id !== remove);
|
|
2043
|
+
removedSlots.push(...droppedCodexSlots(current.providers, providers));
|
|
2044
|
+
removedAnthropic.length = 0;
|
|
2045
|
+
removedAnthropic.push(...droppedAnthropicAccounts(current.providers, providers));
|
|
2046
|
+
}
|
|
2047
|
+
else {
|
|
2048
|
+
providers = current.providers.map(item => item.id === clearKey ? { ...item, apiKey: undefined } : item);
|
|
2049
|
+
}
|
|
2050
|
+
const ids = new Set(providers.map(item => item.id));
|
|
2051
|
+
const requested = typeof params.active === 'string' && params.active ? params.active : current.provider;
|
|
2052
|
+
const provider = ids.has(requested) ? requested : fallbackProviderId(providers);
|
|
2053
|
+
return reconcileSubagentPair({ ...current, providers, provider });
|
|
2054
|
+
});
|
|
2055
|
+
return next;
|
|
2056
|
+
}
|
|
2057
|
+
catch (error) {
|
|
2058
|
+
if (error instanceof AppServerError)
|
|
2059
|
+
throw error;
|
|
2060
|
+
throw error instanceof ConfigConflictError ? new AppServerError('busy', message(error)) : new AppServerError('invalid-params', message(error));
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
// Removing Andorra: the decision is recorded before the config without the entry is saved (and put back when
|
|
2064
|
+
// the save fails), so a check in another process can never create the entry again in between.
|
|
2065
|
+
const removesAndorra = remove !== undefined
|
|
2066
|
+
&& (await loadConfig(this.directory).catch(() => undefined))?.providers.some(item => item.id === remove && item.type === 'andorra') === true;
|
|
2067
|
+
return removesAndorra ? removingAndorraEntry(this.directory, save) : save();
|
|
1928
2068
|
});
|
|
2069
|
+
await this.hosted.entryChanged();
|
|
1929
2070
|
const view = await this.analyticsConfigView(saved);
|
|
1930
2071
|
this.emit('config.changed', { config: view });
|
|
1931
2072
|
await this.retireSlots(removedSlots);
|
|
@@ -2190,6 +2331,7 @@ export class AppServer {
|
|
|
2190
2331
|
...(access.dailyDecisionUsed === undefined ? {} : { dailyDecisionUsed: access.dailyDecisionUsed }),
|
|
2191
2332
|
...(access.decisionsSinceRollout === undefined ? {} : { decisionsSinceRollout: access.decisionsSinceRollout }),
|
|
2192
2333
|
...(access.fairUse === undefined ? {} : { fairUse: access.fairUse }),
|
|
2334
|
+
...(access.unlimited === undefined ? {} : { unlimited: access.unlimited }),
|
|
2193
2335
|
...(access.windowDays === undefined ? {} : { windowDays: access.windowDays }),
|
|
2194
2336
|
...(access.windowDecisionLimit === undefined ? {} : { windowDecisionLimit: access.windowDecisionLimit }),
|
|
2195
2337
|
...(access.windowDecisionUsed === undefined ? {} : { windowDecisionUsed: access.windowDecisionUsed }),
|
|
@@ -2253,6 +2395,7 @@ export class AppServer {
|
|
|
2253
2395
|
try {
|
|
2254
2396
|
const status = await this.operation(180_000, signal => login({ signal, onMessage: detail => this.emit('account.login.message', { message: detail }) }));
|
|
2255
2397
|
await this.publishAccount();
|
|
2398
|
+
this.checkHostedAfterAccountChange();
|
|
2256
2399
|
return { signedIn: status.signedIn, subject: status.subject };
|
|
2257
2400
|
}
|
|
2258
2401
|
catch (error) {
|
|
@@ -2264,12 +2407,18 @@ export class AppServer {
|
|
|
2264
2407
|
try {
|
|
2265
2408
|
const { revoked } = await logout();
|
|
2266
2409
|
await this.publishAccount();
|
|
2410
|
+
this.checkHostedAfterAccountChange();
|
|
2267
2411
|
return { revoked };
|
|
2268
2412
|
}
|
|
2269
2413
|
catch (error) {
|
|
2270
2414
|
throw new AppServerError('auth', message(error));
|
|
2271
2415
|
}
|
|
2272
2416
|
}
|
|
2417
|
+
/** Signing in or out changes what Andorra offers this account: ask now instead of at the next interval. */
|
|
2418
|
+
checkHostedAfterAccountChange() {
|
|
2419
|
+
if (process.env.ANDORRA_AUTOMATION_WORKER !== '1' && !this.closed)
|
|
2420
|
+
void this.hosted.check('account');
|
|
2421
|
+
}
|
|
2273
2422
|
async publishAccount() {
|
|
2274
2423
|
try {
|
|
2275
2424
|
this.emit('account.changed', await this.accountStatus());
|
|
@@ -2384,6 +2533,27 @@ export class AppServer {
|
|
|
2384
2533
|
return renamed;
|
|
2385
2534
|
});
|
|
2386
2535
|
}
|
|
2536
|
+
async setSessionJev(params) {
|
|
2537
|
+
const id = identifier(params.id, 'id');
|
|
2538
|
+
if (typeof params.enabled !== 'boolean')
|
|
2539
|
+
throw new AppServerError('invalid-params', 'enabled must be a boolean');
|
|
2540
|
+
const enabled = params.enabled;
|
|
2541
|
+
if (this.startingSession === id || this.starting)
|
|
2542
|
+
throw new AppServerError('busy', 'That task is starting. Wait for it to begin, then change Jev.');
|
|
2543
|
+
const ownRunId = this.run?.sessionId === id ? this.run.runId
|
|
2544
|
+
: this.finishingRunId !== undefined && this.finishingSessionId === id ? this.finishingRunId : undefined;
|
|
2545
|
+
return this.withSessionMutation(id, async () => {
|
|
2546
|
+
const record = await this.readSession(id);
|
|
2547
|
+
if ((record.jevEnabled !== false) === enabled)
|
|
2548
|
+
return record;
|
|
2549
|
+
if (await sessionHasOpenRun(this.directory, id, ownRunId === undefined ? {} : { ignoreRunId: ownRunId }))
|
|
2550
|
+
throw new AppServerError('busy', 'That task is running in another window. Stop the run or wait for it to finish, then change Jev.');
|
|
2551
|
+
const updated = { ...record, jevEnabled: enabled };
|
|
2552
|
+
await this.store().save(savedSessionFields(updated));
|
|
2553
|
+
this.emit('session.updated', { session: this.summary(updated) });
|
|
2554
|
+
return updated;
|
|
2555
|
+
});
|
|
2556
|
+
}
|
|
2387
2557
|
async setSessionGoal(params) {
|
|
2388
2558
|
const id = identifier(params.id, 'id');
|
|
2389
2559
|
const command = typeof params.command === 'string' ? params.command : '';
|
|
@@ -2605,7 +2775,7 @@ export class AppServer {
|
|
|
2605
2775
|
if (turns[turns.length - 1] !== turn)
|
|
2606
2776
|
throw new AppServerError('invalid-params', 'That attempt is no longer the newest turn in the session, so it cannot be resumed.');
|
|
2607
2777
|
const rawSelection = typeof source.graphSelection === 'string' ? source.graphSelection : source.graph?.id;
|
|
2608
|
-
const graphId = rawSelection === 'software-engineer' ? 'default' : rawSelection === 'andorra' ?
|
|
2778
|
+
const graphId = rawSelection === 'software-engineer' ? 'default' : rawSelection === 'andorra' ? RETIRED_ANDORRA_SELECTION : rawSelection;
|
|
2609
2779
|
if (!await claimRunResume(this.directory, originalRunId))
|
|
2610
2780
|
throw new AppServerError('busy', 'That run is already being resumed by another engine.');
|
|
2611
2781
|
const inheritedPermissions = params.permissions === undefined && isPermissionMode(source.permissions)
|
|
@@ -2709,9 +2879,9 @@ export class AppServer {
|
|
|
2709
2879
|
}
|
|
2710
2880
|
async loadResumeGraph(selection, signal, overrideAllNodes, nodeModelOverrides, config) {
|
|
2711
2881
|
if (overrideAllNodes || nodeModelOverrides === undefined) {
|
|
2712
|
-
return this.loadGraph(selection, signal, undefined, { bindProviders: !overrideAllNodes, allowDeleted: true });
|
|
2882
|
+
return this.loadGraph(selection, signal, undefined, { bindProviders: !overrideAllNodes, allowDeleted: true, allowRetired: true });
|
|
2713
2883
|
}
|
|
2714
|
-
const raw = await this.loadGraph(selection, signal, undefined, { bindProviders: false, allowDeleted: true });
|
|
2884
|
+
const raw = await this.loadGraph(selection, signal, undefined, { bindProviders: false, allowDeleted: true, allowRetired: true });
|
|
2715
2885
|
const prebound = structuredClone(raw);
|
|
2716
2886
|
for (const [nodeId, pair] of Object.entries(nodeModelOverrides)) {
|
|
2717
2887
|
const node = prebound.nodes[nodeId];
|
|
@@ -2773,7 +2943,10 @@ export class AppServer {
|
|
|
2773
2943
|
const runState = params.state !== undefined && typeof params.state === 'object' && params.state !== null && !Array.isArray(params.state)
|
|
2774
2944
|
? structuredClone(params.state) : undefined;
|
|
2775
2945
|
const implicit = params.graph === undefined || params.graph === '';
|
|
2776
|
-
|
|
2946
|
+
// A resumed attempt keeps the graph it stopped on, the removed Andorra preset included: its journal and
|
|
2947
|
+
// checkpoints name that graph's nodes. A new task that names the preset runs Default.
|
|
2948
|
+
let selection = implicit ? configuredGraphSelection(config, await currentGraphSubject())
|
|
2949
|
+
: internal?.resumedFrom !== undefined ? identifier(params.graph, 'graph') : currentGraphSelection(identifier(params.graph, 'graph'));
|
|
2777
2950
|
if (implicit && await this.selectionIsDeleted(selection))
|
|
2778
2951
|
selection = 'default';
|
|
2779
2952
|
const requested = params.permissions === undefined ? undefined : permissionMode(params.permissions);
|
|
@@ -2825,7 +2998,9 @@ export class AppServer {
|
|
|
2825
2998
|
inheritedTurns: existing.history.length, lineage: lineagePoints(existing, existing.usage, existing.history.length) };
|
|
2826
2999
|
await copySessionSkill(this.directory, existing.id, record.id).catch(error => this.log('warn', `Could not carry the session's active skill to its continuation: ${message(error)}`));
|
|
2827
3000
|
}
|
|
2828
|
-
|
|
3001
|
+
if (params.jevEnabled !== undefined && typeof params.jevEnabled !== 'boolean')
|
|
3002
|
+
throw new AppServerError('invalid-params', 'jevEnabled must be a boolean');
|
|
3003
|
+
record = { ...record, workspace: root, projectId: record.projectId ?? await this.projectIdFor(root), updatedAt: new Date().toISOString(), ...(params.jevEnabled === undefined ? {} : { jevEnabled: params.jevEnabled }) };
|
|
2829
3004
|
const controller = new AbortController();
|
|
2830
3005
|
const runId = randomUUID();
|
|
2831
3006
|
const telemetryRunId = randomUUID();
|
|
@@ -3151,7 +3326,7 @@ export class AppServer {
|
|
|
3151
3326
|
const openRecord = { id: runId, status: 'running', sessionId: record.id, startedAt, pid: process.pid, graphSelection: selection, graph: { id: selection }, provider: provider.id, model: modelId,
|
|
3152
3327
|
surface: configuredSurface('desktop'),
|
|
3153
3328
|
...(accountSubject ? { accountSubject } : {}),
|
|
3154
|
-
telemetry: { runId: telemetryRunId, nodes: 0, subagents: false, jevEnabled: config.jevEnabled !== false, decisionRouting: config.decisions?.mode ?? 'off', permissionMode: internal?.inheritedPermissions ?? effective, startSent: false },
|
|
3329
|
+
telemetry: { runId: telemetryRunId, nodes: 0, subagents: false, jevEnabled: config.jevEnabled !== false && record.jevEnabled !== false, decisionRouting: config.decisions?.mode ?? 'off', permissionMode: internal?.inheritedPermissions ?? effective, startSent: false },
|
|
3155
3330
|
...(runInput === undefined ? {} : { runInput }), ...(runState === undefined ? {} : { runState }), ...(effort === undefined ? {} : { reasoningEffort: effort }),
|
|
3156
3331
|
...(automationContext === undefined ? {} : { automationContext }),
|
|
3157
3332
|
...(internal?.inheritedPermissions === undefined ? {} : { permissions: internal.inheritedPermissions }),
|
|
@@ -3202,7 +3377,7 @@ export class AppServer {
|
|
|
3202
3377
|
const permissionControl = new RunControl();
|
|
3203
3378
|
permissionControl.permissions = effective;
|
|
3204
3379
|
permissionControl.yolo = effective === 'full-access';
|
|
3205
|
-
this.run = { runId, sessionId: record.id, controller, workspace: root, steers: liveSteers, steersClosed: false,
|
|
3380
|
+
this.run = { runId, sessionId: record.id, controller, workspace: root, steers: liveSteers, subagents: new Set(), steersClosed: false,
|
|
3206
3381
|
permissionControl, permissionRevision: 0, approvals: new Set(), boundPermissions: internal?.inheritedPermissions !== undefined,
|
|
3207
3382
|
codeIntelPermissions: effective, ...(lineage.length === 0 ? {} : { lineage: [...lineage] }) };
|
|
3208
3383
|
{
|
|
@@ -3245,7 +3420,8 @@ export class AppServer {
|
|
|
3245
3420
|
controller.signal.addEventListener('abort', () => resolve(), { once: true });
|
|
3246
3421
|
})]);
|
|
3247
3422
|
const settled = released
|
|
3248
|
-
|
|
3423
|
+
// A run Andorra refused (unavailable, sign in, allowance, busy) ended without an answer: no second request follows the refusal.
|
|
3424
|
+
.then(() => controller.signal.aborted || this.workGeneration !== generation || (provider.type === 'andorra' && !this.titleAnswered.has(runId)) ? '' : summarizeSessionPrompt(task, createAdapter(provider), modelId, controller.signal))
|
|
3249
3425
|
.then(async (summary) => {
|
|
3250
3426
|
if (!summary || controller.signal.aborted || record.renamed === true)
|
|
3251
3427
|
return;
|
|
@@ -3266,6 +3442,7 @@ export class AppServer {
|
|
|
3266
3442
|
})
|
|
3267
3443
|
.finally(() => {
|
|
3268
3444
|
this.titleReleases.delete(runId);
|
|
3445
|
+
this.titleAnswered.delete(runId);
|
|
3269
3446
|
if (this.sessionTitles.get(record.id) === controller)
|
|
3270
3447
|
this.sessionTitles.delete(record.id);
|
|
3271
3448
|
this.operations.delete(controller);
|
|
@@ -3321,6 +3498,11 @@ export class AppServer {
|
|
|
3321
3498
|
let localCacheReadTokens = 0;
|
|
3322
3499
|
const probeUsage = { requests: 0, inputTokens: 0, outputTokens: 0 };
|
|
3323
3500
|
const probeModels = new Map();
|
|
3501
|
+
// Set by the first model request this run sends to an Andorra provider (the health probe's included): the
|
|
3502
|
+
// hosted usage is asked for again when such a run ends.
|
|
3503
|
+
let askedAndorra = false;
|
|
3504
|
+
const watchAndorra = (providerType, adapter) => providerType === 'andorra' ? watchRequests(adapter, () => { askedAndorra = true; }) : adapter;
|
|
3505
|
+
const watchResolved = (resolved) => ({ ...resolved, adapter: watchAndorra(resolved.providerType, resolved.adapter) });
|
|
3324
3506
|
let history = (input.record.contextHistory ?? input.record.history ?? []).filter(turn => turn.runId !== runId).slice(-SESSION_HISTORY_TURNS);
|
|
3325
3507
|
const armedRunIdSet = new Set(armedRunIds ?? []);
|
|
3326
3508
|
const contextSeed = history.filter(turn => !armedRunIdSet.has(turn.runId ?? ''));
|
|
@@ -3433,7 +3615,7 @@ export class AppServer {
|
|
|
3433
3615
|
}
|
|
3434
3616
|
const startedHandle = createRunHandle(telemetryRunId, startedAt, {
|
|
3435
3617
|
graphId: selection, ...graphShape(graph), permissionMode: boundPermissions ?? permissions,
|
|
3436
|
-
jevEnabled: config.jevEnabled !== false, decisionRouting: config.decisions?.mode ?? 'off',
|
|
3618
|
+
jevEnabled: config.jevEnabled !== false && input.record.jevEnabled !== false, decisionRouting: config.decisions?.mode ?? 'off',
|
|
3437
3619
|
}, root);
|
|
3438
3620
|
telemetryHandle = startedHandle;
|
|
3439
3621
|
telemetryStart = reportRunStarted(telemetrySurfaceFor(config), startedHandle).catch(() => { });
|
|
@@ -3479,7 +3661,8 @@ export class AppServer {
|
|
|
3479
3661
|
}
|
|
3480
3662
|
probeModels.set(key, entry);
|
|
3481
3663
|
},
|
|
3482
|
-
createAdapter: provider => this.tracedAdapter(createAdapter(provider), provider.id),
|
|
3664
|
+
createAdapter: provider => watchAndorra(provider.type, this.tracedAdapter(createAdapter(provider), provider.id)),
|
|
3665
|
+
andorra: () => this.hosted.gate(),
|
|
3483
3666
|
}));
|
|
3484
3667
|
healthSettled = healthProbe.then(() => undefined, () => undefined);
|
|
3485
3668
|
const judgeHealth = async () => {
|
|
@@ -3603,7 +3786,7 @@ export class AppServer {
|
|
|
3603
3786
|
await healthGate;
|
|
3604
3787
|
runGoal = input.record.goal?.status === 'active' ? input.record.goal : undefined;
|
|
3605
3788
|
const options = {
|
|
3606
|
-
task, runId, provider: provider.id, model: snapshot.model, adapter: this.tracedAdapter(this.reasoningAdapter(createAdapter(snapshot)), provider.id),
|
|
3789
|
+
task, runId, provider: provider.id, model: snapshot.model, adapter: watchAndorra(provider.type, this.tracedAdapter(this.reasoningAdapter(createAdapter(snapshot, { sessionId: input.record.id })), provider.id)),
|
|
3607
3790
|
...(openingAttachments === undefined ? {} : { attachments: openingAttachments }),
|
|
3608
3791
|
...(snapshot.contextWindow === undefined ? {} : { contextWindow: snapshot.contextWindow }),
|
|
3609
3792
|
tools: [...createTools(), createBrowserPanelTool(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined, panelHold),
|
|
@@ -3613,15 +3796,15 @@ export class AppServer {
|
|
|
3613
3796
|
instructions: `${await loadWorkspaceInstructions(root, signal, systemPromptOverrideFor(graph, config.systemPromptOverride))}${extension.instructions}`,
|
|
3614
3797
|
codeIntel, todoStore: new TodoStore(), ...(commandMemory ? { commandMemory } : {}), ...(projectMemory ? { projectMemory } : {}),
|
|
3615
3798
|
limits: resolveConfiguredLimits(config),
|
|
3616
|
-
...hostedDecisionPolicy(membership, config.jevEnabled !== false, config.decisions),
|
|
3799
|
+
...hostedDecisionPolicy(membership, config.jevEnabled !== false && input.record.jevEnabled !== false, config.decisions),
|
|
3617
3800
|
...(config.efficiency ? { efficiency: config.efficiency } : {}),
|
|
3618
3801
|
...(runGoal ? { goalCompletionVerification: { goal: runGoal.text } } : {}),
|
|
3619
3802
|
modelPinned: modelPinned || overrideAllNodes,
|
|
3620
3803
|
...(entryHistory ? { entryHistory: true } : {}),
|
|
3621
3804
|
...(startNode === undefined ? {} : { startNode }),
|
|
3622
3805
|
configuredModels: config.providers.map(item => ({ id: item.id, model: item.model, ...(item.models ? { models: [...item.models] } : {}) })),
|
|
3623
|
-
resolveModel: (id, model, modelSignal) => this.resolveModel(config, id, model, modelSignal, id === provider.id && (model === undefined || model === modelId) ? reasoningEffort : undefined),
|
|
3624
|
-
resolveProvider: id => this.resolveProvider(config, id),
|
|
3806
|
+
resolveModel: (id, model, modelSignal) => this.resolveModel(config, id, model, modelSignal, id === provider.id && (model === undefined || model === modelId) ? reasoningEffort : undefined, input.record.id).then(watchResolved),
|
|
3807
|
+
resolveProvider: id => watchResolved(this.resolveProvider(config, id, input.record.id)),
|
|
3625
3808
|
getLiveModel: async (nodeId, fallbackProvider, fallbackModel, modelSignal) => {
|
|
3626
3809
|
while (true) {
|
|
3627
3810
|
const current = liveRun?.modelSelection;
|
|
@@ -3660,7 +3843,7 @@ export class AppServer {
|
|
|
3660
3843
|
return undefined;
|
|
3661
3844
|
const selectedEffort = targetProvider === current.provider && effectiveModel === current.model
|
|
3662
3845
|
? current.reasoningEffort : undefined;
|
|
3663
|
-
const resolved = await this.resolveModel(current.config, targetProvider, targetModel, modelSignal, selectedEffort);
|
|
3846
|
+
const resolved = watchResolved(await this.resolveModel(current.config, targetProvider, targetModel, modelSignal, selectedEffort, input.record.id));
|
|
3664
3847
|
if (liveRun?.modelSelection !== current)
|
|
3665
3848
|
continue;
|
|
3666
3849
|
return { ...resolved, provider: targetProvider };
|
|
@@ -3682,6 +3865,23 @@ export class AppServer {
|
|
|
3682
3865
|
if (answered)
|
|
3683
3866
|
this.modelHealth.add(answered, event.data.model);
|
|
3684
3867
|
}
|
|
3868
|
+
if ((event.type === 'subagent.started' || event.type === 'subagent.completed') && typeof event.data.subagentId === 'string') {
|
|
3869
|
+
const live = this.run?.runId === runId ? this.run : undefined;
|
|
3870
|
+
const subagentId = event.data.subagentId;
|
|
3871
|
+
if (event.type === 'subagent.started')
|
|
3872
|
+
live?.subagents.add(subagentId);
|
|
3873
|
+
else {
|
|
3874
|
+
live?.subagents.delete(subagentId);
|
|
3875
|
+
// A message the subagent never read goes to the agent that started it, which is next to act.
|
|
3876
|
+
const unread = liveSteers.filter(entry => entry.subagentId === subagentId);
|
|
3877
|
+
for (const entry of unread) {
|
|
3878
|
+
delete entry.subagentId;
|
|
3879
|
+
entry.content = `(The user sent this to a subagent that finished before reading it.)\n${entry.content}`;
|
|
3880
|
+
}
|
|
3881
|
+
if (unread.length > 0)
|
|
3882
|
+
live?.permissionControl.notifySteer();
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3685
3885
|
if (event.type === 'graph.node.completed' && typeof event.data.nodeId === 'string') {
|
|
3686
3886
|
const nodeId = event.data.nodeId;
|
|
3687
3887
|
const attempts = new Set([runId, ...lineage]);
|
|
@@ -3713,7 +3913,7 @@ export class AppServer {
|
|
|
3713
3913
|
},
|
|
3714
3914
|
onNodeCheckpoint: persistCheckpoint,
|
|
3715
3915
|
getSteeringMessages: async () => {
|
|
3716
|
-
const live = takeSteers(entry => entry.wake === undefined);
|
|
3916
|
+
const live = takeSteers(entry => entry.wake === undefined && entry.subagentId === undefined);
|
|
3717
3917
|
for (const entry of live) {
|
|
3718
3918
|
for (const dir of entry.roots ?? [])
|
|
3719
3919
|
if (!attachmentRoots.includes(dir))
|
|
@@ -3726,6 +3926,16 @@ export class AppServer {
|
|
|
3726
3926
|
deliveredIds.add(entry.id);
|
|
3727
3927
|
return [...armedBatch, ...live].map(entry => ({ role: 'user', content: entry.content, ...(entry.images.length ? { images: entry.images } : {}) }));
|
|
3728
3928
|
},
|
|
3929
|
+
getSubagentSteeringMessages: async (subagentId) => {
|
|
3930
|
+
const own = takeSteers(entry => entry.subagentId === subagentId);
|
|
3931
|
+
for (const entry of own) {
|
|
3932
|
+
for (const dir of entry.roots ?? [])
|
|
3933
|
+
if (!attachmentRoots.includes(dir))
|
|
3934
|
+
attachmentRoots.push(dir);
|
|
3935
|
+
deliveredSteers.push(entry);
|
|
3936
|
+
}
|
|
3937
|
+
return own.map(entry => ({ role: 'user', content: `Message from the user, sent to you while you work. Follow it:\n${entry.content}`, ...(entry.images.length ? { images: entry.images } : {}) }));
|
|
3938
|
+
},
|
|
3729
3939
|
getNodeSteeringMessages: async (nodeId) => {
|
|
3730
3940
|
const own = takeSteers(entry => entry.wake?.origin?.nodeId === nodeId);
|
|
3731
3941
|
for (const entry of own)
|
|
@@ -3751,6 +3961,9 @@ export class AppServer {
|
|
|
3751
3961
|
panelHold.stop();
|
|
3752
3962
|
healthAbort.abort();
|
|
3753
3963
|
await healthSettled;
|
|
3964
|
+
// However the run ended, a run that spent from the hosted allowance asks for the new figure; never awaited.
|
|
3965
|
+
if (askedAndorra && process.env.ANDORRA_AUTOMATION_WORKER !== '1' && !this.closed)
|
|
3966
|
+
void this.hosted.check('run-end').catch(() => { });
|
|
3754
3967
|
await codeIntelSettled;
|
|
3755
3968
|
if (steering?.length || [...nodeArmed.values()].some(list => list.length > 0)) {
|
|
3756
3969
|
this.log('warn', `The direction sent with the resume was not delivered: the continued attempt reached no agent turn boundary to read it. Send it again as a follow-up.`);
|
|
@@ -3803,9 +4016,13 @@ export class AppServer {
|
|
|
3803
4016
|
await trajectory.record('run.finished', { runId, status: closedWithRun && result?.status === 'cancelled' ? 'interrupted' : result?.status ?? (closedWithRun ? 'interrupted' : controller.signal.aborted ? 'cancelled' : 'infrastructure_error'), usage: runUsage, ...(result?.toolCalls !== undefined ? { toolCalls: result.toolCalls } : {}), ...(result === undefined && failure !== undefined ? { error: message(failure) } : {}) });
|
|
3804
4017
|
await trajectory.flush();
|
|
3805
4018
|
}
|
|
3806
|
-
|
|
4019
|
+
// A message read by a subagent keeps its recipient in the record and stays out of the history later
|
|
4020
|
+
// tasks are given: it was an instruction for that subagent's work, not for the run's own agent.
|
|
4021
|
+
const steers = deliveredSteers.map(entry => ({ text: entry.text, ...(entry.refs?.length ? { attachments: entry.refs } : {}), ...(entry.wake === undefined ? {} : { wake: 'timer' }),
|
|
4022
|
+
...(entry.subagentId === undefined ? {} : { subagentId: entry.subagentId }) }));
|
|
4023
|
+
const contextSteers = steers.filter(steer => steer.subagentId === undefined);
|
|
3807
4024
|
archive.push({ task, completion, runId, ...(resumedFrom === undefined ? {} : { resumed: true }), ...(direction === undefined ? {} : { direction }), ...(attachments?.refs.length ? { attachments: attachments.refs } : {}), ...(steers.length ? { steers } : {}), ...(wake === undefined ? {} : { wake }) });
|
|
3808
|
-
history = [...history, { task, completion, runId, ...(resumedFrom === undefined ? {} : { resumed: true }), ...(direction === undefined ? {} : { direction }), ...(attachments?.refs.length ? { attachments: attachments.refs } : {}), ...(
|
|
4025
|
+
history = [...history, { task, completion, runId, ...(resumedFrom === undefined ? {} : { resumed: true }), ...(direction === undefined ? {} : { direction }), ...(attachments?.refs.length ? { attachments: attachments.refs } : {}), ...(contextSteers.length ? { steers: contextSteers } : {}), ...(wake === undefined ? {} : { wake }) }].slice(-SESSION_HISTORY_TURNS);
|
|
3809
4026
|
const record = { ...input.record, history: archive, contextHistory: history, updatedAt: new Date().toISOString(), usage,
|
|
3810
4027
|
...(result ? { widgets: result.widgets } : {}),
|
|
3811
4028
|
context: contextUsedTokens > 0 ? { usedTokens: contextUsedTokens, ...(contextWindow === undefined ? {} : { window: contextWindow }),
|
|
@@ -4185,14 +4402,15 @@ export class AppServer {
|
|
|
4185
4402
|
live.codeIntelSync = step.then(() => undefined, () => undefined);
|
|
4186
4403
|
return step;
|
|
4187
4404
|
}
|
|
4188
|
-
|
|
4405
|
+
/** `sessionId`: the session whose run will talk to this adapter; a run passes its own, known before `this.run` is set. */
|
|
4406
|
+
async resolveModel(config, id, model, signal, reasoningEffort, sessionId = this.run?.sessionId) {
|
|
4189
4407
|
const provider = config.providers.find(item => item.id === id);
|
|
4190
4408
|
if (!provider)
|
|
4191
4409
|
throw new Error(`Unknown provider: ${id}. Add it in Settings, then retry.`);
|
|
4192
4410
|
const resolved = await resolveModelContext(provider, model || provider.model, signal);
|
|
4193
4411
|
if (reasoningEffort !== undefined)
|
|
4194
4412
|
resolved.reasoningEffort = reasoningEffort;
|
|
4195
|
-
return { model: resolved.model, adapter: this.tracedAdapter(this.reasoningAdapter(createAdapter(resolved)), id), ...(resolved.contextWindow === undefined ? {} : { contextWindow: resolved.contextWindow }), ...(resolved.reasoningEffort === undefined ? {} : { reasoningEffort: resolved.reasoningEffort }), providerType: provider.type, baseUrl: provider.baseUrl };
|
|
4413
|
+
return { model: resolved.model, adapter: this.tracedAdapter(this.reasoningAdapter(createAdapter(resolved, { sessionId })), id), ...(resolved.contextWindow === undefined ? {} : { contextWindow: resolved.contextWindow }), ...(resolved.reasoningEffort === undefined ? {} : { reasoningEffort: resolved.reasoningEffort }), providerType: provider.type, baseUrl: provider.baseUrl };
|
|
4196
4414
|
}
|
|
4197
4415
|
async analyticsConfigView(config) {
|
|
4198
4416
|
try {
|
|
@@ -4204,11 +4422,11 @@ export class AppServer {
|
|
|
4204
4422
|
return configView(config);
|
|
4205
4423
|
}
|
|
4206
4424
|
}
|
|
4207
|
-
resolveProvider(config, id) {
|
|
4425
|
+
resolveProvider(config, id, sessionId = this.run?.sessionId) {
|
|
4208
4426
|
const provider = config.providers.find(item => item.id === id);
|
|
4209
4427
|
if (!provider)
|
|
4210
4428
|
throw new Error(`Unknown provider: ${id}. Add it in Settings, then retry.`);
|
|
4211
|
-
return { model: provider.model, adapter: this.tracedAdapter(this.reasoningAdapter(createAdapter(provider)), id), ...(provider.contextWindow === undefined ? {} : { contextWindow: provider.contextWindow }), providerType: provider.type, baseUrl: provider.baseUrl };
|
|
4429
|
+
return { model: provider.model, adapter: this.tracedAdapter(this.reasoningAdapter(createAdapter(provider, { sessionId })), id), ...(provider.contextWindow === undefined ? {} : { contextWindow: provider.contextWindow }), providerType: provider.type, baseUrl: provider.baseUrl };
|
|
4212
4430
|
}
|
|
4213
4431
|
codeIntelligence(root, permissions, signal, options = {}) {
|
|
4214
4432
|
const opened = this.codeIntelOpening.then(() => options.onlyWhileIdle && (this.run !== undefined || this.starting)
|
|
@@ -4270,8 +4488,11 @@ export class AppServer {
|
|
|
4270
4488
|
return writer;
|
|
4271
4489
|
}
|
|
4272
4490
|
async recordRunEvent(runId, event) {
|
|
4273
|
-
if (event.type === 'agent.model.completed')
|
|
4491
|
+
if (event.type === 'agent.model.completed') {
|
|
4492
|
+
if (this.titleReleases.has(runId))
|
|
4493
|
+
this.titleAnswered.add(runId);
|
|
4274
4494
|
this.releaseTitleWaiter(runId);
|
|
4495
|
+
}
|
|
4275
4496
|
await this.journalFor(runId).append(event);
|
|
4276
4497
|
if (event.type === 'graph.started' || event.type === 'graph.node.started')
|
|
4277
4498
|
bootMark(`run.event.${event.type}`, typeof event.data?.nodeId === 'string' ? `node=${event.data.nodeId}` : undefined);
|
|
@@ -4438,6 +4659,8 @@ export class AppServer {
|
|
|
4438
4659
|
}
|
|
4439
4660
|
const refs = resolved?.refs ?? [];
|
|
4440
4661
|
const roots = await Promise.all(createdSpools.map(dir => realpath(dir).catch(() => dir)));
|
|
4662
|
+
// A subagent that has already finished cannot read a message, so it goes to the run's own agent.
|
|
4663
|
+
const subagentId = typeof params.subagentId === 'string' && live.subagents.has(params.subagentId) ? params.subagentId : undefined;
|
|
4441
4664
|
if (this.run !== live || live.steersClosed) {
|
|
4442
4665
|
await Promise.all(createdSpools.map(dir => rm(dir, { recursive: true, force: true }).catch(() => { })));
|
|
4443
4666
|
throw live.controller.signal.aborted || live.steersClosed
|
|
@@ -4452,14 +4675,15 @@ export class AppServer {
|
|
|
4452
4675
|
...(refs.length ? { refs } : {}),
|
|
4453
4676
|
...(roots.length ? { roots } : {}),
|
|
4454
4677
|
at: new Date().toISOString(),
|
|
4678
|
+
...(subagentId === undefined ? {} : { subagentId }),
|
|
4455
4679
|
};
|
|
4456
4680
|
live.steers.push(entry);
|
|
4457
4681
|
await this.recordRunEvent(runId, {
|
|
4458
4682
|
type: 'run.steered',
|
|
4459
4683
|
time: entry.at,
|
|
4460
|
-
data: { runId, sessionId: live.sessionId, steerId: entry.id, text: entry.text, ...(refs.length ? { attachments: refs } : {}) },
|
|
4684
|
+
data: { runId, sessionId: live.sessionId, steerId: entry.id, text: entry.text, ...(refs.length ? { attachments: refs } : {}), ...(subagentId === undefined ? {} : { subagentId }) },
|
|
4461
4685
|
});
|
|
4462
|
-
live.permissionControl.notifySteer();
|
|
4686
|
+
live.permissionControl.notifySteer(subagentId);
|
|
4463
4687
|
return { queued: true };
|
|
4464
4688
|
}
|
|
4465
4689
|
async selectionIsDeleted(selection) {
|
|
@@ -4500,8 +4724,6 @@ export class AppServer {
|
|
|
4500
4724
|
const free = membership.paid !== true;
|
|
4501
4725
|
const confirmed = free && subject !== undefined && membership.subject === subject && !membership.unavailable;
|
|
4502
4726
|
const kept = confirmed ? (await readGraphQuota(directory, saved)).freeGraphId : undefined;
|
|
4503
|
-
if (status.signedIn && !free)
|
|
4504
|
-
graphs.push({ id: ANDORRA_GRAPH_SELECTION, name: 'Andorra', revision: getAndorraHarness().revision, preset: true });
|
|
4505
4727
|
for (const graph of withoutDeletedGraphs(saved)) {
|
|
4506
4728
|
if (graph.id === 'default' || (free && (graph.id !== kept || freeTierGraphViolation(graph) !== undefined)))
|
|
4507
4729
|
continue;
|
|
@@ -4524,7 +4746,7 @@ export class AppServer {
|
|
|
4524
4746
|
return { name: definition.name, json: JSON.stringify(exportAgentDefinition(definition), null, 2) };
|
|
4525
4747
|
}
|
|
4526
4748
|
async getGraph(params) {
|
|
4527
|
-
const id = identifier(params.id, 'id');
|
|
4749
|
+
const id = currentGraphSelection(identifier(params.id, 'id'));
|
|
4528
4750
|
const revision = params.revision === undefined ? undefined : Number(params.revision);
|
|
4529
4751
|
if (revision !== undefined && (!Number.isSafeInteger(revision) || revision < 1))
|
|
4530
4752
|
throw new AppServerError('invalid-params', 'revision must be a positive integer');
|
|
@@ -4535,15 +4757,6 @@ export class AppServer {
|
|
|
4535
4757
|
? structuredClone(SOFTWARE_ENGINEER_HARNESS)
|
|
4536
4758
|
: await loadGraph(id, revision, directory);
|
|
4537
4759
|
}
|
|
4538
|
-
if (id === ANDORRA_GRAPH_SELECTION) {
|
|
4539
|
-
try {
|
|
4540
|
-
return await this.loadGraph(ANDORRA_GRAPH_SELECTION);
|
|
4541
|
-
}
|
|
4542
|
-
catch (error) {
|
|
4543
|
-
const paid = error instanceof Error && /Paid membership/.test(error.message);
|
|
4544
|
-
throw new AppServerError(paid ? 'auth' : 'invalid-params', message(error));
|
|
4545
|
-
}
|
|
4546
|
-
}
|
|
4547
4760
|
return await loadGraph(id, revision, directory);
|
|
4548
4761
|
};
|
|
4549
4762
|
const graph = await read();
|
|
@@ -4561,7 +4774,7 @@ export class AppServer {
|
|
|
4561
4774
|
return { graph, ...(execution !== undefined ? { execution } : {}), ...(subject === undefined ? {} : { subject }) };
|
|
4562
4775
|
}
|
|
4563
4776
|
async selectGraph(params) {
|
|
4564
|
-
const id = identifier(params.id, 'id');
|
|
4777
|
+
const id = currentGraphSelection(identifier(params.id, 'id'));
|
|
4565
4778
|
const madeFor = params.subject === undefined || params.subject === '' ? undefined : identifier(params.subject, 'subject');
|
|
4566
4779
|
const madeSignedOut = madeFor === undefined && params.signedOut === true;
|
|
4567
4780
|
const identityHolds = async () => identityStillHolds({
|
|
@@ -4598,13 +4811,6 @@ export class AppServer {
|
|
|
4598
4811
|
modelWarning = formatGraphHealthFailure(health, 'Open the graph in Studio, correct the model selections, then select it again.');
|
|
4599
4812
|
}
|
|
4600
4813
|
const withWarning = (answer) => modelWarning === undefined ? answer : { ...answer, modelWarning };
|
|
4601
|
-
if (id === ANDORRA_GRAPH_SELECTION) {
|
|
4602
|
-
if (!await identityHolds()) {
|
|
4603
|
-
throw new AppServerError('busy', 'The account changed while the graph was being selected. Choose it again.');
|
|
4604
|
-
}
|
|
4605
|
-
const current = await loadConfig(this.directory);
|
|
4606
|
-
return withWarning({ config: await this.analyticsConfigView(current), selected: id, persisted: false });
|
|
4607
|
-
}
|
|
4608
4814
|
const subject = await currentGraphSubject();
|
|
4609
4815
|
if (!await identityHolds()) {
|
|
4610
4816
|
throw new AppServerError('busy', 'The account changed while the graph was being selected. Choose it again.');
|
|
@@ -5853,6 +6059,7 @@ export class AppServer {
|
|
|
5853
6059
|
await sharedOpenCodeServer().close().catch(() => { });
|
|
5854
6060
|
if (this.automationCheck)
|
|
5855
6061
|
clearInterval(this.automationCheck);
|
|
6062
|
+
this.hosted.stop();
|
|
5856
6063
|
await this.pullRequestWatcher.stop().catch(() => { });
|
|
5857
6064
|
for (const waiter of [...this.reviewWaiters.values()])
|
|
5858
6065
|
waiter({ kind: 'aborted' });
|