blink 0.1.72 → 0.1.73

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/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/{dev-Cr9A596F.js → dev-C5lfmoC7.js} +99 -103
  30. package/dist/cli/index.js +2 -2
  31. package/dist/cli/{init-LfebhEg-.js → init-DRNYG3Kd.js} +23 -21
  32. package/dist/node/agent/index.node.cjs +10 -0
  33. package/dist/node/agent/index.node.d.cts +2 -0
  34. package/dist/node/agent/index.node.d.ts +2 -0
  35. package/dist/node/agent/index.node.js +10 -0
  36. package/dist/node/index.node-BBpGHHxe.d.ts +460 -0
  37. package/dist/node/index.node-iaeCqAo6.d.cts +460 -0
  38. package/dist/node/test.d.cts +20 -50
  39. package/dist/node/test.d.ts +20 -50
  40. package/package.json +21 -19
  41. package/dist/browser/api/index.browser.cjs +0 -1
  42. package/dist/browser/api/index.browser.d.cts +0 -2
  43. package/dist/browser/api/index.browser.d.ts +0 -2
  44. package/dist/browser/api/index.browser.js +0 -1
  45. package/dist/browser/client-3mJjOKuh.d.ts +0 -94
  46. package/dist/browser/client-B7xl9jGk.d.cts +0 -94
  47. package/dist/browser/client-BbZudkEc.js +0 -21
  48. package/dist/browser/client-DFaZjb1-.cjs +0 -21
  49. package/dist/browser/http/index.cjs +0 -1
  50. package/dist/browser/http/index.d.cts +0 -207
  51. package/dist/browser/http/index.d.ts +0 -207
  52. package/dist/browser/http/index.js +0 -1
  53. package/dist/browser/index.browser-BwGhLjB7.cjs +0 -1
  54. package/dist/browser/index.browser-Dj8kjB6X.js +0 -1
  55. package/dist/browser/index.browser-c6tjyX5u.d.cts +0 -316
  56. package/dist/browser/index.browser-ekIUKJkA.d.ts +0 -316
  57. package/dist/node/api/index.node.cjs +0 -30
  58. package/dist/node/api/index.node.d.cts +0 -82
  59. package/dist/node/api/index.node.d.ts +0 -82
  60. package/dist/node/api/index.node.js +0 -30
  61. package/dist/node/index.browser-Bo1v3lXu.d.cts +0 -316
  62. package/dist/node/index.browser-Dhyi8IHz.d.ts +0 -316
