@yukino.js/yukino 0.0.3 → 0.0.5

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 (71) hide show
  1. package/README.md +90 -64
  2. package/dist/acp-LOU6R4C7.js +14 -0
  3. package/dist/{agent-D6LSQHAD.js → agent-5NW5ZV5P.js} +1 -1
  4. package/dist/anthropic-UXFSBFXM.js +4 -0
  5. package/dist/{bwrap-MLSZLWHD.js → bwrap-BZ7Q2A5B.js} +1 -1
  6. package/dist/chunk-2HUCPWD6.js +29 -0
  7. package/dist/{chunk-XO7ITAWR.js → chunk-3EQYWNP6.js} +1 -1
  8. package/dist/chunk-3SPUH3TD.js +164 -0
  9. package/dist/chunk-5HF4GLFR.js +865 -0
  10. package/dist/{chunk-QG22QNQJ.js → chunk-BPA7URET.js} +1 -1
  11. package/dist/chunk-HBXZ6MB4.js +4 -0
  12. package/dist/chunk-KILUTRHM.js +4 -0
  13. package/dist/chunk-MQAQBW7F.js +35 -0
  14. package/dist/chunk-NAQRFHUX.js +4 -0
  15. package/dist/chunk-SDXAS44V.js +4 -0
  16. package/dist/chunk-TJVN4NL5.js +5 -0
  17. package/dist/chunk-VM26JJ6N.js +4 -0
  18. package/dist/chunk-VM4YKTHC.js +10 -0
  19. package/dist/chunk-WNHTKUKK.js +4 -0
  20. package/dist/chunk-YVLW4WBA.js +241 -0
  21. package/dist/chunk-ZPYQCXWT.js +5 -0
  22. package/dist/{devtools-YWVUN4HX.js → devtools-UVGRIXO2.js} +1 -1
  23. package/dist/esm-5V3TYPZK.js +229 -0
  24. package/dist/lib/{agent-KNGNHPSW.js → agent-UGEA6EVB.js} +5 -5
  25. package/dist/lib/{anthropic-MSGL4VBM.js → anthropic-UC7XIWCM.js} +5 -4
  26. package/dist/lib/{bwrap-2OL7VPSO.js → bwrap-STOJ4TEH.js} +1 -1
  27. package/dist/lib/{chunk-E6VFL5IO.js → chunk-64Z3SMSG.js} +32 -30
  28. package/dist/lib/{chunk-6AKRDUQF.js → chunk-65EUCQOF.js} +1 -1
  29. package/dist/lib/{chunk-FLKB4BK7.js → chunk-DXUJGZ5F.js} +16 -4
  30. package/dist/lib/{chunk-ENTAZT2J.js → chunk-GAWWN3TY.js} +44 -32
  31. package/dist/lib/{chunk-YIWNQ7OA.js → chunk-MGPT7DWP.js} +1 -0
  32. package/dist/lib/{chunk-BDJLW7U2.js → chunk-NIJXTKNM.js} +342 -184
  33. package/dist/lib/{chunk-MDX24JQ5.js → chunk-OCTB6YMC.js} +23 -17
  34. package/dist/lib/{chunk-24L3QT3J.js → chunk-OYQY3Q45.js} +68 -27
  35. package/dist/lib/chunk-R3NJ2EET.js +540 -0
  36. package/dist/lib/{chunk-7SU77J32.js → chunk-UKINFW65.js} +55 -2
  37. package/dist/lib/chunk-V2EYBIAU.js +323 -0
  38. package/dist/lib/{chunk-K4VUUC44.js → chunk-WDO5MWH2.js} +1 -1
  39. package/dist/lib/index.d.ts +3431 -2269
  40. package/dist/lib/index.js +14801 -12912
  41. package/dist/lib/{openai-DL5VBJR4.js → openai-OL5HXQUU.js} +4 -3
  42. package/dist/lib/{permissions-Q4FBU5VD.js → permissions-EAKP6IZ3.js} +7 -3
  43. package/dist/lib/{providers-VKVMAYIT.js → providers-N35WJDJM.js} +1 -1
  44. package/dist/lib/{seatbelt-WO7YWKLR.js → seatbelt-G5Z5QEDD.js} +1 -1
  45. package/dist/lib/{tool-filter-PY6XY254.js → tool-filter-HUVHJN3O.js} +3 -3
  46. package/dist/main.js +201 -192
  47. package/dist/{openai-AQNX24XU.js → openai-NIBMRDVB.js} +5 -5
  48. package/dist/permissions-5EQWZS7O.js +4 -0
  49. package/dist/{providers-SVAEL2RU.js → providers-TG3LGHNS.js} +1 -1
  50. package/dist/{seatbelt-JOCANLYS.js → seatbelt-IOLIYZZX.js} +1 -1
  51. package/dist/server-7ENYPCYC.js +4 -0
  52. package/dist/tool-filter-XZ7I6KU7.js +4 -0
  53. package/package.json +85 -32
  54. package/dist/acp-5YESBJ7N.js +0 -14
  55. package/dist/anthropic-CEUDAJL2.js +0 -4
  56. package/dist/chunk-6GCU7CRK.js +0 -607
  57. package/dist/chunk-77W2UPS2.js +0 -4
  58. package/dist/chunk-7DLUKIPE.js +0 -5
  59. package/dist/chunk-HLE7243Q.js +0 -4
  60. package/dist/chunk-K4BYVVW7.js +0 -5
  61. package/dist/chunk-L2BWSPCF.js +0 -10
  62. package/dist/chunk-OAFPGTZY.js +0 -164
  63. package/dist/chunk-RCXKUD3Y.js +0 -4
  64. package/dist/chunk-SAJCBGHL.js +0 -4
  65. package/dist/chunk-UPNNYP7M.js +0 -60
  66. package/dist/chunk-YBUSZS75.js +0 -237
  67. package/dist/esm-NCEEJIH3.js +0 -229
  68. package/dist/lib/chunk-BMODZ6SU.js +0 -673
  69. package/dist/permissions-VCDMNX3L.js +0 -4
  70. package/dist/server-UI2ZQVXG.js +0 -4
  71. package/dist/tool-filter-BQZDV3TF.js +0 -4
