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.
Files changed (80) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +233 -200
  3. package/dist/chunks/local-agent-Bj-QKikS.d.cts +270 -0
  4. package/dist/chunks/local-agent-Bj-QKikS.d.mts +270 -0
  5. package/dist/cjs/chunks/strict-json-schema-bKwaMWm1.cjs +145 -0
  6. package/dist/cjs/index.cjs +989 -11504
  7. package/dist/cjs/local-agent.cjs +819 -877
  8. package/dist/esm/chunks/strict-json-schema-Du2LLrVP.mjs +138 -0
  9. package/dist/esm/index.mjs +987 -11502
  10. package/dist/esm/local-agent.mjs +792 -878
  11. package/dist/index.d.cts +94 -0
  12. package/dist/index.d.mts +94 -0
  13. package/dist/local-agent.d.cts +150 -0
  14. package/dist/local-agent.d.mts +150 -0
  15. package/package.json +12 -17
  16. package/dist/cjs/chunks/strict-json-schema-DUE7RTxG.cjs +0 -177
  17. package/dist/esm/chunks/strict-json-schema-DI9qiH5h.mjs +0 -174
  18. package/dist/types/__tests__/helpers/client-factory.d.ts +0 -39
  19. package/dist/types/__tests__/helpers/index.d.ts +0 -2
  20. package/dist/types/backend/direct.d.ts +0 -29
  21. package/dist/types/backend/gateway.d.ts +0 -24
  22. package/dist/types/backend/types.d.ts +0 -68
  23. package/dist/types/index.d.cts +0 -7
  24. package/dist/types/index.d.mts +0 -7
  25. package/dist/types/lib/auth.d.ts +0 -14
  26. package/dist/types/lib/env.d.ts +0 -1
  27. package/dist/types/lib/error-response.d.ts +0 -6
  28. package/dist/types/lib/error-utils.d.ts +0 -6
  29. package/dist/types/local-agent.d.cts +0 -2
  30. package/dist/types/local-agent.d.mts +0 -2
  31. package/dist/types/nua-llm-core/index.d.ts +0 -23
  32. package/dist/types/nua-llm-core/lib/error-utils.d.ts +0 -6
  33. package/dist/types/nua-llm-core/lib/logger.d.ts +0 -44
  34. package/dist/types/nua-llm-core/lib/nua-errors.d.ts +0 -12
  35. package/dist/types/nua-llm-core/lib/prompt-template-utils.d.ts +0 -2
  36. package/dist/types/nua-llm-core/lib/schema-utils.d.ts +0 -1
  37. package/dist/types/nua-llm-core/lib/stable-stringify.d.ts +0 -1
  38. package/dist/types/nua-llm-core/lib/strict-json-schema.d.ts +0 -7
  39. package/dist/types/nua-llm-core/lib/types.d.ts +0 -8
  40. package/dist/types/nua-llm-core/lib/validate-mappable-input-data.d.ts +0 -4
  41. package/dist/types/nua-llm-core/local-agent.d.ts +0 -7
  42. package/dist/types/nua-llm-core/modules/agent/agent-loop.d.ts +0 -10
  43. package/dist/types/nua-llm-core/modules/agent/agent-turn.d.ts +0 -17
  44. package/dist/types/nua-llm-core/modules/agent/provider-formatters.d.ts +0 -22
  45. package/dist/types/nua-llm-core/modules/agent/run-agent.d.ts +0 -7
  46. package/dist/types/nua-llm-core/modules/agent/types.d.ts +0 -90
  47. package/dist/types/nua-llm-core/modules/cast/cast-request.d.ts +0 -32
  48. package/dist/types/nua-llm-core/modules/cast/envelope.d.ts +0 -9
  49. package/dist/types/nua-llm-core/modules/cast/list-schema.d.ts +0 -32
  50. package/dist/types/nua-llm-core/modules/cast/prompts/list-prompt.d.ts +0 -3
  51. package/dist/types/nua-llm-core/modules/cast/prompts/render-prompt.d.ts +0 -7
  52. package/dist/types/nua-llm-core/modules/cast/prompts/value-prompt.d.ts +0 -3
  53. package/dist/types/nua-llm-core/modules/cast/run-cast.d.ts +0 -44
  54. package/dist/types/nua-llm-core/modules/engine/engine-router.d.ts +0 -23
  55. package/dist/types/nua-llm-core/modules/engine/http/http-engine.d.ts +0 -13
  56. package/dist/types/nua-llm-core/modules/engine/http/provider-call.d.ts +0 -33
  57. package/dist/types/nua-llm-core/modules/engine/http/provider-config.d.ts +0 -70
  58. package/dist/types/nua-llm-core/modules/engine/http/provider-engines.d.ts +0 -35
  59. package/dist/types/nua-llm-core/modules/engine/llm-engine.d.ts +0 -73
  60. package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/claude-code.d.ts +0 -2
  61. package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/codex.d.ts +0 -2
  62. package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/failure-classification.d.ts +0 -4
  63. package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/index.d.ts +0 -3
  64. package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/pi.d.ts +0 -2
  65. package/dist/types/nua-llm-core/modules/engine/local-agent/adapters/types.d.ts +0 -61
  66. package/dist/types/nua-llm-core/modules/engine/local-agent/agent-id.d.ts +0 -4
  67. package/dist/types/nua-llm-core/modules/engine/local-agent/create-local-agent.d.ts +0 -36
  68. package/dist/types/nua-llm-core/modules/engine/local-agent/detect.d.ts +0 -20
  69. package/dist/types/nua-llm-core/modules/engine/local-agent/local-agent-engine.d.ts +0 -32
  70. package/dist/types/nua-llm-core/modules/engine/local-agent/local-agent.d.ts +0 -25
  71. package/dist/types/nua-llm-core/modules/engine/local-agent/process-runner.d.ts +0 -16
  72. package/dist/types/nua-llm-core/modules/engine/local-agent/semaphore.d.ts +0 -8
  73. package/dist/types/nua-llm-core/modules/execution/llm-response-extraction.d.ts +0 -5
  74. package/dist/types/nua-llm-core/modules/json-schema-validation/ajv-instances.d.ts +0 -12
  75. package/dist/types/nua-llm-core/modules/json-schema-validation/nua-json-schema-value-validation.d.ts +0 -10
  76. package/dist/types/nua-llm-core/modules/json-schema-validation/validate-json-schema.d.ts +0 -2
  77. package/dist/types/nua-llm-core/modules/model-info/index.d.ts +0 -15
  78. package/dist/types/nua-llm-core/modules/streaming/sse-parser.d.ts +0 -7
  79. package/dist/types/nua-llm-core/nua-llm-client.d.ts +0 -37
  80. package/dist/types/nua.d.ts +0 -42
