ai 3.1.16 → 3.1.18

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,4 +1,3 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
1
  import { ReactNode } from 'react';
3
2
  import OpenAI from 'openai';
4
3
  import { z } from 'zod';
@@ -41,8 +40,8 @@ type StreamableValue<T = any, E = any> = {};
41
40
  * @example const state = getAIState() // Get the entire AI state
42
41
  * @example const field = getAIState('key') // Get the value of the key
43
42
  */
44
- declare function getAIState<AI extends AIProvider = any>(): InferAIState<AI, any>;
45
- declare function getAIState<AI extends AIProvider = any>(key: keyof InferAIState<AI, any>): InferAIState<AI, any>[typeof key];
43
+ declare function getAIState<AI extends AIProvider = any>(): Readonly<InferAIState<AI, any>>;
44
+ declare function getAIState<AI extends AIProvider = any>(key: keyof InferAIState<AI, any>): Readonly<InferAIState<AI, any>[typeof key]>;
46
45
  /**
47
46
  * Get the mutable AI state. Note that you must call `.close()` when finishing
48
47
  * updating the AI state.
@@ -64,19 +63,15 @@ declare function getAIState<AI extends AIProvider = any>(key: keyof InferAIState
64
63
  declare function getMutableAIState<AI extends AIProvider = any>(): MutableAIState<InferAIState<AI, any>>;
65
64
  declare function getMutableAIState<AI extends AIProvider = any>(key: keyof InferAIState<AI, any>): MutableAIState<InferAIState<AI, any>[typeof key]>;
66
65
 
67
- /**
68
- * Create a piece of changable UI that can be streamed to the client.
69
- * On the client side, it can be rendered as a normal React node.
70
- */
71
- declare function createStreamableUI(initialValue?: React.ReactNode): {
66
+ type StreamableUIWrapper = {
72
67
  /**
73
68
  * The value of the streamable UI. This can be returned from a Server Action and received by the client.
74
69
  */
75
- value: react_jsx_runtime.JSX.Element;
70
+ readonly value: React.ReactNode;
76
71
  /**
77
72
  * This method updates the current UI node. It takes a new UI node and replaces the old one.
78
73
  */
79
- update(value: React.ReactNode): any;
74
+ update(value: React.ReactNode): StreamableUIWrapper;
80
75
  /**
81
76
  * This method is used to append a new UI node to the end of the old one.
82
77
  * Once appended a new UI node, the previous UI node cannot be updated anymore.
@@ -93,31 +88,31 @@ declare function createStreamableUI(initialValue?: React.ReactNode): {
93
88
  * // </>
94
89
  * ```
95
90
  */
96
- append(value: React.ReactNode): any;
91
+ append(value: React.ReactNode): StreamableUIWrapper;
97
92
  /**
98
93
  * This method is used to signal that there is an error in the UI stream.
99
94
  * It will be thrown on the client side and caught by the nearest error boundary component.
100
95
  */
101
- error(error: any): any;
96
+ error(error: any): StreamableUIWrapper;
102
97
  /**
103
98
  * This method marks the UI node as finalized. You can either call it without any parameters or with a new UI node as the final state.
104
99
  * Once called, the UI node cannot be updated or appended anymore.
105
100
  *
106
101
  * This method is always **required** to be called, otherwise the response will be stuck in a loading state.
107
102
  */
108
- done(...args: [] | [React.ReactNode]): any;
103
+ done(...args: [React.ReactNode] | []): StreamableUIWrapper;
109
104
  };
110
- declare const STREAMABLE_VALUE_INTERNAL_LOCK: unique symbol;
105
+ /**
106
+ * Create a piece of changable UI that can be streamed to the client.
107
+ * On the client side, it can be rendered as a normal React node.
108
+ */
109
+ declare function createStreamableUI(initialValue?: React.ReactNode): StreamableUIWrapper;
111
110
  /**
112
111
  * Create a wrapped, changable value that can be streamed to the client.
113
112
  * On the client side, the value can be accessed via the readStreamableValue() API.
114
113
  */
115
- declare function createStreamableValue<T = any, E = any>(initialValue?: T | ReadableStream<T>): {
116
- /**
117
- * @internal This is an internal lock to prevent the value from being
118
- * updated by the user.
119
- */
120
- [STREAMABLE_VALUE_INTERNAL_LOCK]: boolean;
114
+ declare function createStreamableValue<T = any, E = any>(initialValue?: T | ReadableStream<T>): StreamableValueWrapper<T, E>;
115
+ type StreamableValueWrapper<T, E> = {
121
116
  /**
122
117
  * The value of the streamable. This can be returned from a Server Action and
123
118
  * received by the client. To read the streamed values, use the
@@ -127,7 +122,7 @@ declare function createStreamableValue<T = any, E = any>(initialValue?: T | Read
127
122
  /**
128
123
  * This method updates the current value with a new one.
129
124
  */
130
- update(value: T): any;
125
+ update(value: T): StreamableValueWrapper<T, E>;
131
126
  /**
132
127
  * This method is used to append a delta string to the current value. It
133
128
  * requires the current value of the streamable to be a string.
@@ -140,13 +135,13 @@ declare function createStreamableValue<T = any, E = any>(initialValue?: T | Read
140
135
  * // The value will be 'hello world'
141
136
  * ```
142
137
  */
143
- append(value: T): any;
138
+ append(value: T): StreamableValueWrapper<T, E>;
144
139
  /**
145
140
  * This method is used to signal that there is an error in the value stream.
146
141
  * It will be thrown on the client side when consumed via
147
142
  * `readStreamableValue` or `useStreamableValue`.
148
143
  */
149
- error(error: any): any;
144
+ error(error: any): StreamableValueWrapper<T, E>;
150
145
  /**
151
146
  * This method marks the value as finalized. You can either call it without
152
147
  * any parameters or with a new value as the final state.
@@ -155,7 +150,7 @@ declare function createStreamableValue<T = any, E = any>(initialValue?: T | Read
155
150
  * This method is always **required** to be called, otherwise the response
156
151
  * will be stuck in a loading state.
157
152
  */
158
- done(...args: [] | [T]): any;
153
+ done(...args: [T] | []): StreamableValueWrapper<T, E>;
159
154
  };
160
155
 
161
156
  type Streamable$1 = ReactNode | Promise<ReactNode>;
@@ -1242,13 +1242,7 @@ function createStreamableUI(initialValue) {
1242
1242
  }
1243
1243
  warnUnclosedStream();
1244
1244
  const streamable2 = {
1245
- /**
1246
- * The value of the streamable UI. This can be returned from a Server Action and received by the client.
1247
- */
1248
1245
  value: row,
1249
- /**
1250
- * This method updates the current UI node. It takes a new UI node and replaces the old one.
1251
- */
1252
1246
  update(value) {
1253
1247
  assertStream(".update()");
1254
1248
  if (value === currentValue) {
@@ -1263,22 +1257,6 @@ function createStreamableUI(initialValue) {
1263
1257
  warnUnclosedStream();
1264
1258
  return streamable2;
1265
1259
  },
1266
- /**
1267
- * This method is used to append a new UI node to the end of the old one.
1268
- * Once appended a new UI node, the previous UI node cannot be updated anymore.
1269
- *
1270
- * @example
1271
- * ```jsx
1272
- * const ui = createStreamableUI(<div>hello</div>)
1273
- * ui.append(<div>world</div>)
1274
- *
1275
- * // The UI node will be:
1276
- * // <>
1277
- * // <div>hello</div>
1278
- * // <div>world</div>
1279
- * // </>
1280
- * ```
1281
- */
1282
1260
  append(value) {
1283
1261
  assertStream(".append()");
1284
1262
  const resolvable = createResolvablePromise();
@@ -1289,10 +1267,6 @@ function createStreamableUI(initialValue) {
1289
1267
  warnUnclosedStream();
1290
1268
  return streamable2;
1291
1269
  },
1292
- /**
1293
- * This method is used to signal that there is an error in the UI stream.
1294
- * It will be thrown on the client side and caught by the nearest error boundary component.
1295
- */
1296
1270
  error(error) {
1297
1271
  assertStream(".error()");
1298
1272
  if (warningTimeout) {
@@ -1302,12 +1276,6 @@ function createStreamableUI(initialValue) {
1302
1276
  reject(error);
1303
1277
  return streamable2;
1304
1278
  },
1305
- /**
1306
- * This method marks the UI node as finalized. You can either call it without any parameters or with a new UI node as the final state.
1307
- * Once called, the UI node cannot be updated or appended anymore.
1308
- *
1309
- * This method is always **required** to be called, otherwise the response will be stuck in a loading state.
1310
- */
1311
1279
  done(...args) {
1312
1280
  assertStream(".done()");
1313
1281
  if (warningTimeout) {
@@ -1420,24 +1388,12 @@ function createStreamableValueImpl(initialValue) {
1420
1388
  currentValue = value;
1421
1389
  }
1422
1390
  const streamable2 = {
1423
- /**
1424
- * @internal This is an internal lock to prevent the value from being
1425
- * updated by the user.
1426
- */
1427
1391
  set [STREAMABLE_VALUE_INTERNAL_LOCK](state) {
1428
1392
  locked = state;
1429
1393
  },
1430
- /**
1431
- * The value of the streamable. This can be returned from a Server Action and
1432
- * received by the client. To read the streamed values, use the
1433
- * `readStreamableValue` or `useStreamableValue` APIs.
1434
- */
1435
1394
  get value() {
1436
1395
  return createWrapped(true);
1437
1396
  },
1438
- /**
1439
- * This method updates the current value with a new one.
1440
- */
1441
1397
  update(value) {
1442
1398
  assertStream(".update()");
1443
1399
  const resolvePrevious = resolvable.resolve;
@@ -1448,18 +1404,6 @@ function createStreamableValueImpl(initialValue) {
1448
1404
  warnUnclosedStream();
1449
1405
  return streamable2;
1450
1406
  },
1451
- /**
1452
- * This method is used to append a delta string to the current value. It
1453
- * requires the current value of the streamable to be a string.
1454
- *
1455
- * @example
1456
- * ```jsx
1457
- * const streamable = createStreamableValue('hello');
1458
- * streamable.append(' world');
1459
- *
1460
- * // The value will be 'hello world'
1461
- * ```
1462
- */
1463
1407
  append(value) {
1464
1408
  assertStream(".append()");
1465
1409
  if (typeof currentValue !== "string" && typeof currentValue !== "undefined") {
@@ -1486,11 +1430,6 @@ function createStreamableValueImpl(initialValue) {
1486
1430
  warnUnclosedStream();
1487
1431
  return streamable2;
1488
1432
  },
1489
- /**
1490
- * This method is used to signal that there is an error in the value stream.
1491
- * It will be thrown on the client side when consumed via
1492
- * `readStreamableValue` or `useStreamableValue`.
1493
- */
1494
1433
  error(error) {
1495
1434
  assertStream(".error()");
1496
1435
  if (warningTimeout) {
@@ -1502,14 +1441,6 @@ function createStreamableValueImpl(initialValue) {
1502
1441
  resolvable.resolve({ error });
1503
1442
  return streamable2;
1504
1443
  },
1505
- /**
1506
- * This method marks the value as finalized. You can either call it without
1507
- * any parameters or with a new value as the final state.
1508
- * Once called, the value cannot be updated or appended anymore.
1509
- *
1510
- * This method is always **required** to be called, otherwise the response
1511
- * will be stuck in a loading state.
1512
- */
1513
1444
  done(...args) {
1514
1445
  assertStream(".done()");
1515
1446
  if (warningTimeout) {