dev-ai-sdk 0.0.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 (68) hide show
  1. package/.env.example +4 -0
  2. package/LICENSE +20 -0
  3. package/README.md +491 -0
  4. package/dist/client.d.ts +8 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +71 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/core/config.d.ts +16 -0
  9. package/dist/core/config.d.ts.map +1 -0
  10. package/dist/core/config.js +2 -0
  11. package/dist/core/config.js.map +1 -0
  12. package/dist/core/error.d.ts +5 -0
  13. package/dist/core/error.d.ts.map +1 -0
  14. package/dist/core/error.js +8 -0
  15. package/dist/core/error.js.map +1 -0
  16. package/dist/core/fallbackEngine.d.ts +4 -0
  17. package/dist/core/fallbackEngine.d.ts.map +1 -0
  18. package/dist/core/fallbackEngine.js +89 -0
  19. package/dist/core/fallbackEngine.js.map +1 -0
  20. package/dist/core/validate.d.ts +5 -0
  21. package/dist/core/validate.d.ts.map +1 -0
  22. package/dist/core/validate.js +73 -0
  23. package/dist/core/validate.js.map +1 -0
  24. package/dist/index.d.ts +5 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +2 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/providers/deepseek-stream.d.ts +3 -0
  29. package/dist/providers/deepseek-stream.d.ts.map +1 -0
  30. package/dist/providers/deepseek-stream.js +70 -0
  31. package/dist/providers/deepseek-stream.js.map +1 -0
  32. package/dist/providers/deepseek.d.ts +3 -0
  33. package/dist/providers/deepseek.d.ts.map +1 -0
  34. package/dist/providers/deepseek.js +45 -0
  35. package/dist/providers/deepseek.js.map +1 -0
  36. package/dist/providers/google-core.d.ts +3 -0
  37. package/dist/providers/google-core.d.ts.map +1 -0
  38. package/dist/providers/google-core.js +48 -0
  39. package/dist/providers/google-core.js.map +1 -0
  40. package/dist/providers/google-stream.d.ts +3 -0
  41. package/dist/providers/google-stream.d.ts.map +1 -0
  42. package/dist/providers/google-stream.js +51 -0
  43. package/dist/providers/google-stream.js.map +1 -0
  44. package/dist/providers/google.d.ts +3 -0
  45. package/dist/providers/google.d.ts.map +1 -0
  46. package/dist/providers/google.js +10 -0
  47. package/dist/providers/google.js.map +1 -0
  48. package/dist/providers/mistral-stream.d.ts +3 -0
  49. package/dist/providers/mistral-stream.d.ts.map +1 -0
  50. package/dist/providers/mistral-stream.js +67 -0
  51. package/dist/providers/mistral-stream.js.map +1 -0
  52. package/dist/providers/mistral.d.ts +3 -0
  53. package/dist/providers/mistral.d.ts.map +1 -0
  54. package/dist/providers/mistral.js +43 -0
  55. package/dist/providers/mistral.js.map +1 -0
  56. package/dist/providers/openai-stream.d.ts +3 -0
  57. package/dist/providers/openai-stream.d.ts.map +1 -0
  58. package/dist/providers/openai-stream.js +65 -0
  59. package/dist/providers/openai-stream.js.map +1 -0
  60. package/dist/providers/openai.d.ts +3 -0
  61. package/dist/providers/openai.d.ts.map +1 -0
  62. package/dist/providers/openai.js +40 -0
  63. package/dist/providers/openai.js.map +1 -0
  64. package/dist/types/types.d.ts +45 -0
  65. package/dist/types/types.d.ts.map +1 -0
  66. package/dist/types/types.js +2 -0
  67. package/dist/types/types.js.map +1 -0
  68. package/package.json +50 -0
