@andorra-labs/code 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/dist/src/acp-agent.d.ts +6 -0
  2. package/dist/src/acp-agent.js +15 -4
  3. package/dist/src/agent-definitions.js +29 -6
  4. package/dist/src/agent-execution.js +15 -10
  5. package/dist/src/agent-mcp-catalog.js +1 -0
  6. package/dist/src/agent-mcp.d.ts +4 -1
  7. package/dist/src/agent-mcp.js +46 -10
  8. package/dist/src/andorra/entry.d.ts +10 -0
  9. package/dist/src/andorra/entry.js +18 -4
  10. package/dist/src/andorra/hosted.d.ts +2 -1
  11. package/dist/src/andorra/hosted.js +2 -1
  12. package/dist/src/andorra/notices.d.ts +5 -0
  13. package/dist/src/andorra/notices.js +7 -0
  14. package/dist/src/andorra/state.d.ts +3 -2
  15. package/dist/src/andorra/state.js +4 -4
  16. package/dist/src/andorra/terminal.js +7 -2
  17. package/dist/src/anthropic-credentials.js +2 -0
  18. package/dist/src/app-server/error.d.ts +5 -0
  19. package/dist/src/app-server/error.js +7 -0
  20. package/dist/src/app-server/protocol.d.ts +22 -44
  21. package/dist/src/app-server/protocol.js +5 -1
  22. package/dist/src/app-server/workspace.d.ts +89 -0
  23. package/dist/src/app-server/workspace.js +457 -11
  24. package/dist/src/app-server.d.ts +465 -32
  25. package/dist/src/app-server.js +3308 -517
  26. package/dist/src/auth/deployment.js +2 -2
  27. package/dist/src/bridge/cloud.d.ts +27 -0
  28. package/dist/src/bridge/cloud.js +187 -0
  29. package/dist/src/bridge/command.d.ts +30 -0
  30. package/dist/src/bridge/command.js +347 -0
  31. package/dist/src/bridge/control.d.ts +68 -0
  32. package/dist/src/bridge/control.js +233 -0
  33. package/dist/src/bridge/engines.d.ts +90 -0
  34. package/dist/src/bridge/engines.js +601 -0
  35. package/dist/src/bridge/host-ops.d.ts +9 -0
  36. package/dist/src/bridge/host-ops.js +129 -0
  37. package/dist/src/bridge/host.d.ts +47 -0
  38. package/dist/src/bridge/host.js +540 -0
  39. package/dist/src/bridge/link.d.ts +38 -0
  40. package/dist/src/bridge/link.js +508 -0
  41. package/dist/src/bridge/login-link.d.ts +29 -0
  42. package/dist/src/bridge/login-link.js +54 -0
  43. package/dist/src/bridge/protocol.d.ts +136 -0
  44. package/dist/src/bridge/protocol.js +11 -0
  45. package/dist/src/bridge/store.d.ts +12 -0
  46. package/dist/src/bridge/store.js +61 -0
  47. package/dist/src/bridge/wording.d.ts +6 -0
  48. package/dist/src/bridge/wording.js +10 -0
  49. package/dist/src/browser-runner.js +1 -0
  50. package/dist/src/browser-server.js +7 -1
  51. package/dist/src/browser-ui/style.css +3 -3
  52. package/dist/src/browser-ui/tokens.css +28 -17
  53. package/dist/src/change-authors.d.ts +41 -0
  54. package/dist/src/change-authors.js +146 -0
  55. package/dist/src/claude-provider.js +3 -1
  56. package/dist/src/cli.js +202 -38
  57. package/dist/src/codex-errors.js +4 -1
  58. package/dist/src/coding-tools.js +15 -15
  59. package/dist/src/command-screens.d.ts +6 -0
  60. package/dist/src/command-screens.js +19 -14
  61. package/dist/src/commands.d.ts +14 -1
  62. package/dist/src/compaction-phrases.d.ts +4 -0
  63. package/dist/src/compaction-phrases.js +20 -0
  64. package/dist/src/completion.js +82 -5
  65. package/dist/src/config.d.ts +71 -3
  66. package/dist/src/config.js +202 -77
  67. package/dist/src/context-compaction.js +2 -1
  68. package/dist/src/deadline.js +13 -1
  69. package/dist/src/decision/DecisionManager.js +3 -2
  70. package/dist/src/decision/checks.js +1 -1
  71. package/dist/src/decision/requestPhrases.d.ts +4 -0
  72. package/dist/src/decision/requestPhrases.js +22 -0
  73. package/dist/src/default-graph.js +1 -1
  74. package/dist/src/file-diff.d.ts +4 -0
  75. package/dist/src/file-diff.js +2 -1
  76. package/dist/src/github-app/agent-writes.d.ts +102 -0
  77. package/dist/src/github-app/agent-writes.js +320 -0
  78. package/dist/src/github-app/client.d.ts +349 -0
  79. package/dist/src/github-app/client.js +810 -0
  80. package/dist/src/github-app/event-source.d.ts +208 -0
  81. package/dist/src/github-app/event-source.js +684 -0
  82. package/dist/src/github-app/metrics.d.ts +32 -0
  83. package/dist/src/github-app/metrics.js +49 -0
  84. package/dist/src/github-app/review-loop.d.ts +274 -0
  85. package/dist/src/github-app/review-loop.js +1177 -0
  86. package/dist/src/github-app/review-node.d.ts +81 -0
  87. package/dist/src/github-app/review-node.js +205 -0
  88. package/dist/src/github-app/review-post.d.ts +73 -0
  89. package/dist/src/github-app/review-post.js +139 -0
  90. package/dist/src/github-app/review-text.d.ts +107 -0
  91. package/dist/src/github-app/review-text.js +1133 -0
  92. package/dist/src/github-app/review-threads.d.ts +47 -0
  93. package/dist/src/github-app/review-threads.js +107 -0
  94. package/dist/src/github-app/reviewer.d.ts +121 -0
  95. package/dist/src/github-app/reviewer.js +598 -0
  96. package/dist/src/github-app/store.d.ts +59 -0
  97. package/dist/src/github-app/store.js +148 -0
  98. package/dist/src/github-app/triggers.d.ts +141 -0
  99. package/dist/src/github-app/triggers.js +441 -0
  100. package/dist/src/github-inbox.d.ts +55 -0
  101. package/dist/src/github-inbox.js +153 -0
  102. package/dist/src/github-names.d.ts +8 -0
  103. package/dist/src/github-names.js +8 -0
  104. package/dist/src/glob-search.d.ts +61 -0
  105. package/dist/src/glob-search.js +180 -0
  106. package/dist/src/graph-health.js +13 -4
  107. package/dist/src/graph-manager-chat.js +1 -1
  108. package/dist/src/graph-preview.d.ts +46 -0
  109. package/dist/src/graph-preview.js +55 -0
  110. package/dist/src/graph-provider-portability.js +34 -11
  111. package/dist/src/graph-quota.d.ts +29 -2
  112. package/dist/src/graph-quota.js +68 -10
  113. package/dist/src/graph-runner.js +88 -10
  114. package/dist/src/graph-server.d.ts +1 -1
  115. package/dist/src/graph-server.js +11 -9
  116. package/dist/src/graph-sync.js +3 -3
  117. package/dist/src/graph-ui/app.js +201 -40
  118. package/dist/src/graph-ui/controls.css +1 -0
  119. package/dist/src/graph-ui/embed.js +2 -2
  120. package/dist/src/graph-ui/icons.js +3 -1
  121. package/dist/src/graph-ui/index.html +1 -1
  122. package/dist/src/graph-ui/manager.css +1 -1
  123. package/dist/src/graph-ui/manager.js +2 -2
  124. package/dist/src/graph-ui/sidebar.js +30 -0
  125. package/dist/src/graph-ui/studio-canvas.js +26 -13
  126. package/dist/src/graph-ui/studio.css +15 -7
  127. package/dist/src/graph-ui/studio.js +26 -5
  128. package/dist/src/graph-ui/style.css +77 -45
  129. package/dist/src/graph-ui/theme.js +3 -36
  130. package/dist/src/graph-ui/tokens.css +28 -20
  131. package/dist/src/graphs.d.ts +34 -1
  132. package/dist/src/graphs.js +162 -17
  133. package/dist/src/image-input.d.ts +16 -0
  134. package/dist/src/image-input.js +41 -0
  135. package/dist/src/membership.d.ts +30 -1
  136. package/dist/src/membership.js +48 -8
  137. package/dist/src/model-health-cache.js +1 -1
  138. package/dist/src/model-metadata.d.ts +7 -1
  139. package/dist/src/model-metadata.js +39 -17
  140. package/dist/src/model-relay/local.d.ts +116 -0
  141. package/dist/src/model-relay/local.js +468 -0
  142. package/dist/src/model-relay/remote.d.ts +129 -0
  143. package/dist/src/model-relay/remote.js +252 -0
  144. package/dist/src/model-relay/runs.d.ts +34 -0
  145. package/dist/src/model-relay/runs.js +146 -0
  146. package/dist/src/model-relay/wire.d.ts +5 -0
  147. package/dist/src/model-relay/wire.js +5 -0
  148. package/dist/src/plan-pass.d.ts +59 -0
  149. package/dist/src/plan-pass.js +165 -0
  150. package/dist/src/project-registry.d.ts +21 -0
  151. package/dist/src/project-registry.js +74 -0
  152. package/dist/src/provider-engine.js +3 -0
  153. package/dist/src/provider-import.d.ts +0 -12
  154. package/dist/src/provider-import.js +7 -195
  155. package/dist/src/providers.d.ts +40 -2
  156. package/dist/src/providers.js +93 -23
  157. package/dist/src/pull-request-checks.d.ts +26 -0
  158. package/dist/src/pull-request-checks.js +56 -0
  159. package/dist/src/pull-request-conversation.d.ts +134 -0
  160. package/dist/src/pull-request-conversation.js +221 -0
  161. package/dist/src/pull-request-create.d.ts +175 -0
  162. package/dist/src/pull-request-create.js +392 -0
  163. package/dist/src/pull-request-details.d.ts +242 -0
  164. package/dist/src/pull-request-details.js +614 -0
  165. package/dist/src/pull-request-edit.d.ts +23 -0
  166. package/dist/src/pull-request-edit.js +91 -0
  167. package/dist/src/pull-request-logs.d.ts +87 -0
  168. package/dist/src/pull-request-logs.js +183 -0
  169. package/dist/src/pull-request-merge.d.ts +112 -0
  170. package/dist/src/pull-request-merge.js +258 -0
  171. package/dist/src/pull-request-review.d.ts +137 -0
  172. package/dist/src/pull-request-review.js +401 -0
  173. package/dist/src/pull-requests.d.ts +369 -8
  174. package/dist/src/pull-requests.js +524 -55
  175. package/dist/src/react-runtime.js +38 -5
  176. package/dist/src/remote/engine-pool.d.ts +88 -4
  177. package/dist/src/remote/engine-pool.js +379 -90
  178. package/dist/src/remote/roots.d.ts +19 -0
  179. package/dist/src/remote/roots.js +45 -7
  180. package/dist/src/remote/types.d.ts +0 -44
  181. package/dist/src/run-control.d.ts +17 -0
  182. package/dist/src/run-control.js +47 -0
  183. package/dist/src/run-progress.d.ts +10 -0
  184. package/dist/src/run-progress.js +122 -0
  185. package/dist/src/run-records.d.ts +7 -2
  186. package/dist/src/run-records.js +71 -6
  187. package/dist/src/runtime.d.ts +9 -1
  188. package/dist/src/runtime.js +24 -4
  189. package/dist/src/session-changes.d.ts +35 -0
  190. package/dist/src/session-changes.js +194 -6
  191. package/dist/src/session-monitor.js +2 -1
  192. package/dist/src/session-reaper.d.ts +1 -1
  193. package/dist/src/session-reaper.js +6 -1
  194. package/dist/src/session-summary.d.ts +2 -1
  195. package/dist/src/session-summary.js +2 -1
  196. package/dist/src/sessions.d.ts +11 -1
  197. package/dist/src/sessions.js +17 -4
  198. package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
  199. package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
  200. package/dist/src/skills/bundled/provenance.json +2 -2
  201. package/dist/src/skills/runtime-skills.js +1 -1
  202. package/dist/src/subagent-run.js +1 -0
  203. package/dist/src/telemetry/capture-core.d.ts +17 -0
  204. package/dist/src/telemetry/capture-core.js +59 -1
  205. package/dist/src/telemetry/classify.d.ts +3 -1
  206. package/dist/src/telemetry/classify.js +37 -0
  207. package/dist/src/telemetry/emitter.d.ts +17 -0
  208. package/dist/src/telemetry/emitter.js +76 -5
  209. package/dist/src/telemetry/schema.d.ts +47 -2
  210. package/dist/src/telemetry/schema.js +120 -5
  211. package/dist/src/telemetry/surface.d.ts +3 -1
  212. package/dist/src/telemetry/surface.js +4 -1
  213. package/dist/src/telemetry/uploader.d.ts +6 -1
  214. package/dist/src/telemetry/uploader.js +22 -3
  215. package/dist/src/terminal-ui.d.ts +1 -0
  216. package/dist/src/terminal-ui.js +10 -3
  217. package/dist/src/test-edit-guard.d.ts +7 -0
  218. package/dist/src/test-edit-guard.js +49 -1
  219. package/dist/src/timers.d.ts +2 -0
  220. package/dist/src/tools.js +59 -9
  221. package/dist/src/transcript.js +8 -2
  222. package/dist/src/types.d.ts +7 -0
  223. package/dist/src/usage-analytics.js +18 -10
  224. package/package.json +6 -1
  225. package/dist/src/remote/cert.d.ts +0 -11
  226. package/dist/src/remote/cert.js +0 -87
  227. package/dist/src/remote/client.d.ts +0 -119
  228. package/dist/src/remote/client.js +0 -544
  229. package/dist/src/remote/command.d.ts +0 -4
  230. package/dist/src/remote/command.js +0 -194
  231. package/dist/src/remote/errors.d.ts +0 -11
  232. package/dist/src/remote/errors.js +0 -14
  233. package/dist/src/remote/network.d.ts +0 -22
  234. package/dist/src/remote/network.js +0 -102
  235. package/dist/src/remote/pairing.d.ts +0 -63
  236. package/dist/src/remote/pairing.js +0 -299
  237. package/dist/src/remote/pem.d.ts +0 -2
  238. package/dist/src/remote/pem.js +0 -7
  239. package/dist/src/remote/serve.d.ts +0 -68
  240. package/dist/src/remote/serve.js +0 -244
  241. package/dist/src/remote/server.d.ts +0 -21
  242. package/dist/src/remote/server.js +0 -406
