aieo 0.1.11 → 0.1.13
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/{index.mjs → index.cjs} +74 -24
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +130 -0
- package/dist/index.d.ts +87 -25
- package/dist/index.js +41 -55
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
- package/dist/index.d.mts +0 -68
- package/dist/index.mjs.map +0 -1
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ConversationStorage: () => ConversationStorage,
|
|
24
|
+
MAX_CONVERSATIONS: () => MAX_CONVERSATIONS,
|
|
25
|
+
OUTRO: () => OUTRO,
|
|
26
|
+
PROVIDERS: () => PROVIDERS,
|
|
27
|
+
SYSTEM: () => SYSTEM,
|
|
28
|
+
callModel: () => callModel,
|
|
29
|
+
getModel: () => getModel,
|
|
30
|
+
getProviderOptions: () => getProviderOptions
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
|
|
1
34
|
// ../node_modules/uuid/dist/esm/stringify.js
|
|
2
35
|
var byteToHex = [];
|
|
3
36
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -8,20 +41,20 @@ function unsafeStringify(arr, offset = 0) {
|
|
|
8
41
|
}
|
|
9
42
|
|
|
10
43
|
// ../node_modules/uuid/dist/esm/rng.js
|
|
11
|
-
|
|
44
|
+
var import_crypto = require("crypto");
|
|
12
45
|
var rnds8Pool = new Uint8Array(256);
|
|
13
46
|
var poolPtr = rnds8Pool.length;
|
|
14
47
|
function rng() {
|
|
15
48
|
if (poolPtr > rnds8Pool.length - 16) {
|
|
16
|
-
randomFillSync(rnds8Pool);
|
|
49
|
+
(0, import_crypto.randomFillSync)(rnds8Pool);
|
|
17
50
|
poolPtr = 0;
|
|
18
51
|
}
|
|
19
52
|
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
20
53
|
}
|
|
21
54
|
|
|
22
55
|
// ../node_modules/uuid/dist/esm/native.js
|
|
23
|
-
|
|
24
|
-
var native_default = { randomUUID };
|
|
56
|
+
var import_crypto2 = require("crypto");
|
|
57
|
+
var native_default = { randomUUID: import_crypto2.randomUUID };
|
|
25
58
|
|
|
26
59
|
// ../node_modules/uuid/dist/esm/v4.js
|
|
27
60
|
function v4(options, buf, offset) {
|
|
@@ -126,35 +159,49 @@ var ConversationStorage = class {
|
|
|
126
159
|
};
|
|
127
160
|
|
|
128
161
|
// src/provider.ts
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
162
|
+
var import_anthropic = require("@ai-sdk/anthropic");
|
|
163
|
+
var import_google = require("@ai-sdk/google");
|
|
164
|
+
var import_openai = require("@ai-sdk/openai");
|
|
165
|
+
var import_ai_sdk_provider_claude_code = require("ai-sdk-provider-claude-code");
|
|
166
|
+
var PROVIDERS = [
|
|
167
|
+
"anthropic",
|
|
168
|
+
"google",
|
|
169
|
+
"openai",
|
|
170
|
+
"claude_code"
|
|
171
|
+
];
|
|
135
172
|
var SOTA = {
|
|
136
|
-
anthropic: "claude-
|
|
173
|
+
anthropic: "claude-4-sonnet-20250514",
|
|
137
174
|
google: "gemini-2.5-pro-preview-05-06",
|
|
138
|
-
openai: "gpt-4.1"
|
|
175
|
+
openai: "gpt-4.1",
|
|
176
|
+
claude_code: "sonnet"
|
|
139
177
|
};
|
|
140
|
-
async function getModel(provider, apiKey) {
|
|
178
|
+
async function getModel(provider, apiKey, cwd) {
|
|
141
179
|
switch (provider) {
|
|
142
180
|
case "anthropic":
|
|
143
|
-
const anthropic = createAnthropic({
|
|
181
|
+
const anthropic = (0, import_anthropic.createAnthropic)({
|
|
144
182
|
apiKey
|
|
145
183
|
});
|
|
146
184
|
return anthropic(SOTA[provider]);
|
|
147
185
|
case "google":
|
|
148
|
-
const google = createGoogleGenerativeAI({
|
|
186
|
+
const google = (0, import_google.createGoogleGenerativeAI)({
|
|
149
187
|
apiKey
|
|
150
188
|
});
|
|
151
189
|
return google(SOTA[provider]);
|
|
152
190
|
case "openai":
|
|
153
|
-
const openai = createOpenAI({
|
|
154
|
-
apiKey
|
|
155
|
-
compatibility: "strict"
|
|
191
|
+
const openai = (0, import_openai.createOpenAI)({
|
|
192
|
+
apiKey
|
|
156
193
|
});
|
|
157
194
|
return openai(SOTA[provider]);
|
|
195
|
+
case "claude_code":
|
|
196
|
+
const customProvider = (0, import_ai_sdk_provider_claude_code.createClaudeCode)({
|
|
197
|
+
defaultSettings: {
|
|
198
|
+
// Skip permission prompts for all operations
|
|
199
|
+
permissionMode: "bypassPermissions",
|
|
200
|
+
// Set working directory for file operations
|
|
201
|
+
cwd
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
return customProvider(SOTA[provider]);
|
|
158
205
|
default:
|
|
159
206
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
160
207
|
}
|
|
@@ -180,18 +227,20 @@ function getProviderOptions(provider, thinkingSpeed) {
|
|
|
180
227
|
return {
|
|
181
228
|
openai: {}
|
|
182
229
|
};
|
|
230
|
+
case "claude_code":
|
|
231
|
+
return;
|
|
183
232
|
default:
|
|
184
233
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
185
234
|
}
|
|
186
235
|
}
|
|
187
236
|
|
|
188
237
|
// src/stream.ts
|
|
189
|
-
|
|
238
|
+
var import_ai = require("ai");
|
|
190
239
|
async function callModel(provider, apiKey, messages, tools, parser, thinkingSpeed) {
|
|
191
240
|
const model = await getModel(provider, apiKey);
|
|
192
241
|
const providerOptions = getProviderOptions(provider, thinkingSpeed);
|
|
193
242
|
console.log(`Calling ${provider} with options:`, providerOptions);
|
|
194
|
-
const result = streamText({
|
|
243
|
+
const result = (0, import_ai.streamText)({
|
|
195
244
|
model,
|
|
196
245
|
tools,
|
|
197
246
|
messages,
|
|
@@ -207,7 +256,7 @@ async function callModel(provider, apiKey, messages, tools, parser, thinkingSpee
|
|
|
207
256
|
if (parser) {
|
|
208
257
|
parser(fullResponse);
|
|
209
258
|
}
|
|
210
|
-
fullResponse += part.
|
|
259
|
+
fullResponse += part.text;
|
|
211
260
|
break;
|
|
212
261
|
}
|
|
213
262
|
}
|
|
@@ -232,7 +281,8 @@ If asked to make further changes after already writing code, use the <content> b
|
|
|
232
281
|
var OUTRO = `
|
|
233
282
|
Please write all the necessary code to fully implement the feature end-to-end. Do not make mock data or example placeholders!!!
|
|
234
283
|
`;
|
|
235
|
-
export
|
|
284
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
285
|
+
0 && (module.exports = {
|
|
236
286
|
ConversationStorage,
|
|
237
287
|
MAX_CONVERSATIONS,
|
|
238
288
|
OUTRO,
|
|
@@ -241,5 +291,5 @@ export {
|
|
|
241
291
|
callModel,
|
|
242
292
|
getModel,
|
|
243
293
|
getProviderOptions
|
|
244
|
-
};
|
|
245
|
-
//# sourceMappingURL=index.
|
|
294
|
+
});
|
|
295
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../../node_modules/uuid/dist/esm/stringify.js","../../node_modules/uuid/dist/esm/rng.js","../../node_modules/uuid/dist/esm/native.js","../../node_modules/uuid/dist/esm/v4.js","../src/store.ts","../src/provider.ts","../src/stream.ts","../src/prompt.ts"],"sourcesContent":["export * from \"./store\";\nexport * from \"./provider\";\nexport * from \"./stream\";\nexport * from \"./prompt\";\n\nexport type { ModelMessage } from \"ai\";\nexport type { Tool, ToolSet } from \"ai\";\n","import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n","import { randomFillSync } from 'crypto';\nconst rnds8Pool = new Uint8Array(256);\nlet poolPtr = rnds8Pool.length;\nexport default function rng() {\n if (poolPtr > rnds8Pool.length - 16) {\n randomFillSync(rnds8Pool);\n poolPtr = 0;\n }\n return rnds8Pool.slice(poolPtr, (poolPtr += 16));\n}\n","import { randomUUID } from 'crypto';\nexport default { randomUUID };\n","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n options = options || {};\n const rnds = options.random ?? options.rng?.() ?? rng();\n if (rnds.length < 16) {\n throw new Error('Random bytes length must be >= 16');\n }\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n if (offset < 0 || offset + 16 > buf.length) {\n throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);\n }\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;\n","import { ModelMessage } from \"ai\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nexport interface Conversation {\n id: string;\n summary: string;\n timestamp: number;\n}\n\nexport interface ConversationData {\n id: string;\n summary: string;\n messages: ModelMessage[];\n lastUpdated: number;\n}\n\nexport const MAX_CONVERSATIONS = 100;\n\nexport abstract class ConversationStorage {\n // Abstract methods to be implemented by platform-specific storage\n abstract currentConversationId(): Promise<string>;\n abstract selectConversation(conversationId: string): Promise<void>;\n abstract listConversations(): Promise<Conversation[]>;\n abstract getConversation(\n conversationId: string\n ): Promise<ConversationData | null>;\n abstract storeConversationData(\n conversationId: string,\n data: ConversationData\n ): Promise<void>;\n abstract deleteConversationData(conversationId: string): Promise<boolean>;\n\n // Shared functionality that works across platforms\n async createConversation(\n messages: ModelMessage[]\n ): Promise<ConversationData> {\n const id = uuidv4();\n const initialMessage = messages.find((msg) => msg.role === \"user\");\n const summary = initialMessage\n ? this.generateSummary(initialMessage.content as string)\n : `New conversation ${new Date().toLocaleString()}`;\n const conversation: ConversationData = {\n id,\n summary,\n messages,\n lastUpdated: Date.now(),\n };\n await this.storeConversationData(id, conversation);\n await this.selectConversation(id);\n await this.pruneOldConversations();\n return conversation;\n }\n\n async addMessageToConversation(\n conversationId: string,\n message: ModelMessage\n ): Promise<ConversationData> {\n const conversation = await this.getConversation(conversationId);\n if (!conversation) {\n throw new Error(`Conversation with ID ${conversationId} not found`);\n }\n conversation.messages.push({ ...message });\n conversation.lastUpdated = Date.now();\n await this.storeConversationData(conversationId, conversation);\n return conversation;\n }\n\n async getCurrentConversation(): Promise<ConversationData | null> {\n const currentId = await this.currentConversationId();\n if (!currentId) return null;\n return await this.getConversation(currentId);\n }\n\n async getLatestConversation(): Promise<ConversationData | null> {\n const convos = await this.listConversations();\n if (!convos.length) return null;\n // Sort by most recent first\n const sortedConvos = [...convos].sort((a, b) => b.timestamp - a.timestamp);\n return await this.getConversation(sortedConvos[0].id);\n }\n\n async updateConversationSummary(\n conversationId: string,\n summary: string\n ): Promise<ConversationData> {\n const conversation = await this.getConversation(conversationId);\n if (!conversation) {\n throw new Error(`Conversation with ID ${conversationId} not found`);\n }\n conversation.summary = summary;\n conversation.lastUpdated = Date.now();\n await this.storeConversationData(conversationId, conversation);\n return conversation;\n }\n\n private async pruneOldConversations(): Promise<void> {\n const conversations = await this.listConversations();\n if (conversations.length <= MAX_CONVERSATIONS) return;\n // Sort by timestamp (oldest first)\n const sortedConversations = [...conversations].sort(\n (a, b) => a.timestamp - b.timestamp\n );\n // Calculate how many need to be deleted\n const deleteCount = sortedConversations.length - MAX_CONVERSATIONS;\n // Get the conversations to delete (the oldest ones)\n const conversationsToDelete = sortedConversations.slice(0, deleteCount);\n // Delete each conversation\n for (const convo of conversationsToDelete) {\n await this.deleteConversationData(convo.id);\n }\n }\n\n protected generateSummary(content: string): string {\n let summary = content.split(\"\\n\")[0].trim();\n if (summary.length > 50) {\n summary = summary.substring(0, 47) + \"...\";\n } else if (summary.length === 0 && content.length > 0) {\n summary = content.substring(0, Math.min(50, content.length));\n if (summary.length === 50) summary = summary + \"...\";\n } else if (summary.length === 0) {\n summary = `Conversation created on ${new Date().toLocaleString()}`;\n }\n return summary;\n }\n}\n","import { createAnthropic, AnthropicProviderOptions } from \"@ai-sdk/anthropic\";\nimport {\n createGoogleGenerativeAI,\n GoogleGenerativeAIProviderOptions,\n} from \"@ai-sdk/google\";\nimport { createOpenAI, OpenAIResponsesProviderOptions } from \"@ai-sdk/openai\";\nimport { createClaudeCode } from \"ai-sdk-provider-claude-code\";\n\nexport type Provider = \"anthropic\" | \"google\" | \"openai\" | \"claude_code\";\n\nexport const PROVIDERS: Provider[] = [\n \"anthropic\",\n \"google\",\n \"openai\",\n \"claude_code\",\n];\n\nconst SOTA = {\n anthropic: \"claude-4-sonnet-20250514\",\n google: \"gemini-2.5-pro-preview-05-06\",\n openai: \"gpt-4.1\",\n claude_code: \"sonnet\",\n};\n\nexport async function getModel(\n provider: Provider,\n apiKey: string,\n cwd?: string\n) {\n switch (provider) {\n case \"anthropic\":\n const anthropic = createAnthropic({\n apiKey,\n });\n return anthropic(SOTA[provider]);\n case \"google\":\n const google = createGoogleGenerativeAI({\n apiKey,\n });\n return google(SOTA[provider]);\n case \"openai\":\n const openai = createOpenAI({\n apiKey,\n });\n return openai(SOTA[provider]);\n case \"claude_code\":\n const customProvider = createClaudeCode({\n defaultSettings: {\n // Skip permission prompts for all operations\n permissionMode: \"bypassPermissions\",\n // Set working directory for file operations\n cwd: cwd,\n },\n });\n return customProvider(SOTA[provider]);\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n}\n\nexport type ThinkingSpeed = \"thinking\" | \"fast\";\n\nexport function getProviderOptions(\n provider: Provider,\n thinkingSpeed?: ThinkingSpeed\n) {\n const fast = thinkingSpeed === \"fast\";\n const budget = fast ? 0 : 24000;\n switch (provider) {\n case \"anthropic\":\n let thinking = fast\n ? { type: \"disabled\" as const }\n : { type: \"enabled\" as const, budgetTokens: budget };\n return {\n anthropic: {\n thinking,\n } satisfies AnthropicProviderOptions,\n };\n case \"google\":\n return {\n google: {\n thinkingConfig: { thinkingBudget: budget },\n } satisfies GoogleGenerativeAIProviderOptions,\n };\n case \"openai\":\n return {\n openai: {} satisfies OpenAIResponsesProviderOptions,\n };\n case \"claude_code\":\n return;\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n}\n","import { ModelMessage, streamText, ToolSet } from \"ai\";\nimport {\n Provider,\n getModel,\n getProviderOptions,\n ThinkingSpeed,\n} from \"./provider\";\n\nexport async function callModel(\n provider: Provider,\n apiKey: string,\n messages: ModelMessage[],\n tools?: ToolSet,\n parser?: (fullResponse: string) => void,\n thinkingSpeed?: ThinkingSpeed\n): Promise<string> {\n const model = await getModel(provider, apiKey);\n const providerOptions = getProviderOptions(provider, thinkingSpeed);\n console.log(`Calling ${provider} with options:`, providerOptions);\n const result = streamText({\n model,\n tools,\n messages,\n temperature: 0,\n providerOptions: providerOptions as any,\n });\n let fullResponse = \"\";\n for await (const part of result.fullStream) {\n switch (part.type) {\n case \"error\":\n throw part.error;\n case \"text-delta\":\n if (parser) {\n parser(fullResponse);\n }\n fullResponse += part.text;\n break;\n }\n }\n return fullResponse;\n}\n","export const SYSTEM = `You are an expert dev. You are given a codebase and a task. You need to write the code for the task. You can also suggest changes to the codebase if needed.\n\nAvoid assuming that certain functions are available in the codebase. Don't use to_timestamp or to_date in SQL if you don't see examples of them being used. DO NOT make up functions like a logger or other utils. Only use utility functions that you ABSOLUTELY know exist in the code.\n\nTry to write as simple and straightforward code as possible. Make a real implementation, do NOT do a mockup or add sample data. Assume there is already mock data in the database. If you see snippets of backend code, that means you have access to the backend codebase and can add new backend endpoints or other functionality as needed.\n\nYou will be provided with code snippets to edit or create. Please preserve the EXACT file paths when you make edits. Do not truncate the file paths.\n\nYou may see multiple code snippets from the same file! In that case, please organize the code properly: if you need to add an import statement, do it in the snippet that has other imports in it! Since you won't always be able to see the whole file, try to be careful and avoid adding new code just above a snippet, since you might not know exactly what other code is there.\n\nAlways remember to add correct code that will compile!!! Make sure to properly add function signatures if needed, such as to Go interfaces or Rust traits (if you see those in the code snippets).\n\nIf asked to make further changes after already writing code, use the <content> blocks from your previous edits in order to identify code snippets to replace.\n`;\n\nexport const OUTRO = `\nPlease write all the necessary code to fully implement the feature end-to-end. Do not make mock data or example placeholders!!!\n`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAM,YAAY,CAAC;AACnB,SAAS,IAAI,GAAG,IAAI,KAAK,EAAE,GAAG;AAC1B,YAAU,MAAM,IAAI,KAAO,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AACpD;AACO,SAAS,gBAAgB,KAAK,SAAS,GAAG;AAC7C,UAAQ,UAAU,IAAI,SAAS,CAAC,CAAC,IAC7B,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,GAAG,YAAY;AACjD;;;AC1BA,oBAA+B;AAC/B,IAAM,YAAY,IAAI,WAAW,GAAG;AACpC,IAAI,UAAU,UAAU;AACT,SAAR,MAAuB;AAC1B,MAAI,UAAU,UAAU,SAAS,IAAI;AACjC,sCAAe,SAAS;AACxB,cAAU;AAAA,EACd;AACA,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,MACjB,KAAK;AACH,cAAM,KAAK;AAAA,MACb,KAAK;AACH,YAAI,QAAQ;AACV,iBAAO,YAAY;AAAA,QACrB;AACA,wBAAgB,KAAK;AACrB;AAAA,IACJ;AAAA,EACF;AACA,SAAO;AACT;;;ACxCO,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAef,IAAM,QAAQ;AAAA;AAAA;","names":["import_crypto"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ModelMessage, ToolSet } from 'ai';
|
|
2
|
+
export { ModelMessage, Tool, ToolSet } from 'ai';
|
|
3
|
+
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
4
|
+
|
|
5
|
+
interface Conversation {
|
|
6
|
+
id: string;
|
|
7
|
+
summary: string;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
}
|
|
10
|
+
interface ConversationData {
|
|
11
|
+
id: string;
|
|
12
|
+
summary: string;
|
|
13
|
+
messages: ModelMessage[];
|
|
14
|
+
lastUpdated: number;
|
|
15
|
+
}
|
|
16
|
+
declare const MAX_CONVERSATIONS = 100;
|
|
17
|
+
declare abstract class ConversationStorage {
|
|
18
|
+
abstract currentConversationId(): Promise<string>;
|
|
19
|
+
abstract selectConversation(conversationId: string): Promise<void>;
|
|
20
|
+
abstract listConversations(): Promise<Conversation[]>;
|
|
21
|
+
abstract getConversation(conversationId: string): Promise<ConversationData | null>;
|
|
22
|
+
abstract storeConversationData(conversationId: string, data: ConversationData): Promise<void>;
|
|
23
|
+
abstract deleteConversationData(conversationId: string): Promise<boolean>;
|
|
24
|
+
createConversation(messages: ModelMessage[]): Promise<ConversationData>;
|
|
25
|
+
addMessageToConversation(conversationId: string, message: ModelMessage): Promise<ConversationData>;
|
|
26
|
+
getCurrentConversation(): Promise<ConversationData | null>;
|
|
27
|
+
getLatestConversation(): Promise<ConversationData | null>;
|
|
28
|
+
updateConversationSummary(conversationId: string, summary: string): Promise<ConversationData>;
|
|
29
|
+
private pruneOldConversations;
|
|
30
|
+
protected generateSummary(content: string): string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type Provider = "anthropic" | "google" | "openai" | "claude_code";
|
|
34
|
+
declare const PROVIDERS: Provider[];
|
|
35
|
+
declare function getModel(provider: Provider, apiKey: string, cwd?: string): Promise<_ai_sdk_provider.LanguageModelV2>;
|
|
36
|
+
type ThinkingSpeed = "thinking" | "fast";
|
|
37
|
+
declare function getProviderOptions(provider: Provider, thinkingSpeed?: ThinkingSpeed): {
|
|
38
|
+
anthropic: z.infer<z.ZodObject<{
|
|
39
|
+
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
thinking: z.ZodOptional<z.ZodObject<{
|
|
41
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>;
|
|
42
|
+
budgetTokens: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
}, z.core.$strip>>;
|
|
44
|
+
disableParallelToolUse: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
google?: undefined;
|
|
47
|
+
openai?: undefined;
|
|
48
|
+
} | {
|
|
49
|
+
google: z.infer<z.ZodObject<{
|
|
50
|
+
responseModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
51
|
+
TEXT: "TEXT";
|
|
52
|
+
IMAGE: "IMAGE";
|
|
53
|
+
}>>>;
|
|
54
|
+
thinkingConfig: z.ZodOptional<z.ZodObject<{
|
|
55
|
+
thinkingBudget: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
includeThoughts: z.ZodOptional<z.ZodBoolean>;
|
|
57
|
+
}, z.core.$strip>>;
|
|
58
|
+
cachedContent: z.ZodOptional<z.ZodString>;
|
|
59
|
+
structuredOutputs: z.ZodOptional<z.ZodBoolean>;
|
|
60
|
+
safetySettings: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
61
|
+
category: z.ZodEnum<{
|
|
62
|
+
HARM_CATEGORY_UNSPECIFIED: "HARM_CATEGORY_UNSPECIFIED";
|
|
63
|
+
HARM_CATEGORY_HATE_SPEECH: "HARM_CATEGORY_HATE_SPEECH";
|
|
64
|
+
HARM_CATEGORY_DANGEROUS_CONTENT: "HARM_CATEGORY_DANGEROUS_CONTENT";
|
|
65
|
+
HARM_CATEGORY_HARASSMENT: "HARM_CATEGORY_HARASSMENT";
|
|
66
|
+
HARM_CATEGORY_SEXUALLY_EXPLICIT: "HARM_CATEGORY_SEXUALLY_EXPLICIT";
|
|
67
|
+
HARM_CATEGORY_CIVIC_INTEGRITY: "HARM_CATEGORY_CIVIC_INTEGRITY";
|
|
68
|
+
}>;
|
|
69
|
+
threshold: z.ZodEnum<{
|
|
70
|
+
HARM_BLOCK_THRESHOLD_UNSPECIFIED: "HARM_BLOCK_THRESHOLD_UNSPECIFIED";
|
|
71
|
+
BLOCK_LOW_AND_ABOVE: "BLOCK_LOW_AND_ABOVE";
|
|
72
|
+
BLOCK_MEDIUM_AND_ABOVE: "BLOCK_MEDIUM_AND_ABOVE";
|
|
73
|
+
BLOCK_ONLY_HIGH: "BLOCK_ONLY_HIGH";
|
|
74
|
+
BLOCK_NONE: "BLOCK_NONE";
|
|
75
|
+
OFF: "OFF";
|
|
76
|
+
}>;
|
|
77
|
+
}, z.core.$strip>>>;
|
|
78
|
+
threshold: z.ZodOptional<z.ZodEnum<{
|
|
79
|
+
HARM_BLOCK_THRESHOLD_UNSPECIFIED: "HARM_BLOCK_THRESHOLD_UNSPECIFIED";
|
|
80
|
+
BLOCK_LOW_AND_ABOVE: "BLOCK_LOW_AND_ABOVE";
|
|
81
|
+
BLOCK_MEDIUM_AND_ABOVE: "BLOCK_MEDIUM_AND_ABOVE";
|
|
82
|
+
BLOCK_ONLY_HIGH: "BLOCK_ONLY_HIGH";
|
|
83
|
+
BLOCK_NONE: "BLOCK_NONE";
|
|
84
|
+
OFF: "OFF";
|
|
85
|
+
}>>;
|
|
86
|
+
audioTimestamp: z.ZodOptional<z.ZodBoolean>;
|
|
87
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
anthropic?: undefined;
|
|
90
|
+
openai?: undefined;
|
|
91
|
+
} | {
|
|
92
|
+
openai: z.infer<z.ZodObject<{
|
|
93
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
|
|
94
|
+
parallelToolCalls: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
95
|
+
previousResponseId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
96
|
+
store: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
97
|
+
user: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
98
|
+
reasoningEffort: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
99
|
+
strictJsonSchema: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
100
|
+
instructions: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
101
|
+
reasoningSummary: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
102
|
+
serviceTier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
103
|
+
auto: "auto";
|
|
104
|
+
flex: "flex";
|
|
105
|
+
priority: "priority";
|
|
106
|
+
}>>>;
|
|
107
|
+
include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
108
|
+
"reasoning.encrypted_content": "reasoning.encrypted_content";
|
|
109
|
+
"file_search_call.results": "file_search_call.results";
|
|
110
|
+
"message.output_text.logprobs": "message.output_text.logprobs";
|
|
111
|
+
}>>>>;
|
|
112
|
+
textVerbosity: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
113
|
+
low: "low";
|
|
114
|
+
medium: "medium";
|
|
115
|
+
high: "high";
|
|
116
|
+
}>>>;
|
|
117
|
+
promptCacheKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
118
|
+
safetyIdentifier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
119
|
+
logprobs: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber]>>;
|
|
120
|
+
}, z.core.$strip>>;
|
|
121
|
+
anthropic?: undefined;
|
|
122
|
+
google?: undefined;
|
|
123
|
+
} | undefined;
|
|
124
|
+
|
|
125
|
+
declare function callModel(provider: Provider, apiKey: string, messages: ModelMessage[], tools?: ToolSet, parser?: (fullResponse: string) => void, thinkingSpeed?: ThinkingSpeed): Promise<string>;
|
|
126
|
+
|
|
127
|
+
declare const SYSTEM = "You are an expert dev. You are given a codebase and a task. You need to write the code for the task. You can also suggest changes to the codebase if needed.\n\nAvoid assuming that certain functions are available in the codebase. Don't use to_timestamp or to_date in SQL if you don't see examples of them being used. DO NOT make up functions like a logger or other utils. Only use utility functions that you ABSOLUTELY know exist in the code.\n\nTry to write as simple and straightforward code as possible. Make a real implementation, do NOT do a mockup or add sample data. Assume there is already mock data in the database. If you see snippets of backend code, that means you have access to the backend codebase and can add new backend endpoints or other functionality as needed.\n\nYou will be provided with code snippets to edit or create. Please preserve the EXACT file paths when you make edits. Do not truncate the file paths.\n\nYou may see multiple code snippets from the same file! In that case, please organize the code properly: if you need to add an import statement, do it in the snippet that has other imports in it! Since you won't always be able to see the whole file, try to be careful and avoid adding new code just above a snippet, since you might not know exactly what other code is there.\n\nAlways remember to add correct code that will compile!!! Make sure to properly add function signatures if needed, such as to Go interfaces or Rust traits (if you see those in the code snippets).\n\nIf asked to make further changes after already writing code, use the <content> blocks from your previous edits in order to identify code snippets to replace.\n";
|
|
128
|
+
declare const OUTRO = "\nPlease write all the necessary code to fully implement the feature end-to-end. Do not make mock data or example placeholders!!!\n";
|
|
129
|
+
|
|
130
|
+
export { type Conversation, type ConversationData, ConversationStorage, MAX_CONVERSATIONS, OUTRO, PROVIDERS, type Provider, SYSTEM, type ThinkingSpeed, callModel, getModel, getProviderOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ModelMessage, ToolSet } from 'ai';
|
|
2
|
+
export { ModelMessage, Tool, ToolSet } from 'ai';
|
|
3
|
+
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
4
4
|
|
|
5
5
|
interface Conversation {
|
|
6
6
|
id: string;
|
|
@@ -10,7 +10,7 @@ interface Conversation {
|
|
|
10
10
|
interface ConversationData {
|
|
11
11
|
id: string;
|
|
12
12
|
summary: string;
|
|
13
|
-
messages:
|
|
13
|
+
messages: ModelMessage[];
|
|
14
14
|
lastUpdated: number;
|
|
15
15
|
}
|
|
16
16
|
declare const MAX_CONVERSATIONS = 100;
|
|
@@ -21,8 +21,8 @@ declare abstract class ConversationStorage {
|
|
|
21
21
|
abstract getConversation(conversationId: string): Promise<ConversationData | null>;
|
|
22
22
|
abstract storeConversationData(conversationId: string, data: ConversationData): Promise<void>;
|
|
23
23
|
abstract deleteConversationData(conversationId: string): Promise<boolean>;
|
|
24
|
-
createConversation(messages:
|
|
25
|
-
addMessageToConversation(conversationId: string, message:
|
|
24
|
+
createConversation(messages: ModelMessage[]): Promise<ConversationData>;
|
|
25
|
+
addMessageToConversation(conversationId: string, message: ModelMessage): Promise<ConversationData>;
|
|
26
26
|
getCurrentConversation(): Promise<ConversationData | null>;
|
|
27
27
|
getLatestConversation(): Promise<ConversationData | null>;
|
|
28
28
|
updateConversationSummary(conversationId: string, summary: string): Promise<ConversationData>;
|
|
@@ -30,37 +30,99 @@ declare abstract class ConversationStorage {
|
|
|
30
30
|
protected generateSummary(content: string): string;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
type Provider = "anthropic" | "google" | "openai";
|
|
33
|
+
type Provider = "anthropic" | "google" | "openai" | "claude_code";
|
|
34
34
|
declare const PROVIDERS: Provider[];
|
|
35
|
-
declare function getModel(provider: Provider, apiKey: string): Promise<
|
|
35
|
+
declare function getModel(provider: Provider, apiKey: string, cwd?: string): Promise<_ai_sdk_provider.LanguageModelV2>;
|
|
36
36
|
type ThinkingSpeed = "thinking" | "fast";
|
|
37
37
|
declare function getProviderOptions(provider: Provider, thinkingSpeed?: ThinkingSpeed): {
|
|
38
|
-
anthropic: {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
38
|
+
anthropic: z.infer<z.ZodObject<{
|
|
39
|
+
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
thinking: z.ZodOptional<z.ZodObject<{
|
|
41
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>;
|
|
42
|
+
budgetTokens: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
}, z.core.$strip>>;
|
|
44
|
+
disableParallelToolUse: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
+
}, z.core.$strip>>;
|
|
47
46
|
google?: undefined;
|
|
48
47
|
openai?: undefined;
|
|
49
48
|
} | {
|
|
50
|
-
google: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
google: z.infer<z.ZodObject<{
|
|
50
|
+
responseModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
51
|
+
TEXT: "TEXT";
|
|
52
|
+
IMAGE: "IMAGE";
|
|
53
|
+
}>>>;
|
|
54
|
+
thinkingConfig: z.ZodOptional<z.ZodObject<{
|
|
55
|
+
thinkingBudget: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
includeThoughts: z.ZodOptional<z.ZodBoolean>;
|
|
57
|
+
}, z.core.$strip>>;
|
|
58
|
+
cachedContent: z.ZodOptional<z.ZodString>;
|
|
59
|
+
structuredOutputs: z.ZodOptional<z.ZodBoolean>;
|
|
60
|
+
safetySettings: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
61
|
+
category: z.ZodEnum<{
|
|
62
|
+
HARM_CATEGORY_UNSPECIFIED: "HARM_CATEGORY_UNSPECIFIED";
|
|
63
|
+
HARM_CATEGORY_HATE_SPEECH: "HARM_CATEGORY_HATE_SPEECH";
|
|
64
|
+
HARM_CATEGORY_DANGEROUS_CONTENT: "HARM_CATEGORY_DANGEROUS_CONTENT";
|
|
65
|
+
HARM_CATEGORY_HARASSMENT: "HARM_CATEGORY_HARASSMENT";
|
|
66
|
+
HARM_CATEGORY_SEXUALLY_EXPLICIT: "HARM_CATEGORY_SEXUALLY_EXPLICIT";
|
|
67
|
+
HARM_CATEGORY_CIVIC_INTEGRITY: "HARM_CATEGORY_CIVIC_INTEGRITY";
|
|
68
|
+
}>;
|
|
69
|
+
threshold: z.ZodEnum<{
|
|
70
|
+
HARM_BLOCK_THRESHOLD_UNSPECIFIED: "HARM_BLOCK_THRESHOLD_UNSPECIFIED";
|
|
71
|
+
BLOCK_LOW_AND_ABOVE: "BLOCK_LOW_AND_ABOVE";
|
|
72
|
+
BLOCK_MEDIUM_AND_ABOVE: "BLOCK_MEDIUM_AND_ABOVE";
|
|
73
|
+
BLOCK_ONLY_HIGH: "BLOCK_ONLY_HIGH";
|
|
74
|
+
BLOCK_NONE: "BLOCK_NONE";
|
|
75
|
+
OFF: "OFF";
|
|
76
|
+
}>;
|
|
77
|
+
}, z.core.$strip>>>;
|
|
78
|
+
threshold: z.ZodOptional<z.ZodEnum<{
|
|
79
|
+
HARM_BLOCK_THRESHOLD_UNSPECIFIED: "HARM_BLOCK_THRESHOLD_UNSPECIFIED";
|
|
80
|
+
BLOCK_LOW_AND_ABOVE: "BLOCK_LOW_AND_ABOVE";
|
|
81
|
+
BLOCK_MEDIUM_AND_ABOVE: "BLOCK_MEDIUM_AND_ABOVE";
|
|
82
|
+
BLOCK_ONLY_HIGH: "BLOCK_ONLY_HIGH";
|
|
83
|
+
BLOCK_NONE: "BLOCK_NONE";
|
|
84
|
+
OFF: "OFF";
|
|
85
|
+
}>>;
|
|
86
|
+
audioTimestamp: z.ZodOptional<z.ZodBoolean>;
|
|
87
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
88
|
+
}, z.core.$strip>>;
|
|
55
89
|
anthropic?: undefined;
|
|
56
90
|
openai?: undefined;
|
|
57
91
|
} | {
|
|
58
|
-
openai: {
|
|
92
|
+
openai: z.infer<z.ZodObject<{
|
|
93
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
|
|
94
|
+
parallelToolCalls: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
95
|
+
previousResponseId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
96
|
+
store: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
97
|
+
user: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
98
|
+
reasoningEffort: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
99
|
+
strictJsonSchema: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
100
|
+
instructions: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
101
|
+
reasoningSummary: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
102
|
+
serviceTier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
103
|
+
auto: "auto";
|
|
104
|
+
flex: "flex";
|
|
105
|
+
priority: "priority";
|
|
106
|
+
}>>>;
|
|
107
|
+
include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
108
|
+
"reasoning.encrypted_content": "reasoning.encrypted_content";
|
|
109
|
+
"file_search_call.results": "file_search_call.results";
|
|
110
|
+
"message.output_text.logprobs": "message.output_text.logprobs";
|
|
111
|
+
}>>>>;
|
|
112
|
+
textVerbosity: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
113
|
+
low: "low";
|
|
114
|
+
medium: "medium";
|
|
115
|
+
high: "high";
|
|
116
|
+
}>>>;
|
|
117
|
+
promptCacheKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
118
|
+
safetyIdentifier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
119
|
+
logprobs: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber]>>;
|
|
120
|
+
}, z.core.$strip>>;
|
|
59
121
|
anthropic?: undefined;
|
|
60
122
|
google?: undefined;
|
|
61
|
-
};
|
|
123
|
+
} | undefined;
|
|
62
124
|
|
|
63
|
-
declare function callModel(provider: Provider, apiKey: string, messages:
|
|
125
|
+
declare function callModel(provider: Provider, apiKey: string, messages: ModelMessage[], tools?: ToolSet, parser?: (fullResponse: string) => void, thinkingSpeed?: ThinkingSpeed): Promise<string>;
|
|
64
126
|
|
|
65
127
|
declare const SYSTEM = "You are an expert dev. You are given a codebase and a task. You need to write the code for the task. You can also suggest changes to the codebase if needed.\n\nAvoid assuming that certain functions are available in the codebase. Don't use to_timestamp or to_date in SQL if you don't see examples of them being used. DO NOT make up functions like a logger or other utils. Only use utility functions that you ABSOLUTELY know exist in the code.\n\nTry to write as simple and straightforward code as possible. Make a real implementation, do NOT do a mockup or add sample data. Assume there is already mock data in the database. If you see snippets of backend code, that means you have access to the backend codebase and can add new backend endpoints or other functionality as needed.\n\nYou will be provided with code snippets to edit or create. Please preserve the EXACT file paths when you make edits. Do not truncate the file paths.\n\nYou may see multiple code snippets from the same file! In that case, please organize the code properly: if you need to add an import statement, do it in the snippet that has other imports in it! Since you won't always be able to see the whole file, try to be careful and avoid adding new code just above a snippet, since you might not know exactly what other code is there.\n\nAlways remember to add correct code that will compile!!! Make sure to properly add function signatures if needed, such as to Go interfaces or Rust traits (if you see those in the code snippets).\n\nIf asked to make further changes after already writing code, use the <content> blocks from your previous edits in order to identify code snippets to replace.\n";
|
|
66
128
|
declare const OUTRO = "\nPlease write all the necessary code to fully implement the feature end-to-end. Do not make mock data or example placeholders!!!\n";
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
ConversationStorage: () => ConversationStorage,
|
|
24
|
-
MAX_CONVERSATIONS: () => MAX_CONVERSATIONS,
|
|
25
|
-
OUTRO: () => OUTRO,
|
|
26
|
-
PROVIDERS: () => PROVIDERS,
|
|
27
|
-
SYSTEM: () => SYSTEM,
|
|
28
|
-
callModel: () => callModel,
|
|
29
|
-
getModel: () => getModel,
|
|
30
|
-
getProviderOptions: () => getProviderOptions
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(index_exports);
|
|
33
|
-
|
|
34
1
|
// ../node_modules/uuid/dist/esm/stringify.js
|
|
35
2
|
var byteToHex = [];
|
|
36
3
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -41,20 +8,20 @@ function unsafeStringify(arr, offset = 0) {
|
|
|
41
8
|
}
|
|
42
9
|
|
|
43
10
|
// ../node_modules/uuid/dist/esm/rng.js
|
|
44
|
-
|
|
11
|
+
import { randomFillSync } from "crypto";
|
|
45
12
|
var rnds8Pool = new Uint8Array(256);
|
|
46
13
|
var poolPtr = rnds8Pool.length;
|
|
47
14
|
function rng() {
|
|
48
15
|
if (poolPtr > rnds8Pool.length - 16) {
|
|
49
|
-
|
|
16
|
+
randomFillSync(rnds8Pool);
|
|
50
17
|
poolPtr = 0;
|
|
51
18
|
}
|
|
52
19
|
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
53
20
|
}
|
|
54
21
|
|
|
55
22
|
// ../node_modules/uuid/dist/esm/native.js
|
|
56
|
-
|
|
57
|
-
var native_default = { randomUUID
|
|
23
|
+
import { randomUUID } from "crypto";
|
|
24
|
+
var native_default = { randomUUID };
|
|
58
25
|
|
|
59
26
|
// ../node_modules/uuid/dist/esm/v4.js
|
|
60
27
|
function v4(options, buf, offset) {
|
|
@@ -159,33 +126,51 @@ var ConversationStorage = class {
|
|
|
159
126
|
};
|
|
160
127
|
|
|
161
128
|
// src/provider.ts
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
129
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
130
|
+
import {
|
|
131
|
+
createGoogleGenerativeAI
|
|
132
|
+
} from "@ai-sdk/google";
|
|
133
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
134
|
+
import { createClaudeCode } from "ai-sdk-provider-claude-code";
|
|
135
|
+
var PROVIDERS = [
|
|
136
|
+
"anthropic",
|
|
137
|
+
"google",
|
|
138
|
+
"openai",
|
|
139
|
+
"claude_code"
|
|
140
|
+
];
|
|
166
141
|
var SOTA = {
|
|
167
|
-
anthropic: "claude-
|
|
142
|
+
anthropic: "claude-4-sonnet-20250514",
|
|
168
143
|
google: "gemini-2.5-pro-preview-05-06",
|
|
169
|
-
openai: "gpt-4.1"
|
|
144
|
+
openai: "gpt-4.1",
|
|
145
|
+
claude_code: "sonnet"
|
|
170
146
|
};
|
|
171
|
-
async function getModel(provider, apiKey) {
|
|
147
|
+
async function getModel(provider, apiKey, cwd) {
|
|
172
148
|
switch (provider) {
|
|
173
149
|
case "anthropic":
|
|
174
|
-
const anthropic =
|
|
150
|
+
const anthropic = createAnthropic({
|
|
175
151
|
apiKey
|
|
176
152
|
});
|
|
177
153
|
return anthropic(SOTA[provider]);
|
|
178
154
|
case "google":
|
|
179
|
-
const google =
|
|
155
|
+
const google = createGoogleGenerativeAI({
|
|
180
156
|
apiKey
|
|
181
157
|
});
|
|
182
158
|
return google(SOTA[provider]);
|
|
183
159
|
case "openai":
|
|
184
|
-
const openai =
|
|
185
|
-
apiKey
|
|
186
|
-
compatibility: "strict"
|
|
160
|
+
const openai = createOpenAI({
|
|
161
|
+
apiKey
|
|
187
162
|
});
|
|
188
163
|
return openai(SOTA[provider]);
|
|
164
|
+
case "claude_code":
|
|
165
|
+
const customProvider = createClaudeCode({
|
|
166
|
+
defaultSettings: {
|
|
167
|
+
// Skip permission prompts for all operations
|
|
168
|
+
permissionMode: "bypassPermissions",
|
|
169
|
+
// Set working directory for file operations
|
|
170
|
+
cwd
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return customProvider(SOTA[provider]);
|
|
189
174
|
default:
|
|
190
175
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
191
176
|
}
|
|
@@ -211,18 +196,20 @@ function getProviderOptions(provider, thinkingSpeed) {
|
|
|
211
196
|
return {
|
|
212
197
|
openai: {}
|
|
213
198
|
};
|
|
199
|
+
case "claude_code":
|
|
200
|
+
return;
|
|
214
201
|
default:
|
|
215
202
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
216
203
|
}
|
|
217
204
|
}
|
|
218
205
|
|
|
219
206
|
// src/stream.ts
|
|
220
|
-
|
|
207
|
+
import { streamText } from "ai";
|
|
221
208
|
async function callModel(provider, apiKey, messages, tools, parser, thinkingSpeed) {
|
|
222
209
|
const model = await getModel(provider, apiKey);
|
|
223
210
|
const providerOptions = getProviderOptions(provider, thinkingSpeed);
|
|
224
211
|
console.log(`Calling ${provider} with options:`, providerOptions);
|
|
225
|
-
const result =
|
|
212
|
+
const result = streamText({
|
|
226
213
|
model,
|
|
227
214
|
tools,
|
|
228
215
|
messages,
|
|
@@ -238,7 +225,7 @@ async function callModel(provider, apiKey, messages, tools, parser, thinkingSpee
|
|
|
238
225
|
if (parser) {
|
|
239
226
|
parser(fullResponse);
|
|
240
227
|
}
|
|
241
|
-
fullResponse += part.
|
|
228
|
+
fullResponse += part.text;
|
|
242
229
|
break;
|
|
243
230
|
}
|
|
244
231
|
}
|
|
@@ -263,8 +250,7 @@ If asked to make further changes after already writing code, use the <content> b
|
|
|
263
250
|
var OUTRO = `
|
|
264
251
|
Please write all the necessary code to fully implement the feature end-to-end. Do not make mock data or example placeholders!!!
|
|
265
252
|
`;
|
|
266
|
-
|
|
267
|
-
0 && (module.exports = {
|
|
253
|
+
export {
|
|
268
254
|
ConversationStorage,
|
|
269
255
|
MAX_CONVERSATIONS,
|
|
270
256
|
OUTRO,
|
|
@@ -273,5 +259,5 @@ Please write all the necessary code to fully implement the feature end-to-end. D
|
|
|
273
259
|
callModel,
|
|
274
260
|
getModel,
|
|
275
261
|
getProviderOptions
|
|
276
|
-
}
|
|
262
|
+
};
|
|
277
263
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../../node_modules/uuid/dist/esm/stringify.js","../../node_modules/uuid/dist/esm/rng.js","../../node_modules/uuid/dist/esm/native.js","../../node_modules/uuid/dist/esm/v4.js","../src/store.ts","../src/provider.ts","../src/stream.ts","../src/prompt.ts"],"sourcesContent":["export * from \"./store\";\nexport * from \"./provider\";\nexport * from \"./stream\";\nexport * from \"./prompt\";\n\nexport type { CoreMessage } from \"ai\";\nexport type { Tool, ToolSet } from \"ai\";\n","import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n","import { randomFillSync } from 'crypto';\nconst rnds8Pool = new Uint8Array(256);\nlet poolPtr = rnds8Pool.length;\nexport default function rng() {\n if (poolPtr > rnds8Pool.length - 16) {\n randomFillSync(rnds8Pool);\n poolPtr = 0;\n }\n return rnds8Pool.slice(poolPtr, (poolPtr += 16));\n}\n","import { randomUUID } from 'crypto';\nexport default { randomUUID };\n","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n options = options || {};\n const rnds = options.random ?? options.rng?.() ?? rng();\n if (rnds.length < 16) {\n throw new Error('Random bytes length must be >= 16');\n }\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n if (offset < 0 || offset + 16 > buf.length) {\n throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);\n }\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;\n","import { CoreMessage } from \"ai\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nexport interface Conversation {\n id: string;\n summary: string;\n timestamp: number;\n}\n\nexport interface ConversationData {\n id: string;\n summary: string;\n messages: CoreMessage[];\n lastUpdated: number;\n}\n\nexport const MAX_CONVERSATIONS = 100;\n\nexport abstract class ConversationStorage {\n // Abstract methods to be implemented by platform-specific storage\n abstract currentConversationId(): Promise<string>;\n abstract selectConversation(conversationId: string): Promise<void>;\n abstract listConversations(): Promise<Conversation[]>;\n abstract getConversation(\n conversationId: string\n ): Promise<ConversationData | null>;\n abstract storeConversationData(\n conversationId: string,\n data: ConversationData\n ): Promise<void>;\n abstract deleteConversationData(conversationId: string): Promise<boolean>;\n\n // Shared functionality that works across platforms\n async createConversation(messages: CoreMessage[]): Promise<ConversationData> {\n const id = uuidv4();\n const initialMessage = messages.find((msg) => msg.role === \"user\");\n const summary = initialMessage\n ? this.generateSummary(initialMessage.content as string)\n : `New conversation ${new Date().toLocaleString()}`;\n const conversation: ConversationData = {\n id,\n summary,\n messages,\n lastUpdated: Date.now(),\n };\n await this.storeConversationData(id, conversation);\n await this.selectConversation(id);\n await this.pruneOldConversations();\n return conversation;\n }\n\n async addMessageToConversation(\n conversationId: string,\n message: CoreMessage\n ): Promise<ConversationData> {\n const conversation = await this.getConversation(conversationId);\n if (!conversation) {\n throw new Error(`Conversation with ID ${conversationId} not found`);\n }\n conversation.messages.push({ ...message });\n conversation.lastUpdated = Date.now();\n await this.storeConversationData(conversationId, conversation);\n return conversation;\n }\n\n async getCurrentConversation(): Promise<ConversationData | null> {\n const currentId = await this.currentConversationId();\n if (!currentId) return null;\n return await this.getConversation(currentId);\n }\n\n async getLatestConversation(): Promise<ConversationData | null> {\n const convos = await this.listConversations();\n if (!convos.length) return null;\n // Sort by most recent first\n const sortedConvos = [...convos].sort((a, b) => b.timestamp - a.timestamp);\n return await this.getConversation(sortedConvos[0].id);\n }\n\n async updateConversationSummary(\n conversationId: string,\n summary: string\n ): Promise<ConversationData> {\n const conversation = await this.getConversation(conversationId);\n if (!conversation) {\n throw new Error(`Conversation with ID ${conversationId} not found`);\n }\n conversation.summary = summary;\n conversation.lastUpdated = Date.now();\n await this.storeConversationData(conversationId, conversation);\n return conversation;\n }\n\n private async pruneOldConversations(): Promise<void> {\n const conversations = await this.listConversations();\n if (conversations.length <= MAX_CONVERSATIONS) return;\n // Sort by timestamp (oldest first)\n const sortedConversations = [...conversations].sort(\n (a, b) => a.timestamp - b.timestamp\n );\n // Calculate how many need to be deleted\n const deleteCount = sortedConversations.length - MAX_CONVERSATIONS;\n // Get the conversations to delete (the oldest ones)\n const conversationsToDelete = sortedConversations.slice(0, deleteCount);\n // Delete each conversation\n for (const convo of conversationsToDelete) {\n await this.deleteConversationData(convo.id);\n }\n }\n\n protected generateSummary(content: string): string {\n let summary = content.split(\"\\n\")[0].trim();\n if (summary.length > 50) {\n summary = summary.substring(0, 47) + \"...\";\n } else if (summary.length === 0 && content.length > 0) {\n summary = content.substring(0, Math.min(50, content.length));\n if (summary.length === 50) summary = summary + \"...\";\n } else if (summary.length === 0) {\n summary = `Conversation created on ${new Date().toLocaleString()}`;\n }\n return summary;\n }\n}\n","import { createAnthropic, AnthropicProviderOptions } from \"@ai-sdk/anthropic\";\nimport {\n createGoogleGenerativeAI,\n GoogleGenerativeAIProviderOptions,\n} from \"@ai-sdk/google\";\nimport { createOpenAI, OpenAIResponsesProviderOptions } from \"@ai-sdk/openai\";\n\nexport type Provider = \"anthropic\" | \"google\" | \"openai\";\n\nexport const PROVIDERS: Provider[] = [\"anthropic\", \"google\", \"openai\"];\n\nconst SOTA = {\n anthropic: \"claude-3-7-sonnet-20250219\",\n google: \"gemini-2.5-pro-preview-05-06\",\n openai: \"gpt-4.1\",\n};\n\nexport async function getModel(provider: Provider, apiKey: string) {\n switch (provider) {\n case \"anthropic\":\n const anthropic = createAnthropic({\n apiKey,\n });\n return anthropic(SOTA[provider]);\n case \"google\":\n const google = createGoogleGenerativeAI({\n apiKey,\n });\n return google(SOTA[provider]);\n case \"openai\":\n const openai = createOpenAI({\n apiKey,\n compatibility: \"strict\",\n });\n return openai(SOTA[provider]);\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n}\n\nexport type ThinkingSpeed = \"thinking\" | \"fast\";\n\nexport function getProviderOptions(\n provider: Provider,\n thinkingSpeed?: ThinkingSpeed\n) {\n const fast = thinkingSpeed === \"fast\";\n const budget = fast ? 0 : 24000;\n switch (provider) {\n case \"anthropic\":\n let thinking = fast\n ? { type: \"disabled\" as const }\n : { type: \"enabled\" as const, budgetTokens: budget };\n return {\n anthropic: {\n thinking,\n } satisfies AnthropicProviderOptions,\n };\n case \"google\":\n return {\n google: {\n thinkingConfig: { thinkingBudget: budget },\n } satisfies GoogleGenerativeAIProviderOptions,\n };\n case \"openai\":\n return {\n openai: {} satisfies OpenAIResponsesProviderOptions,\n };\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n}\n","import { CoreMessage, streamText, ToolSet } from \"ai\";\nimport {\n Provider,\n getModel,\n getProviderOptions,\n ThinkingSpeed,\n} from \"./provider\";\n\nexport async function callModel(\n provider: Provider,\n apiKey: string,\n messages: CoreMessage[],\n tools?: ToolSet,\n parser?: (fullResponse: string) => void,\n thinkingSpeed?: ThinkingSpeed\n): Promise<string> {\n const model = await getModel(provider, apiKey);\n const providerOptions = getProviderOptions(provider, thinkingSpeed);\n console.log(`Calling ${provider} with options:`, providerOptions);\n const result = streamText({\n model,\n tools,\n messages,\n temperature: 0,\n providerOptions: providerOptions as any,\n });\n let fullResponse = \"\";\n for await (const part of result.fullStream) {\n switch (part.type) {\n case \"error\":\n throw part.error;\n case \"text-delta\":\n if (parser) {\n parser(fullResponse);\n }\n fullResponse += part.textDelta;\n break;\n }\n }\n return fullResponse;\n}\n","export const SYSTEM = `You are an expert dev. You are given a codebase and a task. You need to write the code for the task. You can also suggest changes to the codebase if needed.\n\nAvoid assuming that certain functions are available in the codebase. Don't use to_timestamp or to_date in SQL if you don't see examples of them being used. DO NOT make up functions like a logger or other utils. Only use utility functions that you ABSOLUTELY know exist in the code.\n\nTry to write as simple and straightforward code as possible. Make a real implementation, do NOT do a mockup or add sample data. Assume there is already mock data in the database. If you see snippets of backend code, that means you have access to the backend codebase and can add new backend endpoints or other functionality as needed.\n\nYou will be provided with code snippets to edit or create. Please preserve the EXACT file paths when you make edits. Do not truncate the file paths.\n\nYou may see multiple code snippets from the same file! In that case, please organize the code properly: if you need to add an import statement, do it in the snippet that has other imports in it! Since you won't always be able to see the whole file, try to be careful and avoid adding new code just above a snippet, since you might not know exactly what other code is there.\n\nAlways remember to add correct code that will compile!!! Make sure to properly add function signatures if needed, such as to Go interfaces or Rust traits (if you see those in the code snippets).\n\nIf asked to make further changes after already writing code, use the <content> blocks from your previous edits in order to identify code snippets to replace.\n`;\n\nexport const OUTRO = `\nPlease write all the necessary code to fully implement the feature end-to-end. Do not make mock data or example placeholders!!!\n`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAM,YAAY,CAAC;AACnB,SAAS,IAAI,GAAG,IAAI,KAAK,EAAE,GAAG;AAC1B,YAAU,MAAM,IAAI,KAAO,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AACpD;AACO,SAAS,gBAAgB,KAAK,SAAS,GAAG;AAC7C,UAAQ,UAAU,IAAI,SAAS,CAAC,CAAC,IAC7B,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,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,UAAU,MAAM;AAC7C,QAAM,kBAAkB,mBAAmB,UAAU,aAAa;AAClE,UAAQ,IAAI,WAAW,QAAQ,kBAAkB,eAAe;AAChE,QAAM,aAAS,sBAAW;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb;AAAA,EACF,CAAC;AACD,MAAI,eAAe;AACnB,mBAAiB,QAAQ,OAAO,YAAY;AAC1C,YAAQ,KAAK,MAAM;AAAA,MACjB,KAAK;AACH,cAAM,KAAK;AAAA,MACb,KAAK;AACH,YAAI,QAAQ;AACV,iBAAO,YAAY;AAAA,QACrB;AACA,wBAAgB,KAAK;AACrB;AAAA,IACJ;AAAA,EACF;AACA,SAAO;AACT;;;ACxCO,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAef,IAAM,QAAQ;AAAA;AAAA;","names":["import_crypto"]}
|
|
1
|
+
{"version":3,"sources":["../../node_modules/uuid/dist/esm/stringify.js","../../node_modules/uuid/dist/esm/rng.js","../../node_modules/uuid/dist/esm/native.js","../../node_modules/uuid/dist/esm/v4.js","../src/store.ts","../src/provider.ts","../src/stream.ts","../src/prompt.ts"],"sourcesContent":["import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n","import { randomFillSync } from 'crypto';\nconst rnds8Pool = new Uint8Array(256);\nlet poolPtr = rnds8Pool.length;\nexport default function rng() {\n if (poolPtr > rnds8Pool.length - 16) {\n randomFillSync(rnds8Pool);\n poolPtr = 0;\n }\n return rnds8Pool.slice(poolPtr, (poolPtr += 16));\n}\n","import { randomUUID } from 'crypto';\nexport default { randomUUID };\n","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n options = options || {};\n const rnds = options.random ?? options.rng?.() ?? rng();\n if (rnds.length < 16) {\n throw new Error('Random bytes length must be >= 16');\n }\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n if (offset < 0 || offset + 16 > buf.length) {\n throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);\n }\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;\n","import { ModelMessage } from \"ai\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nexport interface Conversation {\n id: string;\n summary: string;\n timestamp: number;\n}\n\nexport interface ConversationData {\n id: string;\n summary: string;\n messages: ModelMessage[];\n lastUpdated: number;\n}\n\nexport const MAX_CONVERSATIONS = 100;\n\nexport abstract class ConversationStorage {\n // Abstract methods to be implemented by platform-specific storage\n abstract currentConversationId(): Promise<string>;\n abstract selectConversation(conversationId: string): Promise<void>;\n abstract listConversations(): Promise<Conversation[]>;\n abstract getConversation(\n conversationId: string\n ): Promise<ConversationData | null>;\n abstract storeConversationData(\n conversationId: string,\n data: ConversationData\n ): Promise<void>;\n abstract deleteConversationData(conversationId: string): Promise<boolean>;\n\n // Shared functionality that works across platforms\n async createConversation(\n messages: ModelMessage[]\n ): Promise<ConversationData> {\n const id = uuidv4();\n const initialMessage = messages.find((msg) => msg.role === \"user\");\n const summary = initialMessage\n ? this.generateSummary(initialMessage.content as string)\n : `New conversation ${new Date().toLocaleString()}`;\n const conversation: ConversationData = {\n id,\n summary,\n messages,\n lastUpdated: Date.now(),\n };\n await this.storeConversationData(id, conversation);\n await this.selectConversation(id);\n await this.pruneOldConversations();\n return conversation;\n }\n\n async addMessageToConversation(\n conversationId: string,\n message: ModelMessage\n ): Promise<ConversationData> {\n const conversation = await this.getConversation(conversationId);\n if (!conversation) {\n throw new Error(`Conversation with ID ${conversationId} not found`);\n }\n conversation.messages.push({ ...message });\n conversation.lastUpdated = Date.now();\n await this.storeConversationData(conversationId, conversation);\n return conversation;\n }\n\n async getCurrentConversation(): Promise<ConversationData | null> {\n const currentId = await this.currentConversationId();\n if (!currentId) return null;\n return await this.getConversation(currentId);\n }\n\n async getLatestConversation(): Promise<ConversationData | null> {\n const convos = await this.listConversations();\n if (!convos.length) return null;\n // Sort by most recent first\n const sortedConvos = [...convos].sort((a, b) => b.timestamp - a.timestamp);\n return await this.getConversation(sortedConvos[0].id);\n }\n\n async updateConversationSummary(\n conversationId: string,\n summary: string\n ): Promise<ConversationData> {\n const conversation = await this.getConversation(conversationId);\n if (!conversation) {\n throw new Error(`Conversation with ID ${conversationId} not found`);\n }\n conversation.summary = summary;\n conversation.lastUpdated = Date.now();\n await this.storeConversationData(conversationId, conversation);\n return conversation;\n }\n\n private async pruneOldConversations(): Promise<void> {\n const conversations = await this.listConversations();\n if (conversations.length <= MAX_CONVERSATIONS) return;\n // Sort by timestamp (oldest first)\n const sortedConversations = [...conversations].sort(\n (a, b) => a.timestamp - b.timestamp\n );\n // Calculate how many need to be deleted\n const deleteCount = sortedConversations.length - MAX_CONVERSATIONS;\n // Get the conversations to delete (the oldest ones)\n const conversationsToDelete = sortedConversations.slice(0, deleteCount);\n // Delete each conversation\n for (const convo of conversationsToDelete) {\n await this.deleteConversationData(convo.id);\n }\n }\n\n protected generateSummary(content: string): string {\n let summary = content.split(\"\\n\")[0].trim();\n if (summary.length > 50) {\n summary = summary.substring(0, 47) + \"...\";\n } else if (summary.length === 0 && content.length > 0) {\n summary = content.substring(0, Math.min(50, content.length));\n if (summary.length === 50) summary = summary + \"...\";\n } else if (summary.length === 0) {\n summary = `Conversation created on ${new Date().toLocaleString()}`;\n }\n return summary;\n }\n}\n","import { createAnthropic, AnthropicProviderOptions } from \"@ai-sdk/anthropic\";\nimport {\n createGoogleGenerativeAI,\n GoogleGenerativeAIProviderOptions,\n} from \"@ai-sdk/google\";\nimport { createOpenAI, OpenAIResponsesProviderOptions } from \"@ai-sdk/openai\";\nimport { createClaudeCode } from \"ai-sdk-provider-claude-code\";\n\nexport type Provider = \"anthropic\" | \"google\" | \"openai\" | \"claude_code\";\n\nexport const PROVIDERS: Provider[] = [\n \"anthropic\",\n \"google\",\n \"openai\",\n \"claude_code\",\n];\n\nconst SOTA = {\n anthropic: \"claude-4-sonnet-20250514\",\n google: \"gemini-2.5-pro-preview-05-06\",\n openai: \"gpt-4.1\",\n claude_code: \"sonnet\",\n};\n\nexport async function getModel(\n provider: Provider,\n apiKey: string,\n cwd?: string\n) {\n switch (provider) {\n case \"anthropic\":\n const anthropic = createAnthropic({\n apiKey,\n });\n return anthropic(SOTA[provider]);\n case \"google\":\n const google = createGoogleGenerativeAI({\n apiKey,\n });\n return google(SOTA[provider]);\n case \"openai\":\n const openai = createOpenAI({\n apiKey,\n });\n return openai(SOTA[provider]);\n case \"claude_code\":\n const customProvider = createClaudeCode({\n defaultSettings: {\n // Skip permission prompts for all operations\n permissionMode: \"bypassPermissions\",\n // Set working directory for file operations\n cwd: cwd,\n },\n });\n return customProvider(SOTA[provider]);\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n}\n\nexport type ThinkingSpeed = \"thinking\" | \"fast\";\n\nexport function getProviderOptions(\n provider: Provider,\n thinkingSpeed?: ThinkingSpeed\n) {\n const fast = thinkingSpeed === \"fast\";\n const budget = fast ? 0 : 24000;\n switch (provider) {\n case \"anthropic\":\n let thinking = fast\n ? { type: \"disabled\" as const }\n : { type: \"enabled\" as const, budgetTokens: budget };\n return {\n anthropic: {\n thinking,\n } satisfies AnthropicProviderOptions,\n };\n case \"google\":\n return {\n google: {\n thinkingConfig: { thinkingBudget: budget },\n } satisfies GoogleGenerativeAIProviderOptions,\n };\n case \"openai\":\n return {\n openai: {} satisfies OpenAIResponsesProviderOptions,\n };\n case \"claude_code\":\n return;\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n}\n","import { ModelMessage, streamText, ToolSet } from \"ai\";\nimport {\n Provider,\n getModel,\n getProviderOptions,\n ThinkingSpeed,\n} from \"./provider\";\n\nexport async function callModel(\n provider: Provider,\n apiKey: string,\n messages: ModelMessage[],\n tools?: ToolSet,\n parser?: (fullResponse: string) => void,\n thinkingSpeed?: ThinkingSpeed\n): Promise<string> {\n const model = await getModel(provider, apiKey);\n const providerOptions = getProviderOptions(provider, thinkingSpeed);\n console.log(`Calling ${provider} with options:`, providerOptions);\n const result = streamText({\n model,\n tools,\n messages,\n temperature: 0,\n providerOptions: providerOptions as any,\n });\n let fullResponse = \"\";\n for await (const part of result.fullStream) {\n switch (part.type) {\n case \"error\":\n throw part.error;\n case \"text-delta\":\n if (parser) {\n parser(fullResponse);\n }\n fullResponse += part.text;\n break;\n }\n }\n return fullResponse;\n}\n","export const SYSTEM = `You are an expert dev. You are given a codebase and a task. You need to write the code for the task. You can also suggest changes to the codebase if needed.\n\nAvoid assuming that certain functions are available in the codebase. Don't use to_timestamp or to_date in SQL if you don't see examples of them being used. DO NOT make up functions like a logger or other utils. Only use utility functions that you ABSOLUTELY know exist in the code.\n\nTry to write as simple and straightforward code as possible. Make a real implementation, do NOT do a mockup or add sample data. Assume there is already mock data in the database. If you see snippets of backend code, that means you have access to the backend codebase and can add new backend endpoints or other functionality as needed.\n\nYou will be provided with code snippets to edit or create. Please preserve the EXACT file paths when you make edits. Do not truncate the file paths.\n\nYou may see multiple code snippets from the same file! In that case, please organize the code properly: if you need to add an import statement, do it in the snippet that has other imports in it! Since you won't always be able to see the whole file, try to be careful and avoid adding new code just above a snippet, since you might not know exactly what other code is there.\n\nAlways remember to add correct code that will compile!!! Make sure to properly add function signatures if needed, such as to Go interfaces or Rust traits (if you see those in the code snippets).\n\nIf asked to make further changes after already writing code, use the <content> blocks from your previous edits in order to identify code snippets to replace.\n`;\n\nexport const OUTRO = `\nPlease write all the necessary code to fully implement the feature end-to-end. Do not make mock data or example placeholders!!!\n`;\n"],"mappings":";AACA,IAAM,YAAY,CAAC;AACnB,SAAS,IAAI,GAAG,IAAI,KAAK,EAAE,GAAG;AAC1B,YAAU,MAAM,IAAI,KAAO,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AACpD;AACO,SAAS,gBAAgB,KAAK,SAAS,GAAG;AAC7C,UAAQ,UAAU,IAAI,SAAS,CAAC,CAAC,IAC7B,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI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MAAM,SAAS,UAAU,MAAM;AAC7C,QAAM,kBAAkB,mBAAmB,UAAU,aAAa;AAClE,UAAQ,IAAI,WAAW,QAAQ,kBAAkB,eAAe;AAChE,QAAM,SAAS,WAAW;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb;AAAA,EACF,CAAC;AACD,MAAI,eAAe;AACnB,mBAAiB,QAAQ,OAAO,YAAY;AAC1C,YAAQ,KAAK,MAAM;AAAA,MACjB,KAAK;AACH,cAAM,KAAK;AAAA,MACb,KAAK;AACH,YAAI,QAAQ;AACV,iBAAO,YAAY;AAAA,QACrB;AACA,wBAAgB,KAAK;AACrB;AAAA,IACJ;AAAA,EACF;AACA,SAAO;AACT;;;ACxCO,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAef,IAAM,QAAQ;AAAA;AAAA;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aieo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"module": "./dist/index.mjs",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
@@ -21,12 +22,14 @@
|
|
|
21
22
|
"license": "ISC",
|
|
22
23
|
"description": "typescript ai utils",
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@ai-sdk/anthropic": "^
|
|
25
|
-
"@ai-sdk/google": "^
|
|
26
|
-
"@ai-sdk/openai": "^
|
|
27
|
-
"ai": "^
|
|
25
|
+
"@ai-sdk/anthropic": "^2.0.6",
|
|
26
|
+
"@ai-sdk/google": "^2.0.8",
|
|
27
|
+
"@ai-sdk/openai": "^2.0.19",
|
|
28
|
+
"ai": "^5.0.22",
|
|
29
|
+
"ai-sdk-provider-claude-code": "^1.1.0"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
32
|
+
"@types/node": "^24.3.0",
|
|
30
33
|
"tsup": "^8.4.0"
|
|
31
34
|
}
|
|
32
35
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import * as ai from 'ai';
|
|
2
|
-
import { CoreMessage, ToolSet } from 'ai';
|
|
3
|
-
export { CoreMessage, Tool, ToolSet } from 'ai';
|
|
4
|
-
|
|
5
|
-
interface Conversation {
|
|
6
|
-
id: string;
|
|
7
|
-
summary: string;
|
|
8
|
-
timestamp: number;
|
|
9
|
-
}
|
|
10
|
-
interface ConversationData {
|
|
11
|
-
id: string;
|
|
12
|
-
summary: string;
|
|
13
|
-
messages: CoreMessage[];
|
|
14
|
-
lastUpdated: number;
|
|
15
|
-
}
|
|
16
|
-
declare const MAX_CONVERSATIONS = 100;
|
|
17
|
-
declare abstract class ConversationStorage {
|
|
18
|
-
abstract currentConversationId(): Promise<string>;
|
|
19
|
-
abstract selectConversation(conversationId: string): Promise<void>;
|
|
20
|
-
abstract listConversations(): Promise<Conversation[]>;
|
|
21
|
-
abstract getConversation(conversationId: string): Promise<ConversationData | null>;
|
|
22
|
-
abstract storeConversationData(conversationId: string, data: ConversationData): Promise<void>;
|
|
23
|
-
abstract deleteConversationData(conversationId: string): Promise<boolean>;
|
|
24
|
-
createConversation(messages: CoreMessage[]): Promise<ConversationData>;
|
|
25
|
-
addMessageToConversation(conversationId: string, message: CoreMessage): Promise<ConversationData>;
|
|
26
|
-
getCurrentConversation(): Promise<ConversationData | null>;
|
|
27
|
-
getLatestConversation(): Promise<ConversationData | null>;
|
|
28
|
-
updateConversationSummary(conversationId: string, summary: string): Promise<ConversationData>;
|
|
29
|
-
private pruneOldConversations;
|
|
30
|
-
protected generateSummary(content: string): string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type Provider = "anthropic" | "google" | "openai";
|
|
34
|
-
declare const PROVIDERS: Provider[];
|
|
35
|
-
declare function getModel(provider: Provider, apiKey: string): Promise<ai.LanguageModelV1>;
|
|
36
|
-
type ThinkingSpeed = "thinking" | "fast";
|
|
37
|
-
declare function getProviderOptions(provider: Provider, thinkingSpeed?: ThinkingSpeed): {
|
|
38
|
-
anthropic: {
|
|
39
|
-
thinking: {
|
|
40
|
-
type: "disabled";
|
|
41
|
-
budgetTokens?: undefined;
|
|
42
|
-
} | {
|
|
43
|
-
type: "enabled";
|
|
44
|
-
budgetTokens: number;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
google?: undefined;
|
|
48
|
-
openai?: undefined;
|
|
49
|
-
} | {
|
|
50
|
-
google: {
|
|
51
|
-
thinkingConfig: {
|
|
52
|
-
thinkingBudget: number;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
anthropic?: undefined;
|
|
56
|
-
openai?: undefined;
|
|
57
|
-
} | {
|
|
58
|
-
openai: {};
|
|
59
|
-
anthropic?: undefined;
|
|
60
|
-
google?: undefined;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
declare function callModel(provider: Provider, apiKey: string, messages: CoreMessage[], tools?: ToolSet, parser?: (fullResponse: string) => void, thinkingSpeed?: ThinkingSpeed): Promise<string>;
|
|
64
|
-
|
|
65
|
-
declare const SYSTEM = "You are an expert dev. You are given a codebase and a task. You need to write the code for the task. You can also suggest changes to the codebase if needed.\n\nAvoid assuming that certain functions are available in the codebase. Don't use to_timestamp or to_date in SQL if you don't see examples of them being used. DO NOT make up functions like a logger or other utils. Only use utility functions that you ABSOLUTELY know exist in the code.\n\nTry to write as simple and straightforward code as possible. Make a real implementation, do NOT do a mockup or add sample data. Assume there is already mock data in the database. If you see snippets of backend code, that means you have access to the backend codebase and can add new backend endpoints or other functionality as needed.\n\nYou will be provided with code snippets to edit or create. Please preserve the EXACT file paths when you make edits. Do not truncate the file paths.\n\nYou may see multiple code snippets from the same file! In that case, please organize the code properly: if you need to add an import statement, do it in the snippet that has other imports in it! Since you won't always be able to see the whole file, try to be careful and avoid adding new code just above a snippet, since you might not know exactly what other code is there.\n\nAlways remember to add correct code that will compile!!! Make sure to properly add function signatures if needed, such as to Go interfaces or Rust traits (if you see those in the code snippets).\n\nIf asked to make further changes after already writing code, use the <content> blocks from your previous edits in order to identify code snippets to replace.\n";
|
|
66
|
-
declare const OUTRO = "\nPlease write all the necessary code to fully implement the feature end-to-end. Do not make mock data or example placeholders!!!\n";
|
|
67
|
-
|
|
68
|
-
export { type Conversation, type ConversationData, ConversationStorage, MAX_CONVERSATIONS, OUTRO, PROVIDERS, type Provider, SYSTEM, type ThinkingSpeed, callModel, getModel, getProviderOptions };
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../node_modules/uuid/dist/esm/stringify.js","../../node_modules/uuid/dist/esm/rng.js","../../node_modules/uuid/dist/esm/native.js","../../node_modules/uuid/dist/esm/v4.js","../src/store.ts","../src/provider.ts","../src/stream.ts","../src/prompt.ts"],"sourcesContent":["import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n","import { randomFillSync } from 'crypto';\nconst rnds8Pool = new Uint8Array(256);\nlet poolPtr = rnds8Pool.length;\nexport default function rng() {\n if (poolPtr > rnds8Pool.length - 16) {\n randomFillSync(rnds8Pool);\n poolPtr = 0;\n }\n return rnds8Pool.slice(poolPtr, (poolPtr += 16));\n}\n","import { randomUUID } from 'crypto';\nexport default { randomUUID };\n","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n options = options || {};\n const rnds = options.random ?? options.rng?.() ?? rng();\n if (rnds.length < 16) {\n throw new Error('Random bytes length must be >= 16');\n }\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n if (offset < 0 || offset + 16 > buf.length) {\n throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);\n }\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;\n","import { CoreMessage } from \"ai\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nexport interface Conversation {\n id: string;\n summary: string;\n timestamp: number;\n}\n\nexport interface ConversationData {\n id: string;\n summary: string;\n messages: CoreMessage[];\n lastUpdated: number;\n}\n\nexport const MAX_CONVERSATIONS = 100;\n\nexport abstract class ConversationStorage {\n // Abstract methods to be implemented by platform-specific storage\n abstract currentConversationId(): Promise<string>;\n abstract selectConversation(conversationId: string): Promise<void>;\n abstract listConversations(): Promise<Conversation[]>;\n abstract getConversation(\n conversationId: string\n ): Promise<ConversationData | null>;\n abstract storeConversationData(\n conversationId: string,\n data: ConversationData\n ): Promise<void>;\n abstract deleteConversationData(conversationId: string): Promise<boolean>;\n\n // Shared functionality that works across platforms\n async createConversation(messages: CoreMessage[]): Promise<ConversationData> {\n const id = uuidv4();\n const initialMessage = messages.find((msg) => msg.role === \"user\");\n const summary = initialMessage\n ? this.generateSummary(initialMessage.content as string)\n : `New conversation ${new Date().toLocaleString()}`;\n const conversation: ConversationData = {\n id,\n summary,\n messages,\n lastUpdated: Date.now(),\n };\n await this.storeConversationData(id, conversation);\n await this.selectConversation(id);\n await this.pruneOldConversations();\n return conversation;\n }\n\n async addMessageToConversation(\n conversationId: string,\n message: CoreMessage\n ): Promise<ConversationData> {\n const conversation = await this.getConversation(conversationId);\n if (!conversation) {\n throw new Error(`Conversation with ID ${conversationId} not found`);\n }\n conversation.messages.push({ ...message });\n conversation.lastUpdated = Date.now();\n await this.storeConversationData(conversationId, conversation);\n return conversation;\n }\n\n async getCurrentConversation(): Promise<ConversationData | null> {\n const currentId = await this.currentConversationId();\n if (!currentId) return null;\n return await this.getConversation(currentId);\n }\n\n async getLatestConversation(): Promise<ConversationData | null> {\n const convos = await this.listConversations();\n if (!convos.length) return null;\n // Sort by most recent first\n const sortedConvos = [...convos].sort((a, b) => b.timestamp - a.timestamp);\n return await this.getConversation(sortedConvos[0].id);\n }\n\n async updateConversationSummary(\n conversationId: string,\n summary: string\n ): Promise<ConversationData> {\n const conversation = await this.getConversation(conversationId);\n if (!conversation) {\n throw new Error(`Conversation with ID ${conversationId} not found`);\n }\n conversation.summary = summary;\n conversation.lastUpdated = Date.now();\n await this.storeConversationData(conversationId, conversation);\n return conversation;\n }\n\n private async pruneOldConversations(): Promise<void> {\n const conversations = await this.listConversations();\n if (conversations.length <= MAX_CONVERSATIONS) return;\n // Sort by timestamp (oldest first)\n const sortedConversations = [...conversations].sort(\n (a, b) => a.timestamp - b.timestamp\n );\n // Calculate how many need to be deleted\n const deleteCount = sortedConversations.length - MAX_CONVERSATIONS;\n // Get the conversations to delete (the oldest ones)\n const conversationsToDelete = sortedConversations.slice(0, deleteCount);\n // Delete each conversation\n for (const convo of conversationsToDelete) {\n await this.deleteConversationData(convo.id);\n }\n }\n\n protected generateSummary(content: string): string {\n let summary = content.split(\"\\n\")[0].trim();\n if (summary.length > 50) {\n summary = summary.substring(0, 47) + \"...\";\n } else if (summary.length === 0 && content.length > 0) {\n summary = content.substring(0, Math.min(50, content.length));\n if (summary.length === 50) summary = summary + \"...\";\n } else if (summary.length === 0) {\n summary = `Conversation created on ${new Date().toLocaleString()}`;\n }\n return summary;\n }\n}\n","import { createAnthropic, AnthropicProviderOptions } from \"@ai-sdk/anthropic\";\nimport {\n createGoogleGenerativeAI,\n GoogleGenerativeAIProviderOptions,\n} from \"@ai-sdk/google\";\nimport { createOpenAI, OpenAIResponsesProviderOptions } from \"@ai-sdk/openai\";\n\nexport type Provider = \"anthropic\" | \"google\" | \"openai\";\n\nexport const PROVIDERS: Provider[] = [\"anthropic\", \"google\", \"openai\"];\n\nconst SOTA = {\n anthropic: \"claude-3-7-sonnet-20250219\",\n google: \"gemini-2.5-pro-preview-05-06\",\n openai: \"gpt-4.1\",\n};\n\nexport async function getModel(provider: Provider, apiKey: string) {\n switch (provider) {\n case \"anthropic\":\n const anthropic = createAnthropic({\n apiKey,\n });\n return anthropic(SOTA[provider]);\n case \"google\":\n const google = createGoogleGenerativeAI({\n apiKey,\n });\n return google(SOTA[provider]);\n case \"openai\":\n const openai = createOpenAI({\n apiKey,\n compatibility: \"strict\",\n });\n return openai(SOTA[provider]);\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n}\n\nexport type ThinkingSpeed = \"thinking\" | \"fast\";\n\nexport function getProviderOptions(\n provider: Provider,\n thinkingSpeed?: ThinkingSpeed\n) {\n const fast = thinkingSpeed === \"fast\";\n const budget = fast ? 0 : 24000;\n switch (provider) {\n case \"anthropic\":\n let thinking = fast\n ? { type: \"disabled\" as const }\n : { type: \"enabled\" as const, budgetTokens: budget };\n return {\n anthropic: {\n thinking,\n } satisfies AnthropicProviderOptions,\n };\n case \"google\":\n return {\n google: {\n thinkingConfig: { thinkingBudget: budget },\n } satisfies GoogleGenerativeAIProviderOptions,\n };\n case \"openai\":\n return {\n openai: {} satisfies OpenAIResponsesProviderOptions,\n };\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n}\n","import { CoreMessage, streamText, ToolSet } from \"ai\";\nimport {\n Provider,\n getModel,\n getProviderOptions,\n ThinkingSpeed,\n} from \"./provider\";\n\nexport async function callModel(\n provider: Provider,\n apiKey: string,\n messages: CoreMessage[],\n tools?: ToolSet,\n parser?: (fullResponse: string) => void,\n thinkingSpeed?: ThinkingSpeed\n): Promise<string> {\n const model = await getModel(provider, apiKey);\n const providerOptions = getProviderOptions(provider, thinkingSpeed);\n console.log(`Calling ${provider} with options:`, providerOptions);\n const result = streamText({\n model,\n tools,\n messages,\n temperature: 0,\n providerOptions: providerOptions as any,\n });\n let fullResponse = \"\";\n for await (const part of result.fullStream) {\n switch (part.type) {\n case \"error\":\n throw part.error;\n case \"text-delta\":\n if (parser) {\n parser(fullResponse);\n }\n fullResponse += part.textDelta;\n break;\n }\n }\n return fullResponse;\n}\n","export const SYSTEM = `You are an expert dev. You are given a codebase and a task. You need to write the code for the task. You can also suggest changes to the codebase if needed.\n\nAvoid assuming that certain functions are available in the codebase. Don't use to_timestamp or to_date in SQL if you don't see examples of them being used. DO NOT make up functions like a logger or other utils. Only use utility functions that you ABSOLUTELY know exist in the code.\n\nTry to write as simple and straightforward code as possible. Make a real implementation, do NOT do a mockup or add sample data. Assume there is already mock data in the database. If you see snippets of backend code, that means you have access to the backend codebase and can add new backend endpoints or other functionality as needed.\n\nYou will be provided with code snippets to edit or create. Please preserve the EXACT file paths when you make edits. Do not truncate the file paths.\n\nYou may see multiple code snippets from the same file! In that case, please organize the code properly: if you need to add an import statement, do it in the snippet that has other imports in it! Since you won't always be able to see the whole file, try to be careful and avoid adding new code just above a snippet, since you might not know exactly what other code is there.\n\nAlways remember to add correct code that will compile!!! Make sure to properly add function signatures if needed, such as to Go interfaces or Rust traits (if you see those in the code snippets).\n\nIf asked to make further changes after already writing code, use the <content> blocks from your previous edits in order to identify code snippets to replace.\n`;\n\nexport const OUTRO = `\nPlease write all the necessary code to fully implement the feature end-to-end. Do not make mock data or example placeholders!!!\n`;\n"],"mappings":";AACA,IAAM,YAAY,CAAC;AACnB,SAAS,IAAI,GAAG,IAAI,KAAK,EAAE,GAAG;AAC1B,YAAU,MAAM,IAAI,KAAO,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AACpD;AACO,SAAS,gBAAgB,KAAK,SAAS,GAAG;AAC7C,UAAQ,UAAU,IAAI,SAAS,CAAC,CAAC,IAC7B,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,UAAU,IAAI,SAAS,CAAC,CAAC,IACzB,MACA,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,IAC1B,UAAU,IAAI,SAAS,EAAE,CAAC,GAAG,YAAY;AACjD;;;AC1BA,SAAS,sBAAsB;AAC/B,IAAM,YAAY,IAAI,WAAW,GAAG;AACpC,IAAI,UAAU,UAAU;AACT,SAAR,MAAuB;AAC1B,MAAI,UAAU,UAAU,SAAS,IAAI;AACjC,mBAAe,SAAS;AACxB,cAAU;AAAA,EACd;AACA,SAAO,UAAU,MAAM,SAAU,WAAW,EAAG;AACnD;;;ACTA,SAAS,kBAAkB;AAC3B,IAAO,iBAAQ,EAAE,WAAW;;;ACE5B,SAAS,GAAG,SAAS,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