@@ -2,12 +2,12 @@ import {
2
2
  Agent,
3
3
  events_exports,
4
4
  streaming_executor_exports
5
- } from "./chunk-BDJLW7U2.js";
6
- import "./chunk-K4VUUC44.js";
5
+ } from "./chunk-NIJXTKNM.js";
6
+ import "./chunk-WDO5MWH2.js";
7
7
  import "./chunk-F2YJG72O.js";
8
- import "./chunk-BMODZ6SU.js";
9
- import "./chunk-6AKRDUQF.js";
10
- import "./chunk-7SU77J32.js";
8
+ import "./chunk-65EUCQOF.js";
9
+ import "./chunk-V2EYBIAU.js";
10
+ import "./chunk-UKINFW65.js";
11
11
  import "./chunk-MLKGABMK.js";
12
12
  export {
13
13
  Agent,
@@ -4,11 +4,12 @@ import {
4
4
  markLastUserTailForCache,
5
5
  markToolsForCache,
6
6
  needsToolSearchBeta
7
- } from "./chunk-ENTAZT2J.js";
7
+ } from "./chunk-GAWWN3TY.js";
8
8
  import "./chunk-F2YJG72O.js";
9
- import "./chunk-BMODZ6SU.js";
10
- import "./chunk-6AKRDUQF.js";
11
- import "./chunk-7SU77J32.js";
9
+ import "./chunk-65EUCQOF.js";
10
+ import "./chunk-R3NJ2EET.js";
11
+ import "./chunk-V2EYBIAU.js";
12
+ import "./chunk-UKINFW65.js";
12
13
  import "./chunk-MLKGABMK.js";
