@agentic-kit/openai 1.0.3 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -2
- package/esm/index.js +627 -82
- package/esm/package.json +1 -0
- package/index.d.ts +206 -25
- package/index.js +629 -87
- package/package.json +14 -6
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/index.d.ts
CHANGED
|
@@ -1,37 +1,218 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
2
|
+
type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
3
|
+
interface JsonObject {
|
|
4
|
+
[key: string]: JsonValue | undefined;
|
|
5
|
+
}
|
|
6
|
+
interface JsonSchema {
|
|
7
|
+
additionalProperties?: boolean | JsonSchema;
|
|
8
|
+
description?: string;
|
|
9
|
+
enum?: JsonValue[];
|
|
10
|
+
items?: JsonSchema | JsonSchema[];
|
|
11
|
+
properties?: Record<string, JsonSchema>;
|
|
12
|
+
required?: string[];
|
|
13
|
+
type?: string | string[];
|
|
14
|
+
}
|
|
15
|
+
interface OpenAICompatibleCompat {
|
|
16
|
+
maxTokensField?: 'max_completion_tokens' | 'max_tokens';
|
|
17
|
+
reasoningFormat?: 'none' | 'openai';
|
|
18
|
+
supportsReasoningEffort?: boolean;
|
|
19
|
+
supportsStrictToolSchema?: boolean;
|
|
20
|
+
supportsUsageInStreaming?: boolean;
|
|
21
|
+
toolCallIdFormat?: 'passthrough' | 'safe64' | 'mistral9';
|
|
22
|
+
requiresToolResultName?: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface ModelDescriptor {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
api: string;
|
|
28
|
+
provider: string;
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
input: Array<'text' | 'image'>;
|
|
31
|
+
reasoning: boolean;
|
|
32
|
+
tools?: boolean;
|
|
33
|
+
contextWindow?: number;
|
|
34
|
+
maxOutputTokens?: number;
|
|
35
|
+
cost?: {
|
|
36
|
+
input?: number;
|
|
37
|
+
output?: number;
|
|
38
|
+
cacheRead?: number;
|
|
39
|
+
cacheWrite?: number;
|
|
40
|
+
};
|
|
41
|
+
headers?: Record<string, string>;
|
|
42
|
+
compat?: OpenAICompatibleCompat;
|
|
43
|
+
}
|
|
44
|
+
interface TextContent {
|
|
45
|
+
type: 'text';
|
|
46
|
+
text: string;
|
|
4
47
|
}
|
|
5
|
-
|
|
48
|
+
interface ImageContent {
|
|
49
|
+
type: 'image';
|
|
50
|
+
data: string;
|
|
51
|
+
mimeType: string;
|
|
52
|
+
}
|
|
53
|
+
interface ThinkingContent {
|
|
54
|
+
type: 'thinking';
|
|
55
|
+
thinking: string;
|
|
56
|
+
signature?: string;
|
|
57
|
+
}
|
|
58
|
+
interface ToolCallContent {
|
|
59
|
+
type: 'toolCall';
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
arguments: Record<string, JsonValue | undefined>;
|
|
63
|
+
rawArguments?: string;
|
|
64
|
+
}
|
|
65
|
+
type Message = {
|
|
66
|
+
role: 'user';
|
|
67
|
+
content: string | Array<TextContent | ImageContent>;
|
|
68
|
+
timestamp: number;
|
|
69
|
+
} | {
|
|
70
|
+
role: 'assistant';
|
|
71
|
+
content: Array<TextContent | ThinkingContent | ToolCallContent>;
|
|
72
|
+
api: string;
|
|
73
|
+
provider: string;
|
|
6
74
|
model: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
75
|
+
usage: Usage;
|
|
76
|
+
stopReason: 'stop' | 'length' | 'toolUse' | 'error' | 'aborted';
|
|
77
|
+
errorMessage?: string;
|
|
78
|
+
timestamp: number;
|
|
79
|
+
} | {
|
|
80
|
+
role: 'toolResult';
|
|
81
|
+
toolCallId: string;
|
|
82
|
+
toolName: string;
|
|
83
|
+
content: Array<TextContent | ImageContent>;
|
|
84
|
+
isError: boolean;
|
|
85
|
+
details?: unknown;
|
|
86
|
+
timestamp: number;
|
|
87
|
+
};
|
|
88
|
+
interface ToolDefinition {
|
|
89
|
+
name: string;
|
|
90
|
+
description: string;
|
|
91
|
+
parameters: JsonSchema;
|
|
92
|
+
}
|
|
93
|
+
interface Context {
|
|
94
|
+
systemPrompt?: string;
|
|
95
|
+
messages: Message[];
|
|
96
|
+
tools?: ToolDefinition[];
|
|
97
|
+
}
|
|
98
|
+
interface StreamOptions {
|
|
99
|
+
apiKey?: string;
|
|
100
|
+
headers?: Record<string, string>;
|
|
12
101
|
maxTokens?: number;
|
|
102
|
+
onPayload?: (payload: unknown) => void;
|
|
103
|
+
reasoning?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
104
|
+
signal?: AbortSignal;
|
|
105
|
+
temperature?: number;
|
|
106
|
+
}
|
|
107
|
+
interface Usage {
|
|
108
|
+
input: number;
|
|
109
|
+
output: number;
|
|
110
|
+
reasoning: number;
|
|
111
|
+
cacheRead: number;
|
|
112
|
+
cacheWrite: number;
|
|
113
|
+
totalTokens: number;
|
|
114
|
+
cost: {
|
|
115
|
+
input: number;
|
|
116
|
+
output: number;
|
|
117
|
+
cacheRead: number;
|
|
118
|
+
cacheWrite: number;
|
|
119
|
+
total: number;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
type AssistantMessage = Extract<Message, {
|
|
123
|
+
role: 'assistant';
|
|
124
|
+
}>;
|
|
125
|
+
type AssistantMessageEvent = {
|
|
126
|
+
type: 'start';
|
|
127
|
+
partial: AssistantMessage;
|
|
128
|
+
} | {
|
|
129
|
+
type: 'text_start';
|
|
130
|
+
contentIndex: number;
|
|
131
|
+
partial: AssistantMessage;
|
|
132
|
+
} | {
|
|
133
|
+
type: 'text_delta';
|
|
134
|
+
contentIndex: number;
|
|
135
|
+
delta: string;
|
|
136
|
+
partial: AssistantMessage;
|
|
137
|
+
} | {
|
|
138
|
+
type: 'text_end';
|
|
139
|
+
contentIndex: number;
|
|
140
|
+
content: string;
|
|
141
|
+
partial: AssistantMessage;
|
|
142
|
+
} | {
|
|
143
|
+
type: 'thinking_start';
|
|
144
|
+
contentIndex: number;
|
|
145
|
+
partial: AssistantMessage;
|
|
146
|
+
} | {
|
|
147
|
+
type: 'thinking_delta';
|
|
148
|
+
contentIndex: number;
|
|
149
|
+
delta: string;
|
|
150
|
+
partial: AssistantMessage;
|
|
151
|
+
} | {
|
|
152
|
+
type: 'thinking_end';
|
|
153
|
+
contentIndex: number;
|
|
154
|
+
content: string;
|
|
155
|
+
partial: AssistantMessage;
|
|
156
|
+
} | {
|
|
157
|
+
type: 'toolcall_start';
|
|
158
|
+
contentIndex: number;
|
|
159
|
+
partial: AssistantMessage;
|
|
160
|
+
} | {
|
|
161
|
+
type: 'toolcall_delta';
|
|
162
|
+
contentIndex: number;
|
|
163
|
+
delta: string;
|
|
164
|
+
partial: AssistantMessage;
|
|
165
|
+
} | {
|
|
166
|
+
type: 'toolcall_end';
|
|
167
|
+
contentIndex: number;
|
|
168
|
+
toolCall: ToolCallContent;
|
|
169
|
+
partial: AssistantMessage;
|
|
170
|
+
} | {
|
|
171
|
+
type: 'done';
|
|
172
|
+
reason: 'stop' | 'length' | 'toolUse';
|
|
173
|
+
message: AssistantMessage;
|
|
174
|
+
} | {
|
|
175
|
+
type: 'error';
|
|
176
|
+
reason: 'error' | 'aborted';
|
|
177
|
+
error: AssistantMessage;
|
|
178
|
+
};
|
|
179
|
+
interface AssistantMessageEventStream extends AsyncIterable<AssistantMessageEvent> {
|
|
180
|
+
result(): Promise<AssistantMessage>;
|
|
181
|
+
}
|
|
182
|
+
interface OpenAIModelDefinition extends ModelDescriptor {
|
|
13
183
|
}
|
|
14
184
|
export interface OpenAIOptions {
|
|
15
|
-
apiKey
|
|
16
|
-
/** Override base URL — works with any OpenAI-compatible API (LM Studio, vLLM, Together, etc.) */
|
|
185
|
+
apiKey?: string;
|
|
17
186
|
baseUrl?: string;
|
|
18
|
-
|
|
187
|
+
compat?: OpenAICompatibleCompat;
|
|
188
|
+
contextWindow?: number;
|
|
189
|
+
defaultInput?: Array<'text' | 'image'>;
|
|
19
190
|
defaultModel?: string;
|
|
20
|
-
|
|
191
|
+
headers?: Record<string, string>;
|
|
21
192
|
maxTokens?: number;
|
|
193
|
+
provider?: string;
|
|
194
|
+
reasoning?: boolean;
|
|
195
|
+
tools?: boolean;
|
|
22
196
|
}
|
|
197
|
+
export declare const OPENAI_COMPATIBLE_MODELS: OpenAIModelDefinition[];
|
|
23
198
|
export declare class OpenAIAdapter {
|
|
24
|
-
readonly
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
private
|
|
34
|
-
private
|
|
35
|
-
private
|
|
199
|
+
readonly api = "openai-compatible";
|
|
200
|
+
readonly provider: string;
|
|
201
|
+
readonly name: string;
|
|
202
|
+
private readonly apiKey?;
|
|
203
|
+
private readonly baseUrl;
|
|
204
|
+
private readonly compat;
|
|
205
|
+
private readonly defaultHeaders?;
|
|
206
|
+
private readonly defaultInput;
|
|
207
|
+
private readonly defaultMaxTokens;
|
|
208
|
+
private readonly defaultModel;
|
|
209
|
+
private readonly defaultReasoning;
|
|
210
|
+
private readonly defaultTools;
|
|
211
|
+
private readonly defaultContextWindow?;
|
|
212
|
+
constructor(options?: OpenAIOptions | string);
|
|
213
|
+
createModel(modelId: string, overrides?: Partial<ModelDescriptor>): ModelDescriptor;
|
|
214
|
+
listModels(): Promise<Array<ModelDescriptor | string>>;
|
|
215
|
+
stream(model: ModelDescriptor, context: Context, options?: StreamOptions): AssistantMessageEventStream;
|
|
216
|
+
private buildHeaders;
|
|
36
217
|
}
|
|
37
218
|
export default OpenAIAdapter;
|