extrait 0.5.6 → 0.6.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 +159 -9
- package/dist/generate-shared.d.ts +79 -0
- package/dist/generate.d.ts +3 -0
- package/dist/index.cjs +993 -598
- package/dist/index.d.ts +2 -1
- package/dist/index.js +993 -598
- package/dist/llm.d.ts +18 -2
- package/dist/structured.d.ts +4 -4
- package/dist/types.d.ts +76 -8
- package/package.json +4 -4
package/dist/llm.d.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
2
|
import { type ModelAdapterConfig, type ProviderRegistry } from "./providers/registry";
|
|
3
|
-
import type { EmbeddingRequest, EmbeddingResult, LLMAdapter, StructuredCallOptions, StructuredPromptBuilder, StructuredResult } from "./types";
|
|
3
|
+
import type { EmbeddingRequest, EmbeddingResult, GenerateCallOptions, GenerateOptions, GenerateResult, LLMAdapter, LLMRequest, ParseLLMOutputOptions, StructuredDebugOptions, StructuredCallOptions, StructuredMode, StructuredSelfHealInput, StructuredPromptBuilder, StructuredResult, StructuredTimeoutOptions, StructuredTraceEvent, GenerateTraceEvent } from "./types";
|
|
4
|
+
interface LLMClientDefaults {
|
|
5
|
+
mode?: StructuredMode;
|
|
6
|
+
outdent?: boolean;
|
|
7
|
+
parse?: ParseLLMOutputOptions;
|
|
8
|
+
selfHeal?: StructuredSelfHealInput;
|
|
9
|
+
stream?: StructuredCallOptions<z.ZodTypeAny>["stream"] | GenerateCallOptions["stream"];
|
|
10
|
+
debug?: boolean | StructuredDebugOptions;
|
|
11
|
+
observe?: ((event: StructuredTraceEvent | GenerateTraceEvent) => void) | undefined;
|
|
12
|
+
systemPrompt?: string;
|
|
13
|
+
request?: Omit<LLMRequest, "prompt" | "systemPrompt" | "messages">;
|
|
14
|
+
schemaInstruction?: string;
|
|
15
|
+
timeout?: StructuredTimeoutOptions;
|
|
16
|
+
}
|
|
4
17
|
export interface CreateLLMOptions extends ModelAdapterConfig {
|
|
5
|
-
defaults?:
|
|
18
|
+
defaults?: LLMClientDefaults;
|
|
6
19
|
}
|
|
7
20
|
export interface LLMClient {
|
|
8
21
|
adapter: LLMAdapter;
|
|
9
22
|
provider?: string;
|
|
10
23
|
model?: string;
|
|
11
24
|
structured<TSchema extends z.ZodTypeAny>(schema: TSchema, prompt: StructuredPromptBuilder, options?: StructuredCallOptions<TSchema>): Promise<StructuredResult<z.infer<TSchema>>>;
|
|
25
|
+
generate(prompt: StructuredPromptBuilder, options?: GenerateCallOptions): Promise<GenerateResult>;
|
|
26
|
+
generate(options: GenerateOptions): Promise<GenerateResult>;
|
|
12
27
|
embed(input: string | string[], options?: Omit<EmbeddingRequest, "input">): Promise<EmbeddingResult>;
|
|
13
28
|
}
|
|
14
29
|
export declare function createLLM(config: CreateLLMOptions, registry?: ProviderRegistry): LLMClient;
|
|
30
|
+
export {};
|
package/dist/structured.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import type { z } from "zod";
|
|
|
2
2
|
import type { LLMAdapter, ParseLLMOutputOptions, StructuredCallOptions, StructuredError, StructuredOptions, StructuredPromptBuilder, StructuredResult } from "./types";
|
|
3
3
|
export declare class StructuredParseError extends Error implements StructuredError {
|
|
4
4
|
readonly name: "StructuredParseError";
|
|
5
|
-
readonly
|
|
6
|
-
readonly
|
|
5
|
+
readonly text: string;
|
|
6
|
+
readonly reasoning: string;
|
|
7
7
|
readonly candidates: string[];
|
|
8
8
|
readonly zodIssues?: z.ZodIssue[];
|
|
9
9
|
readonly repairLog?: string[];
|
|
10
10
|
readonly attempt: number;
|
|
11
11
|
constructor(input: {
|
|
12
12
|
message?: string;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
text: string;
|
|
14
|
+
reasoning: string;
|
|
15
15
|
candidates: string[];
|
|
16
16
|
zodIssues?: z.ZodIssue[];
|
|
17
17
|
repairLog?: string[];
|
package/dist/types.d.ts
CHANGED
|
@@ -144,11 +144,13 @@ export interface LLMMessage {
|
|
|
144
144
|
content: LLMMessageContent;
|
|
145
145
|
[key: string]: unknown;
|
|
146
146
|
}
|
|
147
|
+
export type LLMReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "max";
|
|
147
148
|
export interface LLMRequest {
|
|
148
149
|
prompt?: string;
|
|
149
150
|
systemPrompt?: string;
|
|
150
151
|
messages?: LLMMessage[];
|
|
151
152
|
temperature?: number;
|
|
153
|
+
reasoningEffort?: LLMReasoningEffort;
|
|
152
154
|
maxTokens?: number;
|
|
153
155
|
mcpClients?: MCPToolClient[];
|
|
154
156
|
toolChoice?: LLMToolChoice;
|
|
@@ -171,6 +173,7 @@ export interface LLMUsage {
|
|
|
171
173
|
}
|
|
172
174
|
export interface LLMResponse {
|
|
173
175
|
text: string;
|
|
176
|
+
reasoning?: string;
|
|
174
177
|
raw?: unknown;
|
|
175
178
|
usage?: LLMUsage;
|
|
176
179
|
finishReason?: string;
|
|
@@ -179,6 +182,7 @@ export interface LLMResponse {
|
|
|
179
182
|
}
|
|
180
183
|
export interface LLMStreamChunk {
|
|
181
184
|
textDelta: string;
|
|
185
|
+
reasoningDelta?: string;
|
|
182
186
|
raw?: unknown;
|
|
183
187
|
done?: boolean;
|
|
184
188
|
usage?: LLMUsage;
|
|
@@ -265,6 +269,12 @@ export interface StructuredTraceEvent {
|
|
|
265
269
|
message: string;
|
|
266
270
|
details?: unknown;
|
|
267
271
|
}
|
|
272
|
+
export interface GenerateTraceEvent {
|
|
273
|
+
stage: "llm.request" | "llm.response" | "llm.stream.delta" | "llm.stream.data" | "result";
|
|
274
|
+
attempt: number;
|
|
275
|
+
message: string;
|
|
276
|
+
details?: unknown;
|
|
277
|
+
}
|
|
268
278
|
export interface StructuredPromptContext {
|
|
269
279
|
mode: StructuredMode;
|
|
270
280
|
}
|
|
@@ -281,6 +291,7 @@ export type StructuredPromptBuilder = StructuredPromptValue | ((context: Structu
|
|
|
281
291
|
export interface StructuredDebugOptions {
|
|
282
292
|
enabled?: boolean;
|
|
283
293
|
colors?: boolean;
|
|
294
|
+
verbose?: boolean;
|
|
284
295
|
logger?: (line: string) => void;
|
|
285
296
|
}
|
|
286
297
|
export interface StructuredSelfHealOptions {
|
|
@@ -299,9 +310,18 @@ export interface StructuredTimeoutOptions {
|
|
|
299
310
|
export type StructuredStreamData<T> = T extends Array<infer TItem> ? Array<StructuredStreamData<TItem>> : T extends object ? {
|
|
300
311
|
[K in keyof T]?: StructuredStreamData<T[K]> | null;
|
|
301
312
|
} : T | null;
|
|
302
|
-
export interface
|
|
313
|
+
export interface StructuredStreamDelta {
|
|
314
|
+
text: string;
|
|
315
|
+
reasoning: string;
|
|
316
|
+
}
|
|
317
|
+
export interface StructuredStreamSnapshot<T = unknown> {
|
|
318
|
+
text: string;
|
|
319
|
+
reasoning: string;
|
|
303
320
|
data: StructuredStreamData<T> | null;
|
|
304
|
-
|
|
321
|
+
}
|
|
322
|
+
export interface StructuredStreamEvent<T = unknown> {
|
|
323
|
+
delta: StructuredStreamDelta;
|
|
324
|
+
snapshot: StructuredStreamSnapshot<T>;
|
|
305
325
|
done: boolean;
|
|
306
326
|
usage?: LLMUsage;
|
|
307
327
|
finishReason?: string;
|
|
@@ -312,6 +332,39 @@ export interface StructuredStreamOptions<T = unknown> {
|
|
|
312
332
|
to?: "stdout";
|
|
313
333
|
}
|
|
314
334
|
export type StructuredStreamInput<T = unknown> = boolean | StructuredStreamOptions<T>;
|
|
335
|
+
export interface GenerateStreamDelta {
|
|
336
|
+
text: string;
|
|
337
|
+
reasoning: string;
|
|
338
|
+
}
|
|
339
|
+
export interface GenerateStreamSnapshot {
|
|
340
|
+
text: string;
|
|
341
|
+
reasoning: string;
|
|
342
|
+
}
|
|
343
|
+
export interface GenerateStreamEvent {
|
|
344
|
+
delta: GenerateStreamDelta;
|
|
345
|
+
snapshot: GenerateStreamSnapshot;
|
|
346
|
+
done: boolean;
|
|
347
|
+
usage?: LLMUsage;
|
|
348
|
+
finishReason?: string;
|
|
349
|
+
}
|
|
350
|
+
export interface GenerateStreamOptions {
|
|
351
|
+
enabled?: boolean;
|
|
352
|
+
onData?: (event: GenerateStreamEvent) => void;
|
|
353
|
+
to?: "stdout";
|
|
354
|
+
}
|
|
355
|
+
export type GenerateStreamInput = boolean | GenerateStreamOptions;
|
|
356
|
+
export interface GenerateCallOptions {
|
|
357
|
+
outdent?: boolean;
|
|
358
|
+
stream?: GenerateStreamInput;
|
|
359
|
+
debug?: boolean | StructuredDebugOptions;
|
|
360
|
+
observe?: (event: GenerateTraceEvent) => void;
|
|
361
|
+
systemPrompt?: string;
|
|
362
|
+
request?: Omit<LLMRequest, "prompt" | "systemPrompt" | "messages">;
|
|
363
|
+
timeout?: StructuredTimeoutOptions;
|
|
364
|
+
}
|
|
365
|
+
export interface GenerateOptions extends GenerateCallOptions {
|
|
366
|
+
prompt: StructuredPromptBuilder;
|
|
367
|
+
}
|
|
315
368
|
export interface StructuredCallOptions<TSchema extends z.ZodTypeAny> {
|
|
316
369
|
mode?: StructuredMode;
|
|
317
370
|
outdent?: boolean;
|
|
@@ -333,8 +386,8 @@ export interface StructuredAttempt<T> {
|
|
|
333
386
|
attempt: number;
|
|
334
387
|
selfHeal: boolean;
|
|
335
388
|
via: "complete" | "stream";
|
|
336
|
-
|
|
337
|
-
|
|
389
|
+
text: string;
|
|
390
|
+
reasoning: string;
|
|
338
391
|
json: unknown | null;
|
|
339
392
|
candidates: string[];
|
|
340
393
|
repairLog: string[];
|
|
@@ -344,19 +397,34 @@ export interface StructuredAttempt<T> {
|
|
|
344
397
|
finishReason?: string;
|
|
345
398
|
parsed: ParseLLMOutputResult<T>;
|
|
346
399
|
}
|
|
400
|
+
export interface GenerateAttempt {
|
|
401
|
+
attempt: number;
|
|
402
|
+
via: "complete" | "stream";
|
|
403
|
+
text: string;
|
|
404
|
+
reasoning: string;
|
|
405
|
+
usage?: LLMUsage;
|
|
406
|
+
finishReason?: string;
|
|
407
|
+
}
|
|
347
408
|
export interface StructuredResult<T> {
|
|
348
409
|
data: T;
|
|
349
|
-
|
|
350
|
-
|
|
410
|
+
text: string;
|
|
411
|
+
reasoning: string;
|
|
351
412
|
json: unknown | null;
|
|
352
413
|
attempts: StructuredAttempt<T>[];
|
|
353
414
|
usage?: LLMUsage;
|
|
354
415
|
finishReason?: string;
|
|
355
416
|
}
|
|
417
|
+
export interface GenerateResult {
|
|
418
|
+
text: string;
|
|
419
|
+
reasoning: string;
|
|
420
|
+
attempts: GenerateAttempt[];
|
|
421
|
+
usage?: LLMUsage;
|
|
422
|
+
finishReason?: string;
|
|
423
|
+
}
|
|
356
424
|
export interface StructuredError {
|
|
357
425
|
name: "StructuredParseError";
|
|
358
|
-
|
|
359
|
-
|
|
426
|
+
text: string;
|
|
427
|
+
reasoning: string;
|
|
360
428
|
candidates: string[];
|
|
361
429
|
zodIssues?: z.ZodIssue[];
|
|
362
430
|
repairLog?: string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extrait",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/tterrasson/extrait.git"
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"main": "./dist/index.cjs",
|
|
9
9
|
"module": "./dist/index.js",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
12
|
-
"jsonrepair": "^3.13.
|
|
11
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
12
|
+
"jsonrepair": "^3.13.3",
|
|
13
13
|
"zod": "^4.3.6"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@types/bun": "^1.3.
|
|
16
|
+
"@types/bun": "^1.3.11",
|
|
17
17
|
"@types/sharp": "^0.32.0",
|
|
18
18
|
"typescript": "^5.9.3"
|
|
19
19
|
},
|