blink 0.1.64 → 0.1.66

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 (62) hide show
  1. package/dist/browser/api/index.browser.cjs +1 -0
  2. package/dist/browser/api/index.browser.d.cts +2 -0
  3. package/dist/browser/api/index.browser.d.ts +2 -0
  4. package/dist/browser/api/index.browser.js +1 -0
  5. package/dist/browser/client-C9uh5T54.cjs +21 -0
  6. package/dist/{index-y1u5VC2_.d.ts → browser/client-Co98ZOqj.d.cts} +3 -22
  7. package/dist/browser/client-DsiYP47H.js +21 -0
  8. package/dist/{index-DXNEroA1.d.cts → browser/client-J5gD4j_a.d.ts} +3 -22
  9. package/dist/browser/http/index.cjs +1 -0
  10. package/dist/browser/http/index.d.cts +60 -0
  11. package/dist/browser/http/index.d.ts +60 -0
  12. package/dist/browser/http/index.js +1 -0
  13. package/dist/browser/index.browser-CFap1r_Y.cjs +1 -0
  14. package/dist/{index-BdS2C_9A.d.cts → browser/index.browser-CHLe3dau.d.cts} +15 -91
  15. package/dist/browser/index.browser-CeE1x4lk.js +1 -0
  16. package/dist/{index-E064W90j.d.ts → browser/index.browser-Db4eudpn.d.ts} +15 -91
  17. package/dist/browser/react/index.cjs +1 -0
  18. package/dist/browser/react/index.d.cts +31 -0
  19. package/dist/browser/react/index.d.ts +31 -0
  20. package/dist/browser/react/index.js +1 -0
  21. package/dist/cli/{auth-BUNIOupD.js → auth-Dw-wJ1IM.js} +1 -1
  22. package/dist/cli/{chat-L0VBV1Zr.js → chat-CvTLq5E0.js} +1 -1
  23. package/dist/cli/{dev-C0ieiMQk.js → dev-Cp22zef8.js} +64 -70
  24. package/dist/cli/index.js +3 -3
  25. package/dist/cli/{init-B61NlodJ.js → init-LfebhEg-.js} +3 -3
  26. package/dist/cli/login-KHDcJ0iZ.js +1 -0
  27. package/dist/node/api/index.node.cjs +30 -0
  28. package/dist/node/api/index.node.d.cts +82 -0
  29. package/dist/node/api/index.node.d.ts +82 -0
  30. package/dist/node/api/index.node.js +30 -0
  31. package/dist/node/index.browser-D1y2mwdW.d.ts +281 -0
  32. package/dist/node/index.browser-wBJ4jcnM.d.cts +281 -0
  33. package/dist/node/test.d.cts +88 -0
  34. package/dist/node/test.d.ts +88 -0
  35. package/package.json +35 -17
  36. package/dist/api/index.cjs +0 -24
  37. package/dist/api/index.d.cts +0 -2
  38. package/dist/api/index.d.ts +0 -2
  39. package/dist/api/index.js +0 -24
  40. package/dist/cli/login-DKW_KVCA.js +0 -1
  41. package/dist/http/api.cjs +0 -1
  42. package/dist/http/api.d.cts +0 -204
  43. package/dist/http/api.d.ts +0 -204
  44. package/dist/http/api.js +0 -1
  45. package/dist/http/index.cjs +0 -1
  46. package/dist/http/index.d.cts +0 -3
  47. package/dist/http/index.d.ts +0 -3
  48. package/dist/http/index.js +0 -1
  49. package/dist/http-CU96NOdn.js +0 -21
  50. package/dist/http-DXLJkJIR.cjs +0 -21
  51. package/dist/test.d.cts +0 -12
  52. package/dist/test.d.ts +0 -12
  53. /package/dist/cli/{dist-NqrnQGst.js → dist-CN69Y-yA.js} +0 -0
  54. /package/dist/cli/{open-CSMQaj0E.js → open-Cr8lEmcs.js} +0 -0
  55. /package/dist/{build → node/build}/index.cjs +0 -0
  56. /package/dist/{build → node/build}/index.d.cts +0 -0
  57. /package/dist/{build → node/build}/index.d.ts +0 -0
  58. /package/dist/{build → node/build}/index.js +0 -0
  59. /package/dist/{chunk-___ucjiX.js → node/chunk-___ucjiX.js} +0 -0
  60. /package/dist/{chunk-hhQzssFb.cjs → node/chunk-hhQzssFb.cjs} +0 -0
  61. /package/dist/{test.cjs → node/test.cjs} +0 -0
  62. /package/dist/{test.js → node/test.js} +0 -0
