@thewhateverapp/platform 0.10.1 → 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 +17 -7
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +65 -63
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/namespace.d.ts +11 -71
- package/dist/ai/namespace.d.ts.map +1 -1
- package/dist/ai/namespace.js +11 -78
- package/dist/ai/namespace.js.map +1 -1
- 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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/ai/index.d.ts
CHANGED
|
@@ -40,22 +40,32 @@
|
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
42
|
import type { AIServiceProvider, AIRequest, AIEnv } from './types';
|
|
43
|
-
import { type WorkersAIHelpers, type WorkersAIEnv } from './workers';
|
|
44
43
|
export type * from './types';
|
|
45
|
-
export type { WorkersAIHelpers, WorkersAIEnv } from './workers';
|
|
46
44
|
/**
|
|
47
45
|
* Get an AI service instance for the current request
|
|
48
46
|
*
|
|
49
|
-
* Automatically
|
|
50
|
-
*
|
|
47
|
+
* Automatically detects available providers and routes requests appropriately.
|
|
48
|
+
* Supports Cloudflare Workers AI, Replicate, and Platform API (Anthropic/OpenAI/Google).
|
|
51
49
|
*
|
|
52
50
|
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
53
51
|
* If not provided, uses the env configured via configurePlatformEnv().
|
|
54
|
-
* @returns AI service provider instance
|
|
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
|
+
* ```
|
|
55
65
|
*/
|
|
56
66
|
export declare function getAI(req?: AIRequest | {
|
|
57
|
-
env: AIEnv
|
|
58
|
-
} |
|
|
67
|
+
env: AIEnv;
|
|
68
|
+
} | AIEnv): AIServiceProvider;
|
|
59
69
|
/**
|
|
60
70
|
* Create an AI service instance directly with config
|
|
61
71
|
*
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,SAAS,EACT,KAAK,EAIN,MAAM,SAAS,CAAC;
|
|
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
|
@@ -40,18 +40,30 @@
|
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
42
|
import { getPlatformEnv, isPlatformEnvConfigured } from '../env';
|
|
43
|
-
import {
|
|
43
|
+
import { createCloudflareProvider, createReplicateProvider, createPlatformAPIProvider, detectAvailableProviders, selectProvider, } from './providers';
|
|
44
44
|
// Default platform API URL
|
|
45
45
|
const DEFAULT_PLATFORM_API = 'https://api.thewhatever.app';
|
|
46
46
|
/**
|
|
47
47
|
* Get an AI service instance for the current request
|
|
48
48
|
*
|
|
49
|
-
* Automatically
|
|
50
|
-
*
|
|
49
|
+
* Automatically detects available providers and routes requests appropriately.
|
|
50
|
+
* Supports Cloudflare Workers AI, Replicate, and Platform API (Anthropic/OpenAI/Google).
|
|
51
51
|
*
|
|
52
52
|
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
53
53
|
* If not provided, uses the env configured via configurePlatformEnv().
|
|
54
|
-
* @returns AI service provider instance
|
|
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
|
+
* ```
|
|
55
67
|
*/
|
|
56
68
|
export function getAI(req) {
|
|
57
69
|
let env;
|
|
@@ -66,7 +78,7 @@ export function getAI(req) {
|
|
|
66
78
|
else if ('env' in req) {
|
|
67
79
|
env = req.env;
|
|
68
80
|
}
|
|
69
|
-
else if ('PLATFORM_API_KEY' in req || 'PLATFORM_API_URL' in req || 'TILE_ID' in req || 'AI' 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) {
|
|
70
82
|
// Direct env object
|
|
71
83
|
env = req;
|
|
72
84
|
}
|
|
@@ -76,38 +88,8 @@ export function getAI(req) {
|
|
|
76
88
|
if (!env) {
|
|
77
89
|
throw new Error('No environment found in request. Ensure you are running in edge runtime.');
|
|
78
90
|
}
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
return createWorkersAIWithHelpers(env.AI);
|
|
82
|
-
}
|
|
83
|
-
// Fall back to platform API
|
|
84
|
-
const apiUrl = env.PLATFORM_API_URL || DEFAULT_PLATFORM_API;
|
|
85
|
-
const apiKey = env.PLATFORM_API_KEY;
|
|
86
|
-
if (!apiKey) {
|
|
87
|
-
throw new Error('No AI binding or PLATFORM_API_KEY found. ' +
|
|
88
|
-
'Add AI binding to wrangler.jsonc or set PLATFORM_API_KEY secret.');
|
|
89
|
-
}
|
|
90
|
-
// Platform API doesn't support all helper methods, so we need to create a compatible wrapper
|
|
91
|
-
const baseProvider = createAIProvider(apiUrl, apiKey);
|
|
92
|
-
// Return with stub implementations for helpers (not supported via platform API)
|
|
93
|
-
return {
|
|
94
|
-
...baseProvider,
|
|
95
|
-
async embed() {
|
|
96
|
-
throw new Error('embed() requires Workers AI binding (env.AI). Platform API does not support embeddings.');
|
|
97
|
-
},
|
|
98
|
-
async generateImage() {
|
|
99
|
-
throw new Error('generateImage() requires Workers AI binding (env.AI). Platform API does not support image generation.');
|
|
100
|
-
},
|
|
101
|
-
async transcribe() {
|
|
102
|
-
throw new Error('transcribe() requires Workers AI binding (env.AI). Platform API does not support speech recognition.');
|
|
103
|
-
},
|
|
104
|
-
async translate() {
|
|
105
|
-
throw new Error('translate() requires Workers AI binding (env.AI). Platform API does not support translation.');
|
|
106
|
-
},
|
|
107
|
-
async run() {
|
|
108
|
-
throw new Error('run() requires Workers AI binding (env.AI). Use ask() or prompt() instead.');
|
|
109
|
-
},
|
|
110
|
-
};
|
|
91
|
+
// Create a unified provider that routes to the appropriate backend
|
|
92
|
+
return createUnifiedProvider(env);
|
|
111
93
|
}
|
|
112
94
|
/**
|
|
113
95
|
* Create an AI service instance directly with config
|
|
@@ -122,40 +104,60 @@ export function getAI(req) {
|
|
|
122
104
|
*/
|
|
123
105
|
export function createAI(config) {
|
|
124
106
|
const apiUrl = config.apiUrl || DEFAULT_PLATFORM_API;
|
|
125
|
-
return
|
|
107
|
+
return createPlatformAPIProvider(apiUrl, config.apiKey);
|
|
126
108
|
}
|
|
127
109
|
/**
|
|
128
|
-
* Internal: Create
|
|
110
|
+
* Internal: Create unified provider that routes to appropriate backend
|
|
129
111
|
*/
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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}`);
|
|
143
146
|
}
|
|
144
|
-
|
|
147
|
+
providerCache.set(providerName, instance);
|
|
148
|
+
return instance;
|
|
145
149
|
}
|
|
150
|
+
// Return unified provider that routes requests
|
|
146
151
|
return {
|
|
147
152
|
async ask(prompt, options) {
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
capabilities: options?.capabilities,
|
|
152
|
-
maxTokens: options?.maxTokens,
|
|
153
|
-
temperature: options?.temperature,
|
|
154
|
-
});
|
|
155
|
-
return result.text;
|
|
153
|
+
const provider = selectProvider(options?.provider, availableProviders);
|
|
154
|
+
const instance = getProviderInstance(provider);
|
|
155
|
+
return instance.ask(prompt, options);
|
|
156
156
|
},
|
|
157
|
-
async prompt(
|
|
158
|
-
|
|
157
|
+
async prompt(request) {
|
|
158
|
+
const provider = selectProvider(request.provider, availableProviders);
|
|
159
|
+
const instance = getProviderInstance(provider);
|
|
160
|
+
return instance.prompt(request);
|
|
159
161
|
},
|
|
160
162
|
};
|
|
161
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;;;;;;;;;;;;;;;;;;;;;;;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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"}
|
package/dist/ai/namespace.d.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AI Namespace API - Convenience wrappers
|
|
3
3
|
*
|
|
4
|
-
* Provides a clean namespace-based API for common AI tasks
|
|
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).
|
|
5
6
|
*
|
|
6
7
|
* @example
|
|
7
8
|
* ```typescript
|
|
8
9
|
* import { ai } from '@thewhateverapp/platform';
|
|
9
10
|
*
|
|
10
|
-
* // Simple text generation
|
|
11
|
+
* // Simple text generation (works with all providers)
|
|
11
12
|
* const answer = await ai.chat("What is TypeScript?");
|
|
12
13
|
*
|
|
13
|
-
* // Generate embeddings
|
|
14
|
-
* const vectors = await ai.embed(["hello world", "foo bar"]);
|
|
15
|
-
*
|
|
16
|
-
* // Generate image
|
|
17
|
-
* const imageBuffer = await ai.generateImage("a sunset over mountains");
|
|
18
|
-
*
|
|
19
14
|
* // Advanced usage with full control
|
|
20
|
-
* const
|
|
21
|
-
*
|
|
15
|
+
* const response = await ai.prompt({
|
|
16
|
+
* prompt: "Describe this",
|
|
17
|
+
* provider: 'cloudflare', // or 'replicate', 'anthropic', etc.
|
|
18
|
+
* capabilities: ['vision']
|
|
19
|
+
* });
|
|
22
20
|
* ```
|
|
23
21
|
*/
|
|
24
22
|
import type { AskOptions, PromptRequest } from './types';
|
|
@@ -27,62 +25,15 @@ import type { AskOptions, PromptRequest } from './types';
|
|
|
27
25
|
*/
|
|
28
26
|
export declare const ai: {
|
|
29
27
|
/**
|
|
30
|
-
* Simple chat/text generation
|
|
28
|
+
* Simple chat/text generation (works with all providers)
|
|
31
29
|
*
|
|
32
30
|
* @example
|
|
33
31
|
* ```typescript
|
|
34
32
|
* const answer = await ai.chat("Explain quantum computing in simple terms");
|
|
33
|
+
* const replicateAnswer = await ai.chat("Create a story", { provider: 'replicate' });
|
|
35
34
|
* ```
|
|
36
35
|
*/
|
|
37
36
|
chat(prompt: string, options?: AskOptions): Promise<string>;
|
|
38
|
-
/**
|
|
39
|
-
* Generate text embeddings for semantic search
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* const embeddings = await ai.embed("search query");
|
|
44
|
-
* const multipleEmbeddings = await ai.embed(["query 1", "query 2"]);
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
embed(text: string | string[]): Promise<number[][]>;
|
|
48
|
-
/**
|
|
49
|
-
* Generate an image from a text prompt
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* const imageBuffer = await ai.generateImage("a beautiful sunset over mountains");
|
|
54
|
-
* const blob = new Blob([imageBuffer], { type: 'image/png' });
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
generateImage(prompt: string, options?: {
|
|
58
|
-
model?: string;
|
|
59
|
-
width?: number;
|
|
60
|
-
height?: number;
|
|
61
|
-
steps?: number;
|
|
62
|
-
}): Promise<ArrayBuffer>;
|
|
63
|
-
/**
|
|
64
|
-
* Transcribe audio to text
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* const audioBlob = await fetch('/audio.mp3').then(r => r.blob());
|
|
69
|
-
* const transcript = await ai.transcribe(audioBlob);
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
transcribe(audio: ArrayBuffer | Blob, options?: {
|
|
73
|
-
model?: string;
|
|
74
|
-
language?: string;
|
|
75
|
-
}): Promise<string>;
|
|
76
|
-
/**
|
|
77
|
-
* Translate text between languages
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* const spanish = await ai.translate("Hello, world!", "es");
|
|
82
|
-
* const french = await ai.translate("Hello, world!", "fr", "en");
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
translate(text: string, targetLang: string, sourceLang?: string): Promise<string>;
|
|
86
37
|
/**
|
|
87
38
|
* Advanced: Full prompt with detailed options and response
|
|
88
39
|
*
|
|
@@ -90,6 +41,7 @@ export declare const ai: {
|
|
|
90
41
|
* ```typescript
|
|
91
42
|
* const response = await ai.prompt({
|
|
92
43
|
* prompt: "Describe this image",
|
|
44
|
+
* provider: 'cloudflare',
|
|
93
45
|
* capabilities: ['vision'],
|
|
94
46
|
* images: [{ type: 'url', data: 'https://example.com/image.jpg' }],
|
|
95
47
|
* maxTokens: 500
|
|
@@ -99,17 +51,5 @@ export declare const ai: {
|
|
|
99
51
|
* ```
|
|
100
52
|
*/
|
|
101
53
|
prompt(request: PromptRequest): Promise<import("./types").PromptResponse>;
|
|
102
|
-
/**
|
|
103
|
-
* Run a specific model directly with custom options
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* const result = await ai.run('@cf/meta/llama-3.1-8b-instruct', {
|
|
108
|
-
* prompt: "Hello!",
|
|
109
|
-
* max_tokens: 100
|
|
110
|
-
* });
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
run<T = any>(model: string, options: any): Promise<T>;
|
|
114
54
|
};
|
|
115
55
|
//# sourceMappingURL=namespace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../src/ai/namespace.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|
package/dist/ai/namespace.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AI Namespace API - Convenience wrappers
|
|
3
3
|
*
|
|
4
|
-
* Provides a clean namespace-based API for common AI tasks
|
|
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).
|
|
5
6
|
*
|
|
6
7
|
* @example
|
|
7
8
|
* ```typescript
|
|
8
9
|
* import { ai } from '@thewhateverapp/platform';
|
|
9
10
|
*
|
|
10
|
-
* // Simple text generation
|
|
11
|
+
* // Simple text generation (works with all providers)
|
|
11
12
|
* const answer = await ai.chat("What is TypeScript?");
|
|
12
13
|
*
|
|
13
|
-
* // Generate embeddings
|
|
14
|
-
* const vectors = await ai.embed(["hello world", "foo bar"]);
|
|
15
|
-
*
|
|
16
|
-
* // Generate image
|
|
17
|
-
* const imageBuffer = await ai.generateImage("a sunset over mountains");
|
|
18
|
-
*
|
|
19
14
|
* // Advanced usage with full control
|
|
20
|
-
* const
|
|
21
|
-
*
|
|
15
|
+
* const response = await ai.prompt({
|
|
16
|
+
* prompt: "Describe this",
|
|
17
|
+
* provider: 'cloudflare', // or 'replicate', 'anthropic', etc.
|
|
18
|
+
* capabilities: ['vision']
|
|
19
|
+
* });
|
|
22
20
|
* ```
|
|
23
21
|
*/
|
|
24
22
|
import { getAI } from './index';
|
|
@@ -27,69 +25,18 @@ import { getAI } from './index';
|
|
|
27
25
|
*/
|
|
28
26
|
export const ai = {
|
|
29
27
|
/**
|
|
30
|
-
* Simple chat/text generation
|
|
28
|
+
* Simple chat/text generation (works with all providers)
|
|
31
29
|
*
|
|
32
30
|
* @example
|
|
33
31
|
* ```typescript
|
|
34
32
|
* const answer = await ai.chat("Explain quantum computing in simple terms");
|
|
33
|
+
* const replicateAnswer = await ai.chat("Create a story", { provider: 'replicate' });
|
|
35
34
|
* ```
|
|
36
35
|
*/
|
|
37
36
|
async chat(prompt, options) {
|
|
38
37
|
const provider = getAI();
|
|
39
38
|
return provider.ask(prompt, options);
|
|
40
39
|
},
|
|
41
|
-
/**
|
|
42
|
-
* Generate text embeddings for semantic search
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* const embeddings = await ai.embed("search query");
|
|
47
|
-
* const multipleEmbeddings = await ai.embed(["query 1", "query 2"]);
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
async embed(text) {
|
|
51
|
-
const provider = getAI();
|
|
52
|
-
return provider.embed(text);
|
|
53
|
-
},
|
|
54
|
-
/**
|
|
55
|
-
* Generate an image from a text prompt
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```typescript
|
|
59
|
-
* const imageBuffer = await ai.generateImage("a beautiful sunset over mountains");
|
|
60
|
-
* const blob = new Blob([imageBuffer], { type: 'image/png' });
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
async generateImage(prompt, options) {
|
|
64
|
-
const provider = getAI();
|
|
65
|
-
return provider.generateImage(prompt, options);
|
|
66
|
-
},
|
|
67
|
-
/**
|
|
68
|
-
* Transcribe audio to text
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const audioBlob = await fetch('/audio.mp3').then(r => r.blob());
|
|
73
|
-
* const transcript = await ai.transcribe(audioBlob);
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
async transcribe(audio, options) {
|
|
77
|
-
const provider = getAI();
|
|
78
|
-
return provider.transcribe(audio, options);
|
|
79
|
-
},
|
|
80
|
-
/**
|
|
81
|
-
* Translate text between languages
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```typescript
|
|
85
|
-
* const spanish = await ai.translate("Hello, world!", "es");
|
|
86
|
-
* const french = await ai.translate("Hello, world!", "fr", "en");
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
async translate(text, targetLang, sourceLang) {
|
|
90
|
-
const provider = getAI();
|
|
91
|
-
return provider.translate(text, targetLang, sourceLang);
|
|
92
|
-
},
|
|
93
40
|
/**
|
|
94
41
|
* Advanced: Full prompt with detailed options and response
|
|
95
42
|
*
|
|
@@ -97,6 +44,7 @@ export const ai = {
|
|
|
97
44
|
* ```typescript
|
|
98
45
|
* const response = await ai.prompt({
|
|
99
46
|
* prompt: "Describe this image",
|
|
47
|
+
* provider: 'cloudflare',
|
|
100
48
|
* capabilities: ['vision'],
|
|
101
49
|
* images: [{ type: 'url', data: 'https://example.com/image.jpg' }],
|
|
102
50
|
* maxTokens: 500
|
|
@@ -109,20 +57,5 @@ export const ai = {
|
|
|
109
57
|
const provider = getAI();
|
|
110
58
|
return provider.prompt(request);
|
|
111
59
|
},
|
|
112
|
-
/**
|
|
113
|
-
* Run a specific model directly with custom options
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```typescript
|
|
117
|
-
* const result = await ai.run('@cf/meta/llama-3.1-8b-instruct', {
|
|
118
|
-
* prompt: "Hello!",
|
|
119
|
-
* max_tokens: 100
|
|
120
|
-
* });
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
async run(model, options) {
|
|
124
|
-
const provider = getAI();
|
|
125
|
-
return provider.run(model, options);
|
|
126
|
-
},
|
|
127
60
|
};
|
|
128
61
|
//# sourceMappingURL=namespace.js.map
|
package/dist/ai/namespace.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namespace.js","sourceRoot":"","sources":["../../src/ai/namespace.ts"],"names":[],"mappings":"AAAA
|
|
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;Y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AAI,GAAG,CAAC,gBAAgB,EAAE,CAAC;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,C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AC,CAAC;CACzD;AAED;;GAEG;AACH,MAAM,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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export { getPublicStorage, createPublicStorage, resetPublicStorage, } from './pu
|
|
|
38
38
|
export type { PublicStorageProvider, PublicStorageUploadOptions, PublicStorageUploadResult, } from './public-storage';
|
|
39
39
|
export { getAI, createAI } from './ai';
|
|
40
40
|
export { ai } from './ai/namespace';
|
|
41
|
-
export type { AIServiceProvider, AIProvider, AICapability, AskOptions, PromptRequest, PromptResponse, ImageInput,
|
|
41
|
+
export type { AIServiceProvider, AIProvider, AICapability, AskOptions, PromptRequest, PromptResponse, ImageInput, CloudflareAI, } from './ai';
|
|
42
42
|
export { getTileState } from './tile-state';
|
|
43
43
|
export type { TileStateProvider, Comment, Report, } from './tile-state/types';
|
|
44
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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mB,EACnB,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,GACjB,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ 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 (Cloudflare Workers AI
|
|
42
|
+
// AI - Artificial Intelligence (Cloudflare Workers AI, Replicate, Platform API)
|
|
43
43
|
export { getAI, createAI } from './ai';
|
|
44
44
|
export { ai } from './ai/namespace';
|
|
45
45
|
// Tile State - Durable Objects for real-time state
|
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;AA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