@neurouter/evals 0.0.0-stage → 0.1.0
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/LICENSE +202 -0
- package/NOTICE +10 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/check.d.ts +41 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +187 -0
- package/dist/check.js.map +1 -0
- package/dist/generate.d.ts +105 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +187 -0
- package/dist/generate.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/judge.d.ts +33 -0
- package/dist/judge.d.ts.map +1 -0
- package/dist/judge.js +47 -0
- package/dist/judge.js.map +1 -0
- package/dist/llm/anthropic.d.ts +18 -0
- package/dist/llm/anthropic.d.ts.map +1 -0
- package/dist/llm/anthropic.js +47 -0
- package/dist/llm/anthropic.js.map +1 -0
- package/dist/llm/factory.d.ts +49 -0
- package/dist/llm/factory.d.ts.map +1 -0
- package/dist/llm/factory.js +92 -0
- package/dist/llm/factory.js.map +1 -0
- package/dist/llm/fake.d.ts +36 -0
- package/dist/llm/fake.d.ts.map +1 -0
- package/dist/llm/fake.js +75 -0
- package/dist/llm/fake.js.map +1 -0
- package/dist/llm/gemini.d.ts +43 -0
- package/dist/llm/gemini.d.ts.map +1 -0
- package/dist/llm/gemini.js +147 -0
- package/dist/llm/gemini.js.map +1 -0
- package/dist/llm/index.d.ts +8 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +8 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/openai.d.ts +39 -0
- package/dist/llm/openai.d.ts.map +1 -0
- package/dist/llm/openai.js +145 -0
- package/dist/llm/openai.js.map +1 -0
- package/dist/llm/stub.d.ts +36 -0
- package/dist/llm/stub.d.ts.map +1 -0
- package/dist/llm/stub.js +430 -0
- package/dist/llm/stub.js.map +1 -0
- package/dist/llm/types.d.ts +121 -0
- package/dist/llm/types.d.ts.map +1 -0
- package/dist/llm/types.js +59 -0
- package/dist/llm/types.js.map +1 -0
- package/dist/mcp.d.ts +42 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +50 -0
- package/dist/mcp.js.map +1 -0
- package/dist/prompts.d.ts +18 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +38 -0
- package/dist/prompts.js.map +1 -0
- package/dist/report.d.ts +57 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +65 -0
- package/dist/report.js.map +1 -0
- package/dist/rng.d.ts +9 -0
- package/dist/rng.d.ts.map +1 -0
- package/dist/rng.js +45 -0
- package/dist/rng.js.map +1 -0
- package/dist/run.d.ts +82 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +275 -0
- package/dist/run.js.map +1 -0
- package/dist/score.d.ts +34 -0
- package/dist/score.d.ts.map +1 -0
- package/dist/score.js +154 -0
- package/dist/score.js.map +1 -0
- package/dist/suggest.d.ts +82 -0
- package/dist/suggest.d.ts.map +1 -0
- package/dist/suggest.js +239 -0
- package/dist/suggest.js.map +1 -0
- package/dist/types.d.ts +223 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/yaml-emit.d.ts +3 -0
- package/dist/yaml-emit.d.ts.map +1 -0
- package/dist/yaml-emit.js +47 -0
- package/dist/yaml-emit.js.map +1 -0
- package/package.json +55 -4
- package/README.md +0 -3
package/dist/judge.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type LlmClient } from './llm/types.js';
|
|
2
|
+
import type { AttemptRecord, EvalTask, JudgeResult } from './types.js';
|
|
3
|
+
export declare const JUDGE_SCHEMA: {
|
|
4
|
+
readonly type: "object";
|
|
5
|
+
readonly properties: {
|
|
6
|
+
readonly score: {
|
|
7
|
+
readonly type: "number";
|
|
8
|
+
};
|
|
9
|
+
readonly verdict: {
|
|
10
|
+
readonly type: "string";
|
|
11
|
+
readonly enum: readonly ["pass", "fail"];
|
|
12
|
+
};
|
|
13
|
+
readonly reasons: {
|
|
14
|
+
readonly type: "array";
|
|
15
|
+
readonly items: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
readonly required: readonly ["score", "verdict", "reasons"];
|
|
21
|
+
readonly additionalProperties: false;
|
|
22
|
+
};
|
|
23
|
+
export declare function needsJudge(task: EvalTask): boolean;
|
|
24
|
+
/** One judge call per attempt (§15.5): rubric + criteria + final answer + a compact call list. */
|
|
25
|
+
export declare function judgeAttempt(opts: {
|
|
26
|
+
llm: LlmClient;
|
|
27
|
+
model: string;
|
|
28
|
+
task: EvalTask;
|
|
29
|
+
record: AttemptRecord;
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}): Promise<JudgeResult>;
|
|
32
|
+
export declare function normalizeJudge(raw: unknown): JudgeResult;
|
|
33
|
+
//# sourceMappingURL=judge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"judge.d.ts","sourceRoot":"","sources":["../src/judge.ts"],"names":[],"mappings":"AAEA,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEvE,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;CASf,CAAC;AAEX,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAElD;AAED,kGAAkG;AAClG,wBAAsB,YAAY,CAAC,IAAI,EAAE;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAoB7J;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,CAMxD"}
|
package/dist/judge.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { JUDGE_PASS_SCORE } from '@neurouter/shared';
|
|
2
|
+
import { JUDGE_MARKER, JUDGE_PROMPT_VERSION, JUDGE_SYSTEM, markerMessage } from './prompts.js';
|
|
3
|
+
import { parseJsonText, textOf } from './llm/types.js';
|
|
4
|
+
export const JUDGE_SCHEMA = {
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
score: { type: 'number' },
|
|
8
|
+
verdict: { type: 'string', enum: ['pass', 'fail'] },
|
|
9
|
+
reasons: { type: 'array', items: { type: 'string' } },
|
|
10
|
+
},
|
|
11
|
+
required: ['score', 'verdict', 'reasons'],
|
|
12
|
+
additionalProperties: false,
|
|
13
|
+
};
|
|
14
|
+
export function needsJudge(task) {
|
|
15
|
+
return task.assertions.some((a) => a.type === 'judge');
|
|
16
|
+
}
|
|
17
|
+
/** One judge call per attempt (§15.5): rubric + criteria + final answer + a compact call list. */
|
|
18
|
+
export async function judgeAttempt(opts) {
|
|
19
|
+
const criteria = opts.task.assertions.filter((a) => a.type === 'judge').map((a) => a.criterion);
|
|
20
|
+
const input = {
|
|
21
|
+
prompt: opts.task.prompt,
|
|
22
|
+
rubric: opts.task.rubric,
|
|
23
|
+
criteria,
|
|
24
|
+
finalAnswer: opts.record.finalAnswer.slice(0, 8000),
|
|
25
|
+
calls: opts.record.calls.slice(0, 60).map((c) => ({ tool: c.tool, args: truncateJson(c.arguments, 300), status: c.status })),
|
|
26
|
+
};
|
|
27
|
+
const res = await opts.llm.create({
|
|
28
|
+
model: opts.model,
|
|
29
|
+
max_tokens: 2000,
|
|
30
|
+
system: JUDGE_SYSTEM,
|
|
31
|
+
messages: [{ role: 'user', content: markerMessage(JUDGE_MARKER, JUDGE_PROMPT_VERSION, input, 'Grade the agent against the rubric and criteria.') }],
|
|
32
|
+
output_config: { effort: 'low', format: { type: 'json_schema', schema: JUDGE_SCHEMA } },
|
|
33
|
+
}, opts.signal ? { signal: opts.signal } : {});
|
|
34
|
+
return normalizeJudge(parseJsonText(textOf(res)));
|
|
35
|
+
}
|
|
36
|
+
export function normalizeJudge(raw) {
|
|
37
|
+
const o = (raw ?? {});
|
|
38
|
+
const score = Math.max(0, Math.min(1, Number(o.score) || 0));
|
|
39
|
+
const verdict = o.verdict === 'pass' && score >= JUDGE_PASS_SCORE ? 'pass' : 'fail';
|
|
40
|
+
const reasons = Array.isArray(o.reasons) ? o.reasons.map(String).slice(0, 3) : [];
|
|
41
|
+
return { score, verdict, reasons };
|
|
42
|
+
}
|
|
43
|
+
function truncateJson(v, max) {
|
|
44
|
+
const s = JSON.stringify(v) ?? '';
|
|
45
|
+
return s.length > max ? `${s.slice(0, max)}…` : s;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=judge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"judge.js","sourceRoot":"","sources":["../src/judge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkB,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,EAAkB,MAAM,gBAAgB,CAAC;AAGvE,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzB,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;QACnD,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ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AAM,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAClC,OAAO,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type LlmClient, type LlmCreateOptions, type LlmRequest, type LlmResponse } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Real adapter over `@anthropic-ai/sdk` 1.14.0. `output_config` (effort, format) and top-level
|
|
4
|
+
* `cache_control` are typed params of `messages.create`; `fallbacks` exists only on the beta
|
|
5
|
+
* endpoint (`client.beta.messages.create` with `betas: ['server-side-fallback-2026-07-01']`).
|
|
6
|
+
*/
|
|
7
|
+
export declare class AnthropicLlmClient implements LlmClient {
|
|
8
|
+
readonly provider: "anthropic";
|
|
9
|
+
private readonly client;
|
|
10
|
+
constructor(opts: {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
baseURL?: string;
|
|
13
|
+
maxRetries?: number;
|
|
14
|
+
});
|
|
15
|
+
create(req: LlmRequest, opts?: LlmCreateOptions): Promise<LlmResponse>;
|
|
16
|
+
}
|
|
17
|
+
export declare function mapSdkError(err: unknown): Error;
|
|
18
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/llm/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,EAA2D,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE/J;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,SAAS;IAClD,QAAQ,CAAC,QAAQ,EAAG,WAAW,CAAU;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBAEvB,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;IAKrE,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,GAAE,gBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC;CAejF;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAS/C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import { FALLBACK_BETA, LlmError, LlmKeyError, LlmRateLimitError } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Real adapter over `@anthropic-ai/sdk` 1.14.0. `output_config` (effort, format) and top-level
|
|
5
|
+
* `cache_control` are typed params of `messages.create`; `fallbacks` exists only on the beta
|
|
6
|
+
* endpoint (`client.beta.messages.create` with `betas: ['server-side-fallback-2026-07-01']`).
|
|
7
|
+
*/
|
|
8
|
+
export class AnthropicLlmClient {
|
|
9
|
+
provider = 'anthropic';
|
|
10
|
+
client;
|
|
11
|
+
constructor(opts) {
|
|
12
|
+
if (!opts.apiKey)
|
|
13
|
+
throw new LlmKeyError();
|
|
14
|
+
this.client = new Anthropic({ apiKey: opts.apiKey, ...(opts.baseURL ? { baseURL: opts.baseURL } : {}), maxRetries: opts.maxRetries ?? 2 });
|
|
15
|
+
}
|
|
16
|
+
async create(req, opts = {}) {
|
|
17
|
+
const { fallbacks, ...rest } = req;
|
|
18
|
+
const betas = [...(opts.betas ?? [])];
|
|
19
|
+
if (fallbacks && !betas.includes(FALLBACK_BETA))
|
|
20
|
+
betas.push(FALLBACK_BETA);
|
|
21
|
+
try {
|
|
22
|
+
if (betas.length) {
|
|
23
|
+
const res = await this.client.beta.messages.create({ ...rest, ...(fallbacks ? { fallbacks } : {}), betas }, opts.signal ? { signal: opts.signal } : undefined);
|
|
24
|
+
return res;
|
|
25
|
+
}
|
|
26
|
+
const res = await this.client.messages.create(rest, opts.signal ? { signal: opts.signal } : undefined);
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
throw mapSdkError(err);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function mapSdkError(err) {
|
|
35
|
+
if (err instanceof Anthropic.AuthenticationError || err instanceof Anthropic.PermissionDeniedError)
|
|
36
|
+
return new LlmKeyError(err.message);
|
|
37
|
+
if (err instanceof Anthropic.RateLimitError) {
|
|
38
|
+
const ra = Number(err.headers?.get?.('retry-after'));
|
|
39
|
+
return new LlmRateLimitError(err.message, Number.isFinite(ra) && ra > 0 ? ra * 1000 : null);
|
|
40
|
+
}
|
|
41
|
+
if (err instanceof Anthropic.APIUserAbortError)
|
|
42
|
+
return err;
|
|
43
|
+
if (err instanceof Anthropic.APIError)
|
|
44
|
+
return new LlmError(err.message, typeof err.status === 'number' ? err.status : null);
|
|
45
|
+
return err instanceof Error ? err : new LlmError(String(err));
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/llm/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,iBAAiB,EAA4E,MAAM,YAAY,CAAC;AAE/J;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACpB,QAAQ,GAAG,WAAoB,CAAC;IACxB,MAAM,CAAY;IAEnC,YAAY,IAA+D;QACzE,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,WAAW,EAAE,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,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AW,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,IAAI,GAAG,YAAY,SAAS,CAAC,mBAAmB,IAAI,GAAG,YAAY,SAAS,CAAC,qBAAqB;QAAE,OAAO,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACxI,IAAI,GAAG,YAAY,SAAS,CAAC,cAAc,EAAE,CAAC;QAC5C,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;QACrD,OAAO,IAAI,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC9F,CAAC;IACD,IAAI,GAAG,YAAY,SAAS,CAAC,iBAAiB;QAAE,OAAO,GAAG,CAAC;IAC3D,IAAI,GAAG,YAAY,SAAS,CAAC,QAAQ;QAAE,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC5H,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type LlmProviderKind } from '@neurouter/shared';
|
|
2
|
+
import { type LlmClient, type LlmCreateOptions, type LlmRequest, type LlmResponse } from './types.js';
|
|
3
|
+
export type LlmProvider = LlmProviderKind | 'stub' | 'fake';
|
|
4
|
+
/** Per-provider API keys (null/undefined = not configured). */
|
|
5
|
+
export type LlmKeys = Partial<Record<LlmProviderKind, string | null | undefined>>;
|
|
6
|
+
export interface CreateLlmClientOptions {
|
|
7
|
+
provider: LlmProvider;
|
|
8
|
+
apiKey?: string | null;
|
|
9
|
+
/** fixture dir for `fake`. */
|
|
10
|
+
fakeDir?: string;
|
|
11
|
+
baseURL?: string;
|
|
12
|
+
nodeEnv?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Explicit provider selection: the stub and the fake are never picked implicitly. */
|
|
15
|
+
export declare function createLlmClient(opts: CreateLlmClientOptions): LlmClient;
|
|
16
|
+
/**
|
|
17
|
+
* Routes each request to the provider its model belongs to (`gpt-*`/`o<digit>*` → OpenAI,
|
|
18
|
+
* `claude-*` → Anthropic, `gemini-*` → Gemini, or an explicit `provider:model`), creating one SDK
|
|
19
|
+
* client per provider on first use. A model whose provider has no key fails with `LlmKeyError`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class RoutingLlmClient implements LlmClient {
|
|
22
|
+
private readonly keys;
|
|
23
|
+
readonly provider: LlmProviderKind;
|
|
24
|
+
private readonly clients;
|
|
25
|
+
private readonly create_;
|
|
26
|
+
constructor(keys: LlmKeys, opts?: {
|
|
27
|
+
defaultModel?: string;
|
|
28
|
+
create?: (provider: LlmProviderKind, apiKey: string) => LlmClient;
|
|
29
|
+
});
|
|
30
|
+
/** The provider and bare model id a model reference resolves to (throws when unroutable or keyless). */
|
|
31
|
+
resolve(modelRef: string): {
|
|
32
|
+
provider: LlmProviderKind;
|
|
33
|
+
model: string;
|
|
34
|
+
};
|
|
35
|
+
hasKeyFor(modelRef: string): boolean;
|
|
36
|
+
create(req: LlmRequest, opts?: LlmCreateOptions): Promise<LlmResponse>;
|
|
37
|
+
}
|
|
38
|
+
/** Keys from the environment (OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY), overlaid by `stored` where env is unset. */
|
|
39
|
+
export declare function keysFromEnv(env: Record<string, string | undefined>, stored?: LlmKeys): LlmKeys;
|
|
40
|
+
/**
|
|
41
|
+
* Provider from the environment: `NEUROUTER_EVAL_FAKE_LLM=<dir>` (tests) → fake;
|
|
42
|
+
* `NEUROUTER_EVAL_LLM=stub` → deterministic stub; otherwise a router over the providers that have
|
|
43
|
+
* a key (env wins over `stored`; a bare string is a legacy stored Anthropic key). No key at all →
|
|
44
|
+
* `LlmKeyError`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function llmFromEnv(env?: Record<string, string | undefined>, stored?: LlmKeys | string | null, opts?: {
|
|
47
|
+
defaultModel?: string;
|
|
48
|
+
}): LlmClient;
|
|
49
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/llm/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAMhI,OAAO,EAAyB,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7H,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAE5D,+DAA+D;AAC/D,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC;AAElF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,IAAI,EAAE,sBAAsB,GAAG,SAAS,CAiBvE;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,SAAS;IAM9C,OAAO,CAAC,QAAQ,CAAC,IAAI;IALvB,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyC;IACjE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2D;gBAGhE,IAAI,EAAE,OAAO,EAC9B,IAAI,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,KAAK,SAAS,CAAA;KAAO;IAMzG,wGAAwG;IACxG,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAOvE,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAK9B,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC;CAS7E;AAED,8HAA8H;AAC9H,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,MAAM,GAAE,OAAY,GAAG,OAAO,CAIlG;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,EAAE,IAAI,GAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,SAAS,CAMnK"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { DEFAULT_EVAL_MODEL, parseModelRef, PROVIDER_ENV_KEYS, PROVIDER_LABELS } from '@neurouter/shared';
|
|
2
|
+
import { AnthropicLlmClient } from './anthropic.js';
|
|
3
|
+
import { FakeLlmClient } from './fake.js';
|
|
4
|
+
import { GeminiLlmClient } from './gemini.js';
|
|
5
|
+
import { OpenAiLlmClient } from './openai.js';
|
|
6
|
+
import { StubLlmClient } from './stub.js';
|
|
7
|
+
import { LlmError, LlmKeyError } from './types.js';
|
|
8
|
+
/** Explicit provider selection: the stub and the fake are never picked implicitly. */
|
|
9
|
+
export function createLlmClient(opts) {
|
|
10
|
+
switch (opts.provider) {
|
|
11
|
+
case 'openai':
|
|
12
|
+
if (!opts.apiKey)
|
|
13
|
+
throw new LlmKeyError('OPENAI_API_KEY is not configured');
|
|
14
|
+
return new OpenAiLlmClient({ apiKey: opts.apiKey, ...(opts.baseURL ? { baseURL: opts.baseURL } : {}) });
|
|
15
|
+
case 'anthropic':
|
|
16
|
+
if (!opts.apiKey)
|
|
17
|
+
throw new LlmKeyError('ANTHROPIC_API_KEY is not configured');
|
|
18
|
+
return new AnthropicLlmClient({ apiKey: opts.apiKey, ...(opts.baseURL ? { baseURL: opts.baseURL } : {}) });
|
|
19
|
+
case 'gemini':
|
|
20
|
+
if (!opts.apiKey)
|
|
21
|
+
throw new LlmKeyError('GEMINI_API_KEY is not configured');
|
|
22
|
+
return new GeminiLlmClient({ apiKey: opts.apiKey });
|
|
23
|
+
case 'stub':
|
|
24
|
+
return new StubLlmClient();
|
|
25
|
+
case 'fake':
|
|
26
|
+
if (!opts.fakeDir)
|
|
27
|
+
throw new LlmError('fake LLM needs a fixture directory');
|
|
28
|
+
return new FakeLlmClient(opts.fakeDir, { env: opts.nodeEnv ?? process.env.NODE_ENV });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Routes each request to the provider its model belongs to (`gpt-*`/`o<digit>*` → OpenAI,
|
|
33
|
+
* `claude-*` → Anthropic, `gemini-*` → Gemini, or an explicit `provider:model`), creating one SDK
|
|
34
|
+
* client per provider on first use. A model whose provider has no key fails with `LlmKeyError`.
|
|
35
|
+
*/
|
|
36
|
+
export class RoutingLlmClient {
|
|
37
|
+
keys;
|
|
38
|
+
provider;
|
|
39
|
+
clients = new Map();
|
|
40
|
+
create_;
|
|
41
|
+
constructor(keys, opts = {}) {
|
|
42
|
+
this.keys = keys;
|
|
43
|
+
this.provider = parseModelRef(opts.defaultModel ?? DEFAULT_EVAL_MODEL).provider ?? 'openai';
|
|
44
|
+
this.create_ = opts.create ?? ((provider, apiKey) => createLlmClient({ provider, apiKey }));
|
|
45
|
+
}
|
|
46
|
+
/** The provider and bare model id a model reference resolves to (throws when unroutable or keyless). */
|
|
47
|
+
resolve(modelRef) {
|
|
48
|
+
const { provider, model } = parseModelRef(modelRef);
|
|
49
|
+
if (!provider)
|
|
50
|
+
throw new LlmError(`Cannot tell which provider serves model "${modelRef}"; prefix it with openai:, anthropic: or gemini:`, 400);
|
|
51
|
+
if (!this.keys[provider])
|
|
52
|
+
throw new LlmKeyError(`${PROVIDER_LABELS[provider]} API key missing for model ${model} (set ${PROVIDER_ENV_KEYS[provider]} or add it in Settings › Models)`);
|
|
53
|
+
return { provider, model };
|
|
54
|
+
}
|
|
55
|
+
hasKeyFor(modelRef) {
|
|
56
|
+
const { provider } = parseModelRef(modelRef);
|
|
57
|
+
return Boolean(provider && this.keys[provider]);
|
|
58
|
+
}
|
|
59
|
+
async create(req, opts) {
|
|
60
|
+
const { provider, model } = this.resolve(req.model);
|
|
61
|
+
let client = this.clients.get(provider);
|
|
62
|
+
if (!client) {
|
|
63
|
+
client = this.create_(provider, this.keys[provider]);
|
|
64
|
+
this.clients.set(provider, client);
|
|
65
|
+
}
|
|
66
|
+
return client.create(model === req.model ? req : { ...req, model }, opts);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Keys from the environment (OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY), overlaid by `stored` where env is unset. */
|
|
70
|
+
export function keysFromEnv(env, stored = {}) {
|
|
71
|
+
const out = {};
|
|
72
|
+
for (const k of ['openai', 'anthropic', 'gemini'])
|
|
73
|
+
out[k] = env[PROVIDER_ENV_KEYS[k]] || stored[k] || null;
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Provider from the environment: `NEUROUTER_EVAL_FAKE_LLM=<dir>` (tests) → fake;
|
|
78
|
+
* `NEUROUTER_EVAL_LLM=stub` → deterministic stub; otherwise a router over the providers that have
|
|
79
|
+
* a key (env wins over `stored`; a bare string is a legacy stored Anthropic key). No key at all →
|
|
80
|
+
* `LlmKeyError`.
|
|
81
|
+
*/
|
|
82
|
+
export function llmFromEnv(env = process.env, stored, opts = {}) {
|
|
83
|
+
if (env.NEUROUTER_EVAL_FAKE_LLM)
|
|
84
|
+
return createLlmClient({ provider: 'fake', fakeDir: env.NEUROUTER_EVAL_FAKE_LLM, ...(env.NODE_ENV ? { nodeEnv: env.NODE_ENV } : {}) });
|
|
85
|
+
if (env.NEUROUTER_EVAL_LLM === 'stub')
|
|
86
|
+
return createLlmClient({ provider: 'stub' });
|
|
87
|
+
const keys = keysFromEnv(env, typeof stored === 'string' ? { anthropic: stored } : (stored ?? {}));
|
|
88
|
+
if (!Object.values(keys).some(Boolean))
|
|
89
|
+
throw new LlmKeyError('No model provider key is configured (set OPENAI_API_KEY, ANTHROPIC_API_KEY or GEMINI_API_KEY, or add a key in Settings › Models)');
|
|
90
|
+
return new RoutingLlmClient(keys, { defaultModel: opts.defaultModel ?? env.NEUROUTER_EVAL_MODEL ?? DEFAULT_EVAL_MODEL });
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/llm/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAwB,MAAM,mBAAmB,CAAC;AAChI,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EA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tJ,IAAI,GAAG,CAAC,uBAAuB;QAAE,OAAO,eAAe,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,uBAAuB,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACxK,IAAI,GAAG,CAAC,kBAAkB,KAAK,MAAM;QAAE,OAAO,eAAe,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IACpF,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;IACnG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,WAAW,CAAC,kIAAkI,CAAC,CAAC;IAClM,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,IAAI,GAAG,CAAC,oBAAoB,IAAI,kBAAkB,EAAE,CAAC,CAAC;AAC3H,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type LlmClient, type LlmRequest, type LlmResponse } from './types.js';
|
|
2
|
+
/** Stable hash of the parts of a request that determine the answer (model, system, messages, tool names). */
|
|
3
|
+
export declare function promptHash(req: LlmRequest): string;
|
|
4
|
+
/**
|
|
5
|
+
* Test-only fixture replay (backend §19.1): answers are `<dir>/<promptHash>.json` files holding an
|
|
6
|
+
* `LlmResponse`. Enabled with `NEUROUTER_EVAL_FAKE_LLM=<dir>`; refused unless `NODE_ENV=test`.
|
|
7
|
+
* With `record` set, a miss is answered by the fallback client and written to the fixture dir.
|
|
8
|
+
*/
|
|
9
|
+
export declare class FakeLlmClient implements LlmClient {
|
|
10
|
+
private readonly dir;
|
|
11
|
+
private readonly opts;
|
|
12
|
+
readonly provider: "fake";
|
|
13
|
+
constructor(dir: string, opts?: {
|
|
14
|
+
env?: string | undefined;
|
|
15
|
+
record?: LlmClient;
|
|
16
|
+
});
|
|
17
|
+
create(req: LlmRequest): Promise<LlmResponse>;
|
|
18
|
+
}
|
|
19
|
+
/** In-memory scripted client for unit tests: a queue of responses or a responder function. */
|
|
20
|
+
export declare class ScriptedLlmClient implements LlmClient {
|
|
21
|
+
private readonly fallback?;
|
|
22
|
+
readonly provider: "scripted";
|
|
23
|
+
readonly requests: LlmRequest[];
|
|
24
|
+
private readonly queue;
|
|
25
|
+
constructor(responses?: Array<LlmResponse | Error | ((req: LlmRequest) => LlmResponse | Promise<LlmResponse>)>, fallback?: ((req: LlmRequest, index: number) => LlmResponse | Promise<LlmResponse>) | undefined);
|
|
26
|
+
create(req: LlmRequest): Promise<LlmResponse>;
|
|
27
|
+
}
|
|
28
|
+
/** Builds an `LlmResponse` (tests and the stub). */
|
|
29
|
+
export declare function llmResponse(content: LlmResponse['content'], opts?: {
|
|
30
|
+
model?: string;
|
|
31
|
+
stop?: string;
|
|
32
|
+
input?: number;
|
|
33
|
+
output?: number;
|
|
34
|
+
iterations?: LlmResponse['usage']['iterations'];
|
|
35
|
+
}): LlmResponse;
|
|
36
|
+
//# sourceMappingURL=fake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake.d.ts","sourceRoot":"","sources":["../../src/llm/fake.ts"],"names":[],"mappings":"AAGA,OAAO,EAAY,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzF,6GAA6G;AAC7G,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAGlD;AAED;;;;GAIG;AACH,qBAAa,aAAc,YAAW,SAAS;IAG3C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}
|
package/dist/llm/fake.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { LlmError } from './types.js';
|
|
5
|
+
/** Stable hash of the parts of a request that determine the answer (model, system, messages, tool names). */
|
|
6
|
+
export function promptHash(req) {
|
|
7
|
+
const key = JSON.stringify({ model: req.model, system: req.system ?? null, messages: req.messages, tools: (req.tools ?? []).map((t) => t.name), format: req.output_config?.format ?? null });
|
|
8
|
+
return createHash('sha256').update(key).digest('hex');
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Test-only fixture replay (backend §19.1): answers are `<dir>/<promptHash>.json` files holding an
|
|
12
|
+
* `LlmResponse`. Enabled with `NEUROUTER_EVAL_FAKE_LLM=<dir>`; refused unless `NODE_ENV=test`.
|
|
13
|
+
* With `record` set, a miss is answered by the fallback client and written to the fixture dir.
|
|
14
|
+
*/
|
|
15
|
+
export class FakeLlmClient {
|
|
16
|
+
dir;
|
|
17
|
+
opts;
|
|
18
|
+
provider = 'fake';
|
|
19
|
+
constructor(dir, opts = {}) {
|
|
20
|
+
this.dir = dir;
|
|
21
|
+
this.opts = opts;
|
|
22
|
+
const env = opts.env ?? process.env.NODE_ENV;
|
|
23
|
+
if (env !== 'test')
|
|
24
|
+
throw new LlmError('NEUROUTER_EVAL_FAKE_LLM is only allowed when NODE_ENV=test');
|
|
25
|
+
}
|
|
26
|
+
async create(req) {
|
|
27
|
+
const file = path.join(this.dir, `${promptHash(req)}.json`);
|
|
28
|
+
if (fs.existsSync(file))
|
|
29
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
30
|
+
if (this.opts.record) {
|
|
31
|
+
const res = await this.opts.record.create(req);
|
|
32
|
+
fs.mkdirSync(this.dir, { recursive: true });
|
|
33
|
+
fs.writeFileSync(file, JSON.stringify(res, null, 2));
|
|
34
|
+
return res;
|
|
35
|
+
}
|
|
36
|
+
throw new LlmError(`fake LLM: no fixture ${path.basename(file)}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** In-memory scripted client for unit tests: a queue of responses or a responder function. */
|
|
40
|
+
export class ScriptedLlmClient {
|
|
41
|
+
fallback;
|
|
42
|
+
provider = 'scripted';
|
|
43
|
+
requests = [];
|
|
44
|
+
queue;
|
|
45
|
+
constructor(responses = [], fallback) {
|
|
46
|
+
this.fallback = fallback;
|
|
47
|
+
this.queue = [...responses];
|
|
48
|
+
}
|
|
49
|
+
async create(req) {
|
|
50
|
+
this.requests.push(structuredClone(req));
|
|
51
|
+
const next = this.queue.shift();
|
|
52
|
+
if (next === undefined) {
|
|
53
|
+
if (this.fallback)
|
|
54
|
+
return this.fallback(req, this.requests.length - 1);
|
|
55
|
+
throw new LlmError('scripted LLM: no more responses');
|
|
56
|
+
}
|
|
57
|
+
if (next instanceof Error)
|
|
58
|
+
throw next;
|
|
59
|
+
return typeof next === 'function' ? next(req) : next;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
let counter = 0;
|
|
63
|
+
/** Builds an `LlmResponse` (tests and the stub). */
|
|
64
|
+
export function llmResponse(content, opts = {}) {
|
|
65
|
+
const stop = opts.stop ?? (content.some((b) => b.type === 'tool_use') ? 'tool_use' : 'end_turn');
|
|
66
|
+
return {
|
|
67
|
+
id: `msg_${(++counter).toString(36)}`,
|
|
68
|
+
model: opts.model ?? 'gpt-6-luna',
|
|
69
|
+
role: 'assistant',
|
|
70
|
+
content,
|
|
71
|
+
stop_reason: stop,
|
|
72
|
+
usage: { input_tokens: opts.input ?? 100, output_tokens: opts.output ?? 20, cache_read_input_tokens: 0, ...(opts.iterations ? { iterations: opts.iterations } : {}) },
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=fake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake.js","sourceRoot":"","sources":["../../src/llm/fake.ts"],"names":[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
import { type LlmClient, type LlmCreateOptions, type LlmMessageParam, type LlmRequest, type LlmResponse } from './types.js';
|
|
3
|
+
type CreateParams = Parameters<GoogleGenAI['interactions']['create']>[0];
|
|
4
|
+
type CreateOptions = Parameters<GoogleGenAI['interactions']['create']>[1];
|
|
5
|
+
type Step = Interactions.Step;
|
|
6
|
+
/** The fields of `GoogleGenAIInteraction` the adapter reads. */
|
|
7
|
+
export type GeminiInteraction = Pick<GoogleGenAIInteraction, 'id' | 'status' | 'steps' | 'usage'> & {
|
|
8
|
+
model?: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
/** Opaque assistant block carrying the model's Interactions steps (thoughts with signatures, calls, output) verbatim. */
|
|
11
|
+
export interface GeminiStepsBlock {
|
|
12
|
+
type: 'gemini_steps';
|
|
13
|
+
steps: Step[];
|
|
14
|
+
}
|
|
15
|
+
/** The slice of the SDK this adapter calls (injectable for tests). */
|
|
16
|
+
export interface GeminiInteractionsApi {
|
|
17
|
+
interactions: {
|
|
18
|
+
create(params: CreateParams, options?: CreateOptions): Promise<GeminiInteraction>;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Adapter over `@google/genai` 3.6.1, Interactions API (`ai.interactions.create`), as the Gemini
|
|
23
|
+
* function-calling docs show it, in stateless mode: `store: false` and the full step history as
|
|
24
|
+
* `input` each turn (the model's own steps — thoughts with their `signature` — sent back
|
|
25
|
+
* unchanged). Tools are `{ type: 'function', name, description, parameters }`; results go back as
|
|
26
|
+
* `function_result` steps. Effort → `generation_config.thinking_level`.
|
|
27
|
+
*/
|
|
28
|
+
export declare class GeminiLlmClient implements LlmClient {
|
|
29
|
+
readonly provider: "gemini";
|
|
30
|
+
private readonly client;
|
|
31
|
+
constructor(opts: {
|
|
32
|
+
apiKey: string;
|
|
33
|
+
client?: GeminiInteractionsApi;
|
|
34
|
+
});
|
|
35
|
+
create(req: LlmRequest, opts?: LlmCreateOptions): Promise<LlmResponse>;
|
|
36
|
+
}
|
|
37
|
+
export declare function toGeminiRequest(req: LlmRequest): CreateParams;
|
|
38
|
+
export declare function toGeminiSteps(messages: LlmMessageParam[]): Step[];
|
|
39
|
+
export declare function fromGeminiInteraction(res: GeminiInteraction, requestedModel: string): LlmResponse;
|
|
40
|
+
/** Both SDK error families (`ApiError`, Interactions `APIError`) carry a numeric `status`. */
|
|
41
|
+
export declare function mapGeminiError(err: unknown): Error;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../src/llm/gemini.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,sBAAsB,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAA4C,KAAK,SAAS,EAAwB,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAoE,MAAM,YAAY,CAAC;AAE9P,KAAK,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,KAAK,aAAa,GAAG,UAAU,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1E,KAAK,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;AAC9B,gEAAgE;AAChE,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,sBAAsB,EAAE,IAAI,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEnI,yHAAyH;AACzH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,sEAAsE;AACtE,MA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