anygate 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -165,7 +165,7 @@ import {
165
165
  validateCustomEndpointUrl,
166
166
  writeSecureLogLine,
167
167
  zenRegistryStub
168
- } from "./chunk-2N334BEP.js";
168
+ } from "./chunk-6GVUN4JO.js";
169
169
  import {
170
170
  filterTemplates,
171
171
  getTemplateById,
@@ -1931,6 +1931,31 @@ function makeReasoningOutputItem(id, text4) {
1931
1931
  summary: text4.trim() ? [{ type: "summary_text", text: text4 }] : []
1932
1932
  };
1933
1933
  }
1934
+ function splitBackFunctionCall(item, namespaceMap, customNames) {
1935
+ const ns = namespaceMap?.get(item.name);
1936
+ if (ns) {
1937
+ return {
1938
+ type: "function_call",
1939
+ namespace: ns.namespace,
1940
+ name: ns.name,
1941
+ call_id: item.call_id,
1942
+ arguments: item.arguments,
1943
+ ...item.id ? { id: item.id } : {},
1944
+ ...item.status ? { status: item.status } : {}
1945
+ };
1946
+ }
1947
+ if (customNames?.has(item.name)) {
1948
+ return {
1949
+ type: "custom_tool_call",
1950
+ call_id: item.call_id,
1951
+ name: item.name,
1952
+ input: item.arguments,
1953
+ ...item.id ? { id: item.id } : {},
1954
+ ...item.status ? { status: item.status } : {}
1955
+ };
1956
+ }
1957
+ return item;
1958
+ }
1934
1959
  function translateResponsesInput(input, instructions, npm) {
1935
1960
  if (typeof input === "string") {
1936
1961
  return {
@@ -1942,6 +1967,9 @@ function translateResponsesInput(input, instructions, npm) {
1942
1967
  const toolNames = annotateToolNamesFromCalls(remaining);
1943
1968
  const messages = [];
1944
1969
  let pendingReasoning = "";
1970
+ const namespaceMap = /* @__PURE__ */ new Map();
1971
+ const customToolNames = /* @__PURE__ */ new Set();
1972
+ ingestNamespacesFromSearchOutput(remaining, namespaceMap, customToolNames);
1945
1973
  for (const item of remaining) {
1946
1974
  if (item.type === "reasoning") {
1947
1975
  pendingReasoning += reasoningSummaryText(item);
@@ -1984,9 +2012,70 @@ function translateResponsesInput(input, instructions, npm) {
1984
2012
  }
1985
2013
  return {
1986
2014
  system,
1987
- messages: ensureUserFirst(mergeConsecutiveMessages(messages))
2015
+ messages: ensureUserFirst(mergeConsecutiveMessages(messages)),
2016
+ namespaceMap,
2017
+ customToolNames
1988
2018
  };
1989
2019
  }
2020
+ var TOOL_SEARCH_FLAT = {
2021
+ type: "function",
2022
+ name: "tool_search",
2023
+ description: "Search the available deferred Codex tools, plugin tools, MCP namespaces, and connectors by query. Use this when a needed tool is not already present in the current tool list. Returns matching tool definitions for a follow-up call.",
2024
+ parameters: {
2025
+ type: "object",
2026
+ properties: {
2027
+ query: { type: "string", description: "Search query describing the tool or capability needed." },
2028
+ limit: { type: "number", description: "Maximum number of matching tools to return. Defaults to 8." }
2029
+ },
2030
+ required: ["query"],
2031
+ additionalProperties: false
2032
+ }
2033
+ };
2034
+ function buildNamespaceMap(tools, options = {}) {
2035
+ const map = /* @__PURE__ */ new Map();
2036
+ const customNames = /* @__PURE__ */ new Set();
2037
+ if (!tools?.length) return { map, customNames };
2038
+ for (const t of tools) {
2039
+ if (t.type === "namespace" && t.name && Array.isArray(t.tools)) {
2040
+ for (const nested of t.tools) {
2041
+ if (nested.type !== "function" || !nested.name) continue;
2042
+ map.set(`${t.name}__${nested.name}`, {
2043
+ namespace: t.name,
2044
+ name: nested.name,
2045
+ parameters: nested.parameters
2046
+ });
2047
+ }
2048
+ } else if (t.type === "custom" && t.name) {
2049
+ customNames.add(t.name);
2050
+ }
2051
+ }
2052
+ return { map, customNames };
2053
+ }
2054
+ function ingestNamespacesFromSearchOutput(items, map, customNames) {
2055
+ for (const item of items) {
2056
+ if (item.type !== "tool_search_output") continue;
2057
+ const search = item;
2058
+ const tools = search.tools;
2059
+ if (!Array.isArray(tools)) continue;
2060
+ for (const ns of tools) {
2061
+ if (!ns || typeof ns !== "object") continue;
2062
+ if (ns.type === "namespace" && ns.name && Array.isArray(ns.tools)) {
2063
+ for (const sub of ns.tools) {
2064
+ if (sub && sub.name) {
2065
+ map.set(`${ns.name}__${sub.name}`, {
2066
+ namespace: ns.name,
2067
+ name: sub.name,
2068
+ parameters: sub.parameters
2069
+ });
2070
+ }
2071
+ }
2072
+ } else if (ns.type === "function" && ns.name) {
2073
+ } else if (ns.type === "custom" && ns.name) {
2074
+ customNames.add(ns.name);
2075
+ }
2076
+ }
2077
+ }
2078
+ }
1990
2079
  function translateResponsesTools(tools, options = {}) {
1991
2080
  if (!tools?.length) return void 0;
1992
2081
  const out = {};
@@ -2007,6 +2096,21 @@ function translateResponsesTools(tools, options = {}) {
2007
2096
  }
2008
2097
  continue;
2009
2098
  }
2099
+ if (t.type === "tool_search") {
2100
+ addTool("tool_search", TOOL_SEARCH_FLAT);
2101
+ continue;
2102
+ }
2103
+ if (t.type === "additional_tools") {
2104
+ for (const nested of t.tools ?? []) {
2105
+ if (nested.type !== "function" || !nested.name) continue;
2106
+ addTool(nested.name, nested);
2107
+ }
2108
+ continue;
2109
+ }
2110
+ if (t.type === "custom") {
2111
+ addTool(t.name, { type: "function", name: t.name, description: t.description ?? "", parameters: { type: "object", properties: {} } });
2112
+ continue;
2113
+ }
2010
2114
  if (t.type !== "function" || !t.name) continue;
2011
2115
  addTool(t.name, t);
2012
2116
  }
@@ -2020,13 +2124,25 @@ function translateResponsesRequest(body, npm, metadata, options = {}) {
2020
2124
  effortProviderOptions(npm, effort, metadata?.upstreamModelId ?? body.model, metadata)
2021
2125
  );
2022
2126
  const tools = translateResponsesTools(body.tools, options);
2127
+ const reqMap = buildNamespaceMap(body.tools);
2128
+ const inputResult = translateResponsesInput(body.input, body.instructions, npm);
2129
+ const namespaceMap = new Map([
2130
+ ...reqMap.map.entries(),
2131
+ ...(inputResult.namespaceMap ?? /* @__PURE__ */ new Map()).entries()
2132
+ ]);
2133
+ const customToolNames = /* @__PURE__ */ new Set([
2134
+ ...reqMap.customNames,
2135
+ ...inputResult.customToolNames ?? /* @__PURE__ */ new Set()
2136
+ ]);
2023
2137
  return {
2024
- system,
2025
- messages,
2138
+ system: inputResult.system,
2139
+ messages: inputResult.messages,
2026
2140
  tools,
2027
2141
  maxOutputTokens: body.max_output_tokens,
2028
2142
  temperature: body.temperature,
2029
- providerOptions
2143
+ providerOptions,
2144
+ namespaceMap,
2145
+ customToolNames
2030
2146
  };
2031
2147
  }
2032
2148
  function newResponseId() {
@@ -2083,6 +2199,9 @@ async function writeResponsesStream(fullStream, modelId, write, onDone, onProgre
2083
2199
  let reasoningRepeat = INITIAL_REPEAT_TRACKER;
2084
2200
  let textRepeat = INITIAL_REPEAT_TRACKER;
2085
2201
  let loopDetected;
2202
+ const namespaceMap = options?.namespaceMap;
2203
+ const customToolNames = options?.customToolNames;
2204
+ const isCompaction = options?.isCompaction ?? false;
2086
2205
  const ensureTextItem = () => {
2087
2206
  if (!textItemId) {
2088
2207
  textItemId = newItemId("msg");
@@ -2354,8 +2473,9 @@ async function writeResponsesStream(fullStream, modelId, write, onDone, onProgre
2354
2473
  arguments: args
2355
2474
  });
2356
2475
  const fcItem = { type: "function_call", id: itemId, call_id: callId, name: call.name, arguments: args, status: "completed" };
2357
- emit("response.output_item.done", { type: "response.output_item.done", output_index: idx, item: fcItem });
2358
- outputItems.push(fcItem);
2476
+ const fcSplit = splitBackFunctionCall(fcItem, namespaceMap, customToolNames);
2477
+ emit("response.output_item.done", { type: "response.output_item.done", output_index: idx, item: fcSplit });
2478
+ outputItems.push(fcSplit);
2359
2479
  }
2360
2480
  } else if (textItemId) {
2361
2481
  emit("response.output_text.done", {
@@ -2420,6 +2540,11 @@ async function writeResponsesStream(fullStream, modelId, write, onDone, onProgre
2420
2540
  if (outputItems.length === 0) {
2421
2541
  outputItems.push({ id: newItemId("msg"), type: "message", role: "assistant", status: "completed", content: [{ type: "output_text", text: "(conversation context was too large to summarize)" }] });
2422
2542
  }
2543
+ let finalOutput = outputItems;
2544
+ if (isCompaction) {
2545
+ const summaryText = (textFull ?? "").trim() || (reasoningText ?? "").trim() || "(conversation context was too large to summarize)";
2546
+ finalOutput = [{ type: "compaction", summary: summaryText }];
2547
+ }
2423
2548
  onDone?.({
2424
2549
  reasoningChars: reasoningText.length,
2425
2550
  reasoningPreview: reasoningText.slice(0, 200),
@@ -2437,7 +2562,7 @@ async function writeResponsesStream(fullStream, modelId, write, onDone, onProgre
2437
2562
  model: modelId,
2438
2563
  created_at: createdAt,
2439
2564
  status: "completed",
2440
- output: outputItems,
2565
+ output: finalOutput,
2441
2566
  usage
2442
2567
  }
2443
2568
  });
@@ -2479,17 +2604,51 @@ async function streamResponsesResponse(model, params, modelId, write, onDone, on
2479
2604
  }
2480
2605
  })();
2481
2606
  await writeResponsesStream(watchedStream, modelId, write, onDone, onProgress, {
2482
- onForceStop: (reason) => abort.abort(new Error(reason))
2607
+ onForceStop: (reason) => abort.abort(new Error(reason)),
2608
+ namespaceMap: params.namespaceMap,
2609
+ customToolNames: params.customToolNames,
2610
+ isCompaction: params.isCompaction
2483
2611
  });
2484
2612
  }
2485
2613
  async function generateResponsesResponse(model, params, modelId) {
2614
+ const output = [];
2486
2615
  const r = await generateText({ model, ...params });
2487
2616
  const createdAt = Math.floor(Date.now() / 1e3);
2488
2617
  const responseId = newResponseId();
2489
- const output = [];
2618
+ if (params.isCompaction) {
2619
+ const summaryText = (r.text ?? "").trim() || (r.reasoningText ?? "").trim() || "(conversation context was too large to summarize)";
2620
+ return {
2621
+ id: responseId,
2622
+ object: "response",
2623
+ model: modelId,
2624
+ created_at: createdAt,
2625
+ status: "completed",
2626
+ output: [{ type: "compaction", summary: summaryText }],
2627
+ usage: {
2628
+ input_tokens: r.usage?.inputTokens ?? 0,
2629
+ output_tokens: r.usage?.outputTokens ?? 0,
2630
+ total_tokens: (r.usage?.inputTokens ?? 0) + (r.usage?.outputTokens ?? 0)
2631
+ }
2632
+ };
2633
+ }
2490
2634
  if (r.reasoningText?.trim()) {
2491
2635
  output.push(makeReasoningOutputItem(newItemId("rs"), r.reasoningText));
2492
2636
  }
2637
+ for (const tc of r.toolCalls ?? []) {
2638
+ const callId = tc.toolCallId ?? newItemId("fc");
2639
+ const argsRaw = tc.args;
2640
+ const sig = grabRoundTripSignature(tc);
2641
+ if (sig) encodeToolUseId(callId, sig, false);
2642
+ const fcItem = {
2643
+ type: "function_call",
2644
+ id: callId,
2645
+ call_id: callId,
2646
+ name: tc.toolName,
2647
+ arguments: typeof argsRaw === "string" ? argsRaw : JSON.stringify(argsRaw ?? {}),
2648
+ status: "completed"
2649
+ };
2650
+ output.push(splitBackFunctionCall(fcItem, params.namespaceMap, params.customToolNames));
2651
+ }
2493
2652
  if (r.text !== null && r.text !== void 0) {
2494
2653
  output.push({
2495
2654
  id: newItemId("msg"),
@@ -2499,17 +2658,6 @@ async function generateResponsesResponse(model, params, modelId) {
2499
2658
  content: [{ type: "output_text", text: r.text }]
2500
2659
  });
2501
2660
  }
2502
- for (const tc of r.toolCalls) {
2503
- const encodedId = encodeToolUseId(tc.toolCallId, grabRoundTripSignature(tc), false);
2504
- output.push({
2505
- type: "function_call",
2506
- id: tc.toolCallId,
2507
- call_id: encodedId,
2508
- name: tc.toolName,
2509
- arguments: JSON.stringify(tc.input ?? {}),
2510
- status: "completed"
2511
- });
2512
- }
2513
2661
  if (output.length === 0) {
2514
2662
  output.push({ id: newItemId("msg"), type: "message", role: "assistant", status: "completed", content: [{ type: "output_text", text: "(conversation context was too large to summarize)" }] });
2515
2663
  }
@@ -2942,6 +3090,7 @@ async function startCodexProxy(routes, options = {}) {
2942
3090
  const compaction = isLikelyCodexCompactionRequest(body);
2943
3091
  if (debug) log14(`context check: model=${route.modelId} window=${route.contextWindow} chars=${estimatedChars} compaction=${compaction ? "yes" : "no"} messages=${before}`);
2944
3092
  params = protectCodexCompactionParams(body, params, route.contextWindow);
3093
+ params.isCompaction = compaction;
2945
3094
  if (debug && params.messages.length < before) {
2946
3095
  log14(`context trim: model=${route.modelId} window=${route.contextWindow} kept=${params.messages.length}/${before} messages`);
2947
3096
  }
@@ -3168,6 +3317,7 @@ data: ${JSON.stringify({ error: { message: `Unknown model: ${modelId}` } })}
3168
3317
  const compaction = isLikelyCodexCompactionRequest(body);
3169
3318
  if (debug) log14(`WS context check: model=${route.modelId} window=${route.contextWindow} chars=${estimatedChars} compaction=${compaction ? "yes" : "no"} messages=${before} tools=${params.tools ? Object.keys(params.tools).length : 0}`);
3170
3319
  params = protectCodexCompactionParams(body, params, route.contextWindow);
3320
+ params.isCompaction = compaction;
3171
3321
  if (debug && params.messages.length < before) {
3172
3322
  log14(`WS context trim: model=${route.modelId} window=${route.contextWindow} kept=${params.messages.length}/${before} messages tools=${params.tools ? Object.keys(params.tools).length : 0}`);
3173
3323
  }
@@ -12265,12 +12415,14 @@ async function main(args = process.argv.slice(2)) {
12265
12415
  const parsed = parseArgs(args);
12266
12416
  if (process.stdout.isTTY) {
12267
12417
  printAsciiBanner();
12268
- const update = await checkForUpdates();
12269
- if (update.updateAvailable && update.latestVersion) {
12270
- console.log(`
12418
+ }
12419
+ const update = await checkForUpdates();
12420
+ if (update.updateAvailable && update.latestVersion) {
12421
+ const notice = `
12271
12422
  ${formatUpdateNotification(update.currentVersion, update.latestVersion)}
12272
- `);
12273
- }
12423
+ `;
12424
+ if (process.stdout.isTTY) console.log(notice);
12425
+ else console.error(notice);
12274
12426
  }
12275
12427
  if (parsed.error) {
12276
12428
  console.error(pc12.red(`
@@ -12326,7 +12478,7 @@ Error: ${parsed.error}
12326
12478
  console.log("Usage: anygate ui [--trace]\n\nOpen the settings UI in your browser.");
12327
12479
  return 0;
12328
12480
  }
12329
- const { runUiCommand } = await import("./command-SVWF7UJ6.js");
12481
+ const { runUiCommand } = await import("./command-OQI56XYG.js");
12330
12482
  return runUiCommand({ trace: parsed.trace });
12331
12483
  }
12332
12484
  if (parsed.command === "models") {