blink 0.1.60 → 0.1.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- import * as _ai_sdk_provider0 from "@ai-sdk/provider";
2
- import * as ai0 from "ai";
3
- import { AsyncIterableStream, InferUIMessageChunk, Tool, ToolSet, UIDataTypes, UIMessage, UIMessagePart, UITools } from "ai";
4
1
  import http from "http";
2
+ import * as ai0 from "ai";
3
+ import { AsyncIterableStream, InferToolInput, InferToolOutput, InferUIMessageChunk, Tool, ToolSet, UIDataTypes, UIMessage, UIMessagePart, UITools } from "ai";
4
+ import * as _ai_sdk_provider0 from "@ai-sdk/provider";
5
5
 
6
6
  //#region src/api/chat.d.ts
7
7
  interface Chat {
@@ -39,6 +39,31 @@ declare const chat: Readonly<{
39
39
  type ToolWithContext<CONTEXT, TOOL extends Tool> = TOOL & {
40
40
  withContext(context: CONTEXT): TOOL;
41
41
  };
42
+ /**
43
+ * ToolWithApproval is a tool that supports the "autoApprove" method.
44
+ *
45
+ * @param TOOL The tool type.
46
+ * @returns The tool with the given approval.
47
+ */
48
+ type ToolWithApproval<INPUT, OUTPUT> = Tool<INPUT, OUTPUT> & {
49
+ /**
50
+ * autoApprove is a function that can be used to automatically approve
51
+ * an approval tool call based on the input.
52
+ *
53
+ * @param input The input to the tool.
54
+ * @returns Whether the tool call should be approved.
55
+ */
56
+ autoApprove?: (input: INPUT) => Promise<boolean> | boolean;
57
+ };
58
+ type ToolSetWithApproval<TOOLS extends ToolSet> = { [K in keyof TOOLS]: ToolWithApproval<InferToolInput<TOOLS[K]>, InferToolOutput<TOOLS[K]>> };
59
+ /**
60
+ * toolWithApproval is a helper for inferring the execute and autoApprove
61
+ * arguments of a tool.
62
+ *
63
+ * @param tool The tool to wrap.
64
+ * @returns The wrapped tool.
65
+ */
66
+ declare function toolWithApproval<INPUT, OUTPUT>(tool: ToolWithApproval<INPUT, OUTPUT>): ToolWithApproval<INPUT, OUTPUT>;
42
67
  /**
43
68
  * Tools are helpers for managing tools.
44
69
  */
@@ -67,7 +92,7 @@ declare const tools: {
67
92
  *
68
93
  * @returns Tools that should be sent in `streamText`.
69
94
  */
70
- withApproval<TOOLS extends ToolSet, MESSAGE extends UIMessage>(options: {
95
+ withApproval<TOOLSET extends ToolSet, TOOLS extends ToolSetWithApproval<TOOLSET>, MESSAGE extends UIMessage>(options: {
71
96
  messages: MESSAGE[];
72
97
  tools: TOOLS;
73
98
  abortSignal?: AbortSignal;
@@ -169,6 +194,45 @@ type ExperimentalCompletion = {
169
194
  replace?: [number, number];
170
195
  };
171
196
  type ExperimentalProvideCompletionsResponse = ReadableStream<ExperimentalCompletion> | Promise<ReadableStream<ExperimentalCompletion>> | Promise<ExperimentalCompletion> | ExperimentalCompletion;
197
+ type ProvideOptionsRequest<MESSAGE extends UIMessage = UIMessage> = {
198
+ /**
199
+ * Options that are actively selected by the user.
200
+ *
201
+ * Use this to provide custom options based on previous selections.
202
+ */
203
+ readonly selectedOptions?: ExtractUIOptions<MESSAGE>;
204
+ };
205
+ type OptionSelectValue<ID extends string = string> = {
206
+ readonly id: ID;
207
+ readonly label: string;
208
+ };
209
+ type OptionSelect<Values extends readonly OptionSelectValue[] = readonly OptionSelectValue[]> = {
210
+ readonly type: "select";
211
+ readonly label: string;
212
+ readonly values: Values;
213
+ readonly defaultValue: Values[number]["id"];
214
+ };
215
+ type Options = Record<string, string>;
216
+ type WithUIOptions<OPTIONS extends Options, MESSAGE extends UIMessage = UIMessage> = MESSAGE & {
217
+ readonly role: "user";
218
+ readonly metadata: MESSAGE["metadata"] & {
219
+ readonly options: OPTIONS;
220
+ };
221
+ };
222
+ type ExtractUIOptions<M> = M extends WithUIOptions<infer O> ? O : never;
223
+ type OptionsSchema<OPTIONS extends Options> = { [K in keyof OPTIONS]: OptionSelect<Array<{
224
+ id: OPTIONS[K];
225
+ label: string;
226
+ }>> };
227
+ /**
228
+ * lastUIOptions finds the last user message with options.
229
+ * Options are stored in message metadata to preserve the history
230
+ * of changing options.
231
+ *
232
+ * @param messages - The messages to search.
233
+ * @returns The last user message with options, or undefined if no such message exists.
234
+ */
235
+ declare function lastUIOptions<MESSAGE extends UIMessage>(messages: MESSAGE[]): ExtractUIOptions<MESSAGE> | undefined;
172
236
  interface AgentOptions<MESSAGE extends UIMessage = UIMessage> {
173
237
  /**
174
238
  * sendMessages is called when the agent is streaming chat messages.
@@ -196,14 +260,24 @@ interface AgentOptions<MESSAGE extends UIMessage = UIMessage> {
196
260
  * @returns A stream of completions, or a single completion.
197
261
  */
198
262
  experimental_provideCompletions?(options: ExperimentalProvideCompletionsOptions<MESSAGE>): ExperimentalProvideCompletionsResponse;
263
+ /**
264
+ * provideUIOptions is called when the agent is asked to provide
265
+ * user-selectable options.
266
+ *
267
+ * To provide options, use:
268
+ * @example
269
+ * ```ts
270
+ * blink.agent<blink.WithUIOptions<{
271
+ * model: "gpt-5" | "sonnet"
272
+ * }>>({
273
+ * // ...
274
+ * })
275
+ * ```
276
+ *
277
+ * @returns A schema for the options.
278
+ */
279
+ provideUIOptions?(options: ProvideOptionsRequest<MESSAGE>): Promise<OptionsSchema<ExtractUIOptions<MESSAGE>>> | OptionsSchema<ExtractUIOptions<MESSAGE>>;
199
280
  }
200
- /**
201
- * A Blink agent is simply an HTTP handler with a reserved
202
- * "/_agent/" path used for agent-specific requests.
203
- *
204
- * The environment variable "BLINK_API_SERVER_URL" is used
205
- * to serve responses to the `blink.*` API. (e.g. blink.chat.upsert).
206
- */
207
281
  interface Agent {
208
282
  /**
209
283
  * fetch is the HTTP handler for the agent.
@@ -221,9 +295,6 @@ interface Agent {
221
295
  */
222
296
  serve(options?: ServeOptions): http.Server;
223
297
  }
224
- /**
225
- * ServeOptions is the options for the `.serve()` method.
226
- */
227
298
  type ServeOptions = {
228
299
  readonly host?: string;
229
300
  readonly port?: number;
@@ -274,7 +345,7 @@ declare const _default: {
274
345
  withContext(context: unknown): ai0.Tool;
275
346
  };
276
347
  }>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: ai0.Tool };
277
- withApproval<TOOLS extends ai0.ToolSet, MESSAGE extends UIMessage>(options: {
348
+ withApproval<TOOLSET extends ai0.ToolSet, TOOLS extends ToolSetWithApproval<TOOLSET>, MESSAGE extends UIMessage>(options: {
278
349
  messages: MESSAGE[];
279
350
  tools: TOOLS;
280
351
  abortSignal?: AbortSignal;
@@ -283,4 +354,4 @@ declare const _default: {
283
354
  };
284
355
  };
285
356
  //#endregion
286
- export { Agent, AgentOptions, Chat, ChatBehavior, ContextFromTools, ExperimentalCompletion, ExperimentalProvideCompletionsOptions, ExperimentalProvideCompletionsResponse, Message, MessageOptions, SendMessagesOptions, SendMessagesResponse, ServeOptions, StreamResponseFormat, ToolApprovalOutput, ToolWithContext, _default, agent, chat, isToolApprovalOutput, model, storage, tools, withResponseFormat };
357
+ export { Agent, AgentOptions, Chat, ChatBehavior, ContextFromTools, ExperimentalCompletion, ExperimentalProvideCompletionsOptions, ExperimentalProvideCompletionsResponse, ExtractUIOptions, Message, MessageOptions, OptionSelect, OptionSelectValue, Options, OptionsSchema, ProvideOptionsRequest, SendMessagesOptions, SendMessagesResponse, ServeOptions, StreamResponseFormat, ToolApprovalOutput, ToolSetWithApproval, ToolWithApproval, ToolWithContext, WithUIOptions, _default, agent, chat, isToolApprovalOutput, lastUIOptions, model, storage, toolWithApproval, tools, withResponseFormat };
@@ -1,4 +1,4 @@
1
- import { Chat, ExperimentalCompletion } from "./index-CIUoZVwP.js";
1
+ import { Chat, ExperimentalCompletion, OptionsSchema, ProvideOptionsRequest, WithUIOptions } from "./index-E064W90j.js";
2
2
  import { UIMessage, UIMessageChunk } from "ai";
3
3
 
4
4
  //#region src/http/async-iterable-stream.d.ts
@@ -60,6 +60,7 @@ interface ExperimentalProvideCompletionsRequest {
60
60
  interface CapabilitiesResponse {
61
61
  readonly requests: boolean;
62
62
  readonly completions: boolean;
63
+ readonly options: boolean;
63
64
  }
64
65
  interface ClientOptions {
65
66
  readonly baseUrl: string;
@@ -90,6 +91,12 @@ declare class Client {
90
91
  * This is used to check if the agent supports requests and completions.
91
92
  */
92
93
  capabilities(): Promise<CapabilitiesResponse>;
94
+ /**
95
+ * provideUIOptions provides selectable options to the user.
96
+ */
97
+ provideUIOptions(request: ProvideOptionsRequest<WithUIOptions<Record<string, any>>>, options?: {
98
+ signal?: AbortSignal;
99
+ }): Promise<OptionsSchema<any>>;
93
100
  /**
94
101
  * health simply returns a 200 response.
95
102
  * This is used to check if the agent is running.
@@ -99,4 +106,8 @@ declare class Client {
99
106
  }
100
107
  declare const streamSSE: <T>(resp: Response) => ReadableStream<T>;
101
108
  //#endregion
102
- export { APIServerURLEnvironmentVariable, AsyncIterableStream$1 as AsyncIterableStream, CapabilitiesResponse, Client, ClientOptions, ExperimentalProvideCompletionsRequest, SendMessagesRequest, StreamResponseFormatHeader, createAsyncIterableStream, streamSSE };
109
+ //#region src/http/convert-response-to-ui-message-stream.d.ts
110
+ type StreamResponseFormat = "ui-message" | "openai-chat" | "openai-response" | "anthropic" | "google" | "xai";
111
+ declare function convertResponseToUIMessageStream(response: Response): ReadableStream<UIMessageChunk>;
112
+ //#endregion
113
+ export { APIServerURLEnvironmentVariable, AsyncIterableStream$1 as AsyncIterableStream, CapabilitiesResponse, Client, ClientOptions, ExperimentalProvideCompletionsRequest, SendMessagesRequest, StreamResponseFormat, StreamResponseFormatHeader, convertResponseToUIMessageStream, createAsyncIterableStream, streamSSE };
package/dist/test.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import "./index-IWju3eNc.cjs";
2
- import { Client } from "./index-D4ib-Sj-.cjs";
1
+ import "./index-BdS2C_9A.cjs";
2
+ import { Client } from "./index-DXNEroA1.cjs";
3
3
 
4
4
  //#region src/test.d.ts
5
5
  interface CreateOptions {
package/dist/test.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import "./index-CIUoZVwP.js";
2
- import { Client } from "./index-9U4QN9Pz.js";
1
+ import "./index-E064W90j.js";
2
+ import { Client } from "./index-y1u5VC2_.js";
3
3
 
4
4
  //#region src/test.d.ts
5
5
  interface CreateOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blink",
3
- "version": "0.1.60",
3
+ "version": "0.1.62",
4
4
  "description": "Blink is a JavaScript runtime for building and deploying AI agents.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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};
File without changes
File without changes