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/types.d.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
export type Falsy = false | null | undefined | 0 | "";
|
|
2
|
+
export interface OriginalError {
|
|
3
|
+
readonly originalError: Error;
|
|
4
|
+
readonly refreshError: Error;
|
|
5
|
+
readonly status: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ContentItem {
|
|
8
|
+
readonly type: "text" | "image_url";
|
|
9
|
+
readonly text?: string;
|
|
10
|
+
readonly image_url?: {
|
|
11
|
+
readonly url: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface Message {
|
|
15
|
+
readonly role: "user" | "system" | "assistant";
|
|
16
|
+
readonly content: string | ContentItem[];
|
|
17
|
+
}
|
|
18
|
+
export interface ResponseMeta {
|
|
19
|
+
model: string;
|
|
20
|
+
endpoint?: string;
|
|
21
|
+
timing: {
|
|
22
|
+
readonly startTime: number;
|
|
23
|
+
endTime?: number;
|
|
24
|
+
duration?: number;
|
|
25
|
+
};
|
|
26
|
+
rawResponse?: ModelId | string;
|
|
27
|
+
}
|
|
28
|
+
export interface ModelId {
|
|
29
|
+
readonly model: string;
|
|
30
|
+
readonly id: string;
|
|
31
|
+
}
|
|
32
|
+
export interface Schema {
|
|
33
|
+
readonly name?: string;
|
|
34
|
+
readonly properties: Record<string, unknown>;
|
|
35
|
+
readonly required?: string[];
|
|
36
|
+
readonly additionalProperties?: boolean;
|
|
37
|
+
readonly [key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
export interface ToolUseType {
|
|
40
|
+
readonly type: "tool_use";
|
|
41
|
+
readonly input: string;
|
|
42
|
+
readonly tool_calls: OpenAIFunctionCall[];
|
|
43
|
+
}
|
|
44
|
+
export declare function isToolUseType(obj: unknown): obj is ToolUseType;
|
|
45
|
+
export interface ToolUseResponse {
|
|
46
|
+
readonly tool_use: {
|
|
47
|
+
readonly input: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export declare function isToolUseResponse(obj: unknown): obj is ToolUseResponse;
|
|
51
|
+
export interface AIResult {
|
|
52
|
+
choices: {
|
|
53
|
+
message: {
|
|
54
|
+
content?: string;
|
|
55
|
+
function_call: string | ToolUseType | ToolUseResponse;
|
|
56
|
+
tool_calls?: string;
|
|
57
|
+
};
|
|
58
|
+
text?: string;
|
|
59
|
+
}[];
|
|
60
|
+
}
|
|
61
|
+
export interface OpenAIFunctionCall {
|
|
62
|
+
readonly type: "function";
|
|
63
|
+
readonly function: {
|
|
64
|
+
readonly arguments?: string;
|
|
65
|
+
readonly name?: string;
|
|
66
|
+
readonly description?: string;
|
|
67
|
+
readonly parameters?: RequestSchema | ProcessedSchema;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export declare function isOpenAIArray(obj: unknown): obj is OpenAIFunctionCall[];
|
|
71
|
+
export interface RequestSchema {
|
|
72
|
+
model?: string;
|
|
73
|
+
name?: string;
|
|
74
|
+
type: "object";
|
|
75
|
+
description?: string;
|
|
76
|
+
properties?: unknown;
|
|
77
|
+
required?: unknown[];
|
|
78
|
+
parameters?: RequestSchema;
|
|
79
|
+
additionalProperties?: unknown;
|
|
80
|
+
}
|
|
81
|
+
export interface SchemaAIMessageRequest {
|
|
82
|
+
model: string;
|
|
83
|
+
messages: Message[];
|
|
84
|
+
max_tokens: number;
|
|
85
|
+
temperature: number;
|
|
86
|
+
top_p: number;
|
|
87
|
+
stream: boolean;
|
|
88
|
+
response_format?: SchemaAIJsonSchemaRequest["response_format"] | SchemaAIJsonObjectRequest["response_format"];
|
|
89
|
+
[key: string]: unknown;
|
|
90
|
+
}
|
|
91
|
+
export interface ProcessedSchema {
|
|
92
|
+
properties: Record<string, unknown>;
|
|
93
|
+
items?: ProcessedSchema;
|
|
94
|
+
[key: string]: unknown;
|
|
95
|
+
}
|
|
96
|
+
export interface SchemaType {
|
|
97
|
+
readonly type: string;
|
|
98
|
+
}
|
|
99
|
+
export interface SchemaDescription {
|
|
100
|
+
readonly description: string;
|
|
101
|
+
}
|
|
102
|
+
export interface SchemaAIJsonObjectRequest {
|
|
103
|
+
response_format: {
|
|
104
|
+
type: "json_object";
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export interface SchemaAIJsonSchemaRequest {
|
|
108
|
+
response_format: {
|
|
109
|
+
type: "json_schema";
|
|
110
|
+
json_schema: {
|
|
111
|
+
name: string;
|
|
112
|
+
strict?: boolean;
|
|
113
|
+
schema: ProcessedSchema;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
interface SchemaAIToolRequest {
|
|
118
|
+
tools: OpenAIFunctionCall[];
|
|
119
|
+
tool_choice: OpenAIFunctionCall;
|
|
120
|
+
}
|
|
121
|
+
interface SchemaAISimpleMsg {
|
|
122
|
+
readonly messages: Message[];
|
|
123
|
+
}
|
|
124
|
+
export interface ModelStrategy {
|
|
125
|
+
readonly name: string;
|
|
126
|
+
readonly prepareRequest: (schema: Schema | Falsy, messages: Message[]) => SchemaAISimpleMsg | SchemaAIMessageRequest | SchemaAIToolRequest | SchemaAIJsonSchemaRequest | SchemaAIJsonObjectRequest;
|
|
127
|
+
readonly processResponse: (content: string | ToolUseType | ToolUseResponse | OpenAIFunctionCall[]) => string;
|
|
128
|
+
readonly shouldForceStream?: boolean;
|
|
129
|
+
}
|
|
130
|
+
export interface CallAIErrorParams {
|
|
131
|
+
readonly message: string;
|
|
132
|
+
readonly status: number;
|
|
133
|
+
readonly statusText?: string;
|
|
134
|
+
readonly details?: unknown;
|
|
135
|
+
readonly contentType?: string;
|
|
136
|
+
readonly statusCode?: number;
|
|
137
|
+
readonly response?: {
|
|
138
|
+
readonly status: number;
|
|
139
|
+
};
|
|
140
|
+
readonly partialContent?: string;
|
|
141
|
+
readonly name?: string;
|
|
142
|
+
readonly cause?: unknown;
|
|
143
|
+
readonly originalError?: CallAIErrorParams | Error;
|
|
144
|
+
readonly refreshError?: unknown;
|
|
145
|
+
readonly errorType?: string;
|
|
146
|
+
}
|
|
147
|
+
export declare class CallAIError extends Error {
|
|
148
|
+
readonly message: string;
|
|
149
|
+
readonly status: number;
|
|
150
|
+
readonly statusText?: string;
|
|
151
|
+
readonly details?: unknown;
|
|
152
|
+
readonly contentType?: string;
|
|
153
|
+
readonly originalError?: CallAIErrorParams | Error;
|
|
154
|
+
readonly refreshError?: unknown;
|
|
155
|
+
readonly errorType?: string;
|
|
156
|
+
readonly partialContent?: string;
|
|
157
|
+
constructor(params: CallAIErrorParams);
|
|
158
|
+
}
|
|
159
|
+
export type SchemaStrategyType = "json_schema" | "tool_mode" | "system_message" | "none";
|
|
160
|
+
export interface SchemaStrategy {
|
|
161
|
+
readonly strategy: SchemaStrategyType;
|
|
162
|
+
readonly model: string;
|
|
163
|
+
readonly prepareRequest: ModelStrategy["prepareRequest"];
|
|
164
|
+
readonly processResponse: ModelStrategy["processResponse"];
|
|
165
|
+
readonly shouldForceStream: boolean;
|
|
166
|
+
}
|
|
167
|
+
export type StreamResponse = AsyncGenerator<string, string, unknown>;
|
|
168
|
+
export type ThenableStreamResponse = AsyncGenerator<string, string, unknown> & Promise<StreamResponse>;
|
|
169
|
+
export interface CallAIOptions {
|
|
170
|
+
readonly apiKey?: string;
|
|
171
|
+
readonly model?: string;
|
|
172
|
+
readonly endpoint?: string;
|
|
173
|
+
readonly chatUrl?: string;
|
|
174
|
+
stream?: boolean;
|
|
175
|
+
refreshToken?: string;
|
|
176
|
+
readonly updateRefreshToken?: (currentToken: string) => Promise<string>;
|
|
177
|
+
readonly schema?: Schema | null;
|
|
178
|
+
readonly modalities?: string[];
|
|
179
|
+
readonly skipRetry?: boolean;
|
|
180
|
+
readonly skipRefresh?: boolean;
|
|
181
|
+
readonly debug?: boolean;
|
|
182
|
+
readonly referer?: string;
|
|
183
|
+
readonly title?: string;
|
|
184
|
+
readonly schemaStrategy?: SchemaStrategy;
|
|
185
|
+
readonly maxTokens?: number;
|
|
186
|
+
temperature?: number;
|
|
187
|
+
readonly topP?: number;
|
|
188
|
+
response_format?: {
|
|
189
|
+
type: "json_object";
|
|
190
|
+
};
|
|
191
|
+
readonly mock?: Mocks;
|
|
192
|
+
[key: string]: unknown;
|
|
193
|
+
}
|
|
194
|
+
export interface Mocks {
|
|
195
|
+
readonly fetch?: typeof fetch;
|
|
196
|
+
}
|
|
197
|
+
export interface AIResponse {
|
|
198
|
+
readonly text: string;
|
|
199
|
+
readonly usage?: {
|
|
200
|
+
readonly promptTokens: number;
|
|
201
|
+
readonly completionTokens: number;
|
|
202
|
+
readonly totalTokens: number;
|
|
203
|
+
};
|
|
204
|
+
readonly model: string;
|
|
205
|
+
}
|
|
206
|
+
export interface ImageResponse {
|
|
207
|
+
readonly created: number;
|
|
208
|
+
readonly data: {
|
|
209
|
+
readonly b64_json: string;
|
|
210
|
+
readonly url?: string;
|
|
211
|
+
readonly revised_prompt?: string;
|
|
212
|
+
}[];
|
|
213
|
+
}
|
|
214
|
+
export interface ImageGenOptions {
|
|
215
|
+
readonly apiKey?: string;
|
|
216
|
+
readonly model?: string;
|
|
217
|
+
readonly size?: string;
|
|
218
|
+
readonly quality?: string;
|
|
219
|
+
readonly style?: string;
|
|
220
|
+
readonly images?: File[];
|
|
221
|
+
readonly imgUrl?: string;
|
|
222
|
+
readonly debug?: boolean;
|
|
223
|
+
readonly mock?: Mocks;
|
|
224
|
+
}
|
|
225
|
+
export type ImageEditOptions = ImageGenOptions;
|
|
226
|
+
export {};
|
package/types.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function isToolUseType(obj) {
|
|
2
|
+
return !!obj && obj.type === "tool_use";
|
|
3
|
+
}
|
|
4
|
+
export function isToolUseResponse(obj) {
|
|
5
|
+
return !!obj && obj.tool_use !== undefined;
|
|
6
|
+
}
|
|
7
|
+
export function isOpenAIArray(obj) {
|
|
8
|
+
return Array.isArray(obj) && obj.length > 0 && obj[0].function !== undefined;
|
|
9
|
+
}
|
|
10
|
+
export class CallAIError extends Error {
|
|
11
|
+
message;
|
|
12
|
+
status;
|
|
13
|
+
statusText;
|
|
14
|
+
details;
|
|
15
|
+
contentType;
|
|
16
|
+
originalError;
|
|
17
|
+
refreshError;
|
|
18
|
+
errorType;
|
|
19
|
+
partialContent;
|
|
20
|
+
constructor(params) {
|
|
21
|
+
super(params.message);
|
|
22
|
+
this.message = params.message;
|
|
23
|
+
this.status = params.status;
|
|
24
|
+
this.statusText = params.statusText;
|
|
25
|
+
this.details = params.details;
|
|
26
|
+
this.contentType = params.contentType;
|
|
27
|
+
this.originalError = params.originalError;
|
|
28
|
+
this.partialContent = params.partialContent;
|
|
29
|
+
this.refreshError = params.refreshError;
|
|
30
|
+
this.errorType = params.errorType;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=types.js.map
|
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../jsr/types.ts"],"names":[],"mappings":"AAgGA,MAAM,UAAU,aAAa,CAAC,GAAY,EAAsB;IAC9D,OAAO,CAAC,CAAC,GAAG,IAAK,GAAmB,CAAC,IAAI,KAAK,UAAU,CAAC;AAAA,CAC1D;AAOD,MAAM,UAAU,iBAAiB,CAAC,GAAY,EAA0B;IACtE,OAAO,CAAC,CAAC,GAAG,IAAK,GAAuB,CAAC,QAAQ,KAAK,SAAS,CAAC;AAAA,CACjE;AAuBD,MAAM,UAAU,aAAa,CAAC,GAAY,EAA+B;IACvE,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC;AAAA,CAC9E;AA+FD,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,UAAU,CAAU;IACpB,OAAO,CAAW;IAClB,WAAW,CAAU;IACrB,aAAa,CAA6B;IAC1C,YAAY,CAAW;IACvB,SAAS,CAAU;IACnB,cAAc,CAAU;IAEjC,YAAY,MAAyB,EAAE;QACrC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;QAC1C,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;QAC5C,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IAAA,CACnC;CACF"}
|
package/utils.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ProcessedSchema } from "./types.js";
|
|
2
|
+
export declare function recursivelyAddAdditionalProperties(schema: ProcessedSchema): ProcessedSchema;
|
|
3
|
+
declare class CallAIEnv {
|
|
4
|
+
envFromProcess(): Record<string, string>;
|
|
5
|
+
envFromImportMeta(): Record<string, string>;
|
|
6
|
+
envFromWindow(): Record<string, string>;
|
|
7
|
+
setup(): Record<string, string>[];
|
|
8
|
+
readonly envs: Record<string, string>[];
|
|
9
|
+
private getEnv;
|
|
10
|
+
overrideEnv(env: Record<string, string>): void;
|
|
11
|
+
readonly def: {
|
|
12
|
+
readonly CALLAI_REFRESH_ENDPOINT: string;
|
|
13
|
+
};
|
|
14
|
+
get CALLAI_IMG_URL(): string | undefined;
|
|
15
|
+
get CALLAI_CHAT_URL(): string | undefined;
|
|
16
|
+
get CALLAI_API_KEY(): string;
|
|
17
|
+
get CALLAI_REFRESH_ENDPOINT(): string | undefined;
|
|
18
|
+
get CALL_AI_REFRESH_TOKEN(): string | undefined;
|
|
19
|
+
get CALLAI_REKEY_ENDPOINT(): string | undefined;
|
|
20
|
+
get CALL_AI_KEY_TOKEN(): string | undefined;
|
|
21
|
+
get CALLAI_REFRESH_TOKEN(): string | undefined;
|
|
22
|
+
get CALLAI_DEBUG(): boolean;
|
|
23
|
+
get NODE_ENV(): string | undefined;
|
|
24
|
+
}
|
|
25
|
+
export declare const callAiEnv: CallAIEnv;
|
|
26
|
+
export declare function entriesHeaders(headers: Headers): [string, string][];
|
|
27
|
+
export declare function callAiFetch(options: {
|
|
28
|
+
mock?: {
|
|
29
|
+
fetch?: typeof fetch;
|
|
30
|
+
};
|
|
31
|
+
}): typeof fetch;
|
|
32
|
+
export {};
|
package/utils.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export function recursivelyAddAdditionalProperties(schema) {
|
|
2
|
+
const result = { ...schema };
|
|
3
|
+
if (result.type === "object") {
|
|
4
|
+
if (result.additionalProperties === undefined) {
|
|
5
|
+
result.additionalProperties = false;
|
|
6
|
+
}
|
|
7
|
+
if (result.properties) {
|
|
8
|
+
result.properties = { ...result.properties };
|
|
9
|
+
if (result.required === undefined) {
|
|
10
|
+
result.required = Object.keys(result.properties);
|
|
11
|
+
}
|
|
12
|
+
Object.keys(result.properties).forEach((key) => {
|
|
13
|
+
const prop = result.properties[key];
|
|
14
|
+
if (prop && typeof prop === "object") {
|
|
15
|
+
const oprop = prop;
|
|
16
|
+
result.properties[key] = recursivelyAddAdditionalProperties(oprop);
|
|
17
|
+
if (oprop.type === "object" && oprop.properties) {
|
|
18
|
+
oprop.required = Object.keys(oprop.properties);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (result.type === "array" && result.items && typeof result.items === "object") {
|
|
25
|
+
result.items = recursivelyAddAdditionalProperties(result.items);
|
|
26
|
+
if (result.items.type === "object" && result.items.properties) {
|
|
27
|
+
result.items.required = Object.keys(result.items.properties);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
class CallAIEnv {
|
|
33
|
+
envFromProcess() {
|
|
34
|
+
return globalThis.process?.env || {};
|
|
35
|
+
}
|
|
36
|
+
envFromImportMeta() {
|
|
37
|
+
return import.meta?.env || {};
|
|
38
|
+
}
|
|
39
|
+
envFromWindow() {
|
|
40
|
+
return globalThis.window?.env || {};
|
|
41
|
+
}
|
|
42
|
+
setup() {
|
|
43
|
+
const envs = [];
|
|
44
|
+
try {
|
|
45
|
+
envs.push(this.envFromProcess());
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
/* no-op */
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
envs.push(this.envFromImportMeta());
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
/* no-op */
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
envs.push(this.envFromWindow());
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
/* no-op */
|
|
61
|
+
}
|
|
62
|
+
return envs;
|
|
63
|
+
}
|
|
64
|
+
envs = this.setup();
|
|
65
|
+
getEnv(key) {
|
|
66
|
+
for (const prefix of ["", "VITE_"]) {
|
|
67
|
+
for (const env of this.envs) {
|
|
68
|
+
if (env && env[prefix + key]) {
|
|
69
|
+
return env[prefix + key];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
overrideEnv(env) {
|
|
76
|
+
this.envs.splice(0, this.envs.length, env);
|
|
77
|
+
}
|
|
78
|
+
def = {
|
|
79
|
+
get CALLAI_REFRESH_ENDPOINT() {
|
|
80
|
+
return callAiEnv.CALLAI_REFRESH_ENDPOINT ?? "https://vibecode.garden";
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
get CALLAI_IMG_URL() {
|
|
84
|
+
return this.getEnv("CALLAI_IMG_URL");
|
|
85
|
+
}
|
|
86
|
+
get CALLAI_CHAT_URL() {
|
|
87
|
+
return this.getEnv("CALLAI_CHAT_URL");
|
|
88
|
+
}
|
|
89
|
+
get CALLAI_API_KEY() {
|
|
90
|
+
const x = this.getEnv("CALLAI_API_KEY") ??
|
|
91
|
+
this.getEnv("OPENROUTER_API_KEY") ??
|
|
92
|
+
this.envFromWindow()?.callAi?.API_KEY ??
|
|
93
|
+
this.getEnv("LOW_BALANCE_OPENROUTER_API_KEY");
|
|
94
|
+
return x;
|
|
95
|
+
}
|
|
96
|
+
get CALLAI_REFRESH_ENDPOINT() {
|
|
97
|
+
return this.getEnv("CALLAI_REFRESH_ENDPOINT");
|
|
98
|
+
}
|
|
99
|
+
get CALL_AI_REFRESH_TOKEN() {
|
|
100
|
+
return this.getEnv("CALL_AI_REFRESH_TOKEN");
|
|
101
|
+
}
|
|
102
|
+
get CALLAI_REKEY_ENDPOINT() {
|
|
103
|
+
return this.getEnv("CALLAI_REKEY_ENDPOINT");
|
|
104
|
+
}
|
|
105
|
+
get CALL_AI_KEY_TOKEN() {
|
|
106
|
+
return this.getEnv("CALL_AI_KEY_TOKEN");
|
|
107
|
+
}
|
|
108
|
+
get CALLAI_REFRESH_TOKEN() {
|
|
109
|
+
return this.getEnv("CALLAI_REFRESH_TOKEN");
|
|
110
|
+
}
|
|
111
|
+
get CALLAI_DEBUG() {
|
|
112
|
+
return !!this.getEnv("CALLAI_DEBUG");
|
|
113
|
+
}
|
|
114
|
+
get NODE_ENV() {
|
|
115
|
+
return this.getEnv("NODE_ENV");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export const callAiEnv = new CallAIEnv();
|
|
119
|
+
export function entriesHeaders(headers) {
|
|
120
|
+
const entries = [];
|
|
121
|
+
headers.forEach((value, key) => {
|
|
122
|
+
entries.push([key, value]);
|
|
123
|
+
});
|
|
124
|
+
return entries;
|
|
125
|
+
}
|
|
126
|
+
export function callAiFetch(options) {
|
|
127
|
+
return options.mock?.fetch || globalThis.fetch;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=utils.js.map
|
package/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../jsr/utils.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,kCAAkC,CAAC,MAAuB,EAAmB;IAE3F,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAG7B,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAE7B,IAAI,MAAM,CAAC,oBAAoB,KAAK,SAAS,EAAE,CAAC;YAC9C,MAAM,CAAC,oBAAoB,GAAG,KAAK,CAAC;QACtC,CAAC;QAGD,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,MAAM,CAAC,UAAU,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;YAG7C,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAClC,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACnD,CAAC;YAGD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CA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E,CAAC;AAEzC,MAAM,UAAU,cAAc,CAAC,OAAgB,EAAE;IAC/C,MAAM,OAAO,GAAuB,EAAE,CAAC;IACvC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC;QAC9B,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAAA,CAC5B,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AAAA,CAChB;AAED,MAAM,UAAU,WAAW,CAAC,OAA4C,EAAgB;IACtF,OAAO,OAAO,CAAC,IAAI,EAAE,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC;AAAA,CAChD"}
|
package/version.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PACKAGE_VERSION = "0.0.1";
|
package/version.js
ADDED
package/version.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../jsr/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC"}
|
package/dist/api-core.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core API implementation for call-ai
|
|
3
|
-
*/
|
|
4
|
-
import { CallAIOptions, Message, StreamResponse, ThenableStreamResponse } from "./types";
|
|
5
|
-
declare const PACKAGE_VERSION: any;
|
|
6
|
-
/**
|
|
7
|
-
* Main API interface function for making AI API calls
|
|
8
|
-
*
|
|
9
|
-
* @param prompt The prompt to send to the AI, either a string or a Message array
|
|
10
|
-
* @param options Configuration options for the API call
|
|
11
|
-
* @returns Promise<string> for non-streaming or AsyncGenerator for streaming
|
|
12
|
-
*/
|
|
13
|
-
declare function callAi(prompt: string | Message[], options?: CallAIOptions): ThenableStreamResponse | Promise<string>;
|
|
14
|
-
/**
|
|
15
|
-
* Buffers the results of a streaming generator into a single string
|
|
16
|
-
*
|
|
17
|
-
* @param generator The streaming generator returned by callAi
|
|
18
|
-
* @returns Promise<string> with the complete response
|
|
19
|
-
*/
|
|
20
|
-
declare function bufferStreamingResults(generator: AsyncGenerator<string, string, unknown>): Promise<string>;
|
|
21
|
-
/**
|
|
22
|
-
* Create a proxy that acts both as a Promise and an AsyncGenerator for backward compatibility
|
|
23
|
-
* @internal This is for internal use only, not part of public API
|
|
24
|
-
*/
|
|
25
|
-
declare function createBackwardCompatStreamingProxy(promise: Promise<StreamResponse>): ThenableStreamResponse;
|
|
26
|
-
/**
|
|
27
|
-
* Validates and prepares request parameters for API calls
|
|
28
|
-
*
|
|
29
|
-
* @param prompt User prompt (string or Message array)
|
|
30
|
-
* @param options Call options
|
|
31
|
-
* @returns Validated and processed parameters including apiKey
|
|
32
|
-
*/
|
|
33
|
-
declare function prepareRequestParams(prompt: string | Message[], options?: CallAIOptions): {
|
|
34
|
-
messages: Message[] | {
|
|
35
|
-
role: string;
|
|
36
|
-
content: string;
|
|
37
|
-
}[];
|
|
38
|
-
apiKey: any;
|
|
39
|
-
};
|
|
40
|
-
export { callAi, bufferStreamingResults, createBackwardCompatStreamingProxy, prepareRequestParams, PACKAGE_VERSION, };
|
package/dist/api.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core API implementation for call-ai
|
|
3
|
-
*/
|
|
4
|
-
import { CallAIOptions, Message, StreamResponse } from "./types";
|
|
5
|
-
import { getMeta } from "./response-metadata";
|
|
6
|
-
export { getMeta };
|
|
7
|
-
/**
|
|
8
|
-
* Make an AI API call with the given options
|
|
9
|
-
* @param prompt User prompt as string or an array of message objects
|
|
10
|
-
* @param options Configuration options including optional schema for structured output
|
|
11
|
-
* @returns A Promise that resolves to the complete response string when streaming is disabled,
|
|
12
|
-
* or a Promise that resolves to an AsyncGenerator when streaming is enabled.
|
|
13
|
-
* The AsyncGenerator yields partial responses as they arrive.
|
|
14
|
-
*/
|
|
15
|
-
export declare function callAi(prompt: string | Message[], options?: CallAIOptions): Promise<string | StreamResponse>;
|