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.
Files changed (68) hide show
  1. package/dist/browser/agent/client/index.cjs +21 -0
  2. package/dist/browser/agent/client/index.d.cts +4 -0
  3. package/dist/browser/agent/client/index.d.ts +4 -0
  4. package/dist/browser/agent/client/index.js +21 -0
  5. package/dist/browser/agent/index.browser.cjs +1 -0
  6. package/dist/browser/agent/index.browser.d.cts +3 -0
  7. package/dist/browser/agent/index.browser.d.ts +3 -0
  8. package/dist/browser/agent/index.browser.js +1 -0
  9. package/dist/browser/chat-B5eFQu26.d.cts +129 -0
  10. package/dist/browser/chat-BN7SYTWY.d.ts +129 -0
  11. package/dist/browser/control/index.cjs +1 -0
  12. package/dist/browser/control/index.d.cts +187 -0
  13. package/dist/browser/control/index.d.ts +187 -0
  14. package/dist/browser/control/index.js +1 -0
  15. package/dist/browser/index-B5faDAC2.d.ts +53 -0
  16. package/dist/browser/index-C-GJWB97.d.cts +53 -0
  17. package/dist/browser/index.browser-09e-NXpn.cjs +1 -0
  18. package/dist/browser/index.browser-0KfCzcI7.js +1 -0
  19. package/dist/browser/index.browser-BUMCZUeQ.d.ts +180 -0
  20. package/dist/browser/index.browser-CnGab8Yp.d.cts +180 -0
  21. package/dist/browser/index.node-DJv-HF6j.js +3 -0
  22. package/dist/browser/index.node-mda_IL6K.cjs +3 -0
  23. package/dist/browser/react/index.cjs +1 -1
  24. package/dist/browser/react/index.d.cts +6 -5
  25. package/dist/browser/react/index.d.ts +6 -5
  26. package/dist/browser/react/index.js +1 -1
  27. package/dist/browser/validator-CvSEfFnI.cjs +1 -0
  28. package/dist/browser/validator-DOrmtI_l.js +1 -0
  29. package/dist/cli/{auth-Dw-wJ1IM.js → auth-BUNIOupD.js} +1 -1
  30. package/dist/cli/{chat-CvTLq5E0.js → chat-L0VBV1Zr.js} +1 -1
  31. package/dist/cli/{dev-Cr9A596F.js → dev-CMwHkKBI.js} +133 -137
  32. package/dist/cli/index.js +4 -4
  33. package/dist/cli/{init-LfebhEg-.js → init-B6vWokUI.js} +24 -22
  34. package/dist/cli/login-DKW_KVCA.js +1 -0
  35. package/dist/node/agent/index.node.cjs +10 -0
  36. package/dist/node/agent/index.node.d.cts +2 -0
  37. package/dist/node/agent/index.node.d.ts +2 -0
  38. package/dist/node/agent/index.node.js +10 -0
  39. package/dist/node/index.node-BBpGHHxe.d.ts +460 -0
  40. package/dist/node/index.node-iaeCqAo6.d.cts +460 -0
  41. package/dist/node/test.d.cts +20 -50
  42. package/dist/node/test.d.ts +20 -50
  43. package/package.json +21 -19
  44. package/dist/browser/api/index.browser.cjs +0 -1
  45. package/dist/browser/api/index.browser.d.cts +0 -2
  46. package/dist/browser/api/index.browser.d.ts +0 -2
  47. package/dist/browser/api/index.browser.js +0 -1
  48. package/dist/browser/client-3mJjOKuh.d.ts +0 -94
  49. package/dist/browser/client-B7xl9jGk.d.cts +0 -94
  50. package/dist/browser/client-BbZudkEc.js +0 -21
  51. package/dist/browser/client-DFaZjb1-.cjs +0 -21
  52. package/dist/browser/http/index.cjs +0 -1
  53. package/dist/browser/http/index.d.cts +0 -207
  54. package/dist/browser/http/index.d.ts +0 -207
  55. package/dist/browser/http/index.js +0 -1
  56. package/dist/browser/index.browser-BwGhLjB7.cjs +0 -1
  57. package/dist/browser/index.browser-Dj8kjB6X.js +0 -1
  58. package/dist/browser/index.browser-c6tjyX5u.d.cts +0 -316
  59. package/dist/browser/index.browser-ekIUKJkA.d.ts +0 -316
  60. package/dist/cli/login-KHDcJ0iZ.js +0 -1
  61. package/dist/node/api/index.node.cjs +0 -30
  62. package/dist/node/api/index.node.d.cts +0 -82
  63. package/dist/node/api/index.node.d.ts +0 -82
  64. package/dist/node/api/index.node.js +0 -30
  65. package/dist/node/index.browser-Bo1v3lXu.d.cts +0 -316
  66. package/dist/node/index.browser-Dhyi8IHz.d.ts +0 -316
  67. /package/dist/cli/{dist-CN69Y-yA.js → dist-NqrnQGst.js} +0 -0
  68. /package/dist/cli/{open-Cr8lEmcs.js → open-CSMQaj0E.js} +0 -0
