blink 0.1.72 → 0.1.74
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/dist/browser/agent/client/index.cjs +21 -0
- package/dist/browser/agent/client/index.d.cts +4 -0
- package/dist/browser/agent/client/index.d.ts +4 -0
- package/dist/browser/agent/client/index.js +21 -0
- package/dist/browser/agent/index.browser.cjs +1 -0
- package/dist/browser/agent/index.browser.d.cts +3 -0
- package/dist/browser/agent/index.browser.d.ts +3 -0
- package/dist/browser/agent/index.browser.js +1 -0
- package/dist/browser/chat-B5eFQu26.d.cts +129 -0
- package/dist/browser/chat-BN7SYTWY.d.ts +129 -0
- package/dist/browser/control/index.cjs +1 -0
- package/dist/browser/control/index.d.cts +187 -0
- package/dist/browser/control/index.d.ts +187 -0
- package/dist/browser/control/index.js +1 -0
- package/dist/browser/index-B5faDAC2.d.ts +53 -0
- package/dist/browser/index-C-GJWB97.d.cts +53 -0
- package/dist/browser/index.browser-09e-NXpn.cjs +1 -0
- package/dist/browser/index.browser-0KfCzcI7.js +1 -0
- package/dist/browser/index.browser-BUMCZUeQ.d.ts +180 -0
- package/dist/browser/index.browser-CnGab8Yp.d.cts +180 -0
- package/dist/browser/index.node-DJv-HF6j.js +3 -0
- package/dist/browser/index.node-mda_IL6K.cjs +3 -0
- package/dist/browser/react/index.cjs +1 -1
- package/dist/browser/react/index.d.cts +6 -5
- package/dist/browser/react/index.d.ts +6 -5
- package/dist/browser/react/index.js +1 -1
- package/dist/browser/validator-CvSEfFnI.cjs +1 -0
- package/dist/browser/validator-DOrmtI_l.js +1 -0
- package/dist/cli/{auth-Dw-wJ1IM.js → auth-BUNIOupD.js} +1 -1
- package/dist/cli/{chat-CvTLq5E0.js → chat-L0VBV1Zr.js} +1 -1
- package/dist/cli/{dev-Cr9A596F.js → dev-CMwHkKBI.js} +133 -137
- package/dist/cli/index.js +4 -4
- package/dist/cli/{init-LfebhEg-.js → init-B6vWokUI.js} +24 -22
- package/dist/cli/login-DKW_KVCA.js +1 -0
- package/dist/node/agent/index.node.cjs +10 -0
- package/dist/node/agent/index.node.d.cts +2 -0
- package/dist/node/agent/index.node.d.ts +2 -0
- package/dist/node/agent/index.node.js +10 -0
- package/dist/node/index.node-BBpGHHxe.d.ts +460 -0
- package/dist/node/index.node-iaeCqAo6.d.cts +460 -0
- package/dist/node/test.d.cts +20 -50
- package/dist/node/test.d.ts +20 -50
- package/package.json +21 -19
- package/dist/browser/api/index.browser.cjs +0 -1
- package/dist/browser/api/index.browser.d.cts +0 -2
- package/dist/browser/api/index.browser.d.ts +0 -2
- package/dist/browser/api/index.browser.js +0 -1
- package/dist/browser/client-3mJjOKuh.d.ts +0 -94
- package/dist/browser/client-B7xl9jGk.d.cts +0 -94
- package/dist/browser/client-BbZudkEc.js +0 -21
- package/dist/browser/client-DFaZjb1-.cjs +0 -21
- package/dist/browser/http/index.cjs +0 -1
- package/dist/browser/http/index.d.cts +0 -207
- package/dist/browser/http/index.d.ts +0 -207
- package/dist/browser/http/index.js +0 -1
- package/dist/browser/index.browser-BwGhLjB7.cjs +0 -1
- package/dist/browser/index.browser-Dj8kjB6X.js +0 -1
- package/dist/browser/index.browser-c6tjyX5u.d.cts +0 -316
- package/dist/browser/index.browser-ekIUKJkA.d.ts +0 -316
- package/dist/cli/login-KHDcJ0iZ.js +0 -1
- package/dist/node/api/index.node.cjs +0 -30
- package/dist/node/api/index.node.d.cts +0 -82
- package/dist/node/api/index.node.d.ts +0 -82
- package/dist/node/api/index.node.js +0 -30
- package/dist/node/index.browser-Bo1v3lXu.d.cts +0 -316
- package/dist/node/index.browser-Dhyi8IHz.d.ts +0 -316
- /package/dist/cli/{dist-CN69Y-yA.js → dist-NqrnQGst.js} +0 -0
- /package/dist/cli/{open-Cr8lEmcs.js → open-CSMQaj0E.js} +0 -0
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import { AsyncIterableStream, InferToolInput, InferToolOutput, InferUIMessageChunk, TextStreamPart, Tool, ToolSet, UIDataTypes, UIMessage, UIMessagePart, UITools } from "ai";
|
|
2
|
-
|
|
3
|
-
//#region src/api/chat.d.ts
|
|
4
|
-
interface Chat {
|
|
5
|
-
readonly id: string;
|
|
6
|
-
}
|
|
7
|
-
type ChatBehavior = "enqueue" | "interrupt" | "append";
|
|
8
|
-
interface MessageOptions {
|
|
9
|
-
/**
|
|
10
|
-
* behavior of the chat when sending this message.
|
|
11
|
-
*
|
|
12
|
-
* - "enqueue" will add messages to the chat and start the chat eventually.
|
|
13
|
-
* - "interrupt" will interrupt the chat if running and send messages.
|
|
14
|
-
* - "append" will add messages to the chat.
|
|
15
|
-
*/
|
|
16
|
-
readonly behavior?: ChatBehavior;
|
|
17
|
-
}
|
|
18
|
-
interface Message<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataTypes, TOOLS extends UITools = UITools> {
|
|
19
|
-
readonly role: UIMessage["role"];
|
|
20
|
-
readonly parts: UIMessagePart<DATA_TYPES, TOOLS>[];
|
|
21
|
-
readonly metadata?: METADATA;
|
|
22
|
-
}
|
|
23
|
-
declare const chat: Readonly<{
|
|
24
|
-
upsert: (id: string) => Promise<Chat>;
|
|
25
|
-
message: (id: string, message: Message, options?: MessageOptions) => Promise<void>;
|
|
26
|
-
}>;
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/api/storage.d.ts
|
|
29
|
-
/**
|
|
30
|
-
* Storage allows agents to persist data.
|
|
31
|
-
* Every agent has it's own persistent storage namespace.
|
|
32
|
-
*/
|
|
33
|
-
declare const storage: Readonly<{
|
|
34
|
-
kv: Readonly<{
|
|
35
|
-
get: (key: string) => Promise<string | undefined>;
|
|
36
|
-
set: (key: string, value: string) => Promise<void>;
|
|
37
|
-
del: (key: string) => Promise<void>;
|
|
38
|
-
}>;
|
|
39
|
-
}>;
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/api/tools.d.ts
|
|
42
|
-
/**
|
|
43
|
-
* ToolWithContext is a tool that supports the "withContext" method.
|
|
44
|
-
*
|
|
45
|
-
* @param CONTEXT The context type.
|
|
46
|
-
* @param TOOL The tool type.
|
|
47
|
-
* @returns The tool with the given context.
|
|
48
|
-
*/
|
|
49
|
-
type ToolWithContext<CONTEXT, TOOL extends Tool> = TOOL & {
|
|
50
|
-
withContext(context: CONTEXT): TOOL;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* ToolWithApproval is a tool that supports the "autoApprove" method.
|
|
54
|
-
*
|
|
55
|
-
* @param TOOL The tool type.
|
|
56
|
-
* @returns The tool with the given approval.
|
|
57
|
-
*/
|
|
58
|
-
type ToolWithApproval<INPUT, OUTPUT> = Tool<INPUT, OUTPUT> & {
|
|
59
|
-
/**
|
|
60
|
-
* autoApprove is a function that can be used to automatically approve
|
|
61
|
-
* an approval tool call based on the input.
|
|
62
|
-
*
|
|
63
|
-
* @param input The input to the tool.
|
|
64
|
-
* @returns Whether the tool call should be approved.
|
|
65
|
-
*/
|
|
66
|
-
autoApprove?: (input: INPUT) => Promise<boolean> | boolean;
|
|
67
|
-
};
|
|
68
|
-
type ToolSetWithApproval<TOOLS extends ToolSet> = { [K in keyof TOOLS]: ToolWithApproval<InferToolInput<TOOLS[K]>, InferToolOutput<TOOLS[K]>> };
|
|
69
|
-
/**
|
|
70
|
-
* toolWithApproval is a helper for inferring the execute and autoApprove
|
|
71
|
-
* arguments of a tool.
|
|
72
|
-
*
|
|
73
|
-
* @param tool The tool to wrap.
|
|
74
|
-
* @returns The wrapped tool.
|
|
75
|
-
*/
|
|
76
|
-
declare function toolWithApproval<INPUT, OUTPUT>(tool: ToolWithApproval<INPUT, OUTPUT>): ToolWithApproval<INPUT, OUTPUT>;
|
|
77
|
-
/**
|
|
78
|
-
* Tools are helpers for managing tools.
|
|
79
|
-
*/
|
|
80
|
-
declare const tools: {
|
|
81
|
-
/**
|
|
82
|
-
* withContext adds context to a set of tools that supports the "withContext" method.
|
|
83
|
-
*
|
|
84
|
-
* @param context
|
|
85
|
-
* @param tools
|
|
86
|
-
* @returns
|
|
87
|
-
*/
|
|
88
|
-
withContext<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
|
|
89
|
-
/**
|
|
90
|
-
* @internal
|
|
91
|
-
* @deprecated Use withContext instead - it's the same thing.
|
|
92
|
-
*/
|
|
93
|
-
with<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
|
|
94
|
-
/**
|
|
95
|
-
* withApproval ensures a set of tools need explicit user approval
|
|
96
|
-
* before they are executed.
|
|
97
|
-
*
|
|
98
|
-
* This works by replacing the execution of all provided tools with
|
|
99
|
-
* special output that interfaces must handle.
|
|
100
|
-
*
|
|
101
|
-
* On approval, the tool will be executed with the verbatim input.
|
|
102
|
-
*
|
|
103
|
-
* @returns Tools that should be sent in `streamText`.
|
|
104
|
-
*/
|
|
105
|
-
withApproval<TOOLSET extends ToolSet, TOOLS extends ToolSetWithApproval<TOOLSET>, MESSAGE extends UIMessage>(options: {
|
|
106
|
-
messages: MESSAGE[];
|
|
107
|
-
tools: TOOLS;
|
|
108
|
-
abortSignal?: AbortSignal;
|
|
109
|
-
}): Promise<TOOLS>;
|
|
110
|
-
/**
|
|
111
|
-
* prefix adds a prefix to all the tools in a tool set.
|
|
112
|
-
*
|
|
113
|
-
* @param tools The tool set to prefix.
|
|
114
|
-
* @param prefix The prefix to add to the tools.
|
|
115
|
-
* @returns The prefixed tool set.
|
|
116
|
-
*/
|
|
117
|
-
prefix(tools: ToolSet, prefix: string): ToolSet;
|
|
118
|
-
};
|
|
119
|
-
type ToolsWithContext = Record<string, Tool & {
|
|
120
|
-
withContext(context: unknown): Tool;
|
|
121
|
-
}>;
|
|
122
|
-
type ContextFromTools<TOOLS extends ToolsWithContext> = TOOLS[keyof TOOLS] extends {
|
|
123
|
-
withContext(context: infer C): any;
|
|
124
|
-
} ? C : never;
|
|
125
|
-
/**
|
|
126
|
-
* ToolApprovalOutput is the output of a tool that requires approval.
|
|
127
|
-
*
|
|
128
|
-
* This should be consumed by the UI to display an approval prompt.
|
|
129
|
-
*/
|
|
130
|
-
interface ToolApprovalOutput {
|
|
131
|
-
type: "tool-approval";
|
|
132
|
-
outcome: "pending" | "approved" | "rejected";
|
|
133
|
-
reason?: string;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* isToolApprovalOutput checks if an output is a tool approval output.
|
|
137
|
-
*/
|
|
138
|
-
declare function isToolApprovalOutput(output: unknown): output is ToolApprovalOutput;
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region src/api/index.browser.d.ts
|
|
141
|
-
/**
|
|
142
|
-
* SendMessagesResponse is the response of the sendMessages function.
|
|
143
|
-
* It can be a stream of messages or an arbitrary response.
|
|
144
|
-
*/
|
|
145
|
-
type SendMessagesResponse = {
|
|
146
|
-
toUIMessageStream(options?: {
|
|
147
|
-
messageMetadata?: (options: {
|
|
148
|
-
part: TextStreamPart<any>;
|
|
149
|
-
}) => any;
|
|
150
|
-
}): AsyncIterableStream<InferUIMessageChunk<UIMessage>>;
|
|
151
|
-
} | Response | ReadableStream<InferUIMessageChunk<UIMessage>>;
|
|
152
|
-
/**
|
|
153
|
-
* SendMessagesOptions is the options for the sendMessages function.
|
|
154
|
-
*/
|
|
155
|
-
interface SendMessagesOptions<MESSAGE extends UIMessage = UIMessage> {
|
|
156
|
-
/**
|
|
157
|
-
* Messages are all messages for the history of the chat.
|
|
158
|
-
* It is the user's responsibility to manage context for the chat.
|
|
159
|
-
*/
|
|
160
|
-
readonly messages: MESSAGE[];
|
|
161
|
-
/**
|
|
162
|
-
* Chat is the associated chat for the messages.
|
|
163
|
-
*/
|
|
164
|
-
readonly chat: Chat;
|
|
165
|
-
/**
|
|
166
|
-
* abortSignal can be used to terminate streaming operations
|
|
167
|
-
* immediately when the streaming request ends.
|
|
168
|
-
*/
|
|
169
|
-
readonly abortSignal?: AbortSignal;
|
|
170
|
-
}
|
|
171
|
-
interface ExperimentalProvideCompletionsOptions<MESSAGE extends UIMessage = UIMessage> {
|
|
172
|
-
/**
|
|
173
|
-
* The chat for the completions.
|
|
174
|
-
* Omitted if there is no chat.
|
|
175
|
-
*/
|
|
176
|
-
readonly chat?: Chat;
|
|
177
|
-
/**
|
|
178
|
-
* Messages that are part of the current chat.
|
|
179
|
-
* Omitted if there is no chat.
|
|
180
|
-
*/
|
|
181
|
-
readonly messages?: MESSAGE[];
|
|
182
|
-
readonly input: string;
|
|
183
|
-
readonly caret: number;
|
|
184
|
-
readonly selection?: [number, number];
|
|
185
|
-
readonly abortSignal?: AbortSignal;
|
|
186
|
-
}
|
|
187
|
-
type ExperimentalCompletion = {
|
|
188
|
-
text: string;
|
|
189
|
-
replace?: [number, number];
|
|
190
|
-
} | {
|
|
191
|
-
id: string;
|
|
192
|
-
label: string;
|
|
193
|
-
detail?: string;
|
|
194
|
-
insertText?: string;
|
|
195
|
-
replace?: [number, number];
|
|
196
|
-
};
|
|
197
|
-
type ExperimentalProvideCompletionsResponse = ReadableStream<ExperimentalCompletion> | Promise<ReadableStream<ExperimentalCompletion>> | Promise<ExperimentalCompletion> | ExperimentalCompletion;
|
|
198
|
-
type ProvideOptionsRequest<MESSAGE extends UIMessage = UIMessage> = {
|
|
199
|
-
/**
|
|
200
|
-
* Options that are actively selected by the user.
|
|
201
|
-
*
|
|
202
|
-
* Use this to provide custom options based on previous selections.
|
|
203
|
-
*/
|
|
204
|
-
readonly selectedOptions?: ExtractUIOptions<MESSAGE>;
|
|
205
|
-
};
|
|
206
|
-
type OptionIcon = `lucide:${string}` | `simple-icons:${string}`;
|
|
207
|
-
type OptionSelectValue<ID extends string = string> = {
|
|
208
|
-
readonly id: ID;
|
|
209
|
-
readonly label: string;
|
|
210
|
-
/**
|
|
211
|
-
* description will provide additional context to the user in the UI.
|
|
212
|
-
*/
|
|
213
|
-
readonly description?: string | Array<{
|
|
214
|
-
readonly text: string;
|
|
215
|
-
readonly color?: "primary" | "muted" | "warning";
|
|
216
|
-
}>;
|
|
217
|
-
/**
|
|
218
|
-
* icon is a slug of a Lucide or SimpleIcons icon.
|
|
219
|
-
* This will only be rendered in a web-based UI.
|
|
220
|
-
*
|
|
221
|
-
* Find icons:
|
|
222
|
-
* - https://simpleicons.org/
|
|
223
|
-
* - https://lucide.dev/icons/
|
|
224
|
-
*/
|
|
225
|
-
readonly icon?: OptionIcon;
|
|
226
|
-
};
|
|
227
|
-
type OptionSelect<Values extends readonly OptionSelectValue[] = readonly OptionSelectValue[]> = {
|
|
228
|
-
readonly type: "select";
|
|
229
|
-
/**
|
|
230
|
-
* label indicates the purpose of the option.
|
|
231
|
-
* If omitted, it will not be displayed in the UI.
|
|
232
|
-
*/
|
|
233
|
-
readonly label?: string;
|
|
234
|
-
/**
|
|
235
|
-
* icon is a slug of a Lucide or SimpleIcons icon.
|
|
236
|
-
* This will only be rendered in a web-based UI.
|
|
237
|
-
*
|
|
238
|
-
* Find icons:
|
|
239
|
-
* - https://simpleicons.org/
|
|
240
|
-
* - https://lucide.dev/icons/
|
|
241
|
-
*/
|
|
242
|
-
readonly icon?: OptionIcon;
|
|
243
|
-
/**
|
|
244
|
-
* defaultValue is the default value for the option.
|
|
245
|
-
* If omitted, the option will not be selected by default.
|
|
246
|
-
*/
|
|
247
|
-
readonly defaultValue: Values[number]["id"];
|
|
248
|
-
readonly values: Values;
|
|
249
|
-
};
|
|
250
|
-
type Options = Record<string, string>;
|
|
251
|
-
type WithUIOptions<OPTIONS extends Options, MESSAGE extends UIMessage = UIMessage> = MESSAGE & {
|
|
252
|
-
readonly role: "user";
|
|
253
|
-
readonly metadata: MESSAGE["metadata"] & {
|
|
254
|
-
readonly options: OPTIONS;
|
|
255
|
-
};
|
|
256
|
-
};
|
|
257
|
-
type ExtractUIOptions<M> = M extends WithUIOptions<infer O> ? O : never;
|
|
258
|
-
type OptionsSchema<OPTIONS extends Options> = { [K in keyof OPTIONS]: OptionSelect<Array<OptionSelectValue<OPTIONS[K]>>> };
|
|
259
|
-
/**
|
|
260
|
-
* lastUIOptions finds the last user message with options.
|
|
261
|
-
* Options are stored in message metadata to preserve the history
|
|
262
|
-
* of changing options.
|
|
263
|
-
*
|
|
264
|
-
* @param messages - The messages to search.
|
|
265
|
-
* @returns The last user message with options, or undefined if no such message exists.
|
|
266
|
-
*/
|
|
267
|
-
declare function lastUIOptions<MESSAGE extends UIMessage>(messages: MESSAGE[]): ExtractUIOptions<MESSAGE> | undefined;
|
|
268
|
-
interface AgentOptions<MESSAGE extends UIMessage = UIMessage> {
|
|
269
|
-
/**
|
|
270
|
-
* sendMessages is called when the agent is streaming chat messages.
|
|
271
|
-
* This is invoked on chat creation, and can be programatically
|
|
272
|
-
* invoked at any time with `blink.chat.message`.
|
|
273
|
-
*/
|
|
274
|
-
sendMessages(options: SendMessagesOptions<MESSAGE>): Promise<SendMessagesResponse> | SendMessagesResponse;
|
|
275
|
-
/**
|
|
276
|
-
* onRequest is called when the agent receives a request.
|
|
277
|
-
* This is for handling webhooks, or incoming client payloads
|
|
278
|
-
* that warrant a response.
|
|
279
|
-
*
|
|
280
|
-
* @param request The request received by the agent.
|
|
281
|
-
* @returns A response to the request. If void, the agent will
|
|
282
|
-
* respond with a 404.
|
|
283
|
-
*/
|
|
284
|
-
onRequest?(request: Request): Promise<Response | void>;
|
|
285
|
-
/**
|
|
286
|
-
* experimental_provideCompletions is called when the user is typing in the chat input.
|
|
287
|
-
* This is used to provide completions to the user.
|
|
288
|
-
*
|
|
289
|
-
* *NOTE*: This *only* works in the browser at the moment.
|
|
290
|
-
*
|
|
291
|
-
* @param options The options for the completions.
|
|
292
|
-
* @returns A stream of completions, or a single completion.
|
|
293
|
-
*/
|
|
294
|
-
experimental_provideCompletions?(options: ExperimentalProvideCompletionsOptions<MESSAGE>): ExperimentalProvideCompletionsResponse;
|
|
295
|
-
/**
|
|
296
|
-
* provideUIOptions is called when the agent is asked to provide
|
|
297
|
-
* user-selectable options.
|
|
298
|
-
*
|
|
299
|
-
* To provide options, use:
|
|
300
|
-
* @example
|
|
301
|
-
* ```ts
|
|
302
|
-
* blink.agent<blink.WithUIOptions<{
|
|
303
|
-
* model: "gpt-5" | "sonnet"
|
|
304
|
-
* }>>({
|
|
305
|
-
* // ...
|
|
306
|
-
* })
|
|
307
|
-
* ```
|
|
308
|
-
*
|
|
309
|
-
* @returns A schema for the options.
|
|
310
|
-
*/
|
|
311
|
-
provideUIOptions?(options: ProvideOptionsRequest<MESSAGE>): Promise<OptionsSchema<ExtractUIOptions<MESSAGE>>> | OptionsSchema<ExtractUIOptions<MESSAGE>>;
|
|
312
|
-
}
|
|
313
|
-
type StreamResponseFormat = "ui-message" | "openai-chat" | "openai-response" | "anthropic" | "google" | "xai";
|
|
314
|
-
declare function withResponseFormat(response: Response, format: StreamResponseFormat): Response;
|
|
315
|
-
//#endregion
|
|
316
|
-
export { AgentOptions, Chat, ChatBehavior, ContextFromTools, ExperimentalCompletion, ExperimentalProvideCompletionsOptions, ExperimentalProvideCompletionsResponse, ExtractUIOptions, Message, MessageOptions, OptionSelect, OptionSelectValue, Options, OptionsSchema, ProvideOptionsRequest, SendMessagesOptions, SendMessagesResponse, StreamResponseFormat, ToolApprovalOutput, ToolSetWithApproval, ToolWithApproval, ToolWithContext, WithUIOptions, chat, isToolApprovalOutput, lastUIOptions, storage, toolWithApproval, tools, withResponseFormat };
|
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import { AsyncIterableStream, InferToolInput, InferToolOutput, InferUIMessageChunk, TextStreamPart, Tool, ToolSet, UIDataTypes, UIMessage, UIMessagePart, UITools } from "ai";
|
|
2
|
-
|
|
3
|
-
//#region src/api/chat.d.ts
|
|
4
|
-
interface Chat {
|
|
5
|
-
readonly id: string;
|
|
6
|
-
}
|
|
7
|
-
type ChatBehavior = "enqueue" | "interrupt" | "append";
|
|
8
|
-
interface MessageOptions {
|
|
9
|
-
/**
|
|
10
|
-
* behavior of the chat when sending this message.
|
|
11
|
-
*
|
|
12
|
-
* - "enqueue" will add messages to the chat and start the chat eventually.
|
|
13
|
-
* - "interrupt" will interrupt the chat if running and send messages.
|
|
14
|
-
* - "append" will add messages to the chat.
|
|
15
|
-
*/
|
|
16
|
-
readonly behavior?: ChatBehavior;
|
|
17
|
-
}
|
|
18
|
-
interface Message<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataTypes, TOOLS extends UITools = UITools> {
|
|
19
|
-
readonly role: UIMessage["role"];
|
|
20
|
-
readonly parts: UIMessagePart<DATA_TYPES, TOOLS>[];
|
|
21
|
-
readonly metadata?: METADATA;
|
|
22
|
-
}
|
|
23
|
-
declare const chat: Readonly<{
|
|
24
|
-
upsert: (id: string) => Promise<Chat>;
|
|
25
|
-
message: (id: string, message: Message, options?: MessageOptions) => Promise<void>;
|
|
26
|
-
}>;
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/api/storage.d.ts
|
|
29
|
-
/**
|
|
30
|
-
* Storage allows agents to persist data.
|
|
31
|
-
* Every agent has it's own persistent storage namespace.
|
|
32
|
-
*/
|
|
33
|
-
declare const storage: Readonly<{
|
|
34
|
-
kv: Readonly<{
|
|
35
|
-
get: (key: string) => Promise<string | undefined>;
|
|
36
|
-
set: (key: string, value: string) => Promise<void>;
|
|
37
|
-
del: (key: string) => Promise<void>;
|
|
38
|
-
}>;
|
|
39
|
-
}>;
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/api/tools.d.ts
|
|
42
|
-
/**
|
|
43
|
-
* ToolWithContext is a tool that supports the "withContext" method.
|
|
44
|
-
*
|
|
45
|
-
* @param CONTEXT The context type.
|
|
46
|
-
* @param TOOL The tool type.
|
|
47
|
-
* @returns The tool with the given context.
|
|
48
|
-
*/
|
|
49
|
-
type ToolWithContext<CONTEXT, TOOL extends Tool> = TOOL & {
|
|
50
|
-
withContext(context: CONTEXT): TOOL;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* ToolWithApproval is a tool that supports the "autoApprove" method.
|
|
54
|
-
*
|
|
55
|
-
* @param TOOL The tool type.
|
|
56
|
-
* @returns The tool with the given approval.
|
|
57
|
-
*/
|
|
58
|
-
type ToolWithApproval<INPUT, OUTPUT> = Tool<INPUT, OUTPUT> & {
|
|
59
|
-
/**
|
|
60
|
-
* autoApprove is a function that can be used to automatically approve
|
|
61
|
-
* an approval tool call based on the input.
|
|
62
|
-
*
|
|
63
|
-
* @param input The input to the tool.
|
|
64
|
-
* @returns Whether the tool call should be approved.
|
|
65
|
-
*/
|
|
66
|
-
autoApprove?: (input: INPUT) => Promise<boolean> | boolean;
|
|
67
|
-
};
|
|
68
|
-
type ToolSetWithApproval<TOOLS extends ToolSet> = { [K in keyof TOOLS]: ToolWithApproval<InferToolInput<TOOLS[K]>, InferToolOutput<TOOLS[K]>> };
|
|
69
|
-
/**
|
|
70
|
-
* toolWithApproval is a helper for inferring the execute and autoApprove
|
|
71
|
-
* arguments of a tool.
|
|
72
|
-
*
|
|
73
|
-
* @param tool The tool to wrap.
|
|
74
|
-
* @returns The wrapped tool.
|
|
75
|
-
*/
|
|
76
|
-
declare function toolWithApproval<INPUT, OUTPUT>(tool: ToolWithApproval<INPUT, OUTPUT>): ToolWithApproval<INPUT, OUTPUT>;
|
|
77
|
-
/**
|
|
78
|
-
* Tools are helpers for managing tools.
|
|
79
|
-
*/
|
|
80
|
-
declare const tools: {
|
|
81
|
-
/**
|
|
82
|
-
* withContext adds context to a set of tools that supports the "withContext" method.
|
|
83
|
-
*
|
|
84
|
-
* @param context
|
|
85
|
-
* @param tools
|
|
86
|
-
* @returns
|
|
87
|
-
*/
|
|
88
|
-
withContext<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
|
|
89
|
-
/**
|
|
90
|
-
* @internal
|
|
91
|
-
* @deprecated Use withContext instead - it's the same thing.
|
|
92
|
-
*/
|
|
93
|
-
with<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
|
|
94
|
-
/**
|
|
95
|
-
* withApproval ensures a set of tools need explicit user approval
|
|
96
|
-
* before they are executed.
|
|
97
|
-
*
|
|
98
|
-
* This works by replacing the execution of all provided tools with
|
|
99
|
-
* special output that interfaces must handle.
|
|
100
|
-
*
|
|
101
|
-
* On approval, the tool will be executed with the verbatim input.
|
|
102
|
-
*
|
|
103
|
-
* @returns Tools that should be sent in `streamText`.
|
|
104
|
-
*/
|
|
105
|
-
withApproval<TOOLSET extends ToolSet, TOOLS extends ToolSetWithApproval<TOOLSET>, MESSAGE extends UIMessage>(options: {
|
|
106
|
-
messages: MESSAGE[];
|
|
107
|
-
tools: TOOLS;
|
|
108
|
-
abortSignal?: AbortSignal;
|
|
109
|
-
}): Promise<TOOLS>;
|
|
110
|
-
/**
|
|
111
|
-
* prefix adds a prefix to all the tools in a tool set.
|
|
112
|
-
*
|
|
113
|
-
* @param tools The tool set to prefix.
|
|
114
|
-
* @param prefix The prefix to add to the tools.
|
|
115
|
-
* @returns The prefixed tool set.
|
|
116
|
-
*/
|
|
117
|
-
prefix(tools: ToolSet, prefix: string): ToolSet;
|
|
118
|
-
};
|
|
119
|
-
type ToolsWithContext = Record<string, Tool & {
|
|
120
|
-
withContext(context: unknown): Tool;
|
|
121
|
-
}>;
|
|
122
|
-
type ContextFromTools<TOOLS extends ToolsWithContext> = TOOLS[keyof TOOLS] extends {
|
|
123
|
-
withContext(context: infer C): any;
|
|
124
|
-
} ? C : never;
|
|
125
|
-
/**
|
|
126
|
-
* ToolApprovalOutput is the output of a tool that requires approval.
|
|
127
|
-
*
|
|
128
|
-
* This should be consumed by the UI to display an approval prompt.
|
|
129
|
-
*/
|
|
130
|
-
interface ToolApprovalOutput {
|
|
131
|
-
type: "tool-approval";
|
|
132
|
-
outcome: "pending" | "approved" | "rejected";
|
|
133
|
-
reason?: string;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* isToolApprovalOutput checks if an output is a tool approval output.
|
|
137
|
-
*/
|
|
138
|
-
declare function isToolApprovalOutput(output: unknown): output is ToolApprovalOutput;
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region src/api/index.browser.d.ts
|
|
141
|
-
/**
|
|
142
|
-
* SendMessagesResponse is the response of the sendMessages function.
|
|
143
|
-
* It can be a stream of messages or an arbitrary response.
|
|
144
|
-
*/
|
|
145
|
-
type SendMessagesResponse = {
|
|
146
|
-
toUIMessageStream(options?: {
|
|
147
|
-
messageMetadata?: (options: {
|
|
148
|
-
part: TextStreamPart<any>;
|
|
149
|
-
}) => any;
|
|
150
|
-
}): AsyncIterableStream<InferUIMessageChunk<UIMessage>>;
|
|
151
|
-
} | Response | ReadableStream<InferUIMessageChunk<UIMessage>>;
|
|
152
|
-
/**
|
|
153
|
-
* SendMessagesOptions is the options for the sendMessages function.
|
|
154
|
-
*/
|
|
155
|
-
interface SendMessagesOptions<MESSAGE extends UIMessage = UIMessage> {
|
|
156
|
-
/**
|
|
157
|
-
* Messages are all messages for the history of the chat.
|
|
158
|
-
* It is the user's responsibility to manage context for the chat.
|
|
159
|
-
*/
|
|
160
|
-
readonly messages: MESSAGE[];
|
|
161
|
-
/**
|
|
162
|
-
* Chat is the associated chat for the messages.
|
|
163
|
-
*/
|
|
164
|
-
readonly chat: Chat;
|
|
165
|
-
/**
|
|
166
|
-
* abortSignal can be used to terminate streaming operations
|
|
167
|
-
* immediately when the streaming request ends.
|
|
168
|
-
*/
|
|
169
|
-
readonly abortSignal?: AbortSignal;
|
|
170
|
-
}
|
|
171
|
-
interface ExperimentalProvideCompletionsOptions<MESSAGE extends UIMessage = UIMessage> {
|
|
172
|
-
/**
|
|
173
|
-
* The chat for the completions.
|
|
174
|
-
* Omitted if there is no chat.
|
|
175
|
-
*/
|
|
176
|
-
readonly chat?: Chat;
|
|
177
|
-
/**
|
|
178
|
-
* Messages that are part of the current chat.
|
|
179
|
-
* Omitted if there is no chat.
|
|
180
|
-
*/
|
|
181
|
-
readonly messages?: MESSAGE[];
|
|
182
|
-
readonly input: string;
|
|
183
|
-
readonly caret: number;
|
|
184
|
-
readonly selection?: [number, number];
|
|
185
|
-
readonly abortSignal?: AbortSignal;
|
|
186
|
-
}
|
|
187
|
-
type ExperimentalCompletion = {
|
|
188
|
-
text: string;
|
|
189
|
-
replace?: [number, number];
|
|
190
|
-
} | {
|
|
191
|
-
id: string;
|
|
192
|
-
label: string;
|
|
193
|
-
detail?: string;
|
|
194
|
-
insertText?: string;
|
|
195
|
-
replace?: [number, number];
|
|
196
|
-
};
|
|
197
|
-
type ExperimentalProvideCompletionsResponse = ReadableStream<ExperimentalCompletion> | Promise<ReadableStream<ExperimentalCompletion>> | Promise<ExperimentalCompletion> | ExperimentalCompletion;
|
|
198
|
-
type ProvideOptionsRequest<MESSAGE extends UIMessage = UIMessage> = {
|
|
199
|
-
/**
|
|
200
|
-
* Options that are actively selected by the user.
|
|
201
|
-
*
|
|
202
|
-
* Use this to provide custom options based on previous selections.
|
|
203
|
-
*/
|
|
204
|
-
readonly selectedOptions?: ExtractUIOptions<MESSAGE>;
|
|
205
|
-
};
|
|
206
|
-
type OptionIcon = `lucide:${string}` | `simple-icons:${string}`;
|
|
207
|
-
type OptionSelectValue<ID extends string = string> = {
|
|
208
|
-
readonly id: ID;
|
|
209
|
-
readonly label: string;
|
|
210
|
-
/**
|
|
211
|
-
* description will provide additional context to the user in the UI.
|
|
212
|
-
*/
|
|
213
|
-
readonly description?: string | Array<{
|
|
214
|
-
readonly text: string;
|
|
215
|
-
readonly color?: "primary" | "muted" | "warning";
|
|
216
|
-
}>;
|
|
217
|
-
/**
|
|
218
|
-
* icon is a slug of a Lucide or SimpleIcons icon.
|
|
219
|
-
* This will only be rendered in a web-based UI.
|
|
220
|
-
*
|
|
221
|
-
* Find icons:
|
|
222
|
-
* - https://simpleicons.org/
|
|
223
|
-
* - https://lucide.dev/icons/
|
|
224
|
-
*/
|
|
225
|
-
readonly icon?: OptionIcon;
|
|
226
|
-
};
|
|
227
|
-
type OptionSelect<Values extends readonly OptionSelectValue[] = readonly OptionSelectValue[]> = {
|
|
228
|
-
readonly type: "select";
|
|
229
|
-
/**
|
|
230
|
-
* label indicates the purpose of the option.
|
|
231
|
-
* If omitted, it will not be displayed in the UI.
|
|
232
|
-
*/
|
|
233
|
-
readonly label?: string;
|
|
234
|
-
/**
|
|
235
|
-
* icon is a slug of a Lucide or SimpleIcons icon.
|
|
236
|
-
* This will only be rendered in a web-based UI.
|
|
237
|
-
*
|
|
238
|
-
* Find icons:
|
|
239
|
-
* - https://simpleicons.org/
|
|
240
|
-
* - https://lucide.dev/icons/
|
|
241
|
-
*/
|
|
242
|
-
readonly icon?: OptionIcon;
|
|
243
|
-
/**
|
|
244
|
-
* defaultValue is the default value for the option.
|
|
245
|
-
* If omitted, the option will not be selected by default.
|
|
246
|
-
*/
|
|
247
|
-
readonly defaultValue: Values[number]["id"];
|
|
248
|
-
readonly values: Values;
|
|
249
|
-
};
|
|
250
|
-
type Options = Record<string, string>;
|
|
251
|
-
type WithUIOptions<OPTIONS extends Options, MESSAGE extends UIMessage = UIMessage> = MESSAGE & {
|
|
252
|
-
readonly role: "user";
|
|
253
|
-
readonly metadata: MESSAGE["metadata"] & {
|
|
254
|
-
readonly options: OPTIONS;
|
|
255
|
-
};
|
|
256
|
-
};
|
|
257
|
-
type ExtractUIOptions<M> = M extends WithUIOptions<infer O> ? O : never;
|
|
258
|
-
type OptionsSchema<OPTIONS extends Options> = { [K in keyof OPTIONS]: OptionSelect<Array<OptionSelectValue<OPTIONS[K]>>> };
|
|
259
|
-
/**
|
|
260
|
-
* lastUIOptions finds the last user message with options.
|
|
261
|
-
* Options are stored in message metadata to preserve the history
|
|
262
|
-
* of changing options.
|
|
263
|
-
*
|
|
264
|
-
* @param messages - The messages to search.
|
|
265
|
-
* @returns The last user message with options, or undefined if no such message exists.
|
|
266
|
-
*/
|
|
267
|
-
declare function lastUIOptions<MESSAGE extends UIMessage>(messages: MESSAGE[]): ExtractUIOptions<MESSAGE> | undefined;
|
|
268
|
-
interface AgentOptions<MESSAGE extends UIMessage = UIMessage> {
|
|
269
|
-
/**
|
|
270
|
-
* sendMessages is called when the agent is streaming chat messages.
|
|
271
|
-
* This is invoked on chat creation, and can be programatically
|
|
272
|
-
* invoked at any time with `blink.chat.message`.
|
|
273
|
-
*/
|
|
274
|
-
sendMessages(options: SendMessagesOptions<MESSAGE>): Promise<SendMessagesResponse> | SendMessagesResponse;
|
|
275
|
-
/**
|
|
276
|
-
* onRequest is called when the agent receives a request.
|
|
277
|
-
* This is for handling webhooks, or incoming client payloads
|
|
278
|
-
* that warrant a response.
|
|
279
|
-
*
|
|
280
|
-
* @param request The request received by the agent.
|
|
281
|
-
* @returns A response to the request. If void, the agent will
|
|
282
|
-
* respond with a 404.
|
|
283
|
-
*/
|
|
284
|
-
onRequest?(request: Request): Promise<Response | void>;
|
|
285
|
-
/**
|
|
286
|
-
* experimental_provideCompletions is called when the user is typing in the chat input.
|
|
287
|
-
* This is used to provide completions to the user.
|
|
288
|
-
*
|
|
289
|
-
* *NOTE*: This *only* works in the browser at the moment.
|
|
290
|
-
*
|
|
291
|
-
* @param options The options for the completions.
|
|
292
|
-
* @returns A stream of completions, or a single completion.
|
|
293
|
-
*/
|
|
294
|
-
experimental_provideCompletions?(options: ExperimentalProvideCompletionsOptions<MESSAGE>): ExperimentalProvideCompletionsResponse;
|
|
295
|
-
/**
|
|
296
|
-
* provideUIOptions is called when the agent is asked to provide
|
|
297
|
-
* user-selectable options.
|
|
298
|
-
*
|
|
299
|
-
* To provide options, use:
|
|
300
|
-
* @example
|
|
301
|
-
* ```ts
|
|
302
|
-
* blink.agent<blink.WithUIOptions<{
|
|
303
|
-
* model: "gpt-5" | "sonnet"
|
|
304
|
-
* }>>({
|
|
305
|
-
* // ...
|
|
306
|
-
* })
|
|
307
|
-
* ```
|
|
308
|
-
*
|
|
309
|
-
* @returns A schema for the options.
|
|
310
|
-
*/
|
|
311
|
-
provideUIOptions?(options: ProvideOptionsRequest<MESSAGE>): Promise<OptionsSchema<ExtractUIOptions<MESSAGE>>> | OptionsSchema<ExtractUIOptions<MESSAGE>>;
|
|
312
|
-
}
|
|
313
|
-
type StreamResponseFormat = "ui-message" | "openai-chat" | "openai-response" | "anthropic" | "google" | "xai";
|
|
314
|
-
declare function withResponseFormat(response: Response, format: StreamResponseFormat): Response;
|
|
315
|
-
//#endregion
|
|
316
|
-
export { AgentOptions, Chat, ChatBehavior, ContextFromTools, ExperimentalCompletion, ExperimentalProvideCompletionsOptions, ExperimentalProvideCompletionsResponse, ExtractUIOptions, Message, MessageOptions, OptionSelect, OptionSelectValue, Options, OptionsSchema, ProvideOptionsRequest, SendMessagesOptions, SendMessagesResponse, StreamResponseFormat, ToolApprovalOutput, ToolSetWithApproval, ToolWithApproval, ToolWithContext, WithUIOptions, chat, isToolApprovalOutput, lastUIOptions, storage, toolWithApproval, tools, withResponseFormat };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{login as e}from"./auth-Dw-wJ1IM.js";import"./dist-CN69Y-yA.js";import"./open-Cr8lEmcs.js";async function t(){await e()}export{t as default};
|