@almadar/llm 1.0.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.
@@ -0,0 +1,113 @@
1
+ import { a as RateLimiterOptions, b as TokenUsage } from './rate-limiter-9XAWfHwe.js';
2
+ import { z } from 'zod';
3
+
4
+ /**
5
+ * JSON Schema type used for OpenAI structured outputs.
6
+ */
7
+ interface JsonSchema {
8
+ type?: string | string[];
9
+ properties?: Record<string, JsonSchema>;
10
+ required?: string[];
11
+ items?: JsonSchema;
12
+ enum?: unknown[];
13
+ const?: unknown;
14
+ anyOf?: JsonSchema[];
15
+ oneOf?: JsonSchema[];
16
+ allOf?: JsonSchema[];
17
+ $ref?: string;
18
+ $defs?: Record<string, JsonSchema>;
19
+ definitions?: Record<string, JsonSchema>;
20
+ additionalProperties?: boolean | JsonSchema;
21
+ description?: string;
22
+ default?: unknown;
23
+ minItems?: number;
24
+ maxItems?: number;
25
+ minLength?: number;
26
+ }
27
+ interface StructuredOutputOptions {
28
+ model?: string;
29
+ temperature?: number;
30
+ maxTokens?: number;
31
+ rateLimiter?: RateLimiterOptions;
32
+ useGlobalRateLimiter?: boolean;
33
+ trackTokens?: boolean;
34
+ }
35
+ interface StructuredGenerationOptions {
36
+ /** User's natural language request */
37
+ userRequest: string;
38
+ /** Model to use (overrides client default) */
39
+ model?: string;
40
+ /** Temperature (overrides client default) */
41
+ temperature?: number;
42
+ /** Maximum tokens (overrides client default) */
43
+ maxTokens?: number;
44
+ /** JSON Schema for structured output */
45
+ jsonSchema?: JsonSchema;
46
+ /** Schema name for the json_schema response format */
47
+ schemaName?: string;
48
+ /** System prompt override */
49
+ systemPrompt?: string;
50
+ /** System prompt builder function (called dynamically) */
51
+ buildSystemPrompt?: () => string;
52
+ /** Additional system prompt instructions */
53
+ additionalInstructions?: string;
54
+ /** Existing context for updates (e.g., existing schema JSON) */
55
+ existingContext?: string;
56
+ /** Skip post-generation validation (default: false) */
57
+ skipValidation?: boolean;
58
+ }
59
+ interface StructuredGenerationResult<T = unknown> {
60
+ /** Generated data (guaranteed to match JSON Schema structure) */
61
+ data: T;
62
+ /** Raw JSON string from API */
63
+ raw: string;
64
+ /** Token usage statistics */
65
+ usage: {
66
+ promptTokens: number;
67
+ completionTokens: number;
68
+ totalTokens: number;
69
+ };
70
+ /** Generation latency in milliseconds */
71
+ latencyMs: number;
72
+ /** Model used for generation */
73
+ model: string;
74
+ /** Zod validation result (if not skipped) */
75
+ zodValidation?: {
76
+ success: boolean;
77
+ errors?: z.ZodError['errors'];
78
+ };
79
+ }
80
+ declare const STRUCTURED_OUTPUT_MODELS: {
81
+ readonly GPT5_MINI: "gpt-5-mini";
82
+ readonly GPT4O_MINI: "gpt-4o-mini";
83
+ readonly GPT4O: "gpt-4o";
84
+ readonly GPT4O_2024_08_06: "gpt-4o-2024-08-06";
85
+ };
86
+ declare class StructuredOutputClient {
87
+ private openai;
88
+ private rateLimiter;
89
+ private tokenTracker;
90
+ private defaultModel;
91
+ private defaultTemperature;
92
+ private defaultMaxTokens;
93
+ constructor(options?: StructuredOutputOptions);
94
+ private usesMaxCompletionTokens;
95
+ /**
96
+ * Generate structured output with guaranteed JSON Schema compliance.
97
+ */
98
+ generate<T = unknown>(options: StructuredGenerationOptions): Promise<StructuredGenerationResult<T>>;
99
+ getModel(): string;
100
+ getRateLimiterStatus(): {
101
+ queueLength: number;
102
+ activeRequests: number;
103
+ minuteTokens: number;
104
+ secondTokens: number;
105
+ backoffMs: number;
106
+ };
107
+ getTokenUsage(): TokenUsage | null;
108
+ }
109
+ declare function getStructuredOutputClient(options?: StructuredOutputOptions): StructuredOutputClient;
110
+ declare function resetStructuredOutputClient(): void;
111
+ declare function isStructuredOutputAvailable(): boolean;
112
+
113
+ export { type JsonSchema, STRUCTURED_OUTPUT_MODELS, type StructuredGenerationOptions, type StructuredGenerationResult, StructuredOutputClient, type StructuredOutputOptions, getStructuredOutputClient, isStructuredOutputAvailable, resetStructuredOutputClient };
@@ -0,0 +1,16 @@
1
+ import {
2
+ STRUCTURED_OUTPUT_MODELS,
3
+ StructuredOutputClient,
4
+ getStructuredOutputClient,
5
+ isStructuredOutputAvailable,
6
+ resetStructuredOutputClient
7
+ } from "./chunk-KH4JNOLT.js";
8
+ import "./chunk-MJS33AAS.js";
9
+ export {
10
+ STRUCTURED_OUTPUT_MODELS,
11
+ StructuredOutputClient,
12
+ getStructuredOutputClient,
13
+ isStructuredOutputAvailable,
14
+ resetStructuredOutputClient
15
+ };
16
+ //# sourceMappingURL=structured-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@almadar/llm",
3
+ "version": "1.0.0",
4
+ "description": "Multi-provider LLM client with rate limiting, token tracking, structured outputs, and continuation handling",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./client": {
14
+ "types": "./dist/client.d.ts",
15
+ "import": "./dist/client.js"
16
+ },
17
+ "./json-parser": {
18
+ "types": "./dist/json-parser.d.ts",
19
+ "import": "./dist/json-parser.js"
20
+ },
21
+ "./structured-output": {
22
+ "types": "./dist/structured-output.d.ts",
23
+ "import": "./dist/structured-output.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "src"
29
+ ],
30
+ "dependencies": {
31
+ "@anthropic-ai/sdk": "^0.52.0",
32
+ "@langchain/anthropic": "^0.3.0",
33
+ "@langchain/openai": "^0.3.0",
34
+ "openai": "^4.0.0",
35
+ "zod": "^3.22.0"
36
+ },
37
+ "peerDependencies": {
38
+ "@almadar/core": "1.0.1"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "@almadar/core": {
42
+ "optional": true
43
+ }
44
+ },
45
+ "devDependencies": {
46
+ "tsup": "^8.0.0",
47
+ "typescript": "^5.3.0"
48
+ },
49
+ "scripts": {
50
+ "build": "tsup",
51
+ "dev": "tsup --watch",
52
+ "typecheck": "tsc --noEmit",
53
+ "clean": "rm -rf dist"
54
+ }
55
+ }