@@ -0,0 +1,460 @@
1
+ import * as http from "http";
2
+ import { InferToolInput, InferToolOutput, InferUIMessageChunk, StreamTextResult, Tool, ToolSet, UIMessage } from "ai";
3
+ import * as hono_utils_http_status0 from "hono/utils/http-status";
4
+ import * as hono_types0 from "hono/types";
5
+ import * as hono_hono_base0 from "hono/hono-base";
6
+
7
+ //#region src/agent/context.d.ts
8
+ interface Context {
9
+ readonly chat: ChatContext;
10
+ /**
11
+ * Store is basic key-value storage for the agent.
12
+ *
13
+ * Commonly used for: authentication state, caching external resources, or other state.
14
+ */
15
+ readonly store: StoreContext;
16
+ }
17
+ interface ChatContext {
18
+ /**
19
+ * ensure gets or creates a chat by key for the agent.
20
+ *
21
+ * @param key A unique key for the chat (e.g. "github-pr-1234")
22
+ * @returns the gotten or created chat.
23
+ */
24
+ ensure(key: string): Promise<EnsuredChat>;
25
+ /**
26
+ * message sends a message to a chat.
27
+ *
28
+ * If the chat does not exist, an error will be thrown.
29
+ *
30
+ * @param key the key of the chat.
31
+ * @param message the message to send.
32
+ * @param options the options for the message.
33
+ */
34
+ message(key: string, message: Omit<UIMessage, "id">, options?: MessageOptions): Promise<void>;
35
+ }
36
+ interface StoreContext {
37
+ /**
38
+ * get retrieves a value from storage.
39
+ *
40
+ * @param key the key of the value.
41
+ * @returns the value.
42
+ */
43
+ get(key: string): Promise<string | undefined>;
44
+ /**
45
+ * set a value.
46
+ *
47
+ * @param key the key of the value.
48
+ * @param value the value to set.
49
+ */
50
+ set(key: string, value: string, options?: {
51
+ /**
52
+ * ttl is the number of seconds to keep the value.
53
+ *
54
+ * If not set, the value will never expire.
55
+ */
56
+ ttl?: number;
57
+ }): Promise<void>;
58
+ /**
59
+ * delete a value.
60
+ *
61
+ * @param key the key of the value.
62
+ */
63
+ delete(key: string): Promise<void>;
64
+ /**
65
+ * list all values by prefix.
66
+ *
67
+ * @param prefix the prefix of the keys.
68
+ * @returns the values.
69
+ */
70
+ list(prefix?: string, options?: {
71
+ /**
72
+ * limit is the maximum number of values to return.
73
+ *
74
+ * Defaults to 100. Limit is 1000.
75
+ */
76
+ limit?: number;
77
+ /**
78
+ * cursor is the cursor to start from.
79
+ *
80
+ * If not set, the list will start from the beginning.
81
+ */
82
+ cursor?: string;
83
+ }): Promise<{
84
+ entries: Array<{
85
+ key: string;
86
+ ttl?: number;
87
+ }>;
88
+ cursor?: string;
89
+ }>;
90
+ }
91
+ //#endregion
92
+ //#region src/agent/internal/types.d.ts
93
+ type Promisable<T> = T | Promise<T>;
94
+ //#endregion
95
+ //#region src/agent/chat.d.ts
96
+ interface Chat {
97
+ readonly key: string;
98
+ }
99
+ interface EnsuredChat extends Chat {
100
+ readonly created: boolean;
101
+ }
102
+ type ChatBehavior = "enqueue" | "interrupt" | "append";
103
+ interface MessageOptions {
104
+ /**
105
+ * behavior of the chat when sending this message.
106
+ *
107
+ * - "enqueue" will add messages to the chat and start the chat eventually.
108
+ * - "interrupt" will interrupt the chat if running and send messages.
109
+ * - "append" will add messages to the chat.
110
+ */
111
+ readonly behavior?: ChatBehavior;
112
+ /**
113
+ * createdAt is the timestamp of the message.
114
+ *
115
+ * If not set, the message will be created at the current time.
116
+ *
117
+ * Use this to handle incoming messages displaying at the
118
+ * timestamp of their origin (e.g. a comment from GitHub).
119
+ */
120
+ readonly createdAt?: Date;
121
+ }
122
+ interface ChatEvent<MESSAGE extends UIMessage> {
123
+ readonly key: string;
124
+ readonly messages: MESSAGE[];
125
+ readonly abortSignal?: AbortSignal;
126
+ readonly context: Context;
127
+ }
128
+ type ChatResponse<MESSAGE extends UIMessage> = {
129
+ toUIMessageStream: StreamTextResult<any, any>["toUIMessageStream"];
130
+ } | Response | ReadableStream<InferUIMessageChunk<MESSAGE>> | void;
131
+ type ChatHandler<MESSAGE extends UIMessage> = (event: ChatEvent<MESSAGE>) => Promisable<ChatResponse<MESSAGE>>;
132
+ //#endregion
133
+ //#region src/agent/ui.d.ts
134
+ type UIOptionIcon = `lucide:${string}` | `simple-icons:${string}`;
135
+ type UIOptionSelectValue<ID extends string = string> = {
136
+ readonly id: ID;
137
+ readonly label: string;
138
+ /**
139
+ * description will provide additional context to the user in the UI.
140
+ */
141
+ readonly description?: string | Array<{
142
+ readonly text: string;
143
+ readonly color?: "primary" | "muted" | "warning";
144
+ }>;
145
+ /**
146
+ * icon is a slug of a Lucide or SimpleIcons icon.
147
+ * This will only be rendered in a web-based UI.
148
+ *
149
+ * Find icons:
150
+ * - https://simpleicons.org/
151
+ * - https://lucide.dev/icons/
152
+ */
153
+ readonly icon?: UIOptionIcon;
154
+ };
155
+ type UIOptionSelect<Values extends readonly UIOptionSelectValue[] = readonly UIOptionSelectValue[]> = {
156
+ readonly type: "select";
157
+ /**
158
+ * label indicates the purpose of the option.
159
+ * If omitted, it will not be displayed in the UI.
160
+ */
161
+ readonly label?: string;
162
+ /**
163
+ * icon is a slug of a Lucide or SimpleIcons icon.
164
+ * This will only be rendered in a web-based UI.
165
+ *
166
+ * Find icons:
167
+ * - https://simpleicons.org/
168
+ * - https://lucide.dev/icons/
169
+ */
170
+ readonly icon?: UIOptionIcon;
171
+ /**
172
+ * defaultValue is the default value for the option.
173
+ * If omitted, the option will not be selected by default.
174
+ */
175
+ readonly defaultValue: Values[number]["id"];
176
+ readonly values: Values;
177
+ };
178
+ type UIOptions = Record<string, string>;
179
+ type WithUIOptions<OPTIONS extends UIOptions, MESSAGE extends UIMessage = UIMessage> = MESSAGE & {
180
+ readonly role: "user";
181
+ readonly metadata: MESSAGE["metadata"] & {
182
+ readonly options: OPTIONS;
183
+ };
184
+ };
185
+ type ExtractUIOptions<M> = M extends WithUIOptions<infer O> ? O : UIOptions;
186
+ type UIOptionsSchema<OPTIONS extends UIOptions = UIOptions> = { [K in keyof OPTIONS]: UIOptionSelect<Array<UIOptionSelectValue<OPTIONS[K]>>> };
187
+ interface UIEvent<MESSAGE extends UIMessage> {
188
+ readonly selectedOptions?: ExtractUIOptions<MESSAGE>;
189
+ }
190
+ type UIHandler<MESSAGE extends UIMessage> = (event: UIEvent<MESSAGE>) => Promisable<UIOptionsSchema<ExtractUIOptions<MESSAGE>> | void>;
191
+ /**
192
+ * lastUIOptions finds the last user message with options.
193
+ * Options are stored in message metadata to preserve the history
194
+ * of changing options.
195
+ *
196
+ * @param messages - The messages to search.
197
+ * @returns The last user message with options, or undefined if no such message exists.
198
+ */
199
+ declare function lastUIOptions<MESSAGE extends UIMessage>(messages: MESSAGE[]): ExtractUIOptions<MESSAGE> | undefined;
200
+ //#endregion
201
+ //#region src/agent/agent.d.ts
202
+ interface ServeOptions {
203
+ /**
204
+ * apiUrl is the URL of the Blink API server which the agent
205
+ * uses to create chats, send messages, and manage storage.
206
+ *
207
+ * Defaults `BLINK_API_URL`. If not set, the agent will warn
208
+ * and throw an error if a request is attempted to the API.
209
+ */
210
+ apiUrl?: string;
211
+ /**
212
+ * host is the host to serve the agent on.
213
+ *
214
+ * Defaults to `HOST` or `127.0.0.1.
215
+ */
216
+ host?: string;
217
+ /**
218
+ * port is the port to serve the agent on.
219
+ *
220
+ * Defaults to `PORT` or `3000`.
221
+ */
222
+ port?: number;
223
+ }
224
+ type RequestHandler = (request: Request, context: Context) => Promisable<Response | void>;
225
+ type ErrorHandler = (error: Error) => Promisable<Response | void>;
226
+ interface Agent<MESSAGE extends UIMessage> {
227
+ on(event: "chat", handler: ChatHandler<MESSAGE>): Agent<MESSAGE>;
228
+ on(event: "ui", handler: UIHandler<MESSAGE>): Agent<MESSAGE>;
229
+ on(event: "request", handler: RequestHandler): Agent<MESSAGE>;
230
+ on(event: "error", handler: ErrorHandler): Agent<MESSAGE>;
231
+ serve(options?: ServeOptions): http.Server;
232
+ }
233
+ type OverloadedParameters<T> = T extends {
234
+ (...a: infer A): any;
235
+ (...a: infer B): any;
236
+ (...a: infer C): any;
237
+ (...a: infer D): any;
238
+ (...a: infer E): any;
239
+ } ? A | B | C | D | E : never;
240
+ type OnTuples<M extends UIMessage> = OverloadedParameters<Agent<M>["on"]>;
241
+ type OnEvent<M extends UIMessage> = OnTuples<M>[0];
242
+ type OnHandler<M extends UIMessage, E extends OnEvent<M>> = Extract<OnTuples<M>, [E, any]>[1];
243
+ type Listeners<M extends UIMessage> = { [E in OnEvent<M>]: Array<OnHandler<M, E>> };
244
+ /**
245
+ * agent constructs a new agent.
246
+ *
247
+ * @param options
248
+ * @returns
249
+ */
250
+ declare function agent<MESSAGE extends UIMessage>(): Agent<MESSAGE>;
251
+ declare const api: hono_hono_base0.HonoBase<{
252
+ Bindings: {
253
+ listeners: Listeners<any>;
254
+ context: Context;
255
+ };
256
+ }, {
257
+ "*": {
258
+ $all: {
259
+ input: {};
260
+ output: {};
261
+ outputFormat: string;
262
+ status: hono_utils_http_status0.StatusCode;
263
+ };
264
+ };
265
+ } | (hono_types0.MergeSchemaPath<{
266
+ "/chat": {
267
+ $post: {
268
+ input: {
269
+ json: {
270
+ messages: UIMessage[];
271
+ chat: Chat;
272
+ };
273
+ };
274
+ output: {};
275
+ outputFormat: string;
276
+ status: hono_utils_http_status0.StatusCode;
277
+ };
278
+ };
279
+ } & {
280
+ "/capabilities": {
281
+ $get: {
282
+ input: {};
283
+ output: {
284
+ ui: boolean;
285
+ chat: boolean;
286
+ request: boolean;
287
+ error: boolean;
288
+ };
289
+ outputFormat: "json";
290
+ status: 200;
291
+ };
292
+ };
293
+ } & {
294
+ "/health": {
295
+ $get: {
296
+ input: {};
297
+ output: "OK";
298
+ outputFormat: "body";
299
+ status: 200;
300
+ };
301
+ };
302
+ } & {
303
+ "/ui": {
304
+ $get: {
305
+ input: {};
306
+ output: {
307
+ error: string;
308
+ };
309
+ outputFormat: "json";
310
+ status: 400;
311
+ } | {
312
+ input: {};
313
+ output: {
314
+ [x: string]: {
315
+ readonly type: "select";
316
+ readonly label?: string | undefined;
317
+ readonly icon?: (`lucide:${string}` | `simple-icons:${string}`) | undefined;
318
+ readonly defaultValue: string;
319
+ readonly values: {
320
+ readonly id: string;
321
+ readonly label: string;
322
+ readonly description?: string | {
323
+ readonly text: string;
324
+ readonly color?: "primary" | "muted" | "warning" | undefined;
325
+ }[] | undefined;
326
+ readonly icon?: (`lucide:${string}` | `simple-icons:${string}`) | undefined;
327
+ }[];
328
+ };
329
+ };
330
+ outputFormat: "json";
331
+ status: 200;
332
+ } | {
333
+ input: {};
334
+ output: {
335
+ error: string;
336
+ };
337
+ outputFormat: "json";
338
+ status: 404;
339
+ };
340
+ };
341
+ }, "/_agent"> & {
342
+ "*": {
343
+ $all: {
344
+ input: {};
345
+ output: {};
346
+ outputFormat: string;
347
+ status: hono_utils_http_status0.StatusCode;
348
+ };
349
+ };
350
+ }), "/">;
351
+ //#endregion
352
+ //#region src/agent/tools.d.ts
353
+ /**
354
+ * ToolWithContext is a tool that supports the "withContext" method.
355
+ *
356
+ * @param CONTEXT The context type.
357
+ * @param TOOL The tool type.
358
+ * @returns The tool with the given context.
359
+ */
360
+ type ToolWithContext<CONTEXT, TOOL extends Tool> = TOOL & {
361
+ withContext(context: CONTEXT): TOOL;
362
+ };
363
+ /**
364
+ * ToolWithApproval is a tool that supports the "autoApprove" method.
365
+ *
366
+ * @param TOOL The tool type.
367
+ * @returns The tool with the given approval.
368
+ */
369
+ type ToolWithApproval<INPUT, OUTPUT> = Tool<INPUT, OUTPUT> & {
370
+ /**
371
+ * autoApprove is a function that can be used to automatically approve
372
+ * an approval tool call based on the input.
373
+ *
374
+ * @param input The input to the tool.
375
+ * @returns Whether the tool call should be approved.
376
+ */
377
+ autoApprove?: (input: INPUT) => Promise<boolean> | boolean;
378
+ };
379
+ type ToolSetWithApproval<TOOLS extends ToolSet> = { [K in keyof TOOLS]: ToolWithApproval<InferToolInput<TOOLS[K]>, InferToolOutput<TOOLS[K]>> };
380
+ /**
381
+ * toolWithApproval is a helper for inferring the execute and autoApprove
382
+ * arguments of a tool.
383
+ *
384
+ * @param tool The tool to wrap.
385
+ * @returns The wrapped tool.
386
+ */
387
+ declare function toolWithApproval<INPUT, OUTPUT>(tool: ToolWithApproval<INPUT, OUTPUT>): ToolWithApproval<INPUT, OUTPUT>;
388
+ /**
389
+ * Tools are helpers for managing tools.
390
+ */
391
+ declare const tools: Readonly<{
392
+ /**
393
+ * withContext adds context to a set of tools that supports the "withContext" method.
394
+ *
395
+ * @param context
396
+ * @param tools
397
+ * @returns
398
+ */
399
+ withContext<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
400
+ /**
401
+ * @internal
402
+ * @deprecated Use withContext instead - it's the same thing.
403
+ */
404
+ with<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
405
+ /**
406
+ * withApproval ensures a set of tools need explicit user approval
407
+ * before they are executed.
408
+ *
409
+ * This works by replacing the execution of all provided tools with
410
+ * special output that interfaces must handle.
411
+ *
412
+ * On approval, the tool will be executed with the verbatim input.
413
+ *
414
+ * @returns Tools that should be sent in `streamText`.
415
+ */
416
+ withApproval<TOOLSET extends ToolSet, TOOLS extends ToolSetWithApproval<TOOLSET>, MESSAGE extends UIMessage>(options: {
417
+ messages: MESSAGE[];
418
+ tools: TOOLS;
419
+ abortSignal?: AbortSignal;
420
+ }): Promise<TOOLS>;
421
+ /**
422
+ * prefix adds a prefix to all the tools in a tool set.
423
+ *
424
+ * @param tools The tool set to prefix.
425
+ * @param prefix The prefix to add to the tools.
426
+ * @returns The prefixed tool set.
427
+ */
428
+ prefix(tools: ToolSet, prefix: string): ToolSet;
429
+ }>;
430
+ type ToolsWithContext = Record<string, Tool & {
431
+ withContext(context: unknown): Tool;
432
+ }>;
433
+ type ContextFromTools<TOOLS extends ToolsWithContext> = TOOLS[keyof TOOLS] extends {
434
+ withContext(context: infer C): any;
435
+ } ? C : never;
436
+ /**
437
+ * ToolApprovalOutput is the output of a tool that requires approval.
438
+ *
439
+ * This should be consumed by the UI to display an approval prompt.
440
+ */
441
+ interface ToolApprovalOutput {
442
+ type: "tool-approval";
443
+ outcome: "pending" | "approved" | "rejected";
444
+ reason?: string;
445
+ }
446
+ /**
447
+ * isToolApprovalOutput checks if an output is a tool approval output.
448
+ */
449
+ declare function isToolApprovalOutput(output: unknown): output is ToolApprovalOutput;
450
+ //#endregion
451
+ //#region src/agent/index.browser.d.ts
452
+ type StreamResponseFormat = "ui-message" | "openai-chat" | "openai-response" | "anthropic" | "google" | "xai";
453
+ /**
454
+ * StreamResponseFormatHeader indicates to a client the stream response
455
+ * format that the agent is using.
456
+ */
457
+ declare const StreamResponseFormatHeader = "x-blink-stream-response-format";
458
+ declare function withResponseFormat(response: Response, format: StreamResponseFormat): Response;
459
+ //#endregion
460
+ export { Agent, Chat, ChatBehavior, ChatContext, ChatEvent, ChatHandler, ChatResponse, Context, ContextFromTools, EnsuredChat, ErrorHandler, ExtractUIOptions, MessageOptions, RequestHandler, ServeOptions, StoreContext, StreamResponseFormat, StreamResponseFormatHeader, ToolApprovalOutput, ToolSetWithApproval, ToolWithApproval, ToolWithContext, UIEvent, UIHandler, UIOptionSelect, UIOptionSelectValue, UIOptions, UIOptionsSchema, WithUIOptions, agent, api, isToolApprovalOutput, lastUIOptions, toolWithApproval, tools, withResponseFormat };