@swifty.js/swifty 0.0.29 → 0.0.31

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 (48) hide show
  1. package/README.md +25 -11
  2. package/dist/agent-O6C4FCQY.js +4 -0
  3. package/dist/anthropic-CFM2DXMB.js +4 -0
  4. package/dist/checker-A6PGACKZ.js +4 -0
  5. package/dist/chunk-4ABFUBO4.js +601 -0
  6. package/dist/{chunk-K5ZK27BX.js → chunk-AGJYBJ5M.js} +1 -1
  7. package/dist/chunk-AQ3A5CF4.js +5 -0
  8. package/dist/chunk-MVVSONAE.js +4 -0
  9. package/dist/chunk-OQCEP2F5.js +4 -0
  10. package/dist/{chunk-QFSCPD63.js → chunk-TCQ4EB4G.js} +1 -1
  11. package/dist/chunk-Y2UUXOQA.js +4 -0
  12. package/dist/chunk-YAXZ2OUD.js +150 -0
  13. package/dist/lib/agent-YRTROHXU.js +10 -0
  14. package/dist/lib/{anthropic-KWO3KLNV.js → anthropic-R6DMXE7U.js} +4 -5
  15. package/dist/lib/{checker-AXHPKVBY.js → checker-M7RKMKJQ.js} +2 -3
  16. package/dist/lib/{chunk-KZSBR4FO.js → chunk-4MDCRPVV.js} +76 -40
  17. package/dist/lib/{chunk-DJ6AILPN.js → chunk-A4MXZA5Q.js} +209 -51
  18. package/dist/lib/{chunk-2IVEVG5N.js → chunk-EWE5IWZE.js} +28 -25
  19. package/dist/lib/{chunk-KG4MJGKQ.js → chunk-FZ4Y6MBN.js} +1 -4
  20. package/dist/lib/{chunk-GCY44T7S.js → chunk-J6AV7SIF.js} +221 -351
  21. package/dist/lib/{chunk-3FBS5NB7.js → chunk-OEPCNATU.js} +217 -41
  22. package/dist/lib/{chunk-Z4CYHTII.js → chunk-OQIQOU5S.js} +85 -26
  23. package/dist/lib/{chunk-PIL7M52F.js → chunk-XT67KGWE.js} +16 -3
  24. package/dist/lib/index.d.ts +1212 -932
  25. package/dist/lib/index.js +2836 -1611
  26. package/dist/lib/{openai-PBF7EWNJ.js → openai-5N42ZYIJ.js} +2 -2
  27. package/dist/lib/{tool-filter-R6HDDJHE.js → tool-filter-XG2GXFVN.js} +3 -2
  28. package/dist/main.js +197 -189
  29. package/dist/openai-NQYARTT6.js +34 -0
  30. package/dist/{server-G23HCFLI.js → server-BNT2IIKB.js} +18 -18
  31. package/dist/tool-filter-5NDJMSTD.js +4 -0
  32. package/package.json +4 -3
  33. package/dist/agent-YR6YK26C.js +0 -4
  34. package/dist/anthropic-5GRR5JCT.js +0 -4
  35. package/dist/checker-N5TIJEN5.js +0 -4
  36. package/dist/chunk-D34FUVGU.js +0 -4
  37. package/dist/chunk-E55KH72M.js +0 -4
  38. package/dist/chunk-LIMEBKCY.js +0 -408
  39. package/dist/chunk-POHIQUFP.js +0 -301
  40. package/dist/chunk-QCKJLO6X.js +0 -4
  41. package/dist/chunk-TMEX7RFA.js +0 -4
  42. package/dist/chunk-Y6SQB5FG.js +0 -4
  43. package/dist/glob.wasm +0 -0
  44. package/dist/lib/agent-5WEKVRTD.js +0 -11
  45. package/dist/lib/chunk-GHF2PSEW.js +0 -8
  46. package/dist/lib/glob.wasm +0 -0
  47. package/dist/openai-QQ2K7GPF.js +0 -34
  48. package/dist/tool-filter-VBP6WOGO.js +0 -4
package/README.md CHANGED
@@ -29,7 +29,7 @@ Beyond interactive use, Swifty supports a non-interactive print mode for scripti
29
29
 
30
30
  ### Skills and Commands
31
31
 
32
- - Skill catalog with three-tier loading: built-in, user-global (~/.swifty/skills/), and project-level (.swifty/skills/)
32
+ - Skill catalog with three-tier loading: built-in, user-global (~/.agents/skills/), and project-level (.agents/skills/)
33
33
  - Hot-reload support for skills edited on disk
34
34
  - Inline and fork execution modes for skills
