call-ai 0.0.0-dev-prompts
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/LICENSE.md +232 -0
- package/README.md +264 -0
- package/api-core.d.ts +13 -0
- package/api-core.js +238 -0
- package/api-core.js.map +1 -0
- package/api.d.ts +4 -0
- package/api.js +365 -0
- package/api.js.map +1 -0
- package/api.ts.off +595 -0
- package/env.d.ts +22 -0
- package/env.js +65 -0
- package/env.js.map +1 -0
- package/error-handling.d.ts +14 -0
- package/error-handling.js +144 -0
- package/error-handling.js.map +1 -0
- package/image.d.ts +2 -0
- package/image.js +72 -0
- package/image.js.map +1 -0
- package/index.d.ts +7 -0
- package/index.js +8 -0
- package/index.js.map +1 -0
- package/index.ts.bak +16 -0
- package/key-management.d.ts +29 -0
- package/key-management.js +190 -0
- package/key-management.js.map +1 -0
- package/non-streaming.d.ts +7 -0
- package/non-streaming.js +206 -0
- package/non-streaming.js.map +1 -0
- package/package.json +43 -0
- package/response-metadata.d.ts +6 -0
- package/response-metadata.js +22 -0
- package/response-metadata.js.map +1 -0
- package/strategies/index.d.ts +2 -0
- package/strategies/index.js +3 -0
- package/strategies/index.js.map +1 -0
- package/strategies/model-strategies.d.ts +6 -0
- package/strategies/model-strategies.js +138 -0
- package/strategies/model-strategies.js.map +1 -0
- package/strategies/strategy-selector.d.ts +2 -0
- package/strategies/strategy-selector.js +66 -0
- package/strategies/strategy-selector.js.map +1 -0
- package/streaming.d.ts +4 -0
- package/streaming.js +365 -0
- package/streaming.js.map +1 -0
- package/streaming.ts.off +571 -0
- package/tsconfig.json +18 -0
- package/types.d.ts +228 -0
- package/types.js +33 -0
- package/types.js.map +1 -0
- package/utils.d.ts +8 -0
- package/utils.js +42 -0
- package/utils.js.map +1 -0
- package/version.d.ts +1 -0
- package/version.js +2 -0
- package/version.js.map +1 -0
package/api-core.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { isToolUseType, isToolUseResponse, isOpenAIArray, CallAIError, } from "./types.js";
|
|
2
|
+
import { globalDebug } from "./key-management.js";
|
|
3
|
+
import { callAINonStreaming } from "./non-streaming.js";
|
|
4
|
+
import { callAIStreaming } from "./streaming.js";
|
|
5
|
+
import { PACKAGE_VERSION } from "./version.js";
|
|
6
|
+
import { callAiEnv } from "./env.js";
|
|
7
|
+
function callAi(prompt, options = {}) {
|
|
8
|
+
const debug = options.debug === undefined ? globalDebug : options.debug;
|
|
9
|
+
prepareRequestParams(prompt, options);
|
|
10
|
+
let schemaStrategy = {
|
|
11
|
+
strategy: "none",
|
|
12
|
+
model: options.model || "openai/gpt-3.5-turbo",
|
|
13
|
+
prepareRequest: () => {
|
|
14
|
+
throw new Error("Schema strategy not implemented");
|
|
15
|
+
},
|
|
16
|
+
processResponse: (response) => {
|
|
17
|
+
if (response && typeof response === "object") {
|
|
18
|
+
return JSON.stringify(response);
|
|
19
|
+
}
|
|
20
|
+
if (typeof response !== "string") {
|
|
21
|
+
throw new Error(`Unexpected response type: ${typeof response}`);
|
|
22
|
+
}
|
|
23
|
+
return response;
|
|
24
|
+
},
|
|
25
|
+
shouldForceStream: false,
|
|
26
|
+
};
|
|
27
|
+
if (options.schema) {
|
|
28
|
+
const model = options.model || "openai/gpt-3.5-turbo";
|
|
29
|
+
if (/claude/i.test(model) || /anthropic/i.test(model)) {
|
|
30
|
+
schemaStrategy = {
|
|
31
|
+
strategy: "tool_mode",
|
|
32
|
+
model,
|
|
33
|
+
shouldForceStream: false,
|
|
34
|
+
prepareRequest: (schema) => {
|
|
35
|
+
let toolDef = {};
|
|
36
|
+
if (typeof schema === "string") {
|
|
37
|
+
try {
|
|
38
|
+
toolDef = JSON.parse(schema);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
toolDef = { description: schema };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (schema) {
|
|
45
|
+
toolDef = schema;
|
|
46
|
+
}
|
|
47
|
+
const tools = [
|
|
48
|
+
{
|
|
49
|
+
type: "function",
|
|
50
|
+
function: {
|
|
51
|
+
name: toolDef.name || "execute_function",
|
|
52
|
+
description: toolDef.description || "Execute a function",
|
|
53
|
+
parameters: toolDef.parameters || {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: {},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
return {
|
|
61
|
+
tools,
|
|
62
|
+
tool_choice: {
|
|
63
|
+
type: "function",
|
|
64
|
+
function: { name: tools[0].function.name },
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
processResponse: (response) => {
|
|
69
|
+
if (typeof response === "string") {
|
|
70
|
+
return response;
|
|
71
|
+
}
|
|
72
|
+
if (isToolUseType(response)) {
|
|
73
|
+
return response.input || "{}";
|
|
74
|
+
}
|
|
75
|
+
if (isToolUseResponse(response)) {
|
|
76
|
+
return response.tool_use.input || "{}";
|
|
77
|
+
}
|
|
78
|
+
if (isOpenAIArray(response)) {
|
|
79
|
+
if (response.length > 0 && response[0].function && response[0].function.arguments) {
|
|
80
|
+
return response[0].function.arguments;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return typeof response === "string" ? response : JSON.stringify(response);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
schemaStrategy = {
|
|
89
|
+
strategy: "json_schema",
|
|
90
|
+
model,
|
|
91
|
+
shouldForceStream: false,
|
|
92
|
+
prepareRequest: (schema) => {
|
|
93
|
+
const schemaObj = schema || {};
|
|
94
|
+
return {
|
|
95
|
+
response_format: {
|
|
96
|
+
type: "json_schema",
|
|
97
|
+
json_schema: {
|
|
98
|
+
name: schemaObj.name || "result",
|
|
99
|
+
schema: {
|
|
100
|
+
type: "object",
|
|
101
|
+
properties: schemaObj.properties || {},
|
|
102
|
+
required: schemaObj.required || Object.keys(schemaObj.properties || {}),
|
|
103
|
+
additionalProperties: schemaObj.additionalProperties !== undefined ? schemaObj.additionalProperties : false,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
processResponse: (response) => {
|
|
110
|
+
if (typeof response === "string") {
|
|
111
|
+
return response;
|
|
112
|
+
}
|
|
113
|
+
return JSON.stringify(response);
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (options.stream) {
|
|
119
|
+
if (debug) {
|
|
120
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Making streaming request`);
|
|
121
|
+
}
|
|
122
|
+
const streamPromise = (async () => {
|
|
123
|
+
return callAIStreaming(prompt, {
|
|
124
|
+
...options,
|
|
125
|
+
schemaStrategy,
|
|
126
|
+
});
|
|
127
|
+
})();
|
|
128
|
+
return createBackwardCompatStreamingProxy(streamPromise);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
if (debug) {
|
|
132
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Making non-streaming request`);
|
|
133
|
+
}
|
|
134
|
+
const optionsWithSchema = {
|
|
135
|
+
...options,
|
|
136
|
+
schemaStrategy,
|
|
137
|
+
};
|
|
138
|
+
return callAINonStreaming(prompt, optionsWithSchema);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function bufferStreamingResults(generator) {
|
|
142
|
+
let result = "";
|
|
143
|
+
try {
|
|
144
|
+
for await (const chunk of generator) {
|
|
145
|
+
result += chunk;
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (error instanceof Error) {
|
|
151
|
+
const enhancedError = new CallAIError({
|
|
152
|
+
message: `${error.message} (Partial content: ${result.slice(0, 100)}...)`,
|
|
153
|
+
status: 511,
|
|
154
|
+
partialContent: result,
|
|
155
|
+
originalError: error,
|
|
156
|
+
});
|
|
157
|
+
throw enhancedError;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const newError = new CallAIError({
|
|
161
|
+
message: `Streaming error: ${String(error)}`,
|
|
162
|
+
status: 511,
|
|
163
|
+
partialContent: result,
|
|
164
|
+
originalError: error,
|
|
165
|
+
});
|
|
166
|
+
throw newError;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function createBackwardCompatStreamingProxy(promise) {
|
|
171
|
+
return new Proxy({}, {
|
|
172
|
+
get(_target, prop) {
|
|
173
|
+
if (prop === "next" || prop === "throw" || prop === "return" || prop === Symbol.asyncIterator) {
|
|
174
|
+
if (prop === Symbol.asyncIterator) {
|
|
175
|
+
return function () {
|
|
176
|
+
return {
|
|
177
|
+
async next(value) {
|
|
178
|
+
try {
|
|
179
|
+
const generator = await promise;
|
|
180
|
+
return generator.next(value);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return Promise.reject(error);
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return async function (value) {
|
|
190
|
+
const generator = await promise;
|
|
191
|
+
switch (prop) {
|
|
192
|
+
case "next":
|
|
193
|
+
return generator.next(value);
|
|
194
|
+
case "throw":
|
|
195
|
+
return generator.throw(value);
|
|
196
|
+
case "return":
|
|
197
|
+
return generator.return(value);
|
|
198
|
+
default:
|
|
199
|
+
throw new Error(`Unknown method: ${String(prop)}`);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
if (prop === "then" || prop === "catch" || prop === "finally") {
|
|
204
|
+
return promise[prop].bind(promise);
|
|
205
|
+
}
|
|
206
|
+
return undefined;
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function prepareRequestParams(prompt, options = {}) {
|
|
211
|
+
const apiKey = options.apiKey || callAiEnv.CALLAI_API_KEY;
|
|
212
|
+
if (!apiKey) {
|
|
213
|
+
throw new Error("API key is required. Provide it via options.apiKey or set window.CALLAI_API_KEY");
|
|
214
|
+
}
|
|
215
|
+
if (!prompt || (typeof prompt !== "string" && !Array.isArray(prompt))) {
|
|
216
|
+
throw new Error(`Invalid prompt: ${prompt}. Must be a string or an array of message objects.`);
|
|
217
|
+
}
|
|
218
|
+
const messages = Array.isArray(prompt) ? prompt : [{ role: "user", content: prompt }];
|
|
219
|
+
if (Array.isArray(prompt)) {
|
|
220
|
+
for (const message of prompt) {
|
|
221
|
+
if (!message.role || !message.content) {
|
|
222
|
+
throw new Error(`Invalid message format. Each message must have 'role' and 'content' properties. Received: ${JSON.stringify(message)}`);
|
|
223
|
+
}
|
|
224
|
+
if (typeof message.role !== "string" || (typeof message.content !== "string" && !Array.isArray(message.content))) {
|
|
225
|
+
throw new Error(`Invalid message format. 'role' must be a string and 'content' must be a string or array. Received role: ${typeof message.role}, content: ${typeof message.content}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (options.provider && options.provider !== "auto" && options.model && !options.model.startsWith(options.provider + "/")) {
|
|
230
|
+
console.warn(`[callAi:${PACKAGE_VERSION}] WARNING: Specified provider '${options.provider}' doesn't match model '${options.model}'. Using model as specified.`);
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
messages,
|
|
234
|
+
apiKey,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
export { callAi, bufferStreamingResults, createBackwardCompatStreamingProxy, prepareRequestParams, PACKAGE_VERSION };
|
|
238
|
+
//# sourceMappingURL=api-core.js.map
|
package/api-core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-core.js","sourceRoot":"","sources":["../jsr/api-core.ts"],"names":[],"mappings":"AAIA,OAAO,EAOL,aAAa,EACb,iBAAiB,EACjB,aAAa,EAGb,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,M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@@
|
|
|
1
|
+
import { CallAIError } from "./types.js";
|
|
2
|
+
import { chooseSchemaStrategy } from "./strategies/index.js";
|
|
3
|
+
import { responseMetadata, boxString, getMeta } from "./response-metadata.js";
|
|
4
|
+
import { keyStore, globalDebug } from "./key-management.js";
|
|
5
|
+
import { handleApiError, checkForInvalidModelError } from "./error-handling.js";
|
|
6
|
+
import { createBackwardCompatStreamingProxy } from "./api-core.js";
|
|
7
|
+
import { extractContent, extractClaudeResponse, PACKAGE_VERSION } from "./non-streaming.js";
|
|
8
|
+
import { createStreamingGenerator } from "./streaming.js";
|
|
9
|
+
import { callAiFetch } from "./utils.js";
|
|
10
|
+
import { callAiEnv } from "./env.js";
|
|
11
|
+
export { getMeta };
|
|
12
|
+
const FALLBACK_MODEL = "openrouter/auto";
|
|
13
|
+
export function callAi(prompt, options = {}) {
|
|
14
|
+
const schemaStrategy = chooseSchemaStrategy(options.model, options.schema || null);
|
|
15
|
+
if (!options.stream && schemaStrategy.shouldForceStream) {
|
|
16
|
+
return bufferStreamingResults(prompt, options);
|
|
17
|
+
}
|
|
18
|
+
if (options.stream !== true) {
|
|
19
|
+
return callAINonStreaming(prompt, options);
|
|
20
|
+
}
|
|
21
|
+
const streamPromise = (async () => {
|
|
22
|
+
const { endpoint, requestOptions, model, schemaStrategy } = prepareRequestParams(prompt, { ...options, stream: true });
|
|
23
|
+
const debug = options.debug || globalDebug;
|
|
24
|
+
if (debug) {
|
|
25
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Making fetch request to: ${endpoint}`);
|
|
26
|
+
console.log(`[callAi:${PACKAGE_VERSION}] With model: ${model}`);
|
|
27
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Request headers:`, JSON.stringify(requestOptions.headers));
|
|
28
|
+
}
|
|
29
|
+
let response;
|
|
30
|
+
try {
|
|
31
|
+
response = await callAiFetch(options)(endpoint, requestOptions);
|
|
32
|
+
if (options.debug) {
|
|
33
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Fetch completed with status:`, response.status, response.statusText);
|
|
34
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Response headers:`);
|
|
35
|
+
response.headers.forEach((value, name) => {
|
|
36
|
+
console.log(`[callAi:${PACKAGE_VERSION}] ${name}: ${value}`);
|
|
37
|
+
});
|
|
38
|
+
const diagnosticResponse = response.clone();
|
|
39
|
+
try {
|
|
40
|
+
const responseText = await diagnosticResponse.text();
|
|
41
|
+
console.log(`[callAi:${PACKAGE_VERSION}] First 500 chars of response body:`, responseText.substring(0, 500) + (responseText.length > 500 ? "..." : ""));
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Could not read response body for diagnostics:`, e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (fetchError) {
|
|
49
|
+
if (options.debug) {
|
|
50
|
+
console.error(`[callAi:${PACKAGE_VERSION}] Network error during fetch:`, fetchError);
|
|
51
|
+
}
|
|
52
|
+
throw fetchError;
|
|
53
|
+
}
|
|
54
|
+
const contentType = response?.headers?.get?.("content-type") || "";
|
|
55
|
+
if (options.debug) {
|
|
56
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Response.ok =`, response.ok);
|
|
57
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Response.status =`, response.status);
|
|
58
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Response.statusText =`, response.statusText);
|
|
59
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Response.type =`, response.type);
|
|
60
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Content-Type =`, contentType);
|
|
61
|
+
}
|
|
62
|
+
const hasHttpError = !response.ok || response.status >= 400;
|
|
63
|
+
const hasJsonError = contentType.includes("application/json");
|
|
64
|
+
if (hasHttpError || hasJsonError) {
|
|
65
|
+
if (options.debug) {
|
|
66
|
+
console.log(`[callAi:${PACKAGE_VERSION}] ⚠️ Error detected - HTTP Status: ${response.status}, Content-Type: ${contentType}`);
|
|
67
|
+
}
|
|
68
|
+
if (!options.skipRetry) {
|
|
69
|
+
const clonedResponse = response.clone();
|
|
70
|
+
let isInvalidModel = false;
|
|
71
|
+
try {
|
|
72
|
+
const modelCheckResult = await checkForInvalidModelError(clonedResponse, model, options.debug);
|
|
73
|
+
isInvalidModel = modelCheckResult.isInvalidModel;
|
|
74
|
+
if (isInvalidModel) {
|
|
75
|
+
if (options.debug) {
|
|
76
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Retrying with fallback model: ${FALLBACK_MODEL}`);
|
|
77
|
+
}
|
|
78
|
+
return (await callAi(prompt, {
|
|
79
|
+
...options,
|
|
80
|
+
model: FALLBACK_MODEL,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (modelCheckError) {
|
|
85
|
+
console.error(`[callAi:${PACKAGE_VERSION}] Error during model check:`, modelCheckError);
|
|
86
|
+
// Continue with normal error handling
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const errorBody = await response.text();
|
|
91
|
+
if (options.debug) {
|
|
92
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Error body:`, errorBody);
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const errorJson = JSON.parse(errorBody);
|
|
96
|
+
if (options.debug) {
|
|
97
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Parsed error:`, errorJson);
|
|
98
|
+
}
|
|
99
|
+
let errorMessage = "";
|
|
100
|
+
if (errorJson.error && typeof errorJson.error === "object" && errorJson.error.message) {
|
|
101
|
+
errorMessage = errorJson.error.message;
|
|
102
|
+
}
|
|
103
|
+
else if (errorJson.error && typeof errorJson.error === "string") {
|
|
104
|
+
errorMessage = errorJson.error;
|
|
105
|
+
}
|
|
106
|
+
else if (errorJson.message) {
|
|
107
|
+
errorMessage = errorJson.message;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
errorMessage = `API returned ${response.status}: ${response.statusText}`;
|
|
111
|
+
}
|
|
112
|
+
if (!errorMessage.includes(response.status.toString())) {
|
|
113
|
+
errorMessage = `${errorMessage} (Status: ${response.status})`;
|
|
114
|
+
}
|
|
115
|
+
if (options.debug) {
|
|
116
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Extracted error message:`, errorMessage);
|
|
117
|
+
}
|
|
118
|
+
const error = new CallAIError({
|
|
119
|
+
message: errorMessage,
|
|
120
|
+
status: response.status,
|
|
121
|
+
statusText: response.statusText,
|
|
122
|
+
details: errorJson,
|
|
123
|
+
contentType,
|
|
124
|
+
});
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
catch (jsonError) {
|
|
128
|
+
if (options.debug) {
|
|
129
|
+
console.log(`[callAi:${PACKAGE_VERSION}] JSON parse error:`, jsonError);
|
|
130
|
+
}
|
|
131
|
+
let errorMessage = "";
|
|
132
|
+
if (errorBody && errorBody.trim().length > 0) {
|
|
133
|
+
errorMessage = errorBody.length > 100 ? errorBody.substring(0, 100) + "..." : errorBody;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
errorMessage = `API error: ${response.status} ${response.statusText}`;
|
|
137
|
+
}
|
|
138
|
+
if (!errorMessage.includes(response.status.toString())) {
|
|
139
|
+
errorMessage = `${errorMessage} (Status: ${response.status})`;
|
|
140
|
+
}
|
|
141
|
+
if (options.debug) {
|
|
142
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Extracted text error message:`, errorMessage);
|
|
143
|
+
}
|
|
144
|
+
const error = new CallAIError({
|
|
145
|
+
message: errorMessage,
|
|
146
|
+
status: response.status,
|
|
147
|
+
statusText: response.statusText,
|
|
148
|
+
details: errorBody,
|
|
149
|
+
contentType,
|
|
150
|
+
});
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (responseError) {
|
|
155
|
+
if (responseError instanceof Error) {
|
|
156
|
+
throw responseError;
|
|
157
|
+
}
|
|
158
|
+
const error = new CallAIError({
|
|
159
|
+
message: `API returned ${response.status}: ${response.statusText}`,
|
|
160
|
+
status: response.status,
|
|
161
|
+
statusText: response.statusText,
|
|
162
|
+
contentType,
|
|
163
|
+
});
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (options.debug) {
|
|
168
|
+
console.log(`[callAi:${PACKAGE_VERSION}] Response OK, creating streaming generator`);
|
|
169
|
+
}
|
|
170
|
+
return createStreamingGenerator(response, options, schemaStrategy, model);
|
|
171
|
+
})();
|
|
172
|
+
if (process.env.NODE_ENV !== "production") {
|
|
173
|
+
if (options.debug) {
|
|
174
|
+
console.warn(`[callAi:${PACKAGE_VERSION}] No await found - using legacy streaming pattern. This will be removed in a future version and may cause issues with certain models.`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return createBackwardCompatStreamingProxy(streamPromise);
|
|
178
|
+
}
|
|
179
|
+
async function bufferStreamingResults(prompt, options) {
|
|
180
|
+
const streamingOptions = {
|
|
181
|
+
...options,
|
|
182
|
+
stream: true,
|
|
183
|
+
};
|
|
184
|
+
try {
|
|
185
|
+
const generator = (await callAi(prompt, streamingOptions));
|
|
186
|
+
const isClaudeJson = /claude/.test(options.model || "") && options.schema;
|
|
187
|
+
if (isClaudeJson) {
|
|
188
|
+
let lastChunk = "";
|
|
189
|
+
for await (const chunk of generator) {
|
|
190
|
+
lastChunk = chunk;
|
|
191
|
+
}
|
|
192
|
+
return lastChunk;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
let result = "";
|
|
196
|
+
for await (const chunk of generator) {
|
|
197
|
+
result += chunk;
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
await handleApiError(error, "Buffered streaming", options.debug, {
|
|
204
|
+
apiKey: options.apiKey,
|
|
205
|
+
endpoint: options.endpoint,
|
|
206
|
+
skipRefresh: options.skipRefresh,
|
|
207
|
+
refreshToken: options.refreshToken,
|
|
208
|
+
updateRefreshToken: options.updateRefreshToken,
|
|
209
|
+
});
|
|
210
|
+
return bufferStreamingResults(prompt, {
|
|
211
|
+
...options,
|
|
212
|
+
apiKey: keyStore().current,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
throw new Error("Unexpected code path in bufferStreamingResults");
|
|
216
|
+
}
|
|
217
|
+
function prepareRequestParams(prompt, options) {
|
|
218
|
+
const apiKey = options.apiKey ||
|
|
219
|
+
keyStore().current ||
|
|
220
|
+
callAiEnv.CALLAI_API_KEY ||
|
|
221
|
+
null;
|
|
222
|
+
const schema = options.schema || null;
|
|
223
|
+
const schemaStrategy = chooseSchemaStrategy(options.model, schema);
|
|
224
|
+
const model = schemaStrategy.model;
|
|
225
|
+
const customChatOrigin = options.chatUrl || callAiEnv.def.CALLAI_CHAT_URL || null;
|
|
226
|
+
const endpoint = options.endpoint ||
|
|
227
|
+
(customChatOrigin ? `${customChatOrigin}/api/v1/chat/completions` : "https://openrouter.ai/api/v1/chat/completions");
|
|
228
|
+
const messages = Array.isArray(prompt) ? prompt : [{ role: "user", content: prompt }];
|
|
229
|
+
const requestParams = {
|
|
230
|
+
model,
|
|
231
|
+
messages,
|
|
232
|
+
stream: options.stream !== undefined ? options.stream : false,
|
|
233
|
+
};
|
|
234
|
+
if (options.temperature !== undefined) {
|
|
235
|
+
requestParams.temperature = options.temperature;
|
|
236
|
+
}
|
|
237
|
+
if (options.topP !== undefined) {
|
|
238
|
+
requestParams.top_p = options.topP;
|
|
239
|
+
}
|
|
240
|
+
if (options.maxTokens !== undefined) {
|
|
241
|
+
requestParams.max_tokens = options.maxTokens;
|
|
242
|
+
}
|
|
243
|
+
if (options.stop) {
|
|
244
|
+
requestParams.stop = Array.isArray(options.stop) ? options.stop : [options.stop];
|
|
245
|
+
}
|
|
246
|
+
if (options.responseFormat === "json") {
|
|
247
|
+
requestParams.response_format = { type: "json_object" };
|
|
248
|
+
}
|
|
249
|
+
if (schema) {
|
|
250
|
+
Object.assign(requestParams, schemaStrategy.prepareRequest(schema, messages));
|
|
251
|
+
}
|
|
252
|
+
const headers = {
|
|
253
|
+
Authorization: `Bearer ${apiKey}`,
|
|
254
|
+
"Content-Type": "application/json",
|
|
255
|
+
"HTTP-Referer": options.referer || "https://vibes.diy",
|
|
256
|
+
"X-Title": options.title || "Vibes",
|
|
257
|
+
};
|
|
258
|
+
if (options.headers) {
|
|
259
|
+
Object.assign(headers, options.headers);
|
|
260
|
+
}
|
|
261
|
+
const requestOptions = {
|
|
262
|
+
method: "POST",
|
|
263
|
+
headers: {
|
|
264
|
+
...headers,
|
|
265
|
+
"Content-Type": "application/json",
|
|
266
|
+
},
|
|
267
|
+
body: JSON.stringify(requestParams),
|
|
268
|
+
};
|
|
269
|
+
if (!apiKey) {
|
|
270
|
+
throw new Error("API key is required. Provide it via options.apiKey or set window.CALLAI_API_KEY");
|
|
271
|
+
}
|
|
272
|
+
if (options.debug) {
|
|
273
|
+
console.log(`[callAi-prepareRequest:raw] Endpoint: ${endpoint}`);
|
|
274
|
+
console.log(`[callAi-prepareRequest:raw] Model: ${model}`);
|
|
275
|
+
console.log(`[callAi-prepareRequest:raw] Payload:`, JSON.stringify(requestParams));
|
|
276
|
+
}
|
|
277
|
+
return { apiKey, model, endpoint, requestOptions, schemaStrategy };
|
|
278
|
+
}
|
|
279
|
+
async function callAINonStreaming(prompt, options = {}, isRetry = false) {
|
|
280
|
+
try {
|
|
281
|
+
const startTime = Date.now();
|
|
282
|
+
const meta = {
|
|
283
|
+
model: options.model || "unknown",
|
|
284
|
+
timing: {
|
|
285
|
+
startTime: startTime,
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
const { endpoint, requestOptions, model, schemaStrategy } = prepareRequestParams(prompt, options);
|
|
289
|
+
const response = await callAiFetch(options)(endpoint, requestOptions);
|
|
290
|
+
if (!response.ok || response.status >= 400) {
|
|
291
|
+
const { isInvalidModel } = await checkForInvalidModelError(response, model, options.debug);
|
|
292
|
+
if (isInvalidModel && !options.skipRetry) {
|
|
293
|
+
return callAINonStreaming(prompt, { ...options, model: FALLBACK_MODEL }, true);
|
|
294
|
+
}
|
|
295
|
+
const error = new CallAIError({
|
|
296
|
+
message: `HTTP error! Status: ${response.status}`,
|
|
297
|
+
status: response.status,
|
|
298
|
+
statusCode: response.status,
|
|
299
|
+
contentType: "text/plain",
|
|
300
|
+
});
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
let result;
|
|
304
|
+
if (/claude/i.test(model)) {
|
|
305
|
+
try {
|
|
306
|
+
result = await extractClaudeResponse(response);
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
handleApiError(error, "Claude API response processing failed", options.debug);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
result = await response.json();
|
|
314
|
+
}
|
|
315
|
+
if (options.debug) {
|
|
316
|
+
console.log(`[callAi-nonStreaming:raw] Response:`, JSON.stringify(result));
|
|
317
|
+
}
|
|
318
|
+
if (result.error) {
|
|
319
|
+
if (options.debug) {
|
|
320
|
+
console.error("API returned an error:", result.error);
|
|
321
|
+
}
|
|
322
|
+
if (!isRetry &&
|
|
323
|
+
!options.skipRetry &&
|
|
324
|
+
result.error.message &&
|
|
325
|
+
result.error.message.toLowerCase().includes("not a valid model")) {
|
|
326
|
+
if (options.debug) {
|
|
327
|
+
console.warn(`Model ${model} error, retrying with ${FALLBACK_MODEL}`);
|
|
328
|
+
}
|
|
329
|
+
return callAINonStreaming(prompt, { ...options, model: FALLBACK_MODEL }, true);
|
|
330
|
+
}
|
|
331
|
+
return JSON.stringify({
|
|
332
|
+
error: result.error,
|
|
333
|
+
message: result.error.message || "API returned an error",
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
const content = extractContent(result, schemaStrategy);
|
|
337
|
+
if (result) {
|
|
338
|
+
meta.rawResponse = result;
|
|
339
|
+
}
|
|
340
|
+
meta.model = model;
|
|
341
|
+
if (meta.timing) {
|
|
342
|
+
meta.timing.endTime = Date.now();
|
|
343
|
+
meta.timing.duration = meta.timing.endTime - meta.timing.startTime;
|
|
344
|
+
}
|
|
345
|
+
const processedContent = schemaStrategy.processResponse(content);
|
|
346
|
+
const boxed = boxString(processedContent);
|
|
347
|
+
responseMetadata.set(boxed, meta);
|
|
348
|
+
return processedContent;
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
await handleApiError(error, "Non-streaming API call", options.debug, {
|
|
352
|
+
apiKey: options.apiKey,
|
|
353
|
+
endpoint: options.endpoint,
|
|
354
|
+
skipRefresh: options.skipRefresh,
|
|
355
|
+
refreshToken: options.refreshToken,
|
|
356
|
+
updateRefreshToken: options.updateRefreshToken,
|
|
357
|
+
});
|
|
358
|
+
return callAINonStreaming(prompt, {
|
|
359
|
+
...options,
|
|
360
|
+
apiKey: keyStore().current,
|
|
361
|
+
}, true);
|
|
362
|
+
}
|
|
363
|
+
throw new Error("Unexpected code path in callAINonStreaming");
|
|
364
|
+
}
|
|
365
|
+
//# sourceMappingURL=api.js.map
|
package/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../jsr/api.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAwE,MAAM,YAAY,CAAC;AAC/G,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,kCAAkC,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,wBAAwB,EAAE,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