extrait 0.5.6 → 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/README.md +159 -9
- package/dist/generate-shared.d.ts +79 -0
- package/dist/generate.d.ts +3 -0
- package/dist/index.cjs +854 -516
- package/dist/index.d.ts +2 -1
- package/dist/index.js +854 -516
- package/dist/llm.d.ts +18 -2
- package/dist/structured.d.ts +4 -4
- package/dist/types.d.ts +75 -8
- package/package.json +1 -1
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
|
@@ -149,6 +149,7 @@ export interface LLMRequest {
|
|
|
149
149
|
systemPrompt?: string;
|
|
150
150
|
messages?: LLMMessage[];
|
|
151
151
|
temperature?: number;
|
|
152
|
+
reasoningEffort?: "low" | "medium" | "high" | "max";
|
|
152
153
|
maxTokens?: number;
|
|
153
154
|
mcpClients?: MCPToolClient[];
|
|
154
155
|
toolChoice?: LLMToolChoice;
|
|
@@ -171,6 +172,7 @@ export interface LLMUsage {
|
|
|
171
172
|
}
|
|
172
173
|
export interface LLMResponse {
|
|
173
174
|
text: string;
|
|
175
|
+
reasoning?: string;
|
|
174
176
|
raw?: unknown;
|
|
175
177
|
usage?: LLMUsage;
|
|
176
178
|
finishReason?: string;
|
|
@@ -179,6 +181,7 @@ export interface LLMResponse {
|
|
|
179
181
|
}
|
|
180
182
|
export interface LLMStreamChunk {
|
|
181
183
|
textDelta: string;
|
|
184
|
+
reasoningDelta?: string;
|
|
182
185
|
raw?: unknown;
|
|
183
186
|
done?: boolean;
|
|
184
187
|
usage?: LLMUsage;
|
|
@@ -265,6 +268,12 @@ export interface StructuredTraceEvent {
|
|
|
265
268
|
message: string;
|
|
266
269
|
details?: unknown;
|
|
267
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
|
+
}
|
|
268
277
|
export interface StructuredPromptContext {
|
|
269
278
|
mode: StructuredMode;
|
|
270
279
|
}
|
|
@@ -281,6 +290,7 @@ export type StructuredPromptBuilder = StructuredPromptValue | ((context: Structu
|
|
|
281
290
|
export interface StructuredDebugOptions {
|
|
282
291
|
enabled?: boolean;
|
|
283
292
|
colors?: boolean;
|
|
293
|
+
verbose?: boolean;
|
|
284
294
|
logger?: (line: string) => void;
|
|
285
295
|
}
|
|
286
296
|
export interface StructuredSelfHealOptions {
|
|
@@ -299,9 +309,18 @@ export interface StructuredTimeoutOptions {
|
|
|
299
309
|
export type StructuredStreamData<T> = T extends Array<infer TItem> ? Array<StructuredStreamData<TItem>> : T extends object ? {
|
|
300
310
|
[K in keyof T]?: StructuredStreamData<T[K]> | null;
|
|
301
311
|
} : T | null;
|
|
302
|
-
export interface
|
|
312
|
+
export interface StructuredStreamDelta {
|
|
313
|
+
text: string;
|
|
314
|
+
reasoning: string;
|
|
315
|
+
}
|
|
316
|
+
export interface StructuredStreamSnapshot<T = unknown> {
|
|
317
|
+
text: string;
|
|
318
|
+
reasoning: string;
|
|
303
319
|
data: StructuredStreamData<T> | null;
|
|
304
|
-
|
|
320
|
+
}
|
|
321
|
+
export interface StructuredStreamEvent<T = unknown> {
|
|
322
|
+
delta: StructuredStreamDelta;
|
|
323
|
+
snapshot: StructuredStreamSnapshot<T>;
|
|
305
324
|
done: boolean;
|
|
306
325
|
usage?: LLMUsage;
|
|
307
326
|
finishReason?: string;
|
|
@@ -312,6 +331,39 @@ export interface StructuredStreamOptions<T = unknown> {
|
|
|
312
331
|
to?: "stdout";
|
|
313
332
|
}
|
|
314
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
|
+
}
|
|
315
367
|
export interface StructuredCallOptions<TSchema extends z.ZodTypeAny> {
|
|
316
368
|
mode?: StructuredMode;
|
|
317
369
|
outdent?: boolean;
|
|
@@ -333,8 +385,8 @@ export interface StructuredAttempt<T> {
|
|
|
333
385
|
attempt: number;
|
|
334
386
|
selfHeal: boolean;
|
|
335
387
|
via: "complete" | "stream";
|
|
336
|
-
|
|
337
|
-
|
|
388
|
+
text: string;
|
|
389
|
+
reasoning: string;
|
|
338
390
|
json: unknown | null;
|
|
339
391
|
candidates: string[];
|
|
340
392
|
repairLog: string[];
|
|
@@ -344,19 +396,34 @@ export interface StructuredAttempt<T> {
|
|
|
344
396
|
finishReason?: string;
|
|
345
397
|
parsed: ParseLLMOutputResult<T>;
|
|
346
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
|
+
}
|
|
347
407
|
export interface StructuredResult<T> {
|
|
348
408
|
data: T;
|
|
349
|
-
|
|
350
|
-
|
|
409
|
+
text: string;
|
|
410
|
+
reasoning: string;
|
|
351
411
|
json: unknown | null;
|
|
352
412
|
attempts: StructuredAttempt<T>[];
|
|
353
413
|
usage?: LLMUsage;
|
|
354
414
|
finishReason?: string;
|
|
355
415
|
}
|
|
416
|
+
export interface GenerateResult {
|
|
417
|
+
text: string;
|
|
418
|
+
reasoning: string;
|
|
419
|
+
attempts: GenerateAttempt[];
|
|
420
|
+
usage?: LLMUsage;
|
|
421
|
+
finishReason?: string;
|
|
422
|
+
}
|
|
356
423
|
export interface StructuredError {
|
|
357
424
|
name: "StructuredParseError";
|
|
358
|
-
|
|
359
|
-
|
|
425
|
+
text: string;
|
|
426
|
+
reasoning: string;
|
|
360
427
|
candidates: string[];
|
|
361
428
|
zodIssues?: z.ZodIssue[];
|
|
362
429
|
repairLog?: string[];
|