@shrkcrft/ai 0.1.0-alpha.21 → 0.1.0-alpha.23
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/gemini/gemini-provider.d.ts.map +1 -1
- package/dist/gemini/gemini-provider.js +6 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/provider-resolver.js +7 -0
- package/package.json +3 -3
- package/dist/claude/claude-cli-adapter.d.ts +0 -17
- package/dist/claude/claude-cli-adapter.d.ts.map +0 -1
- package/dist/claude/claude-cli-adapter.js +0 -52
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini-provider.d.ts","sourceRoot":"","sources":["../../src/gemini/gemini-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAkC,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAErG;;;;;;;;;;;;;GAaG;AACH,qBAAa,cAAe,SAAQ,kBAAkB;IACpD,QAAQ,CAAC,EAAE,YAAY;IACvB,QAAQ,CAAC,IAAI,0BAA0B;IAEvC,OAAO,IAAI,OAAO;IAIZ,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"gemini-provider.d.ts","sourceRoot":"","sources":["../../src/gemini/gemini-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAkC,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAErG;;;;;;;;;;;;;GAaG;AACH,qBAAa,cAAe,SAAQ,kBAAkB;IACpD,QAAQ,CAAC,EAAE,YAAY;IACvB,QAAQ,CAAC,IAAI,0BAA0B;IAEvC,OAAO,IAAI,OAAO;IAIZ,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;CA6ExE"}
|
|
@@ -47,10 +47,14 @@ export class GeminiProvider extends AbstractAiProvider {
|
|
|
47
47
|
body.systemInstruction = { role: 'system', parts: [{ text: systemInstructionText }] };
|
|
48
48
|
}
|
|
49
49
|
try {
|
|
50
|
-
|
|
50
|
+
// Pass the API key via the `x-goog-api-key` header rather than a
|
|
51
|
+
// `?key=` query param (mirrors ClaudeProvider's `x-api-key` form). A
|
|
52
|
+
// key in the URL leaks into proxy logs, server access logs, and the
|
|
53
|
+
// `catch` below (which reports `e.message`, often containing the URL).
|
|
54
|
+
const url = `${baseUrl}/v1beta/models/${encodeURIComponent(model)}:generateContent`;
|
|
51
55
|
const res = await fetch(url, {
|
|
52
56
|
method: 'POST',
|
|
53
|
-
headers: { 'content-type': 'application/json' },
|
|
57
|
+
headers: { 'content-type': 'application/json', 'x-goog-api-key': apiKey },
|
|
54
58
|
body: JSON.stringify(body),
|
|
55
59
|
});
|
|
56
60
|
if (!res.ok) {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export * from './ai-provider.js';
|
|
|
2
2
|
export * from './ai-request.js';
|
|
3
3
|
export * from './prompt/prompt-builder.js';
|
|
4
4
|
export * from './claude/claude-provider.js';
|
|
5
|
-
export * from './claude/claude-cli-adapter.js';
|
|
6
5
|
export * from './gemini/gemini-provider.js';
|
|
7
6
|
export * from './ollama/ollama-provider.js';
|
|
8
7
|
export * from './llamacpp/llama-cpp-provider.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,wBAAwB,CAAC;AACvC,cAAc,oCAAoC,CAAC;AACnD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ export * from "./ai-provider.js";
|
|
|
2
2
|
export * from "./ai-request.js";
|
|
3
3
|
export * from "./prompt/prompt-builder.js";
|
|
4
4
|
export * from "./claude/claude-provider.js";
|
|
5
|
-
export * from "./claude/claude-cli-adapter.js";
|
|
6
5
|
export * from "./gemini/gemini-provider.js";
|
|
7
6
|
export * from "./ollama/ollama-provider.js";
|
|
8
7
|
export * from "./llamacpp/llama-cpp-provider.js";
|
|
@@ -47,6 +47,13 @@ function normaliseKind(kind) {
|
|
|
47
47
|
const known = new Set(['claude', 'gemini', 'ollama', 'llamacpp']);
|
|
48
48
|
if (kind !== undefined) {
|
|
49
49
|
const explicit = kind.trim().toLowerCase();
|
|
50
|
+
// An explicit `auto` is itself a request — the user is asking for the
|
|
51
|
+
// local-first chain. It must NOT be overridden by AI_PROVIDER (which
|
|
52
|
+
// could be `claude`/`gemini` and would silently ship the deterministic
|
|
53
|
+
// seed — CLAUDE.md + knowledge + file paths — off-machine to a hosted
|
|
54
|
+
// API). AI_PROVIDER is consulted ONLY when no kind was passed at all.
|
|
55
|
+
if (explicit === 'auto')
|
|
56
|
+
return 'auto';
|
|
50
57
|
if (known.has(explicit))
|
|
51
58
|
return explicit;
|
|
52
59
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shrkcrft/ai",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.23",
|
|
4
4
|
"description": "SharkCraft local LLM provider abstraction: Ollama (HTTP) + llama.cpp (in-process) + multi-pass enhancement pipeline.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SharkCraft contributors",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@shrkcrft/core": "^0.1.0-alpha.
|
|
47
|
-
"@shrkcrft/context": "^0.1.0-alpha.
|
|
46
|
+
"@shrkcrft/core": "^0.1.0-alpha.23",
|
|
47
|
+
"@shrkcrft/context": "^0.1.0-alpha.23",
|
|
48
48
|
"node-llama-cpp": "^3.16.0"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type AppError, type Result } from '@shrkcrft/core';
|
|
2
|
-
import { AbstractAiProvider } from '../ai-provider.js';
|
|
3
|
-
import type { IAiRequest, IAiResponse } from '../ai-request.js';
|
|
4
|
-
/**
|
|
5
|
-
* Optional adapter that shells out to a local `claude` CLI binary.
|
|
6
|
-
* It assumes the binary supports `--print --output-format=text`. If it does not,
|
|
7
|
-
* isReady() returns false and send() returns an actionable error.
|
|
8
|
-
*/
|
|
9
|
-
export declare class ClaudeCliAdapter extends AbstractAiProvider {
|
|
10
|
-
readonly id = "claude-cli";
|
|
11
|
-
readonly name = "Claude (local CLI)";
|
|
12
|
-
private readonly cliPath;
|
|
13
|
-
constructor(cliPath?: string);
|
|
14
|
-
isReady(): boolean;
|
|
15
|
-
send(request: IAiRequest): Promise<Result<IAiResponse, AppError>>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=claude-cli-adapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claude-cli-adapter.d.ts","sourceRoot":"","sources":["../../src/claude/claude-cli-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEhG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEhE;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,kBAAkB;IACtD,QAAQ,CAAC,EAAE,gBAAgB;IAC3B,QAAQ,CAAC,IAAI,wBAAwB;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,SAAW;IAK9B,OAAO,IAAI,OAAO;IAKZ,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;CAgDxE"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { AppErrorImpl, ERROR_CODES, err, ok } from '@shrkcrft/core';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
|
-
import { AbstractAiProvider } from "../ai-provider.js";
|
|
4
|
-
/**
|
|
5
|
-
* Optional adapter that shells out to a local `claude` CLI binary.
|
|
6
|
-
* It assumes the binary supports `--print --output-format=text`. If it does not,
|
|
7
|
-
* isReady() returns false and send() returns an actionable error.
|
|
8
|
-
*/
|
|
9
|
-
export class ClaudeCliAdapter extends AbstractAiProvider {
|
|
10
|
-
id = 'claude-cli';
|
|
11
|
-
name = 'Claude (local CLI)';
|
|
12
|
-
cliPath;
|
|
13
|
-
constructor(cliPath = 'claude') {
|
|
14
|
-
super();
|
|
15
|
-
this.cliPath = cliPath;
|
|
16
|
-
}
|
|
17
|
-
isReady() {
|
|
18
|
-
// Best-effort. The actual check happens during send().
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
async send(request) {
|
|
22
|
-
const prompt = request.messages.map((m) => `[${m.role}] ${m.content}`).join('\n\n');
|
|
23
|
-
return await new Promise((resolve) => {
|
|
24
|
-
try {
|
|
25
|
-
const proc = spawn(this.cliPath, ['--print', '--output-format=text'], {
|
|
26
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
27
|
-
});
|
|
28
|
-
let stdout = '';
|
|
29
|
-
let stderr = '';
|
|
30
|
-
proc.stdout.on('data', (b) => (stdout += b.toString('utf8')));
|
|
31
|
-
proc.stderr.on('data', (b) => (stderr += b.toString('utf8')));
|
|
32
|
-
proc.on('error', (e) => {
|
|
33
|
-
resolve(err(new AppErrorImpl(ERROR_CODES.IO_ERROR, `Failed to spawn claude CLI at "${this.cliPath}": ${e.message}`, { suggestion: 'Install Claude Code or pass a different cliPath', cause: e })));
|
|
34
|
-
});
|
|
35
|
-
proc.on('close', (code) => {
|
|
36
|
-
if (code === 0) {
|
|
37
|
-
resolve(ok({ content: stdout.trim(), model: 'claude-cli' }));
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
resolve(err(new AppErrorImpl(ERROR_CODES.IO_ERROR, `claude CLI exited with ${code}: ${stderr.slice(0, 500)}`)));
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
proc.stdin.end(prompt);
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
resolve(err(new AppErrorImpl(ERROR_CODES.IO_ERROR, `Failed to invoke claude CLI: ${e.message}`, {
|
|
47
|
-
cause: e,
|
|
48
|
-
})));
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|