@foldrun/core 0.3.0 → 0.4.0

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 (83) hide show
  1. package/README.md +27 -10
  2. package/dist/src/approvals.d.ts +104 -1
  3. package/dist/src/approvals.js +192 -2
  4. package/dist/src/budget.d.ts +32 -0
  5. package/dist/src/budget.js +177 -0
  6. package/dist/src/catalog.js +2 -1
  7. package/dist/src/confine.js +6 -1
  8. package/dist/src/egress.d.ts +19 -2
  9. package/dist/src/egress.js +2 -1
  10. package/dist/src/evals.d.ts +4 -0
  11. package/dist/src/evals.js +20 -11
  12. package/dist/src/flow-lint.d.ts +4 -0
  13. package/dist/src/flow-lint.js +108 -0
  14. package/dist/src/host-env.d.ts +8 -0
  15. package/dist/src/host-env.js +48 -0
  16. package/dist/src/json-schema.d.ts +12 -0
  17. package/dist/src/json-schema.js +202 -0
  18. package/dist/src/library.js +13 -1
  19. package/dist/src/notify.d.ts +79 -1
  20. package/dist/src/notify.js +243 -9
  21. package/dist/src/paths.d.ts +5 -0
  22. package/dist/src/paths.js +32 -0
  23. package/dist/src/platform.d.ts +102 -2
  24. package/dist/src/platform.js +18 -2
  25. package/dist/src/provider-health.d.ts +55 -0
  26. package/dist/src/provider-health.js +232 -0
  27. package/dist/src/run-container.d.ts +57 -4
  28. package/dist/src/run-container.js +147 -41
  29. package/dist/src/runner.d.ts +39 -3
  30. package/dist/src/runner.js +422 -73
  31. package/dist/src/script-tools.d.ts +12 -0
  32. package/dist/src/script-tools.js +10 -2
  33. package/dist/src/secret-health.d.ts +59 -0
  34. package/dist/src/secret-health.js +155 -0
  35. package/dist/src/secrets.d.ts +19 -1
  36. package/dist/src/secrets.js +44 -12
  37. package/dist/src/starter.js +3 -0
  38. package/dist/src/step-exec.d.ts +47 -1
  39. package/dist/src/step-exec.js +155 -60
  40. package/dist/src/store.d.ts +276 -3
  41. package/dist/src/store.js +552 -26
  42. package/dist/src/tar.js +2 -1
  43. package/dist/src/test-mode.d.ts +111 -0
  44. package/dist/src/test-mode.js +285 -0
  45. package/dist/src/tool-test.js +48 -21
  46. package/dist/src/translator.js +2 -1
  47. package/dist/src/trigger-log.d.ts +43 -0
  48. package/dist/src/trigger-log.js +122 -0
  49. package/dist/src/triggers.d.ts +20 -0
  50. package/dist/src/triggers.js +91 -10
  51. package/dist/src/webhook.d.ts +15 -3
  52. package/dist/src/webhook.js +11 -11
  53. package/package.json +4 -4
  54. package/src/approvals.ts +253 -2
  55. package/src/budget.ts +178 -0
  56. package/src/catalog.ts +2 -1
  57. package/src/confine.ts +6 -1
  58. package/src/egress.ts +20 -4
  59. package/src/evals.ts +25 -9
  60. package/src/flow-lint.ts +118 -0
  61. package/src/host-env.ts +51 -0
  62. package/src/json-schema.ts +184 -0
  63. package/src/library.ts +13 -1
  64. package/src/notify.ts +272 -11
  65. package/src/paths.ts +29 -0
  66. package/src/platform.ts +107 -3
  67. package/src/provider-health.ts +274 -0
  68. package/src/run-container.ts +175 -36
  69. package/src/runner.ts +435 -65
  70. package/src/script-tools.ts +18 -2
  71. package/src/secret-health.ts +185 -0
  72. package/src/secrets.ts +44 -10
  73. package/src/starter.ts +3 -0
  74. package/src/step-exec.ts +128 -13
  75. package/src/storage.ts +8 -2
  76. package/src/store.ts +746 -25
  77. package/src/tar.ts +2 -1
  78. package/src/test-mode.ts +311 -0
  79. package/src/tool-test.ts +49 -20
  80. package/src/translator.ts +2 -1
  81. package/src/trigger-log.ts +159 -0
  82. package/src/triggers.ts +92 -10
  83. package/src/webhook.ts +17 -11
