@swifty.js/swifty 0.0.35 → 0.0.37

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 (34) hide show
  1. package/README.md +8 -8
  2. package/dist/{acp-A4KRKOHD.js → acp-R22FJPVN.js} +1 -1
  3. package/dist/{agent-VDWIGFIV.js → agent-WOWGQDBG.js} +1 -1
  4. package/dist/anthropic-3DXT42SN.js +4 -0
  5. package/dist/{chunk-4B4SGVJH.js → chunk-ENZ5LHRN.js} +23 -23
  6. package/dist/chunk-FOPUR6OB.js +610 -0
  7. package/dist/{chunk-IOLGXPUQ.js → chunk-LW273HD5.js} +1 -1
  8. package/dist/{chunk-TNF3EHFY.js → chunk-QBGGDF62.js} +1 -1
  9. package/dist/{chunk-TOM34LJB.js → chunk-R62BGTT4.js} +17 -17
  10. package/dist/chunk-S2VEXEVV.js +4 -0
  11. package/dist/{chunk-H56UQALW.js → chunk-VN7HK3YD.js} +1 -1
  12. package/dist/lib/{agent-TC4HSVMS.js → agent-ZSFK66FQ.js} +2 -2
  13. package/dist/lib/{anthropic-FKIGL7NL.js → anthropic-GD3ILYG6.js} +1 -1
  14. package/dist/lib/{chunk-S5VWPTME.js → chunk-5OJV33Y2.js} +37 -14
  15. package/dist/lib/{chunk-RUDYC7OS.js → chunk-BHSNJT6Z.js} +1 -1
  16. package/dist/lib/{chunk-LRN4MOQ3.js → chunk-GWZDEU27.js} +0 -5
  17. package/dist/lib/{chunk-ALQHMYOZ.js → chunk-LKFJIK6F.js} +0 -3
  18. package/dist/lib/{chunk-OJTISIYU.js → chunk-O35GIE35.js} +1 -1
  19. package/dist/lib/{chunk-6V7RW6HA.js → chunk-TD7Z6L4D.js} +10 -13
  20. package/dist/lib/index.d.ts +689 -563
  21. package/dist/lib/index.js +1153 -729
  22. package/dist/lib/{openai-ZWIYIBLC.js → openai-N6X7XUQJ.js} +1 -1
  23. package/dist/lib/{permissions-BW4QPZXV.js → permissions-77UJQITR.js} +1 -1
  24. package/dist/lib/{providers-ROWSB6ND.js → providers-WQ3UOLMF.js} +1 -1
  25. package/dist/lib/{tool-filter-QU4LOZII.js → tool-filter-S3ZZOXFD.js} +1 -1
  26. package/dist/main.js +154 -153
  27. package/dist/{openai-7LMX5HKW.js → openai-XMJVVTTX.js} +1 -1
  28. package/dist/{providers-2J4JJYQD.js → providers-NWLGMQOZ.js} +1 -1
  29. package/dist/{server-ZYK4L22D.js → server-TINTK5DM.js} +1 -1
  30. package/dist/{tool-filter-U5SSL3LR.js → tool-filter-QETBQPHL.js} +1 -1
  31. package/package.json +2 -2
  32. package/dist/anthropic-AR2Y4FBR.js +0 -4
  33. package/dist/chunk-F4FOFPKL.js +0 -611
  34. package/dist/chunk-UJGMTIYO.js +0 -4
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __swiftyCreateRequire } from "node:module";
3
+ const require = __swiftyCreateRequire(import.meta.url);
4
+ var d=class{tools=new Map;discovered=new Set;mcpLoadingMode="eager";exposeToolSearch=!1;exposeMcpCall=!1;register(e){this.tools.set(e.name,e)}unregister(e){this.tools.delete(e),this.discovered.delete(e)}get(e){return this.tools.get(e)}listTools(){return[...this.tools.values()]}getAllSchemas(e,o){let t=e??"anthropic",i=t==="openai"||t==="openai-compat",n=this.mcpLoadingMode==="native"&&!i,r=[];for(let a of this.tools.values()){if(o&&!o(a.name)||a.name==="ToolSearch"&&!this.exposeToolSearch||a.name==="McpCall"&&!this.exposeMcpCall)continue;let p=!!a.deferred&&!this.discovered.has(a.name);if(p&&!n)continue;let s=a.schema();t==="openai"?r.push({strict:s.strict??!1,type:"function",name:s.name,description:s.description,parameters:s.input_schema}):t==="openai-compat"?r.push({type:"function",function:{name:s.name,description:s.description,parameters:s.input_schema,strict:s.strict??!1}}):r.push({...s,type:"custom",...p?{defer_loading:!0}:{}})}return r}getDeferredToolNames(){let e=[];for(let o of this.tools.values())o.deferred&&!this.discovered.has(o.name)&&e.push(o.name);return e.sort()}getDeferredTools(){return[...this.tools.values()].filter(e=>e.deferred&&!this.discovered.has(e.name))}searchDeferred(e,o=5){let t=e.toLowerCase(),i=[];for(let n of this.tools.values())if(!(!n.deferred||this.discovered.has(n.name))&&(n.name.toLowerCase().includes(t)||n.description.toLowerCase().includes(t))&&(i.push(n),i.length>=o))break;return i}findDeferredByNames(e){let o=new Map;for(let[t,i]of this.tools)o.set(t.toLowerCase(),i);return e.map(t=>o.get(t.toLowerCase())).filter(t=>t?.deferred??!1)}markDiscovered(e){this.discovered.add(e)}isDiscovered(e){return this.discovered.has(e)}};var h=new Set(["ComputerUse","AskUserQuestion","ExitPlanMode"]),m=new Set([...h,"Agent","TaskStop"]),L=new Set(["TeamCreate","TeamDelete"]),T=new Set(["ExitPlanMode","Agent","AskUserQuestion","TaskStop"]),f=new Set(["ReadFile","Grep","Glob","Bash","JavaScript","PowerShell","EditFile","WriteFile","LoadSkill","SyntheticOutput","ToolSearch","EnterWorktree","ExitWorktree","McpCall"]);function g(l){return l.startsWith("mcp__")}function O(l,e,o,t,i=!1){let n=new Set(o??[]),r=new Set(e??[]),a=r.size>0&&!(r.size===1&&r.has("*")),p=new d;p.mcpLoadingMode=l.mcpLoadingMode;for(let s of l.listTools()){let c=s.name;if(g(c)){!n.has(c)&&(!a||r.has(c))&&p.register(s);continue}m.has(c)||i&&T.has(c)||t&&!f.has(c)||n.has(c)||a&&!r.has(c)||p.register(s)}return p}var S="agent:builtin:fork";function v(l){let e=new d;e.mcpLoadingMode=l.mcpLoadingMode;for(let o of l.listTools())if(!h.has(o.name))if(o.name==="Agent"&&"querySource"in o){let t=Object.create(Object.getPrototypeOf(o),Object.getOwnPropertyDescriptors(o));t.querySource=S,e.register(t)}else e.register(o);return e}export{d as a,h as b,m as c,L as d,T as e,f,O as g,S as h,v as i};
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __swiftyCreateRequire } from "node:module";
3
3
  const require = __swiftyCreateRequire(import.meta.url);
