extrait 0.5.5 → 0.6.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/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?: StructuredCallOptions<z.ZodTypeAny>;
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 {};
@@ -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 raw: string;
6
- readonly thinkBlocks: StructuredError["thinkBlocks"];
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
- raw: string;
14
- thinkBlocks: StructuredError["thinkBlocks"];
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
@@ -110,6 +110,7 @@ export interface MCPListToolsResult {
110
110
  export interface MCPCallToolParams {
111
111
  name: string;
112
112
  arguments?: Record<string, unknown>;
113
+ _meta?: Record<string, unknown>;
113
114
  }
114
115
  export interface MCPToolClient {
115
116
  id: string;
@@ -148,6 +149,7 @@ export interface LLMRequest {
148
149
  systemPrompt?: string;
149
150
  messages?: LLMMessage[];
150
151
  temperature?: number;
152
+ reasoningEffort?: "low" | "medium" | "high" | "max";
151
153
  maxTokens?: number;
152
154
  mcpClients?: MCPToolClient[];
153
155
  toolChoice?: LLMToolChoice;
@@ -156,6 +158,7 @@ export interface LLMRequest {
156
158
  onToolExecution?: (execution: LLMToolExecution) => void;
157
159
  transformToolOutput?: LLMToolOutputTransformer;
158
160
  transformToolArguments?: LLMToolArgumentsTransformer;
161
+ transformToolCallParams?: LLMToolCallParamsTransformer;
159
162
  unknownToolError?: (toolName: string) => string;
160
163
  toolDebug?: boolean | LLMToolDebugOptions;
161
164
  body?: Record<string, unknown>;
@@ -169,6 +172,7 @@ export interface LLMUsage {
169
172
  }
170
173
  export interface LLMResponse {
171
174
  text: string;
175
+ reasoning?: string;
172
176
  raw?: unknown;
173
177
  usage?: LLMUsage;
174
178
  finishReason?: string;
@@ -177,6 +181,7 @@ export interface LLMResponse {
177
181
  }
178
182
  export interface LLMStreamChunk {
179
183
  textDelta: string;
184
+ reasoningDelta?: string;
180
185
  raw?: unknown;
181
186
  done?: boolean;
182
187
  usage?: LLMUsage;
@@ -237,6 +242,11 @@ export type LLMToolArgumentsTransformer = (args: Record<string, unknown>, contex
237
242
  remoteName: string;
238
243
  clientId: string;
239
244
  }) => Record<string, unknown> | Promise<Record<string, unknown>>;
245
+ export type LLMToolCallParamsTransformer = (params: MCPCallToolParams, context: {
246
+ name: string;
247
+ remoteName: string;
248
+ clientId: string;
249
+ }) => MCPCallToolParams | Promise<MCPCallToolParams>;
240
250
  export interface LLMToolDebugOptions {
241
251
  enabled?: boolean;
242
252
  logger?: (line: string) => void;
@@ -258,6 +268,12 @@ export interface StructuredTraceEvent {
258
268
  message: string;
259
269
  details?: unknown;
260
270
  }
271
+ export interface GenerateTraceEvent {
272
+ stage: "llm.request" | "llm.response" | "llm.stream.delta" | "llm.stream.data" | "result";
273
+ attempt: number;
274
+ message: string;
275
+ details?: unknown;
276
+ }
261
277
  export interface StructuredPromptContext {
262
278
  mode: StructuredMode;
263
279
  }
@@ -274,6 +290,7 @@ export type StructuredPromptBuilder = StructuredPromptValue | ((context: Structu
274
290
  export interface StructuredDebugOptions {
275
291
  enabled?: boolean;
276
292
  colors?: boolean;
293
+ verbose?: boolean;
277
294
  logger?: (line: string) => void;
278
295
  }
279
296
  export interface StructuredSelfHealOptions {
@@ -292,9 +309,18 @@ export interface StructuredTimeoutOptions {
292
309
  export type StructuredStreamData<T> = T extends Array<infer TItem> ? Array<StructuredStreamData<TItem>> : T extends object ? {
293
310
  [K in keyof T]?: StructuredStreamData<T[K]> | null;
294
311
  } : T | null;
295
- export interface StructuredStreamEvent<T = unknown> {
312
+ export interface StructuredStreamDelta {
313
+ text: string;
314
+ reasoning: string;
315
+ }
316
+ export interface StructuredStreamSnapshot<T = unknown> {
317
+ text: string;
318
+ reasoning: string;
296
319
  data: StructuredStreamData<T> | null;
297
- raw: string;
320
+ }
321
+ export interface StructuredStreamEvent<T = unknown> {
322
+ delta: StructuredStreamDelta;
323
+ snapshot: StructuredStreamSnapshot<T>;
298
324
  done: boolean;
299
325
  usage?: LLMUsage;
300
326
  finishReason?: string;
@@ -305,6 +331,39 @@ export interface StructuredStreamOptions<T = unknown> {
305
331
  to?: "stdout";
306
332
  }
307
333
  export type StructuredStreamInput<T = unknown> = boolean | StructuredStreamOptions<T>;
334
+ export interface GenerateStreamDelta {
335
+ text: string;
336
+ reasoning: string;
337
+ }
338
+ export interface GenerateStreamSnapshot {
339
+ text: string;
340
+ reasoning: string;
341
+ }
342
+ export interface GenerateStreamEvent {
343
+ delta: GenerateStreamDelta;
344
+ snapshot: GenerateStreamSnapshot;
345
+ done: boolean;
346
+ usage?: LLMUsage;
347
+ finishReason?: string;
348
+ }
349
+ export interface GenerateStreamOptions {
350
+ enabled?: boolean;
351
+ onData?: (event: GenerateStreamEvent) => void;
352
+ to?: "stdout";
353
+ }
354
+ export type GenerateStreamInput = boolean | GenerateStreamOptions;
355
+ export interface GenerateCallOptions {
356
+ outdent?: boolean;
357
+ stream?: GenerateStreamInput;
358
+ debug?: boolean | StructuredDebugOptions;
359
+ observe?: (event: GenerateTraceEvent) => void;
360
+ systemPrompt?: string;
361
+ request?: Omit<LLMRequest, "prompt" | "systemPrompt" | "messages">;
362
+ timeout?: StructuredTimeoutOptions;
363
+ }
364
+ export interface GenerateOptions extends GenerateCallOptions {
365
+ prompt: StructuredPromptBuilder;
366
+ }
308
367
  export interface StructuredCallOptions<TSchema extends z.ZodTypeAny> {
309
368
  mode?: StructuredMode;
310
369
  outdent?: boolean;
@@ -326,8 +385,8 @@ export interface StructuredAttempt<T> {
326
385
  attempt: number;
327
386
  selfHeal: boolean;
328
387
  via: "complete" | "stream";
329
- raw: string;
330
- thinkBlocks: ThinkBlock[];
388
+ text: string;
389
+ reasoning: string;
331
390
  json: unknown | null;
332
391
  candidates: string[];
333
392
  repairLog: string[];
@@ -337,19 +396,34 @@ export interface StructuredAttempt<T> {
337
396
  finishReason?: string;
338
397
  parsed: ParseLLMOutputResult<T>;
339
398
  }
399
+ export interface GenerateAttempt {
400
+ attempt: number;
401
+ via: "complete" | "stream";
402
+ text: string;
403
+ reasoning: string;
404
+ usage?: LLMUsage;
405
+ finishReason?: string;
406
+ }
340
407
  export interface StructuredResult<T> {
341
408
  data: T;
342
- raw: string;
343
- thinkBlocks: ThinkBlock[];
409
+ text: string;
410
+ reasoning: string;
344
411
  json: unknown | null;
345
412
  attempts: StructuredAttempt<T>[];
346
413
  usage?: LLMUsage;
347
414
  finishReason?: string;
348
415
  }
416
+ export interface GenerateResult {
417
+ text: string;
418
+ reasoning: string;
419
+ attempts: GenerateAttempt[];
420
+ usage?: LLMUsage;
421
+ finishReason?: string;
422
+ }
349
423
  export interface StructuredError {
350
424
  name: "StructuredParseError";
351
- raw: string;
352
- thinkBlocks: ThinkBlock[];
425
+ text: string;
426
+ reasoning: string;
353
427
  candidates: string[];
354
428
  zodIssues?: z.ZodIssue[];
355
429
  repairLog?: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extrait",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/tterrasson/extrait.git"