@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
@@ -11,13 +11,15 @@ import { ANDORRA_UNAVAILABLE_MESSAGE, andorraBaseUrl } from './andorra/endpoint.
11
11
  import { andorraRefusal } from './andorra/errors.js';
12
12
  import { generateEngineResponse, isEngineContextOverflow } from './provider-engine.js';
13
13
  import { estimateStreamedTokens } from './token-rate.js';
14
+ import { textOnlyAdapter } from './image-input.js';
15
+ export { acceptsImages } from './image-input.js';
14
16
  export const REASONING_EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
15
17
  /** Provider types whose requests carry a thinking-effort override. */
16
- export const REASONING_EFFORT_PROVIDER_TYPES = ['openai-compatible', 'opencode-go', 'anthropic'];
18
+ export const REASONING_EFFORT_PROVIDER_TYPES = ['openai-compatible', 'opencode-go', 'anthropic', 'relayed'];
17
19
  export function supportsReasoningEffort(type) {
18
20
  return REASONING_EFFORT_PROVIDER_TYPES.includes(type);
19
21
  }
20
- export const PROVIDER_TYPES = ['openai-compatible', 'anthropic', 'codex', 'claude', 'opencode-go', 'grok', 'opencode', 'google', 'andorra'];
22
+ export const PROVIDER_TYPES = ['openai-compatible', 'anthropic', 'codex', 'claude', 'opencode-go', 'grok', 'opencode', 'google', 'andorra', 'relayed'];
21
23
  export const SIGN_IN_PROVIDER_TYPES = ['codex', 'claude', 'grok', 'opencode', 'google'];
