@parall/daemon 1.92.0 → 1.93.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/bundle/manifest.json +11 -11
- package/bundle/parall-browser-pod.js +29 -7
- package/bundle/parall-claude-agent.js +443 -44
- package/bundle/parall-codex-agent.js +433 -49
- package/bundle/parall-daemon.js +76 -11
- package/package.json +6 -6
|
@@ -22809,8 +22809,8 @@ var require_BatchSpanProcessorBase = __commonJS({
|
|
|
22809
22809
|
_flushAll() {
|
|
22810
22810
|
return new Promise((resolve3, reject) => {
|
|
22811
22811
|
const promises = [];
|
|
22812
|
-
const
|
|
22813
|
-
for (let i = 0, j =
|
|
22812
|
+
const count2 = Math.ceil(this._finishedSpans.length / this._maxExportBatchSize);
|
|
22813
|
+
for (let i = 0, j = count2; i < j; i++) {
|
|
22814
22814
|
promises.push(this._flushOneBatch());
|
|
22815
22815
|
}
|
|
22816
22816
|
Promise.all(promises).then(() => {
|
|
@@ -52431,6 +52431,7 @@ var ENDPOINTS = {
|
|
|
52431
52431
|
AGENT_ME: (orgId) => `${API_BASE2}/orgs/${orgId}/agents/me`,
|
|
52432
52432
|
AGENT_REPLY_POLICY_CAPABILITY: (orgId) => `${API_BASE2}/orgs/${orgId}/agents/me/reply-policy-capability`,
|
|
52433
52433
|
AGENT_RUNTIME_REPORT: (orgId) => `${API_BASE2}/orgs/${orgId}/agents/me/runtime-report`,
|
|
52434
|
+
AGENT_LLM_USAGE: (orgId) => `${API_BASE2}/orgs/${orgId}/agents/me/llm-usage`,
|
|
52434
52435
|
...secretEndpoints(API_BASE2),
|
|
52435
52436
|
AGENT_NEW_SESSION: (orgId, agentId) => `${API_BASE2}/orgs/${orgId}/agents/${agentId}/new-session`,
|
|
52436
52437
|
AGENT_DEEP_RESET: (orgId, agentId) => `${API_BASE2}/orgs/${orgId}/agents/${agentId}/deep-reset`,
|
|
@@ -53748,6 +53749,10 @@ var ClipConnectionClient = class extends ChannelConversationClient {
|
|
|
53748
53749
|
};
|
|
53749
53750
|
return this.request("PUT", ENDPOINTS.ORG_CLIP_MCP_CONFIG_BY_ID(orgId, clipId, configId), req, void 0, false, { headers: { "If-Match": `"${expectedVersion}"` }, timeoutMs: 4e4 });
|
|
53750
53751
|
}
|
|
53752
|
+
/** Server-resolved hosted authorization; no client URL or secret fields. */
|
|
53753
|
+
async connectManagedMCP(orgId, clipId, alias, target) {
|
|
53754
|
+
return this.request(target ? "PUT" : "POST", target ? ENDPOINTS.ORG_CLIP_MCP_CONFIG_BY_ID(orgId, clipId, target.config_id) : ENDPOINTS.ORG_CLIP_MCP_CONFIGS(orgId, clipId), { auth_type: "managed", ...alias ? { alias } : {} }, void 0, false, { headers: target ? { "If-Match": `"${target.version}"` } : void 0, timeoutMs: 11e4 });
|
|
53755
|
+
}
|
|
53751
53756
|
// ---- Clip connections ----
|
|
53752
53757
|
/** Missing keys are unknown/hidden; present empty arrays are known empty. */
|
|
53753
53758
|
async listClipMCPSummaries(orgId, clipIds) {
|
|
@@ -54249,10 +54254,25 @@ var AgentOwningTeamClient = class extends AgentTeamOnlyClient {
|
|
|
54249
54254
|
}
|
|
54250
54255
|
};
|
|
54251
54256
|
|
|
54257
|
+
// ts/sdk/dist/runtime-auth-llm-usage-client.js
|
|
54258
|
+
var RuntimeAuthLlmUsageClient = class extends AgentOwningTeamClient {
|
|
54259
|
+
/**
|
|
54260
|
+
* Record one batch of usage. The agent's own API key only (403 AGENT_ONLY
|
|
54261
|
+
* otherwise); 204 also for a batch already recorded; 400 for a batch out of
|
|
54262
|
+
* bounds; 409 LLM_ROUTE_NOT_RUNTIME_AUTH when the agent's model route is
|
|
54263
|
+
* not runtime_auth. A server without the endpoint answers 404 with no error
|
|
54264
|
+
* code. Every refusal surfaces as an ApiError with its status and code: what
|
|
54265
|
+
* to do about it is the caller's decision.
|
|
54266
|
+
*/
|
|
54267
|
+
async reportRuntimeAuthLlmUsage(orgId, report, opts) {
|
|
54268
|
+
await this.request("POST", ENDPOINTS.AGENT_LLM_USAGE(orgId), report, void 0, false, opts);
|
|
54269
|
+
}
|
|
54270
|
+
};
|
|
54271
|
+
|
|
54252
54272
|
// ts/sdk/dist/team-graph-client.js
|
|
54253
|
-
var TeamGraphClient = class extends
|
|
54273
|
+
var TeamGraphClient = class extends RuntimeAuthLlmUsageClient {
|
|
54254
54274
|
async getTeamGraph(orgId, opts) {
|
|
54255
|
-
const query = opts?.includeAccess ? "?include=access" : "";
|
|
54275
|
+
const query = opts?.includeAccess ? "?include=access&include=apps" : "";
|
|
54256
54276
|
return this.request("GET", `${ENDPOINTS.TEAM_GRAPH(orgId)}${query}`);
|
|
54257
54277
|
}
|
|
54258
54278
|
/**
|
|
@@ -57112,9 +57132,8 @@ var ParallClient = class _ParallClient extends TemplateCatalogClient {
|
|
|
57112
57132
|
}
|
|
57113
57133
|
async createClipMCPConnection(orgId, clipId, req) {
|
|
57114
57134
|
return this.request("POST", ENDPOINTS.ORG_CLIP_MCP_CONFIGS(orgId, clipId), req, void 0, false, {
|
|
57115
|
-
//
|
|
57116
|
-
|
|
57117
|
-
timeoutMs: "approval_id" in req ? 5e4 : 4e4
|
|
57135
|
+
// Managed no-auth cards also perform a bounded session probe and completion.
|
|
57136
|
+
timeoutMs: "approval_id" in req ? 11e4 : 4e4
|
|
57118
57137
|
});
|
|
57119
57138
|
}
|
|
57120
57139
|
/** Delete one MCP config and its paired connection. */
|
|
@@ -57141,8 +57160,8 @@ var ParallClient = class _ParallClient extends TemplateCatalogClient {
|
|
|
57141
57160
|
void 0,
|
|
57142
57161
|
void 0,
|
|
57143
57162
|
false,
|
|
57144
|
-
//
|
|
57145
|
-
{ timeoutMs:
|
|
57163
|
+
// Managed refresh includes account readback and session creation (60s).
|
|
57164
|
+
{ timeoutMs: 7e4 }
|
|
57146
57165
|
);
|
|
57147
57166
|
}
|
|
57148
57167
|
// ---- Deprecated method aliases (External* → Trigger* rename; same endpoints) ----
|
|
@@ -57278,6 +57297,10 @@ function buildApiError(res, rawErrorBody) {
|
|
|
57278
57297
|
return apiError;
|
|
57279
57298
|
}
|
|
57280
57299
|
|
|
57300
|
+
// ts/sdk/dist/runtime-auth-llm-usage-types.js
|
|
57301
|
+
var RUNTIME_AUTH_LLM_USAGE_MAX_MODELS = 8;
|
|
57302
|
+
var LLM_ROUTE_NOT_RUNTIME_AUTH_ERROR_CODE = "LLM_ROUTE_NOT_RUNTIME_AUTH";
|
|
57303
|
+
|
|
57281
57304
|
// ts/sdk/dist/ws.js
|
|
57282
57305
|
function describeWsStateDetail(detail) {
|
|
57283
57306
|
if (!detail)
|
|
@@ -57708,6 +57731,13 @@ function clearAllProviderCreds(env) {
|
|
|
57708
57731
|
delete env[name];
|
|
57709
57732
|
delete env.PRLL_CLAUDE_ALLOW_API_KEY;
|
|
57710
57733
|
}
|
|
57734
|
+
function isParallModelEndpoint(endpoint, apiUrl) {
|
|
57735
|
+
const base = endpoint?.trim().replace(/\/+$/, "");
|
|
57736
|
+
const api = apiUrl?.trim().replace(/\/+$/, "");
|
|
57737
|
+
if (!base || !api)
|
|
57738
|
+
return false;
|
|
57739
|
+
return base === api || base.startsWith(`${api}/`);
|
|
57740
|
+
}
|
|
57711
57741
|
function parseProviderConfig(env) {
|
|
57712
57742
|
const raw = env.PRLL_PROVIDER_CONFIG?.trim();
|
|
57713
57743
|
if (!raw)
|
|
@@ -58730,8 +58760,8 @@ var OtlpSpoolStore = class {
|
|
|
58730
58760
|
return this.opts.dir;
|
|
58731
58761
|
}
|
|
58732
58762
|
/** Count a batch the exporter dropped for a permanent status (never spooled). */
|
|
58733
|
-
recordDrop(signal, reason,
|
|
58734
|
-
this.opts.onEvent?.({ kind: "dropped", signal, reason, count });
|
|
58763
|
+
recordDrop(signal, reason, count2 = 1) {
|
|
58764
|
+
this.opts.onEvent?.({ kind: "dropped", signal, reason, count: count2 });
|
|
58735
58765
|
}
|
|
58736
58766
|
/**
|
|
58737
58767
|
* Append one serialized request. Resolves once the file is renamed into
|
|
@@ -59041,6 +59071,19 @@ var dispatchSpans = /* @__PURE__ */ new WeakSet();
|
|
|
59041
59071
|
var recordedErrors = /* @__PURE__ */ new WeakSet();
|
|
59042
59072
|
var dispatchCounter = null;
|
|
59043
59073
|
var dispatchDuration = null;
|
|
59074
|
+
var DISPATCH_DURATION_BUCKETS_MS = [
|
|
59075
|
+
1e3,
|
|
59076
|
+
2500,
|
|
59077
|
+
5e3,
|
|
59078
|
+
1e4,
|
|
59079
|
+
2e4,
|
|
59080
|
+
3e4,
|
|
59081
|
+
6e4,
|
|
59082
|
+
12e4,
|
|
59083
|
+
3e5,
|
|
59084
|
+
6e5,
|
|
59085
|
+
18e5
|
|
59086
|
+
];
|
|
59044
59087
|
var missingReplyCounter = null;
|
|
59045
59088
|
var turnTokensCounter = null;
|
|
59046
59089
|
var turnCostCounter = null;
|
|
@@ -59194,7 +59237,7 @@ async function initAgentTelemetry(serviceName, runtimeType, opts = {}) {
|
|
|
59194
59237
|
const metricExporter = spooled(new OTLPMetricExporter({ url: `${otelEndpoint}/v1/metrics`, headers: authHeaders }), "metrics", serializers?.ProtobufMetricsSerializer);
|
|
59195
59238
|
const metricReader = new PeriodicExportingMetricReader({
|
|
59196
59239
|
exporter: metricExporter,
|
|
59197
|
-
exportIntervalMillis:
|
|
59240
|
+
exportIntervalMillis: 6e4
|
|
59198
59241
|
});
|
|
59199
59242
|
const meterProvider = new MeterProvider({ resource, readers: [metricReader] });
|
|
59200
59243
|
metrics.setGlobalMeterProvider(meterProvider);
|
|
@@ -59208,7 +59251,8 @@ async function initAgentTelemetry(serviceName, runtimeType, opts = {}) {
|
|
|
59208
59251
|
});
|
|
59209
59252
|
dispatchDuration = meter.createHistogram("parall.dispatch.duration", {
|
|
59210
59253
|
description: "Dispatch cycle duration in milliseconds",
|
|
59211
|
-
unit: "ms"
|
|
59254
|
+
unit: "ms",
|
|
59255
|
+
advice: { explicitBucketBoundaries: DISPATCH_DURATION_BUCKETS_MS }
|
|
59212
59256
|
});
|
|
59213
59257
|
missingReplyCounter = meter.createCounter("parall.dispatch.missing_reply", {
|
|
59214
59258
|
description: "Dispatches where agent produced text but sent no reply message"
|
|
@@ -61429,6 +61473,224 @@ async function closeRuntimeChildSession(host, sessionKey, reason) {
|
|
|
61429
61473
|
}
|
|
61430
61474
|
}
|
|
61431
61475
|
|
|
61476
|
+
// ts/agent-core/dist/gateway/runtime-usage-reporter.js
|
|
61477
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
61478
|
+
var DEFAULT_INTERVAL_MS = 5 * 6e4;
|
|
61479
|
+
var DEFAULT_RETRY_DELAYS_MS3 = [5e3, 3e4, 12e4];
|
|
61480
|
+
var DEFAULT_FLUSH_MS = 5e3;
|
|
61481
|
+
var MAX_MODEL_NAME = 200;
|
|
61482
|
+
var MAX_COUNT = 1e12;
|
|
61483
|
+
var MAX_QUEUED_BATCHES = 64;
|
|
61484
|
+
var RuntimeUsageReporter = class {
|
|
61485
|
+
opts;
|
|
61486
|
+
enabled;
|
|
61487
|
+
/** Usage not cut into a batch yet, per model. */
|
|
61488
|
+
held = /* @__PURE__ */ new Map();
|
|
61489
|
+
/** Cut batches, oldest first; the head is the one being sent. */
|
|
61490
|
+
queue = [];
|
|
61491
|
+
/** Why the server refused the endpoint; null while reporting. Cleared by the next hello. */
|
|
61492
|
+
stoppedBy = null;
|
|
61493
|
+
disposed = false;
|
|
61494
|
+
flushing = false;
|
|
61495
|
+
sending = null;
|
|
61496
|
+
/** Ends a retry's backoff early (exit flush, dispose). */
|
|
61497
|
+
wake = null;
|
|
61498
|
+
inFlight = new AbortController();
|
|
61499
|
+
warnedRefusals = /* @__PURE__ */ new Set();
|
|
61500
|
+
timer = null;
|
|
61501
|
+
unsubscribe;
|
|
61502
|
+
constructor(opts) {
|
|
61503
|
+
this.opts = opts;
|
|
61504
|
+
const subscribe = opts.dispatchAdapter.subscribeUsage?.bind(opts.dispatchAdapter);
|
|
61505
|
+
this.enabled = opts.reportRuntimeUsage === true && subscribe !== void 0;
|
|
61506
|
+
if (!this.enabled || !subscribe)
|
|
61507
|
+
return;
|
|
61508
|
+
this.unsubscribe = subscribe((sample) => this.add(sample));
|
|
61509
|
+
this.timer = setInterval(() => this.cut(), opts.runtimeUsageIntervalMs ?? DEFAULT_INTERVAL_MS);
|
|
61510
|
+
this.timer.unref?.();
|
|
61511
|
+
}
|
|
61512
|
+
/**
|
|
61513
|
+
* Every hello. A 404 or a route refusal stops reporting until the next
|
|
61514
|
+
* connection: a rolling deploy's brief 404 must not silence the process
|
|
61515
|
+
* for its lifetime.
|
|
61516
|
+
*/
|
|
61517
|
+
resume() {
|
|
61518
|
+
if (this.stoppedBy === null || this.disposed)
|
|
61519
|
+
return;
|
|
61520
|
+
this.opts.log?.info(`runtime usage: reporting resumed on hello (stopped by ${this.stoppedBy})`);
|
|
61521
|
+
this.stoppedBy = null;
|
|
61522
|
+
}
|
|
61523
|
+
/**
|
|
61524
|
+
* Shutdown, beside the step flush: cut what is held and send every waiting
|
|
61525
|
+
* batch once (a batch in its retry backoff goes now), within budgetMs.
|
|
61526
|
+
* Whatever has not gone out by then is dropped. Absorbing, like dispose().
|
|
61527
|
+
*/
|
|
61528
|
+
async flush(budgetMs = this.opts.runtimeUsageFlushMs ?? DEFAULT_FLUSH_MS) {
|
|
61529
|
+
if (!this.enabled || this.disposed)
|
|
61530
|
+
return;
|
|
61531
|
+
let expired = false;
|
|
61532
|
+
let timer;
|
|
61533
|
+
try {
|
|
61534
|
+
this.flushing = true;
|
|
61535
|
+
this.stopObserving();
|
|
61536
|
+
this.cut();
|
|
61537
|
+
this.wake?.();
|
|
61538
|
+
const deadline = new Promise((resolve3) => {
|
|
61539
|
+
timer = setTimeout(() => {
|
|
61540
|
+
expired = true;
|
|
61541
|
+
resolve3();
|
|
61542
|
+
}, Math.max(0, budgetMs));
|
|
61543
|
+
});
|
|
61544
|
+
while (this.sending && !expired)
|
|
61545
|
+
await Promise.race([this.sending, deadline]);
|
|
61546
|
+
} catch (err) {
|
|
61547
|
+
this.opts.log?.warn(`runtime usage: exit flush failed: ${String(err)}`);
|
|
61548
|
+
} finally {
|
|
61549
|
+
clearTimeout(timer);
|
|
61550
|
+
this.dispose();
|
|
61551
|
+
}
|
|
61552
|
+
}
|
|
61553
|
+
/** No more samples, timers or posts; what is held or in flight is dropped. */
|
|
61554
|
+
dispose() {
|
|
61555
|
+
if (this.disposed)
|
|
61556
|
+
return;
|
|
61557
|
+
this.disposed = true;
|
|
61558
|
+
this.stopObserving();
|
|
61559
|
+
this.inFlight.abort();
|
|
61560
|
+
this.wake?.();
|
|
61561
|
+
const unsent = this.queue.length + (this.held.size > 0 ? 1 : 0);
|
|
61562
|
+
if (unsent > 0 && this.stoppedBy === null) {
|
|
61563
|
+
this.opts.log?.warn(`runtime usage: ${unsent} batch(es) not sent before exit, dropped`);
|
|
61564
|
+
}
|
|
61565
|
+
this.queue = [];
|
|
61566
|
+
this.held.clear();
|
|
61567
|
+
}
|
|
61568
|
+
stopObserving() {
|
|
61569
|
+
this.unsubscribe?.();
|
|
61570
|
+
if (this.timer)
|
|
61571
|
+
clearInterval(this.timer);
|
|
61572
|
+
}
|
|
61573
|
+
add(sample) {
|
|
61574
|
+
if (this.disposed || this.stoppedBy !== null)
|
|
61575
|
+
return;
|
|
61576
|
+
const counts = {
|
|
61577
|
+
input_tokens: tokenCount(sample.inputTokens),
|
|
61578
|
+
cache_read_tokens: tokenCount(sample.cacheReadTokens),
|
|
61579
|
+
cache_write_tokens: tokenCount(sample.cacheWriteTokens),
|
|
61580
|
+
output_tokens: tokenCount(sample.outputTokens)
|
|
61581
|
+
};
|
|
61582
|
+
if (Object.values(counts).every((n) => n === 0))
|
|
61583
|
+
return;
|
|
61584
|
+
const model = modelName(sample.model);
|
|
61585
|
+
const held = this.held.get(model);
|
|
61586
|
+
if (!held) {
|
|
61587
|
+
this.held.set(model, counts);
|
|
61588
|
+
return;
|
|
61589
|
+
}
|
|
61590
|
+
for (const key of Object.keys(counts)) {
|
|
61591
|
+
held[key] = Math.min(MAX_COUNT, held[key] + counts[key]);
|
|
61592
|
+
}
|
|
61593
|
+
}
|
|
61594
|
+
/** Held usage → batches of at most 8 models, each with its own id. */
|
|
61595
|
+
cut() {
|
|
61596
|
+
if (this.disposed || this.held.size === 0)
|
|
61597
|
+
return;
|
|
61598
|
+
const models = [...this.held].map(([model, counts]) => ({ model, ...counts }));
|
|
61599
|
+
this.held.clear();
|
|
61600
|
+
for (let i = 0; i < models.length; i += RUNTIME_AUTH_LLM_USAGE_MAX_MODELS) {
|
|
61601
|
+
const chunk = models.slice(i, i + RUNTIME_AUTH_LLM_USAGE_MAX_MODELS);
|
|
61602
|
+
this.queue.push({ id: randomUUID4(), models: chunk, attempts: 0 });
|
|
61603
|
+
}
|
|
61604
|
+
if (this.queue.length > MAX_QUEUED_BATCHES) {
|
|
61605
|
+
const dropped = this.queue.splice(0, this.queue.length - MAX_QUEUED_BATCHES);
|
|
61606
|
+
this.opts.log?.warn(`runtime usage: ${dropped.length} unsent batch(es) dropped (backlog)`);
|
|
61607
|
+
}
|
|
61608
|
+
this.kick();
|
|
61609
|
+
}
|
|
61610
|
+
/** One send loop at a time; a batch cut while it was finishing starts the next. */
|
|
61611
|
+
kick() {
|
|
61612
|
+
if (this.sending || this.disposed)
|
|
61613
|
+
return;
|
|
61614
|
+
this.sending = this.sendQueued().catch((err) => this.opts.log?.warn(`runtime usage: send loop failed: ${String(err)}`)).finally(() => {
|
|
61615
|
+
this.sending = null;
|
|
61616
|
+
if (this.queue.length > 0 && this.stoppedBy === null)
|
|
61617
|
+
this.kick();
|
|
61618
|
+
});
|
|
61619
|
+
}
|
|
61620
|
+
async sendQueued() {
|
|
61621
|
+
const delays = this.opts.runtimeUsageRetryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS3;
|
|
61622
|
+
while (this.queue.length > 0 && this.stoppedBy === null && !this.disposed) {
|
|
61623
|
+
const batch = this.queue[0];
|
|
61624
|
+
const outcome = await this.post(batch);
|
|
61625
|
+
if (outcome === "stopped")
|
|
61626
|
+
return;
|
|
61627
|
+
if (outcome === "retry") {
|
|
61628
|
+
const delay = delays[batch.attempts - 1];
|
|
61629
|
+
if (delay !== void 0 && !this.flushing && !this.disposed) {
|
|
61630
|
+
await this.backoff(delay);
|
|
61631
|
+
continue;
|
|
61632
|
+
}
|
|
61633
|
+
if (!this.disposed) {
|
|
61634
|
+
this.opts.log?.warn(`runtime usage: batch ${batch.id} dropped after ${batch.attempts} attempt(s)`);
|
|
61635
|
+
}
|
|
61636
|
+
}
|
|
61637
|
+
if (this.queue[0] === batch)
|
|
61638
|
+
this.queue.shift();
|
|
61639
|
+
}
|
|
61640
|
+
}
|
|
61641
|
+
async post(batch) {
|
|
61642
|
+
batch.attempts += 1;
|
|
61643
|
+
try {
|
|
61644
|
+
await this.opts.client.reportRuntimeAuthLlmUsage(this.opts.config.org_id, { batch_id: batch.id, models: batch.models }, { signal: this.inFlight.signal });
|
|
61645
|
+
return "done";
|
|
61646
|
+
} catch (err) {
|
|
61647
|
+
if (!(err instanceof ApiError) || err.status === 0 || err.status >= 500)
|
|
61648
|
+
return "retry";
|
|
61649
|
+
if (err.status === 404 && !err.code) {
|
|
61650
|
+
this.stop("a server without the usage endpoint (404)");
|
|
61651
|
+
return "stopped";
|
|
61652
|
+
}
|
|
61653
|
+
if (err.status === 409 && err.code === LLM_ROUTE_NOT_RUNTIME_AUTH_ERROR_CODE) {
|
|
61654
|
+
this.stop(`the server (${LLM_ROUTE_NOT_RUNTIME_AUTH_ERROR_CODE})`);
|
|
61655
|
+
return "stopped";
|
|
61656
|
+
}
|
|
61657
|
+
const kind = err.code ?? `HTTP ${err.status}`;
|
|
61658
|
+
if (!this.warnedRefusals.has(kind)) {
|
|
61659
|
+
this.warnedRefusals.add(kind);
|
|
61660
|
+
this.opts.log?.warn(`runtime usage: batch ${batch.id} refused, dropped: ${String(err)}`);
|
|
61661
|
+
}
|
|
61662
|
+
return "done";
|
|
61663
|
+
}
|
|
61664
|
+
}
|
|
61665
|
+
/** Stop until the next hello; nothing held survives it. */
|
|
61666
|
+
stop(by) {
|
|
61667
|
+
const dropped = this.queue.length + (this.held.size > 0 ? 1 : 0);
|
|
61668
|
+
this.stoppedBy = by;
|
|
61669
|
+
this.queue = [];
|
|
61670
|
+
this.held.clear();
|
|
61671
|
+
this.opts.log?.info(`runtime usage: reporting stopped by ${by} until the next hello; ${dropped} batch(es) dropped`);
|
|
61672
|
+
}
|
|
61673
|
+
backoff(ms) {
|
|
61674
|
+
return new Promise((resolve3) => {
|
|
61675
|
+
const done = () => {
|
|
61676
|
+
clearTimeout(timer);
|
|
61677
|
+
if (this.wake === done)
|
|
61678
|
+
this.wake = null;
|
|
61679
|
+
resolve3();
|
|
61680
|
+
};
|
|
61681
|
+
const timer = setTimeout(done, ms);
|
|
61682
|
+
timer.unref?.();
|
|
61683
|
+
this.wake = done;
|
|
61684
|
+
});
|
|
61685
|
+
}
|
|
61686
|
+
};
|
|
61687
|
+
function tokenCount(value) {
|
|
61688
|
+
return Number.isFinite(value) && value > 0 ? Math.min(MAX_COUNT, Math.floor(value)) : 0;
|
|
61689
|
+
}
|
|
61690
|
+
function modelName(model) {
|
|
61691
|
+
return (model.trim() || "unknown").slice(0, MAX_MODEL_NAME);
|
|
61692
|
+
}
|
|
61693
|
+
|
|
61432
61694
|
// ts/agent-core/dist/gateway/drain.js
|
|
61433
61695
|
var DrainGate = class {
|
|
61434
61696
|
isDrained;
|
|
@@ -61609,7 +61871,7 @@ var DispatchInactivityDeadlines = class {
|
|
|
61609
61871
|
};
|
|
61610
61872
|
|
|
61611
61873
|
// ts/agent-core/dist/session/step-retry-queue.js
|
|
61612
|
-
var
|
|
61874
|
+
var DEFAULT_RETRY_DELAYS_MS4 = [5e3, 1e4, 2e4, 4e4, 6e4];
|
|
61613
61875
|
async function raceWithDeadline2(work, ms) {
|
|
61614
61876
|
let timer;
|
|
61615
61877
|
const timeout = new Promise((resolve3) => {
|
|
@@ -61639,7 +61901,7 @@ var StepRetryQueue = class {
|
|
|
61639
61901
|
disposed = false;
|
|
61640
61902
|
constructor(opts) {
|
|
61641
61903
|
this.opts = opts;
|
|
61642
|
-
this.retryDelays = opts.retryDelaysMs?.length ? opts.retryDelaysMs :
|
|
61904
|
+
this.retryDelays = opts.retryDelaysMs?.length ? opts.retryDelaysMs : DEFAULT_RETRY_DELAYS_MS4;
|
|
61643
61905
|
}
|
|
61644
61906
|
hasPending(sessionId) {
|
|
61645
61907
|
return (this.queues.get(sessionId)?.length ?? 0) > 0;
|
|
@@ -62078,14 +62340,14 @@ function recordToolCall(sessionKey) {
|
|
|
62078
62340
|
}
|
|
62079
62341
|
|
|
62080
62342
|
// ts/agent-core/dist/gateway/input-steps.js
|
|
62081
|
-
import { randomUUID as
|
|
62343
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
62082
62344
|
function inputStepIdempotencyKey(event) {
|
|
62083
62345
|
if (event.type === "message" || event.type === "channel_message") {
|
|
62084
|
-
return event.messageId ? `input:${event.messageId}` :
|
|
62346
|
+
return event.messageId ? `input:${event.messageId}` : randomUUID5();
|
|
62085
62347
|
}
|
|
62086
62348
|
if (event.dispatchEventId)
|
|
62087
62349
|
return `input:${event.dispatchEventId}`;
|
|
62088
|
-
return
|
|
62350
|
+
return randomUUID5();
|
|
62089
62351
|
}
|
|
62090
62352
|
function resolveStepTarget(event) {
|
|
62091
62353
|
if (event.input?.step_target) {
|
|
@@ -62971,12 +63233,12 @@ async function catchUpFromDispatch(host) {
|
|
|
62971
63233
|
let expireSummary = null;
|
|
62972
63234
|
let overflowMode = false;
|
|
62973
63235
|
try {
|
|
62974
|
-
const { count } = await host.opts.client.getDispatchPendingCount(host.opts.config.org_id);
|
|
62975
|
-
if (
|
|
63236
|
+
const { count: count2 } = await host.opts.client.getDispatchPendingCount(host.opts.config.org_id);
|
|
63237
|
+
if (count2 > OVERFLOW_THRESHOLD) {
|
|
62976
63238
|
overflowMode = true;
|
|
62977
63239
|
const result = await host.opts.client.expireDispatch(host.opts.config.org_id, EXPIRE_AGE_HOURS);
|
|
62978
63240
|
if (result.total > 0) {
|
|
62979
|
-
host.opts.log?.warn(`dispatch catch-up overflow: ${
|
|
63241
|
+
host.opts.log?.warn(`dispatch catch-up overflow: ${count2} pending, expired ${result.total} events older than ${EXPIRE_AGE_HOURS}h`);
|
|
62980
63242
|
expireSummary = host.buildOfflineSummary(result.groups);
|
|
62981
63243
|
}
|
|
62982
63244
|
}
|
|
@@ -63030,7 +63292,7 @@ async function catchUpFromDispatch(host) {
|
|
|
63030
63292
|
if (expireSummary)
|
|
63031
63293
|
parts.push(expireSummary);
|
|
63032
63294
|
if (skipped > 0) {
|
|
63033
|
-
const recentLines = [...skippedByType.entries()].map(([type,
|
|
63295
|
+
const recentLines = [...skippedByType.entries()].map(([type, count2]) => `- ${count2} recent ${type.replace(".", " ").replace("_", " ")} events`).join("\n");
|
|
63034
63296
|
parts.push(expireSummary ? `Additionally, ${skipped} recent events exceeded the catch-up limit and were skipped:
|
|
63035
63297
|
${recentLines}` : `[Offline Summary] You were offline. ${skipped} pending events exceeded the catch-up limit and were skipped:
|
|
63036
63298
|
${recentLines}
|
|
@@ -63174,6 +63436,7 @@ async function handleHello(host, data) {
|
|
|
63174
63436
|
log2?.info("re-probing dispatch ledger after reconnect (was disabled)");
|
|
63175
63437
|
host.ledgerDisabled = false;
|
|
63176
63438
|
}
|
|
63439
|
+
host.runtimeUsage.resume();
|
|
63177
63440
|
const intervalSec = data.heartbeat_interval > 0 ? data.heartbeat_interval : 30;
|
|
63178
63441
|
let openFence = () => {
|
|
63179
63442
|
};
|
|
@@ -63290,6 +63553,7 @@ async function shutdown(host, opts = { skipDrain: false }) {
|
|
|
63290
63553
|
if (!settled()) {
|
|
63291
63554
|
await host.drainGate.wait(5e3, settled);
|
|
63292
63555
|
}
|
|
63556
|
+
const usageFlushed = host.runtimeUsage.flush();
|
|
63293
63557
|
if (host.stepPersister.pendingTotal() > 0) {
|
|
63294
63558
|
const remaining = await host.stepPersister.flush(1e4);
|
|
63295
63559
|
if (remaining > 0) {
|
|
@@ -63297,6 +63561,7 @@ async function shutdown(host, opts = { skipDrain: false }) {
|
|
|
63297
63561
|
}
|
|
63298
63562
|
}
|
|
63299
63563
|
host.stepPersister.dispose();
|
|
63564
|
+
await usageFlushed;
|
|
63300
63565
|
const lifecycleRemaining = await host.sessionLifecycle.flush(5e3);
|
|
63301
63566
|
if (lifecycleRemaining > 0) {
|
|
63302
63567
|
host.opts.log?.warn(`${lifecycleRemaining} session lifecycle write(s) unreconciled at shutdown`);
|
|
@@ -63376,6 +63641,8 @@ var ParallAgentGateway = class {
|
|
|
63376
63641
|
drainGate = new DrainGate(() => this.isDrained());
|
|
63377
63642
|
runtimeActivity = createRuntimeActivityState();
|
|
63378
63643
|
unsubscribeRuntimeActivity;
|
|
63644
|
+
// The runtime's own-login model usage, batched (gateway/runtime-usage-reporter.ts).
|
|
63645
|
+
runtimeUsage;
|
|
63379
63646
|
pendingRestartNotification = null;
|
|
63380
63647
|
laneLedger;
|
|
63381
63648
|
stepPersister;
|
|
@@ -63419,6 +63686,7 @@ var ParallAgentGateway = class {
|
|
|
63419
63686
|
this.DISPATCH_DEADLINE_MS = opts.dispatchDeadlineMs ?? 0;
|
|
63420
63687
|
this.INACTIVITY_WARN_MS = opts.inactivityWarnMs ?? 30 * 6e4;
|
|
63421
63688
|
this.unsubscribeRuntimeActivity = opts.dispatchAdapter.subscribeRuntimeActivity?.((event) => this.handleRuntimeActivity(event));
|
|
63689
|
+
this.runtimeUsage = new RuntimeUsageReporter(opts);
|
|
63422
63690
|
this.stepPersister = new StepPersister({
|
|
63423
63691
|
client: opts.client,
|
|
63424
63692
|
orgId: opts.config.org_id,
|
|
@@ -66055,6 +66323,7 @@ var RuntimeActivityPort = class {
|
|
|
66055
66323
|
label;
|
|
66056
66324
|
log;
|
|
66057
66325
|
handler = null;
|
|
66326
|
+
usageHandler = null;
|
|
66058
66327
|
constructor(label, log2) {
|
|
66059
66328
|
this.label = label;
|
|
66060
66329
|
this.log = log2;
|
|
@@ -66068,6 +66337,15 @@ var RuntimeActivityPort = class {
|
|
|
66068
66337
|
this.handler = null;
|
|
66069
66338
|
};
|
|
66070
66339
|
}
|
|
66340
|
+
subscribeUsage(handler) {
|
|
66341
|
+
if (this.usageHandler)
|
|
66342
|
+
throw new Error(`${this.label} supports a single usage subscriber`);
|
|
66343
|
+
this.usageHandler = handler;
|
|
66344
|
+
return () => {
|
|
66345
|
+
if (this.usageHandler === handler)
|
|
66346
|
+
this.usageHandler = null;
|
|
66347
|
+
};
|
|
66348
|
+
}
|
|
66071
66349
|
/** Hand an event to the subscriber; false when there is none or it threw. */
|
|
66072
66350
|
emit(event, log2 = this.log) {
|
|
66073
66351
|
if (!this.handler)
|
|
@@ -66080,6 +66358,14 @@ var RuntimeActivityPort = class {
|
|
|
66080
66358
|
return false;
|
|
66081
66359
|
}
|
|
66082
66360
|
}
|
|
66361
|
+
/** One piece of model usage to the subscriber, if any; a throwing subscriber never breaks the caller. */
|
|
66362
|
+
emitUsage(sample, log2 = this.log) {
|
|
66363
|
+
try {
|
|
66364
|
+
this.usageHandler?.(sample);
|
|
66365
|
+
} catch (err) {
|
|
66366
|
+
log2?.warn?.(`usage subscriber threw: ${String(err)}`);
|
|
66367
|
+
}
|
|
66368
|
+
}
|
|
66083
66369
|
/** A turn opened: to the subscriber when eligible, else drained here. */
|
|
66084
66370
|
surfaceTurn(turn, eligible = true, log2 = this.log) {
|
|
66085
66371
|
if (eligible && this.emit({ kind: "turn", turn }, log2))
|
|
@@ -66087,29 +66373,29 @@ var RuntimeActivityPort = class {
|
|
|
66087
66373
|
void this.drainLocally(turn, log2);
|
|
66088
66374
|
}
|
|
66089
66375
|
async drainLocally(turn, log2 = this.log) {
|
|
66090
|
-
let
|
|
66376
|
+
let count2 = 0;
|
|
66091
66377
|
let outcome;
|
|
66092
66378
|
try {
|
|
66093
66379
|
for await (const event of turn.events) {
|
|
66094
|
-
|
|
66380
|
+
count2 += 1;
|
|
66095
66381
|
if (event.type === "turn_outcome")
|
|
66096
66382
|
outcome = event.outcome;
|
|
66097
66383
|
}
|
|
66098
66384
|
} catch (err) {
|
|
66099
66385
|
log2?.warn?.(`local drain of runtime-initiated turn ${turn.groupKey} failed: ${String(err)}`);
|
|
66100
66386
|
}
|
|
66101
|
-
log2?.info?.(`runtime-initiated turn ${turn.groupKey} on ${turn.sessionKey} (${describeRuntimeTurnTrigger(turn.trigger)}) drained locally: ${
|
|
66387
|
+
log2?.info?.(`runtime-initiated turn ${turn.groupKey} on ${turn.sessionKey} (${describeRuntimeTurnTrigger(turn.trigger)}) drained locally: ${count2} event(s), outcome=${outcome ?? "ok"}`);
|
|
66102
66388
|
}
|
|
66103
66389
|
};
|
|
66104
66390
|
|
|
66105
66391
|
// ts/agent-core/dist/runtime-turn-base.js
|
|
66106
|
-
import { randomUUID as
|
|
66392
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
66107
66393
|
var RuntimeTurnBase = class {
|
|
66108
66394
|
sessionKey;
|
|
66109
66395
|
trigger;
|
|
66110
66396
|
onDetach;
|
|
66111
66397
|
childKind;
|
|
66112
|
-
groupKey =
|
|
66398
|
+
groupKey = randomUUID6();
|
|
66113
66399
|
startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
66114
66400
|
activityListeners = [];
|
|
66115
66401
|
detached = false;
|
|
@@ -66188,6 +66474,9 @@ function resolveClaudeAgentConfig(env = process.env) {
|
|
|
66188
66474
|
allowApiKey: env.PRLL_CLAUDE_ALLOW_API_KEY?.trim() === "1"
|
|
66189
66475
|
};
|
|
66190
66476
|
}
|
|
66477
|
+
function reportsRuntimeUsage(env = process.env) {
|
|
66478
|
+
return !isParallModelEndpoint(env.ANTHROPIC_BASE_URL, env.PRLL_API_URL);
|
|
66479
|
+
}
|
|
66191
66480
|
function resolveWsUrl(apiUrl, explicitWsUrl, swimlaneName) {
|
|
66192
66481
|
const base = explicitWsUrl || `${apiUrl.replace(/\/$/, "").replace(/^http/, "ws")}/ws`;
|
|
66193
66482
|
if (!swimlaneName)
|
|
@@ -66280,7 +66569,7 @@ function createCommandEnv(opts) {
|
|
|
66280
66569
|
|
|
66281
66570
|
// ts/claude-agent/dist/dispatch.js
|
|
66282
66571
|
import { execSync as execSync2, spawn } from "node:child_process";
|
|
66283
|
-
import { randomUUID as
|
|
66572
|
+
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
66284
66573
|
import * as fs11 from "node:fs";
|
|
66285
66574
|
import * as path14 from "node:path";
|
|
66286
66575
|
|
|
@@ -66857,7 +67146,7 @@ function parseContentLength(value) {
|
|
|
66857
67146
|
}
|
|
66858
67147
|
|
|
66859
67148
|
// ts/claude-agent/dist/compact.js
|
|
66860
|
-
import { randomUUID as
|
|
67149
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
66861
67150
|
async function runClaudeCompact(host, { sessionKey, signal, log: log2 }) {
|
|
66862
67151
|
if (signal.aborted)
|
|
66863
67152
|
return { status: "timeout" };
|
|
@@ -66871,7 +67160,7 @@ async function runClaudeCompact(host, { sessionKey, signal, log: log2 }) {
|
|
|
66871
67160
|
if (state.inputs.hasPendingInjections() || state.inputs.hasUnsettledInjections()) {
|
|
66872
67161
|
return { status: "failed", detail: "injections still pending on the session" };
|
|
66873
67162
|
}
|
|
66874
|
-
const delivery = state.inputs.register(`compact:${
|
|
67163
|
+
const delivery = state.inputs.register(`compact:${randomUUID7()}`, void 0, false);
|
|
66875
67164
|
try {
|
|
66876
67165
|
host.writeUserMessage(state.handle, "/compact", delivery.commandUuid);
|
|
66877
67166
|
} catch (err) {
|
|
@@ -67060,6 +67349,106 @@ function aggregateBusyState(states) {
|
|
|
67060
67349
|
return { activeTurns, backgroundWork, ...holdUntil !== void 0 ? { holdUntil } : {} };
|
|
67061
67350
|
}
|
|
67062
67351
|
|
|
67352
|
+
// ts/claude-agent/dist/result-usage.js
|
|
67353
|
+
function parseResultUsage(frame) {
|
|
67354
|
+
const sinceLastResult = perModel(frame.model_usage_since_last_result);
|
|
67355
|
+
const cumulative = perModel(frame.modelUsage);
|
|
67356
|
+
const usage = isRecord(frame.usage) ? frame.usage : void 0;
|
|
67357
|
+
const mainLoop = usage ? {
|
|
67358
|
+
inputTokens: count(usage.input_tokens),
|
|
67359
|
+
cacheReadTokens: count(usage.cache_read_input_tokens),
|
|
67360
|
+
cacheWriteTokens: count(usage.cache_creation_input_tokens),
|
|
67361
|
+
outputTokens: count(usage.output_tokens)
|
|
67362
|
+
} : void 0;
|
|
67363
|
+
if (!sinceLastResult && !cumulative && !mainLoop)
|
|
67364
|
+
return void 0;
|
|
67365
|
+
return {
|
|
67366
|
+
...sinceLastResult ? { sinceLastResult } : {},
|
|
67367
|
+
...cumulative ? { cumulative } : {},
|
|
67368
|
+
...mainLoop ? { mainLoop } : {}
|
|
67369
|
+
};
|
|
67370
|
+
}
|
|
67371
|
+
var ClaudeUsageMeter = class {
|
|
67372
|
+
/** The init frame's model: where the first result's main-loop usage is booked. */
|
|
67373
|
+
mainModel;
|
|
67374
|
+
/** The last `modelUsage` seen, for CLIs without the per-result field. */
|
|
67375
|
+
baseline;
|
|
67376
|
+
noteInit(model) {
|
|
67377
|
+
if (model)
|
|
67378
|
+
this.mainModel = model;
|
|
67379
|
+
}
|
|
67380
|
+
samples(usage) {
|
|
67381
|
+
if (!usage)
|
|
67382
|
+
return [];
|
|
67383
|
+
const previous = this.baseline;
|
|
67384
|
+
if (usage.cumulative)
|
|
67385
|
+
this.baseline = usage.cumulative;
|
|
67386
|
+
if (usage.sinceLastResult)
|
|
67387
|
+
return samplesOf(usage.sinceLastResult);
|
|
67388
|
+
if (!previous) {
|
|
67389
|
+
return usage.mainLoop ? samplesOf(/* @__PURE__ */ new Map([[this.mainModel ?? "unknown", usage.mainLoop]])) : [];
|
|
67390
|
+
}
|
|
67391
|
+
if (!usage.cumulative)
|
|
67392
|
+
return [];
|
|
67393
|
+
if (decreased(previous, usage.cumulative))
|
|
67394
|
+
return samplesOf(usage.cumulative);
|
|
67395
|
+
return samplesOf(difference(usage.cumulative, previous));
|
|
67396
|
+
}
|
|
67397
|
+
};
|
|
67398
|
+
var FIELDS = ["inputTokens", "cacheReadTokens", "cacheWriteTokens", "outputTokens"];
|
|
67399
|
+
function decreased(previous, current) {
|
|
67400
|
+
for (const [model, before] of previous) {
|
|
67401
|
+
const now = current.get(model);
|
|
67402
|
+
if (FIELDS.some((field) => (now?.[field] ?? 0) < before[field]))
|
|
67403
|
+
return true;
|
|
67404
|
+
}
|
|
67405
|
+
return false;
|
|
67406
|
+
}
|
|
67407
|
+
function difference(current, previous) {
|
|
67408
|
+
const out = /* @__PURE__ */ new Map();
|
|
67409
|
+
for (const [model, now] of current) {
|
|
67410
|
+
const before = previous.get(model);
|
|
67411
|
+
out.set(model, {
|
|
67412
|
+
inputTokens: now.inputTokens - (before?.inputTokens ?? 0),
|
|
67413
|
+
cacheReadTokens: now.cacheReadTokens - (before?.cacheReadTokens ?? 0),
|
|
67414
|
+
cacheWriteTokens: now.cacheWriteTokens - (before?.cacheWriteTokens ?? 0),
|
|
67415
|
+
outputTokens: now.outputTokens - (before?.outputTokens ?? 0)
|
|
67416
|
+
});
|
|
67417
|
+
}
|
|
67418
|
+
return out;
|
|
67419
|
+
}
|
|
67420
|
+
function samplesOf(perModelCounts) {
|
|
67421
|
+
const samples = [];
|
|
67422
|
+
for (const [model, counts] of perModelCounts) {
|
|
67423
|
+
if (FIELDS.every((field) => counts[field] === 0))
|
|
67424
|
+
continue;
|
|
67425
|
+
samples.push({ model, ...counts });
|
|
67426
|
+
}
|
|
67427
|
+
return samples;
|
|
67428
|
+
}
|
|
67429
|
+
function perModel(value) {
|
|
67430
|
+
if (!isRecord(value))
|
|
67431
|
+
return void 0;
|
|
67432
|
+
const out = /* @__PURE__ */ new Map();
|
|
67433
|
+
for (const [model, entry] of Object.entries(value)) {
|
|
67434
|
+
if (!model.trim() || !isRecord(entry))
|
|
67435
|
+
continue;
|
|
67436
|
+
out.set(model, {
|
|
67437
|
+
inputTokens: count(entry.inputTokens),
|
|
67438
|
+
cacheReadTokens: count(entry.cacheReadInputTokens),
|
|
67439
|
+
cacheWriteTokens: count(entry.cacheCreationInputTokens),
|
|
67440
|
+
outputTokens: count(entry.outputTokens)
|
|
67441
|
+
});
|
|
67442
|
+
}
|
|
67443
|
+
return out;
|
|
67444
|
+
}
|
|
67445
|
+
function isRecord(value) {
|
|
67446
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
67447
|
+
}
|
|
67448
|
+
function count(value) {
|
|
67449
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;
|
|
67450
|
+
}
|
|
67451
|
+
|
|
67063
67452
|
// ts/claude-agent/dist/runtime-observations.js
|
|
67064
67453
|
function claudeObservation(frame) {
|
|
67065
67454
|
const sessionId = observationField(frame.session_id);
|
|
@@ -67232,10 +67621,12 @@ async function* parseClaudeStreamJson(readable) {
|
|
|
67232
67621
|
if (eventRecord.subtype === "init") {
|
|
67233
67622
|
const sessionId = asTrimmedString(eventRecord.session_id);
|
|
67234
67623
|
const capabilities = Array.isArray(eventRecord.capabilities) ? eventRecord.capabilities.map((capability) => asTrimmedString(capability)).filter((capability) => Boolean(capability)) : [];
|
|
67624
|
+
const model = asTrimmedString(eventRecord.model);
|
|
67235
67625
|
yield {
|
|
67236
67626
|
type: "runtime_init",
|
|
67237
67627
|
...sessionId ? { sessionId } : {},
|
|
67238
|
-
capabilities
|
|
67628
|
+
capabilities,
|
|
67629
|
+
...model ? { model } : {}
|
|
67239
67630
|
};
|
|
67240
67631
|
if (observation)
|
|
67241
67632
|
yield observation;
|
|
@@ -67348,13 +67739,15 @@ async function* parseClaudeStreamJson(readable) {
|
|
|
67348
67739
|
toolUses.clear();
|
|
67349
67740
|
const numTurns = asFiniteNumber(eventRecord.num_turns);
|
|
67350
67741
|
const userMessageUuid = asTrimmedString(eventRecord.user_message_uuid) || asTrimmedString(eventRecord.command_uuid);
|
|
67742
|
+
const usage = parseResultUsage(eventRecord);
|
|
67351
67743
|
yield {
|
|
67352
67744
|
type: "turn_end",
|
|
67353
67745
|
sessionId: asTrimmedString(eventRecord.session_id),
|
|
67354
67746
|
...userMessageUuid ? { userMessageUuid } : {},
|
|
67355
67747
|
isError,
|
|
67356
67748
|
...numTurns !== void 0 ? { numTurns } : {},
|
|
67357
|
-
resultMeta: extractResultMeta(eventRecord, isError, numTurns)
|
|
67749
|
+
resultMeta: extractResultMeta(eventRecord, isError, numTurns),
|
|
67750
|
+
...usage ? { usage } : {}
|
|
67358
67751
|
};
|
|
67359
67752
|
continue;
|
|
67360
67753
|
}
|
|
@@ -67500,11 +67893,11 @@ function extractResultMeta(frame, isError, numTurns) {
|
|
|
67500
67893
|
}
|
|
67501
67894
|
|
|
67502
67895
|
// ts/claude-agent/dist/stdin-frames.js
|
|
67503
|
-
import { randomUUID as
|
|
67896
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
67504
67897
|
function writeCapabilityProbe(handle) {
|
|
67505
67898
|
const payload = JSON.stringify({
|
|
67506
67899
|
type: "user",
|
|
67507
|
-
uuid:
|
|
67900
|
+
uuid: randomUUID8(),
|
|
67508
67901
|
parent_tool_use_id: null,
|
|
67509
67902
|
message: { role: "user", content: [] }
|
|
67510
67903
|
});
|
|
@@ -67621,7 +68014,7 @@ var ClaudeCapabilityProbe = class {
|
|
|
67621
68014
|
};
|
|
67622
68015
|
|
|
67623
68016
|
// ts/claude-agent/dist/input-lifecycle.js
|
|
67624
|
-
import { randomUUID as
|
|
68017
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
67625
68018
|
|
|
67626
68019
|
// ts/claude-agent/dist/turn-outcome.js
|
|
67627
68020
|
var LIMIT_TEXT = /you'?ve (hit|reached) your .*limit|usage limit reached|weekly limit/i;
|
|
@@ -67873,7 +68266,7 @@ var ClaudeInputRegistry = class {
|
|
|
67873
68266
|
if (this.byKey.has(deliveryKey)) {
|
|
67874
68267
|
throw new Error(`duplicate Claude delivery key ${deliveryKey}`);
|
|
67875
68268
|
}
|
|
67876
|
-
const commandUuid =
|
|
68269
|
+
const commandUuid = randomUUID9();
|
|
67877
68270
|
const delivery = {
|
|
67878
68271
|
deliveryKey,
|
|
67879
68272
|
commandUuid,
|
|
@@ -68342,6 +68735,8 @@ var ClaudeProcessPump = class {
|
|
|
68342
68735
|
activeDrain = null;
|
|
68343
68736
|
now;
|
|
68344
68737
|
pendingObservations = [];
|
|
68738
|
+
/** The model usage this process's result frames state (result-usage.ts). */
|
|
68739
|
+
usage = new ClaudeUsageMeter();
|
|
68345
68740
|
constructor(opts) {
|
|
68346
68741
|
this.opts = opts;
|
|
68347
68742
|
this.now = opts.now ?? Date.now;
|
|
@@ -68647,6 +69042,7 @@ var ClaudeProcessPump = class {
|
|
|
68647
69042
|
}
|
|
68648
69043
|
handleInit(init) {
|
|
68649
69044
|
this.capabilities = new Set(init.capabilities);
|
|
69045
|
+
this.usage.noteInit(init.model);
|
|
68650
69046
|
if (init.sessionId)
|
|
68651
69047
|
this.sessionId = init.sessionId;
|
|
68652
69048
|
const fatal = this.opts.hooks.onRuntimeInit(init);
|
|
@@ -68728,6 +69124,8 @@ var ClaudeProcessPump = class {
|
|
|
68728
69124
|
}
|
|
68729
69125
|
}
|
|
68730
69126
|
async handleTurnEnd(parsed) {
|
|
69127
|
+
for (const sample of this.usage.samples(parsed.usage))
|
|
69128
|
+
this.opts.activity.emitUsage(sample);
|
|
68731
69129
|
const live = this.liveDeliveries();
|
|
68732
69130
|
const owner = this.ownerFor(false);
|
|
68733
69131
|
if (parsed.numTurns !== 0 && owner)
|
|
@@ -68812,7 +69210,7 @@ function ownsFrames(delivery) {
|
|
|
68812
69210
|
// ts/claude-agent/dist/session-manager.js
|
|
68813
69211
|
import * as fs9 from "node:fs";
|
|
68814
69212
|
import * as path12 from "node:path";
|
|
68815
|
-
import { randomUUID as
|
|
69213
|
+
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
68816
69214
|
var ClaudeSessionManager = class _ClaudeSessionManager {
|
|
68817
69215
|
mainSessionKey;
|
|
68818
69216
|
stateFilePath;
|
|
@@ -68854,7 +69252,7 @@ var ClaudeSessionManager = class _ClaudeSessionManager {
|
|
|
68854
69252
|
const parentSessionId = this.sessionIds.get(parentSessionKey);
|
|
68855
69253
|
if (!parentSessionId)
|
|
68856
69254
|
return null;
|
|
68857
|
-
const sessionKey = `${_ClaudeSessionManager.FORK_LANE_PREFIX}${
|
|
69255
|
+
const sessionKey = `${_ClaudeSessionManager.FORK_LANE_PREFIX}${randomUUID10()}`;
|
|
68858
69256
|
this.pendingForkParents.set(sessionKey, parentSessionId);
|
|
68859
69257
|
return {
|
|
68860
69258
|
sessionKey,
|
|
@@ -69107,14 +69505,13 @@ var ClaudeCodeAdapter = class {
|
|
|
69107
69505
|
terminateHandle: (handle) => this.terminateHandle(handle)
|
|
69108
69506
|
});
|
|
69109
69507
|
shuttingDown = false;
|
|
69110
|
-
activity;
|
|
69508
|
+
activity = new RuntimeActivityPort("ClaudeCodeAdapter");
|
|
69111
69509
|
_model;
|
|
69112
69510
|
_effortLevel;
|
|
69113
69511
|
_contextWindow;
|
|
69114
69512
|
_maxTokens;
|
|
69115
69513
|
constructor(opts) {
|
|
69116
69514
|
this.opts = opts;
|
|
69117
|
-
this.activity = new RuntimeActivityPort("ClaudeCodeAdapter");
|
|
69118
69515
|
this._model = opts.model;
|
|
69119
69516
|
this._contextWindow = opts.contextWindow;
|
|
69120
69517
|
this._maxTokens = opts.maxTokens;
|
|
@@ -69157,6 +69554,9 @@ var ClaudeCodeAdapter = class {
|
|
|
69157
69554
|
subscribeRuntimeActivity(handler) {
|
|
69158
69555
|
return this.activity.subscribe(handler);
|
|
69159
69556
|
}
|
|
69557
|
+
subscribeUsage(handler) {
|
|
69558
|
+
return this.activity.subscribeUsage(handler);
|
|
69559
|
+
}
|
|
69160
69560
|
busyState(now = this.now()) {
|
|
69161
69561
|
const states = [];
|
|
69162
69562
|
for (const state of this.processes.values()) {
|
|
@@ -69316,9 +69716,6 @@ var ClaudeCodeAdapter = class {
|
|
|
69316
69716
|
releasePreparedAttachments();
|
|
69317
69717
|
}
|
|
69318
69718
|
}
|
|
69319
|
-
getBranchPoint(_sessionKey) {
|
|
69320
|
-
return void 0;
|
|
69321
|
-
}
|
|
69322
69719
|
getSessionHistoryPath(sessionKey) {
|
|
69323
69720
|
const sessionId = this.opts.sessionManager.getSessionId(sessionKey);
|
|
69324
69721
|
if (!sessionId)
|
|
@@ -69412,7 +69809,7 @@ var ClaudeCodeAdapter = class {
|
|
|
69412
69809
|
async *consumeDelivery(sessionKey, state, target, noteActivity) {
|
|
69413
69810
|
if (target.terminal)
|
|
69414
69811
|
return;
|
|
69415
|
-
const groupKey =
|
|
69812
|
+
const groupKey = randomUUID11();
|
|
69416
69813
|
state.pump.setActiveDrain(target, noteActivity);
|
|
69417
69814
|
try {
|
|
69418
69815
|
while (true) {
|
|
@@ -69901,6 +70298,8 @@ async function main() {
|
|
|
69901
70298
|
claude_home: config.claudeHome
|
|
69902
70299
|
},
|
|
69903
70300
|
dispatchAdapter: adapter,
|
|
70301
|
+
// After resolveProviderEnv: the CLI's own-login usage, not Parall's metered models.
|
|
70302
|
+
reportRuntimeUsage: reportsRuntimeUsage(),
|
|
69904
70303
|
log: agentLog,
|
|
69905
70304
|
// Live capability view for hint routing: the channel reply hint points
|
|
69906
70305
|
// at the vendor CLI only while the grant is active (config manager
|