@lobehub/cli 0.0.122 → 0.0.123
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/index.js +187 -52
- package/man/man1/lh.1 +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -62775,16 +62775,20 @@ var CodexAppServerAdapter = class {
|
|
|
62775
62775
|
started = false;
|
|
62776
62776
|
/** A steered message was read; the next visible output opens a new step. */
|
|
62777
62777
|
steerStepPending = false;
|
|
62778
|
-
stepIndex
|
|
62778
|
+
stepIndex;
|
|
62779
62779
|
terminal = false;
|
|
62780
62780
|
constructor(options = {}) {
|
|
62781
62781
|
this.currentModel = options.initialModel;
|
|
62782
62782
|
this.lastCumulativeUsage = options.initialCumulativeUsage;
|
|
62783
62783
|
this.sessionId = options.sessionId;
|
|
62784
|
+
this.stepIndex = options.initialStepIndex ?? 0;
|
|
62784
62785
|
}
|
|
62785
62786
|
get cumulativeUsage() {
|
|
62786
62787
|
return this.latestCumulativeUsage ?? this.lastCumulativeUsage;
|
|
62787
62788
|
}
|
|
62789
|
+
get nextStepIndex() {
|
|
62790
|
+
return this.stepIndex + 1;
|
|
62791
|
+
}
|
|
62788
62792
|
startUserInput(toolCallId, args) {
|
|
62789
62793
|
const payload = {
|
|
62790
62794
|
apiName: "askUserQuestion",
|
|
@@ -62850,7 +62854,10 @@ var CodexAppServerAdapter = class {
|
|
|
62850
62854
|
if (this.started) return [];
|
|
62851
62855
|
this.started = true;
|
|
62852
62856
|
this.currentTurnId = params.turn.id;
|
|
62853
|
-
return [this.makeEvent("stream_start", this.streamStartData({
|
|
62857
|
+
return [this.makeEvent("stream_start", this.streamStartData({
|
|
62858
|
+
messageId: params.turn.id,
|
|
62859
|
+
newStep: this.stepIndex > 0 || void 0
|
|
62860
|
+
}))];
|
|
62854
62861
|
}
|
|
62855
62862
|
handleItemStarted({ item }) {
|
|
62856
62863
|
if (item.type === "userMessage") return this.handleSteeredUserMessage(item);
|
|
@@ -63228,6 +63235,61 @@ const codexUserInputResponse = (request, answer) => {
|
|
|
63228
63235
|
return { answers: Object.fromEntries(entries) };
|
|
63229
63236
|
};
|
|
63230
63237
|
|
|
63238
|
+
//#endregion
|
|
63239
|
+
//#region ../../packages/heterogeneous-agents/src/codex/asyncUserInput.ts
|
|
63240
|
+
init_zod$1();
|
|
63241
|
+
const nonBlank = string().refine((value) => value.trim().length > 0);
|
|
63242
|
+
const notificationSchema = object$1({ item: object$1({
|
|
63243
|
+
delivery: literal("async"),
|
|
63244
|
+
id: nonBlank,
|
|
63245
|
+
questions: array(object$1({
|
|
63246
|
+
options: array(nonBlank).nullish(),
|
|
63247
|
+
title: nonBlank
|
|
63248
|
+
})).min(1),
|
|
63249
|
+
type: literal("agentMessage")
|
|
63250
|
+
}) });
|
|
63251
|
+
const readCodexAsyncQuestion = (params) => {
|
|
63252
|
+
const item = notificationSchema.safeParse(params).data?.item;
|
|
63253
|
+
if (!item) return;
|
|
63254
|
+
const questionNames = new Set(["__freeform__", "__supplement__"]);
|
|
63255
|
+
const questions = item.questions.map(({ options, title }, index) => {
|
|
63256
|
+
let question = title;
|
|
63257
|
+
for (let suffix = 2; questionNames.has(question); suffix++) question = `${title} (${suffix})`;
|
|
63258
|
+
questionNames.add(question);
|
|
63259
|
+
return {
|
|
63260
|
+
header: "",
|
|
63261
|
+
id: JSON.stringify([
|
|
63262
|
+
"request_user_input_async",
|
|
63263
|
+
item.id,
|
|
63264
|
+
index
|
|
63265
|
+
]),
|
|
63266
|
+
isSecret: false,
|
|
63267
|
+
options: [...new Set(options)].map((label) => ({
|
|
63268
|
+
description: "",
|
|
63269
|
+
label
|
|
63270
|
+
})),
|
|
63271
|
+
question,
|
|
63272
|
+
title
|
|
63273
|
+
};
|
|
63274
|
+
});
|
|
63275
|
+
return {
|
|
63276
|
+
itemId: item.id,
|
|
63277
|
+
questions
|
|
63278
|
+
};
|
|
63279
|
+
};
|
|
63280
|
+
const codexAsyncAnswers = (request, answer) => {
|
|
63281
|
+
const { answers } = codexUserInputResponse(request, answer);
|
|
63282
|
+
return request.questions.flatMap(({ id, title }) => {
|
|
63283
|
+
const response = answers[id]?.answers.join("\n");
|
|
63284
|
+
return response ? [{
|
|
63285
|
+
answer: response,
|
|
63286
|
+
question: title,
|
|
63287
|
+
questionItemId: id
|
|
63288
|
+
}] : [];
|
|
63289
|
+
});
|
|
63290
|
+
};
|
|
63291
|
+
const formatCodexAsyncReplies = (replies) => `<send_user_message_question_reply>\n${JSON.stringify(replies)}\n</send_user_message_question_reply>`;
|
|
63292
|
+
|
|
63231
63293
|
//#endregion
|
|
63232
63294
|
//#region ../../packages/heterogeneous-agents/src/codex/CodexThreadSession.ts
|
|
63233
63295
|
init_object$1();
|
|
@@ -63297,49 +63359,14 @@ var CodexThreadSession = class {
|
|
|
63297
63359
|
const threadId = this.threadId;
|
|
63298
63360
|
if (!threadId) throw new Error("Codex thread is not attached");
|
|
63299
63361
|
traceUnsubscribers.push(this.options.client.onRawMessage(threadId, options.onRawMessage));
|
|
63300
|
-
|
|
63301
|
-
|
|
63302
|
-
|
|
63303
|
-
|
|
63304
|
-
|
|
63305
|
-
|
|
63306
|
-
|
|
63307
|
-
|
|
63308
|
-
});
|
|
63309
|
-
const activeTurn = {
|
|
63310
|
-
adapter,
|
|
63311
|
-
askUserBridge: options.askUserBridge,
|
|
63312
|
-
completion,
|
|
63313
|
-
interruptRequested: this.interruptRequested,
|
|
63314
|
-
notificationQueue: Promise.resolve(),
|
|
63315
|
-
operationId: options.operationId,
|
|
63316
|
-
resolve: resolveTurn,
|
|
63317
|
-
terminalNotificationReceived: false,
|
|
63318
|
-
transportInterrupted: false
|
|
63319
|
-
};
|
|
63320
|
-
this.activeTurn = activeTurn;
|
|
63321
|
-
const turnParams = {
|
|
63322
|
-
input: options.input,
|
|
63323
|
-
threadId
|
|
63324
|
-
};
|
|
63325
|
-
this.canFallback = false;
|
|
63326
|
-
activeTurn.turnId = (await this.options.client.request("turn/start", turnParams))?.turn?.id;
|
|
63327
|
-
if (!activeTurn.turnId) throw new Error("Codex app-server returned no turn id");
|
|
63328
|
-
if (activeTurn.interruptRequested || this.closedByHost) await this.requestInterrupt(activeTurn);
|
|
63329
|
-
if (this.closedByHost) return;
|
|
63330
|
-
this.emitStatus("running", options.operationId);
|
|
63331
|
-
await activeTurn.completion;
|
|
63332
|
-
await activeTurn.notificationQueue;
|
|
63333
|
-
if (this.closedByHost) return;
|
|
63334
|
-
if (activeTurn.notificationError) throw activeTurn.notificationError;
|
|
63335
|
-
if (activeTurn.transportInterrupted) {
|
|
63336
|
-
this.cumulativeUsage = adapter.cumulativeUsage;
|
|
63337
|
-
this.emitStatus("idle", options.operationId);
|
|
63338
|
-
return;
|
|
63339
|
-
}
|
|
63340
|
-
await this.emitEvents(adapter.flush(), options.operationId);
|
|
63341
|
-
this.cumulativeUsage = adapter.cumulativeUsage;
|
|
63342
|
-
this.emitStatus("idle", options.operationId);
|
|
63362
|
+
let input = options.input;
|
|
63363
|
+
let stepIndex = 0;
|
|
63364
|
+
while (input && !this.closedByHost) {
|
|
63365
|
+
const result = await this.runNativeTurn(options, threadId, input, stepIndex);
|
|
63366
|
+
input = result?.input;
|
|
63367
|
+
stepIndex = result?.stepIndex ?? 0;
|
|
63368
|
+
}
|
|
63369
|
+
if (!this.closedByHost) this.emitStatus("idle", options.operationId);
|
|
63343
63370
|
} catch (error) {
|
|
63344
63371
|
if (this.closedByHost) return;
|
|
63345
63372
|
if (this.activeTurn?.transportInterrupted) {
|
|
@@ -63362,6 +63389,57 @@ var CodexThreadSession = class {
|
|
|
63362
63389
|
this.running = false;
|
|
63363
63390
|
}
|
|
63364
63391
|
}
|
|
63392
|
+
async runNativeTurn(options, threadId, input, stepIndex) {
|
|
63393
|
+
const adapter = new CodexAppServerAdapter({
|
|
63394
|
+
initialCumulativeUsage: this.cumulativeUsage,
|
|
63395
|
+
initialModel: this.model,
|
|
63396
|
+
initialStepIndex: stepIndex,
|
|
63397
|
+
sessionId: this.options.threadParams.ephemeral ? void 0 : threadId
|
|
63398
|
+
});
|
|
63399
|
+
let resolveTurn;
|
|
63400
|
+
const completion = new Promise((resolve) => {
|
|
63401
|
+
resolveTurn = resolve;
|
|
63402
|
+
});
|
|
63403
|
+
const activeTurn = {
|
|
63404
|
+
adapter,
|
|
63405
|
+
askUserBridge: options.askUserBridge,
|
|
63406
|
+
asyncQuestions: /* @__PURE__ */ new Map(),
|
|
63407
|
+
completion,
|
|
63408
|
+
interruptRequested: this.interruptRequested,
|
|
63409
|
+
notificationQueue: Promise.resolve(),
|
|
63410
|
+
operationId: options.operationId,
|
|
63411
|
+
resolve: resolveTurn,
|
|
63412
|
+
synchronousQuestions: /* @__PURE__ */ new Set(),
|
|
63413
|
+
terminalNotificationReceived: false,
|
|
63414
|
+
transportInterrupted: false
|
|
63415
|
+
};
|
|
63416
|
+
this.activeTurn = activeTurn;
|
|
63417
|
+
const turnParams = {
|
|
63418
|
+
input,
|
|
63419
|
+
threadId
|
|
63420
|
+
};
|
|
63421
|
+
this.canFallback = false;
|
|
63422
|
+
activeTurn.turnId = (await this.options.client.request("turn/start", turnParams))?.turn?.id;
|
|
63423
|
+
if (!activeTurn.turnId) throw new Error("Codex app-server returned no turn id");
|
|
63424
|
+
if (activeTurn.interruptRequested || this.closedByHost) await this.requestInterrupt(activeTurn);
|
|
63425
|
+
if (this.closedByHost) return;
|
|
63426
|
+
if (stepIndex === 0) this.emitStatus("running", options.operationId);
|
|
63427
|
+
await activeTurn.completion;
|
|
63428
|
+
await activeTurn.notificationQueue;
|
|
63429
|
+
if (this.closedByHost) return;
|
|
63430
|
+
if (activeTurn.notificationError) throw activeTurn.notificationError;
|
|
63431
|
+
const continuation = activeTurn.deferredCompletion ? await this.finishAsyncQuestions(activeTurn, activeTurn.deferredCompletion) : void 0;
|
|
63432
|
+
if (!activeTurn.transportInterrupted) await this.emitEvents(adapter.flush(), options.operationId);
|
|
63433
|
+
this.cumulativeUsage = adapter.cumulativeUsage;
|
|
63434
|
+
return continuation ? {
|
|
63435
|
+
input: [{
|
|
63436
|
+
text: continuation,
|
|
63437
|
+
text_elements: [],
|
|
63438
|
+
type: "text"
|
|
63439
|
+
}],
|
|
63440
|
+
stepIndex: adapter.nextStepIndex
|
|
63441
|
+
} : void 0;
|
|
63442
|
+
}
|
|
63365
63443
|
/**
|
|
63366
63444
|
* Add a user message to the running turn (`turn/steer`). The model reads it
|
|
63367
63445
|
* at its next step; the app-server reports it back as a `userMessage` item
|
|
@@ -63372,7 +63450,7 @@ var CodexThreadSession = class {
|
|
|
63372
63450
|
async steer(input, clientUserMessageId) {
|
|
63373
63451
|
const activeTurn = this.activeTurn;
|
|
63374
63452
|
const threadId = this.threadId;
|
|
63375
|
-
if (!activeTurn?.turnId || !threadId || activeTurn.interruptRequested || this.closedByHost) return "rejected";
|
|
63453
|
+
if (!activeTurn?.turnId || !threadId || activeTurn.terminalNotificationReceived || activeTurn.interruptRequested || this.closedByHost) return "rejected";
|
|
63376
63454
|
try {
|
|
63377
63455
|
const params = {
|
|
63378
63456
|
clientUserMessageId,
|
|
@@ -63394,7 +63472,7 @@ var CodexThreadSession = class {
|
|
|
63394
63472
|
if (!activeTurn) return;
|
|
63395
63473
|
activeTurn.interruptRequested = true;
|
|
63396
63474
|
activeTurn.askUserBridge?.cancelAll("session_ended");
|
|
63397
|
-
if (!activeTurn.turnId) return;
|
|
63475
|
+
if (!activeTurn.turnId || activeTurn.terminalNotificationReceived) return;
|
|
63398
63476
|
try {
|
|
63399
63477
|
await this.requestInterrupt(activeTurn);
|
|
63400
63478
|
} catch (error) {
|
|
@@ -63408,7 +63486,7 @@ var CodexThreadSession = class {
|
|
|
63408
63486
|
this.interruptRequested = true;
|
|
63409
63487
|
if (this.activeTurn) {
|
|
63410
63488
|
this.activeTurn.interruptRequested = true;
|
|
63411
|
-
if (this.activeTurn.turnId) this.requestInterrupt(this.activeTurn).catch((error) => {
|
|
63489
|
+
if (this.activeTurn.turnId && !this.activeTurn.terminalNotificationReceived) this.requestInterrupt(this.activeTurn).catch((error) => {
|
|
63412
63490
|
console.error("Failed to interrupt Codex turn while closing the session:", error);
|
|
63413
63491
|
});
|
|
63414
63492
|
this.interruptActiveTurn();
|
|
@@ -63511,10 +63589,11 @@ var CodexThreadSession = class {
|
|
|
63511
63589
|
activeTurn.notificationQueue = activeTurn.notificationQueue.then(() => this.emitEvents(activeTurn.adapter.startUserInput(request.itemId, args), activeTurn.operationId));
|
|
63512
63590
|
await activeTurn.notificationQueue;
|
|
63513
63591
|
if (activeTurn.interruptRequested || activeTurn.terminalNotificationReceived || activeTurn.transportInterrupted) return { answers: {} };
|
|
63592
|
+
activeTurn.synchronousQuestions.add(request.itemId);
|
|
63514
63593
|
const answer = await bridge.pending({
|
|
63515
63594
|
arguments: args,
|
|
63516
63595
|
toolCallId: request.itemId
|
|
63517
|
-
}, request.autoResolutionMs ? { timeoutMs: request.autoResolutionMs } : {});
|
|
63596
|
+
}, request.autoResolutionMs ? { timeoutMs: request.autoResolutionMs } : {}).finally(() => activeTurn.synchronousQuestions.delete(request.itemId));
|
|
63518
63597
|
activeTurn.notificationQueue = activeTurn.notificationQueue.then(() => this.emitEvents(activeTurn.adapter.completeUserInput(request.itemId, answer), activeTurn.operationId));
|
|
63519
63598
|
await activeTurn.notificationQueue;
|
|
63520
63599
|
return codexUserInputResponse(request, answer);
|
|
@@ -63522,12 +63601,12 @@ var CodexThreadSession = class {
|
|
|
63522
63601
|
handleDisconnect() {
|
|
63523
63602
|
if (this.closedByHost) return;
|
|
63524
63603
|
this.attached = false;
|
|
63525
|
-
if (this.activeTurn && !this.activeTurn.terminalNotificationReceived) this.interruptActiveTurn();
|
|
63604
|
+
if (this.activeTurn && (!this.activeTurn.terminalNotificationReceived || this.activeTurn.asyncQuestions.size > 0)) this.interruptActiveTurn();
|
|
63526
63605
|
}
|
|
63527
63606
|
requestInterrupt(activeTurn) {
|
|
63528
63607
|
const threadId = this.threadId;
|
|
63529
63608
|
const turnId = activeTurn.turnId;
|
|
63530
|
-
if (!threadId || !turnId) return Promise.resolve();
|
|
63609
|
+
if (!threadId || !turnId || activeTurn.terminalNotificationReceived) return Promise.resolve();
|
|
63531
63610
|
if (activeTurn.interruptRequest) return activeTurn.interruptRequest;
|
|
63532
63611
|
const params = {
|
|
63533
63612
|
threadId,
|
|
@@ -63549,11 +63628,21 @@ var CodexThreadSession = class {
|
|
|
63549
63628
|
if (method === "turn/completed") {
|
|
63550
63629
|
if (params.turn.status !== "inProgress") {
|
|
63551
63630
|
activeTurn.terminalNotificationReceived = true;
|
|
63552
|
-
activeTurn.askUserBridge?.
|
|
63631
|
+
for (const id of activeTurn.synchronousQuestions) activeTurn.askUserBridge?.cancel(id, "session_ended");
|
|
63553
63632
|
}
|
|
63554
63633
|
}
|
|
63555
63634
|
activeTurn.notificationQueue = activeTurn.notificationQueue.then(async () => {
|
|
63556
63635
|
if (activeTurn.notificationError) return;
|
|
63636
|
+
if (method === "item/completed" && await this.startAsyncQuestion(activeTurn, params)) return;
|
|
63637
|
+
if (method === "turn/completed") {
|
|
63638
|
+
const notification = params;
|
|
63639
|
+
if (notification.turn.status === "completed" && activeTurn.asyncQuestions.size > 0 && !activeTurn.transportInterrupted) {
|
|
63640
|
+
activeTurn.deferredCompletion = notification;
|
|
63641
|
+
activeTurn.resolve();
|
|
63642
|
+
return;
|
|
63643
|
+
}
|
|
63644
|
+
if (notification.turn.status !== "inProgress") activeTurn.askUserBridge?.cancelAll("session_ended");
|
|
63645
|
+
}
|
|
63557
63646
|
await this.emitEvents(activeTurn.adapter.adapt(method, params), activeTurn.operationId);
|
|
63558
63647
|
if (method !== "turn/completed") return;
|
|
63559
63648
|
const notification = params;
|
|
@@ -63565,6 +63654,52 @@ var CodexThreadSession = class {
|
|
|
63565
63654
|
});
|
|
63566
63655
|
return activeTurn.notificationQueue;
|
|
63567
63656
|
}
|
|
63657
|
+
async startAsyncQuestion(activeTurn, params) {
|
|
63658
|
+
const bridge = activeTurn.askUserBridge;
|
|
63659
|
+
if (!bridge || bridge.operationId !== activeTurn.operationId) return false;
|
|
63660
|
+
const request = readCodexAsyncQuestion(params);
|
|
63661
|
+
if (!request) return false;
|
|
63662
|
+
if (activeTurn.asyncQuestions.has(request.itemId)) return true;
|
|
63663
|
+
if (activeTurn.interruptRequested || activeTurn.transportInterrupted) return false;
|
|
63664
|
+
const { itemId } = request;
|
|
63665
|
+
const args = codexUserInputArguments(request);
|
|
63666
|
+
await this.emitEvents(activeTurn.adapter.startUserInput(itemId, args), activeTurn.operationId);
|
|
63667
|
+
if (activeTurn.interruptRequested || activeTurn.transportInterrupted) return true;
|
|
63668
|
+
const answer = bridge.pending({
|
|
63669
|
+
arguments: args,
|
|
63670
|
+
toolCallId: itemId
|
|
63671
|
+
}).catch((error) => {
|
|
63672
|
+
this.recordNotificationError(activeTurn, error);
|
|
63673
|
+
return { cancelled: true };
|
|
63674
|
+
});
|
|
63675
|
+
activeTurn.asyncQuestions.set(itemId, {
|
|
63676
|
+
answer,
|
|
63677
|
+
request
|
|
63678
|
+
});
|
|
63679
|
+
return true;
|
|
63680
|
+
}
|
|
63681
|
+
async finishAsyncQuestions(activeTurn, notification) {
|
|
63682
|
+
const { adapter, asyncQuestions, operationId } = activeTurn;
|
|
63683
|
+
const answers = await Promise.all([...asyncQuestions.values()].map(async ({ answer, request }) => ({
|
|
63684
|
+
answer: await answer,
|
|
63685
|
+
request
|
|
63686
|
+
})));
|
|
63687
|
+
if (activeTurn.notificationError) throw activeTurn.notificationError;
|
|
63688
|
+
if (this.closedByHost || activeTurn.transportInterrupted) {
|
|
63689
|
+
await activeTurn.notificationQueue;
|
|
63690
|
+
return;
|
|
63691
|
+
}
|
|
63692
|
+
const replies = [];
|
|
63693
|
+
for (const { answer, request } of answers) {
|
|
63694
|
+
await this.emitEvents(adapter.completeUserInput(request.itemId, answer), operationId);
|
|
63695
|
+
replies.push(...codexAsyncAnswers(request, answer));
|
|
63696
|
+
}
|
|
63697
|
+
const turnEnded = ({ type }) => type === "agent_runtime_end" || type === "visible_output_end";
|
|
63698
|
+
const events = adapter.adapt("turn/completed", notification);
|
|
63699
|
+
await this.emitEvents(events.filter((event) => !turnEnded(event)), operationId);
|
|
63700
|
+
if (!activeTurn.interruptRequested && !activeTurn.transportInterrupted && replies.length > 0) return formatCodexAsyncReplies(replies);
|
|
63701
|
+
await this.emitEvents(events.filter(turnEnded), operationId);
|
|
63702
|
+
}
|
|
63568
63703
|
isCurrentTurnNotification(method, params, activeTurn) {
|
|
63569
63704
|
if (!isRecord$7(params)) return false;
|
|
63570
63705
|
const notificationTurnId = method === "turn/started" || method === "turn/completed" ? isRecord$7(params.turn) ? pickString$1(params.turn.id) : void 0 : pickString$1(params.turnId);
|
package/man/man1/lh.1
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
.\" Code generated by `npm run man:generate`; DO NOT EDIT.
|
|
2
2
|
.\" Manual command details come from the Commander command tree.
|
|
3
|
-
.TH LH 1 "" "@lobehub/cli 0.0.
|
|
3
|
+
.TH LH 1 "" "@lobehub/cli 0.0.123" "User Commands"
|
|
4
4
|
.SH NAME
|
|
5
5
|
lh \- LobeHub CLI \- manage and connect to LobeHub services
|
|
6
6
|
.SH SYNOPSIS
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.123",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/lobehub/lobehub",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"access": "public",
|
|
84
84
|
"registry": "https://registry.npmjs.org"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "d3e62bb84862c92a421df8803098e0cf049a66a3"
|
|
87
87
|
}
|