@@ -0,0 +1,89 @@
1
+ import { openaiProvider } from '../providers/openai';
2
+ import { deepseekProvider } from '../providers/deepseek';
3
+ import { mistralProvider } from '../providers/mistral';
4
+ import { googleCoreProvider } from '../providers/google-core';
5
+ import { SDKError } from './error';
6
+ export async function fallbackEngine(failedProvider, sdkConfig, originalProvider) {
7
+ const candidates = [];
8
+ if (sdkConfig.google?.apiKey && failedProvider !== 'google')
9
+ candidates.push('google');
10
+ if (sdkConfig.openai?.apiKey && failedProvider !== 'openai')
11
+ candidates.push('openai');
12
+ if (sdkConfig.deepseek?.apiKey && failedProvider !== 'deepseek')
13
+ candidates.push('deepseek');
14
+ if (sdkConfig.mistral?.apiKey && failedProvider !== 'mistral')
15
+ candidates.push('mistral');
16
+ if (candidates.length === 0) {
17
+ throw new SDKError('No fallback providers configured', 'core');
18
+ }
19
+ const sourceConfig = originalProvider.google ??
20
+ originalProvider.openai ??
21
+ originalProvider.deepseek ??
22
+ originalProvider.mistral;
23
+ const wasStreaming = originalProvider.google?.stream === true ||
24
+ originalProvider.openai?.stream === true ||
25
+ originalProvider.deepseek?.stream === true ||
26
+ originalProvider.mistral?.stream === true;
27
+ if (!sourceConfig) {
28
+ throw new SDKError('No original provider config found for fallback', 'core');
29
+ }
30
+ let lastError;
31
+ for (const candidate of candidates) {
32
+ try {
33
+ const nextProvider = {};
34
+ if (candidate === 'google') {
35
+ nextProvider.google = {
36
+ model: 'gemini-2.5-flash-lite',
37
+ prompt: sourceConfig.prompt,
38
+ system: sourceConfig.system,
39
+ temperature: sourceConfig.temperature,
40
+ maxTokens: sourceConfig.maxTokens,
41
+ raw: sourceConfig.raw,
42
+ };
43
+ return await googleCoreProvider(nextProvider, sdkConfig.google.apiKey);
44
+ }
45
+ if (candidate === 'openai') {
46
+ nextProvider.openai = {
47
+ model: 'gpt-5.2',
48
+ prompt: sourceConfig.prompt,
49
+ system: sourceConfig.system,
50
+ temperature: sourceConfig.temperature,
51
+ maxTokens: sourceConfig.maxTokens,
52
+ raw: sourceConfig.raw,
53
+ };
54
+ return await openaiProvider(nextProvider, sdkConfig.openai.apiKey);
55
+ }
56
+ if (candidate === 'deepseek') {
57
+ nextProvider.deepseek = {
58
+ model: 'deepseek-chat',
59
+ prompt: sourceConfig.prompt,
60
+ system: sourceConfig.system,
61
+ temperature: sourceConfig.temperature,
62
+ maxTokens: sourceConfig.maxTokens,
63
+ raw: sourceConfig.raw,
64
+ };
65
+ return await deepseekProvider(nextProvider, sdkConfig.deepseek.apiKey);
66
+ }
67
+ if (candidate === 'mistral') {
68
+ nextProvider.mistral = {
69
+ model: 'mistral-tiny',
70
+ prompt: sourceConfig.prompt,
71
+ system: sourceConfig.system,
72
+ temperature: sourceConfig.temperature,
73
+ maxTokens: sourceConfig.maxTokens,
74
+ raw: sourceConfig.raw,
75
+ };
76
+ return await mistralProvider(nextProvider, sdkConfig.mistral.apiKey);
77
+ }
78
+ }
79
+ catch (err) {
80
+ lastError = err;
81
+ continue;
82
+ }
83
+ }
84
+ if (lastError instanceof SDKError) {
85
+ throw lastError;
86
+ }
87
+ throw new SDKError('All fallback providers failed', 'core');
88
+ }
89
+ //# sourceMappingURL=fallbackEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fallbackEngine.js","sourceRoot":"","sources":["../../src/core/fallbackEngine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,cAAsB,EACtB,SAAoB,EACpB,gBAA0B;IAE1B,MAAM,UAAU,GAAwD,EAAE,CAAC;IAE3E,IAAI,SAAS,CAAC,MAAM,EAAE,MAAM,IAAI,cAAc,KAAK,QAAQ;QAAE,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvF,IAAI,SAAS,CAAC,MAAM,EAAE,MAAM,IAAI,cAAc,KAAK,QAAQ;QAAE,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvF,IAAI,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,cAAc,KAAK,UAAU;QAAE,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7F,IAAI,SAAS,CAAC,OAAO,EAAE,MAAM,IAAI,cAAc,KAAK,SAAS;QAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAE1F,IAAI,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CAAC;QAClC,MAAM,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,QAAQ,CAAC,+BAA+B,EAAE,MAAM,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Provider } from '../types/types';
2
+ import type { SDKConfig } from './config';
3
+ export declare function validateProvider(provider: Provider): void;
4
+ export declare function validateConfig(sdkConfig: SDKConfig): void;
5
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/core/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAI1C,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,QA8BlD;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,QAyClD"}
@@ -0,0 +1,73 @@
1
+ import { SDKError } from './error';
2
+ export function validateProvider(provider) {
3
+ const hasGoogle = !!provider.google;
4
+ const hasOpenAI = !!provider.openai;
5
+ const hasDeepSeek = !!provider.deepseek;
6
+ const hasMistral = !!provider.mistral;
7
+ const totalProviders = Number(hasGoogle) + Number(hasOpenAI) + Number(hasDeepSeek) + Number(hasMistral);
8
+ if (totalProviders === 0)
9
+ throw new SDKError("No provider passed", "core");
10
+ if (totalProviders > 1)
11
+ throw new SDKError("Pass only one provider", "core");
12
+ if (hasGoogle) {
13
+ if (!provider.google.model.trim())
14
+ throw new SDKError("google.model is required", "google");
15
+ if (!provider.google.prompt.trim())
16
+ throw new SDKError("google.prompt is required", "google");
17
+ }
18
+ if (hasOpenAI) {
19
+ if (!provider.openai.model.trim())
20
+ throw new SDKError("openai.model is required", "openai");
21
+ if (!provider.openai.prompt.trim())
22
+ throw new SDKError("openai.prompt is required", "openai");
23
+ }
24
+ if (hasDeepSeek) {
25
+ if (!provider.deepseek.model.trim())
26
+ throw new SDKError("deepseek.model is required", "deepseek");
27
+ if (!provider.deepseek.prompt.trim())
28
+ throw new SDKError("deepseek.prompt is required", "deepseek");
29
+ }
30
+ if (hasMistral) {
31
+ if (!provider.mistral.model.trim())
32
+ throw new SDKError("mistral.model is required", "mistral");
33
+ if (!provider.mistral.prompt.trim())
34
+ throw new SDKError("mistral.prompt is required", "mistral");
35
+ }
36
+ }
37
+ export function validateConfig(sdkConfig) {
38
+ if (!sdkConfig) {
39
+ throw new SDKError('no providers configured', 'core');
40
+ }
41
+ const hasGoogle = !!sdkConfig.google;
42
+ const hasOpenAI = !!sdkConfig.openai;
43
+ const hasDeepSeek = !!sdkConfig.deepseek;
44
+ const hasMistral = !!sdkConfig.mistral;
45
+ if (!hasGoogle && !hasOpenAI && !hasDeepSeek && !hasMistral) {
46
+ throw new SDKError('no providers configured', 'core');
47
+ }
48
+ if (hasGoogle) {
49
+ const key = sdkConfig.google?.apiKey;
50
+ if (typeof key !== 'string' || key.trim().length === 0) {
51
+ throw new SDKError('google.apiKey is required', 'google');
52
+ }
53
+ }
54
+ if (hasOpenAI) {
55
+ const key = sdkConfig.openai?.apiKey;
56
+ if (typeof key !== 'string' || key.trim().length === 0) {
57
+ throw new SDKError('openai.apiKey is required', 'openai');
58
+ }
59
+ }
60
+ if (hasDeepSeek) {
61
+ const key = sdkConfig.deepseek?.apiKey;
62
+ if (typeof key !== 'string' || key.trim().length === 0) {
63
+ throw new SDKError('deepseek.apiKey is required', 'deepseek');
64
+ }
65
+ }
66
+ if (hasMistral) {
67
+ const key = sdkConfig.mistral?.apiKey;
68
+ if (typeof key !== 'string' || key.trim().length === 0) {
69
+ throw new SDKError('mistral.apiKey is required', 'mistral');
70
+ }
71
+ }
72
+ }
73
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/core/validate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAA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SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;QACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,QAAQ,CAAC,2BAA2B,EAAE,QAAQ,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;QACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,QAAQ,CAAC,2BAA2B,EAAE,QAAQ,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;QACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,QAAQ,CAAC,6BAA6B,EAAE,UAAU,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;QACtC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,QAAQ,CAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { genChat } from './client';
2
+ export type { SDKConfig } from './core/config';
3
+ export type { Provider, Output } from './types/types';
4
+ export type { SDKError } from './core/error';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACtD,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { genChat } from './client';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Provider } from '../types/types';
2
+ export declare function deepseekStreamProvider(provider: Provider, apiKey: string): AsyncGenerator<string>;
3
+ //# sourceMappingURL=deepseek-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepseek-stream.d.ts","sourceRoot":"","sources":["../../src/providers/deepseek-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,wBAAuB,sBAAsB,CAC3C,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GACb,cAAc,CAAC,MAAM,CAAC,CA0ExB"}
@@ -0,0 +1,70 @@
1
+ import { SDKError } from '../core/error';
2
+ export async function* deepseekStreamProvider(provider, apiKey) {
3
+ if (!provider.deepseek) {
4
+ throw new SDKError('deepseek provider config missing', 'deepseek');
5
+ }
6
+ const res = await fetch('https://api.deepseek.com/chat/completions', {
7
+ method: 'POST',
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ Authorization: `Bearer ${apiKey}`,
11
+ },
12
+ body: JSON.stringify({
13
+ model: provider.deepseek.model,
14
+ messages: [
15
+ {
16
+ role: 'user',
17
+ content: provider.deepseek.prompt,
18
+ },
19
+ ],
20
+ temperature: provider.deepseek.temperature,
21
+ max_tokens: provider.deepseek.maxTokens,
22
+ stream: true,
23
+ }),
24
+ });
25
+ if (!res.ok || !res.body) {
26
+ let message = `Deepseek streaming error ${res.status}`;
27
+ try {
28
+ const errJson = await res.json();
29
+ message = errJson?.error?.message ?? message;
30
+ }
31
+ catch {
32
+ // ignore JSON parse failures here
33
+ }
34
+ throw new SDKError(message, 'deepseek');
35
+ }
36
+ const reader = res.body.getReader();
37
+ const decoder = new TextDecoder();
38
+ let buffer = '';
39
+ for (;;) {
40
+ const { done, value } = await reader.read();
41
+ if (done)
42
+ break;
43
+ buffer += decoder.decode(value, { stream: true });
44
+ let newlineIndex;
45
+ while ((newlineIndex = buffer.indexOf('\n')) !== -1) {
46
+ const line = buffer.slice(0, newlineIndex).trim();
47
+ buffer = buffer.slice(newlineIndex + 1);
48
+ if (!line)
49
+ continue;
50
+ let event;
51
+ try {
52
+ event = JSON.parse(line);
53
+ }
54
+ catch {
55
+ // skip malformed / partial JSON lines
56
+ continue;
57
+ }
58
+ // DeepSeek streaming format is assumed similar to non-streaming:
59
+ // text in event.output_text or event.output[0].content[*].text
60
+ const text = event.output_text ??
61
+ (event.output?.[0]?.content
62
+ ?.map((c) => (typeof c.text === 'string' ? c.text : ''))
63
+ .join('') ?? '');
64
+ if (text) {
65
+ yield text;
66
+ }
67
+ }
68
+ }
69
+ }
70
+ //# sourceMappingURL=deepseek-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepseek-stream.js","sourceRoot":"","sources":["../../src/providers/deepseek-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,sBAAsB,CAC3C,QAAkB,EAClB,MAAc;IAEd,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACvB,MAAM,IAAI,QAAQ,CAAC,kCA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5C,IAAI,IAAI;YAAE,MAAM;QAEhB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QAElD,IAAI,YAAoB,CAAC;QACzB,OAAO,CAAC,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,IAAI,EAAE,CAAC;YAClD,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;YAExC,IAAI,CAAC,IAAI;gBAAE,SAAS;YAEpB,IAAI,KAAU,CAAC;YACf,IAAI,CAAC;gBACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;YAAC,MAAM,CAAC;gBACP,sCAAsC;gBACtC,SAAS;YACX,CAAC;YAED,iEAAiE;YACjE,+DAA+D;YAC/D,MAAM,IAAI,GACR,KAAK,CAAC,WAAW;gBACjB,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO;oBACzB,EAAE,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;qBAC5D,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;YAErB,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,IAAI,CAAC;YACb,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Provider, Output } from '../types/types';
2
+ export declare function deepseekProvider(provider: Provider, apiKey: string): Promise<Output>;
3
+ //# sourceMappingURL=deepseek.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepseek.d.ts","sourceRoot":"","sources":["../../src/providers/deepseek.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGvD,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiD1F"}
@@ -0,0 +1,45 @@
1
+ import { SDKError } from '../core/error';
2
+ export async function deepseekProvider(provider, apiKey) {
3
+ if (!provider.deepseek) {
4
+ throw new SDKError('deepseek provider config missing', 'deepseek');
5
+ }
6
+ const res = await fetch("https://api.deepseek.com/chat/completions", {
7
+ method: "POST",
8
+ headers: {
9
+ "Content-Type": "application/json",
10
+ Authorization: `Bearer ${apiKey}`,
11
+ },
12
+ body: JSON.stringify({
13
+ model: provider.deepseek.model,
14
+ messages: [
15
+ {
16
+ role: 'user',
17
+ content: provider.deepseek.prompt,
18
+ },
19
+ ],
20
+ temperature: provider.deepseek.temperature,
21
+ max_tokens: provider.deepseek.maxTokens,
22
+ }),
23
+ });
24
+ const data = await res.json();
25
+ if (!res.ok) {
26
+ throw new SDKError(`Deepseek error ${res.status}: ${JSON.stringify(data)}`, 'deepseek');
27
+ }
28
+ const text = data.output_text ??
29
+ data.output?.[0]?.content?.map((c) => c.text).join("") ??
30
+ "";
31
+ if (provider.deepseek.raw === true) {
32
+ return {
33
+ data: text,
34
+ provider: 'deepseek',
35
+ model: provider.deepseek.model,
36
+ raw: data,
37
+ };
38
+ }
39
+ return {
40
+ data: text,
41
+ provider: 'deepseek',
42
+ model: provider.deepseek.model,
43
+ };
44
+ }
45
+ //# sourceMappingURL=deepseek.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepseek.js","sourceRoot":"","sources":["../../src/providers/deepseek.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,CAAC,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AAI,EAAE,IAAI;YACV,QAAQ,EAAE,UAAU;YACpB,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,KAAK;YAC9B,GAAG,EAAE,IAAI;SACV,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,UAAU;QACpB,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,KAAK;KAC/B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Provider, Output } from '../types/types';
2
+ export declare function googleCoreProvider(provider: Provider, apiKey: string): Promise<Output>;
3
+ //# sourceMappingURL=google-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-core.d.ts","sourceRoot":"","sources":["../../src/providers/google-core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGvD,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsD5F"}
@@ -0,0 +1,48 @@
1
+ import { SDKError } from '../core/error';
2
+ export async function googleCoreProvider(provider, apiKey) {
3
+ if (!provider.google) {
4
+ throw new SDKError('google provider config missing', 'google');
5
+ }
6
+ const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${provider.google.model}:generateContent`, {
7
+ method: 'POST',
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ 'x-goog-api-key': apiKey,
11
+ },
12
+ body: JSON.stringify({
13
+ contents: [
14
+ {
15
+ parts: [
16
+ {
17
+ text: `${provider.google.system ?? ''} ${provider.google.prompt}`,
18
+ },
19
+ ],
20
+ },
21
+ ],
22
+ generationConfig: {
23
+ temperature: provider.google.temperature,
24
+ maxOutputTokens: provider.google.maxTokens,
25
+ },
26
+ }),
27
+ });
28
+ const rawData = await res.json();
29
+ if (!res.ok) {
30
+ const msg = rawData?.error?.message ?? 'Gemini error';
31
+ throw new SDKError(`Gemini error ${msg}`, 'google');
32
+ }
33
+ const data = rawData.candidates?.[0]?.content?.parts?.[0]?.text ?? '';
34
+ if (provider.google.raw === true) {
35
+ return {
36
+ data,
37
+ provider: 'google',
38
+ model: provider.google.model,
39
+ raw: rawData,
40
+ };
41
+ }
42
+ return {
43
+ data,
44
+ provider: 'google',
45
+ model: provider.google.model,
46
+ };
47
+ }
48
+ //# sourceMappingURL=google-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-core.js","sourceRoot":"","sources":["../../src/providers/google-core.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,QAAkB,EAAE,MAAc;IACzE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,IAAI,QAAQ,CAAC,gCAAgC,EAAE,QAAQ,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,KAAK,CACrB,2DAA2D,QAAQ,CAAC,MAAM,CAAC,KAAK,kBAAkB,EAClG;QACE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,gBAAgB,EAAE,MAAM;SACzB;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,QAAQ,EAAE;gBACR;oBACE,KAAK,EAAE;wBACL;4BACE,IAAI,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE;yBAClE;qBACF;iBACF;aACF;YACD,gBAAgB,EAAE;gBAChB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW;gBACxC,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS;aAC3C;SACF,CAAC;KACH,CACF,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAEjC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,GAAG,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,IAAI,cAAc,CAAC;QACtD,MAAM,IAAI,QAAQ,CAAC,gBAAgB,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC;IAEtE,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;QACjC,OAAO;YACL,IAAI;YACJ,QAAQ,EAAE,QAAQ;YAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK;YAC5B,GAAG,EAAE,OAAO;SACb,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI;QACJ,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK;KAC7B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Provider } from '../types/types';
2
+ export declare function googleStreamProvider(provider: Provider, apiKey: string): AsyncGenerator<string>;
3
+ //# sourceMappingURL=google-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-stream.d.ts","sourceRoot":"","sources":["../../src/providers/google-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,wBAAuB,oBAAoB,CACzC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GACb,cAAc,CAAC,MAAM,CAAC,CAsDxB"}
@@ -0,0 +1,51 @@
1
+ import { SDKError } from '../core/error';
2
+ export async function* googleStreamProvider(provider, apiKey) {
3
+ if (!provider.google) {
4
+ throw new SDKError('google provider config missing', 'google');
5
+ }
6
+ const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${provider.google.model}:streamGenerateContent`, {
7
+ method: 'POST',
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ 'x-goog-api-key': apiKey,
11
+ },
12
+ body: JSON.stringify({
13
+ contents: [
14
+ {
15
+ parts: [
16
+ {
17
+ text: `${provider.google.system ?? ''} ${provider.google.prompt}`,
18
+ },
19
+ ],
20
+ },
21
+ ],
22
+ generationConfig: {
23
+ temperature: provider.google.temperature,
24
+ maxOutputTokens: provider.google.maxTokens,
25
+ },
26
+ }),
27
+ });
28
+ if (!res.ok || !res.body) {
29
+ let message = 'Gemini streaming error';
30
+ try {
31
+ const errJson = await res.json();
32
+ message = errJson?.error?.message ?? message;
33
+ }
34
+ catch {
35
+ // ignore JSON parse errors here
36
+ }
37
+ throw new SDKError(message, 'google');
38
+ }
39
+ const reader = res.body.getReader();
40
+ const decoder = new TextDecoder();
41
+ for (;;) {
42
+ const { done, value } = await reader.read();
43
+ if (done)
44
+ break;
45
+ const chunk = decoder.decode(value, { stream: true });
46
+ if (chunk) {
47
+ yield chunk;
48
+ }
49
+ }
50
+ }
51
+ //# sourceMappingURL=google-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-stream.js","sourceRoot":"","sources":["../../src/providers/google-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,oBAAoB,CACzC,QAAkB,EAClB,MAAc;IAEd,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,IAAI,QAAQ,CAAC,gCAAgC,EAAE,QAAQ,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,KAAK,CACrB,2DAA2D,QAAQ,CAAC,MAAM,CAAC,KAAK,wBAAwB,EACxG;QACE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAk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CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Provider, Output } from '../types/types';
2
+ export declare function googleProvider(provider: Provider, apiKey: string): Promise<Output | AsyncIterable<string>>;
3
+ //# 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,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAKvD,wBAAsB,cAAc,CAClC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAKzC"}
@@ -0,0 +1,10 @@
1
+ import { googleCoreProvider } from './google-core';
2
+ import { googleStreamProvider } from './google-stream';
3
+ // Backwards-compatible wrapper: chooses streaming or core provider
4
+ export async function googleProvider(provider, apiKey) {
5
+ if (provider.google && provider.google.stream === true) {
6
+ return googleStreamProvider(provider, apiKey);
7
+ }
8
+ return googleCoreProvider(provider, apiKey);
9
+ }
10
+ //# sourceMappingURL=google.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,mEAAmE;AACnE,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,QAAkB,EAClB,MAAc;IAEd,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QACvD,OAAO,oBAAoB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Provider } from '../types/types';
2
+ export declare function mistralStreamProvider(provider: Provider, apiKey: string): AsyncGenerator<string>;
3
+ //# sourceMappingURL=mistral-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mistral-stream.d.ts","sourceRoot":"","sources":["../../src/providers/mistral-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,wBAAuB,qBAAqB,CAC1C,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GACb,cAAc,CAAC,MAAM,CAAC,CAuExB"}
@@ -0,0 +1,67 @@
1
+ import { SDKError } from '../core/error';
2
+ export async function* mistralStreamProvider(provider, apiKey) {
3
+ if (!provider.mistral) {
4
+ throw new SDKError('mistral provider config missing', 'mistral');
5
+ }
6
+ const res = await fetch('https://api.mistral.ai/v1/chat/completions', {
7
+ method: 'POST',
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ Authorization: `Bearer ${apiKey}`,
11
+ },
12
+ body: JSON.stringify({
13
+ model: provider.mistral.model,
14
+ messages: [
15
+ {
16
+ role: 'user',
17
+ content: provider.mistral.prompt,
18
+ },
19
+ ],
20
+ temperature: provider.mistral.temperature,
21
+ max_tokens: provider.mistral.maxTokens,
22
+ stream: true,
23
+ }),
24
+ });
25
+ if (!res.ok || !res.body) {
26
+ let message = `Mistral streaming error ${res.status}`;
27
+ try {
28
+ const errJson = await res.json();
29
+ message = errJson?.error?.message ?? message;
30
+ }
31
+ catch {
32
+ // ignore JSON parse failures here
33
+ }
34
+ throw new SDKError(message, 'mistral');
35
+ }
36
+ const reader = res.body.getReader();
37
+ const decoder = new TextDecoder();
38
+ let buffer = '';
39
+ for (;;) {
40
+ const { done, value } = await reader.read();
41
+ if (done)
42
+ break;
43
+ buffer += decoder.decode(value, { stream: true });
44
+ let newlineIndex;
45
+ while ((newlineIndex = buffer.indexOf('\n')) !== -1) {
46
+ const line = buffer.slice(0, newlineIndex).trim();
47
+ buffer = buffer.slice(newlineIndex + 1);
48
+ if (!line)
49
+ continue;
50
+ let event;
51
+ try {
52
+ event = JSON.parse(line);
53
+ }
54
+ catch {
55
+ // skip malformed / partial JSON lines
56
+ continue;
57
+ }
58
+ // Mistral streaming format is assumed similar to non-streaming:
59
+ // text in event.choices[0].message.content or delta content
60
+ const text = event.choices?.[0]?.message?.content ?? '';
61
+ if (text) {
62
+ yield text;
63
+ }
64
+ }
65
+ }
66
+ }
67
+ //# sourceMappingURL=mistral-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mistral-stream.js","sourceRoot":"","sources":["../../src/providers/mistral-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,qBAAqB,CAC1C,QAAkB,EAClB,MAAc;IAEd,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACtB,MAAM,IAAI,QAAQ,CAAC,iCAAiC,EAAE,SAAS,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,4CAA4C,EAAE;QACpE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,MAAM,EAAE;SAClC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK;YAC7B,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM;iBACjC;aACF;YACD,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,WAAW;YACzC,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,SAAS;YACtC,MAAM,EAAE,IAAI;SACb,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAA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X,CAAC;YAED,gEAAgE;YAChE,4DAA4D;YAC5D,MAAM,IAAI,GACR,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;YAE7C,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,IAAI,CAAC;YACb,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Provider, Output } from '../types/types';
2
+ export declare function mistralProvider(provider: Provider, apiKey: string): Promise<Output>;
3
+ //# sourceMappingURL=mistral.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mistral.d.ts","sourceRoot":"","sources":["../../src/providers/mistral.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGvD,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA8CzF"}