@swifty.js/swifty 0.0.30 → 0.0.32

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 (53) hide show
  1. package/README.md +60 -3
  2. package/dist/agent-2DUTUJFX.js +4 -0
  3. package/dist/anthropic-KR5MXB5I.js +4 -0
  4. package/dist/checker-RKAWOOXC.js +4 -0
  5. package/dist/chunk-2EV72T5X.js +4 -0
  6. package/dist/chunk-4YVJP2CO.js +4 -0
  7. package/dist/chunk-BWWNI2FK.js +121 -0
  8. package/dist/{chunk-K5ZK27BX.js → chunk-JMF2DWGY.js} +1 -1
  9. package/dist/chunk-LTFPTWX4.js +612 -0
  10. package/dist/chunk-NERVCUWE.js +4 -0
  11. package/dist/chunk-S35E7OYL.js +5 -0
  12. package/dist/{chunk-QFSCPD63.js → chunk-TCQ4EB4G.js} +1 -1
  13. package/dist/{chunk-C3WGLVVZ.js → chunk-TKQ5T5VO.js} +1 -1
  14. package/dist/chunk-TW7RHCDS.js +150 -0
  15. package/dist/lib/agent-3OEC4SOB.js +10 -0
  16. package/dist/lib/{anthropic-CL5IK7KN.js → anthropic-B33M2AVN.js} +5 -6
  17. package/dist/lib/{checker-BS4MK3O6.js → checker-QNMXPZ7C.js} +3 -4
  18. package/dist/lib/{chunk-OQIQOU5S.js → chunk-3OFLDUAW.js} +121 -1
  19. package/dist/lib/{chunk-EY7HE52Q.js → chunk-3XCGUKGJ.js} +18 -24
  20. package/dist/lib/{chunk-7QPDFSQE.js → chunk-4BPKIIQD.js} +29 -10
  21. package/dist/lib/{chunk-KG4MJGKQ.js → chunk-BCBD34D2.js} +2 -5
  22. package/dist/lib/{chunk-IYPTOY3Y.js → chunk-FODSMOWP.js} +40 -31
  23. package/dist/lib/{chunk-RMB3J46W.js → chunk-SOOSTGHI.js} +198 -37
  24. package/dist/lib/{chunk-I7OPU4K2.js → chunk-TJLAJGG4.js} +194 -34
  25. package/dist/lib/{chunk-OOSNCCI7.js → chunk-UH5M7FDP.js} +151 -152
  26. package/dist/lib/{chunk-PIL7M52F.js → chunk-XT67KGWE.js} +16 -3
  27. package/dist/lib/index.d.ts +2103 -1344
  28. package/dist/lib/index.js +11869 -9629
  29. package/dist/lib/{openai-LH4E7ZQS.js → openai-C2PZFGJ2.js} +3 -3
  30. package/dist/lib/{tool-filter-CS6W2GMU.js → tool-filter-IMIU7CW2.js} +3 -2
  31. package/dist/main.js +186 -187
  32. package/dist/{node-4LTSRXL2.js → node-GXMM4JG3.js} +1 -1
  33. package/dist/openai-M7B2TITO.js +34 -0
  34. package/dist/seatbelt-3GM2YGXV.js +5 -0
  35. package/dist/{server-IVIRQTO7.js → server-QMMIYNXW.js} +16 -23
  36. package/dist/tool-filter-7LLVAHD5.js +4 -0
  37. package/package.json +9 -12
  38. package/dist/agent-TCNIRVHD.js +0 -4
  39. package/dist/anthropic-7RIVSEDF.js +0 -4
  40. package/dist/checker-3LHDOATB.js +0 -4
  41. package/dist/chunk-2IBMB3ZM.js +0 -150
  42. package/dist/chunk-AQ3A5CF4.js +0 -5
  43. package/dist/chunk-E55KH72M.js +0 -4
  44. package/dist/chunk-FA26MQ7K.js +0 -257
  45. package/dist/chunk-OTVZGPHD.js +0 -121
  46. package/dist/chunk-QCKJLO6X.js +0 -4
  47. package/dist/chunk-TKADLB2Q.js +0 -4
  48. package/dist/chunk-VA64DJNN.js +0 -4
  49. package/dist/lib/agent-IRY7KR5D.js +0 -11
  50. package/dist/lib/chunk-GHF2PSEW.js +0 -8
  51. package/dist/openai-RZLCY55V.js +0 -34
  52. package/dist/seatbelt-YXUQ5XR3.js +0 -5
  53. package/dist/tool-filter-CG3KGQQW.js +0 -4
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  mcpCallPermissionContent
3
- } from "./chunk-KG4MJGKQ.js";
3
+ } from "./chunk-BCBD34D2.js";
4
4
  import {
5
5
  createChildLogger,
6
+ isRecord,
6
7
  strArg
7
- } from "./chunk-EY7HE52Q.js";
8
- import {
9
- MCP_CALL_TOOL_NAME
10
- } from "./chunk-GHF2PSEW.js";
8
+ } from "./chunk-3XCGUKGJ.js";
11
9
 
