nuabase 2.3.11 → 3.0.1
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 +60 -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 +989 -11504
- package/dist/cjs/local-agent.cjs +819 -877
- package/dist/esm/chunks/strict-json-schema-Du2LLrVP.mjs +138 -0
- package/dist/esm/index.mjs +987 -11502
- package/dist/esm/local-agent.mjs +792 -878
- 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 -17
- package/dist/cjs/chunks/strict-json-schema-DUE7RTxG.cjs +0 -177
- package/dist/esm/chunks/strict-json-schema-DI9qiH5h.mjs +0 -174
- 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 -13
- 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 -70
- 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 +0,0 @@
|
|
|
1
|
-
export declare function stableStringify(value: unknown): string;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { JsonSchema } from "./schema-utils";
|
|
2
|
-
/**
|
|
3
|
-
* Converts a schema to OpenAI strict mode, or returns null when that would
|
|
4
|
-
* change which values are valid (optional properties, open-ended objects,
|
|
5
|
-
* unsupported keywords).
|
|
6
|
-
*/
|
|
7
|
-
export declare function toStrictSchema(schema: JsonSchema): JsonSchema | null;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type UserDataPKValue = string | number;
|
|
2
|
-
export type MappableInputDataRow = Record<string, unknown>;
|
|
3
|
-
export type MappableInputData = MappableInputDataRow[];
|
|
4
|
-
export type NormalizedUsage = {
|
|
5
|
-
promptTokens: number;
|
|
6
|
-
completionTokens: number;
|
|
7
|
-
totalTokens: number;
|
|
8
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { NuaValidationError } from "./nua-errors";
|
|
2
|
-
export type MappableInputDataRow = Record<string, unknown>;
|
|
3
|
-
export type MappableInputData = MappableInputDataRow[];
|
|
4
|
-
export declare function validateMappableInputData(data: unknown, primaryKey: string | null): NuaValidationError | MappableInputData;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { findLocalAgent, localAgent } from "./modules/engine/local-agent/create-local-agent";
|
|
2
|
-
export type { LocalAgentAuthMode, LocalAgentConfig, LocalAgentOptions, } from "./modules/engine/local-agent/create-local-agent";
|
|
3
|
-
export type { LocalAgent } from "./modules/engine/local-agent/local-agent";
|
|
4
|
-
export { detectLocalAgents } from "./modules/engine/local-agent/detect";
|
|
5
|
-
export type { LocalAgentStatus } from "./modules/engine/local-agent/detect";
|
|
6
|
-
export { LOCAL_AGENT_IDS, isLocalAgentId } from "./modules/engine/local-agent/agent-id";
|
|
7
|
-
export type { LocalAgentId } from "./modules/engine/local-agent/agent-id";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AgentEventHandler, AgentResult, AgentTool, AgenticParsedResponse, ConversationMessage } from "./types";
|
|
2
|
-
export type SendAgenticRequestFn = (messages: ConversationMessage[], tools: AgentTool[], systemPrompt?: string) => Promise<AgenticParsedResponse>;
|
|
3
|
-
export declare function runAgentLoop(params: {
|
|
4
|
-
messages: ConversationMessage[];
|
|
5
|
-
tools: AgentTool[];
|
|
6
|
-
systemPrompt?: string;
|
|
7
|
-
maxTurns: number;
|
|
8
|
-
sendRequest: SendAgenticRequestFn;
|
|
9
|
-
onEvent?: AgentEventHandler;
|
|
10
|
-
}): Promise<AgentResult>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../lib/logger";
|
|
2
|
-
import { ProviderTarget } from "../engine/http/provider-call";
|
|
3
|
-
import { AgentEventHandler, AgenticParsedResponse, ConversationMessage, ToolDefinition } from "./types";
|
|
4
|
-
export type AgentTurn = {
|
|
5
|
-
target: ProviderTarget;
|
|
6
|
-
maxTokens: number;
|
|
7
|
-
messages: ConversationMessage[];
|
|
8
|
-
tools: ToolDefinition[];
|
|
9
|
-
systemPrompt?: string;
|
|
10
|
-
/** When set, the reply is streamed and reported through it as it arrives. */
|
|
11
|
-
onEvent?: AgentEventHandler;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Sends one turn of a tool-calling conversation to an LLM provider's HTTP API.
|
|
15
|
-
* Throws when the call fails; the agent loop reports that as the end of the conversation.
|
|
16
|
-
*/
|
|
17
|
-
export declare function sendAgentTurn(turn: AgentTurn, logger: Logger): Promise<AgenticParsedResponse>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ProviderRequestBase } from "../engine/http/provider-config";
|
|
2
|
-
import { AgentEventHandler, AgenticParsedResponse, ConversationMessage, ToolDefinition } from "./types";
|
|
3
|
-
export declare function buildOpenAiAgenticRequest(options: {
|
|
4
|
-
messages: ConversationMessage[];
|
|
5
|
-
tools: ToolDefinition[];
|
|
6
|
-
model: string;
|
|
7
|
-
maxTokens: number;
|
|
8
|
-
systemPrompt?: string;
|
|
9
|
-
stream?: boolean;
|
|
10
|
-
}, baseUrl: string, apiKey: string): ProviderRequestBase;
|
|
11
|
-
export declare function parseOpenAiAgenticResponse(response: Response, errorLabel: string): Promise<AgenticParsedResponse>;
|
|
12
|
-
export declare function buildGeminiAgenticRequest(options: {
|
|
13
|
-
messages: ConversationMessage[];
|
|
14
|
-
tools: ToolDefinition[];
|
|
15
|
-
model: string;
|
|
16
|
-
maxTokens: number;
|
|
17
|
-
systemPrompt?: string;
|
|
18
|
-
stream?: boolean;
|
|
19
|
-
}, apiKey: string): ProviderRequestBase;
|
|
20
|
-
export declare function parseGeminiAgenticResponse(response: Response): Promise<AgenticParsedResponse>;
|
|
21
|
-
export declare function streamOpenAiAgenticResponse(response: Response, errorLabel: string, onEvent?: AgentEventHandler): Promise<AgenticParsedResponse>;
|
|
22
|
-
export declare function streamGeminiAgenticResponse(response: Response, onEvent?: AgentEventHandler): Promise<AgenticParsedResponse>;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ProviderEngines } from "../engine/http/provider-engines";
|
|
2
|
-
import { AgentResult, AgentRunParams } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Runs a multi-turn, tool-calling conversation on an LLM provider's API. It needs
|
|
5
|
-
* the providers' API directly, so it takes provider engines rather than any engine router.
|
|
6
|
-
*/
|
|
7
|
-
export declare function runAgent(providers: ProviderEngines, params: AgentRunParams): Promise<AgentResult>;
|
|
@@ -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,13 +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 { ProviderTarget } from "./provider-call";
|
|
5
|
-
/** Answers cast attempts on one model of an LLM provider's HTTP API. */
|
|
6
|
-
export declare class HttpEngine implements LlmEngine {
|
|
7
|
-
private readonly target;
|
|
8
|
-
private readonly logger;
|
|
9
|
-
constructor(target: ProviderTarget, logger: Logger);
|
|
10
|
-
/** Enforced in strict mode on models whose provider supports it; other models get the schema in the prompt. */
|
|
11
|
-
nativeSchema(envelopeSchema: JsonSchema): JsonSchema | null;
|
|
12
|
-
attempt(request: AttemptRequest): Promise<AttemptOutcome>;
|
|
13
|
-
}
|
|
@@ -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,70 +0,0 @@
|
|
|
1
|
-
import { JsonSchema } from "../../../lib/schema-utils";
|
|
2
|
-
export type ProviderRequestBase = {
|
|
3
|
-
url: string;
|
|
4
|
-
method?: string;
|
|
5
|
-
headers?: Record<string, string>;
|
|
6
|
-
body?: unknown;
|
|
7
|
-
/** Request details with secrets removed for logging */
|
|
8
|
-
loggableUrl?: string;
|
|
9
|
-
loggableHeaders?: Record<string, string>;
|
|
10
|
-
loggableBody?: unknown;
|
|
11
|
-
};
|
|
12
|
-
export declare const LLM_PROVIDER_IDS: readonly ["groq", "cerebras", "gemini", "openrouter"];
|
|
13
|
-
export type LlmProviderId = (typeof LLM_PROVIDER_IDS)[number];
|
|
14
|
-
export interface ProviderRequestOptions {
|
|
15
|
-
prompt: string;
|
|
16
|
-
model: string;
|
|
17
|
-
maxTokens: number;
|
|
18
|
-
assistantPrefillPrompt?: string;
|
|
19
|
-
/** A JSON schema the provider enforces on the reply, in strict mode. */
|
|
20
|
-
responseSchema?: JsonSchema;
|
|
21
|
-
}
|
|
22
|
-
export type NormalizedUsage = {
|
|
23
|
-
promptTokens: number;
|
|
24
|
-
completionTokens: number;
|
|
25
|
-
totalTokens: number;
|
|
26
|
-
};
|
|
27
|
-
export declare const normalizedUsageZero: NormalizedUsage;
|
|
28
|
-
export type ProviderParsedResponse = {
|
|
29
|
-
text: string;
|
|
30
|
-
usage: NormalizedUsage;
|
|
31
|
-
};
|
|
32
|
-
export interface ProviderConfig {
|
|
33
|
-
providerId: LlmProviderId;
|
|
34
|
-
apiOperation: string;
|
|
35
|
-
errorLabel: string;
|
|
36
|
-
/** Models that can enforce a response JSON schema in strict mode. */
|
|
37
|
-
strictSchemaModels?: ReadonlySet<string>;
|
|
38
|
-
buildRequest(options: ProviderRequestOptions, apiKey: string): ProviderRequestBase;
|
|
39
|
-
parseResponse(response: Response): Promise<ProviderParsedResponse>;
|
|
40
|
-
}
|
|
41
|
-
type OpenAiThinkingDetail = {
|
|
42
|
-
type?: string;
|
|
43
|
-
summary?: string;
|
|
44
|
-
format?: string;
|
|
45
|
-
index?: number;
|
|
46
|
-
};
|
|
47
|
-
type OpenAiThinkingMessage = {
|
|
48
|
-
content?: string | null;
|
|
49
|
-
reasoning?: string | null;
|
|
50
|
-
reasoning_details?: Array<OpenAiThinkingDetail | Record<string, unknown>>;
|
|
51
|
-
};
|
|
52
|
-
export type OpenAiUsage = {
|
|
53
|
-
prompt_tokens?: number;
|
|
54
|
-
completion_tokens?: number;
|
|
55
|
-
total_tokens?: number;
|
|
56
|
-
prompt_tokens_details?: Record<string, unknown> | null;
|
|
57
|
-
completion_tokens_details?: Record<string, unknown> | null;
|
|
58
|
-
[key: string]: unknown;
|
|
59
|
-
} | null;
|
|
60
|
-
export type GeminiUsageMetadata = {
|
|
61
|
-
promptTokenCount?: number;
|
|
62
|
-
candidatesTokenCount?: number;
|
|
63
|
-
totalTokenCount?: number;
|
|
64
|
-
[key: string]: unknown;
|
|
65
|
-
};
|
|
66
|
-
export declare const normalizeOpenAiUsage: (usage: OpenAiUsage | undefined) => NormalizedUsage;
|
|
67
|
-
export declare const normalizeGeminiUsage: (usage: GeminiUsageMetadata | undefined) => NormalizedUsage;
|
|
68
|
-
export declare const extractOpenAiMessageText: (message: OpenAiThinkingMessage | undefined) => string | undefined;
|
|
69
|
-
export declare const providerConfigs: Record<LlmProviderId, ProviderConfig>;
|
|
70
|
-
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;
|