@super-one/cli 0.51.0-alpha → 0.51.1-alpha

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.
Files changed (3) hide show
  1. package/MANIFEST.json +2 -2
  2. package/lib/cli.mjs +1028 -341
  3. package/package.json +1 -1
package/lib/cli.mjs CHANGED
@@ -3485,6 +3485,31 @@ var init_session_messages = __esm({
3485
3485
  }
3486
3486
  });
3487
3487
 
3488
+ // ../../packages/shared/src/environment/provider-resume.ts
3489
+ function providerSessionIdFromResume(providerResume) {
3490
+ const raw = typeof providerResume === "string" ? providerResume.trim() : "";
3491
+ if (!raw) return null;
3492
+ for (const prefix of RESUME_PREFIXES) {
3493
+ if (raw.startsWith(prefix)) {
3494
+ const id = raw.slice(prefix.length).trim();
3495
+ return id.length > 0 ? id : null;
3496
+ }
3497
+ }
3498
+ return raw;
3499
+ }
3500
+ var RESUME_PREFIXES;
3501
+ var init_provider_resume = __esm({
3502
+ "../../packages/shared/src/environment/provider-resume.ts"() {
3503
+ "use strict";
3504
+ RESUME_PREFIXES = [
3505
+ "claude-session:",
3506
+ "thread:",
3507
+ "acp-session:",
3508
+ "opencode:"
3509
+ ];
3510
+ }
3511
+ });
3512
+
3488
3513
  // ../../packages/shared/src/environment/lease.ts
