@opengeni/worker-bundle 0.8.3 → 0.10.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1261 -434
- package/dist/index.js.map +1 -1
- package/dist/workflow-bundle.js +3 -1
- package/package.json +11 -11
- package/src/activities/agent-turn.ts +639 -293
- package/src/activities/capabilities.ts +3 -1
- package/src/activities/environment.ts +142 -11
- package/src/activities/rig-verification.ts +897 -244
- package/src/activities/sandbox-lease.ts +32 -1
- package/src/observability-metrics.ts +83 -15
- package/src/workflows/rig-verification.ts +3 -1
|
@@ -41,6 +41,7 @@ export async function settingsWithSessionMcpServersForRun(
|
|
|
41
41
|
db: Database,
|
|
42
42
|
workspaceId: string,
|
|
43
43
|
sessionId: string,
|
|
44
|
+
attemptId: string,
|
|
44
45
|
settings: Settings,
|
|
45
46
|
): Promise<Settings> {
|
|
46
47
|
const encryptionKey = environmentsEncryptionKeyBytes(settings);
|
|
@@ -57,7 +58,7 @@ export async function settingsWithSessionMcpServersForRun(
|
|
|
57
58
|
}
|
|
58
59
|
return settingsWithSessionMcpServers(
|
|
59
60
|
settings,
|
|
60
|
-
await listSessionMcpServersForRun(db, workspaceId, sessionId, encryptionKey ?? null),
|
|
61
|
+
await listSessionMcpServersForRun(db, workspaceId, sessionId, attemptId, encryptionKey ?? null),
|
|
61
62
|
);
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -173,6 +174,7 @@ export function withCodexProvider(settings: Settings): Settings {
|
|
|
173
174
|
baseUrl: CODEX_PROVIDER_BASE_URL,
|
|
174
175
|
models: CODEX_FALLBACK_MODEL_SLUGS.map((slug) => ({
|
|
175
176
|
id: `${CODEX_MODEL_ID_PREFIX}${slug}`,
|
|
177
|
+
upstreamModelId: slug,
|
|
176
178
|
label: slug,
|
|
177
179
|
reasoningEffort: true,
|
|
178
180
|
// These three values are the live Codex CLI catalog policy, kept distinct
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type ConnectionCredentialsPort,
|
|
12
12
|
type GitCredentialProvider,
|
|
13
13
|
type GitCredentialRepositoryRef,
|
|
14
|
+
type GitCredentialTransport,
|
|
14
15
|
type GitCredentials,
|
|
15
16
|
type ResourceRef,
|
|
16
17
|
type SandboxSecrets,
|
|
@@ -48,6 +49,7 @@ export type GitCredentialBindingSeed = {
|
|
|
48
49
|
credentialBindingId: string;
|
|
49
50
|
provider: GitCredentialProvider;
|
|
50
51
|
token: string;
|
|
52
|
+
transport?: GitCredentialTransport;
|
|
51
53
|
expiresAt?: string;
|
|
52
54
|
providerBindingCount?: number;
|
|
53
55
|
};
|
|
@@ -71,11 +73,14 @@ export type MintedSandboxToolspaceToken = {
|
|
|
71
73
|
expiresAt: Date;
|
|
72
74
|
};
|
|
73
75
|
|
|
76
|
+
export type SandboxToolspaceAuthority = {
|
|
77
|
+
sessionId: string;
|
|
78
|
+
};
|
|
79
|
+
|
|
74
80
|
export async function mintSandboxToolspaceToken(
|
|
75
81
|
settings: Settings,
|
|
76
82
|
scope: ConnectionScope,
|
|
77
|
-
|
|
78
|
-
runId: string,
|
|
83
|
+
authority: SandboxToolspaceAuthority,
|
|
79
84
|
nowMs = Date.now(),
|
|
80
85
|
): Promise<MintedSandboxToolspaceToken | undefined> {
|
|
81
86
|
if (!settings.toolspaceEnabled || !settings.delegationSecret) {
|
|
@@ -85,10 +90,10 @@ export async function mintSandboxToolspaceToken(
|
|
|
85
90
|
const token = await signDelegatedAccessToken(settings.delegationSecret, {
|
|
86
91
|
accountId: scope.accountId,
|
|
87
92
|
workspaceId: scope.workspaceId,
|
|
88
|
-
subjectId: `sandbox:${
|
|
93
|
+
subjectId: `sandbox:${authority.sessionId}`,
|
|
89
94
|
subjectLabel: "sandbox toolspace",
|
|
90
95
|
permissions: ["toolspace:call"],
|
|
91
|
-
sessionId,
|
|
96
|
+
sessionId: authority.sessionId,
|
|
92
97
|
exp: expiresAtSeconds,
|
|
93
98
|
});
|
|
94
99
|
return { token, expiresAt: new Date(expiresAtSeconds * 1000) };
|
|
@@ -197,8 +202,7 @@ export async function sandboxEnvironmentForRun(
|
|
|
197
202
|
options: RunGitCredentialOptions & {
|
|
198
203
|
skipGitHubToken?: boolean;
|
|
199
204
|
deferGitHubToken?: boolean;
|
|
200
|
-
|
|
201
|
-
runId?: string;
|
|
205
|
+
toolspaceAuthority?: SandboxToolspaceAuthority;
|
|
202
206
|
} = {},
|
|
203
207
|
): Promise<{
|
|
204
208
|
environment: Record<string, string>;
|
|
@@ -232,14 +236,15 @@ export async function sandboxEnvironmentForRun(
|
|
|
232
236
|
// backend, including a connected machine. Unlike platform git provider tokens
|
|
233
237
|
// (inert on selfhosted → skipped above), the toolspace token is the machine's
|
|
234
238
|
// only path to programmatic tool calling, and it grants no more than the
|
|
235
|
-
// machine owner's own authority (toolspace:call, own-session-bound,
|
|
236
|
-
// budgeted, approval-tools
|
|
237
|
-
//
|
|
239
|
+
// machine owner's own authority (toolspace:call, own-session-bound,
|
|
240
|
+
// short-lived and renewable, per-active-turn budgeted, approval-tools
|
|
241
|
+
// excluded). Delivery mirrors the docker path: the caller threads it
|
|
242
|
+
// OFF-MANIFEST as the seed the runtime writes to
|
|
238
243
|
// $OPENGENI_TOOLSPACE_TOKEN_FILE over the box's exec channel.
|
|
239
244
|
const toolspaceScope = options.scope;
|
|
240
245
|
const toolspaceToken =
|
|
241
|
-
toolspaceScope && options.
|
|
242
|
-
? await mintSandboxToolspaceToken(settings, toolspaceScope, options.
|
|
246
|
+
toolspaceScope && options.toolspaceAuthority
|
|
247
|
+
? await mintSandboxToolspaceToken(settings, toolspaceScope, options.toolspaceAuthority)
|
|
243
248
|
: undefined;
|
|
244
249
|
if (toolspaceToken && toolspaceScope) {
|
|
245
250
|
environment.OPENGENI_TOOLSPACE_URL ??= firstPartyMcpWorkspaceUrl(
|
|
@@ -397,6 +402,7 @@ async function mintRunGitTokensWithIdentity(
|
|
|
397
402
|
let identity: { name: string; email: string } | null = null;
|
|
398
403
|
for (const selection of selections) {
|
|
399
404
|
let token: string | null = null;
|
|
405
|
+
let transport: GitCredentialTransport | undefined;
|
|
400
406
|
let tokenExpiresAt: string | undefined;
|
|
401
407
|
if (
|
|
402
408
|
selection.provider === "github" &&
|
|
@@ -431,6 +437,7 @@ async function mintRunGitTokensWithIdentity(
|
|
|
431
437
|
);
|
|
432
438
|
}
|
|
433
439
|
token = minted.token;
|
|
440
|
+
transport = validatedGitCredentialTransport(selection, minted);
|
|
434
441
|
tokenExpiresAt = minted.expiresAt
|
|
435
442
|
? validatedGitCredentialExpiry(selection.provider, minted.expiresAt)
|
|
436
443
|
: undefined;
|
|
@@ -455,6 +462,7 @@ async function mintRunGitTokensWithIdentity(
|
|
|
455
462
|
credentialBindingId: selection.credentialBindingId,
|
|
456
463
|
provider: selection.provider,
|
|
457
464
|
token,
|
|
465
|
+
...(transport ? { transport } : {}),
|
|
458
466
|
...(tokenExpiresAt ? { expiresAt: tokenExpiresAt } : {}),
|
|
459
467
|
});
|
|
460
468
|
}
|
|
@@ -467,6 +475,7 @@ async function mintRunGitTokensWithIdentity(
|
|
|
467
475
|
}
|
|
468
476
|
for (const binding of bindings) {
|
|
469
477
|
binding.providerBindingCount = counts.get(binding.provider) ?? 1;
|
|
478
|
+
if (binding.transport?.kind === "http_broker") continue;
|
|
470
479
|
if (counts.get(binding.provider) !== 1) continue;
|
|
471
480
|
gitTokens[binding.provider] = binding.token;
|
|
472
481
|
if (binding.expiresAt) expiresAt[binding.provider] = binding.expiresAt;
|
|
@@ -482,6 +491,128 @@ function validatedGitCredentialExpiry(provider: GitCredentialProvider, value: st
|
|
|
482
491
|
return new Date(timestamp).toISOString();
|
|
483
492
|
}
|
|
484
493
|
|
|
494
|
+
const MAX_GIT_HTTP_BROKER_ROUTES = 256;
|
|
495
|
+
const MAX_GIT_HTTP_BROKER_URI_LENGTH = 4_096;
|
|
496
|
+
|
|
497
|
+
function validatedGitCredentialTransport(
|
|
498
|
+
selection: GitCredentialSelection,
|
|
499
|
+
minted: GitCredentials,
|
|
500
|
+
): GitCredentialTransport | undefined {
|
|
501
|
+
const transport = minted.transport;
|
|
502
|
+
if (!transport) return undefined;
|
|
503
|
+
|
|
504
|
+
if (
|
|
505
|
+
typeof transport !== "object" ||
|
|
506
|
+
transport.kind !== "http_broker" ||
|
|
507
|
+
!Array.isArray(transport.repositories)
|
|
508
|
+
) {
|
|
509
|
+
throw new Error(
|
|
510
|
+
`connection-credential provider (${selection.provider}) returned an invalid Git credential transport`,
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
const requestedUris = new Set(selection.repositoryRefs.map((repository) => repository.uri));
|
|
514
|
+
if (
|
|
515
|
+
requestedUris.size === 0 ||
|
|
516
|
+
requestedUris.size > MAX_GIT_HTTP_BROKER_ROUTES ||
|
|
517
|
+
transport.repositories.length !== requestedUris.size
|
|
518
|
+
) {
|
|
519
|
+
throw new Error(
|
|
520
|
+
`connection-credential provider (${selection.provider}) returned an incomplete Git HTTP broker route set`,
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const echoedUris = new Set<string>();
|
|
525
|
+
const brokerUris = new Set<string>();
|
|
526
|
+
const repositories = transport.repositories.map((route) => {
|
|
527
|
+
if (
|
|
528
|
+
!route ||
|
|
529
|
+
typeof route !== "object" ||
|
|
530
|
+
typeof route.repositoryUri !== "string" ||
|
|
531
|
+
typeof route.brokerUri !== "string"
|
|
532
|
+
) {
|
|
533
|
+
throw new Error(
|
|
534
|
+
`connection-credential provider (${selection.provider}) returned an invalid Git HTTP broker route`,
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
if (!requestedUris.has(route.repositoryUri) || echoedUris.has(route.repositoryUri)) {
|
|
538
|
+
throw new Error(
|
|
539
|
+
`connection-credential provider (${selection.provider}) returned an unexpected Git HTTP broker repository`,
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
echoedUris.add(route.repositoryUri);
|
|
543
|
+
if (
|
|
544
|
+
route.brokerUri.length === 0 ||
|
|
545
|
+
route.brokerUri.length > MAX_GIT_HTTP_BROKER_URI_LENGTH ||
|
|
546
|
+
route.brokerUri.trim() !== route.brokerUri
|
|
547
|
+
) {
|
|
548
|
+
throw new Error(
|
|
549
|
+
`connection-credential provider (${selection.provider}) returned an invalid Git HTTP broker URI`,
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
let brokerUrl: URL;
|
|
553
|
+
try {
|
|
554
|
+
brokerUrl = new URL(route.brokerUri);
|
|
555
|
+
} catch {
|
|
556
|
+
throw new Error(
|
|
557
|
+
`connection-credential provider (${selection.provider}) returned an invalid Git HTTP broker URI`,
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
if (
|
|
561
|
+
brokerUrl.protocol !== "https:" ||
|
|
562
|
+
brokerUrl.username ||
|
|
563
|
+
brokerUrl.password ||
|
|
564
|
+
brokerUrl.search ||
|
|
565
|
+
brokerUrl.hash ||
|
|
566
|
+
brokerUris.has(brokerUrl.href) ||
|
|
567
|
+
brokerUrl.href === route.repositoryUri
|
|
568
|
+
) {
|
|
569
|
+
throw new Error(
|
|
570
|
+
`connection-credential provider (${selection.provider}) returned an unsafe Git HTTP broker URI`,
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
brokerUris.add(brokerUrl.href);
|
|
574
|
+
return {
|
|
575
|
+
repositoryUri: route.repositoryUri,
|
|
576
|
+
brokerUri: brokerUrl.href,
|
|
577
|
+
};
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
if ([...requestedUris].some((uri) => !echoedUris.has(uri))) {
|
|
581
|
+
throw new Error(
|
|
582
|
+
`connection-credential provider (${selection.provider}) returned an incomplete Git HTTP broker route set`,
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
return { kind: "http_broker", repositories };
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export function assertGitCredentialRenewalTransportUnchanged(
|
|
589
|
+
initial: GitCredentialBindingSeed,
|
|
590
|
+
renewed: GitCredentialBindingSeed,
|
|
591
|
+
): void {
|
|
592
|
+
if (!initial.transport && !renewed.transport) return;
|
|
593
|
+
if (
|
|
594
|
+
!initial.transport ||
|
|
595
|
+
!renewed.transport ||
|
|
596
|
+
initial.transport.kind !== renewed.transport.kind
|
|
597
|
+
) {
|
|
598
|
+
throw new Error(
|
|
599
|
+
`renewed ${initial.provider} credential changed transport for binding ${initial.credentialBindingId}`,
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
const routeKey = (route: { repositoryUri: string; brokerUri: string }) =>
|
|
603
|
+
`${route.repositoryUri}\u0000${route.brokerUri}`;
|
|
604
|
+
const initialRoutes = initial.transport.repositories.map(routeKey).sort();
|
|
605
|
+
const renewedRoutes = renewed.transport.repositories.map(routeKey).sort();
|
|
606
|
+
if (
|
|
607
|
+
initialRoutes.length !== renewedRoutes.length ||
|
|
608
|
+
initialRoutes.some((route, index) => route !== renewedRoutes[index])
|
|
609
|
+
) {
|
|
610
|
+
throw new Error(
|
|
611
|
+
`renewed ${initial.provider} credential changed Git HTTP broker routes for binding ${initial.credentialBindingId}`,
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
485
616
|
async function resolveRunGitIdentityWithSelections(
|
|
486
617
|
settings: Settings,
|
|
487
618
|
selections: GitCredentialSelection[],
|