@opengeni/worker-bundle 1.0.1 → 2.0.0-canary.35625901699001
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/activities/agent-turn/agent-build.d.ts +1 -0
- package/dist/activities/agent-turn/codex.d.ts +1 -1
- package/dist/activities/agent-turn/compaction-prep.d.ts +1 -5
- package/dist/activities/agent-turn/errors.d.ts +31 -5
- package/dist/activities/agent-turn/finalization-monitor.d.ts +17 -0
- package/dist/activities/agent-turn/finalization.d.ts +1 -1
- package/dist/activities/agent-turn/governance-model.d.ts +0 -2
- package/dist/activities/agent-turn/quiescence.d.ts +1 -0
- package/dist/activities/agent-turn/recovery-warning.d.ts +8 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +0 -1
- package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -1
- package/dist/activities/agent-turn/sandbox-route.d.ts +0 -20
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -1
- package/dist/activities/agent-turn/skill-remove.d.ts +14 -0
- package/dist/activities/agent-turn/skill-search.d.ts +1 -1
- package/dist/activities/agent-turn/stream-attempt.d.ts +1 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +34 -4
- package/dist/activities/agent-turn/turn-context.d.ts +2 -0
- package/dist/activities/agent-turn/turn-sandbox-access.d.ts +3 -0
- package/dist/activities/codemode-dispatcher.d.ts +3 -1
- package/dist/activities/codex-capacity.d.ts +6 -1
- package/dist/activities/codex-rotation.d.ts +1 -1
- package/dist/activities/context-compaction.d.ts +7 -1
- package/dist/activities/mcp-account-routes.d.ts +22 -0
- package/dist/activities/mcp-credentials.d.ts +12 -13
- package/dist/activities/mcp-operation-authority.d.ts +0 -5
- package/dist/activities/rig-verification.d.ts +2 -3
- package/dist/activities/sandbox-images.d.ts +1 -1
- package/dist/activities/sandbox-lease.d.ts +4 -3
- package/dist/activities/session-state.d.ts +57 -2
- package/dist/activities/types.d.ts +12 -3
- package/dist/{activities-control-HMFGSKC5.js → activities-control-BOLIY3H4.js} +366 -187
- package/dist/activities-control-BOLIY3H4.js.map +1 -0
- package/dist/activities-control.d.ts +110 -2
- package/dist/{activities-turn-AP67JADS.js → activities-turn-UCFKWOAA.js} +797 -476
- package/dist/activities-turn-UCFKWOAA.js.map +1 -0
- package/dist/activities.d.ts +110 -2
- package/dist/artifact-materializer-entry.js +5 -2
- package/dist/artifact-materializer-entry.js.map +1 -1
- package/dist/artifact-outbox-entry.js +2 -2
- package/dist/artifact-outbox-entry.js.map +1 -1
- package/dist/{chunk-A4XQWVZK.js → chunk-I7HKKMUJ.js} +77 -1
- package/dist/chunk-I7HKKMUJ.js.map +1 -0
- package/dist/{chunk-CYITU5UH.js → chunk-TVEE2UUC.js} +275 -146
- package/dist/chunk-TVEE2UUC.js.map +1 -0
- package/dist/editable-artifact-materializer-service.d.ts +2 -2
- package/dist/editable-artifact-outbox-service.d.ts +2 -2
- package/dist/index.d.ts +55 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/observability-metrics.d.ts +11 -3
- package/dist/retained-process-diagnostics.d.ts +4 -0
- package/dist/sandbox-resume.d.ts +2 -12
- package/dist/sandbox-routing.d.ts +5 -3
- package/dist/sandbox-snapshot-diagnostics.d.ts +20 -0
- package/dist/warm-capture-holder.d.ts +3 -0
- package/dist/workflow-bundle.js +51 -11
- package/package.json +19 -19
- package/src/activities/agent-turn/agent-build.ts +47 -6
- package/src/activities/agent-turn/claim.ts +12 -0
- package/src/activities/agent-turn/codex-capacity.ts +26 -4
- package/src/activities/agent-turn/codex.ts +6 -2
- package/src/activities/agent-turn/compaction-prep.ts +53 -72
- package/src/activities/agent-turn/errors.ts +98 -10
- package/src/activities/agent-turn/failure-settlement.ts +49 -28
- package/src/activities/agent-turn/finalization-monitor.ts +121 -0
- package/src/activities/agent-turn/finalization.ts +79 -21
- package/src/activities/agent-turn/governance-model.ts +15 -19
- package/src/activities/agent-turn/history.ts +24 -10
- package/src/activities/agent-turn/quiescence.ts +3 -0
- package/src/activities/agent-turn/recovery-warning.ts +18 -0
- package/src/activities/agent-turn/run-credentials.ts +3 -7
- package/src/activities/agent-turn/run.ts +69 -52
- package/src/activities/agent-turn/sandbox-establish.ts +10 -2
- package/src/activities/agent-turn/sandbox-route.ts +0 -20
- package/src/activities/agent-turn/sandbox-runtime.ts +40 -7
- package/src/activities/agent-turn/skill-remove.ts +46 -0
- package/src/activities/agent-turn/skill-save.ts +1 -1
- package/src/activities/agent-turn/skill-search.ts +1 -1
- package/src/activities/agent-turn/skill-selection.ts +2 -0
- package/src/activities/agent-turn/skill-tools.ts +10 -5
- package/src/activities/agent-turn/stream-attempt.ts +52 -16
- package/src/activities/agent-turn/tool-environment.ts +49 -29
- package/src/activities/agent-turn/turn-context.ts +3 -0
- package/src/activities/agent-turn/turn-sandbox-access.ts +7 -1
- package/src/activities/capabilities.ts +17 -2
- package/src/activities/codemode-dispatcher.ts +6 -0
- package/src/activities/codex-capacity.ts +38 -9
- package/src/activities/codex-rotation.ts +18 -5
- package/src/activities/context-compaction.ts +26 -4
- package/src/activities/goals.ts +1 -0
- package/src/activities/google-drive-publication.ts +1 -3
- package/src/activities/mcp-account-routes.ts +139 -0
- package/src/activities/mcp-credentials.ts +83 -194
- package/src/activities/mcp-operation-authority.ts +16 -41
- package/src/activities/parent-wake.ts +8 -0
- package/src/activities/rig-verification.ts +38 -37
- package/src/activities/run-input.ts +25 -16
- package/src/activities/sandbox-images.ts +0 -1
- package/src/activities/sandbox-lease.ts +177 -44
- package/src/activities/scheduled-tasks.ts +118 -93
- package/src/activities/session-state.ts +83 -3
- package/src/activities/types.ts +18 -2
- package/src/activities/workflow-wake.ts +2 -17
- package/src/editable-artifact-materializer-service.ts +7 -3
- package/src/editable-artifact-outbox-service.ts +4 -4
- package/src/github-rest-mcp.ts +0 -1
- package/src/index.ts +2 -1
- package/src/observability-metrics.ts +105 -2
- package/src/personal-github-git-credentials.ts +0 -1
- package/src/pr-review-credentials.ts +0 -2
- package/src/retained-process-diagnostics.ts +50 -0
- package/src/sandbox-resume.ts +58 -73
- package/src/sandbox-routing.ts +44 -19
- package/src/sandbox-snapshot-diagnostics.ts +112 -0
- package/src/warm-capture-holder.ts +15 -0
- package/src/workflows/session.ts +64 -2
- package/dist/activities/agent-turn/knowledge-sources.d.ts +0 -20
- package/dist/activities/packs.d.ts +0 -55
- package/dist/activities-control-HMFGSKC5.js.map +0 -1
- package/dist/activities-turn-AP67JADS.js.map +0 -1
- package/dist/chunk-A4XQWVZK.js.map +0 -1
- package/dist/chunk-CYITU5UH.js.map +0 -1
- package/src/activities/agent-turn/knowledge-sources.ts +0 -86
- package/src/activities/packs.ts +0 -166
|
@@ -41,7 +41,7 @@ export function createSkillSaveAttemptToolDefinition(input: {
|
|
|
41
41
|
codemodePath: ["opengeni", "skill_save"],
|
|
42
42
|
title: "Save Skill text",
|
|
43
43
|
description:
|
|
44
|
-
"Create or edit a
|
|
44
|
+
"Create or edit a Skill for reusable procedures or context-specific and personal behavioral preferences, not retrieval-only facts. Put its applicability in the SKILL.md description so the prompt index can guide skill_read; the full body is loaded when relevant. Short always-on workspace rules use instruction_policy_save. Supply only changed UTF-8 text files and explicit deletions; omitted files are preserved. No sandbox is needed. Use the revision and scope version returned by Skill discovery for stale-write protection. For creation choose a new UUID, set expectedRevisionId to null and expectedScopeVersion to 1. The effective Skills setting governs publication: Automatic publishes, Review first saves a pending revision in Knowledge > Needs review while the task continues, and Off prevents agent authoring. Report the actual receipt without asking an approval question. Private chats save personal Skills; shared chats save workspace Skills. Preserve the intended scope; another destination is not a workaround for unavailable scope or learning restrictions.",
|
|
45
45
|
inputSchema: {
|
|
46
46
|
type: "object",
|
|
47
47
|
properties: {
|
|
@@ -8,7 +8,7 @@ export type WorkspaceSkillSearchEntry = Readonly<{
|
|
|
8
8
|
revisionId?: string;
|
|
9
9
|
scopeVersion?: number;
|
|
10
10
|
installationVersion?: number;
|
|
11
|
-
source?: "workspace" | "builtin" | "session"
|
|
11
|
+
source?: "workspace" | "builtin" | "session";
|
|
12
12
|
}>;
|
|
13
13
|
|
|
14
14
|
export function createSkillSearchAttemptToolDefinition(input: {
|
|
@@ -14,6 +14,8 @@ export function configuredBundledSkillNames(context: BundledSkillConfiguration):
|
|
|
14
14
|
const tools = new Set(context.firstPartyTools);
|
|
15
15
|
const artifacts = () => tools.has("editable_artifact_list") && tools.has("editable_artifact_get");
|
|
16
16
|
const definitions = [
|
|
17
|
+
{ name: "opengeni-help", include: () => true },
|
|
18
|
+
{ name: "opengeni-client", include: () => true },
|
|
17
19
|
{ name: "opengeni-visualize", include: () => true },
|
|
18
20
|
{ name: "document-parsing", include: () => true },
|
|
19
21
|
{ name: "opengeni-skills", include: () => true },
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
readSkill,
|
|
19
19
|
resolveSkillImport,
|
|
20
20
|
saveSkill,
|
|
21
|
+
removeSkill,
|
|
21
22
|
} from "@opengeni/core";
|
|
22
23
|
import {
|
|
23
24
|
buildPortableSkillArtifact,
|
|
@@ -31,6 +32,7 @@ import { createSkillReadAttemptToolDefinition, type SkillReadContent } from "./s
|
|
|
31
32
|
import { createSkillSearchAttemptToolDefinition } from "./skill-search";
|
|
32
33
|
import { createSkillSaveAttemptToolDefinition, type SkillSaveRequest } from "./skill-save";
|
|
33
34
|
import { createSkillInstallAttemptToolDefinition } from "./skill-install";
|
|
35
|
+
import { createSkillRemoveAttemptToolDefinition } from "./skill-remove";
|
|
34
36
|
import {
|
|
35
37
|
createSkillCheckoutAttemptToolDefinition,
|
|
36
38
|
createSkillPublishAttemptToolDefinition,
|
|
@@ -122,6 +124,13 @@ export function createWorkspaceSkillTools(input: {
|
|
|
122
124
|
);
|
|
123
125
|
};
|
|
124
126
|
return [
|
|
127
|
+
createSkillRemoveAttemptToolDefinition({
|
|
128
|
+
authorize,
|
|
129
|
+
remove: async (request) =>
|
|
130
|
+
withReviewState(
|
|
131
|
+
await removeSkill(input.db, { ...context, ...request, actor: input.actor }),
|
|
132
|
+
),
|
|
133
|
+
}),
|
|
125
134
|
createSkillReadAttemptToolDefinition({ authorize, load }),
|
|
126
135
|
createSkillSearchAttemptToolDefinition({
|
|
127
136
|
authorize,
|
|
@@ -140,11 +149,7 @@ export function createWorkspaceSkillTools(input: {
|
|
|
140
149
|
id: entry.id,
|
|
141
150
|
name: entry.artifact.name,
|
|
142
151
|
description: entry.artifact.description || entry.artifact.name,
|
|
143
|
-
source: entry.id.startsWith("builtin:")
|
|
144
|
-
? ("builtin" as const)
|
|
145
|
-
: entry.id.startsWith("session:")
|
|
146
|
-
? ("session" as const)
|
|
147
|
-
: ("pack" as const),
|
|
152
|
+
source: entry.id.startsWith("builtin:") ? ("builtin" as const) : ("session" as const),
|
|
148
153
|
})),
|
|
149
154
|
],
|
|
150
155
|
publicSearch: createPublicSkillSearchClient(input.settings),
|
|
@@ -17,11 +17,13 @@ import { publishDurableSessionEvents } from "@opengeni/events";
|
|
|
17
17
|
import {
|
|
18
18
|
normalizeModelCallUsage,
|
|
19
19
|
normalizeSdkEvent,
|
|
20
|
+
withMcpToolDisplayMetadata,
|
|
20
21
|
extractOpenSuffixFromRunState,
|
|
21
22
|
assertOpenSuffixResumable,
|
|
22
23
|
interruptionKindForCallItem,
|
|
23
24
|
releaseMcpResultCustomDataFromSdkEvent,
|
|
24
25
|
findCompactionNeededError,
|
|
26
|
+
compactionProviderRejection,
|
|
25
27
|
withRunCredentialsSession,
|
|
26
28
|
runOwnedSandboxSetup,
|
|
27
29
|
type SandboxFileDownload,
|
|
@@ -69,6 +71,7 @@ import {
|
|
|
69
71
|
isCompletedGeneratedImageSdkEvent,
|
|
70
72
|
} from "../generated-images";
|
|
71
73
|
import { ToolResultSpill } from "./tool-result-spill";
|
|
74
|
+
import { ownedTurnSandboxForAgent } from "./turn-sandbox-access";
|
|
72
75
|
import { createTurnCredentialLeases } from "./credential-leases";
|
|
73
76
|
import { createTurnMediaArtifacts } from "./media-artifacts";
|
|
74
77
|
import { createTurnHistorySink } from "./history-sink";
|
|
@@ -96,6 +99,7 @@ import {
|
|
|
96
99
|
compactionFailureReason,
|
|
97
100
|
safeErrorDiagnostic,
|
|
98
101
|
compactionFailureReasonFromError,
|
|
102
|
+
compactionFailureTurnEventPayload,
|
|
99
103
|
isCompactionSummaryFailure,
|
|
100
104
|
PostCompactionContinuationEmptyError,
|
|
101
105
|
shouldRecoverCompactionProviderFailure,
|
|
@@ -221,7 +225,7 @@ export type TurnStreamAttemptDeps = {
|
|
|
221
225
|
activeSandboxBackend: Settings["sandboxBackend"] | undefined;
|
|
222
226
|
groupBoxBackend: Settings["sandboxBackend"];
|
|
223
227
|
turnExecutionPolicy: TurnExecutionPolicyV1;
|
|
224
|
-
turn: { executionGeneration: number; model: string };
|
|
228
|
+
turn: { executionGeneration: number; model: string; source?: string };
|
|
225
229
|
trigger: NonNullable<Awaited<ReturnType<typeof getSessionEvent>>>;
|
|
226
230
|
humanInputResume: Awaited<ReturnType<typeof getHumanInputResumeForEvent>>;
|
|
227
231
|
attachPendingUpdatesAfterOpenSuffix: () => Promise<boolean>;
|
|
@@ -650,8 +654,7 @@ export async function runTurnStreamAttempt(
|
|
|
650
654
|
});
|
|
651
655
|
}
|
|
652
656
|
};
|
|
653
|
-
const ownedEstablished =
|
|
654
|
-
sandboxState.resolvedSandbox?.established ?? sandboxState.lazyOwnedSandbox;
|
|
657
|
+
const ownedEstablished = ownedTurnSandboxForAgent(sandboxState);
|
|
655
658
|
const runStreamOnce = async (): ReturnType<OpenGeniRuntime["runStream"]> => {
|
|
656
659
|
const eagerResolvedSandbox = sandboxState.resolvedSandbox;
|
|
657
660
|
// Eager owned sessions must settle the exact platform-setup provider
|
|
@@ -759,8 +762,8 @@ export async function runTurnStreamAttempt(
|
|
|
759
762
|
eventing.firstModelRequestPreparationStartedAt = performance.now();
|
|
760
763
|
eventing.firstModelRequestCheckpointAt = eventing.firstModelRequestPreparationStartedAt;
|
|
761
764
|
}
|
|
762
|
-
const
|
|
763
|
-
let
|
|
765
|
+
const streamInitializationStartedAt = performance.now();
|
|
766
|
+
let streamInitializationOutcome: "completed" | "failed" = "completed";
|
|
764
767
|
try {
|
|
765
768
|
// This histogram describes worker preparation until the first entry
|
|
766
769
|
// into the runtime. Lazy SDK request preparation and the durable
|
|
@@ -894,15 +897,15 @@ export async function runTurnStreamAttempt(
|
|
|
894
897
|
: {}),
|
|
895
898
|
});
|
|
896
899
|
} catch (error) {
|
|
897
|
-
|
|
900
|
+
streamInitializationOutcome = "failed";
|
|
898
901
|
throw error;
|
|
899
902
|
} finally {
|
|
900
903
|
recordTurnStartupPhase(observability, {
|
|
901
|
-
phase: "
|
|
904
|
+
phase: "runtime_stream_initialization",
|
|
902
905
|
provider: turnExecutionPolicy.providerId,
|
|
903
906
|
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
904
|
-
outcome:
|
|
905
|
-
durationSeconds: (performance.now() -
|
|
907
|
+
outcome: streamInitializationOutcome,
|
|
908
|
+
durationSeconds: (performance.now() - streamInitializationStartedAt) / 1_000,
|
|
906
909
|
});
|
|
907
910
|
}
|
|
908
911
|
};
|
|
@@ -1302,6 +1305,11 @@ export async function runTurnStreamAttempt(
|
|
|
1302
1305
|
: {},
|
|
1303
1306
|
);
|
|
1304
1307
|
for (const event of normalized) {
|
|
1308
|
+
if (event.type === "agent.toolCall.created")
|
|
1309
|
+
event.payload = withMcpToolDisplayMetadata(
|
|
1310
|
+
eventing.preparedTools?.mcpServers ?? [],
|
|
1311
|
+
event.payload,
|
|
1312
|
+
);
|
|
1305
1313
|
streamTiming.onEvent(event.type);
|
|
1306
1314
|
await eventing.batcher.push(event);
|
|
1307
1315
|
}
|
|
@@ -1639,7 +1647,14 @@ export async function runTurnStreamAttempt(
|
|
|
1639
1647
|
? [
|
|
1640
1648
|
{
|
|
1641
1649
|
type: "session.requiresAction" as const,
|
|
1642
|
-
payload: {
|
|
1650
|
+
payload: {
|
|
1651
|
+
approvals: approvals.map((approval) =>
|
|
1652
|
+
withMcpToolDisplayMetadata(
|
|
1653
|
+
eventing.preparedTools?.mcpServers ?? [],
|
|
1654
|
+
approval,
|
|
1655
|
+
),
|
|
1656
|
+
),
|
|
1657
|
+
},
|
|
1643
1658
|
},
|
|
1644
1659
|
]
|
|
1645
1660
|
: []),
|
|
@@ -1747,6 +1762,7 @@ export async function runTurnStreamAttempt(
|
|
|
1747
1762
|
return claimedResult({ status: "cancelled" });
|
|
1748
1763
|
}
|
|
1749
1764
|
if (
|
|
1765
|
+
turn.source !== "compaction" &&
|
|
1750
1766
|
generateSessionTitleInParallel &&
|
|
1751
1767
|
runtime.generateSessionTitle &&
|
|
1752
1768
|
!runtimeCancellationSignal.aborted
|
|
@@ -1822,6 +1838,7 @@ export async function runTurnStreamAttempt(
|
|
|
1822
1838
|
let compacted = false;
|
|
1823
1839
|
let compactionHandled = false;
|
|
1824
1840
|
let compactionFailureMessage: string | null = null;
|
|
1841
|
+
let compactionFailureError: unknown = null;
|
|
1825
1842
|
let compactionRequestCleared = false;
|
|
1826
1843
|
try {
|
|
1827
1844
|
const outcome = await forceContextCompaction(
|
|
@@ -1856,6 +1873,7 @@ export async function runTurnStreamAttempt(
|
|
|
1856
1873
|
{
|
|
1857
1874
|
clearRequestedCompaction: recoveryKind === "operator",
|
|
1858
1875
|
publishLiveEvents: publishCompactionLiveEvents,
|
|
1876
|
+
providerRejection: compactionProviderRejection(compactError),
|
|
1859
1877
|
},
|
|
1860
1878
|
);
|
|
1861
1879
|
compactionRequestCleared = landmark.requestConsumed;
|
|
@@ -1863,6 +1881,7 @@ export async function runTurnStreamAttempt(
|
|
|
1863
1881
|
await finishParallelSessionTitle();
|
|
1864
1882
|
const deferredSteer = await settleDeferredSteerAfterCompaction();
|
|
1865
1883
|
if (deferredSteer) return deferredSteer;
|
|
1884
|
+
compactionFailureError = compactError;
|
|
1866
1885
|
compactionFailureMessage = String(compactionFailureReasonFromError(compactError));
|
|
1867
1886
|
observability.warn("context compaction recovery compaction failed", {
|
|
1868
1887
|
sessionId: input.sessionId,
|
|
@@ -1880,13 +1899,9 @@ export async function runTurnStreamAttempt(
|
|
|
1880
1899
|
events: [
|
|
1881
1900
|
{
|
|
1882
1901
|
type: "turn.failed",
|
|
1883
|
-
payload: {
|
|
1902
|
+
payload: compactionFailureTurnEventPayload(compactionFailureError, {
|
|
1884
1903
|
error: errorMessage,
|
|
1885
|
-
|
|
1886
|
-
retryable: false,
|
|
1887
|
-
recovery: "user_message",
|
|
1888
|
-
compacted: false,
|
|
1889
|
-
},
|
|
1904
|
+
}),
|
|
1890
1905
|
},
|
|
1891
1906
|
{
|
|
1892
1907
|
type: "session.status.changed",
|
|
@@ -1919,6 +1934,27 @@ export async function runTurnStreamAttempt(
|
|
|
1919
1934
|
await finishParallelSessionTitle();
|
|
1920
1935
|
const deferredSteer = await settleDeferredSteerAfterCompaction();
|
|
1921
1936
|
if (deferredSteer) return deferredSteer;
|
|
1937
|
+
if (turn.source === "compaction") {
|
|
1938
|
+
const settled = await eventing.settle!({
|
|
1939
|
+
events: [
|
|
1940
|
+
{
|
|
1941
|
+
type: "turn.completed",
|
|
1942
|
+
payload: {
|
|
1943
|
+
maintenance: "context_compaction",
|
|
1944
|
+
result: compacted ? "compacted" : "already_applied",
|
|
1945
|
+
},
|
|
1946
|
+
},
|
|
1947
|
+
{ type: "session.status.changed", payload: { status: "idle" } },
|
|
1948
|
+
],
|
|
1949
|
+
turnStatus: "completed",
|
|
1950
|
+
sessionStatus: "idle",
|
|
1951
|
+
activeTurnId: null,
|
|
1952
|
+
});
|
|
1953
|
+
if (!settled) return claimedResult({ status: "cancelled" });
|
|
1954
|
+
control.turnMetricOutcome = "completed";
|
|
1955
|
+
control.activityStatus = "idle";
|
|
1956
|
+
return claimedResult({ status: "idle" });
|
|
1957
|
+
}
|
|
1922
1958
|
// Codex parity: compaction remains inside the same logical turn and
|
|
1923
1959
|
// the same activity. Rebuild the model-visible history from the
|
|
1924
1960
|
// durable replacement and continue the sampling loop; do not create
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
type ConnectorAttachmentMaterializationRequest,
|
|
32
32
|
type ConnectorActionPolicyHooks,
|
|
33
33
|
createFirstPartyInteractionAttemptToolDefinitions,
|
|
34
|
+
mcpToolDisplayMetadata,
|
|
34
35
|
} from "@opengeni/runtime";
|
|
35
36
|
import {
|
|
36
37
|
createGoogleDrivePublicationAttemptTool,
|
|
@@ -38,6 +39,11 @@ import {
|
|
|
38
39
|
resolveGoogleDrivePublicationTarget,
|
|
39
40
|
} from "../google-drive-publication";
|
|
40
41
|
import { connectionTokenResolverForTurn } from "../mcp-credentials";
|
|
42
|
+
import {
|
|
43
|
+
accountRouteAuthNeededPayload,
|
|
44
|
+
expandApiIntegrationAccountRoutes,
|
|
45
|
+
expandMcpAccountRoutes,
|
|
46
|
+
} from "../mcp-account-routes";
|
|
41
47
|
import { createMcpOperationPersistence } from "@opengeni/db/mcp-operations";
|
|
42
48
|
import { createMcpOperationReadStore } from "../mcp-operation-store";
|
|
43
49
|
import { createMcpOperationObserverResolver } from "../mcp-operation-observer";
|
|
@@ -51,7 +57,7 @@ import { buildCodexTokenResolver } from "../codex-auth";
|
|
|
51
57
|
import { CODEX_CLIENT_VERSION } from "@opengeni/codex";
|
|
52
58
|
import { mergeResourceRefs } from "../common";
|
|
53
59
|
import {
|
|
54
|
-
|
|
60
|
+
workspaceSessionToolPolicyDefaultServerIds,
|
|
55
61
|
loadRigDefaultVariableSetEnvironment,
|
|
56
62
|
mergeRigDefaultVariableSetEnvironment,
|
|
57
63
|
buildApiIntegrationMcpServers,
|
|
@@ -64,7 +70,7 @@ import {
|
|
|
64
70
|
import { loadWorkspaceEnvironmentForRunWithCredentials } from "../environment";
|
|
65
71
|
import { withFirstPartyTools } from "../goals";
|
|
66
72
|
import type { TurnActivityServices as ActivityServices, RunAgentTurnInput } from "../types";
|
|
67
|
-
import { recordTurnStartupPhase } from "../../observability-metrics";
|
|
73
|
+
import { recordToolPreparationPhase, recordTurnStartupPhase } from "../../observability-metrics";
|
|
68
74
|
import { ToolResultSpill } from "./tool-result-spill";
|
|
69
75
|
import { createTurnMediaArtifacts } from "./media-artifacts";
|
|
70
76
|
import { SandboxChannelAService } from "@opengeni/runtime/sandbox";
|
|
@@ -103,7 +109,6 @@ import { createListModelsAttemptToolDefinition } from "./list-models";
|
|
|
103
109
|
import { createWorkspaceSkillTools } from "./skill-tools";
|
|
104
110
|
import { loadConfiguredBundledSkills } from "./skill-selection";
|
|
105
111
|
import { guardSkillFilesystem } from "./skill-transfer";
|
|
106
|
-
import type { RuntimeSkillActivation } from "@opengeni/runtime";
|
|
107
112
|
|
|
108
113
|
export type PrepareTurnToolPolicyDeps = {
|
|
109
114
|
input: RunAgentTurnInput;
|
|
@@ -125,7 +130,6 @@ export type PrepareTurnToolRuntimeDeps = {
|
|
|
125
130
|
input: import("../types").RunKnowledgeSourceSyncBatchInput,
|
|
126
131
|
) => Promise<import("../types").RunKnowledgeSourceSyncBatchResult>)
|
|
127
132
|
| undefined;
|
|
128
|
-
selectedSkillActivations: readonly RuntimeSkillActivation[];
|
|
129
133
|
input: RunAgentTurnInput;
|
|
130
134
|
catalogSourceSettings: Settings;
|
|
131
135
|
db: ActivityServices["db"];
|
|
@@ -134,7 +138,6 @@ export type PrepareTurnToolRuntimeDeps = {
|
|
|
134
138
|
objectStorage: ActivityServices["objectStorage"];
|
|
135
139
|
observability: ActivityServices["observability"];
|
|
136
140
|
cancellationSignal: AbortSignal | undefined;
|
|
137
|
-
connectionCredentials: ActivityServices["connectionCredentials"];
|
|
138
141
|
eventing: EventingState;
|
|
139
142
|
attempt: AttemptIdentityState;
|
|
140
143
|
sandboxState: SandboxRuntimeState;
|
|
@@ -152,7 +155,6 @@ export type PrepareTurnToolRuntimeDeps = {
|
|
|
152
155
|
lazyToolTransport: GovernanceModelOk["lazyToolTransport"];
|
|
153
156
|
turnTools: ReturnType<typeof withFirstPartyTools>;
|
|
154
157
|
connectionScope: { accountId: string; workspaceId: string };
|
|
155
|
-
hostCredentialRootSessionId: string | null;
|
|
156
158
|
sandboxArtifactRuntime: ReturnType<typeof sandboxArtifactRuntimeAdmission>;
|
|
157
159
|
activeSandboxBackend: Settings["sandboxBackend"] | undefined;
|
|
158
160
|
groupBoxBackend: Settings["sandboxBackend"];
|
|
@@ -212,7 +214,15 @@ export async function prepareTurnToolPolicy(deps: PrepareTurnToolPolicyDeps) {
|
|
|
212
214
|
? scheduledEffectiveMcpServerIds.filter((id) => currentMcpServerIds.has(id))
|
|
213
215
|
: [...currentMcpServerIds],
|
|
214
216
|
defaultMcpServerIds:
|
|
215
|
-
scheduledEffectiveMcpServerIds ??
|
|
217
|
+
scheduledEffectiveMcpServerIds ??
|
|
218
|
+
(session.toolPolicy.mode === "workspace_default"
|
|
219
|
+
? await workspaceSessionToolPolicyDefaultServerIds(
|
|
220
|
+
db,
|
|
221
|
+
input.workspaceId,
|
|
222
|
+
capabilitySettings,
|
|
223
|
+
fileAuthoritySubjectId ?? undefined,
|
|
224
|
+
)
|
|
225
|
+
: []),
|
|
216
226
|
});
|
|
217
227
|
const mcpAvailabilityNote = unavailableMcpOperationalContext({
|
|
218
228
|
droppedIds: resolvedToolPolicy.effectivePolicy.droppedIds,
|
|
@@ -349,7 +359,6 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
349
359
|
objectStorage,
|
|
350
360
|
observability,
|
|
351
361
|
cancellationSignal,
|
|
352
|
-
connectionCredentials,
|
|
353
362
|
eventing,
|
|
354
363
|
attempt,
|
|
355
364
|
sandboxState,
|
|
@@ -361,10 +370,9 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
361
370
|
codexAppsCredentialId,
|
|
362
371
|
turnExecutionPolicy,
|
|
363
372
|
trigger,
|
|
364
|
-
runSettings,
|
|
373
|
+
runSettings: canonicalRunSettings,
|
|
365
374
|
lazyToolTransport,
|
|
366
|
-
turnTools,
|
|
367
|
-
hostCredentialRootSessionId,
|
|
375
|
+
turnTools: canonicalTurnTools,
|
|
368
376
|
sandboxArtifactRuntime,
|
|
369
377
|
activeSandboxBackend,
|
|
370
378
|
groupBoxBackend,
|
|
@@ -377,26 +385,29 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
377
385
|
throwIfTurnCancelled,
|
|
378
386
|
} = deps;
|
|
379
387
|
|
|
388
|
+
const accountRoutes = expandMcpAccountRoutes({
|
|
389
|
+
settings: canonicalRunSettings,
|
|
390
|
+
tools: canonicalTurnTools,
|
|
391
|
+
bindings: turn.mcpAccountBindings,
|
|
392
|
+
});
|
|
393
|
+
const runSettings = accountRoutes.settings;
|
|
394
|
+
const turnTools = accountRoutes.tools;
|
|
380
395
|
const toolContextPreparationStartedAt = performance.now();
|
|
381
396
|
throwIfWorkerShuttingDown();
|
|
382
397
|
throwIfTurnCancelled();
|
|
383
|
-
const mcpCredentialRootSessionId =
|
|
384
|
-
connectionCredentials?.mcpCredentials && hostCredentialRootSessionId
|
|
385
|
-
? hostCredentialRootSessionId
|
|
386
|
-
: input.sessionId;
|
|
387
398
|
// Connection credentials and the optional Apps credential are resolved
|
|
388
399
|
// independently. Inference auth is never an Apps fallback.
|
|
389
400
|
const rawResolveCredential = connectionTokenResolverForTurn({
|
|
390
401
|
db,
|
|
391
402
|
settings: runSettings,
|
|
392
|
-
|
|
403
|
+
canonicalMcpServerIds: canonicalRunSettings.mcpServers
|
|
404
|
+
.filter((server) => server.connectionRef)
|
|
405
|
+
.map((server) => server.id),
|
|
393
406
|
accountId: input.accountId,
|
|
394
407
|
workspaceId: input.workspaceId,
|
|
395
408
|
sessionId: input.sessionId,
|
|
396
|
-
rootSessionId: mcpCredentialRootSessionId,
|
|
397
409
|
attemptId: input.attemptId,
|
|
398
410
|
turn,
|
|
399
|
-
observability,
|
|
400
411
|
});
|
|
401
412
|
const personalConnectionDelegations = turn.personalConnectionDelegations;
|
|
402
413
|
const delegatedMembershipChecks = new Map<string, Promise<boolean>>();
|
|
@@ -463,16 +474,24 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
463
474
|
return;
|
|
464
475
|
}
|
|
465
476
|
await eventing.publish!(
|
|
466
|
-
[
|
|
477
|
+
[
|
|
478
|
+
{
|
|
479
|
+
type: "tool.auth_needed",
|
|
480
|
+
payload: rollingSafeToolAuthNeededPayload(
|
|
481
|
+
accountRouteAuthNeededPayload(payload, turn.mcpAccountBindings),
|
|
482
|
+
),
|
|
483
|
+
},
|
|
484
|
+
],
|
|
467
485
|
true,
|
|
468
486
|
);
|
|
469
487
|
};
|
|
470
|
-
const selectedApiIntegrationServerIds = new Set(turnTools.map((tool) => tool.id));
|
|
471
488
|
const apiIntegrationMcpServers = buildApiIntegrationMcpServers({
|
|
472
489
|
settings: runSettings,
|
|
473
|
-
integrations:
|
|
474
|
-
|
|
475
|
-
|
|
490
|
+
integrations: expandApiIntegrationAccountRoutes({
|
|
491
|
+
integrations: installedApiIntegrations,
|
|
492
|
+
bindings: turn.mcpAccountBindings,
|
|
493
|
+
tools: turnTools,
|
|
494
|
+
}),
|
|
476
495
|
authority: {
|
|
477
496
|
accountId: input.accountId,
|
|
478
497
|
workspaceId: input.workspaceId,
|
|
@@ -608,7 +627,6 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
608
627
|
});
|
|
609
628
|
const selectedSkills = [
|
|
610
629
|
...bundledSkills,
|
|
611
|
-
...deps.selectedSkillActivations.map((entry) => ({ id: entry.id, artifact: entry.artifact })),
|
|
612
630
|
...session.skills.map((skill) => ({
|
|
613
631
|
id: `session:${session.id}:${skill.name}`,
|
|
614
632
|
artifact: skill,
|
|
@@ -950,6 +968,7 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
950
968
|
try {
|
|
951
969
|
eventing.preparedTools = await waitForTurnOperation(
|
|
952
970
|
runtime.prepareTools(githubRestMcp.settings, githubRestMcp.tools, {
|
|
971
|
+
mcpAccountLabels: accountRoutes.accountLabels,
|
|
953
972
|
accountId: input.accountId,
|
|
954
973
|
workspaceId: input.workspaceId,
|
|
955
974
|
sessionId: input.sessionId,
|
|
@@ -1002,13 +1021,10 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
1002
1021
|
localMcpServers,
|
|
1003
1022
|
...(deferNonEagerToolPreparation ? { deferNonEagerUntilToolDemand: true } : {}),
|
|
1004
1023
|
onPreparationPhase: (measurement) => {
|
|
1005
|
-
|
|
1006
|
-
|
|
1024
|
+
recordToolPreparationPhase(observability, {
|
|
1025
|
+
...measurement,
|
|
1007
1026
|
provider: turnExecutionPolicy.providerId,
|
|
1008
1027
|
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
1009
|
-
outcome: measurement.outcome,
|
|
1010
|
-
durationSeconds: measurement.durationSeconds,
|
|
1011
|
-
count: githubRestMcp.tools.length,
|
|
1012
1028
|
});
|
|
1013
1029
|
},
|
|
1014
1030
|
onAttemptToolCatalog: async (catalog) => {
|
|
@@ -1080,6 +1096,9 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
1080
1096
|
executionGeneration: attempt.executionGeneration,
|
|
1081
1097
|
},
|
|
1082
1098
|
cancellationSignal,
|
|
1099
|
+
undefined,
|
|
1100
|
+
{},
|
|
1101
|
+
(name) => mcpToolDisplayMetadata(tools.mcpServers, name),
|
|
1083
1102
|
);
|
|
1084
1103
|
eventing.codemodeDispatcher.start();
|
|
1085
1104
|
};
|
|
@@ -1098,6 +1117,7 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
1098
1117
|
return {
|
|
1099
1118
|
attemptConnectorActionBindings,
|
|
1100
1119
|
connectorActionPolicy,
|
|
1120
|
+
mcpServers: runSettings.mcpServers,
|
|
1101
1121
|
generateSessionTitleInParallel: titleToolPlan.generateTitleInParallel,
|
|
1102
1122
|
postToolPreparationStartedAt,
|
|
1103
1123
|
preparationIndependentToolNames: [
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TurnHeartbeatDetails } from "../../op-journal";
|
|
1
2
|
import type { Settings } from "@opengeni/config";
|
|
2
3
|
import type { CodexUsageHeaderSnapshot } from "@opengeni/codex";
|
|
3
4
|
import type { AppendEventInput, ApplySessionTurnSettlementInput } from "@opengeni/db";
|
|
@@ -123,6 +124,7 @@ export type RenewalState = {
|
|
|
123
124
|
};
|
|
124
125
|
|
|
125
126
|
export type EventingState = {
|
|
127
|
+
heartbeatDetails: TurnHeartbeatDetails | null;
|
|
126
128
|
heartbeatTimer: ReturnType<typeof startActivityHeartbeat> | undefined;
|
|
127
129
|
batcher: ReturnType<typeof createRuntimeBatcher> | null;
|
|
128
130
|
preparedTools: Awaited<ReturnType<OpenGeniRuntime["prepareTools"]>> | null;
|
|
@@ -254,6 +256,7 @@ export function createTurnContext(input: {
|
|
|
254
256
|
publishedRunCredentialNotices: new Set(),
|
|
255
257
|
},
|
|
256
258
|
eventing: {
|
|
259
|
+
heartbeatDetails: null,
|
|
257
260
|
heartbeatTimer: undefined,
|
|
258
261
|
batcher: null,
|
|
259
262
|
preparedTools: null,
|
|
@@ -13,6 +13,12 @@ export type ResolvedTurnSandboxAccess = Readonly<{
|
|
|
13
13
|
leaseEpoch: number;
|
|
14
14
|
}>;
|
|
15
15
|
|
|
16
|
+
/** The lazy wrapper remains the agent's owner even after provisioning fills
|
|
17
|
+
* resolvedSandbox with the raw provider handle for capture and release. */
|
|
18
|
+
export function ownedTurnSandboxForAgent(sandboxState: TurnSandboxAccessState) {
|
|
19
|
+
return sandboxState.lazyOwnedSandbox ?? sandboxState.resolvedSandbox?.established;
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
/** Join the turn's canonical sandbox boundary and return its active routed session. */
|
|
17
23
|
export async function resolveTurnSandboxAccess(
|
|
18
24
|
sandboxState: TurnSandboxAccessState,
|
|
@@ -24,7 +30,7 @@ export async function resolveTurnSandboxAccess(
|
|
|
24
30
|
sandbox = await sandboxState.turnSandboxProvisioner.get();
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
const session = (sandboxState
|
|
33
|
+
const session = (ownedTurnSandboxForAgent(sandboxState)?.session ??
|
|
28
34
|
sandbox?.established.session ??
|
|
29
35
|
sdkOwnedSandboxSession) as ChannelASession | null;
|
|
30
36
|
if (!session) throw new Error(unavailableMessage);
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
getWorkspaceOpenRouterCustomModelForExecution,
|
|
23
23
|
listSessionMcpServerMetadata,
|
|
24
24
|
listSessionMcpServersForRun,
|
|
25
|
+
getSessionAttemptMcpApprovalPolicies,
|
|
25
26
|
listWorkspaceGatewayCustomModels,
|
|
26
27
|
listWorkspaceOpenRouterCustomModels,
|
|
27
28
|
workspaceCodexSubscriptionActive,
|
|
@@ -47,10 +48,24 @@ export async function settingsWithSessionMcpServersForRun(
|
|
|
47
48
|
},
|
|
48
49
|
): Promise<Settings> {
|
|
49
50
|
const encryptionKey = environmentsEncryptionKeyBytes(settings);
|
|
51
|
+
const policies = await getSessionAttemptMcpApprovalPolicies(
|
|
52
|
+
db,
|
|
53
|
+
workspaceId,
|
|
54
|
+
sessionId,
|
|
55
|
+
attemptId,
|
|
56
|
+
);
|
|
57
|
+
const policySettings = {
|
|
58
|
+
...settings,
|
|
59
|
+
mcpServers: settings.mcpServers.map((server) =>
|
|
60
|
+
Object.hasOwn(policies, server.id)
|
|
61
|
+
? { ...server, requireApproval: policies[server.id] }
|
|
62
|
+
: server,
|
|
63
|
+
),
|
|
64
|
+
};
|
|
50
65
|
if (!encryptionKey) {
|
|
51
66
|
const metadata = await listSessionMcpServerMetadata(db, workspaceId, sessionId);
|
|
52
67
|
if (metadata.length === 0) {
|
|
53
|
-
return
|
|
68
|
+
return policySettings;
|
|
54
69
|
}
|
|
55
70
|
if (metadata.some((server) => server.headerNames.length > 0)) {
|
|
56
71
|
throw new Error(
|
|
@@ -69,7 +84,7 @@ export async function settingsWithSessionMcpServersForRun(
|
|
|
69
84
|
// overlaid into settings. A session projection read earlier in the turn can
|
|
70
85
|
// be stale after a concurrent mcpCredentialUpdates renewal.
|
|
71
86
|
options?.onResolvedServers?.(servers);
|
|
72
|
-
return settingsWithSessionMcpServers(
|
|
87
|
+
return settingsWithSessionMcpServers(policySettings, servers);
|
|
73
88
|
}
|
|
74
89
|
|
|
75
90
|
export function settingsWithSessionMcpServers(
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
CODEMODE_MAX_CONCURRENT_CALLS_PER_ATTEMPT,
|
|
17
17
|
type CodemodeOperation,
|
|
18
18
|
type SessionEvent,
|
|
19
|
+
type ToolDisplayMetadata,
|
|
19
20
|
} from "@opengeni/contracts";
|
|
20
21
|
import {
|
|
21
22
|
cancelQueuedCodemodeOperationsForAttempt,
|
|
@@ -70,6 +71,7 @@ export class CodemodeAttemptDispatcher {
|
|
|
70
71
|
private readonly turnSignal?: AbortSignal,
|
|
71
72
|
private readonly maxConcurrentCalls = CODEMODE_MAX_CONCURRENT_CALLS_PER_ATTEMPT,
|
|
72
73
|
timings: CodemodeDispatcherTimings = {},
|
|
74
|
+
private readonly toolDisplayMetadata?: (modelName: string) => ToolDisplayMetadata | undefined,
|
|
73
75
|
) {
|
|
74
76
|
if (
|
|
75
77
|
environment.catalog.accountId !== scope.accountId ||
|
|
@@ -371,6 +373,10 @@ export class CodemodeAttemptDispatcher {
|
|
|
371
373
|
payload: {
|
|
372
374
|
id: operation.operationId,
|
|
373
375
|
name: entry.modelName,
|
|
376
|
+
display: this.toolDisplayMetadata?.(entry.modelName) ?? {
|
|
377
|
+
toolName: entry.identity.toolName,
|
|
378
|
+
...(entry.title ? { title: entry.title } : {}),
|
|
379
|
+
},
|
|
374
380
|
arguments: operation.arguments,
|
|
375
381
|
origin: "codemode",
|
|
376
382
|
subjectId: operation.caller.subjectId,
|