@inf-minds/mindkit 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.
- package/dist/extensions/index.d.ts +2 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +6 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/mind.d.ts +15 -0
- package/dist/mind.d.ts.map +1 -0
- package/dist/mind.js +274 -0
- package/dist/mind.js.map +1 -0
- package/dist/providers/anthropic.d.ts +9 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +20 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +6 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/openai.d.ts +9 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +20 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/select.d.ts +17 -0
- package/dist/providers/select.d.ts.map +1 -0
- package/dist/providers/select.js +44 -0
- package/dist/providers/select.js.map +1 -0
- package/dist/types.d.ts +156 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
- package/src/extensions/index.ts +7 -0
- package/src/index.ts +32 -0
- package/src/mind.ts +348 -0
- package/src/providers/anthropic.ts +22 -0
- package/src/providers/index.ts +6 -0
- package/src/providers/openai.ts +22 -0
- package/src/providers/select.ts +56 -0
- package/src/types.ts +147 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,uDAAuD;AAEvD,kDAAkD;AAClD,iDAAiD;AAEjD,OAAO,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { Mind, MindConfig, MindInput, MindOutput, MindEvent, MindExtension, ToolDefinition, TokenUsage, ArtifactWithHints, Unsubscribe, GenerateId, } from './types.js';
|
|
2
|
+
export { createMind, type CreateMindOptions } from './mind.js';
|
|
3
|
+
export { createAnthropicModel, createOpenAIModel, selectModel, detectProvider, type ModelProvider, } from './providers/index.js';
|
|
4
|
+
export * from './extensions/index.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,IAAI,EACJ,UAAU,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACT,aAAa,EACb,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG/D,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC;AAG9B,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// ABOUTME: Mindkit package entry point
|
|
2
|
+
// ABOUTME: Exports Mind types, createMind factory, and provider adapters
|
|
3
|
+
// Factory exports
|
|
4
|
+
export { createMind } from './mind.js';
|
|
5
|
+
// Provider exports
|
|
6
|
+
export { createAnthropicModel, createOpenAIModel, selectModel, detectProvider, } from './providers/index.js';
|
|
7
|
+
// Extension exports (placeholder for future extensions)
|
|
8
|
+
export * from './extensions/index.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,yEAAyE;AAiBzE,kBAAkB;AAClB,OAAO,EAAE,UAAU,EAA0B,MAAM,WAAW,CAAC;AAE/D,mBAAmB;AACnB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,cAAc,GAEf,MAAM,sBAAsB,CAAC;AAE9B,wDAAwD;AACxD,cAAc,uBAAuB,CAAC"}
|
package/dist/mind.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Mind, MindConfig, GenerateId } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating a mind
|
|
4
|
+
*/
|
|
5
|
+
export interface CreateMindOptions extends MindConfig {
|
|
6
|
+
/** Custom ID generator */
|
|
7
|
+
generateId?: GenerateId;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a mind instance
|
|
11
|
+
* @param options - Mind configuration and options
|
|
12
|
+
* @returns Mind instance
|
|
13
|
+
*/
|
|
14
|
+
export declare function createMind(options: CreateMindOptions): Mind;
|
|
15
|
+
//# sourceMappingURL=mind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mind.d.ts","sourceRoot":"","sources":["../src/mind.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,IAAI,EACJ,UAAU,EAOV,UAAU,EACX,MAAM,YAAY,CAAC;AAOpB;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,0BAA0B;IAC1B,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AA2SD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAc3D"}
|
package/dist/mind.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// ABOUTME: Mind factory for creating mind instances
|
|
2
|
+
// ABOUTME: Uses Vercel AI SDK for LLM orchestration
|
|
3
|
+
import { generateText, streamText, tool } from 'ai';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { selectModel } from './providers/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Default ID generator using crypto.randomUUID
|
|
8
|
+
*/
|
|
9
|
+
const defaultGenerateId = () => crypto.randomUUID();
|
|
10
|
+
/**
|
|
11
|
+
* Build the final system prompt from base config and extensions
|
|
12
|
+
*/
|
|
13
|
+
function buildSystemPrompt(config) {
|
|
14
|
+
const parts = [];
|
|
15
|
+
// Base system prompt
|
|
16
|
+
if (config.systemPrompt) {
|
|
17
|
+
parts.push(config.systemPrompt);
|
|
18
|
+
}
|
|
19
|
+
// Extension additions
|
|
20
|
+
if (config.extensions) {
|
|
21
|
+
for (const ext of config.extensions) {
|
|
22
|
+
if (ext.systemPromptAddition) {
|
|
23
|
+
parts.push(ext.systemPromptAddition);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return parts.join('\n\n');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Collect tools from config and extensions
|
|
31
|
+
*/
|
|
32
|
+
function collectTools(config) {
|
|
33
|
+
const tools = [];
|
|
34
|
+
// Base tools
|
|
35
|
+
if (config.tools) {
|
|
36
|
+
tools.push(...config.tools);
|
|
37
|
+
}
|
|
38
|
+
// Extension tools
|
|
39
|
+
if (config.extensions) {
|
|
40
|
+
for (const ext of config.extensions) {
|
|
41
|
+
if (ext.tools) {
|
|
42
|
+
tools.push(...ext.tools);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return tools;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Apply extension preprocessors to input
|
|
50
|
+
*/
|
|
51
|
+
function preprocessInput(input, extensions) {
|
|
52
|
+
let processed = input;
|
|
53
|
+
if (extensions) {
|
|
54
|
+
for (const ext of extensions) {
|
|
55
|
+
if (ext.preprocessInput) {
|
|
56
|
+
processed = ext.preprocessInput(processed);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return processed;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Apply extension postprocessors to output
|
|
64
|
+
*/
|
|
65
|
+
function postprocessOutput(output, extensions) {
|
|
66
|
+
let processed = output;
|
|
67
|
+
if (extensions) {
|
|
68
|
+
for (const ext of extensions) {
|
|
69
|
+
if (ext.postprocessOutput) {
|
|
70
|
+
processed = ext.postprocessOutput(processed);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return processed;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Convert tool definitions to Vercel AI SDK tool format
|
|
78
|
+
*/
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
+
function convertToolsToAI(tools) {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
|
+
const aiTools = {};
|
|
83
|
+
for (const toolDef of tools) {
|
|
84
|
+
// Convert parameters to zod schema if it's a plain object
|
|
85
|
+
const parametersSchema = toolDef.parameters instanceof z.ZodType
|
|
86
|
+
? toolDef.parameters
|
|
87
|
+
: z.object(toolDef.parameters);
|
|
88
|
+
aiTools[toolDef.name] = tool({
|
|
89
|
+
description: toolDef.description,
|
|
90
|
+
parameters: parametersSchema,
|
|
91
|
+
execute: toolDef.execute,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return aiTools;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Build messages array from input
|
|
98
|
+
*/
|
|
99
|
+
function buildMessages(systemPrompt, input) {
|
|
100
|
+
const messages = [];
|
|
101
|
+
// Add system message if provided
|
|
102
|
+
if (systemPrompt) {
|
|
103
|
+
messages.push({ role: 'system', content: systemPrompt });
|
|
104
|
+
}
|
|
105
|
+
// Build user message with context
|
|
106
|
+
let userContent = input.task;
|
|
107
|
+
if (input.context) {
|
|
108
|
+
userContent = `Context:\n${JSON.stringify(input.context, null, 2)}\n\nTask:\n${input.task}`;
|
|
109
|
+
}
|
|
110
|
+
messages.push({ role: 'user', content: userContent });
|
|
111
|
+
return messages;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Mind implementation using Vercel AI SDK
|
|
115
|
+
*/
|
|
116
|
+
class MindImpl {
|
|
117
|
+
id;
|
|
118
|
+
config;
|
|
119
|
+
systemPrompt;
|
|
120
|
+
toolDefs;
|
|
121
|
+
model;
|
|
122
|
+
subscribers = new Set();
|
|
123
|
+
constructor(id, config, systemPrompt, toolDefs, model) {
|
|
124
|
+
this.id = id;
|
|
125
|
+
this.config = config;
|
|
126
|
+
this.systemPrompt = systemPrompt;
|
|
127
|
+
this.toolDefs = toolDefs;
|
|
128
|
+
this.model = model;
|
|
129
|
+
}
|
|
130
|
+
emit(event) {
|
|
131
|
+
for (const handler of this.subscribers) {
|
|
132
|
+
try {
|
|
133
|
+
handler(event);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Ignore subscriber errors
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async run(input) {
|
|
141
|
+
// Preprocess input
|
|
142
|
+
const processedInput = preprocessInput(input, this.config.extensions);
|
|
143
|
+
// Emit started event
|
|
144
|
+
this.emit({ type: 'started', timestamp: new Date() });
|
|
145
|
+
try {
|
|
146
|
+
// Build messages
|
|
147
|
+
const messages = buildMessages(this.systemPrompt, processedInput);
|
|
148
|
+
// Convert tools
|
|
149
|
+
const tools = this.toolDefs.length > 0 ? convertToolsToAI(this.toolDefs) : undefined;
|
|
150
|
+
// Execute via Vercel AI SDK
|
|
151
|
+
const result = await generateText({
|
|
152
|
+
model: this.model,
|
|
153
|
+
messages,
|
|
154
|
+
tools,
|
|
155
|
+
maxSteps: 10,
|
|
156
|
+
maxTokens: this.config.maxTokens,
|
|
157
|
+
temperature: this.config.temperature,
|
|
158
|
+
});
|
|
159
|
+
// Build output
|
|
160
|
+
const output = {
|
|
161
|
+
result: result.text,
|
|
162
|
+
usage: result.usage
|
|
163
|
+
? {
|
|
164
|
+
promptTokens: result.usage.promptTokens ?? 0,
|
|
165
|
+
completionTokens: result.usage.completionTokens ?? 0,
|
|
166
|
+
totalTokens: (result.usage.promptTokens ?? 0) + (result.usage.completionTokens ?? 0),
|
|
167
|
+
}
|
|
168
|
+
: undefined,
|
|
169
|
+
};
|
|
170
|
+
// Postprocess output
|
|
171
|
+
const processedOutput = postprocessOutput(output, this.config.extensions);
|
|
172
|
+
// Emit completed event
|
|
173
|
+
this.emit({ type: 'completed', output: processedOutput });
|
|
174
|
+
return processedOutput;
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
178
|
+
this.emit({ type: 'failed', error: errorMessage });
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async *stream(input) {
|
|
183
|
+
// Preprocess input
|
|
184
|
+
const processedInput = preprocessInput(input, this.config.extensions);
|
|
185
|
+
// Emit started event
|
|
186
|
+
const startedEvent = { type: 'started', timestamp: new Date() };
|
|
187
|
+
this.emit(startedEvent);
|
|
188
|
+
yield startedEvent;
|
|
189
|
+
try {
|
|
190
|
+
// Build messages
|
|
191
|
+
const messages = buildMessages(this.systemPrompt, processedInput);
|
|
192
|
+
// Convert tools
|
|
193
|
+
const tools = this.toolDefs.length > 0 ? convertToolsToAI(this.toolDefs) : undefined;
|
|
194
|
+
// Stream via Vercel AI SDK - streamText returns a Promise
|
|
195
|
+
const streamResult = await streamText({
|
|
196
|
+
model: this.model,
|
|
197
|
+
messages,
|
|
198
|
+
tools,
|
|
199
|
+
maxSteps: 10,
|
|
200
|
+
maxTokens: this.config.maxTokens,
|
|
201
|
+
temperature: this.config.temperature,
|
|
202
|
+
});
|
|
203
|
+
let fullText = '';
|
|
204
|
+
// Process stream chunks - fullStream is an AsyncIterable
|
|
205
|
+
for await (const chunk of streamResult.fullStream) {
|
|
206
|
+
if (chunk.type === 'text-delta') {
|
|
207
|
+
const event = { type: 'text_delta', delta: chunk.textDelta };
|
|
208
|
+
fullText += chunk.textDelta;
|
|
209
|
+
this.emit(event);
|
|
210
|
+
yield event;
|
|
211
|
+
}
|
|
212
|
+
else if (chunk.type === 'tool-call') {
|
|
213
|
+
const event = { type: 'tool_call', tool: chunk.toolName, args: chunk.args };
|
|
214
|
+
this.emit(event);
|
|
215
|
+
yield event;
|
|
216
|
+
}
|
|
217
|
+
else if (chunk.type === 'tool-result') {
|
|
218
|
+
const event = { type: 'tool_result', tool: chunk.toolName, result: chunk.result };
|
|
219
|
+
this.emit(event);
|
|
220
|
+
yield event;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Get final usage - usage is a promise that resolves after stream completes
|
|
224
|
+
const usage = await streamResult.usage;
|
|
225
|
+
// Build output
|
|
226
|
+
const output = {
|
|
227
|
+
result: fullText,
|
|
228
|
+
usage: usage
|
|
229
|
+
? {
|
|
230
|
+
promptTokens: usage.promptTokens ?? 0,
|
|
231
|
+
completionTokens: usage.completionTokens ?? 0,
|
|
232
|
+
totalTokens: (usage.promptTokens ?? 0) + (usage.completionTokens ?? 0),
|
|
233
|
+
}
|
|
234
|
+
: undefined,
|
|
235
|
+
};
|
|
236
|
+
// Postprocess output
|
|
237
|
+
const processedOutput = postprocessOutput(output, this.config.extensions);
|
|
238
|
+
// Emit completed event
|
|
239
|
+
const completedEvent = { type: 'completed', output: processedOutput };
|
|
240
|
+
this.emit(completedEvent);
|
|
241
|
+
yield completedEvent;
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
245
|
+
const failedEvent = { type: 'failed', error: errorMessage };
|
|
246
|
+
this.emit(failedEvent);
|
|
247
|
+
yield failedEvent;
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
subscribe(handler) {
|
|
252
|
+
this.subscribers.add(handler);
|
|
253
|
+
return () => {
|
|
254
|
+
this.subscribers.delete(handler);
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Create a mind instance
|
|
260
|
+
* @param options - Mind configuration and options
|
|
261
|
+
* @returns Mind instance
|
|
262
|
+
*/
|
|
263
|
+
export function createMind(options) {
|
|
264
|
+
const generateId = options.generateId ?? defaultGenerateId;
|
|
265
|
+
const id = generateId();
|
|
266
|
+
// Build system prompt
|
|
267
|
+
const systemPrompt = buildSystemPrompt(options);
|
|
268
|
+
// Collect tools (keep as definitions, convert at runtime)
|
|
269
|
+
const toolDefs = collectTools(options);
|
|
270
|
+
// Select model based on config
|
|
271
|
+
const model = selectModel(options.model, options.provider, options.apiKey);
|
|
272
|
+
return new MindImpl(id, options, systemPrompt, toolDefs, model);
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=mind.js.map
|
package/dist/mind.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mind.js","sourceRoot":"","sources":["../src/mind.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,oDAAoD;AAEpD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAwC,MAAM,IAAI,CAAC;AAC1F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAanD;;GAEG;AACH,MAAM,iBAAiB,GAAe,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;AAUhE;;GAEG;AACH,SAAS,iBAAiB,CAAC,MAAkB;IAC3C,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,qBAAqB;IACrB,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;QACxB,K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Y,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAEhD,0DAA0D;IAC1D,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IAEvC,+BAA+B;IAC/B,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3E,OAAO,IAAI,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LanguageModel } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* Create an Anthropic model instance
|
|
4
|
+
* @param modelId - Model identifier (e.g., 'claude-sonnet-4-20250514')
|
|
5
|
+
* @param apiKey - Optional API key (required for edge runtimes like Cloudflare Workers)
|
|
6
|
+
* @returns Anthropic model instance
|
|
7
|
+
*/
|
|
8
|
+
export declare function createAnthropicModel(modelId: string, apiKey?: string): LanguageModel;
|
|
9
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAExC;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CASpF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// ABOUTME: Anthropic provider adapter for mindkit
|
|
2
|
+
// ABOUTME: Creates Anthropic model instances using @ai-sdk/anthropic
|
|
3
|
+
import { createAnthropic, anthropic } from '@ai-sdk/anthropic';
|
|
4
|
+
/**
|
|
5
|
+
* Create an Anthropic model instance
|
|
6
|
+
* @param modelId - Model identifier (e.g., 'claude-sonnet-4-20250514')
|
|
7
|
+
* @param apiKey - Optional API key (required for edge runtimes like Cloudflare Workers)
|
|
8
|
+
* @returns Anthropic model instance
|
|
9
|
+
*/
|
|
10
|
+
export function createAnthropicModel(modelId, apiKey) {
|
|
11
|
+
// Cast needed due to version differences between @ai-sdk/anthropic and ai package
|
|
12
|
+
if (apiKey) {
|
|
13
|
+
// Use explicit API key for edge runtimes that don't have process.env
|
|
14
|
+
const anthropicClient = createAnthropic({ apiKey });
|
|
15
|
+
return anthropicClient(modelId);
|
|
16
|
+
}
|
|
17
|
+
// Fallback to env var for Node.js environments
|
|
18
|
+
return anthropic(modelId);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,qEAAqE;AAErE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG/D;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe,EAAE,MAAe;IACnE,kFAAkF;IAClF,IAAI,MAAM,EAAE,CAAC;QACX,qEAAqE;QACrE,MAAM,eAAe,GAAG,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACpD,OAAO,eAAe,CAAC,OAAO,CAA6B,CAAC;IAC9D,CAAC;IACD,+CAA+C;IAC/C,OAAO,SAAS,CAAC,OAAO,CAA6B,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// ABOUTME: LLM provider adapters for mindkit
|
|
2
|
+
// ABOUTME: Exports provider creation functions for Anthropic and OpenAI
|
|
3
|
+
export { createAnthropicModel } from './anthropic.js';
|
|
4
|
+
export { createOpenAIModel } from './openai.js';
|
|
5
|
+
export { selectModel, detectProvider } from './select.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,wEAAwE;AAExE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAsB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LanguageModel } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* Create an OpenAI model instance
|
|
4
|
+
* @param modelId - Model identifier (e.g., 'gpt-4o')
|
|
5
|
+
* @param apiKey - Optional API key (required for edge runtimes like Cloudflare Workers)
|
|
6
|
+
* @returns OpenAI model instance
|
|
7
|
+
*/
|
|
8
|
+
export declare function createOpenAIModel(modelId: string, apiKey?: string): LanguageModel;
|
|
9
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAExC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CASjF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// ABOUTME: OpenAI provider adapter for mindkit
|
|
2
|
+
// ABOUTME: Creates OpenAI model instances using @ai-sdk/openai
|
|
3
|
+
import { createOpenAI, openai } from '@ai-sdk/openai';
|
|
4
|
+
/**
|
|
5
|
+
* Create an OpenAI model instance
|
|
6
|
+
* @param modelId - Model identifier (e.g., 'gpt-4o')
|
|
7
|
+
* @param apiKey - Optional API key (required for edge runtimes like Cloudflare Workers)
|
|
8
|
+
* @returns OpenAI model instance
|
|
9
|
+
*/
|
|
10
|
+
export function createOpenAIModel(modelId, apiKey) {
|
|
11
|
+
// Cast needed due to version differences between @ai-sdk/openai and ai package
|
|
12
|
+
if (apiKey) {
|
|
13
|
+
// Use explicit API key for edge runtimes that don't have process.env
|
|
14
|
+
const openaiClient = createOpenAI({ apiKey });
|
|
15
|
+
return openaiClient(modelId);
|
|
16
|
+
}
|
|
17
|
+
// Fallback to env var for Node.js environments
|
|
18
|
+
return openai(modelId);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,+DAA+D;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe,EAAE,MAAe;IAChE,+EAA+E;IAC/E,IAAI,MAAM,EAAE,CAAC;QACX,qEAAqE;QACrE,MAAM,YAAY,GAAG,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC9C,OAAO,YAAY,CAAC,OAAO,CAA6B,CAAC;IAC3D,CAAC;IACD,+CAA+C;IAC/C,OAAO,MAAM,CAAC,OAAO,CAA6B,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LanguageModel } from 'ai';
|
|
2
|
+
export type ModelProvider = 'anthropic' | 'openai';
|
|
3
|
+
/**
|
|
4
|
+
* Detect provider from model ID
|
|
5
|
+
* @param modelId - Model identifier
|
|
6
|
+
* @returns Detected provider
|
|
7
|
+
*/
|
|
8
|
+
export declare function detectProvider(modelId: string): ModelProvider;
|
|
9
|
+
/**
|
|
10
|
+
* Select and create model instance based on model ID and optional provider override
|
|
11
|
+
* @param modelId - Model identifier
|
|
12
|
+
* @param provider - Optional provider override
|
|
13
|
+
* @param apiKey - Optional API key (required for edge runtimes like Cloudflare Workers)
|
|
14
|
+
* @returns Model instance
|
|
15
|
+
*/
|
|
16
|
+
export declare function selectModel(modelId: string, provider?: ModelProvider, apiKey?: string): LanguageModel;
|
|
17
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/providers/select.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAIxC,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAqB7D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CAWrG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// ABOUTME: Model selection logic for mindkit
|
|
2
|
+
// ABOUTME: Auto-detects provider from model ID and creates appropriate model instance
|
|
3
|
+
import { createAnthropicModel } from './anthropic.js';
|
|
4
|
+
import { createOpenAIModel } from './openai.js';
|
|
5
|
+
/**
|
|
6
|
+
* Detect provider from model ID
|
|
7
|
+
* @param modelId - Model identifier
|
|
8
|
+
* @returns Detected provider
|
|
9
|
+
*/
|
|
10
|
+
export function detectProvider(modelId) {
|
|
11
|
+
// Anthropic models
|
|
12
|
+
if (modelId.includes('claude') ||
|
|
13
|
+
modelId.startsWith('claude-')) {
|
|
14
|
+
return 'anthropic';
|
|
15
|
+
}
|
|
16
|
+
// OpenAI models
|
|
17
|
+
if (modelId.includes('gpt') ||
|
|
18
|
+
modelId.startsWith('gpt-') ||
|
|
19
|
+
modelId.startsWith('o1') ||
|
|
20
|
+
modelId.startsWith('o3')) {
|
|
21
|
+
return 'openai';
|
|
22
|
+
}
|
|
23
|
+
// Default to OpenAI for unknown models
|
|
24
|
+
return 'openai';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Select and create model instance based on model ID and optional provider override
|
|
28
|
+
* @param modelId - Model identifier
|
|
29
|
+
* @param provider - Optional provider override
|
|
30
|
+
* @param apiKey - Optional API key (required for edge runtimes like Cloudflare Workers)
|
|
31
|
+
* @returns Model instance
|
|
32
|
+
*/
|
|
33
|
+
export function selectModel(modelId, provider, apiKey) {
|
|
34
|
+
const resolvedProvider = provider ?? detectProvider(modelId);
|
|
35
|
+
switch (resolvedProvider) {
|
|
36
|
+
case 'anthropic':
|
|
37
|
+
return createAnthropicModel(modelId, apiKey);
|
|
38
|
+
case 'openai':
|
|
39
|
+
return createOpenAIModel(modelId, apiKey);
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`Unknown provider: ${resolvedProvider}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/providers/select.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,sFAAsF;AAGtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhD;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,mBAAmB;IACnB,IACE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC1B,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,EAC7B,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,gBAAgB;IAChB,IACE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;QACvB,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC;QAC1B,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC;QACxB,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EACxB,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,uCAAuC;IACvC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,QAAwB,EAAE,MAAe;IACpF,MAAM,gBAAgB,GAAG,QAAQ,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IAE7D,QAAQ,gBAAgB,EAAE,CAAC;QACzB,KAAK,WAAW;YACd,OAAO,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC/C,KAAK,QAAQ;YACX,OAAO,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5C;YACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,gBAAgB,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC"}
|