@ruixutong.manee/agent-framework 1.0.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,218 @@
1
+ import type OpenAI from 'openai';
2
+ import type { ClientOptions } from 'openai';
3
+ import type { FileObject } from 'openai/resources/files';
4
+ import type { Response as OpenAIResponse, ResponseCreateParamsNonStreaming } from 'openai/resources/responses/responses';
5
+ import type { AgentBaseSystemMessage, AgentProtocol, AgentTextPart, JsonObject } from '../../agent/types';
6
+ /** 与 OpenAI Files 对齐的上传选项;当前视觉流程仅需要 `user_data`。 */
7
+ export interface OpenAIFileUploadOptions {
8
+ purpose?: 'user_data';
9
+ }
10
+ /** Files API 返回的标准 OpenAI 文件对象。 */
11
+ export type OpenAIFileObject = FileObject;
12
+ /** Responses `input_text` 内容块,Agent 基础 text part 会被 builder 转成该结构。 */
13
+ export interface OpenAIResponsesInputTextPart {
14
+ type: 'input_text';
15
+ text: string;
16
+ }
17
+ /** 方舟兼容 endpoint 为图片输入提供的像素上下限控制。 */
18
+ export interface OpenAIResponsesImagePixelLimit {
19
+ min_pixels?: number;
20
+ max_pixels?: number;
21
+ }
22
+ /**
23
+ * Responses 图片输入。
24
+ *
25
+ * `file_id` / `image_url` 来自标准 Responses 协议;`xhigh` 与
26
+ * `image_pixel_limit` 是方舟 `api/v3` 明确声明的兼容能力。
27
+ */
28
+ export interface OpenAIResponsesInputImagePart {
29
+ type: 'input_image';
30
+ file_id?: string | null;
31
+ image_url?: string | null;
32
+ detail?: 'auto' | 'low' | 'high' | 'original' | 'xhigh';
33
+ image_pixel_limit?: OpenAIResponsesImagePixelLimit | null;
34
+ }
35
+ /** Responses 文件输入内容块,可通过 file id、文件 URL 或内联文件数据引用。 */
36
+ export interface OpenAIResponsesInputFilePart {
37
+ type: 'input_file';
38
+ detail?: 'low' | 'high';
39
+ file_data?: string | null;
40
+ file_id?: string | null;
41
+ file_url?: string | null;
42
+ filename?: string | null;
43
+ }
44
+ /** 方舟 `api/v3` 显式提供的视频输入内容块。 */
45
+ export interface OpenAIResponsesInputVideoPart {
46
+ type: 'input_video';
47
+ file_id?: string | null;
48
+ video_url?: string | null;
49
+ fps?: number;
50
+ }
51
+ /** 方舟 `api/v3` 显式提供的音频输入内容块。 */
52
+ export interface OpenAIResponsesInputAudioPart {
53
+ type: 'input_audio';
54
+ file_id?: string | null;
55
+ audio_url?: string | null;
56
+ }
57
+ /** Responses user input 中除基础文本外允许的协议扩展内容块。 */
58
+ export type OpenAIResponsesUserExtensionPart = OpenAIResponsesInputImagePart | OpenAIResponsesInputFilePart | OpenAIResponsesInputVideoPart | OpenAIResponsesInputAudioPart;
59
+ /** 应用交给 Responses builder 的用户消息结构。 */
60
+ export interface OpenAIResponsesUserMessage {
61
+ content: readonly (AgentTextPart | OpenAIResponsesUserExtensionPart)[];
62
+ }
63
+ /** Responses system builder 使用的基础消息结构。 */
64
+ export type OpenAIResponsesSystemMessage = AgentBaseSystemMessage;
65
+ /** 从 Responses assistant output message 反解析出的文本和 refusal。 */
66
+ export interface OpenAIResponsesAssistantMessage {
67
+ content: readonly AgentTextPart[];
68
+ refusals?: readonly string[];
69
+ }
70
+ /** `function_call_output.output` 允许携带的非字符串内容块。 */
71
+ export type OpenAIResponsesFunctionCallOutputContentPart = OpenAIResponsesInputTextPart | OpenAIResponsesInputImagePart | OpenAIResponsesInputFilePart;
72
+ /** Responses 工具结果 output,既可为字符串,也可为 OpenAI SDK 支持的内容数组。 */
73
+ export type OpenAIResponsesFunctionCallOutputValue = string | readonly OpenAIResponsesFunctionCallOutputContentPart[];
74
+ /** 应用或 Agent 交给工具结果 builder 的结构。 */
75
+ export interface OpenAIResponsesToolCallOutputMessage {
76
+ callId: string;
77
+ output: OpenAIResponsesFunctionCallOutputValue;
78
+ }
79
+ /** Responses item 常见执行状态。 */
80
+ export type OpenAIResponsesItemStatus = 'in_progress' | 'completed' | 'incomplete';
81
+ /**
82
+ * 持久上下文中的请求消息。`partial` 是方舟兼容 endpoint 明确支持的字段。
83
+ */
84
+ export interface OpenAIResponsesInputMessage {
85
+ role: 'system' | 'developer' | 'user';
86
+ content: string | readonly (OpenAIResponsesInputTextPart | OpenAIResponsesUserExtensionPart)[];
87
+ type?: 'message';
88
+ partial?: boolean;
89
+ }
90
+ /** Responses 文件引用注解。 */
91
+ export interface OpenAIResponsesFileCitationAnnotation {
92
+ type: 'file_citation';
93
+ file_id: string;
94
+ filename: string;
95
+ index: number;
96
+ }
97
+ /** Responses URL 引用注解。 */
98
+ export interface OpenAIResponsesUrlCitationAnnotation {
99
+ type: 'url_citation';
100
+ url: string;
101
+ title: string;
102
+ start_index: number;
103
+ end_index: number;
104
+ }
105
+ /** Responses container file 引用注解。 */
106
+ export interface OpenAIResponsesContainerFileCitationAnnotation {
107
+ type: 'container_file_citation';
108
+ container_id: string;
109
+ file_id: string;
110
+ filename: string;
111
+ start_index: number;
112
+ end_index: number;
113
+ }
114
+ /** Responses 文件路径注解。 */
115
+ export interface OpenAIResponsesFilePathAnnotation {
116
+ type: 'file_path';
117
+ file_id: string;
118
+ index: number;
119
+ }
120
+ /** Responses 文本输出中可能携带的注解集合。 */
121
+ export type OpenAIResponsesAnnotation = OpenAIResponsesFileCitationAnnotation | OpenAIResponsesUrlCitationAnnotation | OpenAIResponsesContainerFileCitationAnnotation | OpenAIResponsesFilePathAnnotation;
122
+ /** Responses assistant 输出文本内容块。 */
123
+ export interface OpenAIResponsesOutputTextPart {
124
+ type: 'output_text';
125
+ text: string;
126
+ annotations: readonly OpenAIResponsesAnnotation[];
127
+ logprobs?: readonly OpenAIResponsesLogprob[];
128
+ }
129
+ /** Responses assistant refusal 内容块。 */
130
+ export interface OpenAIResponsesOutputRefusalPart {
131
+ type: 'refusal';
132
+ refusal: string;
133
+ }
134
+ /** Responses logprob 的候选 token 信息。 */
135
+ export interface OpenAIResponsesTopLogprob {
136
+ token: string;
137
+ bytes: readonly number[];
138
+ logprob: number;
139
+ }
140
+ /** Responses 输出文本中单个 token 的 logprob 信息。 */
141
+ export interface OpenAIResponsesLogprob extends OpenAIResponsesTopLogprob {
142
+ top_logprobs: readonly OpenAIResponsesTopLogprob[];
143
+ }
144
+ /** Responses assistant output message,作为 context 原样保存和回传。 */
145
+ export interface OpenAIResponsesOutputMessage {
146
+ type: 'message';
147
+ id: string;
148
+ role: 'assistant';
149
+ content: readonly (OpenAIResponsesOutputTextPart | OpenAIResponsesOutputRefusalPart)[];
150
+ status: OpenAIResponsesItemStatus;
151
+ phase?: 'commentary' | 'final_answer' | null;
152
+ }
153
+ /** reasoning item 的摘要内容块。 */
154
+ export interface OpenAIResponsesReasoningSummaryPart {
155
+ type: 'summary_text';
156
+ text: string;
157
+ }
158
+ /** reasoning item 的详细推理文本内容块。 */
159
+ export interface OpenAIResponsesReasoningContentPart {
160
+ type: 'reasoning_text';
161
+ text: string;
162
+ }
163
+ /** Responses reasoning item;Agent 保存但不会将其映射为普通 assistant 消息。 */
164
+ export interface OpenAIResponsesReasoningItem {
165
+ type: 'reasoning';
166
+ id: string;
167
+ summary: readonly OpenAIResponsesReasoningSummaryPart[];
168
+ content?: readonly OpenAIResponsesReasoningContentPart[];
169
+ encrypted_content?: string | null;
170
+ status?: OpenAIResponsesItemStatus;
171
+ }
172
+ /** Responses function_call item;Model parser 会把它提取为本地工具调用。 */
173
+ export interface OpenAIResponsesFunctionCall {
174
+ type: 'function_call';
175
+ call_id: string;
176
+ name: string;
177
+ arguments: string;
178
+ id?: string;
179
+ namespace?: string;
180
+ status?: OpenAIResponsesItemStatus;
181
+ created_by?: string;
182
+ }
183
+ /** Responses function_call_output item;由工具结果 builder 生成或由历史上下文恢复。 */
184
+ export interface OpenAIResponsesFunctionCallOutput {
185
+ type: 'function_call_output';
186
+ call_id: string;
187
+ output: OpenAIResponsesFunctionCallOutputValue;
188
+ id?: string;
189
+ status?: OpenAIResponsesItemStatus;
190
+ created_by?: string;
191
+ }
192
+ /** Responses 协议下可以进入 Agent context/history 的封闭 item 集合。 */
193
+ export type OpenAIResponsesContext = OpenAIResponsesInputMessage | OpenAIResponsesOutputMessage | OpenAIResponsesReasoningItem | OpenAIResponsesFunctionCall | OpenAIResponsesFunctionCallOutput;
194
+ /** Responses function tool wire structure。 */
195
+ export interface OpenAIResponsesTool {
196
+ type: 'function';
197
+ name: string;
198
+ description: string;
199
+ parameters: JsonObject;
200
+ strict?: boolean;
201
+ }
202
+ /** Responses 协议下 Agent 与 Model 共享的关联类型。 */
203
+ export interface OpenAIResponsesProtocol extends AgentProtocol {
204
+ context: OpenAIResponsesContext;
205
+ tool: OpenAIResponsesTool;
206
+ userMessage: OpenAIResponsesUserMessage;
207
+ systemMessage: OpenAIResponsesSystemMessage;
208
+ assistantMessage: OpenAIResponsesAssistantMessage;
209
+ toolCallOutputMessage: OpenAIResponsesToolCallOutputMessage;
210
+ rawToolCall: OpenAIResponsesFunctionCall;
211
+ rawResponse: OpenAIResponse;
212
+ }
213
+ /** 基于 OpenAI SDK 的 Responses 适配器配置。 */
214
+ export interface OpenAIResponsesModelOptions extends ClientOptions {
215
+ model: string;
216
+ client?: OpenAI;
217
+ defaultParams?: Omit<ResponseCreateParamsNonStreaming, 'input' | 'model' | 'stream' | 'tools'>;
218
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@ruixutong.manee/agent-framework",
3
+ "version": "1.0.0",
4
+ "description": "Node.js AI agent framework.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "keywords": [
9
+ "agent",
10
+ "ai-agent",
11
+ "llm",
12
+ "openai",
13
+ "tool-calling",
14
+ "typescript",
15
+ "decorators",
16
+ "zod"
17
+ ],
18
+ "engines": {
19
+ "node": ">=22"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "main": "./dist/index.cjs",
26
+ "module": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js",
32
+ "require": "./dist/index.cjs"
33
+ }
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "build": "vite build && tsc -p tsconfig.build.json",
40
+ "typecheck": "tsc --noEmit",
41
+ "lint": "eslint .",
42
+ "prepublishOnly": "npm run typecheck && npm run lint && npm run build"
43
+ },
44
+ "dependencies": {
45
+ "openai": "^6.38.0",
46
+ "zod": "^4.4.3",
47
+ "zod-to-json-schema": "^3.25.2"
48
+ }
49
+ }