@opengeni/worker-bundle 0.23.4 → 0.26.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activities/agent-turn/admission.d.ts +17 -2
- package/dist/activities/agent-turn/agent-build.d.ts +3 -10
- package/dist/activities/agent-turn/claim.d.ts +8 -0
- package/dist/activities/agent-turn/codex.d.ts +2 -2
- package/dist/activities/agent-turn/credential-leases.d.ts +8 -0
- package/dist/activities/agent-turn/errors.d.ts +1 -1
- package/dist/activities/agent-turn/failure-settlement.d.ts +43 -1
- package/dist/activities/agent-turn/list-models.d.ts +16 -0
- package/dist/activities/agent-turn/model-usage.d.ts +15 -1
- package/dist/activities/agent-turn/quiescence.d.ts +11 -6
- package/dist/activities/agent-turn/run.d.ts +9 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +15 -0
- package/dist/activities/agent-turn/session-title.d.ts +21 -0
- package/dist/activities/agent-turn/stream-attempt.d.ts +4 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +4 -13
- package/dist/activities/agent-turn/tool-policy.d.ts +40 -5
- package/dist/activities/agent-turn/turn-context.d.ts +13 -2
- package/dist/activities/agent-turn.d.ts +1 -1
- package/dist/activities/automations.d.ts +1 -0
- package/dist/activities/capabilities.d.ts +3 -1
- package/dist/activities/codemode-dispatcher.d.ts +10 -1
- package/dist/activities/codex-capacity.d.ts +32 -3
- package/dist/activities/codex-fleet-shadow.d.ts +1 -1
- package/dist/activities/codex-image-generation.d.ts +1 -1
- package/dist/activities/codex-rotation.d.ts +8 -67
- package/dist/activities/context-compaction.d.ts +2 -0
- package/dist/activities/goals.d.ts +12 -1
- package/dist/activities/google-drive-publication.d.ts +2 -13
- package/dist/activities/image-generation-operation.d.ts +13 -4
- package/dist/activities/image-generation-references.d.ts +2 -1
- package/dist/activities/scheduled-tasks.d.ts +1 -0
- package/dist/activities/session-state.d.ts +4 -2
- package/dist/activities/types.d.ts +19 -1
- package/dist/{activities-control-52W5IDWM.js → activities-control-CTEMLTHG.js} +339 -195
- package/dist/activities-control-CTEMLTHG.js.map +1 -0
- package/dist/activities-control.d.ts +4 -0
- package/dist/{activities-turn-A2G2KLSY.js → activities-turn-S5IU347A.js} +1846 -1136
- package/dist/activities-turn-S5IU347A.js.map +1 -0
- package/dist/activities.d.ts +4 -0
- package/dist/{chunk-GFNXVZVQ.js → chunk-D4ZEFOYH.js} +107 -7
- package/dist/chunk-D4ZEFOYH.js.map +1 -0
- package/dist/{chunk-GRFQTTSQ.js → chunk-GDCLDKSH.js} +7 -3
- package/dist/{chunk-GRFQTTSQ.js.map → chunk-GDCLDKSH.js.map} +1 -1
- package/dist/{chunk-IPVMCAW5.js → chunk-TAUE3GYT.js} +225 -154
- package/dist/chunk-TAUE3GYT.js.map +1 -0
- package/dist/github-rest-mcp.d.ts +0 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +43 -7
- package/dist/index.js.map +1 -1
- package/dist/observability-metrics.d.ts +35 -8
- package/dist/sandbox-reaper-timeout.d.ts +2 -2
- package/dist/sandbox-resume.d.ts +6 -1
- package/dist/workflow-bundle.js +96 -10
- package/dist/workflows/activities.d.ts +6 -1
- package/dist/workflows/automations.d.ts +5 -0
- package/dist/workflows/session.d.ts +3 -0
- package/package.json +17 -17
- package/src/activities/agent-run-admission.ts +7 -1
- package/src/activities/agent-turn/admission.ts +47 -6
- package/src/activities/agent-turn/agent-build.ts +20 -26
- package/src/activities/agent-turn/claim.ts +59 -6
- package/src/activities/agent-turn/codex-capacity.ts +311 -234
- package/src/activities/agent-turn/codex.ts +2 -2
- package/src/activities/agent-turn/compaction-prep.ts +8 -1
- package/src/activities/agent-turn/credential-leases.ts +36 -0
- package/src/activities/agent-turn/errors.ts +29 -1
- package/src/activities/agent-turn/failure-settlement.ts +451 -323
- package/src/activities/agent-turn/finalization.ts +31 -17
- package/src/activities/agent-turn/list-models.ts +101 -0
- package/src/activities/agent-turn/model-usage.ts +120 -45
- package/src/activities/agent-turn/quiescence.ts +32 -17
- package/src/activities/agent-turn/run.ts +98 -9
- package/src/activities/agent-turn/sandbox-runtime.ts +78 -81
- package/src/activities/agent-turn/session-title.ts +55 -2
- package/src/activities/agent-turn/stream-attempt.ts +281 -136
- package/src/activities/agent-turn/tool-environment.ts +132 -39
- package/src/activities/agent-turn/tool-policy.ts +71 -12
- package/src/activities/agent-turn/turn-context.ts +21 -2
- package/src/activities/agent-turn.ts +5 -1
- package/src/activities/automations.ts +122 -67
- package/src/activities/capabilities.ts +129 -2
- package/src/activities/codemode-dispatcher.ts +235 -59
- package/src/activities/codex-capacity.ts +89 -10
- package/src/activities/codex-fleet-shadow.ts +8 -1
- package/src/activities/codex-image-generation.ts +19 -2
- package/src/activities/codex-rotation.ts +45 -142
- package/src/activities/context-compaction.ts +3 -0
- package/src/activities/goals.ts +116 -39
- package/src/activities/google-drive-publication.ts +4 -81
- package/src/activities/image-generation-operation.ts +28 -3
- package/src/activities/image-generation-references.ts +9 -9
- package/src/activities/mcp-credentials.ts +53 -0
- package/src/activities/rig-verification.ts +5 -3
- package/src/activities/sandbox-lease.ts +29 -12
- package/src/activities/scheduled-tasks.ts +217 -110
- package/src/activities/session-state.ts +17 -0
- package/src/activities/site-auth-maintenance.ts +12 -12
- package/src/activities/types.ts +22 -8
- package/src/activities.ts +2 -0
- package/src/activity-services.ts +4 -1
- package/src/github-rest-mcp.ts +2 -83
- package/src/index.ts +34 -4
- package/src/observability-metrics.ts +158 -14
- package/src/sandbox-reaper-timeout.ts +10 -4
- package/src/sandbox-resume.ts +58 -8
- package/src/sandbox-routing.ts +71 -16
- package/src/workflows/activities.ts +16 -0
- package/src/workflows/automations.ts +21 -2
- package/src/workflows/session.ts +85 -7
- package/dist/activities/api-integrations.d.ts +0 -21
- package/dist/activities-control-52W5IDWM.js.map +0 -1
- package/dist/activities-turn-A2G2KLSY.js.map +0 -1
- package/dist/chunk-GFNXVZVQ.js.map +0 -1
- package/dist/chunk-IPVMCAW5.js.map +0 -1
- package/src/activities/api-integrations.ts +0 -141
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
+
beginConnectorActionExecution,
|
|
3
|
+
completeConnectorActionExecution,
|
|
2
4
|
getScheduledVariableSetExpectedGenerationForAttempt,
|
|
5
|
+
getWorkspaceModelPolicy,
|
|
6
|
+
listWorkspaceGatewayCustomModels,
|
|
7
|
+
listWorkspaceOpenRouterCustomModels,
|
|
8
|
+
listOrganizationModelProviderCustomModelsForWorkspace,
|
|
9
|
+
organizationModelProviderConnectionActiveForWorkspace,
|
|
3
10
|
persistAttemptToolCatalog,
|
|
11
|
+
prepareConnectorActionApproval,
|
|
12
|
+
previewConnectorActionApproval,
|
|
4
13
|
namedSubjectHasLiveWorkspaceAuthority,
|
|
5
14
|
updateSessionTitleWithEvent,
|
|
6
15
|
withCodexAppsRequestAuthorization,
|
|
16
|
+
workspaceCodexSubscriptionActive,
|
|
17
|
+
workspaceVercelAiGatewayConnectionActive,
|
|
18
|
+
workspaceOpenRouterConnectionActive,
|
|
19
|
+
workspaceXaiSubscriptionActiveForAuthority,
|
|
7
20
|
} from "@opengeni/db";
|
|
8
21
|
import { publishDurableSessionEvents } from "@opengeni/events";
|
|
9
22
|
import {
|
|
10
23
|
type OpenGeniRuntime,
|
|
11
24
|
type AttemptConnectorActionBinding,
|
|
12
25
|
type ConnectorAttachmentMaterializationRequest,
|
|
26
|
+
type ConnectorActionPolicyHooks,
|
|
13
27
|
createFirstPartyInteractionAttemptToolDefinitions,
|
|
14
28
|
} from "@opengeni/runtime";
|
|
15
29
|
import {
|
|
16
|
-
authorizeGoogleDrivePublicationAttempt,
|
|
17
30
|
createGoogleDrivePublicationAttemptTool,
|
|
18
31
|
googleDrivePublicationConnectorCall,
|
|
19
32
|
resolveGoogleDrivePublicationTarget,
|
|
20
33
|
} from "../google-drive-publication";
|
|
21
34
|
import { connectionTokenResolverForTurn } from "../mcp-credentials";
|
|
22
|
-
import { buildApiIntegrationServersForTurn } from "../api-integrations";
|
|
23
35
|
import { buildGitHubRestMcpForTurn } from "../../github-rest-mcp";
|
|
24
36
|
import { materializeConnectorAttachmentsInChannel } from "../connector-attachments";
|
|
25
37
|
import { allowedFirstPartyMcpToolsForSession, type Settings } from "@opengeni/config";
|
|
@@ -31,6 +43,9 @@ import {
|
|
|
31
43
|
defaultSessionMcpServerIds,
|
|
32
44
|
loadRigDefaultVariableSetEnvironment,
|
|
33
45
|
mergeRigDefaultVariableSetEnvironment,
|
|
46
|
+
buildApiIntegrationMcpServers,
|
|
47
|
+
resolveCatalogSettings,
|
|
48
|
+
resolveWorkspaceModelSelection,
|
|
34
49
|
withFrozenPersonalConnectionDelegations,
|
|
35
50
|
resolveSessionToolPolicy,
|
|
36
51
|
} from "@opengeni/core";
|
|
@@ -44,7 +59,11 @@ import { SandboxChannelAService } from "@opengeni/runtime/sandbox";
|
|
|
44
59
|
import { sandboxRunAs } from "@opengeni/runtime";
|
|
45
60
|
import { type ToolAuthNeededPayload } from "@opengeni/contracts";
|
|
46
61
|
|
|
47
|
-
import {
|
|
62
|
+
import {
|
|
63
|
+
rollingSafeToolAuthNeededPayload,
|
|
64
|
+
shouldPublishToolAuthNeededForTurn,
|
|
65
|
+
xaiCatalogReadinessAuthority,
|
|
66
|
+
} from "./admission";
|
|
48
67
|
import { unavailableMcpOperationalContext } from "./errors";
|
|
49
68
|
import { runtimeResourcesForTurn } from "./file-resources";
|
|
50
69
|
import { waitForTurnOperation } from "./sandbox-provision";
|
|
@@ -65,6 +84,7 @@ import {
|
|
|
65
84
|
shouldRequestMissingSessionTitle,
|
|
66
85
|
} from "./session-title";
|
|
67
86
|
import { resolveTurnSandboxAccess } from "./turn-sandbox-access";
|
|
87
|
+
import { createListModelsAttemptToolDefinition } from "./list-models";
|
|
68
88
|
|
|
69
89
|
export type PrepareTurnToolPolicyDeps = {
|
|
70
90
|
input: RunAgentTurnInput;
|
|
@@ -82,6 +102,7 @@ export type PrepareTurnToolPolicyDeps = {
|
|
|
82
102
|
|
|
83
103
|
export type PrepareTurnToolRuntimeDeps = {
|
|
84
104
|
input: RunAgentTurnInput;
|
|
105
|
+
catalogSourceSettings: Settings;
|
|
85
106
|
db: ActivityServices["db"];
|
|
86
107
|
bus: ActivityServices["bus"];
|
|
87
108
|
runtime: ActivityServices["runtime"];
|
|
@@ -296,6 +317,7 @@ export async function prepareTurnToolPolicy(deps: PrepareTurnToolPolicyDeps) {
|
|
|
296
317
|
export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
297
318
|
const {
|
|
298
319
|
input,
|
|
320
|
+
catalogSourceSettings,
|
|
299
321
|
db,
|
|
300
322
|
bus,
|
|
301
323
|
runtime,
|
|
@@ -415,10 +437,13 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
415
437
|
if (!shouldPublishToolAuthNeededForTurn(payload, trigger, turn)) {
|
|
416
438
|
return;
|
|
417
439
|
}
|
|
418
|
-
await eventing.publish!(
|
|
440
|
+
await eventing.publish!(
|
|
441
|
+
[{ type: "tool.auth_needed", payload: rollingSafeToolAuthNeededPayload(payload) }],
|
|
442
|
+
true,
|
|
443
|
+
);
|
|
419
444
|
};
|
|
420
445
|
const selectedApiIntegrationServerIds = new Set(turnTools.map((tool) => tool.id));
|
|
421
|
-
const apiIntegrationMcpServers =
|
|
446
|
+
const apiIntegrationMcpServers = buildApiIntegrationMcpServers({
|
|
422
447
|
settings: runSettings,
|
|
423
448
|
integrations: installedApiIntegrations.filter((integration) =>
|
|
424
449
|
selectedApiIntegrationServerIds.has(integration.serverId),
|
|
@@ -488,6 +513,7 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
488
513
|
firstPartyMcpTools: selectedFirstPartyMcpTools,
|
|
489
514
|
firstPartyMcpPermissions: session.firstPartyMcpPermissions,
|
|
490
515
|
}),
|
|
516
|
+
parallelGenerationAvailable: typeof runtime.generateSessionTitle === "function",
|
|
491
517
|
});
|
|
492
518
|
const googleDrivePublicationAllowed =
|
|
493
519
|
selectedFirstPartyMcpTools.includes("editable_artifact_export") &&
|
|
@@ -509,7 +535,103 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
509
535
|
},
|
|
510
536
|
]
|
|
511
537
|
: [];
|
|
538
|
+
const attemptConnectorActionBindings = [
|
|
539
|
+
...googleDriveConnectorBindings,
|
|
540
|
+
...githubRestMcp.connectorBindings,
|
|
541
|
+
];
|
|
542
|
+
const connectorActionPolicy: ConnectorActionPolicyHooks = {
|
|
543
|
+
preview: async (call) =>
|
|
544
|
+
await previewConnectorActionApproval(db, connectorActionIdentity, call),
|
|
545
|
+
prepare: async (call) =>
|
|
546
|
+
await prepareConnectorActionApproval(db, connectorActionIdentity, call),
|
|
547
|
+
begin: async (call) => await beginConnectorActionExecution(db, connectorActionIdentity, call),
|
|
548
|
+
complete: async ({ requestId, outcome }) =>
|
|
549
|
+
await completeConnectorActionExecution(db, {
|
|
550
|
+
accountId: input.accountId,
|
|
551
|
+
workspaceId: input.workspaceId,
|
|
552
|
+
requestId,
|
|
553
|
+
attemptId: input.attemptId,
|
|
554
|
+
outcome,
|
|
555
|
+
}),
|
|
556
|
+
};
|
|
512
557
|
const attemptToolDefinitions = [
|
|
558
|
+
createListModelsAttemptToolDefinition({
|
|
559
|
+
currentModelId: turnExecutionPolicy.productModelId,
|
|
560
|
+
load: async () => {
|
|
561
|
+
const currentCatalog = await resolveCatalogSettings(db, catalogSourceSettings);
|
|
562
|
+
const currentSettings = currentCatalog.settings;
|
|
563
|
+
const xaiReadinessAuthority = xaiCatalogReadinessAuthority(turn, credentialSubjectId);
|
|
564
|
+
const [
|
|
565
|
+
policy,
|
|
566
|
+
codexSubscriptionActive,
|
|
567
|
+
xaiSubscriptionActive,
|
|
568
|
+
workspaceGatewayConnectionActive,
|
|
569
|
+
workspaceGatewayCustomModels,
|
|
570
|
+
openRouterConnectionActive,
|
|
571
|
+
workspaceOpenRouterCustomModels,
|
|
572
|
+
organizationGatewayConnectionActive,
|
|
573
|
+
organizationGatewayCustomModels,
|
|
574
|
+
organizationOpenRouterConnectionActive,
|
|
575
|
+
organizationOpenRouterCustomModels,
|
|
576
|
+
] = await Promise.all([
|
|
577
|
+
getWorkspaceModelPolicy(db, input.workspaceId),
|
|
578
|
+
workspaceCodexSubscriptionActive(db, currentSettings, input.workspaceId),
|
|
579
|
+
xaiReadinessAuthority && currentSettings.supergrokSubscriptionEnabled
|
|
580
|
+
? workspaceXaiSubscriptionActiveForAuthority(db, currentSettings, {
|
|
581
|
+
workspaceId: input.workspaceId,
|
|
582
|
+
...xaiReadinessAuthority,
|
|
583
|
+
})
|
|
584
|
+
: false,
|
|
585
|
+
workspaceVercelAiGatewayConnectionActive(db, input.workspaceId),
|
|
586
|
+
listWorkspaceGatewayCustomModels(db, {
|
|
587
|
+
accountId: input.accountId,
|
|
588
|
+
workspaceId: input.workspaceId,
|
|
589
|
+
}),
|
|
590
|
+
workspaceOpenRouterConnectionActive(db, input.workspaceId),
|
|
591
|
+
listWorkspaceOpenRouterCustomModels(db, {
|
|
592
|
+
accountId: input.accountId,
|
|
593
|
+
workspaceId: input.workspaceId,
|
|
594
|
+
}),
|
|
595
|
+
organizationModelProviderConnectionActiveForWorkspace(db, {
|
|
596
|
+
accountId: input.accountId,
|
|
597
|
+
workspaceId: input.workspaceId,
|
|
598
|
+
providerKind: "vercel_gateway",
|
|
599
|
+
}),
|
|
600
|
+
listOrganizationModelProviderCustomModelsForWorkspace(db, {
|
|
601
|
+
accountId: input.accountId,
|
|
602
|
+
workspaceId: input.workspaceId,
|
|
603
|
+
providerKind: "vercel_gateway",
|
|
604
|
+
}),
|
|
605
|
+
organizationModelProviderConnectionActiveForWorkspace(db, {
|
|
606
|
+
accountId: input.accountId,
|
|
607
|
+
workspaceId: input.workspaceId,
|
|
608
|
+
providerKind: "openrouter",
|
|
609
|
+
}),
|
|
610
|
+
listOrganizationModelProviderCustomModelsForWorkspace(db, {
|
|
611
|
+
accountId: input.accountId,
|
|
612
|
+
workspaceId: input.workspaceId,
|
|
613
|
+
providerKind: "openrouter",
|
|
614
|
+
}),
|
|
615
|
+
]);
|
|
616
|
+
return {
|
|
617
|
+
selections: resolveWorkspaceModelSelection({
|
|
618
|
+
settings: currentSettings,
|
|
619
|
+
policy,
|
|
620
|
+
codexSubscriptionActive,
|
|
621
|
+
xaiSubscriptionActive,
|
|
622
|
+
workspaceGatewayConnectionActive,
|
|
623
|
+
workspaceGatewayCustomModels,
|
|
624
|
+
workspaceOpenRouterConnectionActive: openRouterConnectionActive,
|
|
625
|
+
workspaceOpenRouterCustomModels,
|
|
626
|
+
organizationGatewayConnectionActive,
|
|
627
|
+
organizationGatewayCustomModels,
|
|
628
|
+
organizationOpenRouterConnectionActive,
|
|
629
|
+
organizationOpenRouterCustomModels,
|
|
630
|
+
}),
|
|
631
|
+
modelNotes: currentCatalog.modelNotes,
|
|
632
|
+
};
|
|
633
|
+
},
|
|
634
|
+
}),
|
|
513
635
|
...(titleToolPlan.promoteTitleTool
|
|
514
636
|
? [
|
|
515
637
|
createSessionTitleAttemptToolDefinition({
|
|
@@ -661,30 +783,8 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
661
783
|
nestedAgentDepth: session.nestedAgentDepth,
|
|
662
784
|
effectiveMaxNestedAgentDepth: session.effectiveMaxNestedAgentDepth,
|
|
663
785
|
attemptToolDefinitions,
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
? {
|
|
667
|
-
attemptToolAuthorize: async (authorization) => {
|
|
668
|
-
const { call } = authorization;
|
|
669
|
-
if (
|
|
670
|
-
googleDrivePublicationTarget &&
|
|
671
|
-
googleDrivePublicationAllowed &&
|
|
672
|
-
call.caller.kind === "codemode" &&
|
|
673
|
-
call.identity.serverId === "google-drive-publishing" &&
|
|
674
|
-
call.identity.toolName === "google_drive_publish_file"
|
|
675
|
-
) {
|
|
676
|
-
await authorizeGoogleDrivePublicationAttempt({
|
|
677
|
-
db,
|
|
678
|
-
identity: connectorActionIdentity,
|
|
679
|
-
target: googleDrivePublicationTarget,
|
|
680
|
-
approvalId: call.operationId,
|
|
681
|
-
arguments: call.arguments,
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
await githubRestMcp.authorizeCodemodeCall?.(authorization);
|
|
685
|
-
},
|
|
686
|
-
}
|
|
687
|
-
: {}),
|
|
786
|
+
connectorActionPolicy,
|
|
787
|
+
attemptConnectorActionBindings,
|
|
688
788
|
}),
|
|
689
789
|
cancellationSignal,
|
|
690
790
|
async (latePreparedTools) => await latePreparedTools.close().catch(() => undefined),
|
|
@@ -755,17 +855,10 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
|
|
|
755
855
|
} else {
|
|
756
856
|
activatePreparedToolEnvironment(eventing.preparedTools);
|
|
757
857
|
}
|
|
758
|
-
// Genesis turn = the first user turn (no assistant history reconciled
|
|
759
|
-
// yet). Durable Postgres state (countSessionHistoryItems includes
|
|
760
|
-
// superseded rows after compaction), NOT a workflow counter (turnsThisRun
|
|
761
|
-
// resets on continueAsNew). Drives the one-shot title hint appended to the
|
|
762
|
-
// agent's instructions; later attempts and goal continuations never match.
|
|
763
858
|
return {
|
|
764
|
-
attemptConnectorActionBindings
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
],
|
|
768
|
-
connectorActionIdentity,
|
|
859
|
+
attemptConnectorActionBindings,
|
|
860
|
+
connectorActionPolicy,
|
|
861
|
+
generateSessionTitleInParallel: titleToolPlan.generateTitleInParallel,
|
|
769
862
|
postToolPreparationStartedAt,
|
|
770
863
|
preparationIndependentToolNames: titleToolPlan.preparationIndependentToolNames,
|
|
771
864
|
};
|
|
@@ -1,27 +1,86 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
desktopCapableBackend,
|
|
3
|
+
type ComputerToolMode,
|
|
4
|
+
type LazyToolTransport,
|
|
5
|
+
} from "@opengeni/runtime";
|
|
2
6
|
import {
|
|
3
7
|
isDirectOpenAiApiBaseUrl,
|
|
4
8
|
type ModelProviderApi,
|
|
5
|
-
type
|
|
9
|
+
type ResolvedModelProvider,
|
|
6
10
|
type Settings,
|
|
7
11
|
} from "@opengeni/config";
|
|
8
12
|
import { type ModelAttachmentInputPolicy } from "../run-input";
|
|
9
13
|
import { imageProviderBindingHash } from "../image-generation-operation";
|
|
10
14
|
|
|
15
|
+
export function shouldStartOnTurnRecording(params: {
|
|
16
|
+
recordingEnabled: boolean;
|
|
17
|
+
desktopEnabled: boolean;
|
|
18
|
+
establishedBackendId: string;
|
|
19
|
+
effectiveBackend: Settings["sandboxBackend"] | undefined;
|
|
20
|
+
}): boolean {
|
|
21
|
+
return (
|
|
22
|
+
params.recordingEnabled &&
|
|
23
|
+
params.desktopEnabled &&
|
|
24
|
+
desktopCapableBackend(params.establishedBackendId) &&
|
|
25
|
+
params.effectiveBackend !== "selfhosted"
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Decide the EXPLICIT computer-use tool transport for THIS turn.
|
|
31
|
+
*
|
|
32
|
+
* Computer-use is ordinary `computer_*` function tools bound to the live
|
|
33
|
+
* desktop. The worker picks the mode from the resolved provider so the runtime
|
|
34
|
+
* never string-sniffs the model instance:
|
|
35
|
+
* • catalogue `inputModalities` must include `image`, or computer-use is off
|
|
36
|
+
* • Responses wires (Azure/OpenAI, Gateway, Codex, legacy client) →
|
|
37
|
+
* "function-image": screenshot results are structured `{type:'image'}`
|
|
38
|
+
* • Chat Completions → "disabled": tool results on that wire are text, so a
|
|
39
|
+
* screenshot would become a base64 string rather than an image the model sees
|
|
40
|
+
*
|
|
41
|
+
* Pure + exported so the mapping is unit-testable without a live turn.
|
|
42
|
+
*/
|
|
43
|
+
export function computerToolModeForTurn(
|
|
44
|
+
resolvedModel: {
|
|
45
|
+
provider: { kind: ResolvedModelProvider["kind"]; api: ModelProviderApi };
|
|
46
|
+
configured: { capabilities: { inputModalities: string[] } };
|
|
47
|
+
} | null,
|
|
48
|
+
): ComputerToolMode {
|
|
49
|
+
if (!resolvedModel) {
|
|
50
|
+
return "function-image";
|
|
51
|
+
}
|
|
52
|
+
if (!modelSupportsImageInputForTurn(resolvedModel)) {
|
|
53
|
+
return "disabled";
|
|
54
|
+
}
|
|
55
|
+
if (resolvedModel.provider.kind === "codex-subscription") {
|
|
56
|
+
return "function-image";
|
|
57
|
+
}
|
|
58
|
+
if (resolvedModel.provider.api === "chat") {
|
|
59
|
+
return "disabled";
|
|
60
|
+
}
|
|
61
|
+
return "function-image";
|
|
62
|
+
}
|
|
63
|
+
|
|
11
64
|
/** Chat wires and Gateway models do not advertise OpenAI's hosted sandbox tool types. */
|
|
12
65
|
export function structuredToolTransportForTurn(
|
|
13
66
|
resolvedModel: {
|
|
14
|
-
provider: {
|
|
67
|
+
provider: {
|
|
68
|
+
id: string;
|
|
69
|
+
kind: ResolvedModelProvider["kind"];
|
|
70
|
+
api: ModelProviderApi;
|
|
71
|
+
wireProfile: "openai" | "azure-openai";
|
|
72
|
+
builtin: boolean;
|
|
73
|
+
baseUrl?: string | undefined;
|
|
74
|
+
};
|
|
15
75
|
} | null,
|
|
16
76
|
): boolean {
|
|
17
77
|
if (!resolvedModel) return true;
|
|
18
|
-
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
].includes(resolvedModel.provider.kind);
|
|
78
|
+
const provider = resolvedModel.provider;
|
|
79
|
+
if (provider.api === "chat" || provider.kind === "codex-subscription") return false;
|
|
80
|
+
return (
|
|
81
|
+
provider.wireProfile === "azure-openai" ||
|
|
82
|
+
(provider.builtin && provider.id === "openai" && provider.baseUrl === undefined)
|
|
83
|
+
);
|
|
25
84
|
}
|
|
26
85
|
|
|
27
86
|
/**
|
|
@@ -34,7 +93,7 @@ export function lazyToolTransportForTurn(
|
|
|
34
93
|
resolvedModel: {
|
|
35
94
|
provider: {
|
|
36
95
|
id: string;
|
|
37
|
-
kind:
|
|
96
|
+
kind: ResolvedModelProvider["kind"];
|
|
38
97
|
api: ModelProviderApi;
|
|
39
98
|
wireProfile: "openai" | "azure-openai";
|
|
40
99
|
builtin: boolean;
|
|
@@ -108,7 +167,7 @@ export function openAiHostedImageProviderBindingForTurn(
|
|
|
108
167
|
resolvedModel: {
|
|
109
168
|
provider: {
|
|
110
169
|
id: string;
|
|
111
|
-
kind:
|
|
170
|
+
kind: ResolvedModelProvider["kind"];
|
|
112
171
|
builtin: boolean;
|
|
113
172
|
baseUrl?: string | undefined;
|
|
114
173
|
};
|
|
@@ -2,6 +2,7 @@ import type { Settings } from "@opengeni/config";
|
|
|
2
2
|
import type { CodexUsageHeaderSnapshot } from "@opengeni/codex";
|
|
3
3
|
import type { AppendEventInput, ApplySessionTurnSettlementInput } from "@opengeni/db";
|
|
4
4
|
import type {
|
|
5
|
+
CodexCredentialPolicySnapshotV1,
|
|
5
6
|
ModelContextContributionSummary,
|
|
6
7
|
SessionStatus,
|
|
7
8
|
XaiProviderAccountAuthoritySnapshotV1,
|
|
@@ -45,6 +46,7 @@ export type TurnSettleFn = (input: {
|
|
|
45
46
|
| "requires_action";
|
|
46
47
|
sessionStatus: SessionStatus;
|
|
47
48
|
activeTurnId: string | null;
|
|
49
|
+
suppressGoalContinuation?: boolean;
|
|
48
50
|
consumeRequestedCompactionFailure?: boolean;
|
|
49
51
|
runState?: ApplySessionTurnSettlementInput["runState"];
|
|
50
52
|
}) => Promise<boolean>;
|
|
@@ -59,6 +61,7 @@ export type TurnControlState = {
|
|
|
59
61
|
|
|
60
62
|
export type AttemptIdentityState = {
|
|
61
63
|
turnId: string | undefined;
|
|
64
|
+
dispatchId: string;
|
|
62
65
|
triggerEventId: string | undefined;
|
|
63
66
|
executionGeneration: number;
|
|
64
67
|
providerRecoveryCount: number;
|
|
@@ -73,6 +76,8 @@ export type BillingState = {
|
|
|
73
76
|
isCodexTurn: boolean;
|
|
74
77
|
isXaiTurn: boolean;
|
|
75
78
|
isExternallyBilledTurn: boolean;
|
|
79
|
+
chargesOpenGeniCredits: boolean;
|
|
80
|
+
countsTowardTokenCap: boolean;
|
|
76
81
|
};
|
|
77
82
|
|
|
78
83
|
export type SandboxRuntimeState = {
|
|
@@ -95,7 +100,8 @@ export type SandboxRuntimeState = {
|
|
|
95
100
|
sandboxHolderId: TurnSandboxLeaseHolderId | null;
|
|
96
101
|
sandboxGroupId: string | null;
|
|
97
102
|
leaseHeartbeatTimer: ReturnType<typeof setInterval> | undefined;
|
|
98
|
-
|
|
103
|
+
rotationPreemptionInFlight: Promise<void> | null;
|
|
104
|
+
deadlineRotationRequested: boolean;
|
|
99
105
|
snapshotInFlight: Promise<void> | null;
|
|
100
106
|
firstProviderRequestStarted: boolean;
|
|
101
107
|
turnEndCaptureInProgress: boolean;
|
|
@@ -147,6 +153,12 @@ export type ProviderTurnState = {
|
|
|
147
153
|
// The Codex account this turn runs on (pin > workspace active), resolved once
|
|
148
154
|
// a codex-billed turn is confirmed and threaded into the token resolver.
|
|
149
155
|
effectiveCodexCredentialId: string | null;
|
|
156
|
+
/** Exact row version returned by the resolver for the latest provider request. */
|
|
157
|
+
effectiveCodexCredentialVersion: number | null;
|
|
158
|
+
/** Frozen alternate-account ceiling observed by the fenced allocator. */
|
|
159
|
+
codexCredentialFailoverLimit: number;
|
|
160
|
+
/** Accepted Codex allocator policy captured with the first durable lease. */
|
|
161
|
+
codexPolicySnapshot: CodexCredentialPolicySnapshotV1 | null;
|
|
150
162
|
effectiveXaiCredentialId: string | null;
|
|
151
163
|
xaiRotationEnabled: boolean;
|
|
152
164
|
xaiAuthoritySnapshot: XaiProviderAccountAuthoritySnapshotV1 | null;
|
|
@@ -193,6 +205,7 @@ export function createTurnContext(input: {
|
|
|
193
205
|
},
|
|
194
206
|
attempt: {
|
|
195
207
|
turnId: undefined,
|
|
208
|
+
dispatchId: "",
|
|
196
209
|
triggerEventId: undefined,
|
|
197
210
|
executionGeneration: 0,
|
|
198
211
|
providerRecoveryCount: 0,
|
|
@@ -204,6 +217,8 @@ export function createTurnContext(input: {
|
|
|
204
217
|
isCodexTurn: false,
|
|
205
218
|
isXaiTurn: false,
|
|
206
219
|
isExternallyBilledTurn: false,
|
|
220
|
+
chargesOpenGeniCredits: true,
|
|
221
|
+
countsTowardTokenCap: true,
|
|
207
222
|
},
|
|
208
223
|
sandboxState: {
|
|
209
224
|
resolvedSandbox: null,
|
|
@@ -221,7 +236,8 @@ export function createTurnContext(input: {
|
|
|
221
236
|
sandboxHolderId: null,
|
|
222
237
|
sandboxGroupId: null,
|
|
223
238
|
leaseHeartbeatTimer: undefined,
|
|
224
|
-
|
|
239
|
+
rotationPreemptionInFlight: null,
|
|
240
|
+
deadlineRotationRequested: false,
|
|
225
241
|
snapshotInFlight: null,
|
|
226
242
|
firstProviderRequestStarted: false,
|
|
227
243
|
turnEndCaptureInProgress: false,
|
|
@@ -262,6 +278,9 @@ export function createTurnContext(input: {
|
|
|
262
278
|
},
|
|
263
279
|
providerTurn: {
|
|
264
280
|
effectiveCodexCredentialId: null,
|
|
281
|
+
effectiveCodexCredentialVersion: null,
|
|
282
|
+
codexCredentialFailoverLimit: 1,
|
|
283
|
+
codexPolicySnapshot: null,
|
|
265
284
|
effectiveXaiCredentialId: null,
|
|
266
285
|
xaiRotationEnabled: false,
|
|
267
286
|
xaiAuthoritySnapshot: null,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/** Public agent-turn surface. Implementation lives in `./agent-turn/*`. */
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
createRunAgentTurnActivity,
|
|
4
|
+
sessionTitleCodexRequestContext,
|
|
5
|
+
sessionTitleXaiRequestContext,
|
|
6
|
+
} from "./agent-turn/run";
|
|
3
7
|
export * from "./agent-turn/admission";
|
|
4
8
|
export * from "./agent-turn/codex";
|
|
5
9
|
export * from "./agent-turn/errors";
|