@tonyclaw/agent-inspector 2.1.13 → 2.1.15

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 (92) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/assets/CompareDrawer-BcEd6V-V.js +1 -0
  3. package/.output/public/assets/ProxyViewerContainer-h851qWNp.js +106 -0
  4. package/.output/public/assets/ReplayDialog-BNpC0548.js +1 -0
  5. package/.output/public/assets/{RequestAnatomy-BjlBT-Cy.js → RequestAnatomy-Ds1uRLVB.js} +1 -1
  6. package/.output/public/assets/ResponseView-7KPVqKl5.js +3 -0
  7. package/.output/public/assets/{StreamingChunkSequence-D2_SMhlE.js → StreamingChunkSequence-BHQT261s.js} +1 -1
  8. package/.output/public/assets/_sessionId-DWePGjnS.js +1 -0
  9. package/.output/public/assets/index-CI1-G8ua.js +1 -0
  10. package/.output/public/assets/index-DdhFqPsI.css +1 -0
  11. package/.output/public/assets/index-DjKt8XKe.js +14 -0
  12. package/.output/public/assets/json-viewer-CkCu-rka.js +1 -0
  13. package/.output/public/assets/{main-Dtspb4Ui.js → main-DpD1N0S8.js} +2 -2
  14. package/.output/server/_libs/lucide-react.mjs +194 -200
  15. package/.output/server/_libs/react-markdown.mjs +90 -2
  16. package/.output/server/{_sessionId-CXDcLuvi.mjs → _sessionId-DF9Sy8cP.mjs} +6 -57
  17. package/.output/server/_ssr/{CompareDrawer-CMoCAoeq.mjs → CompareDrawer-BoxztaO7.mjs} +50 -74
  18. package/.output/server/_ssr/{ProxyViewerContainer-BW2vVCBN.mjs → ProxyViewerContainer-CRBkqFlJ.mjs} +1221 -799
  19. package/.output/server/_ssr/{ReplayDialog-ChXL1t8H.mjs → ReplayDialog-Cc1dyDuK.mjs} +18 -62
  20. package/.output/server/_ssr/{RequestAnatomy-DtKzIlfU.mjs → RequestAnatomy-CMGSsz5Z.mjs} +6 -57
  21. package/.output/server/_ssr/{ResponseView-B5I8drzc.mjs → ResponseView-Cp10DM1D.mjs} +139 -61
  22. package/.output/server/_ssr/{StreamingChunkSequence-DvwjQNcO.mjs → StreamingChunkSequence-B1VGxy3A.mjs} +13 -58
  23. package/.output/server/_ssr/{index-D_ZHtRfl.mjs → index-47XVPghS.mjs} +6 -57
  24. package/.output/server/_ssr/index.mjs +2 -2
  25. package/.output/server/_ssr/json-viewer-zDE2rrmJ.mjs +478 -0
  26. package/.output/server/_ssr/{router-DhL9Wp3N.mjs → router-DVeuZFqI.mjs} +680 -174
  27. package/.output/server/{_tanstack-start-manifest_v-BHgoAmxZ.mjs → _tanstack-start-manifest_v-Bp8JxtPW.mjs} +1 -1
  28. package/.output/server/index.mjs +72 -58
  29. package/package.json +1 -1
  30. package/src/components/ProxyViewer.tsx +28 -2
  31. package/src/components/ProxyViewerContainer.tsx +25 -17
  32. package/src/components/clients/ClientLogo.tsx +132 -0
  33. package/src/components/groups/GroupsDialog.tsx +18 -13
  34. package/src/components/providers/ImportWizardDialog.tsx +7 -1
  35. package/src/components/providers/ProviderCard.tsx +10 -1
  36. package/src/components/providers/ProviderForm.tsx +157 -41
  37. package/src/components/providers/ProvidersPanel.tsx +5 -1
  38. package/src/components/proxy-viewer/AgentTraceSummary.tsx +56 -23
  39. package/src/components/proxy-viewer/AnswerMarkdown.tsx +8 -3
  40. package/src/components/proxy-viewer/CompareDrawer.tsx +58 -14
  41. package/src/components/proxy-viewer/ConversationGroup.tsx +11 -15
  42. package/src/components/proxy-viewer/ConversationHeader.tsx +33 -41
  43. package/src/components/proxy-viewer/LogEntry.tsx +41 -12
  44. package/src/components/proxy-viewer/LogEntryHeader.tsx +122 -51
  45. package/src/components/proxy-viewer/ProviderLogoStack.tsx +60 -0
  46. package/src/components/proxy-viewer/ReplayDialog.tsx +8 -2
  47. package/src/components/proxy-viewer/RequestToolsPanel.tsx +19 -13
  48. package/src/components/proxy-viewer/StreamingChunkSequence.tsx +9 -3
  49. package/src/components/proxy-viewer/ThreadConnector.tsx +18 -7
  50. package/src/components/proxy-viewer/TurnGroup.tsx +67 -32
  51. package/src/components/proxy-viewer/TurnGroupList.tsx +153 -0
  52. package/src/components/proxy-viewer/anatomy/sessionContextSummary.ts +74 -2
  53. package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +13 -7
  54. package/src/components/proxy-viewer/formats/index.tsx +10 -3
  55. package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +185 -17
  56. package/src/components/proxy-viewer/log-formats/openai.ts +107 -15
  57. package/src/components/proxy-viewer/logFocus.ts +15 -2
  58. package/src/components/proxy-viewer/requestTools.ts +7 -3
  59. package/src/components/proxy-viewer/viewerState.ts +77 -5
  60. package/src/components/ui/json-viewer-bulk.ts +41 -6
  61. package/src/components/ui/json-viewer.tsx +9 -8
  62. package/src/contracts/index.ts +15 -1
  63. package/src/contracts/openai.ts +94 -0
  64. package/src/lib/providerContract.ts +1 -0
  65. package/src/lib/providerModelMetadata.ts +7 -1
  66. package/src/lib/sessionInfoContract.ts +1 -0
  67. package/src/lib/stopReason.ts +59 -15
  68. package/src/lib/upstreamUrl.ts +46 -0
  69. package/src/mcp/previewExtractor.ts +73 -3
  70. package/src/mcp/server.ts +2 -0
  71. package/src/mcp/toolHandlers.ts +2 -0
  72. package/src/proxy/constants.ts +2 -0
  73. package/src/proxy/formats/openai/handler.ts +40 -9
  74. package/src/proxy/formats/openai/index.ts +7 -0
  75. package/src/proxy/formats/openai/schemas.ts +15 -1
  76. package/src/proxy/formats/openai/stream.ts +529 -135
  77. package/src/proxy/formats/registry.ts +9 -1
  78. package/src/proxy/providerImporters.ts +45 -5
  79. package/src/proxy/providers.ts +31 -11
  80. package/src/proxy/schemas.ts +6 -0
  81. package/src/proxy/sessionInfo.ts +5 -1
  82. package/src/proxy/toolSchemaWarnings.ts +25 -3
  83. package/src/proxy/upstream.ts +18 -37
  84. package/src/routes/api/providers.$providerId.ts +1 -0
  85. package/src/routes/api/providers.ts +2 -0
  86. package/.output/public/assets/CompareDrawer-Cz_1vIpR.js +0 -1
  87. package/.output/public/assets/ProxyViewerContainer-7QSiluMf.js +0 -117
  88. package/.output/public/assets/ReplayDialog-sBA1KAYD.js +0 -1
  89. package/.output/public/assets/ResponseView-PtEKzml9.js +0 -1
  90. package/.output/public/assets/_sessionId-DZfB4ruK.js +0 -1
  91. package/.output/public/assets/index-B-QQLbpz.js +0 -1
  92. package/.output/public/assets/index-CmtfjQPv.css +0 -1
@@ -16,7 +16,7 @@ import { Worker } from "node:worker_threads";
16
16
  import { M as McpServer, W as WebStandardStreamableHTTPServerTransport, R as ResourceTemplate } from "../_libs/modelcontextprotocol__server.mjs";
17
17
  import { J as JSZip } from "../_libs/jszip.mjs";
18
18
  import { homedir } from "node:os";
19
- import { d as object, b as string, a as array, r as record, _ as _enum, u as union, n as number, c as boolean, e as unknown, l as literal, k as lazy, g as discriminatedUnion, h as _null } from "../_libs/zod.mjs";
19
+ import { d as object, b as string, a as array, r as record, _ as _enum, u as union, n as number, c as boolean, e as unknown, l as literal, h as _null, k as lazy, g as discriminatedUnion } from "../_libs/zod.mjs";
20
20
  import "../_libs/tiny-warning.mjs";
21
21
  import "../_libs/tanstack__router-core.mjs";
22
22
  import "../_libs/cookie-es.mjs";
@@ -65,7 +65,7 @@ import "../_libs/immediate.mjs";
65
65
  import "../_libs/setimmediate.mjs";
66
66
  import "../_libs/pako.mjs";
67
67
  const faviconSvg = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20role='img'%20aria-label='Agent%20Inspector'%3e%3cg%20fill='none'%20stroke='%23f59e0b'%20stroke-width='1.5'%20stroke-linecap='round'%20stroke-linejoin='round'%20%3e%3cpath%20d='M5%2013%20C5%209%208%207%2012%207%20C16%207%2019%209%2019%2013%20C19%2016%2016%2018%2012%2018%20C8%2018%205%2016%205%2013%20Z'%20/%3e%3cpath%20d='M5%2011%20C3.5%209.5%201.5%2010%202%2012.5%20C2.5%2014%204%2013.5%205%2012.5'%20/%3e%3cpath%20d='M19%2011%20C20.5%209.5%2022.5%2010%2022%2012.5%20C21.5%2014%2020%2013.5%2019%2012.5'%20/%3e%3cline%20x1='10'%20y1='7'%20x2='9.5'%20y2='5'%20/%3e%3cline%20x1='14'%20y1='7'%20x2='14.5'%20y2='5'%20/%3e%3cline%20x1='6.5'%20y1='16'%20x2='4.5'%20y2='19.5'%20/%3e%3cline%20x1='9'%20y1='17.5'%20x2='8'%20y2='20.5'%20/%3e%3cline%20x1='15'%20y1='17.5'%20x2='16'%20y2='20.5'%20/%3e%3cline%20x1='17.5'%20y1='16'%20x2='19.5'%20y2='19.5'%20/%3e%3c/g%3e%3ccircle%20cx='9.5'%20cy='4.5'%20r='0.9'%20fill='%23f59e0b'%20/%3e%3ccircle%20cx='14.5'%20cy='4.5'%20r='0.9'%20fill='%23f59e0b'%20/%3e%3c/svg%3e";
