call-ai 0.10.2 → 0.11.0-dev-preview3
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/README.md +60 -58
- package/api-core.d.ts +13 -0
- package/{dist/api-core.js → api-core.js} +51 -126
- package/api-core.js.map +1 -0
- package/api.d.ts +4 -0
- package/api.js +364 -0
- package/api.js.map +1 -0
- package/api.ts.off +595 -0
- package/{dist/error-handling.d.ts → error-handling.d.ts} +4 -2
- package/{dist/error-handling.js → error-handling.js} +34 -70
- package/error-handling.js.map +1 -0
- package/image.d.ts +2 -0
- package/{dist/image.js → image.js} +10 -33
- package/image.js.map +1 -0
- package/index.d.ts +6 -0
- package/index.js +7 -0
- package/index.js.map +1 -0
- package/index.ts.bak +16 -0
- package/key-management.d.ts +29 -0
- package/key-management.js +189 -0
- package/key-management.js.map +1 -0
- package/{dist/non-streaming.d.ts → non-streaming.d.ts} +5 -8
- package/{dist/non-streaming.js → non-streaming.js} +28 -87
- package/non-streaming.js.map +1 -0
- package/package.json +15 -31
- 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/{dist/strategies → strategies}/model-strategies.js +26 -72
- 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/{dist/streaming.js → streaming.js} +66 -184
- package/streaming.js.map +1 -0
- package/streaming.ts.off +571 -0
- package/tsconfig.json +18 -0
- package/types.d.ts +226 -0
- package/types.js +33 -0
- package/types.js.map +1 -0
- package/utils.d.ts +32 -0
- package/utils.js +129 -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/dist/api-core.d.ts +0 -40
- package/dist/api.d.ts +0 -15
- package/dist/api.js +0 -498
- package/dist/image.d.ts +0 -12
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -32
- package/dist/key-management.d.ts +0 -43
- package/dist/key-management.js +0 -312
- package/dist/response-metadata.d.ts +0 -18
- package/dist/response-metadata.js +0 -44
- package/dist/strategies/index.d.ts +0 -5
- package/dist/strategies/index.js +0 -21
- package/dist/strategies/model-strategies.d.ts +0 -24
- package/dist/strategies/strategy-selector.d.ts +0 -8
- package/dist/strategies/strategy-selector.js +0 -79
- package/dist/streaming.d.ts +0 -7
- package/dist/types.d.ts +0 -226
- package/dist/types.js +0 -5
- package/dist/utils.d.ts +0 -8
- package/dist/utils.js +0 -52
package/dist/types.d.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for call-ai
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Content types for multimodal messages
|
|
6
|
-
*/
|
|
7
|
-
export type ContentItem = {
|
|
8
|
-
type: "text" | "image_url";
|
|
9
|
-
text?: string;
|
|
10
|
-
image_url?: {
|
|
11
|
-
url: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Message type supporting both simple string content and multimodal content
|
|
16
|
-
*/
|
|
17
|
-
export type Message = {
|
|
18
|
-
role: "user" | "system" | "assistant";
|
|
19
|
-
content: string | ContentItem[];
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Metadata associated with a response
|
|
23
|
-
* Available through the getMeta() helper function
|
|
24
|
-
*/
|
|
25
|
-
export interface ResponseMeta {
|
|
26
|
-
/**
|
|
27
|
-
* The model used for the response
|
|
28
|
-
*/
|
|
29
|
-
model: string;
|
|
30
|
-
/**
|
|
31
|
-
* Timing information about the request
|
|
32
|
-
*/
|
|
33
|
-
timing?: {
|
|
34
|
-
startTime: number;
|
|
35
|
-
endTime?: number;
|
|
36
|
-
duration?: number;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Raw response data from the fetch call
|
|
40
|
-
* Contains the parsed JSON result from the API call
|
|
41
|
-
*/
|
|
42
|
-
rawResponse?: any;
|
|
43
|
-
}
|
|
44
|
-
export interface Schema {
|
|
45
|
-
/**
|
|
46
|
-
* Optional schema name - will be sent to OpenRouter if provided
|
|
47
|
-
* If not specified, defaults to "result"
|
|
48
|
-
*/
|
|
49
|
-
name?: string;
|
|
50
|
-
/**
|
|
51
|
-
* Properties defining the structure of your schema
|
|
52
|
-
*/
|
|
53
|
-
properties: Record<string, any>;
|
|
54
|
-
/**
|
|
55
|
-
* Fields that are required in the response (defaults to all properties)
|
|
56
|
-
*/
|
|
57
|
-
required?: string[];
|
|
58
|
-
/**
|
|
59
|
-
* Whether to allow fields not defined in properties (defaults to false)
|
|
60
|
-
*/
|
|
61
|
-
additionalProperties?: boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Any additional schema properties to pass through
|
|
64
|
-
*/
|
|
65
|
-
[key: string]: any;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Strategy interface for handling different model types
|
|
69
|
-
*/
|
|
70
|
-
export interface ModelStrategy {
|
|
71
|
-
name: string;
|
|
72
|
-
prepareRequest: (schema: Schema | null, messages: Message[]) => any;
|
|
73
|
-
processResponse: (content: string | any) => string;
|
|
74
|
-
shouldForceStream?: boolean;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Schema strategies for different model types
|
|
78
|
-
*/
|
|
79
|
-
export type SchemaStrategyType = "json_schema" | "tool_mode" | "system_message" | "none";
|
|
80
|
-
/**
|
|
81
|
-
* Strategy selection result
|
|
82
|
-
*/
|
|
83
|
-
export interface SchemaStrategy {
|
|
84
|
-
strategy: SchemaStrategyType;
|
|
85
|
-
model: string;
|
|
86
|
-
prepareRequest: ModelStrategy["prepareRequest"];
|
|
87
|
-
processResponse: ModelStrategy["processResponse"];
|
|
88
|
-
shouldForceStream: boolean;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Return type for streaming API calls
|
|
92
|
-
*/
|
|
93
|
-
export type StreamResponse = AsyncGenerator<string, string, unknown>;
|
|
94
|
-
/**
|
|
95
|
-
* @internal
|
|
96
|
-
* Internal type for backward compatibility with v0.6.x
|
|
97
|
-
* This type is not exposed in public API documentation
|
|
98
|
-
*/
|
|
99
|
-
export type ThenableStreamResponse = AsyncGenerator<string, string, unknown> & Promise<StreamResponse>;
|
|
100
|
-
export interface CallAIOptions {
|
|
101
|
-
/**
|
|
102
|
-
* API key for authentication
|
|
103
|
-
*/
|
|
104
|
-
apiKey?: string;
|
|
105
|
-
/**
|
|
106
|
-
* Model ID to use for the request
|
|
107
|
-
*/
|
|
108
|
-
model?: string;
|
|
109
|
-
/**
|
|
110
|
-
* API endpoint to send the request to
|
|
111
|
-
*/
|
|
112
|
-
endpoint?: string;
|
|
113
|
-
/**
|
|
114
|
-
* Custom origin for chat API
|
|
115
|
-
* Can also be set via window.CALLAI_CHAT_URL or process.env.CALLAI_CHAT_URL
|
|
116
|
-
*/
|
|
117
|
-
chatUrl?: string;
|
|
118
|
-
/**
|
|
119
|
-
* Whether to stream the response
|
|
120
|
-
*/
|
|
121
|
-
stream?: boolean;
|
|
122
|
-
/**
|
|
123
|
-
* Authentication token for key refresh service
|
|
124
|
-
* Can also be set via window.CALL_AI_REFRESH_TOKEN, process.env.CALL_AI_REFRESH_TOKEN, or default to "use-vibes"
|
|
125
|
-
*/
|
|
126
|
-
refreshToken?: string;
|
|
127
|
-
/**
|
|
128
|
-
* Callback function to update refresh token when current token fails
|
|
129
|
-
* Gets called with the current failing token and should return a new token
|
|
130
|
-
* @param currentToken The current refresh token that failed
|
|
131
|
-
* @returns A Promise that resolves to a new refresh token
|
|
132
|
-
*/
|
|
133
|
-
updateRefreshToken?: (currentToken: string) => Promise<string>;
|
|
134
|
-
/**
|
|
135
|
-
* Schema for structured output
|
|
136
|
-
*/
|
|
137
|
-
schema?: Schema | null;
|
|
138
|
-
/**
|
|
139
|
-
* Modalities to enable in the response (e.g., ["image", "text"])
|
|
140
|
-
* Used for multimodal models that can generate images
|
|
141
|
-
*/
|
|
142
|
-
modalities?: string[];
|
|
143
|
-
/**
|
|
144
|
-
* Whether to skip retry with fallback model when model errors occur
|
|
145
|
-
* Useful in testing and cases where retries should be suppressed
|
|
146
|
-
*/
|
|
147
|
-
skipRetry?: boolean;
|
|
148
|
-
/**
|
|
149
|
-
* Skip key refresh on 4xx errors
|
|
150
|
-
* Useful for testing error conditions or when you want to handle refresh manually
|
|
151
|
-
*/
|
|
152
|
-
skipRefresh?: boolean;
|
|
153
|
-
/**
|
|
154
|
-
* Enable raw response logging without any filtering or processing
|
|
155
|
-
*/
|
|
156
|
-
debug?: boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Any additional options to pass to the API
|
|
159
|
-
*/
|
|
160
|
-
[key: string]: any;
|
|
161
|
-
}
|
|
162
|
-
export interface AIResponse {
|
|
163
|
-
text: string;
|
|
164
|
-
usage?: {
|
|
165
|
-
promptTokens: number;
|
|
166
|
-
completionTokens: number;
|
|
167
|
-
totalTokens: number;
|
|
168
|
-
};
|
|
169
|
-
model: string;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Response from image generation API
|
|
173
|
-
*/
|
|
174
|
-
export interface ImageResponse {
|
|
175
|
-
created: number;
|
|
176
|
-
data: {
|
|
177
|
-
b64_json: string;
|
|
178
|
-
url?: string;
|
|
179
|
-
revised_prompt?: string;
|
|
180
|
-
}[];
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Options for image generation
|
|
184
|
-
*/
|
|
185
|
-
export interface ImageGenOptions {
|
|
186
|
-
/**
|
|
187
|
-
* API key for authentication
|
|
188
|
-
* Defaults to "VIBES_DIY"
|
|
189
|
-
*/
|
|
190
|
-
apiKey?: string;
|
|
191
|
-
/**
|
|
192
|
-
* Model to use for image generation
|
|
193
|
-
* Defaults to "gpt-image-1"
|
|
194
|
-
*/
|
|
195
|
-
model?: string;
|
|
196
|
-
/**
|
|
197
|
-
* Size of the generated image
|
|
198
|
-
*/
|
|
199
|
-
size?: string;
|
|
200
|
-
/**
|
|
201
|
-
* Quality of the generated image
|
|
202
|
-
*/
|
|
203
|
-
quality?: string;
|
|
204
|
-
/**
|
|
205
|
-
* Style of the generated image
|
|
206
|
-
*/
|
|
207
|
-
style?: string;
|
|
208
|
-
/**
|
|
209
|
-
* For image editing: array of File objects to be edited
|
|
210
|
-
*/
|
|
211
|
-
images?: File[];
|
|
212
|
-
/**
|
|
213
|
-
* Custom base URL for the image generation API
|
|
214
|
-
* Can also be set via window.CALLAI_IMG_URL or process.env.CALLAI_IMG_URL
|
|
215
|
-
*/
|
|
216
|
-
imgUrl?: string;
|
|
217
|
-
/**
|
|
218
|
-
* Enable debug logging
|
|
219
|
-
*/
|
|
220
|
-
debug?: boolean;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* @deprecated Use ImageGenOptions instead
|
|
224
|
-
*/
|
|
225
|
-
export interface ImageEditOptions extends ImageGenOptions {
|
|
226
|
-
}
|
package/dist/types.js
DELETED
package/dist/utils.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for call-ai
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Recursively adds additionalProperties: false to all object types in a schema
|
|
6
|
-
* This is needed for OpenAI's strict schema validation in streaming mode
|
|
7
|
-
*/
|
|
8
|
-
export declare function recursivelyAddAdditionalProperties(schema: any): any;
|
package/dist/utils.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Utility functions for call-ai
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.recursivelyAddAdditionalProperties = recursivelyAddAdditionalProperties;
|
|
7
|
-
/**
|
|
8
|
-
* Recursively adds additionalProperties: false to all object types in a schema
|
|
9
|
-
* This is needed for OpenAI's strict schema validation in streaming mode
|
|
10
|
-
*/
|
|
11
|
-
function recursivelyAddAdditionalProperties(schema) {
|
|
12
|
-
// Clone to avoid modifying the original
|
|
13
|
-
const result = { ...schema };
|
|
14
|
-
// If this is an object type, ensure it has additionalProperties: false
|
|
15
|
-
if (result.type === "object") {
|
|
16
|
-
// Set additionalProperties if not already set
|
|
17
|
-
if (result.additionalProperties === undefined) {
|
|
18
|
-
result.additionalProperties = false;
|
|
19
|
-
}
|
|
20
|
-
// Process nested properties if they exist
|
|
21
|
-
if (result.properties) {
|
|
22
|
-
result.properties = { ...result.properties };
|
|
23
|
-
// Set required if not already set - OpenAI requires this for all nested objects
|
|
24
|
-
if (result.required === undefined) {
|
|
25
|
-
result.required = Object.keys(result.properties);
|
|
26
|
-
}
|
|
27
|
-
// Check each property
|
|
28
|
-
Object.keys(result.properties).forEach((key) => {
|
|
29
|
-
const prop = result.properties[key];
|
|
30
|
-
// If property is an object or array type, recursively process it
|
|
31
|
-
if (prop && typeof prop === "object") {
|
|
32
|
-
result.properties[key] = recursivelyAddAdditionalProperties(prop);
|
|
33
|
-
// For nested objects, ensure they also have all properties in their required field
|
|
34
|
-
if (prop.type === "object" && prop.properties) {
|
|
35
|
-
prop.required = Object.keys(prop.properties);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// Handle nested objects in arrays
|
|
42
|
-
if (result.type === "array" &&
|
|
43
|
-
result.items &&
|
|
44
|
-
typeof result.items === "object") {
|
|
45
|
-
result.items = recursivelyAddAdditionalProperties(result.items);
|
|
46
|
-
// If array items are objects, ensure they have all properties in required
|
|
47
|
-
if (result.items.type === "object" && result.items.properties) {
|
|
48
|
-
result.items.required = Object.keys(result.items.properties);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
}
|