3489
3514
  var init_lease = __esm({
3490
3515
  "../../packages/shared/src/environment/lease.ts"() {
@@ -3590,6 +3615,7 @@ var init_environment = __esm({
3590
3615
  init_events();
3591
3616
  init_session_events();
3592
3617
  init_session_messages();
3618
+ init_provider_resume();
3593
3619
  init_lease();
3594
3620
  init_gateway();
3595
3621
  init_connection_supervisor_core();
@@ -10612,7 +10638,145 @@ var init_src2 = __esm({
10612
10638
  }
10613
10639
  });
10614
10640
 
10615
- // ../../packages/runtime/src/session/message-catalog.ts
10641
+ // ../../packages/shared/src/content-delta.ts
10642
+ function parseInputObject(input) {
10643
+ if (input == null || input === "") return {};
10644
+ if (typeof input === "object" && !Array.isArray(input)) {
10645
+ return input;
10646
+ }
10647
+ if (typeof input !== "string" || !input.trim()) return {};
10648
+ try {
10649
+ const parsed = JSON.parse(input);
10650
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
10651
+ } catch {
10652
+ return {};
10653
+ }
10654
+ }
10655
+ function mergeToolUseInputJson(existing, incoming) {
10656
+ const prev = parseInputObject(existing);
10657
+ const next = parseInputObject(incoming);
10658
+ const asString7 = typeof existing === "string" || typeof incoming === "string";
10659
+ if (Object.keys(next).length === 0) {
10660
+ if (existing != null && existing !== "") return existing;
10661
+ return asString7 ? typeof incoming === "string" ? incoming : "{}" : incoming ?? {};
10662
+ }
10663
+ if (Object.keys(prev).length === 0) {
10664
+ return asString7 ? typeof incoming === "string" ? incoming : JSON.stringify(next) : next;
10665
+ }
10666
+ const merged = { ...prev, ...next };
10667
+ for (const key of SUMMARY_INPUT_KEYS) {
10668
+ const n = merged[key];
10669
+ const empty = n == null || n === "";
10670
+ if (empty && prev[key] != null && prev[key] !== "") {
10671
+ merged[key] = prev[key];
10672
+ }
10673
+ }
10674
+ if (!asString7) return merged;
10675
+ try {
10676
+ return JSON.stringify(merged);
10677
+ } catch {
10678
+ return typeof incoming === "string" ? incoming : "{}";
10679
+ }
10680
+ }
10681
+ function pickRicherToolSummary(existing, incoming, mergedInput) {
10682
+ const input = parseInputObject(mergedInput);
10683
+ for (const key of ["query", "pattern", "command", "description"]) {
10684
+ const v2 = input[key];
10685
+ if (typeof v2 === "string" && v2.trim()) return v2.trim();
10686
+ }
10687
+ const a = existing?.trim() || "";
10688
+ const b2 = incoming?.trim() || "";
10689
+ const placeholders = /* @__PURE__ */ new Set(["Web search:", "web_search", "grep", "Grep", "Search"]);
10690
+ if (b2 && !placeholders.has(b2)) return b2;
10691
+ if (a && !placeholders.has(a)) return a;
10692
+ return b2 || a || void 0;
10693
+ }
10694
+ function sameParent(a, b2) {
10695
+ const ap = "parentToolUseId" in a ? a.parentToolUseId ?? null : null;
10696
+ const bp = "parentToolUseId" in b2 ? b2.parentToolUseId ?? null : null;
10697
+ return ap === bp;
10698
+ }
10699
+ function lastMergeTargetIndex(content, delta) {
10700
+ for (let i = content.length - 1; i >= 0; i--) {
10701
+ const b2 = content[i];
10702
+ if (!sameParent(b2, delta)) continue;
10703
+ if (b2.type === "tool_result") continue;
10704
+ return i;
10705
+ }
10706
+ return -1;
10707
+ }
10708
+ function applyContentDelta(content, delta) {
10709
+ if (delta.type === "text") {
10710
+ const idx = lastMergeTargetIndex(content, delta);
10711
+ const target = idx === -1 ? void 0 : content[idx];
10712
+ if (target?.type === "text") {
10713
+ return content.map((b2, i) => i === idx ? { ...target, text: target.text + delta.text } : b2);
10714
+ }
10715
+ }
10716
+ if (delta.type === "thinking") {
10717
+ const idx = lastMergeTargetIndex(content, delta);
10718
+ const target = idx === -1 ? void 0 : content[idx];
10719
+ if (target?.type === "thinking") {
10720
+ return content.map((b2, i) => i === idx ? { ...target, thinking: target.thinking + delta.thinking, endedAt: delta.endedAt ?? target.endedAt } : b2);
10721
+ }
10722
+ }
10723
+ if (delta.type === "tool_use") {
10724
+ const idx = content.findIndex((b2) => b2.type === "tool_use" && b2.toolUseId === delta.toolUseId);
10725
+ if (idx !== -1) {
10726
+ const existing = content[idx];
10727
+ if (existing.type !== "tool_use") {
10728
+ return content.map((b2, i) => i === idx ? { ...delta, startedAt: Date.now() } : b2);
10729
+ }
10730
+ const mergedInput = mergeToolUseInputJson(existing.input, delta.input);
10731
+ const mergedSummary = pickRicherToolSummary(
10732
+ existing.toolSummary,
10733
+ delta.toolSummary,
10734
+ mergedInput
10735
+ );
10736
+ return content.map((b2, i) => i === idx ? {
10737
+ ...existing,
10738
+ ...delta,
10739
+ startedAt: existing.startedAt,
10740
+ elapsedSeconds: delta.elapsedSeconds ?? existing.elapsedSeconds,
10741
+ status: delta.status ?? existing.status,
10742
+ // ContentBlock.input is typed as string; object form is test/legacy only.
10743
+ input: mergedInput,
10744
+ toolSummary: mergedSummary,
10745
+ toolFilePath: delta.toolFilePath || existing.toolFilePath
10746
+ } : b2);
10747
+ }
10748
+ return [...content, { ...delta, startedAt: Date.now() }];
10749
+ }
10750
+ if (delta.type === "tool_result") {
10751
+ const updated = content.map(
10752
+ (b2) => b2.type === "tool_use" && b2.toolUseId === delta.toolUseId ? { ...b2, status: "complete" } : b2
10753
+ );
10754
+ return [...updated, delta];
10755
+ }
10756
+ return [...content, delta];
10757
+ }
10758
+ var SUMMARY_INPUT_KEYS;
10759
+ var init_content_delta = __esm({
10760
+ "../../packages/shared/src/content-delta.ts"() {
10761
+ "use strict";
10762
+ SUMMARY_INPUT_KEYS = [
10763
+ "query",
10764
+ "pattern",
10765
+ "command",
10766
+ "description",
10767
+ "file_path",
10768
+ "path",
10769
+ "url",
10770
+ "prompt",
10771
+ "skill",
10772
+ "tool_name",
10773
+ "subject",
10774
+ "task_id"
10775
+ ];
10776
+ }
10777
+ });
10778
+
10779
+ // ../../packages/shared/src/node-session-event-map.ts
10616
10780
  function asRecord5(value) {
10617
10781
  if (value && typeof value === "object" && !Array.isArray(value)) {
10618
10782
  return value;
@@ -10622,6 +10786,461 @@ function asRecord5(value) {
10622
10786
  function asString2(value) {
10623
10787
  return typeof value === "string" ? value : void 0;
10624
10788
  }
10789
+ function asBool(value) {
10790
+ return typeof value === "boolean" ? value : void 0;
10791
+ }
10792
+ function coerceToolInput(value) {
10793
+ if (typeof value === "string") return value;
10794
+ if (value == null) return "";
10795
+ try {
10796
+ return JSON.stringify(value);
10797
+ } catch {
10798
+ return "";
10799
+ }
10800
+ }
10801
+ function stamp(event, ctx, sequence) {
10802
+ const seqNum = sequence && /^\d+$/.test(sequence) ? Number(sequence) : void 0;
10803
+ return {
10804
+ ...event,
10805
+ ...ctx.projectPath ? { projectPath: ctx.projectPath } : {},
10806
+ sessionId: ctx.sessionId,
10807
+ ...seqNum !== void 0 && Number.isFinite(seqNum) ? { seq: seqNum } : {}
10808
+ };
10809
+ }
10810
+ function mapQuestionRequest(payload, fallbackId) {
10811
+ const interactionId = asString2(payload.interactionId) ?? asString2(payload.requestId) ?? fallbackId;
10812
+ const input = asRecord5(payload.input);
10813
+ const rawQuestions = Array.isArray(payload.questions) ? payload.questions : Array.isArray(input.questions) ? input.questions : [];
10814
+ const questions = [];
10815
+ for (const q of rawQuestions) {
10816
+ if (!q || typeof q !== "object") continue;
10817
+ const row = q;
10818
+ const question = asString2(row.question) ?? asString2(row.header) ?? "";
10819
+ if (!question) continue;
10820
+ const optionsRaw = Array.isArray(row.options) ? row.options : [];
10821
+ const options = optionsRaw.map((opt) => {
10822
+ if (!opt || typeof opt !== "object") return null;
10823
+ const o = opt;
10824
+ const label = asString2(o.label) ?? asString2(o.value) ?? "";
10825
+ if (!label) return null;
10826
+ return {
10827
+ label,
10828
+ description: asString2(o.description) ?? "",
10829
+ ...asString2(o.preview) ? { preview: asString2(o.preview) } : {}
10830
+ };
10831
+ }).filter((o) => o != null);
10832
+ questions.push({
10833
+ question,
10834
+ header: asString2(row.header) ?? question,
10835
+ options,
10836
+ multiSelect: row.multiSelect === true || row.multiple === true
10837
+ });
10838
+ }
10839
+ if (questions.length === 0) {
10840
+ questions.push({
10841
+ question: asString2(payload.toolName) ? `Respond to ${asString2(payload.toolName)}` : "Continue?",
10842
+ header: "Question",
10843
+ options: [{ label: "Yes", description: "" }, { label: "No", description: "" }],
10844
+ multiSelect: false
10845
+ });
10846
+ }
10847
+ return { requestId: interactionId, questions };
10848
+ }
10849
+ function mapPlanRequest(payload, fallbackId) {
10850
+ const interactionId = asString2(payload.interactionId) ?? asString2(payload.requestId) ?? fallbackId;
10851
+ const input = asRecord5(payload.input);
10852
+ let planContent = asString2(payload.plan) ?? asString2(payload.planContent) ?? asString2(input.plan) ?? asString2(input.planContent) ?? "";
10853
+ if (!planContent && input.plan && typeof input.plan === "object") {
10854
+ try {
10855
+ planContent = JSON.stringify(input.plan);
10856
+ } catch {
10857
+ planContent = "";
10858
+ }
10859
+ }
10860
+ return {
10861
+ requestId: interactionId,
10862
+ planContent: planContent || "Plan approval required",
10863
+ planFilePath: asString2(payload.planFilePath) ?? asString2(input.planFilePath) ?? "",
10864
+ allowedPrompts: Array.isArray(payload.allowedPrompts) ? payload.allowedPrompts : Array.isArray(input.allowedPrompts) ? input.allowedPrompts : []
10865
+ };
10866
+ }
10867
+ function userMessage(ctx, blockId, text, nowIso) {
10868
+ return {
10869
+ id: blockId,
10870
+ role: "user",
10871
+ status: "complete",
10872
+ content: text ? [{ type: "text", text }] : [],
10873
+ createdAt: nowIso,
10874
+ providerId: ctx.providerId ?? "codex"
10875
+ };
10876
+ }
10877
+ function assistantMessage(ctx, blockId, nowIso) {
10878
+ return {
10879
+ id: blockId,
10880
+ role: "assistant",
10881
+ status: "streaming",
10882
+ content: [],
10883
+ createdAt: nowIso,
10884
+ providerId: ctx.providerId ?? "codex"
10885
+ };
10886
+ }
10887
+ function mapAgentStatus(status, fallback) {
10888
+ if (status === "streaming" || status === "idle" || status === "error" || status === "background") {
10889
+ return status;
10890
+ }
10891
+ if (status === "interrupted" || status === "ended" || status === "unknown") return "idle";
10892
+ return fallback;
10893
+ }
10894
+ function createNodeSessionEventMapper(ctx) {
10895
+ const startedAssistantIds = /* @__PURE__ */ new Set();
10896
+ const completedAssistantIds = /* @__PURE__ */ new Set();
10897
+ let lastAssistantId = null;
10898
+ let rawTerminalThisTurn = false;
10899
+ const nowIso = ctx.nowIso ?? (() => (/* @__PURE__ */ new Date()).toISOString());
10900
+ const ensureAssistant = (push, preferredId) => {
10901
+ if (lastAssistantId) return lastAssistantId;
10902
+ const id = preferredId && preferredId.length > 0 ? preferredId : `assistant-${ctx.sessionId}`;
10903
+ if (!startedAssistantIds.has(id)) {
10904
+ startedAssistantIds.add(id);
10905
+ push({
10906
+ type: "message_start",
10907
+ message: assistantMessage(ctx, id, nowIso())
10908
+ });
10909
+ }
10910
+ lastAssistantId = id;
10911
+ return id;
10912
+ };
10913
+ const mapOne = (envelope) => {
10914
+ if (envelope.aggregateType && envelope.aggregateType !== "session") return [];
10915
+ if (envelope.aggregateId && envelope.aggregateId !== ctx.sessionId) return [];
10916
+ const eventType = envelope.eventType;
10917
+ const payload = asRecord5(envelope.payload);
10918
+ const out = [];
10919
+ const push = (event) => {
10920
+ out.push(stamp(event, ctx, envelope.sequence));
10921
+ };
10922
+ switch (eventType) {
10923
+ case SESSION_DURABLE_EVENT.userMessage: {
10924
+ if (ctx.skipUserMessage) break;
10925
+ const blockId = asString2(payload.blockId) ?? `user-${envelope.eventId}`;
10926
+ const text = asString2(payload.text) ?? "";
10927
+ push({
10928
+ type: "user_message_appended",
10929
+ message: userMessage(ctx, blockId, text, nowIso())
10930
+ });
10931
+ break;
10932
+ }
10933
+ case SESSION_DURABLE_EVENT.turnStarted: {
10934
+ lastAssistantId = null;
10935
+ rawTerminalThisTurn = false;
10936
+ push({
10937
+ type: "status_change",
10938
+ status: mapAgentStatus(asString2(payload.status), "streaming")
10939
+ });
10940
+ break;
10941
+ }
10942
+ case SESSION_DURABLE_EVENT.agentEvent: {
10943
+ const rawEvent = asRecord5(payload.event);
10944
+ const type = asString2(rawEvent.type);
10945
+ if (!type) break;
10946
+ const eventRecord = { ...rawEvent };
10947
+ delete eventRecord.projectPath;
10948
+ delete eventRecord.sessionId;
10949
+ delete eventRecord.draftSessionId;
10950
+ delete eventRecord.seq;
10951
+ delete eventRecord.epoch;
10952
+ const event = eventRecord;
10953
+ const rawMessageId = type === "message_start" ? asString2(asRecord5(eventRecord.message).id) : asString2(eventRecord.messageId);
10954
+ if (type === "message_start" && rawMessageId) {
10955
+ startedAssistantIds.add(rawMessageId);
10956
+ lastAssistantId = rawMessageId;
10957
+ } else if (rawMessageId) {
10958
+ ensureAssistant(push, rawMessageId);
10959
+ }
10960
+ push(event);
10961
+ if (rawMessageId && (type === "message_complete" || type === "message_error" || type === "message_interrupted")) {
10962
+ completedAssistantIds.add(rawMessageId);
10963
+ rawTerminalThisTurn = true;
10964
+ }
10965
+ break;
10966
+ }
10967
+ case SESSION_DURABLE_EVENT.assistantDelta: {
10968
+ const wireBlockId = asString2(payload.blockId);
10969
+ const messageId = ensureAssistant(push, wireBlockId ?? `assistant-${envelope.eventId}`);
10970
+ const delta = asString2(payload.delta) ?? asString2(payload.text) ?? "";
10971
+ if (delta) {
10972
+ push({
10973
+ type: "content_delta",
10974
+ messageId,
10975
+ delta: { type: "text", text: delta }
10976
+ });
10977
+ }
10978
+ break;
10979
+ }
10980
+ case SESSION_DURABLE_EVENT.assistantText: {
10981
+ const wireBlockId = asString2(payload.blockId);
10982
+ const text = asString2(payload.text) ?? "";
10983
+ const first = lastAssistantId == null;
10984
+ const messageId = ensureAssistant(push, wireBlockId ?? `assistant-${envelope.eventId}`);
10985
+ if (first && text) {
10986
+ push({
10987
+ type: "content_delta",
10988
+ messageId,
10989
+ delta: { type: "text", text }
10990
+ });
10991
+ }
10992
+ break;
10993
+ }
10994
+ case SESSION_DURABLE_EVENT.assistantMessage: {
10995
+ const wireBlockId = asString2(payload.blockId);
10996
+ if (wireBlockId && completedAssistantIds.has(wireBlockId)) break;
10997
+ const text = asString2(payload.text);
10998
+ const wasOpen = lastAssistantId != null;
10999
+ const messageId = ensureAssistant(push, wireBlockId ?? `assistant-${envelope.eventId}`);
11000
+ if (!wasOpen && text) {
11001
+ push({
11002
+ type: "content_delta",
11003
+ messageId,
11004
+ delta: { type: "text", text }
11005
+ });
11006
+ }
11007
+ push({ type: "message_complete", messageId });
11008
+ break;
11009
+ }
11010
+ case SESSION_DURABLE_EVENT.toolStarted: {
11011
+ const toolUseId = asString2(payload.toolUseId) ?? envelope.eventId;
11012
+ const toolName = asString2(payload.toolName) ?? "tool";
11013
+ const input = coerceToolInput(payload.input);
11014
+ const parentToolUseId = asString2(payload.parentToolUseId) ?? null;
11015
+ const messageId = ensureAssistant(push, `assistant-${envelope.eventId}`);
11016
+ push({
11017
+ type: "content_delta",
11018
+ messageId,
11019
+ delta: {
11020
+ type: "tool_use",
11021
+ toolUseId,
11022
+ toolName,
11023
+ input,
11024
+ status: "streaming",
11025
+ parentToolUseId
11026
+ }
11027
+ });
11028
+ break;
11029
+ }
11030
+ case SESSION_DURABLE_EVENT.toolInputDelta: {
11031
+ const toolUseId = asString2(payload.toolUseId) ?? envelope.eventId;
11032
+ const partialJson = asString2(payload.inputDelta) ?? asString2(payload.partialJson) ?? (typeof payload.input === "string" ? payload.input : "");
11033
+ if (!partialJson) break;
11034
+ const messageId = ensureAssistant(push, `assistant-${envelope.eventId}`);
11035
+ push({
11036
+ type: "tool_input_delta",
11037
+ messageId,
11038
+ toolUseId,
11039
+ partialJson,
11040
+ parentToolUseId: asString2(payload.parentToolUseId) ?? null
11041
+ });
11042
+ break;
11043
+ }
11044
+ case SESSION_DURABLE_EVENT.toolCompleted:
11045
+ case SESSION_DURABLE_EVENT.toolFailed: {
11046
+ const toolUseId = asString2(payload.toolUseId) ?? envelope.eventId;
11047
+ const toolName = asString2(payload.toolName) ?? "tool";
11048
+ const output = asString2(payload.output) ?? "";
11049
+ const isError = eventType === SESSION_DURABLE_EVENT.toolFailed || asBool(payload.isError) === true;
11050
+ const messageId = ensureAssistant(push, `assistant-${envelope.eventId}`);
11051
+ push({
11052
+ type: "content_delta",
11053
+ messageId,
11054
+ delta: {
11055
+ type: "tool_use",
11056
+ toolUseId,
11057
+ toolName,
11058
+ input: coerceToolInput(payload.input),
11059
+ status: "complete",
11060
+ parentToolUseId: asString2(payload.parentToolUseId) ?? null
11061
+ }
11062
+ });
11063
+ push({
11064
+ type: "content_delta",
11065
+ messageId,
11066
+ delta: {
11067
+ type: "tool_result",
11068
+ toolUseId,
11069
+ summary: output || (isError ? "failed" : "done"),
11070
+ isError,
11071
+ parentToolUseId: asString2(payload.parentToolUseId) ?? null
11072
+ }
11073
+ });
11074
+ break;
11075
+ }
11076
+ case SESSION_DURABLE_EVENT.turnCompleted: {
11077
+ if (rawTerminalThisTurn) {
11078
+ lastAssistantId = null;
11079
+ rawTerminalThisTurn = false;
11080
+ break;
11081
+ }
11082
+ lastAssistantId = null;
11083
+ push({
11084
+ type: "status_change",
11085
+ status: mapAgentStatus(asString2(payload.status), "idle")
11086
+ });
11087
+ break;
11088
+ }
11089
+ case SESSION_DURABLE_EVENT.turnInterrupted: {
11090
+ if (rawTerminalThisTurn) {
11091
+ lastAssistantId = null;
11092
+ rawTerminalThisTurn = false;
11093
+ break;
11094
+ }
11095
+ if (lastAssistantId) {
11096
+ push({ type: "message_interrupted", messageId: lastAssistantId });
11097
+ }
11098
+ lastAssistantId = null;
11099
+ push({ type: "status_change", status: "idle" });
11100
+ break;
11101
+ }
11102
+ case SESSION_DURABLE_EVENT.turnError: {
11103
+ if (rawTerminalThisTurn) {
11104
+ lastAssistantId = null;
11105
+ rawTerminalThisTurn = false;
11106
+ break;
11107
+ }
11108
+ const message = asString2(payload.message) ?? "remote turn failed";
11109
+ const errorId = ensureAssistant(push);
11110
+ push({ type: "message_error", messageId: errorId, error: message });
11111
+ lastAssistantId = null;
11112
+ push({ type: "status_change", status: "error" });
11113
+ break;
11114
+ }
11115
+ case SESSION_DURABLE_EVENT.statusChanged: {
11116
+ push({
11117
+ type: "status_change",
11118
+ status: mapAgentStatus(asString2(payload.status), "idle")
11119
+ });
11120
+ break;
11121
+ }
11122
+ case SESSION_DURABLE_EVENT.permissionRequested: {
11123
+ const interactionId = asString2(payload.interactionId) ?? asString2(payload.requestId) ?? envelope.eventId;
11124
+ const toolName = asString2(payload.toolName) ?? "tool";
11125
+ const requestKind = asString2(payload.requestKind);
11126
+ const sessionAgentsConfirm = payload.sessionAgentsConfirm && typeof payload.sessionAgentsConfirm === "object" ? payload.sessionAgentsConfirm : void 0;
11127
+ const request = {
11128
+ requestId: interactionId,
11129
+ toolName,
11130
+ toolUseId: asString2(payload.toolUseId),
11131
+ input: asRecord5(payload.input),
11132
+ allowAlwaysAllow: requestKind === "session_agents_confirm" ? false : payload.allowAlwaysAllow !== false,
11133
+ ...requestKind ? {
11134
+ requestKind
11135
+ } : {},
11136
+ ...asString2(payload.serverName) ? { serverName: asString2(payload.serverName) } : {},
11137
+ ...asString2(payload.message) ? { message: asString2(payload.message) } : {},
11138
+ ...sessionAgentsConfirm ? { sessionAgentsConfirm } : {}
11139
+ };
11140
+ push({ type: "permission_request", request });
11141
+ break;
11142
+ }
11143
+ case SESSION_DURABLE_EVENT.permissionResponded:
11144
+ case SESSION_DURABLE_EVENT.permissionTimeout:
11145
+ case SESSION_DURABLE_EVENT.permissionAborted: {
11146
+ const interactionId = asString2(payload.interactionId) ?? asString2(payload.requestId) ?? envelope.eventId;
11147
+ const decision = asString2(payload.decision);
11148
+ const approved = decision === "allow" || decision === "allow_always";
11149
+ push({
11150
+ type: "interaction_resolved",
11151
+ interactionType: "permission",
11152
+ requestId: interactionId,
11153
+ approved
11154
+ });
11155
+ break;
11156
+ }
11157
+ case SESSION_DURABLE_EVENT.questionRequested: {
11158
+ const request = mapQuestionRequest(payload, envelope.eventId);
11159
+ if (request) push({ type: "ask_user_question", request });
11160
+ break;
11161
+ }
11162
+ case SESSION_DURABLE_EVENT.questionResponded:
11163
+ case SESSION_DURABLE_EVENT.questionTimeout:
11164
+ case SESSION_DURABLE_EVENT.questionAborted: {
11165
+ const interactionId = asString2(payload.interactionId) ?? asString2(payload.requestId) ?? envelope.eventId;
11166
+ push({
11167
+ type: "interaction_resolved",
11168
+ interactionType: "question",
11169
+ requestId: interactionId,
11170
+ approved: eventType === SESSION_DURABLE_EVENT.questionResponded
11171
+ });
11172
+ break;
11173
+ }
11174
+ case SESSION_DURABLE_EVENT.planRequested: {
11175
+ const request = mapPlanRequest(payload, envelope.eventId);
11176
+ if (request) push({ type: "plan_approval", request });
11177
+ break;
11178
+ }
11179
+ case SESSION_DURABLE_EVENT.planResponded:
11180
+ case SESSION_DURABLE_EVENT.planTimeout:
11181
+ case SESSION_DURABLE_EVENT.planAborted: {
11182
+ const interactionId = asString2(payload.interactionId) ?? asString2(payload.requestId) ?? envelope.eventId;
11183
+ const decision = asString2(payload.decision);
11184
+ const approved = decision === "approve" || decision === "approved";
11185
+ push({
11186
+ type: "interaction_resolved",
11187
+ interactionType: "plan_approval",
11188
+ requestId: interactionId,
11189
+ approved,
11190
+ ...asString2(payload.feedback) ? { feedback: asString2(payload.feedback) } : {}
11191
+ });
11192
+ break;
11193
+ }
11194
+ case SESSION_DURABLE_EVENT.renamed: {
11195
+ const title = asString2(payload.title);
11196
+ if (title != null) {
11197
+ const sourceRaw = asString2(payload.source);
11198
+ const source = sourceRaw === "agent" || sourceRaw === "user" ? sourceRaw : "user";
11199
+ push({
11200
+ type: "session_title_changed",
11201
+ sessionId: ctx.sessionId,
11202
+ title,
11203
+ source
11204
+ });
11205
+ }
11206
+ break;
11207
+ }
11208
+ case SESSION_DURABLE_EVENT.closed:
11209
+ case SESSION_DURABLE_EVENT.removed: {
11210
+ push({ type: "status_change", status: "idle" });
11211
+ break;
11212
+ }
11213
+ case SESSION_DURABLE_EVENT.created:
11214
+ case SESSION_DURABLE_EVENT.reconciled:
11215
+ case SESSION_DURABLE_EVENT.uiFlags:
11216
+ break;
11217
+ default:
11218
+ break;
11219
+ }
11220
+ return out;
11221
+ };
11222
+ return {
11223
+ map: mapOne,
11224
+ currentAssistantMessageId: () => lastAssistantId
11225
+ };
11226
+ }
11227
+ var init_node_session_event_map = __esm({
11228
+ "../../packages/shared/src/node-session-event-map.ts"() {
11229
+ "use strict";
11230
+ init_session_events();
11231
+ }
11232
+ });
11233
+
11234
+ // ../../packages/runtime/src/session/message-catalog.ts
11235
+ function asRecord6(value) {
11236
+ if (value && typeof value === "object" && !Array.isArray(value)) {
11237
+ return value;
11238
+ }
11239
+ return {};
11240
+ }
11241
+ function asString3(value) {
11242
+ return typeof value === "string" ? value : void 0;
11243
+ }
10625
11244
  function truncate(text, max = SUMMARY_MAX) {
10626
11245
  if (text.length <= max) return text;
10627
11246
  return `${text.slice(0, max)}\u2026`;
@@ -10696,7 +11315,7 @@ function collectToolsByAssistantId(events, sessionId) {
10696
11315
  for (const ev of events) {
10697
11316
  if (ev.aggregateType && ev.aggregateType !== "session") continue;
10698
11317
  if (ev.aggregateId && ev.aggregateId !== sessionId) continue;
10699
- const payload = asRecord5(ev.payload);
11318
+ const payload = asRecord6(ev.payload);
10700
11319
  switch (ev.eventType) {
10701
11320
  case SESSION_DURABLE_EVENT.turnStarted: {
10702
11321
  turnKey += 1;
@@ -10712,47 +11331,47 @@ function collectToolsByAssistantId(events, sessionId) {
10712
11331
  }
10713
11332
  case SESSION_DURABLE_EVENT.assistantDelta:
10714
11333
  case SESSION_DURABLE_EVENT.assistantText: {
10715
- const blockId = asString2(payload.blockId);
11334
+ const blockId = asString3(payload.blockId);
10716
11335
  if (blockId) bindAssistant(blockId);
10717
11336
  break;
10718
11337
  }
10719
11338
  case SESSION_DURABLE_EVENT.assistantMessage: {
10720
- const blockId = asString2(payload.blockId);
11339
+ const blockId = asString3(payload.blockId);
10721
11340
  if (blockId) bindAssistant(blockId, { authoritative: true });
10722
11341
  break;
10723
11342
  }
10724
11343
  case SESSION_DURABLE_EVENT.agentEvent: {
10725
- const raw = asRecord5(payload.event);
10726
- const type = asString2(raw.type);
11344
+ const raw = asRecord6(payload.event);
11345
+ const type = asString3(raw.type);
10727
11346
  if (type === "message_start") {
10728
- const id = asString2(asRecord5(raw.message).id);
11347
+ const id = asString3(asRecord6(raw.message).id);
10729
11348
  if (id) bindAssistant(id);
10730
11349
  } else if (type === "message_complete") {
10731
- const id = asString2(raw.messageId);
11350
+ const id = asString3(raw.messageId);
10732
11351
  if (id) bindAssistant(id, { authoritative: true });
10733
11352
  } else if (type === "content_delta") {
10734
- const messageId = asString2(raw.messageId);
11353
+ const messageId = asString3(raw.messageId);
10735
11354
  if (messageId) bindAssistant(messageId);
10736
- const delta = asRecord5(raw.delta);
10737
- const dType = asString2(delta.type);
11355
+ const delta = asRecord6(raw.delta);
11356
+ const dType = asString3(delta.type);
10738
11357
  if (dType === "tool_use") {
10739
- const toolUseId = asString2(delta.toolUseId);
11358
+ const toolUseId = asString3(delta.toolUseId);
10740
11359
  if (!toolUseId) break;
10741
11360
  const key = currentAssistantId ?? provisionalKey;
10742
11361
  const bucket = ensureBucket(key);
10743
11362
  const existing = bucket.get(toolUseId) ?? {
10744
11363
  toolUseId,
10745
- toolName: asString2(delta.toolName) ?? "tool"
11364
+ toolName: asString3(delta.toolName) ?? "tool"
10746
11365
  };
10747
- existing.toolName = asString2(delta.toolName) ?? existing.toolName;
11366
+ existing.toolName = asString3(delta.toolName) ?? existing.toolName;
10748
11367
  const input = coerceSummary(delta.input);
10749
11368
  if (input) existing.inputSummary = input;
10750
11369
  if (delta.parentToolUseId !== void 0) {
10751
- existing.parentToolUseId = asString2(delta.parentToolUseId) ?? null;
11370
+ existing.parentToolUseId = asString3(delta.parentToolUseId) ?? null;
10752
11371
  }
10753
11372
  bucket.set(toolUseId, existing);
10754
11373
  } else if (dType === "tool_result") {
10755
- const toolUseId = asString2(delta.toolUseId);
11374
+ const toolUseId = asString3(delta.toolUseId);
10756
11375
  if (!toolUseId) break;
10757
11376
  const key = currentAssistantId ?? provisionalKey;
10758
11377
  const bucket = ensureBucket(key);
@@ -10770,34 +11389,34 @@ function collectToolsByAssistantId(events, sessionId) {
10770
11389
  }
10771
11390
  case SESSION_DURABLE_EVENT.toolStarted:
10772
11391
  case SESSION_DURABLE_EVENT.toolInputDelta: {
10773
- const toolUseId = asString2(payload.toolUseId);
11392
+ const toolUseId = asString3(payload.toolUseId);
10774
11393
  if (!toolUseId) break;
10775
11394
  const key = currentAssistantId ?? provisionalKey;
10776
11395
  const bucket = ensureBucket(key);
10777
11396
  const existing = bucket.get(toolUseId) ?? {
10778
11397
  toolUseId,
10779
- toolName: asString2(payload.toolName) ?? "tool"
11398
+ toolName: asString3(payload.toolName) ?? "tool"
10780
11399
  };
10781
- existing.toolName = asString2(payload.toolName) ?? existing.toolName;
11400
+ existing.toolName = asString3(payload.toolName) ?? existing.toolName;
10782
11401
  const input = coerceSummary(payload.input) ?? coerceSummary(payload.inputDelta) ?? existing.inputSummary;
10783
11402
  if (input) existing.inputSummary = input;
10784
11403
  if (payload.parentToolUseId !== void 0) {
10785
- existing.parentToolUseId = asString2(payload.parentToolUseId) ?? null;
11404
+ existing.parentToolUseId = asString3(payload.parentToolUseId) ?? null;
10786
11405
  }
10787
11406
  bucket.set(toolUseId, existing);
10788
11407
  break;
10789
11408
  }
10790
11409
  case SESSION_DURABLE_EVENT.toolCompleted:
10791
11410
  case SESSION_DURABLE_EVENT.toolFailed: {
10792
- const toolUseId = asString2(payload.toolUseId);
11411
+ const toolUseId = asString3(payload.toolUseId);
10793
11412
  if (!toolUseId) break;
10794
11413
  const key = currentAssistantId ?? provisionalKey;
10795
11414
  const bucket = ensureBucket(key);
10796
11415
  const existing = bucket.get(toolUseId) ?? {
10797
11416
  toolUseId,
10798
- toolName: asString2(payload.toolName) ?? "tool"
11417
+ toolName: asString3(payload.toolName) ?? "tool"
10799
11418
  };
10800
- existing.toolName = asString2(payload.toolName) ?? existing.toolName;
11419
+ existing.toolName = asString3(payload.toolName) ?? existing.toolName;
10801
11420
  const input = coerceSummary(payload.input);
10802
11421
  if (input) existing.inputSummary = input;
10803
11422
  const output = coerceSummary(payload.output);
@@ -10806,7 +11425,7 @@ function collectToolsByAssistantId(events, sessionId) {
10806
11425
  existing.isError = true;
10807
11426
  }
10808
11427
  if (payload.parentToolUseId !== void 0) {
10809
- existing.parentToolUseId = asString2(payload.parentToolUseId) ?? null;
11428
+ existing.parentToolUseId = asString3(payload.parentToolUseId) ?? null;
10810
11429
  }
10811
11430
  bucket.set(toolUseId, existing);
10812
11431
  break;
@@ -10839,16 +11458,72 @@ function collectToolsByAssistantId(events, sessionId) {
10839
11458
  }
10840
11459
  return out;
10841
11460
  }
11461
+ function collectContentByAssistantId(events, sessionId) {
11462
+ const contentById = /* @__PURE__ */ new Map();
11463
+ const mapper = createNodeSessionEventMapper({ sessionId });
11464
+ const mergeContent = (fromId, toId) => {
11465
+ if (!fromId || !toId || fromId === toId) return;
11466
+ const from = contentById.get(fromId);
11467
+ if (!from || from.length === 0) return;
11468
+ const to = contentById.get(toId);
11469
+ if (!to || to.length === 0) {
11470
+ contentById.set(toId, from);
11471
+ } else {
11472
+ contentById.set(toId, from.length >= to.length ? from : to);
11473
+ }
11474
+ contentById.delete(fromId);
11475
+ };
11476
+ for (const envelope of events) {
11477
+ if (envelope.aggregateType && envelope.aggregateType !== "session") continue;
11478
+ if (envelope.aggregateId && envelope.aggregateId !== sessionId) continue;
11479
+ const stickyBefore = mapper.currentAssistantMessageId();
11480
+ const mapped = mapper.map(envelope);
11481
+ for (const ev of mapped) {
11482
+ if (ev.type === "content_delta" && ev.messageId) {
11483
+ const prev = contentById.get(ev.messageId) ?? [];
11484
+ contentById.set(ev.messageId, applyContentDelta(prev, ev.delta));
11485
+ continue;
11486
+ }
11487
+ if (ev.type === "tool_input_delta" && ev.messageId && ev.toolUseId && ev.partialJson) {
11488
+ const prev = contentById.get(ev.messageId) ?? [];
11489
+ let changed = false;
11490
+ const next = prev.map((block) => {
11491
+ if (block.type !== "tool_use" || block.toolUseId !== ev.toolUseId) return block;
11492
+ changed = true;
11493
+ return { ...block, input: `${block.input ?? ""}${ev.partialJson}` };
11494
+ });
11495
+ if (changed) contentById.set(ev.messageId, next);
11496
+ }
11497
+ }
11498
+ const payload = asRecord6(envelope.payload);
11499
+ if (envelope.eventType === SESSION_DURABLE_EVENT.assistantMessage) {
11500
+ const blockId = asString3(payload.blockId);
11501
+ const sticky = stickyBefore ?? mapper.currentAssistantMessageId();
11502
+ if (blockId && sticky) mergeContent(sticky, blockId);
11503
+ const text = asString3(payload.text);
11504
+ if (blockId && text) {
11505
+ const prev = contentById.get(blockId) ?? [];
11506
+ const hasTopLevelText = prev.some(
11507
+ (b2) => b2.type === "text" && (b2.parentToolUseId == null || b2.parentToolUseId === void 0)
11508
+ );
11509
+ if (!hasTopLevelText) {
11510
+ contentById.set(blockId, applyContentDelta(prev, { type: "text", text }));
11511
+ }
11512
+ }
11513
+ }
11514
+ }
11515
+ return contentById;
11516
+ }
10842
11517
  function extractCheckpointMeta(events, sessionId, blockId) {
10843
11518
  for (let i = events.length - 1; i >= 0; i--) {
10844
11519
  const ev = events[i];
10845
11520
  if (ev.aggregateType && ev.aggregateType !== "session") continue;
10846
11521
  if (ev.aggregateId && ev.aggregateId !== sessionId) continue;
10847
- const payload = asRecord5(ev.payload);
11522
+ const payload = asRecord6(ev.payload);
10848
11523
  if (ev.eventType === SESSION_DURABLE_EVENT.assistantMessage) {
10849
- if (asString2(payload.blockId) !== blockId) continue;
10850
- const checkpointId = asString2(payload.checkpointId);
10851
- const resumePointId = asString2(payload.resumePointId);
11524
+ if (asString3(payload.blockId) !== blockId) continue;
11525
+ const checkpointId = asString3(payload.checkpointId);
11526
+ const resumePointId = asString3(payload.resumePointId);
10852
11527
  const metadata = payload.metadata && typeof payload.metadata === "object" ? payload.metadata : void 0;
10853
11528
  if (checkpointId || resumePointId || metadata) {
10854
11529
  return {
@@ -10859,14 +11534,14 @@ function extractCheckpointMeta(events, sessionId, blockId) {
10859
11534
  }
10860
11535
  }
10861
11536
  if (ev.eventType === SESSION_DURABLE_EVENT.agentEvent) {
10862
- const raw = asRecord5(payload.event);
10863
- if (asString2(raw.type) !== "message_complete" && asString2(raw.type) !== "checkpoint_captured") {
11537
+ const raw = asRecord6(payload.event);
11538
+ if (asString3(raw.type) !== "message_complete" && asString3(raw.type) !== "checkpoint_captured") {
10864
11539
  continue;
10865
11540
  }
10866
- const messageId = asString2(raw.messageId) ?? asString2(raw.id);
11541
+ const messageId = asString3(raw.messageId) ?? asString3(raw.id);
10867
11542
  if (messageId && messageId !== blockId) continue;
10868
- const checkpointId = asString2(raw.checkpointId);
10869
- const resumePointId = asString2(raw.resumePointId);
11543
+ const checkpointId = asString3(raw.checkpointId);
11544
+ const resumePointId = asString3(raw.resumePointId);
10870
11545
  if (checkpointId || resumePointId) {
10871
11546
  return {
10872
11547
  ...checkpointId ? { checkpointId } : {},
@@ -10879,12 +11554,14 @@ function extractCheckpointMeta(events, sessionId, blockId) {
10879
11554
  }
10880
11555
  function buildSessionMessageCatalog(session, events) {
10881
11556
  const toolsByAssistant = collectToolsByAssistantId(events, session.sessionId);
11557
+ const contentByAssistant = collectContentByAssistantId(events, session.sessionId);
10882
11558
  const transcript = Array.isArray(session.transcript) ? session.transcript : [];
10883
11559
  const out = [];
10884
11560
  for (let i = 0; i < transcript.length; i++) {
10885
11561
  const block = transcript[i];
10886
11562
  const role = block.role === "user" || block.role === "assistant" || block.role === "system" ? block.role : "system";
10887
11563
  const tools = role === "assistant" ? toolsByAssistant.get(block.id) : void 0;
11564
+ const orderedContent = role === "assistant" ? contentByAssistant.get(block.id) : void 0;
10888
11565
  const extra = role === "assistant" ? extractCheckpointMeta(events, session.sessionId, block.id) : {};
10889
11566
  let resumePointId = extra.resumePointId;
10890
11567
  if (!resumePointId && role === "assistant" && i === transcript.length - 1 && session.providerResume) {
@@ -10896,6 +11573,7 @@ function buildSessionMessageCatalog(session, events) {
10896
11573
  text: typeof block.text === "string" ? block.text : "",
10897
11574
  createdAt: typeof block.createdAt === "number" ? block.createdAt : Date.now(),
10898
11575
  sortOrder: i,
11576
+ ...orderedContent && orderedContent.length > 0 ? { content: orderedContent } : {},
10899
11577
  ...tools && tools.length > 0 ? { tools } : {},
10900
11578
  ...extra.metadata ? { metadata: extra.metadata } : {},
10901
11579
  ...extra.checkpointId ? { checkpointId: extra.checkpointId } : {},
@@ -10921,7 +11599,9 @@ var DEFAULT_LIMIT, MAX_LIMIT, SUMMARY_MAX;
10921
11599
  var init_message_catalog = __esm({
10922
11600
  "../../packages/runtime/src/session/message-catalog.ts"() {
10923
11601
  "use strict";
11602
+ init_content_delta();
10924
11603
  init_environment();
11604
+ init_node_session_event_map();
10925
11605
  DEFAULT_LIMIT = 50;
10926
11606
  MAX_LIMIT = 200;
10927
11607
  SUMMARY_MAX = 2e3;
@@ -15516,7 +16196,7 @@ var init_platform_registry = __esm({
15516
16196
  });
15517
16197
 
15518
16198
  // ../../packages/runtime/src/llm-proxy/claude-messages/helpers.ts
15519
- function asString3(value) {
16199
+ function asString4(value) {
15520
16200
  return typeof value === "string" ? value : void 0;
15521
16201
  }
15522
16202
  function asArray(value) {
@@ -15560,13 +16240,13 @@ function splitLeadingThinkBlock(text) {
15560
16240
  }
15561
16241
  function extractReasoningFieldText(value) {
15562
16242
  for (const key of ["reasoning_content", "reasoning"]) {
15563
- const text = asString3(get(value, key));
16243
+ const text = asString4(get(value, key));
15564
16244
  if (text) return text;
15565
16245
  }
15566
16246
  const reasoning = get(value, "reasoning");
15567
16247
  if (reasoning) {
15568
16248
  for (const key of ["content", "text", "summary"]) {
15569
- const text = asString3(get(reasoning, key));
16249
+ const text = asString4(get(reasoning, key));
15570
16250
  if (text) return text;
15571
16251
  }
15572
16252
  }
@@ -15575,12 +16255,12 @@ function extractReasoningFieldText(value) {
15575
16255
  if (typeof details === "string") return details || void 0;
15576
16256
  const arr = asArray(details);
15577
16257
  if (arr) {
15578
- const joined = arr.map((part) => asString3(get(part, "text")) ?? asString3(get(part, "content")) ?? asString3(part)).filter((t) => !!t).join("\n\n");
16258
+ const joined = arr.map((part) => asString4(get(part, "text")) ?? asString4(get(part, "content")) ?? asString4(part)).filter((t) => !!t).join("\n\n");
15579
16259
  return joined || void 0;
15580
16260
  }
15581
16261
  const obj = asObject(details);
15582
16262
  if (obj) {
15583
- const text = asString3(get(obj, "text")) ?? asString3(get(obj, "content")) ?? asString3(get(obj, "summary"));
16263
+ const text = asString4(get(obj, "text")) ?? asString4(get(obj, "content")) ?? asString4(get(obj, "summary"));
15584
16264
  if (text) return text;
15585
16265
  }
15586
16266
  }
@@ -15608,7 +16288,7 @@ function isOpenAiOSeries2(model) {
15608
16288
  function mapThinkingToEffort(thinking, maxTokens) {
15609
16289
  const t = asObject2(thinking);
15610
16290
  if (!t) return null;
15611
- const type = asString4(t.type);
16291
+ const type = asString5(t.type);
15612
16292
  if (type === "disabled") return null;
15613
16293
  if (type === "adaptive") return "medium";
15614
16294
  if (type === "enabled") {
@@ -15634,7 +16314,7 @@ function stripModelPrefix(model, providerName) {
15634
16314
  function asObject2(value) {
15635
16315
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
15636
16316
  }
15637
- function asString4(value) {
16317
+ function asString5(value) {
15638
16318
  return typeof value === "string" ? value : void 0;
15639
16319
  }
15640
16320
  var init_capabilities3 = __esm({
@@ -15647,7 +16327,7 @@ var init_capabilities3 = __esm({
15647
16327
  function claudeMessagesToChatCompletions(body, providerName) {
15648
16328
  const result = {};
15649
16329
  const src = asObject(body) ?? {};
15650
- const rawModel = asString3(src.model) ?? "";
16330
+ const rawModel = asString4(src.model) ?? "";
15651
16331
  const model = stripModelPrefix(rawModel, providerName);
15652
16332
  result.model = model;
15653
16333
  const maxTokens = typeof src.max_tokens === "number" ? src.max_tokens : void 0;
@@ -15690,11 +16370,11 @@ function claudeMessagesToChatCompletions(body, providerName) {
15690
16370
  return result;
15691
16371
  }
15692
16372
  function systemTextFromClaude(value) {
15693
- const str2 = asString3(value);
16373
+ const str2 = asString4(value);
15694
16374
  if (str2 !== void 0) return str2;
15695
16375
  const arr = asArray(value);
15696
16376
  if (arr) {
15697
- return arr.map((part) => asString3(get(part, "text")) ?? asString3(part)).filter((s2) => !!s2).join("\n\n");
16377
+ return arr.map((part) => asString4(get(part, "text")) ?? asString4(part)).filter((s2) => !!s2).join("\n\n");
15698
16378
  }
15699
16379
  return "";
15700
16380
  }
@@ -15702,7 +16382,7 @@ function appendClaudeMessagesAsChat(src, messages) {
15702
16382
  const arr = asArray(src);
15703
16383
  if (!arr) return;
15704
16384
  for (const item of arr) {
15705
- const role = asString3(get(item, "role"));
16385
+ const role = asString4(get(item, "role"));
15706
16386
  if (role === "assistant") {
15707
16387
  messages.push(claudeAssistantToChat(item));
15708
16388
  } else if (role === "user") {
@@ -15722,9 +16402,9 @@ function claudeUserToChat(item) {
15722
16402
  const chatParts = [];
15723
16403
  let hasNonText = false;
15724
16404
  for (const part of parts) {
15725
- const partType = asString3(get(part, "type")) ?? "";
16405
+ const partType = asString4(get(part, "type")) ?? "";
15726
16406
  if (partType === "text" || partType === "input_text") {
15727
- const t = asString3(get(part, "text"));
16407
+ const t = asString4(get(part, "text"));
15728
16408
  if (t) chatParts.push({ type: "text", text: t });
15729
16409
  } else if (partType === "image" || partType === "input_image") {
15730
16410
  hasNonText = true;
@@ -15732,11 +16412,11 @@ function claudeUserToChat(item) {
15732
16412
  const imageUrl = get(part, "image_url");
15733
16413
  let url2;
15734
16414
  if (source) {
15735
- const mediaType = asString3(get(source, "media_type")) ?? "image/png";
15736
- const data = asString3(get(source, "data"));
16415
+ const mediaType = asString4(get(source, "media_type")) ?? "image/png";
16416
+ const data = asString4(get(source, "data"));
15737
16417
  if (data) url2 = `data:${mediaType};base64,${data}`;
15738
16418
  } else if (imageUrl !== void 0) {
15739
- url2 = asString3(imageUrl) ?? "";
16419
+ url2 = asString4(imageUrl) ?? "";
15740
16420
  }
15741
16421
  if (url2) chatParts.push({ type: "image_url", image_url: { url: url2 } });
15742
16422
  }
@@ -15769,17 +16449,17 @@ function extractThinkingFromAssistant(item) {
15769
16449
  const content = asArray(get(item, "content"));
15770
16450
  if (content) {
15771
16451
  for (const part of content) {
15772
- if (asString3(get(part, "type")) === "thinking") {
15773
- const thinking = asString3(get(part, "thinking"));
16452
+ if (asString4(get(part, "type")) === "thinking") {
16453
+ const thinking = asString4(get(part, "thinking"));
15774
16454
  if (thinking) return thinking;
15775
16455
  }
15776
16456
  }
15777
16457
  }
15778
- return asString3(get(item, "reasoning_content"));
16458
+ return asString4(get(item, "reasoning_content"));
15779
16459
  }
15780
16460
  function claudeToolUseToChatToolCall(item) {
15781
- const callId = asString3(get(item, "id")) ?? asString3(get(item, "tool_use_id"));
15782
- const name = asString3(get(item, "name"));
16461
+ const callId = asString4(get(item, "id")) ?? asString4(get(item, "tool_use_id"));
16462
+ const name = asString4(get(item, "name"));
15783
16463
  if (!callId || !name) return void 0;
15784
16464
  const input = get(item, "input") ?? get(item, "arguments");
15785
16465
  return {
@@ -15789,13 +16469,13 @@ function claudeToolUseToChatToolCall(item) {
15789
16469
  };
15790
16470
  }
15791
16471
  function claudeFunctionCallToChatToolCall(functionCall) {
15792
- const callId = asString3(get(functionCall, "id")) ?? "call_0";
15793
- const name = asString3(get(functionCall, "name")) ?? "";
16472
+ const callId = asString4(get(functionCall, "id")) ?? "call_0";
16473
+ const name = asString4(get(functionCall, "name")) ?? "";
15794
16474
  const args = canonicalizeToolArguments(get(functionCall, "arguments"));
15795
16475
  return { id: callId, type: "function", function: { name, arguments: args } };
15796
16476
  }
15797
16477
  function claudeToolResultToChat(item) {
15798
- const toolUseId = asString3(get(item, "tool_use_id")) ?? asString3(get(item, "call_id")) ?? "";
16478
+ const toolUseId = asString4(get(item, "tool_use_id")) ?? asString4(get(item, "call_id")) ?? "";
15799
16479
  const content = get(item, "content");
15800
16480
  const text = contentToText(content);
15801
16481
  const isError = get(item, "is_error") === true;
@@ -15807,7 +16487,7 @@ function claudeToolResultToChat(item) {
15807
16487
  };
15808
16488
  }
15809
16489
  function claudeToolToChatTool(tool) {
15810
- const name = asString3(get(tool, "name"));
16490
+ const name = asString4(get(tool, "name"));
15811
16491
  if (!name) return void 0;
15812
16492
  const schema = asObject(get(tool, "input_schema"));
15813
16493
  const parameters = schema ?? asObject(get(tool, "parameters")) ?? {};
@@ -15824,29 +16504,29 @@ function claudeToolToChatTool(tool) {
15824
16504
  function claudeToolChoiceToChat(toolChoice) {
15825
16505
  const obj = asObject(toolChoice);
15826
16506
  if (obj) {
15827
- const type = asString3(obj.type);
16507
+ const type = asString4(obj.type);
15828
16508
  if (type === "tool" || type === "function") {
15829
- const name = asString3(obj.name) ?? asString3(get(obj, "function.name"));
16509
+ const name = asString4(obj.name) ?? asString4(get(obj, "function.name"));
15830
16510
  if (name) return { type: "function", function: { name } };
15831
16511
  }
15832
16512
  if (type === "any") return "required";
15833
16513
  if (type === "auto" || type === "none") return type;
15834
16514
  }
15835
- if (asString3(toolChoice) === "none" || asString3(toolChoice) === "auto" || asString3(toolChoice) === "required") {
16515
+ if (asString4(toolChoice) === "none" || asString4(toolChoice) === "auto" || asString4(toolChoice) === "required") {
15836
16516
  return toolChoice;
15837
16517
  }
15838
16518
  return toolChoice;
15839
16519
  }
15840
16520
  function contentToText(content) {
15841
16521
  if (content === null || content === void 0) return void 0;
15842
- const str2 = asString3(content);
16522
+ const str2 = asString4(content);
15843
16523
  if (str2 !== void 0) return str2;
15844
16524
  const parts = asArray(content);
15845
16525
  if (!parts) return void 0;
15846
16526
  const textParts = parts.map((part) => {
15847
- const partType = asString3(get(part, "type")) ?? "";
15848
- if (partType === "text" || partType === "input_text") return asString3(get(part, "text"));
15849
- if (partType === "thinking") return asString3(get(part, "thinking"));
16527
+ const partType = asString4(get(part, "type")) ?? "";
16528
+ if (partType === "text" || partType === "input_text") return asString4(get(part, "text"));
16529
+ if (partType === "thinking") return asString4(get(part, "thinking"));
15850
16530
  return void 0;
15851
16531
  }).filter((s2) => s2 !== void 0);
15852
16532
  if (textParts.length === 0) return void 0;
@@ -15856,8 +16536,8 @@ function collapseSystemMessagesToHead(messages) {
15856
16536
  const systemChunks = [];
15857
16537
  const rest = [];
15858
16538
  for (const msg of messages) {
15859
- if (asString3(msg.role) === "system") {
15860
- const text = asString3(msg.content);
16539
+ if (asString4(msg.role) === "system") {
16540
+ const text = asString4(msg.content);
15861
16541
  if (text !== void 0) {
15862
16542
  if (text.trim()) systemChunks.push(text);
15863
16543
  continue;
@@ -15901,10 +16581,10 @@ function chatCompletionToMessage(body) {
15901
16581
  if (choice === void 0) throw new Error("Empty choices in chat response");
15902
16582
  const message = get(choice, "message");
15903
16583
  if (message === void 0) throw new Error("No message in chat choice");
15904
- const messageId = messageIdFromChatId(asString3(get(body, "id")));
15905
- const model = asString3(get(body, "model")) ?? "";
16584
+ const messageId = messageIdFromChatId(asString4(get(body, "id")));
16585
+ const model = asString4(get(body, "model")) ?? "";
15906
16586
  const createdAt = typeof get(body, "created") === "number" ? get(body, "created") : 0;
15907
- const finishReason = asString3(get(choice, "finish_reason"));
16587
+ const finishReason = asString4(get(choice, "finish_reason"));
15908
16588
  const reasoning = chatReasoningText(message);
15909
16589
  const output = [];
15910
16590
  const reasoningItem = chatReasoningToOutputItem(reasoning, messageId);
@@ -15935,7 +16615,7 @@ function chatReasoningToOutputItem(reasoning, messageId) {
15935
16615
  function chatReasoningText(message) {
15936
16616
  const field = extractReasoningFieldText(message);
15937
16617
  if (field) return field;
15938
- const content = asString3(get(message, "content"));
16618
+ const content = asString4(get(message, "content"));
15939
16619
  if (content) {
15940
16620
  const split = splitLeadingThinkBlock(content);
15941
16621
  if (split && split.reasoning) return split.reasoning;
@@ -15944,7 +16624,7 @@ function chatReasoningText(message) {
15944
16624
  }
15945
16625
  function chatMessageToOutputItem(message, messageId) {
15946
16626
  const content = [];
15947
- const text = asString3(get(message, "content"));
16627
+ const text = asString4(get(message, "content"));
15948
16628
  if (text !== void 0) {
15949
16629
  const answer = splitLeadingThinkBlock(text)?.answer ?? text;
15950
16630
  if (answer) content.push({ type: "text", text: answer, annotations: [] });
@@ -15952,12 +16632,12 @@ function chatMessageToOutputItem(message, messageId) {
15952
16632
  const parts = asArray(get(message, "content"));
15953
16633
  if (parts) {
15954
16634
  for (const part of parts) {
15955
- const partType = asString3(get(part, "type")) ?? "";
16635
+ const partType = asString4(get(part, "type")) ?? "";
15956
16636
  if (partType === "text" || partType === "output_text") {
15957
- const t = asString3(get(part, "text"));
16637
+ const t = asString4(get(part, "text"));
15958
16638
  if (t) content.push({ type: "text", text: t, annotations: [] });
15959
16639
  } else if (partType === "refusal") {
15960
- const t = asString3(get(part, "refusal"));
16640
+ const t = asString4(get(part, "refusal"));
15961
16641
  if (t) content.push({ type: "text", text: t, annotations: [] });
15962
16642
  }
15963
16643
  }
@@ -15983,9 +16663,9 @@ function chatToolCallsToOutputItems(message) {
15983
16663
  return output;
15984
16664
  }
15985
16665
  function chatToolCallToOutputItem(toolCall, index) {
15986
- const callId = asString3(get(toolCall, "id"))?.trim() || `call_${index}`;
16666
+ const callId = asString4(get(toolCall, "id"))?.trim() || `call_${index}`;
15987
16667
  const fn = get(toolCall, "function");
15988
- const name = asString3(get(fn, "name")) ?? "";
16668
+ const name = asString4(get(fn, "name")) ?? "";
15989
16669
  const args = canonicalizeToolArguments(get(fn, "arguments"));
15990
16670
  return {
15991
16671
  type: "tool_use",
@@ -15995,8 +16675,8 @@ function chatToolCallToOutputItem(toolCall, index) {
15995
16675
  };
15996
16676
  }
15997
16677
  function chatLegacyFunctionCallToOutputItem(functionCall) {
15998
- const callId = asString3(get(functionCall, "id"))?.trim() || "call_0";
15999
- const name = asString3(get(functionCall, "name")) ?? "";
16678
+ const callId = asString4(get(functionCall, "id"))?.trim() || "call_0";
16679
+ const name = asString4(get(functionCall, "name")) ?? "";
16000
16680
  const args = canonicalizeToolArguments(get(functionCall, "arguments"));
16001
16681
  return {
16002
16682
  type: "tool_use",
@@ -16048,13 +16728,13 @@ function chatErrorToMessageError(body) {
16048
16728
  error: { type: "upstream_error", message: "Upstream returned an empty error response" }
16049
16729
  };
16050
16730
  }
16051
- const str2 = asString3(body);
16731
+ const str2 = asString4(body);
16052
16732
  if (str2 !== void 0) {
16053
16733
  return { type: "error", error: { type: "upstream_error", message: str2 } };
16054
16734
  }
16055
16735
  const source = get(body, "error") ?? body;
16056
- const message = asString3(get(source, "message")) ?? asString3(get(source, "detail")) ?? asString3(get(source, "status_msg")) ?? asString3(get(get(source, "base_resp"), "status_msg")) ?? asString3(source) ?? safeStringify(source);
16057
- const errorType = asString3(get(source, "type")) ?? "upstream_error";
16736
+ const message = asString4(get(source, "message")) ?? asString4(get(source, "detail")) ?? asString4(get(source, "status_msg")) ?? asString4(get(get(source, "base_resp"), "status_msg")) ?? asString4(source) ?? safeStringify(source);
16737
+ const errorType = asString4(get(source, "type")) ?? "upstream_error";
16058
16738
  return {
16059
16739
  type: "error",
16060
16740
  error: { type: errorType, message }
@@ -16147,8 +16827,8 @@ function stripLeadingThinkOpenTag(text) {
16147
16827
  }
16148
16828
  function extractChatSseError(value) {
16149
16829
  const error51 = get(value, "error") ?? value;
16150
- const message = asString3(error51) ?? asString3(get(error51, "message")) ?? asString3(get(error51, "detail")) ?? JSON.stringify(error51);
16151
- const errorType = asString3(get(error51, "type")) ?? asString3(get(error51, "code"));
16830
+ const message = asString4(error51) ?? asString4(get(error51, "message")) ?? asString4(get(error51, "detail")) ?? JSON.stringify(error51);
16831
+ const errorType = asString4(get(error51, "type")) ?? asString4(get(error51, "code"));
16152
16832
  return { message, errorType: errorType ?? void 0 };
16153
16833
  }
16154
16834
  function stripSseField(line, field) {
@@ -16258,9 +16938,9 @@ var init_stream = __esm({
16258
16938
  inputTokens;
16259
16939
  handleChatChunk(chunk) {
16260
16940
  const events = [];
16261
- const id = asString3(get(chunk, "id"));
16941
+ const id = asString4(get(chunk, "id"));
16262
16942
  if (id) this.responseId = messageIdFromChatId(id);
16263
- const model = asString3(get(chunk, "model"));
16943
+ const model = asString4(get(chunk, "model"));
16264
16944
  if (model) this.model = model;
16265
16945
  const created = get(chunk, "created");
16266
16946
  if (typeof created === "number") this.createdAt = created;
@@ -16280,7 +16960,7 @@ var init_stream = __esm({
16280
16960
  if (delta !== void 0) {
16281
16961
  const reasoning = extractReasoningFieldText(delta);
16282
16962
  if (reasoning) events.push(...this.pushReasoningDelta(reasoning));
16283
- const content = asString3(get(delta, "content"));
16963
+ const content = asString4(get(delta, "content"));
16284
16964
  if (content) events.push(...this.pushContentDelta(content));
16285
16965
  const toolCalls = asArray(get(delta, "tool_calls"));
16286
16966
  if (toolCalls) {
@@ -16290,7 +16970,7 @@ var init_stream = __esm({
16290
16970
  for (const toolCall of toolCalls) events.push(...this.pushToolCallDelta(toolCall, reasoningForTool));
16291
16971
  }
16292
16972
  }
16293
- const finishReason = asString3(get(choice, "finish_reason"));
16973
+ const finishReason = asString4(get(choice, "finish_reason"));
16294
16974
  if (finishReason) this.finishReason = finishReason;
16295
16975
  return events;
16296
16976
  }
@@ -16446,10 +17126,10 @@ var init_stream = __esm({
16446
17126
  }
16447
17127
  pushToolCallDelta(toolCall, reasoning) {
16448
17128
  const chatIndex = typeof get(toolCall, "index") === "number" ? get(toolCall, "index") : 0;
16449
- const idDelta = asString3(get(toolCall, "id"));
17129
+ const idDelta = asString4(get(toolCall, "id"));
16450
17130
  const fn = get(toolCall, "function");
16451
- const nameDelta = asString3(get(fn, "name"));
16452
- const argsDelta = asString3(get(fn, "arguments")) ?? "";
17131
+ const nameDelta = asString4(get(fn, "name"));
17132
+ const argsDelta = asString4(get(fn, "arguments")) ?? "";
16453
17133
  let state = this.tools.get(chatIndex);
16454
17134
  if (!state) {
16455
17135
  state = newToolCall();
@@ -16666,7 +17346,7 @@ var init_transformer = __esm({
16666
17346
  });
16667
17347
 
16668
17348
  // ../../packages/runtime/src/llm-proxy/codex-responses/helpers.ts
16669
- function asString5(value) {
17349
+ function asString6(value) {
16670
17350
  return typeof value === "string" ? value : void 0;
16671
17351
  }
16672
17352
  function asArray2(value) {
@@ -16727,7 +17407,7 @@ function stripLeadingThinkOpenTag2(text) {
16727
17407
  }
16728
17408
  function detailPartText(value) {
16729
17409
  for (const key of ["text", "content", "summary"]) {
16730
- const text = asString5(get2(value, key));
17410
+ const text = asString6(get2(value, key));
16731
17411
  if (text) return text;
16732
17412
  }
16733
17413
  const parts = asArray2(get2(value, "parts"));
@@ -16749,13 +17429,13 @@ function detailsText(value) {
16749
17429
  }
16750
17430
  function extractReasoningFieldText2(value) {
16751
17431
  for (const key of ["reasoning_content", "reasoning"]) {
16752
- const text = asString5(get2(value, key));
17432
+ const text = asString6(get2(value, key));
16753
17433
  if (text) return text;
16754
17434
  }
16755
17435
  const reasoning = get2(value, "reasoning");
16756
17436
  if (reasoning) {
16757
17437
  for (const key of ["content", "text", "summary"]) {
16758
- const text = asString5(get2(reasoning, key));
17438
+ const text = asString6(get2(reasoning, key));
16759
17439
  if (text) return text;
16760
17440
  }
16761
17441
  }
@@ -16768,22 +17448,22 @@ function extractReasoningFieldText2(value) {
16768
17448
  }
16769
17449
  function extractReasoningSummaryText(value) {
16770
17450
  for (const key of ["reasoning_content", "content", "text"]) {
16771
- const text = asString5(get2(value, key));
17451
+ const text = asString6(get2(value, key));
16772
17452
  if (text) return text;
16773
17453
  }
16774
17454
  const summary = get2(value, "summary");
16775
17455
  if (summary === void 0) return void 0;
16776
- const asStr = asString5(summary);
17456
+ const asStr = asString6(summary);
16777
17457
  if (asStr !== void 0) return asStr || void 0;
16778
17458
  const parts = asArray2(summary);
16779
17459
  if (!parts) return void 0;
16780
- const joined = parts.map((part) => asString5(get2(part, "text")) ?? asString5(get2(part, "content")) ?? asString5(part)).filter((t) => !!t).join("\n\n");
17460
+ const joined = parts.map((part) => asString6(get2(part, "text")) ?? asString6(get2(part, "content")) ?? asString6(part)).filter((t) => !!t).join("\n\n");
16781
17461
  return joined || void 0;
16782
17462
  }
16783
17463
  function appendReasoningContent(message, reasoning) {
16784
17464
  const trimmed = reasoning.trim();
16785
17465
  if (!trimmed) return false;
16786
- const existing = asString5(message.reasoning_content);
17466
+ const existing = asString6(message.reasoning_content);
16787
17467
  if (existing) {
16788
17468
  message.reasoning_content = `${existing}
16789
17469
 
@@ -16811,7 +17491,7 @@ function applyCodexChatReasoning(result, body, config2) {
16811
17491
  if (!config2) return;
16812
17492
  const reasoning = asObject4(asObject4(body)?.reasoning);
16813
17493
  if (!reasoning) return;
16814
- const rawEffort = asString5(reasoning.effort);
17494
+ const rawEffort = asString6(reasoning.effort);
16815
17495
  const reasoningEnabled = rawEffort ? !isDisabled(rawEffort) : true;
16816
17496
  if (config2.supportsThinking) {
16817
17497
  if (config2.thinkingParam === "thinking") {
@@ -16927,7 +17607,7 @@ function responsesToChatCompletions(body, reasoningConfig) {
16927
17607
  if (instructions) messages.push({ role: "system", content: instructions });
16928
17608
  appendResponsesInputAsChatMessages(src.input, messages);
16929
17609
  result.messages = collapseSystemMessagesToHead2(messages);
16930
- const model = asString5(src.model) ?? "";
17610
+ const model = asString6(src.model) ?? "";
16931
17611
  if (src.max_output_tokens !== void 0) {
16932
17612
  if (isOpenAiOSeries3(model)) result.max_completion_tokens = src.max_output_tokens;
16933
17613
  else result.max_tokens = src.max_output_tokens;
@@ -16954,17 +17634,17 @@ function responsesToChatCompletions(body, reasoningConfig) {
16954
17634
  return result;
16955
17635
  }
16956
17636
  function instructionText(value) {
16957
- const str2 = asString5(value);
17637
+ const str2 = asString6(value);
16958
17638
  if (str2 !== void 0) return str2;
16959
17639
  const arr = asArray2(value);
16960
17640
  if (arr) {
16961
- return arr.map((part) => asString5(get2(part, "text")) ?? asString5(part)).filter((s2) => !!s2).join("\n\n");
17641
+ return arr.map((part) => asString6(get2(part, "text")) ?? asString6(part)).filter((s2) => !!s2).join("\n\n");
16962
17642
  }
16963
17643
  return "";
16964
17644
  }
16965
17645
  function appendResponsesInputAsChatMessages(input, messages) {
16966
17646
  const state = { pendingToolCalls: [], pendingReasoning: void 0, lastAssistantIndex: void 0 };
16967
- const str2 = asString5(input);
17647
+ const str2 = asString6(input);
16968
17648
  if (str2 !== void 0) {
16969
17649
  messages.push({ role: "user", content: str2 });
16970
17650
  } else {
@@ -16979,7 +17659,7 @@ function appendResponsesInputAsChatMessages(input, messages) {
16979
17659
  backfillToolCallReasoningPlaceholders(messages);
16980
17660
  }
16981
17661
  function appendResponsesItem(item, messages, state) {
16982
- const itemType = asString5(get2(item, "type"));
17662
+ const itemType = asString6(get2(item, "type"));
16983
17663
  switch (itemType) {
16984
17664
  case "function_call": {
16985
17665
  appendUniquePendingReasoning(state, extractReasoningFieldText2(item));
@@ -16988,7 +17668,7 @@ function appendResponsesItem(item, messages, state) {
16988
17668
  }
16989
17669
  case "function_call_output": {
16990
17670
  flushPendingToolCalls(messages, state);
16991
- const callId = asString5(get2(item, "call_id")) ?? "";
17671
+ const callId = asString6(get2(item, "call_id")) ?? "";
16992
17672
  messages.push({ role: "tool", tool_call_id: callId, content: functionCallOutput(get2(item, "output")) });
16993
17673
  return;
16994
17674
  }
@@ -17009,7 +17689,7 @@ function appendResponsesItem(item, messages, state) {
17009
17689
  }
17010
17690
  }
17011
17691
  function functionCallOutput(output) {
17012
- const str2 = asString5(output);
17692
+ const str2 = asString6(output);
17013
17693
  if (str2 !== void 0) return canonicalizeJsonStringIfParseable(str2);
17014
17694
  if (output === void 0) return "";
17015
17695
  return canonicalJsonString(output);
@@ -17023,7 +17703,7 @@ function flushPendingToolCalls(messages, state) {
17023
17703
  messages.push(message);
17024
17704
  }
17025
17705
  function responsesMessageItemToChatMessage(item, state) {
17026
- const role = asString5(get2(item, "role")) ?? "user";
17706
+ const role = asString6(get2(item, "role")) ?? "user";
17027
17707
  const chatRole = responsesRoleToChatRole(role);
17028
17708
  const content = "content" in (asObject4(item) ?? {}) ? responsesContentToChatContent(get2(item, "content")) : null;
17029
17709
  const message = { role: chatRole, content };
@@ -17049,7 +17729,7 @@ function responsesRoleToChatRole(role) {
17049
17729
  }
17050
17730
  }
17051
17731
  function updateLastAssistantIndex(messages, message, state) {
17052
- const role = asString5(message.role);
17732
+ const role = asString6(message.role);
17053
17733
  if (role === "assistant") state.lastAssistantIndex = messages.length;
17054
17734
  else if (role !== "tool") state.lastAssistantIndex = void 0;
17055
17735
  }
@@ -17078,51 +17758,51 @@ function attachReasoningToLastAssistant(messages, lastAssistantIndex, reasoning)
17078
17758
  if (!trimmed) return true;
17079
17759
  if (lastAssistantIndex === void 0) return false;
17080
17760
  const message = messages[lastAssistantIndex];
17081
- if (!message || asString5(message.role) !== "assistant") return false;
17761
+ if (!message || asString6(message.role) !== "assistant") return false;
17082
17762
  appendReasoningContent(message, trimmed);
17083
17763
  return true;
17084
17764
  }
17085
17765
  function backfillToolCallReasoningPlaceholders(messages) {
17086
17766
  for (const message of messages) {
17087
- const isToolCall = asString5(message.role) === "assistant" && (asArray2(message.tool_calls)?.length ?? 0) > 0;
17088
- if (isToolCall && !asString5(message.reasoning_content)?.trim()) {
17767
+ const isToolCall = asString6(message.role) === "assistant" && (asArray2(message.tool_calls)?.length ?? 0) > 0;
17768
+ if (isToolCall && !asString6(message.reasoning_content)?.trim()) {
17089
17769
  message.reasoning_content = "tool call";
17090
17770
  }
17091
17771
  }
17092
17772
  }
17093
17773
  function responsesContentToChatContent(content) {
17094
17774
  if (content === null || content === void 0) return null;
17095
- const str2 = asString5(content);
17775
+ const str2 = asString6(content);
17096
17776
  if (str2 !== void 0) return str2;
17097
17777
  const parts = asArray2(content);
17098
17778
  if (!parts) return content;
17099
17779
  const chatParts = [];
17100
17780
  let hasNonText = false;
17101
17781
  for (const part of parts) {
17102
- const partType = asString5(get2(part, "type")) ?? "";
17782
+ const partType = asString6(get2(part, "type")) ?? "";
17103
17783
  if (partType === "input_text" || partType === "output_text" || partType === "text") {
17104
- const text = asString5(get2(part, "text"));
17784
+ const text = asString6(get2(part, "text"));
17105
17785
  if (text) chatParts.push({ type: "text", text });
17106
17786
  } else if (partType === "refusal") {
17107
- const text = asString5(get2(part, "refusal"));
17787
+ const text = asString6(get2(part, "refusal"));
17108
17788
  if (text) chatParts.push({ type: "text", text });
17109
17789
  } else if (partType === "input_image") {
17110
17790
  const imageUrl = get2(part, "image_url");
17111
17791
  if (imageUrl !== void 0) {
17112
- const value = asObject4(imageUrl) ? imageUrl : { url: asString5(imageUrl) ?? "" };
17792
+ const value = asObject4(imageUrl) ? imageUrl : { url: asString6(imageUrl) ?? "" };
17113
17793
  chatParts.push({ type: "image_url", image_url: value });
17114
17794
  hasNonText = true;
17115
17795
  }
17116
17796
  }
17117
17797
  }
17118
17798
  if (!hasNonText) {
17119
- return chatParts.map((part) => asString5(part.text) ?? "").join("\n");
17799
+ return chatParts.map((part) => asString6(part.text) ?? "").join("\n");
17120
17800
  }
17121
17801
  return chatParts;
17122
17802
  }
17123
17803
  function responsesFunctionCallToChatToolCall(item) {
17124
- const callId = asString5(get2(item, "call_id")) ?? asString5(get2(item, "id")) ?? "";
17125
- const name = asString5(get2(item, "name")) ?? "";
17804
+ const callId = asString6(get2(item, "call_id")) ?? asString6(get2(item, "id")) ?? "";
17805
+ const name = asString6(get2(item, "name")) ?? "";
17126
17806
  return {
17127
17807
  id: callId,
17128
17808
  type: "function",
@@ -17130,7 +17810,7 @@ function responsesFunctionCallToChatToolCall(item) {
17130
17810
  };
17131
17811
  }
17132
17812
  function responsesToolToChatTool(tool) {
17133
- if (asString5(get2(tool, "type")) !== "function") return void 0;
17813
+ if (asString6(get2(tool, "type")) !== "function") return void 0;
17134
17814
  const fn = asObject4(get2(tool, "function"));
17135
17815
  if (fn) {
17136
17816
  const cloned = { ...asObject4(tool) };
@@ -17144,7 +17824,7 @@ function responsesToolToChatTool(tool) {
17144
17824
  return cloned;
17145
17825
  }
17146
17826
  const fnObj = {
17147
- name: asString5(get2(tool, "name")) ?? "",
17827
+ name: asString6(get2(tool, "name")) ?? "",
17148
17828
  description: get2(tool, "description") ?? null,
17149
17829
  parameters: get2(tool, "parameters") ?? {}
17150
17830
  };
@@ -17153,8 +17833,8 @@ function responsesToolToChatTool(tool) {
17153
17833
  }
17154
17834
  function responsesToolChoiceToChat(toolChoice) {
17155
17835
  const obj = asObject4(toolChoice);
17156
- if (obj && asString5(obj.type) === "function") {
17157
- return { type: "function", function: { name: asString5(obj.name) ?? "" } };
17836
+ if (obj && asString6(obj.type) === "function") {
17837
+ return { type: "function", function: { name: asString6(obj.name) ?? "" } };
17158
17838
  }
17159
17839
  return toolChoice;
17160
17840
  }
@@ -17162,8 +17842,8 @@ function collapseSystemMessagesToHead2(messages) {
17162
17842
  const systemChunks = [];
17163
17843
  const rest = [];
17164
17844
  for (const msg of messages) {
17165
- if (asString5(msg.role) === "system") {
17166
- const text = asString5(msg.content);
17845
+ if (asString6(msg.role) === "system") {
17846
+ const text = asString6(msg.content);
17167
17847
  if (text !== void 0) {
17168
17848
  if (text.trim()) systemChunks.push(text);
17169
17849
  continue;
@@ -17207,10 +17887,10 @@ function chatCompletionToResponse(body) {
17207
17887
  if (choice === void 0) throw new Error("Empty choices in chat response");
17208
17888
  const message = get2(choice, "message");
17209
17889
  if (message === void 0) throw new Error("No message in chat choice");
17210
- const responseId = responseIdFromChatId(asString5(get2(body, "id")));
17211
- const model = asString5(get2(body, "model")) ?? "";
17890
+ const responseId = responseIdFromChatId(asString6(get2(body, "id")));
17891
+ const model = asString6(get2(body, "model")) ?? "";
17212
17892
  const createdAt = typeof get2(body, "created") === "number" ? get2(body, "created") : 0;
17213
- const finishReason = asString5(get2(choice, "finish_reason"));
17893
+ const finishReason = asString6(get2(choice, "finish_reason"));
17214
17894
  const reasoning = chatReasoningText2(message);
17215
17895
  const output = [];
17216
17896
  const reasoningItem = chatReasoningToOutputItem2(reasoning, responseId);
@@ -17241,7 +17921,7 @@ function chatReasoningToOutputItem2(reasoning, responseId) {
17241
17921
  function chatReasoningText2(message) {
17242
17922
  const field = extractReasoningFieldText2(message);
17243
17923
  if (field) return field;
17244
- const content = asString5(get2(message, "content"));
17924
+ const content = asString6(get2(message, "content"));
17245
17925
  if (content) {
17246
17926
  const split = splitLeadingThinkBlock3(content);
17247
17927
  if (split && split.reasoning) return split.reasoning;
@@ -17250,7 +17930,7 @@ function chatReasoningText2(message) {
17250
17930
  }
17251
17931
  function chatMessageToOutputItem2(message, responseId) {
17252
17932
  const content = [];
17253
- const text = asString5(get2(message, "content"));
17933
+ const text = asString6(get2(message, "content"));
17254
17934
  if (text !== void 0) {
17255
17935
  const answer = splitLeadingThinkBlock3(text)?.answer ?? text;
17256
17936
  if (answer) content.push({ type: "output_text", text: answer, annotations: [] });
@@ -17258,18 +17938,18 @@ function chatMessageToOutputItem2(message, responseId) {
17258
17938
  const parts = asArray2(get2(message, "content"));
17259
17939
  if (parts) {
17260
17940
  for (const part of parts) {
17261
- const partType = asString5(get2(part, "type")) ?? "";
17941
+ const partType = asString6(get2(part, "type")) ?? "";
17262
17942
  if (partType === "text" || partType === "output_text") {
17263
- const t = asString5(get2(part, "text"));
17943
+ const t = asString6(get2(part, "text"));
17264
17944
  if (t) content.push({ type: "output_text", text: t, annotations: [] });
17265
17945
  } else if (partType === "refusal") {
17266
- const t = asString5(get2(part, "refusal"));
17946
+ const t = asString6(get2(part, "refusal"));
17267
17947
  if (t) content.push({ type: "refusal", refusal: t });
17268
17948
  }
17269
17949
  }
17270
17950
  }
17271
17951
  }
17272
- const refusal = asString5(get2(message, "refusal"));
17952
+ const refusal = asString6(get2(message, "refusal"));
17273
17953
  if (refusal) content.push({ type: "refusal", refusal });
17274
17954
  if (content.length === 0) return void 0;
17275
17955
  return {
@@ -17304,15 +17984,15 @@ function functionCallItem(itemId, callId, name, args, reasoning) {
17304
17984
  return item;
17305
17985
  }
17306
17986
  function chatToolCallToOutputItem2(toolCall, index, reasoning) {
17307
- const callId = asString5(get2(toolCall, "id"))?.trim() || `call_${index}`;
17987
+ const callId = asString6(get2(toolCall, "id"))?.trim() || `call_${index}`;
17308
17988
  const fn = get2(toolCall, "function");
17309
- const name = asString5(get2(fn, "name")) ?? "";
17989
+ const name = asString6(get2(fn, "name")) ?? "";
17310
17990
  const args = canonicalizeToolArguments2(get2(fn, "arguments"));
17311
17991
  return functionCallItem(`fc_${callId}`, callId, name, args, reasoning);
17312
17992
  }
17313
17993
  function chatLegacyFunctionCallToOutputItem2(functionCall, reasoning) {
17314
- const callId = asString5(get2(functionCall, "id"))?.trim() || "call_0";
17315
- const name = asString5(get2(functionCall, "name")) ?? "";
17994
+ const callId = asString6(get2(functionCall, "id"))?.trim() || "call_0";
17995
+ const name = asString6(get2(functionCall, "name")) ?? "";
17316
17996
  const args = canonicalizeToolArguments2(get2(functionCall, "arguments"));
17317
17997
  return functionCallItem(`fc_${callId}`, callId, name, args, reasoning);
17318
17998
  }
@@ -17348,13 +18028,13 @@ function chatErrorToResponseError(body) {
17348
18028
  error: { message: "Upstream returned an empty error response", type: "upstream_error", code: null, param: null }
17349
18029
  };
17350
18030
  }
17351
- const str2 = asString5(body);
18031
+ const str2 = asString6(body);
17352
18032
  if (str2 !== void 0) {
17353
18033
  return { error: { message: str2, type: "upstream_error", code: null, param: null } };
17354
18034
  }
17355
18035
  const source = get2(body, "error") ?? body;
17356
- const message = asString5(get2(source, "message")) ?? asString5(get2(source, "detail")) ?? asString5(get2(source, "status_msg")) ?? asString5(get2(get2(source, "base_resp"), "status_msg")) ?? asString5(source) ?? safeStringify2(source);
17357
- const errorType = asString5(get2(source, "type")) ?? "upstream_error";
18036
+ const message = asString6(get2(source, "message")) ?? asString6(get2(source, "detail")) ?? asString6(get2(source, "status_msg")) ?? asString6(get2(get2(source, "base_resp"), "status_msg")) ?? asString6(source) ?? safeStringify2(source);
18037
+ const errorType = asString6(get2(source, "type")) ?? "upstream_error";
17358
18038
  const code = get2(source, "code") ?? get2(get2(source, "base_resp"), "status_code") ?? null;
17359
18039
  const param = get2(source, "param") ?? null;
17360
18040
  return { error: { message, type: errorType, code, param } };
@@ -17407,8 +18087,8 @@ function leadingThinkPrefixDecision2(buffer) {
17407
18087
  }
17408
18088
  function extractChatSseError2(value) {
17409
18089
  const error51 = get2(value, "error") ?? value;
17410
- const message = asString5(error51) ?? asString5(get2(error51, "message")) ?? asString5(get2(error51, "detail")) ?? JSON.stringify(error51);
17411
- const errorType = asString5(get2(error51, "type")) ?? asString5(get2(error51, "code"));
18090
+ const message = asString6(error51) ?? asString6(get2(error51, "message")) ?? asString6(get2(error51, "detail")) ?? JSON.stringify(error51);
18091
+ const errorType = asString6(get2(error51, "type")) ?? asString6(get2(error51, "code"));
17412
18092
  return { message, errorType: errorType ?? void 0 };
17413
18093
  }
17414
18094
  function stripSseField2(line, field) {
@@ -17517,9 +18197,9 @@ var init_stream2 = __esm({
17517
18197
  finishReason;
17518
18198
  handleChatChunk(chunk) {
17519
18199
  const events = [];
17520
- const id = asString5(get2(chunk, "id"));
18200
+ const id = asString6(get2(chunk, "id"));
17521
18201
  if (id) this.responseId = responseIdFromChatId(id);
17522
- const model = asString5(get2(chunk, "model"));
18202
+ const model = asString6(get2(chunk, "model"));
17523
18203
  if (model) this.model = model;
17524
18204
  const created = get2(chunk, "created");
17525
18205
  if (typeof created === "number") this.createdAt = created;
@@ -17532,7 +18212,7 @@ var init_stream2 = __esm({
17532
18212
  if (delta !== void 0) {
17533
18213
  const reasoning = extractReasoningFieldText2(delta);
17534
18214
  if (reasoning) events.push(...this.pushReasoningDelta(reasoning));
17535
- const content = asString5(get2(delta, "content"));
18215
+ const content = asString6(get2(delta, "content"));
17536
18216
  if (content) events.push(...this.pushContentDelta(content));
17537
18217
  const toolCalls = asArray2(get2(delta, "tool_calls"));
17538
18218
  if (toolCalls) {
@@ -17542,7 +18222,7 @@ var init_stream2 = __esm({
17542
18222
  for (const toolCall of toolCalls) events.push(...this.pushToolCallDelta(toolCall, reasoningForTool));
17543
18223
  }
17544
18224
  }
17545
- const finishReason = asString5(get2(choice, "finish_reason"));
18225
+ const finishReason = asString6(get2(choice, "finish_reason"));
17546
18226
  if (finishReason) this.finishReason = finishReason;
17547
18227
  return events;
17548
18228
  }
@@ -17715,10 +18395,10 @@ var init_stream2 = __esm({
17715
18395
  }
17716
18396
  pushToolCallDelta(toolCall, reasoning) {
17717
18397
  const chatIndex = typeof get2(toolCall, "index") === "number" ? get2(toolCall, "index") : 0;
17718
- const idDelta = asString5(get2(toolCall, "id"));
18398
+ const idDelta = asString6(get2(toolCall, "id"));
17719
18399
  const fn = get2(toolCall, "function");
17720
- const nameDelta = asString5(get2(fn, "name"));
17721
- const argsDelta = asString5(get2(fn, "arguments")) ?? "";
18400
+ const nameDelta = asString6(get2(fn, "name"));
18401
+ const argsDelta = asString6(get2(fn, "arguments")) ?? "";
17722
18402
  let state = this.tools.get(chatIndex);
17723
18403
  if (!state) {
17724
18404
  state = newToolCall2();
@@ -40530,7 +41210,7 @@ function toolInputJson(raw) {
40530
41210
  return "{}";
40531
41211
  }
40532
41212
  }
40533
- function asRecord6(raw) {
41213
+ function asRecord7(raw) {
40534
41214
  if (raw && typeof raw === "object" && !Array.isArray(raw)) return raw;
40535
41215
  return {};
40536
41216
  }
@@ -40669,7 +41349,7 @@ function grokMetaInput(tool) {
40669
41349
  const xai = meta3["x.ai/tool"];
40670
41350
  if (!xai || typeof xai !== "object") return {};
40671
41351
  const input = xai.input;
40672
- return asRecord6(input);
41352
+ return asRecord7(input);
40673
41353
  }
40674
41354
  function queryFromWebSearchTitle(title) {
40675
41355
  if (!title) return void 0;
@@ -40927,11 +41607,11 @@ function unwrapMcpEnvelope(tool, raw) {
40927
41607
  if (!isEnvelope) return null;
40928
41608
  const id = raw.tool_name;
40929
41609
  if (typeof id !== "string" || !id.includes("__")) return null;
40930
- return { toolName: `mcp__${id}`, input: asRecord6(raw.tool_input) };
41610
+ return { toolName: `mcp__${id}`, input: asRecord7(raw.tool_input) };
40931
41611
  }
40932
41612
  function normalizeAcpTool(tool, opts) {
40933
- const raw = { ...grokMetaInput(tool), ...asRecord6(tool.rawInput) };
40934
- const mcp = unwrapMcpEnvelope(tool, asRecord6(tool.rawInput));
41613
+ const raw = { ...grokMetaInput(tool), ...asRecord7(tool.rawInput) };
41614
+ const mcp = unwrapMcpEnvelope(tool, asRecord7(tool.rawInput));
40935
41615
  if (mcp) return mcp;
40936
41616
  const diffs = extractDiffs(tool.content);
40937
41617
  const terminalId = extractEmbeddedTerminalId(tool.content);
@@ -41164,7 +41844,7 @@ function bindSubagentToolId(state, subagentId, toolUseId, description, migrateOu
41164
41844
  });
41165
41845
  }
41166
41846
  }
41167
- function asRecord7(v2) {
41847
+ function asRecord8(v2) {
41168
41848
  if (!v2 || typeof v2 !== "object" || Array.isArray(v2)) return null;
41169
41849
  return v2;
41170
41850
  }
@@ -41197,18 +41877,18 @@ function arrField(o, ...keys) {
41197
41877
  return void 0;
41198
41878
  }
41199
41879
  function parseXaiSessionNotificationEnvelope(raw) {
41200
- const o = asRecord7(raw);
41880
+ const o = asRecord8(raw);
41201
41881
  if (!o) return null;
41202
- const update = asRecord7(o.update);
41882
+ const update = asRecord8(o.update);
41203
41883
  if (!update) return null;
41204
41884
  const sessionId = strField(o, "sessionId", "session_id");
41205
- const meta3 = asRecord7(o._meta) ?? asRecord7(o.meta);
41885
+ const meta3 = asRecord8(o._meta) ?? asRecord8(o.meta);
41206
41886
  const eventSeq = meta3 ? numField(meta3, "eventSeq", "event_seq") ?? null : null;
41207
41887
  const eventId = meta3 ? strField(meta3, "eventId", "event_id") ?? null : null;
41208
41888
  return { sessionId, update, meta: meta3, eventSeq, eventId };
41209
41889
  }
41210
41890
  function parseXaiExtParams(raw) {
41211
- return asRecord7(raw) ?? {};
41891
+ return asRecord8(raw) ?? {};
41212
41892
  }
41213
41893
  function parsePlainTextTaskAck(text) {
41214
41894
  const subagentId = text.match(/subagent_id:\s*(\S+)/i)?.[1] ?? text.match(/task_ids?\s*=\s*\[\s*"([^"]+)"/i)?.[1];
@@ -41313,13 +41993,13 @@ function tryParseJsonObject(text) {
41313
41993
  if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) return null;
41314
41994
  try {
41315
41995
  const v2 = JSON.parse(trimmed);
41316
- return asRecord7(v2);
41996
+ return asRecord8(v2);
41317
41997
  } catch {
41318
41998
  const start = trimmed.indexOf("{");
41319
41999
  const end = trimmed.lastIndexOf("}");
41320
42000
  if (start < 0 || end <= start) return null;
41321
42001
  try {
41322
- return asRecord7(JSON.parse(trimmed.slice(start, end + 1)));
42002
+ return asRecord8(JSON.parse(trimmed.slice(start, end + 1)));
41323
42003
  } catch {
41324
42004
  return null;
41325
42005
  }
@@ -41414,7 +42094,7 @@ function mapXaiSessionUpdate(update, state, ctx = {}) {
41414
42094
  case "session_recap":
41415
42095
  return mapSessionRecap(update);
41416
42096
  case "session_recap_unavailable":
41417
- return [];
42097
+ return [{ type: "session_recap_unavailable" }];
41418
42098
  case "unknown":
41419
42099
  return [];
41420
42100
  default:
@@ -41547,7 +42227,7 @@ function mapWorkflowPhases(raw) {
41547
42227
  if (!raw?.length) return [];
41548
42228
  const out = [];
41549
42229
  for (const item of raw) {
41550
- const p2 = asRecord7(item);
42230
+ const p2 = asRecord8(item);
41551
42231
  if (!p2) continue;
41552
42232
  const title = strField(p2, "title");
41553
42233
  if (!title) continue;
@@ -41560,7 +42240,7 @@ function mapWorkflowAgents(raw) {
41560
42240
  if (!raw?.length) return [];
41561
42241
  const out = [];
41562
42242
  for (const item of raw) {
41563
- const a = asRecord7(item);
42243
+ const a = asRecord8(item);
41564
42244
  if (!a) continue;
41565
42245
  const agentId = strField(a, "agent_id", "agentId");
41566
42246
  const label = strField(a, "label") ?? agentId ?? "agent";
@@ -41586,7 +42266,7 @@ function buildWorkflowPhaseSummary(u, currentPhase, pauseMessage, lastEvent, las
41586
42266
  const phaseBits = [];
41587
42267
  if (phases?.length) {
41588
42268
  for (const p2 of phases) {
41589
- const ph = asRecord7(p2);
42269
+ const ph = asRecord8(p2);
41590
42270
  if (!ph) continue;
41591
42271
  const title = strField(ph, "title") ?? "?";
41592
42272
  const state = strField(ph, "state") ?? "";
@@ -41728,7 +42408,7 @@ function mapTaskBackgrounded(u, state) {
41728
42408
  }];
41729
42409
  }
41730
42410
  function mapTaskCompleted(u, state) {
41731
- const snapshot = asRecord7(u.task_snapshot) ?? asRecord7(u.taskSnapshot) ?? u;
42411
+ const snapshot = asRecord8(u.task_snapshot) ?? asRecord8(u.taskSnapshot) ?? u;
41732
42412
  const taskId = strField(snapshot, "task_id", "taskId");
41733
42413
  if (!taskId) return [];
41734
42414
  const known = state.bgTaskById.get(taskId);
@@ -41960,7 +42640,7 @@ function mapResponseStarted(u, state, ctx) {
41960
42640
  return event ? [event] : [];
41961
42641
  }
41962
42642
  function mapResponseCompleted(u, state, ctx) {
41963
- const usageRaw = asRecord7(u.usage) ?? u;
42643
+ const usageRaw = asRecord8(u.usage) ?? u;
41964
42644
  const input = numField(usageRaw, "inputTokens", "input_tokens") ?? 0;
41965
42645
  const output = numField(usageRaw, "outputTokens", "output_tokens") ?? 0;
41966
42646
  const cacheRead = numField(usageRaw, "cacheReadInputTokens", "cache_read_input_tokens") ?? 0;
@@ -41975,7 +42655,7 @@ function mapResponseCompleted(u, state, ctx) {
41975
42655
  }
41976
42656
  function mapTurnCompleted(u, state, ctx) {
41977
42657
  const events = mapTurnStopReason(u, state);
41978
- const usageRaw = asRecord7(u.usage);
42658
+ const usageRaw = asRecord8(u.usage);
41979
42659
  if (!usageRaw) {
41980
42660
  resetTurnTokens(state);
41981
42661
  return events;
@@ -42142,7 +42822,7 @@ function mapModelAutoSwitched(u) {
42142
42822
  ];
42143
42823
  }
42144
42824
  function mapRetryState(u) {
42145
- const nested = asRecord7(u.retry_state) ?? asRecord7(u.retryState) ?? u;
42825
+ const nested = asRecord8(u.retry_state) ?? asRecord8(u.retryState) ?? u;
42146
42826
  const type = (strField(nested, "type") ?? "").toLowerCase();
42147
42827
  if (type === "retrying") {
42148
42828
  const attempt = numField(nested, "attempt") ?? 1;
@@ -42209,7 +42889,7 @@ function mapAutoRecoveryExhausted(u) {
42209
42889
  }];
42210
42890
  }
42211
42891
  function mapFollowUps(u) {
42212
- const meta3 = asRecord7(u._meta) ?? asRecord7(u.meta);
42892
+ const meta3 = asRecord8(u._meta) ?? asRecord8(u.meta);
42213
42893
  if (meta3 && meta3["x.ai/replayed"] === true) return [];
42214
42894
  const responseId = strField(u, "response_id", "responseId");
42215
42895
  if (!responseId || responseId.length > 128) return [];
@@ -42218,7 +42898,7 @@ function mapFollowUps(u) {
42218
42898
  let count = 0;
42219
42899
  for (const s2 of suggestions) {
42220
42900
  if (count >= 6) break;
42221
- const rec = asRecord7(s2);
42901
+ const rec = asRecord8(s2);
42222
42902
  const label = (rec ? strField(rec, "label") : typeof s2 === "string" ? s2 : void 0)?.trim();
42223
42903
  if (!label) continue;
42224
42904
  const cleaned = label.replace(/[\u0000-\u001f\u007f]/g, "").slice(0, 256).trim();
@@ -49753,7 +50433,7 @@ var init_harness_runners = __esm({
49753
50433
  });
49754
50434
 
49755
50435
  // src/session/codex-live-turn.ts
49756
- function asRecord8(value) {
50436
+ function asRecord9(value) {
49757
50437
  return value && typeof value === "object" && !Array.isArray(value) ? value : null;
49758
50438
  }
49759
50439
  function readString4(value) {
@@ -49784,7 +50464,7 @@ function extractAgentTextFromTurn2(turn) {
49784
50464
  let text = "";
49785
50465
  const items = Array.isArray(turn.items) ? turn.items : [];
49786
50466
  for (const item of items) {
49787
- const rec = asRecord8(item);
50467
+ const rec = asRecord9(item);
49788
50468
  if (!rec) continue;
49789
50469
  if (readString4(rec.type) === "agentMessage" || readString4(rec.itemType) === "agentMessage") {
49790
50470
  const t = readString4(rec.text);
@@ -49819,7 +50499,7 @@ async function openTurnAndStream(opts) {
49819
50499
  ...collaborationMode ? { collaborationMode } : {}
49820
50500
  })
49821
50501
  );
49822
- const turn = asRecord8(turnStartResult.turn);
50502
+ const turn = asRecord9(turnStartResult.turn);
49823
50503
  const turnId = readString4(turn?.id);
49824
50504
  opts.onTurnStarted?.(turnId);
49825
50505
  let finalText = "";
@@ -49847,7 +50527,7 @@ async function openTurnAndStream(opts) {
49847
50527
  continue;
49848
50528
  }
49849
50529
  if (note.method === "turn/completed" || note.method === "turn/completed/v2") {
49850
- const completedTurn = asRecord8(note.params.turn);
50530
+ const completedTurn = asRecord9(note.params.turn);
49851
50531
  const completedId = readString4(completedTurn?.id);
49852
50532
  if (turnId && completedId && completedId !== turnId) continue;
49853
50533
  }
@@ -49855,14 +50535,14 @@ async function openTurnAndStream(opts) {
49855
50535
  const applied = agentEventMapper.apply(note);
49856
50536
  if (applied.textDelta) finalText += applied.textDelta;
49857
50537
  } else if (note.method === "item/agentMessage/delta" || note.method === "item/agentMessageDelta") {
49858
- const delta = readString4(note.params.delta) ?? readString4(note.params.text) ?? readString4(asRecord8(note.params.item)?.delta);
50538
+ const delta = readString4(note.params.delta) ?? readString4(note.params.text) ?? readString4(asRecord9(note.params.item)?.delta);
49859
50539
  if (delta) {
49860
50540
  finalText += delta;
49861
50541
  opts.onDelta?.(delta);
49862
50542
  }
49863
50543
  }
49864
50544
  if (note.method === "turn/completed" || note.method === "turn/completed/v2") {
49865
- const completedTurn = asRecord8(note.params.turn);
50545
+ const completedTurn = asRecord9(note.params.turn);
49866
50546
  const status = readString4(completedTurn?.status) ?? readString4(note.params.status);
49867
50547
  if (status === "failed" || status === "error") {
49868
50548
  throw new Error("Codex turn failed");
@@ -57551,8 +58231,8 @@ import { fileURLToPath } from "node:url";
57551
58231
  function resolveCliReleaseVersion() {
57552
58232
  const fromEnv = process.env.SUPERONE_CLI_VERSION?.trim();
57553
58233
  if (fromEnv) return fromEnv;
57554
- if ("0.51.0-alpha".trim()) {
57555
- return "0.51.0-alpha".trim();
58234
+ if ("0.51.1-alpha".trim()) {
58235
+ return "0.51.1-alpha".trim();
57556
58236
  }
57557
58237
  const fromDist = readDistManifestVersion();
57558
58238
  if (fromDist) return fromDist;
@@ -58423,6 +59103,7 @@ function openNodeDatabase(dbPath) {
58423
59103
  mkdirSync2(dirname3(dbPath), { recursive: true });
58424
59104
  const db = new Database(dbPath);
58425
59105
  db.pragma("journal_mode = WAL");
59106
+ db.pragma("busy_timeout = 5000");
58426
59107
  db.pragma("foreign_keys = ON");
58427
59108
  db.exec(SCHEMA_SQL);
58428
59109
  ensureSessionUiColumns(db);
@@ -59948,7 +60629,7 @@ function requireResourceWrite(client3, scope) {
59948
60629
  if (scope === "user") return requireScopes(client3, OPERATION_SCOPES.adminNode);
59949
60630
  return null;
59950
60631
  }
59951
- function asRecord9(payload) {
60632
+ function asRecord10(payload) {
59952
60633
  return payload && typeof payload === "object" ? payload : {};
59953
60634
  }
59954
60635
  function mapThrown(err) {
@@ -59977,7 +60658,7 @@ function manageOpts(ctx) {
59977
60658
  function handleSkillsList(payload, ctx) {
59978
60659
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
59979
60660
  if (denied) return denied;
59980
- const p2 = asRecord9(payload);
60661
+ const p2 = asRecord10(payload);
59981
60662
  try {
59982
60663
  const projectId = String(p2.projectId ?? "");
59983
60664
  const cwd = projectRoot(ctx.projects, projectId);
@@ -59997,7 +60678,7 @@ function handleSkillsList(payload, ctx) {
59997
60678
  function handleSkillsGet(payload, ctx) {
59998
60679
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
59999
60680
  if (denied) return denied;
60000
- const p2 = asRecord9(payload);
60681
+ const p2 = asRecord10(payload);
60001
60682
  try {
60002
60683
  const projectId = String(p2.projectId ?? "");
60003
60684
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60022,7 +60703,7 @@ function handleSkillsGet(payload, ctx) {
60022
60703
  function handleSkillsReadFile(payload, ctx) {
60023
60704
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60024
60705
  if (denied) return denied;
60025
- const p2 = asRecord9(payload);
60706
+ const p2 = asRecord10(payload);
60026
60707
  try {
60027
60708
  const projectId = String(p2.projectId ?? "");
60028
60709
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60056,7 +60737,7 @@ function handleSkillsReadFile(payload, ctx) {
60056
60737
  function handleSkillsDelete(payload, ctx) {
60057
60738
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60058
60739
  if (denied) return denied;
60059
- const p2 = asRecord9(payload);
60740
+ const p2 = asRecord10(payload);
60060
60741
  try {
60061
60742
  const projectId = String(p2.projectId ?? "");
60062
60743
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60081,7 +60762,7 @@ function handleSkillsDelete(payload, ctx) {
60081
60762
  function handleSkillsInstall(payload, ctx) {
60082
60763
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60083
60764
  if (baseDenied) return baseDenied;
60084
- const p2 = asRecord9(payload);
60765
+ const p2 = asRecord10(payload);
60085
60766
  try {
60086
60767
  const projectId = String(p2.projectId ?? "");
60087
60768
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60115,7 +60796,7 @@ function handleSkillsInstall(payload, ctx) {
60115
60796
  function handleMcpList(payload, ctx) {
60116
60797
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60117
60798
  if (denied) return denied;
60118
- const p2 = asRecord9(payload);
60799
+ const p2 = asRecord10(payload);
60119
60800
  try {
60120
60801
  const projectId = String(p2.projectId ?? "");
60121
60802
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60172,7 +60853,7 @@ function parseMcpWriteConfig(raw) {
60172
60853
  function handleMcpSave(payload, ctx) {
60173
60854
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60174
60855
  if (baseDenied) return baseDenied;
60175
- const p2 = asRecord9(payload);
60856
+ const p2 = asRecord10(payload);
60176
60857
  try {
60177
60858
  const projectId = String(p2.projectId ?? "");
60178
60859
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60202,7 +60883,7 @@ function handleMcpSave(payload, ctx) {
60202
60883
  function handleMcpToggle(payload, ctx) {
60203
60884
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60204
60885
  if (baseDenied) return baseDenied;
60205
- const p2 = asRecord9(payload);
60886
+ const p2 = asRecord10(payload);
60206
60887
  try {
60207
60888
  const projectId = String(p2.projectId ?? "");
60208
60889
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60233,7 +60914,7 @@ function handleMcpToggle(payload, ctx) {
60233
60914
  function handleMcpDelete(payload, ctx) {
60234
60915
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60235
60916
  if (baseDenied) return baseDenied;
60236
- const p2 = asRecord9(payload);
60917
+ const p2 = asRecord10(payload);
60237
60918
  try {
60238
60919
  const projectId = String(p2.projectId ?? "");
60239
60920
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60273,7 +60954,7 @@ function parseMarketplaceScope(raw) {
60273
60954
  async function handlePluginsList(payload, ctx) {
60274
60955
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60275
60956
  if (denied) return denied;
60276
- const p2 = asRecord9(payload);
60957
+ const p2 = asRecord10(payload);
60277
60958
  try {
60278
60959
  const projectId = String(p2.projectId ?? "");
60279
60960
  projectRoot(ctx.projects, projectId);
@@ -60320,7 +61001,7 @@ async function handlePluginsList(payload, ctx) {
60320
61001
  function handlePluginsGet(payload, ctx) {
60321
61002
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60322
61003
  if (denied) return denied;
60323
- const p2 = asRecord9(payload);
61004
+ const p2 = asRecord10(payload);
60324
61005
  try {
60325
61006
  const projectId = String(p2.projectId ?? "");
60326
61007
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60344,7 +61025,7 @@ function handlePluginsGet(payload, ctx) {
60344
61025
  function handlePluginsReadFile(payload, ctx) {
60345
61026
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60346
61027
  if (denied) return denied;
60347
- const p2 = asRecord9(payload);
61028
+ const p2 = asRecord10(payload);
60348
61029
  try {
60349
61030
  const projectId = String(p2.projectId ?? "");
60350
61031
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60372,7 +61053,7 @@ function handlePluginsReadFile(payload, ctx) {
60372
61053
  function handlePluginsDelete(payload, ctx) {
60373
61054
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60374
61055
  if (baseDenied) return baseDenied;
60375
- const p2 = asRecord9(payload);
61056
+ const p2 = asRecord10(payload);
60376
61057
  try {
60377
61058
  const projectId = String(p2.projectId ?? "");
60378
61059
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60398,7 +61079,7 @@ function handlePluginsDelete(payload, ctx) {
60398
61079
  async function handlePluginsInstall(payload, ctx) {
60399
61080
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60400
61081
  if (baseDenied) return baseDenied;
60401
- const p2 = asRecord9(payload);
61082
+ const p2 = asRecord10(payload);
60402
61083
  try {
60403
61084
  const projectId = String(p2.projectId ?? "");
60404
61085
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60424,7 +61105,7 @@ async function handlePluginsInstall(payload, ctx) {
60424
61105
  function handlePluginsUpdate(payload, ctx) {
60425
61106
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60426
61107
  if (baseDenied) return baseDenied;
60427
- const p2 = asRecord9(payload);
61108
+ const p2 = asRecord10(payload);
60428
61109
  try {
60429
61110
  const projectId = String(p2.projectId ?? "");
60430
61111
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60450,7 +61131,7 @@ function handlePluginsUpdate(payload, ctx) {
60450
61131
  function handlePluginsListMarketplace(payload, ctx) {
60451
61132
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60452
61133
  if (denied) return denied;
60453
- const p2 = asRecord9(payload);
61134
+ const p2 = asRecord10(payload);
60454
61135
  try {
60455
61136
  const projectId = String(p2.projectId ?? "");
60456
61137
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60472,7 +61153,7 @@ function handlePluginsListMarketplace(payload, ctx) {
60472
61153
  async function handlePluginsAddMarketplace(payload, ctx) {
60473
61154
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60474
61155
  if (baseDenied) return baseDenied;
60475
- const p2 = asRecord9(payload);
61156
+ const p2 = asRecord10(payload);
60476
61157
  try {
60477
61158
  const projectId = String(p2.projectId ?? "");
60478
61159
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60498,7 +61179,7 @@ async function handlePluginsAddMarketplace(payload, ctx) {
60498
61179
  async function handlePluginsRemoveMarketplace(payload, ctx) {
60499
61180
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60500
61181
  if (baseDenied) return baseDenied;
60501
- const p2 = asRecord9(payload);
61182
+ const p2 = asRecord10(payload);
60502
61183
  try {
60503
61184
  const projectId = String(p2.projectId ?? "");
60504
61185
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60533,7 +61214,7 @@ async function handlePluginsUpdateMarketplace(payload, ctx) {
60533
61214
  if (denied) return denied;
60534
61215
  const adminDenied = requireScopes(ctx.client, OPERATION_SCOPES.adminNode);
60535
61216
  if (adminDenied) return adminDenied;
60536
- const p2 = asRecord9(payload);
61217
+ const p2 = asRecord10(payload);
60537
61218
  try {
60538
61219
  const projectId = String(p2.projectId ?? "");
60539
61220
  if (projectId) {
@@ -60555,7 +61236,7 @@ async function handlePluginsUpdateMarketplace(payload, ctx) {
60555
61236
  function handlePluginsReadMarketplace(payload, ctx) {
60556
61237
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60557
61238
  if (denied) return denied;
60558
- const p2 = asRecord9(payload);
61239
+ const p2 = asRecord10(payload);
60559
61240
  try {
60560
61241
  const projectId = String(p2.projectId ?? "");
60561
61242
  if (projectId) {
@@ -60586,7 +61267,7 @@ function handlePluginsReadMarketplace(payload, ctx) {
60586
61267
  function handlePluginsReadMarketplaceFile(payload, ctx) {
60587
61268
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60588
61269
  if (denied) return denied;
60589
- const p2 = asRecord9(payload);
61270
+ const p2 = asRecord10(payload);
60590
61271
  try {
60591
61272
  const projectId = String(p2.projectId ?? "");
60592
61273
  if (projectId) {
@@ -60620,7 +61301,7 @@ function handlePluginsReadMarketplaceFile(payload, ctx) {
60620
61301
  function handleAgentsList(payload, ctx) {
60621
61302
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60622
61303
  if (denied) return denied;
60623
- const p2 = asRecord9(payload);
61304
+ const p2 = asRecord10(payload);
60624
61305
  try {
60625
61306
  const projectId = String(p2.projectId ?? "");
60626
61307
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60637,7 +61318,7 @@ function handleAgentsList(payload, ctx) {
60637
61318
  function handleAgentsReadFile(payload, ctx) {
60638
61319
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60639
61320
  if (denied) return denied;
60640
- const p2 = asRecord9(payload);
61321
+ const p2 = asRecord10(payload);
60641
61322
  try {
60642
61323
  const projectId = String(p2.projectId ?? "");
60643
61324
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60669,7 +61350,7 @@ function parseHookSavePayload(raw) {
60669
61350
  function handleHooksList(payload, ctx) {
60670
61351
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60671
61352
  if (denied) return denied;
60672
- const p2 = asRecord9(payload);
61353
+ const p2 = asRecord10(payload);
60673
61354
  try {
60674
61355
  const projectId = String(p2.projectId ?? "");
60675
61356
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60682,7 +61363,7 @@ function handleHooksList(payload, ctx) {
60682
61363
  function handleHooksSave(payload, ctx) {
60683
61364
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60684
61365
  if (baseDenied) return baseDenied;
60685
- const p2 = asRecord9(payload);
61366
+ const p2 = asRecord10(payload);
60686
61367
  try {
60687
61368
  const projectId = String(p2.projectId ?? "");
60688
61369
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60710,7 +61391,7 @@ function handleHooksSave(payload, ctx) {
60710
61391
  function handleHooksDelete(payload, ctx) {
60711
61392
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60712
61393
  if (baseDenied) return baseDenied;
60713
- const p2 = asRecord9(payload);
61394
+ const p2 = asRecord10(payload);
60714
61395
  try {
60715
61396
  const projectId = String(p2.projectId ?? "");
60716
61397
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60809,7 +61490,7 @@ function requireScopes2(client3, scopes) {
60809
61490
  }
60810
61491
  return null;
60811
61492
  }
60812
- function asRecord10(payload) {
61493
+ function asRecord11(payload) {
60813
61494
  return payload && typeof payload === "object" ? payload : {};
60814
61495
  }
60815
61496
  function mapThrown2(err) {
@@ -60875,7 +61556,7 @@ function parseSchedule(raw) {
60875
61556
  function handleAutomationList(payload, ctx) {
60876
61557
  const denied = requireScopes2(ctx.client, OPERATION_SCOPES.readSession);
60877
61558
  if (denied) return denied;
60878
- const p2 = asRecord10(payload);
61559
+ const p2 = asRecord11(payload);
60879
61560
  const projectId = String(p2.projectId ?? "").trim();
60880
61561
  if (!projectId) {
60881
61562
  return { error: { code: "invalid_argument", message: "projectId is required" } };
@@ -60894,7 +61575,7 @@ function handleAutomationList(payload, ctx) {
60894
61575
  function handleAutomationCreate(payload, ctx) {
60895
61576
  const denied = requireScopes2(ctx.client, OPERATION_SCOPES.operateSession);
60896
61577
  if (denied) return denied;
60897
- const p2 = asRecord10(payload);
61578
+ const p2 = asRecord11(payload);
60898
61579
  const projectId = String(p2.projectId ?? "").trim();
60899
61580
  if (!projectId) {
60900
61581
  return { error: { code: "invalid_argument", message: "projectId is required" } };
@@ -60931,7 +61612,7 @@ function handleAutomationCreate(payload, ctx) {
60931
61612
  function handleAutomationUpdate(payload, ctx) {
60932
61613
  const denied = requireScopes2(ctx.client, OPERATION_SCOPES.operateSession);
60933
61614
  if (denied) return denied;
60934
- const p2 = asRecord10(payload);
61615
+ const p2 = asRecord11(payload);
60935
61616
  const automationId = String(p2.automationId ?? p2.id ?? "").trim();
60936
61617
  if (!automationId) {
60937
61618
  return { error: { code: "invalid_argument", message: "automationId is required" } };
@@ -60975,7 +61656,7 @@ function handleAutomationUpdate(payload, ctx) {
60975
61656
  function handleAutomationDelete(payload, ctx) {
60976
61657
  const denied = requireScopes2(ctx.client, OPERATION_SCOPES.operateSession);
60977
61658
  if (denied) return denied;
60978
- const p2 = asRecord10(payload);
61659
+ const p2 = asRecord11(payload);
60979
61660
  const automationId = String(p2.automationId ?? p2.id ?? "").trim();
60980
61661
  if (!automationId) {
60981
61662
  return { error: { code: "invalid_argument", message: "automationId is required" } };
@@ -61001,7 +61682,7 @@ function handleAutomationDelete(payload, ctx) {
61001
61682
  async function handleAutomationRunNow(payload, ctx) {
61002
61683
  const denied = requireScopes2(ctx.client, OPERATION_SCOPES.operateSession);
61003
61684
  if (denied) return denied;
61004
- const p2 = asRecord10(payload);
61685
+ const p2 = asRecord11(payload);
61005
61686
  const automationId = String(p2.automationId ?? p2.id ?? "").trim();
61006
61687
  if (!automationId) {
61007
61688
  return { error: { code: "invalid_argument", message: "automationId is required" } };
@@ -61059,7 +61740,7 @@ function requireScopes3(client3, scopes) {
61059
61740
  }
61060
61741
  return null;
61061
61742
  }
61062
- function asRecord11(payload) {
61743
+ function asRecord12(payload) {
61063
61744
  return payload && typeof payload === "object" ? payload : {};
61064
61745
  }
61065
61746
  function mapThrown3(err) {
@@ -61130,7 +61811,7 @@ var CODEX_MUTATING_METHODS = [
61130
61811
  function handleGetAuthStatus(payload, ctx) {
61131
61812
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.readEnvironment);
61132
61813
  if (denied) return denied;
61133
- const p2 = asRecord11(payload);
61814
+ const p2 = asRecord12(payload);
61134
61815
  const projectId = projectIdOf(p2);
61135
61816
  if (!projectId) {
61136
61817
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61143,7 +61824,7 @@ function handleGetAuthStatus(payload, ctx) {
61143
61824
  function handleSetAuth(payload, ctx) {
61144
61825
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61145
61826
  if (denied) return denied;
61146
- const p2 = asRecord11(payload);
61827
+ const p2 = asRecord12(payload);
61147
61828
  const projectId = projectIdOf(p2);
61148
61829
  if (!projectId) {
61149
61830
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61168,7 +61849,7 @@ function handleSetAuth(payload, ctx) {
61168
61849
  async function handleGetRateLimits(payload, ctx) {
61169
61850
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.readEnvironment);
61170
61851
  if (denied) return denied;
61171
- const p2 = asRecord11(payload);
61852
+ const p2 = asRecord12(payload);
61172
61853
  const projectId = projectIdOf(p2);
61173
61854
  if (!projectId) {
61174
61855
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61195,7 +61876,7 @@ async function handleGetRateLimits(payload, ctx) {
61195
61876
  async function handleGetAccountUsage(payload, ctx) {
61196
61877
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.readEnvironment);
61197
61878
  if (denied) return denied;
61198
- const p2 = asRecord11(payload);
61879
+ const p2 = asRecord12(payload);
61199
61880
  const projectId = projectIdOf(p2);
61200
61881
  if (!projectId) {
61201
61882
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61222,7 +61903,7 @@ async function handleGetAccountUsage(payload, ctx) {
61222
61903
  async function handleConsumeRateLimitReset(payload, ctx) {
61223
61904
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61224
61905
  if (denied) return denied;
61225
- const p2 = asRecord11(payload);
61906
+ const p2 = asRecord12(payload);
61226
61907
  const projectId = projectIdOf(p2);
61227
61908
  if (!projectId) {
61228
61909
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61252,7 +61933,7 @@ async function handleConsumeRateLimitReset(payload, ctx) {
61252
61933
  async function handleLoginMcpOauth(payload, ctx) {
61253
61934
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61254
61935
  if (denied) return denied;
61255
- const p2 = asRecord11(payload);
61936
+ const p2 = asRecord12(payload);
61256
61937
  const projectId = projectIdOf(p2);
61257
61938
  const serverName = String(p2.serverName ?? p2.name ?? "").trim();
61258
61939
  if (!projectId || !serverName) {
@@ -61272,7 +61953,7 @@ async function handleLoginMcpOauth(payload, ctx) {
61272
61953
  async function handleDetectExternalAgent(payload, ctx) {
61273
61954
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.readEnvironment);
61274
61955
  if (denied) return denied;
61275
- const p2 = asRecord11(payload);
61956
+ const p2 = asRecord12(payload);
61276
61957
  const projectId = projectIdOf(p2);
61277
61958
  if (!projectId) {
61278
61959
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61291,7 +61972,7 @@ async function handleDetectExternalAgent(payload, ctx) {
61291
61972
  async function handleImportExternalAgent(payload, ctx) {
61292
61973
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61293
61974
  if (denied) return denied;
61294
- const p2 = asRecord11(payload);
61975
+ const p2 = asRecord12(payload);
61295
61976
  const projectId = projectIdOf(p2);
61296
61977
  if (!projectId) {
61297
61978
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61309,7 +61990,7 @@ async function handleImportExternalAgent(payload, ctx) {
61309
61990
  async function handlePluginsList2(payload, ctx) {
61310
61991
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.readWorkspace);
61311
61992
  if (denied) return denied;
61312
- const p2 = asRecord11(payload);
61993
+ const p2 = asRecord12(payload);
61313
61994
  const projectId = projectIdOf(p2);
61314
61995
  if (!projectId) {
61315
61996
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61332,7 +62013,7 @@ async function handlePluginsList2(payload, ctx) {
61332
62013
  async function handlePluginsInstall2(payload, ctx) {
61333
62014
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61334
62015
  if (denied) return denied;
61335
- const p2 = asRecord11(payload);
62016
+ const p2 = asRecord12(payload);
61336
62017
  const projectId = projectIdOf(p2);
61337
62018
  const key = String(p2.key ?? p2.pluginId ?? "").trim();
61338
62019
  if (!projectId || !key) {
@@ -61348,7 +62029,7 @@ async function handlePluginsInstall2(payload, ctx) {
61348
62029
  async function handlePluginsUninstall(payload, ctx) {
61349
62030
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61350
62031
  if (denied) return denied;
61351
- const p2 = asRecord11(payload);
62032
+ const p2 = asRecord12(payload);
61352
62033
  const projectId = projectIdOf(p2);
61353
62034
  const key = String(p2.key ?? p2.pluginId ?? "").trim();
61354
62035
  if (!projectId || !key) {
@@ -61364,7 +62045,7 @@ async function handlePluginsUninstall(payload, ctx) {
61364
62045
  async function handleMarketplaceAdd(payload, ctx) {
61365
62046
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61366
62047
  if (denied) return denied;
61367
- const p2 = asRecord11(payload);
62048
+ const p2 = asRecord12(payload);
61368
62049
  const projectId = projectIdOf(p2);
61369
62050
  const source = String(p2.source ?? "").trim();
61370
62051
  if (!projectId || !source) {
@@ -61393,7 +62074,7 @@ async function handleMarketplaceAdd(payload, ctx) {
61393
62074
  async function handleMarketplaceRemove(payload, ctx) {
61394
62075
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61395
62076
  if (denied) return denied;
61396
- const p2 = asRecord11(payload);
62077
+ const p2 = asRecord12(payload);
61397
62078
  const projectId = projectIdOf(p2);
61398
62079
  const marketplaceName = String(p2.marketplaceName ?? p2.name ?? "").trim();
61399
62080
  if (!projectId || !marketplaceName) {
@@ -61416,7 +62097,7 @@ async function handleMarketplaceRemove(payload, ctx) {
61416
62097
  async function handleMarketplaceUpgrade(payload, ctx) {
61417
62098
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61418
62099
  if (denied) return denied;
61419
- const p2 = asRecord11(payload);
62100
+ const p2 = asRecord12(payload);
61420
62101
  const projectId = projectIdOf(p2);
61421
62102
  if (!projectId) {
61422
62103
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61449,7 +62130,7 @@ function requireScopes4(client3, scopes) {
61449
62130
  }
61450
62131
  return null;
61451
62132
  }
61452
- function asRecord12(payload) {
62133
+ function asRecord13(payload) {
61453
62134
  return payload && typeof payload === "object" ? payload : {};
61454
62135
  }
61455
62136
  function mapThrown4(err) {
@@ -61478,7 +62159,7 @@ function dispatchSessionProviderRpc(method, payload, ctx) {
61478
62159
  function handleList(payload, ctx) {
61479
62160
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.readEnvironment);
61480
62161
  if (denied) return denied;
61481
- const p2 = asRecord12(payload);
62162
+ const p2 = asRecord13(payload);
61482
62163
  try {
61483
62164
  const harnessId = typeof p2.harnessId === "string" && p2.harnessId.trim() ? p2.harnessId.trim() : null;
61484
62165
  const providers = harnessId ? ctx.sessionProviders.listByHarness(harnessId) : ctx.sessionProviders.list();
@@ -61490,7 +62171,7 @@ function handleList(payload, ctx) {
61490
62171
  function handleGet(payload, ctx) {
61491
62172
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.readEnvironment);
61492
62173
  if (denied) return denied;
61493
- const p2 = asRecord12(payload);
62174
+ const p2 = asRecord13(payload);
61494
62175
  const id = String(p2.id ?? "");
61495
62176
  if (!id) return { error: { code: "invalid_argument", message: "id required" } };
61496
62177
  try {
@@ -61502,7 +62183,7 @@ function handleGet(payload, ctx) {
61502
62183
  function handleGetBase(payload, ctx) {
61503
62184
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.readEnvironment);
61504
62185
  if (denied) return denied;
61505
- const p2 = asRecord12(payload);
62186
+ const p2 = asRecord13(payload);
61506
62187
  const harnessId = String(p2.harnessId ?? "");
61507
62188
  if (!harnessId) return { error: { code: "invalid_argument", message: "harnessId required" } };
61508
62189
  try {
@@ -61514,7 +62195,7 @@ function handleGetBase(payload, ctx) {
61514
62195
  function handleCreate(payload, ctx) {
61515
62196
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.adminNode);
61516
62197
  if (denied) return denied;
61517
- const p2 = asRecord12(payload);
62198
+ const p2 = asRecord13(payload);
61518
62199
  try {
61519
62200
  const provider = ctx.sessionProviders.create({
61520
62201
  harnessId: String(p2.harnessId ?? ""),
@@ -61530,7 +62211,7 @@ function handleCreate(payload, ctx) {
61530
62211
  function handleUpdate(payload, ctx) {
61531
62212
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.adminNode);
61532
62213
  if (denied) return denied;
61533
- const p2 = asRecord12(payload);
62214
+ const p2 = asRecord13(payload);
61534
62215
  const id = String(p2.id ?? "");
61535
62216
  if (!id) return { error: { code: "invalid_argument", message: "id required" } };
61536
62217
  try {
@@ -61546,7 +62227,7 @@ function handleUpdate(payload, ctx) {
61546
62227
  function handleDelete(payload, ctx) {
61547
62228
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.adminNode);
61548
62229
  if (denied) return denied;
61549
- const p2 = asRecord12(payload);
62230
+ const p2 = asRecord13(payload);
61550
62231
  const id = String(p2.id ?? "");
61551
62232
  if (!id) return { error: { code: "invalid_argument", message: "id required" } };
61552
62233
  try {
@@ -61587,7 +62268,7 @@ function requireScopes5(client3, scopes) {
61587
62268
  }
61588
62269
  return null;
61589
62270
  }
61590
- function asRecord13(payload) {
62271
+ function asRecord14(payload) {
61591
62272
  return payload && typeof payload === "object" ? payload : {};
61592
62273
  }
61593
62274
  function defaultProbeModels(ctx) {
@@ -61615,7 +62296,7 @@ async function dispatchHarnessResourcesRpc(method, payload, ctx) {
61615
62296
  async function handleHarnessResources(payload, ctx) {
61616
62297
  const denied = requireScopes5(ctx.client, OPERATION_SCOPES.readEnvironment);
61617
62298
  if (denied) return denied;
61618
- const p2 = asRecord13(payload);
62299
+ const p2 = asRecord14(payload);
61619
62300
  const projectId = String(p2.projectId ?? "");
61620
62301
  if (!projectId) {
61621
62302
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -62052,7 +62733,7 @@ function handleProviderListCredentials(ctx) {
62052
62733
  function handleProviderGetCredentialDecrypted(payload, ctx) {
62053
62734
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62054
62735
  if (denied) return denied;
62055
- const p2 = asRecord14(payload);
62736
+ const p2 = asRecord15(payload);
62056
62737
  const cred = ctx.providers.getCredentialDecrypted(String(p2.id ?? ""));
62057
62738
  if (!cred) return { error: { code: "not_found", message: "credential not found" } };
62058
62739
  return { result: cred };
@@ -62060,7 +62741,7 @@ function handleProviderGetCredentialDecrypted(payload, ctx) {
62060
62741
  function handleProviderCreateCredential(payload, ctx) {
62061
62742
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62062
62743
  if (denied) return denied;
62063
- const p2 = asRecord14(payload);
62744
+ const p2 = asRecord15(payload);
62064
62745
  try {
62065
62746
  return {
62066
62747
  result: ctx.providers.createCredential({
@@ -62082,7 +62763,7 @@ function handleProviderCreateCredential(payload, ctx) {
62082
62763
  function handleProviderUpdateCredential(payload, ctx) {
62083
62764
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62084
62765
  if (denied) return denied;
62085
- const p2 = asRecord14(payload);
62766
+ const p2 = asRecord15(payload);
62086
62767
  const id = String(p2.id ?? "");
62087
62768
  const updated = ctx.providers.updateCredential(id, {
62088
62769
  name: typeof p2.name === "string" ? p2.name : void 0,
@@ -62099,7 +62780,7 @@ function handleProviderUpdateCredential(payload, ctx) {
62099
62780
  function handleProviderDeleteCredential(payload, ctx) {
62100
62781
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62101
62782
  if (denied) return denied;
62102
- const p2 = asRecord14(payload);
62783
+ const p2 = asRecord15(payload);
62103
62784
  const ok = ctx.providers.deleteCredential(String(p2.id ?? ""));
62104
62785
  if (!ok) return { error: { code: "not_found", message: "credential not found" } };
62105
62786
  return { result: { ok: true } };
@@ -62112,7 +62793,7 @@ function handleProviderListBindings(ctx) {
62112
62793
  function handleProviderSetBinding(payload, ctx) {
62113
62794
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62114
62795
  if (denied) return denied;
62115
- const p2 = asRecord14(payload);
62796
+ const p2 = asRecord15(payload);
62116
62797
  const binding = p2;
62117
62798
  if (!binding.consumer || !binding.credentialId) {
62118
62799
  return { error: { code: "invalid_argument", message: "consumer and credentialId required" } };
@@ -62123,7 +62804,7 @@ function handleProviderSetBinding(payload, ctx) {
62123
62804
  function handleProviderClearBinding(payload, ctx) {
62124
62805
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62125
62806
  if (denied) return denied;
62126
- const p2 = asRecord14(payload);
62807
+ const p2 = asRecord15(payload);
62127
62808
  ctx.providers.clearBinding(String(p2.consumer ?? ""));
62128
62809
  return { result: { ok: true } };
62129
62810
  }
@@ -62135,14 +62816,14 @@ function handleProviderListCustomPlatforms(ctx) {
62135
62816
  function handleProviderUpsertCustomPlatform(payload, ctx) {
62136
62817
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62137
62818
  if (denied) return denied;
62138
- const def = asRecord14(payload);
62819
+ const def = asRecord15(payload);
62139
62820
  if (!def?.id) return { error: { code: "invalid_argument", message: "platform id required" } };
62140
62821
  return { result: ctx.providers.upsertCustomPlatform(def) };
62141
62822
  }
62142
62823
  function handleProviderDeleteCustomPlatform(payload, ctx) {
62143
62824
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62144
62825
  if (denied) return denied;
62145
- const p2 = asRecord14(payload);
62826
+ const p2 = asRecord15(payload);
62146
62827
  const ok = ctx.providers.deleteCustomPlatform(String(p2.id ?? ""));
62147
62828
  if (!ok) return { error: { code: "not_found", message: "custom platform not found" } };
62148
62829
  return { result: { ok: true } };
@@ -62155,7 +62836,7 @@ function handleProviderExportBundle(ctx) {
62155
62836
  function handleProviderListModels(payload, ctx) {
62156
62837
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readEnvironment);
62157
62838
  if (denied) return denied;
62158
- const p2 = asRecord14(payload);
62839
+ const p2 = asRecord15(payload);
62159
62840
  const harness = String(p2.harness ?? p2.harnessId ?? "claude");
62160
62841
  const apiProviderId = typeof p2.apiProviderId === "string" && p2.apiProviderId.trim() ? p2.apiProviderId.trim() : null;
62161
62842
  return {
@@ -62167,7 +62848,7 @@ function handleProviderListModels(payload, ctx) {
62167
62848
  function handleProviderImportBundle(payload, ctx) {
62168
62849
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62169
62850
  if (denied) return denied;
62170
- const p2 = asRecord14(payload);
62851
+ const p2 = asRecord15(payload);
62171
62852
  const bundle = p2.bundle && typeof p2.bundle === "object" ? p2.bundle : p2;
62172
62853
  const replaceAll = p2.replaceAll === true;
62173
62854
  try {
@@ -62232,7 +62913,7 @@ function handleHarnessList(ctx) {
62232
62913
  function handleHarnessShow(payload, ctx) {
62233
62914
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62234
62915
  if (denied) return denied;
62235
- const p2 = asRecord14(payload);
62916
+ const p2 = asRecord15(payload);
62236
62917
  const id = typeof p2.harnessId === "string" ? p2.harnessId : typeof p2.id === "string" ? p2.id : "";
62237
62918
  if (!isNodeHarnessId(id)) {
62238
62919
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
@@ -62242,7 +62923,7 @@ function handleHarnessShow(payload, ctx) {
62242
62923
  function handleHarnessProbe(payload, ctx) {
62243
62924
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62244
62925
  if (denied) return denied;
62245
- const p2 = asRecord14(payload);
62926
+ const p2 = asRecord15(payload);
62246
62927
  const id = typeof p2.harnessId === "string" ? p2.harnessId : typeof p2.id === "string" ? p2.id : "";
62247
62928
  if (!isNodeHarnessId(id)) {
62248
62929
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
@@ -62257,7 +62938,7 @@ function handleHarnessProbe(payload, ctx) {
62257
62938
  async function handleHarnessEnable(payload, ctx) {
62258
62939
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62259
62940
  if (denied) return denied;
62260
- const p2 = asRecord14(payload);
62941
+ const p2 = asRecord15(payload);
62261
62942
  const id = typeof p2.harnessId === "string" ? p2.harnessId : typeof p2.id === "string" ? p2.id : "";
62262
62943
  if (!isNodeHarnessId(id)) {
62263
62944
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
@@ -62283,7 +62964,7 @@ async function handleHarnessEnable(payload, ctx) {
62283
62964
  function handleHarnessDisable(payload, ctx) {
62284
62965
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62285
62966
  if (denied) return denied;
62286
- const p2 = asRecord14(payload);
62967
+ const p2 = asRecord15(payload);
62287
62968
  const id = typeof p2.harnessId === "string" ? p2.harnessId : typeof p2.id === "string" ? p2.id : "";
62288
62969
  if (!isNodeHarnessId(id)) {
62289
62970
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
@@ -62348,7 +63029,7 @@ function handleSettingsGet(ctx) {
62348
63029
  function handleSettingsPatch(payload, ctx) {
62349
63030
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62350
63031
  if (denied) return denied;
62351
- const p2 = asRecord14(payload);
63032
+ const p2 = asRecord15(payload);
62352
63033
  const rawPatch = p2.patch && typeof p2.patch === "object" ? p2.patch : p2;
62353
63034
  try {
62354
63035
  const settings = patchNodeAgentSettings(
@@ -62369,13 +63050,13 @@ async function handleSandboxProbe(ctx) {
62369
63050
  return mapThrown6(err);
62370
63051
  }
62371
63052
  }
62372
- function asRecord14(payload) {
63053
+ function asRecord15(payload) {
62373
63054
  return payload && typeof payload === "object" ? payload : {};
62374
63055
  }
62375
63056
  function handleTerminalCreate(payload, ctx) {
62376
63057
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62377
63058
  if (denied) return denied;
62378
- const p2 = asRecord14(payload);
63059
+ const p2 = asRecord15(payload);
62379
63060
  const cwd = typeof p2.cwd === "string" ? p2.cwd : process.cwd();
62380
63061
  try {
62381
63062
  const info = ctx.terminals.create({
@@ -62400,7 +63081,7 @@ function handleTerminalCreate(payload, ctx) {
62400
63081
  function handleTerminalAttach(payload, ctx) {
62401
63082
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62402
63083
  if (denied) return denied;
62403
- const p2 = asRecord14(payload);
63084
+ const p2 = asRecord15(payload);
62404
63085
  const terminalId = String(p2.terminalId ?? "");
62405
63086
  try {
62406
63087
  const attached = ctx.terminals.attach(terminalId);
@@ -62412,7 +63093,7 @@ function handleTerminalAttach(payload, ctx) {
62412
63093
  function handleTerminalRead(payload, ctx) {
62413
63094
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62414
63095
  if (denied) return denied;
62415
- const p2 = asRecord14(payload);
63096
+ const p2 = asRecord15(payload);
62416
63097
  try {
62417
63098
  return {
62418
63099
  result: ctx.terminals.readAfter(
@@ -62440,7 +63121,7 @@ function requireTerminalLease(payload, ctx, terminalId) {
62440
63121
  function handleTerminalWrite(payload, ctx) {
62441
63122
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62442
63123
  if (denied) return denied;
62443
- const p2 = asRecord14(payload);
63124
+ const p2 = asRecord15(payload);
62444
63125
  const terminalId = String(p2.terminalId ?? "");
62445
63126
  const leaseErr = requireTerminalLease(p2, ctx, terminalId);
62446
63127
  if (leaseErr) return leaseErr;
@@ -62458,7 +63139,7 @@ function handleTerminalWrite(payload, ctx) {
62458
63139
  function handleTerminalResize(payload, ctx) {
62459
63140
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62460
63141
  if (denied) return denied;
62461
- const p2 = asRecord14(payload);
63142
+ const p2 = asRecord15(payload);
62462
63143
  const terminalId = String(p2.terminalId ?? "");
62463
63144
  const leaseErr = requireTerminalLease(p2, ctx, terminalId);
62464
63145
  if (leaseErr) return leaseErr;
@@ -62474,7 +63155,7 @@ function handleTerminalResize(payload, ctx) {
62474
63155
  function handleTerminalKill(payload, ctx) {
62475
63156
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62476
63157
  if (denied) return denied;
62477
- const p2 = asRecord14(payload);
63158
+ const p2 = asRecord15(payload);
62478
63159
  const terminalId = String(p2.terminalId ?? "");
62479
63160
  const leaseErr = requireTerminalLease(p2, ctx, terminalId);
62480
63161
  if (leaseErr) return leaseErr;
@@ -62488,7 +63169,7 @@ function handleTerminalKill(payload, ctx) {
62488
63169
  function handleTerminalAcquireControl(payload, ctx) {
62489
63170
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62490
63171
  if (denied) return denied;
62491
- const p2 = asRecord14(payload);
63172
+ const p2 = asRecord15(payload);
62492
63173
  const terminalId = String(p2.terminalId ?? "");
62493
63174
  try {
62494
63175
  return {
@@ -62505,7 +63186,7 @@ function handleTerminalAcquireControl(payload, ctx) {
62505
63186
  function handleTerminalRenewControl(payload, ctx) {
62506
63187
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62507
63188
  if (denied) return denied;
62508
- const p2 = asRecord14(payload);
63189
+ const p2 = asRecord15(payload);
62509
63190
  try {
62510
63191
  return {
62511
63192
  result: ctx.leases.renew({
@@ -62522,7 +63203,7 @@ function handleTerminalRenewControl(payload, ctx) {
62522
63203
  function handleTerminalReleaseControl(payload, ctx) {
62523
63204
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62524
63205
  if (denied) return denied;
62525
- const p2 = asRecord14(payload);
63206
+ const p2 = asRecord15(payload);
62526
63207
  try {
62527
63208
  ctx.leases.release(
62528
63209
  String(p2.leaseId ?? ""),
@@ -62547,7 +63228,7 @@ function handleProjectList(ctx) {
62547
63228
  function handleProjectGet(payload, ctx) {
62548
63229
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readProject);
62549
63230
  if (denied) return denied;
62550
- const p2 = asRecord14(payload);
63231
+ const p2 = asRecord15(payload);
62551
63232
  const projectId = String(p2.projectId ?? "");
62552
63233
  return { result: ctx.projects.get(projectId) };
62553
63234
  }
@@ -62563,7 +63244,7 @@ function expandHostPath(path) {
62563
63244
  function handleProjectOpen(payload, ctx) {
62564
63245
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.manageProject);
62565
63246
  if (denied) return denied;
62566
- const p2 = asRecord14(payload);
63247
+ const p2 = asRecord15(payload);
62567
63248
  const path = expandHostPath(String(p2.path ?? ""));
62568
63249
  if (!path) {
62569
63250
  return { error: { code: "invalid_argument", message: "path is required" } };
@@ -62581,7 +63262,7 @@ function handleProjectOpen(payload, ctx) {
62581
63262
  function handleProjectRemove(payload, ctx) {
62582
63263
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.manageProject);
62583
63264
  if (denied) return denied;
62584
- const p2 = asRecord14(payload);
63265
+ const p2 = asRecord15(payload);
62585
63266
  const projectId = typeof p2.projectId === "string" && p2.projectId ? p2.projectId : void 0;
62586
63267
  const pathRaw = typeof p2.path === "string" && p2.path ? expandHostPath(p2.path) : void 0;
62587
63268
  if (!projectId && !pathRaw) {
@@ -62600,7 +63281,7 @@ function handleProjectRemove(payload, ctx) {
62600
63281
  function handleFsListDir(payload, ctx) {
62601
63282
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62602
63283
  if (denied) return denied;
62603
- const p2 = asRecord14(payload);
63284
+ const p2 = asRecord15(payload);
62604
63285
  const raw = String(p2.path ?? "");
62605
63286
  if (!raw || raw.includes("\0")) {
62606
63287
  return { error: { code: "invalid_argument", message: "path is required" } };
@@ -62626,7 +63307,7 @@ function handleFsListDir(payload, ctx) {
62626
63307
  function handleWorkspaceListDir(payload, ctx) {
62627
63308
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62628
63309
  if (denied) return denied;
62629
- const p2 = asRecord14(payload);
63310
+ const p2 = asRecord15(payload);
62630
63311
  try {
62631
63312
  return {
62632
63313
  result: ctx.workspaceFs.listDir(String(p2.projectId ?? ""), String(p2.relativePath ?? "."))
@@ -62638,7 +63319,7 @@ function handleWorkspaceListDir(payload, ctx) {
62638
63319
  function handleWorkspaceListFiles(payload, ctx) {
62639
63320
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62640
63321
  if (denied) return denied;
62641
- const p2 = asRecord14(payload);
63322
+ const p2 = asRecord15(payload);
62642
63323
  try {
62643
63324
  return {
62644
63325
  result: {
@@ -62656,7 +63337,7 @@ function handleWorkspaceListFiles(payload, ctx) {
62656
63337
  function handleWorkspaceListSkills(payload, ctx) {
62657
63338
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62658
63339
  if (denied) return denied;
62659
- const p2 = asRecord14(payload);
63340
+ const p2 = asRecord15(payload);
62660
63341
  try {
62661
63342
  return {
62662
63343
  result: ctx.workspaceFs.listSkillsAndCommands(String(p2.projectId ?? ""))
@@ -62668,7 +63349,7 @@ function handleWorkspaceListSkills(payload, ctx) {
62668
63349
  function handleWorkspaceReadFile(payload, ctx) {
62669
63350
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62670
63351
  if (denied) return denied;
62671
- const p2 = asRecord14(payload);
63352
+ const p2 = asRecord15(payload);
62672
63353
  try {
62673
63354
  return {
62674
63355
  result: ctx.workspaceFs.readFile(String(p2.projectId ?? ""), String(p2.relativePath ?? ""), {
@@ -62683,7 +63364,7 @@ function handleWorkspaceReadFile(payload, ctx) {
62683
63364
  function handleWorkspaceWriteFile(payload, ctx) {
62684
63365
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62685
63366
  if (denied) return denied;
62686
- const p2 = asRecord14(payload);
63367
+ const p2 = asRecord15(payload);
62687
63368
  const raw = typeof p2.content === "string" ? p2.content : String(p2.content ?? "");
62688
63369
  const encoding = p2.encoding === "base64" ? "base64" : "utf8";
62689
63370
  let content = raw;
@@ -62713,7 +63394,7 @@ function handleWorkspaceWriteFile(payload, ctx) {
62713
63394
  function handleWorkspaceSearch(payload, ctx) {
62714
63395
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62715
63396
  if (denied) return denied;
62716
- const p2 = asRecord14(payload);
63397
+ const p2 = asRecord15(payload);
62717
63398
  try {
62718
63399
  return {
62719
63400
  result: ctx.workspaceFs.search(
@@ -62729,7 +63410,7 @@ function handleWorkspaceSearch(payload, ctx) {
62729
63410
  function handleWorkspaceRename(payload, ctx) {
62730
63411
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62731
63412
  if (denied) return denied;
62732
- const p2 = asRecord14(payload);
63413
+ const p2 = asRecord15(payload);
62733
63414
  try {
62734
63415
  return {
62735
63416
  result: ctx.workspaceFs.rename(
@@ -62745,7 +63426,7 @@ function handleWorkspaceRename(payload, ctx) {
62745
63426
  function handleWorkspaceMove(payload, ctx) {
62746
63427
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62747
63428
  if (denied) return denied;
62748
- const p2 = asRecord14(payload);
63429
+ const p2 = asRecord15(payload);
62749
63430
  try {
62750
63431
  return {
62751
63432
  result: ctx.workspaceFs.move(
@@ -62761,7 +63442,7 @@ function handleWorkspaceMove(payload, ctx) {
62761
63442
  function handleWorkspaceDelete(payload, ctx) {
62762
63443
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62763
63444
  if (denied) return denied;
62764
- const p2 = asRecord14(payload);
63445
+ const p2 = asRecord15(payload);
62765
63446
  try {
62766
63447
  return {
62767
63448
  result: ctx.workspaceFs.delete(
@@ -62776,7 +63457,7 @@ function handleWorkspaceDelete(payload, ctx) {
62776
63457
  function handleWorkspaceMkdir(payload, ctx) {
62777
63458
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62778
63459
  if (denied) return denied;
62779
- const p2 = asRecord14(payload);
63460
+ const p2 = asRecord15(payload);
62780
63461
  try {
62781
63462
  return {
62782
63463
  result: ctx.workspaceFs.mkdir(
@@ -62791,7 +63472,7 @@ function handleWorkspaceMkdir(payload, ctx) {
62791
63472
  function handleWorkspaceWatchStart(payload, ctx) {
62792
63473
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62793
63474
  if (denied) return denied;
62794
- const p2 = asRecord14(payload);
63475
+ const p2 = asRecord15(payload);
62795
63476
  try {
62796
63477
  const events = [];
62797
63478
  const { watchId, cancel } = ctx.workspaceWatch.subscribe(
@@ -62812,7 +63493,7 @@ function handleWorkspaceWatchStart(payload, ctx) {
62812
63493
  function handleWorkspaceWatchPoll(payload, ctx) {
62813
63494
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62814
63495
  if (denied) return denied;
62815
- const p2 = asRecord14(payload);
63496
+ const p2 = asRecord15(payload);
62816
63497
  const watchId = String(p2.watchId ?? "");
62817
63498
  const buf = watchBuffers.get(watchId);
62818
63499
  if (!buf || buf.owner !== ctx.client.clientSessionId) {
@@ -62824,7 +63505,7 @@ function handleWorkspaceWatchPoll(payload, ctx) {
62824
63505
  function handleWorkspaceWatchStop(payload, ctx) {
62825
63506
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62826
63507
  if (denied) return denied;
62827
- const p2 = asRecord14(payload);
63508
+ const p2 = asRecord15(payload);
62828
63509
  const watchId = String(p2.watchId ?? "");
62829
63510
  const buf = watchBuffers.get(watchId);
62830
63511
  if (buf && buf.owner === ctx.client.clientSessionId) {
@@ -62836,7 +63517,7 @@ function handleWorkspaceWatchStop(payload, ctx) {
62836
63517
  function handleWorkspaceTailWatchStart(payload, ctx) {
62837
63518
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62838
63519
  if (denied) return denied;
62839
- const p2 = asRecord14(payload);
63520
+ const p2 = asRecord15(payload);
62840
63521
  try {
62841
63522
  const offset = typeof p2.offset === "number" ? p2.offset : void 0;
62842
63523
  const absolutePath = typeof p2.absolutePath === "string" ? p2.absolutePath : void 0;
@@ -62854,7 +63535,7 @@ function handleWorkspaceTailWatchStart(payload, ctx) {
62854
63535
  function handleWorkspaceTailWatchPoll(payload, ctx) {
62855
63536
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62856
63537
  if (denied) return denied;
62857
- const p2 = asRecord14(payload);
63538
+ const p2 = asRecord15(payload);
62858
63539
  try {
62859
63540
  return {
62860
63541
  result: ctx.workspaceTailWatch.poll(String(p2.watchId ?? ""), ctx.client.clientSessionId)
@@ -62866,7 +63547,7 @@ function handleWorkspaceTailWatchPoll(payload, ctx) {
62866
63547
  function handleWorkspaceTailWatchStop(payload, ctx) {
62867
63548
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62868
63549
  if (denied) return denied;
62869
- const p2 = asRecord14(payload);
63550
+ const p2 = asRecord15(payload);
62870
63551
  try {
62871
63552
  return {
62872
63553
  result: ctx.workspaceTailWatch.stop(String(p2.watchId ?? ""), ctx.client.clientSessionId)
@@ -62878,7 +63559,7 @@ function handleWorkspaceTailWatchStop(payload, ctx) {
62878
63559
  function handleGitStatus(payload, ctx) {
62879
63560
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62880
63561
  if (denied) return denied;
62881
- const p2 = asRecord14(payload);
63562
+ const p2 = asRecord15(payload);
62882
63563
  try {
62883
63564
  const projectId = String(p2.projectId ?? "");
62884
63565
  const cwd = typeof p2.cwd === "string" ? p2.cwd : null;
@@ -62892,7 +63573,7 @@ function handleGitStatus(payload, ctx) {
62892
63573
  function handleGitDiff(payload, ctx) {
62893
63574
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62894
63575
  if (denied) return denied;
62895
- const p2 = asRecord14(payload);
63576
+ const p2 = asRecord15(payload);
62896
63577
  try {
62897
63578
  return {
62898
63579
  result: ctx.workspaceGit.diff(String(p2.projectId ?? ""), {
@@ -62907,7 +63588,7 @@ function handleGitDiff(payload, ctx) {
62907
63588
  function handleGitBranches(payload, ctx) {
62908
63589
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62909
63590
  if (denied) return denied;
62910
- const p2 = asRecord14(payload);
63591
+ const p2 = asRecord15(payload);
62911
63592
  try {
62912
63593
  return {
62913
63594
  result: ctx.workspaceGit.branches(
@@ -62922,7 +63603,7 @@ function handleGitBranches(payload, ctx) {
62922
63603
  function handleGitSwitchBranch(payload, ctx) {
62923
63604
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62924
63605
  if (denied) return denied;
62925
- const p2 = asRecord14(payload);
63606
+ const p2 = asRecord15(payload);
62926
63607
  try {
62927
63608
  return {
62928
63609
  result: ctx.workspaceGit.switchBranch(String(p2.projectId ?? ""), String(p2.branch ?? ""), {
@@ -62937,7 +63618,7 @@ function handleGitSwitchBranch(payload, ctx) {
62937
63618
  function handleGitCreateBranch(payload, ctx) {
62938
63619
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62939
63620
  if (denied) return denied;
62940
- const p2 = asRecord14(payload);
63621
+ const p2 = asRecord15(payload);
62941
63622
  try {
62942
63623
  return {
62943
63624
  result: ctx.workspaceGit.switchBranch(String(p2.projectId ?? ""), String(p2.branch ?? ""), {
@@ -62952,7 +63633,7 @@ function handleGitCreateBranch(payload, ctx) {
62952
63633
  function handleGitWorktrees(payload, ctx) {
62953
63634
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62954
63635
  if (denied) return denied;
62955
- const p2 = asRecord14(payload);
63636
+ const p2 = asRecord15(payload);
62956
63637
  try {
62957
63638
  return { result: ctx.workspaceGit.worktrees(String(p2.projectId ?? "")) };
62958
63639
  } catch (err) {
@@ -62962,7 +63643,7 @@ function handleGitWorktrees(payload, ctx) {
62962
63643
  function handleGitWorktreeActivate(payload, ctx) {
62963
63644
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62964
63645
  if (denied) return denied;
62965
- const p2 = asRecord14(payload);
63646
+ const p2 = asRecord15(payload);
62966
63647
  const mode = p2.mode === "attach" || p2.mode === "detach" || p2.mode === "branch" ? p2.mode : null;
62967
63648
  if (!mode) {
62968
63649
  return { error: { code: "invalid_argument", message: "mode must be branch|attach|detach" } };
@@ -62983,7 +63664,7 @@ function handleGitWorktreeActivate(payload, ctx) {
62983
63664
  function handleGitWorktreeCheckedOutBranches(payload, ctx) {
62984
63665
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62985
63666
  if (denied) return denied;
62986
- const p2 = asRecord14(payload);
63667
+ const p2 = asRecord15(payload);
62987
63668
  try {
62988
63669
  return { result: { branches: ctx.workspaceGit.checkedOutBranches(String(p2.projectId ?? "")) } };
62989
63670
  } catch (err) {
@@ -62993,7 +63674,7 @@ function handleGitWorktreeCheckedOutBranches(payload, ctx) {
62993
63674
  function handleGitWorktreeAssignBranch(payload, ctx) {
62994
63675
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62995
63676
  if (denied) return denied;
62996
- const p2 = asRecord14(payload);
63677
+ const p2 = asRecord15(payload);
62997
63678
  try {
62998
63679
  return {
62999
63680
  result: ctx.workspaceGit.assignBranch(
@@ -63009,7 +63690,7 @@ function handleGitWorktreeAssignBranch(payload, ctx) {
63009
63690
  function handleGitWorktreeHandoff(payload, ctx) {
63010
63691
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
63011
63692
  if (denied) return denied;
63012
- const p2 = asRecord14(payload);
63693
+ const p2 = asRecord15(payload);
63013
63694
  try {
63014
63695
  return {
63015
63696
  result: ctx.workspaceGit.handoffToMain(
@@ -63024,7 +63705,7 @@ function handleGitWorktreeHandoff(payload, ctx) {
63024
63705
  function handleGitWorktreeHandoffPreview(payload, ctx) {
63025
63706
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
63026
63707
  if (denied) return denied;
63027
- const p2 = asRecord14(payload);
63708
+ const p2 = asRecord15(payload);
63028
63709
  try {
63029
63710
  return {
63030
63711
  result: ctx.workspaceGit.handoffPreview(
@@ -63039,7 +63720,7 @@ function handleGitWorktreeHandoffPreview(payload, ctx) {
63039
63720
  function handleSessionSetCwd(payload, ctx) {
63040
63721
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63041
63722
  if (denied) return denied;
63042
- const p2 = asRecord14(payload);
63723
+ const p2 = asRecord15(payload);
63043
63724
  const sessionId = String(p2.sessionId ?? "");
63044
63725
  const cwdRaw = p2.cwd;
63045
63726
  const cwd = cwdRaw === null || cwdRaw === void 0 || cwdRaw === "" ? null : String(cwdRaw);
@@ -63068,7 +63749,7 @@ function handleSessionSetCwd(payload, ctx) {
63068
63749
  function handleSessionPatchSettings(payload, ctx) {
63069
63750
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63070
63751
  if (denied) return denied;
63071
- const p2 = asRecord14(payload);
63752
+ const p2 = asRecord15(payload);
63072
63753
  const sessionId = String(p2.sessionId ?? "").trim();
63073
63754
  if (!sessionId) {
63074
63755
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63084,7 +63765,7 @@ function handleSessionPatchSettings(payload, ctx) {
63084
63765
  generation: String(p2.generation ?? ""),
63085
63766
  holderClientId: ctx.client.clientSessionId
63086
63767
  });
63087
- const settingsSrc = asRecord14(p2.settings ?? p2);
63768
+ const settingsSrc = asRecord15(p2.settings ?? p2);
63088
63769
  const patch = {};
63089
63770
  const take = (key) => {
63090
63771
  if (!(key in settingsSrc)) return;
@@ -63110,7 +63791,7 @@ function handleSessionPatchSettings(payload, ctx) {
63110
63791
  async function handleSessionFork(payload, ctx) {
63111
63792
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63112
63793
  if (denied) return denied;
63113
- const p2 = asRecord14(payload);
63794
+ const p2 = asRecord15(payload);
63114
63795
  const sessionId = String(p2.sessionId ?? "").trim();
63115
63796
  if (!sessionId) {
63116
63797
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63197,7 +63878,7 @@ async function handleSessionFork(payload, ctx) {
63197
63878
  async function handleGitClone(payload, ctx) {
63198
63879
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.manageProject);
63199
63880
  if (denied) return denied;
63200
- const p2 = asRecord14(payload);
63881
+ const p2 = asRecord15(payload);
63201
63882
  try {
63202
63883
  const cloned = await cloneRepository({
63203
63884
  remoteUrl: String(p2.remoteUrl ?? ""),
@@ -63212,7 +63893,7 @@ async function handleGitClone(payload, ctx) {
63212
63893
  function handleSessionCreate(payload, ctx) {
63213
63894
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63214
63895
  if (denied) return denied;
63215
- const p2 = asRecord14(payload);
63896
+ const p2 = asRecord15(payload);
63216
63897
  const rawHarnessId = typeof p2.harnessId === "string" ? p2.harnessId : "claude";
63217
63898
  const harnessId = normalizeSessionHarnessId(rawHarnessId);
63218
63899
  if (!harnessId) {
@@ -63265,7 +63946,7 @@ function handleSessionCreate(payload, ctx) {
63265
63946
  try {
63266
63947
  const agentSettings = loadNodeAgentSettings(ctx.settingsConfigPath);
63267
63948
  const defaults = resolveAgentTurnDefaults(agentSettings, harnessId);
63268
- const options = asRecord14(p2.options);
63949
+ const options = asRecord15(p2.options);
63269
63950
  const providerId = typeof p2.providerId === "string" && p2.providerId.trim() ? p2.providerId.trim() : void 0;
63270
63951
  const profile = providerId ? ctx.sessionProviders.get(providerId) : null;
63271
63952
  const profileSettings = profile ? settingsFromSessionProviderConfig(profile.config) : {};
@@ -63325,13 +64006,13 @@ function handleSessionCreate(payload, ctx) {
63325
64006
  function handleSessionGet(payload, ctx) {
63326
64007
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
63327
64008
  if (denied) return denied;
63328
- const p2 = asRecord14(payload);
64009
+ const p2 = asRecord15(payload);
63329
64010
  return { result: ctx.sessions.get(String(p2.sessionId ?? "")) };
63330
64011
  }
63331
64012
  function handleSessionList(payload, ctx) {
63332
64013
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
63333
64014
  if (denied) return denied;
63334
- const p2 = asRecord14(payload);
64015
+ const p2 = asRecord15(payload);
63335
64016
  const projectId = typeof p2.projectId === "string" ? p2.projectId : void 0;
63336
64017
  if (typeof p2.limit !== "number" || !Number.isFinite(p2.limit)) {
63337
64018
  return { error: { code: "invalid_argument", message: "session.list requires finite limit" } };
@@ -63343,28 +64024,34 @@ function handleSessionList(payload, ctx) {
63343
64024
  const offset = Math.max(Math.floor(p2.offset), 0);
63344
64025
  const rows = ctx.sessions.list(projectId, { limit, offset });
63345
64026
  return {
63346
- result: rows.map((s2) => ({
63347
- sessionId: s2.sessionId,
63348
- projectId: s2.projectId,
63349
- harnessId: s2.harnessId,
63350
- providerId: s2.providerId,
63351
- title: s2.title,
63352
- status: s2.status,
63353
- messageCount: Array.isArray(s2.transcript) ? s2.transcript.length : 0,
63354
- cwd: s2.cwd,
63355
- createdAt: s2.createdAt,
63356
- updatedAt: s2.updatedAt,
63357
- isPinned: s2.isPinned,
63358
- isHidden: s2.isHidden,
63359
- isAutomation: s2.isAutomation === true,
63360
- automationId: s2.automationId ?? null
63361
- }))
64027
+ result: rows.map((s2) => {
64028
+ const providerResume = s2.providerResume ?? null;
64029
+ const providerSessionId = providerSessionIdFromResume(providerResume);
64030
+ return {
64031
+ sessionId: s2.sessionId,
64032
+ projectId: s2.projectId,
64033
+ harnessId: s2.harnessId,
64034
+ providerId: s2.providerId,
64035
+ title: s2.title,
64036
+ status: s2.status,
64037
+ messageCount: Array.isArray(s2.transcript) ? s2.transcript.length : 0,
64038
+ cwd: s2.cwd,
64039
+ createdAt: s2.createdAt,
64040
+ updatedAt: s2.updatedAt,
64041
+ isPinned: s2.isPinned,
64042
+ isHidden: s2.isHidden,
64043
+ isAutomation: s2.isAutomation === true,
64044
+ automationId: s2.automationId ?? null,
64045
+ providerResume,
64046
+ ...providerSessionId ? { providerSessionId } : {}
64047
+ };
64048
+ })
63362
64049
  };
63363
64050
  }
63364
64051
  function handleSessionAcquireControl(payload, ctx) {
63365
64052
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63366
64053
  if (denied) return denied;
63367
- const p2 = asRecord14(payload);
64054
+ const p2 = asRecord15(payload);
63368
64055
  const sessionId = String(p2.sessionId ?? "");
63369
64056
  if (!sessionId) {
63370
64057
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63383,7 +64070,7 @@ function handleSessionAcquireControl(payload, ctx) {
63383
64070
  function handleSessionRenewControl(payload, ctx) {
63384
64071
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63385
64072
  if (denied) return denied;
63386
- const p2 = asRecord14(payload);
64073
+ const p2 = asRecord15(payload);
63387
64074
  try {
63388
64075
  return {
63389
64076
  result: ctx.leases.renew({
@@ -63400,7 +64087,7 @@ function handleSessionRenewControl(payload, ctx) {
63400
64087
  function handleSessionReleaseControl(payload, ctx) {
63401
64088
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63402
64089
  if (denied) return denied;
63403
- const p2 = asRecord14(payload);
64090
+ const p2 = asRecord15(payload);
63404
64091
  try {
63405
64092
  ctx.leases.release(
63406
64093
  String(p2.leaseId ?? ""),
@@ -63415,7 +64102,7 @@ function handleSessionReleaseControl(payload, ctx) {
63415
64102
  function handleSessionClose(payload, ctx) {
63416
64103
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63417
64104
  if (denied) return denied;
63418
- const p2 = asRecord14(payload);
64105
+ const p2 = asRecord15(payload);
63419
64106
  const sessionId = String(p2.sessionId ?? "");
63420
64107
  try {
63421
64108
  ctx.leases.assertValid({
@@ -63441,7 +64128,7 @@ function handleSessionClose(payload, ctx) {
63441
64128
  function handleSessionRemove(payload, ctx) {
63442
64129
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63443
64130
  if (denied) return denied;
63444
- const p2 = asRecord14(payload);
64131
+ const p2 = asRecord15(payload);
63445
64132
  const sessionId = String(p2.sessionId ?? "");
63446
64133
  if (!sessionId) {
63447
64134
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63468,7 +64155,7 @@ function handleSessionRemove(payload, ctx) {
63468
64155
  function handleSessionRename(payload, ctx) {
63469
64156
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63470
64157
  if (denied) return denied;
63471
- const p2 = asRecord14(payload);
64158
+ const p2 = asRecord15(payload);
63472
64159
  const sessionId = String(p2.sessionId ?? "");
63473
64160
  const title = String(p2.title ?? "");
63474
64161
  const source = p2.source === "agent" ? "agent" : "user";
@@ -63484,7 +64171,7 @@ function handleSessionRename(payload, ctx) {
63484
64171
  function handleSessionSetUiFlags(payload, ctx) {
63485
64172
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63486
64173
  if (denied) return denied;
63487
- const p2 = asRecord14(payload);
64174
+ const p2 = asRecord15(payload);
63488
64175
  const sessionId = String(p2.sessionId ?? "");
63489
64176
  if (!sessionId) {
63490
64177
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63503,9 +64190,9 @@ function handleSessionSetUiFlags(payload, ctx) {
63503
64190
  async function handleSessionSend(payload, ctx) {
63504
64191
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63505
64192
  if (denied) return denied;
63506
- const p2 = asRecord14(payload);
64193
+ const p2 = asRecord15(payload);
63507
64194
  try {
63508
- const options = asRecord14(p2.options);
64195
+ const options = asRecord15(p2.options);
63509
64196
  const modelFromOptions = typeof options.model === "string" && options.model.trim() ? options.model.trim() : null;
63510
64197
  const modelTopLevel = typeof p2.model === "string" && p2.model.trim() ? p2.model.trim() : null;
63511
64198
  const apiProviderId = typeof options.apiProviderId === "string" && options.apiProviderId.trim() ? options.apiProviderId.trim() : typeof p2.apiProviderId === "string" && p2.apiProviderId.trim() ? p2.apiProviderId.trim() : null;
@@ -63598,7 +64285,7 @@ async function handleSessionSend(payload, ctx) {
63598
64285
  function handleSessionInterrupt(payload, ctx) {
63599
64286
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63600
64287
  if (denied) return denied;
63601
- const p2 = asRecord14(payload);
64288
+ const p2 = asRecord15(payload);
63602
64289
  try {
63603
64290
  ctx.sessions.interrupt(
63604
64291
  String(p2.sessionId ?? ""),
@@ -63614,7 +64301,7 @@ function handleSessionInterrupt(payload, ctx) {
63614
64301
  function handleSessionRespondPermission(payload, ctx) {
63615
64302
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63616
64303
  if (denied) return denied;
63617
- const p2 = asRecord14(payload);
64304
+ const p2 = asRecord15(payload);
63618
64305
  try {
63619
64306
  const formAnswers = p2.formAnswers && typeof p2.formAnswers === "object" && !Array.isArray(p2.formAnswers) ? p2.formAnswers : p2.options && typeof p2.options === "object" && !Array.isArray(p2.options) ? p2.options.formAnswers ?? p2.options : void 0;
63620
64307
  ctx.sessions.respondPermission({
@@ -63635,7 +64322,7 @@ function handleSessionRespondPermission(payload, ctx) {
63635
64322
  function handleSessionRespondQuestion(payload, ctx) {
63636
64323
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63637
64324
  if (denied) return denied;
63638
- const p2 = asRecord14(payload);
64325
+ const p2 = asRecord15(payload);
63639
64326
  try {
63640
64327
  ctx.sessions.respondQuestion({
63641
64328
  sessionId: String(p2.sessionId ?? ""),
@@ -63653,7 +64340,7 @@ function handleSessionRespondQuestion(payload, ctx) {
63653
64340
  function handleSessionRespondPlan(payload, ctx) {
63654
64341
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63655
64342
  if (denied) return denied;
63656
- const p2 = asRecord14(payload);
64343
+ const p2 = asRecord15(payload);
63657
64344
  const decision = p2.decision === "approve" || p2.decision === "reject" ? p2.decision : null;
63658
64345
  if (!decision) {
63659
64346
  return { error: { code: "invalid_argument", message: "decision must be approve|reject" } };
@@ -63676,7 +64363,7 @@ function handleSessionRespondPlan(payload, ctx) {
63676
64363
  async function handleSessionHostActionsPoll(payload, ctx) {
63677
64364
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63678
64365
  if (denied) return denied;
63679
- const p2 = asRecord14(payload);
64366
+ const p2 = asRecord15(payload);
63680
64367
  try {
63681
64368
  const result = await ctx.sessions.pollHostActions({
63682
64369
  controllerClientSessionId: ctx.client.clientSessionId,
@@ -63692,7 +64379,7 @@ async function handleSessionHostActionsPoll(payload, ctx) {
63692
64379
  function handleSessionClaimHostAction(payload, ctx) {
63693
64380
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63694
64381
  if (denied) return denied;
63695
- const p2 = asRecord14(payload);
64382
+ const p2 = asRecord15(payload);
63696
64383
  try {
63697
64384
  const result = ctx.sessions.claimHostAction({
63698
64385
  actionId: String(p2.actionId ?? ""),
@@ -63708,7 +64395,7 @@ function handleSessionClaimHostAction(payload, ctx) {
63708
64395
  function handleSessionRespondHostAction(payload, ctx) {
63709
64396
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63710
64397
  if (denied) return denied;
63711
- const p2 = asRecord14(payload);
64398
+ const p2 = asRecord15(payload);
63712
64399
  const outcome = p2.outcome === "failed" ? "failed" : p2.outcome === "succeeded" ? "succeeded" : null;
63713
64400
  if (!outcome) {
63714
64401
  return { error: { code: "invalid_argument", message: "outcome must be succeeded|failed" } };
@@ -63730,14 +64417,14 @@ function handleSessionRespondHostAction(payload, ctx) {
63730
64417
  function handleSessionEvents(payload, ctx) {
63731
64418
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
63732
64419
  if (denied) return denied;
63733
- const p2 = asRecord14(payload);
64420
+ const p2 = asRecord15(payload);
63734
64421
  const after = String(p2.afterSequence ?? "0");
63735
64422
  return { result: { events: ctx.sessions.listEventsAfter(after) } };
63736
64423
  }
63737
64424
  function handleSessionMessagesList(payload, ctx) {
63738
64425
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
63739
64426
  if (denied) return denied;
63740
- const p2 = asRecord14(payload);
64427
+ const p2 = asRecord15(payload);
63741
64428
  const sessionId = String(p2.sessionId ?? "").trim();
63742
64429
  if (!sessionId) {
63743
64430
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63776,7 +64463,7 @@ function handleCollaborationListProfiles(ctx) {
63776
64463
  async function handleCollaborationRequest(payload, ctx) {
63777
64464
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63778
64465
  if (denied) return denied;
63779
- const p2 = asRecord14(payload);
64466
+ const p2 = asRecord15(payload);
63780
64467
  const parentSessionId = String(p2.parentSessionId ?? "");
63781
64468
  if (!parentSessionId) {
63782
64469
  return { error: { code: "invalid_argument", message: "parentSessionId required" } };
@@ -63810,7 +64497,7 @@ async function handleCollaborationRequest(payload, ctx) {
63810
64497
  async function handleCollaborationStart(payload, ctx) {
63811
64498
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63812
64499
  if (denied) return denied;
63813
- const p2 = asRecord14(payload);
64500
+ const p2 = asRecord15(payload);
63814
64501
  const credential = typeof p2.credential === "string" ? p2.credential : void 0;
63815
64502
  const grantId = typeof p2.grantId === "string" ? p2.grantId : void 0;
63816
64503
  if (!credential && !grantId) {
@@ -63856,7 +64543,7 @@ async function handleCollaborationStart(payload, ctx) {
63856
64543
  function handleCollaborationSend(payload, ctx) {
63857
64544
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63858
64545
  if (denied) return denied;
63859
- const p2 = asRecord14(payload);
64546
+ const p2 = asRecord15(payload);
63860
64547
  const credential = String(p2.credential ?? "");
63861
64548
  const sessionId = String(p2.sessionId ?? p2.fromSessionId ?? "");
63862
64549
  const content = typeof p2.content === "string" ? p2.content : p2.body !== void 0 ? typeof p2.body === "string" ? p2.body : JSON.stringify(p2.body) : "";
@@ -63892,7 +64579,7 @@ function handleCollaborationSend(payload, ctx) {
63892
64579
  function handleCollaborationRetrieve(payload, ctx) {
63893
64580
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
63894
64581
  if (denied) return denied;
63895
- const p2 = asRecord14(payload);
64582
+ const p2 = asRecord15(payload);
63896
64583
  const credential = String(p2.credential ?? "");
63897
64584
  const sessionId = String(p2.sessionId ?? "");
63898
64585
  if (!credential) {