nuabase 2.3.7 → 3.0.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/CHANGELOG.md +58 -0
- package/README.md +233 -200
- package/dist/chunks/local-agent-Bj-QKikS.d.cts +270 -0
- package/dist/chunks/local-agent-Bj-QKikS.d.mts +270 -0
- package/dist/cjs/chunks/strict-json-schema-bKwaMWm1.cjs +145 -0
- package/dist/cjs/index.cjs +991 -11473
- package/dist/cjs/local-agent.cjs +809 -953
- package/dist/esm/chunks/strict-json-schema-Du2LLrVP.mjs +138 -0
- package/dist/esm/index.mjs +989 -11471
- package/dist/esm/local-agent.mjs +782 -954
- package/dist/index.d.cts +94 -0
- package/dist/index.d.mts +94 -0
- package/dist/local-agent.d.cts +150 -0
- package/dist/local-agent.d.mts +150 -0
- package/package.json +12 -24
- package/dist/cjs/chunks/logger-Co5uZG0A.cjs +0 -90
- package/dist/esm/chunks/logger-DnkHzkX_.mjs +0 -88
- package/dist/types/__tests__/helpers/client-factory.d.ts +0 -39
- package/dist/types/__tests__/helpers/index.d.ts +0 -2
- package/dist/types/backend/direct.d.ts +0 -29
- package/dist/types/backend/gateway.d.ts +0 -24
- package/dist/types/backend/types.d.ts +0 -68
- package/dist/types/index.d.cts +0 -7
- package/dist/types/index.d.mts +0 -7
- package/dist/types/lib/auth.d.ts +0 -14
- package/dist/types/lib/env.d.ts +0 -1
- package/dist/types/lib/error-response.d.ts +0 -6
- package/dist/types/lib/error-utils.d.ts +0 -6
- package/dist/types/local-agent.d.cts +0 -2
- package/dist/types/local-agent.d.mts +0 -2
- package/dist/types/nua-llm-core/index.d.ts +0 -23
- package/dist/types/nua-llm-core/lib/error-utils.d.ts +0 -6
- package/dist/types/nua-llm-core/lib/logger.d.ts +0 -44
- package/dist/types/nua-llm-core/lib/nua-errors.d.ts +0 -12
- package/dist/types/nua-llm-core/lib/prompt-template-utils.d.ts +0 -2
- package/dist/types/nua-llm-core/lib/schema-utils.d.ts +0 -1
- package/dist/types/nua-llm-core/lib/stable-stringify.d.ts +0 -1
- package/dist/types/nua-llm-core/lib/strict-json-schema.d.ts +0 -7
- package/dist/types/nua-llm-core/lib/types.d.ts +0 -8
- package/dist/types/nua-llm-core/lib/validate-mappable-input-data.d.ts +0 -4
- package/dist/types/nua-llm-core/local-agent.d.ts +0 -7
- package/dist/types/nua-llm-core/modules/agent/agent-loop.d.ts +0 -10
- package/dist/types/nua-llm-core/modules/agent/agent-turn.d.ts +0 -17
- package/dist/types/nua-llm-core/modules/agent/provider-formatters.d.ts +0 -22
- package/dist/types/nua-llm-core/modules/agent/run-agent.d.ts +0 -7
- package/dist/types/nua-llm-core/modules/agent/types.d.ts +0 -90
- package/dist/types/nua-llm-core/modules/cast/cast-request.d.ts +0 -32
- package/dist/types/nua-llm-core/modules/cast/envelope.d.ts +0 -9
- package/dist/types/nua-llm-core/modules/cast/list-schema.d.ts +0 -32
- package/dist/types/nua-llm-core/modules/cast/prompts/list-prompt.d.ts +0 -3
- package/dist/types/nua-llm-core/modules/cast/prompts/render-prompt.d.ts +0 -7
- package/dist/types/nua-llm-core/modules/cast/prompts/value-prompt.d.ts +0 -3
- package/dist/types/nua-llm-core/modules/cast/run-cast.d.ts +0 -44
- package/dist/types/nua-llm-core/modules/engine/engine-router.d.ts +0 -23
- package/dist/types/nua-llm-core/modules/engine/http/http-engine.d.ts +0 -12
- package/dist/types/nua-llm-core/modules/engine/http/provider-call.d.ts +0 -33
- package/dist/types/nua-llm-core/modules/engine/http/provider-config.d.ts +0 -65
- package/dist/types/nua-llm-core/modules/engine/http/provider-engines.d.ts +0 -35
- package/dist/types/nua-llm-core/modules/engine/llm-engine.d.ts +0 -73
- package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/claude-code.d.ts +0 -2
- package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/codex.d.ts +0 -2
- package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/failure-classification.d.ts +0 -4
- package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/index.d.ts +0 -3
- package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/pi.d.ts +0 -2
- package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/types.d.ts +0 -61
- package/dist/types/nua-llm-core/modules/engine/local-agent/agent-id.d.ts +0 -4
- package/dist/types/nua-llm-core/modules/engine/local-agent/create-local-agent.d.ts +0 -36
- package/dist/types/nua-llm-core/modules/engine/local-agent/detect.d.ts +0 -20
- package/dist/types/nua-llm-core/modules/engine/local-agent/local-agent-engine.d.ts +0 -32
- package/dist/types/nua-llm-core/modules/engine/local-agent/local-agent.d.ts +0 -25
- package/dist/types/nua-llm-core/modules/engine/local-agent/process-runner.d.ts +0 -16
- package/dist/types/nua-llm-core/modules/engine/local-agent/semaphore.d.ts +0 -8
- package/dist/types/nua-llm-core/modules/execution/llm-response-extraction.d.ts +0 -5
- package/dist/types/nua-llm-core/modules/json-schema-validation/ajv-instances.d.ts +0 -12
- package/dist/types/nua-llm-core/modules/json-schema-validation/nua-json-schema-value-validation.d.ts +0 -10
- package/dist/types/nua-llm-core/modules/json-schema-validation/validate-json-schema.d.ts +0 -2
- package/dist/types/nua-llm-core/modules/model-info/index.d.ts +0 -15
- package/dist/types/nua-llm-core/modules/streaming/sse-parser.d.ts +0 -7
- package/dist/types/nua-llm-core/nua-llm-client.d.ts +0 -37
- package/dist/types/nua.d.ts +0 -42
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { NormalizedUsage } from "../engine/http/provider-config";
|
|
2
|
-
import { ModelInput } from "../model-info";
|
|
3
|
-
export type ToolDefinition = {
|
|
4
|
-
name: string;
|
|
5
|
-
description: string;
|
|
6
|
-
parameters: Record<string, unknown>;
|
|
7
|
-
};
|
|
8
|
-
export type ToolExecutionResult = {
|
|
9
|
-
content: string;
|
|
10
|
-
isError?: boolean;
|
|
11
|
-
};
|
|
12
|
-
export type AgentTool = ToolDefinition & {
|
|
13
|
-
execute: (args: Record<string, unknown>) => Promise<ToolExecutionResult>;
|
|
14
|
-
};
|
|
15
|
-
export type TextContent = {
|
|
16
|
-
type: "text";
|
|
17
|
-
text: string;
|
|
18
|
-
};
|
|
19
|
-
export type ToolCallContent = {
|
|
20
|
-
type: "toolCall";
|
|
21
|
-
id: string;
|
|
22
|
-
name: string;
|
|
23
|
-
arguments: Record<string, unknown>;
|
|
24
|
-
};
|
|
25
|
-
export type AssistantContentBlock = TextContent | ToolCallContent;
|
|
26
|
-
export type UserMessage = {
|
|
27
|
-
role: "user";
|
|
28
|
-
content: string;
|
|
29
|
-
};
|
|
30
|
-
export type AssistantMessage = {
|
|
31
|
-
role: "assistant";
|
|
32
|
-
content: AssistantContentBlock[];
|
|
33
|
-
};
|
|
34
|
-
export type ToolResultMessage = {
|
|
35
|
-
role: "toolResult";
|
|
36
|
-
toolCallId: string;
|
|
37
|
-
toolName: string;
|
|
38
|
-
content: string;
|
|
39
|
-
isError: boolean;
|
|
40
|
-
};
|
|
41
|
-
export type ConversationMessage = UserMessage | AssistantMessage | ToolResultMessage;
|
|
42
|
-
export type AgenticParsedResponse = {
|
|
43
|
-
message: AssistantMessage;
|
|
44
|
-
usage: NormalizedUsage;
|
|
45
|
-
stopReason: "stop" | "tool_use";
|
|
46
|
-
};
|
|
47
|
-
export type AgentEvent = {
|
|
48
|
-
type: "turn_start";
|
|
49
|
-
turn: number;
|
|
50
|
-
} | {
|
|
51
|
-
type: "text_delta";
|
|
52
|
-
text: string;
|
|
53
|
-
} | {
|
|
54
|
-
type: "response_complete";
|
|
55
|
-
message: AssistantMessage;
|
|
56
|
-
usage: NormalizedUsage;
|
|
57
|
-
stopReason: "stop" | "tool_use";
|
|
58
|
-
} | {
|
|
59
|
-
type: "tool_start";
|
|
60
|
-
toolCallId: string;
|
|
61
|
-
toolName: string;
|
|
62
|
-
arguments: Record<string, unknown>;
|
|
63
|
-
} | {
|
|
64
|
-
type: "tool_complete";
|
|
65
|
-
toolCallId: string;
|
|
66
|
-
toolName: string;
|
|
67
|
-
result: ToolExecutionResult;
|
|
68
|
-
} | {
|
|
69
|
-
type: "error";
|
|
70
|
-
error: string;
|
|
71
|
-
};
|
|
72
|
-
export type AgentEventHandler = (event: AgentEvent) => void;
|
|
73
|
-
export type AgentRunParams = {
|
|
74
|
-
model?: ModelInput;
|
|
75
|
-
systemPrompt?: string;
|
|
76
|
-
messages: ConversationMessage[];
|
|
77
|
-
tools: AgentTool[];
|
|
78
|
-
maxTokens?: number;
|
|
79
|
-
maxTurns?: number;
|
|
80
|
-
onEvent?: AgentEventHandler;
|
|
81
|
-
};
|
|
82
|
-
export type AgentCompletionReason = "stop" | "max_turns" | "error";
|
|
83
|
-
export type AgentResult = {
|
|
84
|
-
success: boolean;
|
|
85
|
-
completionReason: AgentCompletionReason;
|
|
86
|
-
messages: ConversationMessage[];
|
|
87
|
-
textResponse?: string;
|
|
88
|
-
usage: NormalizedUsage;
|
|
89
|
-
error?: string;
|
|
90
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { JsonSchema } from "../../lib/schema-utils";
|
|
2
|
-
import { MappableInputData } from "../../lib/types";
|
|
3
|
-
/** A cast ready to run, as plain data. Its prompt is rendered per attempt (see prompts/render-prompt). */
|
|
4
|
-
export type CastRequest = ValueCastRequest | ListCastRequest;
|
|
5
|
-
/** Asks for one value. */
|
|
6
|
-
export type ValueCastRequest = {
|
|
7
|
-
kind: "value";
|
|
8
|
-
/** The caller's instructions. */
|
|
9
|
-
prompt: string;
|
|
10
|
-
data: unknown;
|
|
11
|
-
outputName: string;
|
|
12
|
-
/** The schema the result must satisfy. */
|
|
13
|
-
schema: JsonSchema;
|
|
14
|
-
maxTokens: number;
|
|
15
|
-
};
|
|
16
|
-
/** Asks for one result row per input row, each keyed by the input row's primary key. */
|
|
17
|
-
export type ListCastRequest = {
|
|
18
|
-
kind: "list";
|
|
19
|
-
/** The caller's instructions. */
|
|
20
|
-
prompt: string;
|
|
21
|
-
rows: MappableInputData;
|
|
22
|
-
primaryKey: string;
|
|
23
|
-
outputName: string;
|
|
24
|
-
/** The schema the whole list must satisfy (see list-schema). */
|
|
25
|
-
schema: JsonSchema;
|
|
26
|
-
maxTokens: number;
|
|
27
|
-
};
|
|
28
|
-
/** The prompt one attempt sends. `system` is the part that tells the model how to shape its answer. */
|
|
29
|
-
export type RenderedPrompt = {
|
|
30
|
-
system: string;
|
|
31
|
-
full: string;
|
|
32
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { JsonSchema } from "../../lib/schema-utils";
|
|
2
|
-
export declare const ENVELOPE_KEY = "value";
|
|
3
|
-
export declare function wrapInEnvelope(schema: JsonSchema): JsonSchema;
|
|
4
|
-
export declare function unwrapEnvelope(envelope: unknown): {
|
|
5
|
-
found: true;
|
|
6
|
-
value: unknown;
|
|
7
|
-
} | {
|
|
8
|
-
found: false;
|
|
9
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { NuaValidationError } from "../../lib/nua-errors";
|
|
2
|
-
import { JsonSchema } from "../../lib/schema-utils";
|
|
3
|
-
declare const listSchemaBrand: unique symbol;
|
|
4
|
-
/** Names the two fields of every row in a list result. */
|
|
5
|
-
export type ListRowKeys = {
|
|
6
|
-
/** Holds the primary key of the input row the result row answers. */
|
|
7
|
-
primaryKey: string;
|
|
8
|
-
/** Holds the output value. */
|
|
9
|
-
outputName: string;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* The schema of a list cast's result, with the row keys it was built for. Only
|
|
13
|
-
* listSchema() and parseListSchema() make one, so a castArray call cannot be
|
|
14
|
-
* given an item schema by mistake.
|
|
15
|
-
*/
|
|
16
|
-
export type ListSchema = ListRowKeys & {
|
|
17
|
-
readonly [listSchemaBrand]: true;
|
|
18
|
-
/** The JSON schema of the whole list, as sent to the model and validated against. */
|
|
19
|
-
jsonSchema: JsonSchema;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Builds the list schema whose rows each hold one `itemSchema` value:
|
|
23
|
-
*
|
|
24
|
-
* array<{ <primaryKey>: string | number, <outputName>: <itemSchema> }>
|
|
25
|
-
*/
|
|
26
|
-
export declare function listSchema(itemSchema: JsonSchema, keys: ListRowKeys): ListSchema;
|
|
27
|
-
/**
|
|
28
|
-
* Reads back a list schema that was built by listSchema() and stored as JSON. It is
|
|
29
|
-
* used exactly as stored, so a change to listSchema() does not alter stored ones.
|
|
30
|
-
*/
|
|
31
|
-
export declare function parseListSchema(jsonSchema: unknown, keys: ListRowKeys): ListSchema | NuaValidationError;
|
|
32
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { SchemaEnforcementKind } from "../../engine/llm-engine";
|
|
2
|
-
import { CastRequest, RenderedPrompt } from "../cast-request";
|
|
3
|
-
/**
|
|
4
|
-
* The prompt for one attempt at a cast. It differs by enforcement: with native
|
|
5
|
-
* enforcement the model is told its answer goes in an envelope field.
|
|
6
|
-
*/
|
|
7
|
-
export declare function renderPrompt(cast: CastRequest, enforcement: SchemaEnforcementKind): RenderedPrompt;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../lib/logger";
|
|
2
|
-
import { NormalizedUsage } from "../engine/http/provider-config";
|
|
3
|
-
import { AnswerOrigin, AttemptOutcome, LlmEngine, SchemaEnforcementKind } from "../engine/llm-engine";
|
|
4
|
-
import { ValidationResult } from "../json-schema-validation/nua-json-schema-value-validation";
|
|
5
|
-
import { CastRequest, RenderedPrompt } from "./cast-request";
|
|
6
|
-
export type CastSuccess<T> = {
|
|
7
|
-
success: true;
|
|
8
|
-
data: T;
|
|
9
|
-
/** Usage of the attempt that succeeded. */
|
|
10
|
-
usage: NormalizedUsage;
|
|
11
|
-
/** The prompt of the attempt that succeeded. */
|
|
12
|
-
prompt: RenderedPrompt;
|
|
13
|
-
origin: AnswerOrigin;
|
|
14
|
-
schemaEnforcement: SchemaEnforcementKind;
|
|
15
|
-
};
|
|
16
|
-
export type CastFailure = {
|
|
17
|
-
success: false;
|
|
18
|
-
error: string;
|
|
19
|
-
/** The prompt of the last attempt, when one was made. */
|
|
20
|
-
prompt?: RenderedPrompt;
|
|
21
|
-
};
|
|
22
|
-
export type CastResult<T> = CastSuccess<T> | CastFailure;
|
|
23
|
-
/**
|
|
24
|
-
* Runs a cast on an engine: asks for an answer, checks it against the schema,
|
|
25
|
-
* and tries again when another attempt could help.
|
|
26
|
-
*/
|
|
27
|
-
export declare function runCast<T>(engine: LlmEngine, request: CastRequest, logger: Logger): Promise<CastResult<T>>;
|
|
28
|
-
export type Verdict = {
|
|
29
|
-
kind: "accept";
|
|
30
|
-
data: unknown;
|
|
31
|
-
usage: NormalizedUsage;
|
|
32
|
-
origin: AnswerOrigin;
|
|
33
|
-
} | {
|
|
34
|
-
kind: "retry";
|
|
35
|
-
error: string;
|
|
36
|
-
} | {
|
|
37
|
-
kind: "retry-in-prompt";
|
|
38
|
-
error: string;
|
|
39
|
-
} | {
|
|
40
|
-
kind: "give-up";
|
|
41
|
-
error: string;
|
|
42
|
-
};
|
|
43
|
-
/** Decides what one attempt means for the cast. */
|
|
44
|
-
export declare function judgeOutcome(outcome: AttemptOutcome, validate: (data: object) => ValidationResult): Verdict;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../lib/logger";
|
|
2
|
-
import { ModelInput } from "../model-info";
|
|
3
|
-
import { LlmEngine } from "./llm-engine";
|
|
4
|
-
/** The engine that runs a model choice, or why none can. */
|
|
5
|
-
export type Route = {
|
|
6
|
-
kind: "routed";
|
|
7
|
-
engine: LlmEngine;
|
|
8
|
-
} | {
|
|
9
|
-
kind: "unroutable";
|
|
10
|
-
message: string;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Where a client's calls run. Every setup answers the same question: for this
|
|
14
|
-
* model choice, which engine runs it? Created by providerEngines() for LLM
|
|
15
|
-
* providers' APIs, or by localAgent() / findLocalAgent() in the Node-only
|
|
16
|
-
* "nua-llm-core/local-agent" entry point for a coding-agent CLI.
|
|
17
|
-
*/
|
|
18
|
-
export interface EngineRouter {
|
|
19
|
-
/** Where the engines log their calls. Casts log their retries here too. */
|
|
20
|
-
readonly logger: Logger;
|
|
21
|
-
/** `model` undefined means this router's default model. */
|
|
22
|
-
route(model: ModelInput | undefined): Route;
|
|
23
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../../lib/logger";
|
|
2
|
-
import { AttemptOutcome, AttemptRequest, LlmEngine } from "../llm-engine";
|
|
3
|
-
import { ProviderTarget } from "./provider-call";
|
|
4
|
-
/** Answers cast attempts on one model of an LLM provider's HTTP API. */
|
|
5
|
-
export declare class HttpEngine implements LlmEngine {
|
|
6
|
-
private readonly target;
|
|
7
|
-
private readonly logger;
|
|
8
|
-
constructor(target: ProviderTarget, logger: Logger);
|
|
9
|
-
/** Provider APIs are given the schema in the prompt; none is enforced natively yet. */
|
|
10
|
-
nativeSchema(): null;
|
|
11
|
-
attempt(request: AttemptRequest): Promise<AttemptOutcome>;
|
|
12
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../../lib/logger";
|
|
2
|
-
import { LlmProviderId, NormalizedUsage, ProviderRequestBase } from "./provider-config";
|
|
3
|
-
/** A provider's model, and the API key to call it with. */
|
|
4
|
-
export type ProviderTarget = {
|
|
5
|
-
provider: LlmProviderId;
|
|
6
|
-
model: string;
|
|
7
|
-
apiKey: string;
|
|
8
|
-
};
|
|
9
|
-
/** One HTTP request to an LLM provider, and how to read its reply. */
|
|
10
|
-
export type ProviderCall<T> = {
|
|
11
|
-
target: ProviderTarget;
|
|
12
|
-
/** The kind of request, for the log (e.g. "chat/completions", "agentic"). */
|
|
13
|
-
apiOperation: string;
|
|
14
|
-
maxTokens: number;
|
|
15
|
-
request: ProviderRequestBase;
|
|
16
|
-
/** Throws when the reply is an error or cannot be read. */
|
|
17
|
-
parseResponse: (response: Response) => Promise<T>;
|
|
18
|
-
/** Characters of reply text, for the log. */
|
|
19
|
-
responseLength: (reply: T) => number;
|
|
20
|
-
usage: (reply: T) => NormalizedUsage | undefined;
|
|
21
|
-
};
|
|
22
|
-
export type ProviderCallResult<T> = {
|
|
23
|
-
kind: "ok";
|
|
24
|
-
reply: T;
|
|
25
|
-
}
|
|
26
|
-
/** `status` is undefined when no HTTP response arrived. */
|
|
27
|
-
| {
|
|
28
|
-
kind: "failed";
|
|
29
|
-
status: number | undefined;
|
|
30
|
-
message: string;
|
|
31
|
-
};
|
|
32
|
-
/** Sends the request and reads the reply, logging the start and the end of the call. Never throws. */
|
|
33
|
-
export declare function callProvider<T>(call: ProviderCall<T>, logger: Logger): Promise<ProviderCallResult<T>>;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export type ProviderRequestBase = {
|
|
2
|
-
url: string;
|
|
3
|
-
method?: string;
|
|
4
|
-
headers?: Record<string, string>;
|
|
5
|
-
body?: unknown;
|
|
6
|
-
/** Request details with secrets removed for logging */
|
|
7
|
-
loggableUrl?: string;
|
|
8
|
-
loggableHeaders?: Record<string, string>;
|
|
9
|
-
loggableBody?: unknown;
|
|
10
|
-
};
|
|
11
|
-
export declare const LLM_PROVIDER_IDS: readonly ["groq", "cerebras", "gemini", "openrouter"];
|
|
12
|
-
export type LlmProviderId = (typeof LLM_PROVIDER_IDS)[number];
|
|
13
|
-
export interface ProviderRequestOptions {
|
|
14
|
-
prompt: string;
|
|
15
|
-
model: string;
|
|
16
|
-
maxTokens: number;
|
|
17
|
-
assistantPrefillPrompt?: string;
|
|
18
|
-
}
|
|
19
|
-
export type NormalizedUsage = {
|
|
20
|
-
promptTokens: number;
|
|
21
|
-
completionTokens: number;
|
|
22
|
-
totalTokens: number;
|
|
23
|
-
};
|
|
24
|
-
export declare const normalizedUsageZero: NormalizedUsage;
|
|
25
|
-
export type ProviderParsedResponse = {
|
|
26
|
-
text: string;
|
|
27
|
-
usage: NormalizedUsage;
|
|
28
|
-
};
|
|
29
|
-
export interface ProviderConfig {
|
|
30
|
-
providerId: LlmProviderId;
|
|
31
|
-
apiOperation: string;
|
|
32
|
-
errorLabel: string;
|
|
33
|
-
buildRequest(options: ProviderRequestOptions, apiKey: string): ProviderRequestBase;
|
|
34
|
-
parseResponse(response: Response): Promise<ProviderParsedResponse>;
|
|
35
|
-
}
|
|
36
|
-
type OpenAiThinkingDetail = {
|
|
37
|
-
type?: string;
|
|
38
|
-
summary?: string;
|
|
39
|
-
format?: string;
|
|
40
|
-
index?: number;
|
|
41
|
-
};
|
|
42
|
-
type OpenAiThinkingMessage = {
|
|
43
|
-
content?: string | null;
|
|
44
|
-
reasoning?: string | null;
|
|
45
|
-
reasoning_details?: Array<OpenAiThinkingDetail | Record<string, unknown>>;
|
|
46
|
-
};
|
|
47
|
-
export type OpenAiUsage = {
|
|
48
|
-
prompt_tokens?: number;
|
|
49
|
-
completion_tokens?: number;
|
|
50
|
-
total_tokens?: number;
|
|
51
|
-
prompt_tokens_details?: Record<string, unknown> | null;
|
|
52
|
-
completion_tokens_details?: Record<string, unknown> | null;
|
|
53
|
-
[key: string]: unknown;
|
|
54
|
-
} | null;
|
|
55
|
-
export type GeminiUsageMetadata = {
|
|
56
|
-
promptTokenCount?: number;
|
|
57
|
-
candidatesTokenCount?: number;
|
|
58
|
-
totalTokenCount?: number;
|
|
59
|
-
[key: string]: unknown;
|
|
60
|
-
};
|
|
61
|
-
export declare const normalizeOpenAiUsage: (usage: OpenAiUsage | undefined) => NormalizedUsage;
|
|
62
|
-
export declare const normalizeGeminiUsage: (usage: GeminiUsageMetadata | undefined) => NormalizedUsage;
|
|
63
|
-
export declare const extractOpenAiMessageText: (message: OpenAiThinkingMessage | undefined) => string | undefined;
|
|
64
|
-
export declare const providerConfigs: Record<LlmProviderId, ProviderConfig>;
|
|
65
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../../lib/logger";
|
|
2
|
-
import { ModelInput } from "../../model-info";
|
|
3
|
-
import { EngineRouter, Route } from "../engine-router";
|
|
4
|
-
import { ProviderTarget } from "./provider-call";
|
|
5
|
-
import { LlmProviderId } from "./provider-config";
|
|
6
|
-
export type ProviderEnginesConfig = {
|
|
7
|
-
/** API keys by provider. Providers without a key are never used. */
|
|
8
|
-
providers: {
|
|
9
|
-
[key in LlmProviderId]?: {
|
|
10
|
-
apiKey: string;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
/** Used when a call names no model. Defaults to the "fast" alias. */
|
|
14
|
-
model?: ModelInput;
|
|
15
|
-
/** Defaults to the console. */
|
|
16
|
-
logger?: Logger;
|
|
17
|
-
};
|
|
18
|
-
type Unroutable = Extract<Route, {
|
|
19
|
-
kind: "unroutable";
|
|
20
|
-
}>;
|
|
21
|
-
/** Runs calls on LLM providers' HTTP APIs, with API keys. Also runs tool-calling agents (see runAgent). */
|
|
22
|
-
export declare function providerEngines(config: ProviderEnginesConfig): ProviderEngines;
|
|
23
|
-
export declare class ProviderEngines implements EngineRouter {
|
|
24
|
-
readonly logger: Logger;
|
|
25
|
-
private readonly apiKeys;
|
|
26
|
-
private readonly defaultModel;
|
|
27
|
-
constructor(config: ProviderEnginesConfig);
|
|
28
|
-
route(model: ModelInput | undefined): Route;
|
|
29
|
-
/** The provider model, with its API key, that a model choice runs on. */
|
|
30
|
-
resolve(model: ModelInput | undefined): {
|
|
31
|
-
kind: "resolved";
|
|
32
|
-
target: ProviderTarget;
|
|
33
|
-
} | Unroutable;
|
|
34
|
-
}
|
|
35
|
-
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { JsonSchema } from "../../lib/schema-utils";
|
|
2
|
-
import { LlmProviderId, NormalizedUsage } from "./http/provider-config";
|
|
3
|
-
import type { LocalAgentId } from "./local-agent/agent-id";
|
|
4
|
-
/**
|
|
5
|
-
* How one attempt makes the model produce the output shape.
|
|
6
|
-
* - in-prompt: the prompt describes the schema; the reply is free text that should contain the JSON.
|
|
7
|
-
* - native: the engine enforces `schema` itself. It is the output schema wrapped in an
|
|
8
|
-
* envelope (see cast/envelope), already converted to the engine's own dialect.
|
|
9
|
-
*/
|
|
10
|
-
export type SchemaEnforcement = {
|
|
11
|
-
kind: "in-prompt";
|
|
12
|
-
} | {
|
|
13
|
-
kind: "native";
|
|
14
|
-
schema: JsonSchema;
|
|
15
|
-
};
|
|
16
|
-
export type SchemaEnforcementKind = SchemaEnforcement["kind"];
|
|
17
|
-
/** One prompt for an engine to answer once, on the model the engine was created for. */
|
|
18
|
-
export type AttemptRequest = {
|
|
19
|
-
prompt: string;
|
|
20
|
-
maxTokens: number;
|
|
21
|
-
enforcement: SchemaEnforcement;
|
|
22
|
-
};
|
|
23
|
-
export type Answer =
|
|
24
|
-
/** A free-text reply that should contain the JSON result. */
|
|
25
|
-
{
|
|
26
|
-
kind: "text";
|
|
27
|
-
text: string;
|
|
28
|
-
}
|
|
29
|
-
/** The envelope object the engine enforced natively. */
|
|
30
|
-
| {
|
|
31
|
-
kind: "structured";
|
|
32
|
-
envelope: unknown;
|
|
33
|
-
};
|
|
34
|
-
/** Which engine produced an answer. */
|
|
35
|
-
export type AnswerOrigin = {
|
|
36
|
-
engine: "http";
|
|
37
|
-
provider: LlmProviderId;
|
|
38
|
-
model: string;
|
|
39
|
-
} | {
|
|
40
|
-
engine: "local-agent";
|
|
41
|
-
agent: LocalAgentId;
|
|
42
|
-
/** The model the agent reports using, else the one requested; undefined when neither is known. */
|
|
43
|
-
model: string | undefined;
|
|
44
|
-
/** The agent's own estimate. On a subscription this is not what the user pays. */
|
|
45
|
-
costUsdEstimate: number | undefined;
|
|
46
|
-
};
|
|
47
|
-
export type AttemptFailure = {
|
|
48
|
-
/**
|
|
49
|
-
* - transient: another attempt may succeed.
|
|
50
|
-
* - fatal: every attempt will fail the same way (bad API key, not logged in, out of quota, timed out).
|
|
51
|
-
* - schema-rejected: the engine refused the native schema; the in-prompt prompt may still work.
|
|
52
|
-
*/
|
|
53
|
-
kind: "transient" | "fatal" | "schema-rejected";
|
|
54
|
-
message: string;
|
|
55
|
-
};
|
|
56
|
-
export type AttemptOutcome = {
|
|
57
|
-
kind: "answered";
|
|
58
|
-
answer: Answer;
|
|
59
|
-
usage: NormalizedUsage;
|
|
60
|
-
origin: AnswerOrigin;
|
|
61
|
-
} | {
|
|
62
|
-
kind: "failed";
|
|
63
|
-
failure: AttemptFailure;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Answers prompts on one model: an LLM provider's HTTP API, or a coding-agent
|
|
67
|
-
* CLI on this machine. Expected failures come back as outcomes, not exceptions.
|
|
68
|
-
*/
|
|
69
|
-
export interface LlmEngine {
|
|
70
|
-
/** The envelope schema in the form this engine enforces natively, or null if it cannot. */
|
|
71
|
-
nativeSchema(envelopeSchema: JsonSchema): JsonSchema | null;
|
|
72
|
-
attempt(request: AttemptRequest): Promise<AttemptOutcome>;
|
|
73
|
-
}
|
package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/failure-classification.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { AttemptFailure } from "../../llm-engine";
|
|
2
|
-
import { AgentProcessResult } from "./types";
|
|
3
|
-
export declare function classifyAgentFailure(agent: string, message: string): AttemptFailure;
|
|
4
|
-
export declare function stderrTail(result: AgentProcessResult, maxChars?: number): string;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { JsonSchema } from "../../../../lib/schema-utils";
|
|
2
|
-
import { ModelAliasName } from "../../../model-info";
|
|
3
|
-
import { NormalizedUsage } from "../../http/provider-config";
|
|
4
|
-
import { Answer, AttemptFailure, AttemptRequest } from "../../llm-engine";
|
|
5
|
-
import { LocalAgentId } from "../agent-id";
|
|
6
|
-
/** A process to run inside a fresh, empty working directory. */
|
|
7
|
-
export type AgentInvocation = {
|
|
8
|
-
args: string[];
|
|
9
|
-
stdin: string;
|
|
10
|
-
/** Files written into the working directory before the process starts. */
|
|
11
|
-
files?: {
|
|
12
|
-
name: string;
|
|
13
|
-
content: string;
|
|
14
|
-
}[];
|
|
15
|
-
/** Files read back from the working directory after the process exits. */
|
|
16
|
-
outputFiles?: string[];
|
|
17
|
-
};
|
|
18
|
-
export type AgentProcessResult = {
|
|
19
|
-
exitCode: number | null;
|
|
20
|
-
stdout: string;
|
|
21
|
-
stderr: string;
|
|
22
|
-
timedOut: boolean;
|
|
23
|
-
/** Contents of the requested output files; undefined when a file was not written. */
|
|
24
|
-
outputFiles: Record<string, string | undefined>;
|
|
25
|
-
};
|
|
26
|
-
/** What an agent's output says about one attempt. */
|
|
27
|
-
export type AgentReply = {
|
|
28
|
-
kind: "answered";
|
|
29
|
-
answer: Answer;
|
|
30
|
-
usage: NormalizedUsage;
|
|
31
|
-
/** The model the agent reports having used, when it says. */
|
|
32
|
-
model: string | undefined;
|
|
33
|
-
costUsdEstimate: number | undefined;
|
|
34
|
-
} | {
|
|
35
|
-
kind: "failed";
|
|
36
|
-
failure: AttemptFailure;
|
|
37
|
-
};
|
|
38
|
-
export type AgentLoginStatus = {
|
|
39
|
-
loggedIn: boolean;
|
|
40
|
-
detail?: string;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Knows one coding-agent CLI: which models it offers, how to invoke it headless,
|
|
44
|
-
* and how to read its output. Adapters do no I/O; the process runner does the spawning.
|
|
45
|
-
*/
|
|
46
|
-
export interface AgentAdapter {
|
|
47
|
-
id: LocalAgentId;
|
|
48
|
-
/** Executable name looked up on PATH. */
|
|
49
|
-
binaryName: string;
|
|
50
|
-
/** Env vars that would make the CLI bill an API key instead of the user's subscription. */
|
|
51
|
-
apiKeyEnvVars: string[];
|
|
52
|
-
/** The CLI's own model name for each model alias it has an equivalent for. */
|
|
53
|
-
modelAliases: Partial<Record<ModelAliasName, string>>;
|
|
54
|
-
/** The envelope schema in the form this CLI accepts, or null if it can't enforce it. */
|
|
55
|
-
nativeSchema(envelopeSchema: JsonSchema): JsonSchema | null;
|
|
56
|
-
/** `model` is the CLI's own model name; undefined uses the CLI's default. */
|
|
57
|
-
buildInvocation(request: AttemptRequest, model: string | undefined): AgentInvocation;
|
|
58
|
-
readResult(result: AgentProcessResult, request: AttemptRequest): AgentReply;
|
|
59
|
-
loginStatusArgs: string[];
|
|
60
|
-
readLoginStatus(result: AgentProcessResult): AgentLoginStatus;
|
|
61
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/** Supported coding-agent CLIs, in the order findLocalAgent() tries them. */
|
|
2
|
-
export declare const LOCAL_AGENT_IDS: readonly ["claude-code", "codex", "pi"];
|
|
3
|
-
export type LocalAgentId = (typeof LOCAL_AGENT_IDS)[number];
|
|
4
|
-
export declare function isLocalAgentId(value: unknown): value is LocalAgentId;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../../lib/logger";
|
|
2
|
-
import { LocalAgentId } from "./agent-id";
|
|
3
|
-
import { LocalAgent } from "./local-agent";
|
|
4
|
-
/**
|
|
5
|
-
* - subscription: removes API-key env vars (ANTHROPIC_API_KEY, OPENAI_API_KEY, ...) from the
|
|
6
|
-
* agent's environment, so the CLI uses its own login and plan.
|
|
7
|
-
* - inherit: passes the environment through unchanged.
|
|
8
|
-
*/
|
|
9
|
-
export type LocalAgentAuthMode = "subscription" | "inherit";
|
|
10
|
-
export type LocalAgentOptions = {
|
|
11
|
-
/** The agent's own model name (e.g. "haiku" for Claude Code) for calls that name no model. Defaults to the agent's default. */
|
|
12
|
-
model?: string;
|
|
13
|
-
/** Per-call limit in milliseconds. Defaults to 180000. */
|
|
14
|
-
timeoutMs?: number;
|
|
15
|
-
/** Maximum agent processes running at once. Defaults to 2. */
|
|
16
|
-
concurrency?: number;
|
|
17
|
-
/** Defaults to "subscription". */
|
|
18
|
-
auth?: LocalAgentAuthMode;
|
|
19
|
-
/** Where calls and cast retries are logged. Defaults to the console. */
|
|
20
|
-
logger?: Logger;
|
|
21
|
-
};
|
|
22
|
-
export type LocalAgentConfig = LocalAgentOptions & {
|
|
23
|
-
agent: LocalAgentId;
|
|
24
|
-
/** Path to the agent executable. Defaults to looking it up on PATH. */
|
|
25
|
-
binaryPath?: string;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Sets up the named coding-agent CLI on this machine. Throws right away when the
|
|
29
|
-
* CLI cannot be found; a missing login shows up as the first call's error. Node.js only.
|
|
30
|
-
*/
|
|
31
|
-
export declare function localAgent(config: LocalAgentConfig): LocalAgent;
|
|
32
|
-
/**
|
|
33
|
-
* Sets up the first supported coding-agent CLI that is installed and logged in,
|
|
34
|
-
* trying Claude Code first. Rejects when none is. Node.js only.
|
|
35
|
-
*/
|
|
36
|
-
export declare function findLocalAgent(options?: LocalAgentOptions): Promise<LocalAgent>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { LocalAgentId } from "./agent-id";
|
|
2
|
-
export type LocalAgentStatus = {
|
|
3
|
-
agent: LocalAgentId;
|
|
4
|
-
installed: false;
|
|
5
|
-
loggedIn: false;
|
|
6
|
-
detail?: string;
|
|
7
|
-
} | {
|
|
8
|
-
agent: LocalAgentId;
|
|
9
|
-
installed: true;
|
|
10
|
-
loggedIn: boolean;
|
|
11
|
-
binaryPath: string;
|
|
12
|
-
version?: string;
|
|
13
|
-
detail?: string;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Reports which supported coding agents are installed and logged in, in
|
|
17
|
-
* preference order. Runs each CLI's version and login-status commands, which
|
|
18
|
-
* make no model calls.
|
|
19
|
-
*/
|
|
20
|
-
export declare function detectLocalAgents(binaryPaths?: Partial<Record<LocalAgentId, string>>): Promise<LocalAgentStatus[]>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../../lib/logger";
|
|
2
|
-
import { JsonSchema } from "../../../lib/schema-utils";
|
|
3
|
-
import { AttemptOutcome, AttemptRequest, LlmEngine } from "../llm-engine";
|
|
4
|
-
import { AgentAdapter } from "./adapters/types";
|
|
5
|
-
import { Semaphore } from "./semaphore";
|
|
6
|
-
/** How to run one installed agent's processes. Set up once and shared by all its engines. */
|
|
7
|
-
export type AgentRunner = {
|
|
8
|
-
adapter: AgentAdapter;
|
|
9
|
-
binaryPath: string;
|
|
10
|
-
/** Per-attempt limit. */
|
|
11
|
-
timeoutMs: number;
|
|
12
|
-
/** Env vars removed from the agent's environment. */
|
|
13
|
-
unsetEnv: string[];
|
|
14
|
-
/** Bounds how many agent processes run at once, across all models. */
|
|
15
|
-
limiter: Semaphore;
|
|
16
|
-
logger: Logger;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Answers prompts on one model of a coding-agent CLI installed on this machine.
|
|
20
|
-
* Each attempt is one agent process. maxTokens has no CLI equivalent and is ignored.
|
|
21
|
-
*/
|
|
22
|
-
export declare class LocalAgentEngine implements LlmEngine {
|
|
23
|
-
private readonly runner;
|
|
24
|
-
/** The CLI's own model name; undefined uses the CLI's default. */
|
|
25
|
-
private readonly model;
|
|
26
|
-
constructor(runner: AgentRunner,
|
|
27
|
-
/** The CLI's own model name; undefined uses the CLI's default. */
|
|
28
|
-
model: string | undefined);
|
|
29
|
-
nativeSchema(envelopeSchema: JsonSchema): JsonSchema | null;
|
|
30
|
-
attempt(request: AttemptRequest): Promise<AttemptOutcome>;
|
|
31
|
-
private runAgent;
|
|
32
|
-
}
|