@opengeni/worker-bundle 0.29.0-canary.0 → 0.29.0-canary.2
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/knowledge-source-tools.d.ts +9 -0
- package/dist/activities/agent-turn/knowledge-sources.d.ts +20 -0
- package/dist/activities/agent-turn/stream-attempt.d.ts +1 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +1 -0
- package/dist/activities/knowledge-indexing.d.ts +10 -0
- package/dist/activities/run-input.d.ts +1 -0
- package/dist/activities/types.d.ts +10 -3
- package/dist/{activities-control-MKGEOBXT.js → activities-control-HMFGSKC5.js} +331 -3381
- package/dist/activities-control-HMFGSKC5.js.map +1 -0
- package/dist/activities-control.d.ts +12 -0
- package/dist/{activities-turn-5MZZ6HQA.js → activities-turn-AP67JADS.js} +1296 -1021
- package/dist/activities-turn-AP67JADS.js.map +1 -0
- package/dist/activities.d.ts +12 -0
- package/dist/{chunk-OA5CSY5N.js → chunk-CYITU5UH.js} +3348 -174
- package/dist/chunk-CYITU5UH.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +48 -1
- package/dist/index.js.map +1 -1
- package/dist/workflow-bundle.js +65 -35
- package/dist/workflows/knowledge-indexing.d.ts +2 -0
- package/dist/workflows.d.ts +1 -0
- package/package.json +19 -18
- package/src/activities/agent-turn/knowledge-source-tools.ts +98 -0
- package/src/activities/agent-turn/knowledge-sources.ts +86 -0
- package/src/activities/agent-turn/run.ts +1244 -1112
- package/src/activities/agent-turn/skill-install.ts +1 -1
- package/src/activities/agent-turn/skill-save.ts +1 -1
- package/src/activities/agent-turn/skill-selection.ts +2 -0
- package/src/activities/agent-turn/skill-tools.ts +5 -12
- package/src/activities/agent-turn/stream-attempt.ts +3 -0
- package/src/activities/agent-turn/tool-environment.ts +24 -0
- package/src/activities/codex-image-generation.ts +1 -2
- package/src/activities/documents.ts +17 -52
- package/src/activities/knowledge-indexing.ts +130 -0
- package/src/activities/knowledge-source-sync.ts +120 -16
- package/src/activities/mcp-credentials.ts +2 -0
- package/src/activities/run-input.ts +2 -0
- package/src/activities/scheduled-tasks.ts +25 -62
- package/src/activities/types.ts +8 -2
- package/src/activities/video-generation-reconciliation.ts +8 -1
- package/src/activities-control.ts +2 -0
- package/src/activities.ts +1 -0
- package/src/index.ts +49 -0
- package/src/pr-review-credentials.ts +2 -2
- package/src/workflows/knowledge-indexing.ts +12 -0
- package/src/workflows.ts +1 -0
- package/dist/activities-control-MKGEOBXT.js.map +0 -1
- package/dist/activities-turn-5MZZ6HQA.js.map +0 -1
- package/dist/chunk-OA5CSY5N.js.map +0 -1
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
compactionFailureReason,
|
|
24
24
|
compactionFailureReasonFromError,
|
|
25
25
|
computeIdleDelayMs,
|
|
26
|
+
createKnowledgeSourceSyncActivities,
|
|
26
27
|
createModelHistoryAttachmentProjector,
|
|
27
28
|
createRuntimeBatcher,
|
|
28
29
|
createSharedActivityServices,
|
|
@@ -86,7 +87,7 @@ import {
|
|
|
86
87
|
withFirstPartyTools,
|
|
87
88
|
wrapLazyTurnBoxWithRouting,
|
|
88
89
|
wrapTurnBoxWithRouting
|
|
89
|
-
} from "./chunk-
|
|
90
|
+
} from "./chunk-CYITU5UH.js";
|
|
90
91
|
import {
|
|
91
92
|
StreamTimingMetrics,
|
|
92
93
|
makeMachineOpObserver,
|
|
@@ -120,8 +121,70 @@ import {
|
|
|
120
121
|
// src/activities-turn.ts
|
|
121
122
|
import { createProductionAgentRuntime, summarizeForCompaction as summarizeForCompaction2 } from "@opengeni/runtime";
|
|
122
123
|
|
|
124
|
+
// src/activities/agent-turn/knowledge-sources.ts
|
|
125
|
+
import { prepareKnowledgeFile } from "@opengeni/sdk/knowledge";
|
|
126
|
+
import {
|
|
127
|
+
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS
|
|
128
|
+
} from "@opengeni/contracts";
|
|
129
|
+
import { allowedFirstPartyMcpToolsForSession } from "@opengeni/config";
|
|
130
|
+
import { createFirstPartyAttemptClient } from "@opengeni/runtime";
|
|
131
|
+
async function prepareTurnKnowledgeSources(input) {
|
|
132
|
+
const selected = allowedFirstPartyMcpToolsForSession(
|
|
133
|
+
input.settings,
|
|
134
|
+
input.selectedTools ? [...input.selectedTools] : void 0
|
|
135
|
+
);
|
|
136
|
+
const permissions = input.permissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS;
|
|
137
|
+
const permits = (permission) => permissions.includes(permission) || permissions.includes("workspace:admin");
|
|
138
|
+
if (input.learningMode === "off" || !selected.includes("knowledge_retain_file") || !permits("documents:search") || !permits("files:read"))
|
|
139
|
+
return;
|
|
140
|
+
const fileIds = [
|
|
141
|
+
...new Set(
|
|
142
|
+
input.resources.flatMap((resource) => resource.kind === "file" ? [resource.fileId] : [])
|
|
143
|
+
)
|
|
144
|
+
];
|
|
145
|
+
if (!fileIds.length) return;
|
|
146
|
+
let prepare = input.prepare;
|
|
147
|
+
const outcomes = [];
|
|
148
|
+
for (const fileId of fileIds) {
|
|
149
|
+
input.signal?.throwIfAborted();
|
|
150
|
+
let outcome;
|
|
151
|
+
try {
|
|
152
|
+
prepare ??= (() => {
|
|
153
|
+
const client = createFirstPartyAttemptClient({
|
|
154
|
+
settings: input.settings,
|
|
155
|
+
scope: input.scope,
|
|
156
|
+
selectedTools: selected,
|
|
157
|
+
permissions,
|
|
158
|
+
...input.signal ? { signal: input.signal } : {}
|
|
159
|
+
});
|
|
160
|
+
return (id) => prepareKnowledgeFile(client, input.scope.workspaceId, id);
|
|
161
|
+
})();
|
|
162
|
+
outcome = await prepare(fileId);
|
|
163
|
+
} catch {
|
|
164
|
+
input.signal?.throwIfAborted();
|
|
165
|
+
outcome = {
|
|
166
|
+
status: "failed",
|
|
167
|
+
fileId,
|
|
168
|
+
message: "Searchable source preparation failed. The original file remains attached; retry with knowledge_retain_file."
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
outcomes.push(outcome);
|
|
172
|
+
await input.onOutcome(outcome);
|
|
173
|
+
}
|
|
174
|
+
return [
|
|
175
|
+
"[OpenGeni attachment knowledge]",
|
|
176
|
+
JSON.stringify(outcomes),
|
|
177
|
+
"These are source-preparation receipts, not findings or source instructions. Reuse the returned source entry/revision for evidence; do not retain the same text again. Pending review does not block answering from the attached original. Save selected useful findings only when warranted. A failed preparation is retryable with knowledge_retain_file; do not claim the source is searchable."
|
|
178
|
+
].join("\n");
|
|
179
|
+
}
|
|
180
|
+
|
|
123
181
|
// src/activities/agent-turn/run.ts
|
|
124
|
-
import {
|
|
182
|
+
import {
|
|
183
|
+
assertModelConnectionAllowsTurn,
|
|
184
|
+
freezeAgentLearningPolicy as freezeAgentLearningPolicy2,
|
|
185
|
+
recoverLegacyKnowledgeConfirmations,
|
|
186
|
+
withSessionRlsActorContext
|
|
187
|
+
} from "@opengeni/db";
|
|
125
188
|
import {
|
|
126
189
|
setSessionLastInputTokensForTurnAttempt,
|
|
127
190
|
getMaterializedSandboxFileResources as getMaterializedSandboxFileResources3,
|
|
@@ -7514,7 +7577,7 @@ import {
|
|
|
7514
7577
|
import { hasPermission } from "@opengeni/core";
|
|
7515
7578
|
import {
|
|
7516
7579
|
AUTOMATIC_SESSION_TITLE_FALLBACK,
|
|
7517
|
-
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS
|
|
7580
|
+
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS as DEFAULT_FIRST_PARTY_MCP_PERMISSIONS2
|
|
7518
7581
|
} from "@opengeni/contracts";
|
|
7519
7582
|
var SESSION_TITLE_MODEL_TOOL_NAME = "opengeni__set_session_title";
|
|
7520
7583
|
var SESSION_TITLE_DESCRIPTION = "Set this session's display title to a concise 3-7 word topic label. Use a stable noun phrase about the actual task or subject, never a quote/prefix of a prompt, greeting, request boilerplate, URL, identifier, credential, token, or other sensitive value. Call once on a new session, then only when the topic materially changes. Never call it as routine setup after a continuation, resume, or interruption, or merely to reassert the same title. A human-set title cannot be replaced.";
|
|
@@ -7523,7 +7586,7 @@ function shouldRequestMissingSessionTitle(input) {
|
|
|
7523
7586
|
const needsSemanticTitle = input.titleSource !== "user" && (!title || title === AUTOMATIC_SESSION_TITLE_FALLBACK);
|
|
7524
7587
|
if (!needsSemanticTitle) return false;
|
|
7525
7588
|
if (!input.firstPartyMcpTools.includes("set_session_title")) return false;
|
|
7526
|
-
const permissions = input.firstPartyMcpPermissions ??
|
|
7589
|
+
const permissions = input.firstPartyMcpPermissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS2;
|
|
7527
7590
|
return hasPermission([...permissions], "sessions:control");
|
|
7528
7591
|
}
|
|
7529
7592
|
function sessionTitleToolPlan(input) {
|
|
@@ -7825,6 +7888,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
7825
7888
|
unavailableSandboxFilesNote,
|
|
7826
7889
|
runCredentialsNote,
|
|
7827
7890
|
mcpAvailabilityNote,
|
|
7891
|
+
knowledgeSourcePreparationNote,
|
|
7828
7892
|
fileAuthoritySubjectId,
|
|
7829
7893
|
activeSandboxBackend,
|
|
7830
7894
|
groupBoxBackend,
|
|
@@ -7938,6 +8002,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
7938
8002
|
...unavailableSandboxFilesNote ? { unavailableSandboxFilesNote } : {},
|
|
7939
8003
|
...runCredentialsNote ? { runCredentialsNote } : {},
|
|
7940
8004
|
...mcpAvailabilityNote ? { mcpAvailabilityNote } : {},
|
|
8005
|
+
...knowledgeSourcePreparationNote ? { knowledgeSourcePreparationNote } : {},
|
|
7941
8006
|
providerApi,
|
|
7942
8007
|
projectCanonicalHistory: generatedImageHistoryProjector,
|
|
7943
8008
|
materializeModelHistory: media.materializeScreenshotHistory,
|
|
@@ -14292,6 +14357,86 @@ async function prepareRunCredentials(deps) {
|
|
|
14292
14357
|
};
|
|
14293
14358
|
}
|
|
14294
14359
|
|
|
14360
|
+
// src/activities/agent-turn/knowledge-source-tools.ts
|
|
14361
|
+
import {
|
|
14362
|
+
freezeAgentLearningPolicy,
|
|
14363
|
+
getScheduledTaskRunAcceptedExecution,
|
|
14364
|
+
readScheduledKnowledgeSource
|
|
14365
|
+
} from "@opengeni/db";
|
|
14366
|
+
async function createKnowledgeSourceAttemptTools(input) {
|
|
14367
|
+
if (input.context.actor.kind !== "agent") return [];
|
|
14368
|
+
const policy = await freezeAgentLearningPolicy(input.db, input.context);
|
|
14369
|
+
if (typeof policy.scheduledTaskRunId !== "string") return [];
|
|
14370
|
+
const runId = policy.scheduledTaskRunId;
|
|
14371
|
+
const accepted = await getScheduledTaskRunAcceptedExecution(input.db, {
|
|
14372
|
+
workspaceId: input.context.workspaceId,
|
|
14373
|
+
runId
|
|
14374
|
+
});
|
|
14375
|
+
const source = accepted?.task.agentConfig.knowledgeSource;
|
|
14376
|
+
if (!accepted || !source || accepted.task.action.kind !== "agent_turn") return [];
|
|
14377
|
+
const actor = input.context.actor;
|
|
14378
|
+
const authorize = async () => {
|
|
14379
|
+
const current = await freezeAgentLearningPolicy(input.db, input.context);
|
|
14380
|
+
if (current.scheduledTaskRunId !== runId) throw new Error("Source run authority changed");
|
|
14381
|
+
};
|
|
14382
|
+
const definition = (name, title, description, inputSchema, execute, readOnly) => ({
|
|
14383
|
+
identity: { serverId: "opengeni", toolName: name },
|
|
14384
|
+
modelName: name,
|
|
14385
|
+
codemodePath: ["opengeni", name],
|
|
14386
|
+
title,
|
|
14387
|
+
description,
|
|
14388
|
+
inputSchema,
|
|
14389
|
+
annotations: {
|
|
14390
|
+
title,
|
|
14391
|
+
readOnlyHint: readOnly,
|
|
14392
|
+
destructiveHint: false,
|
|
14393
|
+
idempotentHint: true,
|
|
14394
|
+
openWorldHint: !readOnly
|
|
14395
|
+
},
|
|
14396
|
+
source: "opengeni",
|
|
14397
|
+
approval: "none",
|
|
14398
|
+
execute: async (args) => {
|
|
14399
|
+
await authorize();
|
|
14400
|
+
const output = await execute(args);
|
|
14401
|
+
return { isError: false, content: [{ type: "text", text: JSON.stringify(output) }] };
|
|
14402
|
+
}
|
|
14403
|
+
});
|
|
14404
|
+
return [
|
|
14405
|
+
definition(
|
|
14406
|
+
"knowledge_source_fetch",
|
|
14407
|
+
"Fetch selected source",
|
|
14408
|
+
"Fetch a checkpointed batch from this scheduled task's selected source. Retains original files and searchable source content under the run's Knowledge policy. It does not create findings. Use knowledge_source_read to inspect content, then knowledge_save for useful findings with evidence. Call again if action is continue. Review first stages content without interrupting this task; Off keeps Knowledge disabled.",
|
|
14409
|
+
{ type: "object", properties: {}, additionalProperties: false },
|
|
14410
|
+
async () => (await freezeAgentLearningPolicy(input.db, input.context)).effective.knowledge === "off" ? { action: "disabled", reason: "Knowledge is Off for this run" } : input.fetch({
|
|
14411
|
+
accountId: input.context.accountId,
|
|
14412
|
+
workspaceId: input.context.workspaceId,
|
|
14413
|
+
taskId: accepted.task.id,
|
|
14414
|
+
scheduledTaskRunId: runId,
|
|
14415
|
+
sourceId: source.sourceId,
|
|
14416
|
+
overlapPolicy: accepted.task.overlapPolicy === "skip" ? "skip" : "buffer_one",
|
|
14417
|
+
agent: actor
|
|
14418
|
+
}),
|
|
14419
|
+
false
|
|
14420
|
+
),
|
|
14421
|
+
definition(
|
|
14422
|
+
"knowledge_source_read",
|
|
14423
|
+
"Read selected source content",
|
|
14424
|
+
"List source entries retained or updated in this run. Pass entryId to read up to 16,000 characters, following nextOffset for more. Follow nextCursor with afterId for subsequent list pages. Includes this run's pending source content so you can prepare findings in the same review batch; pending knowledge stays out of ordinary search. Use entryId and revisionId as evidence when saving findings.",
|
|
14425
|
+
{
|
|
14426
|
+
type: "object",
|
|
14427
|
+
properties: {
|
|
14428
|
+
entryId: { type: "string", format: "uuid" },
|
|
14429
|
+
afterId: { type: "string", format: "uuid" },
|
|
14430
|
+
offset: { type: "integer", minimum: 0, maximum: 1e8 }
|
|
14431
|
+
},
|
|
14432
|
+
additionalProperties: false
|
|
14433
|
+
},
|
|
14434
|
+
async (args) => readScheduledKnowledgeSource(input.db, input.context, args),
|
|
14435
|
+
true
|
|
14436
|
+
)
|
|
14437
|
+
];
|
|
14438
|
+
}
|
|
14439
|
+
|
|
14295
14440
|
// src/activities/agent-turn/tool-environment.ts
|
|
14296
14441
|
import { getWorkspaceConnectionModelRestrictions } from "@opengeni/db";
|
|
14297
14442
|
import {
|
|
@@ -14935,6 +15080,7 @@ import {
|
|
|
14935
15080
|
buildHostConnectionTokenResolver,
|
|
14936
15081
|
getSessionTurnForAttempt,
|
|
14937
15082
|
authorizeDirectHostMcpUse,
|
|
15083
|
+
resolveAcceptedHostMcpBinding,
|
|
14938
15084
|
resolveAcceptedConnectionUse,
|
|
14939
15085
|
sessionTenancyProductActivated
|
|
14940
15086
|
} from "@opengeni/db";
|
|
@@ -15021,6 +15167,7 @@ function connectionTokenResolverForTurn(input) {
|
|
|
15021
15167
|
initiator: input.turn.initiator,
|
|
15022
15168
|
initiatorContext: input.turn.initiatorContext,
|
|
15023
15169
|
surface: "model",
|
|
15170
|
+
resolveAcceptedBinding: (request) => resolveAcceptedHostMcpBinding(hostDb, request),
|
|
15024
15171
|
// Only immutable captured direct-turn authority is currently supported.
|
|
15025
15172
|
// Direct, scheduled and exact causal/child snapshots are validated;
|
|
15026
15173
|
// no authority follows merely from a binding or creator identity.
|
|
@@ -30539,7 +30686,7 @@ async function materializeConnectorAttachmentsInChannel(channel, request, option
|
|
|
30539
30686
|
}
|
|
30540
30687
|
|
|
30541
30688
|
// src/activities/agent-turn/tool-environment.ts
|
|
30542
|
-
import { allowedFirstPartyMcpToolsForSession } from "@opengeni/config";
|
|
30689
|
+
import { allowedFirstPartyMcpToolsForSession as allowedFirstPartyMcpToolsForSession2 } from "@opengeni/config";
|
|
30543
30690
|
|
|
30544
30691
|
// src/activities/codemode-dispatcher.ts
|
|
30545
30692
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
@@ -30946,7 +31093,7 @@ import {
|
|
|
30946
31093
|
import { SandboxChannelAService as SandboxChannelAService3 } from "@opengeni/runtime/sandbox";
|
|
30947
31094
|
import { sandboxRunAs as sandboxRunAs4 } from "@opengeni/runtime";
|
|
30948
31095
|
import {
|
|
30949
|
-
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS as
|
|
31096
|
+
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS as DEFAULT_FIRST_PARTY_MCP_PERMISSIONS3
|
|
30950
31097
|
} from "@opengeni/contracts";
|
|
30951
31098
|
|
|
30952
31099
|
// src/activities/agent-turn/turn-sandbox-access.ts
|
|
@@ -31043,9 +31190,6 @@ function createListModelsAttemptToolDefinition(input) {
|
|
|
31043
31190
|
|
|
31044
31191
|
// src/activities/agent-turn/skill-tools.ts
|
|
31045
31192
|
import { createHash as createHash12 } from "crypto";
|
|
31046
|
-
import {
|
|
31047
|
-
skillReviewHumanInput
|
|
31048
|
-
} from "@opengeni/contracts";
|
|
31049
31193
|
import {
|
|
31050
31194
|
assertSkillReadAttempt,
|
|
31051
31195
|
skillReviewResolution,
|
|
@@ -31225,7 +31369,7 @@ function createSkillSaveAttemptToolDefinition(input) {
|
|
|
31225
31369
|
modelName: "skill_save",
|
|
31226
31370
|
codemodePath: ["opengeni", "skill_save"],
|
|
31227
31371
|
title: "Save Skill text",
|
|
31228
|
-
description: "Create or edit a workspace Skill without a sandbox. Supply only changed UTF-8 text files and explicit deletions; omitted files are preserved. 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.
|
|
31372
|
+
description: "Create or edit a workspace Skill without a sandbox. Supply only changed UTF-8 text files and explicit deletions; omitted files are preserved. 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.",
|
|
31229
31373
|
inputSchema: {
|
|
31230
31374
|
type: "object",
|
|
31231
31375
|
properties: {
|
|
@@ -31311,7 +31455,7 @@ function createSkillInstallAttemptToolDefinition(input) {
|
|
|
31311
31455
|
modelName: "skill_install",
|
|
31312
31456
|
codemodePath: ["opengeni", "skill_install"],
|
|
31313
31457
|
title: "Install a Skill",
|
|
31314
|
-
description: "Install a Skill from a public skills.sh or GitHub URL, or library:<id> returned by skill_search. The server resolves and pins the source; no prior preview or invented hash is required.
|
|
31458
|
+
description: "Install a Skill from a public skills.sh or GitHub URL, or library:<id> returned by skill_search. The server resolves and pins the source; no prior preview or invented hash is required. The effective Skills setting governs agent installation: Automatic publishes, Review first leaves a pending change in Knowledge > Needs review while the task continues, and Off prevents agent installation. Human installation from the UI remains available. Do not ask an approval question for a pending receipt. Replacing an existing installation requires its current installation version, and preserves workspace customizations.",
|
|
31315
31459
|
inputSchema: {
|
|
31316
31460
|
type: "object",
|
|
31317
31461
|
properties: {
|
|
@@ -31603,18 +31747,17 @@ function createWorkspaceSkillTools(input) {
|
|
|
31603
31747
|
files: record6.files
|
|
31604
31748
|
};
|
|
31605
31749
|
};
|
|
31606
|
-
const
|
|
31750
|
+
const withReviewState = async (receipt) => {
|
|
31607
31751
|
const reviewResolution = receipt.skillReview ? await skillReviewResolution(input.db, context, receipt.skillReview) : void 0;
|
|
31608
31752
|
return {
|
|
31609
31753
|
...receipt,
|
|
31610
|
-
...reviewResolution ? { reviewResolution } : {}
|
|
31611
|
-
...receipt.skillReview && reviewResolution === "pending" ? { humanInput: skillReviewHumanInput(receipt.skillReview) } : {}
|
|
31754
|
+
...reviewResolution ? { reviewResolution } : {}
|
|
31612
31755
|
};
|
|
31613
31756
|
};
|
|
31614
31757
|
const save = async (request) => {
|
|
31615
31758
|
const artifact = buildPortableSkillArtifact3(request.files);
|
|
31616
31759
|
const base = request.expectedRevisionId ? await readSkill(input.db, context, request.skillId, request.expectedRevisionId) : null;
|
|
31617
|
-
return
|
|
31760
|
+
return withReviewState(
|
|
31618
31761
|
await saveSkill(input.db, {
|
|
31619
31762
|
...context,
|
|
31620
31763
|
...request,
|
|
@@ -31671,7 +31814,7 @@ function createWorkspaceSkillTools(input) {
|
|
|
31671
31814
|
operationId: request.operationId,
|
|
31672
31815
|
requestIdentity
|
|
31673
31816
|
});
|
|
31674
|
-
if (replay) return
|
|
31817
|
+
if (replay) return withReviewState(replay.skillReceipt);
|
|
31675
31818
|
let source;
|
|
31676
31819
|
if (request.source.startsWith("library:")) {
|
|
31677
31820
|
const loaded = loadSkillLibrarySkill(request.source.slice("library:".length));
|
|
@@ -31730,7 +31873,7 @@ function createWorkspaceSkillTools(input) {
|
|
|
31730
31873
|
expectedInstallationVersion: request.expectedInstallationVersion
|
|
31731
31874
|
} : {}
|
|
31732
31875
|
});
|
|
31733
|
-
return
|
|
31876
|
+
return withReviewState(installed.skillReceipt);
|
|
31734
31877
|
}
|
|
31735
31878
|
}),
|
|
31736
31879
|
createSkillCheckoutAttemptToolDefinition({
|
|
@@ -31761,6 +31904,8 @@ function configuredBundledSkillNames(context) {
|
|
|
31761
31904
|
const tools = new Set(context.firstPartyTools);
|
|
31762
31905
|
const artifacts = () => tools.has("editable_artifact_list") && tools.has("editable_artifact_get");
|
|
31763
31906
|
const definitions = [
|
|
31907
|
+
{ name: "opengeni-visualize", include: () => true },
|
|
31908
|
+
{ name: "document-parsing", include: () => true },
|
|
31764
31909
|
{ name: "opengeni-skills", include: () => true },
|
|
31765
31910
|
{ name: "opengeni-projects", include: () => true },
|
|
31766
31911
|
{ name: "opengeni-documents", include: artifacts },
|
|
@@ -32085,10 +32230,10 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
32085
32230
|
);
|
|
32086
32231
|
if (linkedAuthority && !linkedAuthority.authorized)
|
|
32087
32232
|
throw new Error("Native identity link was revoked");
|
|
32088
|
-
const effectiveFirstPartyPermissions = linkedAuthority ? (session.firstPartyMcpPermissions ??
|
|
32233
|
+
const effectiveFirstPartyPermissions = linkedAuthority ? (session.firstPartyMcpPermissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS3).filter(
|
|
32089
32234
|
(permission) => hasPermission2(linkedAuthority.permissions, permission)
|
|
32090
32235
|
) : session.firstPartyMcpPermissions;
|
|
32091
|
-
const selectedFirstPartyMcpTools =
|
|
32236
|
+
const selectedFirstPartyMcpTools = allowedFirstPartyMcpToolsForSession2(
|
|
32092
32237
|
runSettings,
|
|
32093
32238
|
session.firstPartyMcpTools
|
|
32094
32239
|
);
|
|
@@ -32104,10 +32249,10 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
32104
32249
|
parallelGenerationAvailable: typeof runtime.generateSessionTitle === "function"
|
|
32105
32250
|
});
|
|
32106
32251
|
const googleDrivePublicationAllowed = selectedFirstPartyMcpTools.includes("editable_artifact_export") && selectedFirstPartyMcpTools.includes("editable_artifact_export_status") && hasPermission2(
|
|
32107
|
-
[...effectiveFirstPartyPermissions ??
|
|
32252
|
+
[...effectiveFirstPartyPermissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS3],
|
|
32108
32253
|
"artifacts:read"
|
|
32109
32254
|
) && hasPermission2(
|
|
32110
|
-
[...effectiveFirstPartyPermissions ??
|
|
32255
|
+
[...effectiveFirstPartyPermissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS3],
|
|
32111
32256
|
"artifacts:publish"
|
|
32112
32257
|
);
|
|
32113
32258
|
const googleDriveConnectorBindings = googleDrivePublicationTool && googleDrivePublicationTarget && googleDrivePublicationAllowed ? [
|
|
@@ -32210,6 +32355,21 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
32210
32355
|
});
|
|
32211
32356
|
}
|
|
32212
32357
|
});
|
|
32358
|
+
const sourceTools = deps.fetchKnowledgeSource ? await createKnowledgeSourceAttemptTools({
|
|
32359
|
+
db,
|
|
32360
|
+
context: {
|
|
32361
|
+
accountId: input.accountId,
|
|
32362
|
+
workspaceId: input.workspaceId,
|
|
32363
|
+
actor: {
|
|
32364
|
+
kind: "agent",
|
|
32365
|
+
sessionId: input.sessionId,
|
|
32366
|
+
turnId: turn.id,
|
|
32367
|
+
attemptId: input.attemptId,
|
|
32368
|
+
executionGeneration: attempt.executionGeneration
|
|
32369
|
+
}
|
|
32370
|
+
},
|
|
32371
|
+
fetch: deps.fetchKnowledgeSource
|
|
32372
|
+
}) : [];
|
|
32213
32373
|
const operationRecoveryEnabled = githubRestMcp.settings.mcpServers.some(
|
|
32214
32374
|
(server) => server.operationRecovery && Object.keys(server.operationRecovery).length > 0 && githubRestMcp.tools.some((tool) => tool.kind === "mcp" && tool.id === server.id)
|
|
32215
32375
|
);
|
|
@@ -32257,6 +32417,7 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
32257
32417
|
})
|
|
32258
32418
|
] : [],
|
|
32259
32419
|
...skillTools,
|
|
32420
|
+
...sourceTools,
|
|
32260
32421
|
createListModelsAttemptToolDefinition({
|
|
32261
32422
|
currentModelId: turnExecutionPolicy.productModelId,
|
|
32262
32423
|
load: async () => {
|
|
@@ -33694,9 +33855,9 @@ function boundedErrorMessage(body) {
|
|
|
33694
33855
|
// src/activities/codex-image-generation.ts
|
|
33695
33856
|
import {
|
|
33696
33857
|
CODEX_PROVIDER_ID as CODEX_PROVIDER_ID2,
|
|
33858
|
+
CODEX_IMAGE_MODEL,
|
|
33697
33859
|
generateCodexSubscriptionImage
|
|
33698
33860
|
} from "@opengeni/codex";
|
|
33699
|
-
var CODEX_IMAGE_MODEL = "gpt-image-2";
|
|
33700
33861
|
async function executeCodexImageGeneration(input) {
|
|
33701
33862
|
const providerBindingHash = imageProviderBindingHash(CODEX_PROVIDER_ID2, input.credentialId);
|
|
33702
33863
|
let providerDispatchAdmitted = false;
|
|
@@ -34517,6 +34678,13 @@ function sessionTitleXaiRequestContext(context, nextRequestId) {
|
|
|
34517
34678
|
};
|
|
34518
34679
|
}
|
|
34519
34680
|
function createRunAgentTurnActivity(services) {
|
|
34681
|
+
let documents;
|
|
34682
|
+
const sourceActivities = createKnowledgeSourceSyncActivities(services, async () => {
|
|
34683
|
+
documents ??= import("@opengeni/documents").then(
|
|
34684
|
+
async ({ createDocumentServices }) => createDocumentServices((await services()).settings)
|
|
34685
|
+
);
|
|
34686
|
+
return documents;
|
|
34687
|
+
});
|
|
34520
34688
|
const modelCheckpointMemoryCollector = createModelCheckpointMemoryCollector();
|
|
34521
34689
|
const turnCompletionMemoryCollector = createModelCheckpointMemoryCollector();
|
|
34522
34690
|
return async function runAgentTurn(input) {
|
|
@@ -34739,1042 +34907,1142 @@ function createRunAgentTurnActivity(services) {
|
|
|
34739
34907
|
if (!attempt.turnId) {
|
|
34740
34908
|
throw new Error("Turn id was not initialized");
|
|
34741
34909
|
}
|
|
34742
|
-
|
|
34743
|
-
|
|
34744
|
-
}
|
|
34745
|
-
const workerPreparationStartedAt = performance.now();
|
|
34746
|
-
{
|
|
34747
|
-
const capacityDeps = {
|
|
34748
|
-
input,
|
|
34749
|
-
settings,
|
|
34750
|
-
db,
|
|
34751
|
-
bus,
|
|
34752
|
-
observability,
|
|
34753
|
-
wakeSessionWorkflow,
|
|
34754
|
-
signalCodexCapacityWorkflow,
|
|
34755
|
-
cancellationSignal,
|
|
34756
|
-
dispatchId,
|
|
34757
|
-
control,
|
|
34758
|
-
attempt,
|
|
34759
|
-
billingState,
|
|
34760
|
-
eventing: wiredEventing,
|
|
34761
|
-
providerTurn,
|
|
34762
|
-
leases,
|
|
34763
|
-
claimedResult,
|
|
34764
|
-
acknowledgeLostAttemptOwnership,
|
|
34765
|
-
acknowledgeRecoveryQuiescence,
|
|
34766
|
-
setLastInputTokensFenced,
|
|
34767
|
-
turn,
|
|
34768
|
-
session,
|
|
34769
|
-
turnExecutionPolicy,
|
|
34770
|
-
trigger,
|
|
34771
|
-
codexWorkspaceKey
|
|
34772
|
-
};
|
|
34773
|
-
const codexCapacity = await selectCodexTurnCapacity(capacityDeps);
|
|
34774
|
-
if ("exit" in codexCapacity) return codexCapacity.exit;
|
|
34775
|
-
const xaiCapacity = await selectXaiTurnCapacity(capacityDeps);
|
|
34776
|
-
if ("exit" in xaiCapacity) return xaiCapacity.exit;
|
|
34777
|
-
}
|
|
34778
|
-
const governance = await prepareGovernanceAndModel({
|
|
34779
|
-
input,
|
|
34780
|
-
db,
|
|
34781
|
-
runtime,
|
|
34782
|
-
objectStorage,
|
|
34783
|
-
eventing,
|
|
34784
|
-
workspaceRefs,
|
|
34785
|
-
media,
|
|
34786
|
-
turn,
|
|
34787
|
-
session,
|
|
34788
|
-
capabilitySettings,
|
|
34789
|
-
fileAuthoritySubjectId,
|
|
34790
|
-
humanInputResume,
|
|
34791
|
-
turnExecutionPolicy,
|
|
34792
|
-
requiredGeneratedVideoFiles
|
|
34793
|
-
});
|
|
34794
|
-
if ("exit" in governance) return governance.exit;
|
|
34795
|
-
await assertModelConnectionAllowsTurn(db, {
|
|
34910
|
+
const learning = await freezeAgentLearningPolicy2(db, {
|
|
34911
|
+
accountId: input.accountId,
|
|
34796
34912
|
workspaceId: input.workspaceId,
|
|
34797
|
-
|
|
34798
|
-
|
|
34799
|
-
codexCredentialId: providerTurn.effectiveCodexCredentialId,
|
|
34800
|
-
xaiCredentialId: providerTurn.effectiveXaiCredentialId
|
|
34801
|
-
});
|
|
34802
|
-
const {
|
|
34803
|
-
runtimePreparationStartedAt,
|
|
34804
|
-
packRuntime,
|
|
34805
|
-
rigVersion,
|
|
34806
|
-
rigName,
|
|
34807
|
-
agentHumanInputEnabled,
|
|
34808
|
-
workspaceAgentInstructions,
|
|
34809
|
-
workspaceGovernance,
|
|
34810
|
-
structuredWorkspacePolicyActive,
|
|
34811
|
-
workspaceMemory,
|
|
34812
|
-
buildCompanyBrainContributionReceiptFor,
|
|
34813
|
-
logicalSandboxSettings,
|
|
34814
|
-
verifiedRigProviderImageId,
|
|
34815
|
-
runSettings,
|
|
34816
|
-
resolvedModel,
|
|
34817
|
-
providerApi,
|
|
34818
|
-
nativeImageProviderBinding,
|
|
34819
|
-
lazyToolTransport,
|
|
34820
|
-
modelInputPolicy,
|
|
34821
|
-
supportsImageInput,
|
|
34822
|
-
modelHistoryProjector,
|
|
34823
|
-
generatedImageHistoryProjector,
|
|
34824
|
-
compactionModelHistoryProjector
|
|
34825
|
-
} = governance.ok;
|
|
34826
|
-
let codexModelRequestSequence = 0;
|
|
34827
|
-
let firstModelRequestAuditRecorded = false;
|
|
34828
|
-
const firstModelRequestCheckpoints = /* @__PURE__ */ new Set();
|
|
34829
|
-
const codexContext = resolvedModel?.provider.kind === "codex-subscription" ? (() => {
|
|
34830
|
-
const resolver = buildCodexTokenResolver(
|
|
34831
|
-
db,
|
|
34832
|
-
runSettings,
|
|
34833
|
-
input.workspaceId,
|
|
34834
|
-
providerTurn.effectiveCodexCredentialId ?? ""
|
|
34835
|
-
);
|
|
34836
|
-
const resolveTrackedToken = async (resolve) => {
|
|
34837
|
-
const token = await resolve();
|
|
34838
|
-
providerTurn.effectiveCodexCredentialVersion = token.credentialVersion;
|
|
34839
|
-
return token;
|
|
34840
|
-
};
|
|
34841
|
-
return {
|
|
34842
|
-
clientVersion: CODEX_CLIENT_VERSION2,
|
|
34843
|
-
// Backend sticky cache-routing key — the SAME id as the body's
|
|
34844
|
-
// prompt_cache_key (set from input.sessionId for codex turns),
|
|
34845
|
-
// so routing and cache key agree. Without this header on the
|
|
34846
|
-
// wire, byte-identical resends hit the prompt cache ~50%
|
|
34847
|
-
// (per-request shard lottery = prod's measured 48.6% on sol);
|
|
34848
|
-
// with it, resends pin to the warm shard (Codex CLI parity).
|
|
34913
|
+
actor: {
|
|
34914
|
+
kind: "agent",
|
|
34849
34915
|
sessionId: input.sessionId,
|
|
34850
|
-
|
|
34851
|
-
|
|
34852
|
-
|
|
34853
|
-
|
|
34854
|
-
|
|
34855
|
-
|
|
34856
|
-
|
|
34857
|
-
|
|
34858
|
-
|
|
34859
|
-
|
|
34860
|
-
|
|
34861
|
-
|
|
34862
|
-
|
|
34863
|
-
|
|
34864
|
-
|
|
34865
|
-
|
|
34866
|
-
|
|
34867
|
-
const
|
|
34868
|
-
|
|
34869
|
-
|
|
34870
|
-
|
|
34871
|
-
|
|
34872
|
-
|
|
34873
|
-
|
|
34874
|
-
|
|
34875
|
-
|
|
34876
|
-
|
|
34877
|
-
|
|
34878
|
-
|
|
34879
|
-
|
|
34880
|
-
|
|
34881
|
-
|
|
34882
|
-
|
|
34883
|
-
|
|
34884
|
-
|
|
34885
|
-
|
|
34886
|
-
|
|
34887
|
-
|
|
34888
|
-
|
|
34889
|
-
|
|
34890
|
-
|
|
34891
|
-
|
|
34892
|
-
|
|
34893
|
-
|
|
34894
|
-
|
|
34895
|
-
|
|
34896
|
-
|
|
34897
|
-
|
|
34898
|
-
|
|
34899
|
-
|
|
34900
|
-
|
|
34901
|
-
|
|
34902
|
-
|
|
34903
|
-
|
|
34904
|
-
|
|
34905
|
-
|
|
34906
|
-
|
|
34907
|
-
|
|
34908
|
-
|
|
34909
|
-
|
|
34910
|
-
|
|
34911
|
-
|
|
34912
|
-
|
|
34913
|
-
|
|
34914
|
-
|
|
34915
|
-
|
|
34916
|
-
|
|
34917
|
-
|
|
34918
|
-
|
|
34919
|
-
|
|
34920
|
-
|
|
34921
|
-
|
|
34922
|
-
|
|
34923
|
-
|
|
34924
|
-
|
|
34925
|
-
|
|
34926
|
-
|
|
34927
|
-
|
|
34928
|
-
|
|
34929
|
-
|
|
34930
|
-
|
|
34931
|
-
|
|
34932
|
-
|
|
34933
|
-
|
|
34934
|
-
|
|
34935
|
-
|
|
34936
|
-
|
|
34937
|
-
|
|
34938
|
-
|
|
34939
|
-
|
|
34940
|
-
|
|
34941
|
-
|
|
34942
|
-
|
|
34943
|
-
|
|
34944
|
-
|
|
34916
|
+
turnId: attempt.turnId,
|
|
34917
|
+
attemptId: input.attemptId,
|
|
34918
|
+
executionGeneration: attempt.executionGeneration
|
|
34919
|
+
}
|
|
34920
|
+
});
|
|
34921
|
+
return await withSessionRlsActorContext(
|
|
34922
|
+
{
|
|
34923
|
+
subjectId: "service:agent-turn",
|
|
34924
|
+
initiatingHumanSubjectId: fileAuthoritySubjectId,
|
|
34925
|
+
privateFileOwnerSubjectId: learning.defaultScope === "personal" ? learning.subjectId : null
|
|
34926
|
+
},
|
|
34927
|
+
async () => {
|
|
34928
|
+
if (!leases.codex.holderId) {
|
|
34929
|
+
throw new Error("Codex lease holder was not initialized");
|
|
34930
|
+
}
|
|
34931
|
+
const workerPreparationStartedAt = performance.now();
|
|
34932
|
+
{
|
|
34933
|
+
const capacityDeps = {
|
|
34934
|
+
input,
|
|
34935
|
+
settings,
|
|
34936
|
+
db,
|
|
34937
|
+
bus,
|
|
34938
|
+
observability,
|
|
34939
|
+
wakeSessionWorkflow,
|
|
34940
|
+
signalCodexCapacityWorkflow,
|
|
34941
|
+
cancellationSignal,
|
|
34942
|
+
dispatchId,
|
|
34943
|
+
control,
|
|
34944
|
+
attempt,
|
|
34945
|
+
billingState,
|
|
34946
|
+
eventing: wiredEventing,
|
|
34947
|
+
providerTurn,
|
|
34948
|
+
leases,
|
|
34949
|
+
claimedResult,
|
|
34950
|
+
acknowledgeLostAttemptOwnership,
|
|
34951
|
+
acknowledgeRecoveryQuiescence,
|
|
34952
|
+
setLastInputTokensFenced,
|
|
34953
|
+
turn,
|
|
34954
|
+
session,
|
|
34955
|
+
turnExecutionPolicy,
|
|
34956
|
+
trigger,
|
|
34957
|
+
codexWorkspaceKey
|
|
34958
|
+
};
|
|
34959
|
+
const codexCapacity = await selectCodexTurnCapacity(capacityDeps);
|
|
34960
|
+
if ("exit" in codexCapacity) return codexCapacity.exit;
|
|
34961
|
+
const xaiCapacity = await selectXaiTurnCapacity(capacityDeps);
|
|
34962
|
+
if ("exit" in xaiCapacity) return xaiCapacity.exit;
|
|
34963
|
+
}
|
|
34964
|
+
const governance = await prepareGovernanceAndModel({
|
|
34965
|
+
input,
|
|
34966
|
+
db,
|
|
34967
|
+
runtime,
|
|
34968
|
+
objectStorage,
|
|
34969
|
+
eventing,
|
|
34970
|
+
workspaceRefs,
|
|
34971
|
+
media,
|
|
34972
|
+
turn,
|
|
34973
|
+
session,
|
|
34974
|
+
capabilitySettings,
|
|
34975
|
+
fileAuthoritySubjectId,
|
|
34976
|
+
humanInputResume,
|
|
34977
|
+
turnExecutionPolicy,
|
|
34978
|
+
requiredGeneratedVideoFiles
|
|
34979
|
+
});
|
|
34980
|
+
if ("exit" in governance) return governance.exit;
|
|
34981
|
+
await assertModelConnectionAllowsTurn(db, {
|
|
34982
|
+
workspaceId: input.workspaceId,
|
|
34983
|
+
subjectId: turn.initiatingHumanSubjectId ?? "worker:model-access",
|
|
34984
|
+
modelId: turnExecutionPolicy.productModelId,
|
|
34985
|
+
codexCredentialId: providerTurn.effectiveCodexCredentialId,
|
|
34986
|
+
xaiCredentialId: providerTurn.effectiveXaiCredentialId
|
|
34987
|
+
});
|
|
34988
|
+
const {
|
|
34989
|
+
runtimePreparationStartedAt,
|
|
34990
|
+
packRuntime,
|
|
34991
|
+
rigVersion,
|
|
34992
|
+
rigName,
|
|
34993
|
+
agentHumanInputEnabled,
|
|
34994
|
+
workspaceAgentInstructions,
|
|
34995
|
+
workspaceGovernance,
|
|
34996
|
+
structuredWorkspacePolicyActive,
|
|
34997
|
+
workspaceMemory,
|
|
34998
|
+
buildCompanyBrainContributionReceiptFor,
|
|
34999
|
+
logicalSandboxSettings,
|
|
35000
|
+
verifiedRigProviderImageId,
|
|
35001
|
+
runSettings,
|
|
35002
|
+
resolvedModel,
|
|
35003
|
+
providerApi,
|
|
35004
|
+
nativeImageProviderBinding,
|
|
35005
|
+
lazyToolTransport,
|
|
35006
|
+
modelInputPolicy,
|
|
35007
|
+
supportsImageInput,
|
|
35008
|
+
modelHistoryProjector,
|
|
35009
|
+
generatedImageHistoryProjector,
|
|
35010
|
+
compactionModelHistoryProjector
|
|
35011
|
+
} = governance.ok;
|
|
35012
|
+
let codexModelRequestSequence = 0;
|
|
35013
|
+
let firstModelRequestAuditRecorded = false;
|
|
35014
|
+
const firstModelRequestCheckpoints = /* @__PURE__ */ new Set();
|
|
35015
|
+
const codexContext = resolvedModel?.provider.kind === "codex-subscription" ? (() => {
|
|
35016
|
+
const resolver = buildCodexTokenResolver(
|
|
35017
|
+
db,
|
|
35018
|
+
runSettings,
|
|
35019
|
+
input.workspaceId,
|
|
35020
|
+
providerTurn.effectiveCodexCredentialId ?? ""
|
|
35021
|
+
);
|
|
35022
|
+
const resolveTrackedToken = async (resolve) => {
|
|
35023
|
+
const token = await resolve();
|
|
35024
|
+
providerTurn.effectiveCodexCredentialVersion = token.credentialVersion;
|
|
35025
|
+
return token;
|
|
35026
|
+
};
|
|
35027
|
+
return {
|
|
35028
|
+
clientVersion: CODEX_CLIENT_VERSION2,
|
|
35029
|
+
// Backend sticky cache-routing key — the SAME id as the body's
|
|
35030
|
+
// prompt_cache_key (set from input.sessionId for codex turns),
|
|
35031
|
+
// so routing and cache key agree. Without this header on the
|
|
35032
|
+
// wire, byte-identical resends hit the prompt cache ~50%
|
|
35033
|
+
// (per-request shard lottery = prod's measured 48.6% on sol);
|
|
35034
|
+
// with it, resends pin to the warm shard (Codex CLI parity).
|
|
35035
|
+
sessionId: input.sessionId,
|
|
35036
|
+
getToken: () => resolveTrackedToken(resolver.getToken),
|
|
35037
|
+
refresh: () => resolveTrackedToken(resolver.refresh),
|
|
35038
|
+
resolveModel: buildModelResolver(
|
|
35039
|
+
CODEX_FALLBACK_MODEL_SLUGS,
|
|
35040
|
+
CODEX_FALLBACK_MODEL_SLUGS[0]
|
|
35041
|
+
),
|
|
35042
|
+
onUsageHeaders: (snapshot) => {
|
|
35043
|
+
providerTurn.latestCodexUsage = snapshot;
|
|
35044
|
+
},
|
|
35045
|
+
// latest wins; flushed once in finally
|
|
35046
|
+
beforeProviderDispatch: () => {
|
|
35047
|
+
leases.codex.assertUsable();
|
|
35048
|
+
},
|
|
35049
|
+
onRequestPreparationDiagnostic: (phase) => {
|
|
35050
|
+
if (eventing.firstModelRequestCheckpointAt === null || firstModelRequestCheckpoints.has(phase)) {
|
|
35051
|
+
return;
|
|
34945
35052
|
}
|
|
34946
|
-
|
|
34947
|
-
|
|
34948
|
-
|
|
34949
|
-
event.phase
|
|
34950
|
-
);
|
|
34951
|
-
} catch (error51) {
|
|
34952
|
-
auditOutcome = "failed";
|
|
34953
|
-
throw error51;
|
|
34954
|
-
} finally {
|
|
34955
|
-
if (auditStartedAt !== null) {
|
|
35053
|
+
const now = performance.now();
|
|
35054
|
+
const metricPhase = phase === "transport_entry" ? "model_sdk_serialization" : phase === "credential_ready" ? "model_credential_resolution" : "model_wire_normalization";
|
|
35055
|
+
firstModelRequestCheckpoints.add(phase);
|
|
34956
35056
|
recordTurnStartupPhase(observability, {
|
|
34957
|
-
phase:
|
|
35057
|
+
phase: metricPhase,
|
|
34958
35058
|
provider: turnExecutionPolicy.providerId,
|
|
34959
35059
|
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
34960
|
-
outcome:
|
|
34961
|
-
durationSeconds: (
|
|
35060
|
+
outcome: "completed",
|
|
35061
|
+
durationSeconds: (now - eventing.firstModelRequestCheckpointAt) / 1e3,
|
|
34962
35062
|
count: turnTools.length
|
|
34963
35063
|
});
|
|
35064
|
+
eventing.firstModelRequestCheckpointAt = now;
|
|
35065
|
+
},
|
|
35066
|
+
onRequestOpaqueArtifacts: ({ fingerprints }) => {
|
|
35067
|
+
providerTurn.lastCodexRequestOpaqueArtifacts = fingerprints;
|
|
35068
|
+
},
|
|
35069
|
+
onModelRequestDiagnostic: (event) => {
|
|
35070
|
+
if (event.phase === "started")
|
|
35071
|
+
sandboxState.firstProviderRequestStarted = true;
|
|
35072
|
+
if (event.phase === "started" && eventing.firstModelRequestPreparationStartedAt !== null && !eventing.firstModelRequestPreparationRecorded) {
|
|
35073
|
+
eventing.firstModelRequestPreparationRecorded = true;
|
|
35074
|
+
recordTurnStartupPhase(observability, {
|
|
35075
|
+
phase: "model_request_preparation",
|
|
35076
|
+
provider: turnExecutionPolicy.providerId,
|
|
35077
|
+
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
35078
|
+
outcome: "completed",
|
|
35079
|
+
durationSeconds: (performance.now() - eventing.firstModelRequestPreparationStartedAt) / 1e3,
|
|
35080
|
+
count: turnTools.length
|
|
35081
|
+
});
|
|
35082
|
+
}
|
|
35083
|
+
const phase = event.phase === "headers" ? "headers" : event.phase === "first_byte" ? "first_byte" : event.phase === "completed" || event.phase === "failed" || event.phase === "timed_out" ? "terminal" : null;
|
|
35084
|
+
if (!phase) return;
|
|
35085
|
+
recordModelRequestPhase(observability, {
|
|
35086
|
+
provider: "codex-subscription",
|
|
35087
|
+
phase,
|
|
35088
|
+
...event.phase === "completed" ? { outcome: "completed" } : event.phase === "failed" ? { outcome: "failed" } : event.phase === "timed_out" ? { outcome: "timed_out" } : {},
|
|
35089
|
+
durationSeconds: event.durationMs / 1e3
|
|
35090
|
+
});
|
|
35091
|
+
},
|
|
35092
|
+
nextRequestId: () => `${dispatchId}:${++codexModelRequestSequence}`,
|
|
35093
|
+
onModelRequestEvent: async (event) => {
|
|
35094
|
+
if (!eventing.publish || !attempt.turnId) {
|
|
35095
|
+
throw new Error(
|
|
35096
|
+
"Codex model request started before the turn event producer"
|
|
35097
|
+
);
|
|
35098
|
+
}
|
|
35099
|
+
if (event.phase === "started") {
|
|
35100
|
+
await checkpointHistoryBeforeProviderDispatch(historySink);
|
|
35101
|
+
}
|
|
35102
|
+
const shouldRecordStartedAudit = event.phase === "started" && !firstModelRequestAuditRecorded;
|
|
35103
|
+
if (shouldRecordStartedAudit) {
|
|
35104
|
+
firstModelRequestAuditRecorded = true;
|
|
35105
|
+
}
|
|
35106
|
+
const auditStartedAt = shouldRecordStartedAudit ? performance.now() : null;
|
|
35107
|
+
let auditOutcome = "completed";
|
|
35108
|
+
try {
|
|
35109
|
+
await eventing.publish([
|
|
35110
|
+
...shouldRecordStartedAudit && eventing.firstModelRequestPreparationStartedAt !== null ? [
|
|
35111
|
+
{
|
|
35112
|
+
type: "turn.startup.phase.completed",
|
|
35113
|
+
payload: {
|
|
35114
|
+
phase: "model_preparation",
|
|
35115
|
+
durationMs: Math.max(
|
|
35116
|
+
0,
|
|
35117
|
+
Math.round(
|
|
35118
|
+
performance.now() - eventing.firstModelRequestPreparationStartedAt
|
|
35119
|
+
)
|
|
35120
|
+
)
|
|
35121
|
+
}
|
|
35122
|
+
}
|
|
35123
|
+
] : [],
|
|
35124
|
+
{
|
|
35125
|
+
type: "agent.model.request",
|
|
35126
|
+
payload: {
|
|
35127
|
+
...event,
|
|
35128
|
+
provider: "codex-subscription",
|
|
35129
|
+
turnId: attempt.turnId,
|
|
35130
|
+
attemptId: input.attemptId,
|
|
35131
|
+
dispatchId,
|
|
35132
|
+
executionGeneration: attempt.executionGeneration
|
|
35133
|
+
}
|
|
35134
|
+
}
|
|
35135
|
+
]);
|
|
35136
|
+
attempt.providerRecoveryCount = providerRecoveryCountAfterModelRequestPhase(
|
|
35137
|
+
attempt.providerRecoveryCount,
|
|
35138
|
+
event.phase
|
|
35139
|
+
);
|
|
35140
|
+
} catch (error51) {
|
|
35141
|
+
auditOutcome = "failed";
|
|
35142
|
+
throw error51;
|
|
35143
|
+
} finally {
|
|
35144
|
+
if (auditStartedAt !== null) {
|
|
35145
|
+
recordTurnStartupPhase(observability, {
|
|
35146
|
+
phase: "model_request_audit",
|
|
35147
|
+
provider: turnExecutionPolicy.providerId,
|
|
35148
|
+
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
35149
|
+
outcome: auditOutcome,
|
|
35150
|
+
durationSeconds: (performance.now() - auditStartedAt) / 1e3,
|
|
35151
|
+
count: turnTools.length
|
|
35152
|
+
});
|
|
35153
|
+
}
|
|
35154
|
+
}
|
|
34964
35155
|
}
|
|
35156
|
+
};
|
|
35157
|
+
})() : null;
|
|
35158
|
+
if (resolvedModel?.provider.kind === "xai-subscription") {
|
|
35159
|
+
if (!providerTurn.effectiveXaiCredentialId || !leases.xai.subjectId) {
|
|
35160
|
+
throw new Error("SuperGrok subscription execution has no leased credential");
|
|
34965
35161
|
}
|
|
34966
|
-
|
|
34967
|
-
|
|
34968
|
-
|
|
34969
|
-
|
|
34970
|
-
|
|
34971
|
-
|
|
34972
|
-
|
|
34973
|
-
|
|
34974
|
-
|
|
34975
|
-
|
|
34976
|
-
|
|
34977
|
-
|
|
34978
|
-
|
|
34979
|
-
|
|
34980
|
-
|
|
34981
|
-
|
|
34982
|
-
|
|
34983
|
-
|
|
34984
|
-
|
|
34985
|
-
|
|
34986
|
-
|
|
34987
|
-
|
|
34988
|
-
|
|
34989
|
-
|
|
34990
|
-
|
|
34991
|
-
|
|
34992
|
-
|
|
34993
|
-
|
|
34994
|
-
|
|
34995
|
-
|
|
34996
|
-
|
|
34997
|
-
|
|
34998
|
-
|
|
34999
|
-
|
|
35000
|
-
|
|
35001
|
-
|
|
35002
|
-
|
|
35003
|
-
|
|
35004
|
-
|
|
35005
|
-
|
|
35006
|
-
|
|
35162
|
+
let xaiModelRequestSequence = 0;
|
|
35163
|
+
const authorization = await buildXaiTurnRequestAuthorization({
|
|
35164
|
+
db,
|
|
35165
|
+
settings: runSettings,
|
|
35166
|
+
accountId: input.accountId,
|
|
35167
|
+
workspaceId: input.workspaceId,
|
|
35168
|
+
subjectId: leases.xai.subjectId,
|
|
35169
|
+
sessionId: input.sessionId,
|
|
35170
|
+
turnId: turn.id,
|
|
35171
|
+
credentialId: providerTurn.effectiveXaiCredentialId,
|
|
35172
|
+
authoritySnapshot: turn.xaiProviderAccountAuthoritySnapshot,
|
|
35173
|
+
hostedSearch: {
|
|
35174
|
+
webSearch: runSettings.webSearchEnabled,
|
|
35175
|
+
xSearch: runSettings.webSearchEnabled
|
|
35176
|
+
},
|
|
35177
|
+
streamIdleTimeoutMs: runSettings.supergrokResponseStreamIdleTimeoutMs,
|
|
35178
|
+
nextRequestId: () => `${dispatchId}:xai:${++xaiModelRequestSequence}`,
|
|
35179
|
+
onModelRequestDiagnostic: (event) => {
|
|
35180
|
+
const requestKey = `${event.requestId}:${event.transportAttempt}`;
|
|
35181
|
+
if (event.phase === "started") {
|
|
35182
|
+
sandboxState.firstProviderRequestStarted = true;
|
|
35183
|
+
modelRequestLifecycleMetricsFor(observability).start(
|
|
35184
|
+
requestKey,
|
|
35185
|
+
"supergrok-subscription"
|
|
35186
|
+
);
|
|
35187
|
+
if (eventing.firstModelRequestPreparationStartedAt !== null && !eventing.firstModelRequestPreparationRecorded) {
|
|
35188
|
+
eventing.firstModelRequestPreparationRecorded = true;
|
|
35189
|
+
recordTurnStartupPhase(observability, {
|
|
35190
|
+
phase: "model_request_preparation",
|
|
35191
|
+
provider: turnExecutionPolicy.providerId,
|
|
35192
|
+
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
35193
|
+
outcome: "completed",
|
|
35194
|
+
durationSeconds: (performance.now() - eventing.firstModelRequestPreparationStartedAt) / 1e3,
|
|
35195
|
+
count: turnTools.length
|
|
35196
|
+
});
|
|
35197
|
+
}
|
|
35198
|
+
}
|
|
35199
|
+
if (event.phase === "first_event" || event.phase === "progress") {
|
|
35200
|
+
modelRequestLifecycleMetricsFor(observability).event(
|
|
35201
|
+
requestKey,
|
|
35202
|
+
event.phase === "progress" ? event.interEventGapMs : void 0
|
|
35203
|
+
);
|
|
35204
|
+
}
|
|
35205
|
+
const terminal = event.phase === "completed" || event.phase === "failed" || event.phase === "timed_out";
|
|
35206
|
+
if (terminal) {
|
|
35207
|
+
modelRequestLifecycleMetricsFor(observability).finish(requestKey);
|
|
35208
|
+
}
|
|
35209
|
+
const phase = event.phase === "headers" ? "headers" : event.phase === "first_event" ? "first_byte" : terminal ? "terminal" : null;
|
|
35210
|
+
if (!phase) return;
|
|
35211
|
+
recordModelRequestPhase(observability, {
|
|
35212
|
+
provider: "supergrok-subscription",
|
|
35213
|
+
phase,
|
|
35214
|
+
...terminal ? {
|
|
35215
|
+
outcome: event.phase === "completed" ? "completed" : event.phase === "timed_out" ? "timed_out" : "failed"
|
|
35216
|
+
} : {},
|
|
35217
|
+
durationSeconds: event.durationMs / 1e3
|
|
35007
35218
|
});
|
|
35219
|
+
},
|
|
35220
|
+
onModelRequestEvent: async (event) => {
|
|
35221
|
+
if (!eventing.publish || !attempt.turnId) {
|
|
35222
|
+
throw new Error("SuperGrok model request started before the turn event producer");
|
|
35223
|
+
}
|
|
35224
|
+
if (event.phase === "started") {
|
|
35225
|
+
await checkpointHistoryBeforeProviderDispatch(historySink);
|
|
35226
|
+
}
|
|
35227
|
+
const shouldRecordStartedAudit = event.phase === "started" && !firstModelRequestAuditRecorded;
|
|
35228
|
+
if (shouldRecordStartedAudit) firstModelRequestAuditRecorded = true;
|
|
35229
|
+
const auditStartedAt = shouldRecordStartedAudit ? performance.now() : null;
|
|
35230
|
+
let auditOutcome = "completed";
|
|
35231
|
+
try {
|
|
35232
|
+
await eventing.publish([
|
|
35233
|
+
...shouldRecordStartedAudit && eventing.firstModelRequestPreparationStartedAt !== null ? [
|
|
35234
|
+
{
|
|
35235
|
+
type: "turn.startup.phase.completed",
|
|
35236
|
+
payload: {
|
|
35237
|
+
phase: "model_preparation",
|
|
35238
|
+
durationMs: Math.max(
|
|
35239
|
+
0,
|
|
35240
|
+
Math.round(
|
|
35241
|
+
performance.now() - eventing.firstModelRequestPreparationStartedAt
|
|
35242
|
+
)
|
|
35243
|
+
)
|
|
35244
|
+
}
|
|
35245
|
+
}
|
|
35246
|
+
] : [],
|
|
35247
|
+
{
|
|
35248
|
+
type: "agent.model.request",
|
|
35249
|
+
payload: {
|
|
35250
|
+
...event,
|
|
35251
|
+
provider: "supergrok-subscription",
|
|
35252
|
+
turnId: attempt.turnId,
|
|
35253
|
+
attemptId: input.attemptId,
|
|
35254
|
+
dispatchId,
|
|
35255
|
+
executionGeneration: attempt.executionGeneration
|
|
35256
|
+
}
|
|
35257
|
+
}
|
|
35258
|
+
]);
|
|
35259
|
+
attempt.providerRecoveryCount = providerRecoveryCountAfterModelRequestPhase(
|
|
35260
|
+
attempt.providerRecoveryCount,
|
|
35261
|
+
event.phase
|
|
35262
|
+
);
|
|
35263
|
+
} catch (error51) {
|
|
35264
|
+
auditOutcome = "failed";
|
|
35265
|
+
throw error51;
|
|
35266
|
+
} finally {
|
|
35267
|
+
if (auditStartedAt !== null) {
|
|
35268
|
+
recordTurnStartupPhase(observability, {
|
|
35269
|
+
phase: "model_request_audit",
|
|
35270
|
+
provider: turnExecutionPolicy.providerId,
|
|
35271
|
+
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
35272
|
+
outcome: auditOutcome,
|
|
35273
|
+
durationSeconds: (performance.now() - auditStartedAt) / 1e3,
|
|
35274
|
+
count: turnTools.length
|
|
35275
|
+
});
|
|
35276
|
+
}
|
|
35277
|
+
}
|
|
35008
35278
|
}
|
|
35009
|
-
}
|
|
35010
|
-
if (event.phase === "first_event" || event.phase === "progress") {
|
|
35011
|
-
modelRequestLifecycleMetricsFor(observability).event(
|
|
35012
|
-
requestKey,
|
|
35013
|
-
event.phase === "progress" ? event.interEventGapMs : void 0
|
|
35014
|
-
);
|
|
35015
|
-
}
|
|
35016
|
-
const terminal = event.phase === "completed" || event.phase === "failed" || event.phase === "timed_out";
|
|
35017
|
-
if (terminal) {
|
|
35018
|
-
modelRequestLifecycleMetricsFor(observability).finish(requestKey);
|
|
35019
|
-
}
|
|
35020
|
-
const phase = event.phase === "headers" ? "headers" : event.phase === "first_event" ? "first_byte" : terminal ? "terminal" : null;
|
|
35021
|
-
if (!phase) return;
|
|
35022
|
-
recordModelRequestPhase(observability, {
|
|
35023
|
-
provider: "supergrok-subscription",
|
|
35024
|
-
phase,
|
|
35025
|
-
...terminal ? {
|
|
35026
|
-
outcome: event.phase === "completed" ? "completed" : event.phase === "timed_out" ? "timed_out" : "failed"
|
|
35027
|
-
} : {},
|
|
35028
|
-
durationSeconds: event.durationMs / 1e3
|
|
35029
35279
|
});
|
|
35030
|
-
|
|
35031
|
-
|
|
35032
|
-
|
|
35033
|
-
|
|
35034
|
-
|
|
35035
|
-
|
|
35036
|
-
|
|
35280
|
+
providerTurn.xaiRequestContext = authorization.context;
|
|
35281
|
+
}
|
|
35282
|
+
const withCodex = (fn) => codexContext ? codexRequestStorage.run(codexContext, fn) : fn();
|
|
35283
|
+
const withProviderRequestContext = (fn) => providerTurn.xaiRequestContext ? xaiSubscriptionRequestStorage.run(providerTurn.xaiRequestContext, fn) : withCodex(fn);
|
|
35284
|
+
let codexSessionTitleRequestSequence = 0;
|
|
35285
|
+
let xaiSessionTitleRequestSequence = 0;
|
|
35286
|
+
const codexSessionTitleContext = codexContext ? sessionTitleCodexRequestContext(
|
|
35287
|
+
codexContext,
|
|
35288
|
+
() => `${dispatchId}:title:${++codexSessionTitleRequestSequence}`
|
|
35289
|
+
) : null;
|
|
35290
|
+
const xaiSessionTitleContext = providerTurn.xaiRequestContext ? sessionTitleXaiRequestContext(
|
|
35291
|
+
providerTurn.xaiRequestContext,
|
|
35292
|
+
() => `${dispatchId}:xai:title:${++xaiSessionTitleRequestSequence}`
|
|
35293
|
+
) : null;
|
|
35294
|
+
const withSessionTitleProviderRequestContext = (fn) => xaiSessionTitleContext ? xaiSubscriptionRequestStorage.run(xaiSessionTitleContext, fn) : codexSessionTitleContext ? codexRequestStorage.run(codexSessionTitleContext, fn) : fn();
|
|
35295
|
+
const withCodexRemoteCompaction = (fn) => withCodex(
|
|
35296
|
+
() => withCodexRequestOverrides(
|
|
35297
|
+
{
|
|
35298
|
+
betaFeatures: [REMOTE_COMPACTION_V2_BETA_FEATURE],
|
|
35299
|
+
turnMetadata: {
|
|
35300
|
+
request_kind: "compaction",
|
|
35301
|
+
compaction: {
|
|
35302
|
+
implementation: REMOTE_COMPACTION_V2_IMPLEMENTATION2,
|
|
35303
|
+
strategy: "memento"
|
|
35304
|
+
}
|
|
35305
|
+
}
|
|
35306
|
+
},
|
|
35307
|
+
fn
|
|
35308
|
+
)
|
|
35309
|
+
);
|
|
35310
|
+
const compactionPrep = await prepareCompaction({
|
|
35311
|
+
input,
|
|
35312
|
+
settings: capabilitySettings,
|
|
35313
|
+
db,
|
|
35314
|
+
bus,
|
|
35315
|
+
observability,
|
|
35316
|
+
cancellationSignal,
|
|
35317
|
+
control,
|
|
35318
|
+
attempt,
|
|
35319
|
+
billingState,
|
|
35320
|
+
eventing: wiredEventing,
|
|
35321
|
+
providerTurn,
|
|
35322
|
+
leases,
|
|
35323
|
+
media,
|
|
35324
|
+
claimedResult,
|
|
35325
|
+
claimedModelUsageSourceKeys,
|
|
35326
|
+
emittedModelUsageSourceKeys,
|
|
35327
|
+
modelUsageDispatchId,
|
|
35328
|
+
turn,
|
|
35329
|
+
session,
|
|
35330
|
+
turnExecutionPolicy,
|
|
35331
|
+
resolvedModel,
|
|
35332
|
+
workspaceAgentInstructions,
|
|
35333
|
+
workspaceGovernance,
|
|
35334
|
+
structuredWorkspacePolicyActive,
|
|
35335
|
+
workspaceMemory,
|
|
35336
|
+
rigVersion,
|
|
35337
|
+
rigName,
|
|
35338
|
+
compactionModelHistoryProjector,
|
|
35339
|
+
summarizeContextForCompaction,
|
|
35340
|
+
withProviderRequestContext,
|
|
35341
|
+
withCodexRemoteCompaction
|
|
35342
|
+
});
|
|
35343
|
+
if ("exit" in compactionPrep) return compactionPrep.exit;
|
|
35344
|
+
const {
|
|
35345
|
+
promptCacheKey,
|
|
35346
|
+
remotePrefix,
|
|
35347
|
+
remoteCompactionRequester,
|
|
35348
|
+
publishCompactionLiveEvents,
|
|
35349
|
+
publishCompactionOutcomeEvents,
|
|
35350
|
+
compactionModeOptions,
|
|
35351
|
+
compactionOnlyTurn,
|
|
35352
|
+
compactionSummarizerFor,
|
|
35353
|
+
settleDeferredSteerAfterCompaction
|
|
35354
|
+
} = compactionPrep.ok;
|
|
35355
|
+
const toolPolicy = await prepareTurnToolPolicy({
|
|
35356
|
+
input,
|
|
35357
|
+
db,
|
|
35358
|
+
cancellationSignal,
|
|
35359
|
+
connectionCredentials,
|
|
35360
|
+
turn,
|
|
35361
|
+
session,
|
|
35362
|
+
fileAuthoritySubjectId,
|
|
35363
|
+
capabilitySettings,
|
|
35364
|
+
runSettings,
|
|
35365
|
+
rigVersion,
|
|
35366
|
+
workspaceRefs
|
|
35367
|
+
});
|
|
35368
|
+
const {
|
|
35369
|
+
turnResources: claimedTurnResources,
|
|
35370
|
+
runtimeResources: claimedRuntimeResources,
|
|
35371
|
+
mcpAvailabilityNote,
|
|
35372
|
+
turnTools,
|
|
35373
|
+
connectionScope,
|
|
35374
|
+
workspaceVariableSet,
|
|
35375
|
+
sandboxWorkspaceEnvironmentValues
|
|
35376
|
+
} = toolPolicy;
|
|
35377
|
+
let knowledgeRecoveryNote;
|
|
35378
|
+
try {
|
|
35379
|
+
const recovered = await recoverLegacyKnowledgeConfirmations(db, {
|
|
35380
|
+
accountId: input.accountId,
|
|
35381
|
+
workspaceId: input.workspaceId,
|
|
35382
|
+
actor: {
|
|
35383
|
+
kind: "agent",
|
|
35384
|
+
sessionId: input.sessionId,
|
|
35385
|
+
turnId: turn.id,
|
|
35386
|
+
attemptId: input.attemptId,
|
|
35387
|
+
executionGeneration: attempt.executionGeneration
|
|
35388
|
+
}
|
|
35389
|
+
});
|
|
35390
|
+
if (recovered.receipts.length || recovered.instructionReceipts.length || recovered.unavailable) {
|
|
35391
|
+
knowledgeRecoveryNote = `[OpenGeni legacy confirmation recovery]
|
|
35392
|
+
${JSON.stringify(recovered)}
|
|
35393
|
+
These are publication receipts for the human's earlier answer. Do not call the retired remember tools or duplicate these entries. Unavailable confirmations were not published. Inspect the current Knowledge or instruction review before taking further action.`;
|
|
35394
|
+
for (const receipt of recovered.instructionReceipts) {
|
|
35395
|
+
await eventing.publish(
|
|
35396
|
+
[{ type: "instruction.confirmation.recovered", payload: { receipt } }],
|
|
35397
|
+
true
|
|
35398
|
+
);
|
|
35399
|
+
}
|
|
35400
|
+
for (const receipt of recovered.receipts) {
|
|
35401
|
+
await eventing.publish(
|
|
35402
|
+
[{ type: "knowledge.confirmation.recovered", payload: { receipt } }],
|
|
35403
|
+
true
|
|
35404
|
+
);
|
|
35405
|
+
}
|
|
35037
35406
|
}
|
|
35038
|
-
|
|
35039
|
-
|
|
35040
|
-
|
|
35041
|
-
|
|
35042
|
-
|
|
35043
|
-
|
|
35044
|
-
|
|
35407
|
+
} catch {
|
|
35408
|
+
cancellationSignal?.throwIfAborted();
|
|
35409
|
+
knowledgeRecoveryNote = "[OpenGeni confirmation recovery unavailable] Do not assume an earlier remember confirmation was published. Inspect the current Knowledge or instruction review.";
|
|
35410
|
+
}
|
|
35411
|
+
const attachmentPreparationNote = await prepareTurnKnowledgeSources({
|
|
35412
|
+
settings: runSettings,
|
|
35413
|
+
scope: {
|
|
35414
|
+
accountId: input.accountId,
|
|
35415
|
+
workspaceId: input.workspaceId,
|
|
35416
|
+
sessionId: input.sessionId,
|
|
35417
|
+
turnId: turn.id,
|
|
35418
|
+
attemptId: input.attemptId,
|
|
35419
|
+
executionGeneration: attempt.executionGeneration
|
|
35420
|
+
},
|
|
35421
|
+
// Only attachments on this accepted turn are new source inputs.
|
|
35422
|
+
// Session-level file receipts remain historical context and must
|
|
35423
|
+
// never trigger metadata reads, downloads, or re-preparation.
|
|
35424
|
+
resources: turn.resources,
|
|
35425
|
+
selectedTools: session.firstPartyMcpTools,
|
|
35426
|
+
permissions: session.firstPartyMcpPermissions,
|
|
35427
|
+
learningMode: learning.effective.knowledge,
|
|
35428
|
+
signal: cancellationSignal,
|
|
35429
|
+
onOutcome: async (outcome) => {
|
|
35430
|
+
if (outcome.status === "disabled") return;
|
|
35431
|
+
await eventing.publish(
|
|
35432
|
+
[
|
|
35045
35433
|
{
|
|
35046
|
-
type: "
|
|
35047
|
-
payload:
|
|
35048
|
-
phase: "model_preparation",
|
|
35049
|
-
durationMs: Math.max(
|
|
35050
|
-
0,
|
|
35051
|
-
Math.round(
|
|
35052
|
-
performance.now() - eventing.firstModelRequestPreparationStartedAt
|
|
35053
|
-
)
|
|
35054
|
-
)
|
|
35055
|
-
}
|
|
35056
|
-
}
|
|
35057
|
-
] : [],
|
|
35058
|
-
{
|
|
35059
|
-
type: "agent.model.request",
|
|
35060
|
-
payload: {
|
|
35061
|
-
...event,
|
|
35062
|
-
provider: "supergrok-subscription",
|
|
35063
|
-
turnId: attempt.turnId,
|
|
35064
|
-
attemptId: input.attemptId,
|
|
35065
|
-
dispatchId,
|
|
35066
|
-
executionGeneration: attempt.executionGeneration
|
|
35434
|
+
type: outcome.status === "failed" ? "knowledge.source.failed" : "knowledge.source.prepared",
|
|
35435
|
+
payload: outcome
|
|
35067
35436
|
}
|
|
35068
|
-
|
|
35069
|
-
|
|
35070
|
-
|
|
35071
|
-
|
|
35072
|
-
|
|
35437
|
+
],
|
|
35438
|
+
true
|
|
35439
|
+
);
|
|
35440
|
+
}
|
|
35441
|
+
});
|
|
35442
|
+
const knowledgeSourcePreparationNote = [knowledgeRecoveryNote, attachmentPreparationNote].filter(Boolean).join("\n\n") || void 0;
|
|
35443
|
+
const sandboxRoute = await resolveSandboxRoute({
|
|
35444
|
+
input,
|
|
35445
|
+
settings,
|
|
35446
|
+
db,
|
|
35447
|
+
eventing,
|
|
35448
|
+
sandboxState,
|
|
35449
|
+
media,
|
|
35450
|
+
fileAuthoritySubjectId,
|
|
35451
|
+
runSettings,
|
|
35452
|
+
logicalSandboxSettings
|
|
35453
|
+
});
|
|
35454
|
+
const {
|
|
35455
|
+
routingOn,
|
|
35456
|
+
activeSandboxBackend,
|
|
35457
|
+
machinePrimary,
|
|
35458
|
+
groupBoxBackend,
|
|
35459
|
+
sandboxCreationBackend,
|
|
35460
|
+
effectiveRunCredentialBackend
|
|
35461
|
+
} = sandboxRoute;
|
|
35462
|
+
const { turnResources, runtimeResources } = await waitForTurnOperation(
|
|
35463
|
+
applyTurnGitHubRepositoryBindings({
|
|
35464
|
+
db,
|
|
35465
|
+
settings: runSettings,
|
|
35466
|
+
workspaceId: input.workspaceId,
|
|
35467
|
+
sessionId: input.sessionId,
|
|
35468
|
+
activeSandboxBackend,
|
|
35469
|
+
claimedTurnResources,
|
|
35470
|
+
claimedRuntimeResources,
|
|
35471
|
+
publish: async (events) => {
|
|
35472
|
+
await eventing.publish(events, true);
|
|
35473
|
+
},
|
|
35474
|
+
warn: (message, fields) => observability.warn(message, fields)
|
|
35475
|
+
}),
|
|
35476
|
+
cancellationSignal,
|
|
35477
|
+
void 0
|
|
35478
|
+
);
|
|
35479
|
+
const runCredentials = await prepareRunCredentials({
|
|
35480
|
+
input,
|
|
35481
|
+
settings,
|
|
35482
|
+
db,
|
|
35483
|
+
observability,
|
|
35484
|
+
cancellationSignal,
|
|
35485
|
+
connectionCredentials,
|
|
35486
|
+
personalGitHubCredentials,
|
|
35487
|
+
eventing,
|
|
35488
|
+
attempt,
|
|
35489
|
+
renewals,
|
|
35490
|
+
sandboxState,
|
|
35491
|
+
sandboxRuntime,
|
|
35492
|
+
turn,
|
|
35493
|
+
session,
|
|
35494
|
+
fileAuthoritySubjectId,
|
|
35495
|
+
runSettings,
|
|
35496
|
+
workspaceVariableSet,
|
|
35497
|
+
turnResources,
|
|
35498
|
+
requiredGeneratedVideoFiles,
|
|
35499
|
+
machinePrimary,
|
|
35500
|
+
activeSandboxBackend,
|
|
35501
|
+
groupBoxBackend,
|
|
35502
|
+
sandboxCreationBackend,
|
|
35503
|
+
effectiveRunCredentialBackend,
|
|
35504
|
+
sandboxWorkspaceEnvironmentValues,
|
|
35505
|
+
connectionScope,
|
|
35506
|
+
runWorkspaceMutationForSandbox
|
|
35507
|
+
});
|
|
35508
|
+
const {
|
|
35509
|
+
runCredentialResolver,
|
|
35510
|
+
establishPolicy,
|
|
35511
|
+
initialRunCredentialMaterial,
|
|
35512
|
+
runCredentialsNote,
|
|
35513
|
+
hostCredentialRootSessionId,
|
|
35514
|
+
codemodeAuthority,
|
|
35515
|
+
sandboxArtifactRuntime,
|
|
35516
|
+
sandboxEnvironment,
|
|
35517
|
+
sandboxGitToken,
|
|
35518
|
+
sandboxGitTokens,
|
|
35519
|
+
sandboxGitCredentialBindings,
|
|
35520
|
+
sandboxCodemodeToken,
|
|
35521
|
+
sandboxCodemodeTokenExpiresAt,
|
|
35522
|
+
transientCodemodeEnvironment,
|
|
35523
|
+
initialGitCredentials,
|
|
35524
|
+
startRunGitCredentialsMint,
|
|
35525
|
+
attachGitCredentialRenewal,
|
|
35526
|
+
attachCodemodeTokenRenewal,
|
|
35527
|
+
attachRunCredentialRenewal
|
|
35528
|
+
} = runCredentials;
|
|
35529
|
+
await establishTurnSandbox({
|
|
35530
|
+
...sandboxRoute,
|
|
35531
|
+
input,
|
|
35532
|
+
settings,
|
|
35533
|
+
db,
|
|
35534
|
+
bus,
|
|
35535
|
+
objectStorage,
|
|
35536
|
+
observability,
|
|
35537
|
+
cancellationSignal,
|
|
35538
|
+
runtimeCancellationSignal,
|
|
35539
|
+
sandboxResumeSignal,
|
|
35540
|
+
activityContext,
|
|
35541
|
+
opJournal,
|
|
35542
|
+
sandboxState,
|
|
35543
|
+
eventing,
|
|
35544
|
+
attempt,
|
|
35545
|
+
turn,
|
|
35546
|
+
session,
|
|
35547
|
+
fileAuthoritySubjectId,
|
|
35548
|
+
capabilitySettings,
|
|
35549
|
+
turnExecutionPolicy,
|
|
35550
|
+
runSettings,
|
|
35551
|
+
logicalSandboxSettings,
|
|
35552
|
+
verifiedRigProviderImageId,
|
|
35553
|
+
runtimePreparationStartedAt,
|
|
35554
|
+
establishPolicy,
|
|
35555
|
+
sandboxEnvironment,
|
|
35556
|
+
startRunGitCredentialsMint,
|
|
35557
|
+
machineOpObserver,
|
|
35558
|
+
sandboxOperationObserver,
|
|
35559
|
+
sandboxRuntime,
|
|
35560
|
+
transientCodemodeEnvironment,
|
|
35561
|
+
rigVersion,
|
|
35562
|
+
turnResources
|
|
35563
|
+
});
|
|
35564
|
+
const ordinaryFileResourceDownloads = await (async () => {
|
|
35565
|
+
const fileResolutionStartedAt = performance.now();
|
|
35566
|
+
let fileResolutionOutcome = "completed";
|
|
35567
|
+
try {
|
|
35568
|
+
return await waitForTurnOperation(
|
|
35569
|
+
sandboxFileDownloadsForRun(
|
|
35570
|
+
runSettings,
|
|
35571
|
+
db,
|
|
35572
|
+
objectStorage,
|
|
35573
|
+
input.accountId,
|
|
35574
|
+
input.workspaceId,
|
|
35575
|
+
fileAuthoritySubjectId,
|
|
35576
|
+
turn.resources,
|
|
35577
|
+
activeSandboxBackend ?? groupBoxBackend
|
|
35578
|
+
),
|
|
35579
|
+
cancellationSignal,
|
|
35580
|
+
void 0
|
|
35073
35581
|
);
|
|
35074
35582
|
} catch (error51) {
|
|
35075
|
-
|
|
35583
|
+
fileResolutionOutcome = "failed";
|
|
35076
35584
|
throw error51;
|
|
35077
35585
|
} finally {
|
|
35078
|
-
|
|
35079
|
-
|
|
35080
|
-
|
|
35081
|
-
|
|
35082
|
-
|
|
35083
|
-
|
|
35084
|
-
|
|
35085
|
-
|
|
35086
|
-
});
|
|
35087
|
-
}
|
|
35586
|
+
recordTurnStartupPhase(observability, {
|
|
35587
|
+
phase: "file_resolution",
|
|
35588
|
+
provider: turnExecutionPolicy.providerId,
|
|
35589
|
+
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
35590
|
+
outcome: fileResolutionOutcome,
|
|
35591
|
+
durationSeconds: (performance.now() - fileResolutionStartedAt) / 1e3,
|
|
35592
|
+
count: turn.resources.length
|
|
35593
|
+
});
|
|
35088
35594
|
}
|
|
35595
|
+
})();
|
|
35596
|
+
if (requiredGeneratedVideoFiles.length > 0 && !objectStorage) {
|
|
35597
|
+
throw new Error("Generated video materialization requires object storage");
|
|
35089
35598
|
}
|
|
35090
|
-
|
|
35091
|
-
|
|
35092
|
-
|
|
35093
|
-
|
|
35094
|
-
const withProviderRequestContext = (fn) => providerTurn.xaiRequestContext ? xaiSubscriptionRequestStorage.run(providerTurn.xaiRequestContext, fn) : withCodex(fn);
|
|
35095
|
-
let codexSessionTitleRequestSequence = 0;
|
|
35096
|
-
let xaiSessionTitleRequestSequence = 0;
|
|
35097
|
-
const codexSessionTitleContext = codexContext ? sessionTitleCodexRequestContext(
|
|
35098
|
-
codexContext,
|
|
35099
|
-
() => `${dispatchId}:title:${++codexSessionTitleRequestSequence}`
|
|
35100
|
-
) : null;
|
|
35101
|
-
const xaiSessionTitleContext = providerTurn.xaiRequestContext ? sessionTitleXaiRequestContext(
|
|
35102
|
-
providerTurn.xaiRequestContext,
|
|
35103
|
-
() => `${dispatchId}:xai:title:${++xaiSessionTitleRequestSequence}`
|
|
35104
|
-
) : null;
|
|
35105
|
-
const withSessionTitleProviderRequestContext = (fn) => xaiSessionTitleContext ? xaiSubscriptionRequestStorage.run(xaiSessionTitleContext, fn) : codexSessionTitleContext ? codexRequestStorage.run(codexSessionTitleContext, fn) : fn();
|
|
35106
|
-
const withCodexRemoteCompaction = (fn) => withCodex(
|
|
35107
|
-
() => withCodexRequestOverrides(
|
|
35108
|
-
{
|
|
35109
|
-
betaFeatures: [REMOTE_COMPACTION_V2_BETA_FEATURE],
|
|
35110
|
-
turnMetadata: {
|
|
35111
|
-
request_kind: "compaction",
|
|
35112
|
-
compaction: {
|
|
35113
|
-
implementation: REMOTE_COMPACTION_V2_IMPLEMENTATION2,
|
|
35114
|
-
strategy: "memento"
|
|
35115
|
-
}
|
|
35116
|
-
}
|
|
35117
|
-
},
|
|
35118
|
-
fn
|
|
35119
|
-
)
|
|
35120
|
-
);
|
|
35121
|
-
const compactionPrep = await prepareCompaction({
|
|
35122
|
-
input,
|
|
35123
|
-
settings: capabilitySettings,
|
|
35124
|
-
db,
|
|
35125
|
-
bus,
|
|
35126
|
-
observability,
|
|
35127
|
-
cancellationSignal,
|
|
35128
|
-
control,
|
|
35129
|
-
attempt,
|
|
35130
|
-
billingState,
|
|
35131
|
-
eventing: wiredEventing,
|
|
35132
|
-
providerTurn,
|
|
35133
|
-
leases,
|
|
35134
|
-
media,
|
|
35135
|
-
claimedResult,
|
|
35136
|
-
claimedModelUsageSourceKeys,
|
|
35137
|
-
emittedModelUsageSourceKeys,
|
|
35138
|
-
modelUsageDispatchId,
|
|
35139
|
-
turn,
|
|
35140
|
-
session,
|
|
35141
|
-
turnExecutionPolicy,
|
|
35142
|
-
resolvedModel,
|
|
35143
|
-
workspaceAgentInstructions,
|
|
35144
|
-
workspaceGovernance,
|
|
35145
|
-
structuredWorkspacePolicyActive,
|
|
35146
|
-
workspaceMemory,
|
|
35147
|
-
rigVersion,
|
|
35148
|
-
rigName,
|
|
35149
|
-
compactionModelHistoryProjector,
|
|
35150
|
-
summarizeContextForCompaction,
|
|
35151
|
-
withProviderRequestContext,
|
|
35152
|
-
withCodexRemoteCompaction
|
|
35153
|
-
});
|
|
35154
|
-
if ("exit" in compactionPrep) return compactionPrep.exit;
|
|
35155
|
-
const {
|
|
35156
|
-
promptCacheKey,
|
|
35157
|
-
remotePrefix,
|
|
35158
|
-
remoteCompactionRequester,
|
|
35159
|
-
publishCompactionLiveEvents,
|
|
35160
|
-
publishCompactionOutcomeEvents,
|
|
35161
|
-
compactionModeOptions,
|
|
35162
|
-
compactionOnlyTurn,
|
|
35163
|
-
compactionSummarizerFor,
|
|
35164
|
-
settleDeferredSteerAfterCompaction
|
|
35165
|
-
} = compactionPrep.ok;
|
|
35166
|
-
const toolPolicy = await prepareTurnToolPolicy({
|
|
35167
|
-
input,
|
|
35168
|
-
db,
|
|
35169
|
-
cancellationSignal,
|
|
35170
|
-
connectionCredentials,
|
|
35171
|
-
turn,
|
|
35172
|
-
session,
|
|
35173
|
-
fileAuthoritySubjectId,
|
|
35174
|
-
capabilitySettings,
|
|
35175
|
-
runSettings,
|
|
35176
|
-
rigVersion,
|
|
35177
|
-
workspaceRefs
|
|
35178
|
-
});
|
|
35179
|
-
const {
|
|
35180
|
-
turnResources: claimedTurnResources,
|
|
35181
|
-
runtimeResources: claimedRuntimeResources,
|
|
35182
|
-
mcpAvailabilityNote,
|
|
35183
|
-
turnTools,
|
|
35184
|
-
connectionScope,
|
|
35185
|
-
workspaceVariableSet,
|
|
35186
|
-
sandboxWorkspaceEnvironmentValues
|
|
35187
|
-
} = toolPolicy;
|
|
35188
|
-
const sandboxRoute = await resolveSandboxRoute({
|
|
35189
|
-
input,
|
|
35190
|
-
settings,
|
|
35191
|
-
db,
|
|
35192
|
-
eventing,
|
|
35193
|
-
sandboxState,
|
|
35194
|
-
media,
|
|
35195
|
-
fileAuthoritySubjectId,
|
|
35196
|
-
runSettings,
|
|
35197
|
-
logicalSandboxSettings
|
|
35198
|
-
});
|
|
35199
|
-
const {
|
|
35200
|
-
routingOn,
|
|
35201
|
-
activeSandboxBackend,
|
|
35202
|
-
machinePrimary,
|
|
35203
|
-
groupBoxBackend,
|
|
35204
|
-
sandboxCreationBackend,
|
|
35205
|
-
effectiveRunCredentialBackend
|
|
35206
|
-
} = sandboxRoute;
|
|
35207
|
-
const { turnResources, runtimeResources } = await waitForTurnOperation(
|
|
35208
|
-
applyTurnGitHubRepositoryBindings({
|
|
35209
|
-
db,
|
|
35210
|
-
settings: runSettings,
|
|
35211
|
-
workspaceId: input.workspaceId,
|
|
35212
|
-
sessionId: input.sessionId,
|
|
35213
|
-
activeSandboxBackend,
|
|
35214
|
-
claimedTurnResources,
|
|
35215
|
-
claimedRuntimeResources,
|
|
35216
|
-
publish: async (events) => {
|
|
35217
|
-
await eventing.publish(events, true);
|
|
35218
|
-
},
|
|
35219
|
-
warn: (message, fields) => observability.warn(message, fields)
|
|
35220
|
-
}),
|
|
35221
|
-
cancellationSignal,
|
|
35222
|
-
void 0
|
|
35223
|
-
);
|
|
35224
|
-
const runCredentials = await prepareRunCredentials({
|
|
35225
|
-
input,
|
|
35226
|
-
settings,
|
|
35227
|
-
db,
|
|
35228
|
-
observability,
|
|
35229
|
-
cancellationSignal,
|
|
35230
|
-
connectionCredentials,
|
|
35231
|
-
personalGitHubCredentials,
|
|
35232
|
-
eventing,
|
|
35233
|
-
attempt,
|
|
35234
|
-
renewals,
|
|
35235
|
-
sandboxState,
|
|
35236
|
-
sandboxRuntime,
|
|
35237
|
-
turn,
|
|
35238
|
-
session,
|
|
35239
|
-
fileAuthoritySubjectId,
|
|
35240
|
-
runSettings,
|
|
35241
|
-
workspaceVariableSet,
|
|
35242
|
-
turnResources,
|
|
35243
|
-
requiredGeneratedVideoFiles,
|
|
35244
|
-
machinePrimary,
|
|
35245
|
-
activeSandboxBackend,
|
|
35246
|
-
groupBoxBackend,
|
|
35247
|
-
sandboxCreationBackend,
|
|
35248
|
-
effectiveRunCredentialBackend,
|
|
35249
|
-
sandboxWorkspaceEnvironmentValues,
|
|
35250
|
-
connectionScope,
|
|
35251
|
-
runWorkspaceMutationForSandbox
|
|
35252
|
-
});
|
|
35253
|
-
const {
|
|
35254
|
-
runCredentialResolver,
|
|
35255
|
-
establishPolicy,
|
|
35256
|
-
initialRunCredentialMaterial,
|
|
35257
|
-
runCredentialsNote,
|
|
35258
|
-
hostCredentialRootSessionId,
|
|
35259
|
-
codemodeAuthority,
|
|
35260
|
-
sandboxArtifactRuntime,
|
|
35261
|
-
sandboxEnvironment,
|
|
35262
|
-
sandboxGitToken,
|
|
35263
|
-
sandboxGitTokens,
|
|
35264
|
-
sandboxGitCredentialBindings,
|
|
35265
|
-
sandboxCodemodeToken,
|
|
35266
|
-
sandboxCodemodeTokenExpiresAt,
|
|
35267
|
-
transientCodemodeEnvironment,
|
|
35268
|
-
initialGitCredentials,
|
|
35269
|
-
startRunGitCredentialsMint,
|
|
35270
|
-
attachGitCredentialRenewal,
|
|
35271
|
-
attachCodemodeTokenRenewal,
|
|
35272
|
-
attachRunCredentialRenewal
|
|
35273
|
-
} = runCredentials;
|
|
35274
|
-
await establishTurnSandbox({
|
|
35275
|
-
...sandboxRoute,
|
|
35276
|
-
input,
|
|
35277
|
-
settings,
|
|
35278
|
-
db,
|
|
35279
|
-
bus,
|
|
35280
|
-
objectStorage,
|
|
35281
|
-
observability,
|
|
35282
|
-
cancellationSignal,
|
|
35283
|
-
runtimeCancellationSignal,
|
|
35284
|
-
sandboxResumeSignal,
|
|
35285
|
-
activityContext,
|
|
35286
|
-
opJournal,
|
|
35287
|
-
sandboxState,
|
|
35288
|
-
eventing,
|
|
35289
|
-
attempt,
|
|
35290
|
-
turn,
|
|
35291
|
-
session,
|
|
35292
|
-
fileAuthoritySubjectId,
|
|
35293
|
-
capabilitySettings,
|
|
35294
|
-
turnExecutionPolicy,
|
|
35295
|
-
runSettings,
|
|
35296
|
-
logicalSandboxSettings,
|
|
35297
|
-
verifiedRigProviderImageId,
|
|
35298
|
-
runtimePreparationStartedAt,
|
|
35299
|
-
establishPolicy,
|
|
35300
|
-
sandboxEnvironment,
|
|
35301
|
-
startRunGitCredentialsMint,
|
|
35302
|
-
machineOpObserver,
|
|
35303
|
-
sandboxOperationObserver,
|
|
35304
|
-
sandboxRuntime,
|
|
35305
|
-
transientCodemodeEnvironment,
|
|
35306
|
-
rigVersion,
|
|
35307
|
-
turnResources
|
|
35308
|
-
});
|
|
35309
|
-
const ordinaryFileResourceDownloads = await (async () => {
|
|
35310
|
-
const fileResolutionStartedAt = performance.now();
|
|
35311
|
-
let fileResolutionOutcome = "completed";
|
|
35312
|
-
try {
|
|
35313
|
-
return await waitForTurnOperation(
|
|
35314
|
-
sandboxFileDownloadsForRun(
|
|
35315
|
-
runSettings,
|
|
35316
|
-
db,
|
|
35599
|
+
const generatedVideoDownloads = [];
|
|
35600
|
+
if (objectStorage && requiredGeneratedVideoFiles.length > 0) {
|
|
35601
|
+
const downloadStorage = objectStorageForSandboxDownloads(
|
|
35602
|
+
eventing.modelRunSettings,
|
|
35317
35603
|
objectStorage,
|
|
35318
|
-
|
|
35319
|
-
|
|
35320
|
-
|
|
35321
|
-
|
|
35322
|
-
|
|
35323
|
-
|
|
35604
|
+
media.sandboxFileDownloadBackend
|
|
35605
|
+
);
|
|
35606
|
+
for (const file2 of requiredGeneratedVideoFiles) {
|
|
35607
|
+
const signed = await downloadStorage.createGetUrl({
|
|
35608
|
+
key: file2.objectKey
|
|
35609
|
+
});
|
|
35610
|
+
generatedVideoDownloads.push({
|
|
35611
|
+
fileId: file2.fileId,
|
|
35612
|
+
mountPath: "generated-videos",
|
|
35613
|
+
filename: file2.filename,
|
|
35614
|
+
url: signed.url,
|
|
35615
|
+
expiresAt: signed.expiresAt,
|
|
35616
|
+
sizeBytes: file2.sizeBytes,
|
|
35617
|
+
sha256: file2.sha256
|
|
35618
|
+
});
|
|
35619
|
+
}
|
|
35620
|
+
}
|
|
35621
|
+
const fileResourceDownloads = [
|
|
35622
|
+
...new Map(
|
|
35623
|
+
[...ordinaryFileResourceDownloads, ...generatedVideoDownloads].map((download) => [
|
|
35624
|
+
download.fileId,
|
|
35625
|
+
download
|
|
35626
|
+
])
|
|
35627
|
+
).values()
|
|
35628
|
+
];
|
|
35629
|
+
const toolRuntime = await prepareTurnToolRuntime({
|
|
35630
|
+
fetchKnowledgeSource: sourceActivities.runKnowledgeSourceSyncBatch,
|
|
35631
|
+
selectedSkillActivations: packRuntime.skillActivations,
|
|
35632
|
+
input,
|
|
35633
|
+
catalogSourceSettings,
|
|
35634
|
+
db,
|
|
35635
|
+
bus,
|
|
35636
|
+
runtime,
|
|
35637
|
+
objectStorage,
|
|
35638
|
+
observability,
|
|
35324
35639
|
cancellationSignal,
|
|
35325
|
-
|
|
35326
|
-
|
|
35327
|
-
|
|
35328
|
-
|
|
35329
|
-
|
|
35330
|
-
|
|
35331
|
-
|
|
35332
|
-
|
|
35333
|
-
|
|
35334
|
-
|
|
35335
|
-
|
|
35336
|
-
|
|
35337
|
-
|
|
35640
|
+
connectionCredentials,
|
|
35641
|
+
eventing,
|
|
35642
|
+
attempt,
|
|
35643
|
+
sandboxState,
|
|
35644
|
+
media,
|
|
35645
|
+
toolResultSpill,
|
|
35646
|
+
turn,
|
|
35647
|
+
session,
|
|
35648
|
+
fileAuthoritySubjectId,
|
|
35649
|
+
capabilitySettings,
|
|
35650
|
+
installedApiIntegrations,
|
|
35651
|
+
codexAppsCredentialId,
|
|
35652
|
+
turnExecutionPolicy,
|
|
35653
|
+
trigger,
|
|
35654
|
+
runSettings,
|
|
35655
|
+
lazyToolTransport,
|
|
35656
|
+
turnTools,
|
|
35657
|
+
connectionScope,
|
|
35658
|
+
hostCredentialRootSessionId,
|
|
35659
|
+
sandboxArtifactRuntime,
|
|
35660
|
+
activeSandboxBackend,
|
|
35661
|
+
groupBoxBackend,
|
|
35662
|
+
routingOn,
|
|
35663
|
+
runtimeCancellationSignal,
|
|
35664
|
+
credentialSubjectId,
|
|
35665
|
+
interactionInterventionResume,
|
|
35666
|
+
runWorkspaceMutationForSandbox,
|
|
35667
|
+
throwIfWorkerShuttingDown,
|
|
35668
|
+
throwIfTurnCancelled
|
|
35338
35669
|
});
|
|
35339
|
-
|
|
35340
|
-
|
|
35341
|
-
|
|
35342
|
-
|
|
35343
|
-
|
|
35344
|
-
|
|
35345
|
-
|
|
35346
|
-
|
|
35347
|
-
|
|
35348
|
-
|
|
35349
|
-
|
|
35350
|
-
|
|
35351
|
-
|
|
35352
|
-
|
|
35353
|
-
|
|
35670
|
+
const {
|
|
35671
|
+
attemptConnectorActionBindings,
|
|
35672
|
+
connectorActionPolicy,
|
|
35673
|
+
generateSessionTitleInParallel,
|
|
35674
|
+
postToolPreparationStartedAt,
|
|
35675
|
+
preparationIndependentToolNames
|
|
35676
|
+
} = toolRuntime;
|
|
35677
|
+
const builtAgent = await buildTurnAgent({
|
|
35678
|
+
skillCatalog: toolRuntime.skillCatalog,
|
|
35679
|
+
input,
|
|
35680
|
+
db,
|
|
35681
|
+
runtime,
|
|
35682
|
+
objectStorage,
|
|
35683
|
+
observability,
|
|
35684
|
+
cancellationSignal,
|
|
35685
|
+
runtimeCancellationSignal,
|
|
35686
|
+
eventing,
|
|
35687
|
+
attempt,
|
|
35688
|
+
sandboxState,
|
|
35689
|
+
providerTurn,
|
|
35690
|
+
media,
|
|
35691
|
+
leases,
|
|
35692
|
+
turn,
|
|
35693
|
+
session,
|
|
35694
|
+
fileAuthoritySubjectId,
|
|
35695
|
+
capabilitySettings,
|
|
35696
|
+
humanInputResume,
|
|
35697
|
+
turnExecutionPolicy,
|
|
35698
|
+
runSettings,
|
|
35699
|
+
logicalSandboxSettings,
|
|
35700
|
+
verifiedRigProviderImageId,
|
|
35701
|
+
resolvedModel,
|
|
35702
|
+
nativeImageProviderBinding,
|
|
35703
|
+
lazyToolTransport,
|
|
35704
|
+
modelInputPolicy,
|
|
35705
|
+
supportsImageInput,
|
|
35706
|
+
agentHumanInputEnabled,
|
|
35707
|
+
workspaceAgentInstructions,
|
|
35708
|
+
workspaceGovernance,
|
|
35709
|
+
structuredWorkspacePolicyActive,
|
|
35710
|
+
workspaceMemory,
|
|
35711
|
+
rigVersion,
|
|
35712
|
+
rigName,
|
|
35713
|
+
buildCompanyBrainContributionReceiptFor,
|
|
35714
|
+
promptCacheKey,
|
|
35715
|
+
workspaceVariableSet,
|
|
35716
|
+
runtimeResources,
|
|
35717
|
+
sandboxEnvironment,
|
|
35718
|
+
sandboxArtifactRuntime,
|
|
35719
|
+
sandboxGitToken,
|
|
35720
|
+
sandboxGitTokens,
|
|
35721
|
+
sandboxGitCredentialBindings,
|
|
35722
|
+
sandboxCodemodeToken,
|
|
35723
|
+
fileResourceDownloads,
|
|
35724
|
+
attemptConnectorActionBindings,
|
|
35725
|
+
connectorActionPolicy,
|
|
35726
|
+
trigger,
|
|
35727
|
+
preparationIndependentToolNames,
|
|
35728
|
+
videoGenerationAcceptancesByCallId,
|
|
35729
|
+
activeSandboxBackend,
|
|
35730
|
+
groupBoxBackend,
|
|
35731
|
+
postToolPreparationStartedAt,
|
|
35732
|
+
codexContext
|
|
35354
35733
|
});
|
|
35355
|
-
|
|
35356
|
-
|
|
35357
|
-
|
|
35358
|
-
|
|
35359
|
-
|
|
35360
|
-
|
|
35361
|
-
|
|
35362
|
-
|
|
35734
|
+
const { agent, modelVisibleSkillCatalogText, postAgentPreparationStartedAt } = builtAgent;
|
|
35735
|
+
await bindLazySandboxProvisioner({
|
|
35736
|
+
...sandboxRoute,
|
|
35737
|
+
input,
|
|
35738
|
+
settings,
|
|
35739
|
+
db,
|
|
35740
|
+
bus,
|
|
35741
|
+
objectStorage,
|
|
35742
|
+
observability,
|
|
35743
|
+
cancellationSignal,
|
|
35744
|
+
runtimeCancellationSignal,
|
|
35745
|
+
sandboxResumeSignal,
|
|
35746
|
+
activityContext,
|
|
35747
|
+
opJournal,
|
|
35748
|
+
sandboxState,
|
|
35749
|
+
eventing,
|
|
35750
|
+
attempt,
|
|
35751
|
+
turn,
|
|
35752
|
+
session,
|
|
35753
|
+
fileAuthoritySubjectId,
|
|
35754
|
+
capabilitySettings,
|
|
35755
|
+
turnExecutionPolicy,
|
|
35756
|
+
runSettings,
|
|
35757
|
+
logicalSandboxSettings,
|
|
35758
|
+
verifiedRigProviderImageId,
|
|
35759
|
+
runtimePreparationStartedAt,
|
|
35760
|
+
establishPolicy,
|
|
35761
|
+
sandboxEnvironment,
|
|
35762
|
+
startRunGitCredentialsMint,
|
|
35763
|
+
machineOpObserver,
|
|
35764
|
+
sandboxOperationObserver,
|
|
35765
|
+
sandboxRuntime,
|
|
35766
|
+
transientCodemodeEnvironment,
|
|
35767
|
+
agent,
|
|
35768
|
+
attachRunCredentialRenewal,
|
|
35769
|
+
attachGitCredentialRenewal,
|
|
35770
|
+
attachCodemodeTokenRenewal,
|
|
35771
|
+
throwIfWorkerShuttingDown,
|
|
35772
|
+
throwIfTurnCancelled,
|
|
35773
|
+
initialRunCredentialMaterial,
|
|
35774
|
+
sandboxCodemodeToken,
|
|
35775
|
+
media,
|
|
35776
|
+
toolResultSpill,
|
|
35777
|
+
connectionScope,
|
|
35778
|
+
codemodeAuthority,
|
|
35779
|
+
rigVersion,
|
|
35780
|
+
turnResources
|
|
35363
35781
|
});
|
|
35364
|
-
|
|
35365
|
-
|
|
35366
|
-
|
|
35367
|
-
|
|
35368
|
-
|
|
35369
|
-
|
|
35370
|
-
|
|
35371
|
-
|
|
35372
|
-
|
|
35373
|
-
|
|
35374
|
-
|
|
35375
|
-
|
|
35376
|
-
|
|
35377
|
-
|
|
35378
|
-
|
|
35379
|
-
|
|
35380
|
-
|
|
35381
|
-
|
|
35382
|
-
|
|
35383
|
-
|
|
35384
|
-
|
|
35385
|
-
|
|
35386
|
-
|
|
35387
|
-
|
|
35388
|
-
|
|
35389
|
-
|
|
35390
|
-
|
|
35391
|
-
|
|
35392
|
-
|
|
35393
|
-
|
|
35394
|
-
|
|
35395
|
-
|
|
35396
|
-
|
|
35397
|
-
|
|
35398
|
-
|
|
35399
|
-
|
|
35400
|
-
|
|
35401
|
-
|
|
35402
|
-
|
|
35403
|
-
|
|
35404
|
-
|
|
35405
|
-
|
|
35406
|
-
|
|
35407
|
-
|
|
35408
|
-
|
|
35409
|
-
|
|
35410
|
-
|
|
35411
|
-
|
|
35412
|
-
|
|
35413
|
-
|
|
35414
|
-
|
|
35415
|
-
|
|
35416
|
-
|
|
35417
|
-
|
|
35418
|
-
|
|
35419
|
-
|
|
35420
|
-
|
|
35421
|
-
|
|
35422
|
-
|
|
35423
|
-
|
|
35424
|
-
|
|
35425
|
-
|
|
35426
|
-
|
|
35427
|
-
|
|
35428
|
-
|
|
35429
|
-
|
|
35430
|
-
|
|
35431
|
-
attempt,
|
|
35432
|
-
sandboxState,
|
|
35433
|
-
providerTurn,
|
|
35434
|
-
media,
|
|
35435
|
-
leases,
|
|
35436
|
-
turn,
|
|
35437
|
-
session,
|
|
35438
|
-
fileAuthoritySubjectId,
|
|
35439
|
-
capabilitySettings,
|
|
35440
|
-
humanInputResume,
|
|
35441
|
-
turnExecutionPolicy,
|
|
35442
|
-
runSettings,
|
|
35443
|
-
logicalSandboxSettings,
|
|
35444
|
-
verifiedRigProviderImageId,
|
|
35445
|
-
resolvedModel,
|
|
35446
|
-
nativeImageProviderBinding,
|
|
35447
|
-
lazyToolTransport,
|
|
35448
|
-
modelInputPolicy,
|
|
35449
|
-
supportsImageInput,
|
|
35450
|
-
agentHumanInputEnabled,
|
|
35451
|
-
workspaceAgentInstructions,
|
|
35452
|
-
workspaceGovernance,
|
|
35453
|
-
structuredWorkspacePolicyActive,
|
|
35454
|
-
workspaceMemory,
|
|
35455
|
-
rigVersion,
|
|
35456
|
-
rigName,
|
|
35457
|
-
buildCompanyBrainContributionReceiptFor,
|
|
35458
|
-
promptCacheKey,
|
|
35459
|
-
workspaceVariableSet,
|
|
35460
|
-
runtimeResources,
|
|
35461
|
-
sandboxEnvironment,
|
|
35462
|
-
sandboxArtifactRuntime,
|
|
35463
|
-
sandboxGitToken,
|
|
35464
|
-
sandboxGitTokens,
|
|
35465
|
-
sandboxGitCredentialBindings,
|
|
35466
|
-
sandboxCodemodeToken,
|
|
35467
|
-
fileResourceDownloads,
|
|
35468
|
-
attemptConnectorActionBindings,
|
|
35469
|
-
connectorActionPolicy,
|
|
35470
|
-
trigger,
|
|
35471
|
-
preparationIndependentToolNames,
|
|
35472
|
-
videoGenerationAcceptancesByCallId,
|
|
35473
|
-
activeSandboxBackend,
|
|
35474
|
-
groupBoxBackend,
|
|
35475
|
-
postToolPreparationStartedAt,
|
|
35476
|
-
codexContext
|
|
35477
|
-
});
|
|
35478
|
-
const { agent, modelVisibleSkillCatalogText, postAgentPreparationStartedAt } = builtAgent;
|
|
35479
|
-
await bindLazySandboxProvisioner({
|
|
35480
|
-
...sandboxRoute,
|
|
35481
|
-
input,
|
|
35482
|
-
settings,
|
|
35483
|
-
db,
|
|
35484
|
-
bus,
|
|
35485
|
-
objectStorage,
|
|
35486
|
-
observability,
|
|
35487
|
-
cancellationSignal,
|
|
35488
|
-
runtimeCancellationSignal,
|
|
35489
|
-
sandboxResumeSignal,
|
|
35490
|
-
activityContext,
|
|
35491
|
-
opJournal,
|
|
35492
|
-
sandboxState,
|
|
35493
|
-
eventing,
|
|
35494
|
-
attempt,
|
|
35495
|
-
turn,
|
|
35496
|
-
session,
|
|
35497
|
-
fileAuthoritySubjectId,
|
|
35498
|
-
capabilitySettings,
|
|
35499
|
-
turnExecutionPolicy,
|
|
35500
|
-
runSettings,
|
|
35501
|
-
logicalSandboxSettings,
|
|
35502
|
-
verifiedRigProviderImageId,
|
|
35503
|
-
runtimePreparationStartedAt,
|
|
35504
|
-
establishPolicy,
|
|
35505
|
-
sandboxEnvironment,
|
|
35506
|
-
startRunGitCredentialsMint,
|
|
35507
|
-
machineOpObserver,
|
|
35508
|
-
sandboxOperationObserver,
|
|
35509
|
-
sandboxRuntime,
|
|
35510
|
-
transientCodemodeEnvironment,
|
|
35511
|
-
agent,
|
|
35512
|
-
attachRunCredentialRenewal,
|
|
35513
|
-
attachGitCredentialRenewal,
|
|
35514
|
-
attachCodemodeTokenRenewal,
|
|
35515
|
-
throwIfWorkerShuttingDown,
|
|
35516
|
-
throwIfTurnCancelled,
|
|
35517
|
-
initialRunCredentialMaterial,
|
|
35518
|
-
sandboxCodemodeToken,
|
|
35519
|
-
media,
|
|
35520
|
-
toolResultSpill,
|
|
35521
|
-
connectionScope,
|
|
35522
|
-
codemodeAuthority,
|
|
35523
|
-
rigVersion,
|
|
35524
|
-
turnResources
|
|
35525
|
-
});
|
|
35526
|
-
let companyBrainContributionReceiptRecorded = false;
|
|
35527
|
-
const recordCompanyBrainContributionReceiptOnce = () => {
|
|
35528
|
-
if (companyBrainContributionReceiptRecorded) return;
|
|
35529
|
-
companyBrainContributionReceiptRecorded = true;
|
|
35530
|
-
try {
|
|
35531
|
-
const companyBrainContributionReceipt = buildCompanyBrainContributionReceiptFor(
|
|
35532
|
-
modelVisibleSkillCatalogText
|
|
35533
|
-
);
|
|
35534
|
-
eventing.companyBrainContextContributions = summarizeCompanyBrainContributions(
|
|
35535
|
-
companyBrainContributionReceipt
|
|
35536
|
-
);
|
|
35537
|
-
recordCompanyBrainContributions(observability, companyBrainContributionReceipt);
|
|
35538
|
-
observability.info("model context contribution receipt", {
|
|
35539
|
-
attemptId: companyBrainContributionReceipt.attemptId,
|
|
35540
|
-
turnId: companyBrainContributionReceipt.turnId,
|
|
35541
|
-
contextSelectionReceiptId: companyBrainContributionReceipt.contextSelectionReceiptId,
|
|
35542
|
-
sessionRole: companyBrainContributionReceipt.sessionRole,
|
|
35543
|
-
memoryPromptMode: companyBrainContributionReceipt.memoryPromptMode,
|
|
35544
|
-
instructionPolicySnapshotId: companyBrainContributionReceipt.instructionPolicySnapshotId,
|
|
35545
|
-
preferenceSnapshotId: companyBrainContributionReceipt.preferenceSnapshotId,
|
|
35546
|
-
companyProfileSnapshotId: companyBrainContributionReceipt.companyProfileSnapshotId,
|
|
35547
|
-
contributions: JSON.stringify(companyBrainContributionReceipt.contributions)
|
|
35782
|
+
let companyBrainContributionReceiptRecorded = false;
|
|
35783
|
+
const recordCompanyBrainContributionReceiptOnce = () => {
|
|
35784
|
+
if (companyBrainContributionReceiptRecorded) return;
|
|
35785
|
+
companyBrainContributionReceiptRecorded = true;
|
|
35786
|
+
try {
|
|
35787
|
+
const companyBrainContributionReceipt = buildCompanyBrainContributionReceiptFor(
|
|
35788
|
+
modelVisibleSkillCatalogText
|
|
35789
|
+
);
|
|
35790
|
+
eventing.companyBrainContextContributions = summarizeCompanyBrainContributions(
|
|
35791
|
+
companyBrainContributionReceipt
|
|
35792
|
+
);
|
|
35793
|
+
recordCompanyBrainContributions(observability, companyBrainContributionReceipt);
|
|
35794
|
+
observability.info("model context contribution receipt", {
|
|
35795
|
+
attemptId: companyBrainContributionReceipt.attemptId,
|
|
35796
|
+
turnId: companyBrainContributionReceipt.turnId,
|
|
35797
|
+
contextSelectionReceiptId: companyBrainContributionReceipt.contextSelectionReceiptId,
|
|
35798
|
+
sessionRole: companyBrainContributionReceipt.sessionRole,
|
|
35799
|
+
memoryPromptMode: companyBrainContributionReceipt.memoryPromptMode,
|
|
35800
|
+
instructionPolicySnapshotId: companyBrainContributionReceipt.instructionPolicySnapshotId,
|
|
35801
|
+
preferenceSnapshotId: companyBrainContributionReceipt.preferenceSnapshotId,
|
|
35802
|
+
companyProfileSnapshotId: companyBrainContributionReceipt.companyProfileSnapshotId,
|
|
35803
|
+
contributions: JSON.stringify(companyBrainContributionReceipt.contributions)
|
|
35804
|
+
});
|
|
35805
|
+
} catch {
|
|
35806
|
+
}
|
|
35807
|
+
};
|
|
35808
|
+
const postAgentCompaction = await runPostAgentCompaction({
|
|
35809
|
+
input,
|
|
35810
|
+
settings: capabilitySettings,
|
|
35811
|
+
db,
|
|
35812
|
+
bus,
|
|
35813
|
+
observability,
|
|
35814
|
+
cancellationSignal,
|
|
35815
|
+
control,
|
|
35816
|
+
attempt,
|
|
35817
|
+
billingState,
|
|
35818
|
+
eventing: wiredEventing,
|
|
35819
|
+
providerTurn,
|
|
35820
|
+
leases,
|
|
35821
|
+
media,
|
|
35822
|
+
claimedResult,
|
|
35823
|
+
claimedModelUsageSourceKeys,
|
|
35824
|
+
emittedModelUsageSourceKeys,
|
|
35825
|
+
modelUsageDispatchId,
|
|
35826
|
+
turn,
|
|
35827
|
+
session,
|
|
35828
|
+
turnExecutionPolicy,
|
|
35829
|
+
resolvedModel,
|
|
35830
|
+
workspaceAgentInstructions,
|
|
35831
|
+
workspaceGovernance,
|
|
35832
|
+
structuredWorkspacePolicyActive,
|
|
35833
|
+
workspaceMemory,
|
|
35834
|
+
rigVersion,
|
|
35835
|
+
rigName,
|
|
35836
|
+
compactionModelHistoryProjector,
|
|
35837
|
+
summarizeContextForCompaction,
|
|
35838
|
+
withProviderRequestContext,
|
|
35839
|
+
withCodexRemoteCompaction,
|
|
35840
|
+
remotePrefix,
|
|
35841
|
+
remoteCompactionRequester,
|
|
35842
|
+
publishCompactionLiveEvents,
|
|
35843
|
+
publishCompactionOutcomeEvents,
|
|
35844
|
+
compactionModeOptions,
|
|
35845
|
+
compactionOnlyTurn,
|
|
35846
|
+
compactionSummarizerFor,
|
|
35847
|
+
settleDeferredSteerAfterCompaction,
|
|
35848
|
+
agent
|
|
35548
35849
|
});
|
|
35549
|
-
|
|
35550
|
-
|
|
35551
|
-
|
|
35552
|
-
|
|
35553
|
-
|
|
35554
|
-
|
|
35555
|
-
|
|
35556
|
-
|
|
35557
|
-
observability,
|
|
35558
|
-
cancellationSignal,
|
|
35559
|
-
control,
|
|
35560
|
-
attempt,
|
|
35561
|
-
billingState,
|
|
35562
|
-
eventing: wiredEventing,
|
|
35563
|
-
providerTurn,
|
|
35564
|
-
leases,
|
|
35565
|
-
media,
|
|
35566
|
-
claimedResult,
|
|
35567
|
-
claimedModelUsageSourceKeys,
|
|
35568
|
-
emittedModelUsageSourceKeys,
|
|
35569
|
-
modelUsageDispatchId,
|
|
35570
|
-
turn,
|
|
35571
|
-
session,
|
|
35572
|
-
turnExecutionPolicy,
|
|
35573
|
-
resolvedModel,
|
|
35574
|
-
workspaceAgentInstructions,
|
|
35575
|
-
workspaceGovernance,
|
|
35576
|
-
structuredWorkspacePolicyActive,
|
|
35577
|
-
workspaceMemory,
|
|
35578
|
-
rigVersion,
|
|
35579
|
-
rigName,
|
|
35580
|
-
compactionModelHistoryProjector,
|
|
35581
|
-
summarizeContextForCompaction,
|
|
35582
|
-
withProviderRequestContext,
|
|
35583
|
-
withCodexRemoteCompaction,
|
|
35584
|
-
remotePrefix,
|
|
35585
|
-
remoteCompactionRequester,
|
|
35586
|
-
publishCompactionLiveEvents,
|
|
35587
|
-
publishCompactionOutcomeEvents,
|
|
35588
|
-
compactionModeOptions,
|
|
35589
|
-
compactionOnlyTurn,
|
|
35590
|
-
compactionSummarizerFor,
|
|
35591
|
-
settleDeferredSteerAfterCompaction,
|
|
35592
|
-
agent
|
|
35593
|
-
});
|
|
35594
|
-
if ("exit" in postAgentCompaction) return postAgentCompaction.exit;
|
|
35595
|
-
const { compactSummarizer } = postAgentCompaction.ok;
|
|
35596
|
-
recordTurnStartupPhase(observability, {
|
|
35597
|
-
phase: "post_agent_preparation",
|
|
35598
|
-
provider: turnExecutionPolicy.providerId,
|
|
35599
|
-
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
35600
|
-
outcome: "completed",
|
|
35601
|
-
durationSeconds: (performance.now() - postAgentPreparationStartedAt) / 1e3
|
|
35602
|
-
});
|
|
35603
|
-
let fileMaterializationFailures = [];
|
|
35604
|
-
let fileDownloadsMaterializedForRun = false;
|
|
35605
|
-
if (sandboxState.resolvedSandbox && sandboxState.setupBoxSession && fileResourceDownloads.length > 0) {
|
|
35606
|
-
const fileMaterializationStartedAt = performance.now();
|
|
35607
|
-
let fileMaterializationOutcome = "completed";
|
|
35608
|
-
let fileMaterializationCache = "miss";
|
|
35609
|
-
try {
|
|
35610
|
-
const boxInstanceId = sandboxState.resolvedSandbox.established.instanceId;
|
|
35611
|
-
const alreadyMaterialized = await getMaterializedSandboxFileResources3(db, {
|
|
35612
|
-
accountId: input.accountId,
|
|
35613
|
-
workspaceId: input.workspaceId,
|
|
35614
|
-
sandboxGroupId: session.sandboxGroupId,
|
|
35615
|
-
expectedEpoch: sandboxState.resolvedSandbox.leaseEpoch,
|
|
35616
|
-
instanceId: boxInstanceId
|
|
35850
|
+
if ("exit" in postAgentCompaction) return postAgentCompaction.exit;
|
|
35851
|
+
const { compactSummarizer } = postAgentCompaction.ok;
|
|
35852
|
+
recordTurnStartupPhase(observability, {
|
|
35853
|
+
phase: "post_agent_preparation",
|
|
35854
|
+
provider: turnExecutionPolicy.providerId,
|
|
35855
|
+
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
35856
|
+
outcome: "completed",
|
|
35857
|
+
durationSeconds: (performance.now() - postAgentPreparationStartedAt) / 1e3
|
|
35617
35858
|
});
|
|
35618
|
-
|
|
35619
|
-
|
|
35620
|
-
|
|
35621
|
-
|
|
35622
|
-
|
|
35623
|
-
fileMaterializationCache = "
|
|
35624
|
-
|
|
35625
|
-
|
|
35626
|
-
|
|
35627
|
-
const materialized = await runWorkspaceMutationForSandbox(
|
|
35628
|
-
sandboxState.resolvedSandbox,
|
|
35629
|
-
"fileMaterialization",
|
|
35630
|
-
async () => await materializeSandboxFileDownloads3(
|
|
35631
|
-
sandboxState.setupBoxSession,
|
|
35632
|
-
downloadsToMaterialize,
|
|
35633
|
-
{
|
|
35634
|
-
onRuntimeEvent: async (event) => {
|
|
35635
|
-
await eventing.publish([{ type: event.type, payload: event.payload }], true);
|
|
35636
|
-
},
|
|
35637
|
-
...runAs ? { runAs } : {},
|
|
35638
|
-
...eventing.toolCancellationFenceRef.current ? {
|
|
35639
|
-
commandRunner: eventing.toolCancellationFenceRef.current.runSandboxCommand.bind(
|
|
35640
|
-
eventing.toolCancellationFenceRef.current
|
|
35641
|
-
)
|
|
35642
|
-
} : {}
|
|
35643
|
-
}
|
|
35644
|
-
)
|
|
35645
|
-
);
|
|
35646
|
-
fileMaterializationFailures = materialized.failures;
|
|
35647
|
-
fileMaterializationOutcome = sandboxFileMaterializationOutcome(materialized.failures);
|
|
35648
|
-
const failedFileIds = new Set(materialized.failures.map((failure) => failure.fileId));
|
|
35649
|
-
const succeededFileIds = downloadsToMaterialize.map((download) => download.fileId).filter((fileId) => !failedFileIds.has(fileId));
|
|
35650
|
-
if (succeededFileIds.length > 0) {
|
|
35651
|
-
await markSandboxFileResourcesMaterialized3(db, {
|
|
35859
|
+
let fileMaterializationFailures = [];
|
|
35860
|
+
let fileDownloadsMaterializedForRun = false;
|
|
35861
|
+
if (sandboxState.resolvedSandbox && sandboxState.setupBoxSession && fileResourceDownloads.length > 0) {
|
|
35862
|
+
const fileMaterializationStartedAt = performance.now();
|
|
35863
|
+
let fileMaterializationOutcome = "completed";
|
|
35864
|
+
let fileMaterializationCache = "miss";
|
|
35865
|
+
try {
|
|
35866
|
+
const boxInstanceId = sandboxState.resolvedSandbox.established.instanceId;
|
|
35867
|
+
const alreadyMaterialized = await getMaterializedSandboxFileResources3(db, {
|
|
35652
35868
|
accountId: input.accountId,
|
|
35653
35869
|
workspaceId: input.workspaceId,
|
|
35654
35870
|
sandboxGroupId: session.sandboxGroupId,
|
|
35655
35871
|
expectedEpoch: sandboxState.resolvedSandbox.leaseEpoch,
|
|
35656
|
-
instanceId: boxInstanceId
|
|
35657
|
-
|
|
35872
|
+
instanceId: boxInstanceId
|
|
35873
|
+
});
|
|
35874
|
+
const downloadsToMaterialize = filterUnmaterializedSandboxFileDownloads(
|
|
35875
|
+
fileResourceDownloads,
|
|
35876
|
+
alreadyMaterialized
|
|
35877
|
+
);
|
|
35878
|
+
if (downloadsToMaterialize.length === 0) {
|
|
35879
|
+
fileMaterializationCache = "hit";
|
|
35880
|
+
}
|
|
35881
|
+
const runAs = sandboxRunAs6(runSettings);
|
|
35882
|
+
if (downloadsToMaterialize.length > 0) {
|
|
35883
|
+
const materialized = await runWorkspaceMutationForSandbox(
|
|
35884
|
+
sandboxState.resolvedSandbox,
|
|
35885
|
+
"fileMaterialization",
|
|
35886
|
+
async () => await materializeSandboxFileDownloads3(
|
|
35887
|
+
sandboxState.setupBoxSession,
|
|
35888
|
+
downloadsToMaterialize,
|
|
35889
|
+
{
|
|
35890
|
+
onRuntimeEvent: async (event) => {
|
|
35891
|
+
await eventing.publish(
|
|
35892
|
+
[{ type: event.type, payload: event.payload }],
|
|
35893
|
+
true
|
|
35894
|
+
);
|
|
35895
|
+
},
|
|
35896
|
+
...runAs ? { runAs } : {},
|
|
35897
|
+
...eventing.toolCancellationFenceRef.current ? {
|
|
35898
|
+
commandRunner: eventing.toolCancellationFenceRef.current.runSandboxCommand.bind(
|
|
35899
|
+
eventing.toolCancellationFenceRef.current
|
|
35900
|
+
)
|
|
35901
|
+
} : {}
|
|
35902
|
+
}
|
|
35903
|
+
)
|
|
35904
|
+
);
|
|
35905
|
+
fileMaterializationFailures = materialized.failures;
|
|
35906
|
+
fileMaterializationOutcome = sandboxFileMaterializationOutcome(
|
|
35907
|
+
materialized.failures
|
|
35908
|
+
);
|
|
35909
|
+
const failedFileIds = new Set(
|
|
35910
|
+
materialized.failures.map((failure) => failure.fileId)
|
|
35911
|
+
);
|
|
35912
|
+
const succeededFileIds = downloadsToMaterialize.map((download) => download.fileId).filter((fileId) => !failedFileIds.has(fileId));
|
|
35913
|
+
if (succeededFileIds.length > 0) {
|
|
35914
|
+
await markSandboxFileResourcesMaterialized3(db, {
|
|
35915
|
+
accountId: input.accountId,
|
|
35916
|
+
workspaceId: input.workspaceId,
|
|
35917
|
+
sandboxGroupId: session.sandboxGroupId,
|
|
35918
|
+
expectedEpoch: sandboxState.resolvedSandbox.leaseEpoch,
|
|
35919
|
+
instanceId: boxInstanceId,
|
|
35920
|
+
fileIds: succeededFileIds
|
|
35921
|
+
});
|
|
35922
|
+
}
|
|
35923
|
+
}
|
|
35924
|
+
fileDownloadsMaterializedForRun = true;
|
|
35925
|
+
} catch (error51) {
|
|
35926
|
+
fileMaterializationOutcome = "failed";
|
|
35927
|
+
throw error51;
|
|
35928
|
+
} finally {
|
|
35929
|
+
recordTurnStartupPhase(observability, {
|
|
35930
|
+
phase: "file_materialization",
|
|
35931
|
+
provider: turnExecutionPolicy.providerId,
|
|
35932
|
+
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
35933
|
+
outcome: fileMaterializationOutcome,
|
|
35934
|
+
durationSeconds: (performance.now() - fileMaterializationStartedAt) / 1e3,
|
|
35935
|
+
count: fileResourceDownloads.length,
|
|
35936
|
+
cache: fileMaterializationCache
|
|
35658
35937
|
});
|
|
35659
35938
|
}
|
|
35939
|
+
} else {
|
|
35940
|
+
recordTurnStartupPhase(observability, {
|
|
35941
|
+
phase: "file_materialization",
|
|
35942
|
+
provider: turnExecutionPolicy.providerId,
|
|
35943
|
+
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
35944
|
+
outcome: "completed",
|
|
35945
|
+
durationSeconds: 0,
|
|
35946
|
+
count: 0
|
|
35947
|
+
});
|
|
35660
35948
|
}
|
|
35661
|
-
|
|
35662
|
-
|
|
35663
|
-
|
|
35664
|
-
|
|
35665
|
-
|
|
35666
|
-
|
|
35667
|
-
|
|
35668
|
-
|
|
35669
|
-
|
|
35670
|
-
|
|
35671
|
-
|
|
35672
|
-
|
|
35673
|
-
|
|
35949
|
+
const requiredVideoFileIds = new Set(
|
|
35950
|
+
requiredGeneratedVideoFiles.map((file2) => file2.fileId)
|
|
35951
|
+
);
|
|
35952
|
+
const failedRequiredVideo = fileMaterializationFailures.find(
|
|
35953
|
+
(failure) => requiredVideoFileIds.has(failure.fileId)
|
|
35954
|
+
);
|
|
35955
|
+
if (failedRequiredVideo) {
|
|
35956
|
+
observability.warn("Generated video sandbox materialization deferred", {
|
|
35957
|
+
errorClass: "SandboxFileDownloadFailure",
|
|
35958
|
+
errorCode: "generated_video_materialization_deferred",
|
|
35959
|
+
origin: "worker"
|
|
35960
|
+
});
|
|
35961
|
+
}
|
|
35962
|
+
const unavailableSandboxFilesNote = sandboxFileDownloadFailureNote(
|
|
35963
|
+
fileMaterializationFailures
|
|
35964
|
+
);
|
|
35965
|
+
return await runTurnStreamAttempt({
|
|
35966
|
+
input,
|
|
35967
|
+
settings: capabilitySettings,
|
|
35968
|
+
db,
|
|
35969
|
+
bus,
|
|
35970
|
+
runtime,
|
|
35971
|
+
objectStorage,
|
|
35972
|
+
observability,
|
|
35973
|
+
entitlements,
|
|
35974
|
+
startVideoGenerationWorkflow,
|
|
35975
|
+
cancellationSignal,
|
|
35976
|
+
runtimeCancellationSignal,
|
|
35977
|
+
activityContext,
|
|
35978
|
+
dispatchId,
|
|
35979
|
+
control,
|
|
35980
|
+
attempt,
|
|
35981
|
+
billingState,
|
|
35982
|
+
sandboxState,
|
|
35983
|
+
eventing: wiredEventing,
|
|
35984
|
+
providerTurn,
|
|
35985
|
+
leases,
|
|
35986
|
+
historySink,
|
|
35987
|
+
media,
|
|
35988
|
+
toolResultSpill,
|
|
35989
|
+
claimedResult,
|
|
35990
|
+
flushRuntimeBatcher,
|
|
35991
|
+
finalizeTurnOpStreamOps,
|
|
35992
|
+
runWorkspaceMutationForSandbox,
|
|
35993
|
+
throwIfWorkerShuttingDown,
|
|
35994
|
+
throwIfTurnCancelled,
|
|
35995
|
+
setLastInputTokensFenced,
|
|
35996
|
+
attachGitCredentialRenewal,
|
|
35997
|
+
attachCodemodeTokenRenewal,
|
|
35998
|
+
attachRunCredentialRenewal,
|
|
35999
|
+
withProviderRequestContext,
|
|
36000
|
+
withSessionTitleProviderRequestContext,
|
|
36001
|
+
publishCompactionLiveEvents,
|
|
36002
|
+
publishCompactionOutcomeEvents,
|
|
36003
|
+
recordCompanyBrainContributionReceiptOnce,
|
|
36004
|
+
modelCheckpointMemoryCollector,
|
|
36005
|
+
claimedModelUsageSourceKeys,
|
|
36006
|
+
emittedModelUsageSourceKeys,
|
|
36007
|
+
modelUsageDispatchId,
|
|
36008
|
+
workerPreparationStartedAt,
|
|
36009
|
+
fileDownloadsMaterializedForRun,
|
|
36010
|
+
unavailableSandboxFilesNote,
|
|
36011
|
+
runCredentialsNote,
|
|
36012
|
+
mcpAvailabilityNote,
|
|
36013
|
+
knowledgeSourcePreparationNote,
|
|
36014
|
+
fileAuthoritySubjectId,
|
|
36015
|
+
activeSandboxBackend,
|
|
36016
|
+
groupBoxBackend,
|
|
36017
|
+
turnExecutionPolicy,
|
|
36018
|
+
turn,
|
|
36019
|
+
trigger,
|
|
36020
|
+
humanInputResume,
|
|
36021
|
+
attachPendingUpdatesAfterOpenSuffix,
|
|
36022
|
+
agent,
|
|
36023
|
+
resolvedModel,
|
|
36024
|
+
providerApi,
|
|
36025
|
+
runSettings,
|
|
36026
|
+
turnTools,
|
|
36027
|
+
generateSessionTitleInParallel,
|
|
36028
|
+
sessionTitlePrompt: session.initialMessage.trim() ? session.initialMessage : turn.prompt,
|
|
36029
|
+
compactSummarizer,
|
|
36030
|
+
settleDeferredSteerAfterCompaction,
|
|
36031
|
+
compactionModelHistoryProjector,
|
|
36032
|
+
generatedImageHistoryProjector,
|
|
36033
|
+
modelHistoryProjector,
|
|
36034
|
+
compactionModeOptions,
|
|
36035
|
+
initialRunCredentialMaterial,
|
|
36036
|
+
initialGitCredentials,
|
|
36037
|
+
sandboxEnvironment,
|
|
36038
|
+
sandboxCodemodeToken,
|
|
36039
|
+
sandboxCodemodeTokenExpiresAt,
|
|
36040
|
+
fileResourceDownloads,
|
|
36041
|
+
runCredentialResolver,
|
|
36042
|
+
videoGenerationAcceptancesByCallId
|
|
35674
36043
|
});
|
|
35675
36044
|
}
|
|
35676
|
-
} else {
|
|
35677
|
-
recordTurnStartupPhase(observability, {
|
|
35678
|
-
phase: "file_materialization",
|
|
35679
|
-
provider: turnExecutionPolicy.providerId,
|
|
35680
|
-
backend: activeSandboxBackend ?? groupBoxBackend,
|
|
35681
|
-
outcome: "completed",
|
|
35682
|
-
durationSeconds: 0,
|
|
35683
|
-
count: 0
|
|
35684
|
-
});
|
|
35685
|
-
}
|
|
35686
|
-
const requiredVideoFileIds = new Set(requiredGeneratedVideoFiles.map((file2) => file2.fileId));
|
|
35687
|
-
const failedRequiredVideo = fileMaterializationFailures.find(
|
|
35688
|
-
(failure) => requiredVideoFileIds.has(failure.fileId)
|
|
35689
36045
|
);
|
|
35690
|
-
if (failedRequiredVideo) {
|
|
35691
|
-
observability.warn("Generated video sandbox materialization deferred", {
|
|
35692
|
-
errorClass: "SandboxFileDownloadFailure",
|
|
35693
|
-
errorCode: "generated_video_materialization_deferred",
|
|
35694
|
-
origin: "worker"
|
|
35695
|
-
});
|
|
35696
|
-
}
|
|
35697
|
-
const unavailableSandboxFilesNote = sandboxFileDownloadFailureNote(
|
|
35698
|
-
fileMaterializationFailures
|
|
35699
|
-
);
|
|
35700
|
-
return await runTurnStreamAttempt({
|
|
35701
|
-
input,
|
|
35702
|
-
settings: capabilitySettings,
|
|
35703
|
-
db,
|
|
35704
|
-
bus,
|
|
35705
|
-
runtime,
|
|
35706
|
-
objectStorage,
|
|
35707
|
-
observability,
|
|
35708
|
-
entitlements,
|
|
35709
|
-
startVideoGenerationWorkflow,
|
|
35710
|
-
cancellationSignal,
|
|
35711
|
-
runtimeCancellationSignal,
|
|
35712
|
-
activityContext,
|
|
35713
|
-
dispatchId,
|
|
35714
|
-
control,
|
|
35715
|
-
attempt,
|
|
35716
|
-
billingState,
|
|
35717
|
-
sandboxState,
|
|
35718
|
-
eventing: wiredEventing,
|
|
35719
|
-
providerTurn,
|
|
35720
|
-
leases,
|
|
35721
|
-
historySink,
|
|
35722
|
-
media,
|
|
35723
|
-
toolResultSpill,
|
|
35724
|
-
claimedResult,
|
|
35725
|
-
flushRuntimeBatcher,
|
|
35726
|
-
finalizeTurnOpStreamOps,
|
|
35727
|
-
runWorkspaceMutationForSandbox,
|
|
35728
|
-
throwIfWorkerShuttingDown,
|
|
35729
|
-
throwIfTurnCancelled,
|
|
35730
|
-
setLastInputTokensFenced,
|
|
35731
|
-
attachGitCredentialRenewal,
|
|
35732
|
-
attachCodemodeTokenRenewal,
|
|
35733
|
-
attachRunCredentialRenewal,
|
|
35734
|
-
withProviderRequestContext,
|
|
35735
|
-
withSessionTitleProviderRequestContext,
|
|
35736
|
-
publishCompactionLiveEvents,
|
|
35737
|
-
publishCompactionOutcomeEvents,
|
|
35738
|
-
recordCompanyBrainContributionReceiptOnce,
|
|
35739
|
-
modelCheckpointMemoryCollector,
|
|
35740
|
-
claimedModelUsageSourceKeys,
|
|
35741
|
-
emittedModelUsageSourceKeys,
|
|
35742
|
-
modelUsageDispatchId,
|
|
35743
|
-
workerPreparationStartedAt,
|
|
35744
|
-
fileDownloadsMaterializedForRun,
|
|
35745
|
-
unavailableSandboxFilesNote,
|
|
35746
|
-
runCredentialsNote,
|
|
35747
|
-
mcpAvailabilityNote,
|
|
35748
|
-
fileAuthoritySubjectId,
|
|
35749
|
-
activeSandboxBackend,
|
|
35750
|
-
groupBoxBackend,
|
|
35751
|
-
turnExecutionPolicy,
|
|
35752
|
-
turn,
|
|
35753
|
-
trigger,
|
|
35754
|
-
humanInputResume,
|
|
35755
|
-
attachPendingUpdatesAfterOpenSuffix,
|
|
35756
|
-
agent,
|
|
35757
|
-
resolvedModel,
|
|
35758
|
-
providerApi,
|
|
35759
|
-
runSettings,
|
|
35760
|
-
turnTools,
|
|
35761
|
-
generateSessionTitleInParallel,
|
|
35762
|
-
sessionTitlePrompt: session.initialMessage.trim() ? session.initialMessage : turn.prompt,
|
|
35763
|
-
compactSummarizer,
|
|
35764
|
-
settleDeferredSteerAfterCompaction,
|
|
35765
|
-
compactionModelHistoryProjector,
|
|
35766
|
-
generatedImageHistoryProjector,
|
|
35767
|
-
modelHistoryProjector,
|
|
35768
|
-
compactionModeOptions,
|
|
35769
|
-
initialRunCredentialMaterial,
|
|
35770
|
-
initialGitCredentials,
|
|
35771
|
-
sandboxEnvironment,
|
|
35772
|
-
sandboxCodemodeToken,
|
|
35773
|
-
sandboxCodemodeTokenExpiresAt,
|
|
35774
|
-
fileResourceDownloads,
|
|
35775
|
-
runCredentialResolver,
|
|
35776
|
-
videoGenerationAcceptancesByCallId
|
|
35777
|
-
});
|
|
35778
36046
|
} catch (error51) {
|
|
35779
36047
|
eventing.preparedTools?.inputWaitYield?.closeAdmission();
|
|
35780
36048
|
return await settleTurnFailure({
|
|
@@ -35856,6 +36124,7 @@ import {
|
|
|
35856
36124
|
markVideoGenerationTerminalUpdate,
|
|
35857
36125
|
markVideoGenerationTerminalUpdateInTransaction,
|
|
35858
36126
|
mediaGenerationResultForStoredOperation,
|
|
36127
|
+
withSessionRlsActorContext as withSessionRlsActorContext2,
|
|
35859
36128
|
rescheduleVideoGenerationOperation,
|
|
35860
36129
|
settleVideoGenerationFailure,
|
|
35861
36130
|
settleVideoGenerationReady
|
|
@@ -36707,7 +36976,13 @@ async function cleanupTerminalReferences(service, operation) {
|
|
|
36707
36976
|
}
|
|
36708
36977
|
}
|
|
36709
36978
|
async function terminalPayload(service, operation) {
|
|
36710
|
-
return
|
|
36979
|
+
return withSessionRlsActorContext2(
|
|
36980
|
+
{
|
|
36981
|
+
subjectId: "service:video-generation-reconciliation",
|
|
36982
|
+
privateFileOwnerSubjectId: operation.privateFileOwnerSubjectId ?? null
|
|
36983
|
+
},
|
|
36984
|
+
() => mediaGenerationResultForStoredOperation(service.db, operation)
|
|
36985
|
+
);
|
|
36711
36986
|
}
|
|
36712
36987
|
async function requireOperation(service, input) {
|
|
36713
36988
|
const operation = await getVideoGenerationOperation2(
|
|
@@ -36927,4 +37202,4 @@ export {
|
|
|
36927
37202
|
createTurnActivities,
|
|
36928
37203
|
createTurnActivitiesFromServices
|
|
36929
37204
|
};
|
|
36930
|
-
//# sourceMappingURL=activities-turn-
|
|
37205
|
+
//# sourceMappingURL=activities-turn-AP67JADS.js.map
|