@@ -0,0 +1,281 @@
1
+ import { AsyncIterableStream, InferToolInput, InferToolOutput, InferUIMessageChunk, 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/tools.d.ts
29
+ /**
30
+ * ToolWithContext is a tool that supports the "withContext" method.
31
+ *
32
+ * @param CONTEXT The context type.
33
+ * @param TOOL The tool type.
34
+ * @returns The tool with the given context.
35
+ */
36
+ type ToolWithContext<CONTEXT, TOOL extends Tool> = TOOL & {
37
+ withContext(context: CONTEXT): TOOL;
38
+ };
39
+ /**
40
+ * ToolWithApproval is a tool that supports the "autoApprove" method.
41
+ *
42
+ * @param TOOL The tool type.
43
+ * @returns The tool with the given approval.
44
+ */
45
+ type ToolWithApproval<INPUT, OUTPUT> = Tool<INPUT, OUTPUT> & {
46
+ /**
47
+ * autoApprove is a function that can be used to automatically approve
48
+ * an approval tool call based on the input.
49
+ *
50
+ * @param input The input to the tool.
51
+ * @returns Whether the tool call should be approved.
52
+ */
53
+ autoApprove?: (input: INPUT) => Promise<boolean> | boolean;
54
+ };
55
+ type ToolSetWithApproval<TOOLS extends ToolSet> = { [K in keyof TOOLS]: ToolWithApproval<InferToolInput<TOOLS[K]>, InferToolOutput<TOOLS[K]>> };
56
+ /**
57
+ * toolWithApproval is a helper for inferring the execute and autoApprove
58
+ * arguments of a tool.
59
+ *
60
+ * @param tool The tool to wrap.
61
+ * @returns The wrapped tool.
62
+ */
63
+ declare function toolWithApproval<INPUT, OUTPUT>(tool: ToolWithApproval<INPUT, OUTPUT>): ToolWithApproval<INPUT, OUTPUT>;
64
+ /**
65
+ * Tools are helpers for managing tools.
66
+ */
67
+ declare const tools: {
68
+ /**
69
+ * withContext adds context to a set of tools that supports the "withContext" method.
70
+ *
71
+ * @param context
72
+ * @param tools
73
+ * @returns
74
+ */
75
+ withContext<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
76
+ /**
77
+ * @internal
78
+ * @deprecated Use withContext instead - it's the same thing.
79
+ */
80
+ with<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
81
+ /**
82
+ * withApproval ensures a set of tools need explicit user approval
83
+ * before they are executed.
84
+ *
85
+ * This works by replacing the execution of all provided tools with
86
+ * special output that interfaces must handle.
87
+ *
88
+ * On approval, the tool will be executed with the verbatim input.
89
+ *
90
+ * @returns Tools that should be sent in `streamText`.
91
+ */
92
+ withApproval<TOOLSET extends ToolSet, TOOLS extends ToolSetWithApproval<TOOLSET>, MESSAGE extends UIMessage>(options: {
93
+ messages: MESSAGE[];
94
+ tools: TOOLS;
95
+ abortSignal?: AbortSignal;
96
+ }): Promise<TOOLS>;
97
+ /**
98
+ * prefix adds a prefix to all the tools in a tool set.
99
+ *
100
+ * @param tools The tool set to prefix.
101
+ * @param prefix The prefix to add to the tools.
102
+ * @returns The prefixed tool set.
103
+ */
104
+ prefix(tools: ToolSet, prefix: string): ToolSet;
105
+ };
106
+ type ToolsWithContext = Record<string, Tool & {
107
+ withContext(context: unknown): Tool;
108
+ }>;
109
+ type ContextFromTools<TOOLS extends ToolsWithContext> = TOOLS[keyof TOOLS] extends {
110
+ withContext(context: infer C): any;
111
+ } ? C : never;
112
+ /**
113
+ * ToolApprovalOutput is the output of a tool that requires approval.
114
+ *
115
+ * This should be consumed by the UI to display an approval prompt.
116
+ */
117
+ interface ToolApprovalOutput {
118
+ type: "tool-approval";
119
+ outcome: "pending" | "approved" | "rejected";
120
+ reason?: string;
121
+ }
122
+ /**
123
+ * isToolApprovalOutput checks if an output is a tool approval output.
124
+ */
125
+ declare function isToolApprovalOutput(output: unknown): output is ToolApprovalOutput;
126
+ //#endregion
127
+ //#region src/api/storage.d.ts
128
+ /**
129
+ * Storage allows agents to persist data.
130
+ * Every agent has it's own persistent storage namespace.
131
+ */
132
+ declare const storage: Readonly<{
133
+ kv: Readonly<{
134
+ get: (key: string) => Promise<string | undefined>;
135
+ set: (key: string, value: string) => Promise<void>;
136
+ del: (key: string) => Promise<void>;
137
+ }>;
138
+ }>;
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(): AsyncIterableStream<InferUIMessageChunk<UIMessage>>;
147
+ } | Response | ReadableStream<InferUIMessageChunk<UIMessage>>;
148
+ /**
149
+ * SendMessagesOptions is the options for the sendMessages function.
150
+ */
151
+ interface SendMessagesOptions<MESSAGE extends UIMessage = UIMessage> {
152
+ /**
153
+ * Messages are all messages for the history of the chat.
154
+ * It is the user's responsibility to manage context for the chat.
155
+ */
156
+ readonly messages: MESSAGE[];
157
+ /**
158
+ * Chat is the associated chat for the messages.
159
+ */
160
+ readonly chat: Chat;
161
+ /**
162
+ * abortSignal can be used to terminate streaming operations
163
+ * immediately when the streaming request ends.
164
+ */
165
+ readonly abortSignal?: AbortSignal;
166
+ }
167
+ interface ExperimentalProvideCompletionsOptions<MESSAGE extends UIMessage = UIMessage> {
168
+ /**
169
+ * The chat for the completions.
170
+ * Omitted if there is no chat.
171
+ */
172
+ readonly chat?: Chat;
173
+ /**
174
+ * Messages that are part of the current chat.
175
+ * Omitted if there is no chat.
176
+ */
177
+ readonly messages?: MESSAGE[];
178
+ readonly input: string;
179
+ readonly caret: number;
180
+ readonly selection?: [number, number];
181
+ readonly abortSignal?: AbortSignal;
182
+ }
183
+ type ExperimentalCompletion = {
184
+ text: string;
185
+ replace?: [number, number];
186
+ } | {
187
+ id: string;
188
+ label: string;
189
+ detail?: string;
190
+ insertText?: string;
191
+ replace?: [number, number];
192
+ };
193
+ type ExperimentalProvideCompletionsResponse = ReadableStream<ExperimentalCompletion> | Promise<ReadableStream<ExperimentalCompletion>> | Promise<ExperimentalCompletion> | ExperimentalCompletion;
194
+ type ProvideOptionsRequest<MESSAGE extends UIMessage = UIMessage> = {
195
+ /**
196
+ * Options that are actively selected by the user.
197
+ *
198
+ * Use this to provide custom options based on previous selections.
199
+ */
200
+ readonly selectedOptions?: ExtractUIOptions<MESSAGE>;
201
+ };
202
+ type OptionSelectValue<ID extends string = string> = {
203
+ readonly id: ID;
204
+ readonly label: string;
205
+ };
206
+ type OptionSelect<Values extends readonly OptionSelectValue[] = readonly OptionSelectValue[]> = {
207
+ readonly type: "select";
208
+ readonly label: string;
209
+ readonly values: Values;
210
+ readonly defaultValue: Values[number]["id"];
211
+ };
212
+ type Options = Record<string, string>;
213
+ type WithUIOptions<OPTIONS extends Options, MESSAGE extends UIMessage = UIMessage> = MESSAGE & {
214
+ readonly role: "user";
215
+ readonly metadata: MESSAGE["metadata"] & {
216
+ readonly options: OPTIONS;
217
+ };
218
+ };
219
+ type ExtractUIOptions<M> = M extends WithUIOptions<infer O> ? O : never;
220
+ type OptionsSchema<OPTIONS extends Options> = { [K in keyof OPTIONS]: OptionSelect<Array<{
221
+ id: OPTIONS[K];
222
+ label: string;
223
+ }>> };
224
+ /**
225
+ * lastUIOptions finds the last user message with options.
226
+ * Options are stored in message metadata to preserve the history
227
+ * of changing options.
228
+ *
229
+ * @param messages - The messages to search.
230
+ * @returns The last user message with options, or undefined if no such message exists.
231
+ */
232
+ declare function lastUIOptions<MESSAGE extends UIMessage>(messages: MESSAGE[]): ExtractUIOptions<MESSAGE> | undefined;
233
+ interface AgentOptions<MESSAGE extends UIMessage = UIMessage> {
234
+ /**
235
+ * sendMessages is called when the agent is streaming chat messages.
236
+ * This is invoked on chat creation, and can be programatically
237
+ * invoked at any time with `blink.chat.message`.
238
+ */
239
+ sendMessages(options: SendMessagesOptions<MESSAGE>): Promise<SendMessagesResponse> | SendMessagesResponse;
240
+ /**
241
+ * onRequest is called when the agent receives a request.
242
+ * This is for handling webhooks, or incoming client payloads
243
+ * that warrant a response.
244
+ *
245
+ * @param request The request received by the agent.
246
+ * @returns A response to the request. If void, the agent will
247
+ * respond with a 404.
248
+ */
249
+ onRequest?(request: Request): Promise<Response | void>;
250
+ /**
251
+ * experimental_provideCompletions is called when the user is typing in the chat input.
252
+ * This is used to provide completions to the user.
253
+ *
254
+ * *NOTE*: This *only* works in the browser at the moment.
255
+ *
256
+ * @param options The options for the completions.
257
+ * @returns A stream of completions, or a single completion.
258
+ */
259
+ experimental_provideCompletions?(options: ExperimentalProvideCompletionsOptions<MESSAGE>): ExperimentalProvideCompletionsResponse;
260
+ /**
261
+ * provideUIOptions is called when the agent is asked to provide
262
+ * user-selectable options.
263
+ *
264
+ * To provide options, use:
265
+ * @example
266
+ * ```ts
267
+ * blink.agent<blink.WithUIOptions<{
268
+ * model: "gpt-5" | "sonnet"
269
+ * }>>({
270
+ * // ...
271
+ * })
272
+ * ```
273
+ *
274
+ * @returns A schema for the options.
275
+ */
276
+ provideUIOptions?(options: ProvideOptionsRequest<MESSAGE>): Promise<OptionsSchema<ExtractUIOptions<MESSAGE>>> | OptionsSchema<ExtractUIOptions<MESSAGE>>;
277
+ }
278
+ type StreamResponseFormat = "ui-message" | "openai-chat" | "openai-response" | "anthropic" | "google" | "xai";
279
+ declare function withResponseFormat(response: Response, format: StreamResponseFormat): Response;
280
+ //#endregion
281
+ 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 };
@@ -0,0 +1,281 @@
1
+ import { AsyncIterableStream, InferToolInput, InferToolOutput, InferUIMessageChunk, 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/tools.d.ts
29
+ /**
30
+ * ToolWithContext is a tool that supports the "withContext" method.
31
+ *
32
+ * @param CONTEXT The context type.
33
+ * @param TOOL The tool type.
34
+ * @returns The tool with the given context.
35
+ */
36
+ type ToolWithContext<CONTEXT, TOOL extends Tool> = TOOL & {
37
+ withContext(context: CONTEXT): TOOL;
38
+ };
39
+ /**
40
+ * ToolWithApproval is a tool that supports the "autoApprove" method.
41
+ *
42
+ * @param TOOL The tool type.
43
+ * @returns The tool with the given approval.
44
+ */
45
+ type ToolWithApproval<INPUT, OUTPUT> = Tool<INPUT, OUTPUT> & {
46
+ /**
47
+ * autoApprove is a function that can be used to automatically approve
48
+ * an approval tool call based on the input.
49
+ *
50
+ * @param input The input to the tool.
51
+ * @returns Whether the tool call should be approved.
52
+ */
53
+ autoApprove?: (input: INPUT) => Promise<boolean> | boolean;
54
+ };
55
+ type ToolSetWithApproval<TOOLS extends ToolSet> = { [K in keyof TOOLS]: ToolWithApproval<InferToolInput<TOOLS[K]>, InferToolOutput<TOOLS[K]>> };
56
+ /**
57
+ * toolWithApproval is a helper for inferring the execute and autoApprove
58
+ * arguments of a tool.
59
+ *
60
+ * @param tool The tool to wrap.
61
+ * @returns The wrapped tool.
62
+ */
63
+ declare function toolWithApproval<INPUT, OUTPUT>(tool: ToolWithApproval<INPUT, OUTPUT>): ToolWithApproval<INPUT, OUTPUT>;
64
+ /**
65
+ * Tools are helpers for managing tools.
66
+ */
67
+ declare const tools: {
68
+ /**
69
+ * withContext adds context to a set of tools that supports the "withContext" method.
70
+ *
71
+ * @param context
72
+ * @param tools
73
+ * @returns
74
+ */
75
+ withContext<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
76
+ /**
77
+ * @internal
78
+ * @deprecated Use withContext instead - it's the same thing.
79
+ */
80
+ with<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
81
+ /**
82
+ * withApproval ensures a set of tools need explicit user approval
83
+ * before they are executed.
84
+ *
85
+ * This works by replacing the execution of all provided tools with
86
+ * special output that interfaces must handle.
87
+ *
88
+ * On approval, the tool will be executed with the verbatim input.
89
+ *
90
+ * @returns Tools that should be sent in `streamText`.
91
+ */
92
+ withApproval<TOOLSET extends ToolSet, TOOLS extends ToolSetWithApproval<TOOLSET>, MESSAGE extends UIMessage>(options: {
93
+ messages: MESSAGE[];
94
+ tools: TOOLS;
95
+ abortSignal?: AbortSignal;
96
+ }): Promise<TOOLS>;
97
+ /**
98
+ * prefix adds a prefix to all the tools in a tool set.
99
+ *
100
+ * @param tools The tool set to prefix.
101
+ * @param prefix The prefix to add to the tools.
102
+ * @returns The prefixed tool set.
103
+ */
104
+ prefix(tools: ToolSet, prefix: string): ToolSet;
105
+ };
106
+ type ToolsWithContext = Record<string, Tool & {
107
+ withContext(context: unknown): Tool;
108
+ }>;
109
+ type ContextFromTools<TOOLS extends ToolsWithContext> = TOOLS[keyof TOOLS] extends {
110
+ withContext(context: infer C): any;
111
+ } ? C : never;
112
+ /**
113
+ * ToolApprovalOutput is the output of a tool that requires approval.
114
+ *
115
+ * This should be consumed by the UI to display an approval prompt.
116
+ */
117
+ interface ToolApprovalOutput {
118
+ type: "tool-approval";
119
+ outcome: "pending" | "approved" | "rejected";
120
+ reason?: string;
121
+ }
122
+ /**
123
+ * isToolApprovalOutput checks if an output is a tool approval output.
124
+ */
125
+ declare function isToolApprovalOutput(output: unknown): output is ToolApprovalOutput;
126
+ //#endregion
127
+ //#region src/api/storage.d.ts
128
+ /**
129
+ * Storage allows agents to persist data.
130
+ * Every agent has it's own persistent storage namespace.
131
+ */
132
+ declare const storage: Readonly<{
133
+ kv: Readonly<{
134
+ get: (key: string) => Promise<string | undefined>;
135
+ set: (key: string, value: string) => Promise<void>;
136
+ del: (key: string) => Promise<void>;
137
+ }>;
138
+ }>;
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(): AsyncIterableStream<InferUIMessageChunk<UIMessage>>;
147
+ } | Response | ReadableStream<InferUIMessageChunk<UIMessage>>;
148
+ /**
149
+ * SendMessagesOptions is the options for the sendMessages function.
150
+ */
151
+ interface SendMessagesOptions<MESSAGE extends UIMessage = UIMessage> {
152
+ /**
153
+ * Messages are all messages for the history of the chat.
154
+ * It is the user's responsibility to manage context for the chat.
155
+ */
156
+ readonly messages: MESSAGE[];
157
+ /**
158
+ * Chat is the associated chat for the messages.
159
+ */
160
+ readonly chat: Chat;
161
+ /**
162
+ * abortSignal can be used to terminate streaming operations
163
+ * immediately when the streaming request ends.
164
+ */
165
+ readonly abortSignal?: AbortSignal;
166
+ }
167
+ interface ExperimentalProvideCompletionsOptions<MESSAGE extends UIMessage = UIMessage> {
168
+ /**
169
+ * The chat for the completions.
170
+ * Omitted if there is no chat.
171
+ */
172
+ readonly chat?: Chat;
173
+ /**
174
+ * Messages that are part of the current chat.
175
+ * Omitted if there is no chat.
176
+ */
177
+ readonly messages?: MESSAGE[];
178
+ readonly input: string;
179
+ readonly caret: number;
180
+ readonly selection?: [number, number];
181
+ readonly abortSignal?: AbortSignal;
182
+ }
183
+ type ExperimentalCompletion = {
184
+ text: string;
185
+ replace?: [number, number];
186
+ } | {
187
+ id: string;
188
+ label: string;
189
+ detail?: string;
190
+ insertText?: string;
191
+ replace?: [number, number];
192
+ };
193
+ type ExperimentalProvideCompletionsResponse = ReadableStream<ExperimentalCompletion> | Promise<ReadableStream<ExperimentalCompletion>> | Promise<ExperimentalCompletion> | ExperimentalCompletion;
194
+ type ProvideOptionsRequest<MESSAGE extends UIMessage = UIMessage> = {
195
+ /**
196
+ * Options that are actively selected by the user.
197
+ *
198
+ * Use this to provide custom options based on previous selections.
199
+ */
200
+ readonly selectedOptions?: ExtractUIOptions<MESSAGE>;
201
+ };
202
+ type OptionSelectValue<ID extends string = string> = {
203
+ readonly id: ID;
204
+ readonly label: string;
205
+ };
206
+ type OptionSelect<Values extends readonly OptionSelectValue[] = readonly OptionSelectValue[]> = {
207
+ readonly type: "select";
208
+ readonly label: string;
209
+ readonly values: Values;
210
+ readonly defaultValue: Values[number]["id"];
211
+ };
212
+ type Options = Record<string, string>;
213
+ type WithUIOptions<OPTIONS extends Options, MESSAGE extends UIMessage = UIMessage> = MESSAGE & {
214
+ readonly role: "user";
215
+ readonly metadata: MESSAGE["metadata"] & {
216
+ readonly options: OPTIONS;
217
+ };
218
+ };
219
+ type ExtractUIOptions<M> = M extends WithUIOptions<infer O> ? O : never;
220
+ type OptionsSchema<OPTIONS extends Options> = { [K in keyof OPTIONS]: OptionSelect<Array<{
221
+ id: OPTIONS[K];
222
+ label: string;
223
+ }>> };
224
+ /**
225
+ * lastUIOptions finds the last user message with options.
226
+ * Options are stored in message metadata to preserve the history
227
+ * of changing options.
228
+ *
229
+ * @param messages - The messages to search.
230
+ * @returns The last user message with options, or undefined if no such message exists.
231
+ */
232
+ declare function lastUIOptions<MESSAGE extends UIMessage>(messages: MESSAGE[]): ExtractUIOptions<MESSAGE> | undefined;
233
+ interface AgentOptions<MESSAGE extends UIMessage = UIMessage> {
234
+ /**
235
+ * sendMessages is called when the agent is streaming chat messages.
236
+ * This is invoked on chat creation, and can be programatically
237
+ * invoked at any time with `blink.chat.message`.
238
+ */
239
+ sendMessages(options: SendMessagesOptions<MESSAGE>): Promise<SendMessagesResponse> | SendMessagesResponse;
240
+ /**
241
+ * onRequest is called when the agent receives a request.
242
+ * This is for handling webhooks, or incoming client payloads
243
+ * that warrant a response.
244
+ *
245
+ * @param request The request received by the agent.
246
+ * @returns A response to the request. If void, the agent will
247
+ * respond with a 404.
248
+ */
249
+ onRequest?(request: Request): Promise<Response | void>;
250
+ /**
251
+ * experimental_provideCompletions is called when the user is typing in the chat input.
252
+ * This is used to provide completions to the user.
253
+ *
254
+ * *NOTE*: This *only* works in the browser at the moment.
255
+ *
256
+ * @param options The options for the completions.
257
+ * @returns A stream of completions, or a single completion.
258
+ */
259
+ experimental_provideCompletions?(options: ExperimentalProvideCompletionsOptions<MESSAGE>): ExperimentalProvideCompletionsResponse;
260
+ /**
261
+ * provideUIOptions is called when the agent is asked to provide
262
+ * user-selectable options.
263
+ *
264
+ * To provide options, use:
265
+ * @example
266
+ * ```ts
267
+ * blink.agent<blink.WithUIOptions<{
268
+ * model: "gpt-5" | "sonnet"
269
+ * }>>({
270
+ * // ...
271
+ * })
272
+ * ```
273
+ *
274
+ * @returns A schema for the options.
275
+ */
276
+ provideUIOptions?(options: ProvideOptionsRequest<MESSAGE>): Promise<OptionsSchema<ExtractUIOptions<MESSAGE>>> | OptionsSchema<ExtractUIOptions<MESSAGE>>;
277
+ }
278
+ type StreamResponseFormat = "ui-message" | "openai-chat" | "openai-response" | "anthropic" | "google" | "xai";
279
+ declare function withResponseFormat(response: Response, format: StreamResponseFormat): Response;
280
+ //#endregion
281
+ 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 };
@@ -0,0 +1,88 @@
1
+ import { Chat, ExperimentalCompletion, OptionsSchema, ProvideOptionsRequest, WithUIOptions } from "./index.browser-wBJ4jcnM.cjs";
2
+ import { UIMessage, UIMessageChunk } from "ai";
3
+
4
+ //#region src/http/client.d.ts
5
+
6
+ /**
7
+ * SendMessagesRequest is the request format of the `/_agent/send-messages` endpoint.
8
+ *
9
+ * It executes the `sendMessages` function.
10
+ */
11
+ interface SendMessagesRequest {
12
+ readonly messages: UIMessage[];
13
+ readonly chat: Chat;
14
+ }
15
+ /**
16
+ * ExperimentalProvideCompletionsRequest is the request format of the `/_agent/completions` endpoint.
17
+ *
18
+ * It executes the `experimental_provideCompletions` function.
19
+ */
20
+ interface ExperimentalProvideCompletionsRequest {
21
+ readonly messages: UIMessage[];
22
+ readonly chat?: Chat;
23
+ readonly input: string;
24
+ readonly caret: number;
25
+ readonly selection?: [number, number];
26
+ }
27
+ /**
28
+ * CapabilitiesResponse is the response format of the `/_agent/capabilities` endpoint.
29
+ *
30
+ * It indicates whether the agent supports requests and completions.
31
+ */
32
+ interface CapabilitiesResponse {
33
+ readonly requests: boolean;
34
+ readonly completions: boolean;
35
+ readonly options: boolean;
36
+ }
37
+ interface ClientOptions {
38
+ readonly baseUrl: string;
39
+ readonly headers?: Record<string, string>;
40
+ }
41
+ /**
42
+ * Client is a client for the Blink agent HTTP API.
43
+ */
44
+ declare class Client {
45
+ private readonly options;
46
+ constructor(options: ClientOptions);
47
+ get baseUrl(): string;
48
+ /**
49
+ * sendMessages sends messages to the agent.
50
+ *
51
+ * The response format is automatically converted to a UI message stream.
52
+ */
53
+ sendMessages(request: SendMessagesRequest, options?: {
54
+ signal?: AbortSignal;
55
+ }): Promise<ReadableStream<UIMessageChunk>>;
56
+ /**
57
+ * experimental_provideCompletions provides completions to the user.
58
+ * This is used to provide completions to the user.
59
+ */
60
+ experimental_provideCompletions(request: ExperimentalProvideCompletionsRequest): Promise<ReadableStream<ExperimentalCompletion>>;
61
+ /**
62
+ * capabilities returns the capabilities of the agent.
63
+ * This is used to check if the agent supports requests and completions.
64
+ */
65
+ capabilities(): Promise<CapabilitiesResponse>;
66
+ /**
67
+ * provideUIOptions provides selectable options to the user.
68
+ */
69
+ provideUIOptions(request: ProvideOptionsRequest<WithUIOptions<Record<string, any>>>, options?: {
70
+ signal?: AbortSignal;
71
+ }): Promise<OptionsSchema<any>>;
72
+ /**
73
+ * health simply returns a 200 response.
74
+ * This is used to check if the agent is running.
75
+ */
76
+ health(): Promise<void>;
77
+ private handleError;
78
+ }
79
+ //#endregion
80
+ //#region src/test.d.ts
81
+ interface CreateOptions {
82
+ readonly entrypoint?: string;
83
+ readonly cwd?: string;
84
+ readonly env?: Record<string, string>;
85
+ }
86
+ declare function create(options?: CreateOptions): Promise<Client>;
87
+ //#endregion
88
+ export { CreateOptions, create };