@lobehub/cli 0.0.98 → 0.0.99
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/acceptance-report.html +235 -235
- package/dist/index.js +336 -62
- package/man/man1/lh.1 +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { Buffer as Buffer$1 } from "node:buffer";
|
|
|
15
15
|
import * as net$1 from "node:net";
|
|
16
16
|
import net, { BlockList, connect, createServer, isIP } from "node:net";
|
|
17
17
|
import { scheduler, setImmediate as setImmediate$1, setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
18
|
-
import
|
|
18
|
+
import _w, { cwd, execArgv, execPath, hrtime, platform as platform$1 } from "node:process";
|
|
19
19
|
import { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
|
|
20
20
|
import { finished, pipeline } from "node:stream/promises";
|
|
21
21
|
import { Duplex, PassThrough, Readable, Transform, Writable, getDefaultHighWaterMark, pipeline as pipeline$1 } from "node:stream";
|
|
@@ -9497,6 +9497,10 @@ var init_creds = __esmMin((() => {}));
|
|
|
9497
9497
|
//#region ../../packages/types/src/dashboard/index.ts
|
|
9498
9498
|
var init_dashboard = __esmMin((() => {}));
|
|
9499
9499
|
|
|
9500
|
+
//#endregion
|
|
9501
|
+
//#region ../../packages/types/src/dataExport.ts
|
|
9502
|
+
var init_dataExport = __esmMin((() => {}));
|
|
9503
|
+
|
|
9500
9504
|
//#endregion
|
|
9501
9505
|
//#region ../../packages/types/src/dbMigration.ts
|
|
9502
9506
|
var init_dbMigration = __esmMin((() => {}));
|
|
@@ -12230,6 +12234,7 @@ var init_src$2 = __esmMin((() => {
|
|
|
12230
12234
|
init_conversation();
|
|
12231
12235
|
init_creds();
|
|
12232
12236
|
init_dashboard();
|
|
12237
|
+
init_dataExport();
|
|
12233
12238
|
init_dbMigration();
|
|
12234
12239
|
init_device();
|
|
12235
12240
|
init_deviceFilePreviewFailure();
|
|
@@ -18609,7 +18614,7 @@ const HOTKEYS_REGISTRATION = [
|
|
|
18609
18614
|
{
|
|
18610
18615
|
group: HotkeyGroupEnum.Essential,
|
|
18611
18616
|
id: HotkeyEnum.SwitchTab,
|
|
18612
|
-
keys: combineKeys([KeyEnum.
|
|
18617
|
+
keys: combineKeys([KeyEnum.Mod, KeyEnum.Number]),
|
|
18613
18618
|
nonEditable: true,
|
|
18614
18619
|
scopes: [HotkeyScopeEnum.Global]
|
|
18615
18620
|
},
|
|
@@ -21872,7 +21877,7 @@ var require_command = /* @__PURE__ */ __commonJSMin$2(((exports) => {
|
|
|
21872
21877
|
const childProcess$2 = __require("node:child_process");
|
|
21873
21878
|
const path$16 = __require("node:path");
|
|
21874
21879
|
const fs$17 = __require("node:fs");
|
|
21875
|
-
const process$
|
|
21880
|
+
const process$2 = __require("node:process");
|
|
21876
21881
|
const { Argument, humanReadableArgName } = require_argument();
|
|
21877
21882
|
const { CommanderError } = require_error$1();
|
|
21878
21883
|
const { Help, stripColor } = require_help();
|
|
@@ -21924,13 +21929,13 @@ var require_command = /* @__PURE__ */ __commonJSMin$2(((exports) => {
|
|
|
21924
21929
|
this._showSuggestionAfterError = true;
|
|
21925
21930
|
this._savedState = null;
|
|
21926
21931
|
this._outputConfiguration = {
|
|
21927
|
-
writeOut: (str) => process$
|
|
21928
|
-
writeErr: (str) => process$
|
|
21932
|
+
writeOut: (str) => process$2.stdout.write(str),
|
|
21933
|
+
writeErr: (str) => process$2.stderr.write(str),
|
|
21929
21934
|
outputError: (str, write) => write(str),
|
|
21930
|
-
getOutHelpWidth: () => process$
|
|
21931
|
-
getErrHelpWidth: () => process$
|
|
21932
|
-
getOutHasColors: () => useColor() ?? (process$
|
|
21933
|
-
getErrHasColors: () => useColor() ?? (process$
|
|
21935
|
+
getOutHelpWidth: () => process$2.stdout.isTTY ? process$2.stdout.columns : void 0,
|
|
21936
|
+
getErrHelpWidth: () => process$2.stderr.isTTY ? process$2.stderr.columns : void 0,
|
|
21937
|
+
getOutHasColors: () => useColor() ?? (process$2.stdout.isTTY && process$2.stdout.hasColors?.()),
|
|
21938
|
+
getErrHasColors: () => useColor() ?? (process$2.stderr.isTTY && process$2.stderr.hasColors?.()),
|
|
21934
21939
|
stripColor: (str) => stripColor(str)
|
|
21935
21940
|
};
|
|
21936
21941
|
this._hidden = false;
|
|
@@ -22288,7 +22293,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22288
22293
|
*/
|
|
22289
22294
|
_exit(exitCode, code, message) {
|
|
22290
22295
|
if (this._exitCallback) this._exitCallback(new CommanderError(exitCode, code, message));
|
|
22291
|
-
process$
|
|
22296
|
+
process$2.exit(exitCode);
|
|
22292
22297
|
}
|
|
22293
22298
|
/**
|
|
22294
22299
|
* Register callback `fn` for the command.
|
|
@@ -22627,11 +22632,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22627
22632
|
if (argv !== void 0 && !Array.isArray(argv)) throw new Error("first parameter to parse must be array or undefined");
|
|
22628
22633
|
parseOptions = parseOptions || {};
|
|
22629
22634
|
if (argv === void 0 && parseOptions.from === void 0) {
|
|
22630
|
-
if (process$
|
|
22631
|
-
const execArgv = process$
|
|
22635
|
+
if (process$2.versions?.electron) parseOptions.from = "electron";
|
|
22636
|
+
const execArgv = process$2.execArgv ?? [];
|
|
22632
22637
|
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) parseOptions.from = "eval";
|
|
22633
22638
|
}
|
|
22634
|
-
if (argv === void 0) argv = process$
|
|
22639
|
+
if (argv === void 0) argv = process$2.argv;
|
|
22635
22640
|
this.rawArgs = argv.slice();
|
|
22636
22641
|
let userArgs;
|
|
22637
22642
|
switch (parseOptions.from) {
|
|
@@ -22641,7 +22646,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22641
22646
|
userArgs = argv.slice(2);
|
|
22642
22647
|
break;
|
|
22643
22648
|
case "electron":
|
|
22644
|
-
if (process$
|
|
22649
|
+
if (process$2.defaultApp) {
|
|
22645
22650
|
this._scriptPath = argv[1];
|
|
22646
22651
|
userArgs = argv.slice(2);
|
|
22647
22652
|
} else userArgs = argv.slice(1);
|
|
@@ -22806,16 +22811,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22806
22811
|
}
|
|
22807
22812
|
launchWithNode = sourceExt.includes(path$16.extname(executableFile));
|
|
22808
22813
|
let proc;
|
|
22809
|
-
if (process$
|
|
22814
|
+
if (process$2.platform !== "win32") if (launchWithNode) {
|
|
22810
22815
|
args.unshift(executableFile);
|
|
22811
|
-
args = incrementNodeInspectorPort(process$
|
|
22812
|
-
proc = childProcess$2.spawn(process$
|
|
22816
|
+
args = incrementNodeInspectorPort(process$2.execArgv).concat(args);
|
|
22817
|
+
proc = childProcess$2.spawn(process$2.argv[0], args, { stdio: "inherit" });
|
|
22813
22818
|
} else proc = childProcess$2.spawn(executableFile, args, { stdio: "inherit" });
|
|
22814
22819
|
else {
|
|
22815
22820
|
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
22816
22821
|
args.unshift(executableFile);
|
|
22817
|
-
args = incrementNodeInspectorPort(process$
|
|
22818
|
-
proc = childProcess$2.spawn(process$
|
|
22822
|
+
args = incrementNodeInspectorPort(process$2.execArgv).concat(args);
|
|
22823
|
+
proc = childProcess$2.spawn(process$2.execPath, args, { stdio: "inherit" });
|
|
22819
22824
|
}
|
|
22820
22825
|
if (!proc.killed) [
|
|
22821
22826
|
"SIGUSR1",
|
|
@@ -22824,20 +22829,20 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22824
22829
|
"SIGINT",
|
|
22825
22830
|
"SIGHUP"
|
|
22826
22831
|
].forEach((signal) => {
|
|
22827
|
-
process$
|
|
22832
|
+
process$2.on(signal, () => {
|
|
22828
22833
|
if (proc.killed === false && proc.exitCode === null) proc.kill(signal);
|
|
22829
22834
|
});
|
|
22830
22835
|
});
|
|
22831
22836
|
const exitCallback = this._exitCallback;
|
|
22832
22837
|
proc.on("close", (code) => {
|
|
22833
22838
|
code = code ?? 1;
|
|
22834
|
-
if (!exitCallback) process$
|
|
22839
|
+
if (!exitCallback) process$2.exit(code);
|
|
22835
22840
|
else exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
22836
22841
|
});
|
|
22837
22842
|
proc.on("error", (err) => {
|
|
22838
22843
|
if (err.code === "ENOENT") this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
22839
22844
|
else if (err.code === "EACCES") throw new Error(`'${executableFile}' not executable`);
|
|
22840
|
-
if (!exitCallback) process$
|
|
22845
|
+
if (!exitCallback) process$2.exit(1);
|
|
22841
22846
|
else {
|
|
22842
22847
|
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
22843
22848
|
wrappedError.nestedError = err;
|
|
@@ -23246,13 +23251,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
23246
23251
|
*/
|
|
23247
23252
|
_parseOptionsEnv() {
|
|
23248
23253
|
this.options.forEach((option) => {
|
|
23249
|
-
if (option.envVar && option.envVar in process$
|
|
23254
|
+
if (option.envVar && option.envVar in process$2.env) {
|
|
23250
23255
|
const optionKey = option.attributeName();
|
|
23251
23256
|
if (this.getOptionValue(optionKey) === void 0 || [
|
|
23252
23257
|
"default",
|
|
23253
23258
|
"config",
|
|
23254
23259
|
"env"
|
|
23255
|
-
].includes(this.getOptionValueSource(optionKey))) if (option.required || option.optional) this.emit(`optionEnv:${option.name()}`, process$
|
|
23260
|
+
].includes(this.getOptionValueSource(optionKey))) if (option.required || option.optional) this.emit(`optionEnv:${option.name()}`, process$2.env[option.envVar]);
|
|
23256
23261
|
else this.emit(`optionEnv:${option.name()}`);
|
|
23257
23262
|
}
|
|
23258
23263
|
});
|
|
@@ -23669,7 +23674,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
23669
23674
|
*/
|
|
23670
23675
|
help(contextOptions) {
|
|
23671
23676
|
this.outputHelp(contextOptions);
|
|
23672
|
-
let exitCode = Number(process$
|
|
23677
|
+
let exitCode = Number(process$2.exitCode ?? 0);
|
|
23673
23678
|
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) exitCode = 1;
|
|
23674
23679
|
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
23675
23680
|
}
|
|
@@ -23759,8 +23764,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
23759
23764
|
* @package
|
|
23760
23765
|
*/
|
|
23761
23766
|
function useColor() {
|
|
23762
|
-
if (process$
|
|
23763
|
-
if (process$
|
|
23767
|
+
if (process$2.env.NO_COLOR || process$2.env.FORCE_COLOR === "0" || process$2.env.FORCE_COLOR === "false") return false;
|
|
23768
|
+
if (process$2.env.FORCE_COLOR || process$2.env.CLICOLOR_FORCE !== void 0) return true;
|
|
23764
23769
|
}
|
|
23765
23770
|
exports.Command = Command;
|
|
23766
23771
|
exports.useColor = useColor;
|
|
@@ -47766,6 +47771,9 @@ var GatewayMuxClient = class {
|
|
|
47766
47771
|
case "channel_changed":
|
|
47767
47772
|
this.listeners.emit("channel_changed", message);
|
|
47768
47773
|
break;
|
|
47774
|
+
case "user_changed":
|
|
47775
|
+
this.listeners.emit("user_changed", message);
|
|
47776
|
+
break;
|
|
47769
47777
|
case "op_lifecycle":
|
|
47770
47778
|
this.listeners.emit("lifecycle", message);
|
|
47771
47779
|
break;
|
|
@@ -64356,6 +64364,181 @@ var AntigravityAdapter = class {
|
|
|
64356
64364
|
}
|
|
64357
64365
|
};
|
|
64358
64366
|
|
|
64367
|
+
//#endregion
|
|
64368
|
+
//#region ../../packages/heterogeneous-agents/src/adapters/claudeCodeBackgroundTasks.ts
|
|
64369
|
+
/** Agent tasks are subagents: the subagent thread list already shows them. */
|
|
64370
|
+
const AGENT_TASK_TYPES = new Set(["local_agent", "remote_agent"]);
|
|
64371
|
+
const SUBAGENT_TOOL_NAMES = new Set(["Agent", "Task"]);
|
|
64372
|
+
const NOTIFICATION_STATUSES = {
|
|
64373
|
+
completed: "completed",
|
|
64374
|
+
failed: "failed",
|
|
64375
|
+
stopped: "stopped"
|
|
64376
|
+
};
|
|
64377
|
+
/** `task_updated` statuses that end a task; CC's `killed` is the `stopped` notification's. */
|
|
64378
|
+
const TERMINAL_PATCH_STATUSES = {
|
|
64379
|
+
completed: "completed",
|
|
64380
|
+
failed: "failed",
|
|
64381
|
+
killed: "stopped"
|
|
64382
|
+
};
|
|
64383
|
+
/**
|
|
64384
|
+
* `run_in_background` Bash answers at once with the path it writes to:
|
|
64385
|
+
* "Command running in background with ID: <id>. Output is being written to:
|
|
64386
|
+
* <path>.output. …" — the only place the path shows before the task ends.
|
|
64387
|
+
*/
|
|
64388
|
+
const OUTPUT_PATH_PATTERN = /Output is being written to: (\S+?\.output)\b/;
|
|
64389
|
+
/**
|
|
64390
|
+
* Claude Code background tasks, as complete snapshots for the tool message
|
|
64391
|
+
* that started each one.
|
|
64392
|
+
*
|
|
64393
|
+
* CC reports a task's life as `system` events: `task_started` →
|
|
64394
|
+
* `task_updated` / `task_progress` … → `task_notification`. Each one that
|
|
64395
|
+
* changes a visible task yields a full {@link BackgroundTaskEventData}, so
|
|
64396
|
+
* every consumer simply replaces the stored snapshot.
|
|
64397
|
+
*
|
|
64398
|
+
* A task ends only when Claude Code says it did: a terminal `task_updated`
|
|
64399
|
+
* status (`killed` → `stopped`) or its `task_notification`, never because a
|
|
64400
|
+
* stop was requested. CC patches the status the moment the process ends, but
|
|
64401
|
+
* may hold the notification until its next turn boundary, so the patch is what
|
|
64402
|
+
* keeps a stopped row from reading "running" for half a minute. A task still
|
|
64403
|
+
* running when the stream ends is `interrupted`.
|
|
64404
|
+
*/
|
|
64405
|
+
var ClaudeCodeBackgroundTasks = class {
|
|
64406
|
+
tasks = /* @__PURE__ */ new Map();
|
|
64407
|
+
/** Every CC `task_*` system event belongs here, reported or not. */
|
|
64408
|
+
static isTaskEvent(raw) {
|
|
64409
|
+
return typeof raw?.subtype === "string" && raw.subtype.startsWith("task_");
|
|
64410
|
+
}
|
|
64411
|
+
/**
|
|
64412
|
+
* @param enabled Whether snapshots are reported at all; the task lineage of
|
|
64413
|
+
* {@link ClaudeCodeTaskSignals} is driven either way.
|
|
64414
|
+
* @param toEvent Wraps one snapshot into the adapter's `background_task` event.
|
|
64415
|
+
*/
|
|
64416
|
+
constructor(enabled, toEvent) {
|
|
64417
|
+
this.enabled = enabled;
|
|
64418
|
+
this.toEvent = toEvent;
|
|
64419
|
+
}
|
|
64420
|
+
/**
|
|
64421
|
+
* One CC `task_*` system event. Also drives the callback-turn lineage of
|
|
64422
|
+
* {@link ClaudeCodeTaskSignals}, which sees every task, subagents included.
|
|
64423
|
+
*/
|
|
64424
|
+
onSystem(raw, ctx) {
|
|
64425
|
+
const taskId = raw.task_id;
|
|
64426
|
+
if (typeof taskId !== "string" || !taskId) return [];
|
|
64427
|
+
switch (raw.subtype) {
|
|
64428
|
+
case "task_started": {
|
|
64429
|
+
const toolUseId = raw.tool_use_id;
|
|
64430
|
+
if (typeof toolUseId !== "string" || !toolUseId) return [];
|
|
64431
|
+
const toolName = ctx.mainToolName(toolUseId);
|
|
64432
|
+
ctx.taskSignals.start(taskId, toolUseId, toolName ?? "unknown", ctx.mainToolInput(toolUseId));
|
|
64433
|
+
return this.start(raw, taskId, toolUseId, toolName);
|
|
64434
|
+
}
|
|
64435
|
+
case "task_updated": return this.update(taskId, raw.patch);
|
|
64436
|
+
case "task_progress": return this.progress(taskId, raw);
|
|
64437
|
+
case "task_notification":
|
|
64438
|
+
ctx.taskSignals.end(taskId);
|
|
64439
|
+
return this.end(taskId, raw);
|
|
64440
|
+
default: return [];
|
|
64441
|
+
}
|
|
64442
|
+
}
|
|
64443
|
+
/**
|
|
64444
|
+
* A tool_result: pick up the output path a background Bash answers with.
|
|
64445
|
+
* Only main-agent tools start tracked tasks, so a subagent's result never matches.
|
|
64446
|
+
*/
|
|
64447
|
+
onToolResult(toolCallId, content) {
|
|
64448
|
+
const path = OUTPUT_PATH_PATTERN.exec(content)?.[1];
|
|
64449
|
+
if (!path) return [];
|
|
64450
|
+
for (const tracked of this.tasks.values()) {
|
|
64451
|
+
if (tracked.toolCallId !== toolCallId || tracked.task.outputFile) continue;
|
|
64452
|
+
tracked.task = {
|
|
64453
|
+
...tracked.task,
|
|
64454
|
+
outputFile: path
|
|
64455
|
+
};
|
|
64456
|
+
return this.snapshot(tracked);
|
|
64457
|
+
}
|
|
64458
|
+
return [];
|
|
64459
|
+
}
|
|
64460
|
+
/** The stream ended: every task still running lost its session. */
|
|
64461
|
+
flush(now = Date.now()) {
|
|
64462
|
+
const out = [];
|
|
64463
|
+
for (const tracked of this.tasks.values()) {
|
|
64464
|
+
if (!tracked.visible || tracked.task.status !== "running") continue;
|
|
64465
|
+
tracked.task = {
|
|
64466
|
+
...tracked.task,
|
|
64467
|
+
endedAt: now,
|
|
64468
|
+
status: "interrupted"
|
|
64469
|
+
};
|
|
64470
|
+
out.push(...this.snapshot(tracked));
|
|
64471
|
+
}
|
|
64472
|
+
this.tasks.clear();
|
|
64473
|
+
return out;
|
|
64474
|
+
}
|
|
64475
|
+
start(raw, taskId, toolCallId, toolName) {
|
|
64476
|
+
if (!toolName || SUBAGENT_TOOL_NAMES.has(toolName)) return [];
|
|
64477
|
+
if (AGENT_TASK_TYPES.has(raw.task_type) || raw.subagent_type) return [];
|
|
64478
|
+
const tracked = {
|
|
64479
|
+
task: {
|
|
64480
|
+
description: typeof raw.description === "string" ? raw.description : "",
|
|
64481
|
+
startedAt: Date.now(),
|
|
64482
|
+
status: "running",
|
|
64483
|
+
taskId,
|
|
64484
|
+
...typeof raw.task_type === "string" && { taskType: raw.task_type },
|
|
64485
|
+
toolName
|
|
64486
|
+
},
|
|
64487
|
+
toolCallId,
|
|
64488
|
+
visible: raw.is_backgrounded !== false
|
|
64489
|
+
};
|
|
64490
|
+
this.tasks.set(taskId, tracked);
|
|
64491
|
+
return this.snapshot(tracked);
|
|
64492
|
+
}
|
|
64493
|
+
update(taskId, patch) {
|
|
64494
|
+
const tracked = this.tasks.get(taskId);
|
|
64495
|
+
if (!tracked || !patch || typeof patch !== "object") return [];
|
|
64496
|
+
const next = { ...tracked.task };
|
|
64497
|
+
if (typeof patch.description === "string" && patch.description) next.description = patch.description;
|
|
64498
|
+
if (typeof patch.error === "string" && patch.error) next.error = patch.error;
|
|
64499
|
+
if (typeof patch.end_time === "number") next.endedAt = patch.end_time;
|
|
64500
|
+
if (patch.is_backgrounded === true) tracked.visible = true;
|
|
64501
|
+
const ended = TERMINAL_PATCH_STATUSES[patch.status];
|
|
64502
|
+
if (ended && next.status === "running") {
|
|
64503
|
+
next.status = ended;
|
|
64504
|
+
next.endedAt ??= Date.now();
|
|
64505
|
+
}
|
|
64506
|
+
tracked.task = next;
|
|
64507
|
+
return this.snapshot(tracked);
|
|
64508
|
+
}
|
|
64509
|
+
progress(taskId, raw) {
|
|
64510
|
+
const tracked = this.tasks.get(taskId);
|
|
64511
|
+
if (!tracked) return [];
|
|
64512
|
+
const next = { ...tracked.task };
|
|
64513
|
+
if (typeof raw.description === "string" && raw.description) next.description = raw.description;
|
|
64514
|
+
if (typeof raw.summary === "string" && raw.summary) next.summary = raw.summary;
|
|
64515
|
+
if (typeof raw.last_tool_name === "string") next.lastToolName = raw.last_tool_name;
|
|
64516
|
+
tracked.task = next;
|
|
64517
|
+
return this.snapshot(tracked);
|
|
64518
|
+
}
|
|
64519
|
+
end(taskId, raw) {
|
|
64520
|
+
const tracked = this.tasks.get(taskId);
|
|
64521
|
+
if (!tracked) return [];
|
|
64522
|
+
this.tasks.delete(taskId);
|
|
64523
|
+
const status = NOTIFICATION_STATUSES[raw.status] ?? "completed";
|
|
64524
|
+
tracked.task = {
|
|
64525
|
+
...tracked.task,
|
|
64526
|
+
endedAt: tracked.task.endedAt ?? Date.now(),
|
|
64527
|
+
status,
|
|
64528
|
+
...typeof raw.output_file === "string" && raw.output_file && { outputFile: raw.output_file },
|
|
64529
|
+
...typeof raw.summary === "string" && raw.summary && { summary: raw.summary }
|
|
64530
|
+
};
|
|
64531
|
+
return this.snapshot(tracked);
|
|
64532
|
+
}
|
|
64533
|
+
snapshot(tracked) {
|
|
64534
|
+
if (!this.enabled || !tracked.visible) return [];
|
|
64535
|
+
return [this.toEvent({
|
|
64536
|
+
task: { ...tracked.task },
|
|
64537
|
+
toolCallId: tracked.toolCallId
|
|
64538
|
+
})];
|
|
64539
|
+
}
|
|
64540
|
+
};
|
|
64541
|
+
|
|
64359
64542
|
//#endregion
|
|
64360
64543
|
//#region ../../packages/heterogeneous-agents/src/adapters/claudeCodeTaskSignals.ts
|
|
64361
64544
|
/**
|
|
@@ -65242,6 +65425,7 @@ var ClaudeCompatibleStreamAdapter = class {
|
|
|
65242
65425
|
mainToolNamesById = /* @__PURE__ */ new Map();
|
|
65243
65426
|
/** CC's long-running task lifecycle and the signal lineage it stamps on turns. */
|
|
65244
65427
|
taskSignals;
|
|
65428
|
+
backgroundTasks;
|
|
65245
65429
|
/**
|
|
65246
65430
|
* True after a `user` event has been seen but the next turn hasn't yet
|
|
65247
65431
|
* opened (`message_start` not yet fired). Carries the "this next turn
|
|
@@ -65290,6 +65474,7 @@ var ClaudeCompatibleStreamAdapter = class {
|
|
|
65290
65474
|
};
|
|
65291
65475
|
this.profile = profile;
|
|
65292
65476
|
this.taskSignals = new ClaudeCodeTaskSignals(this.options.signalBackgroundTaskCompletion);
|
|
65477
|
+
this.backgroundTasks = new ClaudeCodeBackgroundTasks(profile.agentType === "claude-code", (data) => this.makeEvent("background_task", data));
|
|
65293
65478
|
}
|
|
65294
65479
|
adapt(raw) {
|
|
65295
65480
|
if (!raw || typeof raw !== "object") return [];
|
|
@@ -65309,20 +65494,15 @@ var ClaudeCompatibleStreamAdapter = class {
|
|
|
65309
65494
|
flush() {
|
|
65310
65495
|
const events = [...this.pendingToolCalls].map((id) => this.makeEvent("tool_end", this.buildToolEndData(id, false)));
|
|
65311
65496
|
this.pendingToolCalls.clear();
|
|
65312
|
-
return events;
|
|
65497
|
+
return [...events, ...this.backgroundTasks.flush()];
|
|
65313
65498
|
}
|
|
65314
65499
|
handleSystem(raw) {
|
|
65315
65500
|
if (raw.subtype === "api_retry") return [this.makeEvent("stream_retry", getApiRetryData(raw, this.profile.agentType))];
|
|
65316
|
-
if (raw
|
|
65317
|
-
|
|
65318
|
-
|
|
65319
|
-
|
|
65320
|
-
}
|
|
65321
|
-
if (raw.subtype === "task_notification" && raw.task_id) {
|
|
65322
|
-
this.taskSignals.end(raw.task_id);
|
|
65323
|
-
return [];
|
|
65324
|
-
}
|
|
65325
|
-
if (raw.subtype === "task_updated") return [];
|
|
65501
|
+
if (ClaudeCodeBackgroundTasks.isTaskEvent(raw)) return this.backgroundTasks.onSystem(raw, {
|
|
65502
|
+
mainToolInput: (id) => this.mainToolInputsById.get(id),
|
|
65503
|
+
mainToolName: (id) => this.mainToolNamesById.get(id),
|
|
65504
|
+
taskSignals: this.taskSignals
|
|
65505
|
+
});
|
|
65326
65506
|
if (raw.subtype !== "init") return [];
|
|
65327
65507
|
this.sessionId = raw.session_id;
|
|
65328
65508
|
if (this.profile.ignoreDuplicateInit && this.started) return [];
|
|
@@ -65662,6 +65842,7 @@ var ClaudeCompatibleStreamAdapter = class {
|
|
|
65662
65842
|
subagent: subagentCtx,
|
|
65663
65843
|
toolCallId
|
|
65664
65844
|
}));
|
|
65845
|
+
events.push(...this.backgroundTasks.onToolResult(toolCallId, resultContent));
|
|
65665
65846
|
if (this.pendingToolCalls.has(toolCallId)) {
|
|
65666
65847
|
this.pendingToolCalls.delete(toolCallId);
|
|
65667
65848
|
events.push(this.makeEvent("tool_end", this.buildToolEndData(toolCallId, !block.is_error, {
|
|
@@ -72532,8 +72713,8 @@ const DEFAULT_IDLE_CLOSE_MS = 1800 * 1e3;
|
|
|
72532
72713
|
/**
|
|
72533
72714
|
* How long a task that ends between turns may wait for the main-agent turn its
|
|
72534
72715
|
* notification wakes. Claude Code opens that turn within milliseconds; the
|
|
72535
|
-
* grace only bounds an end that wakes nothing
|
|
72536
|
-
*
|
|
72716
|
+
* grace only bounds an end that unexpectedly wakes nothing. A stopped task
|
|
72717
|
+
* never wakes one, so it does not wait (see `observeSystem`).
|
|
72537
72718
|
*/
|
|
72538
72719
|
const DEFAULT_WAKE_UP_GRACE_MS = 30 * 1e3;
|
|
72539
72720
|
const TERMINAL_TASK_STATUSES = new Set([
|
|
@@ -72726,7 +72907,8 @@ var ClaudeCodeLiveInput = class {
|
|
|
72726
72907
|
}
|
|
72727
72908
|
if ((message.subtype === "task_notification" || message.subtype === "task_updated" && TERMINAL_TASK_STATUSES.has(message.patch?.status)) && message.task_id) {
|
|
72728
72909
|
this.activeTasks.delete(message.task_id);
|
|
72729
|
-
this.
|
|
72910
|
+
if (message.patch?.status === "killed" || message.subtype === "task_notification" && message.status === "stopped") this.closeIfIdle();
|
|
72911
|
+
else this.awaitWakeUpTurn();
|
|
72730
72912
|
}
|
|
72731
72913
|
}
|
|
72732
72914
|
/** A newer turn supersedes how the last one ended until it reports its own. */
|
|
@@ -72772,6 +72954,47 @@ var ClaudeCodeLiveInput = class {
|
|
|
72772
72954
|
}
|
|
72773
72955
|
};
|
|
72774
72956
|
|
|
72957
|
+
//#endregion
|
|
72958
|
+
//#region ../../packages/heterogeneous-agents/src/spawn/claudeCodeStopTask.ts
|
|
72959
|
+
/** How long Claude Code gets to accept a stop before the request is given up. */
|
|
72960
|
+
const STOP_TASK_ANSWER_TIMEOUT_MS = 1e4;
|
|
72961
|
+
const waitForAnswer = (answer, timeoutMs, signal) => new Promise((resolve, reject) => {
|
|
72962
|
+
const onAbort = () => fail("The run ended before Claude Code answered");
|
|
72963
|
+
const fail = (message) => {
|
|
72964
|
+
clearTimeout(timer);
|
|
72965
|
+
signal?.removeEventListener("abort", onAbort);
|
|
72966
|
+
reject(new Error(message));
|
|
72967
|
+
};
|
|
72968
|
+
const timer = setTimeout(() => fail("Claude Code did not answer the stop request in time"), timeoutMs);
|
|
72969
|
+
if (signal?.aborted) return onAbort();
|
|
72970
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
72971
|
+
answer.then((value) => {
|
|
72972
|
+
clearTimeout(timer);
|
|
72973
|
+
signal?.removeEventListener("abort", onAbort);
|
|
72974
|
+
resolve(value);
|
|
72975
|
+
});
|
|
72976
|
+
});
|
|
72977
|
+
/**
|
|
72978
|
+
* Stop one Claude Code background task through the session's live input: write
|
|
72979
|
+
* a `stop_task` control request and wait for Claude Code to accept it. The stop
|
|
72980
|
+
* is only proven by the task's `killed` / `stopped` report, which arrives on the
|
|
72981
|
+
* session's own output; this resolves when Claude Code took the request.
|
|
72982
|
+
*
|
|
72983
|
+
* @param send Writes a control request into the session's stdin; `undefined`
|
|
72984
|
+
* once that input has closed.
|
|
72985
|
+
* @throws When the input is closed, Claude Code refuses or never answers, or
|
|
72986
|
+
* `signal` aborts first.
|
|
72987
|
+
*/
|
|
72988
|
+
const stopClaudeCodeTask = async (send, taskId, options = {}) => {
|
|
72989
|
+
const sent = send({
|
|
72990
|
+
subtype: "stop_task",
|
|
72991
|
+
task_id: taskId
|
|
72992
|
+
});
|
|
72993
|
+
if (!sent) throw new Error("The Claude Code session no longer takes input");
|
|
72994
|
+
const answer = await waitForAnswer(sent.response, options.timeoutMs ?? 1e4, options.signal);
|
|
72995
|
+
if (answer.subtype === "error") throw new Error(answer.error);
|
|
72996
|
+
};
|
|
72997
|
+
|
|
72775
72998
|
//#endregion
|
|
72776
72999
|
//#region ../../packages/heterogeneous-agents/src/spawn/presetEnv.ts
|
|
72777
73000
|
/**
|
|
@@ -266851,6 +267074,7 @@ const parseSkillFrontmatter = (raw) => {
|
|
|
266851
267074
|
const { data } = (0, import_gray_matter.default)(raw);
|
|
266852
267075
|
return {
|
|
266853
267076
|
description: readStringField(data, "description"),
|
|
267077
|
+
disableModelInvocation: data["disable-model-invocation"] === true,
|
|
266854
267078
|
name: readStringField(data, "name")
|
|
266855
267079
|
};
|
|
266856
267080
|
} catch {
|
|
@@ -266877,6 +267101,7 @@ const scanSkillsInSource = async ({ previewRoot, scope, source, sourceRoot }) =>
|
|
|
266877
267101
|
const files = await listSkillFilesRecursive(skillDir);
|
|
266878
267102
|
return {
|
|
266879
267103
|
description: fields.description || void 0,
|
|
267104
|
+
disableModelInvocation: fields.disableModelInvocation,
|
|
266880
267105
|
fileCount: files.length,
|
|
266881
267106
|
files,
|
|
266882
267107
|
name: fields.name || entry.name,
|
|
@@ -331235,7 +331460,7 @@ var stdio_exports = /* @__PURE__ */ __exportAll$2({
|
|
|
331235
331460
|
function getDefaultEnvironment() {
|
|
331236
331461
|
const env = {};
|
|
331237
331462
|
for (const key of DEFAULT_INHERITED_ENV_VARS) {
|
|
331238
|
-
const value =
|
|
331463
|
+
const value = _w.env[key];
|
|
331239
331464
|
if (value === void 0) continue;
|
|
331240
331465
|
if (value.startsWith("()")) continue;
|
|
331241
331466
|
env[key] = value;
|
|
@@ -331246,7 +331471,7 @@ var import_cross_spawn$1, DEFAULT_INHERITED_ENV_VARS, StdioClientTransport;
|
|
|
331246
331471
|
var init_stdio = __esmMin((() => {
|
|
331247
331472
|
init_src_CeKsbNLO();
|
|
331248
331473
|
import_cross_spawn$1 = /* @__PURE__ */ __toESM$2(require_cross_spawn(), 1);
|
|
331249
|
-
DEFAULT_INHERITED_ENV_VARS =
|
|
331474
|
+
DEFAULT_INHERITED_ENV_VARS = _w.platform === "win32" ? [
|
|
331250
331475
|
"APPDATA",
|
|
331251
331476
|
"COMSPEC",
|
|
331252
331477
|
"HOMEDRIVE",
|
|
@@ -331303,7 +331528,7 @@ var init_stdio = __esmMin((() => {
|
|
|
331303
331528
|
this._serverParams.stderr ?? "inherit"
|
|
331304
331529
|
],
|
|
331305
331530
|
shell: false,
|
|
331306
|
-
windowsHide:
|
|
331531
|
+
windowsHide: _w.platform === "win32",
|
|
331307
331532
|
cwd: this._serverParams.cwd
|
|
331308
331533
|
});
|
|
331309
331534
|
this._process.on("error", (error) => {
|
|
@@ -334337,9 +334562,9 @@ const getSubprocessResult = ({ stdout }) => {
|
|
|
334337
334562
|
//#region node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/utils/standard-stream.js
|
|
334338
334563
|
const isStandardStream = (stream) => STANDARD_STREAMS.includes(stream);
|
|
334339
334564
|
const STANDARD_STREAMS = [
|
|
334340
|
-
|
|
334341
|
-
|
|
334342
|
-
|
|
334565
|
+
_w.stdin,
|
|
334566
|
+
_w.stdout,
|
|
334567
|
+
_w.stderr
|
|
334343
334568
|
];
|
|
334344
334569
|
const STANDARD_STREAMS_ALIASES = [
|
|
334345
334570
|
"stdin",
|
|
@@ -334464,9 +334689,9 @@ const NO_ESCAPE_REGEXP = /^[\w./-]+$/;
|
|
|
334464
334689
|
//#endregion
|
|
334465
334690
|
//#region node_modules/.pnpm/is-unicode-supported@2.1.0/node_modules/is-unicode-supported/index.js
|
|
334466
334691
|
function isUnicodeSupported() {
|
|
334467
|
-
const { env } =
|
|
334692
|
+
const { env } = _w;
|
|
334468
334693
|
const { TERM, TERM_PROGRAM } = env;
|
|
334469
|
-
if (
|
|
334694
|
+
if (_w.platform !== "win32") return TERM !== "linux";
|
|
334470
334695
|
return Boolean(env.WT_SESSION) || Boolean(env.TERMINUS_SUBLIME) || env.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
334471
334696
|
}
|
|
334472
334697
|
|
|
@@ -335001,7 +335226,7 @@ function traversePathUp(startPath) {
|
|
|
335001
335226
|
|
|
335002
335227
|
//#endregion
|
|
335003
335228
|
//#region node_modules/.pnpm/npm-run-path@6.0.0/node_modules/npm-run-path/index.js
|
|
335004
|
-
const npmRunPath = ({ cwd =
|
|
335229
|
+
const npmRunPath = ({ cwd = _w.cwd(), path: pathOption = _w.env[pathKey()], preferLocal = true, execPath = _w.execPath, addExecPath = true } = {}) => {
|
|
335005
335230
|
const cwdPath = path.resolve(toPath(cwd));
|
|
335006
335231
|
const result = [];
|
|
335007
335232
|
const pathParts = pathOption.split(path.delimiter);
|
|
@@ -335019,7 +335244,7 @@ const applyExecPath = (result, pathParts, execPath, cwdPath) => {
|
|
|
335019
335244
|
const pathPart = path.resolve(cwdPath, toPath(execPath), "..");
|
|
335020
335245
|
if (!pathParts.includes(pathPart)) result.push(pathPart);
|
|
335021
335246
|
};
|
|
335022
|
-
const npmRunPathEnv = ({ env =
|
|
335247
|
+
const npmRunPathEnv = ({ env = _w.env, ...options } = {}) => {
|
|
335023
335248
|
env = { ...env };
|
|
335024
335249
|
const pathName = pathKey({ env });
|
|
335025
335250
|
options.path = env[pathName];
|
|
@@ -336154,7 +336379,7 @@ const normalizeCwd = (cwd = getDefaultCwd()) => {
|
|
|
336154
336379
|
};
|
|
336155
336380
|
const getDefaultCwd = () => {
|
|
336156
336381
|
try {
|
|
336157
|
-
return
|
|
336382
|
+
return _w.cwd();
|
|
336158
336383
|
} catch (error) {
|
|
336159
336384
|
error.message = `The current directory does not exist.\n${error.message}`;
|
|
336160
336385
|
throw error;
|
|
@@ -336190,7 +336415,7 @@ const normalizeOptions = (filePath, rawArguments, rawOptions) => {
|
|
|
336190
336415
|
options.killSignal = normalizeKillSignal(options.killSignal);
|
|
336191
336416
|
options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);
|
|
336192
336417
|
options.lines = options.lines.map((lines, fdNumber) => lines && !BINARY_ENCODINGS.has(options.encoding) && options.buffer[fdNumber]);
|
|
336193
|
-
if (
|
|
336418
|
+
if (_w.platform === "win32" && path.basename(file, ".exe") === "cmd") commandArguments.unshift("/q");
|
|
336194
336419
|
return {
|
|
336195
336420
|
file,
|
|
336196
336421
|
commandArguments,
|
|
@@ -336217,7 +336442,7 @@ const addDefaultOptions = ({ extendEnv = true, preferLocal = false, cwd, localDi
|
|
|
336217
336442
|
});
|
|
336218
336443
|
const getEnv = ({ env: envOption, extendEnv, preferLocal, node, localDirectory, nodePath }) => {
|
|
336219
336444
|
const env = extendEnv ? {
|
|
336220
|
-
...
|
|
336445
|
+
..._w.env,
|
|
336221
336446
|
...envOption
|
|
336222
336447
|
} : envOption;
|
|
336223
336448
|
if (preferLocal || node) return npmRunPathEnv({
|
|
@@ -337219,12 +337444,12 @@ const guessStreamDirection = {
|
|
|
337219
337444
|
}
|
|
337220
337445
|
};
|
|
337221
337446
|
const getStandardStreamDirection = (value) => {
|
|
337222
|
-
if ([0,
|
|
337447
|
+
if ([0, _w.stdin].includes(value)) return "input";
|
|
337223
337448
|
if ([
|
|
337224
337449
|
1,
|
|
337225
337450
|
2,
|
|
337226
|
-
|
|
337227
|
-
|
|
337451
|
+
_w.stdout,
|
|
337452
|
+
_w.stderr
|
|
337228
337453
|
].includes(value)) return "output";
|
|
337229
337454
|
};
|
|
337230
337455
|
const DEFAULT_DIRECTION = "output";
|
|
@@ -338288,9 +338513,9 @@ const addIpcMethods = (subprocess, { ipc }) => {
|
|
|
338288
338513
|
Object.assign(subprocess, getIpcMethods(subprocess, false, ipc));
|
|
338289
338514
|
};
|
|
338290
338515
|
const getIpcExport = () => {
|
|
338291
|
-
const anyProcess =
|
|
338516
|
+
const anyProcess = _w;
|
|
338292
338517
|
const isSubprocess = true;
|
|
338293
|
-
const ipc =
|
|
338518
|
+
const ipc = _w.channel !== void 0;
|
|
338294
338519
|
return {
|
|
338295
338520
|
...getIpcMethods(anyProcess, isSubprocess, ipc),
|
|
338296
338521
|
getCancelSignal: getCancelSignal$1.bind(void 0, {
|
|
@@ -338767,7 +338992,7 @@ var SignalExitFallback = class extends SignalExitBase {
|
|
|
338767
338992
|
};
|
|
338768
338993
|
var SignalExit = class extends SignalExitBase {
|
|
338769
338994
|
/* c8 ignore start */
|
|
338770
|
-
#hupSig = process$
|
|
338995
|
+
#hupSig = process$1.platform === "win32" ? "SIGINT" : "SIGHUP";
|
|
338771
338996
|
/* c8 ignore stop */
|
|
338772
338997
|
#emitter = new Emitter();
|
|
338773
338998
|
#process;
|
|
@@ -338862,8 +339087,8 @@ var SignalExit = class extends SignalExitBase {
|
|
|
338862
339087
|
} else return og.call(this.#process, ev, ...args);
|
|
338863
339088
|
}
|
|
338864
339089
|
};
|
|
338865
|
-
const process$
|
|
338866
|
-
const { onExit, load: load$1, unload } = signalExitWrap(processOk(process$
|
|
339090
|
+
const process$1 = globalThis.process;
|
|
339091
|
+
const { onExit, load: load$1, unload } = signalExitWrap(processOk(process$1) ? new SignalExit(process$1) : new SignalExitFallback());
|
|
338867
339092
|
|
|
338868
339093
|
//#endregion
|
|
338869
339094
|
//#region node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/terminate/cleanup.js
|
|
@@ -581287,6 +581512,17 @@ var CoalescingBatchIngester = class {
|
|
|
581287
581512
|
* not know it" from "it failed".
|
|
581288
581513
|
*/
|
|
581289
581514
|
const handlers = /* @__PURE__ */ new Map();
|
|
581515
|
+
/**
|
|
581516
|
+
* Register the handler for `command`, replacing any earlier one.
|
|
581517
|
+
*
|
|
581518
|
+
* @returns a function that removes it again
|
|
581519
|
+
*/
|
|
581520
|
+
const registerHeteroControlHandler = (command, handler) => {
|
|
581521
|
+
handlers.set(command, handler);
|
|
581522
|
+
return () => {
|
|
581523
|
+
if (handlers.get(command) === handler) handlers.delete(command);
|
|
581524
|
+
};
|
|
581525
|
+
};
|
|
581290
581526
|
/** Run the handler for a control message and say how it went; never throws. */
|
|
581291
581527
|
const dispatchHeteroControl = async (message, context) => {
|
|
581292
581528
|
const handler = handlers.get(message.command);
|
|
@@ -581309,6 +581545,23 @@ const dispatchHeteroControl = async (message, context) => {
|
|
|
581309
581545
|
}
|
|
581310
581546
|
};
|
|
581311
581547
|
|
|
581548
|
+
//#endregion
|
|
581549
|
+
//#region src/utils/heteroStopTask.ts
|
|
581550
|
+
/** The control command the server queues to stop one background task. */
|
|
581551
|
+
const HETERO_STOP_TASK_COMMAND = "stop_task";
|
|
581552
|
+
/**
|
|
581553
|
+
* Stop one Claude Code background task: write a `stop_task` control request
|
|
581554
|
+
* into the session's stdin and wait for Claude Code to accept it. The stop is
|
|
581555
|
+
* only proven by the task's `stopped` report, which reaches the server through
|
|
581556
|
+
* the run's normal event stream; this reports that CC took the request.
|
|
581557
|
+
*/
|
|
581558
|
+
const stopTaskHandler = async ({ params, sendControlRequest, signal }) => {
|
|
581559
|
+
const taskId = params?.taskId;
|
|
581560
|
+
if (typeof taskId !== "string" || !taskId) throw new Error("stop_task needs a taskId");
|
|
581561
|
+
await stopClaudeCodeTask(sendControlRequest, taskId, { signal });
|
|
581562
|
+
};
|
|
581563
|
+
registerHeteroControlHandler(HETERO_STOP_TASK_COMMAND, stopTaskHandler);
|
|
581564
|
+
|
|
581312
581565
|
//#endregion
|
|
581313
581566
|
//#region src/utils/heteroSteer.ts
|
|
581314
581567
|
/** The prompt a follow-up is typed in as: its text, then its images as image blocks. */
|
|
@@ -581611,7 +581864,14 @@ const createOperationTokenRenewal = ({ operationId, renew }) => {
|
|
|
581611
581864
|
* The CLI authenticates using the `LOBEHUB_JWT` env var (operation-scoped JWT
|
|
581612
581865
|
* injected by the server before spawning the sandbox / desktop process).
|
|
581613
581866
|
*/
|
|
581867
|
+
const withoutBackgroundTasks = (events) => events.filter((event) => event.type !== "background_task");
|
|
581614
581868
|
var TrpcIngestSink = class {
|
|
581869
|
+
/**
|
|
581870
|
+
* Cleared once the server refused a batch for carrying `background_task`
|
|
581871
|
+
* events: a server that predates them rejects the whole batch at input
|
|
581872
|
+
* validation, so they are dropped for the rest of the run instead.
|
|
581873
|
+
*/
|
|
581874
|
+
sendBackgroundTasks = true;
|
|
581615
581875
|
constructor(client, agentType, operationId, topicId, assistantMessageId) {
|
|
581616
581876
|
this.client = client;
|
|
581617
581877
|
this.agentType = agentType;
|
|
@@ -581641,6 +581901,20 @@ var TrpcIngestSink = class {
|
|
|
581641
581901
|
}
|
|
581642
581902
|
}
|
|
581643
581903
|
async ingest(events) {
|
|
581904
|
+
const sendable = this.sendBackgroundTasks ? events : withoutBackgroundTasks(events);
|
|
581905
|
+
if (sendable.length === 0 && events.length > 0) return { accepted: true };
|
|
581906
|
+
try {
|
|
581907
|
+
return await this.send(sendable);
|
|
581908
|
+
} catch (error) {
|
|
581909
|
+
const code = error?.data?.code;
|
|
581910
|
+
const hasTasks = sendable.some((event) => event.type === "background_task");
|
|
581911
|
+
if (code !== "BAD_REQUEST" || !hasTasks) throw error;
|
|
581912
|
+
this.sendBackgroundTasks = false;
|
|
581913
|
+
const rest = withoutBackgroundTasks(sendable);
|
|
581914
|
+
return rest.length > 0 ? this.send(rest) : { accepted: true };
|
|
581915
|
+
}
|
|
581916
|
+
}
|
|
581917
|
+
async send(events) {
|
|
581644
581918
|
const ack = await this.client.aiAgent.heteroIngest.mutate({
|
|
581645
581919
|
agentType: this.agentType,
|
|
581646
581920
|
assistantMessageId: this.assistantMessageId,
|