@agentscope-ai/agentscope 0.0.2 → 0.0.4
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 +202 -0
- package/dist/agent/index.d.mts +10 -10
- package/dist/agent/index.d.ts +10 -10
- package/dist/agent/index.js +104 -93
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/index.mjs +104 -93
- package/dist/agent/index.mjs.map +1 -1
- package/dist/{base-BOx3UzOl.d.mts → base-1YVBgB4n.d.mts} +2 -2
- package/dist/{base-DYlBMCy_.d.mts → base-B_MQMHWr.d.mts} +3 -3
- package/dist/{base-Cwi4bjze.d.ts → base-BherSLRs.d.ts} +3 -3
- package/dist/{base-NX-knWOv.d.ts → base-CY4DMBH1.d.ts} +1 -1
- package/dist/{base-BoIps2RL.d.ts → base-ChWjyzPL.d.ts} +2 -2
- package/dist/{base-C7jwyH4Z.d.mts → base-ClilytRZ.d.mts} +1 -1
- package/dist/{block-VsnHrllL.d.mts → block-B72uPF1H.d.mts} +7 -5
- package/dist/{block-VsnHrllL.d.ts → block-B72uPF1H.d.ts} +7 -5
- package/dist/event/index.d.mts +105 -89
- package/dist/event/index.d.ts +105 -89
- package/dist/event/index.js +8 -8
- package/dist/event/index.js.map +1 -1
- package/dist/event/index.mjs +8 -8
- package/dist/event/index.mjs.map +1 -1
- package/dist/formatter/index.d.mts +4 -3
- package/dist/formatter/index.d.ts +4 -3
- package/dist/formatter/index.js +17 -17
- package/dist/formatter/index.js.map +1 -1
- package/dist/formatter/index.mjs +17 -17
- package/dist/formatter/index.mjs.map +1 -1
- package/dist/{index-BcatlwXQ.d.ts → index-BNfyKbQN.d.ts} +1 -1
- package/dist/{index-BTJDlKvQ.d.mts → index-UQCwdfet.d.mts} +1 -1
- package/dist/mcp/index.d.mts +2 -2
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/index.mjs +1 -1
- package/dist/mcp/index.mjs.map +1 -1
- package/dist/message/index.d.mts +3 -2
- package/dist/message/index.d.ts +3 -2
- package/dist/message/index.js +204 -5
- package/dist/message/index.js.map +1 -1
- package/dist/message/index.mjs +200 -5
- package/dist/message/index.mjs.map +1 -1
- package/dist/message-CPZd0NIc.d.ts +133 -0
- package/dist/message-DgpfAaHK.d.mts +133 -0
- package/dist/model/index.d.mts +6 -5
- package/dist/model/index.d.ts +6 -5
- package/dist/model/index.js +39 -28
- package/dist/model/index.js.map +1 -1
- package/dist/model/index.mjs +39 -28
- package/dist/model/index.mjs.map +1 -1
- package/dist/storage/index.d.mts +4 -3
- package/dist/storage/index.d.ts +4 -3
- package/dist/storage/index.js +4 -4
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +4 -4
- package/dist/storage/index.mjs.map +1 -1
- package/dist/tool/index.d.mts +4 -4
- package/dist/tool/index.d.ts +4 -4
- package/dist/{toolkit-CEpulFi0.d.ts → toolkit-DeOlul5Y.d.ts} +2 -2
- package/dist/{toolkit-CGEZSZPa.d.mts → toolkit-jwe7NmVJ.d.mts} +2 -2
- package/package.json +87 -87
- package/src/agent/agent.test.ts +104 -71
- package/src/agent/agent.ts +112 -104
- package/src/agent/test-compression.ts +1 -1
- package/src/event/index.ts +96 -98
- package/src/formatter/base.ts +3 -3
- package/src/formatter/dashscope-chat-formatter.test.ts +11 -8
- package/src/formatter/dashscope-chat-formatter.ts +3 -3
- package/src/formatter/openai-chat-formatter.test.ts +13 -5
- package/src/formatter/openai-chat-formatter.ts +6 -6
- package/src/mcp/base.ts +1 -1
- package/src/mcp/http.test.ts +2 -0
- package/src/mcp/stdio.test.ts +1 -0
- package/src/message/append-event.test.ts +783 -0
- package/src/message/block.ts +8 -4
- package/src/message/index.ts +12 -1
- package/src/message/message.test.ts +3 -1
- package/src/message/message.ts +310 -47
- package/src/model/dashscope-model.test.ts +4 -0
- package/src/model/dashscope-model.ts +3 -0
- package/src/model/deepseek-model.test.ts +2 -0
- package/src/model/deepseek-model.ts +3 -0
- package/src/model/ollama-model.test.ts +1 -0
- package/src/model/ollama-model.ts +2 -0
- package/src/model/openai-model.ts +3 -0
- package/src/permission/index.ts +13 -0
- package/src/storage/file-system.test.ts +4 -3
- package/src/storage/file-system.ts +4 -4
- package/src/tool/toolkit.test.ts +12 -0
- package/dist/message-CkN21KaY.d.mts +0 -99
- package/dist/message-CzLeTlua.d.ts +0 -99
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { J as JSONSerializableObject } from './index-CAxQAkiP.js';
|
|
2
|
+
import { C as ContentBlock, T as TextBlock, a as ThinkingBlock, D as DataBlock, b as ToolCallBlock, d as ToolResultBlock } from './block-B72uPF1H.js';
|
|
3
|
+
import { AgentEvent } from './event/index.js';
|
|
4
|
+
|
|
5
|
+
/** A chat message exchanged between agents or between an agent and a model. */
|
|
6
|
+
interface Msg {
|
|
7
|
+
/** Unique identifier for the message. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Display name of the message sender. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Conversation role of the sender. */
|
|
12
|
+
role: 'user' | 'assistant' | 'system';
|
|
13
|
+
/** Message body. */
|
|
14
|
+
content: ContentBlock[];
|
|
15
|
+
/** Arbitrary key-value metadata attached to the message. */
|
|
16
|
+
metadata: Record<string, JSONSerializableObject>;
|
|
17
|
+
/** ISO-8601 creation timestamp. */
|
|
18
|
+
created_at: string;
|
|
19
|
+
/** ISO-8601 finished timestamp. */
|
|
20
|
+
finished_at?: string | null;
|
|
21
|
+
/** Usage information for the message, such as token counts. */
|
|
22
|
+
usage?: {
|
|
23
|
+
inputTokens: number;
|
|
24
|
+
outputTokens: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a new {@link Msg} object, filling in `id` and `created_at` when omitted.
|
|
29
|
+
* A plain string `content` is automatically wrapped in a single {@link TextBlock}.
|
|
30
|
+
* @param root0
|
|
31
|
+
* @param root0.name
|
|
32
|
+
* @param root0.content
|
|
33
|
+
* @param root0.role
|
|
34
|
+
* @param root0.metadata
|
|
35
|
+
* @param root0.id
|
|
36
|
+
* @param root0.created_at
|
|
37
|
+
* @param root0.finished_at
|
|
38
|
+
* @param root0.usage
|
|
39
|
+
* @returns A Msg object.
|
|
40
|
+
*/
|
|
41
|
+
declare function createMsg({ name, content, role, metadata, id, created_at, finished_at, usage, }: Omit<Msg, 'id' | 'created_at' | 'metadata' | 'content'> & Partial<Pick<Msg, 'id' | 'created_at' | 'metadata'>> & {
|
|
42
|
+
content: string | ContentBlock[];
|
|
43
|
+
}): Msg;
|
|
44
|
+
/**
|
|
45
|
+
* Create a user {@link Msg}.
|
|
46
|
+
* @param root0
|
|
47
|
+
* @param root0.name
|
|
48
|
+
* @param root0.content
|
|
49
|
+
* @param root0.metadata
|
|
50
|
+
* @param root0.id
|
|
51
|
+
* @param root0.created_at
|
|
52
|
+
* @returns A Msg object with role 'user'.
|
|
53
|
+
*/
|
|
54
|
+
declare function UserMsg({ name, content, metadata, id, created_at, }: {
|
|
55
|
+
name: string;
|
|
56
|
+
content: string | ContentBlock[];
|
|
57
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
58
|
+
id?: string;
|
|
59
|
+
created_at?: string;
|
|
60
|
+
}): Msg;
|
|
61
|
+
/**
|
|
62
|
+
* Create an assistant {@link Msg}.
|
|
63
|
+
* @param root0
|
|
64
|
+
* @param root0.name
|
|
65
|
+
* @param root0.content
|
|
66
|
+
* @param root0.metadata
|
|
67
|
+
* @param root0.id
|
|
68
|
+
* @param root0.created_at
|
|
69
|
+
* @param root0.usage
|
|
70
|
+
* @returns A Msg object with role 'assistant'.
|
|
71
|
+
*/
|
|
72
|
+
declare function AssistantMsg({ name, content, metadata, id, created_at, usage, }: {
|
|
73
|
+
name: string;
|
|
74
|
+
content: string | ContentBlock[];
|
|
75
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
76
|
+
id?: string;
|
|
77
|
+
created_at?: string;
|
|
78
|
+
usage?: Msg['usage'];
|
|
79
|
+
}): Msg;
|
|
80
|
+
/**
|
|
81
|
+
* Create a system {@link Msg}.
|
|
82
|
+
* @param root0
|
|
83
|
+
* @param root0.name
|
|
84
|
+
* @param root0.content
|
|
85
|
+
* @param root0.metadata
|
|
86
|
+
* @param root0.id
|
|
87
|
+
* @param root0.created_at
|
|
88
|
+
* @returns A Msg object with role 'system'.
|
|
89
|
+
*/
|
|
90
|
+
declare function SystemMsg({ name, content, metadata, id, created_at, }: {
|
|
91
|
+
name: string;
|
|
92
|
+
content: string | ContentBlock[];
|
|
93
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
94
|
+
id?: string;
|
|
95
|
+
created_at?: string;
|
|
96
|
+
}): Msg;
|
|
97
|
+
/**
|
|
98
|
+
* Extract the plain-text content from a message.
|
|
99
|
+
*
|
|
100
|
+
* When `content` is a string it is returned as-is. When it is an array of
|
|
101
|
+
* content blocks, all {@link TextBlock} texts are joined with `separator`.
|
|
102
|
+
*
|
|
103
|
+
* @param msg - The message to read.
|
|
104
|
+
* @param separator - String inserted between consecutive text blocks. Defaults to `'\n'`.
|
|
105
|
+
* @returns The concatenated text, or `null` when no text blocks are present.
|
|
106
|
+
*/
|
|
107
|
+
declare function getTextContent(msg: Msg, separator?: string): string | null;
|
|
108
|
+
/**
|
|
109
|
+
* Return all content blocks from a message, regardless of type.
|
|
110
|
+
*
|
|
111
|
+
* When `content` is a plain string it is wrapped in a single {@link TextBlock}.
|
|
112
|
+
*
|
|
113
|
+
* @param msg - The message to read.
|
|
114
|
+
* @returns An array of all {@link ContentBlock} objects.
|
|
115
|
+
*/
|
|
116
|
+
declare function getContentBlocks(msg: Msg): ContentBlock[];
|
|
117
|
+
declare function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];
|
|
118
|
+
declare function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];
|
|
119
|
+
declare function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];
|
|
120
|
+
declare function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];
|
|
121
|
+
declare function getContentBlocks(msg: Msg, blockType: 'tool_result'): ToolResultBlock[];
|
|
122
|
+
/**
|
|
123
|
+
* Apply a streaming {@link AgentEvent} to a {@link Msg}, mutating it in place.
|
|
124
|
+
*
|
|
125
|
+
* Only `content` and `finished_at` are ever modified. Events whose
|
|
126
|
+
* `reply_id` does not match `msg.id` are skipped with a warning.
|
|
127
|
+
* @param msg
|
|
128
|
+
* @param event
|
|
129
|
+
* @returns The mutated {@link Msg} object.
|
|
130
|
+
*/
|
|
131
|
+
declare function appendEvent(msg: Msg, event: AgentEvent): Msg;
|
|
132
|
+
|
|
133
|
+
export { AssistantMsg as A, type Msg as M, SystemMsg as S, UserMsg as U, appendEvent as a, getTextContent as b, createMsg as c, getContentBlocks as g };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { J as JSONSerializableObject } from './index-CAxQAkiP.mjs';
|
|
2
|
+
import { C as ContentBlock, T as TextBlock, a as ThinkingBlock, D as DataBlock, b as ToolCallBlock, d as ToolResultBlock } from './block-B72uPF1H.mjs';
|
|
3
|
+
import { AgentEvent } from './event/index.mjs';
|
|
4
|
+
|
|
5
|
+
/** A chat message exchanged between agents or between an agent and a model. */
|
|
6
|
+
interface Msg {
|
|
7
|
+
/** Unique identifier for the message. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Display name of the message sender. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Conversation role of the sender. */
|
|
12
|
+
role: 'user' | 'assistant' | 'system';
|
|
13
|
+
/** Message body. */
|
|
14
|
+
content: ContentBlock[];
|
|
15
|
+
/** Arbitrary key-value metadata attached to the message. */
|
|
16
|
+
metadata: Record<string, JSONSerializableObject>;
|
|
17
|
+
/** ISO-8601 creation timestamp. */
|
|
18
|
+
created_at: string;
|
|
19
|
+
/** ISO-8601 finished timestamp. */
|
|
20
|
+
finished_at?: string | null;
|
|
21
|
+
/** Usage information for the message, such as token counts. */
|
|
22
|
+
usage?: {
|
|
23
|
+
inputTokens: number;
|
|
24
|
+
outputTokens: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a new {@link Msg} object, filling in `id` and `created_at` when omitted.
|
|
29
|
+
* A plain string `content` is automatically wrapped in a single {@link TextBlock}.
|
|
30
|
+
* @param root0
|
|
31
|
+
* @param root0.name
|
|
32
|
+
* @param root0.content
|
|
33
|
+
* @param root0.role
|
|
34
|
+
* @param root0.metadata
|
|
35
|
+
* @param root0.id
|
|
36
|
+
* @param root0.created_at
|
|
37
|
+
* @param root0.finished_at
|
|
38
|
+
* @param root0.usage
|
|
39
|
+
* @returns A Msg object.
|
|
40
|
+
*/
|
|
41
|
+
declare function createMsg({ name, content, role, metadata, id, created_at, finished_at, usage, }: Omit<Msg, 'id' | 'created_at' | 'metadata' | 'content'> & Partial<Pick<Msg, 'id' | 'created_at' | 'metadata'>> & {
|
|
42
|
+
content: string | ContentBlock[];
|
|
43
|
+
}): Msg;
|
|
44
|
+
/**
|
|
45
|
+
* Create a user {@link Msg}.
|
|
46
|
+
* @param root0
|
|
47
|
+
* @param root0.name
|
|
48
|
+
* @param root0.content
|
|
49
|
+
* @param root0.metadata
|
|
50
|
+
* @param root0.id
|
|
51
|
+
* @param root0.created_at
|
|
52
|
+
* @returns A Msg object with role 'user'.
|
|
53
|
+
*/
|
|
54
|
+
declare function UserMsg({ name, content, metadata, id, created_at, }: {
|
|
55
|
+
name: string;
|
|
56
|
+
content: string | ContentBlock[];
|
|
57
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
58
|
+
id?: string;
|
|
59
|
+
created_at?: string;
|
|
60
|
+
}): Msg;
|
|
61
|
+
/**
|
|
62
|
+
* Create an assistant {@link Msg}.
|
|
63
|
+
* @param root0
|
|
64
|
+
* @param root0.name
|
|
65
|
+
* @param root0.content
|
|
66
|
+
* @param root0.metadata
|
|
67
|
+
* @param root0.id
|
|
68
|
+
* @param root0.created_at
|
|
69
|
+
* @param root0.usage
|
|
70
|
+
* @returns A Msg object with role 'assistant'.
|
|
71
|
+
*/
|
|
72
|
+
declare function AssistantMsg({ name, content, metadata, id, created_at, usage, }: {
|
|
73
|
+
name: string;
|
|
74
|
+
content: string | ContentBlock[];
|
|
75
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
76
|
+
id?: string;
|
|
77
|
+
created_at?: string;
|
|
78
|
+
usage?: Msg['usage'];
|
|
79
|
+
}): Msg;
|
|
80
|
+
/**
|
|
81
|
+
* Create a system {@link Msg}.
|
|
82
|
+
* @param root0
|
|
83
|
+
* @param root0.name
|
|
84
|
+
* @param root0.content
|
|
85
|
+
* @param root0.metadata
|
|
86
|
+
* @param root0.id
|
|
87
|
+
* @param root0.created_at
|
|
88
|
+
* @returns A Msg object with role 'system'.
|
|
89
|
+
*/
|
|
90
|
+
declare function SystemMsg({ name, content, metadata, id, created_at, }: {
|
|
91
|
+
name: string;
|
|
92
|
+
content: string | ContentBlock[];
|
|
93
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
94
|
+
id?: string;
|
|
95
|
+
created_at?: string;
|
|
96
|
+
}): Msg;
|
|
97
|
+
/**
|
|
98
|
+
* Extract the plain-text content from a message.
|
|
99
|
+
*
|
|
100
|
+
* When `content` is a string it is returned as-is. When it is an array of
|
|
101
|
+
* content blocks, all {@link TextBlock} texts are joined with `separator`.
|
|
102
|
+
*
|
|
103
|
+
* @param msg - The message to read.
|
|
104
|
+
* @param separator - String inserted between consecutive text blocks. Defaults to `'\n'`.
|
|
105
|
+
* @returns The concatenated text, or `null` when no text blocks are present.
|
|
106
|
+
*/
|
|
107
|
+
declare function getTextContent(msg: Msg, separator?: string): string | null;
|
|
108
|
+
/**
|
|
109
|
+
* Return all content blocks from a message, regardless of type.
|
|
110
|
+
*
|
|
111
|
+
* When `content` is a plain string it is wrapped in a single {@link TextBlock}.
|
|
112
|
+
*
|
|
113
|
+
* @param msg - The message to read.
|
|
114
|
+
* @returns An array of all {@link ContentBlock} objects.
|
|
115
|
+
*/
|
|
116
|
+
declare function getContentBlocks(msg: Msg): ContentBlock[];
|
|
117
|
+
declare function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];
|
|
118
|
+
declare function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];
|
|
119
|
+
declare function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];
|
|
120
|
+
declare function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];
|
|
121
|
+
declare function getContentBlocks(msg: Msg, blockType: 'tool_result'): ToolResultBlock[];
|
|
122
|
+
/**
|
|
123
|
+
* Apply a streaming {@link AgentEvent} to a {@link Msg}, mutating it in place.
|
|
124
|
+
*
|
|
125
|
+
* Only `content` and `finished_at` are ever modified. Events whose
|
|
126
|
+
* `reply_id` does not match `msg.id` are skipped with a warning.
|
|
127
|
+
* @param msg
|
|
128
|
+
* @param event
|
|
129
|
+
* @returns The mutated {@link Msg} object.
|
|
130
|
+
*/
|
|
131
|
+
declare function appendEvent(msg: Msg, event: AgentEvent): Msg;
|
|
132
|
+
|
|
133
|
+
export { AssistantMsg as A, type Msg as M, SystemMsg as S, UserMsg as U, appendEvent as a, getTextContent as b, createMsg as c, getContentBlocks as g };
|
package/dist/model/index.d.mts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { C as ChatModelBase, c as ChatModelOptions, d as ChatModelRequestOptions, b as ChatResponse } from '../base-
|
|
2
|
-
export { a as ChatUsage } from '../base-
|
|
1
|
+
import { C as ChatModelBase, c as ChatModelOptions, d as ChatModelRequestOptions, b as ChatResponse } from '../base-B_MQMHWr.mjs';
|
|
2
|
+
export { a as ChatUsage } from '../base-B_MQMHWr.mjs';
|
|
3
3
|
import { a as ToolChoice, T as ToolSchema } from '../index-CAxQAkiP.mjs';
|
|
4
|
-
import { b as ToolCallBlock, T as TextBlock, a as ThinkingBlock } from '../block-
|
|
4
|
+
import { b as ToolCallBlock, T as TextBlock, a as ThinkingBlock } from '../block-B72uPF1H.mjs';
|
|
5
5
|
import { Ollama, AbortableAsyncIterator, ChatResponse as ChatResponse$1 } from 'ollama';
|
|
6
6
|
import { OpenAI } from 'openai';
|
|
7
7
|
import { ChatCompletionMessageParam, ChatCompletionToolChoiceOption } from 'openai/resources/chat/completions';
|
|
8
8
|
import 'zod';
|
|
9
|
-
import '../base-
|
|
10
|
-
import '../message-
|
|
9
|
+
import '../base-1YVBgB4n.mjs';
|
|
10
|
+
import '../message-DgpfAaHK.mjs';
|
|
11
|
+
import '../event/index.mjs';
|
|
11
12
|
|
|
12
13
|
interface DashScopeThinkingConfig {
|
|
13
14
|
/**
|
package/dist/model/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { C as ChatModelBase, c as ChatModelOptions, d as ChatModelRequestOptions, b as ChatResponse } from '../base-
|
|
2
|
-
export { a as ChatUsage } from '../base-
|
|
1
|
+
import { C as ChatModelBase, c as ChatModelOptions, d as ChatModelRequestOptions, b as ChatResponse } from '../base-BherSLRs.js';
|
|
2
|
+
export { a as ChatUsage } from '../base-BherSLRs.js';
|
|
3
3
|
import { a as ToolChoice, T as ToolSchema } from '../index-CAxQAkiP.js';
|
|
4
|
-
import { b as ToolCallBlock, T as TextBlock, a as ThinkingBlock } from '../block-
|
|
4
|
+
import { b as ToolCallBlock, T as TextBlock, a as ThinkingBlock } from '../block-B72uPF1H.js';
|
|
5
5
|
import { Ollama, AbortableAsyncIterator, ChatResponse as ChatResponse$1 } from 'ollama';
|
|
6
6
|
import { OpenAI } from 'openai';
|
|
7
7
|
import { ChatCompletionMessageParam, ChatCompletionToolChoiceOption } from 'openai/resources/chat/completions';
|
|
8
8
|
import 'zod';
|
|
9
|
-
import '../base-
|
|
10
|
-
import '../message-
|
|
9
|
+
import '../base-ChWjyzPL.js';
|
|
10
|
+
import '../message-CPZd0NIc.js';
|
|
11
|
+
import '../event/index.js';
|
|
11
12
|
|
|
12
13
|
interface DashScopeThinkingConfig {
|
|
13
14
|
/**
|
package/dist/model/index.js
CHANGED
|
@@ -35,16 +35,16 @@ function createMsg({
|
|
|
35
35
|
role,
|
|
36
36
|
metadata = {},
|
|
37
37
|
id = crypto.randomUUID(),
|
|
38
|
-
|
|
38
|
+
created_at = (/* @__PURE__ */ new Date()).toISOString(),
|
|
39
|
+
finished_at,
|
|
39
40
|
usage
|
|
40
41
|
}) {
|
|
41
|
-
|
|
42
|
+
const contentBlocks = typeof content === "string" ? [{ id: crypto.randomUUID(), type: "text", text: content }] : content;
|
|
43
|
+
return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };
|
|
42
44
|
}
|
|
43
45
|
function getTextContent(msg, separator = "\n") {
|
|
44
46
|
const textBlocks = msg.content.filter((block) => block.type === "text");
|
|
45
|
-
if (textBlocks.length === 0)
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
47
|
+
if (textBlocks.length === 0) return null;
|
|
48
48
|
return textBlocks.map((block) => block.text).join(separator);
|
|
49
49
|
}
|
|
50
50
|
function getContentBlocks(msg, blockType) {
|
|
@@ -256,10 +256,10 @@ var FormatterBase = class {
|
|
|
256
256
|
textualOutput.push(block.text);
|
|
257
257
|
break;
|
|
258
258
|
default:
|
|
259
|
-
const type = block.source.
|
|
259
|
+
const type = block.source.media_type.split("/")[0];
|
|
260
260
|
if (type !== "image" && type !== "audio" && type !== "video") {
|
|
261
261
|
console.log(
|
|
262
|
-
`Unsupported media type '${block.source.
|
|
262
|
+
`Unsupported media type '${block.source.media_type}' in tool output. Only image, audio and video are supported.`
|
|
263
263
|
);
|
|
264
264
|
break;
|
|
265
265
|
}
|
|
@@ -283,7 +283,7 @@ var FormatterBase = class {
|
|
|
283
283
|
}
|
|
284
284
|
const promotedBlocks = [];
|
|
285
285
|
promotedData.forEach(({ id, block }) => {
|
|
286
|
-
const type = block.source.
|
|
286
|
+
const type = block.source.media_type.split("/")[0];
|
|
287
287
|
promotedBlocks.push({
|
|
288
288
|
id: crypto.randomUUID(),
|
|
289
289
|
type: "text",
|
|
@@ -429,10 +429,10 @@ var DashScopeChatFormatter = class extends FormatterBase {
|
|
|
429
429
|
* @returns An object representing the formatted multimodal content.
|
|
430
430
|
*/
|
|
431
431
|
_formatMultimodalBlock(block) {
|
|
432
|
-
const type = block.source.
|
|
432
|
+
const type = block.source.media_type.split("/")[0];
|
|
433
433
|
if (!["image", "audio", "video"].includes(type)) {
|
|
434
434
|
console.log(
|
|
435
|
-
`Skip unsupported media type ${block.source.
|
|
435
|
+
`Skip unsupported media type ${block.source.media_type} in DashScopeChatFormatter. Only image, audio and video are supported.`
|
|
436
436
|
);
|
|
437
437
|
return [];
|
|
438
438
|
}
|
|
@@ -441,7 +441,7 @@ var DashScopeChatFormatter = class extends FormatterBase {
|
|
|
441
441
|
}
|
|
442
442
|
return [
|
|
443
443
|
{
|
|
444
|
-
[type]: `data:${block.source.
|
|
444
|
+
[type]: `data:${block.source.media_type};base64,${block.source.data}`
|
|
445
445
|
}
|
|
446
446
|
];
|
|
447
447
|
}
|
|
@@ -692,7 +692,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
|
|
|
692
692
|
block,
|
|
693
693
|
role
|
|
694
694
|
}) {
|
|
695
|
-
const type = block.source.
|
|
695
|
+
const type = block.source.media_type.split("/")[0];
|
|
696
696
|
if (type === "image") {
|
|
697
697
|
return [
|
|
698
698
|
{
|
|
@@ -715,7 +715,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
|
|
|
715
715
|
];
|
|
716
716
|
}
|
|
717
717
|
console.log(
|
|
718
|
-
`Skip unsupported media type ${block.source.
|
|
718
|
+
`Skip unsupported media type ${block.source.media_type} in OpenAIChatFormatter. Only image and audio are supported.`
|
|
719
719
|
);
|
|
720
720
|
return [];
|
|
721
721
|
}
|
|
@@ -726,7 +726,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
|
|
|
726
726
|
*/
|
|
727
727
|
async _toOpenAIImageURL(block) {
|
|
728
728
|
if (block.source.type === "base64") {
|
|
729
|
-
return `data:${block.source.
|
|
729
|
+
return `data:${block.source.media_type};base64,${block.source.data}`;
|
|
730
730
|
}
|
|
731
731
|
const sourceUrl = block.source.url;
|
|
732
732
|
if (sourceUrl.startsWith("http://") || sourceUrl.startsWith("https://")) {
|
|
@@ -747,7 +747,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
|
|
|
747
747
|
);
|
|
748
748
|
}
|
|
749
749
|
const file = await (0, import_promises.readFile)(localPath);
|
|
750
|
-
const mime = block.source.
|
|
750
|
+
const mime = block.source.media_type || `image/${ext.slice(1)}`;
|
|
751
751
|
return `data:${mime};base64,${file.toString("base64")}`;
|
|
752
752
|
}
|
|
753
753
|
/**
|
|
@@ -763,10 +763,10 @@ var OpenAIChatFormatter = class extends FormatterBase {
|
|
|
763
763
|
["audio/mpeg", "mp3"]
|
|
764
764
|
]);
|
|
765
765
|
if (block.source.type === "base64") {
|
|
766
|
-
const format2 = supportedMediaTypes.get(block.source.
|
|
766
|
+
const format2 = supportedMediaTypes.get(block.source.media_type);
|
|
767
767
|
if (!format2) {
|
|
768
768
|
throw new TypeError(
|
|
769
|
-
`Unsupported audio media type: ${block.source.
|
|
769
|
+
`Unsupported audio media type: ${block.source.media_type}, only audio/wav and audio/mp3 are supported.`
|
|
770
770
|
);
|
|
771
771
|
}
|
|
772
772
|
return { data: block.source.data, format: format2 };
|
|
@@ -938,7 +938,8 @@ var DashScopeChatModel = class extends ChatModelBase {
|
|
|
938
938
|
type: "tool_call",
|
|
939
939
|
id: String(toolCall.id),
|
|
940
940
|
name: String(toolCall.function.name),
|
|
941
|
-
input: inputString
|
|
941
|
+
input: inputString,
|
|
942
|
+
state: "pending"
|
|
942
943
|
});
|
|
943
944
|
}
|
|
944
945
|
});
|
|
@@ -1037,7 +1038,8 @@ var DashScopeChatModel = class extends ChatModelBase {
|
|
|
1037
1038
|
type: "tool_call",
|
|
1038
1039
|
id: meta.id,
|
|
1039
1040
|
name: meta.name,
|
|
1040
|
-
input: deltaArgs
|
|
1041
|
+
input: deltaArgs,
|
|
1042
|
+
state: "pending"
|
|
1041
1043
|
});
|
|
1042
1044
|
}
|
|
1043
1045
|
});
|
|
@@ -1064,7 +1066,8 @@ var DashScopeChatModel = class extends ChatModelBase {
|
|
|
1064
1066
|
type: "tool_call",
|
|
1065
1067
|
id: meta.id,
|
|
1066
1068
|
name: meta.name,
|
|
1067
|
-
input: accToolInputs.get(index) || "{}"
|
|
1069
|
+
input: accToolInputs.get(index) || "{}",
|
|
1070
|
+
state: "pending"
|
|
1068
1071
|
});
|
|
1069
1072
|
});
|
|
1070
1073
|
const blocks = this._dataToBlocks(accText, accThinking, finalToolCalls);
|
|
@@ -1212,7 +1215,8 @@ var DeepSeekChatModel = class extends ChatModelBase {
|
|
|
1212
1215
|
type: "tool_call",
|
|
1213
1216
|
id: String(toolCall.id),
|
|
1214
1217
|
name: String(toolCall.function.name),
|
|
1215
|
-
input: inputString
|
|
1218
|
+
input: inputString,
|
|
1219
|
+
state: "pending"
|
|
1216
1220
|
});
|
|
1217
1221
|
}
|
|
1218
1222
|
});
|
|
@@ -1309,7 +1313,8 @@ var DeepSeekChatModel = class extends ChatModelBase {
|
|
|
1309
1313
|
type: "tool_call",
|
|
1310
1314
|
id: meta.id,
|
|
1311
1315
|
name: meta.name,
|
|
1312
|
-
input: deltaArgs
|
|
1316
|
+
input: deltaArgs,
|
|
1317
|
+
state: "pending"
|
|
1313
1318
|
});
|
|
1314
1319
|
}
|
|
1315
1320
|
});
|
|
@@ -1336,7 +1341,8 @@ var DeepSeekChatModel = class extends ChatModelBase {
|
|
|
1336
1341
|
type: "tool_call",
|
|
1337
1342
|
id: meta.id,
|
|
1338
1343
|
name: meta.name,
|
|
1339
|
-
input: accToolInputs.get(index) || "{}"
|
|
1344
|
+
input: accToolInputs.get(index) || "{}",
|
|
1345
|
+
state: "pending"
|
|
1340
1346
|
});
|
|
1341
1347
|
});
|
|
1342
1348
|
const blocks = this._accDataToBlocks(accText, accThinking, finalToolCalls);
|
|
@@ -1509,7 +1515,8 @@ var OllamaChatModel = class extends ChatModelBase {
|
|
|
1509
1515
|
type: "tool_call",
|
|
1510
1516
|
id: toolId,
|
|
1511
1517
|
name: func.name,
|
|
1512
|
-
input: JSON.stringify(func.arguments)
|
|
1518
|
+
input: JSON.stringify(func.arguments),
|
|
1519
|
+
state: "pending"
|
|
1513
1520
|
};
|
|
1514
1521
|
toolCalls.set(toolId, toolCallBlock);
|
|
1515
1522
|
deltaToolCalls.set(toolId, toolCallBlock);
|
|
@@ -1569,7 +1576,8 @@ var OllamaChatModel = class extends ChatModelBase {
|
|
|
1569
1576
|
type: "tool_call",
|
|
1570
1577
|
id: `${idx}_${toolCall.function.name}`,
|
|
1571
1578
|
name: toolCall.function.name,
|
|
1572
|
-
input: JSON.stringify(toolCall.function.arguments)
|
|
1579
|
+
input: JSON.stringify(toolCall.function.arguments),
|
|
1580
|
+
state: "pending"
|
|
1573
1581
|
});
|
|
1574
1582
|
}
|
|
1575
1583
|
}
|
|
@@ -1706,7 +1714,8 @@ var OpenAIChatModel = class extends ChatModelBase {
|
|
|
1706
1714
|
type: "tool_call",
|
|
1707
1715
|
id: toolCall.id,
|
|
1708
1716
|
name: toolCall.function.name,
|
|
1709
|
-
input: toolCall.function.arguments
|
|
1717
|
+
input: toolCall.function.arguments,
|
|
1718
|
+
state: "pending"
|
|
1710
1719
|
});
|
|
1711
1720
|
}
|
|
1712
1721
|
});
|
|
@@ -1800,7 +1809,8 @@ var OpenAIChatModel = class extends ChatModelBase {
|
|
|
1800
1809
|
type: "tool_call",
|
|
1801
1810
|
id: meta.id,
|
|
1802
1811
|
name: meta.name,
|
|
1803
|
-
input: deltaArgs
|
|
1812
|
+
input: deltaArgs,
|
|
1813
|
+
state: "pending"
|
|
1804
1814
|
});
|
|
1805
1815
|
}
|
|
1806
1816
|
});
|
|
@@ -1829,7 +1839,8 @@ var OpenAIChatModel = class extends ChatModelBase {
|
|
|
1829
1839
|
type: "tool_call",
|
|
1830
1840
|
id: meta.id,
|
|
1831
1841
|
name: meta.name,
|
|
1832
|
-
input: accToolInputs.get(index) || "{}"
|
|
1842
|
+
input: accToolInputs.get(index) || "{}",
|
|
1843
|
+
state: "pending"
|
|
1833
1844
|
});
|
|
1834
1845
|
});
|
|
1835
1846
|
const blocks = this._accDataToBlocks(accText, finalToolCalls);
|