@@ -0,0 +1 @@
1
+ const e=require(`../validator-CvSEfFnI.cjs`),t=(e,t)=>e.json({error:t},400),n=e=>{let t=e.req.param(`key`);return!t||t===``?{key:t,err:`Key is required`}:t.length>475?{key:t,err:`Key is too long. Max length is 475 characters.`}:{key:t}},r=()=>new e.Hono,i=r().get(`/:key`,async e=>{let{key:r,err:i}=n(e);if(i)return t(e,i);let a=await e.env.context.store.get(r);return e.json({value:a},200)}).post(`/:key`,e.validator(`json`,(e,n)=>{let r=e.value;return r?typeof r==`string`?r.length>2e4?t(n,`Value is too long. Max length is 20,000 characters.`):{value:r}:t(n,`Value must be a string`):t(n,`Value is required`)}),async e=>{let{key:r,err:i}=n(e);if(i)return t(e,i);let{value:a}=e.req.valid(`json`);return await e.env.context.store.set(r,a),e.body(null,204)}).delete(`/:key`,async e=>{let{key:r,err:i}=n(e);return i?t(e,i):(await e.env.context.store.delete(r),e.body(null,204))}).get(`/`,async e=>{let{cursor:t,limit:n,prefix:r}=e.req.query(),{entries:i,cursor:a}=await e.env.context.store.list(r,{cursor:t?String(t):void 0,limit:n?Number(n):100});return e.json({entries:i,cursor:a})}),a=e=>{let t=e.req.param(`key`);return t?t.length>475?{key:t,err:`Key is too long. Max length is 475 characters.`}:{key:t}:{key:t,err:`Key is required`}},o=r().basePath(`/:key`).post(`/`,async e=>{let{key:n,err:r}=a(e);return r?t(e,r):e.json(await e.env.context.chat.ensure(n),200)}).post(`/sendMessages`,e.validator(`json`,(e,t)=>({message:e.message,options:e.options})),async e=>{let{key:n,err:r}=a(e);if(r)return t(e,r);let{message:i,options:o}=e.req.valid(`json`);try{await e.env.context.chat.message(n,i,o)}catch(n){return t(e,n instanceof Error?n.message:`Unknown error`)}return e.body(null,204)}),s=new e.Hono().route(`/kv`,i).route(`/chat`,o);exports.api=s;
@@ -0,0 +1,187 @@
1
+ import { Context, MessageOptions } from "../chat-B5eFQu26.cjs";
2
+ import { 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/control/index.d.ts
8
+
9
+ /**
10
+ * To implement your own API bindings, you can use Hono's
11
+ * `createServerAdapter` to create a server that will
12
+ * handle requests to the API.
13
+ *
14
+ * ```ts
15
+ * const server = createHTTPServer(
16
+ * createServerAdapter((req) => {
17
+ * return api.fetch(req, <your-bindings>);
18
+ * })
19
+ * );
20
+ * server.listen(options.port);
21
+ * ```
22
+ */
23
+ declare const api: hono_hono_base0.HonoBase<{
24
+ Bindings: {
25
+ context: Context;
26
+ };
27
+ }, hono_types0.BlankSchema | hono_types0.MergeSchemaPath<{
28
+ "/:key": {
29
+ $get: {
30
+ input: {
31
+ param: {
32
+ key: string;
33
+ };
34
+ };
35
+ output: {
36
+ error: string;
37
+ };
38
+ outputFormat: "json";
39
+ status: 400;
40
+ } | {
41
+ input: {
42
+ param: {
43
+ key: string;
44
+ };
45
+ };
46
+ output: {
47
+ value: string | undefined;
48
+ };
49
+ outputFormat: "json";
50
+ status: 200;
51
+ };
52
+ };
53
+ } & {
54
+ "/:key": {
55
+ $post: {
56
+ input: {
57
+ json: {
58
+ value: string;
59
+ };
60
+ } & {
61
+ param: {
62
+ key: string;
63
+ };
64
+ };
65
+ output: {
66
+ error: string;
67
+ };
68
+ outputFormat: "json";
69
+ status: 400;
70
+ } | {
71
+ input: {
72
+ json: {
73
+ value: string;
74
+ };
75
+ } & {
76
+ param: {
77
+ key: string;
78
+ };
79
+ };
80
+ output: null;
81
+ outputFormat: "body";
82
+ status: 204;
83
+ };
84
+ };
85
+ } & {
86
+ "/:key": {
87
+ $delete: {
88
+ input: {
89
+ param: {
90
+ key: string;
91
+ };
92
+ };
93
+ output: {
94
+ error: string;
95
+ };
96
+ outputFormat: "json";
97
+ status: 400;
98
+ } | {
99
+ input: {
100
+ param: {
101
+ key: string;
102
+ };
103
+ };
104
+ output: null;
105
+ outputFormat: "body";
106
+ status: 204;
107
+ };
108
+ };
109
+ } & {
110
+ "/": {
111
+ $get: {
112
+ input: {};
113
+ output: {
114
+ entries: {
115
+ key: string;
116
+ ttl?: number | undefined;
117
+ }[];
118
+ cursor: string | undefined;
119
+ };
120
+ outputFormat: "json";
121
+ status: hono_utils_http_status0.ContentfulStatusCode;
122
+ };
123
+ };
124
+ }, "/kv"> | hono_types0.MergeSchemaPath<{
125
+ "/:key": {
126
+ $post: {
127
+ input: {
128
+ param: {
129
+ key: string;
130
+ };
131
+ };
132
+ output: {
133
+ error: string;
134
+ };
135
+ outputFormat: "json";
136
+ status: 400;
137
+ } | {
138
+ input: {
139
+ param: {
140
+ key: string;
141
+ };
142
+ };
143
+ output: {
144
+ readonly created: boolean;
145
+ readonly key: string;
146
+ };
147
+ outputFormat: "json";
148
+ status: 200;
149
+ };
150
+ };
151
+ } & {
152
+ "/:key/sendMessages": {
153
+ $post: {
154
+ input: {
155
+ json: {
156
+ message: Omit<UIMessage, "id">;
157
+ options: MessageOptions;
158
+ };
159
+ } & {
160
+ param: {
161
+ key: string;
162
+ };
163
+ };
164
+ output: {
165
+ error: string;
166
+ };
167
+ outputFormat: "json";
168
+ status: 400;
169
+ } | {
170
+ input: {
171
+ json: {
172
+ message: Omit<UIMessage, "id">;
173
+ options: MessageOptions;
174
+ };
175
+ } & {
176
+ param: {
177
+ key: string;
178
+ };
179
+ };
180
+ output: null;
181
+ outputFormat: "body";
182
+ status: 204;
183
+ };
184
+ };
185
+ }, "/chat">, "/">;
186
+ //#endregion
187
+ export { api };
@@ -0,0 +1,187 @@
1
+ import { Context, MessageOptions } from "../chat-BN7SYTWY.js";
2
+ import { 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/control/index.d.ts
8
+
9
+ /**
10
+ * To implement your own API bindings, you can use Hono's
11
+ * `createServerAdapter` to create a server that will
12
+ * handle requests to the API.
13
+ *
14
+ * ```ts
15
+ * const server = createHTTPServer(
16
+ * createServerAdapter((req) => {
17
+ * return api.fetch(req, <your-bindings>);
18
+ * })
19
+ * );
20
+ * server.listen(options.port);
21
+ * ```
22
+ */
23
+ declare const api: hono_hono_base0.HonoBase<{
24
+ Bindings: {
25
+ context: Context;
26
+ };
27
+ }, hono_types0.BlankSchema | hono_types0.MergeSchemaPath<{
28
+ "/:key": {
29
+ $get: {
30
+ input: {
31
+ param: {
32
+ key: string;
33
+ };
34
+ };
35
+ output: {
36
+ error: string;
37
+ };
38
+ outputFormat: "json";
39
+ status: 400;
40
+ } | {
41
+ input: {
42
+ param: {
43
+ key: string;
44
+ };
45
+ };
46
+ output: {
47
+ value: string | undefined;
48
+ };
49
+ outputFormat: "json";
50
+ status: 200;
51
+ };
52
+ };
53
+ } & {
54
+ "/:key": {
55
+ $post: {
56
+ input: {
57
+ json: {
58
+ value: string;
59
+ };
60
+ } & {
61
+ param: {
62
+ key: string;
63
+ };
64
+ };
65
+ output: {
66
+ error: string;
67
+ };
68
+ outputFormat: "json";
69
+ status: 400;
70
+ } | {
71
+ input: {
72
+ json: {
73
+ value: string;
74
+ };
75
+ } & {
76
+ param: {
77
+ key: string;
78
+ };
79
+ };
80
+ output: null;
81
+ outputFormat: "body";
82
+ status: 204;
83
+ };
84
+ };
85
+ } & {
86
+ "/:key": {
87
+ $delete: {
88
+ input: {
89
+ param: {
90
+ key: string;
91
+ };
92
+ };
93
+ output: {
94
+ error: string;
95
+ };
96
+ outputFormat: "json";
97
+ status: 400;
98
+ } | {
99
+ input: {
100
+ param: {
101
+ key: string;
102
+ };
103
+ };
104
+ output: null;
105
+ outputFormat: "body";
106
+ status: 204;
107
+ };
108
+ };
109
+ } & {
110
+ "/": {
111
+ $get: {
112
+ input: {};
113
+ output: {
114
+ entries: {
115
+ key: string;
116
+ ttl?: number | undefined;
117
+ }[];
118
+ cursor: string | undefined;
119
+ };
120
+ outputFormat: "json";
121
+ status: hono_utils_http_status0.ContentfulStatusCode;
122
+ };
123
+ };
124
+ }, "/kv"> | hono_types0.MergeSchemaPath<{
125
+ "/:key": {
126
+ $post: {
127
+ input: {
128
+ param: {
129
+ key: string;
130
+ };
131
+ };
132
+ output: {
133
+ error: string;
134
+ };
135
+ outputFormat: "json";
136
+ status: 400;
137
+ } | {
138
+ input: {
139
+ param: {
140
+ key: string;
141
+ };
142
+ };
143
+ output: {
144
+ readonly created: boolean;
145
+ readonly key: string;
146
+ };
147
+ outputFormat: "json";
148
+ status: 200;
149
+ };
150
+ };
151
+ } & {
152
+ "/:key/sendMessages": {
153
+ $post: {
154
+ input: {
155
+ json: {
156
+ message: Omit<UIMessage, "id">;
157
+ options: MessageOptions;
158
+ };
159
+ } & {
160
+ param: {
161
+ key: string;
162
+ };
163
+ };
164
+ output: {
165
+ error: string;
166
+ };
167
+ outputFormat: "json";
168
+ status: 400;
169
+ } | {
170
+ input: {
171
+ json: {
172
+ message: Omit<UIMessage, "id">;
173
+ options: MessageOptions;
174
+ };
175
+ } & {
176
+ param: {
177
+ key: string;
178
+ };
179
+ };
180
+ output: null;
181
+ outputFormat: "body";
182
+ status: 204;
183
+ };
184
+ };
185
+ }, "/chat">, "/">;
186
+ //#endregion
187
+ export { api };
@@ -0,0 +1 @@
1
+ import{Hono as e,validator as t}from"../validator-DOrmtI_l.js";const n=(e,t)=>e.json({error:t},400),r=e=>{let t=e.req.param(`key`);return!t||t===``?{key:t,err:`Key is required`}:t.length>475?{key:t,err:`Key is too long. Max length is 475 characters.`}:{key:t}},i=()=>new e,a=i().get(`/:key`,async e=>{let{key:t,err:i}=r(e);if(i)return n(e,i);let a=await e.env.context.store.get(t);return e.json({value:a},200)}).post(`/:key`,t(`json`,(e,t)=>{let r=e.value;return r?typeof r==`string`?r.length>2e4?n(t,`Value is too long. Max length is 20,000 characters.`):{value:r}:n(t,`Value must be a string`):n(t,`Value is required`)}),async e=>{let{key:t,err:i}=r(e);if(i)return n(e,i);let{value:a}=e.req.valid(`json`);return await e.env.context.store.set(t,a),e.body(null,204)}).delete(`/:key`,async e=>{let{key:t,err:i}=r(e);return i?n(e,i):(await e.env.context.store.delete(t),e.body(null,204))}).get(`/`,async e=>{let{cursor:t,limit:n,prefix:r}=e.req.query(),{entries:i,cursor:a}=await e.env.context.store.list(r,{cursor:t?String(t):void 0,limit:n?Number(n):100});return e.json({entries:i,cursor:a})}),o=e=>{let t=e.req.param(`key`);return t?t.length>475?{key:t,err:`Key is too long. Max length is 475 characters.`}:{key:t}:{key:t,err:`Key is required`}},s=i().basePath(`/:key`).post(`/`,async e=>{let{key:t,err:r}=o(e);return r?n(e,r):e.json(await e.env.context.chat.ensure(t),200)}).post(`/sendMessages`,t(`json`,(e,t)=>({message:e.message,options:e.options})),async e=>{let{key:t,err:r}=o(e);if(r)return n(e,r);let{message:i,options:a}=e.req.valid(`json`);try{await e.env.context.chat.message(t,i,a)}catch(t){return n(e,t instanceof Error?t.message:`Unknown error`)}return e.body(null,204)}),c=new e().route(`/kv`,a).route(`/chat`,s);export{c as api};
@@ -0,0 +1,53 @@
1
+ import { Chat } from "./chat-BN7SYTWY.js";
2
+ import { UIOptions, UIOptionsSchema } from "./index.browser-BUMCZUeQ.js";
3
+ import { UIMessage, UIMessageChunk } from "ai";
4
+
5
+ //#region src/agent/client/index.d.ts
6
+ declare const APIServerURLEnvironmentVariable = "BLINK_API_URL";
7
+ interface ClientOptions {
8
+ readonly baseUrl: string;
9
+ readonly headers?: Record<string, string>;
10
+ }
11
+ type CapabilitiesResponse = Awaited<ReturnType<Client["capabilities"]>>;
12
+ /**
13
+ * Client is a client for the Blink agent HTTP API.
14
+ */
15
+ declare class Client {
16
+ readonly baseUrl: string;
17
+ private readonly client;
18
+ constructor(options: ClientOptions);
19
+ /**
20
+ * chat starts chatting with the agent.
21
+ */
22
+ chat(request: {
23
+ messages: UIMessage[];
24
+ chat: Chat;
25
+ }, options?: {
26
+ signal?: AbortSignal;
27
+ headers?: Record<string, string>;
28
+ }): Promise<ReadableStream<UIMessageChunk>>;
29
+ /**
30
+ * capabilities returns the capabilities of the agent.
31
+ * This is used to check if the agent supports requests and completions.
32
+ */
33
+ capabilities(): Promise<{
34
+ ui: boolean;
35
+ chat: boolean;
36
+ request: boolean;
37
+ error: boolean;
38
+ }>;
39
+ ui(request: {
40
+ selectedOptions?: UIOptions;
41
+ }, options?: {
42
+ signal?: AbortSignal;
43
+ }): Promise<UIOptionsSchema>;
44
+ /**
45
+ * health simply returns a 200 response.
46
+ * This is used to check if the agent is running.
47
+ */
48
+ health(): Promise<void>;
49
+ private handleError;
50
+ }
51
+ declare const streamSSE: <T>(resp: Response) => ReadableStream<T>;
52
+ //#endregion
53
+ export { APIServerURLEnvironmentVariable, CapabilitiesResponse, Client, ClientOptions, streamSSE };
@@ -0,0 +1,53 @@
1
+ import { Chat } from "./chat-B5eFQu26.cjs";
2
+ import { UIOptions, UIOptionsSchema } from "./index.browser-CnGab8Yp.cjs";
3
+ import { UIMessage, UIMessageChunk } from "ai";
4
+
5
+ //#region src/agent/client/index.d.ts
6
+ declare const APIServerURLEnvironmentVariable = "BLINK_API_URL";
7
+ interface ClientOptions {
8
+ readonly baseUrl: string;
9
+ readonly headers?: Record<string, string>;
10
+ }
11
+ type CapabilitiesResponse = Awaited<ReturnType<Client["capabilities"]>>;
12
+ /**
13
+ * Client is a client for the Blink agent HTTP API.
14
+ */
15
+ declare class Client {
16
+ readonly baseUrl: string;
17
+ private readonly client;
18
+ constructor(options: ClientOptions);
19
+ /**
20
+ * chat starts chatting with the agent.
21
+ */
22
+ chat(request: {
23
+ messages: UIMessage[];
24
+ chat: Chat;
25
+ }, options?: {
26
+ signal?: AbortSignal;
27
+ headers?: Record<string, string>;
28
+ }): Promise<ReadableStream<UIMessageChunk>>;
29
+ /**
30
+ * capabilities returns the capabilities of the agent.
31
+ * This is used to check if the agent supports requests and completions.
32
+ */
33
+ capabilities(): Promise<{
34
+ ui: boolean;
35
+ chat: boolean;
36
+ request: boolean;
37
+ error: boolean;
38
+ }>;
39
+ ui(request: {
40
+ selectedOptions?: UIOptions;
41
+ }, options?: {
42
+ signal?: AbortSignal;
43
+ }): Promise<UIOptionsSchema>;
44
+ /**
45
+ * health simply returns a 200 response.
46
+ * This is used to check if the agent is running.
47
+ */
48
+ health(): Promise<void>;
49
+ private handleError;
50
+ }
51
+ declare const streamSSE: <T>(resp: Response) => ReadableStream<T>;
52
+ //#endregion
53
+ export { APIServerURLEnvironmentVariable, CapabilitiesResponse, Client, ClientOptions, streamSSE };
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`ai`);c=s(c);function l(e){return typeof e==`object`&&!!e&&typeof e[Symbol.asyncIterator]==`function`}var u=class extends Error{constructor(e,t){super(e),this.response=t}};function d(e){return e}const f=Object.freeze({withContext(e,t){let n={};for(let r of Object.keys(e)){let i=e[r];n[r]=i.withContext(t)}return n},with(e,t){let n={};for(let r of Object.keys(e)){let i=e[r];n[r]=i.withContext(t)}return n},async withApproval(e){let t={};for(let[n,r]of Object.entries(e.tools)){let e=r.execute;t[n]={...r,execute:async(t,n)=>{if(r.autoApprove&&e){let i=await r.autoApprove(t);if(i)return e(t,n)}let i={type:`tool-approval`,outcome:`pending`};return i}}}let n=e.messages[e.messages.length-1];if(!n?.parts)return t;let r=[];for(let t of n.parts){if(!(0,c.isToolUIPart)(t))continue;let n=(0,c.getToolName)(t),i=e.tools[n];if(!i||t.state!==`output-available`||!i.execute||!p(t.output))continue;t.output.outcome===`approved`&&r.push({toolName:(0,c.getToolName)(t),tool:i,input:t.input,toolCallId:t.toolCallId})}if(r.length>0){let t=(0,c.createUIMessageStream)({execute:async({writer:t})=>{t.write({type:`start-step`}),await Promise.all(r.map(async n=>{if(!n.tool.execute)throw Error(`Tool does not support execute.`);t.write({type:`tool-input-available`,toolCallId:n.toolCallId,toolName:n.toolName,input:n.input});try{let r=await n.tool.execute(n.input,{toolCallId:n.toolCallId,messages:(0,c.convertToModelMessages)(e.messages,{tools:e.tools}),abortSignal:e.abortSignal});if(l(r))for await(let e of r)t.write({type:`tool-output-available`,toolCallId:n.toolCallId,output:e,preliminary:!0});t.write({type:`tool-output-available`,toolCallId:n.toolCallId,output:r})}catch(e){t.write({type:`tool-output-error`,toolCallId:n.toolCallId,errorText:e instanceof Error?e.message:String(e)})}})),t.write({type:`finish`})}});throw new u(`Executing tools`,t)}return t},prefix(e,t){let n={};for(let[r,i]of Object.entries(e))n[`${t}${r}`]=i;return n}});function p(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`tool-approval`}function m(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n!==void 0&&n.role===`user`&&!(typeof n.metadata!=`object`||n.metadata===null)&&`options`in n.metadata)return n.metadata.options}}const h=`x-blink-stream-response-format`;function g(e,t){let n=new Headers(e.headers);return n.set(h,t),new Response(e.body,{status:e.status,statusText:e.statusText,headers:n})}Object.defineProperty(exports,`CustomChatResponseError`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`StreamResponseFormatHeader`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`__toESM`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`isToolApprovalOutput`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`lastUIOptions`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`toolWithApproval`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`tools`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`withResponseFormat`,{enumerable:!0,get:function(){return g}});
@@ -0,0 +1 @@
1
+ import{convertToModelMessages as e,createUIMessageStream as t,getToolName as n,isToolUIPart as r}from"ai";function i(e){return typeof e==`object`&&!!e&&typeof e[Symbol.asyncIterator]==`function`}var a=class extends Error{constructor(e,t){super(e),this.response=t}};function o(e){return e}const s=Object.freeze({withContext(e,t){let n={};for(let r of Object.keys(e)){let i=e[r];n[r]=i.withContext(t)}return n},with(e,t){let n={};for(let r of Object.keys(e)){let i=e[r];n[r]=i.withContext(t)}return n},async withApproval(o){let s={};for(let[e,t]of Object.entries(o.tools)){let n=t.execute;s[e]={...t,execute:async(e,r)=>{if(t.autoApprove&&n){let i=await t.autoApprove(e);if(i)return n(e,r)}let i={type:`tool-approval`,outcome:`pending`};return i}}}let l=o.messages[o.messages.length-1];if(!l?.parts)return s;let u=[];for(let e of l.parts){if(!r(e))continue;let t=n(e),i=o.tools[t];if(!i||e.state!==`output-available`||!i.execute||!c(e.output))continue;e.output.outcome===`approved`&&u.push({toolName:n(e),tool:i,input:e.input,toolCallId:e.toolCallId})}if(u.length>0){let n=t({execute:async({writer:t})=>{t.write({type:`start-step`}),await Promise.all(u.map(async n=>{if(!n.tool.execute)throw Error(`Tool does not support execute.`);t.write({type:`tool-input-available`,toolCallId:n.toolCallId,toolName:n.toolName,input:n.input});try{let r=await n.tool.execute(n.input,{toolCallId:n.toolCallId,messages:e(o.messages,{tools:o.tools}),abortSignal:o.abortSignal});if(i(r))for await(let e of r)t.write({type:`tool-output-available`,toolCallId:n.toolCallId,output:e,preliminary:!0});t.write({type:`tool-output-available`,toolCallId:n.toolCallId,output:r})}catch(e){t.write({type:`tool-output-error`,toolCallId:n.toolCallId,errorText:e instanceof Error?e.message:String(e)})}})),t.write({type:`finish`})}});throw new a(`Executing tools`,n)}return s},prefix(e,t){let n={};for(let[r,i]of Object.entries(e))n[`${t}${r}`]=i;return n}});function c(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`tool-approval`}function l(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n!==void 0&&n.role===`user`&&!(typeof n.metadata!=`object`||n.metadata===null)&&`options`in n.metadata)return n.metadata.options}}const u=`x-blink-stream-response-format`;function d(e,t){let n=new Headers(e.headers);return n.set(u,t),new Response(e.body,{status:e.status,statusText:e.statusText,headers:n})}export{a as CustomChatResponseError,u as StreamResponseFormatHeader,c as isToolApprovalOutput,l as lastUIOptions,o as toolWithApproval,s as tools,d as withResponseFormat};
@@ -0,0 +1,180 @@
1
+ import { Promisable } from "./chat-BN7SYTWY.js";
2
+ import { InferToolInput, InferToolOutput, Tool, ToolSet, UIMessage } from "ai";
3
+
4
+ //#region src/agent/ui.d.ts
5
+ type UIOptionIcon = `lucide:${string}` | `simple-icons:${string}`;
6
+ type UIOptionSelectValue<ID extends string = string> = {
7
+ readonly id: ID;
8
+ readonly label: string;
9
+ /**
10
+ * description will provide additional context to the user in the UI.
11
+ */
12
+ readonly description?: string | Array<{
13
+ readonly text: string;
14
+ readonly color?: "primary" | "muted" | "warning";
15
+ }>;
16
+ /**
17
+ * icon is a slug of a Lucide or SimpleIcons icon.
18
+ * This will only be rendered in a web-based UI.
19
+ *
20
+ * Find icons:
21
+ * - https://simpleicons.org/
22
+ * - https://lucide.dev/icons/
23
+ */
24
+ readonly icon?: UIOptionIcon;
25
+ };
26
+ type UIOptionSelect<Values extends readonly UIOptionSelectValue[] = readonly UIOptionSelectValue[]> = {
27
+ readonly type: "select";
28
+ /**
29
+ * label indicates the purpose of the option.
30
+ * If omitted, it will not be displayed in the UI.
31
+ */
32
+ readonly label?: string;
33
+ /**
34
+ * icon is a slug of a Lucide or SimpleIcons icon.
35
+ * This will only be rendered in a web-based UI.
36
+ *
37
+ * Find icons:
38
+ * - https://simpleicons.org/
39
+ * - https://lucide.dev/icons/
40
+ */
41
+ readonly icon?: UIOptionIcon;
42
+ /**
43
+ * defaultValue is the default value for the option.
44
+ * If omitted, the option will not be selected by default.
45
+ */
46
+ readonly defaultValue: Values[number]["id"];
47
+ readonly values: Values;
48
+ };
49
+ type UIOptions = Record<string, string>;
50
+ type WithUIOptions<OPTIONS extends UIOptions, MESSAGE extends UIMessage = UIMessage> = MESSAGE & {
51
+ readonly role: "user";
52
+ readonly metadata: MESSAGE["metadata"] & {
53
+ readonly options: OPTIONS;
54
+ };
55
+ };
56
+ type ExtractUIOptions<M> = M extends WithUIOptions<infer O> ? O : UIOptions;
57
+ type UIOptionsSchema<OPTIONS extends UIOptions = UIOptions> = { [K in keyof OPTIONS]: UIOptionSelect<Array<UIOptionSelectValue<OPTIONS[K]>>> };
58
+ interface UIEvent<MESSAGE extends UIMessage> {
59
+ readonly selectedOptions?: ExtractUIOptions<MESSAGE>;
60
+ }
61
+ type UIHandler<MESSAGE extends UIMessage> = (event: UIEvent<MESSAGE>) => Promisable<UIOptionsSchema<ExtractUIOptions<MESSAGE>> | void>;
62
+ /**
63
+ * lastUIOptions finds the last user message with options.
64
+ * Options are stored in message metadata to preserve the history
65
+ * of changing options.
66
+ *
67
+ * @param messages - The messages to search.
68
+ * @returns The last user message with options, or undefined if no such message exists.
69
+ */
70
+ declare function lastUIOptions<MESSAGE extends UIMessage>(messages: MESSAGE[]): ExtractUIOptions<MESSAGE> | undefined;
71
+ //#endregion
72
+ //#region src/agent/tools.d.ts
73
+ /**
74
+ * ToolWithContext is a tool that supports the "withContext" method.
75
+ *
76
+ * @param CONTEXT The context type.
77
+ * @param TOOL The tool type.
78
+ * @returns The tool with the given context.
79
+ */
80
+ type ToolWithContext<CONTEXT, TOOL extends Tool> = TOOL & {
81
+ withContext(context: CONTEXT): TOOL;
82
+ };
83
+ /**
84
+ * ToolWithApproval is a tool that supports the "autoApprove" method.
85
+ *
86
+ * @param TOOL The tool type.
87
+ * @returns The tool with the given approval.
88
+ */
89
+ type ToolWithApproval<INPUT, OUTPUT> = Tool<INPUT, OUTPUT> & {
90
+ /**
91
+ * autoApprove is a function that can be used to automatically approve
92
+ * an approval tool call based on the input.
93
+ *
94
+ * @param input The input to the tool.
95
+ * @returns Whether the tool call should be approved.
96
+ */
97
+ autoApprove?: (input: INPUT) => Promise<boolean> | boolean;
98
+ };
99
+ type ToolSetWithApproval<TOOLS extends ToolSet> = { [K in keyof TOOLS]: ToolWithApproval<InferToolInput<TOOLS[K]>, InferToolOutput<TOOLS[K]>> };
100
+ /**
101
+ * toolWithApproval is a helper for inferring the execute and autoApprove
102
+ * arguments of a tool.
103
+ *
104
+ * @param tool The tool to wrap.
105
+ * @returns The wrapped tool.
106
+ */
107
+ declare function toolWithApproval<INPUT, OUTPUT>(tool: ToolWithApproval<INPUT, OUTPUT>): ToolWithApproval<INPUT, OUTPUT>;
108
+ /**
109
+ * Tools are helpers for managing tools.
110
+ */
111
+ declare const tools: Readonly<{
112
+ /**
113
+ * withContext adds context to a set of tools that supports the "withContext" method.
114
+ *
115
+ * @param context
116
+ * @param tools
117
+ * @returns
118
+ */
119
+ withContext<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
120
+ /**
121
+ * @internal
122
+ * @deprecated Use withContext instead - it's the same thing.
123
+ */
124
+ with<const TOOLS extends ToolsWithContext>(tools: TOOLS, context: ContextFromTools<TOOLS>): { [K in keyof TOOLS]: Tool };
125
+ /**
126
+ * withApproval ensures a set of tools need explicit user approval
127
+ * before they are executed.
128
+ *
129
+ * This works by replacing the execution of all provided tools with
130
+ * special output that interfaces must handle.
131
+ *
132
+ * On approval, the tool will be executed with the verbatim input.
133
+ *
134
+ * @returns Tools that should be sent in `streamText`.
135
+ */
136
+ withApproval<TOOLSET extends ToolSet, TOOLS extends ToolSetWithApproval<TOOLSET>, MESSAGE extends UIMessage>(options: {
137
+ messages: MESSAGE[];
138
+ tools: TOOLS;
139
+ abortSignal?: AbortSignal;
140
+ }): Promise<TOOLS>;
141
+ /**
142
+ * prefix adds a prefix to all the tools in a tool set.
143
+ *
144
+ * @param tools The tool set to prefix.
145
+ * @param prefix The prefix to add to the tools.
146
+ * @returns The prefixed tool set.
147
+ */
148
+ prefix(tools: ToolSet, prefix: string): ToolSet;
149
+ }>;
150
+ type ToolsWithContext = Record<string, Tool & {
151
+ withContext(context: unknown): Tool;
152
+ }>;
153
+ type ContextFromTools<TOOLS extends ToolsWithContext> = TOOLS[keyof TOOLS] extends {
154
+ withContext(context: infer C): any;
155
+ } ? C : never;
156
+ /**
157
+ * ToolApprovalOutput is the output of a tool that requires approval.
158
+ *
159
+ * This should be consumed by the UI to display an approval prompt.
160
+ */
161
+ interface ToolApprovalOutput {
162
+ type: "tool-approval";
163
+ outcome: "pending" | "approved" | "rejected";
164
+ reason?: string;
165
+ }
166
+ /**
167
+ * isToolApprovalOutput checks if an output is a tool approval output.
168
+ */
169
+ declare function isToolApprovalOutput(output: unknown): output is ToolApprovalOutput;
170
+ //#endregion
171
+ //#region src/agent/index.browser.d.ts
172
+ type StreamResponseFormat = "ui-message" | "openai-chat" | "openai-response" | "anthropic" | "google" | "xai";
173
+ /**
174
+ * StreamResponseFormatHeader indicates to a client the stream response
175
+ * format that the agent is using.
176
+ */
177
+ declare const StreamResponseFormatHeader = "x-blink-stream-response-format";
178
+ declare function withResponseFormat(response: Response, format: StreamResponseFormat): Response;
179
+ //#endregion
180
+ export { ContextFromTools, ExtractUIOptions, StreamResponseFormat, StreamResponseFormatHeader, ToolApprovalOutput, ToolSetWithApproval, ToolWithApproval, ToolWithContext, UIEvent, UIHandler, UIOptionSelect, UIOptionSelectValue, UIOptions, UIOptionsSchema, WithUIOptions, isToolApprovalOutput, lastUIOptions, toolWithApproval, tools, withResponseFormat };