@desplega.ai/agent-swarm 1.95.0 → 1.97.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.
- package/README.md +3 -3
- package/openapi.json +136 -1
- package/package.json +1 -1
- package/src/be/boot-scrub-logs.ts +76 -0
- package/src/be/db.ts +73 -10
- package/src/be/migrations/095_api_key_rate_limit_windows.sql +5 -0
- package/src/be/modelsdev-cache.json +89422 -85636
- package/src/be/scripts/boot-reembed.ts +57 -17
- package/src/be/scripts/embeddings.ts +26 -15
- package/src/commands/provider-credentials.ts +37 -15
- package/src/commands/runner.ts +68 -0
- package/src/http/agents.ts +1 -0
- package/src/http/api-keys.ts +51 -0
- package/src/http/config.ts +24 -4
- package/src/http/index.ts +9 -0
- package/src/prompts/session-templates.ts +21 -0
- package/src/providers/claude-adapter.ts +1 -0
- package/src/providers/codex-adapter.ts +3 -0
- package/src/providers/harness-version.ts +49 -2
- package/src/providers/pi-mono-adapter.ts +113 -19
- package/src/providers/types.ts +37 -9
- package/src/tests/api-key-tracking.test.ts +62 -0
- package/src/tests/bedrock-model-groups.test.ts +135 -0
- package/src/tests/credential-check.test.ts +361 -12
- package/src/tests/harness-version.test.ts +47 -0
- package/src/tests/opencode-adapter.test.ts +7 -6
- package/src/tests/providers/pi-cost.test.ts +7 -6
- package/src/tests/rate-limit-event.test.ts +37 -0
- package/src/tests/scripts-boot-reembed.test.ts +61 -2
- package/src/tests/scripts-embeddings.test.ts +27 -0
- package/src/tests/secret-scrubber.test.ts +73 -1
- package/src/tools/swarm-config/get-config.ts +9 -1
- package/src/tools/swarm-config/list-config.ts +8 -0
- package/src/types.ts +21 -0
- package/src/utils/error-tracker.ts +59 -0
- package/src/utils/secret-scrubber.ts +33 -12
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { existsSync, lstatSync, symlinkSync, unlinkSync } from "node:fs";
|
|
10
10
|
import { join } from "node:path";
|
|
11
|
-
import { getModel } from "@earendil-works/pi-ai";
|
|
11
|
+
import { getModel, getModels } from "@earendil-works/pi-ai";
|
|
12
12
|
import type {
|
|
13
13
|
AgentSessionEvent,
|
|
14
14
|
CreateAgentSessionOptions,
|
|
@@ -75,29 +75,99 @@ function modelToCredKeys(modelStr: string | undefined): string[] | null {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
79
|
-
* API
|
|
80
|
-
*
|
|
81
|
-
*
|
|
78
|
+
* Return the pi-ai Bedrock models the harness can actually drive via the
|
|
79
|
+
* Converse API (the catalog from `getModels("amazon-bedrock")`). Each id is a
|
|
80
|
+
* valid pi-ai id — base foundation-model id OR inference-profile id (`us.` /
|
|
81
|
+
* `eu.` / `apac.` / `au.` / `global.` prefixes) — so the matched id round-trips
|
|
82
|
+
* through `MODEL_OVERRIDE=amazon-bedrock/<id>` unchanged. Used as the
|
|
83
|
+
* harness-drivable half of the (drivable ∩ invocable) intersection.
|
|
84
|
+
*/
|
|
85
|
+
function getHarnessDrivableBedrockModels(): Array<{ id: string; name: string }> {
|
|
86
|
+
try {
|
|
87
|
+
return getModels("amazon-bedrock").map((m) => ({ id: m.id, name: m.name }));
|
|
88
|
+
} catch {
|
|
89
|
+
// getModels may throw if the pi-ai catalog is empty or corrupted.
|
|
90
|
+
// Return an empty list — the intersection will be empty too, which is safe.
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Enumerate the Bedrock models that are both invocable by this AWS account and
|
|
97
|
+
* drivable by the pi-ai Converse harness, and verify the credential chain in
|
|
98
|
+
* one pass:
|
|
99
|
+
* 1. VERIFY the active credential chain is valid for Bedrock in `region`
|
|
100
|
+
* (the AWS list calls throw on auth/access failure).
|
|
101
|
+
* 2. ENUMERATE usable models = harness-drivable ∩ AWS-invocable, where the
|
|
102
|
+
* AWS-invocable set is:
|
|
103
|
+
* - `ListFoundationModels` filtered to on-demand TEXT models that are
|
|
104
|
+
* `ACTIVE` (base foundation-model ids), UNION
|
|
105
|
+
* - `ListInferenceProfiles` ids (the `us.`/`eu.`/… cross-region profile
|
|
106
|
+
* ids). The newest Claude models on Bedrock are invocable ONLY via an
|
|
107
|
+
* inference profile and never appear in `ListFoundationModels`, so this
|
|
108
|
+
* union is what keeps the current models in the usable list.
|
|
109
|
+
*
|
|
110
|
+
* `ListFoundationModels` reports models that EXIST in the region, not strictly
|
|
111
|
+
* ones the account has enabled access to, so the on-demand/ACTIVE filtering
|
|
112
|
+
* narrows it; base on-demand access-grant is not fully enumerable from the
|
|
113
|
+
* catalog. The inference-profile union is what makes the *current* models
|
|
114
|
+
* accurate. The matched id is stored/displayed as the pi-ai id (the id the
|
|
115
|
+
* harness can drive); ids are matched exactly.
|
|
82
116
|
*
|
|
117
|
+
* Two list calls per refresh, no pagination loops or per-model lookups.
|
|
83
118
|
* Dynamically imported so the API binary never loads `@aws-sdk/client-bedrock`.
|
|
84
119
|
* Tests inject a stub via `CredCheckOptions.bedrockProbe` instead.
|
|
120
|
+
*
|
|
121
|
+
* Returns `Array<{id, name}>` on success; throws on auth/access failure.
|
|
85
122
|
*/
|
|
86
|
-
async function
|
|
87
|
-
|
|
123
|
+
export async function runBedrockSdkProbeAndEnumerate(
|
|
124
|
+
region: string,
|
|
125
|
+
): Promise<Array<{ id: string; name: string }>> {
|
|
126
|
+
const { BedrockClient, ListFoundationModelsCommand, ListInferenceProfilesCommand } = await import(
|
|
127
|
+
"@aws-sdk/client-bedrock"
|
|
128
|
+
);
|
|
88
129
|
const client = new BedrockClient({ region });
|
|
89
|
-
|
|
130
|
+
|
|
131
|
+
// AWS-invocable set, region-scoped to `region`.
|
|
132
|
+
const invocable = new Set<string>();
|
|
133
|
+
|
|
134
|
+
// Base on-demand TEXT foundation models that are ACTIVE.
|
|
135
|
+
const fmResponse = await client.send(
|
|
136
|
+
new ListFoundationModelsCommand({ byInferenceType: "ON_DEMAND", byOutputModality: "TEXT" }),
|
|
137
|
+
);
|
|
138
|
+
for (const m of fmResponse.modelSummaries ?? []) {
|
|
139
|
+
if (m.modelId && m.modelLifecycle?.status === "ACTIVE") {
|
|
140
|
+
invocable.add(m.modelId);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Inference-profile / cross-region ids (`us.`/`eu.`/`apac.`/…). These are the
|
|
145
|
+
// only invocation path for the newest Claude models and are absent from
|
|
146
|
+
// `ListFoundationModels`.
|
|
147
|
+
const profileResponse = await client.send(new ListInferenceProfilesCommand({}));
|
|
148
|
+
for (const p of profileResponse.inferenceProfileSummaries ?? []) {
|
|
149
|
+
if (p.inferenceProfileId) {
|
|
150
|
+
invocable.add(p.inferenceProfileId);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Usable = harness-drivable ∩ AWS-invocable, exact-id match. The stored id is
|
|
155
|
+
// the pi-ai id so it round-trips through `getModel("amazon-bedrock", id)`.
|
|
156
|
+
return getHarnessDrivableBedrockModels().filter((m) => invocable.has(m.id));
|
|
90
157
|
}
|
|
91
158
|
|
|
92
159
|
/**
|
|
93
160
|
* Pi-mono is satisfied by ANY of:
|
|
94
161
|
* 1. `BEDROCK_AUTH_MODE=sdk` — or `MODEL_OVERRIDE` selects the
|
|
95
162
|
* `amazon-bedrock` provider (prefix-inference fallback when
|
|
96
|
-
* `BEDROCK_AUTH_MODE` is absent).
|
|
97
|
-
*
|
|
98
|
-
* `
|
|
99
|
-
*
|
|
100
|
-
*
|
|
163
|
+
* `BEDROCK_AUTH_MODE` is absent). The AWS SDK default credential chain is
|
|
164
|
+
* exercised by a real enumeration pass (`ListFoundationModels` +
|
|
165
|
+
* `ListInferenceProfiles`) that both verifies access and lists the usable
|
|
166
|
+
* models. Success → `ready:true, satisfiedBy:"sdk-delegated"` with the
|
|
167
|
+
* enumerated models; failure → `ready:false` with a classified hint;
|
|
168
|
+
* `AWS_REGION` unset → `ready:false` with a set-region hint. The
|
|
169
|
+
* enumeration is worker-only (the pi dynamic-import arm in
|
|
170
|
+
* `checkProviderCredentials`); the API binary never imports the SDK.
|
|
101
171
|
* 2. `~/.pi/agent/auth.json` exists.
|
|
102
172
|
* 3. `MODEL_OVERRIDE` is set to a non-Bedrock provider-prefixed model — only
|
|
103
173
|
* the matching provider's key is required.
|
|
@@ -118,7 +188,7 @@ export async function checkPiMonoCredentials(
|
|
|
118
188
|
// - Fallback: BEDROCK_AUTH_MODE absent AND MODEL_OVERRIDE starts with
|
|
119
189
|
// "amazon-bedrock/" (preserves today's prefix-inference semantics)
|
|
120
190
|
// BEDROCK_AUTH_MODE=bearer is declared/validated but the full bearer-token
|
|
121
|
-
// path is
|
|
191
|
+
// path is not implemented yet — it falls through to the standard auth check.
|
|
122
192
|
const bedrockAuthMode = env.BEDROCK_AUTH_MODE?.toLowerCase();
|
|
123
193
|
const isBedrockSdk =
|
|
124
194
|
bedrockAuthMode === "sdk" ||
|
|
@@ -126,15 +196,37 @@ export async function checkPiMonoCredentials(
|
|
|
126
196
|
env.MODEL_OVERRIDE?.toLowerCase().startsWith("amazon-bedrock/"));
|
|
127
197
|
|
|
128
198
|
if (isBedrockSdk) {
|
|
129
|
-
const region = env.AWS_REGION
|
|
130
|
-
|
|
199
|
+
const region = env.AWS_REGION;
|
|
200
|
+
if (!region) {
|
|
201
|
+
// Do NOT fabricate a region. A guessed `us-east-1` can differ from where
|
|
202
|
+
// inference actually runs, which would enumerate the wrong region's
|
|
203
|
+
// models. Report a not-ready Bedrock state with a hint instead, so the
|
|
204
|
+
// enumeration region always matches the inference region. `bedrockRegion`
|
|
205
|
+
// is an empty string (not undefined) so the report still carries a
|
|
206
|
+
// Bedrock block and the picker can surface the reason.
|
|
207
|
+
return {
|
|
208
|
+
ready: false,
|
|
209
|
+
missing: [],
|
|
210
|
+
hint: "AWS_REGION is not set — set it to the region where your Bedrock models are accessible so model enumeration matches the inference region.",
|
|
211
|
+
bedrockModels: [],
|
|
212
|
+
bedrockRegion: "",
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const probe = opts.bedrockProbe ?? (() => runBedrockSdkProbeAndEnumerate(region));
|
|
131
216
|
try {
|
|
132
|
-
await probe();
|
|
217
|
+
const probeResult = await probe();
|
|
218
|
+
// `probeResult` is `Array<{id,name}> | void` — void comes from auth-only
|
|
219
|
+
// stubs that don't exercise enumeration. Treat void as [].
|
|
220
|
+
const bedrockModels: Array<{ id: string; name: string }> = Array.isArray(probeResult)
|
|
221
|
+
? probeResult
|
|
222
|
+
: [];
|
|
133
223
|
return {
|
|
134
224
|
ready: true,
|
|
135
225
|
missing: [],
|
|
136
226
|
satisfiedBy: "sdk-delegated",
|
|
137
|
-
hint: `
|
|
227
|
+
hint: `Bedrock models invocable in ${region} enumerated (${bedrockModels.length} usable; ListFoundationModels + ListInferenceProfiles).`,
|
|
228
|
+
bedrockModels,
|
|
229
|
+
bedrockRegion: region,
|
|
138
230
|
};
|
|
139
231
|
} catch (err) {
|
|
140
232
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
@@ -144,7 +236,9 @@ export async function checkPiMonoCredentials(
|
|
|
144
236
|
missing: [],
|
|
145
237
|
hint:
|
|
146
238
|
classification?.message ??
|
|
147
|
-
`AWS Bedrock
|
|
239
|
+
`AWS Bedrock enumeration failed (region: ${region}): ${errorMessage}`,
|
|
240
|
+
bedrockModels: [],
|
|
241
|
+
bedrockRegion: region,
|
|
148
242
|
};
|
|
149
243
|
}
|
|
150
244
|
}
|
package/src/providers/types.ts
CHANGED
|
@@ -34,6 +34,7 @@ export interface CostData {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
import type { ProviderName } from "../types";
|
|
37
|
+
import type { RateLimitWindowTelemetry } from "../utils/error-tracker";
|
|
37
38
|
|
|
38
39
|
/** Normalized event emitted by any provider adapter. */
|
|
39
40
|
export type ProviderEvent =
|
|
@@ -137,6 +138,12 @@ export interface ProviderResult {
|
|
|
137
138
|
* three-tier cooldown resolver.
|
|
138
139
|
*/
|
|
139
140
|
rateLimitResetAt?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Latest provider-emitted rate-limit window snapshots observed during the
|
|
143
|
+
* session, keyed by provider window type (for Claude: five_hour, seven_day).
|
|
144
|
+
* Best-effort and informational; consumers must tolerate it being absent.
|
|
145
|
+
*/
|
|
146
|
+
rateLimitWindows?: RateLimitWindowTelemetry;
|
|
140
147
|
}
|
|
141
148
|
|
|
142
149
|
/** Behavioral traits that govern prompt assembly and feature gating. */
|
|
@@ -181,6 +188,19 @@ export interface CredStatus {
|
|
|
181
188
|
missing: string[];
|
|
182
189
|
satisfiedBy?: "env" | "file" | "side-effect-pending" | "sdk-delegated";
|
|
183
190
|
hint?: string;
|
|
191
|
+
/**
|
|
192
|
+
* Pi-mono Bedrock mode only: usable model list = harness-drivable ∩
|
|
193
|
+
* AWS-invocable (on-demand/ACTIVE foundation models ∪ inference profiles),
|
|
194
|
+
* region-scoped. Empty when enumeration failed (ready===false), when
|
|
195
|
+
* `AWS_REGION` is unset, or when the intersection is empty. Undefined when not
|
|
196
|
+
* in Bedrock mode.
|
|
197
|
+
*/
|
|
198
|
+
bedrockModels?: Array<{ id: string; name: string }>;
|
|
199
|
+
/**
|
|
200
|
+
* Pi-mono Bedrock mode only: AWS region the enumeration ran against. An empty
|
|
201
|
+
* string signals Bedrock mode with `AWS_REGION` unset (no region fabricated).
|
|
202
|
+
*/
|
|
203
|
+
bedrockRegion?: string;
|
|
184
204
|
}
|
|
185
205
|
|
|
186
206
|
/**
|
|
@@ -189,19 +209,27 @@ export interface CredStatus {
|
|
|
189
209
|
* `~/.pi/agent/auth.json`, `~/.local/share/opencode/auth.json`. Tests inject
|
|
190
210
|
* a fake `fs` + `homeDir` to exercise the file-vs-env branches deterministically.
|
|
191
211
|
*
|
|
192
|
-
* `bedrockProbe` is an injectable for the Bedrock SDK
|
|
193
|
-
* `checkPiMonoCredentials`. In production it is left undefined and the
|
|
194
|
-
*
|
|
195
|
-
* `ListFoundationModels`
|
|
212
|
+
* `bedrockProbe` is an injectable for the Bedrock SDK enumeration path in
|
|
213
|
+
* `checkPiMonoCredentials`. In production it is left undefined and the function
|
|
214
|
+
* dynamically imports `@aws-sdk/client-bedrock` to run real
|
|
215
|
+
* `ListFoundationModels` + `ListInferenceProfiles` calls. Tests inject a stub
|
|
216
|
+
* to avoid hitting AWS.
|
|
196
217
|
*/
|
|
197
218
|
export interface CredCheckOptions {
|
|
198
219
|
homeDir?: string;
|
|
199
220
|
fs?: { existsSync(p: string): boolean };
|
|
200
221
|
/**
|
|
201
|
-
* Injectable for Bedrock SDK
|
|
202
|
-
* of the real `@aws-sdk/client-bedrock` `ListFoundationModels`
|
|
203
|
-
* Should throw on auth/access failure (with an
|
|
204
|
-
* or resolve
|
|
222
|
+
* Injectable for the Bedrock SDK enumeration. When provided, called instead
|
|
223
|
+
* of the real `@aws-sdk/client-bedrock` `ListFoundationModels` +
|
|
224
|
+
* `ListInferenceProfiles` calls. Should throw on auth/access failure (with an
|
|
225
|
+
* AWS SDK-shaped error message) or resolve with the intersected
|
|
226
|
+
* (harness-drivable ∩ AWS-invocable) model list on success.
|
|
227
|
+
*
|
|
228
|
+
* Return type is `Array<{id,name}> | undefined` for backward compatibility:
|
|
229
|
+
* existing test stubs that return void (`async () => {}`) are still valid
|
|
230
|
+
* (void is assignable to undefined in TypeScript's structural typing);
|
|
231
|
+
* new tests that need to exercise the model list inject stubs that return
|
|
232
|
+
* an array. Production code always returns the model list.
|
|
205
233
|
*/
|
|
206
|
-
bedrockProbe?: () => Promise<
|
|
234
|
+
bedrockProbe?: () => Promise<Array<{ id: string; name: string }> | undefined>;
|
|
207
235
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
getKeyStatuses,
|
|
12
12
|
initDb,
|
|
13
13
|
markKeyRateLimited,
|
|
14
|
+
recordKeyRateLimitWindows,
|
|
14
15
|
recordKeyUsage,
|
|
15
16
|
} from "../be/db";
|
|
16
17
|
import type { CredentialSelection } from "../utils/credentials";
|
|
@@ -240,6 +241,67 @@ describe("API key tracking DB queries", () => {
|
|
|
240
241
|
const cleared = clearKeyRateLimit("OPENAI_API_KEY", "oai02");
|
|
241
242
|
expect(cleared).toBe(false);
|
|
242
243
|
});
|
|
244
|
+
|
|
245
|
+
test("recordKeyRateLimitWindows persists latest provider windows", () => {
|
|
246
|
+
recordKeyRateLimitWindows("ANTHROPIC_API_KEY", "aaa11", 0, {
|
|
247
|
+
seven_day: {
|
|
248
|
+
status: "allowed_warning",
|
|
249
|
+
utilization: 0.82,
|
|
250
|
+
resetsAt: 1781334000,
|
|
251
|
+
isUsingOverage: false,
|
|
252
|
+
surpassedThreshold: 0.75,
|
|
253
|
+
lastSeenAt: "2026-06-12T00:00:00.000Z",
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const key = getKeyStatuses("ANTHROPIC_API_KEY").find((s) => s.keySuffix === "aaa11");
|
|
258
|
+
expect(key?.rateLimitWindows).toEqual({
|
|
259
|
+
seven_day: {
|
|
260
|
+
status: "allowed_warning",
|
|
261
|
+
utilization: 0.82,
|
|
262
|
+
resetsAt: 1781334000,
|
|
263
|
+
isUsingOverage: false,
|
|
264
|
+
surpassedThreshold: 0.75,
|
|
265
|
+
lastSeenAt: "2026-06-12T00:00:00.000Z",
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("recordKeyRateLimitWindows merges with existing provider windows", () => {
|
|
271
|
+
recordKeyRateLimitWindows("ANTHROPIC_API_KEY", "aaa11", 0, {
|
|
272
|
+
seven_day: {
|
|
273
|
+
status: "allowed_warning",
|
|
274
|
+
utilization: 0.82,
|
|
275
|
+
resetsAt: 1781334000,
|
|
276
|
+
lastSeenAt: "2026-06-12T00:00:00.000Z",
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
recordKeyRateLimitWindows("ANTHROPIC_API_KEY", "aaa11", 0, {
|
|
281
|
+
five_hour: {
|
|
282
|
+
status: "allowed",
|
|
283
|
+
utilization: 0.2,
|
|
284
|
+
resetsAt: 1781270000,
|
|
285
|
+
lastSeenAt: "2026-06-12T01:00:00.000Z",
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
const key = getKeyStatuses("ANTHROPIC_API_KEY").find((s) => s.keySuffix === "aaa11");
|
|
290
|
+
expect(key?.rateLimitWindows).toEqual({
|
|
291
|
+
seven_day: {
|
|
292
|
+
status: "allowed_warning",
|
|
293
|
+
utilization: 0.82,
|
|
294
|
+
resetsAt: 1781334000,
|
|
295
|
+
lastSeenAt: "2026-06-12T00:00:00.000Z",
|
|
296
|
+
},
|
|
297
|
+
five_hour: {
|
|
298
|
+
status: "allowed",
|
|
299
|
+
utilization: 0.2,
|
|
300
|
+
resetsAt: 1781270000,
|
|
301
|
+
lastSeenAt: "2026-06-12T01:00:00.000Z",
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
});
|
|
243
305
|
});
|
|
244
306
|
|
|
245
307
|
// ─── Cross-keyType Failover Logic Tests ──────────────────────────────────────
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for amazon-bedrock model group behaviour in modelGroupsForHarness.
|
|
3
|
+
*
|
|
4
|
+
* Verifies:
|
|
5
|
+
* - Bedrock group always appears for the pi harness (NEVER blank).
|
|
6
|
+
* - Live worker-reported models are preferred when present.
|
|
7
|
+
* - Static snapshot from modelsdev-cache.json is used as fallback.
|
|
8
|
+
* - Converse-incompatible models listed by AWS but absent from pi-ai's catalog
|
|
9
|
+
* are NOT in the live list (the intersection is worker-side; this test just
|
|
10
|
+
* ensures the UI renders what the worker sent, without adding phantom entries).
|
|
11
|
+
* - Non-pi harnesses do NOT get a Bedrock group.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, expect, test } from "bun:test";
|
|
15
|
+
import {
|
|
16
|
+
type LiveBedrockStatus,
|
|
17
|
+
modelGroupsForHarness,
|
|
18
|
+
} from "../../ui/src/lib/agent-runtime-models";
|
|
19
|
+
|
|
20
|
+
describe("modelGroupsForHarness — Bedrock group for pi harness", () => {
|
|
21
|
+
const configs = undefined;
|
|
22
|
+
const envPresence = undefined;
|
|
23
|
+
|
|
24
|
+
test("pi harness always includes an Amazon Bedrock group (NEVER blank)", () => {
|
|
25
|
+
// No live status provided — falls back to static snapshot.
|
|
26
|
+
const groups = modelGroupsForHarness("pi", configs, envPresence);
|
|
27
|
+
const bedrockGroup = groups.find((g) => g.provider === "Amazon Bedrock");
|
|
28
|
+
expect(bedrockGroup).toBeDefined();
|
|
29
|
+
// Static snapshot has 98 models — at least one must be present.
|
|
30
|
+
expect(bedrockGroup!.models.length).toBeGreaterThan(0);
|
|
31
|
+
// All model IDs must be prefixed with the provider.
|
|
32
|
+
for (const m of bedrockGroup!.models) {
|
|
33
|
+
expect(m.id.startsWith("amazon-bedrock/")).toBe(true);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("pi harness with no live report → Bedrock group disabled (auth state unknown)", () => {
|
|
38
|
+
const groups = modelGroupsForHarness("pi", configs, envPresence, null);
|
|
39
|
+
const bedrockGroup = groups.find((g) => g.provider === "Amazon Bedrock");
|
|
40
|
+
expect(bedrockGroup).toBeDefined();
|
|
41
|
+
expect(bedrockGroup!.enabled).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("pi harness with live report ready:true → Bedrock group enabled + live models", () => {
|
|
45
|
+
const liveStatus: LiveBedrockStatus = {
|
|
46
|
+
ready: true,
|
|
47
|
+
models: [
|
|
48
|
+
{ id: "anthropic.claude-sonnet-4-20250514-v1:0", name: "Claude Sonnet 4" },
|
|
49
|
+
{ id: "anthropic.claude-haiku-4-5-20251001-v1:0", name: "Claude Haiku 4.5" },
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
const groups = modelGroupsForHarness("pi", configs, envPresence, liveStatus);
|
|
53
|
+
const bedrockGroup = groups.find((g) => g.provider === "Amazon Bedrock");
|
|
54
|
+
expect(bedrockGroup).toBeDefined();
|
|
55
|
+
expect(bedrockGroup!.enabled).toBe(true);
|
|
56
|
+
expect(bedrockGroup!.models).toHaveLength(2);
|
|
57
|
+
expect(bedrockGroup!.models[0]!.id).toBe(
|
|
58
|
+
"amazon-bedrock/anthropic.claude-sonnet-4-20250514-v1:0",
|
|
59
|
+
);
|
|
60
|
+
expect(bedrockGroup!.models[0]!.label).toBe("Claude Sonnet 4");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("pi harness with live report ready:false → Bedrock group disabled + live models shown", () => {
|
|
64
|
+
// Auth failed but we still show models so the operator can see what's available.
|
|
65
|
+
const liveStatus: LiveBedrockStatus = {
|
|
66
|
+
ready: false,
|
|
67
|
+
models: [{ id: "anthropic.claude-sonnet-4-20250514-v1:0", name: "Claude Sonnet 4" }],
|
|
68
|
+
};
|
|
69
|
+
const groups = modelGroupsForHarness("pi", configs, envPresence, liveStatus);
|
|
70
|
+
const bedrockGroup = groups.find((g) => g.provider === "Amazon Bedrock");
|
|
71
|
+
expect(bedrockGroup!.enabled).toBe(false);
|
|
72
|
+
expect(bedrockGroup!.models).toHaveLength(1);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("pi harness with failed probe surfaces the probe error as disabledReason", () => {
|
|
76
|
+
// A failed probe (ready:false with an error) should surface WHY the group is
|
|
77
|
+
// disabled instead of a silent disable.
|
|
78
|
+
const liveStatus: LiveBedrockStatus = {
|
|
79
|
+
ready: false,
|
|
80
|
+
models: [],
|
|
81
|
+
error: "Token expired — run aws sso login",
|
|
82
|
+
};
|
|
83
|
+
const groups = modelGroupsForHarness("pi", configs, envPresence, liveStatus);
|
|
84
|
+
const bedrockGroup = groups.find((g) => g.provider === "Amazon Bedrock");
|
|
85
|
+
expect(bedrockGroup!.enabled).toBe(false);
|
|
86
|
+
expect(bedrockGroup!.disabledReason).toBe("Token expired — run aws sso login");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("pi harness with ready:true → no disabledReason and Bedrock icon key", () => {
|
|
90
|
+
const liveStatus: LiveBedrockStatus = {
|
|
91
|
+
ready: true,
|
|
92
|
+
models: [{ id: "anthropic.claude-sonnet-4-20250514-v1:0", name: "Claude Sonnet 4" }],
|
|
93
|
+
};
|
|
94
|
+
const groups = modelGroupsForHarness("pi", configs, envPresence, liveStatus);
|
|
95
|
+
const bedrockGroup = groups.find((g) => g.provider === "Amazon Bedrock");
|
|
96
|
+
expect(bedrockGroup!.disabledReason).toBeUndefined();
|
|
97
|
+
// Bedrock has its own provider icon — it no longer borrows the OpenRouter glyph.
|
|
98
|
+
expect(bedrockGroup!.models[0]!.providerId).toBe("amazon-bedrock");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("pi harness with live report and empty model list → shows empty list (not snapshot fallback)", () => {
|
|
102
|
+
// Worker reported successfully but no models were in the intersection.
|
|
103
|
+
const liveStatus: LiveBedrockStatus = { ready: true, models: [] };
|
|
104
|
+
const groups = modelGroupsForHarness("pi", configs, envPresence, liveStatus);
|
|
105
|
+
const bedrockGroup = groups.find((g) => g.provider === "Amazon Bedrock");
|
|
106
|
+
expect(bedrockGroup!.models).toHaveLength(0);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("opencode harness does NOT get a Bedrock group", () => {
|
|
110
|
+
const groups = modelGroupsForHarness("opencode", configs, envPresence);
|
|
111
|
+
const bedrockGroup = groups.find((g) => g.provider === "Amazon Bedrock");
|
|
112
|
+
expect(bedrockGroup).toBeUndefined();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("claude harness does NOT get a Bedrock group", () => {
|
|
116
|
+
const groups = modelGroupsForHarness("claude", configs, envPresence);
|
|
117
|
+
const bedrockGroup = groups.find((g) => g.provider === "Amazon Bedrock");
|
|
118
|
+
expect(bedrockGroup).toBeUndefined();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("codex harness does NOT get a Bedrock group", () => {
|
|
122
|
+
const groups = modelGroupsForHarness("codex", configs, envPresence);
|
|
123
|
+
const bedrockGroup = groups.find((g) => g.provider === "Amazon Bedrock");
|
|
124
|
+
expect(bedrockGroup).toBeUndefined();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("pi harness still returns openrouter/anthropic/openai snapshot groups alongside Bedrock", () => {
|
|
128
|
+
const groups = modelGroupsForHarness("pi", configs, envPresence);
|
|
129
|
+
const providerNames = groups.map((g) => g.provider);
|
|
130
|
+
expect(providerNames).toContain("OpenRouter");
|
|
131
|
+
expect(providerNames).toContain("Anthropic");
|
|
132
|
+
expect(providerNames).toContain("OpenAI");
|
|
133
|
+
expect(providerNames).toContain("Amazon Bedrock");
|
|
134
|
+
});
|
|
135
|
+
});
|