@@ -1,4 +1,5 @@
1
1
  import { type Graph } from './graphs.js';
2
+ import { readOfflinePlan } from './plan-pass.js';
2
3
  import type { TelemetryPlan } from './telemetry/schema.js';
3
4
  export declare const SOFTWARE_ENGINEER_HARNESS: Graph;
4
5
  export declare const RETIRED_ANDORRA_SELECTION = ":andorra";
@@ -31,6 +32,8 @@ export interface Membership {
31
32
  windowDecisionResetsAt?: string;
32
33
  /** Uncapped Paid account: no daily, window or global cap applies. The service answers `unlimited: true` and omits every allowance field. */
33
34
  unlimited?: boolean;
35
+ /** The plan comes from a stored, signed pass because the account service could not be reached. */
36
+ offline?: true;
34
37
  billingUrl?: string;
35
38
  }
36
39
  export declare function membershipPlanLabel(tier: MembershipTier | undefined, paid: boolean): string;
@@ -48,14 +51,40 @@ export interface MembershipDependencies {
48
51
  apiBaseUrl(): string;
49
52
  fetch: typeof globalThis.fetch;
50
53
  recordPlan?: (answer: PlanConfirmation, home?: string) => Promise<void>;
54
+ /** Keeps the signed pass an answer carried, for use while the service is unreachable. */
55
+ storePass?: (pass: unknown, subject: string, home: string, serverTime: number | undefined, plan: {
56
+ paid: boolean;
57
+ tier?: string;
58
+ }) => Promise<unknown>;
59
+ /** Loopback `http:` is allowed only for the GitHub App's test-mode account API (a local fake); everything else must be `https:`. */
60
+ allowLoopbackHttp?: boolean;
51
61
  }