35
35
  - Slash command system with built-in commands and user-defined commands from .swifty/commands/
@@ -60,6 +60,20 @@ Beyond interactive use, Swifty supports a non-interactive print mode for scripti
60
60
  npm install -g @swifty.js/swifty
61
61
  ```
62
62
 
63
+ Or use the one-line installers ([macOS / Linux](../../install.sh), [Windows](../../install.ps1)):
64
+
65
+ ```bash
66
+ # macOS / Linux
67
+ curl -fsSL https://raw.githubusercontent.com/hangtiancheng/swifty-code/main/install.sh | bash
68
+ ```
69
+
70
+ ```powershell
71
+ # Windows (PowerShell)
72
+ irm https://raw.githubusercontent.com/hangtiancheng/swifty-code/main/install.ps1 | iex
73
+ ```
74
+
75
+ Both installers write a default `~/.swifty/config.yaml` if none exists, verify Node.js >= 20, and support uninstall / pinned-version / dist-tag options (see their `--help` / `-Help` output).
76
+
63
77
  Or run directly from the monorepo:
64
78
 
65
79
  ```bash
@@ -110,16 +124,16 @@ enable_coordinator_mode: false
110
124
 
111
125
  Provider fields:
112
126
 
113
- | Field | Required | Description |
114
- | ----------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
115
- | name | yes | Display name for the provider |
116
- | protocol | yes | One of: anthropic, openai, openai-compat |
117
- | base_url | yes | API base URL |
118
- | model | yes | Model identifier |
119
- | api_key | no | API key (falls back to environment variable) |
120
- | thinking | no | Thinking level: off, minimal, low, medium, high, xhigh, max. Defaults to `high` for `anthropic` and `off` for `openai`/`openai-compat` (reasoning parameters are only sent when configured). A legacy `true`/`false` is still accepted (`false` → off, `true` → the protocol default). |
121
- | context_window | no | Context window in tokens (default: 1000000; no model-name inference) |
122
- | max_output_tokens | no | Output cap for the model (default: 128000, never above `context_window`). Set this for models with a smaller output limit. |
127
+ | Field | Required | Description |
128
+ | ----------------- | -------- | -------------------------------------------------------------------------------------------------------------------------- |
129
+ | name | yes | Display name for the provider |
130
+ | protocol | yes | One of: anthropic, openai, openai-compat |
131
+ | base_url | yes | API base URL |
132
+ | model | yes | Model identifier |
133
+ | api_key | no | API key (falls back to environment variable) |
134
+ | thinking | no | Thinking level: off, minimal, low, medium, high, xhigh, max (default: `high` for every protocol). |
135
+ | context_window | no | Context window in tokens (default: 1000000; no model-name inference) |
136
+ | max_output_tokens | no | Output cap for the model (default: 128000, never above `context_window`). Set this for models with a smaller output limit. |
123
137
 
124
138
  The thinking level controls reasoning depth. For `anthropic` it maps to a thinking token budget (minimal 1024, low 2048, medium 8192, high 16384, xhigh 32768, max 65536); for `openai` and `openai-compat` it maps to the provider reasoning effort. The budget shares `max_output_tokens` and always leaves at least 1024 answer tokens, so lower `max_output_tokens` shrinks the thinking budget instead of disabling it (below a 2048-token cap no valid budget remains and thinking falls back to disabled). On `openai`/`openai-compat`, the effort string is passed through verbatim, and only levels supported by the model are accepted (`xhigh`/`max` are model-specific). Use `/thinking <level>` to change it at runtime (the change is applied to the active client and saved to `~/.swifty/config.yaml`), or `/thinking` to show the current level.
125
139
 
