ai 7.0.100 → 7.0.102
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/CHANGELOG.md +36 -0
- package/dist/index.d.ts +82 -20
- package/dist/index.js +2017 -330
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +12 -5
- package/dist/internal/index.js.map +1 -1
- package/docs/03-agents/07-workflow-agent.mdx +1 -1
- package/docs/03-ai-sdk-core/36-realtime.mdx +41 -18
- package/docs/04-ai-sdk-ui/21-transport.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/05-use-realtime.mdx +364 -48
- package/docs/07-reference/04-ai-sdk-workflow/02-workflow-chat-transport.mdx +4 -4
- package/docs/07-reference/05-ai-sdk-errors/index.mdx +131 -36
- package/package.json +12 -12
- package/src/generate-text/execute-tools-from-stream.ts +7 -0
- package/src/generate-text/stream-text.ts +3 -1
- package/src/prompt/create-tool-model-output.ts +16 -5
- package/src/realtime/__fixtures__/fake-live-websocket.ts +71 -0
- package/src/realtime/__fixtures__/fake-realtime.ts +36 -0
- package/src/realtime/__fixtures__/fake-webrtc.ts +133 -0
- package/src/realtime/browser-realtime-audio.ts +107 -10
- package/src/realtime/browser-realtime-live-websocket.ts +247 -0
- package/src/realtime/browser-realtime-transport.ts +235 -69
- package/src/realtime/browser-realtime-webrtc.ts +582 -0
- package/src/realtime/encode-realtime-frame.ts +33 -0
- package/src/realtime/index.ts +1 -0
- package/src/realtime/realtime-attempt.ts +45 -0
- package/src/realtime/realtime-command-tracker.ts +81 -0
- package/src/realtime/realtime-event-channel.ts +170 -0
- package/src/realtime/realtime-event-reducer.ts +3 -0
- package/src/realtime/realtime-session-state.ts +65 -0
- package/src/realtime/realtime-session.ts +768 -218
- package/src/realtime/realtime-types.ts +1 -1
- package/src/realtime/validate-realtime-setup.ts +37 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from '../util/zod';
|
|
2
|
+
import type { RealtimeSetupResponse } from './realtime-types';
|
|
3
|
+
|
|
4
|
+
const setupSchema = z.object({
|
|
5
|
+
token: z.string().refine(value => value.trim().length > 0),
|
|
6
|
+
url: z.string().refine(value => {
|
|
7
|
+
try {
|
|
8
|
+
const url = new URL(value);
|
|
9
|
+
return (
|
|
10
|
+
(url.protocol === 'ws:' || url.protocol === 'wss:') &&
|
|
11
|
+
url.hostname !== ''
|
|
12
|
+
);
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}),
|
|
17
|
+
expiresAt: z.number().positive().max(Number.MAX_SAFE_INTEGER).optional(),
|
|
18
|
+
tools: z
|
|
19
|
+
.array(
|
|
20
|
+
z.object({
|
|
21
|
+
type: z.literal('function'),
|
|
22
|
+
name: z.string().min(1),
|
|
23
|
+
description: z.string().optional(),
|
|
24
|
+
parameters: z.record(z.string(), z.unknown()),
|
|
25
|
+
}),
|
|
26
|
+
)
|
|
27
|
+
.optional(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export function validateRealtimeSetup(payload: unknown): RealtimeSetupResponse {
|
|
31
|
+
const result = setupSchema.safeParse(payload);
|
|
32
|
+
if (!result.success)
|
|
33
|
+
throw new Error(
|
|
34
|
+
'Invalid realtime setup: expected a nonempty token, a ws(s) URL, and valid optional expiresAt/tools',
|
|
35
|
+
);
|
|
36
|
+
return result.data;
|
|
37
|
+
}
|