@ai-sdk/provider 4.0.14 → 4.0.16
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 +21 -0
- package/dist/index.d.ts +220 -10
- package/dist/index.js +126 -100
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/errors/evaluation-unsupported-question-type-error.ts +44 -0
- package/src/errors/index.ts +1 -0
- package/src/evaluation-model/v4/evaluation-model-v4-call-options.ts +14 -0
- package/src/evaluation-model/v4/evaluation-model-v4-question.ts +32 -0
- package/src/evaluation-model/v4/evaluation-model-v4-result.ts +56 -0
- package/src/evaluation-model/v4/evaluation-model-v4.ts +16 -0
- package/src/evaluation-model/v4/index.ts +10 -0
- package/src/index.ts +1 -0
- package/src/json-value/json-value.ts +2 -2
- package/src/realtime-model/v4/realtime-model-v4-client-event.ts +27 -0
- package/src/realtime-model/v4/realtime-model-v4-server-event.ts +49 -1
- package/src/realtime-model/v4/realtime-model-v4.ts +38 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { JSONObject, JSONValue } from '../../json-value';
|
|
2
|
+
|
|
3
|
+
/** Shared state or structured instructions for an evaluation. */
|
|
4
|
+
export type EvaluationModelV4Input =
|
|
5
|
+
| string
|
|
6
|
+
| Readonly<JSONObject>
|
|
7
|
+
| readonly JSONValue[];
|
|
8
|
+
|
|
9
|
+
/** A judgment to make about the shared state. */
|
|
10
|
+
export type EvaluationModelV4Question =
|
|
11
|
+
| {
|
|
12
|
+
readonly type: 'choice';
|
|
13
|
+
readonly instructions: EvaluationModelV4Input;
|
|
14
|
+
/** Nonempty map of option names to descriptions. Null means no description. */
|
|
15
|
+
readonly criteria: Readonly<
|
|
16
|
+
Record<string, EvaluationModelV4Input | null>
|
|
17
|
+
>;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
readonly type: 'score';
|
|
21
|
+
readonly instructions: EvaluationModelV4Input;
|
|
22
|
+
/** At least two ordered levels, indexed from zero. */
|
|
23
|
+
readonly criteria: readonly (EvaluationModelV4Input | null)[];
|
|
24
|
+
}
|
|
25
|
+
| {
|
|
26
|
+
readonly type: 'boolean';
|
|
27
|
+
readonly instructions: EvaluationModelV4Input;
|
|
28
|
+
readonly criteria?: {
|
|
29
|
+
readonly true?: EvaluationModelV4Input | null;
|
|
30
|
+
readonly false?: EvaluationModelV4Input | null;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SharedV4Headers,
|
|
3
|
+
SharedV4ProviderMetadata,
|
|
4
|
+
SharedV4Warning,
|
|
5
|
+
} from '../../shared/v4';
|
|
6
|
+
|
|
7
|
+
export type EvaluationModelV4Answer =
|
|
8
|
+
| {
|
|
9
|
+
type: 'choice';
|
|
10
|
+
/** The selected option, with maximal probability when a distribution exists. */
|
|
11
|
+
choice: string;
|
|
12
|
+
/** Complete distribution over the question's options, when available. */
|
|
13
|
+
probabilities?: Record<string, number>;
|
|
14
|
+
}
|
|
15
|
+
| {
|
|
16
|
+
type: 'score';
|
|
17
|
+
/** Fractional position in [0, number of levels - 1]. */
|
|
18
|
+
score: number;
|
|
19
|
+
/**
|
|
20
|
+
* Complete distribution, keyed by zero-based level indices as strings.
|
|
21
|
+
* When supplied, score is its probability-weighted mean.
|
|
22
|
+
*/
|
|
23
|
+
probabilities?: Record<string, number>;
|
|
24
|
+
}
|
|
25
|
+
| {
|
|
26
|
+
type: 'boolean';
|
|
27
|
+
/** Model-estimated P(true), in [0, 1]. Not confidence in either outcome. */
|
|
28
|
+
probability: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type EvaluationModelV4Result = {
|
|
32
|
+
/** Exactly one answer per question, under the original question IDs. */
|
|
33
|
+
answers: Record<string, EvaluationModelV4Answer>;
|
|
34
|
+
/**
|
|
35
|
+
* Decimal places used when the provider rounds its output. Omit for full
|
|
36
|
+
* precision. Core allows half a unit in the last place per rounded value
|
|
37
|
+
* when checking distribution sums and weighted scores, preserving the values.
|
|
38
|
+
*/
|
|
39
|
+
rounding?: {
|
|
40
|
+
probabilityDecimals?: number;
|
|
41
|
+
scoreDecimals?: number;
|
|
42
|
+
};
|
|
43
|
+
usage?: {
|
|
44
|
+
inputTokens?: number;
|
|
45
|
+
outputTokens?: number;
|
|
46
|
+
};
|
|
47
|
+
warnings: SharedV4Warning[];
|
|
48
|
+
providerMetadata?: SharedV4ProviderMetadata;
|
|
49
|
+
response?: {
|
|
50
|
+
id?: string;
|
|
51
|
+
timestamp?: Date;
|
|
52
|
+
modelId?: string;
|
|
53
|
+
headers?: SharedV4Headers;
|
|
54
|
+
body?: unknown;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EvaluationModelV4CallOptions } from './evaluation-model-v4-call-options';
|
|
2
|
+
import type { EvaluationModelV4Question } from './evaluation-model-v4-question';
|
|
3
|
+
import type { EvaluationModelV4Result } from './evaluation-model-v4-result';
|
|
4
|
+
|
|
5
|
+
/** Experimental evaluation model contract. May change in patch releases. */
|
|
6
|
+
export type EvaluationModelV4 = {
|
|
7
|
+
readonly specificationVersion: 'v4';
|
|
8
|
+
readonly provider: string;
|
|
9
|
+
readonly modelId: string;
|
|
10
|
+
/** Supported question types, used to reject unsupported calls before any I/O. */
|
|
11
|
+
readonly supportedQuestionTypes: readonly EvaluationModelV4Question['type'][];
|
|
12
|
+
/** Evaluate every question against the same state. No partial results. */
|
|
13
|
+
doEvaluate(
|
|
14
|
+
options: EvaluationModelV4CallOptions,
|
|
15
|
+
): PromiseLike<EvaluationModelV4Result>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { EvaluationModelV4 as Experimental_EvaluationModelV4 } from './evaluation-model-v4';
|
|
2
|
+
export type { EvaluationModelV4CallOptions as Experimental_EvaluationModelV4CallOptions } from './evaluation-model-v4-call-options';
|
|
3
|
+
export type {
|
|
4
|
+
EvaluationModelV4Input as Experimental_EvaluationModelV4Input,
|
|
5
|
+
EvaluationModelV4Question as Experimental_EvaluationModelV4Question,
|
|
6
|
+
} from './evaluation-model-v4-question';
|
|
7
|
+
export type {
|
|
8
|
+
EvaluationModelV4Answer as Experimental_EvaluationModelV4Answer,
|
|
9
|
+
EvaluationModelV4Result as Experimental_EvaluationModelV4Result,
|
|
10
|
+
} from './evaluation-model-v4-result';
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './batch/index';
|
|
2
2
|
export * from './embedding-model/index';
|
|
3
3
|
export * from './errors/index';
|
|
4
|
+
export * from './evaluation-model/v4/index';
|
|
4
5
|
export * from './files/index';
|
|
5
6
|
export * from './image-model/index';
|
|
6
7
|
export * from './image-model-middleware/index';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SharedV4ProviderOptions } from '../../shared/v4/shared-v4-provider-options';
|
|
1
2
|
import type { RealtimeModelV4ConversationItem } from './realtime-model-v4-conversation-item';
|
|
2
3
|
import type { RealtimeModelV4SessionConfig } from './realtime-model-v4-session-config';
|
|
3
4
|
|
|
@@ -12,6 +13,31 @@ export type RealtimeModelV4ClientEvent =
|
|
|
12
13
|
| {
|
|
13
14
|
type: 'session-update';
|
|
14
15
|
config: RealtimeModelV4SessionConfig;
|
|
16
|
+
eventId?: string;
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
type: 'session-start';
|
|
20
|
+
config: RealtimeModelV4SessionConfig;
|
|
21
|
+
eventId?: string;
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
type: 'session-close';
|
|
25
|
+
eventId?: string;
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
type: 'input-audio-mute';
|
|
29
|
+
eventId?: string;
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
type: 'input-audio-unmute';
|
|
33
|
+
eventId?: string;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
type: 'context-append';
|
|
37
|
+
content: string;
|
|
38
|
+
delegationId: string | null;
|
|
39
|
+
eventId?: string;
|
|
40
|
+
providerOptions?: SharedV4ProviderOptions;
|
|
15
41
|
}
|
|
16
42
|
|
|
17
43
|
// ── Input audio buffer ─────────────────────────────────────────────
|
|
@@ -22,6 +48,7 @@ export type RealtimeModelV4ClientEvent =
|
|
|
22
48
|
* Base64-encoded audio chunk to append to the input buffer.
|
|
23
49
|
*/
|
|
24
50
|
audio: string;
|
|
51
|
+
eventId?: string;
|
|
25
52
|
}
|
|
26
53
|
| {
|
|
27
54
|
type: 'input-audio-commit';
|
|
@@ -6,8 +6,55 @@
|
|
|
6
6
|
* event data for debugging and provider-specific access.
|
|
7
7
|
*/
|
|
8
8
|
export type RealtimeModelV4ServerEvent =
|
|
9
|
+
| {
|
|
10
|
+
type: 'session-started';
|
|
11
|
+
sessionId: string;
|
|
12
|
+
delegationMode?: 'client' | 'provider';
|
|
13
|
+
raw: unknown;
|
|
14
|
+
}
|
|
15
|
+
| {
|
|
16
|
+
type: 'session-closed';
|
|
17
|
+
sessionId?: string;
|
|
18
|
+
usage: { seconds: number };
|
|
19
|
+
reason: string;
|
|
20
|
+
raw: unknown;
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
type: 'session-usage';
|
|
24
|
+
/** Cumulative duration snapshot, not an increment. */
|
|
25
|
+
usage: { seconds: number };
|
|
26
|
+
contextWindowUsageRatio?: number;
|
|
27
|
+
raw: unknown;
|
|
28
|
+
}
|
|
29
|
+
| {
|
|
30
|
+
type: 'audio-chunk';
|
|
31
|
+
delta: string;
|
|
32
|
+
raw: unknown;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
type: 'transcript-fragment';
|
|
36
|
+
speaker: 'user' | 'assistant';
|
|
37
|
+
delta: string;
|
|
38
|
+
startMs: number;
|
|
39
|
+
endMs: number;
|
|
40
|
+
raw: unknown;
|
|
41
|
+
}
|
|
42
|
+
| {
|
|
43
|
+
type: 'delegation-created';
|
|
44
|
+
delegationId: string;
|
|
45
|
+
target?: 'client' | 'provider';
|
|
46
|
+
offsetMs?: number;
|
|
47
|
+
responseId?: string;
|
|
48
|
+
raw: unknown;
|
|
49
|
+
}
|
|
50
|
+
| {
|
|
51
|
+
type: 'command-acknowledged';
|
|
52
|
+
/** Provider-native command name that was acknowledged. */
|
|
53
|
+
command: string;
|
|
54
|
+
clientEventId?: string;
|
|
55
|
+
raw: unknown;
|
|
56
|
+
}
|
|
9
57
|
// ── Session lifecycle ──────────────────────────────────────────────
|
|
10
|
-
|
|
11
58
|
| {
|
|
12
59
|
type: 'session-created';
|
|
13
60
|
sessionId?: string;
|
|
@@ -184,6 +231,7 @@ export type RealtimeModelV4ServerEvent =
|
|
|
184
231
|
type: 'error';
|
|
185
232
|
message: string;
|
|
186
233
|
code?: string;
|
|
234
|
+
clientEventId?: string;
|
|
187
235
|
raw: unknown;
|
|
188
236
|
}
|
|
189
237
|
|
|
@@ -29,6 +29,37 @@ export type RealtimeModelV4 = {
|
|
|
29
29
|
*/
|
|
30
30
|
readonly modelId: string;
|
|
31
31
|
|
|
32
|
+
/** Conversation semantics and supported transports, when declared. */
|
|
33
|
+
readonly capabilities?: {
|
|
34
|
+
conversation: 'continuous' | 'turn-based';
|
|
35
|
+
transports: readonly ('websocket' | 'webrtc')[];
|
|
36
|
+
/** Omission preserves the legacy client-secret WebSocket connection. */
|
|
37
|
+
connections?: readonly (
|
|
38
|
+
| 'client-secret-websocket'
|
|
39
|
+
| 'server-websocket'
|
|
40
|
+
| 'webrtc'
|
|
41
|
+
)[];
|
|
42
|
+
/** Omission preserves session-update startup. WebRTC setup may start the session. */
|
|
43
|
+
startup?: 'session-start' | 'session-update';
|
|
44
|
+
/** Omission preserves transport-close finalization. */
|
|
45
|
+
finalization?: 'session-close' | 'transport-close';
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Server-only connection settings. Headers can contain long-lived credentials. */
|
|
49
|
+
getServerWebSocketConfig?():
|
|
50
|
+
| { url: string; headers: Record<string, string> }
|
|
51
|
+
| PromiseLike<{ url: string; headers: Record<string, string> }>;
|
|
52
|
+
|
|
53
|
+
/** Provider-specific setup for the WebRTC event channel. */
|
|
54
|
+
getWebRTCConfig?(): { dataChannelLabel: string };
|
|
55
|
+
|
|
56
|
+
/** Server-side SDP exchange. Return only the answer and session ID to the client. */
|
|
57
|
+
doCreateWebRTCSession?(options: {
|
|
58
|
+
sdp: string;
|
|
59
|
+
sessionConfig?: RealtimeModelV4SessionConfig;
|
|
60
|
+
abortSignal?: AbortSignal;
|
|
61
|
+
}): PromiseLike<{ sessionId: string; sdp: string }>;
|
|
62
|
+
|
|
32
63
|
/**
|
|
33
64
|
* Server-side: Creates an ephemeral client secret for authenticating
|
|
34
65
|
* browser-side WebSocket connections. The secret is short-lived and
|
|
@@ -36,7 +67,7 @@ export type RealtimeModelV4 = {
|
|
|
36
67
|
*
|
|
37
68
|
* Naming: "do" prefix to prevent accidental direct usage by the user.
|
|
38
69
|
*/
|
|
39
|
-
doCreateClientSecret(
|
|
70
|
+
doCreateClientSecret?(
|
|
40
71
|
options: RealtimeModelV4ClientSecretOptions,
|
|
41
72
|
): PromiseLike<RealtimeModelV4ClientSecretResult>;
|
|
42
73
|
|
|
@@ -45,7 +76,7 @@ export type RealtimeModelV4 = {
|
|
|
45
76
|
* when connecting. Each provider has its own authentication mechanism
|
|
46
77
|
* (e.g. OpenAI uses subprotocol headers, xAI may use query params).
|
|
47
78
|
*/
|
|
48
|
-
getWebSocketConfig(options: { token: string; url: string }): {
|
|
79
|
+
getWebSocketConfig?(options: { token: string; url: string }): {
|
|
49
80
|
url: string;
|
|
50
81
|
protocols?: string[];
|
|
51
82
|
};
|
|
@@ -63,6 +94,11 @@ export type RealtimeModelV4 = {
|
|
|
63
94
|
raw: unknown,
|
|
64
95
|
): RealtimeModelV4ServerEvent | RealtimeModelV4ServerEvent[];
|
|
65
96
|
|
|
97
|
+
/** Create a raw-event parser per connection and discard it on disconnect. */
|
|
98
|
+
createServerEventParser?(): (
|
|
99
|
+
raw: unknown,
|
|
100
|
+
) => RealtimeModelV4ServerEvent | RealtimeModelV4ServerEvent[];
|
|
101
|
+
|
|
66
102
|
/**
|
|
67
103
|
* Browser-side: Serializes a normalized client event into the
|
|
68
104
|
* provider's native JSON format for sending over the WebSocket.
|