@@ -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
+ import{s as a}from"./chunk-YAXZ2OUD.js";import"./chunk-TCQ4EB4G.js";import"./chunk-AQ3A5CF4.js";import"./chunk-OQCEP2F5.js";import"./chunk-OTVZGPHD.js";import"./chunk-X3UA5OZL.js";export{a as Agent};
@@ -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
+ import{a as Z}from"./chunk-AGJYBJ5M.js";import{a as Q}from"./chunk-TCQ4EB4G.js";import{g as M}from"./chunk-C3WGLVVZ.js";import{A as V,B as q,D as X,k as B,m as O,n as U,o as j,p as $,q as K,r as F,t as C,u as E,x as D,y as I,z as J}from"./chunk-AQ3A5CF4.js";import"./chunk-OQCEP2F5.js";import{D as w,I as N,J as H,K as z,L as G,M as d,N as W,R as Y,g as R}from"./chunk-OTVZGPHD.js";import"./chunk-X3UA5OZL.js";function oe(o){for(let t=o.length-1;t>=0;t--){let e=o[t];if(e.defer_loading!==!0){e.cache_control={type:"ephemeral"};return}}}function ne(o){return o.some(t=>"defer_loading"in t&&t.defer_loading===!0)}var re="computer-use-2025-11-24";function se(o){if("type"in o&&o.type==="computer_20251124")return{...o};if("input_schema"in o){let t=o,{cache_control:e,...n}=t;return{...n,type:"custom",...t.defer_loading!==!0&&e?{cache_control:e}:{}}}throw new Error("Anthropic received a tool schema serialized for another protocol.")}var T=N({module:"llm"});var ie=3e3,ae=w.object({max_input_tokens:w.coerce.number()});async function Te(o){if(o.protocol!=="anthropic")return 0;let t=E(o),n=`${o.base_url.replace(/\/+$/,"")}/v1/models/${encodeURIComponent(o.model)}`,r=new AbortController,s=setTimeout(()=>{r.abort()},ie);try{let c=await fetch(n,{method:"GET",headers:{"anthropic-version":"2023-06-01",...t?{"x-api-key":t}:{}},signal:r.signal});if(!c.ok)return 0;let v=await c.json(),{success:p,error:u,data:h}=await R(ae,v);if(!p)return T.warn({message:u.message},"model context window schema validation failed"),0;let m=h.max_input_tokens;return Math.max(m,0)}catch(c){return T.error({err:c},"failed to fetch model context window"),0}finally{clearTimeout(s)}}function y(o){return typeof o=="string"?[{type:"text",text:o}]:o.map(t=>{let e=Q(t);if(!e||e.type==="tool_reference")throw new Error(`Unsupported user content block: ${Y(t,"type","unknown")}`);return e})}function le(o){let t=[];for(let e of o)if(e.role==="assistant"){let n=[];if(e.thinkingBlocks)for(let s of e.thinkingBlocks)n.push({type:"thinking",thinking:s.thinking,signature:s.signature});let r=typeof e.content=="string"?e.content:H(e.content);if(r&&n.push({type:"text",text:r}),e.toolUses)for(let s of e.toolUses)n.push({type:"tool_use",id:s.toolUseId,name:s.toolName==="ComputerUse"?"computer":s.toolName,input:s.arguments});n.length===0&&n.push({type:"text",text:""}),t.push({role:"assistant",content:n})}else if(e.toolResults&&e.toolResults.length>0){let n=[];for(let r of e.toolResults)n.push({type:"tool_result",tool_use_id:r.toolUseId,is_error:r.isError,content:r.contentBlocks?.length?r.contentBlocks:r.content});e.content.length>0&&n.push(...y(e.content)),t.push({role:"user",content:n})}else{if(t.length===0){t.push({role:"user",content:y(e.content)});continue}let n=!1,r=t[t.length-1],s=r.content;r.role==="user"&&(typeof s=="string"||Array.isArray(s)&&s.length>0&&(s[0].type==="text"||s[0].type==="image"))&&(n=!0),n?(typeof s=="string"&&(s=r.content=s.trim().length>0?[{type:"text",text:s}]:[]),s.push(...y(e.content))):t.push({role:"user",content:y(e.content)})}return t}var ee=class{protocol="anthropic";client;model;thinkingLevel;systemPrompt;maxOutputTokens;config;constructor(t,e){let n=E(t);if(!n)throw new I("Anthropic API key not found, set ANTHROPIC_API_KEY in ~/.swifty/config.yaml, or via ANTHROPIC_API_KEY env variable.");this.client=new M({apiKey:n,baseURL:t.base_url}),this.model=t.model,this.config={...t},this.thinkingLevel=O(t),this.systemPrompt=e,this.maxOutputTokens=C(t)}setSystemPrompt(t){this.systemPrompt=t}setMaxOutputTokens(t){this.config={...this.config,max_output_tokens:t},this.maxOutputTokens=C(this.config),this.setThinkingLevel(this.thinkingLevel)}setThinkingLevel(t){return this.thinkingLevel=F(this.config,t),this.thinkingLevel}getThinkingLevel(){return this.thinkingLevel}getSupportedThinkingLevels(){return K(this.config)}async*stream(t,e,n){let r=le(X(t.getMessages())),s=ne(e),c=e.map(se),v=c.some(l=>"type"in l&&l.type==="computer_20251124");oe(c),ce(r);let p={model:this.model,max_tokens:this.maxOutputTokens,stream:!0,system:[{type:"text",text:this.systemPrompt,cache_control:{type:"ephemeral"}}],messages:r,...c.length>0?{tools:c}:{}},u=this.getThinkingLevel();if(this.config.reasoning!==!1)if(u==="off")p.thinking={type:"disabled"};else if(this.config.thinking_mode==="adaptive"){let l=$(u,this.config);l!==null&&(p.thinking={type:"adaptive"},p.output_config={effort:l})}else{let l=j(u,this.config);l!==null&&l!=="none"&&(p.thinking={type:"enabled",budget_tokens:Math.min(U(l),this.maxOutputTokens-B)})}let h=0,m=0,x=0,A=0,S="end_turn",b="",L="",P=!1;try{let l=[...s?[Z]:[],...v?[re]:[]],te=this.client.messages.stream(p,{...n?{signal:n}:{},...l.length>0?{headers:{"anthropic-beta":l.join(",")}}:{}}),g="",k="",f="";for await(let a of te)switch(a.type){case"content_block_start":{let i=a.content_block;i.type==="thinking"?(P=!0,b="",L=""):i.type==="tool_use"&&(k=i.id,g=i.name==="computer"?"ComputerUse":i.name,f="",yield{type:"tool_call_start",toolName:g,toolId:k});break}case"content_block_delta":{let i=a.delta;i.type==="thinking_delta"?(b+=i.thinking,yield{type:"thinking_delta",text:i.thinking}):i.type==="signature_delta"?L+=i.signature:i.type==="text_delta"?yield{type:"text_delta",text:i.text}:i.type==="input_json_delta"&&(f+=i.partial_json,yield{type:"tool_call_delta",text:i.partial_json});break}case"content_block_stop":{if(P&&(yield{type:"thinking_complete",thinking:b,signature:L},P=!1),g){let i={};if(f)try{let _=JSON.parse(f);i=z(_)?G(_):{}}catch(_){T.error({err:_},"llm operation failed"),i={}}yield{type:"tool_call_complete",toolId:k,toolName:g,arguments:i},g="",k="",f=""}break}case"message_delta":{a.delta.stop_reason&&(S=a.delta.stop_reason),a.usage.output_tokens&&(m=a.usage.output_tokens,a.usage.input_tokens&&(h=a.usage.input_tokens),a.usage.cache_read_input_tokens&&(x=a.usage.cache_read_input_tokens),a.usage.cache_creation_input_tokens&&(A=a.usage.cache_creation_input_tokens));break}case"message_start":{h=a.message.usage.input_tokens,m=a.message.usage.output_tokens,x=a.message.usage.cache_read_input_tokens??0,A=a.message.usage.cache_creation_input_tokens??0;break}}yield{type:"stream_end",stopReason:S,usage:{inputTokens:h,outputTokens:m,cacheReadInputTokens:x,cacheCreationInputTokens:A}}}catch(l){throw T.error({err:l},"llm operation failed"),pe(l)}}};function ce(o){for(let t=o.length-1;t>=0;t--){if(o[t].role!=="user")continue;let e=o[t].content;if(typeof e=="string"&&e.length===0||Array.isArray(e)&&e.length===0)return;typeof e=="string"&&(e=o[t].content=[{type:"text",text:e}]);let n=e[e.length-1];for(let r=e.length-1;r>=0;r--)if(e[r].type!=="image"){n=e[r];break}Reflect.set(n,"cache_control",{type:"ephemeral"});return}}function pe(o){if(o instanceof M.APIError){if(o.status===413||/prompts?\s+too\s+long/i.test(o.message))return new q(`Prompt too long: ${o.message}`);if(o.status===401)return new I(`Invalid API key: ${o.message}`);if(o.status===429){let t=o.headers,e=t instanceof Headers?t.get("retry-after"):void 0,n="Rate Limited";if(e){let r=Number.parseInt(d(e));Number.isNaN(r)?n+=", please wait.":n+=`, retry after ${d(r)}s.`}else n+=", please wait.";return new J(n,e?d(e):void 0)}return new D(`Anthropic API error (${d(o.status)}): ${o.message}`)}return new V(`Network error: ${W(o)}`)}export{ee as AnthropicClient,le as buildAnthropicMessages,Te as fetchModelContextWindow,ce as markLastUserTailForCache,oe as markToolsForCache,ne as needsToolSearchBeta};
@@ -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
+ import{c as a,d as b,e as c,f as d,g as e,h as f}from"./chunk-MVVSONAE.js";import"./chunk-OQCEP2F5.js";import"./chunk-OTVZGPHD.js";import"./chunk-X3UA5OZL.js";export{b as PathSandbox,f as PermissionChecker,d as RuleEngine,c as evaluateRules,a as extractContent,e as isSafeCommand};