@mzhub/promptc 0.1.0 → 0.1.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.
Files changed (144) hide show
  1. package/README.md +0 -0
  2. package/dist/examples/load-compiled.d.ts +7 -0
  3. package/dist/examples/load-compiled.d.ts.map +1 -0
  4. package/dist/examples/load-compiled.js +44 -0
  5. package/dist/examples/load-compiled.js.map +1 -0
  6. package/dist/examples/multi-provider.d.ts +7 -0
  7. package/dist/examples/multi-provider.d.ts.map +1 -0
  8. package/dist/examples/multi-provider.js +63 -0
  9. package/dist/examples/multi-provider.js.map +1 -0
  10. package/dist/examples/name-extractor.d.ts +11 -0
  11. package/dist/examples/name-extractor.d.ts.map +1 -0
  12. package/dist/examples/name-extractor.js +85 -0
  13. package/dist/examples/name-extractor.js.map +1 -0
  14. package/dist/examples/qa-system.d.ts +8 -0
  15. package/dist/examples/qa-system.d.ts.map +1 -0
  16. package/dist/examples/qa-system.js +73 -0
  17. package/dist/examples/qa-system.js.map +1 -0
  18. package/dist/src/cli.d.ts +3 -0
  19. package/dist/src/cli.d.ts.map +1 -0
  20. package/dist/src/cli.js +111 -0
  21. package/dist/src/cli.js.map +1 -0
  22. package/dist/src/compiler/BootstrapFewShot.d.ts +13 -0
  23. package/dist/src/compiler/BootstrapFewShot.d.ts.map +1 -0
  24. package/dist/src/compiler/BootstrapFewShot.js +93 -0
  25. package/dist/src/compiler/BootstrapFewShot.js.map +1 -0
  26. package/dist/src/compiler/CandidatePool.d.ts +10 -0
  27. package/dist/src/compiler/CandidatePool.d.ts.map +1 -0
  28. package/dist/src/compiler/CandidatePool.js +29 -0
  29. package/dist/src/compiler/CandidatePool.js.map +1 -0
  30. package/dist/src/compiler/CompiledProgram.d.ts +43 -0
  31. package/dist/src/compiler/CompiledProgram.d.ts.map +1 -0
  32. package/dist/src/compiler/CompiledProgram.js +41 -0
  33. package/dist/src/compiler/CompiledProgram.js.map +1 -0
  34. package/dist/src/compiler/InstructionRewrite.d.ts +19 -0
  35. package/dist/src/compiler/InstructionRewrite.d.ts.map +1 -0
  36. package/dist/src/compiler/InstructionRewrite.js +117 -0
  37. package/dist/src/compiler/InstructionRewrite.js.map +1 -0
  38. package/dist/src/compiler/index.d.ts +8 -0
  39. package/dist/src/compiler/index.d.ts.map +1 -0
  40. package/dist/src/compiler/index.js +5 -0
  41. package/dist/src/compiler/index.js.map +1 -0
  42. package/dist/src/compiler/types.d.ts +41 -0
  43. package/dist/src/compiler/types.d.ts.map +1 -0
  44. package/dist/src/compiler/types.js +2 -0
  45. package/dist/src/compiler/types.js.map +1 -0
  46. package/dist/src/eval/exactMatch.d.ts +5 -0
  47. package/dist/src/eval/exactMatch.d.ts.map +1 -0
  48. package/dist/src/eval/exactMatch.js +58 -0
  49. package/dist/src/eval/exactMatch.js.map +1 -0
  50. package/dist/src/eval/index.d.ts +5 -0
  51. package/dist/src/eval/index.d.ts.map +1 -0
  52. package/dist/src/eval/index.js +3 -0
  53. package/dist/src/eval/index.js.map +1 -0
  54. package/dist/src/eval/llmJudge.d.ts +9 -0
  55. package/dist/src/eval/llmJudge.d.ts.map +1 -0
  56. package/dist/src/eval/llmJudge.js +33 -0
  57. package/dist/src/eval/llmJudge.js.map +1 -0
  58. package/dist/src/eval/types.d.ts +2 -0
  59. package/dist/src/eval/types.d.ts.map +1 -0
  60. package/dist/src/eval/types.js +2 -0
  61. package/dist/src/eval/types.js.map +1 -0
  62. package/dist/src/index.d.ts +14 -0
  63. package/dist/src/index.d.ts.map +1 -0
  64. package/dist/src/index.js +8 -0
  65. package/dist/src/index.js.map +1 -0
  66. package/dist/src/program/ChainOfThought.d.ts +6 -0
  67. package/dist/src/program/ChainOfThought.d.ts.map +1 -0
  68. package/dist/src/program/ChainOfThought.js +44 -0
  69. package/dist/src/program/ChainOfThought.js.map +1 -0
  70. package/dist/src/program/Predict.d.ts +6 -0
  71. package/dist/src/program/Predict.d.ts.map +1 -0
  72. package/dist/src/program/Predict.js +33 -0
  73. package/dist/src/program/Predict.js.map +1 -0
  74. package/dist/src/program/Program.d.ts +33 -0
  75. package/dist/src/program/Program.d.ts.map +1 -0
  76. package/dist/src/program/Program.js +28 -0
  77. package/dist/src/program/Program.js.map +1 -0
  78. package/dist/src/program/index.d.ts +5 -0
  79. package/dist/src/program/index.d.ts.map +1 -0
  80. package/dist/src/program/index.js +4 -0
  81. package/dist/src/program/index.js.map +1 -0
  82. package/dist/src/providers/anthropic.d.ts +10 -0
  83. package/dist/src/providers/anthropic.d.ts.map +1 -0
  84. package/dist/src/providers/anthropic.js +40 -0
  85. package/dist/src/providers/anthropic.js.map +1 -0
  86. package/dist/src/providers/cerebras.d.ts +10 -0
  87. package/dist/src/providers/cerebras.d.ts.map +1 -0
  88. package/dist/src/providers/cerebras.js +39 -0
  89. package/dist/src/providers/cerebras.js.map +1 -0
  90. package/dist/src/providers/google.d.ts +10 -0
  91. package/dist/src/providers/google.d.ts.map +1 -0
  92. package/dist/src/providers/google.js +42 -0
  93. package/dist/src/providers/google.js.map +1 -0
  94. package/dist/src/providers/groq.d.ts +10 -0
  95. package/dist/src/providers/groq.d.ts.map +1 -0
  96. package/dist/src/providers/groq.js +42 -0
  97. package/dist/src/providers/groq.js.map +1 -0
  98. package/dist/src/providers/index.d.ts +11 -0
  99. package/dist/src/providers/index.d.ts.map +1 -0
  100. package/dist/src/providers/index.js +31 -0
  101. package/dist/src/providers/index.js.map +1 -0
  102. package/dist/src/providers/ollama.d.ts +9 -0
  103. package/dist/src/providers/ollama.d.ts.map +1 -0
  104. package/dist/src/providers/ollama.js +39 -0
  105. package/dist/src/providers/ollama.js.map +1 -0
  106. package/dist/src/providers/openai.d.ts +10 -0
  107. package/dist/src/providers/openai.d.ts.map +1 -0
  108. package/dist/src/providers/openai.js +42 -0
  109. package/dist/src/providers/openai.js.map +1 -0
  110. package/dist/src/providers/types.d.ts +25 -0
  111. package/dist/src/providers/types.d.ts.map +1 -0
  112. package/dist/src/providers/types.js +2 -0
  113. package/dist/src/providers/types.js.map +1 -0
  114. package/dist/src/runtime/cache.d.ts +18 -0
  115. package/dist/src/runtime/cache.d.ts.map +1 -0
  116. package/dist/src/runtime/cache.js +45 -0
  117. package/dist/src/runtime/cache.js.map +1 -0
  118. package/dist/src/runtime/concurrency.d.ts +7 -0
  119. package/dist/src/runtime/concurrency.d.ts.map +1 -0
  120. package/dist/src/runtime/concurrency.js +14 -0
  121. package/dist/src/runtime/concurrency.js.map +1 -0
  122. package/dist/src/runtime/costTracker.d.ts +24 -0
  123. package/dist/src/runtime/costTracker.d.ts.map +1 -0
  124. package/dist/src/runtime/costTracker.js +37 -0
  125. package/dist/src/runtime/costTracker.js.map +1 -0
  126. package/dist/src/runtime/index.d.ts +9 -0
  127. package/dist/src/runtime/index.d.ts.map +1 -0
  128. package/dist/src/runtime/index.js +5 -0
  129. package/dist/src/runtime/index.js.map +1 -0
  130. package/dist/src/runtime/retry.d.ts +10 -0
  131. package/dist/src/runtime/retry.d.ts.map +1 -0
  132. package/dist/src/runtime/retry.js +39 -0
  133. package/dist/src/runtime/retry.js.map +1 -0
  134. package/dist/src/schema/defineSchema.d.ts +18 -0
  135. package/dist/src/schema/defineSchema.d.ts.map +1 -0
  136. package/dist/src/schema/defineSchema.js +27 -0
  137. package/dist/src/schema/defineSchema.js.map +1 -0
  138. package/dist/src/schema/index.d.ts +3 -0
  139. package/dist/src/schema/index.d.ts.map +1 -0
  140. package/dist/src/schema/index.js +2 -0
  141. package/dist/src/schema/index.js.map +1 -0
  142. package/examples/README.md +1 -1
  143. package/package.json +3 -3
  144. package/src/cli.ts +1 -1
