@agentic-kit/openai 0.1.0 → 1.2.0

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.
@@ -0,0 +1 @@
1
+ {"type":"module"}
package/index.d.ts CHANGED
@@ -1,37 +1,217 @@
1
- export interface ChatMessage {
2
- role: 'system' | 'user' | 'assistant';
3
- content: string;
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
- export interface GenerateInput {
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
- prompt?: string;
8
- messages?: ChatMessage[];
9
- system?: string;
10
- stream?: boolean;
11
- temperature?: number;
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
+ cacheRead: number;
111
+ cacheWrite: number;
112
+ totalTokens: number;
113
+ cost: {
114
+ input: number;
115
+ output: number;
116
+ cacheRead: number;
117
+ cacheWrite: number;
118
+ total: number;
119
+ };
120
+ }
121
+ type AssistantMessage = Extract<Message, {
122
+ role: 'assistant';
123
+ }>;
124
+ type AssistantMessageEvent = {
125
+ type: 'start';
126
+ partial: AssistantMessage;
127
+ } | {
128
+ type: 'text_start';
129
+ contentIndex: number;
130
+ partial: AssistantMessage;
131
+ } | {
132
+ type: 'text_delta';
133
+ contentIndex: number;
134
+ delta: string;
135
+ partial: AssistantMessage;
136
+ } | {
137
+ type: 'text_end';
138
+ contentIndex: number;
139
+ content: string;
140
+ partial: AssistantMessage;
141
+ } | {
142
+ type: 'thinking_start';
143
+ contentIndex: number;
144
+ partial: AssistantMessage;
145
+ } | {
146
+ type: 'thinking_delta';
147
+ contentIndex: number;
148
+ delta: string;
149
+ partial: AssistantMessage;
150
+ } | {
151
+ type: 'thinking_end';
152
+ contentIndex: number;
153
+ content: string;
154
+ partial: AssistantMessage;
155
+ } | {
156
+ type: 'toolcall_start';
157
+ contentIndex: number;
158
+ partial: AssistantMessage;
159
+ } | {
160
+ type: 'toolcall_delta';
161
+ contentIndex: number;
162
+ delta: string;
163
+ partial: AssistantMessage;
164
+ } | {
165
+ type: 'toolcall_end';
166
+ contentIndex: number;
167
+ toolCall: ToolCallContent;
168
+ partial: AssistantMessage;
169
+ } | {
170
+ type: 'done';
171
+ reason: 'stop' | 'length' | 'toolUse';
172
+ message: AssistantMessage;
173
+ } | {
174
+ type: 'error';
175
+ reason: 'error' | 'aborted';
176
+ error: AssistantMessage;
177
+ };
178
+ interface AssistantMessageEventStream extends AsyncIterable<AssistantMessageEvent> {
179
+ result(): Promise<AssistantMessage>;
180
+ }
181
+ interface OpenAIModelDefinition extends ModelDescriptor {
13
182
  }
14
183
  export interface OpenAIOptions {
15
- apiKey: string;
16
- /** Override base URL — works with any OpenAI-compatible API (LM Studio, vLLM, Together, etc.) */
184
+ apiKey?: string;
17
185
  baseUrl?: string;
18
- /** Default model when GenerateInput.model is not set */
186
+ compat?: OpenAICompatibleCompat;
187
+ contextWindow?: number;
188
+ defaultInput?: Array<'text' | 'image'>;
19
189
  defaultModel?: string;
20
- /** Default max_tokens */
190
+ headers?: Record<string, string>;
21
191
  maxTokens?: number;
192
+ provider?: string;
193
+ reasoning?: boolean;
194
+ tools?: boolean;
22
195
  }
196
+ export declare const OPENAI_COMPATIBLE_MODELS: OpenAIModelDefinition[];
23
197
  export declare class OpenAIAdapter {
24
- readonly name = "openai";
25
- private apiKey;
26
- private baseUrl;
27
- private defaultModel;
28
- private defaultMaxTokens;
29
- constructor(options: OpenAIOptions | string);
30
- generate(input: GenerateInput): Promise<string>;
31
- generateStreaming(input: GenerateInput, onChunk: (chunk: string) => void): Promise<void>;
32
- listModels(): Promise<string[]>;
33
- private _request;
34
- private _buildMessages;
35
- private _stream;
198
+ readonly api = "openai-compatible";
199
+ readonly provider: string;
200
+ readonly name: string;
201
+ private readonly apiKey?;
202
+ private readonly baseUrl;
203
+ private readonly compat;
204
+ private readonly defaultHeaders?;
205
+ private readonly defaultInput;
206
+ private readonly defaultMaxTokens;
207
+ private readonly defaultModel;
208
+ private readonly defaultReasoning;
209
+ private readonly defaultTools;
210
+ private readonly defaultContextWindow?;
211
+ constructor(options?: OpenAIOptions | string);
212
+ createModel(modelId: string, overrides?: Partial<ModelDescriptor>): ModelDescriptor;
213
+ listModels(): Promise<Array<ModelDescriptor | string>>;
214
+ stream(model: ModelDescriptor, context: Context, options?: StreamOptions): AssistantMessageEventStream;
215
+ private buildHeaders;
36
216
  }
37
217
  export default OpenAIAdapter;