@ai-sdk/provider 4.0.0-beta.14 → 4.0.0-beta.19
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 +40 -0
- package/dist/index.d.ts +524 -31
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/language-model/v4/language-model-v4-prompt.ts +17 -38
- package/src/realtime-model/index.ts +1 -0
- package/src/realtime-model/v4/index.ts +20 -0
- package/src/realtime-model/v4/realtime-factory-v4.ts +20 -0
- package/src/realtime-model/v4/realtime-model-v4-client-event.ts +68 -0
- package/src/realtime-model/v4/realtime-model-v4-client-secret.ts +40 -0
- package/src/realtime-model/v4/realtime-model-v4-conversation-item.ts +55 -0
- package/src/realtime-model/v4/realtime-model-v4-server-event.ts +199 -0
- package/src/realtime-model/v4/realtime-model-v4-session-config.ts +142 -0
- package/src/realtime-model/v4/realtime-model-v4-tool-definition.ts +28 -0
- package/src/realtime-model/v4/realtime-model-v4.ts +89 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RealtimeModelV4ClientSecretOptions,
|
|
3
|
+
RealtimeModelV4ClientSecretResult,
|
|
4
|
+
} from './realtime-model-v4-client-secret';
|
|
5
|
+
import type { RealtimeModelV4ClientEvent } from './realtime-model-v4-client-event';
|
|
6
|
+
import type { RealtimeModelV4ServerEvent } from './realtime-model-v4-server-event';
|
|
7
|
+
import type { RealtimeModelV4SessionConfig } from './realtime-model-v4-session-config';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Specification for a realtime model that supports bidirectional
|
|
11
|
+
* audio/text communication over WebSocket.
|
|
12
|
+
*
|
|
13
|
+
* Providers implement this interface to enable realtime voice
|
|
14
|
+
* conversations through the AI SDK.
|
|
15
|
+
*/
|
|
16
|
+
export type RealtimeModelV4 = {
|
|
17
|
+
/**
|
|
18
|
+
* The realtime model must specify which interface version it implements.
|
|
19
|
+
*/
|
|
20
|
+
readonly specificationVersion: 'v4';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Provider ID (e.g. 'openai', 'xai').
|
|
24
|
+
*/
|
|
25
|
+
readonly provider: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Provider-specific model ID (e.g. 'gpt-4o-realtime', 'grok-3').
|
|
29
|
+
*/
|
|
30
|
+
readonly modelId: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Server-side: Creates an ephemeral client secret for authenticating
|
|
34
|
+
* browser-side WebSocket connections. The secret is short-lived and
|
|
35
|
+
* safe to expose to client code.
|
|
36
|
+
*
|
|
37
|
+
* Naming: "do" prefix to prevent accidental direct usage by the user.
|
|
38
|
+
*/
|
|
39
|
+
doCreateClientSecret(
|
|
40
|
+
options: RealtimeModelV4ClientSecretOptions,
|
|
41
|
+
): PromiseLike<RealtimeModelV4ClientSecretResult>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Browser-side: Returns the WebSocket URL and subprotocols to use
|
|
45
|
+
* when connecting. Each provider has its own authentication mechanism
|
|
46
|
+
* (e.g. OpenAI uses subprotocol headers, xAI may use query params).
|
|
47
|
+
*/
|
|
48
|
+
getWebSocketConfig(options: { token: string; url: string }): {
|
|
49
|
+
url: string;
|
|
50
|
+
protocols?: string[];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Browser-side: Parses a raw JSON event received over the WebSocket
|
|
55
|
+
* and returns one or more normalized events. Providers map their native
|
|
56
|
+
* event format to the common RealtimeModelV4ServerEvent union.
|
|
57
|
+
*
|
|
58
|
+
* Returns an array when a single provider message maps to multiple
|
|
59
|
+
* normalized events (e.g. Google's serverContent can contain audio,
|
|
60
|
+
* text, and turn-complete data in one message).
|
|
61
|
+
*/
|
|
62
|
+
parseServerEvent(
|
|
63
|
+
raw: unknown,
|
|
64
|
+
): RealtimeModelV4ServerEvent | RealtimeModelV4ServerEvent[];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Browser-side: Serializes a normalized client event into the
|
|
68
|
+
* provider's native JSON format for sending over the WebSocket.
|
|
69
|
+
*/
|
|
70
|
+
serializeClientEvent(
|
|
71
|
+
event: RealtimeModelV4ClientEvent,
|
|
72
|
+
): unknown | PromiseLike<unknown>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Browser-side: Builds the provider-specific session configuration
|
|
76
|
+
* payload from a normalized session config. Used to construct the
|
|
77
|
+
* session.update event sent after WebSocket connection.
|
|
78
|
+
*/
|
|
79
|
+
buildSessionConfig(config: RealtimeModelV4SessionConfig): unknown;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Browser-side: Returns a message to auto-send back over the WebSocket
|
|
83
|
+
* in response to a raw incoming message, or null if no response is needed.
|
|
84
|
+
*
|
|
85
|
+
* Used for provider-specific keepalive protocols (e.g. ping/pong).
|
|
86
|
+
* Called by the session layer before parseServerEvent.
|
|
87
|
+
*/
|
|
88
|
+
getHealthCheckResponse?(raw: unknown): unknown | null;
|
|
89
|
+
};
|