@@ -0,0 +1,33 @@
1
+ import { Program } from "./Program.js";
2
+ export class Predict extends Program {
3
+ async run(input, config = {}) {
4
+ const startTime = Date.now();
5
+ const validatedInput = this.schema.validateInput(input);
6
+ const instructions = config.instructions || this.schema.description;
7
+ const fewShotSection = this.buildFewShotString(config.fewShotExamples);
8
+ const outputFormat = this.buildOutputFormat();
9
+ const prompt = `${instructions}
10
+
11
+ ${fewShotSection ? `Here are some examples:\n\n${fewShotSection}\n\n` : ""}Now process this input and respond with valid JSON matching this format:
12
+ ${outputFormat}
13
+
14
+ Input: ${JSON.stringify(validatedInput)}
15
+
16
+ Respond ONLY with valid JSON, no additional text.`;
17
+ const response = await this.provider.complete({
18
+ prompt,
19
+ responseFormat: "json",
20
+ });
21
+ const parsed = this.parseJsonResponse(response.content);
22
+ const result = this.schema.validateOutput(parsed);
23
+ return {
24
+ result,
25
+ trace: {
26
+ promptUsed: prompt,
27
+ usage: response.usage,
28
+ latencyMs: Date.now() - startTime,
29
+ },
30
+ };
31
+ }
32
+ }
33
+ //# sourceMappingURL=Predict.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Predict.js","sourceRoot":"","sources":["../../../src/program/Predict.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAgC,MAAM,cAAc,CAAC;AAErE,MAAM,OAAO,OAGX,SAAQ,OAAa;IACrB,KAAK,CAAC,GAAG,CACP,KAA4B,EAC5B,SAAwB,EAAE;QAE1B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAExD,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACpE,MAAM,cAAc,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACvE,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAE9C,MAAM,MAAM,GAAG,GAAG,YAAY;;EAGhC,cAAc,CAAC,CAAC,CAAC,8BAA8B,cAAc,MAAM,CAAC,CAAC,CAAC,EACxE;EACE,YAAY;;SAEL,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;;kDAEW,CAAC;QAE/C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAC5C,MAAM;YACN,cAAc,EAAE,MAAM;SACvB,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAElD,OAAO;YACL,MAAM;YACN,KAAK,EAAE;gBACL,UAAU,EAAE,MAAM;gBAClB,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;aAClC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,33 @@
1
+ import { z, ZodRawShape, ZodObject } from "zod";
2
+ import { Schema } from "../schema/defineSchema.js";
3
+ import type { LLMProvider } from "../providers/types.js";
4
+ export interface ProgramConfig {
5
+ instructions?: string;
6
+ fewShotExamples?: Array<{
7
+ input: Record<string, unknown>;
8
+ output: Record<string, unknown>;
9
+ }>;
10
+ }
11
+ export interface ProgramTrace {
12
+ promptUsed: string;
13
+ reasoning?: string;
14
+ usage: {
15
+ inputTokens: number;
16
+ outputTokens: number;
17
+ };
18
+ latencyMs: number;
19
+ }
20
+ export interface ProgramOutput<O> {
21
+ result: O;
22
+ trace: ProgramTrace;
23
+ }
24
+ export declare abstract class Program<I extends ZodRawShape, O extends ZodRawShape> {
25
+ protected schema: Schema<I, O>;
26
+ protected provider: LLMProvider;
27
+ constructor(schema: Schema<I, O>, provider: LLMProvider);
28
+ abstract run(input: z.infer<ZodObject<I>>, config?: ProgramConfig): Promise<ProgramOutput<z.infer<ZodObject<O>>>>;
29
+ protected buildFewShotString(examples: ProgramConfig["fewShotExamples"]): string;
30
+ protected buildOutputFormat(): string;
31
+ protected parseJsonResponse(content: string): Record<string, unknown>;
32
+ }
33
+ //# sourceMappingURL=Program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Program.d.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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhD,SAAS,CAAC,kBAAkB,CAC1B,QAAQ,EAAE,aAAa,CAAC,iBAAiB,CAAC,GACzC,MAAM;IAaT,SAAS,CAAC,iBAAiB,IAAI,MAAM;IAMrC,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOtE"}
@@ -0,0 +1,28 @@
1
+ export class Program {
2
+ schema;
3
+ provider;
4
+ constructor(schema, provider) {
5
+ this.schema = schema;
6
+ this.provider = provider;
7
+ }
8
+ buildFewShotString(examples) {
9
+ if (!examples || examples.length === 0)
10
+ return "";
11
+ return examples
12
+ .map((ex, i) => `Example ${i + 1}:\nInput: ${JSON.stringify(ex.input)}\nOutput: ${JSON.stringify(ex.output)}`)
13
+ .join("\n\n");
14
+ }
15
+ buildOutputFormat() {
16
+ const keys = this.schema.getOutputKeys();
17
+ const format = keys.map((k) => `"${k}": <value>`).join(",\n ");
18
+ return `{\n ${format}\n}`;
19
+ }
20
+ parseJsonResponse(content) {
21
+ const jsonMatch = content.match(/\{[\s\S]*\}/);
22
+ if (!jsonMatch) {
23
+ throw new Error("No JSON found in response");
24
+ }
25
+ return JSON.parse(jsonMatch[0]);
26
+ }
27
+ }
28
+ //# sourceMappingURL=Program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Program.js","sourceRoot":"","sources":["../../../src/program/Program.ts"],"names":[],"mappings":"AAwBA,MAAM,OAAgB,OAAO;IAEf;IACA;IAFZ,YACY,MAAoB,EACpB,QAAqB;QADrB,WAAM,GAAN,MAAM,CAAc;QACpB,aAAQ,GAAR,QAAQ,CAAa;IAC9B,CAAC;IAOM,kBAAkB,CAC1B,QAA0C;QAE1C,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QAElD,OAAO,QAAQ;aACZ,GAAG,CACF,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CACR,WAAW,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,SAAS,CACzC,EAAE,CAAC,KAAK,CACT,aAAa,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAC5C;aACA,IAAI,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAES,iBAAiB;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;QACzC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChE,OAAO,QAAQ,MAAM,KAAK,CAAC;IAC7B,CAAC;IAES,iBAAiB,CAAC,OAAe;QACzC,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export { Program } from "./Program.js";
2
+ export type { ProgramConfig, ProgramOutput, ProgramTrace } from "./Program.js";
3
+ export { Predict } from "./Predict.js";
4
+ export { ChainOfThought } from "./ChainOfThought.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/program/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { Program } from "./Program.js";
2
+ export { Predict } from "./Predict.js";
3
+ export { ChainOfThought } from "./ChainOfThought.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/program/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { LLMProvider, CompletionParams, CompletionResult, ProviderConfig } from "./types.js";
2
+ export declare class AnthropicProvider implements LLMProvider {
3
+ name: string;
4
+ defaultModel: string;
5
+ private apiKey;
6
+ private baseUrl;
7
+ constructor(config: ProviderConfig);
8
+ complete(params: CompletionParams): Promise<CompletionResult>;
9
+ }
10
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,qBAAa,iBAAkB,YAAW,WAAW;IACnD,IAAI,SAAe;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,cAAc;IAM5B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAmCpE"}
@@ -0,0 +1,40 @@
1
+ export class AnthropicProvider {
2
+ name = "anthropic";
3
+ defaultModel;
4
+ apiKey;
5
+ baseUrl;
6
+ constructor(config) {
7
+ this.apiKey = config.apiKey || process.env.ANTHROPIC_API_KEY || "";
8
+ this.baseUrl = config.baseUrl || "https://api.anthropic.com/v1";
9
+ this.defaultModel = config.defaultModel || "claude-3-5-sonnet-20241022";
10
+ }
11
+ async complete(params) {
12
+ const response = await fetch(`${this.baseUrl}/messages`, {
13
+ method: "POST",
14
+ headers: {
15
+ "Content-Type": "application/json",
16
+ "x-api-key": this.apiKey,
17
+ "anthropic-version": "2023-06-01",
18
+ },
19
+ body: JSON.stringify({
20
+ model: params.model || this.defaultModel,
21
+ max_tokens: params.maxTokens ?? 1024,
22
+ messages: [{ role: "user", content: params.prompt }],
23
+ }),
24
+ });
25
+ if (!response.ok) {
26
+ const error = await response.text();
27
+ throw new Error(`Anthropic API error: ${response.status} - ${error}`);
28
+ }
29
+ const data = (await response.json());
30
+ const textContent = data.content.find((c) => c.type === "text");
31
+ return {
32
+ content: textContent?.text || "",
33
+ usage: {
34
+ inputTokens: data.usage.input_tokens,
35
+ outputTokens: data.usage.output_tokens,
36
+ },
37
+ };
38
+ }
39
+ }
40
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/providers/anthropic.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,iBAAiB;IAC5B,IAAI,GAAG,WAAW,CAAC;IACnB,YAAY,CAAS;IACb,MAAM,CAAS;IACf,OAAO,CAAS;IAExB,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAC;QACnE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,8BAA8B,CAAC;QAChE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,4BAA4B,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAwB;QACrC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,WAAW,EAAE;YACvD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,WAAW,EAAE,IAAI,CAAC,MAAM;gBACxB,mBAAmB,EAAE,YAAY;aAClC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,YAAY;gBACxC,UAAU,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI;gBACpC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;aACrD,CAAC;SACH,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,wBAAwB,QAAQ,CAAC,MAAM,MAAM,KAAK,EAAE,CAAC,CAAC;QACxE,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAGlC,CAAC;QAEF,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;QAEhE,OAAO;YACL,OAAO,EAAE,WAAW,EAAE,IAAI,IAAI,EAAE;YAChC,KAAK,EAAE;gBACL,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY;gBACpC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa;aACvC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import type { LLMProvider, CompletionParams, CompletionResult, ProviderConfig } from "./types.js";
2
+ export declare class CerebrasProvider implements LLMProvider {
3
+ name: string;
4
+ defaultModel: string;
5
+ private apiKey;
6
+ private baseUrl;
7
+ constructor(config: ProviderConfig);
8
+ complete(params: CompletionParams): Promise<CompletionResult>;
9
+ }
10
+ //# sourceMappingURL=cerebras.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cerebras.d.ts","sourceRoot":"","sources":["../../../src/providers/cerebras.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,qBAAa,gBAAiB,YAAW,WAAW;IAClD,IAAI,SAAc;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,cAAc;IAM5B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAiCpE"}
@@ -0,0 +1,39 @@
1
+ export class CerebrasProvider {
2
+ name = "cerebras";
3
+ defaultModel;
4
+ apiKey;
5
+ baseUrl;
6
+ constructor(config) {
7
+ this.apiKey = config.apiKey || process.env.CEREBRAS_API_KEY || "";
8
+ this.baseUrl = config.baseUrl || "https://api.cerebras.ai/v1";
9
+ this.defaultModel = config.defaultModel || "llama3.1-8b";
10
+ }
11
+ async complete(params) {
12
+ const response = await fetch(`${this.baseUrl}/chat/completions`, {
13
+ method: "POST",
14
+ headers: {
15
+ "Content-Type": "application/json",
16
+ Authorization: `Bearer ${this.apiKey}`,
17
+ },
18
+ body: JSON.stringify({
19
+ model: params.model || this.defaultModel,
20
+ messages: [{ role: "user", content: params.prompt }],
21
+ temperature: params.temperature ?? 0.7,
22
+ max_tokens: params.maxTokens ?? 1024,
23
+ }),
24
+ });
25
+ if (!response.ok) {
26
+ const error = await response.text();
27
+ throw new Error(`Cerebras API error: ${response.status} - ${error}`);
28
+ }
29
+ const data = (await response.json());
30
+ return {
31
+ content: data.choices[0].message.content,
32
+ usage: {
33
+ inputTokens: data.usage.prompt_tokens,
34
+ outputTokens: data.usage.completion_tokens,
35
+ },
36
+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,uBAAuB,QAAQ,CAAC,MAAM,MAAM,KAAK,EAAE,CAAC,CAAC;QACvE,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAGlC,CAAC;QAEF,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO;YACxC,KAAK,EAAE;gBACL,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa;gBACrC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB;aAC3C;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import type { LLMProvider, CompletionParams, CompletionResult, ProviderConfig } from "./types.js";
2
+ export declare class GoogleProvider implements LLMProvider {
3
+ name: string;
4
+ defaultModel: string;
5
+ private apiKey;
6
+ private baseUrl;
7
+ constructor(config: ProviderConfig);
8
+ complete(params: CompletionParams): Promise<CompletionResult>;
9
+ }
10
+ //# sourceMappingURL=google.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,qBAAa,cAAe,YAAW,WAAW;IAChD,IAAI,SAAY;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,cAAc;IAO5B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAoCpE"}
@@ -0,0 +1,42 @@
1
+ export class GoogleProvider {
2
+ name = "google";
3
+ defaultModel;
4
+ apiKey;
5
+ baseUrl;
6
+ constructor(config) {
7
+ this.apiKey = config.apiKey || process.env.GOOGLE_API_KEY || "";
8
+ this.baseUrl =
9
+ config.baseUrl || "https://generativelanguage.googleapis.com/v1beta";
10
+ this.defaultModel = config.defaultModel || "gemini-2.0-flash";
11
+ }
12
+ async complete(params) {
13
+ const model = params.model || this.defaultModel;
14
+ const url = `${this.baseUrl}/models/${model}:generateContent?key=${this.apiKey}`;
15
+ const response = await fetch(url, {
16
+ method: "POST",
17
+ headers: {
18
+ "Content-Type": "application/json",
19
+ },
20
+ body: JSON.stringify({
21
+ contents: [{ parts: [{ text: params.prompt }] }],
22
+ generationConfig: {
23
+ temperature: params.temperature ?? 0.7,
24
+ maxOutputTokens: params.maxTokens ?? 1024,
25
+ },
26
+ }),
27
+ });
28
+ if (!response.ok) {
29
+ const error = await response.text();
30
+ throw new Error(`Google API error: ${response.status} - ${error}`);
31
+ }
32
+ const data = (await response.json());
33
+ return {
34
+ content: data.candidates[0]?.content?.parts[0]?.text || "",
35
+ usage: {
36
+ inputTokens: data.usageMetadata?.promptTokenCount || 0,
37
+ outputTokens: data.usageMetadata?.candidatesTokenCount || 0,
38
+ },
39
+ };
40
+ }
41
+ }
42
+ //# sourceMappingURL=google.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.js","sourceRoot":"","sources":["../../../src/providers/google.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,cAAc;IACzB,IAAI,GAAG,QAAQ,CAAC;IAChB,YAAY,CAAS;IACb,MAAM,CAAS;IACf,OAAO,CAAS;IAExB,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC;QAChE,IAAI,CAAC,OAAO;YACV,MAAM,CAAC,OAAO,IAAI,kDAAkD,CAAC;QACvE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,kBAAkB,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAwB;QACrC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,IAA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export declare class GroqProvider implements LLMProvider {
3
+ name: string;
4
+ defaultModel: string;
5
+ private apiKey;
6
+ private baseUrl;
7
+ constructor(config: ProviderConfig);
8
+ complete(params: CompletionParams): Promise<CompletionResult>;
9
+ }
10
+ //# sourceMappingURL=groq.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groq.d.ts","sourceRoot":"","sources":["../../../src/providers/groq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,qBAAa,YAAa,YAAW,WAAW;IAC9C,IAAI,SAAU;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,cAAc;IAM5B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAqCpE"}
@@ -0,0 +1,42 @@
1
+ export class GroqProvider {
2
+ name = "groq";
3
+ defaultModel;
4
+ apiKey;
5
+ baseUrl;
6
+ constructor(config) {
7
+ this.apiKey = config.apiKey || process.env.GROQ_API_KEY || "";
8
+ this.baseUrl = config.baseUrl || "https://api.groq.com/openai/v1";
9
+ this.defaultModel = config.defaultModel || "llama-3.3-70b-versatile";
10
+ }
11
+ async complete(params) {
12
+ const response = await fetch(`${this.baseUrl}/chat/completions`, {
13
+ method: "POST",
14
+ headers: {
15
+ "Content-Type": "application/json",
16
+ Authorization: `Bearer ${this.apiKey}`,
17
+ },
18
+ body: JSON.stringify({
19
+ model: params.model || this.defaultModel,
20
+ messages: [{ role: "user", content: params.prompt }],
21
+ temperature: params.temperature ?? 0.7,
22
+ max_tokens: params.maxTokens ?? 1024,
23
+ response_format: params.responseFormat === "json"
24
+ ? { type: "json_object" }
25
+ : undefined,
26
+ }),
27
+ });
28
+ if (!response.ok) {
29
+ const error = await response.text();
30
+ throw new Error(`Groq API error: ${response.status} - ${error}`);
31
+ }
32
+ const data = (await response.json());
33
+ return {
34
+ content: data.choices[0].message.content,
35
+ usage: {
36
+ inputTokens: data.usage.prompt_tokens,
37
+ outputTokens: data.usage.completion_tokens,
38
+ },
39
+ };
40
+ }
41
+ }
42
+ //# sourceMappingURL=groq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groq.js","sourceRoot":"","sources":["../../../src/providers/groq.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,YAAY;IACvB,IAAI,GAAG,MAAM,CAAC;IACd,YAAY,CAAS;IACb,MAAM,CAAS;IACf,OAAO,CAAS;IAExB,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;QAC9D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,gCAAgC,CAAC;QAClE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,yBAAyB,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAwB;QACrC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,mBAAmB,EAAE;YAC/D,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;aACvC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,YAAY;gBACxC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;gBACpD,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,GAAG;gBACtC,UAAU,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI;gBACpC,eAAe,EACb,MAAM,CAAC,cAAc,KAAK,MAAM;oBAC9B,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE;oBACzB,CAAC,CAAC,SAAS;aAChB,CAAC;SACH,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,mBAAmB,QAAQ,CAAC,MAAM,MAAM,KAAK,EAAE,CAAC,CAAC;QACnE,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAGlC,CAAC;QAEF,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO;YACxC,KAAK,EAAE;gBACL,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa;gBACrC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB;aAC3C;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import type { LLMProvider, ProviderConfig } from "./types.js";
2
+ export type ProviderName = "openai" | "anthropic" | "google" | "ollama" | "groq" | "cerebras";
3
+ export declare function createProvider(name: ProviderName, config?: ProviderConfig): LLMProvider;
4
+ export { OpenAIProvider } from "./openai.js";
5
+ export { AnthropicProvider } from "./anthropic.js";
6
+ export { GoogleProvider } from "./google.js";
7
+ export { OllamaProvider } from "./ollama.js";
8
+ export { GroqProvider } from "./groq.js";
9
+ export { CerebrasProvider } from "./cerebras.js";
10
+ export type { LLMProvider, CompletionParams, CompletionResult, ProviderConfig, } from "./types.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,UAAU,CAAC;AAEf,wBAAgB,cAAc,CAC5B,IAAI,EAAE,YAAY,EAClB,MAAM,GAAE,cAAmB,GAC1B,WAAW,CAiBb;AAED,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,YAAY,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { OpenAIProvider } from "./openai.js";
2
+ import { AnthropicProvider } from "./anthropic.js";
3
+ import { GoogleProvider } from "./google.js";
4
+ import { OllamaProvider } from "./ollama.js";
5
+ import { GroqProvider } from "./groq.js";
6
+ import { CerebrasProvider } from "./cerebras.js";
7
+ export function createProvider(name, config = {}) {
8
+ switch (name) {
9
+ case "openai":
10
+ return new OpenAIProvider(config);
11
+ case "anthropic":
12
+ return new AnthropicProvider(config);
13
+ case "google":
14
+ return new GoogleProvider(config);
15
+ case "ollama":
16
+ return new OllamaProvider(config);
17
+ case "groq":
18
+ return new GroqProvider(config);
19
+ case "cerebras":
20
+ return new CerebrasProvider(config);
21
+ default:
22
+ throw new Error(`Unknown provider: ${name}`);
23
+ }
24
+ }
25
+ export { OpenAIProvider } from "./openai.js";
26
+ export { AnthropicProvider } from "./anthropic.js";
27
+ export { GoogleProvider } from "./google.js";
28
+ export { OllamaProvider } from "./ollama.js";
29
+ export { GroqProvider } from "./groq.js";
30
+ export { CerebrasProvider } from "./cerebras.js";
31
+ //#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C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { LLMProvider, CompletionParams, CompletionResult, ProviderConfig } from "./types.js";
2
+ export declare class OllamaProvider implements LLMProvider {
3
+ name: string;
4
+ defaultModel: string;
5
+ private baseUrl;
6
+ constructor(config?: ProviderConfig);
7
+ complete(params: CompletionParams): Promise<CompletionResult>;
8
+ }
9
+ //# sourceMappingURL=ollama.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../../src/providers/ollama.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,qBAAa,cAAe,YAAW,WAAW;IAChD,IAAI,SAAY;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,GAAE,cAAmB;IAKjC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAoCpE"}
@@ -0,0 +1,39 @@
1
+ export class OllamaProvider {
2
+ name = "ollama";
3
+ defaultModel;
4
+ baseUrl;
5
+ constructor(config = {}) {
6
+ this.baseUrl = config.baseUrl || "http://localhost:11434";
7
+ this.defaultModel = config.defaultModel || "llama3.2";
8
+ }
9
+ async complete(params) {
10
+ const response = await fetch(`${this.baseUrl}/api/generate`, {
11
+ method: "POST",
12
+ headers: {
13
+ "Content-Type": "application/json",
14
+ },
15
+ body: JSON.stringify({
16
+ model: params.model || this.defaultModel,
17
+ prompt: params.prompt,
18
+ stream: false,
19
+ options: {
20
+ temperature: params.temperature ?? 0.7,
21
+ num_predict: params.maxTokens ?? 1024,
22
+ },
23
+ }),
24
+ });
25
+ if (!response.ok) {
26
+ const error = await response.text();
27
+ throw new Error(`Ollama API error: ${response.status} - ${error}`);
28
+ }
29
+ const data = (await response.json());
30
+ return {
31
+ content: data.response,
32
+ usage: {
33
+ inputTokens: data.prompt_eval_count || 0,
34
+ outputTokens: data.eval_count || 0,
35
+ },
36
+ };
37
+ }
38
+ }
39
+ //# sourceMappingURL=ollama.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama.js","sourceRoot":"","sources":["../../../src/providers/ollama.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,cAAc;IACzB,IAAI,GAAG,QAAQ,CAAC;IAChB,YAAY,CAAS;IACb,OAAO,CAAS;IAExB,YAAY,SAAyB,EAAE;QACrC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,wBAAwB,CAAC;QAC1D,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,UAAU,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAwB;QACrC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,eAAe,EAAE;YAC3D,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,YAAY;gBACxC,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACP,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,GAAG;oBACtC,WAAW,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI;iBACtC;aACF,CAAC;SACH,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,CAAC,MAAM,MAAM,KAAK,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAIlC,CAAC;QAEF,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,KAAK,EAAE;gBACL,WAAW,EAAE,IAAI,CAAC,iBAAiB,IAAI,CAAC;gBACxC,YAAY,EAAE,IAAI,CAAC,UAAU,IAAI,CAAC;aACnC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import type { LLMProvider, CompletionParams, CompletionResult, ProviderConfig } from "./types.js";
2
+ export declare class OpenAIProvider implements LLMProvider {
3
+ name: string;
4
+ defaultModel: string;
5
+ private apiKey;
6
+ private baseUrl;
7
+ constructor(config: ProviderConfig);
8
+ complete(params: CompletionParams): Promise<CompletionResult>;
9
+ }
10
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/providers/openai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,qBAAa,cAAe,YAAW,WAAW;IAChD,IAAI,SAAY;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,cAAc;IAM5B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAqCpE"}
@@ -0,0 +1,42 @@
1
+ export class OpenAIProvider {
2
+ name = "openai";
3
+ defaultModel;
4
+ apiKey;
5
+ baseUrl;
6
+ constructor(config) {
7
+ this.apiKey = config.apiKey || process.env.OPENAI_API_KEY || "";
8
+ this.baseUrl = config.baseUrl || "https://api.openai.com/v1";
9
+ this.defaultModel = config.defaultModel || "gpt-4o-mini";
10
+ }
11
+ async complete(params) {
12
+ const response = await fetch(`${this.baseUrl}/chat/completions`, {
13
+ method: "POST",
14
+ headers: {
15
+ "Content-Type": "application/json",
16
+ Authorization: `Bearer ${this.apiKey}`,
17
+ },
18
+ body: JSON.stringify({
19
+ model: params.model || this.defaultModel,
20
+ messages: [{ role: "user", content: params.prompt }],
21
+ temperature: params.temperature ?? 0.7,
22
+ max_tokens: params.maxTokens ?? 1024,
23
+ response_format: params.responseFormat === "json"
24
+ ? { type: "json_object" }
25
+ : undefined,
26
+ }),
27
+ });
28
+ if (!response.ok) {
29
+ const error = await response.text();
30
+ throw new Error(`OpenAI API error: ${response.status} - ${error}`);
31
+ }
32
+ const data = (await response.json());
33
+ return {
34
+ content: data.choices[0].message.content,
35
+ usage: {
36
+ inputTokens: data.usage.prompt_tokens,
37
+ outputTokens: data.usage.completion_tokens,
38
+ },
39
+ };
40
+ }
41
+ }
42
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/providers/openai.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,cAAc;IACzB,IAAI,GAAG,QAAQ,CAAC;IAChB,YAAY,CAAS;IACb,MAAM,CAAS;IACf,OAAO,CAAS;IAExB,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC;QAChE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,2BAA2B,CAAC;QAC7D,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,aAAa,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAwB;QACrC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,mBAAmB,EAAE;YAC/D,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;aACvC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,YAAY;gBACxC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;gBACpD,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,GAAG;gBACtC,UAAU,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI;gBACpC,eAAe,EACb,MAAM,CAAC,cAAc,KAAK,MAAM;oBAC9B,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE;oBACzB,CAAC,CAAC,SAAS;aAChB,CAAC;SACH,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,CAAC,MAAM,MAAM,KAAK,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAGlC,CAAC;QAEF,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO;YACxC,KAAK,EAAE;gBACL,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa;gBACrC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB;aAC3C;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ export interface CompletionParams {
2
+ prompt: string;
3
+ model?: string;
4
+ temperature?: number;
5
+ maxTokens?: number;
6
+ responseFormat?: "text" | "json";
7
+ }
8
+ export interface CompletionResult {
9
+ content: string;
10
+ usage: {
11
+ inputTokens: number;
12
+ outputTokens: number;
13
+ };
14
+ }
15
+ export interface LLMProvider {
16
+ name: string;
17
+ defaultModel: string;
18
+ complete(params: CompletionParams): Promise<CompletionResult>;
19
+ }
20
+ export interface ProviderConfig {
21
+ apiKey?: string;
22
+ baseUrl?: string;
23
+ defaultModel?: string;
24
+ }
25
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE;QACL,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC/D;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/providers/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ export interface CacheOptions {
2
+ maxSize?: number;
3
+ ttlMs?: number;
4
+ }
5
+ export declare class PromptCache<T> {
6
+ private cache;
7
+ private maxSize;
8
+ private ttlMs;
9
+ constructor(options?: CacheOptions);
10
+ private makeKey;
11
+ get(prompt: string, input: unknown): T | undefined;
12
+ set(prompt: string, input: unknown, value: T): void;
13
+ has(prompt: string, input: unknown): boolean;
14
+ clear(): void;
15
+ get size(): number;
16
+ }
17
+ export declare function createCache<T>(options?: CacheOptions): PromptCache<T>;
18
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/runtime/cache.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAOD,qBAAa,WAAW,CAAC,CAAC;IACxB,OAAO,CAAC,KAAK,CAAoC;IACjD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAS;gBAEV,OAAO,GAAE,YAAiB;IAKtC,OAAO,CAAC,OAAO;IAIf,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,GAAG,SAAS;IAclD,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAWnD,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO;IAI5C,KAAK,IAAI,IAAI;IAIb,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW,CAAC,CAAC,CAAC,CAEzE"}