@cloudbase/agent-ui-web 0.0.2

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,215 @@
1
+ import { Schema, Tool, ZodInfer } from '@cloudbase/agent-shared';
2
+ import React$1 from 'react';
3
+
4
+ type Interrupt = {
5
+ id: string;
6
+ reason: string;
7
+ payload: unknown;
8
+ };
9
+ type InterruptWithResume = {
10
+ renderWithResume: (props: {
11
+ interrupt: Interrupt;
12
+ resume: (result: unknown) => void;
13
+ }) => React$1.ReactNode;
14
+ };
15
+
16
+ type UIMessageUser = {
17
+ role: "user";
18
+ parts: Array<UIMessagePartText>;
19
+ };
20
+ type UIMessagePartToolCallWithRender = UIMessagePartToolCall & {
21
+ render?: () => React.ReactNode;
22
+ };
23
+ type UIMessagePartInterrupt = {
24
+ type: "interrupt";
25
+ interrupt: Interrupt;
26
+ render?: () => React.ReactNode;
27
+ };
28
+ type UIMessageAssistant = {
29
+ role: "assistant";
30
+ parts: Array<UIMessagePartText | UIMessagePartToolCallWithRender | UIMessagePartInterrupt>;
31
+ };
32
+ type UIMessagePart = UIMessagePartText | UIMessagePartToolCall | UIMessagePartInterrupt;
33
+ type UIMessagePartText = {
34
+ type: "text";
35
+ text: string;
36
+ };
37
+ type UIMessagePartToolCall = {
38
+ type: "tool-call";
39
+ id: string;
40
+ name: string;
41
+ arguments: string;
42
+ result?: string;
43
+ state?: "input-streaming" | "input-available" | "output-available" | "output-error";
44
+ errorText?: string;
45
+ };
46
+ type UIMessage = UIMessageUser | UIMessageAssistant;
47
+
48
+ type ClientToolWithInputSchema<TSchema extends Schema> = Omit<Tool, "parameters"> & {
49
+ parameters: TSchema;
50
+ };
51
+ type ClientToolWithHandler<TSchema extends Schema> = ClientToolWithInputSchema<TSchema> & {
52
+ handler: (input: ZodInfer<TSchema>) => unknown;
53
+ };
54
+ type ClientToolWithRender<TSchema extends Schema> = ClientToolWithInputSchema<TSchema> & {
55
+ render: (props: {
56
+ input: ZodInfer<TSchema>;
57
+ part: UIMessagePartToolCall;
58
+ }) => React$1.ReactNode;
59
+ };
60
+ type ClientToolWithRenderAndWaitForResponse<TSchema extends Schema> = ClientToolWithInputSchema<TSchema> & {
61
+ renderAndWaitForResponse: (props: {
62
+ part: UIMessagePartToolCall;
63
+ submitToolResult?: (output: string) => void;
64
+ }) => React$1.ReactNode;
65
+ };
66
+ type ClientToolBase<TSchema extends Schema> = ClientToolWithInputSchema<TSchema> & {
67
+ handler?: never;
68
+ render?: never;
69
+ renderAndWaitForResponse?: never;
70
+ };
71
+ type ClientTool<TSchema extends Schema> = ClientToolBase<TSchema> | (ClientToolWithHandler<TSchema> & {
72
+ render?: never;
73
+ renderAndWaitForResponse?: never;
74
+ }) | (ClientToolWithRender<TSchema> & {
75
+ handler?: never;
76
+ renderAndWaitForResponse?: never;
77
+ }) | (ClientToolWithRenderAndWaitForResponse<TSchema> & {
78
+ handler?: never;
79
+ render?: never;
80
+ });
81
+ type ServerTool<TSchema extends Schema> = {
82
+ parameters?: TSchema;
83
+ name: string;
84
+ render: (props: {
85
+ input: ZodInfer<TSchema>;
86
+ part: UIMessagePartToolCall;
87
+ }) => React$1.ReactNode;
88
+ };
89
+ type ToolStreamingState = "input-streaming" | "input-available" | "output-available" | "output-error";
90
+
91
+ declare function clientTool<TSchema extends Schema>(tool: ClientToolBase<TSchema>): ClientToolWithInputSchema<TSchema>;
92
+ declare function clientTool<TSchema extends Schema>(tool: ClientToolWithHandler<TSchema>): ClientToolWithInputSchema<TSchema>;
93
+ declare function clientTool<TSchema extends Schema>(tool: ClientToolWithRender<TSchema>): ClientToolWithInputSchema<TSchema>;
94
+ declare function clientTool<TSchema extends Schema>(tool: ClientToolWithRenderAndWaitForResponse<TSchema>): ClientToolWithInputSchema<TSchema>;
95
+ declare function serverTool<TSchema extends Schema>(tool: ServerTool<TSchema>): ServerTool<TSchema>;
96
+
97
+ interface UseChatOptions {
98
+ url?: string;
99
+ clientTools?: ReadonlyArray<ReturnType<typeof clientTool>>;
100
+ serverTools?: ReadonlyArray<ReturnType<typeof serverTool>>;
101
+ threadId?: string;
102
+ interrupt?: InterruptWithResume;
103
+ fetch?: typeof fetch;
104
+ }
105
+ declare function useChat({ clientTools, serverTools, url, threadId, interrupt, fetch, }: UseChatOptions): {
106
+ messages: ({
107
+ role: "system";
108
+ content: string;
109
+ } | {
110
+ role: "user";
111
+ content: string;
112
+ } | {
113
+ role: "tool";
114
+ content: string;
115
+ toolCallId: string;
116
+ } | {
117
+ role: "assistant";
118
+ content?: string | undefined;
119
+ toolCalls?: {
120
+ id: string;
121
+ type: "function";
122
+ function: {
123
+ name: string;
124
+ arguments: string;
125
+ };
126
+ }[] | undefined;
127
+ })[];
128
+ setMessages: (value: ({
129
+ role: "system";
130
+ content: string;
131
+ } | {
132
+ role: "user";
133
+ content: string;
134
+ } | {
135
+ role: "tool";
136
+ content: string;
137
+ toolCallId: string;
138
+ } | {
139
+ role: "assistant";
140
+ content?: string | undefined;
141
+ toolCalls?: {
142
+ id: string;
143
+ type: "function";
144
+ function: {
145
+ name: string;
146
+ arguments: string;
147
+ };
148
+ }[] | undefined;
149
+ })[] | ((prev: ({
150
+ role: "system";
151
+ content: string;
152
+ } | {
153
+ role: "user";
154
+ content: string;
155
+ } | {
156
+ role: "tool";
157
+ content: string;
158
+ toolCallId: string;
159
+ } | {
160
+ role: "assistant";
161
+ content?: string | undefined;
162
+ toolCalls?: {
163
+ id: string;
164
+ type: "function";
165
+ function: {
166
+ name: string;
167
+ arguments: string;
168
+ };
169
+ }[] | undefined;
170
+ })[]) => ({
171
+ role: "system";
172
+ content: string;
173
+ } | {
174
+ role: "user";
175
+ content: string;
176
+ } | {
177
+ role: "tool";
178
+ content: string;
179
+ toolCallId: string;
180
+ } | {
181
+ role: "assistant";
182
+ content?: string | undefined;
183
+ toolCalls?: {
184
+ id: string;
185
+ type: "function";
186
+ function: {
187
+ name: string;
188
+ arguments: string;
189
+ };
190
+ }[] | undefined;
191
+ })[])) => void;
192
+ uiMessages: UIMessage[];
193
+ uiToolCalls: {
194
+ id: string;
195
+ name: string;
196
+ arguments: string;
197
+ result?: string;
198
+ state: ToolStreamingState;
199
+ errorText?: string;
200
+ }[];
201
+ sendMessage: (prop?: string | {
202
+ toolCallId: string;
203
+ content: string;
204
+ } | {
205
+ interruptId: string;
206
+ payload: unknown;
207
+ }) => Promise<void>;
208
+ loading: boolean;
209
+ streaming: boolean;
210
+ error: unknown;
211
+ };
212
+
213
+ declare function partialParse<T>(input: string): T;
214
+
215
+ export { type ClientTool, type ClientToolBase, type ClientToolWithHandler, type ClientToolWithInputSchema, type ClientToolWithRender, type ClientToolWithRenderAndWaitForResponse, type Interrupt, type InterruptWithResume, type ServerTool, type ToolStreamingState, type UIMessage, type UIMessageAssistant, type UIMessagePart, type UIMessagePartInterrupt, type UIMessagePartText, type UIMessagePartToolCall, type UIMessagePartToolCallWithRender, type UIMessageUser, clientTool, partialParse, serverTool, useChat };
@@ -0,0 +1,215 @@
1
+ import { Schema, Tool, ZodInfer } from '@cloudbase/agent-shared';
2
+ import React$1 from 'react';
3
+
4
+ type Interrupt = {
5
+ id: string;
6
+ reason: string;
7
+ payload: unknown;
8
+ };
9
+ type InterruptWithResume = {
10
+ renderWithResume: (props: {
11
+ interrupt: Interrupt;
12
+ resume: (result: unknown) => void;
13
+ }) => React$1.ReactNode;
14
+ };
15
+
16
+ type UIMessageUser = {
17
+ role: "user";
18
+ parts: Array<UIMessagePartText>;
19
+ };
20
+ type UIMessagePartToolCallWithRender = UIMessagePartToolCall & {
21
+ render?: () => React.ReactNode;
22
+ };
23
+ type UIMessagePartInterrupt = {
24
+ type: "interrupt";
25
+ interrupt: Interrupt;
26
+ render?: () => React.ReactNode;
27
+ };
28
+ type UIMessageAssistant = {
29
+ role: "assistant";
30
+ parts: Array<UIMessagePartText | UIMessagePartToolCallWithRender | UIMessagePartInterrupt>;
31
+ };
32
+ type UIMessagePart = UIMessagePartText | UIMessagePartToolCall | UIMessagePartInterrupt;
33
+ type UIMessagePartText = {
34
+ type: "text";
35
+ text: string;
36
+ };
37
+ type UIMessagePartToolCall = {
38
+ type: "tool-call";
39
+ id: string;
40
+ name: string;
41
+ arguments: string;
42
+ result?: string;
43
+ state?: "input-streaming" | "input-available" | "output-available" | "output-error";
44
+ errorText?: string;
45
+ };
46
+ type UIMessage = UIMessageUser | UIMessageAssistant;
47
+
48
+ type ClientToolWithInputSchema<TSchema extends Schema> = Omit<Tool, "parameters"> & {
49
+ parameters: TSchema;
50
+ };
51
+ type ClientToolWithHandler<TSchema extends Schema> = ClientToolWithInputSchema<TSchema> & {
52
+ handler: (input: ZodInfer<TSchema>) => unknown;
53
+ };
54
+ type ClientToolWithRender<TSchema extends Schema> = ClientToolWithInputSchema<TSchema> & {
55
+ render: (props: {
56
+ input: ZodInfer<TSchema>;
57
+ part: UIMessagePartToolCall;
58
+ }) => React$1.ReactNode;
59
+ };
60
+ type ClientToolWithRenderAndWaitForResponse<TSchema extends Schema> = ClientToolWithInputSchema<TSchema> & {
61
+ renderAndWaitForResponse: (props: {
62
+ part: UIMessagePartToolCall;
63
+ submitToolResult?: (output: string) => void;
64
+ }) => React$1.ReactNode;
65
+ };
66
+ type ClientToolBase<TSchema extends Schema> = ClientToolWithInputSchema<TSchema> & {
67
+ handler?: never;
68
+ render?: never;
69
+ renderAndWaitForResponse?: never;
70
+ };
71
+ type ClientTool<TSchema extends Schema> = ClientToolBase<TSchema> | (ClientToolWithHandler<TSchema> & {
72
+ render?: never;
73
+ renderAndWaitForResponse?: never;
74
+ }) | (ClientToolWithRender<TSchema> & {
75
+ handler?: never;
76
+ renderAndWaitForResponse?: never;
77
+ }) | (ClientToolWithRenderAndWaitForResponse<TSchema> & {
78
+ handler?: never;
79
+ render?: never;
80
+ });
81
+ type ServerTool<TSchema extends Schema> = {
82
+ parameters?: TSchema;
83
+ name: string;
84
+ render: (props: {
85
+ input: ZodInfer<TSchema>;
86
+ part: UIMessagePartToolCall;
87
+ }) => React$1.ReactNode;
88
+ };
89
+ type ToolStreamingState = "input-streaming" | "input-available" | "output-available" | "output-error";
90
+
91
+ declare function clientTool<TSchema extends Schema>(tool: ClientToolBase<TSchema>): ClientToolWithInputSchema<TSchema>;
92
+ declare function clientTool<TSchema extends Schema>(tool: ClientToolWithHandler<TSchema>): ClientToolWithInputSchema<TSchema>;
93
+ declare function clientTool<TSchema extends Schema>(tool: ClientToolWithRender<TSchema>): ClientToolWithInputSchema<TSchema>;
94
+ declare function clientTool<TSchema extends Schema>(tool: ClientToolWithRenderAndWaitForResponse<TSchema>): ClientToolWithInputSchema<TSchema>;
95
+ declare function serverTool<TSchema extends Schema>(tool: ServerTool<TSchema>): ServerTool<TSchema>;
96
+
97
+ interface UseChatOptions {
98
+ url?: string;
99
+ clientTools?: ReadonlyArray<ReturnType<typeof clientTool>>;
100
+ serverTools?: ReadonlyArray<ReturnType<typeof serverTool>>;
101
+ threadId?: string;
102
+ interrupt?: InterruptWithResume;
103
+ fetch?: typeof fetch;
104
+ }
105
+ declare function useChat({ clientTools, serverTools, url, threadId, interrupt, fetch, }: UseChatOptions): {
106
+ messages: ({
107
+ role: "system";
108
+ content: string;
109
+ } | {
110
+ role: "user";
111
+ content: string;
112
+ } | {
113
+ role: "tool";
114
+ content: string;
115
+ toolCallId: string;
116
+ } | {
117
+ role: "assistant";
118
+ content?: string | undefined;
119
+ toolCalls?: {
120
+ id: string;
121
+ type: "function";
122
+ function: {
123
+ name: string;
124
+ arguments: string;
125
+ };
126
+ }[] | undefined;
127
+ })[];
128
+ setMessages: (value: ({
129
+ role: "system";
130
+ content: string;
131
+ } | {
132
+ role: "user";
133
+ content: string;
134
+ } | {
135
+ role: "tool";
136
+ content: string;
137
+ toolCallId: string;
138
+ } | {
139
+ role: "assistant";
140
+ content?: string | undefined;
141
+ toolCalls?: {
142
+ id: string;
143
+ type: "function";
144
+ function: {
145
+ name: string;
146
+ arguments: string;
147
+ };
148
+ }[] | undefined;
149
+ })[] | ((prev: ({
150
+ role: "system";
151
+ content: string;
152
+ } | {
153
+ role: "user";
154
+ content: string;
155
+ } | {
156
+ role: "tool";
157
+ content: string;
158
+ toolCallId: string;
159
+ } | {
160
+ role: "assistant";
161
+ content?: string | undefined;
162
+ toolCalls?: {
163
+ id: string;
164
+ type: "function";
165
+ function: {
166
+ name: string;
167
+ arguments: string;
168
+ };
169
+ }[] | undefined;
170
+ })[]) => ({
171
+ role: "system";
172
+ content: string;
173
+ } | {
174
+ role: "user";
175
+ content: string;
176
+ } | {
177
+ role: "tool";
178
+ content: string;
179
+ toolCallId: string;
180
+ } | {
181
+ role: "assistant";
182
+ content?: string | undefined;
183
+ toolCalls?: {
184
+ id: string;
185
+ type: "function";
186
+ function: {
187
+ name: string;
188
+ arguments: string;
189
+ };
190
+ }[] | undefined;
191
+ })[])) => void;
192
+ uiMessages: UIMessage[];
193
+ uiToolCalls: {
194
+ id: string;
195
+ name: string;
196
+ arguments: string;
197
+ result?: string;
198
+ state: ToolStreamingState;
199
+ errorText?: string;
200
+ }[];
201
+ sendMessage: (prop?: string | {
202
+ toolCallId: string;
203
+ content: string;
204
+ } | {
205
+ interruptId: string;
206
+ payload: unknown;
207
+ }) => Promise<void>;
208
+ loading: boolean;
209
+ streaming: boolean;
210
+ error: unknown;
211
+ };
212
+
213
+ declare function partialParse<T>(input: string): T;
214
+
215
+ export { type ClientTool, type ClientToolBase, type ClientToolWithHandler, type ClientToolWithInputSchema, type ClientToolWithRender, type ClientToolWithRenderAndWaitForResponse, type Interrupt, type InterruptWithResume, type ServerTool, type ToolStreamingState, type UIMessage, type UIMessageAssistant, type UIMessagePart, type UIMessagePartInterrupt, type UIMessagePartText, type UIMessagePartToolCall, type UIMessagePartToolCallWithRender, type UIMessageUser, clientTool, partialParse, serverTool, useChat };