@kybernesis/brain-llm-claude 0.8.0 → 0.8.2
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/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -13,11 +13,32 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { ClaudeCallOpts, LLMProvider } from '@kybernesis/brain-core';
|
|
15
15
|
export type { ClaudeCallOpts, LLMProvider };
|
|
16
|
+
/** Why a `call()` resolved `null`, for the optional onError hook. */
|
|
17
|
+
export interface SubprocessFailure {
|
|
18
|
+
reason: 'spawn' | 'exit' | 'empty' | 'timeout';
|
|
19
|
+
/** Process exit code, when the failure came from a close event. */
|
|
20
|
+
code?: number | null;
|
|
21
|
+
/** Trimmed stderr preview (non-zero exits only). */
|
|
22
|
+
stderr?: string;
|
|
23
|
+
}
|
|
16
24
|
export interface SubprocessProviderOptions {
|
|
17
25
|
/** Claude CLI binary name or path. Defaults to 'claude'. */
|
|
18
26
|
binary?: string;
|
|
19
27
|
/** Working directory for the spawned subprocess. */
|
|
20
28
|
cwd?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Kill the subprocess (SIGTERM) and resolve `null` if it hasn't exited after
|
|
31
|
+
* this many ms. Default 60_000. Set to 0 to disable (not recommended — a hung
|
|
32
|
+
* `claude` would otherwise hang the caller forever).
|
|
33
|
+
*/
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Optional failure hook, called once before each `null` resolution. Without it
|
|
37
|
+
* failures degrade silently — a missing binary, a non-zero exit, an empty
|
|
38
|
+
* response and a timeout all look identical. Wire it to your logger to tell
|
|
39
|
+
* them apart. Do not log the prompt/output (may be large/sensitive).
|
|
40
|
+
*/
|
|
41
|
+
onError?: (info: SubprocessFailure) => void;
|
|
21
42
|
}
|
|
22
43
|
/**
|
|
23
44
|
* Create a subprocess-backed LLMProvider.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1E,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC;AAE5C,MAAM,WAAW,yBAAyB;IACxC,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,GAAG,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1E,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC;AAE5C,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IAC/C,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC7C;AAmBD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,GAAE,yBAA8B,GAAG,WAAW,CAwE1F;AAED,gEAAgE;AAChE,wBAAsB,iBAAiB,CAAC,MAAM,SAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAM3E"}
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,8 @@ function resolveModel(raw) {
|
|
|
38
38
|
export function createSubprocessProvider(opts = {}) {
|
|
39
39
|
const binary = opts.binary ?? 'claude';
|
|
40
40
|
const cwd = opts.cwd;
|
|
41
|
+
const timeoutMs = opts.timeoutMs ?? 60_000;
|
|
42
|
+
const onError = opts.onError;
|
|
41
43
|
return {
|
|
42
44
|
call(prompt, callOpts = {}) {
|
|
43
45
|
return new Promise((resolve) => {
|
|
@@ -46,6 +48,9 @@ export function createSubprocessProvider(opts = {}) {
|
|
|
46
48
|
if (callOpts.system) {
|
|
47
49
|
args.push('--system-prompt', String(callOpts.system));
|
|
48
50
|
}
|
|
51
|
+
// NOTE: callOpts.maxTokens has no `claude --print` equivalent — the CLI
|
|
52
|
+
// exposes no max-tokens flag (verified against `claude --help`), so it is
|
|
53
|
+
// intentionally unused here rather than silently mis-applied.
|
|
49
54
|
const proc = spawn(binary, args, {
|
|
50
55
|
env: { ...process.env, CLAUDECODE: '', CLAUDE_CODE_ENTRYPOINT: '' },
|
|
51
56
|
cwd,
|
|
@@ -53,7 +58,29 @@ export function createSubprocessProvider(opts = {}) {
|
|
|
53
58
|
});
|
|
54
59
|
const out = [];
|
|
55
60
|
const err = [];
|
|
61
|
+
let settled = false;
|
|
62
|
+
let timer = null;
|
|
63
|
+
const finish = (value, failure) => {
|
|
64
|
+
if (settled)
|
|
65
|
+
return;
|
|
66
|
+
settled = true;
|
|
67
|
+
if (timer)
|
|
68
|
+
clearTimeout(timer);
|
|
69
|
+
out.length = 0;
|
|
70
|
+
err.length = 0;
|
|
71
|
+
if (failure)
|
|
72
|
+
onError?.(failure);
|
|
73
|
+
resolve(value);
|
|
74
|
+
};
|
|
75
|
+
if (timeoutMs > 0) {
|
|
76
|
+
timer = setTimeout(() => {
|
|
77
|
+
proc.kill('SIGTERM');
|
|
78
|
+
finish(null, { reason: 'timeout' });
|
|
79
|
+
}, timeoutMs);
|
|
80
|
+
}
|
|
56
81
|
if (proc.stdin) {
|
|
82
|
+
// Swallow EPIPE when the proc exits before we finish writing.
|
|
83
|
+
proc.stdin.on('error', () => { });
|
|
57
84
|
proc.stdin.write(prompt);
|
|
58
85
|
proc.stdin.end();
|
|
59
86
|
}
|
|
@@ -61,12 +88,19 @@ export function createSubprocessProvider(opts = {}) {
|
|
|
61
88
|
proc.stdout.on('data', (c) => out.push(c));
|
|
62
89
|
if (proc.stderr)
|
|
63
90
|
proc.stderr.on('data', (c) => err.push(c));
|
|
64
|
-
proc.on('error', () => {
|
|
91
|
+
proc.on('error', () => finish(null, { reason: 'spawn' }));
|
|
65
92
|
proc.on('close', (code) => {
|
|
66
93
|
const text = Buffer.concat(out).toString().trim();
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
94
|
+
const stderr = Buffer.concat(err).toString().trim();
|
|
95
|
+
if (code === 0 && text) {
|
|
96
|
+
finish(text);
|
|
97
|
+
}
|
|
98
|
+
else if (code === 0) {
|
|
99
|
+
finish(null, { reason: 'empty', code });
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
finish(null, { reason: 'exit', code, stderr: stderr.slice(0, 500) });
|
|
103
|
+
}
|
|
70
104
|
});
|
|
71
105
|
});
|
|
72
106
|
},
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAoC3C,MAAM,aAAa,GAA2B;IAC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C,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAAM,GAAG,QAAQ;IACvD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC/D,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACvC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kybernesis/brain-llm-claude",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Claude subprocess LLM provider for brain-core",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "David Cruwys (AppyDave)",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"README.md"
|
|
28
28
|
],
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@kybernesis/brain-core": "0.8.
|
|
30
|
+
"@kybernesis/brain-core": "0.8.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@kybernesis/brain-core": "0.8.
|
|
33
|
+
"@kybernesis/brain-core": "0.8.2"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|