@parall/daemon 1.91.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 +76 -14
- package/bundle/parall-claude-agent.js +490 -51
- package/bundle/parall-codex-agent.js +480 -56
- package/bundle/parall-daemon.js +143 -19
- 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(() => {
|
|
@@ -52161,6 +52161,8 @@ var clipConnectionEndpoints = {
|
|
|
52161
52161
|
CLIP_CONNECTIONS_ALL: (orgId) => `/api/v1/orgs/${orgId}/clip-connections/all`,
|
|
52162
52162
|
CLIP_CONNECTIONS: (orgId, clipId) => `/api/v1/orgs/${orgId}/clip-registry/${clipId}/connections`,
|
|
52163
52163
|
CLIP_CONNECTION_ACCESS: (orgId, connId) => `/api/v1/orgs/${orgId}/clip-connections/${connId}/access`,
|
|
52164
|
+
/** Who among the org's agents may use one account (per-account setting). */
|
|
52165
|
+
CLIP_CONNECTION_AGENT_ACCESS: (orgId, connId) => `/api/v1/orgs/${orgId}/clip-connections/${connId}/agent-access`,
|
|
52164
52166
|
CLIP_CONNECTION: (orgId, connId) => `/api/v1/orgs/${orgId}/clip-connections/${connId}`,
|
|
52165
52167
|
/** The caller's own (person-owned) connections; login session only. */
|
|
52166
52168
|
ORG_MY_CONNECTIONS: (orgId) => `/api/v1/orgs/${orgId}/me/connections`,
|
|
@@ -52429,6 +52431,7 @@ var ENDPOINTS = {
|
|
|
52429
52431
|
AGENT_ME: (orgId) => `${API_BASE2}/orgs/${orgId}/agents/me`,
|
|
52430
52432
|
AGENT_REPLY_POLICY_CAPABILITY: (orgId) => `${API_BASE2}/orgs/${orgId}/agents/me/reply-policy-capability`,
|
|
52431
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`,
|
|
52432
52435
|
...secretEndpoints(API_BASE2),
|
|
52433
52436
|
AGENT_NEW_SESSION: (orgId, agentId) => `${API_BASE2}/orgs/${orgId}/agents/${agentId}/new-session`,
|
|
52434
52437
|
AGENT_DEEP_RESET: (orgId, agentId) => `${API_BASE2}/orgs/${orgId}/agents/${agentId}/deep-reset`,
|
|
@@ -53507,8 +53510,16 @@ var MiniAppAccessClient = class extends MiniAppActionClient {
|
|
|
53507
53510
|
async removeMiniAppAccessGrant(orgId, appId, userId) {
|
|
53508
53511
|
return this.request("DELETE", `${access(orgId, appId)}/grants/${encodeURIComponent(userId)}`);
|
|
53509
53512
|
}
|
|
53510
|
-
/**
|
|
53511
|
-
* the
|
|
53513
|
+
/** Puts a team of the organization on the app's access list, or changes
|
|
53514
|
+
* its level: everyone the team reaches gets at least that much. */
|
|
53515
|
+
async setMiniAppAccessTeamGrant(orgId, appId, teamId, level) {
|
|
53516
|
+
return this.request("PUT", `${access(orgId, appId)}/team-grants/${encodeURIComponent(teamId)}`, { access: level });
|
|
53517
|
+
}
|
|
53518
|
+
async removeMiniAppAccessTeamGrant(orgId, appId, teamId) {
|
|
53519
|
+
return this.request("DELETE", `${access(orgId, appId)}/team-grants/${encodeURIComponent(teamId)}`);
|
|
53520
|
+
}
|
|
53521
|
+
/** The change record, newest first: member_access, the access list (people
|
|
53522
|
+
* and teams) and the author roster. */
|
|
53512
53523
|
async getMiniAppAccessLog(orgId, appId, query = {}) {
|
|
53513
53524
|
const response = await this.request("GET", `${access(orgId, appId)}/log`, void 0, { limit: query.limit, before_id: query.before_id });
|
|
53514
53525
|
return response.data;
|
|
@@ -53738,6 +53749,10 @@ var ClipConnectionClient = class extends ChannelConversationClient {
|
|
|
53738
53749
|
};
|
|
53739
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 });
|
|
53740
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
|
+
}
|
|
53741
53756
|
// ---- Clip connections ----
|
|
53742
53757
|
/** Missing keys are unknown/hidden; present empty arrays are known empty. */
|
|
53743
53758
|
async listClipMCPSummaries(orgId, clipIds) {
|
|
@@ -53776,6 +53791,17 @@ var ClipConnectionClient = class extends ChannelConversationClient {
|
|
|
53776
53791
|
async putClipConnectionAccess(orgId, connId, input) {
|
|
53777
53792
|
return this.request("PUT", ENDPOINTS.CLIP_CONNECTION_ACCESS(orgId, connId), input);
|
|
53778
53793
|
}
|
|
53794
|
+
/** Who among the org's agents may use this account. Any org member may read. */
|
|
53795
|
+
async getClipConnectionAgentAccess(orgId, connId) {
|
|
53796
|
+
return this.request("GET", ENDPOINTS.CLIP_CONNECTION_AGENT_ACCESS(orgId, connId));
|
|
53797
|
+
}
|
|
53798
|
+
/**
|
|
53799
|
+
* Replace this account's agent access. Human org owner/admin only (JWT or
|
|
53800
|
+
* personal key); saving `selected` also turns `org_public` off.
|
|
53801
|
+
*/
|
|
53802
|
+
async putClipConnectionAgentAccess(orgId, connId, input) {
|
|
53803
|
+
return this.request("PUT", ENDPOINTS.CLIP_CONNECTION_AGENT_ACCESS(orgId, connId), input);
|
|
53804
|
+
}
|
|
53779
53805
|
/** Start OAuth using the reviewed platform app or provider registration ladder.
|
|
53780
53806
|
* Allow discovery (30s), persistence (10s), and network overhead to finish. */
|
|
53781
53807
|
async createClipMCPOAuthConnection(orgId, clipId, serverUrl, alias, oauthClient) {
|
|
@@ -54228,10 +54254,25 @@ var AgentOwningTeamClient = class extends AgentTeamOnlyClient {
|
|
|
54228
54254
|
}
|
|
54229
54255
|
};
|
|
54230
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
|
+
|
|
54231
54272
|
// ts/sdk/dist/team-graph-client.js
|
|
54232
|
-
var TeamGraphClient = class extends
|
|
54273
|
+
var TeamGraphClient = class extends RuntimeAuthLlmUsageClient {
|
|
54233
54274
|
async getTeamGraph(orgId, opts) {
|
|
54234
|
-
const query = opts?.includeAccess ? "?include=access" : "";
|
|
54275
|
+
const query = opts?.includeAccess ? "?include=access&include=apps" : "";
|
|
54235
54276
|
return this.request("GET", `${ENDPOINTS.TEAM_GRAPH(orgId)}${query}`);
|
|
54236
54277
|
}
|
|
54237
54278
|
/**
|
|
@@ -54241,9 +54282,12 @@ var TeamGraphClient = class extends AgentOwningTeamClient {
|
|
|
54241
54282
|
* would refuse, with the same codes. 503 when it cannot compute the whole answer
|
|
54242
54283
|
* (`TEAM_MOVE_PREVIEW_WIKI_UNAVAILABLE`, `TEAM_MOVE_PREVIEW_TIMEOUT`,
|
|
54243
54284
|
* `TEAM_MOVE_PREVIEW_TOO_LARGE`). Send `tree_revision` back on `setTeamParent`.
|
|
54285
|
+
* Asks for Mini Apps too (`include=apps`): without it, a move that changes
|
|
54286
|
+
* someone's access to an app answers 503 `TEAM_MOVE_PREVIEW_APPS_UNSUPPORTED`
|
|
54287
|
+
* (mini-app-access-team-grants-design.md §5).
|
|
54244
54288
|
*/
|
|
54245
54289
|
async previewTeamMove(orgId, teamId, parentTeamId) {
|
|
54246
|
-
return this.request("POST", ENDPOINTS.TEAM_PARENT_PREVIEW(orgId, teamId)
|
|
54290
|
+
return this.request("POST", `${ENDPOINTS.TEAM_PARENT_PREVIEW(orgId, teamId)}?include=apps`, {
|
|
54247
54291
|
parent_team_id: parentTeamId
|
|
54248
54292
|
});
|
|
54249
54293
|
}
|
|
@@ -54498,6 +54542,20 @@ var ChatBookmarksClient = class extends WikiPageShareClient {
|
|
|
54498
54542
|
}
|
|
54499
54543
|
};
|
|
54500
54544
|
|
|
54545
|
+
// ts/sdk/dist/template-catalog-client.js
|
|
54546
|
+
var templateCatalogPath = (orgId) => `${API_BASE2}/orgs/${orgId}/templates/catalog`;
|
|
54547
|
+
var TemplateCatalogClient = class extends ChatBookmarksClient {
|
|
54548
|
+
/**
|
|
54549
|
+
* The published team templates this organization can hire. Open to every
|
|
54550
|
+
* member, people and agents alike (owners and admins also have the full
|
|
54551
|
+
* definitions through `listOfficialTemplates`).
|
|
54552
|
+
*/
|
|
54553
|
+
async listTemplateCatalog(orgId) {
|
|
54554
|
+
const res = await this.request("GET", templateCatalogPath(orgId));
|
|
54555
|
+
return res.templates ?? [];
|
|
54556
|
+
}
|
|
54557
|
+
};
|
|
54558
|
+
|
|
54501
54559
|
// ts/sdk/dist/wiki-changeset.js
|
|
54502
54560
|
function normalizeWikiChangeset(changeset) {
|
|
54503
54561
|
return {
|
|
@@ -54533,7 +54591,7 @@ function legacyHeartbeatFromReport(report) {
|
|
|
54533
54591
|
detectedRuntimes
|
|
54534
54592
|
};
|
|
54535
54593
|
}
|
|
54536
|
-
var ParallClient = class _ParallClient extends
|
|
54594
|
+
var ParallClient = class _ParallClient extends TemplateCatalogClient {
|
|
54537
54595
|
baseUrl;
|
|
54538
54596
|
wikiBaseUrl;
|
|
54539
54597
|
token;
|
|
@@ -56837,9 +56895,11 @@ var ParallClient = class _ParallClient extends ChatBookmarksClient {
|
|
|
56837
56895
|
});
|
|
56838
56896
|
}
|
|
56839
56897
|
/** Idempotently begin deleting a hosted Cloud Profile; every repeat returns
|
|
56840
|
-
* `202 deleting` until the pod and stored browser state are finalized.
|
|
56841
|
-
|
|
56842
|
-
|
|
56898
|
+
* `202 deleting` until the pod and stored browser state are finalized.
|
|
56899
|
+
* `ifUnused` deletes only when no connection runs on it and no browser
|
|
56900
|
+
* profile on it is shared or granted; otherwise `409 EDGE_IN_USE`. */
|
|
56901
|
+
async deleteEdgeDevice(orgId, edgeId, options) {
|
|
56902
|
+
return this.request("DELETE", ENDPOINTS.ORG_EDGE_DEVICE(orgId, edgeId), void 0, options?.ifUnused ? { if_unused: "true" } : void 0);
|
|
56843
56903
|
}
|
|
56844
56904
|
/** Move the human caller's OWN BYOC device between the org layer and their
|
|
56845
56905
|
* personal layer (ADR-020). `member` takes the device — and every clip
|
|
@@ -57072,9 +57132,8 @@ var ParallClient = class _ParallClient extends ChatBookmarksClient {
|
|
|
57072
57132
|
}
|
|
57073
57133
|
async createClipMCPConnection(orgId, clipId, req) {
|
|
57074
57134
|
return this.request("POST", ENDPOINTS.ORG_CLIP_MCP_CONFIGS(orgId, clipId), req, void 0, false, {
|
|
57075
|
-
//
|
|
57076
|
-
|
|
57077
|
-
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
|
|
57078
57137
|
});
|
|
57079
57138
|
}
|
|
57080
57139
|
/** Delete one MCP config and its paired connection. */
|
|
@@ -57101,8 +57160,8 @@ var ParallClient = class _ParallClient extends ChatBookmarksClient {
|
|
|
57101
57160
|
void 0,
|
|
57102
57161
|
void 0,
|
|
57103
57162
|
false,
|
|
57104
|
-
//
|
|
57105
|
-
{ timeoutMs:
|
|
57163
|
+
// Managed refresh includes account readback and session creation (60s).
|
|
57164
|
+
{ timeoutMs: 7e4 }
|
|
57106
57165
|
);
|
|
57107
57166
|
}
|
|
57108
57167
|
// ---- Deprecated method aliases (External* → Trigger* rename; same endpoints) ----
|
|
@@ -57238,6 +57297,10 @@ function buildApiError(res, rawErrorBody) {
|
|
|
57238
57297
|
return apiError;
|
|
57239
57298
|
}
|
|
57240
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
|
+
|
|
57241
57304
|
// ts/sdk/dist/ws.js
|
|
57242
57305
|
function describeWsStateDetail(detail) {
|
|
57243
57306
|
if (!detail)
|
|
@@ -57668,6 +57731,13 @@ function clearAllProviderCreds(env) {
|
|
|
57668
57731
|
delete env[name];
|
|
57669
57732
|
delete env.PRLL_CLAUDE_ALLOW_API_KEY;
|
|
57670
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
|
+
}
|
|
57671
57741
|
function parseProviderConfig(env) {
|
|
57672
57742
|
const raw = env.PRLL_PROVIDER_CONFIG?.trim();
|
|
57673
57743
|
if (!raw)
|
|
@@ -58690,8 +58760,8 @@ var OtlpSpoolStore = class {
|
|
|
58690
58760
|
return this.opts.dir;
|
|
58691
58761
|
}
|
|
58692
58762
|
/** Count a batch the exporter dropped for a permanent status (never spooled). */
|
|
58693
|
-
recordDrop(signal, reason,
|
|
58694
|
-
this.opts.onEvent?.({ kind: "dropped", signal, reason, count });
|
|
58763
|
+
recordDrop(signal, reason, count2 = 1) {
|
|
58764
|
+
this.opts.onEvent?.({ kind: "dropped", signal, reason, count: count2 });
|
|
58695
58765
|
}
|
|
58696
58766
|
/**
|
|
58697
58767
|
* Append one serialized request. Resolves once the file is renamed into
|
|
@@ -59001,6 +59071,19 @@ var dispatchSpans = /* @__PURE__ */ new WeakSet();
|
|
|
59001
59071
|
var recordedErrors = /* @__PURE__ */ new WeakSet();
|
|
59002
59072
|
var dispatchCounter = null;
|
|
59003
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
|
+
];
|
|
59004
59087
|
var missingReplyCounter = null;
|
|
59005
59088
|
var turnTokensCounter = null;
|
|
59006
59089
|
var turnCostCounter = null;
|
|
@@ -59154,7 +59237,7 @@ async function initAgentTelemetry(serviceName, runtimeType, opts = {}) {
|
|
|
59154
59237
|
const metricExporter = spooled(new OTLPMetricExporter({ url: `${otelEndpoint}/v1/metrics`, headers: authHeaders }), "metrics", serializers?.ProtobufMetricsSerializer);
|
|
59155
59238
|
const metricReader = new PeriodicExportingMetricReader({
|
|
59156
59239
|
exporter: metricExporter,
|
|
59157
|
-
exportIntervalMillis:
|
|
59240
|
+
exportIntervalMillis: 6e4
|
|
59158
59241
|
});
|
|
59159
59242
|
const meterProvider = new MeterProvider({ resource, readers: [metricReader] });
|
|
59160
59243
|
metrics.setGlobalMeterProvider(meterProvider);
|
|
@@ -59168,7 +59251,8 @@ async function initAgentTelemetry(serviceName, runtimeType, opts = {}) {
|
|
|
59168
59251
|
});
|
|
59169
59252
|
dispatchDuration = meter.createHistogram("parall.dispatch.duration", {
|
|
59170
59253
|
description: "Dispatch cycle duration in milliseconds",
|
|
59171
|
-
unit: "ms"
|
|
59254
|
+
unit: "ms",
|
|
59255
|
+
advice: { explicitBucketBoundaries: DISPATCH_DURATION_BUCKETS_MS }
|
|
59172
59256
|
});
|
|
59173
59257
|
missingReplyCounter = meter.createCounter("parall.dispatch.missing_reply", {
|
|
59174
59258
|
description: "Dispatches where agent produced text but sent no reply message"
|
|
@@ -61389,6 +61473,224 @@ async function closeRuntimeChildSession(host, sessionKey, reason) {
|
|
|
61389
61473
|
}
|
|
61390
61474
|
}
|
|
61391
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
|
+
|
|
61392
61694
|
// ts/agent-core/dist/gateway/drain.js
|
|
61393
61695
|
var DrainGate = class {
|
|
61394
61696
|
isDrained;
|
|
@@ -61569,7 +61871,7 @@ var DispatchInactivityDeadlines = class {
|
|
|
61569
61871
|
};
|
|
61570
61872
|
|
|
61571
61873
|
// ts/agent-core/dist/session/step-retry-queue.js
|
|
61572
|
-
var
|
|
61874
|
+
var DEFAULT_RETRY_DELAYS_MS4 = [5e3, 1e4, 2e4, 4e4, 6e4];
|
|
61573
61875
|
async function raceWithDeadline2(work, ms) {
|
|
61574
61876
|
let timer;
|
|
61575
61877
|
const timeout = new Promise((resolve3) => {
|
|
@@ -61599,7 +61901,7 @@ var StepRetryQueue = class {
|
|
|
61599
61901
|
disposed = false;
|
|
61600
61902
|
constructor(opts) {
|
|
61601
61903
|
this.opts = opts;
|
|
61602
|
-
this.retryDelays = opts.retryDelaysMs?.length ? opts.retryDelaysMs :
|
|
61904
|
+
this.retryDelays = opts.retryDelaysMs?.length ? opts.retryDelaysMs : DEFAULT_RETRY_DELAYS_MS4;
|
|
61603
61905
|
}
|
|
61604
61906
|
hasPending(sessionId) {
|
|
61605
61907
|
return (this.queues.get(sessionId)?.length ?? 0) > 0;
|
|
@@ -62038,14 +62340,14 @@ function recordToolCall(sessionKey) {
|
|
|
62038
62340
|
}
|
|
62039
62341
|
|
|
62040
62342
|
// ts/agent-core/dist/gateway/input-steps.js
|
|
62041
|
-
import { randomUUID as
|
|
62343
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
62042
62344
|
function inputStepIdempotencyKey(event) {
|
|
62043
62345
|
if (event.type === "message" || event.type === "channel_message") {
|
|
62044
|
-
return event.messageId ? `input:${event.messageId}` :
|
|
62346
|
+
return event.messageId ? `input:${event.messageId}` : randomUUID5();
|
|
62045
62347
|
}
|
|
62046
62348
|
if (event.dispatchEventId)
|
|
62047
62349
|
return `input:${event.dispatchEventId}`;
|
|
62048
|
-
return
|
|
62350
|
+
return randomUUID5();
|
|
62049
62351
|
}
|
|
62050
62352
|
function resolveStepTarget(event) {
|
|
62051
62353
|
if (event.input?.step_target) {
|
|
@@ -62931,12 +63233,12 @@ async function catchUpFromDispatch(host) {
|
|
|
62931
63233
|
let expireSummary = null;
|
|
62932
63234
|
let overflowMode = false;
|
|
62933
63235
|
try {
|
|
62934
|
-
const { count } = await host.opts.client.getDispatchPendingCount(host.opts.config.org_id);
|
|
62935
|
-
if (
|
|
63236
|
+
const { count: count2 } = await host.opts.client.getDispatchPendingCount(host.opts.config.org_id);
|
|
63237
|
+
if (count2 > OVERFLOW_THRESHOLD) {
|
|
62936
63238
|
overflowMode = true;
|
|
62937
63239
|
const result = await host.opts.client.expireDispatch(host.opts.config.org_id, EXPIRE_AGE_HOURS);
|
|
62938
63240
|
if (result.total > 0) {
|
|
62939
|
-
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`);
|
|
62940
63242
|
expireSummary = host.buildOfflineSummary(result.groups);
|
|
62941
63243
|
}
|
|
62942
63244
|
}
|
|
@@ -62990,7 +63292,7 @@ async function catchUpFromDispatch(host) {
|
|
|
62990
63292
|
if (expireSummary)
|
|
62991
63293
|
parts.push(expireSummary);
|
|
62992
63294
|
if (skipped > 0) {
|
|
62993
|
-
const recentLines = [...skippedByType.entries()].map(([type,
|
|
63295
|
+
const recentLines = [...skippedByType.entries()].map(([type, count2]) => `- ${count2} recent ${type.replace(".", " ").replace("_", " ")} events`).join("\n");
|
|
62994
63296
|
parts.push(expireSummary ? `Additionally, ${skipped} recent events exceeded the catch-up limit and were skipped:
|
|
62995
63297
|
${recentLines}` : `[Offline Summary] You were offline. ${skipped} pending events exceeded the catch-up limit and were skipped:
|
|
62996
63298
|
${recentLines}
|
|
@@ -63134,6 +63436,7 @@ async function handleHello(host, data) {
|
|
|
63134
63436
|
log2?.info("re-probing dispatch ledger after reconnect (was disabled)");
|
|
63135
63437
|
host.ledgerDisabled = false;
|
|
63136
63438
|
}
|
|
63439
|
+
host.runtimeUsage.resume();
|
|
63137
63440
|
const intervalSec = data.heartbeat_interval > 0 ? data.heartbeat_interval : 30;
|
|
63138
63441
|
let openFence = () => {
|
|
63139
63442
|
};
|
|
@@ -63250,6 +63553,7 @@ async function shutdown(host, opts = { skipDrain: false }) {
|
|
|
63250
63553
|
if (!settled()) {
|
|
63251
63554
|
await host.drainGate.wait(5e3, settled);
|
|
63252
63555
|
}
|
|
63556
|
+
const usageFlushed = host.runtimeUsage.flush();
|
|
63253
63557
|
if (host.stepPersister.pendingTotal() > 0) {
|
|
63254
63558
|
const remaining = await host.stepPersister.flush(1e4);
|
|
63255
63559
|
if (remaining > 0) {
|
|
@@ -63257,6 +63561,7 @@ async function shutdown(host, opts = { skipDrain: false }) {
|
|
|
63257
63561
|
}
|
|
63258
63562
|
}
|
|
63259
63563
|
host.stepPersister.dispose();
|
|
63564
|
+
await usageFlushed;
|
|
63260
63565
|
const lifecycleRemaining = await host.sessionLifecycle.flush(5e3);
|
|
63261
63566
|
if (lifecycleRemaining > 0) {
|
|
63262
63567
|
host.opts.log?.warn(`${lifecycleRemaining} session lifecycle write(s) unreconciled at shutdown`);
|
|
@@ -63336,6 +63641,8 @@ var ParallAgentGateway = class {
|
|
|
63336
63641
|
drainGate = new DrainGate(() => this.isDrained());
|
|
63337
63642
|
runtimeActivity = createRuntimeActivityState();
|
|
63338
63643
|
unsubscribeRuntimeActivity;
|
|
63644
|
+
// The runtime's own-login model usage, batched (gateway/runtime-usage-reporter.ts).
|
|
63645
|
+
runtimeUsage;
|
|
63339
63646
|
pendingRestartNotification = null;
|
|
63340
63647
|
laneLedger;
|
|
63341
63648
|
stepPersister;
|
|
@@ -63379,6 +63686,7 @@ var ParallAgentGateway = class {
|
|
|
63379
63686
|
this.DISPATCH_DEADLINE_MS = opts.dispatchDeadlineMs ?? 0;
|
|
63380
63687
|
this.INACTIVITY_WARN_MS = opts.inactivityWarnMs ?? 30 * 6e4;
|
|
63381
63688
|
this.unsubscribeRuntimeActivity = opts.dispatchAdapter.subscribeRuntimeActivity?.((event) => this.handleRuntimeActivity(event));
|
|
63689
|
+
this.runtimeUsage = new RuntimeUsageReporter(opts);
|
|
63382
63690
|
this.stepPersister = new StepPersister({
|
|
63383
63691
|
client: opts.client,
|
|
63384
63692
|
orgId: opts.config.org_id,
|
|
@@ -66015,6 +66323,7 @@ var RuntimeActivityPort = class {
|
|
|
66015
66323
|
label;
|
|
66016
66324
|
log;
|
|
66017
66325
|
handler = null;
|
|
66326
|
+
usageHandler = null;
|
|
66018
66327
|
constructor(label, log2) {
|
|
66019
66328
|
this.label = label;
|
|
66020
66329
|
this.log = log2;
|
|
@@ -66028,6 +66337,15 @@ var RuntimeActivityPort = class {
|
|
|
66028
66337
|
this.handler = null;
|
|
66029
66338
|
};
|
|
66030
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
|
+
}
|
|
66031
66349
|
/** Hand an event to the subscriber; false when there is none or it threw. */
|
|
66032
66350
|
emit(event, log2 = this.log) {
|
|
66033
66351
|
if (!this.handler)
|
|
@@ -66040,6 +66358,14 @@ var RuntimeActivityPort = class {
|
|
|
66040
66358
|
return false;
|
|
66041
66359
|
}
|
|
66042
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
|
+
}
|
|
66043
66369
|
/** A turn opened: to the subscriber when eligible, else drained here. */
|
|
66044
66370
|
surfaceTurn(turn, eligible = true, log2 = this.log) {
|
|
66045
66371
|
if (eligible && this.emit({ kind: "turn", turn }, log2))
|
|
@@ -66047,29 +66373,29 @@ var RuntimeActivityPort = class {
|
|
|
66047
66373
|
void this.drainLocally(turn, log2);
|
|
66048
66374
|
}
|
|
66049
66375
|
async drainLocally(turn, log2 = this.log) {
|
|
66050
|
-
let
|
|
66376
|
+
let count2 = 0;
|
|
66051
66377
|
let outcome;
|
|
66052
66378
|
try {
|
|
66053
66379
|
for await (const event of turn.events) {
|
|
66054
|
-
|
|
66380
|
+
count2 += 1;
|
|
66055
66381
|
if (event.type === "turn_outcome")
|
|
66056
66382
|
outcome = event.outcome;
|
|
66057
66383
|
}
|
|
66058
66384
|
} catch (err) {
|
|
66059
66385
|
log2?.warn?.(`local drain of runtime-initiated turn ${turn.groupKey} failed: ${String(err)}`);
|
|
66060
66386
|
}
|
|
66061
|
-
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"}`);
|
|
66062
66388
|
}
|
|
66063
66389
|
};
|
|
66064
66390
|
|
|
66065
66391
|
// ts/agent-core/dist/runtime-turn-base.js
|
|
66066
|
-
import { randomUUID as
|
|
66392
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
66067
66393
|
var RuntimeTurnBase = class {
|
|
66068
66394
|
sessionKey;
|
|
66069
66395
|
trigger;
|
|
66070
66396
|
onDetach;
|
|
66071
66397
|
childKind;
|
|
66072
|
-
groupKey =
|
|
66398
|
+
groupKey = randomUUID6();
|
|
66073
66399
|
startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
66074
66400
|
activityListeners = [];
|
|
66075
66401
|
detached = false;
|
|
@@ -66148,6 +66474,9 @@ function resolveClaudeAgentConfig(env = process.env) {
|
|
|
66148
66474
|
allowApiKey: env.PRLL_CLAUDE_ALLOW_API_KEY?.trim() === "1"
|
|
66149
66475
|
};
|
|
66150
66476
|
}
|
|
66477
|
+
function reportsRuntimeUsage(env = process.env) {
|
|
66478
|
+
return !isParallModelEndpoint(env.ANTHROPIC_BASE_URL, env.PRLL_API_URL);
|
|
66479
|
+
}
|
|
66151
66480
|
function resolveWsUrl(apiUrl, explicitWsUrl, swimlaneName) {
|
|
66152
66481
|
const base = explicitWsUrl || `${apiUrl.replace(/\/$/, "").replace(/^http/, "ws")}/ws`;
|
|
66153
66482
|
if (!swimlaneName)
|
|
@@ -66240,7 +66569,7 @@ function createCommandEnv(opts) {
|
|
|
66240
66569
|
|
|
66241
66570
|
// ts/claude-agent/dist/dispatch.js
|
|
66242
66571
|
import { execSync as execSync2, spawn } from "node:child_process";
|
|
66243
|
-
import { randomUUID as
|
|
66572
|
+
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
66244
66573
|
import * as fs11 from "node:fs";
|
|
66245
66574
|
import * as path14 from "node:path";
|
|
66246
66575
|
|
|
@@ -66817,7 +67146,7 @@ function parseContentLength(value) {
|
|
|
66817
67146
|
}
|
|
66818
67147
|
|
|
66819
67148
|
// ts/claude-agent/dist/compact.js
|
|
66820
|
-
import { randomUUID as
|
|
67149
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
66821
67150
|
async function runClaudeCompact(host, { sessionKey, signal, log: log2 }) {
|
|
66822
67151
|
if (signal.aborted)
|
|
66823
67152
|
return { status: "timeout" };
|
|
@@ -66831,7 +67160,7 @@ async function runClaudeCompact(host, { sessionKey, signal, log: log2 }) {
|
|
|
66831
67160
|
if (state.inputs.hasPendingInjections() || state.inputs.hasUnsettledInjections()) {
|
|
66832
67161
|
return { status: "failed", detail: "injections still pending on the session" };
|
|
66833
67162
|
}
|
|
66834
|
-
const delivery = state.inputs.register(`compact:${
|
|
67163
|
+
const delivery = state.inputs.register(`compact:${randomUUID7()}`, void 0, false);
|
|
66835
67164
|
try {
|
|
66836
67165
|
host.writeUserMessage(state.handle, "/compact", delivery.commandUuid);
|
|
66837
67166
|
} catch (err) {
|
|
@@ -67020,6 +67349,106 @@ function aggregateBusyState(states) {
|
|
|
67020
67349
|
return { activeTurns, backgroundWork, ...holdUntil !== void 0 ? { holdUntil } : {} };
|
|
67021
67350
|
}
|
|
67022
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
|
+
|
|
67023
67452
|
// ts/claude-agent/dist/runtime-observations.js
|
|
67024
67453
|
function claudeObservation(frame) {
|
|
67025
67454
|
const sessionId = observationField(frame.session_id);
|
|
@@ -67192,10 +67621,12 @@ async function* parseClaudeStreamJson(readable) {
|
|
|
67192
67621
|
if (eventRecord.subtype === "init") {
|
|
67193
67622
|
const sessionId = asTrimmedString(eventRecord.session_id);
|
|
67194
67623
|
const capabilities = Array.isArray(eventRecord.capabilities) ? eventRecord.capabilities.map((capability) => asTrimmedString(capability)).filter((capability) => Boolean(capability)) : [];
|
|
67624
|
+
const model = asTrimmedString(eventRecord.model);
|
|
67195
67625
|
yield {
|
|
67196
67626
|
type: "runtime_init",
|
|
67197
67627
|
...sessionId ? { sessionId } : {},
|
|
67198
|
-
capabilities
|
|
67628
|
+
capabilities,
|
|
67629
|
+
...model ? { model } : {}
|
|
67199
67630
|
};
|
|
67200
67631
|
if (observation)
|
|
67201
67632
|
yield observation;
|
|
@@ -67308,13 +67739,15 @@ async function* parseClaudeStreamJson(readable) {
|
|
|
67308
67739
|
toolUses.clear();
|
|
67309
67740
|
const numTurns = asFiniteNumber(eventRecord.num_turns);
|
|
67310
67741
|
const userMessageUuid = asTrimmedString(eventRecord.user_message_uuid) || asTrimmedString(eventRecord.command_uuid);
|
|
67742
|
+
const usage = parseResultUsage(eventRecord);
|
|
67311
67743
|
yield {
|
|
67312
67744
|
type: "turn_end",
|
|
67313
67745
|
sessionId: asTrimmedString(eventRecord.session_id),
|
|
67314
67746
|
...userMessageUuid ? { userMessageUuid } : {},
|
|
67315
67747
|
isError,
|
|
67316
67748
|
...numTurns !== void 0 ? { numTurns } : {},
|
|
67317
|
-
resultMeta: extractResultMeta(eventRecord, isError, numTurns)
|
|
67749
|
+
resultMeta: extractResultMeta(eventRecord, isError, numTurns),
|
|
67750
|
+
...usage ? { usage } : {}
|
|
67318
67751
|
};
|
|
67319
67752
|
continue;
|
|
67320
67753
|
}
|
|
@@ -67460,11 +67893,11 @@ function extractResultMeta(frame, isError, numTurns) {
|
|
|
67460
67893
|
}
|
|
67461
67894
|
|
|
67462
67895
|
// ts/claude-agent/dist/stdin-frames.js
|
|
67463
|
-
import { randomUUID as
|
|
67896
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
67464
67897
|
function writeCapabilityProbe(handle) {
|
|
67465
67898
|
const payload = JSON.stringify({
|
|
67466
67899
|
type: "user",
|
|
67467
|
-
uuid:
|
|
67900
|
+
uuid: randomUUID8(),
|
|
67468
67901
|
parent_tool_use_id: null,
|
|
67469
67902
|
message: { role: "user", content: [] }
|
|
67470
67903
|
});
|
|
@@ -67581,7 +68014,7 @@ var ClaudeCapabilityProbe = class {
|
|
|
67581
68014
|
};
|
|
67582
68015
|
|
|
67583
68016
|
// ts/claude-agent/dist/input-lifecycle.js
|
|
67584
|
-
import { randomUUID as
|
|
68017
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
67585
68018
|
|
|
67586
68019
|
// ts/claude-agent/dist/turn-outcome.js
|
|
67587
68020
|
var LIMIT_TEXT = /you'?ve (hit|reached) your .*limit|usage limit reached|weekly limit/i;
|
|
@@ -67833,7 +68266,7 @@ var ClaudeInputRegistry = class {
|
|
|
67833
68266
|
if (this.byKey.has(deliveryKey)) {
|
|
67834
68267
|
throw new Error(`duplicate Claude delivery key ${deliveryKey}`);
|
|
67835
68268
|
}
|
|
67836
|
-
const commandUuid =
|
|
68269
|
+
const commandUuid = randomUUID9();
|
|
67837
68270
|
const delivery = {
|
|
67838
68271
|
deliveryKey,
|
|
67839
68272
|
commandUuid,
|
|
@@ -68302,6 +68735,8 @@ var ClaudeProcessPump = class {
|
|
|
68302
68735
|
activeDrain = null;
|
|
68303
68736
|
now;
|
|
68304
68737
|
pendingObservations = [];
|
|
68738
|
+
/** The model usage this process's result frames state (result-usage.ts). */
|
|
68739
|
+
usage = new ClaudeUsageMeter();
|
|
68305
68740
|
constructor(opts) {
|
|
68306
68741
|
this.opts = opts;
|
|
68307
68742
|
this.now = opts.now ?? Date.now;
|
|
@@ -68607,6 +69042,7 @@ var ClaudeProcessPump = class {
|
|
|
68607
69042
|
}
|
|
68608
69043
|
handleInit(init) {
|
|
68609
69044
|
this.capabilities = new Set(init.capabilities);
|
|
69045
|
+
this.usage.noteInit(init.model);
|
|
68610
69046
|
if (init.sessionId)
|
|
68611
69047
|
this.sessionId = init.sessionId;
|
|
68612
69048
|
const fatal = this.opts.hooks.onRuntimeInit(init);
|
|
@@ -68688,6 +69124,8 @@ var ClaudeProcessPump = class {
|
|
|
68688
69124
|
}
|
|
68689
69125
|
}
|
|
68690
69126
|
async handleTurnEnd(parsed) {
|
|
69127
|
+
for (const sample of this.usage.samples(parsed.usage))
|
|
69128
|
+
this.opts.activity.emitUsage(sample);
|
|
68691
69129
|
const live = this.liveDeliveries();
|
|
68692
69130
|
const owner = this.ownerFor(false);
|
|
68693
69131
|
if (parsed.numTurns !== 0 && owner)
|
|
@@ -68772,7 +69210,7 @@ function ownsFrames(delivery) {
|
|
|
68772
69210
|
// ts/claude-agent/dist/session-manager.js
|
|
68773
69211
|
import * as fs9 from "node:fs";
|
|
68774
69212
|
import * as path12 from "node:path";
|
|
68775
|
-
import { randomUUID as
|
|
69213
|
+
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
68776
69214
|
var ClaudeSessionManager = class _ClaudeSessionManager {
|
|
68777
69215
|
mainSessionKey;
|
|
68778
69216
|
stateFilePath;
|
|
@@ -68814,7 +69252,7 @@ var ClaudeSessionManager = class _ClaudeSessionManager {
|
|
|
68814
69252
|
const parentSessionId = this.sessionIds.get(parentSessionKey);
|
|
68815
69253
|
if (!parentSessionId)
|
|
68816
69254
|
return null;
|
|
68817
|
-
const sessionKey = `${_ClaudeSessionManager.FORK_LANE_PREFIX}${
|
|
69255
|
+
const sessionKey = `${_ClaudeSessionManager.FORK_LANE_PREFIX}${randomUUID10()}`;
|
|
68818
69256
|
this.pendingForkParents.set(sessionKey, parentSessionId);
|
|
68819
69257
|
return {
|
|
68820
69258
|
sessionKey,
|
|
@@ -69067,14 +69505,13 @@ var ClaudeCodeAdapter = class {
|
|
|
69067
69505
|
terminateHandle: (handle) => this.terminateHandle(handle)
|
|
69068
69506
|
});
|
|
69069
69507
|
shuttingDown = false;
|
|
69070
|
-
activity;
|
|
69508
|
+
activity = new RuntimeActivityPort("ClaudeCodeAdapter");
|
|
69071
69509
|
_model;
|
|
69072
69510
|
_effortLevel;
|
|
69073
69511
|
_contextWindow;
|
|
69074
69512
|
_maxTokens;
|
|
69075
69513
|
constructor(opts) {
|
|
69076
69514
|
this.opts = opts;
|
|
69077
|
-
this.activity = new RuntimeActivityPort("ClaudeCodeAdapter");
|
|
69078
69515
|
this._model = opts.model;
|
|
69079
69516
|
this._contextWindow = opts.contextWindow;
|
|
69080
69517
|
this._maxTokens = opts.maxTokens;
|
|
@@ -69117,6 +69554,9 @@ var ClaudeCodeAdapter = class {
|
|
|
69117
69554
|
subscribeRuntimeActivity(handler) {
|
|
69118
69555
|
return this.activity.subscribe(handler);
|
|
69119
69556
|
}
|
|
69557
|
+
subscribeUsage(handler) {
|
|
69558
|
+
return this.activity.subscribeUsage(handler);
|
|
69559
|
+
}
|
|
69120
69560
|
busyState(now = this.now()) {
|
|
69121
69561
|
const states = [];
|
|
69122
69562
|
for (const state of this.processes.values()) {
|
|
@@ -69276,9 +69716,6 @@ var ClaudeCodeAdapter = class {
|
|
|
69276
69716
|
releasePreparedAttachments();
|
|
69277
69717
|
}
|
|
69278
69718
|
}
|
|
69279
|
-
getBranchPoint(_sessionKey) {
|
|
69280
|
-
return void 0;
|
|
69281
|
-
}
|
|
69282
69719
|
getSessionHistoryPath(sessionKey) {
|
|
69283
69720
|
const sessionId = this.opts.sessionManager.getSessionId(sessionKey);
|
|
69284
69721
|
if (!sessionId)
|
|
@@ -69372,7 +69809,7 @@ var ClaudeCodeAdapter = class {
|
|
|
69372
69809
|
async *consumeDelivery(sessionKey, state, target, noteActivity) {
|
|
69373
69810
|
if (target.terminal)
|
|
69374
69811
|
return;
|
|
69375
|
-
const groupKey =
|
|
69812
|
+
const groupKey = randomUUID11();
|
|
69376
69813
|
state.pump.setActiveDrain(target, noteActivity);
|
|
69377
69814
|
try {
|
|
69378
69815
|
while (true) {
|
|
@@ -69861,6 +70298,8 @@ async function main() {
|
|
|
69861
70298
|
claude_home: config.claudeHome
|
|
69862
70299
|
},
|
|
69863
70300
|
dispatchAdapter: adapter,
|
|
70301
|
+
// After resolveProviderEnv: the CLI's own-login usage, not Parall's metered models.
|
|
70302
|
+
reportRuntimeUsage: reportsRuntimeUsage(),
|
|
69864
70303
|
log: agentLog,
|
|
69865
70304
|
// Live capability view for hint routing: the channel reply hint points
|
|
69866
70305
|
// at the vendor CLI only while the grant is active (config manager
|