@opengeni/worker-bundle 0.23.4-canary.0 → 0.24.2-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 +7 -0
- package/dist/activities/agent-turn/model-usage.d.ts +5 -0
- package/dist/activities/agent-turn/quiescence.d.ts +2 -0
- 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 +1 -0
- package/dist/activities/agent-turn/turn-context.d.ts +2 -1
- package/dist/activities/agent-turn.d.ts +1 -1
- package/dist/activities/capabilities.d.ts +1 -0
- package/dist/activities/context-compaction.d.ts +2 -0
- package/dist/{activities-control-SGU2WEVB.js → activities-control-ZWH7J4KZ.js} +102 -94
- package/dist/activities-control-ZWH7J4KZ.js.map +1 -0
- package/dist/{activities-turn-7EAQXW6Q.js → activities-turn-I4OPLQLS.js} +613 -284
- package/dist/activities-turn-I4OPLQLS.js.map +1 -0
- package/dist/{chunk-TJIPCHMP.js → chunk-65JEWP2Q.js} +105 -6
- package/dist/chunk-65JEWP2Q.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-S2QVRVJW.js → chunk-RQNH6CGR.js} +28 -41
- package/dist/chunk-RQNH6CGR.js.map +1 -0
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/dist/observability-metrics.d.ts +33 -7
- package/dist/sandbox-reaper-timeout.d.ts +2 -2
- package/dist/sandbox-resume.d.ts +6 -1
- package/package.json +17 -17
- package/src/activities/agent-turn/admission.ts +19 -0
- package/src/activities/agent-turn/claim.ts +9 -1
- package/src/activities/agent-turn/compaction-prep.ts +6 -1
- package/src/activities/agent-turn/finalization.ts +31 -17
- package/src/activities/agent-turn/model-usage.ts +33 -4
- package/src/activities/agent-turn/quiescence.ts +11 -2
- package/src/activities/agent-turn/run.ts +74 -1
- 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 +258 -135
- package/src/activities/agent-turn/tool-environment.ts +41 -7
- package/src/activities/agent-turn/turn-context.ts +4 -2
- package/src/activities/agent-turn.ts +5 -1
- package/src/activities/api-integrations.ts +11 -1
- package/src/activities/capabilities.ts +57 -0
- package/src/activities/context-compaction.ts +3 -0
- package/src/activities/goals.ts +1 -0
- package/src/activities/mcp-credentials.ts +53 -0
- package/src/activities/rig-verification.ts +5 -3
- package/src/activities/scheduled-tasks.ts +111 -98
- package/src/index.ts +15 -0
- package/src/observability-metrics.ts +152 -14
- package/src/sandbox-reaper-timeout.ts +10 -4
- package/src/sandbox-resume.ts +58 -8
- package/dist/activities-control-SGU2WEVB.js.map +0 -1
- package/dist/activities-turn-7EAQXW6Q.js.map +0 -1
- package/dist/chunk-S2QVRVJW.js.map +0 -1
- package/dist/chunk-TJIPCHMP.js.map +0 -1
|
@@ -41,7 +41,6 @@ import {
|
|
|
41
41
|
mergeResourceRefs,
|
|
42
42
|
nextStreamEvent,
|
|
43
43
|
persistOrSignalSessionAttemptQuiescence,
|
|
44
|
-
persistSandboxDeadlineRotationCheckpoint,
|
|
45
44
|
postClaimDatabaseRecoveryFailure,
|
|
46
45
|
preClaimAdmissionFailure,
|
|
47
46
|
providerRecoveryCountAfterModelRequestPhase,
|
|
@@ -81,7 +80,7 @@ import {
|
|
|
81
80
|
waitForTurnOperation,
|
|
82
81
|
waitForWarmSnapshot,
|
|
83
82
|
withFirstPartyTools
|
|
84
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-RQNH6CGR.js";
|
|
85
84
|
import {
|
|
86
85
|
StreamTimingMetrics,
|
|
87
86
|
makeMachineOpObserver,
|
|
@@ -90,6 +89,7 @@ import {
|
|
|
90
89
|
recordBatchFlush,
|
|
91
90
|
recordCompanyBrainContributions,
|
|
92
91
|
recordContextCompaction,
|
|
92
|
+
recordContextCompactionStarted,
|
|
93
93
|
recordCreditMicros,
|
|
94
94
|
recordModelCacheTokens,
|
|
95
95
|
recordModelInputTokens,
|
|
@@ -106,7 +106,7 @@ import {
|
|
|
106
106
|
recordTurnWorkerPreparationTotal,
|
|
107
107
|
runtimeMetricsHooksForObservability,
|
|
108
108
|
turnLifecycleMetricsFor
|
|
109
|
-
} from "./chunk-
|
|
109
|
+
} from "./chunk-65JEWP2Q.js";
|
|
110
110
|
|
|
111
111
|
// src/activities-turn.ts
|
|
112
112
|
import { createProductionAgentRuntime, summarizeForCompaction as summarizeForCompaction2 } from "@opengeni/runtime";
|
|
@@ -136,7 +136,9 @@ import {
|
|
|
136
136
|
codexRequestStorage,
|
|
137
137
|
withCodexRequestOverrides
|
|
138
138
|
} from "@opengeni/codex";
|
|
139
|
-
import {
|
|
139
|
+
import {
|
|
140
|
+
xaiSubscriptionRequestStorage
|
|
141
|
+
} from "@opengeni/xai-subscription";
|
|
140
142
|
|
|
141
143
|
// src/activities/xai-auth.ts
|
|
142
144
|
import { environmentsEncryptionKeyBytes } from "@opengeni/config";
|
|
@@ -3486,7 +3488,8 @@ function createTurnContext(input) {
|
|
|
3486
3488
|
sandboxHolderId: null,
|
|
3487
3489
|
sandboxGroupId: null,
|
|
3488
3490
|
leaseHeartbeatTimer: void 0,
|
|
3489
|
-
|
|
3491
|
+
rotationPreemptionInFlight: null,
|
|
3492
|
+
deadlineRotationRequested: false,
|
|
3490
3493
|
snapshotInFlight: null,
|
|
3491
3494
|
firstProviderRequestStarted: false,
|
|
3492
3495
|
turnEndCaptureInProgress: false,
|
|
@@ -4432,6 +4435,19 @@ async function finalizeTurnAttempt(deps) {
|
|
|
4432
4435
|
cancellationSignal,
|
|
4433
4436
|
control.activityStatus
|
|
4434
4437
|
);
|
|
4438
|
+
const drainInFlightWarmSnapshot = async () => {
|
|
4439
|
+
const snapshot = sandboxState.snapshotInFlight;
|
|
4440
|
+
if (!snapshot) return;
|
|
4441
|
+
await snapshot.catch((error) => {
|
|
4442
|
+
console.error(
|
|
4443
|
+
"in-flight workspace snapshot settlement failed (turn outcome unaffected)",
|
|
4444
|
+
safeErrorDiagnostic(error)
|
|
4445
|
+
);
|
|
4446
|
+
});
|
|
4447
|
+
if (sandboxState.snapshotInFlight === snapshot) {
|
|
4448
|
+
sandboxState.snapshotInFlight = null;
|
|
4449
|
+
}
|
|
4450
|
+
};
|
|
4435
4451
|
try {
|
|
4436
4452
|
const toolCancellationFence = eventing.toolCancellationFenceRef.current;
|
|
4437
4453
|
renewals.gitCredentialRenewalClosed = true;
|
|
@@ -4668,7 +4684,8 @@ async function finalizeTurnAttempt(deps) {
|
|
|
4668
4684
|
}
|
|
4669
4685
|
const runTurnEndPersistence = shouldRunTurnEndWorkspacePersistence({
|
|
4670
4686
|
activityStatus: control.activityStatus,
|
|
4671
|
-
cancellationRequested: finalizerSignal?.aborted === true
|
|
4687
|
+
cancellationRequested: finalizerSignal?.aborted === true,
|
|
4688
|
+
deadlineRotationRequested: sandboxState.deadlineRotationRequested
|
|
4672
4689
|
});
|
|
4673
4690
|
if (runTurnEndPersistence && attempt.turnId && sandboxState.resolvedSandbox && sandboxState.setupBoxSession && sandboxState.sandboxGroupId) {
|
|
4674
4691
|
sandboxState.turnEndCaptureInProgress = true;
|
|
@@ -4747,22 +4764,14 @@ async function finalizeTurnAttempt(deps) {
|
|
|
4747
4764
|
if (sandboxState.leaseHeartbeatTimer) {
|
|
4748
4765
|
stopLeaseHeartbeat();
|
|
4749
4766
|
}
|
|
4750
|
-
if (sandboxState.
|
|
4751
|
-
await
|
|
4752
|
-
() => void 0
|
|
4753
|
-
);
|
|
4767
|
+
if (sandboxState.rotationPreemptionInFlight) {
|
|
4768
|
+
await sandboxState.rotationPreemptionInFlight.catch(() => void 0);
|
|
4754
4769
|
}
|
|
4770
|
+
await drainInFlightWarmSnapshot();
|
|
4755
4771
|
if (sandboxState.resolvedSandbox) {
|
|
4756
4772
|
const settledTurnId = attempt.turnId;
|
|
4757
4773
|
if (runTurnEndPersistence && sandboxState.setupBoxSession && sandboxState.sandboxGroupId && settledTurnId) {
|
|
4758
|
-
|
|
4759
|
-
await waitForWarmSnapshot(
|
|
4760
|
-
sandboxState.snapshotInFlight,
|
|
4761
|
-
settings.sandboxSnapshotTimeoutMs,
|
|
4762
|
-
finalizerSignal
|
|
4763
|
-
);
|
|
4764
|
-
}
|
|
4765
|
-
const persisted = await maybePersistWarmWorkspaceSnapshot(
|
|
4774
|
+
const snapshot = maybePersistWarmWorkspaceSnapshot(
|
|
4766
4775
|
{ db, settings, objectStorage },
|
|
4767
4776
|
{
|
|
4768
4777
|
accountId: input.accountId,
|
|
@@ -4776,6 +4785,8 @@ async function finalizeTurnAttempt(deps) {
|
|
|
4776
4785
|
sandboxState.resolvedSandbox.leaseEpoch,
|
|
4777
4786
|
finalizerSignal
|
|
4778
4787
|
);
|
|
4788
|
+
sandboxState.snapshotInFlight = snapshot.settled;
|
|
4789
|
+
const persisted = await snapshot;
|
|
4779
4790
|
if (persisted && eventing.publish) {
|
|
4780
4791
|
await eventing.publish([
|
|
4781
4792
|
{
|
|
@@ -4794,6 +4805,10 @@ async function finalizeTurnAttempt(deps) {
|
|
|
4794
4805
|
);
|
|
4795
4806
|
} finally {
|
|
4796
4807
|
stopLeaseHeartbeat();
|
|
4808
|
+
if (sandboxState.rotationPreemptionInFlight) {
|
|
4809
|
+
await sandboxState.rotationPreemptionInFlight.catch(() => void 0);
|
|
4810
|
+
}
|
|
4811
|
+
await drainInFlightWarmSnapshot();
|
|
4797
4812
|
const sandboxReleaseTargets = new Set(sandboxState.lateSandboxesAwaitingWriterDrain);
|
|
4798
4813
|
sandboxState.lateSandboxesAwaitingWriterDrain.clear();
|
|
4799
4814
|
if (sandboxState.resolvedSandbox) {
|
|
@@ -4981,6 +4996,7 @@ function createModelResponseEventState(claimedSourceKeys = /* @__PURE__ */ new S
|
|
|
4981
4996
|
function createCompactionModelUsageEventState(claimedSourceKeys = /* @__PURE__ */ new Set()) {
|
|
4982
4997
|
return { usageCount: 0, claimedSourceKeys };
|
|
4983
4998
|
}
|
|
4999
|
+
var createSessionTitleModelUsageEventState = createCompactionModelUsageEventState;
|
|
4984
5000
|
function modelResponseContextSignal(state) {
|
|
4985
5001
|
return state.contextSignal;
|
|
4986
5002
|
}
|
|
@@ -5111,7 +5127,7 @@ async function processCompactionModelUsageEvent(input) {
|
|
|
5111
5127
|
const sourceKey = modelUsageSourceKey({
|
|
5112
5128
|
responseId: input.usage.responseId,
|
|
5113
5129
|
dispatchId: input.dispatchId,
|
|
5114
|
-
positionalKey:
|
|
5130
|
+
positionalKey: `${input.sourceKind ?? "compaction"}-${usageOrdinal}`
|
|
5115
5131
|
});
|
|
5116
5132
|
if (input.state.claimedSourceKeys.has(sourceKey)) {
|
|
5117
5133
|
return { status: "duplicate", sourceKey };
|
|
@@ -5186,6 +5202,12 @@ async function processCompactionModelUsageEvent(input) {
|
|
|
5186
5202
|
});
|
|
5187
5203
|
return { status: "processed", sourceKey, authoritative };
|
|
5188
5204
|
}
|
|
5205
|
+
async function processSessionTitleModelUsageEvent(input) {
|
|
5206
|
+
return await processCompactionModelUsageEvent({
|
|
5207
|
+
...input,
|
|
5208
|
+
sourceKind: "session-title"
|
|
5209
|
+
});
|
|
5210
|
+
}
|
|
5189
5211
|
async function emitModelCallUsage(input) {
|
|
5190
5212
|
const usage = input.usage && typeof input.usage === "object" && "usage" in input.usage ? input.usage.usage : null;
|
|
5191
5213
|
if (!usage || typeof usage !== "object") {
|
|
@@ -5293,7 +5315,7 @@ async function recordModelUsageAndDebitCredits(settings, db, input) {
|
|
|
5293
5315
|
creditCostMicros: 0
|
|
5294
5316
|
} : calculateGatewayReportedCostBreakdown(
|
|
5295
5317
|
settings,
|
|
5296
|
-
input.model,
|
|
5318
|
+
configuredPricingModel ?? input.model,
|
|
5297
5319
|
gatewayBilling.inferenceCostUsd,
|
|
5298
5320
|
{ inputTokens }
|
|
5299
5321
|
) : configuredPricingModel ? calculateModelUsageCostBreakdown(settings, configuredPricingModel, sanitizedUsage, {
|
|
@@ -5301,6 +5323,7 @@ async function recordModelUsageAndDebitCredits(settings, db, input) {
|
|
|
5301
5323
|
}) : null;
|
|
5302
5324
|
const hasCompleteCoreTokenTelemetry = normalizedUsage.telemetry.inputTokens !== null && normalizedUsage.telemetry.outputTokens !== null;
|
|
5303
5325
|
const estimatedProviderCostMicros = gatewayBilling ? pricingBreakdown?.providerCostMicros ?? null : hasCompleteCoreTokenTelemetry ? pricingBreakdown?.providerCostMicros ?? null : null;
|
|
5326
|
+
const equivalentCreditCostMicros = pricingBreakdown && !unpinnedWorkspaceGatewayModel ? gatewayBilling || hasCompleteCoreTokenTelemetry ? pricingBreakdown.creditCostMicros : null : null;
|
|
5304
5327
|
const pricingSource = gatewayBilling ? "gateway_reported" : estimatedProviderCostMicros !== null ? "configured_list_price" : null;
|
|
5305
5328
|
if (countsTowardTokenCap && totalTokens > 0) {
|
|
5306
5329
|
await recordUsageEvent(db, {
|
|
@@ -5335,6 +5358,7 @@ async function recordModelUsageAndDebitCredits(settings, db, input) {
|
|
|
5335
5358
|
billingPath: "external",
|
|
5336
5359
|
pricedCostMicros: 0,
|
|
5337
5360
|
estimatedProviderCostMicros,
|
|
5361
|
+
equivalentCreditCostMicros,
|
|
5338
5362
|
pricingSource,
|
|
5339
5363
|
normalizedUsage,
|
|
5340
5364
|
...gatewayBilling ? { upstreamProvider: gatewayBilling.finalProvider } : {}
|
|
@@ -5346,6 +5370,7 @@ async function recordModelUsageAndDebitCredits(settings, db, input) {
|
|
|
5346
5370
|
billingPath: "opengeni_credits",
|
|
5347
5371
|
pricedCostMicros: 0,
|
|
5348
5372
|
estimatedProviderCostMicros,
|
|
5373
|
+
equivalentCreditCostMicros,
|
|
5349
5374
|
pricingSource,
|
|
5350
5375
|
normalizedUsage,
|
|
5351
5376
|
...gatewayBilling ? { upstreamProvider: gatewayBilling.finalProvider } : {}
|
|
@@ -5399,6 +5424,7 @@ async function recordModelUsageAndDebitCredits(settings, db, input) {
|
|
|
5399
5424
|
billingPath: "opengeni_credits",
|
|
5400
5425
|
pricedCostMicros: costMicros,
|
|
5401
5426
|
estimatedProviderCostMicros,
|
|
5427
|
+
equivalentCreditCostMicros,
|
|
5402
5428
|
pricingSource,
|
|
5403
5429
|
normalizedUsage,
|
|
5404
5430
|
...gatewayBilling ? { upstreamProvider: gatewayBilling.finalProvider } : {}
|
|
@@ -5420,6 +5446,7 @@ async function recordAuthoritativeModelCallFact(input) {
|
|
|
5420
5446
|
billingPath: input.billing.billingPath,
|
|
5421
5447
|
pricedCostMicros: input.billing.pricedCostMicros,
|
|
5422
5448
|
estimatedProviderCostMicros: input.billing.estimatedProviderCostMicros,
|
|
5449
|
+
equivalentCreditCostMicros: input.billing.equivalentCreditCostMicros,
|
|
5423
5450
|
pricingSource: input.billing.pricingSource,
|
|
5424
5451
|
inputTokens: telemetry.inputTokens,
|
|
5425
5452
|
outputTokens: telemetry.outputTokens,
|
|
@@ -5440,9 +5467,10 @@ function sanitizedModelUsageInput(normalized) {
|
|
|
5440
5467
|
...normalized.telemetry.inputTokens !== null ? { inputTokens: normalized.telemetry.inputTokens } : {},
|
|
5441
5468
|
...normalized.telemetry.outputTokens !== null ? { outputTokens: normalized.telemetry.outputTokens } : {},
|
|
5442
5469
|
...normalized.totalTokens !== null ? { totalTokens: normalized.totalTokens } : {},
|
|
5443
|
-
...normalized.telemetry.cachedTokens !== null ? {
|
|
5470
|
+
...normalized.telemetry.cachedTokens !== null || normalized.telemetry.cacheWriteTokens !== null ? {
|
|
5444
5471
|
inputTokensDetails: {
|
|
5445
|
-
cached_tokens: normalized.telemetry.cachedTokens
|
|
5472
|
+
...normalized.telemetry.cachedTokens === null ? {} : { cached_tokens: normalized.telemetry.cachedTokens },
|
|
5473
|
+
...normalized.telemetry.cacheWriteTokens === null ? {} : { cache_write_tokens: normalized.telemetry.cacheWriteTokens }
|
|
5446
5474
|
}
|
|
5447
5475
|
} : {},
|
|
5448
5476
|
...normalized.requestUsageEntries ? { requestUsageEntries: normalized.requestUsageEntries } : {}
|
|
@@ -5493,6 +5521,16 @@ function shouldPublishToolAuthNeededForTurn(payload, trigger, turn) {
|
|
|
5493
5521
|
const text = trigger.payload.text;
|
|
5494
5522
|
return typeof text === "string" && /\bslack\b/i.test(text);
|
|
5495
5523
|
}
|
|
5524
|
+
function rollingSafeToolAuthNeededPayload(payload) {
|
|
5525
|
+
if (payload.authoritySource !== "host") {
|
|
5526
|
+
return payload;
|
|
5527
|
+
}
|
|
5528
|
+
return {
|
|
5529
|
+
...payload,
|
|
5530
|
+
reason: "unsupported_auth",
|
|
5531
|
+
hostReason: payload.hostReason ?? payload.reason
|
|
5532
|
+
};
|
|
5533
|
+
}
|
|
5496
5534
|
function turnExecutionPolicyBillingIdentity(policy) {
|
|
5497
5535
|
return {
|
|
5498
5536
|
externallyBilled: policy.billing.metering === "external",
|
|
@@ -6651,8 +6689,10 @@ import {
|
|
|
6651
6689
|
attachOpenSuffixToPendingToolCalls,
|
|
6652
6690
|
clearDurablePendingSessionToolCalls,
|
|
6653
6691
|
isSessionCompactionRequested,
|
|
6654
|
-
nextSessionHistoryPosition as nextSessionHistoryPosition2
|
|
6692
|
+
nextSessionHistoryPosition as nextSessionHistoryPosition2,
|
|
6693
|
+
updateSessionTitleWithEvent
|
|
6655
6694
|
} from "@opengeni/db";
|
|
6695
|
+
import { publishDurableSessionEvents as publishDurableSessionEvents3 } from "@opengeni/events";
|
|
6656
6696
|
import {
|
|
6657
6697
|
normalizeModelCallUsage as normalizeModelCallUsage2,
|
|
6658
6698
|
normalizeSdkEvent,
|
|
@@ -6664,6 +6704,7 @@ import {
|
|
|
6664
6704
|
withRunCredentialsSession,
|
|
6665
6705
|
runOwnedSandboxSetup
|
|
6666
6706
|
} from "@opengeni/runtime";
|
|
6707
|
+
import { serviceTierForLatencyMode } from "@opengeni/config";
|
|
6667
6708
|
|
|
6668
6709
|
// src/activities/context-compaction.ts
|
|
6669
6710
|
import {
|
|
@@ -7242,6 +7283,7 @@ async function maybeCompactContext(db, settings, scope, lastInputTokens, summari
|
|
|
7242
7283
|
`turn attempt was fenced while recording context compaction start: ${started.reason}`
|
|
7243
7284
|
);
|
|
7244
7285
|
}
|
|
7286
|
+
options.onCompactionStarted?.(trigger);
|
|
7245
7287
|
await options.publishLiveEvents?.(started.events);
|
|
7246
7288
|
if (useRemoteV2) {
|
|
7247
7289
|
const outcome2 = await compactContextRemoteV2(
|
|
@@ -7783,6 +7825,111 @@ import {
|
|
|
7783
7825
|
resolveWorkspaceAgentHumanInputEnabled
|
|
7784
7826
|
} from "@opengeni/contracts";
|
|
7785
7827
|
|
|
7828
|
+
// src/activities/agent-turn/session-title.ts
|
|
7829
|
+
import { hasPermission } from "@opengeni/core";
|
|
7830
|
+
import {
|
|
7831
|
+
AUTOMATIC_SESSION_TITLE_FALLBACK,
|
|
7832
|
+
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS
|
|
7833
|
+
} from "@opengeni/contracts";
|
|
7834
|
+
var SESSION_TITLE_MODEL_TOOL_NAME = "opengeni__set_session_title";
|
|
7835
|
+
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.";
|
|
7836
|
+
function shouldRequestMissingSessionTitle(input) {
|
|
7837
|
+
const title = input.title?.trim() ?? "";
|
|
7838
|
+
const needsSemanticTitle = input.titleSource !== "user" && (!title || title === AUTOMATIC_SESSION_TITLE_FALLBACK);
|
|
7839
|
+
if (!needsSemanticTitle) return false;
|
|
7840
|
+
if (!input.firstPartyMcpTools.includes("set_session_title")) return false;
|
|
7841
|
+
const permissions = input.firstPartyMcpPermissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS;
|
|
7842
|
+
return hasPermission([...permissions], "sessions:control");
|
|
7843
|
+
}
|
|
7844
|
+
function sessionTitleToolPlan(input) {
|
|
7845
|
+
const titleToolAvailable = input.shouldRequestTitle && input.tools.some((tool) => tool.kind === "mcp" && tool.id === "opengeni");
|
|
7846
|
+
const generateTitleInParallel = titleToolAvailable && input.parallelGenerationAvailable;
|
|
7847
|
+
const promoteTitleTool = titleToolAvailable && !generateTitleInParallel;
|
|
7848
|
+
return {
|
|
7849
|
+
promoteTitleTool,
|
|
7850
|
+
generateTitleInParallel,
|
|
7851
|
+
remoteFirstPartyMcpTools: titleToolAvailable ? input.selectedFirstPartyMcpTools.filter((tool) => tool !== "set_session_title") : [...input.selectedFirstPartyMcpTools],
|
|
7852
|
+
preparationIndependentToolNames: promoteTitleTool ? [SESSION_TITLE_MODEL_TOOL_NAME] : []
|
|
7853
|
+
};
|
|
7854
|
+
}
|
|
7855
|
+
var PARALLEL_SESSION_TITLE_TIMEOUT_MS = 15e3;
|
|
7856
|
+
function startParallelSessionTitleGeneration(input) {
|
|
7857
|
+
const cancellationController = new AbortController();
|
|
7858
|
+
const timeoutSignal = AbortSignal.timeout(input.timeoutMs ?? PARALLEL_SESSION_TITLE_TIMEOUT_MS);
|
|
7859
|
+
const signals = [cancellationController.signal, timeoutSignal];
|
|
7860
|
+
if (input.signal) signals.push(input.signal);
|
|
7861
|
+
const signal = AbortSignal.any(signals);
|
|
7862
|
+
const generation = input.generate(signal).then((result) => signal.aborted ? null : result).catch((error) => {
|
|
7863
|
+
if (!signal.aborted) input.onError?.(error);
|
|
7864
|
+
return null;
|
|
7865
|
+
});
|
|
7866
|
+
let finished = null;
|
|
7867
|
+
return {
|
|
7868
|
+
finish: () => {
|
|
7869
|
+
if (finished) return finished;
|
|
7870
|
+
finished = generation;
|
|
7871
|
+
return finished;
|
|
7872
|
+
},
|
|
7873
|
+
cancel: async () => {
|
|
7874
|
+
cancellationController.abort();
|
|
7875
|
+
await generation;
|
|
7876
|
+
}
|
|
7877
|
+
};
|
|
7878
|
+
}
|
|
7879
|
+
function createSessionTitleAttemptToolDefinition(input) {
|
|
7880
|
+
return {
|
|
7881
|
+
identity: { serverId: "opengeni", toolName: "set_session_title" },
|
|
7882
|
+
modelName: SESSION_TITLE_MODEL_TOOL_NAME,
|
|
7883
|
+
codemodePath: ["opengeni", "set_session_title"],
|
|
7884
|
+
title: "Set session title",
|
|
7885
|
+
description: SESSION_TITLE_DESCRIPTION,
|
|
7886
|
+
inputSchema: {
|
|
7887
|
+
type: "object",
|
|
7888
|
+
properties: {
|
|
7889
|
+
title: { type: "string", minLength: 1, maxLength: 200 }
|
|
7890
|
+
},
|
|
7891
|
+
required: ["title"],
|
|
7892
|
+
additionalProperties: false
|
|
7893
|
+
},
|
|
7894
|
+
outputSchema: {
|
|
7895
|
+
type: "object",
|
|
7896
|
+
properties: {
|
|
7897
|
+
ok: { type: "boolean", const: true },
|
|
7898
|
+
updated: { type: "boolean" },
|
|
7899
|
+
title: { type: "string" }
|
|
7900
|
+
},
|
|
7901
|
+
required: ["ok", "updated", "title"],
|
|
7902
|
+
additionalProperties: false
|
|
7903
|
+
},
|
|
7904
|
+
annotations: {
|
|
7905
|
+
title: "Set session title",
|
|
7906
|
+
readOnlyHint: false,
|
|
7907
|
+
destructiveHint: false,
|
|
7908
|
+
idempotentHint: true,
|
|
7909
|
+
openWorldHint: false
|
|
7910
|
+
},
|
|
7911
|
+
source: "opengeni",
|
|
7912
|
+
approval: "none",
|
|
7913
|
+
execute: async (args) => {
|
|
7914
|
+
const title = args.title;
|
|
7915
|
+
if (typeof title !== "string") {
|
|
7916
|
+
throw new Error("set_session_title requires a title string");
|
|
7917
|
+
}
|
|
7918
|
+
const result = await input.updateTitle(title);
|
|
7919
|
+
const output = {
|
|
7920
|
+
ok: true,
|
|
7921
|
+
updated: result.updated,
|
|
7922
|
+
title: result.title ?? title
|
|
7923
|
+
};
|
|
7924
|
+
return {
|
|
7925
|
+
isError: false,
|
|
7926
|
+
content: [{ type: "text", text: JSON.stringify(output) }],
|
|
7927
|
+
structuredContent: output
|
|
7928
|
+
};
|
|
7929
|
+
}
|
|
7930
|
+
};
|
|
7931
|
+
}
|
|
7932
|
+
|
|
7786
7933
|
// src/activities/agent-turn/sandbox-shared-preparation.ts
|
|
7787
7934
|
import { randomUUID } from "crypto";
|
|
7788
7935
|
import {
|
|
@@ -7949,6 +8096,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
7949
8096
|
input,
|
|
7950
8097
|
settings,
|
|
7951
8098
|
db,
|
|
8099
|
+
bus,
|
|
7952
8100
|
runtime,
|
|
7953
8101
|
objectStorage,
|
|
7954
8102
|
observability,
|
|
@@ -7979,6 +8127,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
7979
8127
|
attachCodemodeTokenRenewal,
|
|
7980
8128
|
attachRunCredentialRenewal,
|
|
7981
8129
|
withProviderRequestContext,
|
|
8130
|
+
withSessionTitleProviderRequestContext,
|
|
7982
8131
|
publishCompactionLiveEvents,
|
|
7983
8132
|
publishCompactionOutcomeEvents,
|
|
7984
8133
|
recordCompanyBrainContributionReceiptOnce,
|
|
@@ -8004,6 +8153,8 @@ async function runTurnStreamAttempt(deps) {
|
|
|
8004
8153
|
providerApi,
|
|
8005
8154
|
runSettings,
|
|
8006
8155
|
turnTools,
|
|
8156
|
+
generateSessionTitleInParallel,
|
|
8157
|
+
sessionTitlePrompt,
|
|
8007
8158
|
compactSummarizer,
|
|
8008
8159
|
settleDeferredSteerAfterCompaction,
|
|
8009
8160
|
compactionModelHistoryProjector,
|
|
@@ -8023,6 +8174,69 @@ async function runTurnStreamAttempt(deps) {
|
|
|
8023
8174
|
if (!activeTurnId) {
|
|
8024
8175
|
throw new Error("Turn id was not initialized");
|
|
8025
8176
|
}
|
|
8177
|
+
const sessionTitleUsageState = createSessionTitleModelUsageEventState(
|
|
8178
|
+
claimedModelUsageSourceKeys
|
|
8179
|
+
);
|
|
8180
|
+
let parallelSessionTitle = null;
|
|
8181
|
+
let parallelSessionTitleFinished = false;
|
|
8182
|
+
const finishParallelSessionTitle = async () => {
|
|
8183
|
+
if (parallelSessionTitleFinished) return;
|
|
8184
|
+
parallelSessionTitleFinished = true;
|
|
8185
|
+
const generated = await parallelSessionTitle?.finish();
|
|
8186
|
+
if (!generated) return;
|
|
8187
|
+
if (generated.usage) {
|
|
8188
|
+
await processSessionTitleModelUsageEvent({
|
|
8189
|
+
usage: generated.usage,
|
|
8190
|
+
state: sessionTitleUsageState,
|
|
8191
|
+
dispatchId: modelUsageDispatchId,
|
|
8192
|
+
settings,
|
|
8193
|
+
db,
|
|
8194
|
+
observability,
|
|
8195
|
+
publish: eventing.publish,
|
|
8196
|
+
accountId: input.accountId,
|
|
8197
|
+
workspaceId: input.workspaceId,
|
|
8198
|
+
sessionId: input.sessionId,
|
|
8199
|
+
turnId: activeTurnId,
|
|
8200
|
+
turnAttemptId: input.attemptId,
|
|
8201
|
+
provider: resolvedModel?.provider.id ?? settings.openaiProvider,
|
|
8202
|
+
providerApi: resolvedModel?.provider.api ?? "responses",
|
|
8203
|
+
model: resolvedModel?.configured.id ?? turn.model,
|
|
8204
|
+
externallyBilled: billingState.isExternallyBilledTurn,
|
|
8205
|
+
chargesOpenGeniCredits: billingState.chargesOpenGeniCredits,
|
|
8206
|
+
countsTowardTokenCap: billingState.countsTowardTokenCap,
|
|
8207
|
+
servingCredentialId: providerTurn.effectiveCodexCredentialId,
|
|
8208
|
+
priorSessionCredentialId: providerTurn.priorSessionCodexCredentialId,
|
|
8209
|
+
emittedSourceKeys: emittedModelUsageSourceKeys,
|
|
8210
|
+
renewLease: () => leases.renewServing("model_usage"),
|
|
8211
|
+
leaseLost: leases.servingLost,
|
|
8212
|
+
leaseLostMessage: "Provider credential lease expired during session title generation"
|
|
8213
|
+
});
|
|
8214
|
+
}
|
|
8215
|
+
if (!generated.title) return;
|
|
8216
|
+
try {
|
|
8217
|
+
const result = await updateSessionTitleWithEvent(db, {
|
|
8218
|
+
workspaceId: input.workspaceId,
|
|
8219
|
+
sessionId: input.sessionId,
|
|
8220
|
+
title: generated.title,
|
|
8221
|
+
source: "agent"
|
|
8222
|
+
});
|
|
8223
|
+
if (result.events.length > 0) {
|
|
8224
|
+
await publishDurableSessionEvents3(bus, input.workspaceId, input.sessionId, result.events);
|
|
8225
|
+
}
|
|
8226
|
+
} catch (error) {
|
|
8227
|
+
observability.warn("parallel session title persistence failed", {
|
|
8228
|
+
...safeErrorDiagnostic(error),
|
|
8229
|
+
errorClass: "ParallelSessionTitlePersistenceError",
|
|
8230
|
+
errorCode: "parallel_session_title_persistence_failed",
|
|
8231
|
+
origin: "worker"
|
|
8232
|
+
});
|
|
8233
|
+
}
|
|
8234
|
+
};
|
|
8235
|
+
const cancelParallelSessionTitle = async () => {
|
|
8236
|
+
if (parallelSessionTitleFinished) return;
|
|
8237
|
+
parallelSessionTitleFinished = true;
|
|
8238
|
+
await parallelSessionTitle?.cancel();
|
|
8239
|
+
};
|
|
8026
8240
|
let runInput = null;
|
|
8027
8241
|
const prepareRunAttemptInput = async () => {
|
|
8028
8242
|
const historyPreparationStartedAt = performance.now();
|
|
@@ -8994,6 +9208,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
8994
9208
|
if (!attached.accepted) {
|
|
8995
9209
|
return claimedResult({ status: "cancelled" });
|
|
8996
9210
|
}
|
|
9211
|
+
await finishParallelSessionTitle();
|
|
8997
9212
|
if (!await eventing.settle({
|
|
8998
9213
|
events: [
|
|
8999
9214
|
...requestEvents,
|
|
@@ -9027,6 +9242,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
9027
9242
|
const finalOutput = String(requireAgentStreamFinalOutput(eventing.stream.finalOutput));
|
|
9028
9243
|
await historySink.reconcileConversationTruth({ requireDurable: true });
|
|
9029
9244
|
await finalizeTurnOpStreamOps();
|
|
9245
|
+
await finishParallelSessionTitle();
|
|
9030
9246
|
if (!await eventing.settle({
|
|
9031
9247
|
events: [
|
|
9032
9248
|
{
|
|
@@ -9088,125 +9304,161 @@ async function runTurnStreamAttempt(deps) {
|
|
|
9088
9304
|
})) {
|
|
9089
9305
|
return claimedResult({ status: "cancelled" });
|
|
9090
9306
|
}
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9095
|
-
|
|
9096
|
-
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
|
|
9307
|
+
if (generateSessionTitleInParallel && runtime.generateSessionTitle && !runtimeCancellationSignal.aborted) {
|
|
9308
|
+
const serviceTier = serviceTierForLatencyMode(
|
|
9309
|
+
turnExecutionPolicy.providerId,
|
|
9310
|
+
turnExecutionPolicy.latencyMode
|
|
9311
|
+
);
|
|
9312
|
+
parallelSessionTitle = startParallelSessionTitleGeneration({
|
|
9313
|
+
signal: runtimeCancellationSignal,
|
|
9314
|
+
generate: async (signal) => await withSessionTitleProviderRequestContext(
|
|
9315
|
+
() => runtime.generateSessionTitle(runSettings, sessionTitlePrompt, {
|
|
9316
|
+
...resolvedModel ? {
|
|
9317
|
+
client: resolvedModel.client,
|
|
9318
|
+
provider: resolvedModel.provider,
|
|
9319
|
+
model: resolvedModel.model
|
|
9320
|
+
} : {},
|
|
9321
|
+
modelName: turnExecutionPolicy.upstreamModelId,
|
|
9322
|
+
...serviceTier ? { serviceTier } : {},
|
|
9323
|
+
signal
|
|
9324
|
+
})
|
|
9325
|
+
),
|
|
9326
|
+
onError: (error) => {
|
|
9327
|
+
observability.warn("parallel session title generation failed", {
|
|
9328
|
+
...safeErrorDiagnostic(error),
|
|
9329
|
+
errorClass: "ParallelSessionTitleGenerationError",
|
|
9330
|
+
errorCode: "parallel_session_title_generation_failed",
|
|
9331
|
+
origin: "worker"
|
|
9101
9332
|
});
|
|
9102
9333
|
}
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
if (!recoveryKind || !eventing.publish || !eventing.turnStartedPublished) {
|
|
9109
|
-
throw attemptError;
|
|
9110
|
-
}
|
|
9111
|
-
await flushRuntimeBatcher();
|
|
9112
|
-
await historySink.reconcileConversationTruth({ skipInputOnlyRows: true });
|
|
9113
|
-
observability.warn("context compaction recovery attempted", {
|
|
9114
|
-
sessionId: input.sessionId,
|
|
9115
|
-
turnId: activeTurnId,
|
|
9116
|
-
reason: recoveryKind,
|
|
9117
|
-
...safeErrorDiagnostic(attemptError),
|
|
9118
|
-
signalTokens: compactionNeeded?.signalTokens,
|
|
9119
|
-
thresholdTokens: compactionNeeded?.thresholdTokens
|
|
9120
|
-
});
|
|
9121
|
-
let compacted = false;
|
|
9122
|
-
let compactionHandled = false;
|
|
9123
|
-
let compactionFailureMessage = null;
|
|
9124
|
-
let compactionRequestCleared = false;
|
|
9334
|
+
});
|
|
9335
|
+
}
|
|
9336
|
+
try {
|
|
9337
|
+
let retriedAfterCompaction = false;
|
|
9338
|
+
while (true) {
|
|
9125
9339
|
try {
|
|
9126
|
-
const
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
)
|
|
9130
|
-
|
|
9131
|
-
if (outcome.compacted) {
|
|
9132
|
-
compactionHandled = true;
|
|
9133
|
-
} else {
|
|
9134
|
-
compactionHandled = recoveryKind === "operator" && outcome.requestConsumed;
|
|
9135
|
-
if (!compactionHandled) {
|
|
9136
|
-
compactionFailureMessage = compactionFailureReason(outcome.reason);
|
|
9137
|
-
}
|
|
9138
|
-
}
|
|
9139
|
-
} catch (compactError) {
|
|
9140
|
-
if (shouldRecoverCompactionProviderFailure(compactError)) throw compactError;
|
|
9141
|
-
if (compactError instanceof TurnAttemptFencedError) throw compactError;
|
|
9142
|
-
const landmark = await settleFailedContextCompactionLandmark(
|
|
9143
|
-
db,
|
|
9144
|
-
{
|
|
9145
|
-
accountId: input.accountId,
|
|
9146
|
-
workspaceId: input.workspaceId,
|
|
9340
|
+
const result = await runStreamAttempt({
|
|
9341
|
+
requireTerminalModelResponse: retriedAfterCompaction
|
|
9342
|
+
});
|
|
9343
|
+
if (retriedAfterCompaction) {
|
|
9344
|
+
observability.info("context compaction recovery succeeded after in-activity retry", {
|
|
9147
9345
|
sessionId: input.sessionId,
|
|
9148
|
-
turnId: activeTurnId
|
|
9149
|
-
|
|
9150
|
-
|
|
9151
|
-
|
|
9152
|
-
|
|
9153
|
-
|
|
9154
|
-
|
|
9155
|
-
|
|
9156
|
-
)
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
observability.warn("context compaction recovery compaction failed", {
|
|
9346
|
+
turnId: activeTurnId
|
|
9347
|
+
});
|
|
9348
|
+
}
|
|
9349
|
+
return result;
|
|
9350
|
+
} catch (attemptError) {
|
|
9351
|
+
const overflow = classifyContextWindowOverflowError(attemptError);
|
|
9352
|
+
const compactionNeeded = findCompactionNeededError(attemptError);
|
|
9353
|
+
const recoveryKind = compactionNeeded ? compactionNeeded.trigger === "operator" ? "operator" : "proactive" : overflow ? "overflow" : null;
|
|
9354
|
+
if (!recoveryKind || !eventing.publish || !eventing.turnStartedPublished) {
|
|
9355
|
+
throw attemptError;
|
|
9356
|
+
}
|
|
9357
|
+
await flushRuntimeBatcher();
|
|
9358
|
+
await historySink.reconcileConversationTruth({ skipInputOnlyRows: true });
|
|
9359
|
+
observability.warn("context compaction recovery attempted", {
|
|
9163
9360
|
sessionId: input.sessionId,
|
|
9164
9361
|
turnId: activeTurnId,
|
|
9165
|
-
|
|
9362
|
+
reason: recoveryKind,
|
|
9363
|
+
...safeErrorDiagnostic(attemptError),
|
|
9364
|
+
signalTokens: compactionNeeded?.signalTokens,
|
|
9365
|
+
thresholdTokens: compactionNeeded?.thresholdTokens
|
|
9166
9366
|
});
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9367
|
+
let compacted = false;
|
|
9368
|
+
let compactionHandled = false;
|
|
9369
|
+
let compactionFailureMessage = null;
|
|
9370
|
+
let compactionRequestCleared = false;
|
|
9371
|
+
try {
|
|
9372
|
+
const outcome = await forceContextCompaction(
|
|
9373
|
+
recoveryKind,
|
|
9374
|
+
compactionNeeded?.signalTokens ?? null
|
|
9375
|
+
);
|
|
9376
|
+
compacted = outcome.compacted;
|
|
9377
|
+
if (outcome.compacted) {
|
|
9378
|
+
compactionHandled = true;
|
|
9379
|
+
} else {
|
|
9380
|
+
compactionHandled = recoveryKind === "operator" && outcome.requestConsumed;
|
|
9381
|
+
if (!compactionHandled) {
|
|
9382
|
+
compactionFailureMessage = compactionFailureReason(outcome.reason);
|
|
9383
|
+
}
|
|
9384
|
+
}
|
|
9385
|
+
} catch (compactError) {
|
|
9386
|
+
if (shouldRecoverCompactionProviderFailure(compactError)) throw compactError;
|
|
9387
|
+
if (compactError instanceof TurnAttemptFencedError) throw compactError;
|
|
9388
|
+
const landmark = await settleFailedContextCompactionLandmark(
|
|
9389
|
+
db,
|
|
9172
9390
|
{
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
compacted: false
|
|
9180
|
-
}
|
|
9391
|
+
accountId: input.accountId,
|
|
9392
|
+
workspaceId: input.workspaceId,
|
|
9393
|
+
sessionId: input.sessionId,
|
|
9394
|
+
turnId: activeTurnId,
|
|
9395
|
+
executionGeneration: attempt.executionGeneration,
|
|
9396
|
+
attemptId: input.attemptId
|
|
9181
9397
|
},
|
|
9182
9398
|
{
|
|
9183
|
-
|
|
9184
|
-
|
|
9399
|
+
clearRequestedCompaction: recoveryKind === "operator",
|
|
9400
|
+
publishLiveEvents: publishCompactionLiveEvents
|
|
9185
9401
|
}
|
|
9186
|
-
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9402
|
+
);
|
|
9403
|
+
compactionRequestCleared = landmark.requestConsumed;
|
|
9404
|
+
if (!isCompactionSummaryFailure(compactError)) throw compactError;
|
|
9405
|
+
await finishParallelSessionTitle();
|
|
9406
|
+
const deferredSteer2 = await settleDeferredSteerAfterCompaction();
|
|
9407
|
+
if (deferredSteer2) return deferredSteer2;
|
|
9408
|
+
compactionFailureMessage = String(compactionFailureReasonFromError(compactError));
|
|
9409
|
+
observability.warn("context compaction recovery compaction failed", {
|
|
9410
|
+
sessionId: input.sessionId,
|
|
9411
|
+
turnId: activeTurnId,
|
|
9412
|
+
...safeErrorDiagnostic(compactError)
|
|
9413
|
+
});
|
|
9193
9414
|
}
|
|
9194
|
-
|
|
9195
|
-
|
|
9196
|
-
|
|
9197
|
-
|
|
9415
|
+
if (!compactionHandled) {
|
|
9416
|
+
const errorMessage = compactionFailureMessage ?? "compaction summarization failed: compaction produced no replacement history";
|
|
9417
|
+
await finishParallelSessionTitle();
|
|
9418
|
+
if (!await eventing.settle({
|
|
9419
|
+
events: [
|
|
9420
|
+
{
|
|
9421
|
+
type: "turn.failed",
|
|
9422
|
+
payload: {
|
|
9423
|
+
error: errorMessage,
|
|
9424
|
+
code: "context_compaction_failed",
|
|
9425
|
+
retryable: false,
|
|
9426
|
+
recovery: "user_message",
|
|
9427
|
+
compacted: false
|
|
9428
|
+
}
|
|
9429
|
+
},
|
|
9430
|
+
{
|
|
9431
|
+
type: "session.status.changed",
|
|
9432
|
+
payload: { status: "idle" }
|
|
9433
|
+
}
|
|
9434
|
+
],
|
|
9435
|
+
turnStatus: "failed",
|
|
9436
|
+
sessionStatus: "idle",
|
|
9437
|
+
activeTurnId: null,
|
|
9438
|
+
...recoveryKind === "operator" && !compactionRequestCleared ? { consumeRequestedCompactionFailure: true } : {}
|
|
9439
|
+
})) {
|
|
9440
|
+
return claimedResult({ status: "cancelled" });
|
|
9441
|
+
}
|
|
9442
|
+
control.turnMetricOutcome = "failed";
|
|
9443
|
+
control.activityStatus = "idle";
|
|
9444
|
+
control.activityError = attemptError;
|
|
9445
|
+
return claimedResult({ status: "idle", deferredUntilWake: true });
|
|
9446
|
+
}
|
|
9447
|
+
await finishParallelSessionTitle();
|
|
9448
|
+
const deferredSteer = await settleDeferredSteerAfterCompaction();
|
|
9449
|
+
if (deferredSteer) return deferredSteer;
|
|
9450
|
+
retriedAfterCompaction = true;
|
|
9451
|
+
observability.info("context compaction recovery retrying turn after compaction", {
|
|
9452
|
+
sessionId: input.sessionId,
|
|
9453
|
+
turnId: activeTurnId,
|
|
9454
|
+
reason: recoveryKind,
|
|
9455
|
+
compacted
|
|
9456
|
+
});
|
|
9457
|
+
await prepareRunAttemptInput();
|
|
9198
9458
|
}
|
|
9199
|
-
const deferredSteer = await settleDeferredSteerAfterCompaction();
|
|
9200
|
-
if (deferredSteer) return deferredSteer;
|
|
9201
|
-
retriedAfterCompaction = true;
|
|
9202
|
-
observability.info("context compaction recovery retrying turn after compaction", {
|
|
9203
|
-
sessionId: input.sessionId,
|
|
9204
|
-
turnId: activeTurnId,
|
|
9205
|
-
reason: recoveryKind,
|
|
9206
|
-
compacted
|
|
9207
|
-
});
|
|
9208
|
-
await prepareRunAttemptInput();
|
|
9209
9459
|
}
|
|
9460
|
+
} finally {
|
|
9461
|
+
await cancelParallelSessionTitle();
|
|
9210
9462
|
}
|
|
9211
9463
|
}
|
|
9212
9464
|
|
|
@@ -9221,7 +9473,7 @@ import {
|
|
|
9221
9473
|
workspaceCodexSubscriptionActive as workspaceCodexSubscriptionActive2,
|
|
9222
9474
|
requireSession
|
|
9223
9475
|
} from "@opengeni/db";
|
|
9224
|
-
import { appendAndPublishTurnEventsFenced as appendAndPublishTurnEventsFenced2, publishDurableSessionEvents as
|
|
9476
|
+
import { appendAndPublishTurnEventsFenced as appendAndPublishTurnEventsFenced2, publishDurableSessionEvents as publishDurableSessionEvents4 } from "@opengeni/events";
|
|
9225
9477
|
import {
|
|
9226
9478
|
assertTurnExecutionPolicyMatchesConfigV1,
|
|
9227
9479
|
resolveTurnExecutionPolicyV1 as resolveTurnExecutionPolicyV12
|
|
@@ -9237,6 +9489,12 @@ import {
|
|
|
9237
9489
|
withWorkspaceGatewayCredential,
|
|
9238
9490
|
withWorkspaceOpenRouterCatalogProvider,
|
|
9239
9491
|
withWorkspaceOpenRouterCredential,
|
|
9492
|
+
withOrganizationGatewayCatalogProvider,
|
|
9493
|
+
withOrganizationGatewayCredential,
|
|
9494
|
+
withOrganizationOpenRouterCatalogProvider,
|
|
9495
|
+
withOrganizationOpenRouterCredential,
|
|
9496
|
+
ORGANIZATION_GATEWAY_MODEL_ID_PREFIX,
|
|
9497
|
+
ORGANIZATION_OPENROUTER_MODEL_ID_PREFIX,
|
|
9240
9498
|
withXaiSubscriptionCatalogProvider
|
|
9241
9499
|
} from "@opengeni/config";
|
|
9242
9500
|
import { settingsWithEnabledCapabilityMcpServers } from "@opengeni/core";
|
|
@@ -9249,7 +9507,10 @@ import {
|
|
|
9249
9507
|
listWorkspaceOpenRouterCustomModels,
|
|
9250
9508
|
workspaceCodexSubscriptionActive,
|
|
9251
9509
|
loadWorkspaceVercelAiGatewayApiKey,
|
|
9252
|
-
loadWorkspaceOpenRouterApiKey
|
|
9510
|
+
loadWorkspaceOpenRouterApiKey,
|
|
9511
|
+
listOrganizationModelProviderCustomModelsForWorkspace,
|
|
9512
|
+
getOrganizationModelProviderCustomModelForExecution,
|
|
9513
|
+
loadOrganizationModelProviderApiKey
|
|
9253
9514
|
} from "@opengeni/db";
|
|
9254
9515
|
async function settingsWithSessionMcpServersForRun(db, workspaceId, sessionId, attemptId, settings, options) {
|
|
9255
9516
|
const encryptionKey = environmentsEncryptionKeyBytes2(settings);
|
|
@@ -9348,6 +9609,37 @@ async function settingsWithWorkspaceOpenRouterCredential(db, accountId, workspac
|
|
|
9348
9609
|
const apiKey = await loadWorkspaceOpenRouterApiKey(db, settings, workspaceId);
|
|
9349
9610
|
return apiKey ? withWorkspaceOpenRouterCredential(catalogSettings, apiKey, customModels) : catalogSettings;
|
|
9350
9611
|
}
|
|
9612
|
+
async function settingsWithOrganizationProviderCredentials(db, accountId, workspaceId, settings, retainedProductModelId) {
|
|
9613
|
+
const buildModels = async (providerKind, prefix) => {
|
|
9614
|
+
const active = await listOrganizationModelProviderCustomModelsForWorkspace(db, {
|
|
9615
|
+
accountId,
|
|
9616
|
+
workspaceId,
|
|
9617
|
+
providerKind
|
|
9618
|
+
});
|
|
9619
|
+
const upstreamModelId = retainedProductModelId?.startsWith(prefix) ? retainedProductModelId.slice(prefix.length) : null;
|
|
9620
|
+
const retained = upstreamModelId ? await getOrganizationModelProviderCustomModelForExecution(db, {
|
|
9621
|
+
accountId,
|
|
9622
|
+
workspaceId,
|
|
9623
|
+
providerKind,
|
|
9624
|
+
upstreamModelId
|
|
9625
|
+
}) : null;
|
|
9626
|
+
return retained && !active.some((model) => model.id === retained.id) ? [...active, retained] : active;
|
|
9627
|
+
};
|
|
9628
|
+
const gatewayModels = await buildModels("vercel_gateway", ORGANIZATION_GATEWAY_MODEL_ID_PREFIX);
|
|
9629
|
+
const openRouterModels = await buildModels("openrouter", ORGANIZATION_OPENROUTER_MODEL_ID_PREFIX);
|
|
9630
|
+
const gatewayKey = await loadOrganizationModelProviderApiKey(db, settings, {
|
|
9631
|
+
accountId,
|
|
9632
|
+
workspaceId,
|
|
9633
|
+
providerKind: "vercel_gateway"
|
|
9634
|
+
});
|
|
9635
|
+
const gatewaySettings = gatewayKey ? withOrganizationGatewayCredential(settings, gatewayKey, gatewayModels) : withOrganizationGatewayCatalogProvider(settings, gatewayModels);
|
|
9636
|
+
const openRouterKey = await loadOrganizationModelProviderApiKey(db, settings, {
|
|
9637
|
+
accountId,
|
|
9638
|
+
workspaceId,
|
|
9639
|
+
providerKind: "openrouter"
|
|
9640
|
+
});
|
|
9641
|
+
return openRouterKey ? withOrganizationOpenRouterCredential(gatewaySettings, openRouterKey, openRouterModels) : withOrganizationOpenRouterCatalogProvider(gatewaySettings, openRouterModels);
|
|
9642
|
+
}
|
|
9351
9643
|
|
|
9352
9644
|
// src/activities/agent-turn/claim.ts
|
|
9353
9645
|
import {
|
|
@@ -9463,13 +9755,20 @@ async function claimTurnAttempt(deps) {
|
|
|
9463
9755
|
xaiSettings,
|
|
9464
9756
|
claimedPolicy.kind === "valid" ? claimedPolicy.policy.productModelId : turn.model
|
|
9465
9757
|
);
|
|
9466
|
-
const
|
|
9758
|
+
const workspaceProviderSettings = await settingsWithWorkspaceOpenRouterCredential(
|
|
9467
9759
|
db,
|
|
9468
9760
|
input.accountId,
|
|
9469
9761
|
input.workspaceId,
|
|
9470
9762
|
gatewaySettings,
|
|
9471
9763
|
claimedPolicy.kind === "valid" ? claimedPolicy.policy.productModelId : turn.model
|
|
9472
9764
|
);
|
|
9765
|
+
const capabilitySettings = await settingsWithOrganizationProviderCredentials(
|
|
9766
|
+
db,
|
|
9767
|
+
input.accountId,
|
|
9768
|
+
input.workspaceId,
|
|
9769
|
+
workspaceProviderSettings,
|
|
9770
|
+
claimedPolicy.kind === "valid" ? claimedPolicy.policy.productModelId : turn.model
|
|
9771
|
+
);
|
|
9473
9772
|
const codexAppsCredentialId = capabilitySettings.codexConnectedAppsEnabled ? await resolveCodexAppsCredentialIdForRun(db, input.workspaceId) : null;
|
|
9474
9773
|
runtime.configure(capabilitySettings);
|
|
9475
9774
|
const policyForAbsent = claimedPolicy.kind === "valid" ? claimedPolicy.policy : resolveTurnExecutionPolicyV12(capabilitySettings, legacyTurnExecutionPolicyInput(turn));
|
|
@@ -9662,7 +9961,7 @@ async function claimTurnAttempt(deps) {
|
|
|
9662
9961
|
}
|
|
9663
9962
|
recordCanonicalStartupMilestones(result.canonicalStartupMilestones);
|
|
9664
9963
|
turnLifecycleMetricsFor(observability).progress(attempt.turnId);
|
|
9665
|
-
await
|
|
9964
|
+
await publishDurableSessionEvents4(bus, input.workspaceId, input.sessionId, result.events);
|
|
9666
9965
|
if (inputSettlement.turnStatus === "requires_action") {
|
|
9667
9966
|
await deliverChildRequiresActionToParent(
|
|
9668
9967
|
{ db, bus, settings, observability, wakeSessionWorkflow },
|
|
@@ -9753,7 +10052,7 @@ import {
|
|
|
9753
10052
|
setActiveCodexCredential,
|
|
9754
10053
|
withSessionCodexCapacityMutation as withSessionCodexCapacityMutation2
|
|
9755
10054
|
} from "@opengeni/db";
|
|
9756
|
-
import { publishDurableSessionEvents as
|
|
10055
|
+
import { publishDurableSessionEvents as publishDurableSessionEvents5 } from "@opengeni/events";
|
|
9757
10056
|
|
|
9758
10057
|
// src/activities/codex-fleet-shadow.ts
|
|
9759
10058
|
import {
|
|
@@ -10288,7 +10587,7 @@ async function selectCodexTurnCapacity(deps) {
|
|
|
10288
10587
|
}
|
|
10289
10588
|
});
|
|
10290
10589
|
if (armed.action === "waiting") {
|
|
10291
|
-
await
|
|
10590
|
+
await publishDurableSessionEvents5(bus, input.workspaceId, input.sessionId, armed.events);
|
|
10292
10591
|
control.turnMetricOutcome = "recovering";
|
|
10293
10592
|
control.activityStatus = "waiting_capacity";
|
|
10294
10593
|
return {
|
|
@@ -10383,7 +10682,7 @@ async function selectCodexTurnCapacity(deps) {
|
|
|
10383
10682
|
failurePayload
|
|
10384
10683
|
});
|
|
10385
10684
|
if (armed.action === "waiting") {
|
|
10386
|
-
await
|
|
10685
|
+
await publishDurableSessionEvents5(bus, input.workspaceId, input.sessionId, armed.events);
|
|
10387
10686
|
control.turnMetricOutcome = "recovering";
|
|
10388
10687
|
control.activityStatus = "waiting_capacity";
|
|
10389
10688
|
return {
|
|
@@ -11065,7 +11364,7 @@ async function prepareGovernanceAndModel(deps) {
|
|
|
11065
11364
|
|
|
11066
11365
|
// src/activities/agent-turn/compaction-prep.ts
|
|
11067
11366
|
import { hasPendingSteerAfterContextCompaction, isSessionCompactionRequested as isSessionCompactionRequested2 } from "@opengeni/db";
|
|
11068
|
-
import { publishDurableSessionEvents as
|
|
11367
|
+
import { publishDurableSessionEvents as publishDurableSessionEvents6 } from "@opengeni/events";
|
|
11069
11368
|
import {
|
|
11070
11369
|
appendSessionInstructions,
|
|
11071
11370
|
appendWorkspaceGovernance,
|
|
@@ -11201,10 +11500,10 @@ async function prepareCompaction(deps) {
|
|
|
11201
11500
|
});
|
|
11202
11501
|
}) : void 0;
|
|
11203
11502
|
const publishCompactionLiveEvents = async (events) => {
|
|
11204
|
-
await
|
|
11503
|
+
await publishDurableSessionEvents6(bus, input.workspaceId, input.sessionId, events);
|
|
11205
11504
|
};
|
|
11206
11505
|
const publishCompactionOutcomeEvents = async (events) => {
|
|
11207
|
-
await
|
|
11506
|
+
await publishDurableSessionEvents6(
|
|
11208
11507
|
bus,
|
|
11209
11508
|
input.workspaceId,
|
|
11210
11509
|
input.sessionId,
|
|
@@ -11214,6 +11513,7 @@ async function prepareCompaction(deps) {
|
|
|
11214
11513
|
const compactionModeOptions = {
|
|
11215
11514
|
codexCompactionMode: session.codexCompactionMode,
|
|
11216
11515
|
isCodexSubscriptionTurn: billingState.isCodexTurn,
|
|
11516
|
+
onCompactionStarted: (trigger) => recordContextCompactionStarted(observability, trigger),
|
|
11217
11517
|
publishLiveEvents: publishCompactionLiveEvents,
|
|
11218
11518
|
...remoteCompactionRequester ? { requestRemoteCompactionV2: remoteCompactionRequester } : {}
|
|
11219
11519
|
};
|
|
@@ -11650,6 +11950,12 @@ import {
|
|
|
11650
11950
|
sandboxWarmRateMicrosPerSecond
|
|
11651
11951
|
} from "@opengeni/config";
|
|
11652
11952
|
import { ChannelAPartialMutationError } from "@opengeni/runtime/sandbox";
|
|
11953
|
+
function preemptSandboxTurnForDeadlineRotation(input) {
|
|
11954
|
+
if (input.controller.signal.aborted || input.cancellationSignal?.aborted) return false;
|
|
11955
|
+
input.sandboxState.deadlineRotationRequested = true;
|
|
11956
|
+
input.controller.abort(new SandboxDeadlineRotationError(input.sandboxGroupId, input.leaseEpoch));
|
|
11957
|
+
return true;
|
|
11958
|
+
}
|
|
11653
11959
|
function createSandboxTurnRuntime(deps) {
|
|
11654
11960
|
const {
|
|
11655
11961
|
input,
|
|
@@ -11772,7 +12078,7 @@ function createSandboxTurnRuntime(deps) {
|
|
|
11772
12078
|
admissionOutcome = "completed";
|
|
11773
12079
|
} catch (admissionError) {
|
|
11774
12080
|
if (admissionError instanceof SandboxWorkspaceMutationFencedError && admissionError.code === "rotation_in_progress" && sandboxState.sandboxGroupId) {
|
|
11775
|
-
void
|
|
12081
|
+
void beginRotationPreemption(
|
|
11776
12082
|
sandbox,
|
|
11777
12083
|
sandbox.leaseEpoch,
|
|
11778
12084
|
sandboxState.sandboxGroupId
|
|
@@ -11883,51 +12189,30 @@ function createSandboxTurnRuntime(deps) {
|
|
|
11883
12189
|
console.error("sandbox box lost event publish failed", safeErrorDiagnostic(publishError));
|
|
11884
12190
|
});
|
|
11885
12191
|
};
|
|
11886
|
-
const
|
|
11887
|
-
if (sandboxState.
|
|
12192
|
+
const beginRotationPreemption = async (sandbox, rotationEpoch, rotationGroupId) => {
|
|
12193
|
+
if (sandboxState.rotationPreemptionInFlight || sandboxRotationController.signal.aborted || cancellationSignal?.aborted) {
|
|
11888
12194
|
return "busy";
|
|
11889
12195
|
}
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
return "not_rotating";
|
|
12196
|
+
if (sandboxState.rotationPreemptionInFlight || sandboxRotationController.signal.aborted) {
|
|
12197
|
+
return "busy";
|
|
11893
12198
|
}
|
|
11894
|
-
|
|
11895
|
-
sandboxState.
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
settings.sandboxSnapshotTimeoutMs,
|
|
11900
|
-
cancellationSignal
|
|
11901
|
-
);
|
|
11902
|
-
}
|
|
11903
|
-
const snapshotSession = sandboxState.setupBoxSession;
|
|
11904
|
-
const snapshotTurnId = attempt.turnId;
|
|
11905
|
-
if (!snapshotSession || !snapshotTurnId) return;
|
|
11906
|
-
const checkpoint = await persistSandboxDeadlineRotationCheckpoint(
|
|
11907
|
-
{ db, settings, objectStorage, observability },
|
|
11908
|
-
{
|
|
11909
|
-
accountId: input.accountId,
|
|
11910
|
-
workspaceId: input.workspaceId,
|
|
11911
|
-
sessionId: input.sessionId,
|
|
11912
|
-
turnId: snapshotTurnId,
|
|
11913
|
-
attemptId: input.attemptId,
|
|
11914
|
-
sandboxGroupId: rotationGroupId
|
|
11915
|
-
},
|
|
11916
|
-
snapshotSession,
|
|
11917
|
-
{ leaseEpoch: rotationEpoch, instanceId: sandbox.established.instanceId },
|
|
11918
|
-
cancellationSignal
|
|
11919
|
-
);
|
|
11920
|
-
if (checkpoint.checkpointed) {
|
|
11921
|
-
sandboxRotationController.abort(
|
|
11922
|
-
new SandboxDeadlineRotationError(rotationGroupId, rotationEpoch)
|
|
11923
|
-
);
|
|
12199
|
+
let disposition = "started";
|
|
12200
|
+
sandboxState.rotationPreemptionInFlight = (async () => {
|
|
12201
|
+
const rotatingLease = await readLease2(db, input.workspaceId, rotationGroupId);
|
|
12202
|
+
if (rotatingLease?.leaseEpoch !== rotationEpoch || rotatingLease.instanceId !== sandbox.established.instanceId || rotatingLease.rotationRequestedAt === null) {
|
|
12203
|
+
disposition = "not_rotating";
|
|
11924
12204
|
return;
|
|
11925
12205
|
}
|
|
11926
|
-
|
|
11927
|
-
|
|
11928
|
-
|
|
12206
|
+
stopLeaseHeartbeat();
|
|
12207
|
+
preemptSandboxTurnForDeadlineRotation({
|
|
12208
|
+
controller: sandboxRotationController,
|
|
12209
|
+
sandboxState,
|
|
12210
|
+
sandboxGroupId: rotationGroupId,
|
|
12211
|
+
leaseEpoch: rotationEpoch,
|
|
12212
|
+
...cancellationSignal ? { cancellationSignal } : {}
|
|
12213
|
+
});
|
|
11929
12214
|
})().catch((error) => {
|
|
11930
|
-
observability.warn("sandbox deadline rotation
|
|
12215
|
+
observability.warn("sandbox deadline rotation preemption check failed; retrying", {
|
|
11931
12216
|
workspaceId: input.workspaceId,
|
|
11932
12217
|
sessionId: input.sessionId,
|
|
11933
12218
|
sandboxGroupId: rotationGroupId,
|
|
@@ -11935,10 +12220,10 @@ function createSandboxTurnRuntime(deps) {
|
|
|
11935
12220
|
...safeErrorDiagnostic(error)
|
|
11936
12221
|
});
|
|
11937
12222
|
}).finally(() => {
|
|
11938
|
-
sandboxState.
|
|
12223
|
+
sandboxState.rotationPreemptionInFlight = null;
|
|
11939
12224
|
});
|
|
11940
|
-
await sandboxState.
|
|
11941
|
-
return
|
|
12225
|
+
await sandboxState.rotationPreemptionInFlight;
|
|
12226
|
+
return disposition;
|
|
11942
12227
|
};
|
|
11943
12228
|
const startLeaseHeartbeat = (sandbox, warmBackend) => {
|
|
11944
12229
|
if (sandboxState.leaseHeartbeatTimer) return;
|
|
@@ -11963,7 +12248,7 @@ function createSandboxTurnRuntime(deps) {
|
|
|
11963
12248
|
expectedEpoch: heartbeatEpoch
|
|
11964
12249
|
}).then(async (alive) => {
|
|
11965
12250
|
if (alive) return;
|
|
11966
|
-
const rotation = await
|
|
12251
|
+
const rotation = await beginRotationPreemption(sandbox, heartbeatEpoch, heartbeatGroupId);
|
|
11967
12252
|
if (rotation === "not_rotating") {
|
|
11968
12253
|
stopLeaseHeartbeat();
|
|
11969
12254
|
}
|
|
@@ -11981,9 +12266,10 @@ function createSandboxTurnRuntime(deps) {
|
|
|
11981
12266
|
if (snapshotSession && snapshotTurnId && shouldStartPeriodicWorkspaceSnapshot({
|
|
11982
12267
|
firstProviderRequestStarted: sandboxState.firstProviderRequestStarted,
|
|
11983
12268
|
snapshotInFlight: Boolean(sandboxState.snapshotInFlight),
|
|
11984
|
-
turnEndCaptureInProgress: sandboxState.turnEndCaptureInProgress
|
|
12269
|
+
turnEndCaptureInProgress: sandboxState.turnEndCaptureInProgress,
|
|
12270
|
+
deadlineRotationRequested: sandboxState.deadlineRotationRequested
|
|
11985
12271
|
})) {
|
|
11986
|
-
|
|
12272
|
+
const snapshot = maybePersistWarmWorkspaceSnapshot(
|
|
11987
12273
|
{ db, settings, objectStorage },
|
|
11988
12274
|
{
|
|
11989
12275
|
accountId: input.accountId,
|
|
@@ -11996,7 +12282,9 @@ function createSandboxTurnRuntime(deps) {
|
|
|
11996
12282
|
snapshotSession,
|
|
11997
12283
|
heartbeatEpoch,
|
|
11998
12284
|
activityContext?.cancellationSignal
|
|
11999
|
-
)
|
|
12285
|
+
);
|
|
12286
|
+
sandboxState.snapshotInFlight = snapshot.settled;
|
|
12287
|
+
void snapshot.then(async (persisted) => {
|
|
12000
12288
|
if (persisted && eventing.publish) {
|
|
12001
12289
|
await eventing.publish([
|
|
12002
12290
|
{
|
|
@@ -12005,8 +12293,11 @@ function createSandboxTurnRuntime(deps) {
|
|
|
12005
12293
|
}
|
|
12006
12294
|
]);
|
|
12007
12295
|
}
|
|
12008
|
-
}).catch(() => void 0)
|
|
12009
|
-
|
|
12296
|
+
}).catch(() => void 0);
|
|
12297
|
+
void snapshot.settled.then(() => {
|
|
12298
|
+
if (sandboxState.snapshotInFlight === snapshot.settled) {
|
|
12299
|
+
sandboxState.snapshotInFlight = null;
|
|
12300
|
+
}
|
|
12010
12301
|
});
|
|
12011
12302
|
}
|
|
12012
12303
|
}, 1e4);
|
|
@@ -13961,7 +14252,7 @@ import {
|
|
|
13961
14252
|
XAI_CREDENTIAL_LEASE_TTL_MS as XAI_CREDENTIAL_LEASE_TTL_MS2,
|
|
13962
14253
|
armXaiCapacityWait as armXaiCapacityWait2
|
|
13963
14254
|
} from "@opengeni/db";
|
|
13964
|
-
import { publishDurableSessionEvents as
|
|
14255
|
+
import { publishDurableSessionEvents as publishDurableSessionEvents7 } from "@opengeni/events";
|
|
13965
14256
|
async function selectXaiTurnCapacity(deps) {
|
|
13966
14257
|
const {
|
|
13967
14258
|
input,
|
|
@@ -14068,7 +14359,7 @@ async function selectXaiTurnCapacity(deps) {
|
|
|
14068
14359
|
}
|
|
14069
14360
|
});
|
|
14070
14361
|
if (armed.action === "waiting") {
|
|
14071
|
-
await
|
|
14362
|
+
await publishDurableSessionEvents7(bus, input.workspaceId, input.sessionId, armed.events);
|
|
14072
14363
|
control.turnMetricOutcome = "recovering";
|
|
14073
14364
|
control.activityStatus = "waiting_capacity";
|
|
14074
14365
|
return {
|
|
@@ -15067,16 +15358,18 @@ import {
|
|
|
15067
15358
|
getWorkspaceModelPolicy as getWorkspaceModelPolicy2,
|
|
15068
15359
|
listWorkspaceGatewayCustomModels as listWorkspaceGatewayCustomModels2,
|
|
15069
15360
|
listWorkspaceOpenRouterCustomModels as listWorkspaceOpenRouterCustomModels2,
|
|
15361
|
+
listOrganizationModelProviderCustomModelsForWorkspace as listOrganizationModelProviderCustomModelsForWorkspace2,
|
|
15362
|
+
organizationModelProviderConnectionActiveForWorkspace,
|
|
15070
15363
|
persistAttemptToolCatalog,
|
|
15071
15364
|
namedSubjectHasLiveWorkspaceAuthority as namedSubjectHasLiveWorkspaceAuthority2,
|
|
15072
|
-
updateSessionTitleWithEvent,
|
|
15365
|
+
updateSessionTitleWithEvent as updateSessionTitleWithEvent2,
|
|
15073
15366
|
withCodexAppsRequestAuthorization,
|
|
15074
15367
|
workspaceCodexSubscriptionActive as workspaceCodexSubscriptionActive3,
|
|
15075
15368
|
workspaceVercelAiGatewayConnectionActive,
|
|
15076
15369
|
workspaceOpenRouterConnectionActive,
|
|
15077
15370
|
workspaceXaiSubscriptionActiveForAuthority
|
|
15078
15371
|
} from "@opengeni/db";
|
|
15079
|
-
import { publishDurableSessionEvents as
|
|
15372
|
+
import { publishDurableSessionEvents as publishDurableSessionEvents9 } from "@opengeni/events";
|
|
15080
15373
|
import {
|
|
15081
15374
|
createFirstPartyInteractionAttemptToolDefinitions
|
|
15082
15375
|
} from "@opengeni/runtime";
|
|
@@ -15751,6 +16044,7 @@ import {
|
|
|
15751
16044
|
sessionTenancyProductActivated
|
|
15752
16045
|
} from "@opengeni/db";
|
|
15753
16046
|
import { recordTenancyCompatibilityLaneUse } from "@opengeni/observability";
|
|
16047
|
+
var OPENGENI_CONNECTION_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
|
|
15754
16048
|
function connectionTokenResolverForTurn(input) {
|
|
15755
16049
|
const hostResolver = input.connectionCredentials?.mcpCredentials;
|
|
15756
16050
|
const baseResolver = hostResolver ? buildHostConnectionTokenResolver(hostResolver, {
|
|
@@ -15766,6 +16060,37 @@ function connectionTokenResolverForTurn(input) {
|
|
|
15766
16060
|
surface: "model"
|
|
15767
16061
|
}) : buildConnectionTokenResolver(input.db, input.settings);
|
|
15768
16062
|
return async (request) => {
|
|
16063
|
+
if (request.connectionRef.authoritySource === "host") {
|
|
16064
|
+
if (hostResolver) return await baseResolver(request);
|
|
16065
|
+
return {
|
|
16066
|
+
status: "auth_needed",
|
|
16067
|
+
reason: "unsupported_auth",
|
|
16068
|
+
providerDomain: request.connectionRef.providerDomain,
|
|
16069
|
+
authoritySource: "host",
|
|
16070
|
+
...request.connectionRef.provider ? { provider: request.connectionRef.provider } : {},
|
|
16071
|
+
...request.connectionRef.connectionId ? { connectionId: request.connectionRef.connectionId } : {},
|
|
16072
|
+
...request.connectionRef.scopes ? { scopes: request.connectionRef.scopes } : {},
|
|
16073
|
+
...request.connectionRef.resource ? { resource: request.connectionRef.resource } : {},
|
|
16074
|
+
...request.connectionRef.selectedResources ? { selectedResources: request.connectionRef.selectedResources } : {}
|
|
16075
|
+
};
|
|
16076
|
+
}
|
|
16077
|
+
if (hostResolver && request.connectionRef.connectionId && !OPENGENI_CONNECTION_ID_PATTERN.test(request.connectionRef.connectionId)) {
|
|
16078
|
+
try {
|
|
16079
|
+
return await baseResolver(request);
|
|
16080
|
+
} catch {
|
|
16081
|
+
return {
|
|
16082
|
+
status: "auth_needed",
|
|
16083
|
+
reason: "refresh_failed",
|
|
16084
|
+
providerDomain: request.connectionRef.providerDomain,
|
|
16085
|
+
authoritySource: "host",
|
|
16086
|
+
...request.connectionRef.provider ? { provider: request.connectionRef.provider } : {},
|
|
16087
|
+
connectionId: request.connectionRef.connectionId,
|
|
16088
|
+
...request.connectionRef.scopes ? { scopes: request.connectionRef.scopes } : {},
|
|
16089
|
+
...request.connectionRef.resource ? { resource: request.connectionRef.resource } : {},
|
|
16090
|
+
...request.connectionRef.selectedResources ? { selectedResources: request.connectionRef.selectedResources } : {}
|
|
16091
|
+
};
|
|
16092
|
+
}
|
|
16093
|
+
}
|
|
15769
16094
|
const acceptedDelegation = input.turn.personalConnectionDelegations.find(
|
|
15770
16095
|
(delegation) => (delegation.connectionType === void 0 || delegation.connectionType === "mcp" || delegation.connectionType === "github_personal" && delegation.serverId === "github:personal" && request.serverId === "github:personal" && request.connectionRef.provider === "github" && request.connectionRef.kind === "oauth2" && request.connectionRef.providerDomain === "github.com" && request.credentialTarget === "http_api" && isGitHubApiDestination(request.destinationUrl)) && delegation.serverId === request.serverId && delegation.connectionId === request.connectionRef.connectionId
|
|
15771
16096
|
);
|
|
@@ -15928,7 +16253,13 @@ function integrationCredentialResolver(input, integration) {
|
|
|
15928
16253
|
forceRefresh: request.forceRefresh === true
|
|
15929
16254
|
});
|
|
15930
16255
|
if (result.status === "auth_needed") {
|
|
15931
|
-
await publishAuthNeeded(
|
|
16256
|
+
await publishAuthNeeded(
|
|
16257
|
+
input,
|
|
16258
|
+
integration.serverId,
|
|
16259
|
+
request.operationKey,
|
|
16260
|
+
result,
|
|
16261
|
+
connectionRef
|
|
16262
|
+
);
|
|
15932
16263
|
return null;
|
|
15933
16264
|
}
|
|
15934
16265
|
const destination = new URL(request.destinationUrl);
|
|
@@ -15946,7 +16277,7 @@ function integrationCredentialResolver(input, integration) {
|
|
|
15946
16277
|
}
|
|
15947
16278
|
};
|
|
15948
16279
|
}
|
|
15949
|
-
async function publishAuthNeeded(input, serverId, toolName, result) {
|
|
16280
|
+
async function publishAuthNeeded(input, serverId, toolName, result, connectionRef) {
|
|
15950
16281
|
try {
|
|
15951
16282
|
await input.onAuthNeeded?.({
|
|
15952
16283
|
serverId,
|
|
@@ -15955,6 +16286,7 @@ async function publishAuthNeeded(input, serverId, toolName, result) {
|
|
|
15955
16286
|
...result.provider ? { provider: result.provider } : {},
|
|
15956
16287
|
reason: result.reason,
|
|
15957
16288
|
...result.connectionId ? { connectionId: result.connectionId } : {},
|
|
16289
|
+
...result.authoritySource === "host" || connectionRef.authoritySource === "host" ? { authoritySource: "host" } : {},
|
|
15958
16290
|
...result.scopes ? { scopes: result.scopes } : {},
|
|
15959
16291
|
...result.resource ? { resource: result.resource } : {},
|
|
15960
16292
|
...result.selectedResources ? { selectedResources: result.selectedResources } : {},
|
|
@@ -16632,7 +16964,7 @@ import {
|
|
|
16632
16964
|
} from "@opengeni/db";
|
|
16633
16965
|
import {
|
|
16634
16966
|
appendAndPublishTurnEventsFenced as appendAndPublishTurnEventsFenced3,
|
|
16635
|
-
publishDurableSessionEvents as
|
|
16967
|
+
publishDurableSessionEvents as publishDurableSessionEvents8
|
|
16636
16968
|
} from "@opengeni/events";
|
|
16637
16969
|
var CodemodeAttemptDispatcher = class {
|
|
16638
16970
|
constructor(db, bus, environment, scope, turnSignal, maxConcurrentCalls = CODEMODE_MAX_CONCURRENT_CALLS_PER_ATTEMPT) {
|
|
@@ -16841,7 +17173,7 @@ var CodemodeAttemptDispatcher = class {
|
|
|
16841
17173
|
settlement
|
|
16842
17174
|
});
|
|
16843
17175
|
if (!result.committed || result.events.length === 0) return;
|
|
16844
|
-
await
|
|
17176
|
+
await publishDurableSessionEvents8(
|
|
16845
17177
|
this.bus,
|
|
16846
17178
|
this.scope.workspaceId,
|
|
16847
17179
|
this.scope.sessionId,
|
|
@@ -16899,84 +17231,6 @@ import {
|
|
|
16899
17231
|
import { SandboxChannelAService as SandboxChannelAService3 } from "@opengeni/runtime/sandbox";
|
|
16900
17232
|
import { sandboxRunAs as sandboxRunAs4 } from "@opengeni/runtime";
|
|
16901
17233
|
|
|
16902
|
-
// src/activities/agent-turn/session-title.ts
|
|
16903
|
-
import { hasPermission } from "@opengeni/core";
|
|
16904
|
-
import {
|
|
16905
|
-
AUTOMATIC_SESSION_TITLE_FALLBACK,
|
|
16906
|
-
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS
|
|
16907
|
-
} from "@opengeni/contracts";
|
|
16908
|
-
var SESSION_TITLE_MODEL_TOOL_NAME = "opengeni__set_session_title";
|
|
16909
|
-
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.";
|
|
16910
|
-
function shouldRequestMissingSessionTitle(input) {
|
|
16911
|
-
const title = input.title?.trim() ?? "";
|
|
16912
|
-
const needsSemanticTitle = input.titleSource !== "user" && (!title || title === AUTOMATIC_SESSION_TITLE_FALLBACK);
|
|
16913
|
-
if (!needsSemanticTitle) return false;
|
|
16914
|
-
if (!input.firstPartyMcpTools.includes("set_session_title")) return false;
|
|
16915
|
-
const permissions = input.firstPartyMcpPermissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS;
|
|
16916
|
-
return hasPermission([...permissions], "sessions:control");
|
|
16917
|
-
}
|
|
16918
|
-
function sessionTitleToolPlan(input) {
|
|
16919
|
-
const promoteTitleTool = input.shouldRequestTitle && input.tools.some((tool) => tool.kind === "mcp" && tool.id === "opengeni");
|
|
16920
|
-
return {
|
|
16921
|
-
promoteTitleTool,
|
|
16922
|
-
remoteFirstPartyMcpTools: promoteTitleTool ? input.selectedFirstPartyMcpTools.filter((tool) => tool !== "set_session_title") : [...input.selectedFirstPartyMcpTools],
|
|
16923
|
-
preparationIndependentToolNames: promoteTitleTool ? [SESSION_TITLE_MODEL_TOOL_NAME] : []
|
|
16924
|
-
};
|
|
16925
|
-
}
|
|
16926
|
-
function createSessionTitleAttemptToolDefinition(input) {
|
|
16927
|
-
return {
|
|
16928
|
-
identity: { serverId: "opengeni", toolName: "set_session_title" },
|
|
16929
|
-
modelName: SESSION_TITLE_MODEL_TOOL_NAME,
|
|
16930
|
-
codemodePath: ["opengeni", "set_session_title"],
|
|
16931
|
-
title: "Set session title",
|
|
16932
|
-
description: SESSION_TITLE_DESCRIPTION,
|
|
16933
|
-
inputSchema: {
|
|
16934
|
-
type: "object",
|
|
16935
|
-
properties: {
|
|
16936
|
-
title: { type: "string", minLength: 1, maxLength: 200 }
|
|
16937
|
-
},
|
|
16938
|
-
required: ["title"],
|
|
16939
|
-
additionalProperties: false
|
|
16940
|
-
},
|
|
16941
|
-
outputSchema: {
|
|
16942
|
-
type: "object",
|
|
16943
|
-
properties: {
|
|
16944
|
-
ok: { type: "boolean", const: true },
|
|
16945
|
-
updated: { type: "boolean" },
|
|
16946
|
-
title: { type: "string" }
|
|
16947
|
-
},
|
|
16948
|
-
required: ["ok", "updated", "title"],
|
|
16949
|
-
additionalProperties: false
|
|
16950
|
-
},
|
|
16951
|
-
annotations: {
|
|
16952
|
-
title: "Set session title",
|
|
16953
|
-
readOnlyHint: false,
|
|
16954
|
-
destructiveHint: false,
|
|
16955
|
-
idempotentHint: true,
|
|
16956
|
-
openWorldHint: false
|
|
16957
|
-
},
|
|
16958
|
-
source: "opengeni",
|
|
16959
|
-
approval: "none",
|
|
16960
|
-
execute: async (args) => {
|
|
16961
|
-
const title = args.title;
|
|
16962
|
-
if (typeof title !== "string") {
|
|
16963
|
-
throw new Error("set_session_title requires a title string");
|
|
16964
|
-
}
|
|
16965
|
-
const result = await input.updateTitle(title);
|
|
16966
|
-
const output = {
|
|
16967
|
-
ok: true,
|
|
16968
|
-
updated: result.updated,
|
|
16969
|
-
title: result.title ?? title
|
|
16970
|
-
};
|
|
16971
|
-
return {
|
|
16972
|
-
isError: false,
|
|
16973
|
-
content: [{ type: "text", text: JSON.stringify(output) }],
|
|
16974
|
-
structuredContent: output
|
|
16975
|
-
};
|
|
16976
|
-
}
|
|
16977
|
-
};
|
|
16978
|
-
}
|
|
16979
|
-
|
|
16980
17234
|
// src/activities/agent-turn/turn-sandbox-access.ts
|
|
16981
17235
|
async function resolveTurnSandboxAccess(sandboxState, sdkOwnedSandboxSession, unavailableMessage) {
|
|
16982
17236
|
let sandbox = sandboxState.resolvedSandbox;
|
|
@@ -17295,7 +17549,10 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
17295
17549
|
if (!shouldPublishToolAuthNeededForTurn(payload, trigger, turn)) {
|
|
17296
17550
|
return;
|
|
17297
17551
|
}
|
|
17298
|
-
await eventing.publish(
|
|
17552
|
+
await eventing.publish(
|
|
17553
|
+
[{ type: "tool.auth_needed", payload: rollingSafeToolAuthNeededPayload(payload) }],
|
|
17554
|
+
true
|
|
17555
|
+
);
|
|
17299
17556
|
};
|
|
17300
17557
|
const selectedApiIntegrationServerIds = new Set(turnTools.map((tool) => tool.id));
|
|
17301
17558
|
const apiIntegrationMcpServers = buildApiIntegrationServersForTurn({
|
|
@@ -17362,7 +17619,8 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
17362
17619
|
titleSource: session.titleSource,
|
|
17363
17620
|
firstPartyMcpTools: selectedFirstPartyMcpTools,
|
|
17364
17621
|
firstPartyMcpPermissions: session.firstPartyMcpPermissions
|
|
17365
|
-
})
|
|
17622
|
+
}),
|
|
17623
|
+
parallelGenerationAvailable: typeof runtime.generateSessionTitle === "function"
|
|
17366
17624
|
});
|
|
17367
17625
|
const googleDrivePublicationAllowed = selectedFirstPartyMcpTools.includes("editable_artifact_export") && selectedFirstPartyMcpTools.includes("editable_artifact_export_status") && (!session.firstPartyMcpPermissions?.length || session.firstPartyMcpPermissions.includes("artifacts:read") && session.firstPartyMcpPermissions.includes("artifacts:publish"));
|
|
17368
17626
|
const googleDriveConnectorBindings = googleDrivePublicationTool && googleDrivePublicationTarget && googleDrivePublicationAllowed ? [
|
|
@@ -17389,7 +17647,11 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
17389
17647
|
workspaceGatewayConnectionActive,
|
|
17390
17648
|
workspaceGatewayCustomModels,
|
|
17391
17649
|
openRouterConnectionActive,
|
|
17392
|
-
workspaceOpenRouterCustomModels
|
|
17650
|
+
workspaceOpenRouterCustomModels,
|
|
17651
|
+
organizationGatewayConnectionActive,
|
|
17652
|
+
organizationGatewayCustomModels,
|
|
17653
|
+
organizationOpenRouterConnectionActive,
|
|
17654
|
+
organizationOpenRouterCustomModels
|
|
17393
17655
|
] = await Promise.all([
|
|
17394
17656
|
getWorkspaceModelPolicy2(db, input.workspaceId),
|
|
17395
17657
|
workspaceCodexSubscriptionActive3(db, currentSettings, input.workspaceId),
|
|
@@ -17406,6 +17668,26 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
17406
17668
|
listWorkspaceOpenRouterCustomModels2(db, {
|
|
17407
17669
|
accountId: input.accountId,
|
|
17408
17670
|
workspaceId: input.workspaceId
|
|
17671
|
+
}),
|
|
17672
|
+
organizationModelProviderConnectionActiveForWorkspace(db, {
|
|
17673
|
+
accountId: input.accountId,
|
|
17674
|
+
workspaceId: input.workspaceId,
|
|
17675
|
+
providerKind: "vercel_gateway"
|
|
17676
|
+
}),
|
|
17677
|
+
listOrganizationModelProviderCustomModelsForWorkspace2(db, {
|
|
17678
|
+
accountId: input.accountId,
|
|
17679
|
+
workspaceId: input.workspaceId,
|
|
17680
|
+
providerKind: "vercel_gateway"
|
|
17681
|
+
}),
|
|
17682
|
+
organizationModelProviderConnectionActiveForWorkspace(db, {
|
|
17683
|
+
accountId: input.accountId,
|
|
17684
|
+
workspaceId: input.workspaceId,
|
|
17685
|
+
providerKind: "openrouter"
|
|
17686
|
+
}),
|
|
17687
|
+
listOrganizationModelProviderCustomModelsForWorkspace2(db, {
|
|
17688
|
+
accountId: input.accountId,
|
|
17689
|
+
workspaceId: input.workspaceId,
|
|
17690
|
+
providerKind: "openrouter"
|
|
17409
17691
|
})
|
|
17410
17692
|
]);
|
|
17411
17693
|
return {
|
|
@@ -17417,7 +17699,11 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
17417
17699
|
workspaceGatewayConnectionActive,
|
|
17418
17700
|
workspaceGatewayCustomModels,
|
|
17419
17701
|
workspaceOpenRouterConnectionActive: openRouterConnectionActive,
|
|
17420
|
-
workspaceOpenRouterCustomModels
|
|
17702
|
+
workspaceOpenRouterCustomModels,
|
|
17703
|
+
organizationGatewayConnectionActive,
|
|
17704
|
+
organizationGatewayCustomModels,
|
|
17705
|
+
organizationOpenRouterConnectionActive,
|
|
17706
|
+
organizationOpenRouterCustomModels
|
|
17421
17707
|
}),
|
|
17422
17708
|
modelNotes: currentCatalog.modelNotes
|
|
17423
17709
|
};
|
|
@@ -17426,13 +17712,13 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
17426
17712
|
...titleToolPlan.promoteTitleTool ? [
|
|
17427
17713
|
createSessionTitleAttemptToolDefinition({
|
|
17428
17714
|
updateTitle: async (title) => {
|
|
17429
|
-
const result = await
|
|
17715
|
+
const result = await updateSessionTitleWithEvent2(db, {
|
|
17430
17716
|
workspaceId: input.workspaceId,
|
|
17431
17717
|
sessionId: input.sessionId,
|
|
17432
17718
|
title,
|
|
17433
17719
|
source: "agent"
|
|
17434
17720
|
});
|
|
17435
|
-
await
|
|
17721
|
+
await publishDurableSessionEvents9(
|
|
17436
17722
|
bus,
|
|
17437
17723
|
input.workspaceId,
|
|
17438
17724
|
input.sessionId,
|
|
@@ -17636,6 +17922,7 @@ async function prepareTurnToolRuntime(deps) {
|
|
|
17636
17922
|
...githubRestMcp.connectorBindings
|
|
17637
17923
|
],
|
|
17638
17924
|
connectorActionIdentity,
|
|
17925
|
+
generateSessionTitleInParallel: titleToolPlan.generateTitleInParallel,
|
|
17639
17926
|
postToolPreparationStartedAt,
|
|
17640
17927
|
preparationIndependentToolNames: titleToolPlan.preparationIndependentToolNames
|
|
17641
17928
|
};
|
|
@@ -17838,7 +18125,7 @@ import {
|
|
|
17838
18125
|
prepareConnectorActionApproval as prepareConnectorActionApproval3
|
|
17839
18126
|
} from "@opengeni/db";
|
|
17840
18127
|
import {
|
|
17841
|
-
serviceTierForLatencyMode,
|
|
18128
|
+
serviceTierForLatencyMode as serviceTierForLatencyMode2,
|
|
17842
18129
|
environmentsEncryptionKeyBytes as environmentsEncryptionKeyBytes4,
|
|
17843
18130
|
WORKSPACE_GATEWAY_PROVIDER_ID as WORKSPACE_GATEWAY_PROVIDER_ID2,
|
|
17844
18131
|
resolveModelProvider as resolveModelProvider2
|
|
@@ -19354,7 +19641,7 @@ async function buildTurnAgent(deps) {
|
|
|
19354
19641
|
}
|
|
19355
19642
|
};
|
|
19356
19643
|
})();
|
|
19357
|
-
const serviceTier =
|
|
19644
|
+
const serviceTier = serviceTierForLatencyMode2(
|
|
19358
19645
|
turnExecutionPolicy.providerId,
|
|
19359
19646
|
turnExecutionPolicy.latencyMode
|
|
19360
19647
|
);
|
|
@@ -19553,6 +19840,32 @@ async function buildTurnAgent(deps) {
|
|
|
19553
19840
|
}
|
|
19554
19841
|
|
|
19555
19842
|
// src/activities/agent-turn/run.ts
|
|
19843
|
+
function sessionTitleCodexRequestContext(context, nextRequestId) {
|
|
19844
|
+
return {
|
|
19845
|
+
clientVersion: context.clientVersion,
|
|
19846
|
+
...context.sessionId !== void 0 ? { sessionId: context.sessionId } : {},
|
|
19847
|
+
getToken: context.getToken,
|
|
19848
|
+
refresh: context.refresh,
|
|
19849
|
+
resolveModel: context.resolveModel,
|
|
19850
|
+
...context.onUsageHeaders ? { onUsageHeaders: context.onUsageHeaders } : {},
|
|
19851
|
+
...context.responseTimeoutPolicy ? { responseTimeoutPolicy: context.responseTimeoutPolicy } : {},
|
|
19852
|
+
nextRequestId,
|
|
19853
|
+
turnMetadata: { request_kind: "session_title" }
|
|
19854
|
+
};
|
|
19855
|
+
}
|
|
19856
|
+
function sessionTitleXaiRequestContext(context, nextRequestId) {
|
|
19857
|
+
return {
|
|
19858
|
+
clientVersion: context.clientVersion,
|
|
19859
|
+
sessionId: context.sessionId,
|
|
19860
|
+
turnId: context.turnId,
|
|
19861
|
+
getToken: context.getToken,
|
|
19862
|
+
refresh: context.refresh,
|
|
19863
|
+
resolveModel: context.resolveModel,
|
|
19864
|
+
...context.streamIdleTimeoutMs !== void 0 ? { streamIdleTimeoutMs: context.streamIdleTimeoutMs } : {},
|
|
19865
|
+
...context.hostedToolContinuationTimeoutMs !== void 0 ? { hostedToolContinuationTimeoutMs: context.hostedToolContinuationTimeoutMs } : {},
|
|
19866
|
+
nextRequestId
|
|
19867
|
+
};
|
|
19868
|
+
}
|
|
19556
19869
|
function createRunAgentTurnActivity(services) {
|
|
19557
19870
|
const modelCheckpointMemoryCollector = createModelCheckpointMemoryCollector();
|
|
19558
19871
|
const turnCompletionMemoryCollector = createModelCheckpointMemoryCollector();
|
|
@@ -20115,6 +20428,17 @@ function createRunAgentTurnActivity(services) {
|
|
|
20115
20428
|
}
|
|
20116
20429
|
const withCodex = (fn) => codexContext ? codexRequestStorage.run(codexContext, fn) : fn();
|
|
20117
20430
|
const withProviderRequestContext = (fn) => providerTurn.xaiRequestContext ? xaiSubscriptionRequestStorage.run(providerTurn.xaiRequestContext, fn) : withCodex(fn);
|
|
20431
|
+
let codexSessionTitleRequestSequence = 0;
|
|
20432
|
+
let xaiSessionTitleRequestSequence = 0;
|
|
20433
|
+
const codexSessionTitleContext = codexContext ? sessionTitleCodexRequestContext(
|
|
20434
|
+
codexContext,
|
|
20435
|
+
() => `${dispatchId}:title:${++codexSessionTitleRequestSequence}`
|
|
20436
|
+
) : null;
|
|
20437
|
+
const xaiSessionTitleContext = providerTurn.xaiRequestContext ? sessionTitleXaiRequestContext(
|
|
20438
|
+
providerTurn.xaiRequestContext,
|
|
20439
|
+
() => `${dispatchId}:xai:title:${++xaiSessionTitleRequestSequence}`
|
|
20440
|
+
) : null;
|
|
20441
|
+
const withSessionTitleProviderRequestContext = (fn) => xaiSessionTitleContext ? xaiSubscriptionRequestStorage.run(xaiSessionTitleContext, fn) : codexSessionTitleContext ? codexRequestStorage.run(codexSessionTitleContext, fn) : fn();
|
|
20118
20442
|
const withCodexRemoteCompaction = (fn) => withCodex(
|
|
20119
20443
|
() => withCodexRequestOverrides(
|
|
20120
20444
|
{
|
|
@@ -20425,6 +20749,7 @@ function createRunAgentTurnActivity(services) {
|
|
|
20425
20749
|
const {
|
|
20426
20750
|
attemptConnectorActionBindings,
|
|
20427
20751
|
connectorActionIdentity,
|
|
20752
|
+
generateSessionTitleInParallel,
|
|
20428
20753
|
postToolPreparationStartedAt,
|
|
20429
20754
|
preparationIndependentToolNames
|
|
20430
20755
|
} = toolRuntime;
|
|
@@ -20711,6 +21036,7 @@ function createRunAgentTurnActivity(services) {
|
|
|
20711
21036
|
input,
|
|
20712
21037
|
settings: capabilitySettings,
|
|
20713
21038
|
db,
|
|
21039
|
+
bus,
|
|
20714
21040
|
runtime,
|
|
20715
21041
|
objectStorage,
|
|
20716
21042
|
observability,
|
|
@@ -20741,6 +21067,7 @@ function createRunAgentTurnActivity(services) {
|
|
|
20741
21067
|
attachCodemodeTokenRenewal,
|
|
20742
21068
|
attachRunCredentialRenewal,
|
|
20743
21069
|
withProviderRequestContext,
|
|
21070
|
+
withSessionTitleProviderRequestContext,
|
|
20744
21071
|
publishCompactionLiveEvents,
|
|
20745
21072
|
publishCompactionOutcomeEvents,
|
|
20746
21073
|
recordCompanyBrainContributionReceiptOnce,
|
|
@@ -20766,6 +21093,8 @@ function createRunAgentTurnActivity(services) {
|
|
|
20766
21093
|
providerApi,
|
|
20767
21094
|
runSettings,
|
|
20768
21095
|
turnTools,
|
|
21096
|
+
generateSessionTitleInParallel,
|
|
21097
|
+
sessionTitlePrompt: session.initialMessage.trim() ? session.initialMessage : turn.prompt,
|
|
20769
21098
|
compactSummarizer,
|
|
20770
21099
|
settleDeferredSteerAfterCompaction,
|
|
20771
21100
|
compactionModelHistoryProjector,
|
|
@@ -20866,7 +21195,7 @@ import {
|
|
|
20866
21195
|
settleVideoGenerationFailure,
|
|
20867
21196
|
settleVideoGenerationReady
|
|
20868
21197
|
} from "@opengeni/db";
|
|
20869
|
-
import { publishDurableSessionEvents as
|
|
21198
|
+
import { publishDurableSessionEvents as publishDurableSessionEvents10 } from "@opengeni/events";
|
|
20870
21199
|
|
|
20871
21200
|
// src/activities/gateway-video-generation.ts
|
|
20872
21201
|
import { readResponseTextBounded as readResponseTextBounded2 } from "@opengeni/network";
|
|
@@ -21668,7 +21997,7 @@ async function deliverTerminalResult(service, operation) {
|
|
|
21668
21997
|
return;
|
|
21669
21998
|
}
|
|
21670
21999
|
if (result.added && result.events.length > 0) {
|
|
21671
|
-
await
|
|
22000
|
+
await publishDurableSessionEvents10(
|
|
21672
22001
|
service.bus,
|
|
21673
22002
|
operation.workspaceId,
|
|
21674
22003
|
operation.sessionId,
|
|
@@ -21933,4 +22262,4 @@ export {
|
|
|
21933
22262
|
createTurnActivities,
|
|
21934
22263
|
createTurnActivitiesFromServices
|
|
21935
22264
|
};
|
|
21936
|
-
//# sourceMappingURL=activities-turn-
|
|
22265
|
+
//# sourceMappingURL=activities-turn-I4OPLQLS.js.map
|