@agentrun/sdk 0.0.3 → 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.
Files changed (130) hide show
  1. package/README.md +20 -15
  2. package/dist/agent-runtime/api/index.cjs +907 -0
  3. package/dist/agent-runtime/api/index.cjs.map +1 -0
  4. package/dist/agent-runtime/api/index.d.cts +193 -0
  5. package/dist/agent-runtime/api/index.d.ts +193 -0
  6. package/dist/agent-runtime/api/index.js +882 -0
  7. package/dist/agent-runtime/api/index.js.map +1 -0
  8. package/dist/agent-runtime/index.cjs +2528 -0
  9. package/dist/agent-runtime/index.cjs.map +1 -0
  10. package/dist/agent-runtime/index.d.cts +778 -0
  11. package/dist/agent-runtime/index.d.ts +778 -0
  12. package/dist/agent-runtime/index.js +2496 -0
  13. package/dist/agent-runtime/index.js.map +1 -0
  14. package/dist/base-K1GMfJbH.d.ts +59 -0
  15. package/dist/base-xcWt5bua.d.cts +59 -0
  16. package/dist/client-DHXxjuo3.d.ts +58 -0
  17. package/dist/client-DPUTs69s.d.cts +58 -0
  18. package/dist/config-07gMelJP.d.cts +125 -0
  19. package/dist/config-07gMelJP.d.ts +125 -0
  20. package/dist/control-api-BWD4eua5.d.cts +27 -0
  21. package/dist/control-api-d-82Sgpr.d.ts +27 -0
  22. package/dist/credential/api/index.cjs +655 -0
  23. package/dist/credential/api/index.cjs.map +1 -0
  24. package/dist/credential/api/index.d.cts +93 -0
  25. package/dist/credential/api/index.d.ts +93 -0
  26. package/dist/credential/api/index.js +630 -0
  27. package/dist/credential/api/index.js.map +1 -0
  28. package/dist/credential/index.cjs +1286 -0
  29. package/dist/credential/index.cjs.map +1 -0
  30. package/dist/credential/index.d.cts +246 -0
  31. package/dist/credential/index.d.ts +246 -0
  32. package/dist/credential/index.js +1263 -0
  33. package/dist/credential/index.js.map +1 -0
  34. package/dist/data-api-B-4h9_Vf.d.ts +166 -0
  35. package/dist/data-api-DsG-8JRQ.d.cts +166 -0
  36. package/dist/exception-DM9H2Rpo.d.cts +68 -0
  37. package/dist/exception-DM9H2Rpo.d.ts +68 -0
  38. package/dist/index.cjs +29281 -1427
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.cts +38 -4485
  41. package/dist/index.d.ts +38 -4485
  42. package/dist/index.js +29259 -1426
  43. package/dist/index.js.map +1 -1
  44. package/dist/integration/builtin/index.cjs +9399 -0
  45. package/dist/integration/builtin/index.cjs.map +1 -0
  46. package/dist/integration/builtin/index.d.cts +692 -0
  47. package/dist/integration/builtin/index.d.ts +692 -0
  48. package/dist/integration/builtin/index.js +9363 -0
  49. package/dist/integration/builtin/index.js.map +1 -0
  50. package/dist/integration/index.cjs +9524 -0
  51. package/dist/integration/index.cjs.map +1 -0
  52. package/dist/integration/index.d.cts +98 -0
  53. package/dist/integration/index.d.ts +98 -0
  54. package/dist/integration/index.js +9481 -0
  55. package/dist/integration/index.js.map +1 -0
  56. package/dist/integration/mastra/index.cjs +9383 -0
  57. package/dist/integration/mastra/index.cjs.map +1 -0
  58. package/dist/integration/mastra/index.d.cts +186 -0
  59. package/dist/integration/mastra/index.d.ts +186 -0
  60. package/dist/integration/mastra/index.js +9348 -0
  61. package/dist/integration/mastra/index.js.map +1 -0
  62. package/dist/model/index.cjs +2392 -0
  63. package/dist/model/index.cjs.map +1 -0
  64. package/dist/model/index.d.cts +97 -0
  65. package/dist/model/index.d.ts +97 -0
  66. package/dist/model/index.js +2368 -0
  67. package/dist/model/index.js.map +1 -0
  68. package/dist/model--I90nCqy.d.cts +66 -0
  69. package/dist/model--I90nCqy.d.ts +66 -0
  70. package/dist/model-BV7A6Trb.d.cts +512 -0
  71. package/dist/model-DGBy-o_L.d.cts +176 -0
  72. package/dist/model-DGBy-o_L.d.ts +176 -0
  73. package/dist/model-RiiiZnou.d.ts +512 -0
  74. package/dist/model-service-D-P2FZNi.d.ts +540 -0
  75. package/dist/model-service-VpzBb7rV.d.cts +540 -0
  76. package/dist/resource-CQovFUeh.d.cts +44 -0
  77. package/dist/resource-DnE_DEka.d.ts +44 -0
  78. package/dist/sandbox/index.cjs +3557 -0
  79. package/dist/sandbox/index.cjs.map +1 -0
  80. package/dist/sandbox/index.d.cts +1598 -0
  81. package/dist/sandbox/index.d.ts +1598 -0
  82. package/dist/sandbox/index.js +3532 -0
  83. package/dist/sandbox/index.js.map +1 -0
  84. package/dist/server/adapter/index.cjs +24886 -0
  85. package/dist/server/adapter/index.cjs.map +1 -0
  86. package/dist/server/adapter/index.d.cts +68 -0
  87. package/dist/server/adapter/index.d.ts +68 -0
  88. package/dist/server/adapter/index.js +24883 -0
  89. package/dist/server/adapter/index.js.map +1 -0
  90. package/dist/server/core/index.cjs +313 -0
  91. package/dist/server/core/index.cjs.map +1 -0
  92. package/dist/server/core/index.d.cts +58 -0
  93. package/dist/server/core/index.d.ts +58 -0
  94. package/dist/server/core/index.js +309 -0
  95. package/dist/server/core/index.js.map +1 -0
  96. package/dist/server/index.cjs +25098 -0
  97. package/dist/server/index.cjs.map +1 -0
  98. package/dist/server/index.d.cts +73 -0
  99. package/dist/server/index.d.ts +73 -0
  100. package/dist/server/index.js +25067 -0
  101. package/dist/server/index.js.map +1 -0
  102. package/dist/server/protocol/index.cjs +1057 -0
  103. package/dist/server/protocol/index.cjs.map +1 -0
  104. package/dist/server/protocol/index.d.cts +135 -0
  105. package/dist/server/protocol/index.d.ts +135 -0
  106. package/dist/server/protocol/index.js +1053 -0
  107. package/dist/server/protocol/index.js.map +1 -0
  108. package/dist/tool-CG0LY-ov.d.cts +155 -0
  109. package/dist/tool-JJHam0ms.d.ts +155 -0
  110. package/dist/toolset/api/index.cjs +754 -0
  111. package/dist/toolset/api/index.cjs.map +1 -0
  112. package/dist/toolset/api/index.d.cts +207 -0
  113. package/dist/toolset/api/index.d.ts +207 -0
  114. package/dist/toolset/api/index.js +727 -0
  115. package/dist/toolset/api/index.js.map +1 -0
  116. package/dist/toolset/index.cjs +1945 -0
  117. package/dist/toolset/index.cjs.map +1 -0
  118. package/dist/toolset/index.d.cts +182 -0
  119. package/dist/toolset/index.d.ts +182 -0
  120. package/dist/toolset/index.js +1920 -0
  121. package/dist/toolset/index.js.map +1 -0
  122. package/dist/toolset-BYDvhwRp.d.cts +394 -0
  123. package/dist/toolset-CSRsJxCb.d.ts +394 -0
  124. package/dist/utils/index.cjs +994 -0
  125. package/dist/utils/index.cjs.map +1 -0
  126. package/dist/utils/index.d.cts +30 -0
  127. package/dist/utils/index.d.ts +30 -0
  128. package/dist/utils/index.js +951 -0
  129. package/dist/utils/index.js.map +1 -0
  130. package/package.json +65 -13
