@swifty.js/swifty 0.0.30 → 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 (43) hide show
  1. package/README.md +14 -0
  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-MVVSONAE.js +4 -0
  8. package/dist/chunk-OQCEP2F5.js +4 -0
  9. package/dist/{chunk-QFSCPD63.js → chunk-TCQ4EB4G.js} +1 -1
  10. package/dist/chunk-Y2UUXOQA.js +4 -0
  11. package/dist/chunk-YAXZ2OUD.js +150 -0
  12. package/dist/lib/agent-YRTROHXU.js +10 -0
  13. package/dist/lib/{anthropic-CL5IK7KN.js → anthropic-R6DMXE7U.js} +3 -4
  14. package/dist/lib/{checker-BS4MK3O6.js → checker-M7RKMKJQ.js} +2 -3
  15. package/dist/lib/{chunk-IYPTOY3Y.js → chunk-4MDCRPVV.js} +35 -26
  16. package/dist/lib/{chunk-RMB3J46W.js → chunk-A4MXZA5Q.js} +197 -36
  17. package/dist/lib/{chunk-7QPDFSQE.js → chunk-EWE5IWZE.js} +20 -10
  18. package/dist/lib/{chunk-KG4MJGKQ.js → chunk-FZ4Y6MBN.js} +1 -4
  19. package/dist/lib/{chunk-OOSNCCI7.js → chunk-J6AV7SIF.js} +143 -148
  20. package/dist/lib/{chunk-I7OPU4K2.js → chunk-OEPCNATU.js} +192 -32
  21. package/dist/lib/{chunk-PIL7M52F.js → chunk-XT67KGWE.js} +16 -3
  22. package/dist/lib/index.d.ts +856 -778
  23. package/dist/lib/index.js +2261 -749
  24. package/dist/lib/{openai-LH4E7ZQS.js → openai-5N42ZYIJ.js} +1 -1
  25. package/dist/lib/{tool-filter-CS6W2GMU.js → tool-filter-XG2GXFVN.js} +3 -2
  26. package/dist/main.js +140 -140
  27. package/dist/openai-NQYARTT6.js +34 -0
  28. package/dist/{server-IVIRQTO7.js → server-BNT2IIKB.js} +17 -17
  29. package/dist/tool-filter-5NDJMSTD.js +4 -0
  30. package/package.json +1 -1
  31. package/dist/agent-TCNIRVHD.js +0 -4
  32. package/dist/anthropic-7RIVSEDF.js +0 -4
  33. package/dist/checker-3LHDOATB.js +0 -4
  34. package/dist/chunk-2IBMB3ZM.js +0 -150
  35. package/dist/chunk-E55KH72M.js +0 -4
  36. package/dist/chunk-FA26MQ7K.js +0 -257
  37. package/dist/chunk-QCKJLO6X.js +0 -4
  38. package/dist/chunk-TKADLB2Q.js +0 -4
  39. package/dist/chunk-VA64DJNN.js +0 -4
  40. package/dist/lib/agent-IRY7KR5D.js +0 -11
  41. package/dist/lib/chunk-GHF2PSEW.js +0 -8
  42. package/dist/openai-RZLCY55V.js +0 -34
  43. package/dist/tool-filter-CG3KGQQW.js +0 -4
@@ -24,7 +24,84 @@ import {
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,
@@ -41,9 +41,17 @@ function normalizeDocumentBlock(value) {
41
41
  if (value.source.type === "url" && typeof value.source.url === "string") {
42
42
  source = { type: "url", url: value.source.url };
43
43
  } else if (value.source.type === "base64" && value.source.media_type === "application/pdf" && typeof value.source.data === "string") {
44
- source = { type: "base64", media_type: "application/pdf", data: value.source.data };
44
+ source = {
45
+ type: "base64",
46
+ media_type: "application/pdf",
47
+ data: value.source.data
48
+ };
45
49
  } else if (value.source.type === "text" && value.source.media_type === "text/plain" && typeof value.source.data === "string") {
46
- source = { type: "text", media_type: "text/plain", data: value.source.data };
50
+ source = {
51
+ type: "text",
52
+ media_type: "text/plain",
53
+ data: value.source.data
54
+ };
47
55
  } else if (value.source.type === "content") {
48
56
  if (typeof value.source.content === "string") {
49
57
  source = { type: "content", content: value.source.content };
@@ -93,7 +101,12 @@ function normalizeToolResultContentBlock(value) {
93
101
  }
94
102
  content.push(block);
95
103
  }
96
- return { type: "search_result", source: value.source, title: value.title, content };
104
+ return {
105
+ type: "search_result",
106
+ source: value.source,
107
+ title: value.title,
108
+ content
109
+ };
97
110
  }
98
111
  return normalizeDocumentBlock(value);
99
112
  }