extrait 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 +21 -0
- package/README.md +247 -0
- package/dist/extract.d.ts +3 -0
- package/dist/format.d.ts +8 -0
- package/dist/index.cjs +4318 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +4290 -0
- package/dist/llm.d.ts +13 -0
- package/dist/markdown.d.ts +3 -0
- package/dist/mcp.d.ts +40 -0
- package/dist/outdent.d.ts +10 -0
- package/dist/parse.d.ts +4 -0
- package/dist/prompt.d.ts +10 -0
- package/dist/providers/anthropic-compatible.d.ts +16 -0
- package/dist/providers/mcp-runtime.d.ts +38 -0
- package/dist/providers/openai-compatible.d.ts +13 -0
- package/dist/providers/registry.d.ts +32 -0
- package/dist/providers/stream-utils.d.ts +2 -0
- package/dist/providers/utils.d.ts +9 -0
- package/dist/schema-builder.d.ts +25 -0
- package/dist/schema.d.ts +2 -0
- package/dist/structured.d.ts +86 -0
- package/dist/think.d.ts +7 -0
- package/dist/types.d.ts +311 -0
- package/dist/utils/common.d.ts +2 -0
- package/dist/utils/debug-colors.d.ts +7 -0
- package/package.json +42 -0
package/dist/llm.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import { type ModelAdapterConfig, type ProviderRegistry } from "./providers/registry";
|
|
3
|
+
import type { LLMAdapter, StructuredCallOptions, StructuredPromptBuilder, StructuredResult } from "./types";
|
|
4
|
+
export interface CreateLLMOptions extends ModelAdapterConfig {
|
|
5
|
+
defaults?: StructuredCallOptions<z.ZodTypeAny>;
|
|
6
|
+
}
|
|
7
|
+
export interface LLMClient {
|
|
8
|
+
adapter: LLMAdapter;
|
|
9
|
+
provider?: string;
|
|
10
|
+
model?: string;
|
|
11
|
+
structured<TSchema extends z.ZodTypeAny>(schema: TSchema, prompt: StructuredPromptBuilder, options?: StructuredCallOptions<TSchema>): Promise<StructuredResult<z.infer<TSchema>>>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createLLM(config: CreateLLMOptions, registry?: ProviderRegistry): LLMClient;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MarkdownCodeBlock, MarkdownCodeOptions } from "./types";
|
|
2
|
+
export declare function extractMarkdownCodeBlocks(input: string, options?: MarkdownCodeOptions): MarkdownCodeBlock[];
|
|
3
|
+
export declare function extractFirstMarkdownCode(input: string, options?: Omit<MarkdownCodeOptions, "firstOnly">): MarkdownCodeBlock | null;
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { type StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
import { type StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
5
|
+
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
6
|
+
import type { MCPToolClient } from "./types";
|
|
7
|
+
export interface MCPClientInfo {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MCPStdioTransportConfig extends Omit<StdioServerParameters, "command"> {
|
|
12
|
+
type: "stdio";
|
|
13
|
+
command: string;
|
|
14
|
+
}
|
|
15
|
+
export interface MCPStreamableHTTPTransportConfig {
|
|
16
|
+
type: "streamable-http";
|
|
17
|
+
url: string | URL;
|
|
18
|
+
options?: StreamableHTTPClientTransportOptions;
|
|
19
|
+
}
|
|
20
|
+
export interface MCPInMemoryTransportConfig {
|
|
21
|
+
type: "in-memory";
|
|
22
|
+
transport: InMemoryTransport;
|
|
23
|
+
}
|
|
24
|
+
export type MCPTransportConfig = MCPStdioTransportConfig | MCPStreamableHTTPTransportConfig | MCPInMemoryTransportConfig;
|
|
25
|
+
export interface CreateMCPClientOptions {
|
|
26
|
+
id: string;
|
|
27
|
+
transport: MCPTransportConfig;
|
|
28
|
+
clientInfo?: MCPClientInfo;
|
|
29
|
+
}
|
|
30
|
+
export interface ManagedMCPToolClient extends MCPToolClient {
|
|
31
|
+
sdkClient: Client;
|
|
32
|
+
transport?: Transport;
|
|
33
|
+
}
|
|
34
|
+
export declare function createMCPClient(options: CreateMCPClientOptions): Promise<ManagedMCPToolClient>;
|
|
35
|
+
export interface WrapMCPClientOptions {
|
|
36
|
+
id: string;
|
|
37
|
+
client: Client;
|
|
38
|
+
transport?: Transport;
|
|
39
|
+
}
|
|
40
|
+
export declare function wrapMCPClient(options: WrapMCPClientOptions): ManagedMCPToolClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface OutdentOptions {
|
|
2
|
+
trimLeadingNewline?: boolean;
|
|
3
|
+
trimTrailingNewline?: boolean;
|
|
4
|
+
newline?: string | null;
|
|
5
|
+
}
|
|
6
|
+
export interface OutdentTag {
|
|
7
|
+
(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
8
|
+
string(input: string): string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createOutdent(options?: OutdentOptions): OutdentTag;
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { ParseLLMOutputOptions, ParseLLMOutputResult } from "./types";
|
|
3
|
+
export declare function parseLLMOutput<TSchema extends z.ZodTypeAny>(output: string, schema: TSchema, options?: ParseLLMOutputOptions): ParseLLMOutputResult<z.infer<TSchema>>;
|
|
4
|
+
export declare function formatZodIssues(issues: z.ZodIssue[]): string;
|
package/dist/prompt.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StructuredPromptPayload, StructuredPromptResolver } from "./types";
|
|
2
|
+
export interface PromptMessageBuilder extends StructuredPromptResolver {
|
|
3
|
+
system(input: string): PromptMessageBuilder;
|
|
4
|
+
system(strings: TemplateStringsArray, ...values: unknown[]): PromptMessageBuilder;
|
|
5
|
+
user(input: string): PromptMessageBuilder;
|
|
6
|
+
user(strings: TemplateStringsArray, ...values: unknown[]): PromptMessageBuilder;
|
|
7
|
+
build(): StructuredPromptPayload;
|
|
8
|
+
}
|
|
9
|
+
export declare function prompt(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
10
|
+
export declare function prompt(): PromptMessageBuilder;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTTPHeaders, LLMAdapter } from "../types";
|
|
2
|
+
export interface AnthropicCompatibleAdapterOptions {
|
|
3
|
+
baseURL: string;
|
|
4
|
+
model: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
path?: string;
|
|
7
|
+
headers?: HTTPHeaders;
|
|
8
|
+
version?: string;
|
|
9
|
+
defaultMaxTokens?: number;
|
|
10
|
+
defaultMaxToolRounds?: number;
|
|
11
|
+
defaultBody?: Record<string, unknown>;
|
|
12
|
+
fetcher?: typeof fetch;
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_ANTHROPIC_MAX_TOKENS = 1024;
|
|
15
|
+
export declare const DEFAULT_ANTHROPIC_VERSION = "2023-06-01";
|
|
16
|
+
export declare function createAnthropicCompatibleAdapter(options: AnthropicCompatibleAdapterOptions): LLMAdapter;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { LLMRequest, LLMToolCall, LLMToolExecution, MCPToolClient } from "../types";
|
|
2
|
+
export interface RuntimeToolCall {
|
|
3
|
+
id?: string;
|
|
4
|
+
type?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
arguments?: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface ResolvedMCPTool {
|
|
9
|
+
name: string;
|
|
10
|
+
remoteName: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
inputSchema: Record<string, unknown>;
|
|
13
|
+
clientId: string;
|
|
14
|
+
client: MCPToolClient;
|
|
15
|
+
}
|
|
16
|
+
export interface ResolvedMCPToolset {
|
|
17
|
+
tools: ResolvedMCPTool[];
|
|
18
|
+
byName: Map<string, ResolvedMCPTool>;
|
|
19
|
+
}
|
|
20
|
+
export interface ExecuteMCPToolCallsOptions {
|
|
21
|
+
round: number;
|
|
22
|
+
request: LLMRequest;
|
|
23
|
+
provider?: string;
|
|
24
|
+
model?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ExecutedMCPToolCall {
|
|
27
|
+
call: LLMToolCall;
|
|
28
|
+
execution: LLMToolExecution;
|
|
29
|
+
}
|
|
30
|
+
export declare const DEFAULT_MAX_TOOL_ROUNDS = 8;
|
|
31
|
+
export declare function resolveMCPToolset(clients: MCPToolClient[] | undefined): Promise<ResolvedMCPToolset>;
|
|
32
|
+
export declare function toProviderFunctionTools(toolset: ResolvedMCPToolset): Array<Record<string, unknown>> | undefined;
|
|
33
|
+
export declare function executeMCPToolCalls(calls: RuntimeToolCall[], toolset: ResolvedMCPToolset, context: ExecuteMCPToolCallsOptions): Promise<ExecutedMCPToolCall[]>;
|
|
34
|
+
export declare function hasMCPClients(clients: MCPToolClient[] | undefined): boolean;
|
|
35
|
+
export declare function normalizeMaxToolRounds(value: number | undefined): number;
|
|
36
|
+
export declare function parseToolArguments(value: unknown): unknown;
|
|
37
|
+
export declare function stringifyToolOutput(value: unknown): string;
|
|
38
|
+
export declare function formatToolExecutionDebugLine(execution: LLMToolExecution): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HTTPHeaders, LLMAdapter } from "../types";
|
|
2
|
+
export interface OpenAICompatibleAdapterOptions {
|
|
3
|
+
baseURL: string;
|
|
4
|
+
model: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
path?: string;
|
|
7
|
+
responsesPath?: string;
|
|
8
|
+
defaultMaxToolRounds?: number;
|
|
9
|
+
headers?: HTTPHeaders;
|
|
10
|
+
defaultBody?: Record<string, unknown>;
|
|
11
|
+
fetcher?: typeof fetch;
|
|
12
|
+
}
|
|
13
|
+
export declare function createOpenAICompatibleAdapter(options: OpenAICompatibleAdapterOptions): LLMAdapter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { HTTPHeaders, LLMAdapter } from "../types";
|
|
2
|
+
export type BuiltinProviderKind = "openai-compatible" | "anthropic-compatible";
|
|
3
|
+
export interface ProviderFactory<TOptions = unknown> {
|
|
4
|
+
(options: TOptions): LLMAdapter;
|
|
5
|
+
}
|
|
6
|
+
export interface ProviderRegistry {
|
|
7
|
+
register<TOptions>(kind: string, factory: ProviderFactory<TOptions>): void;
|
|
8
|
+
create<TOptions>(kind: string, options: TOptions): LLMAdapter;
|
|
9
|
+
has(kind: string): boolean;
|
|
10
|
+
list(): string[];
|
|
11
|
+
}
|
|
12
|
+
export interface ProviderTransportConfig {
|
|
13
|
+
baseURL?: string;
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
path?: string;
|
|
16
|
+
headers?: HTTPHeaders;
|
|
17
|
+
defaultBody?: Record<string, unknown>;
|
|
18
|
+
version?: string;
|
|
19
|
+
fetcher?: typeof fetch;
|
|
20
|
+
}
|
|
21
|
+
export interface ModelAdapterConfig {
|
|
22
|
+
provider: string;
|
|
23
|
+
model: string;
|
|
24
|
+
baseURL?: string;
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
transport?: ProviderTransportConfig;
|
|
27
|
+
options?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export declare function createProviderRegistry(): ProviderRegistry;
|
|
30
|
+
export declare function registerBuiltinProviders(registry: ProviderRegistry): ProviderRegistry;
|
|
31
|
+
export declare function createDefaultProviderRegistry(): ProviderRegistry;
|
|
32
|
+
export declare function createModelAdapter(config: ModelAdapterConfig, registry?: ProviderRegistry): LLMAdapter;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LLMUsage } from "../types";
|
|
2
|
+
export declare function normalizeBaseURL(baseURL: string): string;
|
|
3
|
+
export declare function buildURL(baseURL: string, path: string): string;
|
|
4
|
+
export declare function safeJSONParse(input: string): unknown;
|
|
5
|
+
export declare function cleanUndefined<T extends Record<string, unknown>>(input: T): T;
|
|
6
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
7
|
+
export declare function pickString(value: unknown): string | undefined;
|
|
8
|
+
export declare function toFiniteNumber(value: unknown): number | undefined;
|
|
9
|
+
export declare function mergeUsage(base: LLMUsage | undefined, next: LLMUsage | undefined): LLMUsage | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare module "zod" {
|
|
3
|
+
interface ZodNumber {
|
|
4
|
+
coerce(): z.ZodNumber;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export interface SchemaMetadataSummary {
|
|
8
|
+
name?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
requiredFields: string[];
|
|
11
|
+
defaults: Record<string, unknown>;
|
|
12
|
+
fieldDescriptions: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export declare const s: {
|
|
15
|
+
schema<TSchema extends z.ZodTypeAny>(name: string, schema: TSchema): TSchema;
|
|
16
|
+
string(): z.ZodString;
|
|
17
|
+
number(): z.ZodNumber;
|
|
18
|
+
boolean(): z.ZodBoolean;
|
|
19
|
+
array<TSchema extends z.ZodTypeAny>(schema: TSchema): z.ZodArray<TSchema>;
|
|
20
|
+
object<TShape extends z.ZodRawShape>(shape: TShape): z.ZodObject<TShape>;
|
|
21
|
+
};
|
|
22
|
+
export declare function setSchemaName<TSchema extends z.ZodTypeAny>(schema: TSchema, name: string): TSchema;
|
|
23
|
+
export declare function getSchemaName(schema: z.ZodTypeAny): string | undefined;
|
|
24
|
+
export declare function inspectSchemaMetadata(schema: z.ZodTypeAny): SchemaMetadataSummary;
|
|
25
|
+
export declare function inferSchemaExample(schema: z.ZodTypeAny): unknown | null;
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { LLMAdapter, ParseLLMOutputOptions, StructuredCallOptions, StructuredError, StructuredOptions, StructuredPromptBuilder, StructuredResult } from "./types";
|
|
3
|
+
export declare class StructuredParseError extends Error implements StructuredError {
|
|
4
|
+
readonly name: "StructuredParseError";
|
|
5
|
+
readonly raw: string;
|
|
6
|
+
readonly thinkBlocks: StructuredError["thinkBlocks"];
|
|
7
|
+
readonly candidates: string[];
|
|
8
|
+
readonly zodIssues?: z.ZodIssue[];
|
|
9
|
+
readonly repairLog?: string[];
|
|
10
|
+
readonly attempt: number;
|
|
11
|
+
constructor(input: {
|
|
12
|
+
message?: string;
|
|
13
|
+
raw: string;
|
|
14
|
+
thinkBlocks: StructuredError["thinkBlocks"];
|
|
15
|
+
candidates: string[];
|
|
16
|
+
zodIssues?: z.ZodIssue[];
|
|
17
|
+
repairLog?: string[];
|
|
18
|
+
attempt: number;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export interface BuildDefaultStructuredPromptOptions {
|
|
22
|
+
objectInstruction?: string;
|
|
23
|
+
styleInstruction?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SelfHealPromptTextOptions {
|
|
26
|
+
fixInstruction?: string;
|
|
27
|
+
returnInstruction?: string;
|
|
28
|
+
noIssuesMessage?: string;
|
|
29
|
+
validationErrorsLabel?: string;
|
|
30
|
+
rawOutputLabel?: string;
|
|
31
|
+
contextLabel?: string;
|
|
32
|
+
}
|
|
33
|
+
type ParseDefaults = Pick<ParseLLMOutputOptions, "repair" | "maxCandidates" | "acceptArrays">;
|
|
34
|
+
export declare const DEFAULT_STRUCTURED_OBJECT_INSTRUCTION = "Return exactly one strict JSON object.";
|
|
35
|
+
export declare const DEFAULT_STRUCTURED_STYLE_INSTRUCTION = "No prose. No markdown.";
|
|
36
|
+
export declare const DEFAULT_SELF_HEAL_FIX_INSTRUCTION: string;
|
|
37
|
+
export declare const DEFAULT_SELF_HEAL_RETURN_INSTRUCTION: string;
|
|
38
|
+
export declare const DEFAULT_SELF_HEAL_NO_ISSUES_MESSAGE: string;
|
|
39
|
+
export declare const DEFAULT_SELF_HEAL_VALIDATION_LABEL: string;
|
|
40
|
+
export declare const DEFAULT_SELF_HEAL_RAW_OUTPUT_LABEL: string;
|
|
41
|
+
export declare const DEFAULT_SELF_HEAL_CONTEXT_LABEL: string;
|
|
42
|
+
export declare const DEFAULT_SELF_HEAL_PROTOCOL = "extrait.self-heal.v2";
|
|
43
|
+
export declare const DEFAULT_SELF_HEAL_MAX_CONTEXT_CHARS = 12000;
|
|
44
|
+
export declare const DEFAULT_SELF_HEAL_STOP_ON_NO_PROGRESS = true;
|
|
45
|
+
export declare const DEFAULT_STRICT_PARSE_OPTIONS: ParseDefaults;
|
|
46
|
+
export declare const DEFAULT_LOOSE_PARSE_OPTIONS: ParseDefaults;
|
|
47
|
+
export declare const DEFAULT_SELF_HEAL_BY_MODE: {
|
|
48
|
+
readonly loose: {
|
|
49
|
+
readonly enabled: true;
|
|
50
|
+
readonly maxAttempts: 1;
|
|
51
|
+
};
|
|
52
|
+
readonly strict: {
|
|
53
|
+
readonly enabled: false;
|
|
54
|
+
readonly maxAttempts: 0;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export declare function buildDefaultStructuredPrompt(task: string, options?: BuildDefaultStructuredPromptOptions): string;
|
|
58
|
+
interface SelfHealPromptInput {
|
|
59
|
+
rawOutput: string;
|
|
60
|
+
issues: z.ZodIssue[];
|
|
61
|
+
schema: z.ZodTypeAny;
|
|
62
|
+
schemaInstruction?: string;
|
|
63
|
+
selectedOutput?: string;
|
|
64
|
+
selectedInput?: "candidate" | "sanitized" | "raw";
|
|
65
|
+
sanitizedOutput?: string;
|
|
66
|
+
parserErrors?: Array<{
|
|
67
|
+
stage: string;
|
|
68
|
+
message: string;
|
|
69
|
+
candidateId?: string;
|
|
70
|
+
}>;
|
|
71
|
+
diagnostics?: Array<{
|
|
72
|
+
candidateId: string;
|
|
73
|
+
stage: string;
|
|
74
|
+
usedRepair: boolean;
|
|
75
|
+
message?: string;
|
|
76
|
+
}>;
|
|
77
|
+
repairLog?: string[];
|
|
78
|
+
attempt?: number;
|
|
79
|
+
previousAttempt?: number;
|
|
80
|
+
maxContextChars?: number;
|
|
81
|
+
text?: SelfHealPromptTextOptions;
|
|
82
|
+
}
|
|
83
|
+
export declare function buildSelfHealPrompt(input: SelfHealPromptInput): string;
|
|
84
|
+
export declare function structured<TSchema extends z.ZodTypeAny>(adapter: LLMAdapter, schema: TSchema, prompt: StructuredPromptBuilder, options?: StructuredCallOptions<TSchema>): Promise<StructuredResult<z.infer<TSchema>>>;
|
|
85
|
+
export declare function structured<TSchema extends z.ZodTypeAny>(adapter: LLMAdapter, options: StructuredOptions<TSchema>): Promise<StructuredResult<z.infer<TSchema>>>;
|
|
86
|
+
export {};
|
package/dist/think.d.ts
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
export type StructuredMode = "loose" | "strict";
|
|
3
|
+
export type HTTPHeaders = Record<string, string>;
|
|
4
|
+
export interface ExtractionCandidate {
|
|
5
|
+
id: string;
|
|
6
|
+
source: "fenced" | "scan" | "raw";
|
|
7
|
+
content: string;
|
|
8
|
+
language?: string | null;
|
|
9
|
+
parseHint?: ExtractionParseHint;
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
score: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ExtractionParseHint {
|
|
15
|
+
success: boolean;
|
|
16
|
+
parsed: unknown | null;
|
|
17
|
+
repaired: string | null;
|
|
18
|
+
usedRepair: boolean;
|
|
19
|
+
stage: "parse" | "repair";
|
|
20
|
+
error: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ExtractionHeuristicsOptions {
|
|
23
|
+
firstPassMin: number;
|
|
24
|
+
firstPassCap: number;
|
|
25
|
+
firstPassMultiplier: number;
|
|
26
|
+
secondPassMin: number;
|
|
27
|
+
secondPassCap: number;
|
|
28
|
+
secondPassMultiplier: number;
|
|
29
|
+
hintMaxLength: number;
|
|
30
|
+
}
|
|
31
|
+
export interface ExtractJsonCandidatesOptions {
|
|
32
|
+
maxCandidates?: number;
|
|
33
|
+
acceptArrays?: boolean;
|
|
34
|
+
allowRepairHints?: boolean;
|
|
35
|
+
heuristics?: Partial<ExtractionHeuristicsOptions>;
|
|
36
|
+
}
|
|
37
|
+
export interface ParseTraceEvent {
|
|
38
|
+
stage: "extract" | "repair" | "parse" | "validate" | "result";
|
|
39
|
+
level: "info" | "error";
|
|
40
|
+
message: string;
|
|
41
|
+
candidateId?: string;
|
|
42
|
+
details?: unknown;
|
|
43
|
+
}
|
|
44
|
+
export interface ParseLLMOutputOptions {
|
|
45
|
+
repair?: boolean;
|
|
46
|
+
maxCandidates?: number;
|
|
47
|
+
acceptArrays?: boolean;
|
|
48
|
+
extraction?: Partial<ExtractionHeuristicsOptions>;
|
|
49
|
+
onTrace?: (event: ParseTraceEvent) => void;
|
|
50
|
+
}
|
|
51
|
+
export interface PipelineError {
|
|
52
|
+
stage: "extract" | "repair" | "parse" | "validate" | "llm" | "self-heal";
|
|
53
|
+
message: string;
|
|
54
|
+
candidateId?: string;
|
|
55
|
+
details?: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface CandidateDiagnostics {
|
|
58
|
+
candidateId: string;
|
|
59
|
+
source: ExtractionCandidate["source"];
|
|
60
|
+
usedRepair: boolean;
|
|
61
|
+
parseSuccess: boolean;
|
|
62
|
+
validationSuccess: boolean;
|
|
63
|
+
selected: boolean;
|
|
64
|
+
stage: "repair" | "parse" | "validate" | "success";
|
|
65
|
+
message?: string;
|
|
66
|
+
zodIssues?: z.ZodIssue[];
|
|
67
|
+
}
|
|
68
|
+
export interface ThinkBlock {
|
|
69
|
+
id: string;
|
|
70
|
+
content: string;
|
|
71
|
+
raw: string;
|
|
72
|
+
start: number;
|
|
73
|
+
end: number;
|
|
74
|
+
}
|
|
75
|
+
export interface ThinkDiagnostics {
|
|
76
|
+
unterminatedCount: number;
|
|
77
|
+
nestedCount: number;
|
|
78
|
+
hiddenChars: number;
|
|
79
|
+
}
|
|
80
|
+
export interface ParseLLMOutputResult<T> {
|
|
81
|
+
success: boolean;
|
|
82
|
+
data: T | null;
|
|
83
|
+
raw: string;
|
|
84
|
+
sanitizedRaw: string;
|
|
85
|
+
thinkBlocks: ThinkBlock[];
|
|
86
|
+
thinkDiagnostics: ThinkDiagnostics;
|
|
87
|
+
parsed: unknown | null;
|
|
88
|
+
candidate: ExtractionCandidate | null;
|
|
89
|
+
repaired: string | null;
|
|
90
|
+
candidates: ExtractionCandidate[];
|
|
91
|
+
diagnostics: CandidateDiagnostics[];
|
|
92
|
+
errors: PipelineError[];
|
|
93
|
+
zodIssues: z.ZodIssue[];
|
|
94
|
+
}
|
|
95
|
+
export interface MCPToolSchema {
|
|
96
|
+
type?: string;
|
|
97
|
+
properties?: Record<string, unknown>;
|
|
98
|
+
required?: string[];
|
|
99
|
+
[key: string]: unknown;
|
|
100
|
+
}
|
|
101
|
+
export interface MCPToolDescriptor {
|
|
102
|
+
name: string;
|
|
103
|
+
description?: string;
|
|
104
|
+
inputSchema?: MCPToolSchema;
|
|
105
|
+
}
|
|
106
|
+
export interface MCPListToolsResult {
|
|
107
|
+
tools: MCPToolDescriptor[];
|
|
108
|
+
nextCursor?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface MCPCallToolParams {
|
|
111
|
+
name: string;
|
|
112
|
+
arguments?: Record<string, unknown>;
|
|
113
|
+
}
|
|
114
|
+
export interface MCPToolClient {
|
|
115
|
+
id: string;
|
|
116
|
+
listTools(params?: {
|
|
117
|
+
cursor?: string;
|
|
118
|
+
}): Promise<MCPListToolsResult>;
|
|
119
|
+
callTool(params: MCPCallToolParams): Promise<unknown>;
|
|
120
|
+
close?(): Promise<void>;
|
|
121
|
+
}
|
|
122
|
+
export interface LLMRequest {
|
|
123
|
+
prompt: string;
|
|
124
|
+
systemPrompt?: string;
|
|
125
|
+
temperature?: number;
|
|
126
|
+
maxTokens?: number;
|
|
127
|
+
mcpClients?: MCPToolClient[];
|
|
128
|
+
toolChoice?: LLMToolChoice;
|
|
129
|
+
parallelToolCalls?: boolean;
|
|
130
|
+
maxToolRounds?: number;
|
|
131
|
+
onToolExecution?: (execution: LLMToolExecution) => void;
|
|
132
|
+
toolDebug?: boolean | LLMToolDebugOptions;
|
|
133
|
+
body?: Record<string, unknown>;
|
|
134
|
+
}
|
|
135
|
+
export interface LLMUsage {
|
|
136
|
+
inputTokens?: number;
|
|
137
|
+
outputTokens?: number;
|
|
138
|
+
totalTokens?: number;
|
|
139
|
+
cost?: number;
|
|
140
|
+
}
|
|
141
|
+
export interface LLMResponse {
|
|
142
|
+
text: string;
|
|
143
|
+
raw?: unknown;
|
|
144
|
+
usage?: LLMUsage;
|
|
145
|
+
finishReason?: string;
|
|
146
|
+
toolCalls?: LLMToolCall[];
|
|
147
|
+
toolExecutions?: LLMToolExecution[];
|
|
148
|
+
}
|
|
149
|
+
export interface LLMStreamChunk {
|
|
150
|
+
textDelta: string;
|
|
151
|
+
raw?: unknown;
|
|
152
|
+
done?: boolean;
|
|
153
|
+
usage?: LLMUsage;
|
|
154
|
+
finishReason?: string;
|
|
155
|
+
}
|
|
156
|
+
export interface LLMStreamCallbacks {
|
|
157
|
+
onStart?: () => void;
|
|
158
|
+
onToken?: (token: string) => void;
|
|
159
|
+
onChunk?: (chunk: LLMStreamChunk) => void;
|
|
160
|
+
onComplete?: (response: LLMResponse) => void;
|
|
161
|
+
}
|
|
162
|
+
export interface LLMAdapter {
|
|
163
|
+
provider?: string;
|
|
164
|
+
model?: string;
|
|
165
|
+
complete(request: LLMRequest): Promise<LLMResponse>;
|
|
166
|
+
stream?(request: LLMRequest, callbacks?: LLMStreamCallbacks): Promise<LLMResponse>;
|
|
167
|
+
}
|
|
168
|
+
export interface LLMToolCall {
|
|
169
|
+
id: string;
|
|
170
|
+
type: string;
|
|
171
|
+
name?: string;
|
|
172
|
+
arguments?: unknown;
|
|
173
|
+
output?: unknown;
|
|
174
|
+
error?: string;
|
|
175
|
+
}
|
|
176
|
+
export interface LLMToolExecution {
|
|
177
|
+
callId: string;
|
|
178
|
+
type: string;
|
|
179
|
+
name?: string;
|
|
180
|
+
clientId?: string;
|
|
181
|
+
remoteName?: string;
|
|
182
|
+
arguments?: unknown;
|
|
183
|
+
output?: unknown;
|
|
184
|
+
error?: string;
|
|
185
|
+
round?: number;
|
|
186
|
+
provider?: string;
|
|
187
|
+
model?: string;
|
|
188
|
+
handledLocally: boolean;
|
|
189
|
+
startedAt: string;
|
|
190
|
+
durationMs?: number;
|
|
191
|
+
}
|
|
192
|
+
export interface LLMToolDebugOptions {
|
|
193
|
+
enabled?: boolean;
|
|
194
|
+
logger?: (line: string) => void;
|
|
195
|
+
includeRequest?: boolean;
|
|
196
|
+
includeResult?: boolean;
|
|
197
|
+
includeResultOnError?: boolean;
|
|
198
|
+
pretty?: boolean;
|
|
199
|
+
}
|
|
200
|
+
export type LLMToolChoice = "none" | "auto" | "required" | {
|
|
201
|
+
type: "function";
|
|
202
|
+
function: {
|
|
203
|
+
name: string;
|
|
204
|
+
};
|
|
205
|
+
} | Record<string, unknown>;
|
|
206
|
+
export interface StructuredTraceEvent {
|
|
207
|
+
stage: "llm.request" | "llm.response" | "llm.stream.delta" | "llm.stream.data" | "parse" | "self-heal" | "result";
|
|
208
|
+
attempt: number;
|
|
209
|
+
selfHeal: boolean;
|
|
210
|
+
message: string;
|
|
211
|
+
details?: unknown;
|
|
212
|
+
}
|
|
213
|
+
export interface StructuredPromptContext {
|
|
214
|
+
mode: StructuredMode;
|
|
215
|
+
}
|
|
216
|
+
export interface StructuredPromptPayload {
|
|
217
|
+
prompt: string;
|
|
218
|
+
systemPrompt?: string;
|
|
219
|
+
}
|
|
220
|
+
export interface StructuredPromptResolver {
|
|
221
|
+
resolvePrompt(context: StructuredPromptContext): StructuredPromptPayload;
|
|
222
|
+
}
|
|
223
|
+
export type StructuredPromptValue = string | StructuredPromptPayload | StructuredPromptResolver;
|
|
224
|
+
export type StructuredPromptBuilder = StructuredPromptValue | ((context: StructuredPromptContext) => StructuredPromptValue);
|
|
225
|
+
export interface StructuredDebugOptions {
|
|
226
|
+
enabled?: boolean;
|
|
227
|
+
colors?: boolean;
|
|
228
|
+
logger?: (line: string) => void;
|
|
229
|
+
}
|
|
230
|
+
export interface StructuredSelfHealOptions {
|
|
231
|
+
enabled?: boolean;
|
|
232
|
+
maxAttempts?: number;
|
|
233
|
+
stopOnNoProgress?: boolean;
|
|
234
|
+
maxContextChars?: number;
|
|
235
|
+
}
|
|
236
|
+
export type StructuredSelfHealInput = boolean | number | StructuredSelfHealOptions;
|
|
237
|
+
export type StructuredStreamData<T> = T extends Array<infer TItem> ? Array<StructuredStreamData<TItem>> : T extends object ? {
|
|
238
|
+
[K in keyof T]?: StructuredStreamData<T[K]> | null;
|
|
239
|
+
} : T | null;
|
|
240
|
+
export interface StructuredStreamEvent<T = unknown> {
|
|
241
|
+
data: StructuredStreamData<T> | null;
|
|
242
|
+
raw: string;
|
|
243
|
+
done: boolean;
|
|
244
|
+
usage?: LLMUsage;
|
|
245
|
+
finishReason?: string;
|
|
246
|
+
}
|
|
247
|
+
export interface StructuredStreamOptions<T = unknown> {
|
|
248
|
+
enabled?: boolean;
|
|
249
|
+
onData?: (event: StructuredStreamEvent<T>) => void;
|
|
250
|
+
to?: "stdout";
|
|
251
|
+
}
|
|
252
|
+
export type StructuredStreamInput<T = unknown> = boolean | StructuredStreamOptions<T>;
|
|
253
|
+
export interface StructuredCallOptions<TSchema extends z.ZodTypeAny> {
|
|
254
|
+
mode?: StructuredMode;
|
|
255
|
+
outdent?: boolean;
|
|
256
|
+
parse?: ParseLLMOutputOptions;
|
|
257
|
+
selfHeal?: StructuredSelfHealInput;
|
|
258
|
+
stream?: StructuredStreamInput<z.infer<TSchema>>;
|
|
259
|
+
debug?: boolean | StructuredDebugOptions;
|
|
260
|
+
observe?: (event: StructuredTraceEvent) => void;
|
|
261
|
+
systemPrompt?: string;
|
|
262
|
+
request?: Omit<LLMRequest, "prompt" | "systemPrompt">;
|
|
263
|
+
schemaInstruction?: string;
|
|
264
|
+
}
|
|
265
|
+
export interface StructuredOptions<TSchema extends z.ZodTypeAny> extends StructuredCallOptions<TSchema> {
|
|
266
|
+
schema: TSchema;
|
|
267
|
+
prompt: StructuredPromptBuilder;
|
|
268
|
+
}
|
|
269
|
+
export interface StructuredAttempt<T> {
|
|
270
|
+
attempt: number;
|
|
271
|
+
selfHeal: boolean;
|
|
272
|
+
via: "complete" | "stream";
|
|
273
|
+
raw: string;
|
|
274
|
+
thinkBlocks: ThinkBlock[];
|
|
275
|
+
json: unknown | null;
|
|
276
|
+
candidates: string[];
|
|
277
|
+
repairLog: string[];
|
|
278
|
+
zodIssues: z.ZodIssue[];
|
|
279
|
+
success: boolean;
|
|
280
|
+
usage?: LLMUsage;
|
|
281
|
+
finishReason?: string;
|
|
282
|
+
parsed: ParseLLMOutputResult<T>;
|
|
283
|
+
}
|
|
284
|
+
export interface StructuredResult<T> {
|
|
285
|
+
data: T;
|
|
286
|
+
raw: string;
|
|
287
|
+
thinkBlocks: ThinkBlock[];
|
|
288
|
+
json: unknown | null;
|
|
289
|
+
attempts: StructuredAttempt<T>[];
|
|
290
|
+
usage?: LLMUsage;
|
|
291
|
+
finishReason?: string;
|
|
292
|
+
}
|
|
293
|
+
export interface StructuredError {
|
|
294
|
+
name: "StructuredParseError";
|
|
295
|
+
raw: string;
|
|
296
|
+
thinkBlocks: ThinkBlock[];
|
|
297
|
+
candidates: string[];
|
|
298
|
+
zodIssues?: z.ZodIssue[];
|
|
299
|
+
repairLog?: string[];
|
|
300
|
+
attempt: number;
|
|
301
|
+
}
|
|
302
|
+
export interface MarkdownCodeBlock {
|
|
303
|
+
language: string | null;
|
|
304
|
+
code: string;
|
|
305
|
+
start: number;
|
|
306
|
+
end: number;
|
|
307
|
+
}
|
|
308
|
+
export interface MarkdownCodeOptions {
|
|
309
|
+
language?: string;
|
|
310
|
+
firstOnly?: boolean;
|
|
311
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface ColorSupportConfig {
|
|
2
|
+
colors: boolean;
|
|
3
|
+
}
|
|
4
|
+
export declare function color(config: ColorSupportConfig, text: string, tone: "cyan" | "yellow" | "green" | "red"): string;
|
|
5
|
+
export declare function dim(config: ColorSupportConfig, text: string): string;
|
|
6
|
+
export declare function title(config: ColorSupportConfig, text: string): string;
|
|
7
|
+
export {};
|