4
- import{a as i,d as s}from"./chunk-325L2ILZ.js";var a=10,p=2.5,E="advanced-tool-use-2025-11-20",f=new Set(["api.anthropic.com"]),d="SWIFTY_MCP_LOADING";function u(o){if(!o)return!0;try{return f.has(new URL(o).hostname.toLowerCase())}catch{return!1}}function l(o){return Math.floor(o/p)}function m(o,t,e,n=a){let r=(process.env[d]??"").trim().toLowerCase();if(r==="eager"||r==="native"||r==="dispatch")return r;if(e<=0)return"eager";let c=t*n/100;return l(e)<c?"eager":u(o)?"native":"dispatch"}function g(o){let t=0;for(let e of o.listTools())if(e.name.startsWith(i))try{t+=JSON.stringify(e.schema()).length}catch{t+=e.name.length+(e.description?.length??0)}return t}function T(o,t){o.mcpLoadingMode=t;let e=t==="eager";for(let n of o.listTools())s(n)&&typeof n.setDeferLoading=="function"&&n.setDeferLoading(!e);o.exposeToolSearch=!e,o.exposeMcpCall=t==="dispatch"}function M(o,t,e){let n=m(t,e,g(o));return T(o,n),n}export{E as a,T as b,M as c};
4
+ import{a as i,d as s}from"./chunk-325L2ILZ.js";var a=10,p=2.5,E="advanced-tool-use-2025-11-20",f=new Set(["api.anthropic.com"]),d="SWIFTY_MCP_LOADING";function u(o){if(!o)return!0;try{return f.has(new URL(o).hostname.toLowerCase())}catch{return!1}}function l(o){return Math.floor(o/p)}function m(o,t,e,n=a){let r=(process.env[d]??"").trim().toLowerCase();if(r==="eager"||r==="native"||r==="dispatch")return r;if(e<=0)return"eager";let c=t*n/100;return l(e)<c?"eager":u(o)?"native":"dispatch"}function g(o){let t=0;for(let e of o.listTools())if(e.name.startsWith(i))try{t+=JSON.stringify(e.schema()).length}catch{t+=e.name.length+(e.description?.length??0)}return t}function T(o,t){o.mcpLoadingMode=t;let e=t==="eager";for(let n of o.listTools())s(n)&&typeof n.setDeferLoading=="function"&&n.setDeferLoading(!e);o.exposeToolSearch=!e,o.exposeMcpCall=t==="dispatch"}function M(o,t,e){let n=m(t,e,g(o));return T(o,n),n}export{E as a,u as b,T as c,M as d};
@@ -2,8 +2,8 @@ import {
2
2
  Agent,
3
3
  events_exports,
4
4
  streaming_executor_exports
5
- } from "./chunk-S5VWPTME.js";
6
- import "./chunk-OJTISIYU.js";
5
+ } from "./chunk-5OJV33Y2.js";
6
+ import "./chunk-O35GIE35.js";
7
7
  import "./chunk-BQFVUVLI.js";