@@ -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
- }
@@ -1,25 +0,0 @@
1
- import { Logger } from "../../../lib/logger";
2
- import { ModelInput } from "../../model-info";
3
- import { EngineRouter, Route } from "../engine-router";
4
- import { LocalAgentId } from "./agent-id";
5
- import { AgentRunner } from "./local-agent-engine";
6
- /**
7
- * A coding-agent CLI on this machine, set up once and ready to run casts.
8
- * Created by localAgent() or findLocalAgent().
9
- */
10
- export declare class LocalAgent implements EngineRouter {
11
- private readonly runner;
12
- /** The CLI's own model name for calls that name no model; undefined uses the CLI's default. */
13
- private readonly defaultModel;
14
- readonly agent: LocalAgentId;
15
- readonly logger: Logger;
16
- constructor(runner: AgentRunner,
17
- /** The CLI's own model name for calls that name no model; undefined uses the CLI's default. */
18
- defaultModel: string | undefined);
19
- /**
20
- * No model choice runs the default model. An alias runs the CLI's equivalent
21
- * model, if it has one. Provider models cannot run on a local agent.
22
- */
23
- route(model: ModelInput | undefined): Route;
24
- private routeTo;
25
- }
@@ -1,16 +0,0 @@
1
- import { AgentInvocation, AgentProcessResult } from "./adapters/types";
2
- export type RunInvocationOptions = {
3
- binaryPath: string;
4
- invocation: AgentInvocation;
5
- timeoutMs: number;
6
- /** Env var names removed from the child's environment. */
7
- unsetEnv?: string[];
8
- };
9
- /**
10
- * Runs one CLI invocation in a fresh temporary directory, so the agent sees no
11
- * project files, hooks, MCP config, or instructions, and removes the directory
12
- * afterwards. Rejects only when the process cannot be started.
13
- */
14
- export declare function runInvocation(options: RunInvocationOptions): Promise<AgentProcessResult>;
15
- /** Finds an executable on PATH, honouring PATHEXT on Windows. */
16
- export declare function findOnPath(binaryName: string): string | null;
@@ -1,8 +0,0 @@
1
- /** Runs at most `limit` tasks at once; the rest wait in order. */
2
- export declare class Semaphore {
3
- private readonly limit;
4
- private active;
5
- private readonly waiting;
6
- constructor(limit: number);
7
- run<T>(task: () => Promise<T>): Promise<T>;
8
- }
@@ -1,5 +0,0 @@
1
- export declare function extractThinkingFromResponse(input: string): {
2
- thinking: string;
3
- cleanedResponse: string;
4
- };
5
- export declare function parseJsonFromLlmResponse(input: string): object;
@@ -1,12 +0,0 @@
1
- import Ajv from "ajv";
2
- import Ajv2019 from "ajv/dist/2019.js";
3
- import Ajv2020 from "ajv/dist/2020.js";
4
- declare class AjvInstances {
5
- readonly draft07: Ajv;
6
- readonly draft2019: Ajv2019;
7
- readonly draft2020: Ajv2020;
8
- constructor();
9
- getInstanceForSchema(schema: object): Ajv | Ajv2019 | Ajv2020;
10
- }
11
- export declare const ajvInstances: AjvInstances;
12
- export {};
@@ -1,10 +0,0 @@
1
- export type ValidationResult = {
2
- success: boolean;
3
- data?: object;
4
- error?: string;
5
- };
6
- /**
7
- * Creates a validation function for checking JSON data against a schema using AJV.
8
- * Returns a closure that validates unknown data and returns a typed ValidationResult.
9
- */
10
- export declare function buildNuaJsonSchemaValueValidation(llmRequestId: string, parsedSchema: object): (json: object) => ValidationResult;
@@ -1,2 +0,0 @@
1
- import { NuaValidationError } from "../../lib/nua-errors";
2
- export declare const validateJsonSchema: (schema: Object) => true | NuaValidationError;
@@ -1,15 +0,0 @@
1
- import { NuaValidationError } from "../../lib/nua-errors";
2
- import { LlmProviderId } from "../engine/http/provider-config";
3
- export type ProviderModel = {
4
- provider: LlmProviderId;
5
- model: string;
6
- };
7
- export type ModelAliasName = "fast" | "gemini" | "qwen" | "sonnet" | "opus" | "haiku" | "kimi" | "gpt";
8
- export type ModelInput = ProviderModel | {
9
- alias: ModelAliasName;
10
- };
11
- export declare const MODEL_ALIASES: Record<ModelAliasName, ProviderModel[]>;
12
- export declare const MODEL_ALIAS_NAMES: ModelAliasName[];
13
- export declare function isLlmProviderId(value: unknown): value is LlmProviderId;
14
- export declare function isModelAliasName(value: unknown): value is ModelAliasName;
15
- export declare function resolveModelInput(input: ModelInput | null | undefined, configuredProviders: ReadonlySet<LlmProviderId>): ProviderModel | NuaValidationError;
@@ -1,7 +0,0 @@
1
- /**
2
- * Generic SSE (Server-Sent Events) stream parser.
3
- * Reads a ReadableStream<Uint8Array> and yields each `data:` payload as a string.
4
- * Handles OpenAI's `[DONE]` sentinel and Gemini's stream-close-means-done.
5
- * Uses only web-standard APIs (no node: imports).
6
- */
7
- export declare function parseSSEStream(stream: ReadableStream<Uint8Array>): AsyncGenerator<string>;
@@ -1,37 +0,0 @@
1
- import { ListSchema } from "./modules/cast/list-schema";
2
- import { CastResult } from "./modules/cast/run-cast";
3
- import { EngineRouter } from "./modules/engine/engine-router";
4
- import { ModelInput } from "./modules/model-info";
5
- export type CastValueParams = {
6
- model?: ModelInput;
7
- maxTokens?: number;
8
- input: {
9
- prompt: string;
10
- data?: unknown;
11
- };
12
- output: {
13
- name: string;
14
- schema: object;
15
- };
16
- };
17
- export type CastArrayParams = {
18
- model?: ModelInput;
19
- maxTokens?: number;
20
- input: {
21
- prompt: string;
22
- data: unknown[];
23
- };
24
- /** Built with listSchema(); it names each row's primary key and output field. */
25
- output: ListSchema;
26
- };
27
- /**
28
- * Turns a prompt, data and a JSON schema into a validated value. Where the calls
29
- * run is up to the engine router it is given: providerEngines() for LLM
30
- * providers' APIs, or localAgent() from "nua-llm-core/local-agent".
31
- */
32
- export declare class NuaLlmClient {
33
- private readonly engines;
34
- constructor(engines: EngineRouter);
35
- castValue<T = unknown>(params: CastValueParams): Promise<CastResult<T>>;
36
- castArray<T = unknown>(params: CastArrayParams): Promise<CastResult<T[]>>;
37
- }
@@ -1,42 +0,0 @@
1
- import { DirectConfig } from './backend/direct';
2
- import { GatewayConfig } from './backend/gateway';
3
- import { CastResult, QueueResult } from './backend/types';
4
- import type { ModelInput } from './nua-llm-core/index';
5
- import { z } from 'zod';
6
- export type OutputDef<TSchema extends z.ZodTypeAny> = {
7
- name: string;
8
- schema: TSchema;
9
- };
10
- export type GetOptions<TSchema extends z.ZodTypeAny> = {
11
- input?: unknown;
12
- output: OutputDef<TSchema>;
13
- model?: ModelInput;
14
- };
15
- export type ListOptions<TSchema extends z.ZodTypeAny, TData extends Record<string, unknown>, PrimaryKey extends keyof TData & string> = {
16
- input: TData[];
17
- primaryKey: PrimaryKey;
18
- output: OutputDef<TSchema>;
19
- model?: ModelInput;
20
- };
21
- export type ListResultRow<TSchema extends z.ZodTypeAny, PrimaryKey extends string> = {
22
- [K in PrimaryKey]: string | number;
23
- } & {
24
- [outputName: string]: z.infer<TSchema>;
25
- };
26
- export declare class Nua {
27
- private readonly backend;
28
- private constructor();
29
- static gateway(config: GatewayConfig): Nua;
30
- /**
31
- * Runs casts in this process: on LLM providers' APIs with your API keys (`providers`), or
32
- * on a coding-agent CLI installed on this machine (`localAgent`, set up with `localAgent()` or
33
- * `findLocalAgent()` from "nuabase/local-agent").
34
- */
35
- static direct(config: DirectConfig): Nua;
36
- get(prompt: string): Promise<CastResult<string>>;
37
- get<TSchema extends z.ZodTypeAny>(prompt: string, options: GetOptions<TSchema>): Promise<CastResult<z.infer<TSchema>>>;
38
- list<TSchema extends z.ZodTypeAny, TData extends Record<string, unknown>, PrimaryKey extends keyof TData & string>(prompt: string, options: ListOptions<TSchema, TData, PrimaryKey>): Promise<CastResult<ListResultRow<TSchema, PrimaryKey>[]>>;
39
- queueGet(prompt: string): Promise<QueueResult>;
40
- queueGet<TSchema extends z.ZodTypeAny>(prompt: string, options: GetOptions<TSchema>): Promise<QueueResult>;
41
- queueList<TSchema extends z.ZodTypeAny, TData extends Record<string, unknown>, PrimaryKey extends keyof TData & string>(prompt: string, options: ListOptions<TSchema, TData, PrimaryKey>): Promise<QueueResult>;
42
- }