@autohq/cli 0.1.610 → 0.1.612
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-bridge.js +277 -14
- package/dist/index.js +280 -16
- package/package.json +1 -1
package/dist/agent-bridge.js
CHANGED
|
@@ -37751,7 +37751,7 @@ Object.assign(lookup, {
|
|
|
37751
37751
|
// package.json
|
|
37752
37752
|
var package_default = {
|
|
37753
37753
|
name: "@autohq/cli",
|
|
37754
|
-
version: "0.1.
|
|
37754
|
+
version: "0.1.612",
|
|
37755
37755
|
license: "SEE LICENSE IN README.md",
|
|
37756
37756
|
publishConfig: {
|
|
37757
37757
|
access: "public"
|
|
@@ -42344,10 +42344,12 @@ function isSetupCacheTtl(value2) {
|
|
|
42344
42344
|
var HOSTED_RUNTIME_STATUSES = [
|
|
42345
42345
|
"queued",
|
|
42346
42346
|
"provisioning",
|
|
42347
|
+
"ready",
|
|
42347
42348
|
"running",
|
|
42348
42349
|
"closing",
|
|
42349
42350
|
"closed"
|
|
42350
42351
|
];
|
|
42352
|
+
var HOSTED_RUNTIME_EXECUTION_MODES = ["one_shot", "retained"];
|
|
42351
42353
|
var HOSTED_RUNTIME_OUTCOMES = [
|
|
42352
42354
|
"succeeded",
|
|
42353
42355
|
"failed",
|
|
@@ -42365,9 +42367,13 @@ var HOSTED_RUNTIME_CLOSE_REASONS = [
|
|
|
42365
42367
|
"command_failed",
|
|
42366
42368
|
"provision_failed",
|
|
42367
42369
|
"requested",
|
|
42370
|
+
"idle_timeout",
|
|
42371
|
+
"hard_ttl_expired",
|
|
42368
42372
|
"internal_error"
|
|
42369
42373
|
];
|
|
42370
42374
|
var HOSTED_RUNTIME_MAX_COMMAND_BUDGET_SECONDS = 45 * 60;
|
|
42375
|
+
var HOSTED_RUNTIME_RETAINED_IDLE_TIMEOUT_SECONDS = 15 * 60;
|
|
42376
|
+
var HOSTED_RUNTIME_RETAINED_HARD_TTL_SECONDS = 60 * 60;
|
|
42371
42377
|
var HostedRuntimeEnvironmentInputSchema = external_exports.discriminatedUnion(
|
|
42372
42378
|
"kind",
|
|
42373
42379
|
[
|
|
@@ -42402,7 +42408,7 @@ var HostedRuntimeCommandInputSchema = external_exports.object({
|
|
|
42402
42408
|
timeoutSeconds: external_exports.number().int().min(1).max(300).default(60)
|
|
42403
42409
|
}).strict();
|
|
42404
42410
|
var HostedRuntimeIdempotencyKeySchema = external_exports.string().trim().min(1).max(200);
|
|
42405
|
-
var
|
|
42411
|
+
var HostedRuntimeOneShotRequestSchema = external_exports.object({
|
|
42406
42412
|
environment: HostedRuntimeEnvironmentInputSchema,
|
|
42407
42413
|
commands: external_exports.array(HostedRuntimeCommandInputSchema).min(1).max(20)
|
|
42408
42414
|
}).strict().superRefine((request, context) => {
|
|
@@ -42418,7 +42424,18 @@ var CreateHostedRuntimeRequestSchema = external_exports.object({
|
|
|
42418
42424
|
});
|
|
42419
42425
|
}
|
|
42420
42426
|
});
|
|
42427
|
+
var HostedRuntimeRetainedRequestSchema = external_exports.object({
|
|
42428
|
+
mode: external_exports.literal("retained"),
|
|
42429
|
+
environment: HostedRuntimeEnvironmentInputSchema
|
|
42430
|
+
}).strict();
|
|
42431
|
+
var CreateHostedRuntimeRequestSchema = external_exports.union([
|
|
42432
|
+
HostedRuntimeRetainedRequestSchema,
|
|
42433
|
+
HostedRuntimeOneShotRequestSchema
|
|
42434
|
+
]);
|
|
42421
42435
|
var HostedRuntimeStatusSchema = external_exports.enum(HOSTED_RUNTIME_STATUSES);
|
|
42436
|
+
var HostedRuntimeExecutionModeSchema = external_exports.enum(
|
|
42437
|
+
HOSTED_RUNTIME_EXECUTION_MODES
|
|
42438
|
+
);
|
|
42422
42439
|
var HostedRuntimeOutcomeSchema = external_exports.enum(HOSTED_RUNTIME_OUTCOMES);
|
|
42423
42440
|
var HostedRuntimeCommandStatusSchema = external_exports.enum(
|
|
42424
42441
|
HOSTED_RUNTIME_COMMAND_STATUSES
|
|
@@ -42441,6 +42458,7 @@ var HostedRuntimeCommandRecordSchema = external_exports.object({
|
|
|
42441
42458
|
}).strict();
|
|
42442
42459
|
var HostedRuntimeRecordSchema = external_exports.object({
|
|
42443
42460
|
id: RuntimeIdSchema2,
|
|
42461
|
+
mode: external_exports.literal("retained").optional(),
|
|
42444
42462
|
status: HostedRuntimeStatusSchema,
|
|
42445
42463
|
outcome: HostedRuntimeOutcomeSchema.nullable(),
|
|
42446
42464
|
environment: HostedRuntimeEnvironmentSourceSchema,
|
|
@@ -42448,6 +42466,9 @@ var HostedRuntimeRecordSchema = external_exports.object({
|
|
|
42448
42466
|
error: external_exports.string().nullable(),
|
|
42449
42467
|
closeReason: HostedRuntimeCloseReasonSchema.nullable(),
|
|
42450
42468
|
closeRequestedAt: external_exports.string().datetime().nullable(),
|
|
42469
|
+
idleTimeoutAt: external_exports.string().datetime().optional(),
|
|
42470
|
+
hardTtlAt: external_exports.string().datetime().optional(),
|
|
42471
|
+
lastActivityAt: external_exports.string().datetime().nullable().optional(),
|
|
42451
42472
|
startedAt: external_exports.string().datetime().nullable(),
|
|
42452
42473
|
finishedAt: external_exports.string().datetime().nullable(),
|
|
42453
42474
|
createdAt: external_exports.string().datetime(),
|
|
@@ -42457,12 +42478,20 @@ var HostedRuntimeDispatchStatusSchema = external_exports.enum([
|
|
|
42457
42478
|
"started",
|
|
42458
42479
|
"deferred"
|
|
42459
42480
|
]);
|
|
42481
|
+
var HostedRuntimeCommandReceiptSchema = external_exports.object({
|
|
42482
|
+
runtimeId: RuntimeIdSchema2,
|
|
42483
|
+
command: HostedRuntimeCommandRecordSchema,
|
|
42484
|
+
workflowId: external_exports.string().trim().min(1),
|
|
42485
|
+
dispatchStatus: HostedRuntimeDispatchStatusSchema,
|
|
42486
|
+
replayed: external_exports.boolean()
|
|
42487
|
+
}).strict();
|
|
42460
42488
|
var HostedRuntimeReceiptSchema = external_exports.object({
|
|
42461
42489
|
runtime: HostedRuntimeRecordSchema,
|
|
42462
42490
|
workflowId: external_exports.string().trim().min(1),
|
|
42463
42491
|
dispatchStatus: HostedRuntimeDispatchStatusSchema
|
|
42464
42492
|
}).strict();
|
|
42465
42493
|
var HostedRuntimeWorkflowInputSchema = external_exports.object({ runtimeId: RuntimeIdSchema2 }).strip();
|
|
42494
|
+
var HostedRuntimeRetainedSignalSchema = external_exports.object({ runtimeId: RuntimeIdSchema2 }).strip();
|
|
42466
42495
|
|
|
42467
42496
|
// ../../packages/schemas/src/session-bindings.ts
|
|
42468
42497
|
var BINDING_TARGET_TYPES = [
|
|
@@ -45757,8 +45786,16 @@ var ProjectDashboardSpecSchema = external_exports.object({
|
|
|
45757
45786
|
}).strict().optional(),
|
|
45758
45787
|
views: external_exports.array(DashboardViewSpecSchema).max(12).optional()
|
|
45759
45788
|
}).strict();
|
|
45789
|
+
var ManualRuntimeDefaultsSchema = external_exports.object({
|
|
45790
|
+
idleTimeoutSeconds: external_exports.number().int().min(60).max(60 * 60).default(HOSTED_RUNTIME_RETAINED_IDLE_TIMEOUT_SECONDS),
|
|
45791
|
+
hardTtlSeconds: external_exports.number().int().min(60).max(24 * 60 * 60).default(HOSTED_RUNTIME_RETAINED_HARD_TTL_SECONDS)
|
|
45792
|
+
}).strict().refine((value2) => value2.idleTimeoutSeconds <= value2.hardTtlSeconds, {
|
|
45793
|
+
message: "Manual runtime idle timeout must not exceed its hard TTL",
|
|
45794
|
+
path: ["idleTimeoutSeconds"]
|
|
45795
|
+
});
|
|
45760
45796
|
var ProjectConfigSpecSchema = external_exports.object({
|
|
45761
|
-
dashboard: ProjectDashboardSpecSchema.optional()
|
|
45797
|
+
dashboard: ProjectDashboardSpecSchema.optional(),
|
|
45798
|
+
manualRuntimes: ManualRuntimeDefaultsSchema.optional()
|
|
45762
45799
|
}).strict();
|
|
45763
45800
|
var ProjectConfigResourceSchema = resourceEnvelopeSchema(
|
|
45764
45801
|
ProjectConfigSpecSchema
|
|
@@ -83353,9 +83390,170 @@ var defaultDownload2 = createDownload();
|
|
|
83353
83390
|
|
|
83354
83391
|
// src/commands/agent-bridge/harness/envelope-bounds.ts
|
|
83355
83392
|
import { Buffer as Buffer2 } from "buffer";
|
|
83393
|
+
|
|
83394
|
+
// src/commands/agent-bridge/harness/mcp-result-canonicalization.ts
|
|
83395
|
+
function canonicalizeEnvelopeMcpResults(envelope) {
|
|
83396
|
+
switch (envelope.type) {
|
|
83397
|
+
case "conversation.entry": {
|
|
83398
|
+
const content = canonicalizeMcpResultValue(envelope.content);
|
|
83399
|
+
return toCanonicalizedEnvelope(
|
|
83400
|
+
envelope,
|
|
83401
|
+
{ ...envelope, content: content.value },
|
|
83402
|
+
content.deduplicatedBranches
|
|
83403
|
+
);
|
|
83404
|
+
}
|
|
83405
|
+
case "conversation.delta": {
|
|
83406
|
+
const delta = canonicalizeMcpResultValue(envelope.delta);
|
|
83407
|
+
return toCanonicalizedEnvelope(
|
|
83408
|
+
envelope,
|
|
83409
|
+
{ ...envelope, delta: delta.value },
|
|
83410
|
+
delta.deduplicatedBranches
|
|
83411
|
+
);
|
|
83412
|
+
}
|
|
83413
|
+
case "ui.message.chunk": {
|
|
83414
|
+
const chunk = canonicalizeMcpResultValue(envelope.chunk);
|
|
83415
|
+
return toCanonicalizedEnvelope(
|
|
83416
|
+
envelope,
|
|
83417
|
+
{ ...envelope, chunk: chunk.value },
|
|
83418
|
+
chunk.deduplicatedBranches
|
|
83419
|
+
);
|
|
83420
|
+
}
|
|
83421
|
+
case "ui.message.part": {
|
|
83422
|
+
const part = canonicalizeMcpResultValue(envelope.part);
|
|
83423
|
+
const metadata = canonicalizeMcpResultValue(envelope.messageMetadata);
|
|
83424
|
+
const deduplicatedBranches = part.deduplicatedBranches + metadata.deduplicatedBranches;
|
|
83425
|
+
return toCanonicalizedEnvelope(
|
|
83426
|
+
envelope,
|
|
83427
|
+
{
|
|
83428
|
+
...envelope,
|
|
83429
|
+
part: part.value,
|
|
83430
|
+
...envelope.messageMetadata === void 0 ? {} : { messageMetadata: metadata.value }
|
|
83431
|
+
},
|
|
83432
|
+
deduplicatedBranches
|
|
83433
|
+
);
|
|
83434
|
+
}
|
|
83435
|
+
case "ui.message.completed": {
|
|
83436
|
+
const message = canonicalizeMcpResultValue(envelope.message);
|
|
83437
|
+
return toCanonicalizedEnvelope(
|
|
83438
|
+
envelope,
|
|
83439
|
+
{ ...envelope, message: message.value },
|
|
83440
|
+
message.deduplicatedBranches
|
|
83441
|
+
);
|
|
83442
|
+
}
|
|
83443
|
+
case "runtime.liveness":
|
|
83444
|
+
case "runtime.usage_turn":
|
|
83445
|
+
return { value: envelope, deduplicatedBranches: 0 };
|
|
83446
|
+
}
|
|
83447
|
+
}
|
|
83448
|
+
function toCanonicalizedEnvelope(original, candidate, deduplicatedBranches) {
|
|
83449
|
+
return {
|
|
83450
|
+
value: deduplicatedBranches > 0 ? RuntimeBridgeOutputEnvelopeSchema.parse(candidate) : original,
|
|
83451
|
+
deduplicatedBranches
|
|
83452
|
+
};
|
|
83453
|
+
}
|
|
83454
|
+
function canonicalizeMcpResultValue(value2) {
|
|
83455
|
+
if (Array.isArray(value2)) {
|
|
83456
|
+
let deduplicatedBranches2 = 0;
|
|
83457
|
+
let changed2 = false;
|
|
83458
|
+
const items = value2.map((item) => {
|
|
83459
|
+
const canonical2 = canonicalizeMcpResultValue(item);
|
|
83460
|
+
deduplicatedBranches2 += canonical2.deduplicatedBranches;
|
|
83461
|
+
changed2 ||= canonical2.value !== item;
|
|
83462
|
+
return canonical2.value;
|
|
83463
|
+
});
|
|
83464
|
+
return {
|
|
83465
|
+
value: changed2 ? items : value2,
|
|
83466
|
+
deduplicatedBranches: deduplicatedBranches2
|
|
83467
|
+
};
|
|
83468
|
+
}
|
|
83469
|
+
if (typeof value2 !== "object" || value2 === null) {
|
|
83470
|
+
return { value: value2, deduplicatedBranches: 0 };
|
|
83471
|
+
}
|
|
83472
|
+
const record2 = value2;
|
|
83473
|
+
const duplicateContentIndexes = equivalentMcpTextContentIndexes(record2);
|
|
83474
|
+
let deduplicatedBranches = duplicateContentIndexes.size;
|
|
83475
|
+
let changed = duplicateContentIndexes.size > 0;
|
|
83476
|
+
const canonical = /* @__PURE__ */ Object.create(null);
|
|
83477
|
+
for (const [key, item] of Object.entries(record2)) {
|
|
83478
|
+
if (key === "content" && Array.isArray(item)) {
|
|
83479
|
+
const retainedContent = duplicateContentIndexes.size > 0 ? item.filter(
|
|
83480
|
+
(_contentItem, index) => !duplicateContentIndexes.has(index)
|
|
83481
|
+
) : item;
|
|
83482
|
+
if (retainedContent.length === 0 && duplicateContentIndexes.size > 0) {
|
|
83483
|
+
continue;
|
|
83484
|
+
}
|
|
83485
|
+
const content = canonicalizeMcpResultValue(retainedContent);
|
|
83486
|
+
canonical[key] = content.value;
|
|
83487
|
+
deduplicatedBranches += content.deduplicatedBranches;
|
|
83488
|
+
changed ||= content.value !== item;
|
|
83489
|
+
continue;
|
|
83490
|
+
}
|
|
83491
|
+
const child = canonicalizeMcpResultValue(item);
|
|
83492
|
+
canonical[key] = child.value;
|
|
83493
|
+
deduplicatedBranches += child.deduplicatedBranches;
|
|
83494
|
+
changed ||= child.value !== item;
|
|
83495
|
+
}
|
|
83496
|
+
return {
|
|
83497
|
+
value: changed ? canonical : value2,
|
|
83498
|
+
deduplicatedBranches
|
|
83499
|
+
};
|
|
83500
|
+
}
|
|
83501
|
+
function equivalentMcpTextContentIndexes(value2) {
|
|
83502
|
+
if (!Array.isArray(value2.content) || !Object.hasOwn(value2, "structuredContent") || value2.structuredContent === void 0) {
|
|
83503
|
+
return /* @__PURE__ */ new Set();
|
|
83504
|
+
}
|
|
83505
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
83506
|
+
for (const [index, item] of value2.content.entries()) {
|
|
83507
|
+
if (!isPlainMcpTextBlock(item)) {
|
|
83508
|
+
continue;
|
|
83509
|
+
}
|
|
83510
|
+
const parsed = parseJson(item.text);
|
|
83511
|
+
if (parsed.parsed && jsonValuesEqual(parsed.value, value2.structuredContent)) {
|
|
83512
|
+
indexes.add(index);
|
|
83513
|
+
}
|
|
83514
|
+
}
|
|
83515
|
+
return indexes;
|
|
83516
|
+
}
|
|
83517
|
+
function isPlainMcpTextBlock(value2) {
|
|
83518
|
+
if (typeof value2 !== "object" || value2 === null || Array.isArray(value2)) {
|
|
83519
|
+
return false;
|
|
83520
|
+
}
|
|
83521
|
+
const record2 = value2;
|
|
83522
|
+
const keys = Object.keys(record2);
|
|
83523
|
+
return keys.length === 2 && record2.type === "text" && typeof record2.text === "string";
|
|
83524
|
+
}
|
|
83525
|
+
function parseJson(value2) {
|
|
83526
|
+
try {
|
|
83527
|
+
return { parsed: true, value: JSON.parse(value2) };
|
|
83528
|
+
} catch {
|
|
83529
|
+
return { parsed: false, value: null };
|
|
83530
|
+
}
|
|
83531
|
+
}
|
|
83532
|
+
function jsonValuesEqual(left, right) {
|
|
83533
|
+
if (Object.is(left, right)) {
|
|
83534
|
+
return true;
|
|
83535
|
+
}
|
|
83536
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
83537
|
+
if (!Array.isArray(left) || !Array.isArray(right)) {
|
|
83538
|
+
return false;
|
|
83539
|
+
}
|
|
83540
|
+
return left.length === right.length && left.every((item, index) => jsonValuesEqual(item, right[index]));
|
|
83541
|
+
}
|
|
83542
|
+
if (typeof left !== "object" || left === null || typeof right !== "object" || right === null) {
|
|
83543
|
+
return false;
|
|
83544
|
+
}
|
|
83545
|
+
const leftRecord = left;
|
|
83546
|
+
const rightRecord = right;
|
|
83547
|
+
const leftKeys = Object.keys(leftRecord);
|
|
83548
|
+
const rightKeys = Object.keys(rightRecord);
|
|
83549
|
+
return leftKeys.length === rightKeys.length && leftKeys.every(
|
|
83550
|
+
(key) => Object.hasOwn(rightRecord, key) && jsonValuesEqual(leftRecord[key], rightRecord[key])
|
|
83551
|
+
);
|
|
83552
|
+
}
|
|
83553
|
+
|
|
83554
|
+
// src/commands/agent-bridge/harness/envelope-bounds.ts
|
|
83356
83555
|
var AGENT_BRIDGE_OUTPUT_MAX_ENVELOPE_BYTES = 512 * 1024;
|
|
83357
83556
|
var AGENT_BRIDGE_OUTPUT_QUARANTINE_MAX_ENVELOPE_BYTES = 8 * 1024;
|
|
83358
|
-
var MAX_TARGETED_PAYLOAD_NOTICES = 4;
|
|
83359
83557
|
var PAYLOAD_FIELD_RULES = {
|
|
83360
83558
|
output: { label: "tool output", priority: 0 },
|
|
83361
83559
|
errorText: { label: "tool error", priority: 0 },
|
|
@@ -83390,48 +83588,97 @@ var STRUCTURAL_STRING_FIELDS = /* @__PURE__ */ new Set([
|
|
|
83390
83588
|
"completedAt"
|
|
83391
83589
|
]);
|
|
83392
83590
|
function boundOutputEnvelope(envelope, maxBytes = AGENT_BRIDGE_OUTPUT_MAX_ENVELOPE_BYTES) {
|
|
83393
|
-
const
|
|
83591
|
+
const original = envelopeSerializationInfo(envelope);
|
|
83592
|
+
const originalBytes = original.bytes;
|
|
83394
83593
|
if (originalBytes <= maxBytes) {
|
|
83395
|
-
return {
|
|
83594
|
+
return {
|
|
83595
|
+
envelope,
|
|
83596
|
+
originalBytes,
|
|
83597
|
+
boundedBytes: originalBytes,
|
|
83598
|
+
kind: "none",
|
|
83599
|
+
deduplicatedMcpResultBranches: 0,
|
|
83600
|
+
truncated: false
|
|
83601
|
+
};
|
|
83396
83602
|
}
|
|
83397
|
-
const
|
|
83603
|
+
const canonicalized = original.hasStructuredContent ? canonicalizeEnvelopeMcpResults(envelope) : { value: envelope, deduplicatedBranches: 0 };
|
|
83604
|
+
const canonicalEnvelope = canonicalized.value;
|
|
83605
|
+
const canonicalBytes = serializedByteLength(canonicalEnvelope);
|
|
83606
|
+
if (canonicalBytes <= maxBytes) {
|
|
83607
|
+
return {
|
|
83608
|
+
envelope: canonicalEnvelope,
|
|
83609
|
+
originalBytes,
|
|
83610
|
+
boundedBytes: canonicalBytes,
|
|
83611
|
+
kind: "mcp-result-deduplicated",
|
|
83612
|
+
deduplicatedMcpResultBranches: canonicalized.deduplicatedBranches,
|
|
83613
|
+
truncated: true
|
|
83614
|
+
};
|
|
83615
|
+
}
|
|
83616
|
+
const targeted = truncatePayloads(canonicalEnvelope, maxBytes);
|
|
83398
83617
|
if (targeted) {
|
|
83618
|
+
const boundedEnvelope = RuntimeBridgeOutputEnvelopeSchema.parse(targeted);
|
|
83399
83619
|
return {
|
|
83400
|
-
envelope:
|
|
83620
|
+
envelope: boundedEnvelope,
|
|
83401
83621
|
originalBytes,
|
|
83622
|
+
boundedBytes: serializedByteLength(boundedEnvelope),
|
|
83623
|
+
kind: canonicalized.deduplicatedBranches > 0 ? "mcp-result-deduplicated+targeted-truncation" : "targeted-truncation",
|
|
83624
|
+
deduplicatedMcpResultBranches: canonicalized.deduplicatedBranches,
|
|
83402
83625
|
truncated: true
|
|
83403
83626
|
};
|
|
83404
83627
|
}
|
|
83628
|
+
const fallbackEnvelope = RuntimeBridgeOutputEnvelopeSchema.parse(
|
|
83629
|
+
replacePayloadWithMarker(canonicalEnvelope)
|
|
83630
|
+
);
|
|
83405
83631
|
return {
|
|
83406
|
-
envelope:
|
|
83407
|
-
replacePayloadWithMarker(envelope)
|
|
83408
|
-
),
|
|
83632
|
+
envelope: fallbackEnvelope,
|
|
83409
83633
|
originalBytes,
|
|
83634
|
+
boundedBytes: serializedByteLength(fallbackEnvelope),
|
|
83635
|
+
kind: canonicalized.deduplicatedBranches > 0 ? "mcp-result-deduplicated+payload-fallback" : "payload-fallback",
|
|
83636
|
+
deduplicatedMcpResultBranches: canonicalized.deduplicatedBranches,
|
|
83410
83637
|
truncated: true
|
|
83411
83638
|
};
|
|
83412
83639
|
}
|
|
83413
83640
|
function truncatePayloads(envelope, maxBytes) {
|
|
83414
83641
|
const candidateEnvelope = structuredClone(envelope);
|
|
83415
83642
|
const candidates = collectPayloadCandidates(envelope);
|
|
83416
|
-
|
|
83643
|
+
const truncatedCandidates = [];
|
|
83644
|
+
while (true) {
|
|
83417
83645
|
const currentBytes = serializedByteLength(candidateEnvelope);
|
|
83418
83646
|
if (currentBytes <= maxBytes) {
|
|
83419
83647
|
return candidateEnvelope;
|
|
83420
83648
|
}
|
|
83421
83649
|
const candidate = takePayloadCandidate(candidates, currentBytes - maxBytes);
|
|
83422
83650
|
if (!candidate) {
|
|
83423
|
-
|
|
83651
|
+
break;
|
|
83424
83652
|
}
|
|
83425
83653
|
setValueAtPath(
|
|
83426
83654
|
candidateEnvelope,
|
|
83427
83655
|
candidate.path,
|
|
83428
83656
|
truncationNotice(candidate, "")
|
|
83429
83657
|
);
|
|
83430
|
-
|
|
83658
|
+
const truncatedBytes = serializedByteLength(candidateEnvelope);
|
|
83659
|
+
if (truncatedBytes >= currentBytes) {
|
|
83660
|
+
setValueAtPath(candidateEnvelope, candidate.path, candidate.value);
|
|
83661
|
+
continue;
|
|
83662
|
+
}
|
|
83663
|
+
truncatedCandidates.push(candidate);
|
|
83664
|
+
if (truncatedBytes <= maxBytes) {
|
|
83431
83665
|
maximizePreview(candidateEnvelope, candidate, maxBytes);
|
|
83432
83666
|
return candidateEnvelope;
|
|
83433
83667
|
}
|
|
83434
83668
|
}
|
|
83669
|
+
for (const candidate of truncatedCandidates) {
|
|
83670
|
+
setValueAtPath(
|
|
83671
|
+
candidateEnvelope,
|
|
83672
|
+
candidate.path,
|
|
83673
|
+
compactTruncationNotice(candidate)
|
|
83674
|
+
);
|
|
83675
|
+
}
|
|
83676
|
+
if (serializedByteLength(candidateEnvelope) <= maxBytes) {
|
|
83677
|
+
return candidateEnvelope;
|
|
83678
|
+
}
|
|
83679
|
+
for (const candidate of truncatedCandidates) {
|
|
83680
|
+
setValueAtPath(candidateEnvelope, candidate.path, "");
|
|
83681
|
+
}
|
|
83435
83682
|
return serializedByteLength(candidateEnvelope) <= maxBytes ? candidateEnvelope : null;
|
|
83436
83683
|
}
|
|
83437
83684
|
function collectPayloadCandidates(envelope) {
|
|
@@ -83596,10 +83843,20 @@ function truncationNotice(candidate, preview) {
|
|
|
83596
83843
|
const separator = preview.length > 0 ? "\n" : "";
|
|
83597
83844
|
return `${preview}${separator}[agent-bridge ${candidate.label} truncated: original ${candidate.originalBytes} UTF-8 bytes; kept ${keptBytes}; omitted ${omittedBytes}. Omitted content was not persisted in this transcript.]`;
|
|
83598
83845
|
}
|
|
83846
|
+
function compactTruncationNotice(candidate) {
|
|
83847
|
+
return `[agent-bridge ${candidate.label} truncated: original ${candidate.originalBytes} UTF-8 bytes.]`;
|
|
83848
|
+
}
|
|
83599
83849
|
function serializedByteLength(value2) {
|
|
83600
83850
|
const serialized = JSON.stringify(value2);
|
|
83601
83851
|
return serialized === void 0 ? 0 : Buffer2.byteLength(serialized, "utf8");
|
|
83602
83852
|
}
|
|
83853
|
+
function envelopeSerializationInfo(envelope) {
|
|
83854
|
+
const serialized = JSON.stringify(envelope);
|
|
83855
|
+
return {
|
|
83856
|
+
bytes: Buffer2.byteLength(serialized, "utf8"),
|
|
83857
|
+
hasStructuredContent: serialized.includes('"structuredContent":')
|
|
83858
|
+
};
|
|
83859
|
+
}
|
|
83603
83860
|
function replacePayloadWithMarker(envelope) {
|
|
83604
83861
|
switch (envelope.type) {
|
|
83605
83862
|
case "conversation.entry": {
|
|
@@ -84560,6 +84817,9 @@ var AgentBridgeOutputBuffer = class {
|
|
|
84560
84817
|
"agent_bridge_output_envelope_truncated",
|
|
84561
84818
|
this.outputLogContext(bounded.envelope, {
|
|
84562
84819
|
original_bytes: bounded.originalBytes,
|
|
84820
|
+
bounded_bytes: bounded.boundedBytes,
|
|
84821
|
+
bound_kind: bounded.kind,
|
|
84822
|
+
deduplicated_mcp_result_branches: bounded.deduplicatedMcpResultBranches,
|
|
84563
84823
|
pending_count: this.pendingOutputs.size
|
|
84564
84824
|
})
|
|
84565
84825
|
);
|
|
@@ -84593,6 +84853,9 @@ var AgentBridgeOutputBuffer = class {
|
|
|
84593
84853
|
this.outputLogContext(bounded.envelope, {
|
|
84594
84854
|
exhausts,
|
|
84595
84855
|
original_bytes: bounded.originalBytes,
|
|
84856
|
+
bounded_bytes: bounded.boundedBytes,
|
|
84857
|
+
bound_kind: bounded.kind,
|
|
84858
|
+
deduplicated_mcp_result_branches: bounded.deduplicatedMcpResultBranches,
|
|
84596
84859
|
truncated: bounded.truncated,
|
|
84597
84860
|
pending_count: this.pendingOutputs.size
|
|
84598
84861
|
})
|
package/dist/index.js
CHANGED
|
@@ -19096,7 +19096,7 @@ var init_environments = __esm({
|
|
|
19096
19096
|
});
|
|
19097
19097
|
|
|
19098
19098
|
// ../../packages/schemas/src/hosted-runtimes.ts
|
|
19099
|
-
var HOSTED_RUNTIME_STATUSES, HOSTED_RUNTIME_OUTCOMES, HOSTED_RUNTIME_COMMAND_STATUSES, HOSTED_RUNTIME_CLOSE_REASONS, HOSTED_RUNTIME_MAX_COMMAND_BUDGET_SECONDS, HostedRuntimeEnvironmentInputSchema, HostedRuntimeEnvironmentSourceSchema, HostedRuntimeEnvironmentSnapshotSchema, HostedRuntimeCommandInputSchema, HostedRuntimeIdempotencyKeySchema, CreateHostedRuntimeRequestSchema, HostedRuntimeStatusSchema, HostedRuntimeOutcomeSchema, HostedRuntimeCommandStatusSchema, HostedRuntimeCloseReasonSchema, HostedRuntimeCommandRecordSchema, HostedRuntimeRecordSchema, HostedRuntimeDispatchStatusSchema, HostedRuntimeReceiptSchema, HostedRuntimeWorkflowInputSchema;
|
|
19099
|
+
var HOSTED_RUNTIME_STATUSES, HOSTED_RUNTIME_EXECUTION_MODES, HOSTED_RUNTIME_OUTCOMES, HOSTED_RUNTIME_COMMAND_STATUSES, HOSTED_RUNTIME_CLOSE_REASONS, HOSTED_RUNTIME_MAX_COMMAND_BUDGET_SECONDS, HOSTED_RUNTIME_RETAINED_IDLE_TIMEOUT_SECONDS, HOSTED_RUNTIME_RETAINED_HARD_TTL_SECONDS, HostedRuntimeEnvironmentInputSchema, HostedRuntimeEnvironmentSourceSchema, HostedRuntimeEnvironmentSnapshotSchema, HostedRuntimeCommandInputSchema, HostedRuntimeIdempotencyKeySchema, HostedRuntimeOneShotRequestSchema, HostedRuntimeRetainedRequestSchema, CreateHostedRuntimeRequestSchema, HostedRuntimeStatusSchema, HostedRuntimeExecutionModeSchema, HostedRuntimeOutcomeSchema, HostedRuntimeCommandStatusSchema, HostedRuntimeCloseReasonSchema, HostedRuntimeCommandRecordSchema, HostedRuntimeRecordSchema, HostedRuntimeDispatchStatusSchema, HostedRuntimeCommandReceiptSchema, HostedRuntimeReceiptSchema, HostedRuntimeWorkflowInputSchema, HostedRuntimeRetainedSignalSchema;
|
|
19100
19100
|
var init_hosted_runtimes = __esm({
|
|
19101
19101
|
"../../packages/schemas/src/hosted-runtimes.ts"() {
|
|
19102
19102
|
"use strict";
|
|
@@ -19107,10 +19107,12 @@ var init_hosted_runtimes = __esm({
|
|
|
19107
19107
|
HOSTED_RUNTIME_STATUSES = [
|
|
19108
19108
|
"queued",
|
|
19109
19109
|
"provisioning",
|
|
19110
|
+
"ready",
|
|
19110
19111
|
"running",
|
|
19111
19112
|
"closing",
|
|
19112
19113
|
"closed"
|
|
19113
19114
|
];
|
|
19115
|
+
HOSTED_RUNTIME_EXECUTION_MODES = ["one_shot", "retained"];
|
|
19114
19116
|
HOSTED_RUNTIME_OUTCOMES = [
|
|
19115
19117
|
"succeeded",
|
|
19116
19118
|
"failed",
|
|
@@ -19128,9 +19130,13 @@ var init_hosted_runtimes = __esm({
|
|
|
19128
19130
|
"command_failed",
|
|
19129
19131
|
"provision_failed",
|
|
19130
19132
|
"requested",
|
|
19133
|
+
"idle_timeout",
|
|
19134
|
+
"hard_ttl_expired",
|
|
19131
19135
|
"internal_error"
|
|
19132
19136
|
];
|
|
19133
19137
|
HOSTED_RUNTIME_MAX_COMMAND_BUDGET_SECONDS = 45 * 60;
|
|
19138
|
+
HOSTED_RUNTIME_RETAINED_IDLE_TIMEOUT_SECONDS = 15 * 60;
|
|
19139
|
+
HOSTED_RUNTIME_RETAINED_HARD_TTL_SECONDS = 60 * 60;
|
|
19134
19140
|
HostedRuntimeEnvironmentInputSchema = external_exports.discriminatedUnion(
|
|
19135
19141
|
"kind",
|
|
19136
19142
|
[
|
|
@@ -19165,7 +19171,7 @@ var init_hosted_runtimes = __esm({
|
|
|
19165
19171
|
timeoutSeconds: external_exports.number().int().min(1).max(300).default(60)
|
|
19166
19172
|
}).strict();
|
|
19167
19173
|
HostedRuntimeIdempotencyKeySchema = external_exports.string().trim().min(1).max(200);
|
|
19168
|
-
|
|
19174
|
+
HostedRuntimeOneShotRequestSchema = external_exports.object({
|
|
19169
19175
|
environment: HostedRuntimeEnvironmentInputSchema,
|
|
19170
19176
|
commands: external_exports.array(HostedRuntimeCommandInputSchema).min(1).max(20)
|
|
19171
19177
|
}).strict().superRefine((request, context) => {
|
|
@@ -19181,7 +19187,18 @@ var init_hosted_runtimes = __esm({
|
|
|
19181
19187
|
});
|
|
19182
19188
|
}
|
|
19183
19189
|
});
|
|
19190
|
+
HostedRuntimeRetainedRequestSchema = external_exports.object({
|
|
19191
|
+
mode: external_exports.literal("retained"),
|
|
19192
|
+
environment: HostedRuntimeEnvironmentInputSchema
|
|
19193
|
+
}).strict();
|
|
19194
|
+
CreateHostedRuntimeRequestSchema = external_exports.union([
|
|
19195
|
+
HostedRuntimeRetainedRequestSchema,
|
|
19196
|
+
HostedRuntimeOneShotRequestSchema
|
|
19197
|
+
]);
|
|
19184
19198
|
HostedRuntimeStatusSchema = external_exports.enum(HOSTED_RUNTIME_STATUSES);
|
|
19199
|
+
HostedRuntimeExecutionModeSchema = external_exports.enum(
|
|
19200
|
+
HOSTED_RUNTIME_EXECUTION_MODES
|
|
19201
|
+
);
|
|
19185
19202
|
HostedRuntimeOutcomeSchema = external_exports.enum(HOSTED_RUNTIME_OUTCOMES);
|
|
19186
19203
|
HostedRuntimeCommandStatusSchema = external_exports.enum(
|
|
19187
19204
|
HOSTED_RUNTIME_COMMAND_STATUSES
|
|
@@ -19204,6 +19221,7 @@ var init_hosted_runtimes = __esm({
|
|
|
19204
19221
|
}).strict();
|
|
19205
19222
|
HostedRuntimeRecordSchema = external_exports.object({
|
|
19206
19223
|
id: RuntimeIdSchema,
|
|
19224
|
+
mode: external_exports.literal("retained").optional(),
|
|
19207
19225
|
status: HostedRuntimeStatusSchema,
|
|
19208
19226
|
outcome: HostedRuntimeOutcomeSchema.nullable(),
|
|
19209
19227
|
environment: HostedRuntimeEnvironmentSourceSchema,
|
|
@@ -19211,6 +19229,9 @@ var init_hosted_runtimes = __esm({
|
|
|
19211
19229
|
error: external_exports.string().nullable(),
|
|
19212
19230
|
closeReason: HostedRuntimeCloseReasonSchema.nullable(),
|
|
19213
19231
|
closeRequestedAt: external_exports.string().datetime().nullable(),
|
|
19232
|
+
idleTimeoutAt: external_exports.string().datetime().optional(),
|
|
19233
|
+
hardTtlAt: external_exports.string().datetime().optional(),
|
|
19234
|
+
lastActivityAt: external_exports.string().datetime().nullable().optional(),
|
|
19214
19235
|
startedAt: external_exports.string().datetime().nullable(),
|
|
19215
19236
|
finishedAt: external_exports.string().datetime().nullable(),
|
|
19216
19237
|
createdAt: external_exports.string().datetime(),
|
|
@@ -19220,12 +19241,20 @@ var init_hosted_runtimes = __esm({
|
|
|
19220
19241
|
"started",
|
|
19221
19242
|
"deferred"
|
|
19222
19243
|
]);
|
|
19244
|
+
HostedRuntimeCommandReceiptSchema = external_exports.object({
|
|
19245
|
+
runtimeId: RuntimeIdSchema,
|
|
19246
|
+
command: HostedRuntimeCommandRecordSchema,
|
|
19247
|
+
workflowId: external_exports.string().trim().min(1),
|
|
19248
|
+
dispatchStatus: HostedRuntimeDispatchStatusSchema,
|
|
19249
|
+
replayed: external_exports.boolean()
|
|
19250
|
+
}).strict();
|
|
19223
19251
|
HostedRuntimeReceiptSchema = external_exports.object({
|
|
19224
19252
|
runtime: HostedRuntimeRecordSchema,
|
|
19225
19253
|
workflowId: external_exports.string().trim().min(1),
|
|
19226
19254
|
dispatchStatus: HostedRuntimeDispatchStatusSchema
|
|
19227
19255
|
}).strict();
|
|
19228
19256
|
HostedRuntimeWorkflowInputSchema = external_exports.object({ runtimeId: RuntimeIdSchema }).strip();
|
|
19257
|
+
HostedRuntimeRetainedSignalSchema = external_exports.object({ runtimeId: RuntimeIdSchema }).strip();
|
|
19229
19258
|
}
|
|
19230
19259
|
});
|
|
19231
19260
|
|
|
@@ -22850,13 +22879,14 @@ var init_project_automation_pause = __esm({
|
|
|
22850
22879
|
});
|
|
22851
22880
|
|
|
22852
22881
|
// ../../packages/schemas/src/project-config.ts
|
|
22853
|
-
var RESOURCE_KIND_CONFIG, PROJECT_CONFIG_RESOURCE_NAME, PROJECT_CONFIG_FILE_NAME, DashboardTextSchema, DashboardViewKindSchema, DashboardViewSpecSchema, ProjectDashboardSpecSchema, ProjectConfigSpecSchema, ProjectConfigResourceSchema, ProjectConfigApplyRequestSchema, ProjectHomeAgentSchema, ProjectHomeSessionSchema, ProjectHomeResourceHealthSchema, ProjectHomeTaskSchema, ProjectHomeReadyViewSchema, ProjectHomeUnsupportedViewSchema, ProjectHomeInvalidViewSchema, ProjectHomeReadModelSchema, PROJECT_DEFAULT_AGENT_SOURCES, ProjectDefaultAgentSourceSchema, ProjectDefaultAgentSchema, UpdateProjectSettingsRequestSchema;
|
|
22882
|
+
var RESOURCE_KIND_CONFIG, PROJECT_CONFIG_RESOURCE_NAME, PROJECT_CONFIG_FILE_NAME, DashboardTextSchema, DashboardViewKindSchema, DashboardViewSpecSchema, ProjectDashboardSpecSchema, ManualRuntimeDefaultsSchema, ProjectConfigSpecSchema, ProjectConfigResourceSchema, ProjectConfigApplyRequestSchema, ProjectHomeAgentSchema, ProjectHomeSessionSchema, ProjectHomeResourceHealthSchema, ProjectHomeTaskSchema, ProjectHomeReadyViewSchema, ProjectHomeUnsupportedViewSchema, ProjectHomeInvalidViewSchema, ProjectHomeReadModelSchema, PROJECT_DEFAULT_AGENT_SOURCES, ProjectDefaultAgentSourceSchema, ProjectDefaultAgentSchema, UpdateProjectSettingsRequestSchema;
|
|
22854
22883
|
var init_project_config = __esm({
|
|
22855
22884
|
"../../packages/schemas/src/project-config.ts"() {
|
|
22856
22885
|
"use strict";
|
|
22857
22886
|
init_zod();
|
|
22858
22887
|
init_agents();
|
|
22859
22888
|
init_archive_policy();
|
|
22889
|
+
init_hosted_runtimes();
|
|
22860
22890
|
init_ids();
|
|
22861
22891
|
init_primitives();
|
|
22862
22892
|
init_project_automation_pause();
|
|
@@ -22882,8 +22912,16 @@ var init_project_config = __esm({
|
|
|
22882
22912
|
}).strict().optional(),
|
|
22883
22913
|
views: external_exports.array(DashboardViewSpecSchema).max(12).optional()
|
|
22884
22914
|
}).strict();
|
|
22915
|
+
ManualRuntimeDefaultsSchema = external_exports.object({
|
|
22916
|
+
idleTimeoutSeconds: external_exports.number().int().min(60).max(60 * 60).default(HOSTED_RUNTIME_RETAINED_IDLE_TIMEOUT_SECONDS),
|
|
22917
|
+
hardTtlSeconds: external_exports.number().int().min(60).max(24 * 60 * 60).default(HOSTED_RUNTIME_RETAINED_HARD_TTL_SECONDS)
|
|
22918
|
+
}).strict().refine((value) => value.idleTimeoutSeconds <= value.hardTtlSeconds, {
|
|
22919
|
+
message: "Manual runtime idle timeout must not exceed its hard TTL",
|
|
22920
|
+
path: ["idleTimeoutSeconds"]
|
|
22921
|
+
});
|
|
22885
22922
|
ProjectConfigSpecSchema = external_exports.object({
|
|
22886
|
-
dashboard: ProjectDashboardSpecSchema.optional()
|
|
22923
|
+
dashboard: ProjectDashboardSpecSchema.optional(),
|
|
22924
|
+
manualRuntimes: ManualRuntimeDefaultsSchema.optional()
|
|
22887
22925
|
}).strict();
|
|
22888
22926
|
ProjectConfigResourceSchema = resourceEnvelopeSchema(
|
|
22889
22927
|
ProjectConfigSpecSchema
|
|
@@ -93169,7 +93207,7 @@ var init_package = __esm({
|
|
|
93169
93207
|
"package.json"() {
|
|
93170
93208
|
package_default = {
|
|
93171
93209
|
name: "@autohq/cli",
|
|
93172
|
-
version: "0.1.
|
|
93210
|
+
version: "0.1.612",
|
|
93173
93211
|
license: "SEE LICENSE IN README.md",
|
|
93174
93212
|
publishConfig: {
|
|
93175
93213
|
access: "public"
|
|
@@ -106602,9 +106640,170 @@ import { readUIMessageStream } from "ai";
|
|
|
106602
106640
|
|
|
106603
106641
|
// src/commands/agent-bridge/harness/envelope-bounds.ts
|
|
106604
106642
|
import { Buffer as Buffer2 } from "buffer";
|
|
106643
|
+
|
|
106644
|
+
// src/commands/agent-bridge/harness/mcp-result-canonicalization.ts
|
|
106645
|
+
function canonicalizeEnvelopeMcpResults(envelope) {
|
|
106646
|
+
switch (envelope.type) {
|
|
106647
|
+
case "conversation.entry": {
|
|
106648
|
+
const content = canonicalizeMcpResultValue(envelope.content);
|
|
106649
|
+
return toCanonicalizedEnvelope(
|
|
106650
|
+
envelope,
|
|
106651
|
+
{ ...envelope, content: content.value },
|
|
106652
|
+
content.deduplicatedBranches
|
|
106653
|
+
);
|
|
106654
|
+
}
|
|
106655
|
+
case "conversation.delta": {
|
|
106656
|
+
const delta = canonicalizeMcpResultValue(envelope.delta);
|
|
106657
|
+
return toCanonicalizedEnvelope(
|
|
106658
|
+
envelope,
|
|
106659
|
+
{ ...envelope, delta: delta.value },
|
|
106660
|
+
delta.deduplicatedBranches
|
|
106661
|
+
);
|
|
106662
|
+
}
|
|
106663
|
+
case "ui.message.chunk": {
|
|
106664
|
+
const chunk = canonicalizeMcpResultValue(envelope.chunk);
|
|
106665
|
+
return toCanonicalizedEnvelope(
|
|
106666
|
+
envelope,
|
|
106667
|
+
{ ...envelope, chunk: chunk.value },
|
|
106668
|
+
chunk.deduplicatedBranches
|
|
106669
|
+
);
|
|
106670
|
+
}
|
|
106671
|
+
case "ui.message.part": {
|
|
106672
|
+
const part = canonicalizeMcpResultValue(envelope.part);
|
|
106673
|
+
const metadata = canonicalizeMcpResultValue(envelope.messageMetadata);
|
|
106674
|
+
const deduplicatedBranches = part.deduplicatedBranches + metadata.deduplicatedBranches;
|
|
106675
|
+
return toCanonicalizedEnvelope(
|
|
106676
|
+
envelope,
|
|
106677
|
+
{
|
|
106678
|
+
...envelope,
|
|
106679
|
+
part: part.value,
|
|
106680
|
+
...envelope.messageMetadata === void 0 ? {} : { messageMetadata: metadata.value }
|
|
106681
|
+
},
|
|
106682
|
+
deduplicatedBranches
|
|
106683
|
+
);
|
|
106684
|
+
}
|
|
106685
|
+
case "ui.message.completed": {
|
|
106686
|
+
const message = canonicalizeMcpResultValue(envelope.message);
|
|
106687
|
+
return toCanonicalizedEnvelope(
|
|
106688
|
+
envelope,
|
|
106689
|
+
{ ...envelope, message: message.value },
|
|
106690
|
+
message.deduplicatedBranches
|
|
106691
|
+
);
|
|
106692
|
+
}
|
|
106693
|
+
case "runtime.liveness":
|
|
106694
|
+
case "runtime.usage_turn":
|
|
106695
|
+
return { value: envelope, deduplicatedBranches: 0 };
|
|
106696
|
+
}
|
|
106697
|
+
}
|
|
106698
|
+
function toCanonicalizedEnvelope(original, candidate, deduplicatedBranches) {
|
|
106699
|
+
return {
|
|
106700
|
+
value: deduplicatedBranches > 0 ? RuntimeBridgeOutputEnvelopeSchema.parse(candidate) : original,
|
|
106701
|
+
deduplicatedBranches
|
|
106702
|
+
};
|
|
106703
|
+
}
|
|
106704
|
+
function canonicalizeMcpResultValue(value) {
|
|
106705
|
+
if (Array.isArray(value)) {
|
|
106706
|
+
let deduplicatedBranches2 = 0;
|
|
106707
|
+
let changed2 = false;
|
|
106708
|
+
const items = value.map((item) => {
|
|
106709
|
+
const canonical2 = canonicalizeMcpResultValue(item);
|
|
106710
|
+
deduplicatedBranches2 += canonical2.deduplicatedBranches;
|
|
106711
|
+
changed2 ||= canonical2.value !== item;
|
|
106712
|
+
return canonical2.value;
|
|
106713
|
+
});
|
|
106714
|
+
return {
|
|
106715
|
+
value: changed2 ? items : value,
|
|
106716
|
+
deduplicatedBranches: deduplicatedBranches2
|
|
106717
|
+
};
|
|
106718
|
+
}
|
|
106719
|
+
if (typeof value !== "object" || value === null) {
|
|
106720
|
+
return { value, deduplicatedBranches: 0 };
|
|
106721
|
+
}
|
|
106722
|
+
const record2 = value;
|
|
106723
|
+
const duplicateContentIndexes = equivalentMcpTextContentIndexes(record2);
|
|
106724
|
+
let deduplicatedBranches = duplicateContentIndexes.size;
|
|
106725
|
+
let changed = duplicateContentIndexes.size > 0;
|
|
106726
|
+
const canonical = /* @__PURE__ */ Object.create(null);
|
|
106727
|
+
for (const [key, item] of Object.entries(record2)) {
|
|
106728
|
+
if (key === "content" && Array.isArray(item)) {
|
|
106729
|
+
const retainedContent = duplicateContentIndexes.size > 0 ? item.filter(
|
|
106730
|
+
(_contentItem, index) => !duplicateContentIndexes.has(index)
|
|
106731
|
+
) : item;
|
|
106732
|
+
if (retainedContent.length === 0 && duplicateContentIndexes.size > 0) {
|
|
106733
|
+
continue;
|
|
106734
|
+
}
|
|
106735
|
+
const content = canonicalizeMcpResultValue(retainedContent);
|
|
106736
|
+
canonical[key] = content.value;
|
|
106737
|
+
deduplicatedBranches += content.deduplicatedBranches;
|
|
106738
|
+
changed ||= content.value !== item;
|
|
106739
|
+
continue;
|
|
106740
|
+
}
|
|
106741
|
+
const child = canonicalizeMcpResultValue(item);
|
|
106742
|
+
canonical[key] = child.value;
|
|
106743
|
+
deduplicatedBranches += child.deduplicatedBranches;
|
|
106744
|
+
changed ||= child.value !== item;
|
|
106745
|
+
}
|
|
106746
|
+
return {
|
|
106747
|
+
value: changed ? canonical : value,
|
|
106748
|
+
deduplicatedBranches
|
|
106749
|
+
};
|
|
106750
|
+
}
|
|
106751
|
+
function equivalentMcpTextContentIndexes(value) {
|
|
106752
|
+
if (!Array.isArray(value.content) || !Object.hasOwn(value, "structuredContent") || value.structuredContent === void 0) {
|
|
106753
|
+
return /* @__PURE__ */ new Set();
|
|
106754
|
+
}
|
|
106755
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
106756
|
+
for (const [index, item] of value.content.entries()) {
|
|
106757
|
+
if (!isPlainMcpTextBlock(item)) {
|
|
106758
|
+
continue;
|
|
106759
|
+
}
|
|
106760
|
+
const parsed = parseJson(item.text);
|
|
106761
|
+
if (parsed.parsed && jsonValuesEqual(parsed.value, value.structuredContent)) {
|
|
106762
|
+
indexes.add(index);
|
|
106763
|
+
}
|
|
106764
|
+
}
|
|
106765
|
+
return indexes;
|
|
106766
|
+
}
|
|
106767
|
+
function isPlainMcpTextBlock(value) {
|
|
106768
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
106769
|
+
return false;
|
|
106770
|
+
}
|
|
106771
|
+
const record2 = value;
|
|
106772
|
+
const keys = Object.keys(record2);
|
|
106773
|
+
return keys.length === 2 && record2.type === "text" && typeof record2.text === "string";
|
|
106774
|
+
}
|
|
106775
|
+
function parseJson(value) {
|
|
106776
|
+
try {
|
|
106777
|
+
return { parsed: true, value: JSON.parse(value) };
|
|
106778
|
+
} catch {
|
|
106779
|
+
return { parsed: false, value: null };
|
|
106780
|
+
}
|
|
106781
|
+
}
|
|
106782
|
+
function jsonValuesEqual(left, right) {
|
|
106783
|
+
if (Object.is(left, right)) {
|
|
106784
|
+
return true;
|
|
106785
|
+
}
|
|
106786
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
106787
|
+
if (!Array.isArray(left) || !Array.isArray(right)) {
|
|
106788
|
+
return false;
|
|
106789
|
+
}
|
|
106790
|
+
return left.length === right.length && left.every((item, index) => jsonValuesEqual(item, right[index]));
|
|
106791
|
+
}
|
|
106792
|
+
if (typeof left !== "object" || left === null || typeof right !== "object" || right === null) {
|
|
106793
|
+
return false;
|
|
106794
|
+
}
|
|
106795
|
+
const leftRecord = left;
|
|
106796
|
+
const rightRecord = right;
|
|
106797
|
+
const leftKeys = Object.keys(leftRecord);
|
|
106798
|
+
const rightKeys = Object.keys(rightRecord);
|
|
106799
|
+
return leftKeys.length === rightKeys.length && leftKeys.every(
|
|
106800
|
+
(key) => Object.hasOwn(rightRecord, key) && jsonValuesEqual(leftRecord[key], rightRecord[key])
|
|
106801
|
+
);
|
|
106802
|
+
}
|
|
106803
|
+
|
|
106804
|
+
// src/commands/agent-bridge/harness/envelope-bounds.ts
|
|
106605
106805
|
var AGENT_BRIDGE_OUTPUT_MAX_ENVELOPE_BYTES = 512 * 1024;
|
|
106606
106806
|
var AGENT_BRIDGE_OUTPUT_QUARANTINE_MAX_ENVELOPE_BYTES = 8 * 1024;
|
|
106607
|
-
var MAX_TARGETED_PAYLOAD_NOTICES = 4;
|
|
106608
106807
|
var PAYLOAD_FIELD_RULES = {
|
|
106609
106808
|
output: { label: "tool output", priority: 0 },
|
|
106610
106809
|
errorText: { label: "tool error", priority: 0 },
|
|
@@ -106639,48 +106838,97 @@ var STRUCTURAL_STRING_FIELDS = /* @__PURE__ */ new Set([
|
|
|
106639
106838
|
"completedAt"
|
|
106640
106839
|
]);
|
|
106641
106840
|
function boundOutputEnvelope(envelope, maxBytes = AGENT_BRIDGE_OUTPUT_MAX_ENVELOPE_BYTES) {
|
|
106642
|
-
const
|
|
106841
|
+
const original = envelopeSerializationInfo(envelope);
|
|
106842
|
+
const originalBytes = original.bytes;
|
|
106643
106843
|
if (originalBytes <= maxBytes) {
|
|
106644
|
-
return {
|
|
106844
|
+
return {
|
|
106845
|
+
envelope,
|
|
106846
|
+
originalBytes,
|
|
106847
|
+
boundedBytes: originalBytes,
|
|
106848
|
+
kind: "none",
|
|
106849
|
+
deduplicatedMcpResultBranches: 0,
|
|
106850
|
+
truncated: false
|
|
106851
|
+
};
|
|
106645
106852
|
}
|
|
106646
|
-
const
|
|
106853
|
+
const canonicalized = original.hasStructuredContent ? canonicalizeEnvelopeMcpResults(envelope) : { value: envelope, deduplicatedBranches: 0 };
|
|
106854
|
+
const canonicalEnvelope = canonicalized.value;
|
|
106855
|
+
const canonicalBytes = serializedByteLength(canonicalEnvelope);
|
|
106856
|
+
if (canonicalBytes <= maxBytes) {
|
|
106857
|
+
return {
|
|
106858
|
+
envelope: canonicalEnvelope,
|
|
106859
|
+
originalBytes,
|
|
106860
|
+
boundedBytes: canonicalBytes,
|
|
106861
|
+
kind: "mcp-result-deduplicated",
|
|
106862
|
+
deduplicatedMcpResultBranches: canonicalized.deduplicatedBranches,
|
|
106863
|
+
truncated: true
|
|
106864
|
+
};
|
|
106865
|
+
}
|
|
106866
|
+
const targeted = truncatePayloads(canonicalEnvelope, maxBytes);
|
|
106647
106867
|
if (targeted) {
|
|
106868
|
+
const boundedEnvelope = RuntimeBridgeOutputEnvelopeSchema.parse(targeted);
|
|
106648
106869
|
return {
|
|
106649
|
-
envelope:
|
|
106870
|
+
envelope: boundedEnvelope,
|
|
106650
106871
|
originalBytes,
|
|
106872
|
+
boundedBytes: serializedByteLength(boundedEnvelope),
|
|
106873
|
+
kind: canonicalized.deduplicatedBranches > 0 ? "mcp-result-deduplicated+targeted-truncation" : "targeted-truncation",
|
|
106874
|
+
deduplicatedMcpResultBranches: canonicalized.deduplicatedBranches,
|
|
106651
106875
|
truncated: true
|
|
106652
106876
|
};
|
|
106653
106877
|
}
|
|
106878
|
+
const fallbackEnvelope = RuntimeBridgeOutputEnvelopeSchema.parse(
|
|
106879
|
+
replacePayloadWithMarker(canonicalEnvelope)
|
|
106880
|
+
);
|
|
106654
106881
|
return {
|
|
106655
|
-
envelope:
|
|
106656
|
-
replacePayloadWithMarker(envelope)
|
|
106657
|
-
),
|
|
106882
|
+
envelope: fallbackEnvelope,
|
|
106658
106883
|
originalBytes,
|
|
106884
|
+
boundedBytes: serializedByteLength(fallbackEnvelope),
|
|
106885
|
+
kind: canonicalized.deduplicatedBranches > 0 ? "mcp-result-deduplicated+payload-fallback" : "payload-fallback",
|
|
106886
|
+
deduplicatedMcpResultBranches: canonicalized.deduplicatedBranches,
|
|
106659
106887
|
truncated: true
|
|
106660
106888
|
};
|
|
106661
106889
|
}
|
|
106662
106890
|
function truncatePayloads(envelope, maxBytes) {
|
|
106663
106891
|
const candidateEnvelope = structuredClone(envelope);
|
|
106664
106892
|
const candidates = collectPayloadCandidates(envelope);
|
|
106665
|
-
|
|
106893
|
+
const truncatedCandidates = [];
|
|
106894
|
+
while (true) {
|
|
106666
106895
|
const currentBytes = serializedByteLength(candidateEnvelope);
|
|
106667
106896
|
if (currentBytes <= maxBytes) {
|
|
106668
106897
|
return candidateEnvelope;
|
|
106669
106898
|
}
|
|
106670
106899
|
const candidate = takePayloadCandidate(candidates, currentBytes - maxBytes);
|
|
106671
106900
|
if (!candidate) {
|
|
106672
|
-
|
|
106901
|
+
break;
|
|
106673
106902
|
}
|
|
106674
106903
|
setValueAtPath(
|
|
106675
106904
|
candidateEnvelope,
|
|
106676
106905
|
candidate.path,
|
|
106677
106906
|
truncationNotice(candidate, "")
|
|
106678
106907
|
);
|
|
106679
|
-
|
|
106908
|
+
const truncatedBytes = serializedByteLength(candidateEnvelope);
|
|
106909
|
+
if (truncatedBytes >= currentBytes) {
|
|
106910
|
+
setValueAtPath(candidateEnvelope, candidate.path, candidate.value);
|
|
106911
|
+
continue;
|
|
106912
|
+
}
|
|
106913
|
+
truncatedCandidates.push(candidate);
|
|
106914
|
+
if (truncatedBytes <= maxBytes) {
|
|
106680
106915
|
maximizePreview(candidateEnvelope, candidate, maxBytes);
|
|
106681
106916
|
return candidateEnvelope;
|
|
106682
106917
|
}
|
|
106683
106918
|
}
|
|
106919
|
+
for (const candidate of truncatedCandidates) {
|
|
106920
|
+
setValueAtPath(
|
|
106921
|
+
candidateEnvelope,
|
|
106922
|
+
candidate.path,
|
|
106923
|
+
compactTruncationNotice(candidate)
|
|
106924
|
+
);
|
|
106925
|
+
}
|
|
106926
|
+
if (serializedByteLength(candidateEnvelope) <= maxBytes) {
|
|
106927
|
+
return candidateEnvelope;
|
|
106928
|
+
}
|
|
106929
|
+
for (const candidate of truncatedCandidates) {
|
|
106930
|
+
setValueAtPath(candidateEnvelope, candidate.path, "");
|
|
106931
|
+
}
|
|
106684
106932
|
return serializedByteLength(candidateEnvelope) <= maxBytes ? candidateEnvelope : null;
|
|
106685
106933
|
}
|
|
106686
106934
|
function collectPayloadCandidates(envelope) {
|
|
@@ -106845,10 +107093,20 @@ function truncationNotice(candidate, preview2) {
|
|
|
106845
107093
|
const separator = preview2.length > 0 ? "\n" : "";
|
|
106846
107094
|
return `${preview2}${separator}[agent-bridge ${candidate.label} truncated: original ${candidate.originalBytes} UTF-8 bytes; kept ${keptBytes}; omitted ${omittedBytes}. Omitted content was not persisted in this transcript.]`;
|
|
106847
107095
|
}
|
|
107096
|
+
function compactTruncationNotice(candidate) {
|
|
107097
|
+
return `[agent-bridge ${candidate.label} truncated: original ${candidate.originalBytes} UTF-8 bytes.]`;
|
|
107098
|
+
}
|
|
106848
107099
|
function serializedByteLength(value) {
|
|
106849
107100
|
const serialized = JSON.stringify(value);
|
|
106850
107101
|
return serialized === void 0 ? 0 : Buffer2.byteLength(serialized, "utf8");
|
|
106851
107102
|
}
|
|
107103
|
+
function envelopeSerializationInfo(envelope) {
|
|
107104
|
+
const serialized = JSON.stringify(envelope);
|
|
107105
|
+
return {
|
|
107106
|
+
bytes: Buffer2.byteLength(serialized, "utf8"),
|
|
107107
|
+
hasStructuredContent: serialized.includes('"structuredContent":')
|
|
107108
|
+
};
|
|
107109
|
+
}
|
|
106852
107110
|
function replacePayloadWithMarker(envelope) {
|
|
106853
107111
|
switch (envelope.type) {
|
|
106854
107112
|
case "conversation.entry": {
|
|
@@ -107810,6 +108068,9 @@ var AgentBridgeOutputBuffer = class {
|
|
|
107810
108068
|
"agent_bridge_output_envelope_truncated",
|
|
107811
108069
|
this.outputLogContext(bounded.envelope, {
|
|
107812
108070
|
original_bytes: bounded.originalBytes,
|
|
108071
|
+
bounded_bytes: bounded.boundedBytes,
|
|
108072
|
+
bound_kind: bounded.kind,
|
|
108073
|
+
deduplicated_mcp_result_branches: bounded.deduplicatedMcpResultBranches,
|
|
107813
108074
|
pending_count: this.pendingOutputs.size
|
|
107814
108075
|
})
|
|
107815
108076
|
);
|
|
@@ -107843,6 +108104,9 @@ var AgentBridgeOutputBuffer = class {
|
|
|
107843
108104
|
this.outputLogContext(bounded.envelope, {
|
|
107844
108105
|
exhausts,
|
|
107845
108106
|
original_bytes: bounded.originalBytes,
|
|
108107
|
+
bounded_bytes: bounded.boundedBytes,
|
|
108108
|
+
bound_kind: bounded.kind,
|
|
108109
|
+
deduplicated_mcp_result_branches: bounded.deduplicatedMcpResultBranches,
|
|
107846
108110
|
truncated: bounded.truncated,
|
|
107847
108111
|
pending_count: this.pendingOutputs.size
|
|
107848
108112
|
})
|