package/src/platform.ts CHANGED
@@ -12,13 +12,34 @@
12
12
  // and calls registerPlatform() once at boot. A process that forgets to is a
13
13
  // local install — which is exactly the failure that is safe.
14
14
 
15
- import type { FlowStep, RunRecord } from "./store.ts";
15
+ import type { FlowInfo, FlowStep, RunRecord } from "./store.ts";
16
16
  import type { RunInContainerArgs, ContainerStepOutcome } from "./run-container.ts";
17
17
  import type { EgressHooks } from "./egress.ts";
18
18
 
19
19
  export type IsolatedStepRunner = (args: RunInContainerArgs) => Promise<ContainerStepOutcome>;
20
20
 
21
+ /** Who this install is for. `hosted` means someone is paying the operator
22
+ * for it — a wallet, a plan, a bill. `self-hosted` is everything else: a
23
+ * laptop, a company's own box, the open-source download. */
24
+ export type Edition = "self-hosted" | "hosted";
25
+
26
+ /** What a trigger gate decided. `admit: false` is never an error: the
27
+ * trigger was received and understood, and the flow's own file says this
28
+ * one does not become a run. `detail` is what the sender and the log are
29
+ * told, because a silent drop reads exactly like a broken hook. */
30
+ export type TriggerAdmission =
31
+ | { admit: true }
32
+ | { admit: false; reason: "duplicate" | "throttled" | "quarantined" | "debounced"; detail: string; firesAt?: number };
33
+
21
34
  export interface PlatformHooks {
35
+ /** Is this a hosted install? The ONE question every commercial surface —
36
+ * the wallet, top-ups, plan limits, whatever is added next that assumes
37
+ * a customer — asks before it renders or answers. Default: self-hosted,
38
+ * which is what a process that never registered a platform is, and what
39
+ * the open-source image is unless its operator configures billing. One
40
+ * predicate, one place, so "does the community build show X" is a test
41
+ * and not an audit. */
42
+ edition(): Edition;
22
43
  /** Put a flow run where a worker will pick it up. Default: start it here, now. */
23
44
  enqueueFlowRun(
24
45
  tenant: string,
@@ -27,10 +48,60 @@ export interface PlatformHooks {
27
48
  flowName: string,
28
49
  modelOverride?: string | null,
29
50
  tags?: string[],
51
+ /** The person who asked, when one did — their email. A schedule, a
52
+ * webhook and a chained flow leave it unset, which is what makes
53
+ * "nobody approves their own run" a rule the record can enforce. */
54
+ startedBy?: string | null,
55
+ /** `test: true` marks the run a test run (see test-mode.ts). Unset
56
+ * lets the platform decide — a preview workspace's runs are tests
57
+ * unless the flow says `live: true`. */
58
+ opts?: { test?: boolean },
30
59
  ): Promise<RunRecord>;
31
60
  /** A parked run was approved and has no driver; line it up. Default: nothing —
32
61
  * locally the starter that parked it is still polling the record. */
33
62
  enqueueResume(tenant: string, workspace: string, runId: string): Promise<void>;
63
+ /**
64
+ * What a run has spent so far, in the money the customer is actually
65
+ * billed — tokens AND the sandbox seconds behind them.
66
+ *
67
+ * `budget:` says "the most one run may spend", and for a long time it
68
+ * only ever compared token cost. A step that called no model — a script
69
+ * looping on a page that never loads, a browser waiting on a selector
70
+ * that never appears — spent nothing by that reading and was capped by
71
+ * nothing, while the sandbox billed by the second. The platform has no
72
+ * clock of its own by design, so the cap is the only backstop there is,
73
+ * and it has to count the whole bill for that to be true.
74
+ *
75
+ * Default: token cost, which is the entire bill on an install that
76
+ * prices no compute.
77
+ */
78
+ runSpend(run: RunRecord): number;
79
+ /**
80
+ * Should a trigger become a run? The flow file's `idempotency:`,
81
+ * `throttle:`, `debounce:` and `disable_after:` are all answered here,
82
+ * because all four need state that outlives one delivery — what has been
83
+ * seen, when the last run started, what is still being waited out.
84
+ *
85
+ * Default: yes, always. A laptop has no fleet to protect and no duplicate
86
+ * deliveries to remember; the local runner is the one asking, and it asked
87
+ * because a person did.
88
+ */
89
+ admitTrigger(
90
+ tenant: string,
91
+ workspace: string,
92
+ flow: FlowInfo,
93
+ opts?: { deliveryKey?: string | null; body?: string; tag?: string },
94
+ ): Promise<TriggerAdmission>;
95
+ /** An admitted trigger whose start then threw. Undoes what admitTrigger
96
+ * recorded — the delivery as seen, the throttle window — so the sender's
97
+ * retry is a fresh event rather than a "duplicate" of a run that never
98
+ * existed. Default: nothing, because the default gate records nothing. */
99
+ rollbackTrigger(
100
+ tenant: string,
101
+ workspace: string,
102
+ flow: FlowInfo,
103
+ opts?: { deliveryKey?: string | null; reason?: string },
104
+ ): Promise<void>;
34
105
  /** Step executors by FOLDRUN_RUN_ISOLATION value, beyond the `container`
35
106
  * one core ships. The platform adds `k8s`. */
36
107
  isolation: Record<string, IsolatedStepRunner>;
@@ -55,15 +126,35 @@ export interface PlatformHooks {
55
126
  * on its record is resumed rather than destroyed and run again. Default:
56
127
  * nothing is. */
57
128
  sandboxResumable(kind: string): boolean;
129
+ /**
130
+ * Where the platform's built-in tools sit on disk, materialised at boot —
131
+ * a shelf every account reads, beneath its own library. A name found in
132
+ * the workspace wins, then the account's copy, then this. Default: none,
133
+ * which is what a laptop has; there the gallery is a dashboard feature and
134
+ * not a directory, and an agent grants only what it or its account owns.
135
+ */
136
+ galleryDir(): string | null;
137
+ /**
138
+ * An oauth2 secret was just refreshed — `error` null when it worked, the
139
+ * provider's reason when it did not. The platform keeps each connection's
140
+ * health, emails once when a grant is dead, and answers with the one-click
141
+ * reconnect address, which the failing step's error then quotes. Default:
142
+ * nothing to say, which is a laptop.
143
+ */
144
+ noteOAuthRefresh(ctx: { tenant: string; workspace?: string }, name: string, error: string | null): Promise<string | undefined>;
58
145
  }
59
146
 
60
147
  const local: PlatformHooks = {
61
- async enqueueFlowRun(tenant, workspace, steps, flowName, modelOverride, tags = []) {
148
+ edition: () => "self-hosted",
149
+ async enqueueFlowRun(tenant, workspace, steps, flowName, modelOverride, tags = [], startedBy = null, opts = {}) {
62
150
  // Imported here, not at the top: runner.ts imports this file.
63
151
  const { startFlowRun } = await import("./runner.ts");
64
- return startFlowRun(tenant, workspace, steps, flowName, modelOverride ?? null, tags);
152
+ return startFlowRun(tenant, workspace, steps, flowName, modelOverride ?? null, tags, null, startedBy, opts);
65
153
  },
66
154
  async enqueueResume() {},
155
+ admitTrigger: async () => ({ admit: true }),
156
+ async rollbackTrigger() {},
157
+ runSpend: (run) => run.steps.reduce((sum, s) => sum + (s.costUsd ?? 0), 0),
67
158
  isolation: {},
68
159
  killRunSandboxes() {},
69
160
  syncPublicShares: () => ({ added: [] }),
@@ -72,6 +163,8 @@ const local: PlatformHooks = {
72
163
  egress: { lease: async () => null },
73
164
  workspaceChanged() {},
74
165
  sandboxResumable: () => false,
166
+ galleryDir: () => null,
167
+ noteOAuthRefresh: async () => undefined,
75
168
  };
76
169
 
77
170
  // One object per PROCESS, not per module instance. A bundler that compiles
@@ -93,6 +186,17 @@ export function registerPlatform(hooks: Partial<PlatformHooks>): void {
93
186
  });
94
187
  }
95
188
 
189
+ /**
190
+ * Does a platform own the queue? True once something registered its own
191
+ * enqueueFlowRun — whatever process asks. An eval used to decide this from
192
+ * FOLDRUN_ROLE === "web", so on a worker it started the run in-process and
193
+ * walked around the queue the platform was counting on (the account cap,
194
+ * the lanes, the per-pod lease). The seam is the fact; the role is a guess.
195
+ */
196
+ export function platformQueues(): boolean {
197
+ return platform.enqueueFlowRun !== local.enqueueFlowRun;
198
+ }
199
+
96
200
  /** Back to the local defaults — for tests that register and must not leak. */
97
201
  export function resetPlatform(): void {
98
202
  Object.assign(platform, local, { isolation: {} });
@@ -0,0 +1,274 @@
1
+ // Is the key still good?
2
+ //
3
+ // A customer's own model key can be revoked, expire, run out of credit or
4
+ // have its base URL moved, and today the platform finds out the way the
5
+ // customer does: a desk fails at five in the morning. Twenty-seven of the
6
+ // thirty provider presets have never had an agent run through them from
7
+ // this runtime at all, so "it worked when we set it up" is doing a lot of
8
+ // work in that sentence.
9
+ //
10
+ // This is deliberately NOT the tool-loop probe next door. `foldrun probe`
11
+ // asks "can this model drive an agent", which is a question about a model
12
+ // and is asked once. This asks "does this endpoint still take our key",
13
+ // which is a question about a credential and has to be asked repeatedly —
14
+ // so it has to be cheap. One request, one token of output, no SDK, no tool
15
+ // loop, no agent. A fraction of a cent, and it answers the thing that
16
+ // actually breaks.
17
+ //
18
+ // It reads the same provider block a run reads, resolved the same way, so a
19
+ // pass here means a run would reach the same place with the same key.
20
+
21
+ import fs from "node:fs";
22
+ import path from "node:path";
23
+ import matter from "gray-matter";
24
+ import { getSecret } from "./secrets.ts";
25
+ import { noteSecretUse, healthKey } from "./secret-health.ts";
26
+ import { accountDir, workspaceDir, listWorkspaces, listAgents, parseProvider, type ProviderSpec } from "./store.ts";
27
+
28
+ export type HealthVerdict = "ok" | "credential" | "not-found" | "busy" | "unreachable" | "provider-error";
29
+
30
+ export interface ProviderCheck {
31
+ /** How this provider is written in the file: its preset name, or its host. */
32
+ provider: string;
33
+ /** The model id actually asked for — what a run would send. */
34
+ model: string;
35
+ verdict: HealthVerdict;
36
+ ok: boolean;
37
+ status: number | null;
38
+ ms: number;
39
+ /** One sentence a person can act on, in the provider's own words where
40
+ * they said anything useful. */
41
+ detail: string;
42
+ }
43
+
44
+ /** How long to wait. A provider slower than this is not one a step should
45
+ * be waiting on either, and the check must never hold a tick. */
46
+ const TIMEOUT_MS = 15_000;
47
+
48
+ /** What each status means for a credential, and what a person does about
49
+ * it. Kept as a table because the mapping IS the feature: "401" tells you
50
+ * nothing you can act on, "the key is no longer accepted" tells you
51
+ * everything. */
52
+ function verdictFor(status: number): { verdict: HealthVerdict; detail: string } {
53
+ if (status >= 200 && status < 300) return { verdict: "ok", detail: "the key was accepted and the model answered" };
54
+ if (status === 401 || status === 403) {
55
+ return { verdict: "credential", detail: "the key is no longer accepted — revoked, rotated, or wrong for this endpoint" };
56
+ }
57
+ if (status === 402) return { verdict: "credential", detail: "the account behind this key is out of credit" };
58
+ if (status === 404) {
59
+ return { verdict: "not-found", detail: "the endpoint or the model id does not exist there — check base_url and models:" };
60
+ }
61
+ if (status === 429) {
62
+ // Not a health problem. A busy provider is a provider that is working,
63
+ // and reporting it as broken would train people to ignore the alert.
64
+ return { verdict: "busy", detail: "rate limited right now — the key is fine" };
65
+ }
66
+ if (status >= 500) return { verdict: "provider-error", detail: "the provider is failing at its end" };
67
+ return { verdict: "provider-error", detail: `unexpected HTTP ${status}` };
68
+ }
69
+
70
+ /** `${SECRET}` in a token or header, filled from this account's vault. */
71
+ function resolve(tenant: string, workspace: string | null, raw: string): string {
72
+ return raw.replace(/\$\{([A-Z][A-Z0-9_]*)\}/g, (whole, name) => {
73
+ const hit = getSecret(tenant, name, workspace ?? undefined);
74
+ return hit ? hit.value : whole;
75
+ });
76
+ }
77
+
78
+ /**
79
+ * One request at the provider, in the wire format it speaks, asking for a
80
+ * single token. Never throws: an unreachable host is a verdict, not an
81
+ * exception, because this runs on a tick.
82
+ */
83
+ export async function checkProvider(
84
+ tenant: string,
85
+ workspace: string | null,
86
+ spec: ProviderSpec,
87
+ model: string,
88
+ ): Promise<ProviderCheck> {
89
+ const label = spec.name || (() => {
90
+ try {
91
+ return new URL(spec.baseUrl).host;
92
+ } catch {
93
+ return spec.baseUrl || "provider";
94
+ }
95
+ })();
96
+ const began = Date.now();
97
+ const fail = (verdict: HealthVerdict, detail: string, status: number | null = null): ProviderCheck => ({
98
+ provider: label,
99
+ model,
100
+ verdict,
101
+ ok: false,
102
+ status,
103
+ ms: Date.now() - began,
104
+ detail,
105
+ });
106
+
107
+ const token = resolve(tenant, workspace, spec.token);
108
+ if (!token || token.includes("${")) {
109
+ return fail("credential", `the secret named in provider.token is not in this account's vault (${spec.token})`);
110
+ }
111
+ if (!spec.baseUrl) return fail("unreachable", "this provider block has no base_url");
112
+
113
+ // The three wire formats, each asking for the smallest possible answer.
114
+ const base = spec.baseUrl.replace(/\/+$/, "");
115
+ const anthropic = spec.format === "anthropic";
116
+ const url = anthropic
117
+ ? `${base}/v1/messages`
118
+ : spec.format === "responses"
119
+ ? `${base}/responses`
120
+ : `${base}/chat/completions`;
121
+ const body = anthropic
122
+ ? { model, max_tokens: 1, messages: [{ role: "user", content: "hi" }] }
123
+ : spec.format === "responses"
124
+ ? { model, max_output_tokens: 16, input: "hi" }
125
+ : { model, max_tokens: 1, messages: [{ role: "user", content: "hi" }] };
126
+
127
+ const headers: Record<string, string> = { "content-type": "application/json" };
128
+ // An Anthropic-format endpoint takes the key in whichever header its
129
+ // `auth:` says; everything else is a bearer token.
130
+ if (anthropic && spec.auth === "x-api-key") {
131
+ headers["x-api-key"] = token;
132
+ headers["anthropic-version"] = "2023-06-01";
133
+ } else {
134
+ headers.authorization = `Bearer ${token}`;
135
+ if (anthropic) headers["anthropic-version"] = "2023-06-01";
136
+ }
137
+ for (const [k, v] of Object.entries(spec.headers ?? {})) headers[k.toLowerCase()] = resolve(tenant, workspace, v);
138
+
139
+ try {
140
+ const res = await fetch(url, {
141
+ method: "POST",
142
+ headers,
143
+ body: JSON.stringify(body),
144
+ signal: AbortSignal.timeout(TIMEOUT_MS),
145
+ });
146
+ const { verdict, detail } = verdictFor(res.status);
147
+ // The check is itself a use of the credential, and the most informative
148
+ // one there is: it was made for exactly this purpose.
149
+ const named = spec.token.match(/^\$\{([A-Z][A-Z0-9_]*)\}$/)?.[1];
150
+ if (named) {
151
+ let host = spec.baseUrl;
152
+ try {
153
+ host = new URL(spec.baseUrl).host;
154
+ } catch {
155
+ // an unparseable base_url is its own problem, reported above
156
+ }
157
+ const hit = getSecret(tenant, named, workspace ?? undefined);
158
+ noteSecretUse(tenant, healthKey(named, hit?.scope === "workspace" ? "workspace" : "account", workspace), { host, status: res.status });
159
+ }
160
+ // The provider's own words when it refused. They are the difference
161
+ // between "fix your key" and "fix your model id", and they are only
162
+ // ever in the body.
163
+ let said = "";
164
+ if (!res.ok) {
165
+ said = (await res.text().catch(() => "")).replace(/\s+/g, " ").slice(0, 300);
166
+ }
167
+ return {
168
+ provider: label,
169
+ model,
170
+ verdict,
171
+ // Busy counts as healthy: the key worked, the provider is simply full.
172
+ ok: verdict === "ok" || verdict === "busy",
173
+ status: res.status,
174
+ ms: Date.now() - began,
175
+ detail: said ? `${detail} — ${said}` : detail,
176
+ };
177
+ } catch (err) {
178
+ const message = err instanceof Error ? err.message : String(err);
179
+ return fail("unreachable", /timeout|aborted/i.test(message) ? `no answer within ${TIMEOUT_MS / 1000}s` : message);
180
+ }
181
+ }
182
+
183
+
184
+ /** A provider block in use, and where it is declared — because "which file
185
+ * do I edit" is the next question after "this key is dead". */
186
+ export interface ProviderInUse {
187
+ spec: ProviderSpec;
188
+ /** The workspace whose vault resolves this block's secrets. Null for the
189
+ * account's own block, which resolves against the account vault. */
190
+ workspace: string | null;
191
+ /** Human-readable origin: "account", "rank-desk", "rank-desk/writer". */
192
+ declaredIn: string;
193
+ /** The model id a run would send for the cheapest tier, which is what a
194
+ * health check should spend. */
195
+ model: string;
196
+ }
197
+
198
+ /** The cheapest tier's id for a provider block: what it calls `fast`, or
199
+ * our own fast model when it remaps nothing. */
200
+ function cheapestModel(spec: ProviderSpec): string {
201
+ return spec.models.fast || spec.models.default || spec.models.max || "claude-haiku-4-5-20251001";
202
+ }
203
+
204
+ function frontmatterOf(file: string): Record<string, unknown> {
205
+ try {
206
+ return (matter(fs.readFileSync(file, "utf8")).data ?? {}) as Record<string, unknown>;
207
+ } catch {
208
+ return {};
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Every distinct provider block this account would actually use, read from
214
+ * the same three places a run reads them: the account, each workspace, each
215
+ * agent.
216
+ *
217
+ * Deduplicated by endpoint and token, because ten agents sharing one gateway
218
+ * are one credential and checking it ten times spends ten times as much to
219
+ * learn the same fact. The origin recorded is the first one seen, which is
220
+ * the broadest — an account block covers everything under it.
221
+ */
222
+ export function providersInUse(tenant: string): ProviderInUse[] {
223
+ const out: ProviderInUse[] = [];
224
+ const seen = new Set<string>();
225
+
226
+ const add = (raw: unknown, workspace: string | null, declaredIn: string) => {
227
+ const spec = parseProvider(raw);
228
+ if (!spec || !spec.baseUrl) return;
229
+ // The token is part of the identity: the same gateway with two different
230
+ // keys is two credentials, and either can die on its own.
231
+ const key = `${workspace ?? ""}|${spec.baseUrl}|${spec.token}|${cheapestModel(spec)}`;
232
+ if (seen.has(key)) return;
233
+ seen.add(key);
234
+ out.push({ spec, workspace, declaredIn, model: cheapestModel(spec) });
235
+ };
236
+
237
+ add(frontmatterOf(path.join(accountDir(tenant), "AGENTS.md")).provider, null, "account");
238
+ for (const ws of safeList(() => listWorkspaces(tenant))) {
239
+ const dir = workspaceDir(tenant, ws.name);
240
+ add(frontmatterOf(path.join(dir, "AGENTS.md")).provider, ws.name, ws.name);
241
+ for (const agent of safeList(() => listAgents(tenant, ws.name))) {
242
+ add(
243
+ frontmatterOf(path.join(dir, "agents", agent.name, "agent.md")).provider,
244
+ ws.name,
245
+ `${ws.name}/${agent.name}`,
246
+ );
247
+ }
248
+ }
249
+ return out;
250
+ }
251
+
252
+ function safeList<T>(fn: () => T[]): T[] {
253
+ try {
254
+ return fn();
255
+ } catch {
256
+ return [];
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Check every provider this account uses, one at a time.
262
+ *
263
+ * Serial on purpose: this is housekeeping on a tick, the whole point is that
264
+ * it is cheap, and firing twelve model requests at once to save eight
265
+ * seconds nobody is waiting for would be a strange trade.
266
+ */
267
+ export async function checkAccountProviders(tenant: string): Promise<(ProviderCheck & { declaredIn: string })[]> {
268
+ const results: (ProviderCheck & { declaredIn: string })[] = [];
269
+ for (const use of providersInUse(tenant)) {
270
+ const check = await checkProvider(tenant, use.workspace, use.spec, use.model);
271
+ results.push({ ...check, declaredIn: use.declaredIn });
272
+ }
273
+ return results;
274
+ }