@yukino.js/yukino 0.0.1 → 0.0.3-dev
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.
- package/README.md +34 -27
- package/dist/{acp-IVY5HZR4.js → acp-J6EPN6TP.js} +6 -6
- package/dist/{agent-QANDY7FO.js → agent-LA65FOAB.js} +1 -1
- package/dist/anthropic-YP6DY2F3.js +4 -0
- package/dist/{chunk-UPNNYP7M.js → chunk-2UNWKNDU.js} +1 -1
- package/dist/{chunk-T4O4GQVL.js → chunk-675L7SRF.js} +98 -98
- package/dist/{chunk-VWUGGYUP.js → chunk-7CVY4FXY.js} +1 -1
- package/dist/{chunk-SOO5OXX2.js → chunk-CT773IEX.js} +3 -3
- package/dist/{chunk-RAS3ORX3.js → chunk-JEOQXHOX.js} +29 -29
- package/dist/chunk-M5H5EYXN.js +5 -0
- package/dist/{chunk-SAJCBGHL.js → chunk-P77AEADG.js} +1 -1
- package/dist/{chunk-XO7ITAWR.js → chunk-Y6COQ5UY.js} +1 -1
- package/dist/{chunk-RCXKUD3Y.js → chunk-ZQP5DTJA.js} +1 -1
- package/dist/{esm-ZTIYTMTS.js → esm-NCEEJIH3.js} +3 -3
- package/dist/lib/{agent-6FZX4P2Y.js → agent-KDWPLLAV.js} +5 -5
- package/dist/lib/{anthropic-IP23YZ3P.js → anthropic-OJALXK4E.js} +4 -6
- package/dist/lib/{chunk-O7ELJUEK.js → chunk-24L3QT3J.js} +8 -2
- package/dist/lib/{chunk-KA6POJKI.js → chunk-2DEH6DOX.js} +9 -11
- package/dist/lib/{chunk-I34MAQRE.js → chunk-6AKRDUQF.js} +6 -2
- package/dist/lib/{chunk-2VF3XTGH.js → chunk-77FSPN6Y.js} +148 -60
- package/dist/lib/{chunk-5TGXH7BX.js → chunk-7G4AI2PP.js} +5 -55
- package/dist/lib/{chunk-6OMQD7MK.js → chunk-7SU77J32.js} +9 -1
- package/dist/lib/{chunk-FFM2LB4C.js → chunk-EFNPK4SJ.js} +7 -2
- package/dist/lib/{chunk-QYBQT2DM.js → chunk-SS7OJYHN.js} +27 -9
- package/dist/lib/{chunk-AZRC67RW.js → chunk-WOMWIFSN.js} +2 -2
- package/dist/lib/{chunk-5DVQ64YL.js → chunk-ZF52ER22.js} +3 -3
- package/dist/lib/index.d.ts +69 -52
- package/dist/lib/index.js +331 -123
- package/dist/lib/{openai-EMJ6U4FW.js → openai-FB7BBZVN.js} +3 -3
- package/dist/lib/{permissions-KZ5ACZAX.js → permissions-BZRN4RES.js} +3 -3
- package/dist/lib/{providers-2CGZPBFI.js → providers-7ZGRBCQ4.js} +1 -1
- package/dist/lib/{sandbox-runtime-CCQ3X3SM.js → sandbox-runtime-QDN5SXPM.js} +1 -1
- package/dist/lib/{tool-filter-CKHZUUBQ.js → tool-filter-PY6XY254.js} +1 -1
- package/dist/main.js +223 -217
- package/dist/{openai-YXYO5OW6.js → openai-2FE77NB2.js} +14 -14
- package/dist/{permissions-VCDMNX3L.js → permissions-R7P7RWZU.js} +1 -1
- package/dist/{providers-HNMBGGW6.js → providers-EZFC2EPW.js} +1 -1
- package/dist/{server-ZHQILOBP.js → server-54LNMGWU.js} +1 -1
- package/package.json +19 -12
- package/postinstall.mjs +80 -0
- package/dist/anthropic-6YLT4JZR.js +0 -4
- package/dist/chunk-5VOCXSSX.js +0 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __yukinoCreateRequire } from "node:module";
|
|
3
3
|
const require = __yukinoCreateRequire(import.meta.url);
|
|
4
|
-
import{a,b,c,d,e,f}from"./chunk-
|
|
4
|
+
import{a,b,c,d,e,f}from"./chunk-ZQP5DTJA.js";import"./chunk-Y6COQ5UY.js";import"./chunk-2UNWKNDU.js";import"./chunk-GYBJR2RB.js";import"./chunk-7MKA3SHV.js";export{b as PathSandbox,f as PermissionChecker,d as RuleEngine,c as evaluateRules,a as extractContent,e as isSafeCommand};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __yukinoCreateRequire } from "node:module";
|
|
3
3
|
const require = __yukinoCreateRequire(import.meta.url);
|
|
4
|
-
import{b as a,c as b}from"./chunk-
|
|
4
|
+
import{b as a,c as b}from"./chunk-7CVY4FXY.js";import"./chunk-JFKC4VCA.js";import"./chunk-GYBJR2RB.js";import"./chunk-HMZQYFYG.js";import"./chunk-3QL446GD.js";import"./chunk-AGSYLE4E.js";import"./chunk-CU3IISCC.js";import"./chunk-VCIRD267.js";import"./chunk-7MKA3SHV.js";export{b as createTelemetryRuntime,a as parseExporterTypes};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __yukinoCreateRequire } from "node:module";
|
|
3
3
|
const require = __yukinoCreateRequire(import.meta.url);
|
|
4
|
-
import{b as a,c as b}from"./chunk-
|
|
4
|
+
import{b as a,c as b}from"./chunk-CT773IEX.js";import"./chunk-675L7SRF.js";import"./chunk-HLE7243Q.js";import"./chunk-JEOQXHOX.js";import"./chunk-7CVY4FXY.js";import"./chunk-JFKC4VCA.js";import"./chunk-P77AEADG.js";import"./chunk-OFC2GD5K.js";import"./chunk-M5H5EYXN.js";import"./chunk-ZQP5DTJA.js";import"./chunk-Y6COQ5UY.js";import"./chunk-2UNWKNDU.js";import"./chunk-GYBJR2RB.js";import"./chunk-L2BWSPCF.js";import"./chunk-HMZQYFYG.js";import"./chunk-3QL446GD.js";import"./chunk-AGSYLE4E.js";import"./chunk-CU3IISCC.js";import"./chunk-VCIRD267.js";import"./chunk-7MKA3SHV.js";export{b as RemoteServer,a as createRemoteAgent};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yukino.js/yukino",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-dev",
|
|
4
4
|
"description": "Yukino is a terminal-based AI coding agent. It provides an interactive UI (terminal user interface) for conversing with large language models, executing code, manipulating files, and orchestrating multi-agent workflows, all from the command line.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"dist",
|
|
27
|
+
"postinstall.mjs",
|
|
27
28
|
"README.md"
|
|
28
29
|
],
|
|
29
30
|
"type": "module",
|
|
@@ -41,10 +42,12 @@
|
|
|
41
42
|
"access": "public"
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
|
-
"@
|
|
45
|
-
"@agentclientprotocol/sdk": "^1.4.0",
|
|
45
|
+
"@agentclientprotocol/sdk": "^1.5.0",
|
|
46
46
|
"@anthropic-ai/sandbox-runtime": "^0.0.76",
|
|
47
47
|
"@anthropic-ai/sdk": "^0.104.2",
|
|
48
|
+
"@bufbuild/protobuf": "^2.15.0",
|
|
49
|
+
"@connectrpc/connect": "^2.2.0",
|
|
50
|
+
"@connectrpc/connect-node": "^2.2.0",
|
|
48
51
|
"@langfuse/otel": "^5.11.1",
|
|
49
52
|
"@langfuse/tracing": "^5.11.1",
|
|
50
53
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
@@ -66,7 +69,7 @@
|
|
|
66
69
|
"@opentelemetry/sdk-metrics": "^2.11.0",
|
|
67
70
|
"@opentelemetry/sdk-trace-base": "^2.11.0",
|
|
68
71
|
"@opentelemetry/semantic-conventions": "^1.43.0",
|
|
69
|
-
"@sentry/node": "^10.75.
|
|
72
|
+
"@sentry/node": "^10.75.1",
|
|
70
73
|
"ansi-escapes": "^7.3.0",
|
|
71
74
|
"ansi-regex": "^6.3.0",
|
|
72
75
|
"chalk": "^5.6.2",
|
|
@@ -78,7 +81,7 @@
|
|
|
78
81
|
"ink": "^7.1.1",
|
|
79
82
|
"js-yaml": "^4.3.2",
|
|
80
83
|
"koa": "^3.2.1",
|
|
81
|
-
"marked": "^18.0.
|
|
84
|
+
"marked": "^18.0.14",
|
|
82
85
|
"minimatch": "^10.2.6",
|
|
83
86
|
"node-emoji": "^2.2.0",
|
|
84
87
|
"openai": "^6.49.0",
|
|
@@ -90,12 +93,14 @@
|
|
|
90
93
|
"string-width": "^8.2.2",
|
|
91
94
|
"supports-hyperlinks": "^4.5.0",
|
|
92
95
|
"turndown": "^7.2.4",
|
|
93
|
-
"wrap-ansi": "^10.0.
|
|
96
|
+
"wrap-ansi": "^10.0.2",
|
|
94
97
|
"ws": "^8.21.3",
|
|
95
98
|
"zod": "^4.6.5"
|
|
96
99
|
},
|
|
97
100
|
"devDependencies": {
|
|
98
101
|
"@biomejs/biome": "2.4.15",
|
|
102
|
+
"@bufbuild/buf": "^1.73.0",
|
|
103
|
+
"@bufbuild/protoc-gen-es": "^2.15.0",
|
|
99
104
|
"@eslint/js": "^9.39.5",
|
|
100
105
|
"@tailwindcss/postcss": "^4.3.3",
|
|
101
106
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -112,14 +117,14 @@
|
|
|
112
117
|
"eslint-plugin-react-refresh": "^0.5.7",
|
|
113
118
|
"eslint-plugin-unicorn": "^65.0.1",
|
|
114
119
|
"globals": "^17.12.0",
|
|
115
|
-
"oxfmt": "^0.53.0",
|
|
116
120
|
"pino-pretty": "^13.1.3",
|
|
117
121
|
"postcss": "^8.5.28",
|
|
122
|
+
"prettier": "^3.9.8",
|
|
118
123
|
"tailwindcss": "^4.3.3",
|
|
119
124
|
"tsup": "^8.5.1",
|
|
120
|
-
"tsx": "^4.23.
|
|
125
|
+
"tsx": "^4.23.15",
|
|
121
126
|
"typescript": "^5.9.3",
|
|
122
|
-
"typescript-eslint": "^8.70.
|
|
127
|
+
"typescript-eslint": "^8.70.1",
|
|
123
128
|
"vitest": "^4.1.11"
|
|
124
129
|
},
|
|
125
130
|
"engines": {
|
|
@@ -130,17 +135,19 @@
|
|
|
130
135
|
"build:fe": "cd src/remote/fe && rm -rf ./dist && tsup",
|
|
131
136
|
"preview:fe": "pnpm dlx serve src/remote/fe/dist",
|
|
132
137
|
"dev": "tsx ./src/main.tsx",
|
|
133
|
-
"build": "rm -rf ./dist && tsup",
|
|
138
|
+
"build": "rm -rf ./dist && pnpm gen:pb && tsup",
|
|
134
139
|
"lint": "eslint --cache --quiet ./src ./tests",
|
|
135
140
|
"lint:fix": "eslint --cache --fix --quiet ./src ./tests",
|
|
136
141
|
"test": "vitest run --maxWorkers=2",
|
|
137
142
|
"test:watch": "vitest",
|
|
138
143
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
139
|
-
"format": "
|
|
144
|
+
"format": "prettier -w ./ --experimental-cli",
|
|
140
145
|
"happy": "pnpm typecheck && pnpm lint && pnpm build && pnpm test",
|
|
141
146
|
"happy:fix": "pnpm typecheck && pnpm format && pnpm lint:fix && pnpm build && pnpm test",
|
|
142
147
|
"add:user": "pnpm adduser --registry=https://registry.npmjs.org/",
|
|
143
148
|
"publish:latest": "pnpm publish --access public --registry=https://registry.npmjs.org/",
|
|
144
|
-
"publish:nightly": "pnpm publish --access public --registry=https://registry.npmjs.org/ --tag nightly"
|
|
149
|
+
"publish:nightly": "pnpm publish --access public --registry=https://registry.npmjs.org/ --tag nightly",
|
|
150
|
+
"gen:pb": "buf generate ../../yukino/pb --template ../../yukino/pb/buf.gen.yaml",
|
|
151
|
+
"postinstall": "node postinstall.mjs"
|
|
145
152
|
}
|
|
146
153
|
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Download yukino-code-${os}-${arch} from the fixed GitHub release into
|
|
2
|
+
// ~/.yukino/bin, the directory the CLI resolves the Go agent-bridge binary
|
|
3
|
+
// from. The single binary serves all three bridge transports, selected by its
|
|
4
|
+
// own --remote flag (stdio/rpc/ws).
|
|
5
|
+
//
|
|
6
|
+
// The release tag carries no version: every publish overwrites the same asset,
|
|
7
|
+
// so this always fetches the newest bridge build. Failures never block the
|
|
8
|
+
// install — the binary is only needed by the --remote=stdio/rpc/ws bridge
|
|
9
|
+
// transports, and a missing binary produces a targeted error at that point.
|
|
10
|
+
|
|
11
|
+
// @ts-check
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
chmodSync,
|
|
15
|
+
existsSync,
|
|
16
|
+
mkdirSync,
|
|
17
|
+
renameSync,
|
|
18
|
+
unlinkSync,
|
|
19
|
+
writeFileSync,
|
|
20
|
+
} from "node:fs";
|
|
21
|
+
import { homedir } from "node:os";
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
import { fileURLToPath } from "node:url";
|
|
24
|
+
|
|
25
|
+
const RELEASE_BASE =
|
|
26
|
+
"https://github.com/hangtiancheng/yukino-code/releases/download/binaries";
|
|
27
|
+
const BIN_DIR = path.join(homedir(), ".yukino", "bin");
|
|
28
|
+
|
|
29
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
// Inside the monorepo the developer builds the binary locally instead
|
|
31
|
+
// (pnpm build:yukino); downloading would just overwrite that local build.
|
|
32
|
+
if (existsSync(path.join(here, "..", "..", "release.js"))) {
|
|
33
|
+
console.log(
|
|
34
|
+
"postinstall: inside the yukino-code repo — skipping bridge binary download (run `pnpm build:yukino` to build it into ~/.yukino/bin).",
|
|
35
|
+
);
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { platform, arch } = process;
|
|
40
|
+
if (
|
|
41
|
+
!["linux", "darwin", "win32"].includes(platform) ||
|
|
42
|
+
!["x64", "arm64"].includes(arch)
|
|
43
|
+
) {
|
|
44
|
+
console.warn(
|
|
45
|
+
`postinstall: no prebuilt bridge binary for ${platform}-${arch} — skipping; the --remote=stdio/rpc/ws transports will not be available.`,
|
|
46
|
+
);
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
mkdirSync(BIN_DIR, { recursive: true });
|
|
51
|
+
|
|
52
|
+
const name = `yukino-code-${platform}-${arch}`;
|
|
53
|
+
const dest = path.join(BIN_DIR, name);
|
|
54
|
+
const temporary = `${dest}.part`;
|
|
55
|
+
try {
|
|
56
|
+
const res = await fetch(`${RELEASE_BASE}/${name}`, { redirect: "follow" });
|
|
57
|
+
if (!res.ok) {
|
|
58
|
+
throw new Error(`HTTP ${res.status}`);
|
|
59
|
+
}
|
|
60
|
+
writeFileSync(temporary, Buffer.from(await res.arrayBuffer()));
|
|
61
|
+
if (platform !== "win32") {
|
|
62
|
+
chmodSync(temporary, 0o755);
|
|
63
|
+
}
|
|
64
|
+
renameSync(temporary, dest);
|
|
65
|
+
console.log(`postinstall: downloaded ${name} -> ${dest}`);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
console.warn(
|
|
68
|
+
`postinstall: could not download ${name} (${err instanceof Error ? err.message : String(err)}); the --remote=stdio/rpc/ws bridge transports will not work until it is available.`,
|
|
69
|
+
);
|
|
70
|
+
} finally {
|
|
71
|
+
// The successful path already renamed the temp file away; only a failed
|
|
72
|
+
// download leaves it behind.
|
|
73
|
+
if (existsSync(temporary)) {
|
|
74
|
+
try {
|
|
75
|
+
unlinkSync(temporary);
|
|
76
|
+
} catch {
|
|
77
|
+
/* best effort */
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createRequire as __yukinoCreateRequire } from "node:module";
|
|
3
|
-
const require = __yukinoCreateRequire(import.meta.url);
|
|
4
|
-
import{g as I}from"./chunk-MDPSQ6L7.js";import{a as X,b as Z}from"./chunk-SAJCBGHL.js";import{a as Q}from"./chunk-OFC2GD5K.js";import{A as D,B as E,C as J,D as V,E as q,k as N,m as O,n as B,o as j,p as U,q as $,r as K,t as w,u as C,z as Y}from"./chunk-5VOCXSSX.js";import"./chunk-XO7ITAWR.js";import{f as R,k as F,l as H,m as z,n as k,o as G,s as W}from"./chunk-UPNNYP7M.js";import{D as P,f as S}from"./chunk-GYBJR2RB.js";import"./chunk-7MKA3SHV.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)}function se(o,t){if("input_schema"in o){let e=o,{cache_control:n,...s}=e;return t||delete s.type,{...s,...t?{type:"custom"}:{},...e.defer_loading!==!0&&n?{cache_control:n}:{}}}throw new Error("Anthropic received a tool schema serialized for another protocol.")}var v=R({module:"llm"});var re=3e3,ie=P.object({max_input_tokens:P.coerce.number()});async function ye(o){if(o.protocol!=="anthropic")return 0;let t=C(o),n=`${o.base_url.replace(/\/+$/,"")}/v1/models/${encodeURIComponent(o.model)}`,s=new AbortController,r=setTimeout(()=>{s.abort()},re);try{let c=await fetch(n,{method:"GET",headers:{"anthropic-version":"2023-06-01",...t?{"x-api-key":t}:{}},signal:s.signal});if(!c.ok)return 0;let p=await c.json(),{success:u,error:h,data:m}=await S(ie,p);if(!u)return v.warn({message:h.message},"model context window schema validation failed"),0;let g=m.max_input_tokens;return Math.max(g,0)}catch(c){return v.error({err:c},"failed to fetch model context window"),0}finally{clearTimeout(r)}}function T(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: ${W(t,"type","unknown")}`);return e})}function ae(o){let t=[];for(let e of o)if(e.role==="assistant"){let n=[];if(e.thinkingBlocks)for(let r of e.thinkingBlocks)n.push({type:"thinking",thinking:r.thinking,signature:r.signature});let s=typeof e.content=="string"?e.content:F(e.content);if(s&&n.push({type:"text",text:s}),e.toolUses)for(let r of e.toolUses)n.push({type:"tool_use",id:r.toolUseId,name:r.toolName==="ComputerUse"?"computer":r.toolName,input:r.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 s of e.toolResults)n.push({type:"tool_result",tool_use_id:s.toolUseId,is_error:s.isError,content:s.contentBlocks?.length?s.contentBlocks:s.content});e.content.length>0&&n.push(...T(e.content)),t.push({role:"user",content:n})}else{if(t.length===0){t.push({role:"user",content:T(e.content)});continue}let n=!1,s=t[t.length-1],r=s.content;s.role==="user"&&(typeof r=="string"||Array.isArray(r)&&r.length>0&&(r[0].type==="text"||r[0].type==="image"))&&(n=!0),n?(typeof r=="string"&&(r=s.content=r.trim().length>0?[{type:"text",text:r}]:[]),r.push(...T(e.content))):t.push({role:"user",content:T(e.content)})}return t}var ee=class{protocol="anthropic";client;model;thinkingLevel;systemPrompt;maxOutputTokens;config;useExplicitCustomToolType;constructor(t,e){let n=C(t);if(!n)throw new E("Anthropic API key not found, set ANTHROPIC_API_KEY in ~/.yukino/config.yaml, or via ANTHROPIC_API_KEY env variable.");this.client=new I({apiKey:n,baseURL:t.base_url}),this.useExplicitCustomToolType=Z(t.base_url),this.model=t.model,this.config={...t},this.thinkingLevel=O(t),this.systemPrompt=e,this.maxOutputTokens=w(t)}setSystemPrompt(t){this.systemPrompt=t}setMaxOutputTokens(t){this.config={...this.config,max_output_tokens:t},this.maxOutputTokens=w(this.config),this.setThinkingLevel(this.thinkingLevel)}setThinkingLevel(t){return this.thinkingLevel=K(this.config,t),this.thinkingLevel}getThinkingLevel(){return this.thinkingLevel}getSupportedThinkingLevels(){return $(this.config)}async*stream(t,e,n){let s=ae(Y(t.getMessages())),r=ne(e),c=e.map(l=>se(l,this.useExplicitCustomToolType));oe(c),le(s);let p={model:this.model,max_tokens:this.maxOutputTokens,stream:!0,system:[{type:"text",text:this.systemPrompt,cache_control:{type:"ephemeral"}}],messages:s,...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(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(B(l),this.maxOutputTokens-N)})}let h=0,m=0,g=0,x=0,M="end_turn",A="",b="",L=!1;try{let l=[...r?[X]:[]],te=this.client.messages.stream(p,{...n?{signal:n}:{},...l.length>0?{headers:{"anthropic-beta":l.join(",")}}:{}}),f="",_="",d="";for await(let a of te)switch(a.type){case"content_block_start":{let i=a.content_block;i.type==="thinking"?(L=!0,A="",b=""):i.type==="tool_use"&&(_=i.id,f=i.name==="computer"?"ComputerUse":i.name,d="",yield{type:"tool_call_start",toolName:f,toolId:_});break}case"content_block_delta":{let i=a.delta;i.type==="thinking_delta"?(A+=i.thinking,yield{type:"thinking_delta",text:i.thinking}):i.type==="signature_delta"?b+=i.signature:i.type==="text_delta"?yield{type:"text_delta",text:i.text}:i.type==="input_json_delta"&&(d+=i.partial_json,yield{type:"tool_call_delta",text:i.partial_json});break}case"content_block_stop":{if(L&&(yield{type:"thinking_complete",thinking:A,signature:b},L=!1),f){let i={};if(d)try{let y=JSON.parse(d);i=H(y)?z(y):{}}catch(y){v.error({err:y},"llm operation failed"),i={}}yield{type:"tool_call_complete",toolId:_,toolName:f,arguments:i},f="",_="",d=""}break}case"message_delta":{a.delta.stop_reason&&(M=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&&(g=a.usage.cache_read_input_tokens),a.usage.cache_creation_input_tokens&&(x=a.usage.cache_creation_input_tokens));break}case"message_start":{h=a.message.usage.input_tokens,m=a.message.usage.output_tokens,g=a.message.usage.cache_read_input_tokens??0,x=a.message.usage.cache_creation_input_tokens??0;break}}yield{type:"stream_end",stopReason:M,usage:{inputTokens:h,outputTokens:m,cacheReadInputTokens:g,cacheCreationInputTokens:x}}}catch(l){throw v.error({err:l},"llm operation failed"),ce(l)}}};function le(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 s=e.length-1;s>=0;s--)if(e[s].type!=="image"){n=e[s];break}Reflect.set(n,"cache_control",{type:"ephemeral"});return}}function ce(o){if(o instanceof I.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 E(`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 s=Number.parseInt(k(e));Number.isNaN(s)?n+=", please wait.":n+=`, retry after ${k(s)}s.`}else n+=", please wait.";return new J(n,e?k(e):void 0)}return new D(`Anthropic API error (${k(o.status)}): ${o.message}`)}return new V(`Network error: ${G(o)}`)}export{ee as AnthropicClient,ae as buildAnthropicMessages,ye as fetchModelContextWindow,le as markLastUserTailForCache,oe as markToolsForCache,ne as needsToolSearchBeta};
|
package/dist/chunk-5VOCXSSX.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createRequire as __yukinoCreateRequire } from "node:module";
|
|
3
|
-
const require = __yukinoCreateRequire(import.meta.url);
|
|
4
|
-
import{a as k,f as P}from"./chunk-UPNNYP7M.js";import{D as t,b,c as y}from"./chunk-GYBJR2RB.js";import{existsSync as L,readFileSync as O}from"fs";import{homedir as G}from"os";import{join as N}from"path";function h(e){return!!e._zod}function p(e,n){return h(e)?b(e,n):e.safeParse(n)}async function je(e,n){return h(e)?await y(e,n):await e.safeParseAsync(n)}function Le(e){if(!e)return;let n;if(h(e)?n=e._zod?.def?.shape:n=e.shape,!!n){if(typeof n=="function")try{return n()}catch{return}return n}}function Y(e){return e.length===0?"object root":e.reduce((n,o,r)=>r===0?String(o):typeof o=="number"?`${n}[${o}]`:`${n}.${o}`,"")}function v(e){if(e&&typeof e=="object"){if("issues"in e&&Array.isArray(e.issues)&&e.issues.length>0)return e.issues.map(n=>n.path?.length?`${n.message} at ${Y(n.path)}`:n.message).join(`
|
|
5
|
-
`);if("message"in e&&typeof e.message=="string")return e.message;try{return JSON.stringify(e)}catch{return String(e)}}return String(e)}function Oe(e){if(h(e)){let a=e._zod?.def;if(a){if(a.value!==void 0)return a.value;if(Array.isArray(a.values)&&a.values.length>0)return a.values[0]}}let o=e._def;if(o){if(o.value!==void 0)return o.value;if(Array.isArray(o.values)&&o.values.length>0)return o.values[0]}let r=e.value;if(r!==void 0)return r}var m=P({module:"config"}),I={anthropic:"ANTHROPIC_API_KEY",openai:"OPENAI_API_KEY","openai-compat":"OPENAI_API_KEY"};function W(e){return x.has(e)}var x=new Set(Object.keys(I)),l=class extends Error{constructor(n){super(n),this.name="ConfigError"}};function Z(){return N(G(),".yukino","config.yaml")}var _=["off","minimal","low","medium","high","xhigh","max"],d=t.enum(["none","minimal","low","medium","high","xhigh","max"]),X=t.enum(["low","medium","high","xhigh","max"]),q=t.strictObject({off:t.literal("none").nullable().optional(),minimal:d.nullable().optional(),low:d.nullable().optional(),medium:d.nullable().optional(),high:d.nullable().optional(),xhigh:d.nullable().optional(),max:d.nullable().optional()}),$=t.looseObject({name:t.string(),protocol:t.enum(["anthropic","openai","openai-compat"]),base_url:t.string(),model:t.string(),api_key:t.string().optional(),thinking:t.enum(_).optional(),reasoning:t.boolean().optional(),thinking_level_map:q.optional(),thinking_mode:t.enum(["budget","adaptive"]).optional(),context_window:t.coerce.number().optional(),max_output_tokens:t.coerce.number().optional()}),Q="high",E=1e6,C=128e3,ee={minimal:1024,low:2048,medium:8192,high:16384,xhigh:32768,max:65536},ne=1024,oe=1024;function Ve(e){return _.some(n=>n===e)}function te(e){return se(e,e.thinking??Q)}function Fe(e){return e==="off"?0:ee[e]}function z(e,n){if(n?.reasoning===!1)return null;if(e==="off")return"none";let o=n?.thinking_level_map?.[e];if(o!==void 0)return o;if(n?.protocol==="anthropic"&&n.thinking_mode==="adaptive"){if(e==="minimal")return"low";if(e==="xhigh")return"high"}return e}function re(e,n){let o=X.safeParse(z(e,n));return o.success?o.data:null}function ie(e){return e.reasoning===!1||e.protocol==="anthropic"&&e.thinking_mode!=="adaptive"&&U(e)<ne+oe?["off"]:_.filter(n=>{if(n==="off")return!0;if(e.protocol==="anthropic"&&e.thinking_mode==="adaptive")return re(n,e)!==null;let o=z(n,e);return o!==null&&o!=="none"})}function se(e,n){let o=ie(e),r="off";for(let i of _)if(o.includes(i)&&(r=i),i===n)break;return r}function T(e){return{...e,thinking:te(e),context_window:R(e),max_output_tokens:U(e)}}function R(e){return Number.isSafeInteger(e.context_window)&&(e.context_window??0)>0?e.context_window??E:E}function U(e){let n=e.max_output_tokens,o=Number.isSafeInteger(n)&&(n??0)>0?n??C:C;return Math.min(o,R(e))}function Be(e){if(e.api_key)return e.api_key;let n=W(e.protocol)?I[e.protocol]:"";return n?process.env[n]??"":""}var K=t.object({name:t.string(),command:t.string().optional(),args:t.array(t.string()).optional(),url:t.string().optional(),transport:t.string().optional(),headers:t.record(t.string(),t.string()).optional(),env:t.record(t.string(),t.string()).optional()}),D=t.object({id:t.string().optional(),event:t.string(),condition:t.string().optional(),action:t.object({type:t.string(),command:t.string().optional(),url:t.string().optional(),method:t.string().optional(),prompt:t.string().optional()}),reject:t.boolean().optional(),once:t.boolean().optional(),async:t.boolean().optional(),on_error:t.string().optional()}),V=t.object({enabled:t.boolean().optional(),backend:t.enum(["native","sandbox-runtime"]).optional(),auto_allow:t.boolean().optional(),network_enabled:t.boolean().optional()}),ae=t.looseObject({providers:t.array($),permission_mode:t.string().optional(),mcp_servers:t.array(K).default([]),hooks:t.array(D).default([]),sandbox:V.optional(),enable_coordinator_mode:t.boolean().optional(),enable_fork:t.boolean().optional()});function He(e){return e.enable_fork!==!1}function ce(e){return typeof e=="object"&&e!==null}function A(e){let n=O(e,"utf-8"),o=k.load(n);if(!ce(o))return m.error({path:e},"invalid yaml"),{providers:[],mcp_servers:[],hooks:[]};let r=p(ae,o);if(r.success){let c=r.data;return{...c,providers:c.providers.map(T)}}m.error({error:r.error},"config error");let i=[],a,f=[],s=[],u,S=!1,w=!0;if("providers"in o){let c=p(t.array($),o.providers);if(c.success)i=c.data.map(T);else throw new l(`Invalid provider configuration in ${e}: ${v(c.error)}`)}if("permission_mode"in o&&typeof o.permission_mode=="string"&&(a=o.permission_mode),"mcp_servers"in o){let c=p(t.array(K),o.mcp_servers);if(c.success)f=c.data;else throw new l(`Invalid MCP server configuration in ${e}: ${v(c.error)}`)}if("hooks"in o){let c=p(t.array(D),o.hooks);c.success&&(s=c.data)}if("sandbox"in o){let c=p(V,o.sandbox);if(c.success)u=c.data;else throw new l(`Invalid sandbox configuration in ${e}: ${v(c.error)}`)}return"enable_coordinator_mode"in o&&(S=!!o.enable_coordinator_mode),"enable_fork"in o&&(w=!!o.enable_fork),{providers:i,permission_mode:a,mcp_servers:f,hooks:s,sandbox:u,enable_coordinator_mode:S,enable_fork:w}}function M(e){if(e.providers.length===0)throw new l("At least one provider MUST be configured.");let n=["name","protocol","base_url","model"],o=new Map;for(let r=0;r<e.providers.length;r++){let i=e.providers[r],a={name:i.name,protocol:i.protocol,base_url:i.base_url,model:i.model},f=n.filter(u=>!a[u].trim());if(f.length>0)throw new l(`Provider #${String(r+1)}: missing fields: ${f.join(", ")}`);if(!x.has(i.protocol))throw new l(`Provider #${String(r+1)}: invalid protocol '${i.protocol}', MUST be one of: ${Array.from(x).join(", ")}`);let s=o.get(i.base_url);if(s!==void 0)throw new l(`Provider #${String(r+1)}: duplicate base_url '${i.base_url}' (already used by provider #${String(s+1)}).`);o.set(i.base_url,r)}}function j(e){let n=new Map;for(let o=0;o<e.mcp_servers.length;o++){let r=e.mcp_servers[o],i=`MCP server #${String(o+1)}`;if(!r.name.trim())throw new l(`${i}: name must not be empty.`);let a=n.get(r.name);if(a!==void 0)throw new l(`${i}: duplicate name '${r.name}' (already used by MCP server #${String(a+1)}).`);n.set(r.name,o);let f=!!r.command?.trim(),s=!!r.url?.trim();if(f===s)throw new l(`${i} '${r.name}': configure exactly one of command or url.`);if(f&&r.transport&&r.transport!=="stdio")throw new l(`${i} '${r.name}': command servers must use stdio.`);if(s&&r.transport&&!["http","sse"].includes(r.transport))throw new l(`${i} '${r.name}': URL transport must be http or sse.`)}}var le=".mcp.json",fe=t.looseObject({command:t.string().optional(),args:t.array(t.string()).optional(),env:t.record(t.string(),t.string()).optional(),type:t.enum(["stdio","sse","http"]).optional(),url:t.string().optional(),headers:t.record(t.string(),t.string()).optional()}),ue=t.looseObject({mcpServers:t.record(t.string(),t.unknown()).default({})});function pe(e,n){let o=n.type??(n.command!==void 0?"stdio":"http");return o==="stdio"?!n.command||n.url!==void 0?null:{name:e,command:n.command,args:n.args,env:n.env}:!n.url||n.command!==void 0?null:{name:e,url:n.url,transport:o,headers:n.headers}}function de(e){let n=N(e,le);if(!L(n))return[];let o;try{o=JSON.parse(O(n,"utf-8"))}catch(a){return m.error({err:a,path:n},"invalid .mcp.json"),[]}let r=p(ue,o);if(!r.success)return m.error({error:r.error,path:n},"invalid .mcp.json"),[];let i=[];for(let[a,f]of Object.entries(r.data.mcpServers)){let s=p(fe,f);if(!a.trim()||!s.success){m.warn({name:a,path:n,error:s.success?void 0:s.error},"skipping invalid .mcp.json server entry");continue}let u=pe(a,s.data);u?i.push(u):m.warn({name:a,path:n},"skipping invalid .mcp.json server entry")}return i}function Je(e,n){let o=de(n);if(o.length===0)return e;let r=new Set(e.mcp_servers.map(i=>i.name));return{...e,mcp_servers:[...e.mcp_servers,...o.filter(i=>!r.has(i.name))]}}function Ye(e,n={}){if(e){let i=A(e);return j(i),(!n.allowEmptyProviders||i.providers.length>0)&&M(i),i}let o=Z();if(!L(o)){if(n.allowEmptyProviders)return{providers:[],mcp_servers:[],hooks:[]};throw new l(`No config file found, expected ${o}.`)}let r=A(o);return j(r),(!n.allowEmptyProviders||r.providers.length>0)&&M(r),r}var me="Tool execution was interrupted. The tool may or may not have completed; verify before relying on its effects.",We="The user rejected this tool use. Nothing was changed (for file edits, the new content was NOT written).";function Ze(e){let n=[];for(let o=0;o<e.length;o++){let r=e[o];if(r.role==="assistant"&&r.toolUses?.length){n.push(r);let i=new Set(r.toolUses.map(s=>s.toolUseId)),a=[],f=[];for(;o+1<e.length;){let s=e[o+1];if(s.role!=="user"||!s.toolResults?.length||s.toolUses?.length)break;o++,f.push(s);for(let u of s.toolResults)i.delete(u.toolUseId)&&a.push(u)}for(let s of i)a.push({toolUseId:s,content:me,isError:!0});n.push({...f[0]??{role:"user",content:""},toolResults:a});for(let s of f.slice(1))(s.content.length>0||s.thinkingBlocks?.length)&&n.push({...s,toolResults:[]});continue}if((r.toolResults?.length??0)>0){if(r.content.length===0&&!r.toolUses?.length&&!r.thinkingBlocks?.length)continue;n.push({...r,toolResults:[]})}else n.push(r)}return n}var g=class extends Error{constructor(n){super(n),this.name="LLMError"}},F=class extends g{constructor(n){super(n),this.name="AuthenticationError"}},B=class extends g{retryAfter;constructor(n,o){super(n),this.name="RateLimitError",this.retryAfter=o}},H=class extends g{constructor(n){super(n),this.name="NetworkError"}},J=class extends g{constructor(n){super(n),this.name="ContextTooLongError"}};export{p as a,je as b,Le as c,Oe as d,Z as e,_ as f,$ as g,Q as h,E as i,C as j,oe as k,Ve as l,te as m,Fe as n,z as o,re as p,ie as q,se as r,R as s,U as t,Be as u,He as v,Je as w,Ye as x,We as y,Ze as z,g as A,F as B,B as C,H as D,J as E};
|