8
8
  import "./chunk-HQSYRTER.js";
9
9
  import "./chunk-OLFXCZVH.js";
@@ -5,7 +5,7 @@ import {
5
5
  markLastUserTailForCache,
6
6
  markToolsForCache,
7
7
  needsToolSearchBeta
8
- } from "./chunk-6V7RW6HA.js";
8
+ } from "./chunk-TD7Z6L4D.js";
9
9
  import "./chunk-BQFVUVLI.js";
10
10
  import "./chunk-HQSYRTER.js";
11
11
  import "./chunk-OLFXCZVH.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  providers_exports
3
- } from "./chunk-OJTISIYU.js";
3
+ } from "./chunk-O35GIE35.js";
4
4
  import {
5
5
  normalizeToolResultContentBlock
6
6
  } from "./chunk-BQFVUVLI.js";
@@ -104,7 +104,7 @@ async function initializeTelemetry() {
104
104
  if (!shouldInitialize()) {
105
105
  return;
106
106
  }
107
- initialization = import("./providers-ROWSB6ND.js").then(async ({ createTelemetryRuntime }) => {
107
+ initialization = import("./providers-WQ3UOLMF.js").then(async ({ createTelemetryRuntime }) => {
108
108
  runtime = await createTelemetryRuntime();
109
109
  runtime.setMode(mode);
110
110
  process.once("beforeExit", () => {
@@ -995,7 +995,7 @@ async function compressWithSharp(buf, mediaType2) {
995
995
  }
996
996
 
997
997
  // src/conversation/at-expand.ts
998
- var log4 = createChildLogger({ module: "tui" });
998
+ var log4 = createChildLogger({ module: "terminal" });
999
999
  var MAX_INLINE_BYTES = 1e5;
1000
1000
  var MAX_RANGE_FILE_BYTES = 1e7;
1001
1001
  function parseRef(ref) {
@@ -1060,7 +1060,7 @@ ${readFileSync3(p, "utf-8")}
1060
1060
  </file>`;
1061
1061
  }
1062
1062
  } catch (err) {
1063
- log4.error({ err }, "TUI operation failed");
1063
+ log4.error({ err }, "UI operation failed");
1064
1064
  }
1065
1065
  }
1066
1066
  return appendix ? text + appendix : text;
@@ -1106,7 +1106,7 @@ Error: too many images attached (limit ${String(MAX_IMAGES_PER_MESSAGE)} per mes
1106
1106
 
1107
1107
  <image type="base64" media_type="${attachment.mediaType}" path="${refPath}" />`;
1108
1108
  } catch (err) {
1109
- log4.error({ err }, "TUI operation failed");
1109
+ log4.error({ err }, "UI operation failed");
1110
1110
  }
1111
1111
  } else if (lineStart !== void 0 && lineEnd !== void 0) {
1112
1112
  if (st.size <= MAX_RANGE_FILE_BYTES) {
@@ -1127,7 +1127,7 @@ ${readFileSync3(p, "utf-8")}
1127
1127
  </file>`;
1128
1128
  }
1129
1129
  } catch (err) {
1130
- log4.error({ err }, "TUI operation failed");
1130
+ log4.error({ err }, "UI operation failed");
1131
1131
  }
1132
1132
  }
1133
1133
  const expanded = appendix ? text + appendix : text;
@@ -2377,9 +2377,11 @@ var tool_result_exports = {};
2377
2377
  __export(tool_result_exports, {
2378
2378
  TOOL_RESULT_PREVIEW_CHARS: () => TOOL_RESULT_PREVIEW_CHARS,
2379
2379
  applyBudget: () => applyBudget,
2380
+ buildPersistedOutputPreview: () => buildPersistedOutputPreview,
2380
2381
  isSpillReadback: () => isSpillReadback,
2381
2382
  persistLargeResult: () => persistLargeResult,
2382
2383
  replaceToolResultContent: () => replaceToolResultContent,
2384
+ spillDir: () => spillDir,
2383
2385
  toDisplayPreview: () => toDisplayPreview
2384
2386
  });
2385
2387
  import { writeFileSync as writeFileSync4, mkdirSync as mkdirSync4 } from "fs";
@@ -2421,10 +2423,8 @@ function replaceToolResultContent(result, content) {
2421
2423
  ];
2422
2424
  }
2423
2425
  }
2424
- function buildSpillPreview(content, spillPath) {
2425
- const sizeKB = Math.floor(content.length / 1024);
2426
- const preview = content.slice(0, TOOL_RESULT_PREVIEW_CHARS);
2427
- const hasMore = content.length > TOOL_RESULT_PREVIEW_CHARS;
2426
+ function buildPersistedOutputPreview(totalChars, preview, spillPath) {
2427
+ const sizeKB = Math.floor(totalChars / 1024);
2428
2428
  let msg = `<persisted-output>
2429
2429
  `;
2430
2430
  msg += `Output too large (${String(sizeKB)}KB). Full content saved to:
@@ -2433,12 +2433,19 @@ ${spillPath}
2433
2433
  `;
2434
2434
  msg += `Preview (first 2KB):
2435
2435
  ${preview}`;
2436
- if (hasMore) {
2436
+ if (totalChars > TOOL_RESULT_PREVIEW_CHARS) {
2437
2437
  msg += "\n...";
2438
2438
  }
2439
2439
  msg += "\n</persisted-output>";
2440
2440
  return msg;
2441
2441
  }
2442
+ function buildSpillPreview(content, spillPath) {
2443
+ return buildPersistedOutputPreview(
2444
+ content.length,
2445
+ content.slice(0, TOOL_RESULT_PREVIEW_CHARS),
2446
+ spillPath
2447
+ );
2448
+ }
2442
2449
  function isSpillReadback(toolName, args, workDir, sessionId) {
2443
2450
  if (toolName !== "ReadFile" || !args) {
2444
2451
  return false;
@@ -2517,6 +2524,7 @@ var Agent = class {
2517
2524
  recoveryState;
2518
2525
  maxIterations;
2519
2526
  notificationFn;
2527
+ taskManager;
2520
2528
  onLoopComplete;
2521
2529
  compactTracking = new AutoCompactTrackingState();
2522
2530
  onPermissionRequest;
@@ -2550,6 +2558,7 @@ var Agent = class {
2550
2558
  this.recoveryState = config.recoveryState ?? new RecoveryState();
2551
2559
  this.maxIterations = config.maxIterations ?? 0;
2552
2560
  this.notificationFn = config.notificationFn;
2561
+ this.taskManager = config.taskManager;
2553
2562
  this.onLoopComplete = config.onLoopComplete;
2554
2563
  this.onPermissionRequest = config.onPermissionRequest;
2555
2564
  this.activeSkills = config.activeSkills ?? /* @__PURE__ */ new Map();
@@ -2667,7 +2676,11 @@ ${body}`)
2667
2676
  this.abortSignal
2668
2677
  );
2669
2678
  if (mc.message) {
2670
- yield { type: "compact", message: mc.message, boundary: mc.boundary };
2679
+ yield {
2680
+ type: "compact",
2681
+ message: mc.message,
2682
+ boundary: mc.boundary
2683
+ };
2671
2684
  }
2672
2685
  if (mc.compacted) {
2673
2686
  this.restoreContext();
@@ -2821,7 +2834,11 @@ ${body}`)
2821
2834
  "Output token limit hit. Resume directly from where you stopped. Do not apologize or repeat previous content. Pick up mid-thought if needed."
2822
2835
  );
2823
2836
  }
2824
- yield { type: "retry", reason: "max_tokens escalation", delay: 0 };
2837
+ yield {
2838
+ type: "retry",
2839
+ reason: "max_tokens escalation",
2840
+ delay: 0
2841
+ };
2825
2842
  continue;
2826
2843
  } else if (outputRecoveries < MAX_TOKENS_RECOVERIES) {
2827
2844
  outputRecoveries++;
@@ -3021,6 +3038,8 @@ ${body}`)
3021
3038
  this.registry,
3022
3039
  {
3023
3040
  workDir: this.workDir,
3041
+ sessionId: this.sessionId,
3042
+ taskManager: this.taskManager,
3024
3043
  abortSignal: this.abortSignal,
3025
3044
  fileHistory: this.fileHistory,
3026
3045
  fileStateCache: this.fileStateCache,
@@ -3206,7 +3225,7 @@ ${body}`)
3206
3225
  * Persist the most recently appended conversation message to the session log.
3207
3226
  *
3208
3227
  * Persistence lives in the main loop rather than in individual frontends: both
3209
- * the TUI and Web share the same recording path, ensuring intermediate assistant
3228
+ * the UI and Web share the same recording path, ensuring intermediate assistant
3210
3229
  * text and complete tool-call chains are captured for session restoration.
3211
3230
  * Skipped when sessionId is empty (one-shot invocations, sub-agents).
3212
3231
  */
@@ -3276,6 +3295,10 @@ export {
3276
3295
  plan_file_exports,
3277
3296
  coordinator_exports,
3278
3297
  plan_mode_exports,
3298
+ TOOL_RESULT_PREVIEW_CHARS,
3299
+ spillDir,
3300
+ buildPersistedOutputPreview,
3301
+ persistLargeResult,
3279
3302
  tool_result_exports,
3280
3303
  events_exports,
3281
3304
  Agent,
@@ -583,7 +583,7 @@ var PermissionChecker = class _PermissionChecker {
583
583
  }
584
584
  /**
585
585
  * Generate a human-readable description of the tool action for display in HITL confirmation dialogs.
586
- * Prioritizes extracting fields defined in contentFields (e.g., command, file_path);
586
+ * Prioritizes extracting fields defined in CONTENT_FIELDS (e.g., command, file_path);
587
587
  * falls back to a key:value summary of parameters if no match is found.
588
588
  */
589
589
  describeToolAction(toolName, args) {
@@ -73,11 +73,6 @@ var ToolRegistry = class {
73
73
  if (deferred && !native) {
74
74
  continue;
75
75
  }
76
- const providerSchema = protocol ? tool.providerSchema?.(resolvedProtocol) : void 0;
77
- if (providerSchema) {
78
- schemas.push(providerSchema);
79
- continue;
80
- }
81
76
  const s = tool.schema();
82
77
  if (resolvedProtocol === "openai") {
83
78
  schemas.push({
@@ -72,9 +72,6 @@ function computerCallArguments(item) {
72
72
  };
73
73
  }
74
74
  function toOpenAIResponsesTool(schema) {
75
- if ("type" in schema && schema.type === "computer") {
76
- return { ...schema };
77
- }
78
75
  if ("input_schema" in schema) {
79
76
  const tool = schema;
80
77
  return {
@@ -47,7 +47,7 @@ var PackageJsonSchema = z.object({
47
47
  });
48
48
  function resolveVersion() {
49
49
  if (true) {
50
- return "0.0.35";
50
+ return "0.0.37";
51
51
  }
52
52
  const here = path.dirname(fileURLToPath(import.meta.url));
53
53
  for (const levels of ["..", "../.."]) {
@@ -138,17 +138,16 @@ function markToolsForCache(tools) {
138
138
  function needsToolSearchBeta(toolSchemas) {
139
139
  return toolSchemas.some((schema) => "defer_loading" in schema && schema.defer_loading === true);
140
140
  }
141
- var COMPUTER_USE_BETA = "computer-use-2025-11-24";
142
- function toAnthropicToolSchema(schema) {
143
- if ("type" in schema && schema.type === "computer_20251124") {
144
- return { ...schema };
145
- }
141
+ function toAnthropicToolSchema(schema, useExplicitCustomType) {
146
142
  if ("input_schema" in schema) {
147
143
  const tool = schema;
148
144
  const { cache_control: cacheControl, ...rest } = tool;
145
+ if (!useExplicitCustomType) {
146
+ delete rest.type;
147
+ }
149
148
  return {
150
149
  ...rest,
151
- type: "custom",
150
+ ...useExplicitCustomType ? { type: "custom" } : {},
152
151
  ...tool.defer_loading !== true && cacheControl ? { cache_control: cacheControl } : {}
153
152
  };
154
153
  }
@@ -304,6 +303,7 @@ var AnthropicClient = class {
304
303
  systemPrompt;
305
304
  maxOutputTokens;
306
305
  config;
306
+ useExplicitCustomToolType;
307
307
  constructor(config, systemPrompt) {
308
308
  const apiKey = resolveAPIKey(config);
309
309
  if (!apiKey) {
@@ -315,6 +315,7 @@ var AnthropicClient = class {
315
315
  apiKey,
316
316
  baseURL: config.base_url
317
317
  });
318
+ this.useExplicitCustomToolType = isOfficialAnthropicEndpoint(config.base_url);
318
319
  this.model = config.model;
319
320
  this.config = { ...config };
320
321
  this.thinkingLevel = getThinkingLevel(config);
@@ -342,9 +343,8 @@ var AnthropicClient = class {
342
343
  async *stream(conversation, toolSchemas, abortSignal) {
343
344
  const messages = buildAnthropicMessages(ensureToolPairing(conversation.getMessages()));
344
345
  const sendToolSearchBeta = needsToolSearchBeta(toolSchemas);
345
- const antToolSchemas = toolSchemas.map(toAnthropicToolSchema);
346
- const sendComputerUseBeta = antToolSchemas.some(
347
- (schema) => "type" in schema && schema.type === "computer_20251124"
346
+ const antToolSchemas = toolSchemas.map(
347
+ (schema) => toAnthropicToolSchema(schema, this.useExplicitCustomToolType)
348
348
  );
349
349
  markToolsForCache(antToolSchemas);
350
350
  markLastUserTailForCache(messages);
@@ -400,10 +400,7 @@ var AnthropicClient = class {
400
400
  let thinkingSignature = "";
401
401
  let inThinking = false;
402
402
  try {
403
- const betas = [
404
- ...sendToolSearchBeta ? [NATIVE_TOOL_USE_BETA] : [],
405
- ...sendComputerUseBeta ? [COMPUTER_USE_BETA] : []
406
- ];
403
+ const betas = [...sendToolSearchBeta ? [NATIVE_TOOL_USE_BETA] : []];
407
404
  const response = this.client.messages.stream(params, {
408
405
  ...abortSignal ? { signal: abortSignal } : {},
409
406
  ...betas.length > 0 ? { headers: { "anthropic-beta": betas.join(",") } } : {}