13
14
  export {
14
15
  AnthropicClient,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BwrapSandbox
3
- } from "./chunk-YIWNQ7OA.js";
3
+ } from "./chunk-MGPT7DWP.js";
4
4
  import "./chunk-MLKGABMK.js";
5
5
  export {
6
6
  BwrapSandbox
@@ -1,3 +1,6 @@
1
+ import {
2
+ resolveAPIKey
3
+ } from "./chunk-R3NJ2EET.js";
1
4
  import {
2
5
  AuthenticationError,
3
6
  ContextTooLongError,
@@ -10,9 +13,8 @@ import {
10
13
  getMaxOutputTokens,
11
14
  getSupportedThinkingLevels,
12
15
  getThinkingLevel,
13
- resolveAPIKey,
14
16
  toReasoningEffort
15
- } from "./chunk-BMODZ6SU.js";
17
+ } from "./chunk-V2EYBIAU.js";
16
18
  import {
17
19
  asRecord,
18
20
  asString,
@@ -20,7 +22,7 @@ import {
20
22
  createChildLogger,
21
23
  isRecord,
22
24
  strArg
23
- } from "./chunk-7SU77J32.js";
25
+ } from "./chunk-UKINFW65.js";
24
26
  import {
25
27
  __export
26
28
  } from "./chunk-MLKGABMK.js";
@@ -280,7 +282,6 @@ var OpenAIClient = class {
280
282
  outputTokens,
281
283
  cacheReadInputTokens,
282
284
  cacheCreationInputTokens
283
- // 0
284
285
  }
285
286
  };
