@super-one/cli 0.51.0-alpha → 0.51.2-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 +1043 -343
  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,12 +42227,17 @@ 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;
42234
+ const detail = strField(p2, "detail");
41554
42235
  const state = strField(p2, "state");
41555
- out.push({ title, ...state ? { state } : {} });
42236
+ out.push({
42237
+ title,
42238
+ ...detail ? { detail } : {},
42239
+ ...state ? { state } : {}
42240
+ });
41556
42241
  }
41557
42242
  return out;
41558
42243
  }
@@ -41560,7 +42245,7 @@ function mapWorkflowAgents(raw) {
41560
42245
  if (!raw?.length) return [];
41561
42246
  const out = [];
41562
42247
  for (const item of raw) {
41563
- const a = asRecord7(item);
42248
+ const a = asRecord8(item);
41564
42249
  if (!a) continue;
41565
42250
  const agentId = strField(a, "agent_id", "agentId");
41566
42251
  const label = strField(a, "label") ?? agentId ?? "agent";
@@ -41586,7 +42271,7 @@ function buildWorkflowPhaseSummary(u, currentPhase, pauseMessage, lastEvent, las
41586
42271
  const phaseBits = [];
41587
42272
  if (phases?.length) {
41588
42273
  for (const p2 of phases) {
41589
- const ph = asRecord7(p2);
42274
+ const ph = asRecord8(p2);
41590
42275
  if (!ph) continue;
41591
42276
  const title = strField(ph, "title") ?? "?";
41592
42277
  const state = strField(ph, "state") ?? "";
@@ -41728,7 +42413,7 @@ function mapTaskBackgrounded(u, state) {
41728
42413
  }];
41729
42414
  }
41730
42415
  function mapTaskCompleted(u, state) {
41731
- const snapshot = asRecord7(u.task_snapshot) ?? asRecord7(u.taskSnapshot) ?? u;
42416
+ const snapshot = asRecord8(u.task_snapshot) ?? asRecord8(u.taskSnapshot) ?? u;
41732
42417
  const taskId = strField(snapshot, "task_id", "taskId");
41733
42418
  if (!taskId) return [];
41734
42419
  const known = state.bgTaskById.get(taskId);
@@ -41960,7 +42645,7 @@ function mapResponseStarted(u, state, ctx) {
41960
42645
  return event ? [event] : [];
41961
42646
  }
41962
42647
  function mapResponseCompleted(u, state, ctx) {
41963
- const usageRaw = asRecord7(u.usage) ?? u;
42648
+ const usageRaw = asRecord8(u.usage) ?? u;
41964
42649
  const input = numField(usageRaw, "inputTokens", "input_tokens") ?? 0;
41965
42650
  const output = numField(usageRaw, "outputTokens", "output_tokens") ?? 0;
41966
42651
  const cacheRead = numField(usageRaw, "cacheReadInputTokens", "cache_read_input_tokens") ?? 0;
@@ -41975,7 +42660,7 @@ function mapResponseCompleted(u, state, ctx) {
41975
42660
  }
41976
42661
  function mapTurnCompleted(u, state, ctx) {
41977
42662
  const events = mapTurnStopReason(u, state);
41978
- const usageRaw = asRecord7(u.usage);
42663
+ const usageRaw = asRecord8(u.usage);
41979
42664
  if (!usageRaw) {
41980
42665
  resetTurnTokens(state);
41981
42666
  return events;
@@ -42142,7 +42827,7 @@ function mapModelAutoSwitched(u) {
42142
42827
  ];
42143
42828
  }
42144
42829
  function mapRetryState(u) {
42145
- const nested = asRecord7(u.retry_state) ?? asRecord7(u.retryState) ?? u;
42830
+ const nested = asRecord8(u.retry_state) ?? asRecord8(u.retryState) ?? u;
42146
42831
  const type = (strField(nested, "type") ?? "").toLowerCase();
42147
42832
  if (type === "retrying") {
42148
42833
  const attempt = numField(nested, "attempt") ?? 1;
@@ -42209,7 +42894,7 @@ function mapAutoRecoveryExhausted(u) {
42209
42894
  }];
42210
42895
  }
42211
42896
  function mapFollowUps(u) {
42212
- const meta3 = asRecord7(u._meta) ?? asRecord7(u.meta);
42897
+ const meta3 = asRecord8(u._meta) ?? asRecord8(u.meta);
42213
42898
  if (meta3 && meta3["x.ai/replayed"] === true) return [];
42214
42899
  const responseId = strField(u, "response_id", "responseId");
42215
42900
  if (!responseId || responseId.length > 128) return [];
@@ -42218,7 +42903,7 @@ function mapFollowUps(u) {
42218
42903
  let count = 0;
42219
42904
  for (const s2 of suggestions) {
42220
42905
  if (count >= 6) break;
42221
- const rec = asRecord7(s2);
42906
+ const rec = asRecord8(s2);
42222
42907
  const label = (rec ? strField(rec, "label") : typeof s2 === "string" ? s2 : void 0)?.trim();
42223
42908
  if (!label) continue;
42224
42909
  const cleaned = label.replace(/[\u0000-\u001f\u007f]/g, "").slice(0, 256).trim();
@@ -42435,11 +43120,19 @@ function mapSessionUpdate(update, ctx, opts) {
42435
43120
  const isSkill = Boolean(
42436
43121
  c._meta && typeof c._meta === "object" && typeof c._meta.path === "string" && /SKILL\.md$/i.test(c._meta.path)
42437
43122
  );
43123
+ const workflowSource = c._meta && typeof c._meta === "object" && typeof c._meta.workflowSource === "string" ? c._meta.workflowSource : void 0;
43124
+ const workflowPath = c._meta && typeof c._meta === "object" && typeof c._meta.workflowPath === "string" ? c._meta.workflowPath : void 0;
43125
+ const isWorkflow = Boolean(workflowSource) || Boolean(workflowPath) || typeof c.description === "string" && /^Workflow:\s/i.test(c.description);
42438
43126
  commands.push({
42439
43127
  name,
42440
43128
  description: typeof c.description === "string" ? c.description : "",
42441
43129
  argumentHint: hint,
42442
- isSkill
43130
+ isSkill,
43131
+ ...isWorkflow ? {
43132
+ isWorkflow: true,
43133
+ workflowSource: workflowSource ?? "workflow",
43134
+ ...workflowPath ? { workflowPath } : {}
43135
+ } : {}
42443
43136
  });
42444
43137
  }
42445
43138
  return [{ type: "acp_commands", commands }];
@@ -49753,7 +50446,7 @@ var init_harness_runners = __esm({
49753
50446
  });
49754
50447
 
49755
50448
  // src/session/codex-live-turn.ts
49756
- function asRecord8(value) {
50449
+ function asRecord9(value) {
49757
50450
  return value && typeof value === "object" && !Array.isArray(value) ? value : null;
49758
50451
  }
49759
50452
  function readString4(value) {
@@ -49784,7 +50477,7 @@ function extractAgentTextFromTurn2(turn) {
49784
50477
  let text = "";
49785
50478
  const items = Array.isArray(turn.items) ? turn.items : [];
49786
50479
  for (const item of items) {
49787
- const rec = asRecord8(item);
50480
+ const rec = asRecord9(item);
49788
50481
  if (!rec) continue;
49789
50482
  if (readString4(rec.type) === "agentMessage" || readString4(rec.itemType) === "agentMessage") {
49790
50483
  const t = readString4(rec.text);
@@ -49819,7 +50512,7 @@ async function openTurnAndStream(opts) {
49819
50512
  ...collaborationMode ? { collaborationMode } : {}
49820
50513
  })
49821
50514
  );
49822
- const turn = asRecord8(turnStartResult.turn);
50515
+ const turn = asRecord9(turnStartResult.turn);
49823
50516
  const turnId = readString4(turn?.id);
49824
50517
  opts.onTurnStarted?.(turnId);
49825
50518
  let finalText = "";
@@ -49847,7 +50540,7 @@ async function openTurnAndStream(opts) {
49847
50540
  continue;
49848
50541
  }
49849
50542
  if (note.method === "turn/completed" || note.method === "turn/completed/v2") {
49850
- const completedTurn = asRecord8(note.params.turn);
50543
+ const completedTurn = asRecord9(note.params.turn);
49851
50544
  const completedId = readString4(completedTurn?.id);
49852
50545
  if (turnId && completedId && completedId !== turnId) continue;
49853
50546
  }
@@ -49855,14 +50548,14 @@ async function openTurnAndStream(opts) {
49855
50548
  const applied = agentEventMapper.apply(note);
49856
50549
  if (applied.textDelta) finalText += applied.textDelta;
49857
50550
  } 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);
50551
+ const delta = readString4(note.params.delta) ?? readString4(note.params.text) ?? readString4(asRecord9(note.params.item)?.delta);
49859
50552
  if (delta) {
49860
50553
  finalText += delta;
49861
50554
  opts.onDelta?.(delta);
49862
50555
  }
49863
50556
  }
49864
50557
  if (note.method === "turn/completed" || note.method === "turn/completed/v2") {
49865
- const completedTurn = asRecord8(note.params.turn);
50558
+ const completedTurn = asRecord9(note.params.turn);
49866
50559
  const status = readString4(completedTurn?.status) ?? readString4(note.params.status);
49867
50560
  if (status === "failed" || status === "error") {
49868
50561
  throw new Error("Codex turn failed");
@@ -57551,8 +58244,8 @@ import { fileURLToPath } from "node:url";
57551
58244
  function resolveCliReleaseVersion() {
57552
58245
  const fromEnv = process.env.SUPERONE_CLI_VERSION?.trim();
57553
58246
  if (fromEnv) return fromEnv;
57554
- if ("0.51.0-alpha".trim()) {
57555
- return "0.51.0-alpha".trim();
58247
+ if ("0.51.2-alpha".trim()) {
58248
+ return "0.51.2-alpha".trim();
57556
58249
  }
57557
58250
  const fromDist = readDistManifestVersion();
57558
58251
  if (fromDist) return fromDist;
@@ -58423,6 +59116,7 @@ function openNodeDatabase(dbPath) {
58423
59116
  mkdirSync2(dirname3(dbPath), { recursive: true });
58424
59117
  const db = new Database(dbPath);
58425
59118
  db.pragma("journal_mode = WAL");
59119
+ db.pragma("busy_timeout = 5000");
58426
59120
  db.pragma("foreign_keys = ON");
58427
59121
  db.exec(SCHEMA_SQL);
58428
59122
  ensureSessionUiColumns(db);
@@ -59948,7 +60642,7 @@ function requireResourceWrite(client3, scope) {
59948
60642
  if (scope === "user") return requireScopes(client3, OPERATION_SCOPES.adminNode);
59949
60643
  return null;
59950
60644
  }
59951
- function asRecord9(payload) {
60645
+ function asRecord10(payload) {
59952
60646
  return payload && typeof payload === "object" ? payload : {};
59953
60647
  }
59954
60648
  function mapThrown(err) {
@@ -59977,7 +60671,7 @@ function manageOpts(ctx) {
59977
60671
  function handleSkillsList(payload, ctx) {
59978
60672
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
59979
60673
  if (denied) return denied;
59980
- const p2 = asRecord9(payload);
60674
+ const p2 = asRecord10(payload);
59981
60675
  try {
59982
60676
  const projectId = String(p2.projectId ?? "");
59983
60677
  const cwd = projectRoot(ctx.projects, projectId);
@@ -59997,7 +60691,7 @@ function handleSkillsList(payload, ctx) {
59997
60691
  function handleSkillsGet(payload, ctx) {
59998
60692
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
59999
60693
  if (denied) return denied;
60000
- const p2 = asRecord9(payload);
60694
+ const p2 = asRecord10(payload);
60001
60695
  try {
60002
60696
  const projectId = String(p2.projectId ?? "");
60003
60697
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60022,7 +60716,7 @@ function handleSkillsGet(payload, ctx) {
60022
60716
  function handleSkillsReadFile(payload, ctx) {
60023
60717
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60024
60718
  if (denied) return denied;
60025
- const p2 = asRecord9(payload);
60719
+ const p2 = asRecord10(payload);
60026
60720
  try {
60027
60721
  const projectId = String(p2.projectId ?? "");
60028
60722
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60056,7 +60750,7 @@ function handleSkillsReadFile(payload, ctx) {
60056
60750
  function handleSkillsDelete(payload, ctx) {
60057
60751
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60058
60752
  if (denied) return denied;
60059
- const p2 = asRecord9(payload);
60753
+ const p2 = asRecord10(payload);
60060
60754
  try {
60061
60755
  const projectId = String(p2.projectId ?? "");
60062
60756
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60081,7 +60775,7 @@ function handleSkillsDelete(payload, ctx) {
60081
60775
  function handleSkillsInstall(payload, ctx) {
60082
60776
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60083
60777
  if (baseDenied) return baseDenied;
60084
- const p2 = asRecord9(payload);
60778
+ const p2 = asRecord10(payload);
60085
60779
  try {
60086
60780
  const projectId = String(p2.projectId ?? "");
60087
60781
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60115,7 +60809,7 @@ function handleSkillsInstall(payload, ctx) {
60115
60809
  function handleMcpList(payload, ctx) {
60116
60810
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60117
60811
  if (denied) return denied;
60118
- const p2 = asRecord9(payload);
60812
+ const p2 = asRecord10(payload);
60119
60813
  try {
60120
60814
  const projectId = String(p2.projectId ?? "");
60121
60815
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60172,7 +60866,7 @@ function parseMcpWriteConfig(raw) {
60172
60866
  function handleMcpSave(payload, ctx) {
60173
60867
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60174
60868
  if (baseDenied) return baseDenied;
60175
- const p2 = asRecord9(payload);
60869
+ const p2 = asRecord10(payload);
60176
60870
  try {
60177
60871
  const projectId = String(p2.projectId ?? "");
60178
60872
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60202,7 +60896,7 @@ function handleMcpSave(payload, ctx) {
60202
60896
  function handleMcpToggle(payload, ctx) {
60203
60897
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60204
60898
  if (baseDenied) return baseDenied;
60205
- const p2 = asRecord9(payload);
60899
+ const p2 = asRecord10(payload);
60206
60900
  try {
60207
60901
  const projectId = String(p2.projectId ?? "");
60208
60902
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60233,7 +60927,7 @@ function handleMcpToggle(payload, ctx) {
60233
60927
  function handleMcpDelete(payload, ctx) {
60234
60928
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60235
60929
  if (baseDenied) return baseDenied;
60236
- const p2 = asRecord9(payload);
60930
+ const p2 = asRecord10(payload);
60237
60931
  try {
60238
60932
  const projectId = String(p2.projectId ?? "");
60239
60933
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60273,7 +60967,7 @@ function parseMarketplaceScope(raw) {
60273
60967
  async function handlePluginsList(payload, ctx) {
60274
60968
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60275
60969
  if (denied) return denied;
60276
- const p2 = asRecord9(payload);
60970
+ const p2 = asRecord10(payload);
60277
60971
  try {
60278
60972
  const projectId = String(p2.projectId ?? "");
60279
60973
  projectRoot(ctx.projects, projectId);
@@ -60320,7 +61014,7 @@ async function handlePluginsList(payload, ctx) {
60320
61014
  function handlePluginsGet(payload, ctx) {
60321
61015
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60322
61016
  if (denied) return denied;
60323
- const p2 = asRecord9(payload);
61017
+ const p2 = asRecord10(payload);
60324
61018
  try {
60325
61019
  const projectId = String(p2.projectId ?? "");
60326
61020
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60344,7 +61038,7 @@ function handlePluginsGet(payload, ctx) {
60344
61038
  function handlePluginsReadFile(payload, ctx) {
60345
61039
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60346
61040
  if (denied) return denied;
60347
- const p2 = asRecord9(payload);
61041
+ const p2 = asRecord10(payload);
60348
61042
  try {
60349
61043
  const projectId = String(p2.projectId ?? "");
60350
61044
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60372,7 +61066,7 @@ function handlePluginsReadFile(payload, ctx) {
60372
61066
  function handlePluginsDelete(payload, ctx) {
60373
61067
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60374
61068
  if (baseDenied) return baseDenied;
60375
- const p2 = asRecord9(payload);
61069
+ const p2 = asRecord10(payload);
60376
61070
  try {
60377
61071
  const projectId = String(p2.projectId ?? "");
60378
61072
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60398,7 +61092,7 @@ function handlePluginsDelete(payload, ctx) {
60398
61092
  async function handlePluginsInstall(payload, ctx) {
60399
61093
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60400
61094
  if (baseDenied) return baseDenied;
60401
- const p2 = asRecord9(payload);
61095
+ const p2 = asRecord10(payload);
60402
61096
  try {
60403
61097
  const projectId = String(p2.projectId ?? "");
60404
61098
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60424,7 +61118,7 @@ async function handlePluginsInstall(payload, ctx) {
60424
61118
  function handlePluginsUpdate(payload, ctx) {
60425
61119
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60426
61120
  if (baseDenied) return baseDenied;
60427
- const p2 = asRecord9(payload);
61121
+ const p2 = asRecord10(payload);
60428
61122
  try {
60429
61123
  const projectId = String(p2.projectId ?? "");
60430
61124
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60450,7 +61144,7 @@ function handlePluginsUpdate(payload, ctx) {
60450
61144
  function handlePluginsListMarketplace(payload, ctx) {
60451
61145
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60452
61146
  if (denied) return denied;
60453
- const p2 = asRecord9(payload);
61147
+ const p2 = asRecord10(payload);
60454
61148
  try {
60455
61149
  const projectId = String(p2.projectId ?? "");
60456
61150
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60472,7 +61166,7 @@ function handlePluginsListMarketplace(payload, ctx) {
60472
61166
  async function handlePluginsAddMarketplace(payload, ctx) {
60473
61167
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60474
61168
  if (baseDenied) return baseDenied;
60475
- const p2 = asRecord9(payload);
61169
+ const p2 = asRecord10(payload);
60476
61170
  try {
60477
61171
  const projectId = String(p2.projectId ?? "");
60478
61172
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60498,7 +61192,7 @@ async function handlePluginsAddMarketplace(payload, ctx) {
60498
61192
  async function handlePluginsRemoveMarketplace(payload, ctx) {
60499
61193
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60500
61194
  if (baseDenied) return baseDenied;
60501
- const p2 = asRecord9(payload);
61195
+ const p2 = asRecord10(payload);
60502
61196
  try {
60503
61197
  const projectId = String(p2.projectId ?? "");
60504
61198
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60533,7 +61227,7 @@ async function handlePluginsUpdateMarketplace(payload, ctx) {
60533
61227
  if (denied) return denied;
60534
61228
  const adminDenied = requireScopes(ctx.client, OPERATION_SCOPES.adminNode);
60535
61229
  if (adminDenied) return adminDenied;
60536
- const p2 = asRecord9(payload);
61230
+ const p2 = asRecord10(payload);
60537
61231
  try {
60538
61232
  const projectId = String(p2.projectId ?? "");
60539
61233
  if (projectId) {
@@ -60555,7 +61249,7 @@ async function handlePluginsUpdateMarketplace(payload, ctx) {
60555
61249
  function handlePluginsReadMarketplace(payload, ctx) {
60556
61250
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60557
61251
  if (denied) return denied;
60558
- const p2 = asRecord9(payload);
61252
+ const p2 = asRecord10(payload);
60559
61253
  try {
60560
61254
  const projectId = String(p2.projectId ?? "");
60561
61255
  if (projectId) {
@@ -60586,7 +61280,7 @@ function handlePluginsReadMarketplace(payload, ctx) {
60586
61280
  function handlePluginsReadMarketplaceFile(payload, ctx) {
60587
61281
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60588
61282
  if (denied) return denied;
60589
- const p2 = asRecord9(payload);
61283
+ const p2 = asRecord10(payload);
60590
61284
  try {
60591
61285
  const projectId = String(p2.projectId ?? "");
60592
61286
  if (projectId) {
@@ -60620,7 +61314,7 @@ function handlePluginsReadMarketplaceFile(payload, ctx) {
60620
61314
  function handleAgentsList(payload, ctx) {
60621
61315
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60622
61316
  if (denied) return denied;
60623
- const p2 = asRecord9(payload);
61317
+ const p2 = asRecord10(payload);
60624
61318
  try {
60625
61319
  const projectId = String(p2.projectId ?? "");
60626
61320
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60637,7 +61331,7 @@ function handleAgentsList(payload, ctx) {
60637
61331
  function handleAgentsReadFile(payload, ctx) {
60638
61332
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60639
61333
  if (denied) return denied;
60640
- const p2 = asRecord9(payload);
61334
+ const p2 = asRecord10(payload);
60641
61335
  try {
60642
61336
  const projectId = String(p2.projectId ?? "");
60643
61337
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60669,7 +61363,7 @@ function parseHookSavePayload(raw) {
60669
61363
  function handleHooksList(payload, ctx) {
60670
61364
  const denied = requireScopes(ctx.client, OPERATION_SCOPES.readWorkspace);
60671
61365
  if (denied) return denied;
60672
- const p2 = asRecord9(payload);
61366
+ const p2 = asRecord10(payload);
60673
61367
  try {
60674
61368
  const projectId = String(p2.projectId ?? "");
60675
61369
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60682,7 +61376,7 @@ function handleHooksList(payload, ctx) {
60682
61376
  function handleHooksSave(payload, ctx) {
60683
61377
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60684
61378
  if (baseDenied) return baseDenied;
60685
- const p2 = asRecord9(payload);
61379
+ const p2 = asRecord10(payload);
60686
61380
  try {
60687
61381
  const projectId = String(p2.projectId ?? "");
60688
61382
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60710,7 +61404,7 @@ function handleHooksSave(payload, ctx) {
60710
61404
  function handleHooksDelete(payload, ctx) {
60711
61405
  const baseDenied = requireScopes(ctx.client, OPERATION_SCOPES.writeWorkspace);
60712
61406
  if (baseDenied) return baseDenied;
60713
- const p2 = asRecord9(payload);
61407
+ const p2 = asRecord10(payload);
60714
61408
  try {
60715
61409
  const projectId = String(p2.projectId ?? "");
60716
61410
  const cwd = projectRoot(ctx.projects, projectId);
@@ -60809,7 +61503,7 @@ function requireScopes2(client3, scopes) {
60809
61503
  }
60810
61504
  return null;
60811
61505
  }
60812
- function asRecord10(payload) {
61506
+ function asRecord11(payload) {
60813
61507
  return payload && typeof payload === "object" ? payload : {};
60814
61508
  }
60815
61509
  function mapThrown2(err) {
@@ -60875,7 +61569,7 @@ function parseSchedule(raw) {
60875
61569
  function handleAutomationList(payload, ctx) {
60876
61570
  const denied = requireScopes2(ctx.client, OPERATION_SCOPES.readSession);
60877
61571
  if (denied) return denied;
60878
- const p2 = asRecord10(payload);
61572
+ const p2 = asRecord11(payload);
60879
61573
  const projectId = String(p2.projectId ?? "").trim();
60880
61574
  if (!projectId) {
60881
61575
  return { error: { code: "invalid_argument", message: "projectId is required" } };
@@ -60894,7 +61588,7 @@ function handleAutomationList(payload, ctx) {
60894
61588
  function handleAutomationCreate(payload, ctx) {
60895
61589
  const denied = requireScopes2(ctx.client, OPERATION_SCOPES.operateSession);
60896
61590
  if (denied) return denied;
60897
- const p2 = asRecord10(payload);
61591
+ const p2 = asRecord11(payload);
60898
61592
  const projectId = String(p2.projectId ?? "").trim();
60899
61593
  if (!projectId) {
60900
61594
  return { error: { code: "invalid_argument", message: "projectId is required" } };
@@ -60931,7 +61625,7 @@ function handleAutomationCreate(payload, ctx) {
60931
61625
  function handleAutomationUpdate(payload, ctx) {
60932
61626
  const denied = requireScopes2(ctx.client, OPERATION_SCOPES.operateSession);
60933
61627
  if (denied) return denied;
60934
- const p2 = asRecord10(payload);
61628
+ const p2 = asRecord11(payload);
60935
61629
  const automationId = String(p2.automationId ?? p2.id ?? "").trim();
60936
61630
  if (!automationId) {
60937
61631
  return { error: { code: "invalid_argument", message: "automationId is required" } };
@@ -60975,7 +61669,7 @@ function handleAutomationUpdate(payload, ctx) {
60975
61669
  function handleAutomationDelete(payload, ctx) {
60976
61670
  const denied = requireScopes2(ctx.client, OPERATION_SCOPES.operateSession);
60977
61671
  if (denied) return denied;
60978
- const p2 = asRecord10(payload);
61672
+ const p2 = asRecord11(payload);
60979
61673
  const automationId = String(p2.automationId ?? p2.id ?? "").trim();
60980
61674
  if (!automationId) {
60981
61675
  return { error: { code: "invalid_argument", message: "automationId is required" } };
@@ -61001,7 +61695,7 @@ function handleAutomationDelete(payload, ctx) {
61001
61695
  async function handleAutomationRunNow(payload, ctx) {
61002
61696
  const denied = requireScopes2(ctx.client, OPERATION_SCOPES.operateSession);
61003
61697
  if (denied) return denied;
61004
- const p2 = asRecord10(payload);
61698
+ const p2 = asRecord11(payload);
61005
61699
  const automationId = String(p2.automationId ?? p2.id ?? "").trim();
61006
61700
  if (!automationId) {
61007
61701
  return { error: { code: "invalid_argument", message: "automationId is required" } };
@@ -61059,7 +61753,7 @@ function requireScopes3(client3, scopes) {
61059
61753
  }
61060
61754
  return null;
61061
61755
  }
61062
- function asRecord11(payload) {
61756
+ function asRecord12(payload) {
61063
61757
  return payload && typeof payload === "object" ? payload : {};
61064
61758
  }
61065
61759
  function mapThrown3(err) {
@@ -61130,7 +61824,7 @@ var CODEX_MUTATING_METHODS = [
61130
61824
  function handleGetAuthStatus(payload, ctx) {
61131
61825
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.readEnvironment);
61132
61826
  if (denied) return denied;
61133
- const p2 = asRecord11(payload);
61827
+ const p2 = asRecord12(payload);
61134
61828
  const projectId = projectIdOf(p2);
61135
61829
  if (!projectId) {
61136
61830
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61143,7 +61837,7 @@ function handleGetAuthStatus(payload, ctx) {
61143
61837
  function handleSetAuth(payload, ctx) {
61144
61838
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61145
61839
  if (denied) return denied;
61146
- const p2 = asRecord11(payload);
61840
+ const p2 = asRecord12(payload);
61147
61841
  const projectId = projectIdOf(p2);
61148
61842
  if (!projectId) {
61149
61843
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61168,7 +61862,7 @@ function handleSetAuth(payload, ctx) {
61168
61862
  async function handleGetRateLimits(payload, ctx) {
61169
61863
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.readEnvironment);
61170
61864
  if (denied) return denied;
61171
- const p2 = asRecord11(payload);
61865
+ const p2 = asRecord12(payload);
61172
61866
  const projectId = projectIdOf(p2);
61173
61867
  if (!projectId) {
61174
61868
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61195,7 +61889,7 @@ async function handleGetRateLimits(payload, ctx) {
61195
61889
  async function handleGetAccountUsage(payload, ctx) {
61196
61890
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.readEnvironment);
61197
61891
  if (denied) return denied;
61198
- const p2 = asRecord11(payload);
61892
+ const p2 = asRecord12(payload);
61199
61893
  const projectId = projectIdOf(p2);
61200
61894
  if (!projectId) {
61201
61895
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61222,7 +61916,7 @@ async function handleGetAccountUsage(payload, ctx) {
61222
61916
  async function handleConsumeRateLimitReset(payload, ctx) {
61223
61917
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61224
61918
  if (denied) return denied;
61225
- const p2 = asRecord11(payload);
61919
+ const p2 = asRecord12(payload);
61226
61920
  const projectId = projectIdOf(p2);
61227
61921
  if (!projectId) {
61228
61922
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61252,7 +61946,7 @@ async function handleConsumeRateLimitReset(payload, ctx) {
61252
61946
  async function handleLoginMcpOauth(payload, ctx) {
61253
61947
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61254
61948
  if (denied) return denied;
61255
- const p2 = asRecord11(payload);
61949
+ const p2 = asRecord12(payload);
61256
61950
  const projectId = projectIdOf(p2);
61257
61951
  const serverName = String(p2.serverName ?? p2.name ?? "").trim();
61258
61952
  if (!projectId || !serverName) {
@@ -61272,7 +61966,7 @@ async function handleLoginMcpOauth(payload, ctx) {
61272
61966
  async function handleDetectExternalAgent(payload, ctx) {
61273
61967
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.readEnvironment);
61274
61968
  if (denied) return denied;
61275
- const p2 = asRecord11(payload);
61969
+ const p2 = asRecord12(payload);
61276
61970
  const projectId = projectIdOf(p2);
61277
61971
  if (!projectId) {
61278
61972
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61291,7 +61985,7 @@ async function handleDetectExternalAgent(payload, ctx) {
61291
61985
  async function handleImportExternalAgent(payload, ctx) {
61292
61986
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61293
61987
  if (denied) return denied;
61294
- const p2 = asRecord11(payload);
61988
+ const p2 = asRecord12(payload);
61295
61989
  const projectId = projectIdOf(p2);
61296
61990
  if (!projectId) {
61297
61991
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61309,7 +62003,7 @@ async function handleImportExternalAgent(payload, ctx) {
61309
62003
  async function handlePluginsList2(payload, ctx) {
61310
62004
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.readWorkspace);
61311
62005
  if (denied) return denied;
61312
- const p2 = asRecord11(payload);
62006
+ const p2 = asRecord12(payload);
61313
62007
  const projectId = projectIdOf(p2);
61314
62008
  if (!projectId) {
61315
62009
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61332,7 +62026,7 @@ async function handlePluginsList2(payload, ctx) {
61332
62026
  async function handlePluginsInstall2(payload, ctx) {
61333
62027
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61334
62028
  if (denied) return denied;
61335
- const p2 = asRecord11(payload);
62029
+ const p2 = asRecord12(payload);
61336
62030
  const projectId = projectIdOf(p2);
61337
62031
  const key = String(p2.key ?? p2.pluginId ?? "").trim();
61338
62032
  if (!projectId || !key) {
@@ -61348,7 +62042,7 @@ async function handlePluginsInstall2(payload, ctx) {
61348
62042
  async function handlePluginsUninstall(payload, ctx) {
61349
62043
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61350
62044
  if (denied) return denied;
61351
- const p2 = asRecord11(payload);
62045
+ const p2 = asRecord12(payload);
61352
62046
  const projectId = projectIdOf(p2);
61353
62047
  const key = String(p2.key ?? p2.pluginId ?? "").trim();
61354
62048
  if (!projectId || !key) {
@@ -61364,7 +62058,7 @@ async function handlePluginsUninstall(payload, ctx) {
61364
62058
  async function handleMarketplaceAdd(payload, ctx) {
61365
62059
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61366
62060
  if (denied) return denied;
61367
- const p2 = asRecord11(payload);
62061
+ const p2 = asRecord12(payload);
61368
62062
  const projectId = projectIdOf(p2);
61369
62063
  const source = String(p2.source ?? "").trim();
61370
62064
  if (!projectId || !source) {
@@ -61393,7 +62087,7 @@ async function handleMarketplaceAdd(payload, ctx) {
61393
62087
  async function handleMarketplaceRemove(payload, ctx) {
61394
62088
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61395
62089
  if (denied) return denied;
61396
- const p2 = asRecord11(payload);
62090
+ const p2 = asRecord12(payload);
61397
62091
  const projectId = projectIdOf(p2);
61398
62092
  const marketplaceName = String(p2.marketplaceName ?? p2.name ?? "").trim();
61399
62093
  if (!projectId || !marketplaceName) {
@@ -61416,7 +62110,7 @@ async function handleMarketplaceRemove(payload, ctx) {
61416
62110
  async function handleMarketplaceUpgrade(payload, ctx) {
61417
62111
  const denied = requireScopes3(ctx.client, OPERATION_SCOPES.adminNode);
61418
62112
  if (denied) return denied;
61419
- const p2 = asRecord11(payload);
62113
+ const p2 = asRecord12(payload);
61420
62114
  const projectId = projectIdOf(p2);
61421
62115
  if (!projectId) {
61422
62116
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -61449,7 +62143,7 @@ function requireScopes4(client3, scopes) {
61449
62143
  }
61450
62144
  return null;
61451
62145
  }
61452
- function asRecord12(payload) {
62146
+ function asRecord13(payload) {
61453
62147
  return payload && typeof payload === "object" ? payload : {};
61454
62148
  }
61455
62149
  function mapThrown4(err) {
@@ -61478,7 +62172,7 @@ function dispatchSessionProviderRpc(method, payload, ctx) {
61478
62172
  function handleList(payload, ctx) {
61479
62173
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.readEnvironment);
61480
62174
  if (denied) return denied;
61481
- const p2 = asRecord12(payload);
62175
+ const p2 = asRecord13(payload);
61482
62176
  try {
61483
62177
  const harnessId = typeof p2.harnessId === "string" && p2.harnessId.trim() ? p2.harnessId.trim() : null;
61484
62178
  const providers = harnessId ? ctx.sessionProviders.listByHarness(harnessId) : ctx.sessionProviders.list();
@@ -61490,7 +62184,7 @@ function handleList(payload, ctx) {
61490
62184
  function handleGet(payload, ctx) {
61491
62185
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.readEnvironment);
61492
62186
  if (denied) return denied;
61493
- const p2 = asRecord12(payload);
62187
+ const p2 = asRecord13(payload);
61494
62188
  const id = String(p2.id ?? "");
61495
62189
  if (!id) return { error: { code: "invalid_argument", message: "id required" } };
61496
62190
  try {
@@ -61502,7 +62196,7 @@ function handleGet(payload, ctx) {
61502
62196
  function handleGetBase(payload, ctx) {
61503
62197
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.readEnvironment);
61504
62198
  if (denied) return denied;
61505
- const p2 = asRecord12(payload);
62199
+ const p2 = asRecord13(payload);
61506
62200
  const harnessId = String(p2.harnessId ?? "");
61507
62201
  if (!harnessId) return { error: { code: "invalid_argument", message: "harnessId required" } };
61508
62202
  try {
@@ -61514,7 +62208,7 @@ function handleGetBase(payload, ctx) {
61514
62208
  function handleCreate(payload, ctx) {
61515
62209
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.adminNode);
61516
62210
  if (denied) return denied;
61517
- const p2 = asRecord12(payload);
62211
+ const p2 = asRecord13(payload);
61518
62212
  try {
61519
62213
  const provider = ctx.sessionProviders.create({
61520
62214
  harnessId: String(p2.harnessId ?? ""),
@@ -61530,7 +62224,7 @@ function handleCreate(payload, ctx) {
61530
62224
  function handleUpdate(payload, ctx) {
61531
62225
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.adminNode);
61532
62226
  if (denied) return denied;
61533
- const p2 = asRecord12(payload);
62227
+ const p2 = asRecord13(payload);
61534
62228
  const id = String(p2.id ?? "");
61535
62229
  if (!id) return { error: { code: "invalid_argument", message: "id required" } };
61536
62230
  try {
@@ -61546,7 +62240,7 @@ function handleUpdate(payload, ctx) {
61546
62240
  function handleDelete(payload, ctx) {
61547
62241
  const denied = requireScopes4(ctx.client, OPERATION_SCOPES.adminNode);
61548
62242
  if (denied) return denied;
61549
- const p2 = asRecord12(payload);
62243
+ const p2 = asRecord13(payload);
61550
62244
  const id = String(p2.id ?? "");
61551
62245
  if (!id) return { error: { code: "invalid_argument", message: "id required" } };
61552
62246
  try {
@@ -61587,7 +62281,7 @@ function requireScopes5(client3, scopes) {
61587
62281
  }
61588
62282
  return null;
61589
62283
  }
61590
- function asRecord13(payload) {
62284
+ function asRecord14(payload) {
61591
62285
  return payload && typeof payload === "object" ? payload : {};
61592
62286
  }
61593
62287
  function defaultProbeModels(ctx) {
@@ -61615,7 +62309,7 @@ async function dispatchHarnessResourcesRpc(method, payload, ctx) {
61615
62309
  async function handleHarnessResources(payload, ctx) {
61616
62310
  const denied = requireScopes5(ctx.client, OPERATION_SCOPES.readEnvironment);
61617
62311
  if (denied) return denied;
61618
- const p2 = asRecord13(payload);
62312
+ const p2 = asRecord14(payload);
61619
62313
  const projectId = String(p2.projectId ?? "");
61620
62314
  if (!projectId) {
61621
62315
  return { error: { code: "invalid_argument", message: "projectId required" } };
@@ -62052,7 +62746,7 @@ function handleProviderListCredentials(ctx) {
62052
62746
  function handleProviderGetCredentialDecrypted(payload, ctx) {
62053
62747
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62054
62748
  if (denied) return denied;
62055
- const p2 = asRecord14(payload);
62749
+ const p2 = asRecord15(payload);
62056
62750
  const cred = ctx.providers.getCredentialDecrypted(String(p2.id ?? ""));
62057
62751
  if (!cred) return { error: { code: "not_found", message: "credential not found" } };
62058
62752
  return { result: cred };
@@ -62060,7 +62754,7 @@ function handleProviderGetCredentialDecrypted(payload, ctx) {
62060
62754
  function handleProviderCreateCredential(payload, ctx) {
62061
62755
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62062
62756
  if (denied) return denied;
62063
- const p2 = asRecord14(payload);
62757
+ const p2 = asRecord15(payload);
62064
62758
  try {
62065
62759
  return {
62066
62760
  result: ctx.providers.createCredential({
@@ -62082,7 +62776,7 @@ function handleProviderCreateCredential(payload, ctx) {
62082
62776
  function handleProviderUpdateCredential(payload, ctx) {
62083
62777
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62084
62778
  if (denied) return denied;
62085
- const p2 = asRecord14(payload);
62779
+ const p2 = asRecord15(payload);
62086
62780
  const id = String(p2.id ?? "");
62087
62781
  const updated = ctx.providers.updateCredential(id, {
62088
62782
  name: typeof p2.name === "string" ? p2.name : void 0,
@@ -62099,7 +62793,7 @@ function handleProviderUpdateCredential(payload, ctx) {
62099
62793
  function handleProviderDeleteCredential(payload, ctx) {
62100
62794
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62101
62795
  if (denied) return denied;
62102
- const p2 = asRecord14(payload);
62796
+ const p2 = asRecord15(payload);
62103
62797
  const ok = ctx.providers.deleteCredential(String(p2.id ?? ""));
62104
62798
  if (!ok) return { error: { code: "not_found", message: "credential not found" } };
62105
62799
  return { result: { ok: true } };
@@ -62112,7 +62806,7 @@ function handleProviderListBindings(ctx) {
62112
62806
  function handleProviderSetBinding(payload, ctx) {
62113
62807
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62114
62808
  if (denied) return denied;
62115
- const p2 = asRecord14(payload);
62809
+ const p2 = asRecord15(payload);
62116
62810
  const binding = p2;
62117
62811
  if (!binding.consumer || !binding.credentialId) {
62118
62812
  return { error: { code: "invalid_argument", message: "consumer and credentialId required" } };
@@ -62123,7 +62817,7 @@ function handleProviderSetBinding(payload, ctx) {
62123
62817
  function handleProviderClearBinding(payload, ctx) {
62124
62818
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62125
62819
  if (denied) return denied;
62126
- const p2 = asRecord14(payload);
62820
+ const p2 = asRecord15(payload);
62127
62821
  ctx.providers.clearBinding(String(p2.consumer ?? ""));
62128
62822
  return { result: { ok: true } };
62129
62823
  }
@@ -62135,14 +62829,14 @@ function handleProviderListCustomPlatforms(ctx) {
62135
62829
  function handleProviderUpsertCustomPlatform(payload, ctx) {
62136
62830
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62137
62831
  if (denied) return denied;
62138
- const def = asRecord14(payload);
62832
+ const def = asRecord15(payload);
62139
62833
  if (!def?.id) return { error: { code: "invalid_argument", message: "platform id required" } };
62140
62834
  return { result: ctx.providers.upsertCustomPlatform(def) };
62141
62835
  }
62142
62836
  function handleProviderDeleteCustomPlatform(payload, ctx) {
62143
62837
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62144
62838
  if (denied) return denied;
62145
- const p2 = asRecord14(payload);
62839
+ const p2 = asRecord15(payload);
62146
62840
  const ok = ctx.providers.deleteCustomPlatform(String(p2.id ?? ""));
62147
62841
  if (!ok) return { error: { code: "not_found", message: "custom platform not found" } };
62148
62842
  return { result: { ok: true } };
@@ -62155,7 +62849,7 @@ function handleProviderExportBundle(ctx) {
62155
62849
  function handleProviderListModels(payload, ctx) {
62156
62850
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readEnvironment);
62157
62851
  if (denied) return denied;
62158
- const p2 = asRecord14(payload);
62852
+ const p2 = asRecord15(payload);
62159
62853
  const harness = String(p2.harness ?? p2.harnessId ?? "claude");
62160
62854
  const apiProviderId = typeof p2.apiProviderId === "string" && p2.apiProviderId.trim() ? p2.apiProviderId.trim() : null;
62161
62855
  return {
@@ -62167,7 +62861,7 @@ function handleProviderListModels(payload, ctx) {
62167
62861
  function handleProviderImportBundle(payload, ctx) {
62168
62862
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62169
62863
  if (denied) return denied;
62170
- const p2 = asRecord14(payload);
62864
+ const p2 = asRecord15(payload);
62171
62865
  const bundle = p2.bundle && typeof p2.bundle === "object" ? p2.bundle : p2;
62172
62866
  const replaceAll = p2.replaceAll === true;
62173
62867
  try {
@@ -62232,7 +62926,7 @@ function handleHarnessList(ctx) {
62232
62926
  function handleHarnessShow(payload, ctx) {
62233
62927
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62234
62928
  if (denied) return denied;
62235
- const p2 = asRecord14(payload);
62929
+ const p2 = asRecord15(payload);
62236
62930
  const id = typeof p2.harnessId === "string" ? p2.harnessId : typeof p2.id === "string" ? p2.id : "";
62237
62931
  if (!isNodeHarnessId(id)) {
62238
62932
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
@@ -62242,7 +62936,7 @@ function handleHarnessShow(payload, ctx) {
62242
62936
  function handleHarnessProbe(payload, ctx) {
62243
62937
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62244
62938
  if (denied) return denied;
62245
- const p2 = asRecord14(payload);
62939
+ const p2 = asRecord15(payload);
62246
62940
  const id = typeof p2.harnessId === "string" ? p2.harnessId : typeof p2.id === "string" ? p2.id : "";
62247
62941
  if (!isNodeHarnessId(id)) {
62248
62942
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
@@ -62257,7 +62951,7 @@ function handleHarnessProbe(payload, ctx) {
62257
62951
  async function handleHarnessEnable(payload, ctx) {
62258
62952
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62259
62953
  if (denied) return denied;
62260
- const p2 = asRecord14(payload);
62954
+ const p2 = asRecord15(payload);
62261
62955
  const id = typeof p2.harnessId === "string" ? p2.harnessId : typeof p2.id === "string" ? p2.id : "";
62262
62956
  if (!isNodeHarnessId(id)) {
62263
62957
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
@@ -62283,7 +62977,7 @@ async function handleHarnessEnable(payload, ctx) {
62283
62977
  function handleHarnessDisable(payload, ctx) {
62284
62978
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62285
62979
  if (denied) return denied;
62286
- const p2 = asRecord14(payload);
62980
+ const p2 = asRecord15(payload);
62287
62981
  const id = typeof p2.harnessId === "string" ? p2.harnessId : typeof p2.id === "string" ? p2.id : "";
62288
62982
  if (!isNodeHarnessId(id)) {
62289
62983
  return { error: { code: "invalid_argument", message: `unknown harnessId: ${id}` } };
@@ -62348,7 +63042,7 @@ function handleSettingsGet(ctx) {
62348
63042
  function handleSettingsPatch(payload, ctx) {
62349
63043
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.adminNode);
62350
63044
  if (denied) return denied;
62351
- const p2 = asRecord14(payload);
63045
+ const p2 = asRecord15(payload);
62352
63046
  const rawPatch = p2.patch && typeof p2.patch === "object" ? p2.patch : p2;
62353
63047
  try {
62354
63048
  const settings = patchNodeAgentSettings(
@@ -62369,13 +63063,13 @@ async function handleSandboxProbe(ctx) {
62369
63063
  return mapThrown6(err);
62370
63064
  }
62371
63065
  }
62372
- function asRecord14(payload) {
63066
+ function asRecord15(payload) {
62373
63067
  return payload && typeof payload === "object" ? payload : {};
62374
63068
  }
62375
63069
  function handleTerminalCreate(payload, ctx) {
62376
63070
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62377
63071
  if (denied) return denied;
62378
- const p2 = asRecord14(payload);
63072
+ const p2 = asRecord15(payload);
62379
63073
  const cwd = typeof p2.cwd === "string" ? p2.cwd : process.cwd();
62380
63074
  try {
62381
63075
  const info = ctx.terminals.create({
@@ -62400,7 +63094,7 @@ function handleTerminalCreate(payload, ctx) {
62400
63094
  function handleTerminalAttach(payload, ctx) {
62401
63095
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62402
63096
  if (denied) return denied;
62403
- const p2 = asRecord14(payload);
63097
+ const p2 = asRecord15(payload);
62404
63098
  const terminalId = String(p2.terminalId ?? "");
62405
63099
  try {
62406
63100
  const attached = ctx.terminals.attach(terminalId);
@@ -62412,7 +63106,7 @@ function handleTerminalAttach(payload, ctx) {
62412
63106
  function handleTerminalRead(payload, ctx) {
62413
63107
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62414
63108
  if (denied) return denied;
62415
- const p2 = asRecord14(payload);
63109
+ const p2 = asRecord15(payload);
62416
63110
  try {
62417
63111
  return {
62418
63112
  result: ctx.terminals.readAfter(
@@ -62440,7 +63134,7 @@ function requireTerminalLease(payload, ctx, terminalId) {
62440
63134
  function handleTerminalWrite(payload, ctx) {
62441
63135
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62442
63136
  if (denied) return denied;
62443
- const p2 = asRecord14(payload);
63137
+ const p2 = asRecord15(payload);
62444
63138
  const terminalId = String(p2.terminalId ?? "");
62445
63139
  const leaseErr = requireTerminalLease(p2, ctx, terminalId);
62446
63140
  if (leaseErr) return leaseErr;
@@ -62458,7 +63152,7 @@ function handleTerminalWrite(payload, ctx) {
62458
63152
  function handleTerminalResize(payload, ctx) {
62459
63153
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62460
63154
  if (denied) return denied;
62461
- const p2 = asRecord14(payload);
63155
+ const p2 = asRecord15(payload);
62462
63156
  const terminalId = String(p2.terminalId ?? "");
62463
63157
  const leaseErr = requireTerminalLease(p2, ctx, terminalId);
62464
63158
  if (leaseErr) return leaseErr;
@@ -62474,7 +63168,7 @@ function handleTerminalResize(payload, ctx) {
62474
63168
  function handleTerminalKill(payload, ctx) {
62475
63169
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62476
63170
  if (denied) return denied;
62477
- const p2 = asRecord14(payload);
63171
+ const p2 = asRecord15(payload);
62478
63172
  const terminalId = String(p2.terminalId ?? "");
62479
63173
  const leaseErr = requireTerminalLease(p2, ctx, terminalId);
62480
63174
  if (leaseErr) return leaseErr;
@@ -62488,7 +63182,7 @@ function handleTerminalKill(payload, ctx) {
62488
63182
  function handleTerminalAcquireControl(payload, ctx) {
62489
63183
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62490
63184
  if (denied) return denied;
62491
- const p2 = asRecord14(payload);
63185
+ const p2 = asRecord15(payload);
62492
63186
  const terminalId = String(p2.terminalId ?? "");
62493
63187
  try {
62494
63188
  return {
@@ -62505,7 +63199,7 @@ function handleTerminalAcquireControl(payload, ctx) {
62505
63199
  function handleTerminalRenewControl(payload, ctx) {
62506
63200
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62507
63201
  if (denied) return denied;
62508
- const p2 = asRecord14(payload);
63202
+ const p2 = asRecord15(payload);
62509
63203
  try {
62510
63204
  return {
62511
63205
  result: ctx.leases.renew({
@@ -62522,7 +63216,7 @@ function handleTerminalRenewControl(payload, ctx) {
62522
63216
  function handleTerminalReleaseControl(payload, ctx) {
62523
63217
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateTerminal);
62524
63218
  if (denied) return denied;
62525
- const p2 = asRecord14(payload);
63219
+ const p2 = asRecord15(payload);
62526
63220
  try {
62527
63221
  ctx.leases.release(
62528
63222
  String(p2.leaseId ?? ""),
@@ -62547,7 +63241,7 @@ function handleProjectList(ctx) {
62547
63241
  function handleProjectGet(payload, ctx) {
62548
63242
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readProject);
62549
63243
  if (denied) return denied;
62550
- const p2 = asRecord14(payload);
63244
+ const p2 = asRecord15(payload);
62551
63245
  const projectId = String(p2.projectId ?? "");
62552
63246
  return { result: ctx.projects.get(projectId) };
62553
63247
  }
@@ -62563,7 +63257,7 @@ function expandHostPath(path) {
62563
63257
  function handleProjectOpen(payload, ctx) {
62564
63258
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.manageProject);
62565
63259
  if (denied) return denied;
62566
- const p2 = asRecord14(payload);
63260
+ const p2 = asRecord15(payload);
62567
63261
  const path = expandHostPath(String(p2.path ?? ""));
62568
63262
  if (!path) {
62569
63263
  return { error: { code: "invalid_argument", message: "path is required" } };
@@ -62581,7 +63275,7 @@ function handleProjectOpen(payload, ctx) {
62581
63275
  function handleProjectRemove(payload, ctx) {
62582
63276
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.manageProject);
62583
63277
  if (denied) return denied;
62584
- const p2 = asRecord14(payload);
63278
+ const p2 = asRecord15(payload);
62585
63279
  const projectId = typeof p2.projectId === "string" && p2.projectId ? p2.projectId : void 0;
62586
63280
  const pathRaw = typeof p2.path === "string" && p2.path ? expandHostPath(p2.path) : void 0;
62587
63281
  if (!projectId && !pathRaw) {
@@ -62600,7 +63294,7 @@ function handleProjectRemove(payload, ctx) {
62600
63294
  function handleFsListDir(payload, ctx) {
62601
63295
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62602
63296
  if (denied) return denied;
62603
- const p2 = asRecord14(payload);
63297
+ const p2 = asRecord15(payload);
62604
63298
  const raw = String(p2.path ?? "");
62605
63299
  if (!raw || raw.includes("\0")) {
62606
63300
  return { error: { code: "invalid_argument", message: "path is required" } };
@@ -62626,7 +63320,7 @@ function handleFsListDir(payload, ctx) {
62626
63320
  function handleWorkspaceListDir(payload, ctx) {
62627
63321
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62628
63322
  if (denied) return denied;
62629
- const p2 = asRecord14(payload);
63323
+ const p2 = asRecord15(payload);
62630
63324
  try {
62631
63325
  return {
62632
63326
  result: ctx.workspaceFs.listDir(String(p2.projectId ?? ""), String(p2.relativePath ?? "."))
@@ -62638,7 +63332,7 @@ function handleWorkspaceListDir(payload, ctx) {
62638
63332
  function handleWorkspaceListFiles(payload, ctx) {
62639
63333
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62640
63334
  if (denied) return denied;
62641
- const p2 = asRecord14(payload);
63335
+ const p2 = asRecord15(payload);
62642
63336
  try {
62643
63337
  return {
62644
63338
  result: {
@@ -62656,7 +63350,7 @@ function handleWorkspaceListFiles(payload, ctx) {
62656
63350
  function handleWorkspaceListSkills(payload, ctx) {
62657
63351
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62658
63352
  if (denied) return denied;
62659
- const p2 = asRecord14(payload);
63353
+ const p2 = asRecord15(payload);
62660
63354
  try {
62661
63355
  return {
62662
63356
  result: ctx.workspaceFs.listSkillsAndCommands(String(p2.projectId ?? ""))
@@ -62668,7 +63362,7 @@ function handleWorkspaceListSkills(payload, ctx) {
62668
63362
  function handleWorkspaceReadFile(payload, ctx) {
62669
63363
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62670
63364
  if (denied) return denied;
62671
- const p2 = asRecord14(payload);
63365
+ const p2 = asRecord15(payload);
62672
63366
  try {
62673
63367
  return {
62674
63368
  result: ctx.workspaceFs.readFile(String(p2.projectId ?? ""), String(p2.relativePath ?? ""), {
@@ -62683,7 +63377,7 @@ function handleWorkspaceReadFile(payload, ctx) {
62683
63377
  function handleWorkspaceWriteFile(payload, ctx) {
62684
63378
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62685
63379
  if (denied) return denied;
62686
- const p2 = asRecord14(payload);
63380
+ const p2 = asRecord15(payload);
62687
63381
  const raw = typeof p2.content === "string" ? p2.content : String(p2.content ?? "");
62688
63382
  const encoding = p2.encoding === "base64" ? "base64" : "utf8";
62689
63383
  let content = raw;
@@ -62713,7 +63407,7 @@ function handleWorkspaceWriteFile(payload, ctx) {
62713
63407
  function handleWorkspaceSearch(payload, ctx) {
62714
63408
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62715
63409
  if (denied) return denied;
62716
- const p2 = asRecord14(payload);
63410
+ const p2 = asRecord15(payload);
62717
63411
  try {
62718
63412
  return {
62719
63413
  result: ctx.workspaceFs.search(
@@ -62729,7 +63423,7 @@ function handleWorkspaceSearch(payload, ctx) {
62729
63423
  function handleWorkspaceRename(payload, ctx) {
62730
63424
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62731
63425
  if (denied) return denied;
62732
- const p2 = asRecord14(payload);
63426
+ const p2 = asRecord15(payload);
62733
63427
  try {
62734
63428
  return {
62735
63429
  result: ctx.workspaceFs.rename(
@@ -62745,7 +63439,7 @@ function handleWorkspaceRename(payload, ctx) {
62745
63439
  function handleWorkspaceMove(payload, ctx) {
62746
63440
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62747
63441
  if (denied) return denied;
62748
- const p2 = asRecord14(payload);
63442
+ const p2 = asRecord15(payload);
62749
63443
  try {
62750
63444
  return {
62751
63445
  result: ctx.workspaceFs.move(
@@ -62761,7 +63455,7 @@ function handleWorkspaceMove(payload, ctx) {
62761
63455
  function handleWorkspaceDelete(payload, ctx) {
62762
63456
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62763
63457
  if (denied) return denied;
62764
- const p2 = asRecord14(payload);
63458
+ const p2 = asRecord15(payload);
62765
63459
  try {
62766
63460
  return {
62767
63461
  result: ctx.workspaceFs.delete(
@@ -62776,7 +63470,7 @@ function handleWorkspaceDelete(payload, ctx) {
62776
63470
  function handleWorkspaceMkdir(payload, ctx) {
62777
63471
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62778
63472
  if (denied) return denied;
62779
- const p2 = asRecord14(payload);
63473
+ const p2 = asRecord15(payload);
62780
63474
  try {
62781
63475
  return {
62782
63476
  result: ctx.workspaceFs.mkdir(
@@ -62791,7 +63485,7 @@ function handleWorkspaceMkdir(payload, ctx) {
62791
63485
  function handleWorkspaceWatchStart(payload, ctx) {
62792
63486
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62793
63487
  if (denied) return denied;
62794
- const p2 = asRecord14(payload);
63488
+ const p2 = asRecord15(payload);
62795
63489
  try {
62796
63490
  const events = [];
62797
63491
  const { watchId, cancel } = ctx.workspaceWatch.subscribe(
@@ -62812,7 +63506,7 @@ function handleWorkspaceWatchStart(payload, ctx) {
62812
63506
  function handleWorkspaceWatchPoll(payload, ctx) {
62813
63507
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62814
63508
  if (denied) return denied;
62815
- const p2 = asRecord14(payload);
63509
+ const p2 = asRecord15(payload);
62816
63510
  const watchId = String(p2.watchId ?? "");
62817
63511
  const buf = watchBuffers.get(watchId);
62818
63512
  if (!buf || buf.owner !== ctx.client.clientSessionId) {
@@ -62824,7 +63518,7 @@ function handleWorkspaceWatchPoll(payload, ctx) {
62824
63518
  function handleWorkspaceWatchStop(payload, ctx) {
62825
63519
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62826
63520
  if (denied) return denied;
62827
- const p2 = asRecord14(payload);
63521
+ const p2 = asRecord15(payload);
62828
63522
  const watchId = String(p2.watchId ?? "");
62829
63523
  const buf = watchBuffers.get(watchId);
62830
63524
  if (buf && buf.owner === ctx.client.clientSessionId) {
@@ -62836,7 +63530,7 @@ function handleWorkspaceWatchStop(payload, ctx) {
62836
63530
  function handleWorkspaceTailWatchStart(payload, ctx) {
62837
63531
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62838
63532
  if (denied) return denied;
62839
- const p2 = asRecord14(payload);
63533
+ const p2 = asRecord15(payload);
62840
63534
  try {
62841
63535
  const offset = typeof p2.offset === "number" ? p2.offset : void 0;
62842
63536
  const absolutePath = typeof p2.absolutePath === "string" ? p2.absolutePath : void 0;
@@ -62854,7 +63548,7 @@ function handleWorkspaceTailWatchStart(payload, ctx) {
62854
63548
  function handleWorkspaceTailWatchPoll(payload, ctx) {
62855
63549
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62856
63550
  if (denied) return denied;
62857
- const p2 = asRecord14(payload);
63551
+ const p2 = asRecord15(payload);
62858
63552
  try {
62859
63553
  return {
62860
63554
  result: ctx.workspaceTailWatch.poll(String(p2.watchId ?? ""), ctx.client.clientSessionId)
@@ -62866,7 +63560,7 @@ function handleWorkspaceTailWatchPoll(payload, ctx) {
62866
63560
  function handleWorkspaceTailWatchStop(payload, ctx) {
62867
63561
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62868
63562
  if (denied) return denied;
62869
- const p2 = asRecord14(payload);
63563
+ const p2 = asRecord15(payload);
62870
63564
  try {
62871
63565
  return {
62872
63566
  result: ctx.workspaceTailWatch.stop(String(p2.watchId ?? ""), ctx.client.clientSessionId)
@@ -62878,7 +63572,7 @@ function handleWorkspaceTailWatchStop(payload, ctx) {
62878
63572
  function handleGitStatus(payload, ctx) {
62879
63573
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62880
63574
  if (denied) return denied;
62881
- const p2 = asRecord14(payload);
63575
+ const p2 = asRecord15(payload);
62882
63576
  try {
62883
63577
  const projectId = String(p2.projectId ?? "");
62884
63578
  const cwd = typeof p2.cwd === "string" ? p2.cwd : null;
@@ -62892,7 +63586,7 @@ function handleGitStatus(payload, ctx) {
62892
63586
  function handleGitDiff(payload, ctx) {
62893
63587
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62894
63588
  if (denied) return denied;
62895
- const p2 = asRecord14(payload);
63589
+ const p2 = asRecord15(payload);
62896
63590
  try {
62897
63591
  return {
62898
63592
  result: ctx.workspaceGit.diff(String(p2.projectId ?? ""), {
@@ -62907,7 +63601,7 @@ function handleGitDiff(payload, ctx) {
62907
63601
  function handleGitBranches(payload, ctx) {
62908
63602
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62909
63603
  if (denied) return denied;
62910
- const p2 = asRecord14(payload);
63604
+ const p2 = asRecord15(payload);
62911
63605
  try {
62912
63606
  return {
62913
63607
  result: ctx.workspaceGit.branches(
@@ -62922,7 +63616,7 @@ function handleGitBranches(payload, ctx) {
62922
63616
  function handleGitSwitchBranch(payload, ctx) {
62923
63617
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62924
63618
  if (denied) return denied;
62925
- const p2 = asRecord14(payload);
63619
+ const p2 = asRecord15(payload);
62926
63620
  try {
62927
63621
  return {
62928
63622
  result: ctx.workspaceGit.switchBranch(String(p2.projectId ?? ""), String(p2.branch ?? ""), {
@@ -62937,7 +63631,7 @@ function handleGitSwitchBranch(payload, ctx) {
62937
63631
  function handleGitCreateBranch(payload, ctx) {
62938
63632
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62939
63633
  if (denied) return denied;
62940
- const p2 = asRecord14(payload);
63634
+ const p2 = asRecord15(payload);
62941
63635
  try {
62942
63636
  return {
62943
63637
  result: ctx.workspaceGit.switchBranch(String(p2.projectId ?? ""), String(p2.branch ?? ""), {
@@ -62952,7 +63646,7 @@ function handleGitCreateBranch(payload, ctx) {
62952
63646
  function handleGitWorktrees(payload, ctx) {
62953
63647
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62954
63648
  if (denied) return denied;
62955
- const p2 = asRecord14(payload);
63649
+ const p2 = asRecord15(payload);
62956
63650
  try {
62957
63651
  return { result: ctx.workspaceGit.worktrees(String(p2.projectId ?? "")) };
62958
63652
  } catch (err) {
@@ -62962,7 +63656,7 @@ function handleGitWorktrees(payload, ctx) {
62962
63656
  function handleGitWorktreeActivate(payload, ctx) {
62963
63657
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62964
63658
  if (denied) return denied;
62965
- const p2 = asRecord14(payload);
63659
+ const p2 = asRecord15(payload);
62966
63660
  const mode = p2.mode === "attach" || p2.mode === "detach" || p2.mode === "branch" ? p2.mode : null;
62967
63661
  if (!mode) {
62968
63662
  return { error: { code: "invalid_argument", message: "mode must be branch|attach|detach" } };
@@ -62983,7 +63677,7 @@ function handleGitWorktreeActivate(payload, ctx) {
62983
63677
  function handleGitWorktreeCheckedOutBranches(payload, ctx) {
62984
63678
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
62985
63679
  if (denied) return denied;
62986
- const p2 = asRecord14(payload);
63680
+ const p2 = asRecord15(payload);
62987
63681
  try {
62988
63682
  return { result: { branches: ctx.workspaceGit.checkedOutBranches(String(p2.projectId ?? "")) } };
62989
63683
  } catch (err) {
@@ -62993,7 +63687,7 @@ function handleGitWorktreeCheckedOutBranches(payload, ctx) {
62993
63687
  function handleGitWorktreeAssignBranch(payload, ctx) {
62994
63688
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
62995
63689
  if (denied) return denied;
62996
- const p2 = asRecord14(payload);
63690
+ const p2 = asRecord15(payload);
62997
63691
  try {
62998
63692
  return {
62999
63693
  result: ctx.workspaceGit.assignBranch(
@@ -63009,7 +63703,7 @@ function handleGitWorktreeAssignBranch(payload, ctx) {
63009
63703
  function handleGitWorktreeHandoff(payload, ctx) {
63010
63704
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.writeWorkspace);
63011
63705
  if (denied) return denied;
63012
- const p2 = asRecord14(payload);
63706
+ const p2 = asRecord15(payload);
63013
63707
  try {
63014
63708
  return {
63015
63709
  result: ctx.workspaceGit.handoffToMain(
@@ -63024,7 +63718,7 @@ function handleGitWorktreeHandoff(payload, ctx) {
63024
63718
  function handleGitWorktreeHandoffPreview(payload, ctx) {
63025
63719
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readWorkspace);
63026
63720
  if (denied) return denied;
63027
- const p2 = asRecord14(payload);
63721
+ const p2 = asRecord15(payload);
63028
63722
  try {
63029
63723
  return {
63030
63724
  result: ctx.workspaceGit.handoffPreview(
@@ -63039,7 +63733,7 @@ function handleGitWorktreeHandoffPreview(payload, ctx) {
63039
63733
  function handleSessionSetCwd(payload, ctx) {
63040
63734
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63041
63735
  if (denied) return denied;
63042
- const p2 = asRecord14(payload);
63736
+ const p2 = asRecord15(payload);
63043
63737
  const sessionId = String(p2.sessionId ?? "");
63044
63738
  const cwdRaw = p2.cwd;
63045
63739
  const cwd = cwdRaw === null || cwdRaw === void 0 || cwdRaw === "" ? null : String(cwdRaw);
@@ -63068,7 +63762,7 @@ function handleSessionSetCwd(payload, ctx) {
63068
63762
  function handleSessionPatchSettings(payload, ctx) {
63069
63763
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63070
63764
  if (denied) return denied;
63071
- const p2 = asRecord14(payload);
63765
+ const p2 = asRecord15(payload);
63072
63766
  const sessionId = String(p2.sessionId ?? "").trim();
63073
63767
  if (!sessionId) {
63074
63768
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63084,7 +63778,7 @@ function handleSessionPatchSettings(payload, ctx) {
63084
63778
  generation: String(p2.generation ?? ""),
63085
63779
  holderClientId: ctx.client.clientSessionId
63086
63780
  });
63087
- const settingsSrc = asRecord14(p2.settings ?? p2);
63781
+ const settingsSrc = asRecord15(p2.settings ?? p2);
63088
63782
  const patch = {};
63089
63783
  const take = (key) => {
63090
63784
  if (!(key in settingsSrc)) return;
@@ -63110,7 +63804,7 @@ function handleSessionPatchSettings(payload, ctx) {
63110
63804
  async function handleSessionFork(payload, ctx) {
63111
63805
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63112
63806
  if (denied) return denied;
63113
- const p2 = asRecord14(payload);
63807
+ const p2 = asRecord15(payload);
63114
63808
  const sessionId = String(p2.sessionId ?? "").trim();
63115
63809
  if (!sessionId) {
63116
63810
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63197,7 +63891,7 @@ async function handleSessionFork(payload, ctx) {
63197
63891
  async function handleGitClone(payload, ctx) {
63198
63892
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.manageProject);
63199
63893
  if (denied) return denied;
63200
- const p2 = asRecord14(payload);
63894
+ const p2 = asRecord15(payload);
63201
63895
  try {
63202
63896
  const cloned = await cloneRepository({
63203
63897
  remoteUrl: String(p2.remoteUrl ?? ""),
@@ -63212,7 +63906,7 @@ async function handleGitClone(payload, ctx) {
63212
63906
  function handleSessionCreate(payload, ctx) {
63213
63907
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63214
63908
  if (denied) return denied;
63215
- const p2 = asRecord14(payload);
63909
+ const p2 = asRecord15(payload);
63216
63910
  const rawHarnessId = typeof p2.harnessId === "string" ? p2.harnessId : "claude";
63217
63911
  const harnessId = normalizeSessionHarnessId(rawHarnessId);
63218
63912
  if (!harnessId) {
@@ -63265,7 +63959,7 @@ function handleSessionCreate(payload, ctx) {
63265
63959
  try {
63266
63960
  const agentSettings = loadNodeAgentSettings(ctx.settingsConfigPath);
63267
63961
  const defaults = resolveAgentTurnDefaults(agentSettings, harnessId);
63268
- const options = asRecord14(p2.options);
63962
+ const options = asRecord15(p2.options);
63269
63963
  const providerId = typeof p2.providerId === "string" && p2.providerId.trim() ? p2.providerId.trim() : void 0;
63270
63964
  const profile = providerId ? ctx.sessionProviders.get(providerId) : null;
63271
63965
  const profileSettings = profile ? settingsFromSessionProviderConfig(profile.config) : {};
@@ -63325,13 +64019,13 @@ function handleSessionCreate(payload, ctx) {
63325
64019
  function handleSessionGet(payload, ctx) {
63326
64020
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
63327
64021
  if (denied) return denied;
63328
- const p2 = asRecord14(payload);
64022
+ const p2 = asRecord15(payload);
63329
64023
  return { result: ctx.sessions.get(String(p2.sessionId ?? "")) };
63330
64024
  }
63331
64025
  function handleSessionList(payload, ctx) {
63332
64026
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
63333
64027
  if (denied) return denied;
63334
- const p2 = asRecord14(payload);
64028
+ const p2 = asRecord15(payload);
63335
64029
  const projectId = typeof p2.projectId === "string" ? p2.projectId : void 0;
63336
64030
  if (typeof p2.limit !== "number" || !Number.isFinite(p2.limit)) {
63337
64031
  return { error: { code: "invalid_argument", message: "session.list requires finite limit" } };
@@ -63343,28 +64037,34 @@ function handleSessionList(payload, ctx) {
63343
64037
  const offset = Math.max(Math.floor(p2.offset), 0);
63344
64038
  const rows = ctx.sessions.list(projectId, { limit, offset });
63345
64039
  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
- }))
64040
+ result: rows.map((s2) => {
64041
+ const providerResume = s2.providerResume ?? null;
64042
+ const providerSessionId = providerSessionIdFromResume(providerResume);
64043
+ return {
64044
+ sessionId: s2.sessionId,
64045
+ projectId: s2.projectId,
64046
+ harnessId: s2.harnessId,
64047
+ providerId: s2.providerId,
64048
+ title: s2.title,
64049
+ status: s2.status,
64050
+ messageCount: Array.isArray(s2.transcript) ? s2.transcript.length : 0,
64051
+ cwd: s2.cwd,
64052
+ createdAt: s2.createdAt,
64053
+ updatedAt: s2.updatedAt,
64054
+ isPinned: s2.isPinned,
64055
+ isHidden: s2.isHidden,
64056
+ isAutomation: s2.isAutomation === true,
64057
+ automationId: s2.automationId ?? null,
64058
+ providerResume,
64059
+ ...providerSessionId ? { providerSessionId } : {}
64060
+ };
64061
+ })
63362
64062
  };
63363
64063
  }
63364
64064
  function handleSessionAcquireControl(payload, ctx) {
63365
64065
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63366
64066
  if (denied) return denied;
63367
- const p2 = asRecord14(payload);
64067
+ const p2 = asRecord15(payload);
63368
64068
  const sessionId = String(p2.sessionId ?? "");
63369
64069
  if (!sessionId) {
63370
64070
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63383,7 +64083,7 @@ function handleSessionAcquireControl(payload, ctx) {
63383
64083
  function handleSessionRenewControl(payload, ctx) {
63384
64084
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63385
64085
  if (denied) return denied;
63386
- const p2 = asRecord14(payload);
64086
+ const p2 = asRecord15(payload);
63387
64087
  try {
63388
64088
  return {
63389
64089
  result: ctx.leases.renew({
@@ -63400,7 +64100,7 @@ function handleSessionRenewControl(payload, ctx) {
63400
64100
  function handleSessionReleaseControl(payload, ctx) {
63401
64101
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63402
64102
  if (denied) return denied;
63403
- const p2 = asRecord14(payload);
64103
+ const p2 = asRecord15(payload);
63404
64104
  try {
63405
64105
  ctx.leases.release(
63406
64106
  String(p2.leaseId ?? ""),
@@ -63415,7 +64115,7 @@ function handleSessionReleaseControl(payload, ctx) {
63415
64115
  function handleSessionClose(payload, ctx) {
63416
64116
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63417
64117
  if (denied) return denied;
63418
- const p2 = asRecord14(payload);
64118
+ const p2 = asRecord15(payload);
63419
64119
  const sessionId = String(p2.sessionId ?? "");
63420
64120
  try {
63421
64121
  ctx.leases.assertValid({
@@ -63441,7 +64141,7 @@ function handleSessionClose(payload, ctx) {
63441
64141
  function handleSessionRemove(payload, ctx) {
63442
64142
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63443
64143
  if (denied) return denied;
63444
- const p2 = asRecord14(payload);
64144
+ const p2 = asRecord15(payload);
63445
64145
  const sessionId = String(p2.sessionId ?? "");
63446
64146
  if (!sessionId) {
63447
64147
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63468,7 +64168,7 @@ function handleSessionRemove(payload, ctx) {
63468
64168
  function handleSessionRename(payload, ctx) {
63469
64169
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63470
64170
  if (denied) return denied;
63471
- const p2 = asRecord14(payload);
64171
+ const p2 = asRecord15(payload);
63472
64172
  const sessionId = String(p2.sessionId ?? "");
63473
64173
  const title = String(p2.title ?? "");
63474
64174
  const source = p2.source === "agent" ? "agent" : "user";
@@ -63484,7 +64184,7 @@ function handleSessionRename(payload, ctx) {
63484
64184
  function handleSessionSetUiFlags(payload, ctx) {
63485
64185
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63486
64186
  if (denied) return denied;
63487
- const p2 = asRecord14(payload);
64187
+ const p2 = asRecord15(payload);
63488
64188
  const sessionId = String(p2.sessionId ?? "");
63489
64189
  if (!sessionId) {
63490
64190
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63503,9 +64203,9 @@ function handleSessionSetUiFlags(payload, ctx) {
63503
64203
  async function handleSessionSend(payload, ctx) {
63504
64204
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63505
64205
  if (denied) return denied;
63506
- const p2 = asRecord14(payload);
64206
+ const p2 = asRecord15(payload);
63507
64207
  try {
63508
- const options = asRecord14(p2.options);
64208
+ const options = asRecord15(p2.options);
63509
64209
  const modelFromOptions = typeof options.model === "string" && options.model.trim() ? options.model.trim() : null;
63510
64210
  const modelTopLevel = typeof p2.model === "string" && p2.model.trim() ? p2.model.trim() : null;
63511
64211
  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 +64298,7 @@ async function handleSessionSend(payload, ctx) {
63598
64298
  function handleSessionInterrupt(payload, ctx) {
63599
64299
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63600
64300
  if (denied) return denied;
63601
- const p2 = asRecord14(payload);
64301
+ const p2 = asRecord15(payload);
63602
64302
  try {
63603
64303
  ctx.sessions.interrupt(
63604
64304
  String(p2.sessionId ?? ""),
@@ -63614,7 +64314,7 @@ function handleSessionInterrupt(payload, ctx) {
63614
64314
  function handleSessionRespondPermission(payload, ctx) {
63615
64315
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63616
64316
  if (denied) return denied;
63617
- const p2 = asRecord14(payload);
64317
+ const p2 = asRecord15(payload);
63618
64318
  try {
63619
64319
  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
64320
  ctx.sessions.respondPermission({
@@ -63635,7 +64335,7 @@ function handleSessionRespondPermission(payload, ctx) {
63635
64335
  function handleSessionRespondQuestion(payload, ctx) {
63636
64336
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63637
64337
  if (denied) return denied;
63638
- const p2 = asRecord14(payload);
64338
+ const p2 = asRecord15(payload);
63639
64339
  try {
63640
64340
  ctx.sessions.respondQuestion({
63641
64341
  sessionId: String(p2.sessionId ?? ""),
@@ -63653,7 +64353,7 @@ function handleSessionRespondQuestion(payload, ctx) {
63653
64353
  function handleSessionRespondPlan(payload, ctx) {
63654
64354
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63655
64355
  if (denied) return denied;
63656
- const p2 = asRecord14(payload);
64356
+ const p2 = asRecord15(payload);
63657
64357
  const decision = p2.decision === "approve" || p2.decision === "reject" ? p2.decision : null;
63658
64358
  if (!decision) {
63659
64359
  return { error: { code: "invalid_argument", message: "decision must be approve|reject" } };
@@ -63676,7 +64376,7 @@ function handleSessionRespondPlan(payload, ctx) {
63676
64376
  async function handleSessionHostActionsPoll(payload, ctx) {
63677
64377
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63678
64378
  if (denied) return denied;
63679
- const p2 = asRecord14(payload);
64379
+ const p2 = asRecord15(payload);
63680
64380
  try {
63681
64381
  const result = await ctx.sessions.pollHostActions({
63682
64382
  controllerClientSessionId: ctx.client.clientSessionId,
@@ -63692,7 +64392,7 @@ async function handleSessionHostActionsPoll(payload, ctx) {
63692
64392
  function handleSessionClaimHostAction(payload, ctx) {
63693
64393
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63694
64394
  if (denied) return denied;
63695
- const p2 = asRecord14(payload);
64395
+ const p2 = asRecord15(payload);
63696
64396
  try {
63697
64397
  const result = ctx.sessions.claimHostAction({
63698
64398
  actionId: String(p2.actionId ?? ""),
@@ -63708,7 +64408,7 @@ function handleSessionClaimHostAction(payload, ctx) {
63708
64408
  function handleSessionRespondHostAction(payload, ctx) {
63709
64409
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63710
64410
  if (denied) return denied;
63711
- const p2 = asRecord14(payload);
64411
+ const p2 = asRecord15(payload);
63712
64412
  const outcome = p2.outcome === "failed" ? "failed" : p2.outcome === "succeeded" ? "succeeded" : null;
63713
64413
  if (!outcome) {
63714
64414
  return { error: { code: "invalid_argument", message: "outcome must be succeeded|failed" } };
@@ -63730,14 +64430,14 @@ function handleSessionRespondHostAction(payload, ctx) {
63730
64430
  function handleSessionEvents(payload, ctx) {
63731
64431
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
63732
64432
  if (denied) return denied;
63733
- const p2 = asRecord14(payload);
64433
+ const p2 = asRecord15(payload);
63734
64434
  const after = String(p2.afterSequence ?? "0");
63735
64435
  return { result: { events: ctx.sessions.listEventsAfter(after) } };
63736
64436
  }
63737
64437
  function handleSessionMessagesList(payload, ctx) {
63738
64438
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
63739
64439
  if (denied) return denied;
63740
- const p2 = asRecord14(payload);
64440
+ const p2 = asRecord15(payload);
63741
64441
  const sessionId = String(p2.sessionId ?? "").trim();
63742
64442
  if (!sessionId) {
63743
64443
  return { error: { code: "invalid_argument", message: "sessionId required" } };
@@ -63776,7 +64476,7 @@ function handleCollaborationListProfiles(ctx) {
63776
64476
  async function handleCollaborationRequest(payload, ctx) {
63777
64477
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63778
64478
  if (denied) return denied;
63779
- const p2 = asRecord14(payload);
64479
+ const p2 = asRecord15(payload);
63780
64480
  const parentSessionId = String(p2.parentSessionId ?? "");
63781
64481
  if (!parentSessionId) {
63782
64482
  return { error: { code: "invalid_argument", message: "parentSessionId required" } };
@@ -63810,7 +64510,7 @@ async function handleCollaborationRequest(payload, ctx) {
63810
64510
  async function handleCollaborationStart(payload, ctx) {
63811
64511
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63812
64512
  if (denied) return denied;
63813
- const p2 = asRecord14(payload);
64513
+ const p2 = asRecord15(payload);
63814
64514
  const credential = typeof p2.credential === "string" ? p2.credential : void 0;
63815
64515
  const grantId = typeof p2.grantId === "string" ? p2.grantId : void 0;
63816
64516
  if (!credential && !grantId) {
@@ -63856,7 +64556,7 @@ async function handleCollaborationStart(payload, ctx) {
63856
64556
  function handleCollaborationSend(payload, ctx) {
63857
64557
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.operateSession);
63858
64558
  if (denied) return denied;
63859
- const p2 = asRecord14(payload);
64559
+ const p2 = asRecord15(payload);
63860
64560
  const credential = String(p2.credential ?? "");
63861
64561
  const sessionId = String(p2.sessionId ?? p2.fromSessionId ?? "");
63862
64562
  const content = typeof p2.content === "string" ? p2.content : p2.body !== void 0 ? typeof p2.body === "string" ? p2.body : JSON.stringify(p2.body) : "";
@@ -63892,7 +64592,7 @@ function handleCollaborationSend(payload, ctx) {
63892
64592
  function handleCollaborationRetrieve(payload, ctx) {
63893
64593
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
63894
64594
  if (denied) return denied;
63895
- const p2 = asRecord14(payload);
64595
+ const p2 = asRecord15(payload);
63896
64596
  const credential = String(p2.credential ?? "");
63897
64597
  const sessionId = String(p2.sessionId ?? "");
63898
64598
  if (!credential) {