@@ -0,0 +1,186 @@
1
+ import { C as Config } from '../../config-07gMelJP.cjs';
2
+ export { p as TemplateType } from '../../model-BV7A6Trb.cjs';
3
+ import { LanguageModelV3 } from '@ai-sdk/provider';
4
+ import { ToolsInput } from '@mastra/core/agent';
5
+ import { ToolAction, ToolExecutionContext } from '@mastra/core/tools';
6
+ import { a as AgentEvent } from '../../model-DGBy-o_L.cjs';
7
+ import { ChunkType } from '@mastra/core/stream';
8
+ import '../../model--I90nCqy.cjs';
9
+
10
+ /**
11
+ * Mastra Event Converter
12
+ * Mastra 事件转换器
13
+ *
14
+ * Converts Mastra stream events (ChunkType) to AgentRun events (AgentEventItem).
15
+ * 将 Mastra 流式事件(ChunkType)转换为 AgentRun 事件(AgentEventItem)。
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { MastraConverter } from '@alicloud/agentrun-sdk/integration/mastra';
20
+ * import { Agent } from '@mastra/core/agent';
21
+ *
22
+ * const agent = new Agent({...});
23
+ * const converter = new MastraConverter();
24
+ *
25
+ * async function* invokeAgent(request: AgentRequest) {
26
+ * const mastraStream = await agent.stream(request.messages);
27
+ *
28
+ * for await (const chunk of mastraStream.fullStream) {
29
+ * const events = converter.convert(chunk);
30
+ * for (const event of events) {
31
+ * yield event;
32
+ * }
33
+ * }
34
+ * }
35
+ * ```
36
+ */
37
+
38
+ /**
39
+ * Agent event item - can be a string (text) or AgentEvent (structured event)
40
+ * Agent 事件项 - 可以是字符串(文本)或 AgentEvent(结构化事件)
41
+ */
42
+ type AgentEventItem = string | AgentEvent;
43
+ /**
44
+ * Mastra Event Converter
45
+ * Mastra 事件转换器
46
+ *
47
+ * Converts Mastra stream chunk events to AgentRun standard events.
48
+ * Supports text streaming, tool calls, and error handling.
49
+ *
50
+ * 将 Mastra 流式 chunk 事件转换为 AgentRun 标准事件。
51
+ * 支持文本流式输出、工具调用和错误处理。
52
+ */
53
+ declare class MastraConverter {
54
+ /**
55
+ * Convert a single Mastra chunk to AgentRun events
56
+ * 转换单个 Mastra chunk 为 AgentRun 事件
57
+ *
58
+ * @param chunk - Mastra stream chunk
59
+ * @returns Generator of AgentEventItem (strings or AgentEvents)
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const converter = new MastraConverter();
64
+ * for await (const chunk of mastraStream.fullStream) {
65
+ * const events = converter.convert(chunk);
66
+ * for (const event of events) {
67
+ * yield event;
68
+ * }
69
+ * }
70
+ * ```
71
+ */
72
+ convert<T extends ChunkType<U>, U = undefined>(chunk: T): Generator<AgentEventItem>;
73
+ /**
74
+ * Extract text content from chunk payload
75
+ * 从 chunk payload 提取文本内容
76
+ */
77
+ private extractTextFromPayload;
78
+ /**
79
+ * Extract tool call information from chunk payload
80
+ * 从 chunk payload 提取工具调用信息
81
+ */
82
+ private extractToolCallFromPayload;
83
+ /**
84
+ * Extract tool result information from chunk payload
85
+ * 从 chunk payload 提取工具结果信息
86
+ */
87
+ private extractToolResultFromPayload;
88
+ /**
89
+ * Extract error message from chunk payload
90
+ * 从 chunk payload 提取错误信息
91
+ */
92
+ private extractErrorFromPayload;
93
+ }
94
+
95
+ /**
96
+ * AgentRun Mastra Integration Module
97
+ * AgentRun 与 Mastra 的集成模块
98
+ *
99
+ * Provides integration functions for using AgentRun resources with Mastra framework.
100
+ * This module handles all Mastra-specific conversions to avoid dependencies in builtin module.
101
+ *
102
+ * 提供将 AgentRun 资源与 Mastra 框架集成的函数。
103
+ * 本模块处理所有 Mastra 特定的转换,避免在 builtin 模块中引入依赖。
104
+ */
105
+
106
+ /**
107
+ * Mastra Tool type - a ToolAction with any schema types
108
+ */
109
+ type MastraTool = ToolAction<any, any, any, any, any, string>;
110
+ /**
111
+ * Get Mastra-compatible model from AgentRun ModelService/ModelProxy name
112
+ * 根据 AgentRun ModelService/ModelProxy name 获取 Mastra 可直接使用的 model
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const llm = await model({ name: 'qwen-max' });
117
+ * const agent = createAgent({ model: llm });
118
+ * ```
119
+ */
120
+ declare function model(params: {
121
+ name: string;
122
+ modelName?: string;
123
+ config?: Config;
124
+ }): Promise<LanguageModelV3>;
125
+ /**
126
+ * Create a Mastra tool from ToolAction definition
127
+ * 从 ToolAction 定义创建 Mastra 工具
128
+ *
129
+ * This is a low-level function for creating custom Mastra tools.
130
+ */
131
+ declare function createMastraTool<TId extends string = string, TSchemaIn = unknown, TSchemaOut = unknown, TSuspend = unknown, TResume = unknown, TContext extends ToolExecutionContext<TSuspend, TResume> = ToolExecutionContext<TSuspend, TResume>>(params: ToolAction<TSchemaIn, TSchemaOut, TSuspend, TResume, TContext, TId>): Promise<ToolAction<TSchemaIn, TSchemaOut, TSuspend, TResume, TContext, TId>>;
132
+ /**
133
+ * Get Mastra-compatible tools from AgentRun ToolSet name
134
+ * 根据 AgentRun 工具集 name 获取 Mastra 可直接使用的 tools
135
+ *
136
+ * Returns a ToolsInput map that can be directly used with Mastra Agent.
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const tools = await toolset({ name: 'my-toolset' });
141
+ * const agent = new Agent({ tools });
142
+ * ```
143
+ */
144
+ declare function toolset(params: {
145
+ name: string;
146
+ config?: Config;
147
+ }): Promise<ToolsInput>;
148
+ /**
149
+ * Get Mastra-compatible sandbox tools from AgentRun sandbox template
150
+ * 根据 AgentRun 沙箱模板获取 Mastra 可直接使用的 sandbox 工具
151
+ *
152
+ * Returns a ToolsInput map that can be directly used with Mastra Agent.
153
+ *
154
+ * @param params.templateName - Name of the sandbox template
155
+ * @param params.templateType - Type of sandbox (CODE_INTERPRETER or BROWSER)
156
+ * @param params.sandboxIdleTimeoutSeconds - Idle timeout in seconds (default: 300)
157
+ * @param params.config - Configuration object
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // Get code interpreter tools
162
+ * const codeTools = await sandbox({
163
+ * templateName: 'my-code-interpreter-template',
164
+ * templateType: TemplateType.CODE_INTERPRETER,
165
+ * });
166
+ *
167
+ * // Get browser automation tools
168
+ * const browserTools = await sandbox({
169
+ * templateName: 'my-browser-template',
170
+ * templateType: TemplateType.BROWSER,
171
+ * });
172
+ *
173
+ * // Use with Mastra agent
174
+ * const agent = new Agent({
175
+ * tools: { ...codeTools },
176
+ * model: await model({ name: 'qwen-max' }),
177
+ * });
178
+ * ```
179
+ */
180
+ declare function sandbox(params: {
181
+ templateName: string;
182
+ sandboxIdleTimeoutSeconds?: number;
183
+ config?: Config;
184
+ }): Promise<ToolsInput>;
185
+
186
+ export { type AgentEventItem, MastraConverter, type MastraTool, createMastraTool, model, sandbox, toolset };
@@ -0,0 +1,186 @@
1
+ import { C as Config } from '../../config-07gMelJP.js';
2
+ export { p as TemplateType } from '../../model-RiiiZnou.js';
3
+ import { LanguageModelV3 } from '@ai-sdk/provider';
4
+ import { ToolsInput } from '@mastra/core/agent';
5
+ import { ToolAction, ToolExecutionContext } from '@mastra/core/tools';
6
+ import { a as AgentEvent } from '../../model-DGBy-o_L.js';
7
+ import { ChunkType } from '@mastra/core/stream';
8
+ import '../../model--I90nCqy.js';
9
+
10
+ /**
11
+ * Mastra Event Converter
12
+ * Mastra 事件转换器
13
+ *
14
+ * Converts Mastra stream events (ChunkType) to AgentRun events (AgentEventItem).
15
+ * 将 Mastra 流式事件(ChunkType)转换为 AgentRun 事件(AgentEventItem)。
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { MastraConverter } from '@alicloud/agentrun-sdk/integration/mastra';
20
+ * import { Agent } from '@mastra/core/agent';
21
+ *
22
+ * const agent = new Agent({...});
23
+ * const converter = new MastraConverter();
24
+ *
25
+ * async function* invokeAgent(request: AgentRequest) {
26
+ * const mastraStream = await agent.stream(request.messages);
27
+ *
28
+ * for await (const chunk of mastraStream.fullStream) {
29
+ * const events = converter.convert(chunk);
30
+ * for (const event of events) {
31
+ * yield event;
32
+ * }
33
+ * }
34
+ * }
35
+ * ```
36
+ */
37
+
38
+ /**
39
+ * Agent event item - can be a string (text) or AgentEvent (structured event)
40
+ * Agent 事件项 - 可以是字符串(文本)或 AgentEvent(结构化事件)
41
+ */
42
+ type AgentEventItem = string | AgentEvent;
43
+ /**
44
+ * Mastra Event Converter
45
+ * Mastra 事件转换器
46
+ *
47
+ * Converts Mastra stream chunk events to AgentRun standard events.
48
+ * Supports text streaming, tool calls, and error handling.
49
+ *
50
+ * 将 Mastra 流式 chunk 事件转换为 AgentRun 标准事件。
51
+ * 支持文本流式输出、工具调用和错误处理。
52
+ */
53
+ declare class MastraConverter {
54
+ /**
55
+ * Convert a single Mastra chunk to AgentRun events
56
+ * 转换单个 Mastra chunk 为 AgentRun 事件
57
+ *
58
+ * @param chunk - Mastra stream chunk
59
+ * @returns Generator of AgentEventItem (strings or AgentEvents)
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const converter = new MastraConverter();
64
+ * for await (const chunk of mastraStream.fullStream) {
65
+ * const events = converter.convert(chunk);
66
+ * for (const event of events) {
67
+ * yield event;
68
+ * }
69
+ * }
70
+ * ```
71
+ */
72
+ convert<T extends ChunkType<U>, U = undefined>(chunk: T): Generator<AgentEventItem>;
73
+ /**
74
+ * Extract text content from chunk payload
75
+ * 从 chunk payload 提取文本内容
76
+ */
77
+ private extractTextFromPayload;
78
+ /**
79
+ * Extract tool call information from chunk payload
80
+ * 从 chunk payload 提取工具调用信息
81
+ */
82
+ private extractToolCallFromPayload;
83
+ /**
84
+ * Extract tool result information from chunk payload
85
+ * 从 chunk payload 提取工具结果信息
86
+ */
87
+ private extractToolResultFromPayload;
88
+ /**
89
+ * Extract error message from chunk payload
90
+ * 从 chunk payload 提取错误信息
91
+ */
92
+ private extractErrorFromPayload;
93
+ }
94
+
95
+ /**
96
+ * AgentRun Mastra Integration Module
97
+ * AgentRun 与 Mastra 的集成模块
98
+ *
99
+ * Provides integration functions for using AgentRun resources with Mastra framework.
100
+ * This module handles all Mastra-specific conversions to avoid dependencies in builtin module.
101
+ *
102
+ * 提供将 AgentRun 资源与 Mastra 框架集成的函数。
103
+ * 本模块处理所有 Mastra 特定的转换,避免在 builtin 模块中引入依赖。
104
+ */
105
+
106
+ /**
107
+ * Mastra Tool type - a ToolAction with any schema types
108
+ */
109
+ type MastraTool = ToolAction<any, any, any, any, any, string>;
110
+ /**
111
+ * Get Mastra-compatible model from AgentRun ModelService/ModelProxy name
112
+ * 根据 AgentRun ModelService/ModelProxy name 获取 Mastra 可直接使用的 model
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const llm = await model({ name: 'qwen-max' });
117
+ * const agent = createAgent({ model: llm });
118
+ * ```
119
+ */
120
+ declare function model(params: {
121
+ name: string;
122
+ modelName?: string;
123
+ config?: Config;
124
+ }): Promise<LanguageModelV3>;
125
+ /**
126
+ * Create a Mastra tool from ToolAction definition
127
+ * 从 ToolAction 定义创建 Mastra 工具
128
+ *
129
+ * This is a low-level function for creating custom Mastra tools.
130
+ */
131
+ declare function createMastraTool<TId extends string = string, TSchemaIn = unknown, TSchemaOut = unknown, TSuspend = unknown, TResume = unknown, TContext extends ToolExecutionContext<TSuspend, TResume> = ToolExecutionContext<TSuspend, TResume>>(params: ToolAction<TSchemaIn, TSchemaOut, TSuspend, TResume, TContext, TId>): Promise<ToolAction<TSchemaIn, TSchemaOut, TSuspend, TResume, TContext, TId>>;
132
+ /**
133
+ * Get Mastra-compatible tools from AgentRun ToolSet name
134
+ * 根据 AgentRun 工具集 name 获取 Mastra 可直接使用的 tools
135
+ *
136
+ * Returns a ToolsInput map that can be directly used with Mastra Agent.
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const tools = await toolset({ name: 'my-toolset' });
141
+ * const agent = new Agent({ tools });
142
+ * ```
143
+ */
144
+ declare function toolset(params: {
145
+ name: string;
146
+ config?: Config;
147
+ }): Promise<ToolsInput>;
148
+ /**
149
+ * Get Mastra-compatible sandbox tools from AgentRun sandbox template
150
+ * 根据 AgentRun 沙箱模板获取 Mastra 可直接使用的 sandbox 工具
151
+ *
152
+ * Returns a ToolsInput map that can be directly used with Mastra Agent.
153
+ *
154
+ * @param params.templateName - Name of the sandbox template
155
+ * @param params.templateType - Type of sandbox (CODE_INTERPRETER or BROWSER)
156
+ * @param params.sandboxIdleTimeoutSeconds - Idle timeout in seconds (default: 300)
157
+ * @param params.config - Configuration object
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // Get code interpreter tools
162
+ * const codeTools = await sandbox({
163
+ * templateName: 'my-code-interpreter-template',
164
+ * templateType: TemplateType.CODE_INTERPRETER,
165
+ * });
166
+ *
167
+ * // Get browser automation tools
168
+ * const browserTools = await sandbox({
169
+ * templateName: 'my-browser-template',
170
+ * templateType: TemplateType.BROWSER,
171
+ * });
172
+ *
173
+ * // Use with Mastra agent
174
+ * const agent = new Agent({
175
+ * tools: { ...codeTools },
176
+ * model: await model({ name: 'qwen-max' }),
177
+ * });
178
+ * ```
179
+ */
180
+ declare function sandbox(params: {
181
+ templateName: string;
182
+ sandboxIdleTimeoutSeconds?: number;
183
+ config?: Config;
184
+ }): Promise<ToolsInput>;
185
+
186
+ export { type AgentEventItem, MastraConverter, type MastraTool, createMastraTool, model, sandbox, toolset };