@thewhateverapp/platform 0.10.0 → 0.11.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/ai/index.d.ts +20 -3
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +70 -36
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/namespace.d.ts +55 -0
- package/dist/ai/namespace.d.ts.map +1 -0
- package/dist/ai/namespace.js +61 -0
- package/dist/ai/namespace.js.map +1 -0
- package/dist/ai/providers.d.ts +27 -0
- package/dist/ai/providers.d.ts.map +1 -0
- package/dist/ai/providers.js +231 -0
- package/dist/ai/providers.js.map +1 -0
- package/dist/ai/types.d.ts +11 -1
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/workers.d.ts +77 -0
- package/dist/ai/workers.d.ts.map +1 -0
- package/dist/ai/workers.js +171 -0
- package/dist/ai/workers.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/ai/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Edge AI Service
|
|
3
3
|
*
|
|
4
4
|
* Provides AI capabilities for user-generated tiles running on Cloudflare Workers/Pages.
|
|
5
|
-
*
|
|
5
|
+
* Supports both direct Cloudflare Workers AI (via env.AI binding) and platform API fallback.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* // Configure env once per request
|
|
14
14
|
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
15
|
*
|
|
16
|
-
* const ai =
|
|
16
|
+
* const ai = getAI();
|
|
17
17
|
*
|
|
18
18
|
* // Simple text generation
|
|
19
19
|
* const answer = await ai.ask("Summarize this text: ...");
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
* images: [{ type: 'url', data: imageUrl }]
|
|
32
32
|
* });
|
|
33
33
|
*
|
|
34
|
+
* // Advanced: direct model access
|
|
35
|
+
* const embeddings = await ai.embed("text to embed");
|
|
36
|
+
* const image = await ai.generateImage("a beautiful sunset");
|
|
37
|
+
*
|
|
34
38
|
* return NextResponse.json({ answer });
|
|
35
39
|
* }
|
|
36
40
|
* ```
|
|
@@ -40,11 +44,24 @@ export type * from './types';
|
|
|
40
44
|
/**
|
|
41
45
|
* Get an AI service instance for the current request
|
|
42
46
|
*
|
|
43
|
-
* Automatically
|
|
47
|
+
* Automatically detects available providers and routes requests appropriately.
|
|
48
|
+
* Supports Cloudflare Workers AI, Replicate, and Platform API (Anthropic/OpenAI/Google).
|
|
44
49
|
*
|
|
45
50
|
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
46
51
|
* If not provided, uses the env configured via configurePlatformEnv().
|
|
47
52
|
* @returns AI service provider instance
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const ai = getAI();
|
|
57
|
+
*
|
|
58
|
+
* // Use default provider (auto-selected)
|
|
59
|
+
* const answer = await ai.ask("What is 2+2?");
|
|
60
|
+
*
|
|
61
|
+
* // Use specific provider
|
|
62
|
+
* const response = await ai.ask("Generate code", { provider: 'cloudflare', capabilities: ['coding'] });
|
|
63
|
+
* const replicateResponse = await ai.ask("Create art", { provider: 'replicate' });
|
|
64
|
+
* ```
|
|
48
65
|
*/
|
|
49
66
|
export declare function getAI(req?: AIRequest | {
|
|
50
67
|
env: AIEnv;
|
package/dist/ai/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,SAAS,EACT,KAAK,EAIN,MAAM,SAAS,CAAC;AAWjB,mBAAmB,SAAS,CAAC;AAK7B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,KAAK,CACnB,GAAG,CAAC,EAAE,SAAS,GAAG;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,GAAG,KAAK,GACvC,iBAAiB,CA2BnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,iBAAiB,CAGvF"}
|
package/dist/ai/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Edge AI Service
|
|
3
3
|
*
|
|
4
4
|
* Provides AI capabilities for user-generated tiles running on Cloudflare Workers/Pages.
|
|
5
|
-
*
|
|
5
|
+
* Supports both direct Cloudflare Workers AI (via env.AI binding) and platform API fallback.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* // Configure env once per request
|
|
14
14
|
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
15
|
*
|
|
16
|
-
* const ai =
|
|
16
|
+
* const ai = getAI();
|
|
17
17
|
*
|
|
18
18
|
* // Simple text generation
|
|
19
19
|
* const answer = await ai.ask("Summarize this text: ...");
|
|
@@ -31,21 +31,39 @@
|
|
|
31
31
|
* images: [{ type: 'url', data: imageUrl }]
|
|
32
32
|
* });
|
|
33
33
|
*
|
|
34
|
+
* // Advanced: direct model access
|
|
35
|
+
* const embeddings = await ai.embed("text to embed");
|
|
36
|
+
* const image = await ai.generateImage("a beautiful sunset");
|
|
37
|
+
*
|
|
34
38
|
* return NextResponse.json({ answer });
|
|
35
39
|
* }
|
|
36
40
|
* ```
|
|
37
41
|
*/
|
|
38
42
|
import { getPlatformEnv, isPlatformEnvConfigured } from '../env';
|
|
43
|
+
import { createCloudflareProvider, createReplicateProvider, createPlatformAPIProvider, detectAvailableProviders, selectProvider, } from './providers';
|
|
39
44
|
// Default platform API URL
|
|
40
45
|
const DEFAULT_PLATFORM_API = 'https://api.thewhatever.app';
|
|
41
46
|
/**
|
|
42
47
|
* Get an AI service instance for the current request
|
|
43
48
|
*
|
|
44
|
-
* Automatically
|
|
49
|
+
* Automatically detects available providers and routes requests appropriately.
|
|
50
|
+
* Supports Cloudflare Workers AI, Replicate, and Platform API (Anthropic/OpenAI/Google).
|
|
45
51
|
*
|
|
46
52
|
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
47
53
|
* If not provided, uses the env configured via configurePlatformEnv().
|
|
48
54
|
* @returns AI service provider instance
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const ai = getAI();
|
|
59
|
+
*
|
|
60
|
+
* // Use default provider (auto-selected)
|
|
61
|
+
* const answer = await ai.ask("What is 2+2?");
|
|
62
|
+
*
|
|
63
|
+
* // Use specific provider
|
|
64
|
+
* const response = await ai.ask("Generate code", { provider: 'cloudflare', capabilities: ['coding'] });
|
|
65
|
+
* const replicateResponse = await ai.ask("Create art", { provider: 'replicate' });
|
|
66
|
+
* ```
|
|
49
67
|
*/
|
|
50
68
|
export function getAI(req) {
|
|
51
69
|
let env;
|
|
@@ -60,7 +78,7 @@ export function getAI(req) {
|
|
|
60
78
|
else if ('env' in req) {
|
|
61
79
|
env = req.env;
|
|
62
80
|
}
|
|
63
|
-
else if ('PLATFORM_API_KEY' in req || 'PLATFORM_API_URL' in req || 'TILE_ID' in req) {
|
|
81
|
+
else if ('PLATFORM_API_KEY' in req || 'PLATFORM_API_URL' in req || 'TILE_ID' in req || 'AI' in req || 'REPLICATE_API_TOKEN' in req) {
|
|
64
82
|
// Direct env object
|
|
65
83
|
env = req;
|
|
66
84
|
}
|
|
@@ -70,12 +88,8 @@ export function getAI(req) {
|
|
|
70
88
|
if (!env) {
|
|
71
89
|
throw new Error('No environment found in request. Ensure you are running in edge runtime.');
|
|
72
90
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!apiKey) {
|
|
76
|
-
throw new Error('No PLATFORM_API_KEY found in environment. Add PLATFORM_API_KEY to your wrangler.jsonc secrets.');
|
|
77
|
-
}
|
|
78
|
-
return createAIProvider(apiUrl, apiKey);
|
|
91
|
+
// Create a unified provider that routes to the appropriate backend
|
|
92
|
+
return createUnifiedProvider(env);
|
|
79
93
|
}
|
|
80
94
|
/**
|
|
81
95
|
* Create an AI service instance directly with config
|
|
@@ -90,40 +104,60 @@ export function getAI(req) {
|
|
|
90
104
|
*/
|
|
91
105
|
export function createAI(config) {
|
|
92
106
|
const apiUrl = config.apiUrl || DEFAULT_PLATFORM_API;
|
|
93
|
-
return
|
|
107
|
+
return createPlatformAPIProvider(apiUrl, config.apiKey);
|
|
94
108
|
}
|
|
95
109
|
/**
|
|
96
|
-
* Internal: Create
|
|
110
|
+
* Internal: Create unified provider that routes to appropriate backend
|
|
97
111
|
*/
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
function createUnifiedProvider(env) {
|
|
113
|
+
const availableProviders = detectAvailableProviders(env);
|
|
114
|
+
if (availableProviders.length === 0) {
|
|
115
|
+
throw new Error('No AI providers configured. Set up one of: env.AI (Cloudflare Workers AI), ' +
|
|
116
|
+
'REPLICATE_API_TOKEN, or PLATFORM_API_KEY.');
|
|
117
|
+
}
|
|
118
|
+
// Cache provider instances
|
|
119
|
+
const providerCache = new Map();
|
|
120
|
+
function getProviderInstance(providerName) {
|
|
121
|
+
if (providerCache.has(providerName)) {
|
|
122
|
+
return providerCache.get(providerName);
|
|
123
|
+
}
|
|
124
|
+
let instance;
|
|
125
|
+
switch (providerName) {
|
|
126
|
+
case 'cloudflare':
|
|
127
|
+
if (!env.AI)
|
|
128
|
+
throw new Error('Cloudflare Workers AI binding not available');
|
|
129
|
+
instance = createCloudflareProvider(env.AI);
|
|
130
|
+
break;
|
|
131
|
+
case 'replicate':
|
|
132
|
+
if (!env.REPLICATE_API_TOKEN)
|
|
133
|
+
throw new Error('REPLICATE_API_TOKEN not configured');
|
|
134
|
+
instance = createReplicateProvider(env.REPLICATE_API_TOKEN);
|
|
135
|
+
break;
|
|
136
|
+
case 'anthropic':
|
|
137
|
+
case 'openai':
|
|
138
|
+
case 'google':
|
|
139
|
+
if (!env.PLATFORM_API_KEY)
|
|
140
|
+
throw new Error('PLATFORM_API_KEY not configured');
|
|
141
|
+
const apiUrl = env.PLATFORM_API_URL || DEFAULT_PLATFORM_API;
|
|
142
|
+
instance = createPlatformAPIProvider(apiUrl, env.PLATFORM_API_KEY);
|
|
143
|
+
break;
|
|
144
|
+
default:
|
|
145
|
+
throw new Error(`Unknown provider: ${providerName}`);
|
|
111
146
|
}
|
|
112
|
-
|
|
147
|
+
providerCache.set(providerName, instance);
|
|
148
|
+
return instance;
|
|
113
149
|
}
|
|
150
|
+
// Return unified provider that routes requests
|
|
114
151
|
return {
|
|
115
152
|
async ask(prompt, options) {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
capabilities: options?.capabilities,
|
|
120
|
-
maxTokens: options?.maxTokens,
|
|
121
|
-
temperature: options?.temperature,
|
|
122
|
-
});
|
|
123
|
-
return result.text;
|
|
153
|
+
const provider = selectProvider(options?.provider, availableProviders);
|
|
154
|
+
const instance = getProviderInstance(provider);
|
|
155
|
+
return instance.ask(prompt, options);
|
|
124
156
|
},
|
|
125
|
-
async prompt(
|
|
126
|
-
|
|
157
|
+
async prompt(request) {
|
|
158
|
+
const provider = selectProvider(request.provider, availableProviders);
|
|
159
|
+
const instance = getProviderInstance(provider);
|
|
160
|
+
return instance.prompt(request);
|
|
127
161
|
},
|
|
128
162
|
};
|
|
129
163
|
}
|
package/dist/ai/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAUH,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AACjE,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,GACf,MAAM,aAAa,CAAC;AAKrB,2BAA2B;AAC3B,MAAM,oBAAoB,GAAG,6BAA6B,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,KAAK,CACnB,GAAwC;IAExC,IAAI,GAAsB,CAAC;IAE3B,2DAA2D;IAC3D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,IAAI,CAAC,uBAAuB,EAAE,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,wEAAwE;gBACtE,gHAAgH,CACnH,CAAC;QACJ,CAAC;QACD,GAAG,GAAG,cAAc,EAAW,CAAC;IAClC,CAAC;SAAM,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;QACxB,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IAChB,CAAC;SAAM,IAAI,kBAAkB,IAAI,GAAG,IAAI,kBAAkB,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,IAAI,qBAAqB,IAAI,GAAG,EAAE,CAAC;QACrI,oBAAoB;QACpB,GAAG,GAAG,GAAY,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,GAAG,GAAI,GAAW,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MA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AAK,WAAW,CAAC;YACjB,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ;gBACX,IAAI,CAAC,GAAG,CAAC,gBAAgB;oBAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;gBAC9E,MAAM,MAAM,GAAG,GAAG,CAAC,gBAAgB,IAAI,oBAAoB,CAAC;gBAC5D,QAAQ,GAAG,yBAAyB,CAAC,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;gBACnE,MAAM;YAER;gBACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,YAAY,EAAE,CAAC,CAAC;QACzD,CAAC;QAED,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,+CAA+C;IAC/C,OAAO;QACL,KAAK,CAAC,GAAG,CAAC,MAAc,EAAE,OAAoB;YAC5C,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC;YACvE,MAAM,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;YAC/C,OAAO,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvC,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,OAAsB;YACjC,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;YACtE,MAAM,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;YAC/C,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Namespace API - Convenience wrappers
|
|
3
|
+
*
|
|
4
|
+
* Provides a clean namespace-based API for common AI tasks using the unified provider system.
|
|
5
|
+
* Note: Advanced features (embed, generateImage, etc.) require Cloudflare Workers AI binding (env.AI).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { ai } from '@thewhateverapp/platform';
|
|
10
|
+
*
|
|
11
|
+
* // Simple text generation (works with all providers)
|
|
12
|
+
* const answer = await ai.chat("What is TypeScript?");
|
|
13
|
+
*
|
|
14
|
+
* // Advanced usage with full control
|
|
15
|
+
* const response = await ai.prompt({
|
|
16
|
+
* prompt: "Describe this",
|
|
17
|
+
* provider: 'cloudflare', // or 'replicate', 'anthropic', etc.
|
|
18
|
+
* capabilities: ['vision']
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import type { AskOptions, PromptRequest } from './types';
|
|
23
|
+
/**
|
|
24
|
+
* AI namespace with convenient helper methods
|
|
25
|
+
*/
|
|
26
|
+
export declare const ai: {
|
|
27
|
+
/**
|
|
28
|
+
* Simple chat/text generation (works with all providers)
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const answer = await ai.chat("Explain quantum computing in simple terms");
|
|
33
|
+
* const replicateAnswer = await ai.chat("Create a story", { provider: 'replicate' });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
chat(prompt: string, options?: AskOptions): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Advanced: Full prompt with detailed options and response
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const response = await ai.prompt({
|
|
43
|
+
* prompt: "Describe this image",
|
|
44
|
+
* provider: 'cloudflare',
|
|
45
|
+
* capabilities: ['vision'],
|
|
46
|
+
* images: [{ type: 'url', data: 'https://example.com/image.jpg' }],
|
|
47
|
+
* maxTokens: 500
|
|
48
|
+
* });
|
|
49
|
+
* console.log(response.text);
|
|
50
|
+
* console.log(response.tokensUsed);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
prompt(request: PromptRequest): Promise<import("./types").PromptResponse>;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=namespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../src/ai/namespace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEzD;;GAEG;AACH,eAAO,MAAM,EAAE;IACb;;;;;;;;OAQG;iBACgB,MAAM,YAAY,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjE;;;;;;;;;;;;;;;OAeG;oBACmB,aAAa;CAIpC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Namespace API - Convenience wrappers
|
|
3
|
+
*
|
|
4
|
+
* Provides a clean namespace-based API for common AI tasks using the unified provider system.
|
|
5
|
+
* Note: Advanced features (embed, generateImage, etc.) require Cloudflare Workers AI binding (env.AI).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { ai } from '@thewhateverapp/platform';
|
|
10
|
+
*
|
|
11
|
+
* // Simple text generation (works with all providers)
|
|
12
|
+
* const answer = await ai.chat("What is TypeScript?");
|
|
13
|
+
*
|
|
14
|
+
* // Advanced usage with full control
|
|
15
|
+
* const response = await ai.prompt({
|
|
16
|
+
* prompt: "Describe this",
|
|
17
|
+
* provider: 'cloudflare', // or 'replicate', 'anthropic', etc.
|
|
18
|
+
* capabilities: ['vision']
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { getAI } from './index';
|
|
23
|
+
/**
|
|
24
|
+
* AI namespace with convenient helper methods
|
|
25
|
+
*/
|
|
26
|
+
export const ai = {
|
|
27
|
+
/**
|
|
28
|
+
* Simple chat/text generation (works with all providers)
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const answer = await ai.chat("Explain quantum computing in simple terms");
|
|
33
|
+
* const replicateAnswer = await ai.chat("Create a story", { provider: 'replicate' });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
async chat(prompt, options) {
|
|
37
|
+
const provider = getAI();
|
|
38
|
+
return provider.ask(prompt, options);
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Advanced: Full prompt with detailed options and response
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const response = await ai.prompt({
|
|
46
|
+
* prompt: "Describe this image",
|
|
47
|
+
* provider: 'cloudflare',
|
|
48
|
+
* capabilities: ['vision'],
|
|
49
|
+
* images: [{ type: 'url', data: 'https://example.com/image.jpg' }],
|
|
50
|
+
* maxTokens: 500
|
|
51
|
+
* });
|
|
52
|
+
* console.log(response.text);
|
|
53
|
+
* console.log(response.tokensUsed);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async prompt(request) {
|
|
57
|
+
const provider = getAI();
|
|
58
|
+
return provider.prompt(request);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=namespace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.js","sourceRoot":"","sources":["../../src/ai/namespace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC;;GAEG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,OAAoB;QAC7C,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,MAAM,CAAC,OAAsB;QACjC,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Provider implementations
|
|
3
|
+
*
|
|
4
|
+
* Unified provider system for all AI services (Cloudflare, Replicate, Platform API)
|
|
5
|
+
*/
|
|
6
|
+
import type { AIServiceProvider, AIProvider, AIEnv, CloudflareAI } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Create Cloudflare Workers AI provider
|
|
9
|
+
*/
|
|
10
|
+
export declare function createCloudflareProvider(ai: CloudflareAI): AIServiceProvider;
|
|
11
|
+
/**
|
|
12
|
+
* Create Replicate provider
|
|
13
|
+
*/
|
|
14
|
+
export declare function createReplicateProvider(apiToken: string): AIServiceProvider;
|
|
15
|
+
/**
|
|
16
|
+
* Create Platform API provider (routes to anthropic/openai/google)
|
|
17
|
+
*/
|
|
18
|
+
export declare function createPlatformAPIProvider(apiUrl: string, apiKey: string): AIServiceProvider;
|
|
19
|
+
/**
|
|
20
|
+
* Detect available providers from environment
|
|
21
|
+
*/
|
|
22
|
+
export declare function detectAvailableProviders(env: AIEnv): AIProvider[];
|
|
23
|
+
/**
|
|
24
|
+
* Select best provider based on request and available providers
|
|
25
|
+
*/
|
|
26
|
+
export declare function selectProvider(requestedProvider: AIProvider | undefined, availableProviders: AIProvider[]): AIProvider;
|
|
27
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/ai/providers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EAIV,KAAK,EACL,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,YAAY,GAAG,iBAAiB,CAgF5E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAsF3E;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAoC3F;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,KAAK,GAAG,UAAU,EAAE,CAUjE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,iBAAiB,EAAE,UAAU,GAAG,SAAS,EACzC,kBAAkB,EAAE,UAAU,EAAE,GAC/B,UAAU,CAeZ"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Provider implementations
|
|
3
|
+
*
|
|
4
|
+
* Unified provider system for all AI services (Cloudflare, Replicate, Platform API)
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Create Cloudflare Workers AI provider
|
|
8
|
+
*/
|
|
9
|
+
export function createCloudflareProvider(ai) {
|
|
10
|
+
// Import model selection from workers module
|
|
11
|
+
function selectModel(capabilities) {
|
|
12
|
+
if (!capabilities || capabilities.length === 0) {
|
|
13
|
+
return '@cf/meta/llama-3.1-8b-instruct-fast';
|
|
14
|
+
}
|
|
15
|
+
const caps = new Set(capabilities);
|
|
16
|
+
if (caps.has('vision'))
|
|
17
|
+
return '@cf/meta/llama-3.2-11b-vision-instruct';
|
|
18
|
+
if (caps.has('coding'))
|
|
19
|
+
return '@cf/qwen/qwen2.5-coder-32b-instruct';
|
|
20
|
+
if (caps.has('reasoning'))
|
|
21
|
+
return '@cf/qwen/qwq-32b';
|
|
22
|
+
if (caps.has('fast'))
|
|
23
|
+
return '@cf/meta/llama-3.1-8b-instruct-fast';
|
|
24
|
+
if (caps.has('long-context'))
|
|
25
|
+
return '@cf/meta/llama-3.1-70b-instruct';
|
|
26
|
+
if (caps.has('cost-effective'))
|
|
27
|
+
return '@cf/meta/llama-3.2-1b-instruct';
|
|
28
|
+
if (caps.has('creative'))
|
|
29
|
+
return '@cf/meta/llama-3.1-8b-instruct';
|
|
30
|
+
return '@cf/meta/llama-3.1-8b-instruct-fast';
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
async ask(prompt, options) {
|
|
34
|
+
const model = selectModel(options?.capabilities);
|
|
35
|
+
const response = await ai.run(model, {
|
|
36
|
+
prompt,
|
|
37
|
+
max_tokens: options?.maxTokens,
|
|
38
|
+
temperature: options?.temperature,
|
|
39
|
+
});
|
|
40
|
+
return response.response || '';
|
|
41
|
+
},
|
|
42
|
+
async prompt(request) {
|
|
43
|
+
const model = request.model || selectModel(request.capabilities);
|
|
44
|
+
const messages = [];
|
|
45
|
+
if (request.systemPrompt) {
|
|
46
|
+
messages.push({ role: 'system', content: request.systemPrompt });
|
|
47
|
+
}
|
|
48
|
+
if (request.images && request.images.length > 0) {
|
|
49
|
+
const content = [{ type: 'text', text: request.prompt }];
|
|
50
|
+
for (const img of request.images) {
|
|
51
|
+
if (img.type === 'url') {
|
|
52
|
+
content.push({ type: 'image_url', image_url: { url: img.data } });
|
|
53
|
+
}
|
|
54
|
+
else if (img.type === 'base64') {
|
|
55
|
+
content.push({
|
|
56
|
+
type: 'image_url',
|
|
57
|
+
image_url: { url: `data:${img.mimeType || 'image/jpeg'};base64,${img.data}` },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
messages.push({ role: 'user', content });
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
messages.push({ role: 'user', content: request.prompt });
|
|
65
|
+
}
|
|
66
|
+
const response = await ai.run(model, {
|
|
67
|
+
messages,
|
|
68
|
+
max_tokens: request.maxTokens,
|
|
69
|
+
temperature: request.temperature,
|
|
70
|
+
});
|
|
71
|
+
let text = '';
|
|
72
|
+
if (response.response) {
|
|
73
|
+
text = response.response;
|
|
74
|
+
}
|
|
75
|
+
else if (response.choices && response.choices.length > 0) {
|
|
76
|
+
text = response.choices[0].message?.content || response.choices[0].text || '';
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
text,
|
|
80
|
+
provider: 'cloudflare',
|
|
81
|
+
model,
|
|
82
|
+
tokensUsed: { input: 0, output: 0, total: 0 },
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create Replicate provider
|
|
89
|
+
*/
|
|
90
|
+
export function createReplicateProvider(apiToken) {
|
|
91
|
+
const REPLICATE_API_URL = 'https://api.replicate.com/v1';
|
|
92
|
+
async function request(method, endpoint, body) {
|
|
93
|
+
const response = await fetch(`${REPLICATE_API_URL}${endpoint}`, {
|
|
94
|
+
method,
|
|
95
|
+
headers: {
|
|
96
|
+
'Authorization': `Token ${apiToken}`,
|
|
97
|
+
'Content-Type': 'application/json',
|
|
98
|
+
},
|
|
99
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
100
|
+
});
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
const error = await response.json().catch(() => ({ detail: response.statusText }));
|
|
103
|
+
throw new Error(error.detail || `Replicate API error: ${response.statusText}`);
|
|
104
|
+
}
|
|
105
|
+
return response.json();
|
|
106
|
+
}
|
|
107
|
+
// Default text generation model
|
|
108
|
+
const DEFAULT_TEXT_MODEL = 'meta/meta-llama-3-70b-instruct';
|
|
109
|
+
return {
|
|
110
|
+
async ask(prompt, options) {
|
|
111
|
+
// Create prediction
|
|
112
|
+
const prediction = await request('POST', '/predictions', {
|
|
113
|
+
version: DEFAULT_TEXT_MODEL,
|
|
114
|
+
input: { prompt, max_tokens: options?.maxTokens, temperature: options?.temperature },
|
|
115
|
+
});
|
|
116
|
+
// Poll for completion
|
|
117
|
+
const result = await waitForPrediction(prediction.id);
|
|
118
|
+
return Array.isArray(result.output) ? result.output.join('') : result.output;
|
|
119
|
+
},
|
|
120
|
+
async prompt(req) {
|
|
121
|
+
const model = req.model || DEFAULT_TEXT_MODEL;
|
|
122
|
+
const prediction = await request('POST', '/predictions', {
|
|
123
|
+
version: model,
|
|
124
|
+
input: {
|
|
125
|
+
prompt: req.prompt,
|
|
126
|
+
system_prompt: req.systemPrompt,
|
|
127
|
+
max_tokens: req.maxTokens,
|
|
128
|
+
temperature: req.temperature,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
const result = await waitForPrediction(prediction.id);
|
|
132
|
+
const text = Array.isArray(result.output) ? result.output.join('') : result.output;
|
|
133
|
+
return {
|
|
134
|
+
text,
|
|
135
|
+
provider: 'replicate',
|
|
136
|
+
model,
|
|
137
|
+
tokensUsed: { input: 0, output: 0, total: 0 },
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
async function waitForPrediction(id, timeout = 60000) {
|
|
142
|
+
const startTime = Date.now();
|
|
143
|
+
const pollInterval = 1000;
|
|
144
|
+
while (true) {
|
|
145
|
+
const prediction = await request('GET', `/predictions/${id}`);
|
|
146
|
+
if (prediction.status === 'succeeded' || prediction.status === 'failed' || prediction.status === 'canceled') {
|
|
147
|
+
if (prediction.status === 'failed') {
|
|
148
|
+
throw new Error(`Prediction failed: ${prediction.error || 'Unknown error'}`);
|
|
149
|
+
}
|
|
150
|
+
if (prediction.status === 'canceled') {
|
|
151
|
+
throw new Error('Prediction was canceled');
|
|
152
|
+
}
|
|
153
|
+
return prediction;
|
|
154
|
+
}
|
|
155
|
+
if (Date.now() - startTime > timeout) {
|
|
156
|
+
throw new Error(`Prediction timeout after ${timeout}ms`);
|
|
157
|
+
}
|
|
158
|
+
await new Promise(resolve => setTimeout(resolve, pollInterval));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create Platform API provider (routes to anthropic/openai/google)
|
|
164
|
+
*/
|
|
165
|
+
export function createPlatformAPIProvider(apiUrl, apiKey) {
|
|
166
|
+
async function request(endpoint, body) {
|
|
167
|
+
const response = await fetch(`${apiUrl}/platform/ai${endpoint}`, {
|
|
168
|
+
method: 'POST',
|
|
169
|
+
headers: {
|
|
170
|
+
'Content-Type': 'application/json',
|
|
171
|
+
'X-API-Key': apiKey,
|
|
172
|
+
},
|
|
173
|
+
body: JSON.stringify(body),
|
|
174
|
+
});
|
|
175
|
+
if (!response.ok) {
|
|
176
|
+
const error = await response.json().catch(() => ({}));
|
|
177
|
+
throw new Error(error.error || `AI service error: ${response.statusText}`);
|
|
178
|
+
}
|
|
179
|
+
return response.json();
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
async ask(prompt, options) {
|
|
183
|
+
const result = await request('/prompt', {
|
|
184
|
+
prompt,
|
|
185
|
+
provider: options?.provider,
|
|
186
|
+
capabilities: options?.capabilities,
|
|
187
|
+
maxTokens: options?.maxTokens,
|
|
188
|
+
temperature: options?.temperature,
|
|
189
|
+
});
|
|
190
|
+
return result.text;
|
|
191
|
+
},
|
|
192
|
+
async prompt(req) {
|
|
193
|
+
return request('/prompt', req);
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Detect available providers from environment
|
|
199
|
+
*/
|
|
200
|
+
export function detectAvailableProviders(env) {
|
|
201
|
+
const providers = [];
|
|
202
|
+
if (env.AI)
|
|
203
|
+
providers.push('cloudflare');
|
|
204
|
+
if (env.REPLICATE_API_TOKEN)
|
|
205
|
+
providers.push('replicate');
|
|
206
|
+
if (env.PLATFORM_API_KEY) {
|
|
207
|
+
providers.push('anthropic', 'openai', 'google');
|
|
208
|
+
}
|
|
209
|
+
return providers;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Select best provider based on request and available providers
|
|
213
|
+
*/
|
|
214
|
+
export function selectProvider(requestedProvider, availableProviders) {
|
|
215
|
+
// If specific provider requested, use it if available
|
|
216
|
+
if (requestedProvider && requestedProvider !== 'auto') {
|
|
217
|
+
if (availableProviders.includes(requestedProvider)) {
|
|
218
|
+
return requestedProvider;
|
|
219
|
+
}
|
|
220
|
+
throw new Error(`Provider '${requestedProvider}' not available. Configure ${requestedProvider.toUpperCase()}_API_TOKEN or binding.`);
|
|
221
|
+
}
|
|
222
|
+
// Auto-select: prefer Cloudflare > Platform API > Replicate
|
|
223
|
+
if (availableProviders.includes('cloudflare'))
|
|
224
|
+
return 'cloudflare';
|
|
225
|
+
if (availableProviders.includes('anthropic'))
|
|
226
|
+
return 'anthropic';
|
|
227
|
+
if (availableProviders.includes('replicate'))
|
|
228
|
+
return 'replicate';
|
|
229
|
+
throw new Error('No AI providers configured. Set up env.AI, REPLICATE_API_TOKEN, or PLATFORM_API_KEY.');
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../src/ai/providers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,EAAgB;IACvD,6CAA6C;IAC7C,SAAS,WAAW,CAAC,YAAuB;QAC1C,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/C,OAAO,qCAAqC,CAAC;QAC/C,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;QAEnC,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;YAAE,OAAO,wCAAwC,CAAC;QACxE,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;YAAE,OAAO,qCAAqC,CAAC;QACrE,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;YAAE,OAAO,kBAAkB,CAAC;QACrD,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;YAAE,OAAO,qCAAqC,CAAC;QACnE,IAAI,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;YAAE,OAAO,iCAAiC,CAAC;QACvE,IAAI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;QACzB,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,iBAAyC,EACzC,kBAAgC;IAEhC,sDAAsD;IACtD,IAAI,iBAAiB,IAAI,iBAAiB,KAAK,MAAM,EAAE,CAAC;QACtD,IAAI,kBAAkB,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACnD,OAAO,iBAAiB,CAAC;QAC3B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,aAAa,iBAAiB,8BAA8B,iBAAiB,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAC;IACvI,CAAC;IAED,4DAA4D;IAC5D,IAAI,kBAAkB,CAAC,QAAQ,CAAC,YAAY,CAAC;QAAE,OAAO,YAAY,CAAC;IACnE,IAAI,kBAAkB,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,WAAW,CAAC;IACjE,IAAI,kBAAkB,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,WAAW,CAAC;IAEjE,MAAM,IAAI,KAAK,CAAC,sFAAsF,CAAC,CAAC;AAC1G,CAAC"}
|
package/dist/ai/types.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* AI Provider options
|
|
8
8
|
*/
|
|
9
|
-
export type AIProvider = 'anthropic' | 'openai' | 'google' | 'auto';
|
|
9
|
+
export type AIProvider = 'cloudflare' | 'anthropic' | 'openai' | 'google' | 'replicate' | 'auto';
|
|
10
10
|
/**
|
|
11
11
|
* AI model capabilities for automatic model selection
|
|
12
12
|
*/
|
|
@@ -104,10 +104,20 @@ export interface AIServiceProvider {
|
|
|
104
104
|
*/
|
|
105
105
|
prompt(request: PromptRequest): Promise<PromptResponse>;
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Cloudflare AI binding interface
|
|
109
|
+
*/
|
|
110
|
+
export interface CloudflareAI {
|
|
111
|
+
run<T = any>(model: string, options: any): Promise<T>;
|
|
112
|
+
}
|
|
107
113
|
/**
|
|
108
114
|
* Cloudflare environment interface for AI
|
|
109
115
|
*/
|
|
110
116
|
export interface AIEnv {
|
|
117
|
+
/** Cloudflare Workers AI binding */
|
|
118
|
+
AI?: CloudflareAI;
|
|
119
|
+
/** Replicate API token */
|
|
120
|
+
REPLICATE_API_TOKEN?: string;
|
|
111
121
|
/** Platform API URL */
|
|
112
122
|
PLATFORM_API_URL?: string;
|
|
113
123
|
/** Platform API key for authentication */
|
package/dist/ai/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;AAEjG;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,QAAQ,GACR,WAAW,GACX,UAAU,GACV,MAAM,GACN,gBAAgB,GAChB,cAAc,CAAC;AAEnB;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,iDAAiD;IACjD,YAAY,CAAC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M,WAAW,YAAY;IAC3B,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACvD;AAED;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,oCAAoC;IACpC,EAAE,CAAC,EAAE,YAAY,CAAC;IAClB,0BAA0B;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uBAAuB;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0CAA0C;IAC1C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uBAAuB;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,KAAK,CAAC;CACZ"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Workers AI Provider
|
|
3
|
+
*
|
|
4
|
+
* Direct access to Cloudflare's AI models via env.AI.run()
|
|
5
|
+
* Supports text generation, embeddings, image generation, speech recognition, etc.
|
|
6
|
+
*/
|
|
7
|
+
import type { AIServiceProvider } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Cloudflare AI binding interface
|
|
10
|
+
*/
|
|
11
|
+
interface CloudflareAI {
|
|
12
|
+
run<T = any>(model: string, options: any): Promise<T>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Extended environment with Cloudflare AI binding
|
|
16
|
+
*/
|
|
17
|
+
export interface WorkersAIEnv {
|
|
18
|
+
AI?: CloudflareAI;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create Workers AI provider
|
|
22
|
+
*/
|
|
23
|
+
export declare function createWorkersAI(ai: CloudflareAI): AIServiceProvider;
|
|
24
|
+
/**
|
|
25
|
+
* High-level AI namespace with helper functions
|
|
26
|
+
*/
|
|
27
|
+
export interface WorkersAIHelpers extends AIServiceProvider {
|
|
28
|
+
/**
|
|
29
|
+
* Generate text embeddings for semantic search
|
|
30
|
+
* @param text - Text or array of texts to embed
|
|
31
|
+
* @returns Array of embedding vectors
|
|
32
|
+
*/
|
|
33
|
+
embed(text: string | string[]): Promise<number[][]>;
|
|
34
|
+
/**
|
|
35
|
+
* Generate an image from a text prompt
|
|
36
|
+
* @param prompt - Description of the image to generate
|
|
37
|
+
* @param options - Image generation options
|
|
38
|
+
* @returns Image as ArrayBuffer
|
|
39
|
+
*/
|
|
40
|
+
generateImage(prompt: string, options?: {
|
|
41
|
+
model?: string;
|
|
42
|
+
width?: number;
|
|
43
|
+
height?: number;
|
|
44
|
+
steps?: number;
|
|
45
|
+
}): Promise<ArrayBuffer>;
|
|
46
|
+
/**
|
|
47
|
+
* Transcribe audio to text
|
|
48
|
+
* @param audio - Audio file as ArrayBuffer or Blob
|
|
49
|
+
* @param options - Transcription options
|
|
50
|
+
* @returns Transcribed text
|
|
51
|
+
*/
|
|
52
|
+
transcribe(audio: ArrayBuffer | Blob, options?: {
|
|
53
|
+
model?: string;
|
|
54
|
+
language?: string;
|
|
55
|
+
}): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Translate text between languages
|
|
58
|
+
* @param text - Text to translate
|
|
59
|
+
* @param targetLang - Target language code (e.g., 'es', 'fr', 'de')
|
|
60
|
+
* @param sourceLang - Source language code (auto-detected if not provided)
|
|
61
|
+
* @returns Translated text
|
|
62
|
+
*/
|
|
63
|
+
translate(text: string, targetLang: string, sourceLang?: string): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Run a model directly with custom options
|
|
66
|
+
* @param model - Model ID (e.g., '@cf/meta/llama-3.1-8b-instruct')
|
|
67
|
+
* @param options - Model-specific options
|
|
68
|
+
* @returns Model response
|
|
69
|
+
*/
|
|
70
|
+
run<T = any>(model: string, options: any): Promise<T>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create enhanced Workers AI provider with helper functions
|
|
74
|
+
*/
|
|
75
|
+
export declare function createWorkersAIWithHelpers(ai: CloudflareAI): WorkersAIHelpers;
|
|
76
|
+
export {};
|
|
77
|
+
//# sourceMappingURL=workers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workers.d.ts","sourceRoot":"","sources":["../../src/ai/workers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,iBAAiB,EAKlB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,UAAU,YAAY;IACpB,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACvD;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,CAAC,EAAE,YAAY,CAAC;CACnB;AAoDD;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,YAAY,GAAG,iBAAiB,CAkFnE;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAEpD;;;;;OAKG;IACH,aAAa,CACX,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GACA,OAAO,CAAC,WAAW,CAAC,CAAC;IAExB;;;;;OAKG;IACH,UAAU,CACR,KAAK,EAAE,WAAW,GAAG,IAAI,EACzB,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GACA,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;;OAMG;IACH,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;OAKG;IACH,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACvD;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,YAAY,GAAG,gBAAgB,CA6E7E"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Workers AI Provider
|
|
3
|
+
*
|
|
4
|
+
* Direct access to Cloudflare's AI models via env.AI.run()
|
|
5
|
+
* Supports text generation, embeddings, image generation, speech recognition, etc.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Model selection based on capabilities
|
|
9
|
+
*/
|
|
10
|
+
function selectModel(capabilities) {
|
|
11
|
+
if (!capabilities || capabilities.length === 0) {
|
|
12
|
+
// Default: fast general-purpose model
|
|
13
|
+
return '@cf/meta/llama-3.1-8b-instruct-fast';
|
|
14
|
+
}
|
|
15
|
+
const caps = new Set(capabilities);
|
|
16
|
+
// Vision models
|
|
17
|
+
if (caps.has('vision')) {
|
|
18
|
+
return '@cf/meta/llama-3.2-11b-vision-instruct';
|
|
19
|
+
}
|
|
20
|
+
// Coding models
|
|
21
|
+
if (caps.has('coding')) {
|
|
22
|
+
return '@cf/qwen/qwen2.5-coder-32b-instruct';
|
|
23
|
+
}
|
|
24
|
+
// Reasoning models
|
|
25
|
+
if (caps.has('reasoning')) {
|
|
26
|
+
return '@cf/qwen/qwq-32b';
|
|
27
|
+
}
|
|
28
|
+
// Fast models
|
|
29
|
+
if (caps.has('fast')) {
|
|
30
|
+
return '@cf/meta/llama-3.1-8b-instruct-fast';
|
|
31
|
+
}
|
|
32
|
+
// Long context models
|
|
33
|
+
if (caps.has('long-context')) {
|
|
34
|
+
return '@cf/meta/llama-3.1-70b-instruct';
|
|
35
|
+
}
|
|
36
|
+
// Cost-effective models
|
|
37
|
+
if (caps.has('cost-effective')) {
|
|
38
|
+
return '@cf/meta/llama-3.2-1b-instruct';
|
|
39
|
+
}
|
|
40
|
+
// Creative models
|
|
41
|
+
if (caps.has('creative')) {
|
|
42
|
+
return '@cf/meta/llama-3.1-8b-instruct';
|
|
43
|
+
}
|
|
44
|
+
// Default fallback
|
|
45
|
+
return '@cf/meta/llama-3.1-8b-instruct-fast';
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create Workers AI provider
|
|
49
|
+
*/
|
|
50
|
+
export function createWorkersAI(ai) {
|
|
51
|
+
return {
|
|
52
|
+
async ask(prompt, options) {
|
|
53
|
+
const model = selectModel(options?.capabilities);
|
|
54
|
+
const response = await ai.run(model, {
|
|
55
|
+
prompt,
|
|
56
|
+
max_tokens: options?.maxTokens,
|
|
57
|
+
temperature: options?.temperature,
|
|
58
|
+
});
|
|
59
|
+
return response.response || '';
|
|
60
|
+
},
|
|
61
|
+
async prompt(request) {
|
|
62
|
+
const model = request.model || selectModel(request.capabilities);
|
|
63
|
+
// Build messages array
|
|
64
|
+
const messages = [];
|
|
65
|
+
// Add system message if provided
|
|
66
|
+
if (request.systemPrompt) {
|
|
67
|
+
messages.push({
|
|
68
|
+
role: 'system',
|
|
69
|
+
content: request.systemPrompt,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Add user message with optional images
|
|
73
|
+
if (request.images && request.images.length > 0) {
|
|
74
|
+
// Vision model - include images
|
|
75
|
+
const content = [{ type: 'text', text: request.prompt }];
|
|
76
|
+
for (const img of request.images) {
|
|
77
|
+
if (img.type === 'url') {
|
|
78
|
+
content.push({
|
|
79
|
+
type: 'image_url',
|
|
80
|
+
image_url: { url: img.data },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else if (img.type === 'base64') {
|
|
84
|
+
content.push({
|
|
85
|
+
type: 'image_url',
|
|
86
|
+
image_url: {
|
|
87
|
+
url: `data:${img.mimeType || 'image/jpeg'};base64,${img.data}`,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
messages.push({ role: 'user', content });
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Text-only
|
|
96
|
+
messages.push({ role: 'user', content: request.prompt });
|
|
97
|
+
}
|
|
98
|
+
// Run the model
|
|
99
|
+
const response = await ai.run(model, {
|
|
100
|
+
messages,
|
|
101
|
+
max_tokens: request.maxTokens,
|
|
102
|
+
temperature: request.temperature,
|
|
103
|
+
});
|
|
104
|
+
// Extract text from response (different models return different formats)
|
|
105
|
+
let text = '';
|
|
106
|
+
if (response.response) {
|
|
107
|
+
text = response.response;
|
|
108
|
+
}
|
|
109
|
+
else if (response.choices && response.choices.length > 0) {
|
|
110
|
+
text = response.choices[0].message?.content || response.choices[0].text || '';
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
text,
|
|
114
|
+
provider: 'cloudflare',
|
|
115
|
+
model,
|
|
116
|
+
tokensUsed: {
|
|
117
|
+
input: 0, // Workers AI doesn't return token counts
|
|
118
|
+
output: 0,
|
|
119
|
+
total: 0,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Create enhanced Workers AI provider with helper functions
|
|
127
|
+
*/
|
|
128
|
+
export function createWorkersAIWithHelpers(ai) {
|
|
129
|
+
const baseProvider = createWorkersAI(ai);
|
|
130
|
+
return {
|
|
131
|
+
...baseProvider,
|
|
132
|
+
async embed(text) {
|
|
133
|
+
const texts = Array.isArray(text) ? text : [text];
|
|
134
|
+
const model = '@cf/baai/bge-large-en-v1.5';
|
|
135
|
+
const results = await Promise.all(texts.map((t) => ai.run(model, { text: t })));
|
|
136
|
+
return results.map((r) => r.data[0]);
|
|
137
|
+
},
|
|
138
|
+
async generateImage(prompt, options) {
|
|
139
|
+
const model = options?.model || '@cf/black-forest-labs/flux-1-schnell';
|
|
140
|
+
const response = await ai.run(model, {
|
|
141
|
+
prompt,
|
|
142
|
+
num_steps: options?.steps || 4,
|
|
143
|
+
});
|
|
144
|
+
return response;
|
|
145
|
+
},
|
|
146
|
+
async transcribe(audio, options) {
|
|
147
|
+
const model = options?.model || '@cf/openai/whisper-large-v3-turbo';
|
|
148
|
+
// Convert Blob to ArrayBuffer if needed
|
|
149
|
+
const audioBuffer = audio instanceof Blob ? await audio.arrayBuffer() : audio;
|
|
150
|
+
const response = await ai.run(model, {
|
|
151
|
+
audio: Array.from(new Uint8Array(audioBuffer)),
|
|
152
|
+
language: options?.language,
|
|
153
|
+
});
|
|
154
|
+
return response.text || response.vtt || '';
|
|
155
|
+
},
|
|
156
|
+
async translate(text, targetLang, sourceLang) {
|
|
157
|
+
// Use multilingual translation model
|
|
158
|
+
const model = '@cf/meta/m2m100-1.2b';
|
|
159
|
+
const response = await ai.run(model, {
|
|
160
|
+
text,
|
|
161
|
+
source_lang: sourceLang || 'en',
|
|
162
|
+
target_lang: targetLang,
|
|
163
|
+
});
|
|
164
|
+
return response.translated_text;
|
|
165
|
+
},
|
|
166
|
+
async run(model, options) {
|
|
167
|
+
return ai.run(model, options);
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=workers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workers.js","sourceRoot":"","sources":["../../src/ai/workers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwBH;;GAEG;AACH,SAAS,WAAW,CAAC,YAA6B;IAChD,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/C,sCAAsC;QACtC,OAAO,qCAAqC,CAAC;IAC/C,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,GA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AC,IAAI,IAAI,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC;QAC7C,CAAC;QAED,KAAK,CAAC,SAAS,CACb,IAAY,EACZ,UAAkB,EAClB,UAAmB;YAEnB,qCAAqC;YACrC,MAAM,KAAK,GAAG,sBAAsB,CAAC;YAErC,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,GAAG,CAA8B,KAAK,EAAE;gBAChE,IAAI;gBACJ,WAAW,EAAE,UAAU,IAAI,IAAI;gBAC/B,WAAW,EAAE,UAAU;aACxB,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC,eAAe,CAAC;QAClC,CAAC;QAED,KAAK,CAAC,GAAG,CAAU,KAAa,EAAE,OAAY;YAC5C,OAAO,EAAE,CAAC,GAAG,CAAI,KAAK,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,8 @@ export type { StorageProvider, StorageObject, StorageMetadata, ListOptions as St
|
|
|
37
37
|
export { getPublicStorage, createPublicStorage, resetPublicStorage, } from './public-storage';
|
|
38
38
|
export type { PublicStorageProvider, PublicStorageUploadOptions, PublicStorageUploadResult, } from './public-storage';
|
|
39
39
|
export { getAI, createAI } from './ai';
|
|
40
|
-
export
|
|
40
|
+
export { ai } from './ai/namespace';
|
|
41
|
+
export type { AIServiceProvider, AIProvider, AICapability, AskOptions, PromptRequest, PromptResponse, ImageInput, CloudflareAI, } from './ai';
|
|
41
42
|
export { getTileState } from './tile-state';
|
|
42
43
|
export type { TileStateProvider, Comment, Report, } from './tile-state/types';
|
|
43
44
|
export { getTileContext, clearTileContextCache } from './tile-context';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EACL,oBAAoB,EACpB,c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EACtB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,GACjB,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -39,8 +39,9 @@ export { getKV, createKV } from './kv';
|
|
|
39
39
|
export { getStorage, createStorage } from './r2';
|
|
40
40
|
// Public Storage - Public file uploads via platform-api (CDN-backed)
|
|
41
41
|
export { getPublicStorage, createPublicStorage, resetPublicStorage, } from './public-storage';
|
|
42
|
-
// AI - Artificial Intelligence (
|
|
42
|
+
// AI - Artificial Intelligence (Cloudflare Workers AI, Replicate, Platform API)
|
|
43
43
|
export { getAI, createAI } from './ai';
|
|
44
|
+
export { ai } from './ai/namespace';
|
|
44
45
|
// Tile State - Durable Objects for real-time state
|
|
45
46
|
export { getTileState } from './tile-state';
|
|
46
47
|
// Tile Context - Server-side authentication for tile API routes
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,0EAA0E;AAC1E,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,OAAO,CAAC;AAGf,eAAe;AACf,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAK9D,gFAAgF;AAChF,mEAAmE;AACnE,gFAAgF;AAEhF,mDAAmD;AACnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAazD,yCAAyC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAWvC,gCAAgC;AAChC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAYjD,qEAAqE;AACrE,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAO1B,
|
|
1
|
+
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