12
10
  // src/permissions/checker.ts
13
11
  import { readFileSync, writeFileSync, mkdirSync, statSync } from "fs";
@@ -47,40 +45,193 @@ function isPathWithin(root, path) {
47
45
  var log = createChildLogger({ module: "permissions" });
48
46
  var DANGEROUS_PATTERNS = [];
49
47
  var SAFE_PREFIXES = [
50
- "ls",
51
- "pwd",
52
- "echo",
48
+ "basename",
53
49
  "cat",
50
+ "cksum",
51
+ "cmp",
52
+ "column",
53
+ "comm",
54
+ "cut",
55
+ "df",
56
+ "dirname",
57
+ "du",
58
+ "echo",
59
+ "expr",
60
+ "false",
61
+ "fold",
62
+ "fmt",
63
+ "grep",
64
+ "groups",
54
65
  "head",
66
+ "id",
67
+ "jq",
68
+ "locate",
69
+ "ls",
70
+ "md5",
71
+ "md5sum",
72
+ "nl",
73
+ "od",
74
+ "paste",
75
+ "pgrep",
76
+ "printenv",
77
+ "printf",
78
+ "ps",
79
+ "pwd",
80
+ "readlink",
81
+ "realpath",
82
+ "sha1sum",
83
+ "sha224sum",
84
+ "sha256sum",
85
+ "sha384sum",
86
+ "sha512sum",
87
+ "shasum",
88
+ "stat",
89
+ "strings",
90
+ "tac",
55
91
  "tail",
56
- "wc",
57
- "date",
58
- "whoami",
92
+ "tr",
93
+ "true",
94
+ "tty",
95
+ "type",
59
96
  "uname",
60
- "hostname",
97
+ "uptime",
98
+ "w",
99
+ "wc",
100
+ "whereis",
61
101
  "which",
62
- "type",
63
- "file",
64
- "git status",
65
- "git log",
66
- "git diff",
67
- "git branch",
68
- "git show",
69
- "git rev-parse",
70
- "git remote",
71
- "bun test",
72
- "bun run",
73
- "npm test",
74
- "npm run",
75
- "go test",
76
- "go build",
77
- "go vet",
78
- "python -c",
79
- "node -e"
102
+ "who",
103
+ "whoami",
104
+ "ack",
105
+ "ag",
106
+ "alias",
107
+ "arch",
108
+ "base64",
109
+ "bat",
110
+ "bzcat",
111
+ "cal",
112
+ "col",
113
+ "cloc",
114
+ "diff",
115
+ "diff3",
116
+ "dig",
117
+ "dmesg",
118
+ "expand",
119
+ "factor",
120
+ "free",
121
+ "help",
122
+ "hexdump",
123
+ "host",
124
+ "iconv",
125
+ "info",
126
+ "locale",
127
+ "lscpu",
128
+ "lsblk",
129
+ "lsof",
130
+ "lspci",
131
+ "lsusb",
132
+ "man",
133
+ "mdfind",
134
+ "mdls",
135
+ "ncal",
136
+ "netstat",
137
+ "nproc",
138
+ "nslookup",
139
+ "objdump",
140
+ "otool",
141
+ "pbpaste",
142
+ "ping",
143
+ "readelf",
144
+ "rev",
145
+ "sdiff",
146
+ "seq",
147
+ "sum",
148
+ "sw_vers",
149
+ "tldr",
150
+ "traceroute",
151
+ "unexpand",
152
+ "vm_stat",
153
+ "whois",
154
+ "xxd",
155
+ "xzcat",
156
+ "zcat",
157
+ "zgrep",
158
+ "zipinfo",
159
+ /^command\s+(?:-v|-V)\s+\S+(?:\s+\S+)*$/,
160
+ /^date(?!.*\s(?:-s|--set)(?:=|\s|$))(?:\s.*)?$/,
161
+ /^file(?!.*(?:\s--compile(?:=|\s|$)|\s-[^-\s]*C))(?:\s.*)?$/,
162
+ /^find(?!.*\s(?:-delete|-exec(?:dir)?|-ok(?:dir)?|-fls|-fprint(?:0)?|-fprintf)(?:\s|$))(?:\s.*)?$/,
163
+ /^fd(?!.*\s(?:-x|-X|--exec|--exec-batch)(?:=|\s|$))(?:\s.*)?$/,
164
+ /^hostname(?:\s+(?:-[adfFiIsyVh]|--(?:alias|all-fqdns|all-ip-addresses|domain|fqdn|help|ip-address|long|nis|short|version|yp)))*$/,
165
+ /^rg(?!.*\s(?:--pre|--pre-glob|--hostname-bin)(?:=|\s|$))(?:\s.*)?$/,
166
+ /^sort(?!.*\s(?:-o|--output|--compress-program)(?:=|\s|$))(?:\s.*)?$/,
167
+ /^ss(?!.*\s(?:--kill|-[^-\s]*K)(?:\s|$))(?:\s.*)?$/,
168
+ /^tree(?!.*\s(?:-o|--output)(?:=|\s|$))(?:\s.*)?$/,
169
+ /^git\s+(?:--version|version)$/,
170
+ /^git\s+(?:blame|cat-file|count-objects|describe|for-each-ref|ls-files|ls-tree|merge-base|name-rev|rev-parse|shortlog|show-ref|status|verify-pack)(?:\s.*)?$/,
171
+ /^git\s+(?:diff|log|show)(?!.*\s(?:--ext-diff|--output)(?:=|\s|$))(?:\s.*)?$/,
172
+ /^git\s+branch$/,
173
+ /^git\s+branch(?=.*\s(?:-a|--all|-r|--remotes|--list|--show-current|--contains|--no-contains|--merged|--no-merged)(?:=|\s|$))(?!.*\s(?:-[dDmMcCf]|--(?:copy|create-reflog|delete|edit-description|move|set-upstream-to|unset-upstream))(?:=|\s|$))(?:\s.*)?$/,
174
+ /^git\s+config(?:\s+(?:--blob(?:=|\s)\S+|--file(?:=|\s)\S+|--fixed-value|--global|--local|--null|--show-names|--show-origin|--show-scope|--system|--worktree|-z))*\s+(?:--get|--get-all|--get-regexp|--get-urlmatch|--list|-l)(?:\s.*)?$/,
175
+ /^git\s+notes\s+(?:list|show)(?:\s.*)?$/,
176
+ /^git\s+reflog\s+show(?:\s.*)?$/,
177
+ /^git\s+remote(?:\s+-v)?$/,
178
+ /^git\s+remote\s+get-url(?:\s+(?:--all|--push))*\s+\S+$/,
179
+ /^git\s+remote\s+show(?:\s+-n)?(?:\s+\S+)?$/,
180
+ /^git\s+stash\s+(?:list|show)(?:\s.*)?$/,
181
+ /^git\s+submodule\s+(?:status|summary)(?:\s.*)?$/,
182
+ /^git\s+tag(?:\s+(?:-l|--list)(?:\s.*)?)?$/,
183
+ /^git\s+worktree\s+list(?:\s.*)?$/,
184
+ /^(?:bun|npm|pnpm|yarn)\s+(?:explain|help|info|list|ls|outdated|prefix|query|root|search|show|view|why)(?:\s.*)?$/,
185
+ /^(?:npm|pnpm|yarn)\s+config\s+(?:get|list)(?:\s.*)?$/,
186
+ /^npm\s+pkg\s+get(?:\s.*)?$/,
187
+ /^bun\s+pm\s+ls(?:\s.*)?$/,
188
+ /^(?:bun|cargo|clang|cmake|composer|deno|gcc|gem|node|npm|php|pip|pip3|pnpm|python|python3|ruby|rustc|swift|yarn)\s+(?:--version|-V)$/,
189
+ /^(?:go|helm|kubectl|podman|terraform)\s+version(?:\s.*)?$/,
190
+ /^(?:java|javac)\s+-version$/,
191
+ /^dotnet\s+(?:--info|--list-runtimes|--list-sdks|--version)$/,
192
+ /^(?:docker|podman)\s+(?:diff|events|images|info|inspect|logs|port|ps|stats|top|version)(?:\s.*)?$/,
193
+ /^(?:docker|podman)\s+(?:container|image|network|volume)\s+(?:inspect|ls)(?:\s.*)?$/,
194
+ /^docker\s+compose\s+(?:config|images|logs|ps|top|version)(?:\s.*)?$/,
195
+ /^kubectl\s+(?:api-resources|api-versions|cluster-info|describe|explain|get|logs|top|version)(?:\s.*)?$/,
196
+ /^kubectl\s+config\s+(?:current-context|get-contexts|view)(?:\s.*)?$/,
197
+ /^helm\s+(?:env|get|history|list|search|show|status|version)(?:\s.*)?$/,
198
+ /^terraform\s+(?:output|providers|show|version)(?:\s.*)?$/,
199
+ /^terraform\s+workspace\s+(?:list|show)(?:\s.*)?$/,
200
+ /^systemctl\s+(?:is-active|is-enabled|is-failed|list-dependencies|list-jobs|list-sockets|list-timers|list-unit-files|list-units|show|show-environment|status)(?:\s.*)?$/,
201
+ /^launchctl\s+(?:error|hostinfo|list|managername|managerpid|manageruid|print|print-cache|procinfo|variant|version)(?:\s.*)?$/,
202
+ /^journalctl(?!.*\s--(?:rotate|vacuum|flush|sync))(?:\s.*)?$/,
203
+ /^defaults\s+read(?:\s.*)?$/,
204
+ /^ifconfig$/,
205
+ /^ipconfig(?:\s+\/(?:all|allcompartments|displaydns))?\s*$/,
206
+ /^ip\s+(?:addr(?:ess)?|route)$/,
207
+ /^ip\s+(?:addr(?:ess)?|link|route|neigh(?:bor)?)\s+(?:show|list)\b(?:\s.*)?$/,
208
+ /^tar\s+(?:--list\b|-[a-zA-Z]*t[a-zA-Z]*)(?:\s.*)?$/,
209
+ /^unzip\s+-[a-zA-Z]*l(?:\s.*)?$/,
210
+ /^git\s+(?:grep|fsck|rev-list|whatchanged|help|diff-tree|diff-index|diff-files|ls-remote|verify-tag|verify-commit)(?:\s.*)?$/,
211
+ /^git\s+archive(?!.*\s(?:-o|--output)(?:=|\s|$))(?:\s.*)?$/,
212
+ /^svn\s+(?:status|stat|st|diff|di|log|info|list|ls|cat|blame|ann|annotate|proplist|propget|pg)(?:\s.*)?$/,
213
+ /^hg\s+(?:status|st|log|diff|summary|id|identify|branches|tags|manifest|cat|files|locate|heads|tip|parents|paths|root)(?:\s.*)?$/,
214
+ /^cargo\s+(?:tree|search|locate-project|verify-project|config\s+get)(?:\s.*)?$/,
215
+ /^gem\s+(?:list|search|info|env|dependency|contents|specification|sources\s+(?:-l|--list))(?:\s.*)?$/,
216
+ /^brew\s+(?:--version|-v|list|info|search|outdated|deps|uses|config|leaves|doctor)(?:\s.*)?$/,
217
+ /^choco\s+(?:--version|list|info|search|outdated)(?:\s.*)?$/,
218
+ /^apt(?:-get)?\s+list(?:\s.*)?$/,
219
+ /^apt-cache\s+(?:search|show|showpkg|policy|depends|rdepends|pkgnames)(?:\s.*)?$/,
220
+ /^dpkg\s+(?:-l|-L|-s|-S|--list|--listfiles|--status|--search)\b(?:\s.*)?$/,
221
+ /^rpm\s+-q[a-zA-Z]*(?:\s.*)?$/,
222
+ /^(?:aws|gh|gcloud|az)\s+--version$/,
223
+ /^aws\s+(?:\S+\s+)?(?:describe|list|get|wait)-\S+(?:\s.*)?$/,
224
+ /^aws\s+s3\s+ls(?:\s.*)?$/,
225
+ /^gcloud\s+\S+(?:\s+\S+)*\s+(?:list|describe)(?:\s.*)?$/,
226
+ /^az\s+\S+(?:\s+\S+)*\s+(?:list|show)(?:\s.*)?$/,
227
+ /^gh\s+(?:pr|issue|repo|run|release|gist)\s+(?:view|list|status|checks|diff)(?:\s.*)?$/,
228
+ /^(?:docker|podman)\s+(?:system\s+(?:df|info)|history|context\s+(?:ls|list|show|inspect))(?:\s.*)?$/,
229
+ /^(?:Get-(?:Acl|Alias|AuthenticodeSignature|ChildItem|CimInstance|Clipboard|Command|ComputerInfo|Content|Counter|Culture|Date|DnsClientCache|EventLog|ExecutionPolicy|FileHash|Help|History|Host|HotFix|Item|ItemProperty|Location|Member|Module|NetAdapter|NetIPAddress|NetNeighbor|NetIPConfiguration|NetRoute|NetTCPConnection|NetUDPEndpoint|Package|PackageProvider|PnpDevice|Printer|Process|PSDrive|PSProvider|PSRepository|PSSnapin|ScheduledTask|Service|TimeZone|UICulture|Variable|Verb|WinEvent|WmiObject)|Compare-Object|Format-(?:Custom|Hex|List|Table|Wide)|Group-Object|Measure-Object|Out-String|Resolve-Path|Select-Object|Select-String|Sort-Object|Test-Path|Where-Object|Write-(?:Debug|Error|Host|Information|Output|Progress|Verbose|Warning))(?:\s.*)?$/i
80
230
  ];
81
231
  var CONTENT_FIELDS = {
82
232
  Bash: "command",
83
233
  PowerShell: "command",
234
+ ComputerUse: "action",
84
235
  ReadFile: "file_path",
85
236
  WriteFile: "file_path",
86
237
  EditFile: "file_path",
@@ -88,9 +239,9 @@ var CONTENT_FIELDS = {
88
239
  Grep: "pattern",
89
240
  InstallSkill: "source"
90
241
  };
91
- var DEFAULT_DENY_WRITE = [".swifty/permissions.yaml", ".agents/skills/"];
242
+ var DEFAULT_DENY_WRITE = [];
92
243
  function extractContent(toolName, args) {
93
- if (toolName === MCP_CALL_TOOL_NAME) {
244
+ if (toolName === "McpCall") {
94
245
  return mcpCallPermissionContent(strArg(args, "server", ""), strArg(args, "tool", ""));
95
246
  }
96
247
  const field = CONTENT_FIELDS[toolName];
@@ -98,7 +249,13 @@ function extractContent(toolName, args) {
98
249
  return "";
99
250
  }
100
251
  const v = args[field];
101
- return typeof v === "string" ? v : "";
252
+ if (typeof v === "string") {
253
+ return v;
254
+ }
255
+ if (toolName === "ComputerUse" && Array.isArray(args.actions)) {
256
+ return args.actions.map((item) => isRecord(item) ? strArg(item, "type") : "").filter(Boolean).join(",");
257
+ }
258
+ return "";
102
259
  }
103
260
  var PathSandbox = class {
104
261
  allowedRoots;
@@ -280,12 +437,16 @@ function detectDangerous(command) {
280
437
  }
281
438
  function isSafeCommand(command) {
282
439
  const trimmed = command.trim();
283
- if (trimmed.includes(">") || trimmed.includes("<") || /[\r\n&]/.test(trimmed) || trimmed.includes("|") || trimmed.includes(";") || trimmed.includes("&&") || trimmed.includes("$(") || trimmed.includes("`")) {
440
+ if (/[\r\n&|;<>`(){}[\]]/.test(trimmed)) {
284
441
  return false;
285
442
  }
286
- return SAFE_PREFIXES.some(
287
- (prefix) => trimmed === prefix || trimmed.startsWith(prefix + " ") || trimmed.startsWith(prefix + " ")
288
- );
443
+ return SAFE_PREFIXES.some((prefix) => {
444
+ if (typeof prefix === "string") {
445
+ return trimmed === prefix || trimmed.startsWith(prefix + " ") || trimmed.startsWith(prefix + " ");
446
+ }
447
+ prefix.lastIndex = 0;
448
+ return prefix.test(trimmed);
449
+ });
289
450
  }
290
451
  function modeDecide(mode, category) {
291
452
  switch (mode) {
@@ -11,7 +11,7 @@ import {
11
11
  getThinkingLevel,
12
12
  resolveAPIKey,
13
13
  toReasoningEffort
14
- } from "./chunk-OQIQOU5S.js";
14
+ } from "./chunk-3OFLDUAW.js";
15
15
  import {
16
16
  asRecord,
17
17
  asString,
@@ -19,12 +19,89 @@ import {
19
19
  createChildLogger,
20
20
  isRecord,
21
21
  strArg
22
- } from "./chunk-EY7HE52Q.js";
22
+ } from "./chunk-3XCGUKGJ.js";
23
23
 
24
24
  // src/llm/openai.ts
25
25
  import OpenAI from "openai";
26
26
  var log = createChildLogger({ module: "llm" });
27
+ function computerActionArguments(action) {
28
+ switch (action.type) {
29
+ case "scroll":
30
+ return {
31
+ type: "scroll",
32
+ x: action.x,
33
+ y: action.y,
34
+ scrollX: action.scroll_x,
35
+ scrollY: action.scroll_y,
36
+ ...action.keys?.length ? { keys: action.keys } : {}
37
+ };
38
+ case "click":
39
+ case "double_click":
40
+ case "drag":
41
+ case "move": {
42
+ const { keys, ...rest } = action;
43
+ return {
44
+ ...rest,
45
+ ...keys?.length ? { keys } : {}
46
+ };
47
+ }
48
+ default:
49
+ return { ...action };
50
+ }
51
+ }
52
+ function computerCallArguments(item) {
53
+ const actions = item.actions ?? (item.action ? [item.action] : []);
54
+ return {
55
+ actions: actions.map(computerActionArguments),
56
+ pendingSafetyChecks: item.pending_safety_checks.map((check) => ({
57
+ id: check.id,
58
+ ...check.code ? { code: check.code } : {},
59
+ ...check.message ? { message: check.message } : {}
60
+ })),
61
+ status: item.status
62
+ };
63
+ }
64
+ function toOpenAIResponsesTool(schema) {
65
+ if ("type" in schema && schema.type === "computer") {
66
+ return { ...schema };
67
+ }
68
+ if ("input_schema" in schema) {
69
+ const tool = schema;
70
+ return {
71
+ type: "function",
72
+ name: tool.name,
73
+ description: tool.description,
74
+ parameters: tool.input_schema,
75
+ strict: tool.strict ?? false
76
+ };
77
+ }
78
+ if ("type" in schema && schema.type === "function" && "parameters" in schema) {
79
+ return { ...schema };
80
+ }
81
+ throw new Error("OpenAI Responses received a tool schema serialized for another protocol.");
82
+ }
83
+ function toOpenAICompatTool(schema) {
84
+ if ("input_schema" in schema) {
85
+ const tool = schema;
86
+ return {
87
+ type: "function",
88
+ function: {
89
+ name: tool.name,
90
+ description: tool.description,
91
+ parameters: tool.input_schema,
92
+ strict: tool.strict ?? false
93
+ }
94
+ };
95
+ }
96
+ if ("function" in schema) {
97
+ return { ...schema };
98
+ }
99
+ throw new Error(
100
+ "OpenAI Chat Completions received a tool schema serialized for another protocol."
101
+ );
102
+ }
27
103
  var OpenAIClient = class {
104
+ protocol = "openai";
28
105
  client;
29
106
  model;
30
107
  systemPrompt;
@@ -58,16 +135,7 @@ var OpenAIClient = class {
58
135
  for (const message of messages) {
59
136
  input.push(message);
60
137
  }
61
- const tools = toolSchemas.map((s) => {
62
- const schema = s.input_schema;
63
- return {
64
- type: "function",
65
- name: s.name,
66
- description: s.description,
67
- parameters: schema,
68
- strict: s.strict ?? false
69
- };
70
- });
138
+ const tools = toolSchemas.map(toOpenAIResponsesTool);
71
139
  const effort = toReasoningEffort(this.getThinkingLevel(), this.config);
72
140
  const params = {
73
141
  model: this.model,
@@ -124,6 +192,12 @@ var OpenAIClient = class {
124
192
  toolName: currentToolName,
125
193
  toolId: currentToolId
126
194
  };
195
+ } else if (event.item.type === "computer_call") {
196
+ yield {
197
+ type: "tool_call_start",
198
+ toolName: "ComputerUse",
199
+ toolId: event.item.call_id
200
+ };
127
201
  } else if (event.item.type === "reasoning") {
128
202
  reasoningId = event.item.id ?? "";
129
203
  reasoningText = "";
@@ -149,6 +223,14 @@ var OpenAIClient = class {
149
223
  currentToolName = "";
150
224
  currentToolId = "";
151
225
  jsonAccumulate = "";
226
+ } else if (event.item.type === "computer_call") {
227
+ yield {
228
+ type: "tool_call_complete",
229
+ toolId: event.item.call_id,
230
+ toolName: "ComputerUse",
231
+ arguments: computerCallArguments(event.item),
232
+ providerItemId: event.item.id
233
+ };
152
234
  }
153
235
  } else if (event.type === "response.completed" || event.type === "response.incomplete") {
154
236
  sawTerminalResponse = true;
@@ -292,6 +374,56 @@ function toolOutputForResponses(tr) {
292
374
  }
293
375
  return rich.length > 0 ? rich : tr.content;
294
376
  }
377
+ function computerActionsForResponses(args) {
378
+ if (!Array.isArray(args.actions)) {
379
+ return [];
380
+ }
381
+ const actions = [];
382
+ for (const raw of args.actions) {
383
+ if (!isRecord(raw) || typeof raw.type !== "string") {
384
+ continue;
385
+ }
386
+ if (raw.type === "scroll") {
387
+ actions.push({
388
+ type: "scroll",
389
+ x: Number(raw.x),
390
+ y: Number(raw.y),
391
+ scroll_x: Number(raw.scrollX),
392
+ scroll_y: Number(raw.scrollY),
393
+ ...Array.isArray(raw.keys) ? { keys: raw.keys.map(String) } : {}
394
+ });
395
+ continue;
396
+ }
397
+ actions.push(raw);
398
+ }
399
+ return actions;
400
+ }
401
+ function safetyChecksForResponses(args) {
402
+ if (!Array.isArray(args.pendingSafetyChecks)) {
403
+ return [];
404
+ }
405
+ return args.pendingSafetyChecks.flatMap((raw) => {
406
+ if (!isRecord(raw) || typeof raw.id !== "string") {
407
+ return [];
408
+ }
409
+ return [
410
+ {
411
+ id: raw.id,
412
+ ...typeof raw.code === "string" ? { code: raw.code } : {},
413
+ ...typeof raw.message === "string" ? { message: raw.message } : {}
414
+ }
415
+ ];
416
+ });
417
+ }
418
+ function computerScreenshotUrl(tr) {
419
+ for (const block of tr.contentBlocks ?? []) {
420
+ const url = imageDataUrl(block);
421
+ if (url) {
422
+ return url;
423
+ }
424
+ }
425
+ return void 0;
426
+ }
295
427
  function collectRichParts(tr) {
296
428
  if (!tr.contentBlocks?.length) {
297
429
  return [];
@@ -349,6 +481,14 @@ function userPartsFor(content) {
349
481
  }
350
482
  function buildOpenAIInput(messages) {
351
483
  const result = [];
484
+ const computerCalls = /* @__PURE__ */ new Map();
485
+ for (const message of messages) {
486
+ for (const toolUse of message.toolUses ?? []) {
487
+ if (toolUse.toolName === "ComputerUse") {
488
+ computerCalls.set(toolUse.toolUseId, toolUse);
489
+ }
490
+ }
491
+ }
352
492
  for (const m of messages) {
353
493
  if (m.thinkingBlocks) {
354
494
  for (const tb of m.thinkingBlocks) {
@@ -368,20 +508,49 @@ function buildOpenAIInput(messages) {
368
508
  });
369
509
  }
370
510
  for (const tu of m.toolUses) {
371
- result.push({
372
- type: "function_call",
373
- name: tu.toolName,
374
- call_id: tu.toolUseId,
375
- arguments: JSON.stringify(tu.arguments)
376
- });
511
+ if (tu.toolName === "ComputerUse") {
512
+ const status = tu.arguments.status;
513
+ result.push({
514
+ type: "computer_call",
515
+ id: tu.providerItemId ?? tu.toolUseId,
516
+ call_id: tu.toolUseId,
517
+ status: status === "in_progress" || status === "incomplete" ? status : "completed",
518
+ actions: computerActionsForResponses(tu.arguments),
519
+ pending_safety_checks: safetyChecksForResponses(tu.arguments)
520
+ });
521
+ } else {
522
+ result.push({
523
+ type: "function_call",
524
+ name: tu.toolName,
525
+ call_id: tu.toolUseId,
526
+ arguments: JSON.stringify(tu.arguments)
527
+ });
528
+ }
377
529
  }
378
530
  } else if (m.toolResults && m.toolResults.length > 0) {
379
531
  for (const tr of m.toolResults) {
380
- result.push({
381
- type: "function_call_output",
382
- call_id: tr.toolUseId,
383
- output: toolOutputForResponses(tr)
384
- });
532
+ const computerCall = computerCalls.get(tr.toolUseId);
533
+ if (computerCall) {
534
+ const imageUrl = computerScreenshotUrl(tr);
535
+ result.push({
536
+ type: "computer_call_output",
537
+ call_id: tr.toolUseId,
538
+ output: {
539
+ type: "computer_screenshot",
540
+ ...imageUrl ? { image_url: imageUrl } : {}
541
+ },
542
+ acknowledged_safety_checks: safetyChecksForResponses(computerCall.arguments)
543
+ });
544
+ if (tr.isError || !imageUrl) {
545
+ result.push({ role: "user", content: tr.content });
546
+ }
547
+ } else {
548
+ result.push({
549
+ type: "function_call_output",
550
+ call_id: tr.toolUseId,
551
+ output: toolOutputForResponses(tr)
552
+ });
553
+ }
385
554
  }
386
555
  if (m.content.length > 0) {
387
556
  result.push({ role: "user", content: userContentsFor(m.content) });
@@ -404,6 +573,7 @@ function containsContextLengthError(msg) {
404
573
  return /context_length_exceeded/i.test(msg) || /maximum\scontext\slength/i.test(msg) || /prompts?\s+too\s+long/i.test(msg);
405
574
  }
406
575
  var OpenAICompatClient = class {
576
+ protocol = "openai-compat";
407
577
  client;
408
578
  model;
409
579
  systemPrompt;
@@ -448,17 +618,7 @@ var OpenAICompatClient = class {
448
618
  },
449
619
  ...buildChatCompletionMessages(ensureToolPairing(conversation.getMessages()))
450
620
  ];
451
- const tools = toolSchemas.map((ts) => ({
452
- // name: ts.name,
453
- // description: ts.description,
454
- type: "function",
455
- function: {
456
- name: ts.name,
457
- description: ts.description,
458
- parameters: ts.input_schema,
459
- strict: ts.strict ?? false
460
- }
461
- }));
621
+ const tools = toolSchemas.map(toOpenAICompatTool);
462
622
  const effort = toReasoningEffort(this.getThinkingLevel(), this.config);
463
623
  const params = {
464
624
  model: this.model,