286
287
  } else if (event.type === "response.failed") {
@@ -696,35 +697,36 @@ var OpenAICompatClient = class {
696
697
  }
697
698
  if (delta.tool_calls) {
698
699
  for (const tc of delta.tool_calls) {
699
- if (!toolCalls.has(tc.index)) {
700
- toolCalls.set(tc.index, {
700
+ let entry = toolCalls.get(tc.index);
701
+ if (!entry) {
702
+ entry = {
701
703
  id: tc.id ?? "",
702
704
  name: tc.function?.name ?? "",
703
- args: ""
704
- });
705
- if (tc.id) {
706
- yield {
707
- type: "tool_call_start",
708
- toolName: tc.function?.name ?? "",
709
- toolId: tc.id ?? ""
710
- };
711
- }
705
+ args: "",
706
+ started: false
707
+ };
708
+ toolCalls.set(tc.index, entry);
712
709
  }
713
- const existing = toolCalls.get(tc.index);
714
- if (existing) {
715
- if (tc.id) {
716
- existing.id = tc.id;
717
- }
718
- if (tc.function?.name) {
719
- existing.name = tc.function.name;
720
- }
721
- if (tc.function?.arguments) {
722
- existing.args += tc.function.arguments;
723
- yield {
724
- type: "tool_call_delta",
725
- text: tc.function.arguments
726
- };
727
- }
710
+ if (tc.id) {
711
+ entry.id = tc.id;
712
+ }
713
+ if (tc.function?.name) {
714
+ entry.name = tc.function.name;
715
+ }
716
+ if (!entry.started && entry.id && entry.name) {
717
+ entry.started = true;
718
+ yield {
719
+ type: "tool_call_start",
720
+ toolName: entry.name,
721
+ toolId: entry.id
722
+ };
723
+ }
724
+ if (tc.function?.arguments) {
725
+ entry.args += tc.function.arguments;
726
+ yield {
727
+ type: "tool_call_delta",
728
+ text: tc.function.arguments
729
+ };
728
730
  }
729
731
  }
730
732
  }
@@ -3,7 +3,7 @@ import {
3
3
  asRecord,
4
4
  createChildLogger,
5
5
  strArg
6
- } from "./chunk-7SU77J32.js";
6
+ } from "./chunk-UKINFW65.js";
7
7
  import {
8
8
  __export
9
9
  } from "./chunk-MLKGABMK.js";
@@ -7,7 +7,7 @@ var seatbelt_exports = {};
7
7
  __export(seatbelt_exports, {
8
8
  SeatbeltSandbox: () => SeatbeltSandbox
9
9
  });
10
- import { existsSync, statSync } from "fs";
10
+ import { existsSync, realpathSync, statSync } from "fs";
11
11
  var SANDBOX_EXEC_PATH = "/usr/bin/sandbox-exec";
12
12
  var SeatbeltSandbox = class {
13
13
  implementation = "seatbelt";
@@ -21,6 +21,14 @@ var SeatbeltSandbox = class {
21
21
  };
22
22
  }
23
23
  };
24
+ function pathVariants(path) {
25
+ const variants = /* @__PURE__ */ new Set([path]);
26
+ try {
27
+ variants.add(realpathSync(path));
28
+ } catch {
29
+ }
30
+ return [...variants];
31
+ }
24
32
  function buildProfile(config) {
25
33
  const lines = [];
26
34
  lines.push("(version 1)");
@@ -30,11 +38,15 @@ function buildProfile(config) {
30
38
  lines.push("(allow sysctl-read)");
31
39
  lines.push('(allow file-read* (subpath "/"))');
32
40
  for (const path of config.allowWrite) {
33
- lines.push(`(allow file-write* (subpath "${path}"))`);
41
+ for (const variant of pathVariants(path)) {
42
+ lines.push(`(allow file-write* (subpath "${variant}"))`);
43
+ }
34
44
  }
35
45
  for (const path of config.denyWrite) {
36
- const matcher = existsSync(path) && statSync(path).isDirectory() ? "subpath" : "literal";
37
- lines.push(`(deny file-write* (${matcher} "${path}"))`);
46
+ for (const variant of pathVariants(path)) {
47
+ const matcher = existsSync(variant) && statSync(variant).isDirectory() ? "subpath" : "literal";
48
+ lines.push(`(deny file-write* (${matcher} "${variant}"))`);
49
+ }
38
50
  }
39
51
  if (config.networkEnabled) {
40
52
  lines.push("(allow network*)");
@@ -1,6 +1,13 @@
1
1
  import {
2
2
  normalizeToolResultContentBlock
3
3
  } from "./chunk-F2YJG72O.js";
4
+ import {
5
+ MCP_TOOL_PREFIX,
6
+ isMcpToolLike
7
+ } from "./chunk-65EUCQOF.js";
8
+ import {
9
+ resolveAPIKey
10
+ } from "./chunk-R3NJ2EET.js";
4
11
  import {
5
12
  AuthenticationError,
6
13
  ContextTooLongError,
@@ -14,15 +21,10 @@ import {
14
21
  getMaxOutputTokens,
15
22
  getSupportedThinkingLevels,
16
23
  getThinkingLevel,
17
- resolveAPIKey,
18
24
  thinkingBudgetForLevel,
19
25
  toAnthropicThinkingEffort,
20
26
  toReasoningEffort
21
- } from "./chunk-BMODZ6SU.js";
22
- import {
23
- MCP_TOOL_PREFIX,
24
- isMcpToolLike
25
- } from "./chunk-6AKRDUQF.js";
27
+ } from "./chunk-V2EYBIAU.js";
26
28
  import {
27
29
  asErrorString,
28
30
  asRecord,
@@ -31,7 +33,7 @@ import {
31
33
  createChildLogger,
32
34
  isRecord,
33
35
  strArg
34
- } from "./chunk-7SU77J32.js";
36
+ } from "./chunk-UKINFW65.js";
35
37
  import {
36
38
  __export
37
39
  } from "./chunk-MLKGABMK.js";
@@ -78,7 +80,7 @@ function isOfficialAnthropicEndpoint(baseUrl) {
78
80
  function estimateSchemaTokens(schemaChars) {
79
81
  return Math.floor(schemaChars / CHARS_PER_TOKEN);
80
82
  }
81
- function decideMode(baseUrl, contextWindow, mcpSchemaChars, thresholdPercent = DEFAULT_EAGER_THRESHOLD_PERCENT) {
83
+ function decideMode(baseUrl, protocol, contextWindow, mcpSchemaChars, thresholdPercent = DEFAULT_EAGER_THRESHOLD_PERCENT) {
82
84
  const override = (process.env[ENV_OVERRIDE] ?? "").trim().toLowerCase();
83
85
  if (override === "eager" || override === "native" || override === "dispatch") {
84
86
  return override;
@@ -90,7 +92,8 @@ function decideMode(baseUrl, contextWindow, mcpSchemaChars, thresholdPercent = D
90
92
  if (estimateSchemaTokens(mcpSchemaChars) < budget) {
91
93
  return "eager";
92
94
  }
93
- return isOfficialAnthropicEndpoint(baseUrl) ? "native" : "dispatch";
95
+ const canNative = protocol === "anthropic" && isOfficialAnthropicEndpoint(baseUrl);
96
+ return canNative ? "native" : "dispatch";
94
97
  }
95
98
  function measureSchemaChars(registry) {
96
99
  let total = 0;
@@ -117,8 +120,13 @@ function applyMode(registry, mode) {
117
120
  registry.exposeToolSearch = !eager;
118
121
  registry.exposeMcpCall = mode === "dispatch";
119
122
  }
120
- function decideAndApply(registry, baseUrl, contextWindow) {
121
- const mode = decideMode(baseUrl, contextWindow, measureSchemaChars(registry));
123
+ function decideAndApply(registry, baseUrl, protocol, contextWindow) {
124
+ const mode = decideMode(
125
+ baseUrl,
126
+ protocol,
127
+ contextWindow,
128
+ measureSchemaChars(registry)
129
+ );
122
130
  applyMode(registry, mode);
123
131
  return mode;
124
132
  }
@@ -196,7 +204,6 @@ function buildAnthropicMessages(messages) {
196
204
  for (const tu of m.toolUses) {
197
205
  blocks.push({
198
206
  type: "tool_use",
199
- // tool use **request**
200
207
  id: tu.toolUseId,
201
208
  name: tu.toolName === "ComputerUse" ? "computer" : tu.toolName,
202
209
  input: tu.arguments
@@ -212,7 +219,6 @@ function buildAnthropicMessages(messages) {
212
219
  for (const tr of m.toolResults) {
213
220
  blocks.push({
214
221
  type: "tool_result",
215
- // tool result
216
222
  tool_use_id: tr.toolUseId,
217
223
  is_error: tr.isError,
218
224
  content: tr.contentBlocks?.length ? tr.contentBlocks : tr.content
@@ -233,8 +239,7 @@ function buildAnthropicMessages(messages) {
233
239
  let canMerge = false;
234
240
  const prev = result[result.length - 1];
235
241
  let content = prev.content;
236
- if (prev.role === "user" && (typeof content === "string" || Array.isArray(content) && content.length > 0 && // content[0].type !== "tool_result"
237
- (content[0].type === "text" || content[0].type === "image"))) {
242
+ if (prev.role === "user" && (typeof content === "string" || Array.isArray(content) && content.length > 0 && (content[0].type === "text" || content[0].type === "image"))) {
238
243
  canMerge = true;
239
244
  }
240
245
  if (canMerge) {
@@ -261,7 +266,8 @@ var AnthropicClient = class {
261
266
  protocol = "anthropic";
262
267
  client;
263
268
  model;
264
- /** Effective logical level for budget or explicitly configured adaptive mode. */
269
+ /** Effective logical thinking level (clamped to what the provider supports);
270
+ * translated to a token budget or an adaptive effort per request. */
265
271
  thinkingLevel;
266
272
  systemPrompt;
267
273
  maxOutputTokens;
@@ -325,7 +331,6 @@ var AnthropicClient = class {
325
331
  text: this.systemPrompt,
326
332
  cache_control: {
327
333
  type: "ephemeral"
328
- // Prompt cache
329
334
  }
330
335
  }
331
336
  ],
@@ -366,6 +371,7 @@ var AnthropicClient = class {
366
371
  let thinkingAccumulate = "";
367
372
  let thinkingSignature = "";
368
373
  let inThinking = false;
374
+ let sawMessageStop = false;
369
375
  try {
370
376
  const betas = [...sendToolSearchBeta ? [NATIVE_TOOL_USE_BETA] : []];
371
377
  const response = this.client.messages.stream(params, {
@@ -395,7 +401,6 @@ var AnthropicClient = class {
395
401
  }
396
402
  break;
397
403
  }
398
- // end case "content_block_start"
399
404
  case "content_block_delta": {
400
405
  const delta = event.delta;
401
406
  if (delta.type === "thinking_delta") {
@@ -420,7 +425,6 @@ var AnthropicClient = class {
420
425
  }
421
426
  break;
422
427
  }
423
- // end case "content_block_delta"
424
428
  case "content_block_stop": {
425
429
  if (inThinking) {
426
430
  yield {
@@ -453,26 +457,29 @@ var AnthropicClient = class {
453
457
  }
454
458
  break;
455
459
  }
456
- // end case "content_block_stop"
457
460
  case "message_delta": {
458
461
  if (event.delta.stop_reason) {
459
462
  stopReason = event.delta.stop_reason;
460
463
  }
461
- if (event.usage.output_tokens) {
462
- outputTokens = event.usage.output_tokens;
463
- if (event.usage.input_tokens) {
464
- inputTokens = event.usage.input_tokens;
465
- }
466
- if (event.usage.cache_read_input_tokens) {
467
- cacheReadInputTokens = event.usage.cache_read_input_tokens;
468
- }
469
- if (event.usage.cache_creation_input_tokens) {
470
- cacheCreationInputTokens = event.usage.cache_creation_input_tokens;
471
- }
464
+ const deltaUsage = event.usage;
465
+ if (typeof deltaUsage.output_tokens === "number") {
466
+ outputTokens = deltaUsage.output_tokens;
467
+ }
468
+ if (typeof deltaUsage.input_tokens === "number") {
469
+ inputTokens = deltaUsage.input_tokens;
470
+ }
471
+ if (typeof deltaUsage.cache_read_input_tokens === "number") {
472
+ cacheReadInputTokens = deltaUsage.cache_read_input_tokens;
472
473
  }
474
+ if (typeof deltaUsage.cache_creation_input_tokens === "number") {
475
+ cacheCreationInputTokens = deltaUsage.cache_creation_input_tokens;
476
+ }
477
+ break;
478
+ }
479
+ case "message_stop": {
480
+ sawMessageStop = true;
473
481
  break;
474
482
  }
475
- // end case "message_delta"
476
483
  case "message_start": {
477
484
  inputTokens = event.message.usage.input_tokens;
478
485
  outputTokens = event.message.usage.output_tokens;
@@ -482,6 +489,11 @@ var AnthropicClient = class {
482
489
  }
483
490
  }
484
491
  }
492
+ if (!sawMessageStop) {
493
+ throw new NetworkError(
494
+ "Anthropic stream ended without message_stop; response was truncated"
495
+ );
496
+ }
485
497
  yield {
486
498
  type: "stream_end",
487
499
  stopReason,
@@ -25,6 +25,7 @@ var BwrapSandbox = class {
25
25
  }
26
26
  prepare(command, config) {
27
27
  const args = ["--unshare-user", "--unshare-pid"];
28
+ args.push("--die-with-parent");
28
29
  args.push("--ro-bind", "/", "/");
29
30
  for (const path of config.allowWrite) {
30
31
  args.push("--bind", path, path);