extrait 0.6.1 → 0.7.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/README.md +3 -1
- package/dist/extract-parse-hint.d.ts +3 -0
- package/dist/extract-shape.d.ts +21 -0
- package/dist/generate-debug.d.ts +26 -0
- package/dist/generate-model-call.d.ts +3 -0
- package/dist/generate-output.d.ts +10 -0
- package/dist/generate-shared.d.ts +12 -10
- package/dist/generate-tool-timeout.d.ts +3 -0
- package/dist/index.cjs +1301 -1156
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1301 -1156
- package/dist/parse.d.ts +1 -1
- package/dist/providers/mcp-runtime-debug.d.ts +3 -0
- package/dist/providers/mcp-runtime.d.ts +2 -2
- package/dist/structured-streaming.d.ts +1 -0
- package/dist/structured.d.ts +3 -3
- package/dist/type-definitions/llm.d.ts +246 -0
- package/dist/type-definitions/markdown.d.ts +10 -0
- package/dist/type-definitions/parse.d.ts +93 -0
- package/dist/type-definitions/structured.d.ts +123 -0
- package/dist/types.d.ts +4 -442
- package/package.json +8 -14
package/README.md
CHANGED
|
@@ -71,6 +71,7 @@ These examples cover the most common usage patterns in the repository.
|
|
|
71
71
|
- [`examples/generate.ts`](examples/generate.ts) - High-level text generation
|
|
72
72
|
- [`examples/streaming.ts`](examples/streaming.ts) - Real-time partial output and snapshot updates
|
|
73
73
|
- [`examples/calculator-tool.ts`](examples/calculator-tool.ts) - Structured extraction with MCP tools
|
|
74
|
+
- [`examples/streaming-turns-with-tools.ts`](examples/streaming-turns-with-tools.ts) - Streaming MCP turns, transitions, and reasoning blocks
|
|
74
75
|
- [`examples/conversation.ts`](examples/conversation.ts) - Multi-turn prompts and multimodal content
|
|
75
76
|
- [`examples/image-analysis.ts`](examples/image-analysis.ts) - Vision input with structured output
|
|
76
77
|
- [`examples/embeddings.ts`](examples/embeddings.ts) - Embeddings and similarity workflows
|
|
@@ -345,7 +346,7 @@ const result = await llm.generate(
|
|
|
345
346
|
maxTokens: 800,
|
|
346
347
|
reasoningEffort: "medium",
|
|
347
348
|
mcpClients: [calculatorMCP],
|
|
348
|
-
maxToolRounds:
|
|
349
|
+
maxToolRounds: 10,
|
|
349
350
|
},
|
|
350
351
|
}
|
|
351
352
|
);
|
|
@@ -695,6 +696,7 @@ Available examples:
|
|
|
695
696
|
- `generate` - High-level text generation ([generate.ts](examples/generate.ts))
|
|
696
697
|
- `streaming` - Real LLM streaming + snapshot self-check ([streaming.ts](examples/streaming.ts))
|
|
697
698
|
- `streaming-with-tools` - Real text streaming with MCP tools + self-check ([streaming-with-tools.ts](examples/streaming-with-tools.ts))
|
|
699
|
+
- `streaming-turns-with-tools` - Streaming MCP turns, transitions, and reasoning blocks ([streaming-turns-with-tools.ts](examples/streaming-turns-with-tools.ts))
|
|
698
700
|
- `abort-signal` - Start a generation then cancel quickly with `AbortSignal` ([abort-signal.ts](examples/abort-signal.ts))
|
|
699
701
|
- `timeout` - Set per-request and per-tool timeouts via the `timeout` option ([timeout.ts](examples/timeout.ts))
|
|
700
702
|
- `simple` - Basic structured output with streaming ([simple.ts](examples/simple.ts))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ExtractionCandidate, ExtractionHeuristicsOptions } from "./types";
|
|
2
|
+
export interface RankedCandidate extends ExtractionCandidate {
|
|
3
|
+
shapeScore: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function looksLikeJsonEnvelope(content: string, acceptArrays: boolean): boolean;
|
|
6
|
+
export declare function languageBonus(language: string | null): number;
|
|
7
|
+
export declare function jsonShapeScore(content: string, acceptArrays: boolean): number;
|
|
8
|
+
export declare function boundaryScore(input: string, start: number, end: number): number;
|
|
9
|
+
export declare function lengthScore(length: number): number;
|
|
10
|
+
export declare function passesShapeFilter(candidate: RankedCandidate): boolean;
|
|
11
|
+
export declare function sortCandidates<T extends {
|
|
12
|
+
score: number;
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
}>(candidates: T[]): T[];
|
|
16
|
+
export declare function dedupeCandidates<T extends {
|
|
17
|
+
content: string;
|
|
18
|
+
}>(candidates: T[]): T[];
|
|
19
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
20
|
+
export declare function normalizeInteger(value: unknown, fallback: number): number;
|
|
21
|
+
export declare function resolveExtractionHeuristics(input: Partial<ExtractionHeuristicsOptions> | undefined, defaults: ExtractionHeuristicsOptions): ExtractionHeuristicsOptions;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LLMRequest, LLMUsage } from "./types";
|
|
2
|
+
import type { NormalizedDebugConfig } from "./generate-shared";
|
|
3
|
+
export interface DebugRequestInput {
|
|
4
|
+
label: string;
|
|
5
|
+
provider?: string;
|
|
6
|
+
model?: string;
|
|
7
|
+
attempt: number;
|
|
8
|
+
selfHealAttempt: boolean;
|
|
9
|
+
selfHealEnabled: boolean;
|
|
10
|
+
stream: boolean;
|
|
11
|
+
requestPayload: LLMRequest;
|
|
12
|
+
}
|
|
13
|
+
export interface DebugResponseInput {
|
|
14
|
+
label: string;
|
|
15
|
+
attempt: number;
|
|
16
|
+
selfHealAttempt: boolean;
|
|
17
|
+
selfHealEnabled: boolean;
|
|
18
|
+
via: "complete" | "stream";
|
|
19
|
+
text: string;
|
|
20
|
+
reasoning: string;
|
|
21
|
+
parseSource: string;
|
|
22
|
+
usage?: LLMUsage;
|
|
23
|
+
finishReason?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function emitDebugRequest(config: NormalizedDebugConfig, input: DebugRequestInput): void;
|
|
26
|
+
export declare function emitDebugResponse(config: NormalizedDebugConfig, input: DebugResponseInput): void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { LLMAdapter } from "./types";
|
|
2
|
+
import type { ModelCallOptions, ModelCallResult } from "./generate-shared";
|
|
3
|
+
export declare function callModel<TSnapshot, TTraceEvent>(adapter: LLMAdapter, options: ModelCallOptions<TSnapshot, TTraceEvent>): Promise<ModelCallResult>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LLMUsage, ReasoningBlock, StreamTurnTransition } from "./types";
|
|
2
|
+
import type { NormalizedModelOutput } from "./generate-shared";
|
|
3
|
+
export declare function normalizeModelOutput(text: string, dedicatedReasoning?: string, reasoningBlocks?: ReasoningBlock[]): NormalizedModelOutput;
|
|
4
|
+
export declare function appendReasoningBlock(blocks: ReasoningBlock[] | undefined, transition: StreamTurnTransition): ReasoningBlock[] | undefined;
|
|
5
|
+
export declare function composeParseSource(text: string, reasoning?: string): string;
|
|
6
|
+
export declare function aggregateUsage<T extends {
|
|
7
|
+
usage?: LLMUsage;
|
|
8
|
+
}>(attempts: T[]): LLMUsage | undefined;
|
|
9
|
+
export declare function mergeUsage(base: LLMUsage | undefined, next: LLMUsage | undefined): LLMUsage | undefined;
|
|
10
|
+
export declare function toStreamDataFingerprint(value: unknown): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LLMMessage, LLMRequest, LLMToolCall, LLMUsage, ReasoningBlock, StreamTurnTransition, StructuredDebugOptions, StructuredPromptBuilder, StructuredPromptContext, StructuredPromptPayload, StructuredPromptValue, StructuredTimeoutOptions, ThinkBlock } from "./types";
|
|
2
2
|
export type PromptRequestOptions = Omit<LLMRequest, "prompt" | "systemPrompt" | "messages">;
|
|
3
3
|
export interface StreamDelta {
|
|
4
4
|
text: string;
|
|
@@ -12,7 +12,10 @@ export interface NormalizedStreamConfig<TSnapshot> {
|
|
|
12
12
|
done: boolean;
|
|
13
13
|
usage?: LLMUsage;
|
|
14
14
|
finishReason?: string;
|
|
15
|
+
turnIndex?: number;
|
|
16
|
+
toolCalls?: LLMToolCall[];
|
|
15
17
|
}) => void;
|
|
18
|
+
onTurnTransition?: (transition: StreamTurnTransition) => void;
|
|
16
19
|
to?: "stdout";
|
|
17
20
|
}
|
|
18
21
|
export interface NormalizedDebugConfig {
|
|
@@ -24,6 +27,7 @@ export interface NormalizedDebugConfig {
|
|
|
24
27
|
export interface NormalizedModelOutput {
|
|
25
28
|
text: string;
|
|
26
29
|
reasoning: string;
|
|
30
|
+
reasoningBlocks?: ReasoningBlock[];
|
|
27
31
|
thinkBlocks: ThinkBlock[];
|
|
28
32
|
parseSource: string;
|
|
29
33
|
}
|
|
@@ -55,6 +59,7 @@ export interface ModelCallResult {
|
|
|
55
59
|
via: "complete" | "stream";
|
|
56
60
|
usage?: LLMUsage;
|
|
57
61
|
finishReason?: string;
|
|
62
|
+
reasoningBlocks?: ReasoningBlock[];
|
|
58
63
|
}
|
|
59
64
|
export declare function resolvePrompt(prompt: StructuredPromptBuilder, context: StructuredPromptContext): StructuredPromptPayload;
|
|
60
65
|
export declare function normalizePromptValue(value: StructuredPromptValue, _context: StructuredPromptContext): StructuredPromptPayload;
|
|
@@ -65,15 +70,12 @@ export declare function mergeSystemPrompts(primary?: string, secondary?: string)
|
|
|
65
70
|
export declare function normalizeStreamConfig<TSnapshot>(option: boolean | {
|
|
66
71
|
enabled?: boolean;
|
|
67
72
|
onData?: NormalizedStreamConfig<TSnapshot>["onData"];
|
|
73
|
+
onTurnTransition?: NormalizedStreamConfig<TSnapshot>["onTurnTransition"];
|
|
68
74
|
to?: "stdout";
|
|
69
75
|
} | undefined): NormalizedStreamConfig<TSnapshot>;
|
|
70
76
|
export declare function normalizeDebugConfig(option: StructuredDebugOptions | boolean | undefined): NormalizedDebugConfig;
|
|
71
|
-
export
|
|
72
|
-
export
|
|
73
|
-
export
|
|
74
|
-
export
|
|
75
|
-
export
|
|
76
|
-
export declare function aggregateUsage<T extends {
|
|
77
|
-
usage?: LLMUsage;
|
|
78
|
-
}>(attempts: T[]): LLMUsage | undefined;
|
|
79
|
-
export declare function mergeUsage(base: LLMUsage | undefined, next: LLMUsage | undefined): LLMUsage | undefined;
|
|
77
|
+
export { withToolTimeout, applyToolTimeout } from "./generate-tool-timeout";
|
|
78
|
+
export { callModel } from "./generate-model-call";
|
|
79
|
+
export { aggregateUsage, appendReasoningBlock, composeParseSource, mergeUsage, normalizeModelOutput, toStreamDataFingerprint, } from "./generate-output";
|
|
80
|
+
export type { DebugRequestInput, DebugResponseInput } from "./generate-debug";
|
|
81
|
+
export { emitDebugRequest, emitDebugResponse } from "./generate-debug";
|