@opengeni/worker-bundle 1.1.0 → 1.2.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 +3 -2
- package/dist/activities/agent-turn/compaction-prep.d.ts +1 -0
- package/dist/activities/agent-turn/finalization-monitor.d.ts +6 -1
- package/dist/activities/agent-turn/model-usage.d.ts +10 -0
- package/dist/{activities-control-XZAIMFQJ.js → activities-control-QSDPXLLD.js} +5 -5
- package/dist/activities-control-QSDPXLLD.js.map +1 -0
- package/dist/{activities-turn-4EEVNZCC.js → activities-turn-BMY3CDKL.js} +96 -32
- package/dist/activities-turn-BMY3CDKL.js.map +1 -0
- package/dist/{chunk-OT64XARC.js → chunk-JKMG5ZHH.js} +18 -6
- package/dist/{chunk-OT64XARC.js.map → chunk-JKMG5ZHH.js.map} +1 -1
- package/dist/{chunk-3ZTRWDMN.js → chunk-XONQEVAD.js} +1 -1
- package/dist/chunk-XONQEVAD.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/observability-metrics.d.ts +1 -1
- package/package.json +21 -21
- package/src/activities/agent-turn/admission.ts +11 -5
- package/src/activities/agent-turn/claim.ts +1 -0
- package/src/activities/agent-turn/compaction-prep.ts +20 -1
- package/src/activities/agent-turn/errors.ts +21 -4
- package/src/activities/agent-turn/failure-settlement.ts +9 -1
- package/src/activities/agent-turn/finalization-monitor.ts +14 -1
- package/src/activities/agent-turn/finalization.ts +5 -0
- package/src/activities/agent-turn/model-usage.ts +38 -0
- package/src/activities/agent-turn/run.ts +1 -0
- package/src/activities/agent-turn/stream-attempt.ts +22 -16
- package/src/activities/knowledge-indexing.ts +2 -2
- package/src/observability-metrics.ts +1 -0
- package/dist/activities-control-XZAIMFQJ.js.map +0 -1
- package/dist/activities-turn-4EEVNZCC.js.map +0 -1
- package/dist/chunk-3ZTRWDMN.js.map +0 -1
|
@@ -99,7 +99,7 @@ import {
|
|
|
99
99
|
withFirstPartyTools,
|
|
100
100
|
wrapLazyTurnBoxWithRouting,
|
|
101
101
|
wrapTurnBoxWithRouting
|
|
102
|
-
} from "./chunk-
|
|
102
|
+
} from "./chunk-JKMG5ZHH.js";
|
|
103
103
|
import {
|
|
104
104
|
StreamTimingMetrics,
|
|
105
105
|
makeMachineOpObserver,
|
|
@@ -132,7 +132,7 @@ import {
|
|
|
132
132
|
runtimeMetricsHooksForObservability,
|
|
133
133
|
sandboxAutomaticRecoveryOutcome,
|
|
134
134
|
turnLifecycleMetricsFor
|
|
135
|
-
} from "./chunk-
|
|
135
|
+
} from "./chunk-XONQEVAD.js";
|
|
136
136
|
import {
|
|
137
137
|
__export
|
|
138
138
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -163,7 +163,7 @@ import {
|
|
|
163
163
|
} from "@opengeni/db";
|
|
164
164
|
import {
|
|
165
165
|
sandboxOperationMetricObserver as sandboxOperationMetricObserver2,
|
|
166
|
-
turnExecutionTelemetryKey as
|
|
166
|
+
turnExecutionTelemetryKey as turnExecutionTelemetryKey3,
|
|
167
167
|
withTraceContext,
|
|
168
168
|
withMcpTelemetry
|
|
169
169
|
} from "@opengeni/observability";
|
|
@@ -3670,6 +3670,7 @@ import { fetchXaiSubscriptionQuota } from "@opengeni/xai-subscription";
|
|
|
3670
3670
|
import { environmentsEncryptionKeyBytes } from "@opengeni/config";
|
|
3671
3671
|
|
|
3672
3672
|
// src/activities/agent-turn/finalization-monitor.ts
|
|
3673
|
+
import { turnExecutionTelemetryKey } from "@opengeni/observability";
|
|
3673
3674
|
var TURN_FINALIZATION_STAGES = [
|
|
3674
3675
|
"tool_writers",
|
|
3675
3676
|
"credential_renewals",
|
|
@@ -3701,6 +3702,16 @@ function diagnose(operation) {
|
|
|
3701
3702
|
}
|
|
3702
3703
|
function startTurnFinalizationMonitor(input) {
|
|
3703
3704
|
const { observability, details } = input;
|
|
3705
|
+
const correlation = {};
|
|
3706
|
+
diagnose(() => {
|
|
3707
|
+
if (input.execution) {
|
|
3708
|
+
correlation.correlationId = turnExecutionTelemetryKey(
|
|
3709
|
+
input.execution.workspaceId,
|
|
3710
|
+
input.execution.sessionId,
|
|
3711
|
+
input.execution.attemptId
|
|
3712
|
+
);
|
|
3713
|
+
}
|
|
3714
|
+
});
|
|
3704
3715
|
if (!initialized.has(observability)) {
|
|
3705
3716
|
for (const stage2 of TURN_FINALIZATION_STAGES) {
|
|
3706
3717
|
diagnose(() => observability.incrementGauge({ ...INFLIGHT, labels: { stage: stage2 }, amount: 0 }));
|
|
@@ -3743,7 +3754,8 @@ function startTurnFinalizationMonitor(input) {
|
|
|
3743
3754
|
observability.error("turn finalization stalled; containing worker", {
|
|
3744
3755
|
surface: "turn_finalization",
|
|
3745
3756
|
outcome: "containment",
|
|
3746
|
-
reason: next
|
|
3757
|
+
reason: next,
|
|
3758
|
+
...correlation
|
|
3747
3759
|
});
|
|
3748
3760
|
} catch {
|
|
3749
3761
|
}
|
|
@@ -3756,7 +3768,8 @@ function startTurnFinalizationMonitor(input) {
|
|
|
3756
3768
|
observability.warn("turn finalization is taking longer than expected", {
|
|
3757
3769
|
surface: "turn_finalization",
|
|
3758
3770
|
outcome: "slow",
|
|
3759
|
-
reason: next
|
|
3771
|
+
reason: next,
|
|
3772
|
+
...correlation
|
|
3760
3773
|
});
|
|
3761
3774
|
}),
|
|
3762
3775
|
input.slowAfterMs ?? 3e4
|
|
@@ -4618,7 +4631,12 @@ async function finalizeTurnAttempt(deps) {
|
|
|
4618
4631
|
} catch {
|
|
4619
4632
|
}
|
|
4620
4633
|
},
|
|
4621
|
-
requestWorkerDrain: deps.requestWorkerDrain
|
|
4634
|
+
requestWorkerDrain: deps.requestWorkerDrain,
|
|
4635
|
+
execution: {
|
|
4636
|
+
workspaceId: deps.input.workspaceId,
|
|
4637
|
+
sessionId: deps.input.sessionId,
|
|
4638
|
+
attemptId: deps.input.attemptId
|
|
4639
|
+
}
|
|
4622
4640
|
});
|
|
4623
4641
|
try {
|
|
4624
4642
|
monitor.enter("tool_writers");
|
|
@@ -5259,7 +5277,7 @@ import {
|
|
|
5259
5277
|
} from "@opengeni/codex";
|
|
5260
5278
|
|
|
5261
5279
|
// src/activities/agent-turn/admission.ts
|
|
5262
|
-
import { checkWorkspaceAllowance,
|
|
5280
|
+
import { checkWorkspaceAllowance, getSpendableCreditBalance, sumUsageQuantity } from "@opengeni/db";
|
|
5263
5281
|
import {
|
|
5264
5282
|
configuredStaticUsageLimits
|
|
5265
5283
|
} from "@opengeni/config";
|
|
@@ -5268,6 +5286,7 @@ import { directPersonalConnectionSubjectId } from "@opengeni/core";
|
|
|
5268
5286
|
import { createHash as createHash7 } from "crypto";
|
|
5269
5287
|
|
|
5270
5288
|
// src/activities/agent-turn/model-usage.ts
|
|
5289
|
+
import { canonicalizeConfiguredModelId } from "@opengeni/config";
|
|
5271
5290
|
import {
|
|
5272
5291
|
applyCreditDebitUpToBalance,
|
|
5273
5292
|
recordUsageEvent,
|
|
@@ -5297,6 +5316,12 @@ function modelUsageSourceKey(input) {
|
|
|
5297
5316
|
}
|
|
5298
5317
|
return input.dispatchId ? `${input.dispatchId}:${input.positionalKey}` : input.positionalKey;
|
|
5299
5318
|
}
|
|
5319
|
+
function aggregateCreditPolicyRevision(input) {
|
|
5320
|
+
if (input.chargesOpenGeniCredits && input.responseRevisions.size > 1 && (input.totalTokens ?? 0) > 0) {
|
|
5321
|
+
throw new Error("Aggregate model usage spans different credit policy revisions");
|
|
5322
|
+
}
|
|
5323
|
+
return input.responseRevisions.size === 1 ? input.responseRevisions.values().next().value : input.lastAdmittedRevision;
|
|
5324
|
+
}
|
|
5300
5325
|
async function recordCompletedModelCallBeforeOwnershipFences(input) {
|
|
5301
5326
|
await input.renewLease();
|
|
5302
5327
|
await input.recordUsage();
|
|
@@ -5346,6 +5371,9 @@ async function processModelResponseTerminalEvent(input) {
|
|
|
5346
5371
|
if (!terminal) {
|
|
5347
5372
|
return { status: "not_response" };
|
|
5348
5373
|
}
|
|
5374
|
+
if (!terminal.usage && input.event.type === "raw_model_stream_event" && input.event.data.type !== "response_done") {
|
|
5375
|
+
return { status: "not_response" };
|
|
5376
|
+
}
|
|
5349
5377
|
const responseOrdinal = input.state.responseCount + 1;
|
|
5350
5378
|
const sourceKey = modelUsageSourceKey({
|
|
5351
5379
|
responseId: terminal.responseId,
|
|
@@ -5378,6 +5406,7 @@ async function processModelResponseTerminalEvent(input) {
|
|
|
5378
5406
|
turnId: input.turnId,
|
|
5379
5407
|
turnAttemptId: input.turnAttemptId,
|
|
5380
5408
|
model: input.model,
|
|
5409
|
+
creditPolicyRevision: input.creditPolicyRevision,
|
|
5381
5410
|
externallyBilled: input.externallyBilled,
|
|
5382
5411
|
...input.chargesOpenGeniCredits !== void 0 ? { chargesOpenGeniCredits: input.chargesOpenGeniCredits } : {},
|
|
5383
5412
|
...input.countsTowardTokenCap !== void 0 ? { countsTowardTokenCap: input.countsTowardTokenCap } : {},
|
|
@@ -5478,6 +5507,7 @@ async function processCompactionModelUsageEvent(input) {
|
|
|
5478
5507
|
turnId: input.turnId,
|
|
5479
5508
|
turnAttemptId: input.turnAttemptId,
|
|
5480
5509
|
model: input.model,
|
|
5510
|
+
creditPolicyRevision: input.creditPolicyRevision,
|
|
5481
5511
|
externallyBilled: input.externallyBilled,
|
|
5482
5512
|
...input.chargesOpenGeniCredits !== void 0 ? { chargesOpenGeniCredits: input.chargesOpenGeniCredits } : {},
|
|
5483
5513
|
...input.countsTowardTokenCap !== void 0 ? { countsTowardTokenCap: input.countsTowardTokenCap } : {},
|
|
@@ -5745,6 +5775,8 @@ async function recordModelUsageAndDebitCredits(settings, db, input) {
|
|
|
5745
5775
|
workspaceId: input.workspaceId,
|
|
5746
5776
|
type: "model_usage_debit",
|
|
5747
5777
|
requestedAmountMicros: costMicros,
|
|
5778
|
+
modelId: canonicalizeConfiguredModelId(settings, input.model),
|
|
5779
|
+
creditPolicyRevision: input.creditPolicyRevision,
|
|
5748
5780
|
sourceType: "model_response",
|
|
5749
5781
|
sourceId: `${input.turnId}:${input.sourceKey}`,
|
|
5750
5782
|
idempotencyKey: `credit:model_usage_debit:${input.turnId}:${input.sourceKey}`,
|
|
@@ -5946,7 +5978,7 @@ var AllowanceExhaustedError = class extends Error {
|
|
|
5946
5978
|
};
|
|
5947
5979
|
async function ensureRunAllowedBetweenModelCalls(input) {
|
|
5948
5980
|
try {
|
|
5949
|
-
await ensureRunAllowed(
|
|
5981
|
+
return await ensureRunAllowed(
|
|
5950
5982
|
input.settings,
|
|
5951
5983
|
input.db,
|
|
5952
5984
|
input.accountId,
|
|
@@ -5955,7 +5987,8 @@ async function ensureRunAllowedBetweenModelCalls(input) {
|
|
|
5955
5987
|
input.entitlements,
|
|
5956
5988
|
input.chargesOpenGeniCredits,
|
|
5957
5989
|
input.countsTowardTokenCap,
|
|
5958
|
-
input.initiatingHumanSubjectId
|
|
5990
|
+
input.initiatingHumanSubjectId,
|
|
5991
|
+
input.modelId
|
|
5959
5992
|
);
|
|
5960
5993
|
} catch (limitError) {
|
|
5961
5994
|
let serializedRunState = null;
|
|
@@ -5970,7 +6003,8 @@ async function ensureRunAllowedBetweenModelCalls(input) {
|
|
|
5970
6003
|
);
|
|
5971
6004
|
}
|
|
5972
6005
|
}
|
|
5973
|
-
async function ensureRunAllowed(settings, db, accountId, workspaceId, isExternallyBilledTurn, entitlements, chargesOpenGeniCredits = !isExternallyBilledTurn, countsTowardTokenCap = !isExternallyBilledTurn, initiatingHumanSubjectId = null) {
|
|
6006
|
+
async function ensureRunAllowed(settings, db, accountId, workspaceId, isExternallyBilledTurn, entitlements, chargesOpenGeniCredits = !isExternallyBilledTurn, countsTowardTokenCap = !isExternallyBilledTurn, initiatingHumanSubjectId = null, modelId) {
|
|
6007
|
+
let creditPolicyRevision;
|
|
5974
6008
|
if (chargesOpenGeniCredits && entitlements && (settings.billingMode === "stripe" || settings.usageLimitsMode === "managed")) {
|
|
5975
6009
|
const decision = await entitlements.admitRun({
|
|
5976
6010
|
accountId,
|
|
@@ -5982,7 +6016,8 @@ async function ensureRunAllowed(settings, db, accountId, workspaceId, isExternal
|
|
|
5982
6016
|
throw new Error(decision.reason || "insufficient Opengeni credits");
|
|
5983
6017
|
}
|
|
5984
6018
|
} else if (chargesOpenGeniCredits && (settings.billingMode === "stripe" || settings.usageLimitsMode === "managed")) {
|
|
5985
|
-
const balance = await
|
|
6019
|
+
const balance = await getSpendableCreditBalance(db, accountId, modelId);
|
|
6020
|
+
creditPolicyRevision = balance.creditPolicyRevision;
|
|
5986
6021
|
if (balance.balanceMicros <= 0) {
|
|
5987
6022
|
throw new Error("insufficient Opengeni credits");
|
|
5988
6023
|
}
|
|
@@ -6020,6 +6055,7 @@ async function ensureRunAllowed(settings, db, accountId, workspaceId, isExternal
|
|
|
6020
6055
|
}
|
|
6021
6056
|
}
|
|
6022
6057
|
}
|
|
6058
|
+
return creditPolicyRevision;
|
|
6023
6059
|
}
|
|
6024
6060
|
|
|
6025
6061
|
// src/activities/agent-turn/provider-recovery-metrics.ts
|
|
@@ -6132,9 +6168,13 @@ async function settleTurnFailure(deps) {
|
|
|
6132
6168
|
try {
|
|
6133
6169
|
return await settleTurnFailureInAttempt(deps);
|
|
6134
6170
|
} catch (error51) {
|
|
6171
|
+
if (deps.control.activityStatus === "recovering" && error51 instanceof ApplicationFailure && error51.type === "OpenGeniPostClaimDatabaseRecovery")
|
|
6172
|
+
throw error51;
|
|
6135
6173
|
if (deps.attempt.turnId && deps.attempt.triggerEventId) {
|
|
6136
6174
|
const recovery = postClaimDatabaseRecoveryFailure({
|
|
6137
|
-
|
|
6175
|
+
// A failed rollback/terminal write must not erase no-replay evidence
|
|
6176
|
+
// from the failure we were settling (notably unknown tool effects).
|
|
6177
|
+
error: new AggregateError([error51, deps.error], "Turn failure settlement failed"),
|
|
6138
6178
|
turnId: deps.attempt.turnId,
|
|
6139
6179
|
triggerEventId: deps.attempt.triggerEventId,
|
|
6140
6180
|
executionGeneration: deps.attempt.executionGeneration,
|
|
@@ -8895,6 +8935,8 @@ async function runTurnStreamAttempt(deps) {
|
|
|
8895
8935
|
);
|
|
8896
8936
|
let parallelSessionTitle = null;
|
|
8897
8937
|
let parallelSessionTitleFinished = false;
|
|
8938
|
+
let creditPolicyRevision;
|
|
8939
|
+
let titleCreditPolicyRevision;
|
|
8898
8940
|
const finishParallelSessionTitle = async () => {
|
|
8899
8941
|
if (parallelSessionTitleFinished) return;
|
|
8900
8942
|
parallelSessionTitleFinished = true;
|
|
@@ -8903,6 +8945,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
8903
8945
|
if (generated.usage) {
|
|
8904
8946
|
await processSessionTitleModelUsageEvent({
|
|
8905
8947
|
usage: generated.usage,
|
|
8948
|
+
creditPolicyRevision: titleCreditPolicyRevision,
|
|
8906
8949
|
state: sessionTitleUsageState,
|
|
8907
8950
|
dispatchId: modelUsageDispatchId,
|
|
8908
8951
|
settings,
|
|
@@ -9069,7 +9112,8 @@ async function runTurnStreamAttempt(deps) {
|
|
|
9069
9112
|
let finalReplyNudged = false;
|
|
9070
9113
|
const revalidateModelCallAdmission = async () => {
|
|
9071
9114
|
await historySink.reconcileConversationTruth({ requireDurable: true });
|
|
9072
|
-
await ensureRunAllowedBetweenModelCalls({
|
|
9115
|
+
creditPolicyRevision = await ensureRunAllowedBetweenModelCalls({
|
|
9116
|
+
modelId: resolvedModel?.configured.id ?? turn.model,
|
|
9073
9117
|
settings,
|
|
9074
9118
|
db,
|
|
9075
9119
|
accountId: input.accountId,
|
|
@@ -9091,6 +9135,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
9091
9135
|
signal: runtimeCancellationSignal,
|
|
9092
9136
|
admit: revalidateModelCallAdmission
|
|
9093
9137
|
});
|
|
9138
|
+
const responseCreditPolicyRevisions = /* @__PURE__ */ new Set();
|
|
9094
9139
|
const responseCountBeforeStream = modelResponseState.responseCount;
|
|
9095
9140
|
eventing.batcher = null;
|
|
9096
9141
|
let currentToolBatchCallIds = /* @__PURE__ */ new Set();
|
|
@@ -9260,7 +9305,10 @@ async function runTurnStreamAttempt(deps) {
|
|
|
9260
9305
|
attempt.modelRequestStarted = true;
|
|
9261
9306
|
return await runtime.runStream(agent, runInput, eventing.modelRunSettings, {
|
|
9262
9307
|
beforeModelRequest: modelCallAdmission.beforeModelRequest,
|
|
9263
|
-
onModelResponse:
|
|
9308
|
+
onModelResponse: (event) => {
|
|
9309
|
+
responseCreditPolicyRevisions.add(creditPolicyRevision);
|
|
9310
|
+
return modelCallAdmission.onModelResponse(event);
|
|
9311
|
+
},
|
|
9264
9312
|
signal: runtimeCancellationSignal,
|
|
9265
9313
|
sandboxEnvironment,
|
|
9266
9314
|
onModelVisibleContext: async (snapshot) => {
|
|
@@ -9450,6 +9498,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
9450
9498
|
}
|
|
9451
9499
|
const generatedImageReceipt = generatedImage ? await media.retainNativeGeneratedImage(generatedImage) : null;
|
|
9452
9500
|
const responseResult = await processModelResponseTerminalEvent({
|
|
9501
|
+
creditPolicyRevision,
|
|
9453
9502
|
event: next.value,
|
|
9454
9503
|
state: modelResponseState,
|
|
9455
9504
|
dispatchId: modelUsageDispatchId,
|
|
@@ -9533,18 +9582,6 @@ async function runTurnStreamAttempt(deps) {
|
|
|
9533
9582
|
await historySink.reconcileConversationTruth();
|
|
9534
9583
|
turnLifecycleMetricsFor(observability).progress({ attemptId: input.attemptId });
|
|
9535
9584
|
modelCheckpointMemoryCollector.schedule(observability);
|
|
9536
|
-
await ensureRunAllowedBetweenModelCalls({
|
|
9537
|
-
settings,
|
|
9538
|
-
db,
|
|
9539
|
-
accountId: input.accountId,
|
|
9540
|
-
workspaceId: input.workspaceId,
|
|
9541
|
-
isExternallyBilledTurn: billingState.isExternallyBilledTurn,
|
|
9542
|
-
entitlements,
|
|
9543
|
-
chargesOpenGeniCredits: billingState.chargesOpenGeniCredits,
|
|
9544
|
-
countsTowardTokenCap: billingState.countsTowardTokenCap,
|
|
9545
|
-
initiatingHumanSubjectId: turn.initiatingHumanSubjectId,
|
|
9546
|
-
serializedRunState: () => media.compactMediaRunState(String(eventing.stream.state.toString()))
|
|
9547
|
-
});
|
|
9548
9585
|
}
|
|
9549
9586
|
modelCallAdmission.settle(next.value);
|
|
9550
9587
|
const durableSdkEvent = generatedImageReceipt ? compactGeneratedImageSdkEvent(next.value, generatedImageReceipt) : next.value;
|
|
@@ -9838,6 +9875,12 @@ async function runTurnStreamAttempt(deps) {
|
|
|
9838
9875
|
if (!streamSawPerResponseUsage) {
|
|
9839
9876
|
const aggregateUsage = eventing.stream.state.usage;
|
|
9840
9877
|
const normalizedAggregateUsage = normalizeModelCallUsage2(aggregateUsage);
|
|
9878
|
+
const aggregatePolicyRevision = aggregateCreditPolicyRevision({
|
|
9879
|
+
responseRevisions: responseCreditPolicyRevisions,
|
|
9880
|
+
lastAdmittedRevision: creditPolicyRevision,
|
|
9881
|
+
chargesOpenGeniCredits: billingState.chargesOpenGeniCredits,
|
|
9882
|
+
totalTokens: normalizedAggregateUsage.totalTokens
|
|
9883
|
+
});
|
|
9841
9884
|
const aggregateInput = normalizedAggregateUsage.telemetry.inputTokens;
|
|
9842
9885
|
const aggregateSourceKey = modelUsageSourceKey({
|
|
9843
9886
|
responseId: null,
|
|
@@ -9858,6 +9901,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
9858
9901
|
leaseLostMessage: "Provider credential lease expired during the active turn",
|
|
9859
9902
|
recordUsage: async () => {
|
|
9860
9903
|
const billing = await recordModelUsageAndDebitCredits(settings, db, {
|
|
9904
|
+
creditPolicyRevision: aggregatePolicyRevision,
|
|
9861
9905
|
accountId: input.accountId,
|
|
9862
9906
|
workspaceId: input.workspaceId,
|
|
9863
9907
|
sessionId: input.sessionId,
|
|
@@ -10194,6 +10238,7 @@ async function runTurnStreamAttempt(deps) {
|
|
|
10194
10238
|
turnExecutionPolicy.providerId,
|
|
10195
10239
|
turnExecutionPolicy.latencyMode
|
|
10196
10240
|
);
|
|
10241
|
+
titleCreditPolicyRevision = creditPolicyRevision;
|
|
10197
10242
|
parallelSessionTitle = startParallelSessionTitleGeneration({
|
|
10198
10243
|
signal: runtimeCancellationSignal,
|
|
10199
10244
|
generate: async (signal) => await withSessionTitleProviderRequestContext(
|
|
@@ -10399,7 +10444,7 @@ import {
|
|
|
10399
10444
|
requireSession
|
|
10400
10445
|
} from "@opengeni/db";
|
|
10401
10446
|
import { appendAndPublishTurnEventsFenced as appendAndPublishTurnEventsFenced2, publishDurableSessionEvents as publishDurableSessionEvents4 } from "@opengeni/events";
|
|
10402
|
-
import { linkCurrentSpanToAdmission, turnExecutionTelemetryKey } from "@opengeni/observability";
|
|
10447
|
+
import { linkCurrentSpanToAdmission, turnExecutionTelemetryKey as turnExecutionTelemetryKey2 } from "@opengeni/observability";
|
|
10403
10448
|
import {
|
|
10404
10449
|
assertTurnExecutionPolicyMatchesConfigV1,
|
|
10405
10450
|
settingsForAcceptedSubscriptionTurn,
|
|
@@ -10932,7 +10977,8 @@ async function claimTurnAttempt(deps) {
|
|
|
10932
10977
|
entitlements,
|
|
10933
10978
|
billingState.chargesOpenGeniCredits,
|
|
10934
10979
|
billingState.countsTowardTokenCap,
|
|
10935
|
-
turn.initiatingHumanSubjectId
|
|
10980
|
+
turn.initiatingHumanSubjectId,
|
|
10981
|
+
turnExecutionPolicy.productModelId
|
|
10936
10982
|
),
|
|
10937
10983
|
cancellationSignal,
|
|
10938
10984
|
void 0
|
|
@@ -11082,7 +11128,7 @@ async function claimTurnAttempt(deps) {
|
|
|
11082
11128
|
throwIfTurnCancelled();
|
|
11083
11129
|
recordTurnStartupPhase(observability, {
|
|
11084
11130
|
phase: "claim_and_policy",
|
|
11085
|
-
executionCorrelationId:
|
|
11131
|
+
executionCorrelationId: turnExecutionTelemetryKey2(
|
|
11086
11132
|
input.workspaceId,
|
|
11087
11133
|
input.sessionId,
|
|
11088
11134
|
input.attemptId
|
|
@@ -12820,9 +12866,11 @@ async function prepareCompaction(deps) {
|
|
|
12820
12866
|
};
|
|
12821
12867
|
const promptCacheKey = acceptsPromptCacheKeyForTurn(resolvedModel) ? input.sessionId : void 0;
|
|
12822
12868
|
const compactionUsageState = createCompactionModelUsageEventState(claimedModelUsageSourceKeys);
|
|
12869
|
+
let compactionCreditPolicyRevision;
|
|
12823
12870
|
const recordCompactionUsage = async (usage) => {
|
|
12824
12871
|
await processCompactionModelUsageEvent({
|
|
12825
12872
|
usage,
|
|
12873
|
+
creditPolicyRevision: compactionCreditPolicyRevision,
|
|
12826
12874
|
state: compactionUsageState,
|
|
12827
12875
|
dispatchId: modelUsageDispatchId,
|
|
12828
12876
|
settings,
|
|
@@ -12850,7 +12898,7 @@ async function prepareCompaction(deps) {
|
|
|
12850
12898
|
});
|
|
12851
12899
|
};
|
|
12852
12900
|
const compactionSummarizerFor = (systemInstructions) => {
|
|
12853
|
-
const
|
|
12901
|
+
const summarizeModel = resolvedModel ? (s, m) => withProviderRequestContext(
|
|
12854
12902
|
() => summarizeContextForCompaction(s, m, {
|
|
12855
12903
|
client: resolvedModel.client,
|
|
12856
12904
|
provider: resolvedModel.provider,
|
|
@@ -12871,6 +12919,21 @@ async function prepareCompaction(deps) {
|
|
|
12871
12919
|
...systemInstructions ? { systemInstructions } : {},
|
|
12872
12920
|
...promptCacheKey ? { promptCacheKey } : {}
|
|
12873
12921
|
});
|
|
12922
|
+
const summarize = async (s, m) => {
|
|
12923
|
+
compactionCreditPolicyRevision = await ensureRunAllowedBetweenModelCalls({
|
|
12924
|
+
settings: s,
|
|
12925
|
+
db,
|
|
12926
|
+
accountId: input.accountId,
|
|
12927
|
+
workspaceId: input.workspaceId,
|
|
12928
|
+
modelId: resolvedModel?.configured.id ?? turn.model,
|
|
12929
|
+
isExternallyBilledTurn: billingState.isExternallyBilledTurn,
|
|
12930
|
+
chargesOpenGeniCredits: billingState.chargesOpenGeniCredits,
|
|
12931
|
+
countsTowardTokenCap: billingState.countsTowardTokenCap,
|
|
12932
|
+
initiatingHumanSubjectId: turn.initiatingHumanSubjectId,
|
|
12933
|
+
entitlements: deps.entitlements
|
|
12934
|
+
});
|
|
12935
|
+
return await summarizeModel(s, m);
|
|
12936
|
+
};
|
|
12874
12937
|
summarize.estimatePrefixTokens = () => {
|
|
12875
12938
|
if (resolvedModel?.provider.api === "chat") {
|
|
12876
12939
|
return estimateSerializedValueTokens(systemInstructions ?? "");
|
|
@@ -38486,6 +38549,7 @@ function createRunAgentTurnActivity(services) {
|
|
|
38486
38549
|
)
|
|
38487
38550
|
);
|
|
38488
38551
|
const compactionPrep = await prepareCompaction({
|
|
38552
|
+
entitlements,
|
|
38489
38553
|
input,
|
|
38490
38554
|
settings: capabilitySettings,
|
|
38491
38555
|
db,
|
|
@@ -39297,7 +39361,7 @@ These are publication receipts for the human's earlier answer. Do not call the r
|
|
|
39297
39361
|
const servicesStartedAt = performance.now();
|
|
39298
39362
|
const resolvedServices = await services();
|
|
39299
39363
|
const servicesDurationSeconds = (performance.now() - servicesStartedAt) / 1e3;
|
|
39300
|
-
const correlationId =
|
|
39364
|
+
const correlationId = turnExecutionTelemetryKey3(
|
|
39301
39365
|
input.workspaceId,
|
|
39302
39366
|
input.sessionId,
|
|
39303
39367
|
input.attemptId
|
|
@@ -40443,4 +40507,4 @@ export {
|
|
|
40443
40507
|
createTurnActivities,
|
|
40444
40508
|
createTurnActivitiesFromServices
|
|
40445
40509
|
};
|
|
40446
|
-
//# sourceMappingURL=activities-turn-
|
|
40510
|
+
//# sourceMappingURL=activities-turn-BMY3CDKL.js.map
|