@cloudbase/agent-ui-miniprogram 0.0.12 → 1.0.1-alpha.7

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.
@@ -1,85 +0,0 @@
1
- /**
2
- * AG-UI Transport Implementations
3
- */
4
- import { type BaseEvent, type RunAgentInput, type Transport } from "./types";
5
- /**
6
- * Mock transport implementation for testing and development.
7
- *
8
- * Simulates an AG-UI agent backend by emitting a configurable sequence
9
- * of events. Useful for unit tests, prototyping, and demo applications.
10
- *
11
- * @example
12
- * ```typescript
13
- * // Create with predefined events
14
- * const transport = new MockTransport({
15
- * events: MockTransport.createTextResponse('Hello, world!'),
16
- * delayMs: 100, // Simulate network latency
17
- * });
18
- *
19
- * // Or set events dynamically
20
- * transport.setEvents(MockTransport.createToolCallResponse('get_weather', { city: 'NYC' }));
21
- * ```
22
- */
23
- export declare class MockTransport implements Transport {
24
- private events;
25
- private delayMs;
26
- constructor(options?: {
27
- events?: BaseEvent[];
28
- delayMs?: number;
29
- });
30
- /**
31
- * Set the events to emit during the next `run()` call.
32
- *
33
- * @param events - Array of AG-UI events to emit
34
- */
35
- setEvents(events: BaseEvent[]): void;
36
- /**
37
- * Create a simple text response event sequence.
38
- *
39
- * @param text - The text content of the assistant's response
40
- * @param messageId - Optional message ID (defaults to "msg-1")
41
- * @returns Array of events representing a complete text response
42
- */
43
- static createTextResponse(text: string, messageId?: string): BaseEvent[];
44
- /**
45
- * Create a tool call response event sequence.
46
- *
47
- * @param toolName - Name of the tool being called
48
- * @param args - Arguments to pass to the tool (will be JSON stringified)
49
- * @param toolCallId - Optional tool call ID (defaults to "tc-1")
50
- * @returns Array of events representing a tool call (without RUN_FINISHED)
51
- */
52
- static createToolCallResponse(toolName: string, args: Record<string, unknown>, toolCallId?: string): BaseEvent[];
53
- run(_input: RunAgentInput): AsyncIterable<BaseEvent>;
54
- private delay;
55
- }
56
- /**
57
- * Production transport for WeChat Cloud Development (Cloudbase).
58
- *
59
- * Connects to a WeChat AI Bot configured in the Cloud Development console.
60
- * Requires the `wx.cloud.extend.AI.bot.sendMessage` API to be available.
61
- *
62
- * @example
63
- * ```typescript
64
- * const transport = new CloudbaseTransport({
65
- * botId: 'bot-xxxxxx', // Your bot ID from Cloud Development console
66
- * });
67
- *
68
- * Component({
69
- * behaviors: [createAGUIBehavior({ transport })],
70
- * });
71
- * ```
72
- */
73
- export declare class CloudbaseTransport implements Transport {
74
- private botId;
75
- /**
76
- * Create a new CloudbaseTransport instance.
77
- *
78
- * @param options - Configuration options
79
- * @param options.botId - The bot ID from WeChat Cloud Development console
80
- */
81
- constructor(options: {
82
- botId: string;
83
- });
84
- run(input: RunAgentInput): AsyncIterable<BaseEvent>;
85
- }
package/dist/types.d.ts DELETED
@@ -1,315 +0,0 @@
1
- /**
2
- * AG-UI WeChat Miniprogram SDK Types
3
- */
4
- /**
5
- * Event types for AG-UI protocol
6
- * @see @ag-ui/core EventType
7
- */
8
- export declare enum EventType {
9
- TEXT_MESSAGE_START = "TEXT_MESSAGE_START",
10
- TEXT_MESSAGE_CONTENT = "TEXT_MESSAGE_CONTENT",
11
- TEXT_MESSAGE_END = "TEXT_MESSAGE_END",
12
- TEXT_MESSAGE_CHUNK = "TEXT_MESSAGE_CHUNK",
13
- THINKING_TEXT_MESSAGE_START = "THINKING_TEXT_MESSAGE_START",
14
- THINKING_TEXT_MESSAGE_CONTENT = "THINKING_TEXT_MESSAGE_CONTENT",
15
- THINKING_TEXT_MESSAGE_END = "THINKING_TEXT_MESSAGE_END",
16
- TOOL_CALL_START = "TOOL_CALL_START",
17
- TOOL_CALL_ARGS = "TOOL_CALL_ARGS",
18
- TOOL_CALL_END = "TOOL_CALL_END",
19
- TOOL_CALL_CHUNK = "TOOL_CALL_CHUNK",
20
- TOOL_CALL_RESULT = "TOOL_CALL_RESULT",
21
- THINKING_START = "THINKING_START",
22
- THINKING_END = "THINKING_END",
23
- STATE_SNAPSHOT = "STATE_SNAPSHOT",
24
- STATE_DELTA = "STATE_DELTA",
25
- MESSAGES_SNAPSHOT = "MESSAGES_SNAPSHOT",
26
- ACTIVITY_SNAPSHOT = "ACTIVITY_SNAPSHOT",
27
- ACTIVITY_DELTA = "ACTIVITY_DELTA",
28
- RAW = "RAW",
29
- CUSTOM = "CUSTOM",
30
- RUN_STARTED = "RUN_STARTED",
31
- RUN_FINISHED = "RUN_FINISHED",
32
- RUN_ERROR = "RUN_ERROR",
33
- STEP_STARTED = "STEP_STARTED",
34
- STEP_FINISHED = "STEP_FINISHED"
35
- }
36
- /**
37
- * Base event interface - all events have these fields
38
- */
39
- export interface BaseEvent {
40
- type: EventType;
41
- timestamp?: number;
42
- rawEvent?: unknown;
43
- }
44
- /**
45
- * Event type interfaces for type casting in switch statements
46
- */
47
- export interface RunStartedEvent extends BaseEvent {
48
- type: EventType.RUN_STARTED;
49
- threadId: string;
50
- runId: string;
51
- parentRunId?: string;
52
- }
53
- export interface RunFinishedEvent extends BaseEvent {
54
- type: EventType.RUN_FINISHED;
55
- threadId: string;
56
- runId: string;
57
- }
58
- export interface RunErrorEvent extends BaseEvent {
59
- type: EventType.RUN_ERROR;
60
- message: string;
61
- code?: string;
62
- }
63
- export interface TextMessageStartEvent extends BaseEvent {
64
- type: EventType.TEXT_MESSAGE_START;
65
- messageId: string;
66
- role: "developer" | "system" | "assistant" | "user";
67
- }
68
- export interface TextMessageContentEvent extends BaseEvent {
69
- type: EventType.TEXT_MESSAGE_CONTENT;
70
- messageId: string;
71
- delta: string;
72
- }
73
- export interface TextMessageEndEvent extends BaseEvent {
74
- type: EventType.TEXT_MESSAGE_END;
75
- messageId: string;
76
- }
77
- export interface ToolCallStartEvent extends BaseEvent {
78
- type: EventType.TOOL_CALL_START;
79
- toolCallId: string;
80
- toolCallName: string;
81
- parentMessageId?: string;
82
- }
83
- export interface ToolCallArgsEvent extends BaseEvent {
84
- type: EventType.TOOL_CALL_ARGS;
85
- toolCallId: string;
86
- delta: string;
87
- }
88
- export interface ToolCallEndEvent extends BaseEvent {
89
- type: EventType.TOOL_CALL_END;
90
- toolCallId: string;
91
- }
92
- export interface MessagesSnapshotEvent extends BaseEvent {
93
- type: EventType.MESSAGES_SNAPSHOT;
94
- messages: Message[];
95
- }
96
- /**
97
- * Message structure for AG-UI
98
- * @see @ag-ui/core Message
99
- */
100
- export interface Message {
101
- id: string;
102
- role: "user" | "assistant" | "system" | "tool" | "developer";
103
- content: string;
104
- name?: string;
105
- toolCallId?: string;
106
- toolCalls?: ToolCall[];
107
- }
108
- /**
109
- * Tool definition
110
- */
111
- export interface Tool {
112
- name: string;
113
- description: string;
114
- parameters?: Record<string, unknown>;
115
- }
116
- /**
117
- * Tool call structure
118
- */
119
- export interface ToolCall {
120
- id: string;
121
- type: "function";
122
- function: {
123
- name: string;
124
- arguments: string;
125
- };
126
- }
127
- /**
128
- * Context for agent runs
129
- */
130
- export interface Context {
131
- description: string;
132
- value: string;
133
- }
134
- /**
135
- * Input for running an agent
136
- */
137
- export interface RunAgentInput {
138
- threadId: string;
139
- runId?: string;
140
- messages?: Message[];
141
- tools?: Tool[];
142
- context?: Context[];
143
- state?: unknown;
144
- forwardedProps?: Record<string, unknown>;
145
- }
146
- /**
147
- * Transport interface - abstracts the network layer
148
- * All implementations handle their own HTTP/WebSocket details internally
149
- */
150
- export interface Transport {
151
- run(input: RunAgentInput): AsyncIterable<BaseEvent>;
152
- }
153
- /**
154
- * Parameters passed to tool handler during execution
155
- */
156
- export interface ToolHandlerParams {
157
- /** Tool name */
158
- name: string;
159
- /** Tool description */
160
- description: string;
161
- /** Unique ID for this tool call */
162
- toolCallId: string;
163
- /** Parsed arguments from the agent */
164
- args: Record<string, unknown>;
165
- }
166
- /**
167
- * Tool handler function signature
168
- * Must return a string result (or Promise<string>)
169
- */
170
- export type ToolHandler = (params: ToolHandlerParams) => string | Promise<string>;
171
- /**
172
- * Extended Tool with handler function (AG-UI Tool doesn't include handler)
173
- */
174
- export interface ClientTool extends Tool {
175
- handler: ToolHandler;
176
- }
177
- /**
178
- * Tool call execution status
179
- */
180
- export type ToolCallStatus = "pending" | "ready" | "executing" | "completed" | "failed";
181
- /**
182
- * Tool call state for UI tracking
183
- */
184
- export interface ToolCallState {
185
- /** Tool call ID (from TOOL_CALL_START event) */
186
- toolCallId: string;
187
- name: string;
188
- /** Raw accumulated args string (streaming progress) */
189
- argsString: string;
190
- /** Parsed args (available after TOOL_CALL_END) */
191
- args: Record<string, unknown>;
192
- status: ToolCallStatus;
193
- result?: unknown;
194
- error?: AGUIClientError;
195
- }
196
- /**
197
- * Text part of a UI message
198
- */
199
- export interface TextPart {
200
- /** Message ID this part belongs to */
201
- id: string;
202
- type: "text";
203
- text: string;
204
- state?: "streaming" | "done";
205
- }
206
- /**
207
- * Tool part of a UI message - extends ToolCallState with type discriminator and message id
208
- */
209
- export interface ToolPart extends ToolCallState {
210
- /** Message ID this part belongs to */
211
- id: string;
212
- type: "tool";
213
- }
214
- /**
215
- * Union of all UI message part types
216
- */
217
- export type UIMessagePart = TextPart | ToolPart;
218
- /**
219
- * UI Message - merged and structured for rendering
220
- * Consecutive assistant messages are merged, tool messages are filtered out,
221
- * content is represented as an ordered array of parts.
222
- */
223
- export interface UIMessage {
224
- /** First raw message id in the merge group */
225
- id: string;
226
- role: "user" | "assistant" | "system" | "developer";
227
- parts: UIMessagePart[];
228
- }
229
- /**
230
- * Error codes for the SDK
231
- */
232
- export type AGUIClientErrorCode = "INIT_ERROR" | "TRANSPORT_ERROR" | "RUNTIME_ERROR" | "INVALID_EVENT" | "TOOL_EXECUTION_ERROR" | "TOOL_NOT_FOUND" | "PARSE_ERROR" | "TIMEOUT" | "INVALID_CONFIG" | "UNKNOWN";
233
- /**
234
- * Structured error type for the SDK
235
- */
236
- export interface AGUIClientError {
237
- code: AGUIClientErrorCode;
238
- message: string;
239
- recoverable: boolean;
240
- details?: unknown;
241
- originalError?: Error;
242
- }
243
- /**
244
- * Initialization configuration for AGUI
245
- */
246
- export interface AGUIConfig {
247
- transport: Transport;
248
- threadId?: string;
249
- }
250
- /**
251
- * Options for createAGUIBehavior factory function
252
- */
253
- export interface CreateAGUIBehaviorOptions extends Partial<AGUIConfig> {
254
- messages?: Message[];
255
- tools?: ClientTool[];
256
- contexts?: Context[];
257
- /** Callback for every raw event received from transport */
258
- onRawEvent?: (event: BaseEvent) => void;
259
- }
260
- /**
261
- * Complete AGUI state exposed via Behavior's data
262
- */
263
- export interface AGUIState {
264
- messages: Message[];
265
- /** UI-optimized messages with merged assistant messages and parts-based content */
266
- uiMessages: UIMessage[];
267
- isRunning: boolean;
268
- runId: string | null;
269
- activeToolCalls: ToolCallState[];
270
- error: AGUIClientError | null;
271
- threadId: string;
272
- /** Registered tool definitions (without handlers, for UI display) */
273
- tools: Tool[];
274
- /** Registered contexts */
275
- contexts: Context[];
276
- }
277
- /**
278
- * The `this.agui` interface available on components using the AGUI Behavior.
279
- * Provides both methods and state getters for a unified API.
280
- *
281
- * State getters proxy to `this.data.agui.*` for convenience, so you can use
282
- * either `this.agui.messages` or `this.data.agui.messages` to read state.
283
- * WXML templates should still use `{{agui.xxx}}` which binds to `this.data.agui`.
284
- */
285
- export interface AGUINamespace extends Readonly<AGUIState> {
286
- readonly config: CreateAGUIBehaviorOptions;
287
- init(config: AGUIConfig): void;
288
- setThreadId(threadId: string): void;
289
- sendMessage(input: string | Message[]): Promise<void>;
290
- appendMessage(message: Message): void;
291
- setMessages(messages: Message[]): void;
292
- reset(): void;
293
- addTool(tool: ClientTool): void;
294
- removeTool(name: string): void;
295
- updateTool(name: string, updates: Partial<ClientTool>): void;
296
- clearTools(): void;
297
- }
298
- /**
299
- * Pending tool call during streaming
300
- */
301
- export interface PendingToolCall {
302
- id: string;
303
- name: string;
304
- argsString: string;
305
- parentMessageId?: string;
306
- }
307
- /**
308
- * Active message being streamed
309
- */
310
- export interface ActiveMessage {
311
- id: string;
312
- role: string;
313
- content: string;
314
- toolCalls?: ToolCall[];
315
- }