52
62
  export declare function createMembershipClient(deps: MembershipDependencies): (signal?: AbortSignal, home?: string) => Promise<Membership>;
53
63
  export declare const getMembership: (signal?: AbortSignal, home?: string) => Promise<Membership>;
64
+ /**
65
+ * The plan check for custom graphs. It is `getMembership`, except that when the account service
66
+ * cannot be reached a stored pass for the signed-in account stands in for the answer until the pass
67
+ * lapses. Hosted services still need the network; this only decides which graphs may be used.
68
+ */
69
+ export declare function createGraphMembership(deps: {
70
+ membership: (signal?: AbortSignal, home?: string) => Promise<Membership>;
71
+ subject: () => Promise<string | undefined>;
72
+ readPlan?: typeof readOfflinePlan;
73
+ }): (signal?: AbortSignal, home?: string) => Promise<Membership>;
74
+ export declare const getGraphMembership: (signal?: AbortSignal, home?: string) => Promise<Membership>;
54
75
  export declare function requirePaidMembership(signal?: AbortSignal): Promise<void>;
55
76
  export declare function requireGraphMembership(signal?: AbortSignal): Promise<void>;
56
77
  export declare function readGraphMembership(signal?: AbortSignal): Promise<Membership>;
57
- export declare function loadAccessibleGraph(id?: string, signal?: AbortSignal, membership?: (signal?: AbortSignal, home?: string) => Promise<Membership>, options?: {
78
+ export declare function loadAccessibleGraph(id?: string, signal?: AbortSignal, membership?: (signal?: AbortSignal) => Promise<Membership>, options?: {
58
79
  bindProviders?: boolean;
59
80
  allowDeleted?: boolean;
60
81
  allowRetired?: boolean;
61
82
  }): Promise<Graph>;
83
+ /**
84
+ * The graph a desktop sent with a relayed run. It is checked as a stored graph is and used for that run only:
85
+ * it is never written to disk, and no plan is asked for, because the desktop that sent it already holds it.
86
+ * Its nodes are bound to the relayed providers by the caller.
87
+ */
88
+ export declare function relayedGraph(value: unknown, options?: {
89
+ allowDeleted?: boolean;
90
+ }): Graph;
@@ -1,13 +1,14 @@
1
1
  import { DEFAULT_AGENT_GRAPH } from './default-graph.js';
2
- import { DEFAULT_HARNESS, GRAPH_MANAGER_GRAPH_ID, GRAPH_MANAGER_HARNESS, GraphDeletedError, isDeletedGraph, loadGraph } from './graphs.js';
3
- import { AUTH_REFRESH_BUDGET_MS, AuthError, getAccessToken, getAuthConfiguration } from './auth/index.js';
2
+ import { DEFAULT_HARNESS, builtInGraph, GraphDeletedError, isDeletedGraph, loadGraph, validateGraph } from './graphs.js';
3
+ import { AUTH_REFRESH_BUDGET_MS, AuthError, getAccessToken, getAuthConfiguration, getAuthStatus } from './auth/index.js';
4
+ import { readOfflinePlan, storePlanPass } from './plan-pass.js';
4
5
  import { graphStorageDirectory } from './graph-account.js';
5
6
  import { configDirectory, loadConfig } from './config.js';
6
7
  import { analyticsPlanFromMembership, resolveAnalyticsConfig } from './analytics.js';
7
8
  import { recordConfirmedPlan } from './telemetry/state.js';
8
9
  import { telemetryDirectory } from './telemetry/identity.js';
9
10
  import { bindPortableGraphProviders } from './graph-provider-portability.js';
10
- import { loadFreeTierGraph } from './graph-quota.js';
11
+ import { loadFreeTierGraph, notePremiumGraphAccount } from './graph-quota.js';
11
12
  export const SOFTWARE_ENGINEER_HARNESS = {
12
13
  schemaVersion: 2, id: 'software-engineer', name: DEFAULT_AGENT_GRAPH.name, revision: 1, entry: DEFAULT_AGENT_GRAPH.entry,
13
14
  nodes: structuredClone(DEFAULT_AGENT_GRAPH.nodes), edges: structuredClone(DEFAULT_AGENT_GRAPH.edges),
@@ -95,6 +96,7 @@ export function safeAccountEmail(value) {
95
96
  }
96
97
  export { PaidMembershipRequiredError } from './membership-errors.js';
97
98
  import { PaidMembershipRequiredError } from './membership-errors.js';
99
+ const LOOPBACK_HOSTS = new Set(['127.0.0.1', 'localhost', '[::1]']);
98
100
  async function recordPlanConfirmation(answer, home) {
99
101
  const directory = home ?? configDirectory();
100
102
  const observedAt = new Date().toISOString();
@@ -112,7 +114,8 @@ export function createMembershipClient(deps) {
112
114
  return { paid: false };
113
115
  bounded = signal ? AbortSignal.any([signal, AbortSignal.timeout(5000)]) : AbortSignal.timeout(5000);
114
116
  const base = new URL(deps.apiBaseUrl());
115
- if (base.protocol !== 'https:' || base.username || base.password || base.search || base.hash)
117
+ const loopback = deps.allowLoopbackHttp === true && base.protocol === 'http:' && LOOPBACK_HOSTS.has(base.hostname);
118
+ if ((base.protocol !== 'https:' && !loopback) || base.username || base.password || base.search || base.hash)
116
119
  return { paid: false };
117
120
  const response = await deps.fetch(`${base.href.replace(/\/+$/, '')}/me`, {
118
121
  headers: { Authorization: `Bearer ${token}` }, signal: bounded, redirect: 'error',
@@ -158,6 +161,8 @@ export function createMembershipClient(deps) {
158
161
  ? result.tier : undefined;
159
162
  const observedAt = new Date().toISOString();
160
163
  await (deps.recordPlan ?? recordPlanConfirmation)({ subject: result.subject, tier: analyticsPlanFromMembership(tier, result.paid), observedAt }, home).catch(() => { });
164
+ const served = Date.parse(response.headers?.get?.('date') ?? '');
165
+ await (deps.storePass ?? ((pass, subject, directory, serverTime, plan) => storePlanPass(pass, subject, directory, { serverTime, plan })))(result.pass, result.subject, home ?? configDirectory(), Number.isFinite(served) ? served : undefined, { paid: result.paid, ...(tier ? { tier } : {}) }).catch(() => { });
161
166
  const windowed = windowFields(result);
162
167
  const unlimited = typeof result.unlimited === 'boolean' ? result.unlimited : undefined;
163
168
  const lifetime = Number.isSafeInteger(result.decisionsSinceRollout) && result.decisionsSinceRollout >= 0
@@ -187,6 +192,26 @@ export const getMembership = createMembershipClient({
187
192
  accessToken: getAccessToken, apiBaseUrl: () => getAuthConfiguration().apiBaseUrl,
188
193
  fetch: (...args) => globalThis.fetch(...args),
189
194
  });
195
+ /**
196
+ * The plan check for custom graphs. It is `getMembership`, except that when the account service
197
+ * cannot be reached a stored pass for the signed-in account stands in for the answer until the pass
198
+ * lapses. Hosted services still need the network; this only decides which graphs may be used.
199
+ */
200
+ export function createGraphMembership(deps) {
201
+ return async (signal, home) => {
202
+ const access = await deps.membership(signal, home);
203
+ if (!access.unavailable)
204
+ return access;
205
+ signal?.throwIfAborted();
206
+ const subject = await deps.subject().catch(() => undefined);
207
+ const plan = await (deps.readPlan ?? readOfflinePlan)(subject, home ?? configDirectory()).catch(() => undefined);
208
+ return plan ? { paid: plan.paid, tier: plan.tier, subject: plan.subject, offline: true } : access;
209
+ };
210
+ }
211
+ export const getGraphMembership = createGraphMembership({
212
+ membership: (signal, home) => getMembership(signal, home),
213
+ subject: async () => (await getAuthStatus()).subject,
214
+ });
190
215
  export async function requirePaidMembership(signal) {
191
216
  const access = await getMembership(signal);
192
217
  if (!access.paid)
@@ -196,12 +221,12 @@ export async function requireGraphMembership(signal) {
196
221
  await readGraphMembership(signal);
197
222
  }
198
223
  export async function readGraphMembership(signal) {
199
- const access = await getMembership(signal);
224
+ const access = await getGraphMembership(signal);
200
225
  if (!access.paid && !access.subject)
201
226
  throw PaidMembershipRequiredError.for(access);
202
227
  return access;
203
228
  }
204
- export async function loadAccessibleGraph(id = 'default', signal, membership = getMembership, options = {}) {
229
+ export async function loadAccessibleGraph(id = 'default', signal, membership = getGraphMembership, options = {}) {
205
230
  signal?.throwIfAborted();
206
231
  if (id === RETIRED_ANDORRA_SELECTION && options.allowRetired) {
207
232
  const access = await membership(signal);
@@ -212,8 +237,9 @@ export async function loadAccessibleGraph(id = 'default', signal, membership = g
212
237
  }
213
238
  if (currentGraphSelection(id) === 'default')
214
239
  return structuredClone(SOFTWARE_ENGINEER_HARNESS);
215
- if (id === GRAPH_MANAGER_GRAPH_ID)
216
- return structuredClone(GRAPH_MANAGER_HARNESS);
240
+ const builtIn = builtInGraph(id);
241
+ if (builtIn)
242
+ return builtIn;
217
243
  const access = await membership(signal);
218
244
  signal?.throwIfAborted();
219
245
  if (!access.paid && access.unavailable)
@@ -223,6 +249,8 @@ export async function loadAccessibleGraph(id = 'default', signal, membership = g
223
249
  if (!/^[A-Za-z0-9-]{1,128}$/.test(access.subject))
224
250
  throw new PaidMembershipRequiredError();
225
251
  const directory = await graphStorageDirectory(undefined, access.subject);
252
+ if (access.paid)
253
+ await notePremiumGraphAccount(directory);
226
254
  const graph = access.paid ? await loadGraph(id, undefined, directory) : await loadFreeTierGraph(id, directory);
227
255
  if (!options.allowDeleted && isDeletedGraph(graph))
228
256
  throw new GraphDeletedError(graph.name);
@@ -230,3 +258,15 @@ export async function loadAccessibleGraph(id = 'default', signal, membership = g
230
258
  return graph;
231
259
  return bindPortableGraphProviders(graph, await loadConfig());
232
260
  }
261
+ /**
262
+ * The graph a desktop sent with a relayed run. It is checked as a stored graph is and used for that run only:
263
+ * it is never written to disk, and no plan is asked for, because the desktop that sent it already holds it.
264
+ * Its nodes are bound to the relayed providers by the caller.
265
+ */
266
+ export function relayedGraph(value, options = {}) {
267
+ const graph = validateGraph(value);
268
+ // A deleted graph's definition says so (metadata.deletedAt): a new start refuses it, a resume of a run that used it may go on.
269
+ if (!options.allowDeleted && isDeletedGraph(graph))
270
+ throw new GraphDeletedError(graph.name);
271
+ return graph;
272
+ }
@@ -4,7 +4,7 @@ import { join } from 'node:path';
4
4
  export const MODEL_HEALTH_TTL_MS = 10 * 60_000;
5
5
  const REFRESH_INTERVAL_MS = 60_000;
6
6
  const FILE = 'model-health.json';
7
- const DESCRIPTIVE_FIELDS = new Set(['model', 'models', 'modelContextWindows', 'modelNames', 'modelParameters', 'freeModels', 'contextWindow', 'reasoningEffort']);
7
+ const DESCRIPTIVE_FIELDS = new Set(['model', 'models', 'modelContextWindows', 'modelNames', 'modelParameters', 'freeModels', 'textOnlyModels', 'contextWindow', 'reasoningEffort']);
8
8
  export function modelHealthKey(provider, model) {
9
9
  const reach = Object.fromEntries(Object.entries(provider)
10
10
  .filter(([name]) => !DESCRIPTIVE_FIELDS.has(name))
@@ -4,8 +4,14 @@ export interface ModelMetadata {
4
4
  contextWindow?: number;
5
5
  }
6
6
  export declare function resolveModelContext(provider: ProviderConfig, model: string | undefined, signal: AbortSignal): Promise<ProviderConfig>;
7
- export declare function configuredModelSnapshot(provider: ProviderConfig, model: string | undefined): ProviderConfig;
7
+ export declare function configuredModelSnapshot(provider: ProviderConfig, requested: string | undefined): ProviderConfig;
8
8
  export declare function withEvaluationReasoningEffort(snapshot: ProviderConfig, effort: string | undefined): ProviderConfig;
9
9
  export declare function refreshModelContext(provider: ProviderConfig, signal: AbortSignal): Promise<ProviderConfig>;
10
+ /**
11
+ * The effective context window of each of `models` on `provider`, resolved as `refreshModelContext` resolves one
12
+ * (a window the model server reports, else a saved one, else a known one) with a single listing of the provider.
13
+ * A model whose window is not known is left out.
14
+ */
15
+ export declare function resolveModelContextWindows(provider: ProviderConfig, models: readonly string[], signal: AbortSignal): Promise<Record<string, number>>;
10
16
  /** What the provider lists, with Andorra-known Claude windows filled in where the listing gives none. */
11
17
  export declare function discoverModelMetadata(provider: ProviderConfig, signal: AbortSignal): Promise<ModelMetadata[]>;
@@ -1,4 +1,4 @@
1
- import { configuredContextWindow, deadlinePhrase, MODEL_LISTING_TIMEOUT_MS } from './providers.js';
1
+ import { configuredContextWindow, deadlinePhrase, MODEL_LISTING_TIMEOUT_MS, providerModelId } from './providers.js';
2
2
  import { providerAuthHeaders } from './anthropic-credentials.js';
3
3
  import { validateConfig } from './config.js';
4
4
  import { readOpenCodeModels } from './opencode-catalog.js';
@@ -14,7 +14,9 @@ import { createHostedClient } from './andorra/hosted.js';
14
14
  export async function resolveModelContext(provider, model, signal) {
15
15
  return refreshModelContext(configuredModelSnapshot(provider, model), signal);
16
16
  }
17
- export function configuredModelSnapshot(provider, model) {
17
+ export function configuredModelSnapshot(provider, requested) {
18
+ // A model the provider lists in another case is requested in the provider's own spelling.
19
+ const model = requested === undefined ? undefined : providerModelId(provider, requested) ?? requested;
18
20
  const snapshot = { ...provider };
19
21
  if (model !== undefined && model !== snapshot.model) {
20
22
  snapshot.model = model;
@@ -36,35 +38,53 @@ export function withEvaluationReasoningEffort(snapshot, effort) {
36
38
  export async function refreshModelContext(provider, signal) {
37
39
  const snapshot = configuredModelSnapshot(provider, undefined);
38
40
  signal.throwIfAborted();
39
- if (snapshot.type === 'claude') {
40
- // The Claude CLI's catalog carries no windows; asking it would only cost a process spawn.
41
- if (snapshot.contextWindow === undefined) {
42
- const known = knownClaudeContextWindow(snapshot.model);
43
- if (known !== undefined)
44
- snapshot.contextWindow = known;
45
- }
46
- return snapshot;
41
+ completeContextWindow(snapshot, await readListing(snapshot, signal));
42
+ return snapshot;
43
+ }
44
+ /**
45
+ * The effective context window of each of `models` on `provider`, resolved as `refreshModelContext` resolves one
46
+ * (a window the model server reports, else a saved one, else a known one) with a single listing of the provider.
47
+ * A model whose window is not known is left out.
48
+ */
49
+ export async function resolveModelContextWindows(provider, models, signal) {
50
+ signal.throwIfAborted();
51
+ const listing = await readListing(configuredModelSnapshot(provider, undefined), signal);
52
+ const windows = {};
53
+ for (const model of models) {
54
+ const snapshot = configuredModelSnapshot(provider, model);
55
+ completeContextWindow(snapshot, listing);
56
+ if (snapshot.contextWindow !== undefined)
57
+ windows[model] = snapshot.contextWindow;
47
58
  }
59
+ return windows;
60
+ }
61
+ /** The provider's raw model listing, or undefined for a provider that is not listed for windows or whose listing failed. */
62
+ async function readListing(snapshot, signal) {
63
+ // The Claude CLI's catalog carries no windows; asking it would only cost a process spawn.
48
64
  // Andorra entries carry the router's windows already (saved from GET /v1/hosted).
49
- if (snapshot.type === 'codex' || snapshot.type === 'grok' || snapshot.type === 'google' || snapshot.type === 'andorra')
50
- return snapshot;
65
+ // A relayed entry carries the desktop's windows; its model cannot be listed from here.
66
+ if (['claude', 'codex', 'grok', 'google', 'andorra', 'relayed'].includes(snapshot.type))
67
+ return undefined;
51
68
  try {
52
69
  // The raw listing: a catalog default must not displace a window the user saved.
53
70
  const models = await listModelMetadata(snapshot, signal);
54
71
  signal.throwIfAborted();
55
- const reported = models.find(model => model.id === snapshot.model)?.contextWindow;
56
- if (reported !== undefined)
57
- snapshot.contextWindow = reported;
72
+ return models;
58
73
  }
59
74
  catch {
60
75
  signal.throwIfAborted();
76
+ return undefined;
61
77
  }
62
- if (snapshot.type === 'anthropic' && snapshot.contextWindow === undefined) {
78
+ }
79
+ function completeContextWindow(snapshot, listing) {
80
+ const reported = listing?.find(model => model.id === snapshot.model)?.contextWindow;
81
+ if (reported !== undefined)
82
+ snapshot.contextWindow = reported;
83
+ if ((snapshot.type === 'claude' || snapshot.type === 'anthropic') && snapshot.contextWindow === undefined) {
63
84
  const known = knownClaudeContextWindow(snapshot.model);
64
85
  if (known !== undefined)
65
86
  snapshot.contextWindow = known;
66
87
  }
67
- return snapshot;
68
88
  }
69
89
  function object(value) {
70
90
  return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
@@ -103,6 +123,8 @@ export async function discoverModelMetadata(provider, signal) {
103
123
  return provider.type === 'anthropic' ? models.map(model => model.contextWindow === undefined ? withKnownClaudeWindow(model.id) : model) : models;
104
124
  }
105
125
  async function listModelMetadata(provider, signal) {
126
+ if (provider.type === 'relayed')
127
+ throw new Error('A relayed provider lists its models on your computer.');
106
128
  validateConfig({ version: 1, provider: provider.id, providers: [provider] });
107
129
  if (provider.type === 'codex')
108
130
  return (await readCodexCatalog(signal, codexConnectFor(provider))).models.map(id => ({ id }));
@@ -0,0 +1,116 @@
1
+ import { type ProviderConfig } from '../providers.js';
2
+ import type { EngineFrame } from '../bridge/protocol.js';
3
+ import type { ModelAdapter } from '../types.js';
4
+ /** At most this many relayed requests of one machine are in hand at once, generating or waiting to be delivered; another is left for a later announce. */
5
+ export declare const LOCAL_RELAY_CONCURRENCY = 5;
6
+ /** While a request is generating, the machine hears that it is alive this often, so it keeps the claim. */
7
+ export declare const LOCAL_RELAY_ALIVE_MS = 15000;
8
+ /** Reasoning deltas are sent at most once per this interval. */
9
+ export declare const LOCAL_RELAY_REASONING_BATCH_MS = 100;
10
+ /** A finished result that could not be sent is tried again this often... */
11
+ export declare const LOCAL_RELAY_RESULT_RETRY_MS = 5000;
12
+ /** ...and kept for this long, waiting for the link or for the machine to announce the request again. */
13
+ export declare const LOCAL_RELAY_RESULT_HOLD_MS = 600000;
14
+ /**
15
+ * A request this computer ignored because it does not offer the provider or model asked for, still announced unclaimed
16
+ * this long after, is claimed and declined: another desktop of the account that offers it had that long to take it.
17
+ */
18
+ export declare const LOCAL_RELAY_DECLINE_MS = 60000;
19
+ /**
20
+ * The models a provider offers a linked machine: its default and its listed models. The relay block names exactly
21
+ * these, and a request for any other model is not answered.
22
+ */
23
+ export declare function relayedModelIds(provider: ProviderConfig): string[];
24
+ /** `via` names the link a call went through, so a claim's later calls can be sent through the same one. */
25
+ export type RelaySendAnswer = {
26
+ result?: unknown;
27
+ error?: {
28
+ code: string;
29
+ message: string;
30
+ };
31
+ via?: string;
32
+ };
33
+ export interface LocalModelRelayDeps {
34
+ providers(): Promise<ProviderConfig[]>;
35
+ /** The signed-in account's subject, read once per announce and handed to the two checks below. */
36
+ subject(): Promise<string | undefined>;
37
+ /** Whether `env` may use this computer's models at all: allowed here for `subject`, on its account, not being removed. */
38
+ allowed(env: string, subject: string | undefined): Promise<boolean>;
39
+ /** Whether this computer started or resumed `runId` on `env` for `subject`: only those runs' requests are answered. */
40
+ startedHere(env: string, runId: string, subject: string | undefined): Promise<boolean>;
41
+ createAdapter(provider: ProviderConfig, options: {
42
+ sessionId?: string;
43
+ }): ModelAdapter;
44
+ /**
45
+ * A model.relay call to `env`'s engine. Without `via` it goes through any link that is up and the answer names it;
46
+ * with `via` only through that link, and a link that is gone answers as a link that is down.
47
+ */
48
+ send(env: string, engine: string, method: string, params: Record<string, unknown>, via?: string): Promise<RelaySendAnswer>;
49
+ log(line: string): void;
50
+ now?: () => number;
51
+ }
52
+ /**
53
+ * The desktop engine's half of the model relay: a linked machine's `model.relay.request` is claimed, generated with
54
+ * this computer's own provider, and answered with `model.relay.result`. Only machines the user allowed are answered,
55
+ * only for runs this computer started or resumed there, and nothing but the provider id and the model call itself
56
+ * comes from the machine. The announce carries no payload: it arrives in the answer to the claim.
57
+ */
58
+ export declare class LocalModelRelay {
59
+ private readonly deps;
60
+ private readonly work;
61
+ private readonly ignoredLogged;
62
+ /**
63
+ * Requests this computer ignored because it does not offer their provider or model, by machine and id: when it
64
+ * first ignored each, and when it last saw it announced.
65
+ */
66
+ private readonly declining;
67
+ /** The last announce of each request ignored because its run was not known here yet, so it can be taken once it is. */
68
+ private readonly unknownRun;
69
+ private closed;
70
+ constructor(deps: LocalModelRelayDeps);
71
+ /** Takes a `model.relay.*` frame; true when the frame was one (it is the engine's, not the window's). */
72
+ handle(env: string, frame: EngineFrame): boolean;
73
+ /** Stops every request of `env`: its link ended for good, or it is no longer allowed. */
74
+ dropEnvironment(env: string): void;
75
+ /**
76
+ * This computer has just started or resumed `runId` on `env`: a request of it announced before that was known is
77
+ * taken now rather than at its next announce.
78
+ */
79
+ reconsider(env: string, runId: string): void;
80
+ /** Stops every machine's requests: the account changed. */
81
+ dropAll(): void;
82
+ close(): void;
83
+ private now;
84
+ private key;
85
+ /** `env`'s requests in hand: generating, or answered and waiting to be delivered. */
86
+ private inHand;
87
+ private onRequest;
88
+ private onCancel;
89
+ private ignored;
90
+ private live;
91
+ /**
92
+ * Whether a request this computer does not offer has waited long enough for another desktop to take it. The first
93
+ * time it is seen the clock starts; every announce after that keeps it remembered.
94
+ */
95
+ private declineDue;
96
+ private start;
97
+ /** Claims a request this computer no longer offers and answers that it does not, with no model call. */
98
+ private rememberUnknownRun;
99
+ private decline;
100
+ /** Holds `outcome` for delivery, for at most LOCAL_RELAY_RESULT_HOLD_MS, and sends it. */
101
+ private answer;
102
+ private generate;
103
+ /** Sends a progress call; one that fails (the link is down) is let go, and generation goes on. */
104
+ private progress;
105
+ private reason;
106
+ private scheduleReasoning;
107
+ /** Generation is over: the last batched reasoning goes out first, then the timers that served it stop. */
108
+ private finishGenerating;
109
+ /**
110
+ * Sends the answer. Delivered or refused by the machine, the work is done with it, except that a refusal leaves the
111
+ * answer held for a re-announce; a link that is down keeps it and tries again every 5 s until the hold expires.
112
+ */
113
+ private deliver;
114
+ private reclaim;
115
+ private end;
116
+ }