@codex-app-sdk/backend 0.18.0 → 0.18.2

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 CHANGED
@@ -2065,7 +2065,12 @@ function tr(e, t, n, r, i) {
2065
2065
  summaryIndex: t
2066
2066
  } : null;
2067
2067
  }).filter((e) => e !== null);
2068
- if (a.length === 0) return [...e];
2068
+ a.length === 0 && a.push({
2069
+ type: "reasoning",
2070
+ summary: "",
2071
+ itemId: r,
2072
+ summaryIndex: 0
2073
+ });
2069
2074
  let o = U(e, t, n), s = K(o, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), c = s >= 0 ? o[s] : void 0;
2070
2075
  if (!c) return o;
2071
2076
  let l = c.parts.findIndex((e) => e.type === "reasoning" && e.itemId === r), u = c.parts.filter((e) => e.type !== "reasoning" || e.itemId !== r);
@@ -2347,7 +2352,7 @@ function yr(e, t) {
2347
2352
  });
2348
2353
  }
2349
2354
  function br(e, t) {
2350
- let n = [], r = [], i = Rr(t.startedAt ?? t.completedAt), a = 0, o = !1, s = /* @__PURE__ */ new Set(), c = () => {
2355
+ let n = [], r = [], i = Rr(t.startedAt ?? t.completedAt), a = 0, o = !1, s = !1, c = /* @__PURE__ */ new Set(), l = () => {
2351
2356
  if (r.length === 0) return;
2352
2357
  let o = a === 0 ? "" : `-segment-${a}`;
2353
2358
  n.push({
@@ -2365,11 +2370,11 @@ function br(e, t) {
2365
2370
  };
2366
2371
  for (let a of Array.isArray(t.items) ? t.items : []) {
2367
2372
  if (a.type === "userMessage") {
2368
- let r = Tr(a), l = Dr(a);
2373
+ let r = Tr(a), s = Dr(a);
2369
2374
  if (r.length > 0) {
2370
2375
  let u = o, d = u ? null : JSON.stringify(r);
2371
- if (d && s.has(d)) continue;
2372
- d && s.add(d), c(), n.push({
2376
+ if (d && c.has(d)) continue;
2377
+ d && c.add(d), l(), n.push({
2373
2378
  id: a.clientId ?? `user-${e}-${t.id}-${a.id ?? n.length}`,
2374
2379
  ...u ? { kind: "steer" } : {},
2375
2380
  role: "user",
@@ -2380,8 +2385,8 @@ function br(e, t) {
2380
2385
  metadata: {
2381
2386
  conversationId: e,
2382
2387
  turnId: t.id,
2383
- ...l.length > 0 ? {
2384
- asyncQuestionRequestIds: l,
2388
+ ...s.length > 0 ? {
2389
+ asyncQuestionRequestIds: s,
2385
2390
  asyncQuestionAnswers: Or(a)
2386
2391
  } : {}
2387
2392
  }
@@ -2390,7 +2395,7 @@ function br(e, t) {
2390
2395
  continue;
2391
2396
  }
2392
2397
  if (a.type === "contextCompaction") {
2393
- o = !0, c();
2398
+ o = !0, l();
2394
2399
  let r = `compaction-${t.id}`;
2395
2400
  n.some((e) => e.id === r) || n.push({
2396
2401
  id: r,
@@ -2408,10 +2413,12 @@ function br(e, t) {
2408
2413
  continue;
2409
2414
  }
2410
2415
  if (a.type === "agentMessage") {
2411
- let n = typeof a.text == "string" ? a.text : "", i = Sr(e, t.id, a, !0), s = a.phase === "final_answer" ? ir(n) : null;
2412
- s && !i ? s.visibleText && (o = !0, r.push({
2416
+ let n = typeof a.text == "string" ? a.text : "";
2417
+ a.phase === "final_answer" && n.trim() && (s = !0);
2418
+ let i = Sr(e, t.id, a, !0), c = a.phase === "final_answer" ? ir(n) : null;
2419
+ c && !i ? c.visibleText && (o = !0, r.push({
2413
2420
  type: "text",
2414
- text: s.visibleText,
2421
+ text: c.visibleText,
2415
2422
  itemId: a.id,
2416
2423
  ...a.phase ? { phase: a.phase } : {}
2417
2424
  })) : n && !i && (o = !0, r.push({
@@ -2427,7 +2434,10 @@ function br(e, t) {
2427
2434
  summary: e.trim(),
2428
2435
  summaryIndex: t
2429
2436
  })).filter(({ summary: e }) => e.length > 0);
2430
- e.length > 0 && (o = !0, r.push(...e.map(({ summary: e, summaryIndex: t }) => ({
2437
+ e.length === 0 && s && e.push({
2438
+ summary: "",
2439
+ summaryIndex: 0
2440
+ }), e.length > 0 && (o = !0, r.push(...e.map(({ summary: e, summaryIndex: t }) => ({
2431
2441
  type: "reasoning",
2432
2442
  summary: e,
2433
2443
  itemId: a.id,
@@ -2444,12 +2454,12 @@ function br(e, t) {
2444
2454
  }));
2445
2455
  continue;
2446
2456
  }
2447
- let l = R(a);
2448
- l && (o = !0, r.push(l));
2449
- let u = wr(a);
2450
- u.length && (o = !0, r.push(...u));
2457
+ let u = R(a);
2458
+ u && (o = !0, r.push(u));
2459
+ let d = wr(a);
2460
+ d.length && (o = !0, r.push(...d));
2451
2461
  }
2452
- return c(), t.status === "inProgress" ? n : ur(n, t.id, t.status);
2462
+ return l(), t.status === "inProgress" ? n : ur(n, t.id, t.status);
2453
2463
  }
2454
2464
  function xr(e, t, n) {
2455
2465
  let r = Rr(t.startedAt);
@@ -2694,7 +2704,7 @@ function kr(e) {
2694
2704
  }
2695
2705
  function Ar(e) {
2696
2706
  if (!q(e) || typeof e.type != "string") return null;
2697
- if (e.type === "mention" && typeof e.path == "string") {
2707
+ if (e.type === "mention" && typeof e.path == "string" && !e.path.startsWith("plugin://")) {
2698
2708
  let t = typeof e.name == "string" && e.name.trim() ? e.name.trim() : jr(e.path, "File"), n = Mr(e.path);
2699
2709
  return {
2700
2710
  kind: "file",
@@ -3158,7 +3168,6 @@ var ri = class {
3158
3168
  return;
3159
3169
  }
3160
3170
  if (e.item.type === "reasoning") {
3161
- if (e.item.summary.filter((e) => e.trim().length > 0).length === 0) return;
3162
3171
  let t = this.host.assistantMessageForTurn(e.threadId, e.turnId), r = t ? JSON.stringify(t.parts) : null;
3163
3172
  this.host.patchRuntime(e.threadId, { messages: tr(n.messages, e.threadId, e.turnId, e.item.id, e.item.summary) });
3164
3173
  let i = this.host.assistantMessageForTurn(e.threadId, e.turnId);
@@ -3201,7 +3210,7 @@ var ri = class {
3201
3210
  if (e.item.type === "agentMessage" && this.reviewOutputByTurn.get(i) === t) return;
3202
3211
  e.item.type === "exitedReviewMode" && this.reviewOutputByTurn.set(i, t);
3203
3212
  let a = new Set(n.messages.map((e) => e.id)), o = this.host.assistantMessageForTurn(e.threadId, e.turnId), s = o ? JSON.stringify(o.parts) : null, c = new Set(o?.parts.flatMap((e) => e.type === "question" ? [e.request.id] : []) ?? []), l = n.messages.flatMap((e) => e.parts).find((t) => t.type === "text" && t.itemId === e.item.id)?.text ?? "", u = e.item.type === "agentMessage" ? Sr(e.threadId, e.turnId, e.item) : null, d = u ? "" : t, f = u ? rr(n.messages, e.threadId, e.turnId, e.item.id) : nr(n.messages, e.threadId, e.turnId, e.item.id, t, r);
3204
- if (u && (f = or(f, e.threadId, e.turnId, u)), this.host.patchRuntime(e.threadId, { messages: f }), !d && !u) return;
3213
+ if (u && (f = or(f, e.threadId, e.turnId, u)), this.host.patchRuntime(e.threadId, { messages: f }), !d && !u && !r) return;
3205
3214
  let p = this.host.assistantMessageForTurn(e.threadId, e.turnId);
3206
3215
  if (p && !a.has(p.id)) this.host.emitEvent("notification", {
3207
3216
  type: "message.appended",
@@ -3209,7 +3218,7 @@ var ri = class {
3209
3218
  turnId: e.turnId,
3210
3219
  payload: { message: structuredClone(p) }
3211
3220
  });
3212
- else if (p && u && JSON.stringify(p.parts) !== s) this.host.emitEvent("notification", {
3221
+ else if (p && JSON.stringify(p.parts) !== s && (u || d === l)) this.host.emitEvent("notification", {
3213
3222
  type: "message.updated",
3214
3223
  conversationId: e.threadId,
3215
3224
  turnId: e.turnId,
@@ -3512,9 +3521,7 @@ var oi = class {
3512
3521
  }), this.host.emitConversationActivity(n.threadId, "action");
3513
3522
  }
3514
3523
  async respondToAsyncQuestion(e, t) {
3515
- let n = e ?? this.host.activeConversationId(), r = n === null ? null : this.host.requireRuntime(n), i = null;
3516
- for (let e of r?.messages ?? []) for (let n of e.parts) n.type === "question" && !n.historical && n.request.id === t.id && (i = n.request);
3517
- let a = r && i ? {
3524
+ let n = e ?? this.host.activeConversationId(), r = n === null ? null : this.host.requireRuntime(n), i = r && Ct(r, [], []).clientRequests.find((e) => e.kind === "ask_user" && e.id === t.id), a = r && i ? {
3518
3525
  request: i,
3519
3526
  runtime: r
3520
3527
  } : null;
@@ -6155,7 +6162,8 @@ var Ui = class {
6155
6162
  return [...this.require(e).messages].reverse().find((e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === t) ?? null;
6156
6163
  }
6157
6164
  markTurnActive(e, t) {
6158
- e.activeTurnId = t, e.busy = !0, e.turnStartPending = !1, e.turnIds.includes(t) || e.turnIds.push(t), e.turns = Z(e.turns, {
6165
+ let n = e.turnIds.includes(t) ? [] : this.projection(e).clientRequests.filter((e) => e.kind === "ask_user" && e.payload.request.delivery === "async" && e.turnId && e.turnId !== t);
6166
+ if (e.activeTurnId = t, e.busy = !0, e.turnStartPending = !1, e.turnIds.includes(t) || e.turnIds.push(t), e.turns = Z(e.turns, {
6159
6167
  id: t,
6160
6168
  status: "inProgress",
6161
6169
  error: null,
@@ -6163,7 +6171,19 @@ var Ui = class {
6163
6171
  startedAt: null,
6164
6172
  completedAt: null,
6165
6173
  durationMs: null
6166
- });
6174
+ }), n.length > 0) {
6175
+ this.patch(e.threadId, { answeredClientRequestIds: [.../* @__PURE__ */ new Set([...e.answeredClientRequestIds, ...n.map((e) => e.id)])] });
6176
+ for (let t of n) this.host.emitEvent("notification", {
6177
+ type: "clientRequest.resolved",
6178
+ conversationId: e.threadId,
6179
+ turnId: t.turnId ?? void 0,
6180
+ payload: {
6181
+ request: structuredClone(t),
6182
+ response: null,
6183
+ reason: "server"
6184
+ }
6185
+ });
6186
+ }
6167
6187
  }
6168
6188
  patchConversationStatus(e, t, n = "notification") {
6169
6189
  let r = this.host.getState();