68
- const appCss = "/assets/index-CmtfjQPv.css";
68
+ const appCss = "/assets/index-DdhFqPsI.css";
69
69
  const Route$D = createRootRoute({
70
70
  head: () => ({
71
71
  meta: [
@@ -108,7 +108,7 @@ function RootDocument({ children }) {
108
108
  ] })
109
109
  ] });
110
110
  }
111
- const $$splitComponentImporter$1 = () => import("./index-D_ZHtRfl.mjs");
111
+ const $$splitComponentImporter$1 = () => import("./index-47XVPghS.mjs");
112
112
  const Route$C = createFileRoute("/")({
113
113
  component: lazyRouteComponent($$splitComponentImporter$1, "component")
114
114
  });
@@ -151,7 +151,7 @@ function decodeSessionIdFromPath(encoded) {
151
151
  function getSessionPath(sessionId) {
152
152
  return `/session/${encodeSessionIdForPath(sessionId)}`;
153
153
  }
154
- const $$splitComponentImporter = () => import("../_sessionId-CXDcLuvi.mjs");
154
+ const $$splitComponentImporter = () => import("../_sessionId-DF9Sy8cP.mjs");
155
155
  const Route$B = createFileRoute("/session/$sessionId")({
156
156
  component: lazyRouteComponent($$splitComponentImporter, "component"),
157
157
  parseParams: (params) => ({
@@ -685,6 +685,29 @@ const OpenAIRequestSchema = object({
685
685
  ]).optional(),
686
686
  user: string().optional()
687
687
  });
688
+ const OpenAIResponsesToolDefinition = object({
689
+ type: string(),
690
+ name: string().optional(),
691
+ description: string().optional(),
692
+ parameters: JsonValueSchema.optional(),
693
+ function: object({
694
+ name: string().optional(),
695
+ description: string().optional(),
696
+ parameters: JsonValueSchema.optional()
697
+ }).optional()
698
+ }).passthrough();
699
+ const OpenAIResponsesRequestSchema = object({
700
+ model: string(),
701
+ input: unknown().optional(),
702
+ instructions: union([string(), _null()]).optional(),
703
+ stream: boolean().optional(),
704
+ tools: array(OpenAIResponsesToolDefinition).optional(),
705
+ tool_choice: unknown().optional(),
706
+ max_output_tokens: number().optional(),
707
+ temperature: number().optional(),
708
+ user: string().optional(),
709
+ metadata: record(string(), unknown()).optional()
710
+ }).passthrough();
688
711
  const OpenAIChoiceDelta = object({
689
712
  role: _enum(["assistant"]).optional(),
690
713
  content: string().nullable().optional(),
@@ -750,6 +773,34 @@ const OpenAISSERawChunkSchema = object({
750
773
  total_tokens: number().nullable().optional()
751
774
  }).passthrough().nullable().optional()
752
775
  }).passthrough();
776
+ const OpenAIResponsesUsageSchema = object({
777
+ input_tokens: number().nullable().optional(),
778
+ output_tokens: number().nullable().optional(),
779
+ total_tokens: number().nullable().optional(),
780
+ input_tokens_details: object({
781
+ cached_tokens: number().nullable().optional()
782
+ }).passthrough().nullable().optional(),
783
+ output_tokens_details: object({
784
+ reasoning_tokens: number().nullable().optional()
785
+ }).passthrough().nullable().optional()
786
+ }).passthrough();
787
+ const OpenAIResponsesOutputItemSchema = object({
788
+ type: string()
789
+ }).passthrough();
790
+ const OpenAIResponsesResponseSchema = object({
791
+ id: string(),
792
+ object: literal("response").optional(),
793
+ created_at: number().optional(),
794
+ status: string().nullable().optional(),
795
+ model: string().optional(),
796
+ output: array(OpenAIResponsesOutputItemSchema).optional(),
797
+ output_text: string().optional(),
798
+ usage: OpenAIResponsesUsageSchema.nullable().optional(),
799
+ error: unknown().optional()
800
+ }).passthrough();
801
+ const OpenAIResponsesSSEventSchema = object({
802
+ type: string()
803
+ }).passthrough();
753
804
  function parseOpenAIResponse(rawBody) {
754
805
  try {
755
806
  const json = JSON.parse(rawBody);
@@ -760,6 +811,16 @@ function parseOpenAIResponse(rawBody) {
760
811
  return null;
761
812
  }
762
813
  }
814
+ function parseOpenAIResponsesResponse(rawBody) {
815
+ try {
816
+ const json = JSON.parse(rawBody);
817
+ const result = OpenAIResponsesResponseSchema.safeParse(json);
818
+ if (result.success) return result.data;
819
+ return null;
820
+ } catch {
821
+ return null;
822
+ }
823
+ }
763
824
  const RequestModelSchema = object({
764
825
  model: string()
765
826
  });
@@ -1000,7 +1061,7 @@ function objectFromUnknown$1(value) {
1000
1061
  if (typeof value === "object" || typeof value === "function") return value;
1001
1062
  return null;
1002
1063
  }
1003
- function readProperty$2(value, name) {
1064
+ function readProperty$3(value, name) {
1004
1065
  let current = objectFromUnknown$1(value);
1005
1066
  while (current !== null) {
1006
1067
  const desc = Object.getOwnPropertyDescriptor(current, name);
@@ -1014,7 +1075,7 @@ function readProperty$2(value, name) {
1014
1075
  return void 0;
1015
1076
  }
1016
1077
  function readFunction$1(value, name) {
1017
- const property = readProperty$2(value, name);
1078
+ const property = readProperty$3(value, name);
1018
1079
  return typeof property === "function" ? property : null;
1019
1080
  }
1020
1081
  function callMethod$1(target, methodName, args) {
@@ -1056,7 +1117,7 @@ function execSql$1(db, sql) {
1056
1117
  return result !== void 0;
1057
1118
  }
1058
1119
  function sqliteConstructorFromModule$1(moduleValue, exportName) {
1059
- const exportedValue = readProperty$2(moduleValue, exportName);
1120
+ const exportedValue = readProperty$3(moduleValue, exportName);
1060
1121
  if (typeof exportedValue === "function") {
1061
1122
  return (path2) => Reflect.construct(exportedValue, [path2]);
1062
1123
  }
@@ -1199,11 +1260,11 @@ function entryParams(entry) {
1199
1260
  ];
1200
1261
  }
1201
1262
  function readNumber$1(row, name) {
1202
- const value = readProperty$2(row, name);
1263
+ const value = readProperty$3(row, name);
1203
1264
  return typeof value === "number" && Number.isFinite(value) ? value : null;
1204
1265
  }
1205
1266
  function readString$2(row, name) {
1206
- const value = readProperty$2(row, name);
1267
+ const value = readProperty$3(row, name);
1207
1268
  return typeof value === "string" ? value : null;
1208
1269
  }
1209
1270
  function readBoolean(row, name) {
@@ -1882,6 +1943,10 @@ function buildSessionInfo(input) {
1882
1943
  const inspectorPath = getSessionPath(input.sessionId);
1883
1944
  const apiPath = buildApiPath(input.sessionId);
1884
1945
  const compactLogsPath = buildCompactLogsPath(input.sessionId);
1946
+ const latestLogs = summaries.slice(0, latestLogLimit).map((summary, index) => ({
1947
+ ...summary,
1948
+ sessionLogNumber: Math.max(1, requestCount - index)
1949
+ }));
1885
1950
  return {
1886
1951
  id: input.sessionId,
1887
1952
  status: deriveSessionStatus({
@@ -1921,14 +1986,16 @@ function buildSessionInfo(input) {
1921
1986
  compactLogsPath,
1922
1987
  compactLogsUrl: buildAbsoluteUrl(input.baseUrl, compactLogsPath),
1923
1988
  latestLogLimit,
1924
- latestLogs: summaries.slice(0, latestLogLimit)
1989
+ latestLogs
1925
1990
  };
1926
1991
  }
1927
1992
  const DEFAULT_UPSTREAM$1 = "https://api.anthropic.com";
1928
1993
  const DEFAULT_OPENAI_UPSTREAM$1 = "https://api.openai.com/v1";
1929
1994
  const PROXY_IDENTITY = process.env["PROXY_IDENTITY"] ?? "inspector9527@Tony";
1930
- const PATH_V1_CHAT_COMPLETIONS = "/v1/chat/completions";
1995
+ const PATH_V1_CHAT_COMPLETIONS$1 = "/v1/chat/completions";
1931
1996
  const PATH_CHAT_COMPLETIONS = "/chat/completions";
1997
+ const PATH_V1_RESPONSES = "/v1/responses";
1998
+ const PATH_RESPONSES = "/responses";
1932
1999
  const PATH_V1_MESSAGES = "/v1/messages";
1933
2000
  const HEADER_CONTENT_TYPE = "content-type";
1934
2001
  const HEADER_USER_AGENT = "user-agent";
@@ -1984,8 +2051,10 @@ function apiFormatForPath(path2) {
1984
2051
  return formatRegistry.getApiFormatByPath(path2) ?? "unknown";
1985
2052
  }
1986
2053
  formatRegistry.registerPath(PATH_V1_MESSAGES, "anthropic");
1987
- formatRegistry.registerPath(PATH_V1_CHAT_COMPLETIONS, "openai");
2054
+ formatRegistry.registerPath(PATH_V1_CHAT_COMPLETIONS$1, "openai");
1988
2055
  formatRegistry.registerPath(PATH_CHAT_COMPLETIONS, "openai");
2056
+ formatRegistry.registerPath(PATH_V1_RESPONSES, "openai");
2057
+ formatRegistry.registerPath(PATH_RESPONSES, "openai");
1989
2058
  const SESSION_ARCHIVE_DIR = "sessions";
1990
2059
  const SESSION_ARCHIVE_FILE = "session.sqlite";
1991
2060
  const SQLITE_PACKAGE_NAME = "better-sqlite3";
@@ -2036,7 +2105,7 @@ function objectFromUnknown(value) {
2036
2105
  if (typeof value === "object" || typeof value === "function") return value;
2037
2106
  return null;
2038
2107
  }
2039
- function readProperty$1(value, name) {
2108
+ function readProperty$2(value, name) {
2040
2109
  let current = objectFromUnknown(value);
2041
2110
  while (current !== null) {
2042
2111
  const desc = Object.getOwnPropertyDescriptor(current, name);
@@ -2050,7 +2119,7 @@ function readProperty$1(value, name) {
2050
2119
  return void 0;
2051
2120
  }
2052
2121
  function readFunction(value, name) {
2053
- const property = readProperty$1(value, name);
2122
+ const property = readProperty$2(value, name);
2054
2123
  return typeof property === "function" ? property : null;
2055
2124
  }
2056
2125
  function callMethod(target, methodName, args) {
@@ -2088,7 +2157,7 @@ function closeDatabase(db) {
2088
2157
  callMethod(db, "close", []);
2089
2158
  }
2090
2159
  function sqliteConstructorFromModule(moduleValue, exportName) {
2091
- const exportedValue = readProperty$1(moduleValue, exportName);
2160
+ const exportedValue = readProperty$2(moduleValue, exportName);
2092
2161
  if (typeof exportedValue === "function") {
2093
2162
  return (path2) => Reflect.construct(exportedValue, [path2]);
2094
2163
  }
@@ -2179,11 +2248,11 @@ async function archiveSessionLog(log) {
2179
2248
  }
2180
2249
  }
2181
2250
  function readString$1(row, name) {
2182
- const value = readProperty$1(row, name);
2251
+ const value = readProperty$2(row, name);
2183
2252
  return typeof value === "string" ? value : null;
2184
2253
  }
2185
2254
  function readNumber(row, name) {
2186
- const value = readProperty$1(row, name);
2255
+ const value = readProperty$2(row, name);
2187
2256
  return typeof value === "number" && Number.isFinite(value) ? value : null;
2188
2257
  }
2189
2258
  function logFromJson(value) {
@@ -3736,7 +3805,7 @@ function extractAnthropicStream(raw, log, fallbackModel, collectChunks) {
3736
3805
  let stopSequence = null;
3737
3806
  let inputTokens = 0;
3738
3807
  let outputTokens = 0;
3739
- const MAX_CHUNKS = 1e3;
3808
+ const MAX_CHUNKS2 = 1e3;
3740
3809
  let chunkIndex = 0;
3741
3810
  let streamStartMs = 0;
3742
3811
  const chunks = [];
@@ -3749,7 +3818,7 @@ function extractAnthropicStream(raw, log, fallbackModel, collectChunks) {
3749
3818
  if (!parsed.success) continue;
3750
3819
  const data = parsed.data;
3751
3820
  if (chunkIndex === 0) streamStartMs = Date.now();
3752
- if (collectChunks === true && chunks.length < MAX_CHUNKS) {
3821
+ if (collectChunks === true && chunks.length < MAX_CHUNKS2) {
3753
3822
  chunks.push({
3754
3823
  index: chunkIndex,
3755
3824
  timestamp: Date.now() - streamStartMs,
@@ -3843,7 +3912,7 @@ function extractAnthropicStream(raw, log, fallbackModel, collectChunks) {
3843
3912
  if (collectChunks === true) {
3844
3913
  log.streamingChunks = {
3845
3914
  chunks,
3846
- truncated: chunkIndex > MAX_CHUNKS
3915
+ truncated: chunkIndex > MAX_CHUNKS2
3847
3916
  };
3848
3917
  }
3849
3918
  const orderedContent = [...blocks.entries()].sort(([a], [b]) => a - b).map(([, block]) => finalizeBlock(block));
@@ -3981,7 +4050,98 @@ const anthropicProvider = {
3981
4050
  }
3982
4051
  };
3983
4052
  registry.register(anthropicProvider);
3984
- function extractOpenAIStream(raw, log, fallbackModel, collectChunks = true) {
4053
+ const MAX_CHUNKS = 1e3;
4054
+ function readProperty$1(value, key) {
4055
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
4056
+ return Object.getOwnPropertyDescriptor(value, key)?.value;
4057
+ }
4058
+ function readStringProperty$1(value, key) {
4059
+ const property = readProperty$1(value, key);
4060
+ return typeof property === "string" ? property : null;
4061
+ }
4062
+ function readNumberProperty(value, key) {
4063
+ const property = readProperty$1(value, key);
4064
+ return typeof property === "number" && Number.isFinite(property) ? property : null;
4065
+ }
4066
+ function readObjectProperty(value, key) {
4067
+ const property = readProperty$1(value, key);
4068
+ return property !== null && typeof property === "object" && !Array.isArray(property) ? property : null;
4069
+ }
4070
+ function readArrayProperty(value, key) {
4071
+ const property = readProperty$1(value, key);
4072
+ return Array.isArray(property) ? property : [];
4073
+ }
4074
+ function parseSseEvents(raw) {
4075
+ const events = [];
4076
+ let event = null;
4077
+ let dataLines = [];
4078
+ const commit = () => {
4079
+ if (event === null && dataLines.length === 0) return;
4080
+ events.push({ event, data: dataLines.join("\n") });
4081
+ event = null;
4082
+ dataLines = [];
4083
+ };
4084
+ for (const rawLine of raw.split("\n")) {
4085
+ const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
4086
+ if (line === "") {
4087
+ commit();
4088
+ continue;
4089
+ }
4090
+ if (line.startsWith(":")) continue;
4091
+ const separatorIndex = line.indexOf(":");
4092
+ const field = separatorIndex === -1 ? line : line.slice(0, separatorIndex);
4093
+ const rawValue = separatorIndex === -1 ? "" : line.slice(separatorIndex + 1);
4094
+ const value = rawValue.startsWith(" ") ? rawValue.slice(1) : rawValue;
4095
+ switch (field) {
4096
+ case "event":
4097
+ event = value;
4098
+ break;
4099
+ case "data":
4100
+ if (event === null && dataLines.length > 0 && (value.startsWith("{") || value === "[DONE]")) {
4101
+ commit();
4102
+ }
4103
+ dataLines.push(value);
4104
+ break;
4105
+ }
4106
+ }
4107
+ commit();
4108
+ return events;
4109
+ }
4110
+ function parseJson$2(data) {
4111
+ try {
4112
+ return JSON.parse(data);
4113
+ } catch {
4114
+ return null;
4115
+ }
4116
+ }
4117
+ function eventTypeFor(event, parsed) {
4118
+ if (event.event !== null && event.event !== "") return event.event;
4119
+ const typed = OpenAIResponsesSSEventSchema.safeParse(parsed);
4120
+ return typed.success ? typed.data.type : "";
4121
+ }
4122
+ function isResponsesEvent(event) {
4123
+ if (event.data === "[DONE]") return false;
4124
+ const parsed = parseJson$2(event.data);
4125
+ const type = eventTypeFor(event, parsed);
4126
+ return type.startsWith("response.") || type === "error";
4127
+ }
4128
+ function collectChunk(chunks, chunkIndex, streamStartMs, type, parsed) {
4129
+ if (chunks.length >= MAX_CHUNKS) return;
4130
+ chunks.push({
4131
+ index: chunkIndex,
4132
+ timestamp: Date.now() - streamStartMs,
4133
+ type,
4134
+ data: trustAsJsonValue(parsed)
4135
+ });
4136
+ }
4137
+ function setErrorFromPayload(log, payload) {
4138
+ const errorObject = readObjectProperty(payload, "error");
4139
+ const message = readStringProperty$1(errorObject, "message") ?? readStringProperty$1(payload, "message") ?? readStringProperty$1(payload, "error");
4140
+ if (message !== null && message.length > 0) {
4141
+ log.error = message;
4142
+ }
4143
+ }
4144
+ function extractChatCompletionsStream(events, log, fallbackModel, collectChunks) {
3985
4145
  let id = "";
3986
4146
  let model = "";
3987
4147
  let completionContent = "";
@@ -3992,106 +4152,78 @@ function extractOpenAIStream(raw, log, fallbackModel, collectChunks = true) {
3992
4152
  let usageCaptured = false;
3993
4153
  let started = false;
3994
4154
  const toolCalls = /* @__PURE__ */ new Map();
3995
- const MAX_CHUNKS = 1e3;
3996
4155
  let chunkIndex = 0;
3997
4156
  let streamStartMs = 0;
3998
4157
  const chunks = [];
3999
- for (const line of raw.split("\n")) {
4000
- const trimmedLine = line.trim();
4001
- if (!trimmedLine.startsWith("data: ")) continue;
4002
- const dataStr = trimmedLine.slice(6);
4003
- if (dataStr === "[DONE]") break;
4004
- try {
4005
- const parsed = JSON.parse(dataStr);
4006
- if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
4007
- const errorDesc = Object.getOwnPropertyDescriptor(parsed, "error");
4008
- if (errorDesc !== void 0 && typeof errorDesc.value === "object" && errorDesc.value !== null) {
4009
- const msgDesc = Object.getOwnPropertyDescriptor(errorDesc.value, "message");
4010
- if (msgDesc !== void 0 && typeof msgDesc.value === "string") {
4011
- log.error = msgDesc.value;
4012
- }
4013
- continue;
4014
- }
4158
+ for (const event of events) {
4159
+ if (event.data === "[DONE]") break;
4160
+ const parsed = parseJson$2(event.data);
4161
+ if (parsed === null) continue;
4162
+ setErrorFromPayload(log, parsed);
4163
+ const chunkResult = OpenAISSERawChunkSchema.safeParse(parsed);
4164
+ if (!chunkResult.success) continue;
4165
+ const chunk = chunkResult.data;
4166
+ if (chunkIndex === 0) streamStartMs = Date.now();
4167
+ if (collectChunks) {
4168
+ collectChunk(chunks, chunkIndex, streamStartMs, "chat.completion.chunk", chunk);
4169
+ }
4170
+ chunkIndex++;
4171
+ if (!started) {
4172
+ id = chunk.id;
4173
+ model = chunk.model;
4174
+ started = true;
4175
+ }
4176
+ if (!usageCaptured && chunk.usage !== void 0 && chunk.usage !== null) {
4177
+ promptTokens = chunk.usage.prompt_tokens ?? 0;
4178
+ completionTokens = chunk.usage.completion_tokens ?? 0;
4179
+ log.inputTokens = promptTokens;
4180
+ const usage = readObjectProperty(parsed, "usage");
4181
+ const details = readObjectProperty(usage, "prompt_tokens_details");
4182
+ const cachedTokens = readNumberProperty(details, "cached_tokens");
4183
+ if (cachedTokens !== null) {
4184
+ log.cacheReadInputTokens = cachedTokens;
4015
4185
  }
4016
- const chunkResult = OpenAISSERawChunkSchema.safeParse(parsed);
4017
- if (!chunkResult.success) continue;
4018
- const chunk = chunkResult.data;
4019
- if (chunkIndex === 0) streamStartMs = Date.now();
4020
- if (collectChunks === true && chunks.length < MAX_CHUNKS) {
4021
- chunks.push({
4022
- index: chunkIndex,
4023
- timestamp: Date.now() - streamStartMs,
4024
- type: "chat.completion.chunk",
4025
- data: trustAsJsonValue(chunk)
4026
- });
4186
+ usageCaptured = true;
4187
+ }
4188
+ for (const choice of chunk.choices) {
4189
+ const delta = choice.delta;
4190
+ if (delta.content !== void 0 && delta.content !== null) {
4191
+ completionContent += delta.content;
4027
4192
  }
4028
- chunkIndex++;
4029
- if (!started) {
4030
- id = chunk.id;
4031
- model = chunk.model;
4032
- started = true;
4193
+ if (delta.reasoning_content !== void 0 && delta.reasoning_content !== null) {
4194
+ reasoningContent += delta.reasoning_content;
4033
4195
  }
4034
- if (!usageCaptured && chunk.usage !== void 0 && chunk.usage !== null) {
4035
- promptTokens = chunk.usage.prompt_tokens ?? 0;
4036
- completionTokens = chunk.usage.completion_tokens ?? 0;
4037
- log.inputTokens = promptTokens;
4038
- if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
4039
- const usageDesc = Object.getOwnPropertyDescriptor(parsed, "usage");
4040
- if (usageDesc !== void 0 && typeof usageDesc.value === "object" && usageDesc.value !== null) {
4041
- const detailsDesc = Object.getOwnPropertyDescriptor(
4042
- usageDesc.value,
4043
- "prompt_tokens_details"
4044
- );
4045
- if (detailsDesc !== void 0 && typeof detailsDesc.value === "object" && detailsDesc.value !== null) {
4046
- const cacheDesc = Object.getOwnPropertyDescriptor(detailsDesc.value, "cached_tokens");
4047
- if (cacheDesc !== void 0 && typeof cacheDesc.value === "number") {
4048
- log.cacheReadInputTokens = cacheDesc.value;
4049
- }
4050
- }
4051
- }
4052
- }
4053
- usageCaptured = true;
4196
+ if (delta.thinking !== void 0 && delta.thinking !== null) {
4197
+ reasoningContent += delta.thinking;
4054
4198
  }
4055
- for (const choice of chunk.choices) {
4056
- const delta = choice.delta;
4057
- if (delta.content !== void 0 && delta.content !== null) {
4058
- completionContent += delta.content;
4059
- }
4060
- if (delta.reasoning_content !== void 0 && delta.reasoning_content !== null) {
4061
- reasoningContent += delta.reasoning_content;
4062
- }
4063
- if (delta.thinking !== void 0 && delta.thinking !== null) {
4064
- reasoningContent += delta.thinking;
4065
- }
4066
- const thinkValue = delta.think;
4067
- if (thinkValue !== void 0 && thinkValue !== null) {
4068
- reasoningContent += thinkValue;
4069
- }
4070
- if (choice.finish_reason !== void 0 && choice.finish_reason !== null) {
4071
- finishReason = choice.finish_reason;
4072
- }
4073
- if (delta.tool_calls !== void 0 && delta.tool_calls !== null) {
4074
- for (const tc of delta.tool_calls) {
4075
- let existing = toolCalls.get(tc.index);
4076
- if (existing === void 0) {
4077
- existing = {
4078
- index: tc.index,
4079
- type: "function",
4080
- function: { name: "", arguments: "" }
4081
- };
4082
- toolCalls.set(tc.index, existing);
4083
- }
4084
- if (tc.id !== void 0) existing.id = tc.id;
4085
- if (tc.function?.name !== void 0) existing.function.name += tc.function.name;
4086
- if (tc.function?.arguments !== void 0)
4087
- existing.function.arguments += tc.function.arguments;
4199
+ const thinkValue = delta.think;
4200
+ if (thinkValue !== void 0 && thinkValue !== null) {
4201
+ reasoningContent += thinkValue;
4202
+ }
4203
+ if (choice.finish_reason !== void 0 && choice.finish_reason !== null) {
4204
+ finishReason = choice.finish_reason;
4205
+ }
4206
+ if (delta.tool_calls !== void 0 && delta.tool_calls !== null) {
4207
+ for (const tc of delta.tool_calls) {
4208
+ let existing = toolCalls.get(tc.index);
4209
+ if (existing === void 0) {
4210
+ existing = {
4211
+ index: tc.index,
4212
+ type: "function",
4213
+ function: { name: "", arguments: "" }
4214
+ };
4215
+ toolCalls.set(tc.index, existing);
4216
+ }
4217
+ if (tc.id !== void 0) existing.id = tc.id;
4218
+ if (tc.function?.name !== void 0) existing.function.name += tc.function.name;
4219
+ if (tc.function?.arguments !== void 0) {
4220
+ existing.function.arguments += tc.function.arguments;
4088
4221
  }
4089
4222
  }
4090
4223
  }
4091
- } catch {
4092
4224
  }
4093
4225
  }
4094
- if (collectChunks === true) {
4226
+ if (collectChunks) {
4095
4227
  log.streamingChunks = {
4096
4228
  chunks,
4097
4229
  truncated: chunkIndex > MAX_CHUNKS
@@ -4105,7 +4237,7 @@ function extractOpenAIStream(raw, log, fallbackModel, collectChunks = true) {
4105
4237
  role: "assistant",
4106
4238
  content: completionContent
4107
4239
  };
4108
- if (reasoningContent) message.reasoning_content = reasoningContent;
4240
+ if (reasoningContent.length > 0) message.reasoning_content = reasoningContent;
4109
4241
  if (toolCalls.size > 0) message.tool_calls = [...toolCalls.values()];
4110
4242
  return JSON.stringify({
4111
4243
  id,
@@ -4126,6 +4258,241 @@ function extractOpenAIStream(raw, log, fallbackModel, collectChunks = true) {
4126
4258
  }
4127
4259
  });
4128
4260
  }
4261
+ function parseResponsesResponse(value) {
4262
+ const fromResponseProperty = OpenAIResponsesResponseSchema.safeParse(
4263
+ readProperty$1(value, "response")
4264
+ );
4265
+ if (fromResponseProperty.success) return fromResponseProperty.data;
4266
+ const direct = OpenAIResponsesResponseSchema.safeParse(value);
4267
+ return direct.success ? direct.data : null;
4268
+ }
4269
+ function responseTextFromOutput(response) {
4270
+ if (response.output_text !== void 0 && response.output_text.length > 0) {
4271
+ return response.output_text;
4272
+ }
4273
+ const parts = [];
4274
+ for (const outputItem of response.output ?? []) {
4275
+ const content = readArrayProperty(outputItem, "content");
4276
+ for (const contentPart of content) {
4277
+ const type = readStringProperty$1(contentPart, "type");
4278
+ const text = readStringProperty$1(contentPart, "text");
4279
+ if ((type === "output_text" || type === "text") && text !== null && text.length > 0) {
4280
+ parts.push(text);
4281
+ }
4282
+ }
4283
+ }
4284
+ return parts.join("\n");
4285
+ }
4286
+ function updateUsageFromResponse(response, log) {
4287
+ const usage = response.usage;
4288
+ const inputTokens = usage?.input_tokens ?? null;
4289
+ const outputTokens = usage?.output_tokens ?? null;
4290
+ if (inputTokens !== null) log.inputTokens = inputTokens;
4291
+ if (outputTokens !== null) log.outputTokens = outputTokens;
4292
+ const cachedTokens = usage?.input_tokens_details?.cached_tokens ?? null;
4293
+ if (cachedTokens !== null) log.cacheReadInputTokens = cachedTokens;
4294
+ return { inputTokens, outputTokens };
4295
+ }
4296
+ function functionCallKey(payload, fallbackIndex) {
4297
+ const itemId = readStringProperty$1(payload, "item_id");
4298
+ if (itemId !== null && itemId.length > 0) return itemId;
4299
+ const outputIndex = readNumberProperty(payload, "output_index");
4300
+ if (outputIndex !== null) return String(outputIndex);
4301
+ return `function-${String(fallbackIndex)}`;
4302
+ }
4303
+ function ensureFunctionCall(calls, key) {
4304
+ const existing = calls.get(key);
4305
+ if (existing !== void 0) return existing;
4306
+ const created = {
4307
+ type: "function_call",
4308
+ arguments: ""
4309
+ };
4310
+ calls.set(key, created);
4311
+ return created;
4312
+ }
4313
+ function updateFunctionCallFromItem(calls, key, item) {
4314
+ if (readStringProperty$1(item, "type") !== "function_call") return;
4315
+ const call = ensureFunctionCall(calls, key);
4316
+ const id = readStringProperty$1(item, "id");
4317
+ const callId = readStringProperty$1(item, "call_id");
4318
+ const name = readStringProperty$1(item, "name");
4319
+ const args = readStringProperty$1(item, "arguments");
4320
+ const status = readStringProperty$1(item, "status");
4321
+ if (id !== null) call.id = id;
4322
+ if (callId !== null) call.call_id = callId;
4323
+ if (name !== null) call.name = name;
4324
+ if (args !== null) call.arguments = args;
4325
+ if (status !== null) call.status = status;
4326
+ }
4327
+ function outputFromCollected(outputText, calls) {
4328
+ const output = [];
4329
+ if (outputText.length > 0) {
4330
+ output.push({
4331
+ type: "message",
4332
+ role: "assistant",
4333
+ content: [{ type: "output_text", text: outputText, annotations: [] }]
4334
+ });
4335
+ }
4336
+ for (const call of calls.values()) {
4337
+ output.push(call);
4338
+ }
4339
+ return output;
4340
+ }
4341
+ function responseUsage(inputTokens, outputTokens, outputText) {
4342
+ const finalOutputTokens = outputTokens ?? Math.ceil(outputText.length / 4);
4343
+ return {
4344
+ input_tokens: inputTokens,
4345
+ output_tokens: finalOutputTokens,
4346
+ total_tokens: inputTokens === null ? finalOutputTokens : inputTokens + finalOutputTokens
4347
+ };
4348
+ }
4349
+ function normalizeResponsesResponse(input) {
4350
+ const completedText = input.completedResponse === null ? "" : responseTextFromOutput(input.completedResponse);
4351
+ const outputText = completedText.length > 0 ? completedText : input.outputText;
4352
+ const completedOutput = input.completedResponse?.output;
4353
+ const output = completedOutput !== void 0 && completedOutput.length > 0 ? completedOutput : outputFromCollected(outputText, input.calls);
4354
+ const usage = input.completedResponse?.usage ?? responseUsage(input.inputTokens, input.outputTokens, outputText);
4355
+ return {
4356
+ ...input.completedResponse ?? {},
4357
+ id: input.completedResponse?.id ?? input.responseId,
4358
+ object: "response",
4359
+ created_at: input.completedResponse?.created_at ?? Math.floor(Date.now() / 1e3),
4360
+ status: input.completedResponse?.status ?? input.status ?? "completed",
4361
+ model: input.completedResponse?.model ?? input.model,
4362
+ output,
4363
+ output_text: outputText,
4364
+ usage
4365
+ };
4366
+ }
4367
+ function extractResponsesStream(events, log, fallbackModel, collectChunks) {
4368
+ let completedResponse = null;
4369
+ let responseId = "";
4370
+ let model = fallbackModel ?? "";
4371
+ let status = null;
4372
+ let outputText = "";
4373
+ let inputTokens = null;
4374
+ let outputTokens = null;
4375
+ let chunkIndex = 0;
4376
+ let streamStartMs = 0;
4377
+ const chunks = [];
4378
+ const calls = /* @__PURE__ */ new Map();
4379
+ for (const event of events) {
4380
+ if (event.data === "[DONE]") break;
4381
+ const parsed = parseJson$2(event.data);
4382
+ if (parsed === null) continue;
4383
+ const type = eventTypeFor(event, parsed);
4384
+ if (chunkIndex === 0) streamStartMs = Date.now();
4385
+ if (collectChunks) {
4386
+ collectChunk(
4387
+ chunks,
4388
+ chunkIndex,
4389
+ streamStartMs,
4390
+ type === "" ? "response.event" : type,
4391
+ parsed
4392
+ );
4393
+ }
4394
+ chunkIndex++;
4395
+ setErrorFromPayload(log, parsed);
4396
+ if (type === "error") continue;
4397
+ const response = parseResponsesResponse(parsed);
4398
+ if (response !== null) {
4399
+ completedResponse = response;
4400
+ responseId = response.id;
4401
+ model = response.model ?? model;
4402
+ status = response.status ?? status;
4403
+ const usage = updateUsageFromResponse(response, log);
4404
+ inputTokens = usage.inputTokens ?? inputTokens;
4405
+ outputTokens = usage.outputTokens ?? outputTokens;
4406
+ setErrorFromPayload(log, response);
4407
+ }
4408
+ const delta = readStringProperty$1(parsed, "delta");
4409
+ switch (type) {
4410
+ case "response.output_text.delta":
4411
+ if (delta !== null) outputText += delta;
4412
+ break;
4413
+ case "response.output_text.done": {
4414
+ const text = readStringProperty$1(parsed, "text");
4415
+ if (outputText.length === 0 && text !== null) outputText = text;
4416
+ break;
4417
+ }
4418
+ case "response.function_call_arguments.delta": {
4419
+ if (delta !== null) {
4420
+ const call = ensureFunctionCall(calls, functionCallKey(parsed, calls.size));
4421
+ call.arguments += delta;
4422
+ }
4423
+ break;
4424
+ }
4425
+ case "response.function_call_arguments.done": {
4426
+ const args = readStringProperty$1(parsed, "arguments");
4427
+ if (args !== null) {
4428
+ const call = ensureFunctionCall(calls, functionCallKey(parsed, calls.size));
4429
+ call.arguments = args;
4430
+ }
4431
+ break;
4432
+ }
4433
+ case "response.output_item.added":
4434
+ case "response.output_item.done": {
4435
+ const item = readObjectProperty(parsed, "item");
4436
+ updateFunctionCallFromItem(calls, functionCallKey(parsed, calls.size), item);
4437
+ break;
4438
+ }
4439
+ case "response.failed":
4440
+ case "response.incomplete":
4441
+ status = type.slice("response.".length);
4442
+ break;
4443
+ case "response.completed":
4444
+ status = "completed";
4445
+ break;
4446
+ }
4447
+ }
4448
+ if (collectChunks) {
4449
+ log.streamingChunks = {
4450
+ chunks,
4451
+ truncated: chunkIndex > MAX_CHUNKS
4452
+ };
4453
+ }
4454
+ const normalized = normalizeResponsesResponse({
4455
+ completedResponse,
4456
+ responseId,
4457
+ model,
4458
+ status,
4459
+ outputText,
4460
+ calls,
4461
+ inputTokens,
4462
+ outputTokens
4463
+ });
4464
+ const normalizedResponse = OpenAIResponsesResponseSchema.safeParse(normalized);
4465
+ if (normalizedResponse.success) {
4466
+ const finalUsage = updateUsageFromResponse(normalizedResponse.data, log);
4467
+ if (finalUsage.outputTokens === null) {
4468
+ const finalText = responseTextFromOutput(normalizedResponse.data);
4469
+ const estimatedOutputTokens = Math.ceil(finalText.length / 4);
4470
+ log.outputTokens = estimatedOutputTokens;
4471
+ }
4472
+ return JSON.stringify(normalizedResponse.data);
4473
+ }
4474
+ if (log.outputTokens === null) {
4475
+ const finalText = readStringProperty$1(normalized, "output_text") ?? outputText;
4476
+ const estimatedOutputTokens = Math.ceil(finalText.length / 4);
4477
+ log.outputTokens = estimatedOutputTokens;
4478
+ }
4479
+ return JSON.stringify(normalized);
4480
+ }
4481
+ function extractOpenAIStream(raw, log, fallbackModel, collectChunks = true) {
4482
+ const events = parseSseEvents(raw);
4483
+ if (events.some(isResponsesEvent)) {
4484
+ return extractResponsesStream(events, log, fallbackModel, collectChunks);
4485
+ }
4486
+ return extractChatCompletionsStream(events, log, fallbackModel, collectChunks);
4487
+ }
4488
+ function emptyTokens() {
4489
+ return {
4490
+ inputTokens: null,
4491
+ outputTokens: null,
4492
+ cacheCreationInputTokens: null,
4493
+ cacheReadInputTokens: null
4494
+ };
4495
+ }
4129
4496
  const OpenAIFormatHandler = {
4130
4497
  format: "openai",
4131
4498
  parseRequest(rawBody, headers) {
@@ -4138,6 +4505,13 @@ const OpenAIFormatHandler = {
4138
4505
  sessionId: headers?.get("x-session-affinity") ?? null
4139
4506
  };
4140
4507
  }
4508
+ const responsesResult = OpenAIResponsesRequestSchema.safeParse(json);
4509
+ if (responsesResult.success) {
4510
+ return {
4511
+ model: responsesResult.data.model,
4512
+ sessionId: headers?.get("x-session-affinity") ?? null
4513
+ };
4514
+ }
4141
4515
  return null;
4142
4516
  } catch {
4143
4517
  return null;
@@ -4173,12 +4547,17 @@ const OpenAIFormatHandler = {
4173
4547
  cacheReadInputTokens
4174
4548
  };
4175
4549
  }
4176
- return {
4177
- inputTokens: null,
4178
- outputTokens: null,
4179
- cacheCreationInputTokens: null,
4180
- cacheReadInputTokens: null
4181
- };
4550
+ const responsesParsed = parseOpenAIResponsesResponse(responseBody);
4551
+ if (responsesParsed !== null) {
4552
+ const usage = responsesParsed.usage;
4553
+ return {
4554
+ inputTokens: usage?.input_tokens ?? null,
4555
+ outputTokens: usage?.output_tokens ?? null,
4556
+ cacheCreationInputTokens: null,
4557
+ cacheReadInputTokens: usage?.input_tokens_details?.cached_tokens ?? null
4558
+ };
4559
+ }
4560
+ return emptyTokens();
4182
4561
  },
4183
4562
  extractStream(raw, log, fallbackModel, collectChunks) {
4184
4563
  return extractOpenAIStream(raw, log, fallbackModel, collectChunks);
@@ -4189,7 +4568,7 @@ const OpenAIFormatHandler = {
4189
4568
  const json = JSON.parse(rawBody);
4190
4569
  if (typeof json === "object" && json !== null && !Array.isArray(json)) {
4191
4570
  const keys = Object.keys(json);
4192
- return keys.includes("model") && keys.includes("messages") && !keys.includes("system");
4571
+ return keys.includes("model") && (keys.includes("messages") || keys.includes("input")) && !keys.includes("system");
4193
4572
  }
4194
4573
  return false;
4195
4574
  } catch {
@@ -4281,6 +4660,7 @@ const ProviderConfigSchema = object({
4281
4660
  baseUrl: string().optional(),
4282
4661
  anthropicBaseUrl: string().optional(),
4283
4662
  openaiBaseUrl: string().optional(),
4663
+ openaiResponsesBaseUrl: string().optional(),
4284
4664
  authHeader: _enum(["bearer", "x-api-key"]).optional().default("bearer"),
4285
4665
  apiDocsUrl: string().optional(),
4286
4666
  modelMetadataUrl: string().optional(),
@@ -4346,7 +4726,7 @@ const BUILTIN_PROVIDER_MODEL_REGISTRY = {
4346
4726
  {
4347
4727
  name: "MiniMax",
4348
4728
  aliases: ["minimax"],
4349
- baseUrls: ["https://api.minimaxi.com/anthropic"],
4729
+ baseUrls: ["https://api.minimaxi.com/anthropic", "https://api.minimaxi.com"],
4350
4730
  models: [
4351
4731
  {
4352
4732
  id: "MiniMax M3",
@@ -4506,6 +4886,9 @@ function providerBaseUrls(provider) {
4506
4886
  if (provider.openaiBaseUrl !== void 0 && provider.openaiBaseUrl.trim() !== "") {
4507
4887
  urls.push(provider.openaiBaseUrl);
4508
4888
  }
4889
+ if (provider.openaiResponsesBaseUrl !== void 0 && provider.openaiResponsesBaseUrl.trim() !== "") {
4890
+ urls.push(provider.openaiResponsesBaseUrl);
4891
+ }
4509
4892
  if (provider.baseUrl !== void 0 && provider.baseUrl.trim() !== "") {
4510
4893
  urls.push(provider.baseUrl);
4511
4894
  }
@@ -4670,6 +5053,7 @@ const LegacyProviderConfigSchema = object({
4670
5053
  baseUrl: string().optional(),
4671
5054
  anthropicBaseUrl: string().optional(),
4672
5055
  openaiBaseUrl: string().optional(),
5056
+ openaiResponsesBaseUrl: string().optional(),
4673
5057
  authHeader: _enum(["bearer", "x-api-key"]).optional(),
4674
5058
  apiDocsUrl: string().optional(),
4675
5059
  modelMetadataUrl: string().optional(),
@@ -4698,6 +5082,7 @@ function migrateLegacyProvider(provider, index, now) {
4698
5082
  const baseUrl = provider.baseUrl;
4699
5083
  const anthropicBaseUrl = provider.anthropicBaseUrl ?? (format === "anthropic" && baseUrl !== void 0 ? baseUrl : "");
4700
5084
  const openaiBaseUrl = provider.openaiBaseUrl ?? (format === "openai" && baseUrl !== void 0 ? baseUrl : "");
5085
+ const openaiResponsesBaseUrl = provider.openaiResponsesBaseUrl ?? "";
4701
5086
  const candidate = {
4702
5087
  id: provider.id ?? randomUUID(),
4703
5088
  name,
@@ -4708,6 +5093,7 @@ function migrateLegacyProvider(provider, index, now) {
4708
5093
  baseUrl,
4709
5094
  anthropicBaseUrl,
4710
5095
  openaiBaseUrl,
5096
+ openaiResponsesBaseUrl,
4711
5097
  authHeader: provider.authHeader ?? "bearer",
4712
5098
  apiDocsUrl: provider.apiDocsUrl,
4713
5099
  modelMetadataUrl: provider.modelMetadataUrl,
@@ -4788,13 +5174,13 @@ const store = new Conf({
4788
5174
  migrateFromDataDirConfig(store, dataDir);
4789
5175
  migrateFromLegacyConfLocation(store);
4790
5176
  function migrateProvider(p) {
4791
- if (p.anthropicBaseUrl !== void 0 || p.openaiBaseUrl !== void 0) {
5177
+ if (p.anthropicBaseUrl !== void 0 || p.openaiBaseUrl !== void 0 || p.openaiResponsesBaseUrl !== void 0) {
4792
5178
  return p;
4793
5179
  }
4794
5180
  if (p.format === void 0 || p.baseUrl === void 0 || p.baseUrl === "") {
4795
5181
  return p;
4796
5182
  }
4797
- return p.format === "openai" ? { ...p, anthropicBaseUrl: "", openaiBaseUrl: p.baseUrl } : { ...p, anthropicBaseUrl: p.baseUrl, openaiBaseUrl: "" };
5183
+ return p.format === "openai" ? { ...p, anthropicBaseUrl: "", openaiBaseUrl: p.baseUrl, openaiResponsesBaseUrl: "" } : { ...p, anthropicBaseUrl: p.baseUrl, openaiBaseUrl: "", openaiResponsesBaseUrl: "" };
4798
5184
  }
4799
5185
  function migrateProviders() {
4800
5186
  const providers = store.get("providers", []);
@@ -4817,7 +5203,7 @@ function migrateMultiModel() {
4817
5203
  });
4818
5204
  const groups = /* @__PURE__ */ new Map();
4819
5205
  for (const p of promoted) {
4820
- const key = `${p.apiKey}::${p.anthropicBaseUrl ?? ""}::${p.openaiBaseUrl ?? ""}`;
5206
+ const key = `${p.apiKey}::${p.anthropicBaseUrl ?? ""}::${p.openaiBaseUrl ?? ""}::${p.openaiResponsesBaseUrl ?? ""}`;
4821
5207
  const group = groups.get(key);
4822
5208
  if (group !== void 0) {
4823
5209
  group.push(p);
@@ -4905,14 +5291,15 @@ function redactProviders(providers) {
4905
5291
  function normalizeApiKey(apiKey) {
4906
5292
  return apiKey.replace(/^Bearer\s+/i, "").trim();
4907
5293
  }
4908
- function addProvider(name, apiKey, format, baseUrl, models, authHeader, apiDocsUrl, anthropicBaseUrl, openaiBaseUrl, source, modelMetadataUrl, modelMetadata) {
5294
+ function addProvider(name, apiKey, format, baseUrl, models, authHeader, apiDocsUrl, anthropicBaseUrl, openaiBaseUrl, source, modelMetadataUrl, modelMetadata, openaiResponsesBaseUrl) {
4909
5295
  const providers = getProviders();
4910
5296
  const normalizedKey = normalizeApiKey(apiKey);
4911
5297
  const resolvedAnthropicUrl = anthropicBaseUrl ?? "";
4912
5298
  const resolvedOpenaiUrl = openaiBaseUrl ?? "";
5299
+ const resolvedOpenaiResponsesUrl = openaiResponsesBaseUrl ?? "";
4913
5300
  const now = (/* @__PURE__ */ new Date()).toISOString();
4914
5301
  const existing = providers.find(
4915
- (p) => p.apiKey === normalizedKey && (p.anthropicBaseUrl ?? "") === (resolvedAnthropicUrl ?? "") && (p.openaiBaseUrl ?? "") === (resolvedOpenaiUrl ?? "")
5302
+ (p) => p.apiKey === normalizedKey && (p.anthropicBaseUrl ?? "") === (resolvedAnthropicUrl ?? "") && (p.openaiBaseUrl ?? "") === (resolvedOpenaiUrl ?? "") && (p.openaiResponsesBaseUrl ?? "") === (resolvedOpenaiResponsesUrl ?? "")
4916
5303
  );
4917
5304
  if (existing) {
4918
5305
  const existingIndex = providers.findIndex((p) => p.id === existing.id);
@@ -4937,7 +5324,7 @@ function addProvider(name, apiKey, format, baseUrl, models, authHeader, apiDocsU
4937
5324
  id: randomUUID(),
4938
5325
  name,
4939
5326
  apiKey: normalizedKey,
4940
- format: format ?? (anthropicBaseUrl !== void 0 ? "anthropic" : openaiBaseUrl !== void 0 ? "openai" : void 0),
5327
+ format: format ?? (anthropicBaseUrl !== void 0 ? "anthropic" : openaiBaseUrl !== void 0 || openaiResponsesBaseUrl !== void 0 ? "openai" : void 0),
4941
5328
  baseUrl,
4942
5329
  models: models ?? [],
4943
5330
  authHeader: authHeader ?? "bearer",
@@ -4948,6 +5335,7 @@ function addProvider(name, apiKey, format, baseUrl, models, authHeader, apiDocsU
4948
5335
  updatedAt: now,
4949
5336
  anthropicBaseUrl: resolvedAnthropicUrl,
4950
5337
  openaiBaseUrl: resolvedOpenaiUrl,
5338
+ openaiResponsesBaseUrl: resolvedOpenaiResponsesUrl,
4951
5339
  source
4952
5340
  },
4953
5341
  now
@@ -4978,6 +5366,7 @@ function updateProvider(id, updates) {
4978
5366
  // Handle format-specific URLs
4979
5367
  anthropicBaseUrl: updates.anthropicBaseUrl !== void 0 ? updates.anthropicBaseUrl : existing.anthropicBaseUrl,
4980
5368
  openaiBaseUrl: updates.openaiBaseUrl !== void 0 ? updates.openaiBaseUrl : existing.openaiBaseUrl,
5369
+ openaiResponsesBaseUrl: updates.openaiResponsesBaseUrl !== void 0 ? updates.openaiResponsesBaseUrl : existing.openaiResponsesBaseUrl,
4981
5370
  source: updates.source !== void 0 ? updates.source : existing.source
4982
5371
  },
4983
5372
  updatedAt
@@ -5095,6 +5484,9 @@ function providerRoutingUrls(provider) {
5095
5484
  if (provider.openaiBaseUrl !== void 0 && provider.openaiBaseUrl.trim() !== "") {
5096
5485
  urls.push(provider.openaiBaseUrl);
5097
5486
  }
5487
+ if (provider.openaiResponsesBaseUrl !== void 0 && provider.openaiResponsesBaseUrl.trim() !== "") {
5488
+ urls.push(provider.openaiResponsesBaseUrl);
5489
+ }
5098
5490
  if (provider.baseUrl !== void 0 && provider.baseUrl.trim() !== "") {
5099
5491
  urls.push(provider.baseUrl);
5100
5492
  }
@@ -6053,12 +6445,12 @@ function extractOpenAIToolSchemas(request) {
6053
6445
  const tools = /* @__PURE__ */ new Map();
6054
6446
  for (const tool of readArray(request, "tools")) {
6055
6447
  const functionDefinition = readObject(tool, "function");
6056
- if (functionDefinition === null) continue;
6057
- const name = readString(functionDefinition, "name");
6448
+ const name = functionDefinition === null ? readString(tool, "name") : readString(functionDefinition, "name") ?? readString(tool, "name");
6058
6449
  if (name === null || name === "") continue;
6450
+ const parameters = functionDefinition === null ? readObject(tool, "parameters") : readObject(functionDefinition, "parameters") ?? readObject(tool, "parameters");
6059
6451
  tools.set(name, {
6060
6452
  name,
6061
- schema: readObject(functionDefinition, "parameters")
6453
+ schema: parameters
6062
6454
  });
6063
6455
  }
6064
6456
  return tools;
@@ -6130,6 +6522,21 @@ function extractOpenAIToolCalls(response) {
6130
6522
  }
6131
6523
  choiceIndex++;
6132
6524
  }
6525
+ let outputIndex = 0;
6526
+ for (const item of readArray(response, "output")) {
6527
+ if (readString(item, "type") !== "function_call") {
6528
+ outputIndex++;
6529
+ continue;
6530
+ }
6531
+ const parsedArguments = parseOpenAIArguments(readProperty(item, "arguments"));
6532
+ calls.push({
6533
+ name: readString(item, "name"),
6534
+ arguments: parsedArguments.value,
6535
+ argumentIssue: parsedArguments.issue,
6536
+ location: `output[${outputIndex}]`
6537
+ });
6538
+ outputIndex++;
6539
+ }
6133
6540
  return calls;
6134
6541
  }
6135
6542
  function extractAnthropicToolCalls(response) {
@@ -6710,30 +7117,15 @@ class RawStreamCapture {
6710
7117
  this.chunks = [];
6711
7118
  }
6712
7119
  }
6713
- function describeApiRoute(apiPath) {
6714
- const endpointPath = apiPath.split("?")[0] ?? "";
6715
- const isChatCompletions = endpointPath === PATH_CHAT_COMPLETIONS || endpointPath === PATH_V1_CHAT_COMPLETIONS;
6716
- const normalizedPath = isChatCompletions && !apiPath.startsWith("/v1/") ? `/v1${apiPath}` : apiPath;
6717
- return { apiPath, endpointPath, isChatCompletions, normalizedPath };
6718
- }
6719
- function getProxyApiPath(url) {
6720
- return url.pathname.replace(/^\/proxy/, "") + url.search;
6721
- }
6722
- function selectUpstreamBase(route, provider) {
6723
- if (provider === null) {
6724
- return route.isChatCompletions ? DEFAULT_OPENAI_UPSTREAM$1 : DEFAULT_UPSTREAM$1;
6725
- }
6726
- const formatSpecificUrl = route.isChatCompletions ? provider.openaiBaseUrl : provider.anthropicBaseUrl;
6727
- if (formatSpecificUrl !== void 0 && formatSpecificUrl !== "") {
6728
- return formatSpecificUrl;
6729
- }
6730
- if (provider.baseUrl !== void 0 && provider.baseUrl !== "") {
6731
- return provider.baseUrl;
6732
- }
6733
- return provider.format === "openai" ? DEFAULT_OPENAI_UPSTREAM$1 : DEFAULT_UPSTREAM$1;
6734
- }
7120
+ const PATH_V1_CHAT_COMPLETIONS = "/v1/chat/completions";
6735
7121
  function buildUpstreamUrl(upstreamBase, normalizedPath) {
6736
7122
  const base = upstreamBase.endsWith("/") ? upstreamBase.slice(0, -1) : upstreamBase;
7123
+ const endpointPath = normalizedPath.split("?")[0] ?? normalizedPath;
7124
+ const queryIndex = normalizedPath.indexOf("?");
7125
+ const search = queryIndex >= 0 ? normalizedPath.slice(queryIndex) : "";
7126
+ if (endpointPath !== "" && base.endsWith(endpointPath)) {
7127
+ return base + search;
7128
+ }
6737
7129
  if (isZhipuVersionedOpenAIBase(base) && isVersionedChatCompletionsPath(normalizedPath)) {
6738
7130
  return base + normalizedPath.slice(3);
6739
7131
  }
@@ -6754,6 +7146,40 @@ function isZhipuVersionedOpenAIBase(base) {
6754
7146
  return false;
6755
7147
  }
6756
7148
  }
7149
+ function describeApiRoute(apiPath) {
7150
+ const endpointPath = apiPath.split("?")[0] ?? "";
7151
+ const isChatCompletions = endpointPath === PATH_CHAT_COMPLETIONS || endpointPath === PATH_V1_CHAT_COMPLETIONS$1;
7152
+ const isResponses = endpointPath === PATH_RESPONSES || endpointPath === PATH_V1_RESPONSES;
7153
+ const isOpenAI = isChatCompletions || isResponses;
7154
+ const normalizedPath = isOpenAI && !apiPath.startsWith("/v1/") ? `/v1${apiPath}` : apiPath;
7155
+ return { apiPath, endpointPath, isChatCompletions, isResponses, isOpenAI, normalizedPath };
7156
+ }
7157
+ function getProxyApiPath(url) {
7158
+ return url.pathname.replace(/^\/proxy/, "") + url.search;
7159
+ }
7160
+ function selectUpstreamBase(route, provider) {
7161
+ if (provider === null) {
7162
+ return route.isOpenAI ? DEFAULT_OPENAI_UPSTREAM$1 : DEFAULT_UPSTREAM$1;
7163
+ }
7164
+ const formatSpecificUrl = selectFormatSpecificUrl(route, provider);
7165
+ if (formatSpecificUrl !== void 0 && formatSpecificUrl !== "") {
7166
+ return formatSpecificUrl;
7167
+ }
7168
+ if (provider.baseUrl !== void 0 && provider.baseUrl !== "") {
7169
+ return provider.baseUrl;
7170
+ }
7171
+ return provider.format === "openai" ? DEFAULT_OPENAI_UPSTREAM$1 : DEFAULT_UPSTREAM$1;
7172
+ }
7173
+ function nonEmptyUrl(value) {
7174
+ return value !== void 0 && value !== "" ? value : void 0;
7175
+ }
7176
+ function selectFormatSpecificUrl(route, provider) {
7177
+ if (!route.isOpenAI) return provider.anthropicBaseUrl;
7178
+ if (route.isResponses) {
7179
+ return nonEmptyUrl(provider.openaiResponsesBaseUrl) ?? provider.openaiBaseUrl;
7180
+ }
7181
+ return provider.openaiBaseUrl;
7182
+ }
6757
7183
  function setUpstreamHost(headers, upstreamBase) {
6758
7184
  try {
6759
7185
  headers.set(HEADER_HOST, new URL(upstreamBase).host);
@@ -7061,6 +7487,7 @@ const SessionTokenUsageSchema = object({
7061
7487
  });
7062
7488
  const SessionLogSummarySchema = object({
7063
7489
  id: number().int().positive(),
7490
+ sessionLogNumber: number().int().positive().optional(),
7064
7491
  timestamp: string(),
7065
7492
  provider: string().nullable(),
7066
7493
  model: string().nullable(),
@@ -8498,6 +8925,7 @@ const ProviderInputSchema = object({
8498
8925
  format: _enum(["anthropic", "openai"]).optional(),
8499
8926
  anthropicBaseUrl: string().optional(),
8500
8927
  openaiBaseUrl: string().optional(),
8928
+ openaiResponsesBaseUrl: string().optional(),
8501
8929
  models: array(string()).min(1, "At least one model is required"),
8502
8930
  model: string().optional(),
8503
8931
  authHeader: _enum(["bearer", "x-api-key"]).optional().default("bearer"),
@@ -8533,7 +8961,8 @@ const Route$x = createFileRoute("/api/providers")({
8533
8961
  parsed.data.openaiBaseUrl,
8534
8962
  parsed.data.source,
8535
8963
  parsed.data.modelMetadataUrl,
8536
- parsed.data.modelMetadata
8964
+ parsed.data.modelMetadata,
8965
+ parsed.data.openaiResponsesBaseUrl
8537
8966
  );
8538
8967
  return Response.json(newProvider, { status: 201 });
8539
8968
  }
@@ -8547,7 +8976,7 @@ const Route$w = createFileRoute("/api/models")({
8547
8976
  }
8548
8977
  }
8549
8978
  });
8550
- const version = "2.1.13";
8979
+ const version = "2.1.15";
8551
8980
  const packageJson = {
8552
8981
  version
8553
8982
  };
@@ -9016,6 +9445,7 @@ async function callApi(path2, options = {}) {
9016
9445
  }
9017
9446
  }
9018
9447
  const PREVIEW_MAX_CHARS = 500;
9448
+ const UnknownArraySchema = array(unknown());
9019
9449
  function truncate(text) {
9020
9450
  return text.length <= PREVIEW_MAX_CHARS ? text : text.slice(0, PREVIEW_MAX_CHARS);
9021
9451
  }
@@ -9042,6 +9472,48 @@ function firstOpenAIText(content) {
9042
9472
  }
9043
9473
  return null;
9044
9474
  }
9475
+ function firstResponsesInputText(input) {
9476
+ if (typeof input === "string") return input.length > 0 ? input : null;
9477
+ const parsedInput = UnknownArraySchema.safeParse(input);
9478
+ if (!parsedInput.success) return null;
9479
+ for (let i = parsedInput.data.length - 1; i >= 0; i--) {
9480
+ const item = parsedInput.data[i];
9481
+ const role = safeGetOwnProperty(item, "role");
9482
+ if (role !== "user" && role !== void 0) continue;
9483
+ const directText = safeGetOwnProperty(item, "text");
9484
+ if (typeof directText === "string" && directText.length > 0) return directText;
9485
+ const content = safeGetOwnProperty(item, "content");
9486
+ if (typeof content === "string" && content.length > 0) return content;
9487
+ if (Array.isArray(content)) {
9488
+ for (const part of content) {
9489
+ const type = safeGetOwnProperty(part, "type");
9490
+ const text = safeGetOwnProperty(part, "text");
9491
+ if ((type === "input_text" || type === "text") && typeof text === "string" && text.length > 0) {
9492
+ return text;
9493
+ }
9494
+ }
9495
+ }
9496
+ }
9497
+ return null;
9498
+ }
9499
+ function firstResponsesOutputText(response) {
9500
+ const outputText = safeGetOwnProperty(response, "output_text");
9501
+ if (typeof outputText === "string" && outputText.length > 0) return outputText;
9502
+ const output = safeGetOwnProperty(response, "output");
9503
+ if (!Array.isArray(output)) return null;
9504
+ for (const item of output) {
9505
+ const content = safeGetOwnProperty(item, "content");
9506
+ if (!Array.isArray(content)) continue;
9507
+ for (const part of content) {
9508
+ const type = safeGetOwnProperty(part, "type");
9509
+ const text = safeGetOwnProperty(part, "text");
9510
+ if ((type === "output_text" || type === "text") && typeof text === "string" && text.length > 0) {
9511
+ return text;
9512
+ }
9513
+ }
9514
+ }
9515
+ return null;
9516
+ }
9045
9517
  function extractLastUserMessagePreview(log) {
9046
9518
  if (log.apiFormat === "unknown") return null;
9047
9519
  if (log.rawRequestBody === null) return null;
@@ -9065,7 +9537,12 @@ function extractLastUserMessagePreview(log) {
9065
9537
  }
9066
9538
  if (log.apiFormat === "openai") {
9067
9539
  const parsed = OpenAIRequestSchema.safeParse(json);
9068
- if (!parsed.success) return null;
9540
+ if (!parsed.success) {
9541
+ const responsesParsed = OpenAIResponsesRequestSchema.safeParse(json);
9542
+ if (!responsesParsed.success) return null;
9543
+ const text = firstResponsesInputText(responsesParsed.data.input);
9544
+ return text === null ? null : truncate(text);
9545
+ }
9069
9546
  for (let i = parsed.data.messages.length - 1; i >= 0; i--) {
9070
9547
  const msg = parsed.data.messages[i];
9071
9548
  if (msg && msg.role === "user") {
@@ -9098,7 +9575,12 @@ function extractResponsePreview(log) {
9098
9575
  }
9099
9576
  if (log.apiFormat === "openai") {
9100
9577
  const parsed = OpenAIResponseSchema$1.safeParse(json);
9101
- if (!parsed.success) return null;
9578
+ if (!parsed.success) {
9579
+ const responsesParsed = OpenAIResponsesResponseSchema.safeParse(json);
9580
+ if (!responsesParsed.success) return null;
9581
+ const text = firstResponsesOutputText(responsesParsed.data);
9582
+ return text === null ? null : truncate(text);
9583
+ }
9102
9584
  for (const choice of parsed.data.choices) {
9103
9585
  const msg = choice.message;
9104
9586
  if (!msg) continue;
@@ -10505,6 +10987,7 @@ Persists a new provider to <dataDir>/providers.json. Required fields: name, apiK
10505
10987
  model: string().min(1),
10506
10988
  anthropicBaseUrl: string().optional(),
10507
10989
  openaiBaseUrl: string().optional(),
10990
+ openaiResponsesBaseUrl: string().optional(),
10508
10991
  authHeader: _enum(["bearer", "x-api-key"]).optional(),
10509
10992
  apiDocsUrl: string().optional()
10510
10993
  })
@@ -10528,6 +11011,7 @@ PATCH-style update: only the fields you supply are changed. Returns the updated
10528
11011
  authHeader: _enum(["bearer", "x-api-key"]).optional(),
10529
11012
  anthropicBaseUrl: string().optional(),
10530
11013
  openaiBaseUrl: string().optional(),
11014
+ openaiResponsesBaseUrl: string().optional(),
10531
11015
  apiDocsUrl: string().optional()
10532
11016
  })
10533
11017
  },
@@ -11994,6 +12478,18 @@ const Route$p = createFileRoute("/api/runs/$runId")({
11994
12478
  const ZHIPU_OPENAI_BASE_URL = "https://open.bigmodel.cn/api/paas/v4";
11995
12479
  const ZHIPU_CODING_OPENAI_BASE_URL = "https://open.bigmodel.cn/api/coding/paas/v4";
11996
12480
  const ZHIPU_CODING_ANTHROPIC_BASE_URL = "https://open.bigmodel.cn/api/anthropic";
12481
+ const MINIMAX_OPENAI_BASE_URL = "https://api.minimaxi.com";
12482
+ function defaultOpenAIResponsesBaseUrl(providerId) {
12483
+ const normalized = providerId.toLowerCase();
12484
+ return normalized === "minimax" || normalized.startsWith("minimax-") ? MINIMAX_OPENAI_BASE_URL : "";
12485
+ }
12486
+ function openAIResponsesBaseUrlMatchesExisting(provider, externalProvider) {
12487
+ const existingUrl = provider.openaiResponsesBaseUrl ?? "";
12488
+ if (existingUrl === externalProvider.openaiResponsesBaseUrl) return true;
12489
+ const defaultUrl = defaultOpenAIResponsesBaseUrl(externalProvider.name);
12490
+ if (defaultUrl === "") return false;
12491
+ return existingUrl === "" && externalProvider.openaiResponsesBaseUrl === defaultUrl || existingUrl === defaultUrl && externalProvider.openaiResponsesBaseUrl === "";
12492
+ }
11997
12493
  function readJsonSafe(filePath) {
11998
12494
  try {
11999
12495
  if (!existsSync(filePath)) return null;
@@ -12088,6 +12584,7 @@ function detectClaudeCodeProviders() {
12088
12584
  format: "anthropic",
12089
12585
  anthropicBaseUrl: baseUrl,
12090
12586
  openaiBaseUrl: "",
12587
+ openaiResponsesBaseUrl: "",
12091
12588
  models,
12092
12589
  sourceTool: "claude-code",
12093
12590
  alreadyExists: false
@@ -12146,6 +12643,7 @@ function detectOpenCodeProviders() {
12146
12643
  format,
12147
12644
  anthropicBaseUrl: format === "anthropic" ? baseURL : "",
12148
12645
  openaiBaseUrl: format === "openai" ? baseURL : "",
12646
+ openaiResponsesBaseUrl: defaultOpenAIResponsesBaseUrl(providerId),
12149
12647
  models,
12150
12648
  sourceTool: "opencode",
12151
12649
  alreadyExists: false
@@ -12259,6 +12757,7 @@ function detectMiMoCodeProviders() {
12259
12757
  format,
12260
12758
  anthropicBaseUrl: format === "anthropic" ? baseURL : "",
12261
12759
  openaiBaseUrl: format === "openai" ? baseURL : "",
12760
+ openaiResponsesBaseUrl: defaultOpenAIResponsesBaseUrl(providerId),
12262
12761
  models,
12263
12762
  sourceTool: "mimo-code",
12264
12763
  alreadyExists: false
@@ -12273,12 +12772,14 @@ function detectMiMoCodeProviders() {
12273
12772
  },
12274
12773
  minimax: {
12275
12774
  anthropicBaseUrl: "https://api.minimaxi.com/anthropic",
12276
- openaiBaseUrl: "https://api.minimaxi.com",
12775
+ openaiBaseUrl: MINIMAX_OPENAI_BASE_URL,
12776
+ openaiResponsesBaseUrl: MINIMAX_OPENAI_BASE_URL,
12277
12777
  format: "anthropic"
12278
12778
  },
12279
12779
  "minimax-coding-plan": {
12280
12780
  anthropicBaseUrl: "https://api.minimaxi.com/anthropic",
12281
- openaiBaseUrl: "https://api.minimaxi.com",
12781
+ openaiBaseUrl: MINIMAX_OPENAI_BASE_URL,
12782
+ openaiResponsesBaseUrl: MINIMAX_OPENAI_BASE_URL,
12282
12783
  format: "anthropic"
12283
12784
  },
12284
12785
  openai: {
@@ -12368,6 +12869,7 @@ function detectMiMoCodeProviders() {
12368
12869
  format: defaults.format,
12369
12870
  anthropicBaseUrl: defaults.anthropicBaseUrl,
12370
12871
  openaiBaseUrl: defaults.openaiBaseUrl,
12872
+ openaiResponsesBaseUrl: defaults.openaiResponsesBaseUrl ?? defaultOpenAIResponsesBaseUrl(key),
12371
12873
  models: ["default"],
12372
12874
  sourceTool: "mimo-code",
12373
12875
  alreadyExists: false
@@ -12398,7 +12900,7 @@ function scanExternalProviders() {
12398
12900
  }
12399
12901
  const allProviders = [...claudeProviders, ...opencodeProviders, ...mimoProviders];
12400
12902
  const filteredProviders = allProviders.filter((p) => {
12401
- const url = p.anthropicBaseUrl || p.openaiBaseUrl;
12903
+ const url = p.anthropicBaseUrl || p.openaiBaseUrl || p.openaiResponsesBaseUrl;
12402
12904
  return !/(?:localhost|127\.0\.0\.1)/.test(url);
12403
12905
  });
12404
12906
  let existing = [];
@@ -12412,7 +12914,7 @@ function scanExternalProviders() {
12412
12914
  if (ext.format === "anthropic") {
12413
12915
  return (p.anthropicBaseUrl ?? "") === ext.anthropicBaseUrl;
12414
12916
  }
12415
- return (p.openaiBaseUrl ?? "") === ext.openaiBaseUrl;
12917
+ return (p.openaiBaseUrl ?? "") === ext.openaiBaseUrl && openAIResponsesBaseUrlMatchesExisting(p, ext);
12416
12918
  });
12417
12919
  }
12418
12920
  return { providers: filteredProviders, warnings };
@@ -12499,6 +13001,7 @@ const ProviderUpdateSchema = object({
12499
13001
  authHeader: _enum(["bearer", "x-api-key"]).optional(),
12500
13002
  anthropicBaseUrl: string().optional(),
12501
13003
  openaiBaseUrl: string().optional(),
13004
+ openaiResponsesBaseUrl: string().optional(),
12502
13005
  apiDocsUrl: string().optional(),
12503
13006
  modelMetadataUrl: string().optional(),
12504
13007
  modelMetadata: array(ProviderModelMetadataSchema).optional(),
@@ -15817,8 +16320,10 @@ const router = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
15817
16320
  }, Symbol.toStringTag, { value: "Module" }));
15818
16321
  export {
15819
16322
  AnthropicResponseSchema$1 as A,
16323
+ isPlainRecord as B,
15820
16324
  CapturedLogSchema as C,
15821
16325
  DEFAULT_CAPTURE_MODE as D,
16326
+ router as E,
15822
16327
  GroupEvidenceReadResponseSchema as G,
15823
16328
  InspectorGroupsListResponseSchema as I,
15824
16329
  KnowledgeCandidateSchema as K,
@@ -15834,23 +16339,24 @@ export {
15834
16339
  RuntimeConfigSchema as d,
15835
16340
  AnthropicRequestSchema as e,
15836
16341
  parseOpenAIResponse as f,
15837
- apiFormatForPath as g,
15838
- getSessionPath as h,
15839
- stripClaudeCodeBillingHeader as i,
15840
- AlertSummarySchema as j,
15841
- AlertListResponseSchema as k,
15842
- GroupEvidenceExportResultSchema as l,
15843
- DeleteInspectorGroupResponseSchema as m,
15844
- providerHasContextMetadata as n,
15845
- findProviderModelMetadata as o,
16342
+ parseOpenAIResponsesResponse as g,
16343
+ OpenAIResponsesRequestSchema as h,
16344
+ apiFormatForPath as i,
16345
+ getSessionPath as j,
16346
+ stripClaudeCodeBillingHeader as k,
16347
+ AlertSummarySchema as l,
16348
+ AlertListResponseSchema as m,
16349
+ GroupEvidenceExportResultSchema as n,
16350
+ DeleteInspectorGroupResponseSchema as o,
15846
16351
  packageJson as p,
15847
- maskApiKey as q,
15848
- createPendingProviderTestResults as r,
16352
+ providerHasContextMetadata as q,
16353
+ findProviderModelMetadata as r,
15849
16354
  safeGetOwnProperty as s,
15850
- ProviderTestResultsSchema as t,
15851
- createFailedProviderTestResults as u,
15852
- MAX_PROVIDER_TEST_TIMEOUT_SECONDS as v,
15853
- resolveProviderContextWindow as w,
15854
- isPlainRecord as x,
15855
- router as y
16355
+ maskApiKey as t,
16356
+ buildUpstreamUrl as u,
16357
+ createPendingProviderTestResults as v,
16358
+ ProviderTestResultsSchema as w,
16359
+ createFailedProviderTestResults as x,
16360
+ MAX_PROVIDER_TEST_TIMEOUT_SECONDS as y,
16361
+ resolveProviderContextWindow as z
15856
16362
  };