22
24
  export function isSignInProviderType(type) {
23
25
  return SIGN_IN_PROVIDER_TYPES.includes(type);
@@ -128,6 +130,39 @@ export function providerModels(provider) {
128
130
  return provider.models.filter(model => model.trim());
129
131
  return provider.model.trim() ? [provider.model] : [];
130
132
  }
133
+ /**
134
+ * The provider a run resolves by id: the providers the run started with first, then the live configuration.
135
+ * Editing or deleting a provider while the run works saves configuration for later tasks, so the running task
136
+ * keeps the entry it began with (its endpoint, protocol and credentials); a provider added during the run is
137
+ * found in the configuration. Only an explicit switch moves the run onto a provider's edited settings.
138
+ */
139
+ export function runProvider(config, started, id) {
140
+ return started.find(item => item.id === id) ?? config.providers.find(item => item.id === id);
141
+ }
142
+ /**
143
+ * Provider and model ids are matched without regard to case, so a graph saved on a machine whose provider is "GX10"
144
+ * runs on a machine that calls the same provider "gx10". An exact match always wins; otherwise the one entry whose id
145
+ * differs only in case is taken, and none when several do. Callers use the returned entry's own spelling from then on.
146
+ */
147
+ export function findProviderById(providers, id) {
148
+ if (id === undefined)
149
+ return undefined;
150
+ const exact = providers.find(provider => provider.id === id);
151
+ if (exact !== undefined)
152
+ return exact;
153
+ const folded = id.toLowerCase();
154
+ const matches = providers.filter(provider => typeof provider.id === 'string' && provider.id.toLowerCase() === folded);
155
+ return matches.length === 1 ? matches[0] : undefined;
156
+ }
157
+ /** The provider's own spelling of `model`, matched as findProviderById matches ids; undefined when it does not offer it. */
158
+ export function providerModelId(provider, model) {
159
+ const offered = [provider.model, ...(provider.models ?? [])].filter(item => typeof item === 'string' && item.trim());
160
+ if (offered.includes(model))
161
+ return model;
162
+ const folded = model.toLowerCase();
163
+ const matches = [...new Set(offered.filter(item => item.toLowerCase() === folded))];
164
+ return matches.length === 1 ? matches[0] : undefined;
165
+ }
131
166
  export function configuredContextWindow(provider, model) {
132
167
  const id = model ?? provider.model;
133
168
  if (!provider.modelContextWindows || !Object.hasOwn(provider.modelContextWindows, id))
@@ -168,6 +203,9 @@ export function assertProviderCredentials(provider) {
168
203
  if ((provider.type === 'grok' || provider.type === 'opencode' || provider.type === 'google') && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
169
204
  throw new Error(`${SIGN_IN_PRODUCT[provider.type]} providers use their CLI sign-in; API key overrides are not supported.`);
170
205
  }
206
+ if (provider.type === 'relayed' && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
207
+ throw new Error('Relayed providers use the model on your computer; API keys are not supported.');
208
+ }
171
209
  if (provider.type === 'andorra' && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
172
210
  throw new Error('Andorra providers use your Andorra account sign-in; API keys are not supported.');
173
211
  }
@@ -214,13 +252,39 @@ export class ProviderRequestError extends Error {
214
252
  contextOverflow;
215
253
  /** The system error code behind a connection that could not be made; recorded with the failure, never part of the message. */
216
254
  connectionCause;
255
+ /** What kind of failure this was, for telemetry (`provider_timeout`, `http_429`); never shown and never part of the message. */
256
+ telemetryCode;
217
257
  constructor(message, contextOverflow = false) {
218
258
  super(message);
219
259
  this.contextOverflow = contextOverflow;
220
260
  this.name = 'Error';
221
261
  }
222
262
  }
223
- class RetryableProviderError extends ProviderRequestError {
263
+ function coded(error, code) { error.telemetryCode = code; return error; }
264
+ /**
265
+ * The telemetry error code for an error that ended a run: a provider failure's code, a record-only
266
+ * `telemetryCode` another adapter attached (Claude's exhausted malformed steps), or `runtime_error`.
267
+ */
268
+ export function runFailureCode(error) {
269
+ if (error instanceof ProviderRequestError)
270
+ return providerFailureCode(error);
271
+ const code = error?.telemetryCode;
272
+ return typeof code === 'string' && code ? code : 'runtime_error';
273
+ }
274
+ /** The telemetry error code for a failed provider request: an OS code, a named kind, or `http_<status>`. */
275
+ export function providerFailureCode(error) {
276
+ if (!(error instanceof ProviderRequestError))
277
+ return 'provider_error';
278
+ if (error.connectionCause)
279
+ return error.connectionCause;
280
+ if (error.telemetryCode)
281
+ return error.telemetryCode;
282
+ if (error.contextOverflow)
283
+ return 'context_overflow';
284
+ const status = error.status;
285
+ return typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 599 ? `http_${status}` : 'provider_error';
286
+ }
287
+ export class RetryableProviderError extends ProviderRequestError {
224
288
  retryAfterMs;
225
289
  retryDelaysMs;
226
290
  maxRetries;
@@ -235,13 +299,13 @@ class RetryableProviderError extends ProviderRequestError {
235
299
  }
236
300
  }
237
301
  class MalformedResponseProviderError extends RetryableProviderError {
238
- constructor() { super(MALFORMED_RESPONSE_MESSAGE, 0, MALFORMED_RESPONSE_RETRY_DELAYS_MS, MALFORMED_RESPONSE_RETRIES, true); }
302
+ constructor() { super(MALFORMED_RESPONSE_MESSAGE, 0, MALFORMED_RESPONSE_RETRY_DELAYS_MS, MALFORMED_RESPONSE_RETRIES, true); this.telemetryCode = 'malformed_response'; }
239
303
  }
240
304
  class MalformedStreamProviderError extends MalformedResponseProviderError {
241
305
  }
242
306
  export const BLANK_TOOL_CALL_LIMIT = 4096;
243
307
  class BlankToolCallProviderError extends RetryableProviderError {
244
- constructor() { super('Provider streamed a tool call that kept generating blank output.', 0, MALFORMED_STREAM_RETRY_DELAYS_MS, MALFORMED_STREAM_RETRIES); }
308
+ constructor() { super('Provider streamed a tool call that kept generating blank output.', 0, MALFORMED_STREAM_RETRY_DELAYS_MS, MALFORMED_STREAM_RETRIES); this.telemetryCode = 'blank_tool_call'; }
245
309
  }
246
310
  export function createBlankToolCallGuard(limit = BLANK_TOOL_CALL_LIMIT) {
247
311
  let blank = 0;
@@ -302,7 +366,7 @@ async function boundedJson(response) {
302
366
  let bytes = 0;
303
367
  try {
304
368
  while (true) {
305
- const chunk = await reader.read().catch(() => { throw new RetryableProviderError('Provider connection failed while reading its response.'); });
369
+ const chunk = await reader.read().catch(() => { throw coded(new RetryableProviderError('Provider connection failed while reading its response.'), 'stream_interrupted'); });
306
370
  if (chunk.done)
307
371
  break;
308
372
  if (chunk.value.byteLength > buffer.length - bytes) {
@@ -704,7 +768,7 @@ function createAnthropicStreamAccumulator(now = Date.now) {
704
768
  },
705
769
  finish(requests, completionAdvertised) {
706
770
  if (!started || !stopped || !finishReason)
707
- throw new RetryableProviderError('Provider closed the stream before the response completed.');
771
+ throw coded(new RetryableProviderError('Provider closed the stream before the response completed.'), 'stream_interrupted');
708
772
  const ordered = [...blocks.entries()].sort(([a], [b]) => a - b).map(([, block]) => block);
709
773
  const text = ordered.filter(block => block.type === 'text').map(block => block.text).join('\n');
710
774
  const measured = decodeWindow();
@@ -722,8 +786,15 @@ function createAnthropicStreamAccumulator(now = Date.now) {
722
786
  };
723
787
  }
724
788
  /** The router reads `x-andorra-session` only in this form and ignores anything else, so nothing else is sent. */
725
- const ANDORRA_SESSION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
789
+ export const ANDORRA_SESSION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
790
+ /** The adapter for a provider entry. Requests for one of its text-only models never carry an image. */
726
791
  export function createAdapter(config, options = {}) {
792
+ return textOnlyAdapter(createProviderAdapter(config, options), config);
793
+ }
794
+ function createProviderAdapter(config, options = {}) {
795
+ // A relayed provider's model is on the desktop: only the run's model relay can reach it.
796
+ if (config.type === 'relayed')
797
+ throw new Error('A relayed provider needs a run.');
727
798
  if (config.reasoningEffort !== undefined && (!['openai-compatible', 'opencode-go', 'anthropic'].includes(config.type) || !REASONING_EFFORTS.includes(config.reasoningEffort)))
728
799
  throw new Error('Reasoning effort overrides require an OpenAI-compatible, OpenCode Go or Anthropic provider and a supported effort value.');
729
800
  assertRequestTimeout(config);
@@ -773,7 +844,7 @@ export function createAdapter(config, options = {}) {
773
844
  if (signal.aborted)
774
845
  cancelled();
775
846
  if (authDeadline?.aborted)
776
- throw new RetryableProviderError('Provider request timed out.');
847
+ throw coded(new RetryableProviderError('Provider request timed out.'), 'provider_timeout');
777
848
  throw error;
778
849
  }
779
850
  const headers = { 'content-type': 'application/json', ...sessionHeader, ...credential };
@@ -803,19 +874,18 @@ export function createAdapter(config, options = {}) {
803
874
  if (signal.aborted)
804
875
  throw new Error('Provider request cancelled.');
805
876
  if (deadline?.aborted)
806
- throw new RetryableProviderError('Provider request timed out.');
877
+ throw coded(new RetryableProviderError('Provider request timed out.'), 'provider_timeout');
807
878
  // A connection that could not be made is not one of the router's refusals: it gets the usual bounded
808
879
  // retries, and the plain sentence (no address, no error code) while retrying and when they run out.
809
880
  if (andorra) {
810
881
  const failure = permanentConnectionFailure(error) ? new ProviderRequestError(ANDORRA_UNAVAILABLE_MESSAGE) : new RetryableProviderError(ANDORRA_UNAVAILABLE_MESSAGE);
811
882
  failure.connectionCause = connectionFailureDetail(error);
812
- throw failure;
883
+ throw coded(failure, 'connection_failed');
813
884
  }
814
885
  const cause = connectionFailureDetail(error);
815
886
  const message = `Provider connection failed${cause ? ` (${cause})` : ''}. Check its URL and network connection.`;
816
- if (permanentConnectionFailure(error))
817
- throw new ProviderRequestError(message);
818
- throw new RetryableProviderError(message);
887
+ const failure = permanentConnectionFailure(error) ? new ProviderRequestError(message) : new RetryableProviderError(message);
888
+ throw coded(failure, cause ?? 'connection_failed');
819
889
  }
820
890
  if (response.status === 401 && config.anthropicAuth === 'console' && !forceRefresh) {
821
891
  dispose();
@@ -836,12 +906,12 @@ export function createAdapter(config, options = {}) {
836
906
  // The router's own refusals are sent once and shown as written here, never retried.
837
907
  const refusal = andorra ? andorraRefusal(response.status, errorData, response.headers.get('retry-after')) : undefined;
838
908
  if (refusal)
839
- throw new ProviderRequestError(refusal);
909
+ throw coded(new ProviderRequestError(refusal), `http_${response.status}`);
840
910
  const detail = providerErrorDetail(errorData);
841
911
  const shown = detail === undefined ? undefined : redactCredential(detail, key);
842
912
  const message = `Provider request failed (HTTP ${response.status})${shown ? `: ${shown}` : ''}. Check credentials, model, and provider availability.`;
843
913
  if ([408, 409, 429, 500, 502, 503, 504, 529].includes(response.status)) {
844
- throw new RetryableProviderError(message, retryAfter(response.headers.get('retry-after')));
914
+ throw coded(new RetryableProviderError(message, retryAfter(response.headers.get('retry-after'))), `http_${response.status}`);
845
915
  }
846
916
  throw new HttpProviderError(message, response.status);
847
917
  }
@@ -929,7 +999,7 @@ export function createAdapter(config, options = {}) {
929
999
  if (signal.aborted)
930
1000
  throw new Error('Provider request cancelled.');
931
1001
  if (deadline?.aborted)
932
- throw new RetryableProviderError('Provider request timed out.');
1002
+ throw coded(new RetryableProviderError('Provider request timed out.'), 'provider_timeout');
933
1003
  if (error instanceof ResponseTooLargeError || error instanceof RetryableProviderError)
934
1004
  throw error;
935
1005
  return malformed();
@@ -951,12 +1021,12 @@ export function createAdapter(config, options = {}) {
951
1021
  if (retry >= error.maxRetries)
952
1022
  throw error;
953
1023
  if (error.retryAfterMs > MAX_AUTOMATIC_RETRY_AFTER_MS)
954
- throw new ProviderRequestError(`${error.message} Retry-After exceeds the 120-second automatic retry limit.`);
1024
+ throw coded(new ProviderRequestError(`${error.message} Retry-After exceeds the 120-second automatic retry limit.`), providerFailureCode(error));
955
1025
  const delayMs = Math.max(error.retryDelaysMs[retry] ?? error.retryDelaysMs.at(-1) ?? 0, error.retryAfterMs);
956
1026
  const reason = error instanceof MalformedStreamProviderError
957
1027
  ? 'Provider returned a malformed streamed response; retrying without streaming.'
958
1028
  : error.message;
959
- await onRetry?.({ retry: retry + 1, maxRetries: error.maxRetries, delayMs, reason, ...(error.quiet ? { quiet: true } : {}),
1029
+ await onRetry?.({ retry: retry + 1, maxRetries: error.maxRetries, delayMs, reason, code: providerFailureCode(error), ...(error.quiet ? { quiet: true } : {}),
960
1030
  ...(error.connectionCause ? { cause: error.connectionCause } : {}) });
961
1031
  try {
962
1032
  await delay(delayMs, undefined, { signal });
@@ -1009,7 +1079,7 @@ export function createAdapter(config, options = {}) {
1009
1079
  if (signal.aborted)
1010
1080
  cancelled();
1011
1081
  if (deadline?.aborted)
1012
- throw new RetryableProviderError('Provider request timed out.');
1082
+ throw coded(new RetryableProviderError('Provider request timed out.'), 'provider_timeout');
1013
1083
  if (error instanceof ResponseTooLargeError || error instanceof RetryableProviderError)
1014
1084
  throw error;
1015
1085
  return malformed();
@@ -1051,7 +1121,7 @@ export function createAdapter(config, options = {}) {
1051
1121
  ...(thinking.length ? { providerContinuation: { api: 'anthropic-messages', provider: config.id, model, thinking } } : {}) };
1052
1122
  },
1053
1123
  checkCalls: calls => checkCalls(calls, advertised),
1054
- streamReadError: () => new RetryableProviderError('Provider connection failed while reading its response.'),
1124
+ streamReadError: () => coded(new RetryableProviderError('Provider connection failed while reading its response.'), 'stream_interrupted'),
1055
1125
  streamMalformedError: () => new MalformedStreamProviderError(),
1056
1126
  streamingDisabled: () => currentRequestNonStreaming,
1057
1127
  ...(anthropic ? { streamValidator() {
@@ -1061,7 +1131,7 @@ export function createAdapter(config, options = {}) {
1061
1131
  const validator = createStreamAccumulator(() => { });
1062
1132
  return { event: validator.event, finish() {
1063
1133
  if (!validator.completed)
1064
- throw new RetryableProviderError('Provider closed the stream before the response completed.');
1134
+ throw coded(new RetryableProviderError('Provider closed the stream before the response completed.'), 'stream_interrupted');
1065
1135
  return validator.finish(requests, advertised);
1066
1136
  } };
1067
1137
  } }),
@@ -1069,7 +1139,7 @@ export function createAdapter(config, options = {}) {
1069
1139
  if (signal.aborted)
1070
1140
  cancelled();
1071
1141
  if (deadline?.aborted)
1072
- throw new RetryableProviderError('Provider request timed out.');
1142
+ throw coded(new RetryableProviderError('Provider request timed out.'), 'provider_timeout');
1073
1143
  if (error instanceof Error && !(error instanceof RetryableProviderError) && error.message === MALFORMED_RESPONSE_MESSAGE)
1074
1144
  throw new MalformedResponseProviderError();
1075
1145
  throw error;
@@ -0,0 +1,26 @@
1
+ export type PullRequestCheckState = 'passed' | 'failed' | 'pending' | 'skipped' | 'neutral' | 'cancelled';
2
+ export interface PullRequestCheck {
3
+ name: string;
4
+ workflow?: string;
5
+ state: PullRequestCheckState;
6
+ url?: string;
7
+ description?: string;
8
+ startedAt?: string;
9
+ completedAt?: string;
10
+ }
11
+ /** The checks on the head commit, rolled up: failed if any failed, pending if any is still running, passed otherwise. */
12
+ export interface PullRequestChecksRollup {
13
+ state: 'passed' | 'failed' | 'pending';
14
+ total: number;
15
+ passed: number;
16
+ failed: number;
17
+ pending: number;
18
+ }
19
+ /** One CheckRun or StatusContext from `statusCheckRollup`, in the tab's words. */
20
+ export declare function parseCheck(value: unknown): PullRequestCheck | undefined;
21
+ /** Cancelled, skipped and neutral checks neither pass nor fail the rollup; with nothing else there is no rollup. */
22
+ export declare function checksRollup(checks: readonly Pick<PullRequestCheck, 'state'>[]): PullRequestChecksRollup | undefined;
23
+ export declare function sameChecksRollup(a: PullRequestChecksRollup | undefined, b: PullRequestChecksRollup | undefined): boolean;
24
+ export declare function isChecksRollup(value: unknown): value is PullRequestChecksRollup;
25
+ /** Every check's rollup from a raw `statusCheckRollup` list. */
26
+ export declare function rollupOf(raw: unknown): PullRequestChecksRollup | undefined;
@@ -0,0 +1,56 @@
1
+ // The checks on a pull request's head commit, as GitHub's `statusCheckRollup` reports them, in the
2
+ // desktop's words. Both the PR watcher (for the sidebar's failing-checks mark) and the PR tab read them.
3
+ const text = (value) => typeof value === 'string' && value !== '' ? value : undefined;
4
+ const record = (value) => typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
5
+ // GitHub reports a check that has not finished with the zero time.
6
+ const stamp = (value) => { const at = text(value); return at === undefined || at.startsWith('0001-01-01') ? undefined : at; };
7
+ /** One CheckRun or StatusContext from `statusCheckRollup`, in the tab's words. */
8
+ export function parseCheck(value) {
9
+ const node = record(value);
10
+ if (node.__typename === 'StatusContext' || (node.context !== undefined && node.name === undefined)) {
11
+ const name = text(node.context);
12
+ if (name === undefined)
13
+ return undefined;
14
+ const state = node.state === 'SUCCESS' ? 'passed' : node.state === 'FAILURE' || node.state === 'ERROR' ? 'failed' : 'pending';
15
+ return { name, state, ...defined({ url: text(node.targetUrl), description: text(node.description), startedAt: stamp(node.startedAt) ?? stamp(node.createdAt) }) };
16
+ }
17
+ const name = text(node.name);
18
+ if (name === undefined)
19
+ return undefined;
20
+ const conclusion = typeof node.conclusion === 'string' ? node.conclusion : '';
21
+ const state = node.status !== 'COMPLETED' ? 'pending'
22
+ : conclusion === 'SUCCESS' ? 'passed'
23
+ : conclusion === 'SKIPPED' ? 'skipped'
24
+ : conclusion === 'NEUTRAL' ? 'neutral'
25
+ : conclusion === 'CANCELLED' ? 'cancelled'
26
+ : conclusion === '' ? 'pending' : 'failed';
27
+ return { name, state, ...defined({ workflow: text(node.workflowName), url: text(node.detailsUrl), startedAt: stamp(node.startedAt), completedAt: stamp(node.completedAt) }) };
28
+ }
29
+ /** Cancelled, skipped and neutral checks neither pass nor fail the rollup; with nothing else there is no rollup. */
30
+ export function checksRollup(checks) {
31
+ const passed = checks.filter(check => check.state === 'passed').length;
32
+ const failed = checks.filter(check => check.state === 'failed').length;
33
+ const pending = checks.filter(check => check.state === 'pending').length;
34
+ if (passed + failed + pending === 0)
35
+ return undefined;
36
+ return { state: failed > 0 ? 'failed' : pending > 0 ? 'pending' : 'passed', total: checks.length, passed, failed, pending };
37
+ }
38
+ export function sameChecksRollup(a, b) {
39
+ return a === b || (a !== undefined && b !== undefined && a.state === b.state && a.total === b.total && a.passed === b.passed && a.failed === b.failed && a.pending === b.pending);
40
+ }
41
+ export function isChecksRollup(value) {
42
+ const rollup = record(value);
43
+ return (rollup.state === 'passed' || rollup.state === 'failed' || rollup.state === 'pending')
44
+ && [rollup.total, rollup.passed, rollup.failed, rollup.pending].every(entry => typeof entry === 'number' && Number.isSafeInteger(entry) && entry >= 0);
45
+ }
46
+ /** Every check's rollup from a raw `statusCheckRollup` list. */
47
+ export function rollupOf(raw) {
48
+ return Array.isArray(raw) ? checksRollup(raw.map(parseCheck).filter((check) => check !== undefined)) : undefined;
49
+ }
50
+ function defined(values) {
51
+ const kept = {};
52
+ for (const [key, value] of Object.entries(values))
53
+ if (value !== undefined)
54
+ kept[key] = value;
55
+ return kept;
56
+ }
@@ -0,0 +1,134 @@
1
+ import type { GhRunner } from './pull-requests.js';
2
+ /** GitHub's reactions, in GitHub's order. */
3
+ export declare const REACTION_CONTENTS: readonly ["THUMBS_UP", "THUMBS_DOWN", "LAUGH", "HOORAY", "CONFUSED", "HEART", "ROCKET", "EYES"];
4
+ export type PullRequestReactionContent = typeof REACTION_CONTENTS[number];
5
+ export interface PullRequestReaction {
6
+ content: PullRequestReactionContent;
7
+ count: number;
8
+ /** The viewer reacted with this one. */
9
+ mine: boolean;
10
+ }
11
+ /** What the viewer may do with a comment, as GitHub says. */
12
+ export interface PullRequestCommentAbilities {
13
+ canEdit: boolean;
14
+ canDelete: boolean;
15
+ canReact: boolean;
16
+ }
17
+ /** A comment on the PR's conversation (an issue comment), not on a line. */
18
+ export interface PullRequestTimelineComment extends PullRequestCommentAbilities {
19
+ id: string;
20
+ author: string;
21
+ body: string;
22
+ createdAt?: string;
23
+ editedAt?: string;
24
+ url?: string;
25
+ /** Hidden on GitHub (spam, outdated, off-topic …): GitHub's reason, lower case. */
26
+ hidden?: string;
27
+ viewerIsAuthor: boolean;
28
+ reactions: PullRequestReaction[];
29
+ }
30
+ export type PullRequestReviewBodyState = 'approved' | 'changes-requested' | 'commented' | 'dismissed';
31
+ /** A submitted review, with what the timeline needs to show, react to and edit it. */
32
+ export interface PullRequestReviewBody extends PullRequestCommentAbilities {
33
+ id: string;
34
+ author: string;
35
+ state: PullRequestReviewBodyState;
36
+ body: string;
37
+ submittedAt?: string;
38
+ url?: string;
39
+ /** Line comments the review carried, which sit in the Files diff. */
40
+ comments: number;
41
+ viewerIsAuthor: boolean;
42
+ reactions: PullRequestReaction[];
43
+ }
44
+ export interface PullRequestLabel {
45
+ id: string;
46
+ name: string;
47
+ color?: string;
48
+ description?: string;
49
+ }
50
+ export interface PullRequestAssignee {
51
+ id: string;
52
+ login: string;
53
+ }
54
+ /** The PR's own text and metadata, which the tab can edit. */
55
+ export interface PullRequestMeta {
56
+ title: string;
57
+ body: string;
58
+ canUpdate: boolean;
59
+ canClose: boolean;
60
+ canReopen: boolean;
61
+ headRefName: string;
62
+ headSha: string;
63
+ /** Where the head branch lives (`owner/name`); a suggestion is committed there. */
64
+ headRepository?: string;
65
+ labels: PullRequestLabel[];
66
+ assignees: PullRequestAssignee[];
67
+ /** The repository's labels the PR can take (the first 100, by name). */
68
+ repositoryLabels: PullRequestLabel[];
69
+ /** People the PR can be assigned to (the first 100), with the ids GitHub's mutations take. */
70
+ assignable: PullRequestAssignee[];
71
+ reactions: PullRequestReaction[];
72
+ }
73
+ export declare const REACTION_FIELDS = "reactionGroups { content viewerHasReacted reactors { totalCount } }";
74
+ /** The timeline's comments and reviews and the PR's metadata, asked for inside the review read's `pullRequest`. */
75
+ export declare const CONVERSATION_FIELDS = "title body viewerCanUpdate viewerCanClose viewerCanReopen headRefName headRefOid headRepository { nameWithOwner } reactionGroups { content viewerHasReacted reactors { totalCount } } labels(first: 50) { nodes { id name color description } } assignees(first: 20) { nodes { id login } } comments(last: 100) { totalCount nodes { id author { login } body createdAt lastEditedAt url isMinimized minimizedReason viewerDidAuthor viewerCanUpdate viewerCanDelete viewerCanReact reactionGroups { content viewerHasReacted reactors { totalCount } } } } timelineReviews: reviews(last: 100, states: [APPROVED, CHANGES_REQUESTED, COMMENTED, DISMISSED]) { nodes { id author { login } state body submittedAt url viewerDidAuthor viewerCanUpdate viewerCanReact comments { totalCount } reactionGroups { content viewerHasReacted reactors { totalCount } } } }";
76
+ /** The repository's side of the conversation read, inside `repository`. */
77
+ export declare const REPOSITORY_LABEL_FIELDS = "labels(first: 100, orderBy: { field: NAME, direction: ASC }) { nodes { id name color description } }";
78
+ /** What a review thread's comments add for reactions, editing and suggestions. */
79
+ export declare const THREAD_COMMENT_FIELDS = "author { login ... on User { databaseId } ... on Bot { databaseId } } viewerCanUpdate viewerCanDelete viewerCanReact reactionGroups { content viewerHasReacted reactors { totalCount } }";
80
+ export declare function parseReactions(value: unknown): PullRequestReaction[];
81
+ export declare function abilitiesOf(node: Record<string, unknown>): PullRequestCommentAbilities;
82
+ export declare function parseTimelineComment(value: unknown): PullRequestTimelineComment | undefined;
83
+ export declare function parseReviewBody(value: unknown): PullRequestReviewBody | undefined;
84
+ /** The conversation part of the review read: timeline comments, review bodies and the PR's metadata. */
85
+ export declare function parseConversation(pullRequest: unknown, repository: unknown): {
86
+ comments: PullRequestTimelineComment[];
87
+ moreComments?: number;
88
+ reviewBodies: PullRequestReviewBody[];
89
+ meta: PullRequestMeta;
90
+ } | undefined;
91
+ /**
92
+ * The replacement lines of a comment's ```suggestion block, when it has exactly one; GitHub offers to
93
+ * commit a comment's suggestion only then. An empty block suggests deleting the lines (no lines); a
94
+ * block holding one blank line suggests a blank line (one empty line), as on GitHub.
95
+ */
96
+ export declare function suggestionOf(body: string): string[] | undefined;
97
+ /** Whether a file uses one kind of line ending throughout; a suggestion is committed only into such a file. */
98
+ export declare function uniformLineEndings(file: string): boolean;
99
+ /**
100
+ * The file with lines `start`..`end` (1-based, inclusive) replaced by `replacement`, in the file's own
101
+ * line endings. Undefined when the file has fewer lines than that.
102
+ */
103
+ export declare function applySuggestionText(file: string, start: number, end: number, replacement: readonly string[]): string | undefined;
104
+ /** GitHub's commit trailer for the person who suggested the change. */
105
+ export declare function coAuthorTrailer(login: string, databaseId: number | undefined): string | undefined;
106
+ export declare function addComment(gh: GhRunner, subjectId: string, body: string): Promise<{
107
+ id?: string;
108
+ url?: string;
109
+ }>;
110
+ /** Where a comment the tab can change lives on GitHub, which decides the mutation. */
111
+ export type PullRequestCommentKind = 'issue' | 'review' | 'thread';
112
+ export declare function editComment(gh: GhRunner, kind: PullRequestCommentKind, id: string, body: string): Promise<void>;
113
+ export declare function deleteComment(gh: GhRunner, kind: Exclude<PullRequestCommentKind, 'review'>, id: string): Promise<void>;
114
+ export declare function setReaction(gh: GhRunner, subjectId: string, content: PullRequestReactionContent, add: boolean): Promise<void>;
115
+ /**
116
+ * The file at `ref` in `repository` (`owner/name`): its text and blob sha, which an update names so
117
+ * GitHub refuses one when the file changed since (`409`).
118
+ */
119
+ export declare function readFileAt(gh: GhRunner, repository: string, path: string, ref: string): Promise<{
120
+ text: string;
121
+ sha: string;
122
+ utf8: boolean;
123
+ }>;
124
+ /** Commits `content` as `path` on `branch` (`PUT /repos/{o}/{r}/contents/{path}`), the message and file on standard input. */
125
+ export declare function commitFile(gh: GhRunner, repository: string, change: {
126
+ path: string;
127
+ branch: string;
128
+ sha: string;
129
+ content: string;
130
+ message: string;
131
+ }): Promise<{
132
+ commit?: string;
133
+ }>;
134
+ export declare function reactionContent(value: unknown): PullRequestReactionContent;