ai 3.1.23 → 3.1.25
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.
- package/dist/index.d.mts +45 -5
- package/dist/index.d.ts +45 -5
- package/dist/index.js +51 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/react/dist/index.d.mts +24 -0
- package/react/dist/index.d.ts +24 -0
- package/rsc/dist/index.d.ts +6 -1
- package/rsc/dist/rsc-server.d.mts +6 -1
- package/rsc/dist/rsc-server.mjs +25 -9
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.d.mts +6 -1
- package/solid/dist/index.d.mts +24 -0
- package/solid/dist/index.d.ts +24 -0
- package/svelte/dist/index.d.mts +24 -0
- package/svelte/dist/index.d.ts +24 -0
- package/vue/dist/index.d.mts +24 -0
- package/vue/dist/index.d.ts +24 -0
package/package.json
CHANGED
package/react/dist/index.d.mts
CHANGED
@@ -227,15 +227,39 @@ type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall)
|
|
227
227
|
*/
|
228
228
|
type ToolCallHandler = (chatMessages: Message[], toolCalls: ToolCall[]) => Promise<ChatRequest | void>;
|
229
229
|
type RequestOptions = {
|
230
|
+
/**
|
231
|
+
An optional object of headers to be passed to the API endpoint.
|
232
|
+
*/
|
230
233
|
headers?: Record<string, string> | Headers;
|
234
|
+
/**
|
235
|
+
An optional object to be passed to the API endpoint.
|
236
|
+
*/
|
231
237
|
body?: object;
|
232
238
|
};
|
233
239
|
type ChatRequestOptions = {
|
240
|
+
/**
|
241
|
+
The options to be passed to the fetch call.
|
242
|
+
*/
|
234
243
|
options?: RequestOptions;
|
244
|
+
/**
|
245
|
+
@deprecated
|
246
|
+
*/
|
235
247
|
functions?: Array<Function>;
|
248
|
+
/**
|
249
|
+
@deprecated
|
250
|
+
*/
|
236
251
|
function_call?: FunctionCall;
|
252
|
+
/**
|
253
|
+
@deprecated
|
254
|
+
*/
|
237
255
|
tools?: Array<Tool>;
|
256
|
+
/**
|
257
|
+
@deprecated
|
258
|
+
*/
|
238
259
|
tool_choice?: ToolChoice;
|
260
|
+
/**
|
261
|
+
Additional data to be sent to the server.
|
262
|
+
*/
|
239
263
|
data?: Record<string, string>;
|
240
264
|
};
|
241
265
|
type UseChatOptions = {
|
package/react/dist/index.d.ts
CHANGED
@@ -227,15 +227,39 @@ type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall)
|
|
227
227
|
*/
|
228
228
|
type ToolCallHandler = (chatMessages: Message[], toolCalls: ToolCall[]) => Promise<ChatRequest | void>;
|
229
229
|
type RequestOptions = {
|
230
|
+
/**
|
231
|
+
An optional object of headers to be passed to the API endpoint.
|
232
|
+
*/
|
230
233
|
headers?: Record<string, string> | Headers;
|
234
|
+
/**
|
235
|
+
An optional object to be passed to the API endpoint.
|
236
|
+
*/
|
231
237
|
body?: object;
|
232
238
|
};
|
233
239
|
type ChatRequestOptions = {
|
240
|
+
/**
|
241
|
+
The options to be passed to the fetch call.
|
242
|
+
*/
|
234
243
|
options?: RequestOptions;
|
244
|
+
/**
|
245
|
+
@deprecated
|
246
|
+
*/
|
235
247
|
functions?: Array<Function>;
|
248
|
+
/**
|
249
|
+
@deprecated
|
250
|
+
*/
|
236
251
|
function_call?: FunctionCall;
|
252
|
+
/**
|
253
|
+
@deprecated
|
254
|
+
*/
|
237
255
|
tools?: Array<Tool>;
|
256
|
+
/**
|
257
|
+
@deprecated
|
258
|
+
*/
|
238
259
|
tool_choice?: ToolChoice;
|
260
|
+
/**
|
261
|
+
Additional data to be sent to the server.
|
262
|
+
*/
|
239
263
|
data?: Record<string, string>;
|
240
264
|
};
|
241
265
|
type UseChatOptions = {
|
package/rsc/dist/index.d.ts
CHANGED
@@ -28,11 +28,16 @@ type MutableAIState<AIState> = {
|
|
28
28
|
update: (newState: ValueOrUpdater<AIState>) => void;
|
29
29
|
done: ((newState: AIState) => void) | (() => void);
|
30
30
|
};
|
31
|
+
declare const __internal_curr: unique symbol;
|
32
|
+
declare const __internal_error: unique symbol;
|
31
33
|
/**
|
32
34
|
* StreamableValue is a value that can be streamed over the network via AI Actions.
|
33
35
|
* To read the streamed values, use the `readStreamableValue` or `useStreamableValue` APIs.
|
34
36
|
*/
|
35
|
-
type StreamableValue<T = any, E = any> = {
|
37
|
+
type StreamableValue<T = any, E = any> = {
|
38
|
+
[__internal_curr]?: T;
|
39
|
+
[__internal_error]?: E;
|
40
|
+
};
|
36
41
|
|
37
42
|
/**
|
38
43
|
* Get the current AI state.
|
@@ -26,11 +26,16 @@ type MutableAIState<AIState> = {
|
|
26
26
|
update: (newState: ValueOrUpdater<AIState>) => void;
|
27
27
|
done: ((newState: AIState) => void) | (() => void);
|
28
28
|
};
|
29
|
+
declare const __internal_curr: unique symbol;
|
30
|
+
declare const __internal_error: unique symbol;
|
29
31
|
/**
|
30
32
|
* StreamableValue is a value that can be streamed over the network via AI Actions.
|
31
33
|
* To read the streamed values, use the `readStreamableValue` or `useStreamableValue` APIs.
|
32
34
|
*/
|
33
|
-
type StreamableValue<T = any, E = any> = {
|
35
|
+
type StreamableValue<T = any, E = any> = {
|
36
|
+
[__internal_curr]?: T;
|
37
|
+
[__internal_error]?: E;
|
38
|
+
};
|
34
39
|
|
35
40
|
/**
|
36
41
|
* Get the current AI state.
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -1640,7 +1640,7 @@ async function streamUI({
|
|
1640
1640
|
const ui = createStreamableUI(initial);
|
1641
1641
|
const textRender = text || defaultTextRenderer;
|
1642
1642
|
let finished;
|
1643
|
-
async function handleRender(args, renderer, res) {
|
1643
|
+
async function handleRender(args, renderer, res, lastCall = false) {
|
1644
1644
|
if (!renderer)
|
1645
1645
|
return;
|
1646
1646
|
const resolvable = createResolvablePromise();
|
@@ -1652,13 +1652,21 @@ async function streamUI({
|
|
1652
1652
|
const value = renderer(...args);
|
1653
1653
|
if (value instanceof Promise || value && typeof value === "object" && "then" in value && typeof value.then === "function") {
|
1654
1654
|
const node = await value;
|
1655
|
-
|
1655
|
+
if (lastCall) {
|
1656
|
+
res.done(node);
|
1657
|
+
} else {
|
1658
|
+
res.update(node);
|
1659
|
+
}
|
1656
1660
|
resolvable.resolve(void 0);
|
1657
1661
|
} else if (value && typeof value === "object" && Symbol.asyncIterator in value) {
|
1658
1662
|
const it = value;
|
1659
1663
|
while (true) {
|
1660
1664
|
const { done, value: value2 } = await it.next();
|
1661
|
-
|
1665
|
+
if (lastCall && done) {
|
1666
|
+
res.done(value2);
|
1667
|
+
} else {
|
1668
|
+
res.update(value2);
|
1669
|
+
}
|
1662
1670
|
if (done)
|
1663
1671
|
break;
|
1664
1672
|
}
|
@@ -1667,13 +1675,21 @@ async function streamUI({
|
|
1667
1675
|
const it = value;
|
1668
1676
|
while (true) {
|
1669
1677
|
const { done, value: value2 } = it.next();
|
1670
|
-
|
1678
|
+
if (lastCall && done) {
|
1679
|
+
res.done(value2);
|
1680
|
+
} else {
|
1681
|
+
res.update(value2);
|
1682
|
+
}
|
1671
1683
|
if (done)
|
1672
1684
|
break;
|
1673
1685
|
}
|
1674
1686
|
resolvable.resolve(void 0);
|
1675
1687
|
} else {
|
1676
|
-
|
1688
|
+
if (lastCall) {
|
1689
|
+
res.done(value);
|
1690
|
+
} else {
|
1691
|
+
res.update(value);
|
1692
|
+
}
|
1677
1693
|
resolvable.resolve(void 0);
|
1678
1694
|
}
|
1679
1695
|
}
|
@@ -1727,6 +1743,7 @@ async function streamUI({
|
|
1727
1743
|
availableTools: Object.keys(tools)
|
1728
1744
|
});
|
1729
1745
|
}
|
1746
|
+
hasToolCall = true;
|
1730
1747
|
const parseResult = safeParseJSON({
|
1731
1748
|
text: value.args,
|
1732
1749
|
schema: tool.parameters
|
@@ -1747,7 +1764,8 @@ async function streamUI({
|
|
1747
1764
|
}
|
1748
1765
|
],
|
1749
1766
|
tool.generate,
|
1750
|
-
ui
|
1767
|
+
ui,
|
1768
|
+
true
|
1751
1769
|
);
|
1752
1770
|
break;
|
1753
1771
|
}
|
@@ -1760,11 +1778,9 @@ async function streamUI({
|
|
1760
1778
|
}
|
1761
1779
|
if (hasToolCall) {
|
1762
1780
|
await finished;
|
1763
|
-
ui.done();
|
1764
1781
|
} else {
|
1765
|
-
handleRender([{ content, done: true }], textRender, ui);
|
1782
|
+
handleRender([{ content, done: true }], textRender, ui, true);
|
1766
1783
|
await finished;
|
1767
|
-
ui.done();
|
1768
1784
|
}
|
1769
1785
|
} catch (error) {
|
1770
1786
|
ui.error(error);
|