@chatluna/v1-shared-adapter 1.0.31 → 1.0.33

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/lib/types.d.ts CHANGED
@@ -34,6 +34,175 @@ export interface ChatCompletionUsage {
34
34
  prompt_tokens_details?: ChatCompletionPromptTokensDetails;
35
35
  completion_tokens_details?: ChatCompletionCompletionTokensDetails;
36
36
  }
37
+ export interface ResponseUsage {
38
+ input_tokens: number;
39
+ output_tokens: number;
40
+ total_tokens: number;
41
+ input_tokens_details?: {
42
+ cached_tokens?: number;
43
+ };
44
+ output_tokens_details?: {
45
+ reasoning_tokens?: number;
46
+ };
47
+ }
48
+ export type ResponseInputContent = {
49
+ type: 'input_text';
50
+ text: string;
51
+ } | {
52
+ type: 'input_image';
53
+ image_url: string;
54
+ detail?: 'low' | 'high' | 'auto' | 'original';
55
+ } | {
56
+ type: 'input_file';
57
+ file_url?: string;
58
+ file_data?: string;
59
+ file_id?: string;
60
+ filename?: string;
61
+ };
62
+ export type ResponseInputItem = {
63
+ type: 'message';
64
+ role: 'system' | 'developer' | 'user' | 'assistant';
65
+ content: string | ResponseInputContent[];
66
+ } | {
67
+ type: 'function_call';
68
+ call_id: string;
69
+ name: string;
70
+ arguments: string;
71
+ status?: 'completed' | 'in_progress' | 'incomplete';
72
+ } | {
73
+ type: 'function_call_output';
74
+ call_id: string;
75
+ output: string | ResponseInputContent[];
76
+ };
77
+ export type ResponseBuiltinToolName = 'web_search' | 'web_search_preview' | 'image_generation' | 'code_interpreter' | 'file_search';
78
+ export type ResponseBuiltinTool = {
79
+ type: 'web_search' | 'web_search_2025_08_26';
80
+ filters?: {
81
+ allowed_domains?: string[] | null;
82
+ } | null;
83
+ search_context_size?: 'low' | 'medium' | 'high';
84
+ user_location?: {
85
+ city?: string | null;
86
+ country?: string | null;
87
+ region?: string | null;
88
+ timezone?: string | null;
89
+ type?: 'approximate';
90
+ } | null;
91
+ } | {
92
+ type: 'web_search_preview' | 'web_search_preview_2025_03_11';
93
+ search_content_types?: ('text' | 'image')[];
94
+ search_context_size?: 'low' | 'medium' | 'high';
95
+ user_location?: {
96
+ type: 'approximate';
97
+ city?: string | null;
98
+ country?: string | null;
99
+ region?: string | null;
100
+ timezone?: string | null;
101
+ } | null;
102
+ } | {
103
+ type: 'image_generation';
104
+ action?: 'generate' | 'edit' | 'auto';
105
+ background?: 'transparent' | 'opaque' | 'auto';
106
+ input_fidelity?: 'high' | 'low' | null;
107
+ input_image_mask?: {
108
+ file_id?: string;
109
+ image_url?: string;
110
+ };
111
+ model?: string;
112
+ moderation?: 'auto' | 'low';
113
+ output_compression?: number;
114
+ output_format?: 'png' | 'webp' | 'jpeg';
115
+ partial_images?: number;
116
+ quality?: 'low' | 'medium' | 'high' | 'auto';
117
+ size?: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';
118
+ } | {
119
+ type: 'code_interpreter';
120
+ container: string | {
121
+ type: 'auto';
122
+ file_ids?: string[];
123
+ memory_limit?: '1g' | '4g' | '16g' | '64g' | null;
124
+ };
125
+ } | {
126
+ type: 'file_search';
127
+ vector_store_ids: string[];
128
+ filters?: Record<string, unknown> | null;
129
+ max_num_results?: number;
130
+ ranking_options?: {
131
+ ranker?: 'auto' | 'default-2024-11-15';
132
+ score_threshold?: number;
133
+ hybrid_search?: {
134
+ embedding_weight: number;
135
+ text_weight: number;
136
+ };
137
+ };
138
+ };
139
+ export type ResponseTool = {
140
+ type: 'function';
141
+ name: string;
142
+ description?: string;
143
+ parameters?: {
144
+ [key: string]: any;
145
+ };
146
+ strict?: boolean;
147
+ } | ResponseBuiltinTool;
148
+ export interface ResponseObject {
149
+ id: string;
150
+ object: 'response';
151
+ output_text?: string;
152
+ output?: ResponseOutputItem[];
153
+ usage?: ResponseUsage;
154
+ error?: {
155
+ message?: string;
156
+ } | null;
157
+ conversation?: {
158
+ id: string;
159
+ } | null;
160
+ }
161
+ export type ResponseOutputItem = {
162
+ type: 'message';
163
+ role?: string;
164
+ content?: ResponseOutputContent[];
165
+ } | {
166
+ type: 'function_call';
167
+ id?: string;
168
+ call_id: string;
169
+ name: string;
170
+ arguments: string;
171
+ status?: string;
172
+ } | {
173
+ type: 'image_generation_call';
174
+ id?: string;
175
+ result?: string | null;
176
+ output_format?: 'png' | 'jpeg' | 'webp';
177
+ status?: string;
178
+ } | {
179
+ type: string;
180
+ [key: string]: unknown;
181
+ };
182
+ export type ResponseOutputContent = {
183
+ type: 'output_text';
184
+ text: string;
185
+ } | {
186
+ type: 'refusal';
187
+ refusal: string;
188
+ } | {
189
+ type: string;
190
+ [key: string]: unknown;
191
+ };
192
+ export interface ResponseStreamEvent {
193
+ type: string;
194
+ sequence_number?: number;
195
+ item_id?: string;
196
+ output_index?: number;
197
+ content_index?: number;
198
+ delta?: string;
199
+ text?: string;
200
+ name?: string;
201
+ arguments?: string;
202
+ item?: ResponseOutputItem;
203
+ response?: ResponseObject;
204
+ partial_image_b64?: string;
205
+ }
37
206
  export interface ChatCompletionTextPart {
38
207
  type: 'text';
39
208
  text: string;
package/lib/utils.d.ts CHANGED
@@ -1,19 +1,41 @@
1
1
  import { AIMessageChunk, BaseMessage, ChatMessageChunk, FunctionMessageChunk, HumanMessageChunk, MessageContentComplex, MessageContentImageUrl, MessageType, SystemMessageChunk, ToolMessageChunk, type UsageMetadata } from '@langchain/core/messages';
2
2
  import { StructuredTool } from '@langchain/core/tools';
3
3
  import { JsonSchema7Type } from 'zod-to-json-schema';
4
- import { ChatCompletionResponseMessage, ChatCompletionResponseMessageRoleEnum, ChatCompletionTool, ChatCompletionUsage } from './types';
4
+ import { ChatCompletionResponseMessage, ChatCompletionResponseMessageRoleEnum, ChatCompletionTool, ChatCompletionUsage, type ResponseBuiltinTool, ResponseInputContent, ResponseInputItem, ResponseObject, ResponseTool, ResponseUsage } from './types';
5
5
  import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
6
6
  export declare function createUsageMetadata(data: {
7
7
  inputTokens: number;
8
8
  outputTokens: number;
9
9
  totalTokens: number;
10
10
  inputAudioTokens?: number;
11
+ inputImageTokens?: number;
11
12
  outputAudioTokens?: number;
13
+ outputImageTokens?: number;
12
14
  cacheReadTokens?: number;
13
15
  cacheCreationTokens?: number;
14
16
  reasoningTokens?: number;
15
17
  }): UsageMetadata;
16
18
  export declare function openAIUsageToUsageMetadata(usage: ChatCompletionUsage): UsageMetadata;
19
+ export declare function openAIResponseUsageToUsageMetadata(usage: ResponseUsage): UsageMetadata;
20
+ export declare function langchainMessageToResponseInput(messages: BaseMessage[], plugin: ChatLunaPlugin, model?: string, supportImageInputType?: boolean): Promise<ResponseInputItem[]>;
21
+ export declare function responseInputContent(content: ChatCompletionResponseMessage['content']): string | ResponseInputContent[];
22
+ export declare function formatToolsToResponseTools(tools: StructuredTool[], includeGoogleSearch: boolean, builtinTools?: ResponseBuiltinTool[]): ResponseTool[] | undefined;
23
+ export declare function responseOutputText(response: ResponseObject): string;
24
+ export declare function responseOutputToolCalls(response: ResponseObject): {
25
+ type: "function_call";
26
+ id?: string;
27
+ call_id: string;
28
+ name: string;
29
+ arguments: string;
30
+ status?: string;
31
+ }[];
32
+ export declare function responseOutputImageItems(response: ResponseObject): {
33
+ type: "image_generation_call";
34
+ id?: string;
35
+ result?: string | null;
36
+ output_format?: "png" | "jpeg" | "webp";
37
+ status?: string;
38
+ }[];
17
39
  export declare function langchainMessageToOpenAIMessage(messages: BaseMessage[], plugin: ChatLunaPlugin, model?: string, supportImageInputType?: boolean, removeSystemMessage?: boolean): Promise<ChatCompletionResponseMessage[]>;
18
40
  export declare function processInterleavedThinkMessages(convertedMessages: ChatCompletionResponseMessage[], originalMessages: BaseMessage[]): ChatCompletionResponseMessage[];
19
41
  export declare function transformSystemMessages(messages: ChatCompletionResponseMessage[]): ChatCompletionResponseMessage[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chatluna/v1-shared-adapter",
3
3
  "description": "chatluna shared adapter",
4
- "version": "1.0.31",
4
+ "version": "1.0.33",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",
@@ -70,6 +70,6 @@
70
70
  },
71
71
  "peerDependencies": {
72
72
  "koishi": "^4.18.9",
73
- "koishi-plugin-chatluna": "^1.3.34"
73
+ "koishi-plugin-chatluna": "^1.4.0-alpha.8"
74
74
  }
75
75
  }