@standardagents/openai 0.10.0-dev.ffffff
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.txt +48 -0
- package/dist/index.d.ts +177 -0
- package/dist/index.js +1218 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
PROPRIETARY SOFTWARE LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 FormKit Inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
UNLICENSED - DO NOT USE
|
|
6
|
+
|
|
7
|
+
This software and associated documentation files (the "Software") are the sole
|
|
8
|
+
and exclusive property of FormKit Inc. ("FormKit").
|
|
9
|
+
|
|
10
|
+
USE RESTRICTIONS
|
|
11
|
+
|
|
12
|
+
The Software is UNLICENSED and proprietary. NO PERMISSION is granted to use,
|
|
13
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
14
|
+
the Software, or to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
under any circumstances, without prior written authorization from FormKit Inc.
|
|
16
|
+
|
|
17
|
+
UNAUTHORIZED USE PROHIBITED
|
|
18
|
+
|
|
19
|
+
Any use of this Software without a valid, written license agreement signed by
|
|
20
|
+
authorized officers of FormKit Inc. is strictly prohibited and constitutes
|
|
21
|
+
unauthorized use and infringement of FormKit's intellectual property rights.
|
|
22
|
+
|
|
23
|
+
LICENSING INQUIRIES
|
|
24
|
+
|
|
25
|
+
Organizations interested in licensing this Software should contact:
|
|
26
|
+
enterprise@formkit.com
|
|
27
|
+
|
|
28
|
+
A written license agreement must be executed before any use of this Software
|
|
29
|
+
is authorized.
|
|
30
|
+
|
|
31
|
+
NO WARRANTY
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
36
|
+
FORMKIT INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
37
|
+
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
38
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
39
|
+
|
|
40
|
+
GOVERNING LAW
|
|
41
|
+
|
|
42
|
+
This license shall be governed by and construed in accordance with the laws
|
|
43
|
+
of the jurisdiction in which FormKit Inc. is incorporated, without regard to
|
|
44
|
+
its conflict of law provisions.
|
|
45
|
+
|
|
46
|
+
FormKit Inc.
|
|
47
|
+
https://formkit.com
|
|
48
|
+
enterprise@formkit.com
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { LLMProviderInterface, ProviderFactoryConfig, ModelCapabilities, ToolDefinition, ToolArgs, ToolTenvs, ProviderModelInfo, ProviderRequest, ProviderResponse, ProviderStreamChunk, InspectedRequest, ProviderFactoryWithOptions } from '@standardagents/spec';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* OpenAI provider options schema.
|
|
6
|
+
*
|
|
7
|
+
* Defines typed providerOptions for OpenAI models, providing
|
|
8
|
+
* TypeScript autocompletion and runtime validation.
|
|
9
|
+
*
|
|
10
|
+
* @see https://platform.openai.com/docs/api-reference/chat/create
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* OpenAI provider options schema.
|
|
16
|
+
*
|
|
17
|
+
* These options are passed directly to the OpenAI API and control
|
|
18
|
+
* various aspects of request handling and generation.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* providerOptions: {
|
|
23
|
+
* service_tier: 'default',
|
|
24
|
+
* user: 'user-123',
|
|
25
|
+
* seed: 42,
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare const openaiProviderOptions: z.ZodObject<{
|
|
30
|
+
service_tier: z.ZodOptional<z.ZodEnum<{
|
|
31
|
+
auto: "auto";
|
|
32
|
+
default: "default";
|
|
33
|
+
flex: "flex";
|
|
34
|
+
}>>;
|
|
35
|
+
user: z.ZodOptional<z.ZodString>;
|
|
36
|
+
seed: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
frequency_penalty: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
presence_penalty: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
top_logprobs: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
store: z.ZodOptional<z.ZodBoolean>;
|
|
42
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
43
|
+
}, z.core.$loose>;
|
|
44
|
+
/**
|
|
45
|
+
* TypeScript type for OpenAI provider options.
|
|
46
|
+
* Inferred from the Zod schema for type-safe usage.
|
|
47
|
+
*/
|
|
48
|
+
type OpenAIProviderOptions = z.infer<typeof openaiProviderOptions>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* OpenAI provider implementation for Standard Agents
|
|
52
|
+
*
|
|
53
|
+
* Uses the Responses API for all requests (stateless mode).
|
|
54
|
+
* Supports: gpt-4o, gpt-4-turbo, gpt-3.5-turbo, o1, o3, o4-mini, etc.
|
|
55
|
+
*/
|
|
56
|
+
declare class OpenAIProvider implements LLMProviderInterface {
|
|
57
|
+
readonly name = "openai";
|
|
58
|
+
readonly specificationVersion: "1";
|
|
59
|
+
private client;
|
|
60
|
+
private config;
|
|
61
|
+
/** Cache for models list to avoid repeated API calls */
|
|
62
|
+
private static modelsCache;
|
|
63
|
+
private static modelsCacheTime;
|
|
64
|
+
private static readonly CACHE_TTL;
|
|
65
|
+
constructor(config: ProviderFactoryConfig);
|
|
66
|
+
private getClient;
|
|
67
|
+
supportsModel(modelId: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Get the icon for this provider as a data URI.
|
|
70
|
+
* Always returns the OpenAI icon since all models are from OpenAI.
|
|
71
|
+
*/
|
|
72
|
+
getIcon(_modelId?: string): string;
|
|
73
|
+
/**
|
|
74
|
+
* Hardcoded capability mappings for OpenAI models.
|
|
75
|
+
* OpenAI doesn't provide a capabilities API, so these are manually maintained.
|
|
76
|
+
*/
|
|
77
|
+
private static readonly MODEL_CAPABILITIES;
|
|
78
|
+
/**
|
|
79
|
+
* Get capabilities for a specific model.
|
|
80
|
+
* Uses hardcoded mappings since OpenAI doesn't provide a capabilities API.
|
|
81
|
+
*/
|
|
82
|
+
getModelCapabilities(modelId: string): Promise<ModelCapabilities | null>;
|
|
83
|
+
/**
|
|
84
|
+
* Human-readable names and descriptions for models.
|
|
85
|
+
* Used to enrich API response data.
|
|
86
|
+
*/
|
|
87
|
+
private static readonly MODEL_METADATA;
|
|
88
|
+
/**
|
|
89
|
+
* Prefixes for chat-capable models (filter out embeddings, tts, whisper, dall-e, etc.)
|
|
90
|
+
*/
|
|
91
|
+
private static readonly CHAT_MODEL_PREFIXES;
|
|
92
|
+
/**
|
|
93
|
+
* Provider-embedded tools using defineTool().
|
|
94
|
+
* These are OpenAI's built-in tools that execute on OpenAI's servers.
|
|
95
|
+
* The execute function is a no-op since execution is handled by the provider.
|
|
96
|
+
*/
|
|
97
|
+
private static readonly TOOLS;
|
|
98
|
+
/**
|
|
99
|
+
* Which tools are available for each model.
|
|
100
|
+
*/
|
|
101
|
+
private static readonly MODEL_TOOLS;
|
|
102
|
+
/**
|
|
103
|
+
* Get tools embedded in this provider.
|
|
104
|
+
* These are OpenAI's built-in tools with tenv requirements.
|
|
105
|
+
*
|
|
106
|
+
* @param modelId - Optional filter to get tools available for a specific model
|
|
107
|
+
* @returns Record of tool name to tool definition
|
|
108
|
+
*/
|
|
109
|
+
getTools(modelId?: string): Record<string, ToolDefinition<any, ToolArgs | null, ToolTenvs | null>>;
|
|
110
|
+
/**
|
|
111
|
+
* Fetch models from OpenAI API with caching.
|
|
112
|
+
*/
|
|
113
|
+
private fetchModelsWithCache;
|
|
114
|
+
/**
|
|
115
|
+
* Check if a model ID is a chat-capable model.
|
|
116
|
+
*/
|
|
117
|
+
private isChatModel;
|
|
118
|
+
/**
|
|
119
|
+
* Get human-readable name for a model.
|
|
120
|
+
*/
|
|
121
|
+
private getModelName;
|
|
122
|
+
/**
|
|
123
|
+
* Get description for a model.
|
|
124
|
+
*/
|
|
125
|
+
private getModelDescription;
|
|
126
|
+
/**
|
|
127
|
+
* Map OpenAI model info to ProviderModelInfo.
|
|
128
|
+
*/
|
|
129
|
+
private mapToProviderModelInfo;
|
|
130
|
+
/**
|
|
131
|
+
* Get list of available models from OpenAI.
|
|
132
|
+
* Fetches from the OpenAI API with caching.
|
|
133
|
+
*
|
|
134
|
+
* @param filter - Optional search string to filter models by name/id
|
|
135
|
+
*/
|
|
136
|
+
getModels(filter?: string): Promise<ProviderModelInfo[]>;
|
|
137
|
+
generate(request: ProviderRequest): Promise<ProviderResponse>;
|
|
138
|
+
stream(request: ProviderRequest): Promise<AsyncIterable<ProviderStreamChunk>>;
|
|
139
|
+
private toProviderError;
|
|
140
|
+
/**
|
|
141
|
+
* Transform a ProviderRequest to OpenAI Responses API format for inspection.
|
|
142
|
+
* Returns the exact request body that would be sent to OpenAI, with base64 data truncated.
|
|
143
|
+
*/
|
|
144
|
+
inspectRequest(request: ProviderRequest): Promise<InspectedRequest>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* OpenAI provider factory for Standard Agents
|
|
149
|
+
*
|
|
150
|
+
* Includes typed providerOptions for OpenAI-specific configuration.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* import { defineModel } from '@standardagents/builder';
|
|
155
|
+
* import { openai } from '@standardagents/openai';
|
|
156
|
+
*
|
|
157
|
+
* export default defineModel({
|
|
158
|
+
* name: 'gpt-4o',
|
|
159
|
+
* provider: openai,
|
|
160
|
+
* model: 'gpt-4o',
|
|
161
|
+
* inputPrice: 2.5,
|
|
162
|
+
* outputPrice: 10,
|
|
163
|
+
* capabilities: {
|
|
164
|
+
* supportsImages: true,
|
|
165
|
+
* supportsToolCalls: true,
|
|
166
|
+
* supportsJsonMode: true,
|
|
167
|
+
* maxContextTokens: 128000,
|
|
168
|
+
* },
|
|
169
|
+
* providerOptions: {
|
|
170
|
+
* service_tier: 'default',
|
|
171
|
+
* },
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare const openai: ProviderFactoryWithOptions<typeof openaiProviderOptions>;
|
|
176
|
+
|
|
177
|
+
export { OpenAIProvider, type OpenAIProviderOptions, openai, openaiProviderOptions };
|