@mistralai/mistralai 3.3.0 → 3.4.0
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/esm/extra/realtime/connection.d.ts +16 -3
- package/esm/extra/realtime/connection.d.ts.map +1 -1
- package/esm/extra/realtime/connection.js +35 -9
- package/esm/extra/realtime/connection.js.map +1 -1
- package/esm/extra/realtime/errors.d.ts +18 -0
- package/esm/extra/realtime/errors.d.ts.map +1 -1
- package/esm/extra/realtime/errors.js +19 -0
- package/esm/extra/realtime/errors.js.map +1 -1
- package/esm/extra/realtime/index.d.ts +20 -1
- package/esm/extra/realtime/index.d.ts.map +1 -1
- package/esm/extra/realtime/index.js +5 -0
- package/esm/extra/realtime/index.js.map +1 -1
- package/esm/extra/realtime/speech.d.ts +64 -0
- package/esm/extra/realtime/speech.d.ts.map +1 -0
- package/esm/extra/realtime/speech.js +461 -0
- package/esm/extra/realtime/speech.js.map +1 -0
- package/esm/extra/realtime/transcription.d.ts +2 -2
- package/esm/extra/realtime/transcription.d.ts.map +1 -1
- package/esm/extra/realtime/transcription.js +11 -2
- package/esm/extra/realtime/transcription.js.map +1 -1
- package/esm/extra/workflows/encoding/payload-encoder.d.ts.map +1 -1
- package/esm/extra/workflows/encoding/payload-encoder.js +2 -2
- package/esm/extra/workflows/encoding/payload-encoder.js.map +1 -1
- package/esm/extra/workflows/encoding/python-json.d.ts +3 -2
- package/esm/extra/workflows/encoding/python-json.d.ts.map +1 -1
- package/esm/extra/workflows/encoding/python-json.js +24 -9
- package/esm/extra/workflows/encoding/python-json.js.map +1 -1
- package/esm/funcs/betaRagManagedIndexesCreate.js +1 -1
- package/esm/funcs/betaRagManagedIndexesCreate.js.map +1 -1
- package/esm/lib/config.d.ts +2 -2
- package/esm/lib/config.js +2 -2
- package/esm/models/components/connectionpreference.d.ts +12 -2
- package/esm/models/components/connectionpreference.d.ts.map +1 -1
- package/esm/models/components/connectionpreference.js +3 -3
- package/esm/models/components/connectionpreference.js.map +1 -1
- package/esm/models/components/index.d.ts +11 -5
- package/esm/models/components/index.d.ts.map +1 -1
- package/esm/models/components/index.js +11 -5
- package/esm/models/components/index.js.map +1 -1
- package/esm/models/components/observabilityerrorcode.d.ts +1 -0
- package/esm/models/components/observabilityerrorcode.d.ts.map +1 -1
- package/esm/models/components/observabilityerrorcode.js +1 -0
- package/esm/models/components/observabilityerrorcode.js.map +1 -1
- package/esm/models/components/realtimespeecherror.d.ts +20 -0
- package/esm/models/components/realtimespeecherror.d.ts.map +1 -0
- package/esm/models/components/realtimespeecherror.js +23 -0
- package/esm/models/components/realtimespeecherror.js.map +1 -0
- package/esm/models/components/realtimespeecherrordetail.d.ts +45 -0
- package/esm/models/components/realtimespeecherrordetail.d.ts.map +1 -0
- package/esm/models/components/realtimespeecherrordetail.js +33 -0
- package/esm/models/components/realtimespeecherrordetail.js.map +1 -0
- package/esm/models/components/realtimespeechinputtextappend.d.ts +19 -0
- package/esm/models/components/realtimespeechinputtextappend.d.ts.map +1 -0
- package/esm/models/components/realtimespeechinputtextappend.js +22 -0
- package/esm/models/components/realtimespeechinputtextappend.js.map +1 -0
- package/esm/models/components/realtimespeechinputtextend.d.ts +17 -0
- package/esm/models/components/realtimespeechinputtextend.d.ts.map +1 -0
- package/esm/models/components/realtimespeechinputtextend.js +20 -0
- package/esm/models/components/realtimespeechinputtextend.js.map +1 -0
- package/esm/models/components/realtimespeechinputtextflush.d.ts +19 -0
- package/esm/models/components/realtimespeechinputtextflush.d.ts.map +1 -0
- package/esm/models/components/realtimespeechinputtextflush.js +22 -0
- package/esm/models/components/realtimespeechinputtextflush.js.map +1 -0
- package/esm/models/components/realtimespeechsession.d.ts +31 -0
- package/esm/models/components/realtimespeechsession.d.ts.map +1 -0
- package/esm/models/components/realtimespeechsession.js +49 -0
- package/esm/models/components/realtimespeechsession.js.map +1 -0
- package/esm/models/components/realtimespeechsessioncreated.d.ts +20 -0
- package/esm/models/components/realtimespeechsessioncreated.d.ts.map +1 -0
- package/esm/models/components/realtimespeechsessioncreated.js +23 -0
- package/esm/models/components/realtimespeechsessioncreated.js.map +1 -0
- package/esm/models/components/realtimespeechsessionupdated.d.ts +20 -0
- package/esm/models/components/realtimespeechsessionupdated.d.ts.map +1 -0
- package/esm/models/components/realtimespeechsessionupdated.js +23 -0
- package/esm/models/components/realtimespeechsessionupdated.js.map +1 -0
- package/esm/models/components/realtimespeechsessionupdatemessage.d.ts +20 -0
- package/esm/models/components/realtimespeechsessionupdatemessage.d.ts.map +1 -0
- package/esm/models/components/realtimespeechsessionupdatemessage.js +23 -0
- package/esm/models/components/realtimespeechsessionupdatemessage.js.map +1 -0
- package/esm/models/components/realtimespeechsessionupdatepayload.d.ts +42 -0
- package/esm/models/components/realtimespeechsessionupdatepayload.d.ts.map +1 -0
- package/esm/models/components/realtimespeechsessionupdatepayload.js +45 -0
- package/esm/models/components/realtimespeechsessionupdatepayload.js.map +1 -0
- package/esm/models/components/realtimespeechstreamingmode.d.ts +12 -0
- package/esm/models/components/realtimespeechstreamingmode.d.ts.map +1 -0
- package/esm/models/components/realtimespeechstreamingmode.js +13 -0
- package/esm/models/components/realtimespeechstreamingmode.js.map +1 -0
- package/esm/models/components/speechoutputformat.d.ts +2 -0
- package/esm/models/components/speechoutputformat.d.ts.map +1 -1
- package/esm/models/components/speechoutputformat.js +3 -1
- package/esm/models/components/speechoutputformat.js.map +1 -1
- package/esm/models/components/speechstreamaudiodelta.d.ts +8 -0
- package/esm/models/components/speechstreamaudiodelta.d.ts.map +1 -1
- package/esm/models/components/speechstreamaudiodelta.js +12 -0
- package/esm/models/components/speechstreamaudiodelta.js.map +1 -1
- package/esm/models/components/speechstreamdone.d.ts +10 -2
- package/esm/models/components/speechstreamdone.d.ts.map +1 -1
- package/esm/models/components/speechstreamdone.js +10 -2
- package/esm/models/components/speechstreamdone.js.map +1 -1
- package/jsr.json +1 -1
- package/package.json +12 -12
- package/src/extra/realtime/connection.ts +88 -13
- package/src/extra/realtime/errors.ts +32 -0
- package/src/extra/realtime/index.ts +42 -1
- package/src/extra/realtime/speech.ts +646 -0
- package/src/extra/realtime/transcription.ts +22 -9
- package/src/extra/workflows/encoding/payload-encoder.ts +2 -1
- package/src/extra/workflows/encoding/python-json.ts +34 -8
- package/src/funcs/betaRagManagedIndexesCreate.ts +1 -1
- package/src/lib/config.ts +2 -2
- package/src/models/components/connectionpreference.ts +15 -5
- package/src/models/components/index.ts +11 -5
- package/src/models/components/observabilityerrorcode.ts +2 -0
- package/src/models/components/realtimespeecherror.ts +59 -0
- package/src/models/components/realtimespeecherrordetail.ts +100 -0
- package/src/models/components/realtimespeechinputtextappend.ts +55 -0
- package/src/models/components/realtimespeechinputtextend.ts +49 -0
- package/src/models/components/realtimespeechinputtextflush.ts +55 -0
- package/src/models/components/realtimespeechsession.ts +98 -0
- package/src/models/components/realtimespeechsessioncreated.ts +61 -0
- package/src/models/components/realtimespeechsessionupdated.ts +61 -0
- package/src/models/components/realtimespeechsessionupdatemessage.ts +62 -0
- package/src/models/components/realtimespeechsessionupdatepayload.ts +108 -0
- package/src/models/components/realtimespeechstreamingmode.ts +23 -0
- package/src/models/components/speechoutputformat.ts +5 -1
- package/src/models/components/speechstreamaudiodelta.ts +25 -0
- package/src/models/components/speechstreamdone.ts +28 -5
- package/tests/extra/realtime-speech-ws.test.ts +193 -0
- package/tests/extra/realtime-speech.test.ts +532 -0
- package/tests/extra/realtime.test.ts +217 -0
- package/tests/extra/workflow-encryption.test.ts +2 -2
- package/tests/hooks/workflow-encoding.test.ts +1 -1
- package/esm/models/components/completiontokensdetails.d.ts +0 -19
- package/esm/models/components/completiontokensdetails.d.ts.map +0 -1
- package/esm/models/components/completiontokensdetails.js +0 -18
- package/esm/models/components/completiontokensdetails.js.map +0 -1
- package/esm/models/components/messagetokens.d.ts +0 -18
- package/esm/models/components/messagetokens.d.ts.map +0 -1
- package/esm/models/components/messagetokens.js +0 -26
- package/esm/models/components/messagetokens.js.map +0 -1
- package/esm/models/components/prompttokensdetails.d.ts +0 -16
- package/esm/models/components/prompttokensdetails.d.ts.map +0 -1
- package/esm/models/components/prompttokensdetails.js +0 -22
- package/esm/models/components/prompttokensdetails.js.map +0 -1
- package/esm/models/components/roles.d.ts +0 -12
- package/esm/models/components/roles.d.ts.map +0 -1
- package/esm/models/components/roles.js +0 -14
- package/esm/models/components/roles.js.map +0 -1
- package/esm/models/components/usageinfodollardefs.d.ts +0 -24
- package/esm/models/components/usageinfodollardefs.d.ts.map +0 -1
- package/esm/models/components/usageinfodollardefs.js +0 -41
- package/esm/models/components/usageinfodollardefs.js.map +0 -1
- package/src/models/components/completiontokensdetails.ts +0 -44
- package/src/models/components/messagetokens.ts +0 -47
- package/src/models/components/prompttokensdetails.ts +0 -44
- package/src/models/components/roles.ts +0 -19
- package/src/models/components/usageinfodollardefs.ts +0 -76
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4";
|
|
6
|
+
import { safeParse } from "../../lib/schemas.js";
|
|
7
|
+
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
8
|
+
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
9
|
+
import {
|
|
10
|
+
RealtimeSpeechSession,
|
|
11
|
+
RealtimeSpeechSession$inboundSchema,
|
|
12
|
+
RealtimeSpeechSession$Outbound,
|
|
13
|
+
RealtimeSpeechSession$outboundSchema,
|
|
14
|
+
} from "./realtimespeechsession.js";
|
|
15
|
+
|
|
16
|
+
export type RealtimeSpeechSessionUpdated = {
|
|
17
|
+
type?: "session.updated" | undefined;
|
|
18
|
+
session: RealtimeSpeechSession;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
export const RealtimeSpeechSessionUpdated$inboundSchema: z.ZodType<
|
|
23
|
+
RealtimeSpeechSessionUpdated,
|
|
24
|
+
unknown
|
|
25
|
+
> = z.object({
|
|
26
|
+
type: z.literal("session.updated").default("session.updated"),
|
|
27
|
+
session: RealtimeSpeechSession$inboundSchema,
|
|
28
|
+
});
|
|
29
|
+
/** @internal */
|
|
30
|
+
export type RealtimeSpeechSessionUpdated$Outbound = {
|
|
31
|
+
type: "session.updated";
|
|
32
|
+
session: RealtimeSpeechSession$Outbound;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** @internal */
|
|
36
|
+
export const RealtimeSpeechSessionUpdated$outboundSchema: z.ZodType<
|
|
37
|
+
RealtimeSpeechSessionUpdated$Outbound,
|
|
38
|
+
RealtimeSpeechSessionUpdated
|
|
39
|
+
> = z.object({
|
|
40
|
+
type: z.literal("session.updated").default("session.updated" as const),
|
|
41
|
+
session: RealtimeSpeechSession$outboundSchema,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export function realtimeSpeechSessionUpdatedToJSON(
|
|
45
|
+
realtimeSpeechSessionUpdated: RealtimeSpeechSessionUpdated,
|
|
46
|
+
): string {
|
|
47
|
+
return JSON.stringify(
|
|
48
|
+
RealtimeSpeechSessionUpdated$outboundSchema.parse(
|
|
49
|
+
realtimeSpeechSessionUpdated,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
export function realtimeSpeechSessionUpdatedFromJSON(
|
|
54
|
+
jsonString: string,
|
|
55
|
+
): SafeParseResult<RealtimeSpeechSessionUpdated, SDKValidationError> {
|
|
56
|
+
return safeParse(
|
|
57
|
+
jsonString,
|
|
58
|
+
(x) => RealtimeSpeechSessionUpdated$inboundSchema.parse(JSON.parse(x)),
|
|
59
|
+
`Failed to parse 'RealtimeSpeechSessionUpdated' from JSON`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4";
|
|
6
|
+
import { safeParse } from "../../lib/schemas.js";
|
|
7
|
+
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
8
|
+
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
9
|
+
import {
|
|
10
|
+
RealtimeSpeechSessionUpdatePayload,
|
|
11
|
+
RealtimeSpeechSessionUpdatePayload$inboundSchema,
|
|
12
|
+
RealtimeSpeechSessionUpdatePayload$Outbound,
|
|
13
|
+
RealtimeSpeechSessionUpdatePayload$outboundSchema,
|
|
14
|
+
} from "./realtimespeechsessionupdatepayload.js";
|
|
15
|
+
|
|
16
|
+
export type RealtimeSpeechSessionUpdateMessage = {
|
|
17
|
+
type?: "session.update" | undefined;
|
|
18
|
+
session: RealtimeSpeechSessionUpdatePayload;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
export const RealtimeSpeechSessionUpdateMessage$inboundSchema: z.ZodType<
|
|
23
|
+
RealtimeSpeechSessionUpdateMessage,
|
|
24
|
+
unknown
|
|
25
|
+
> = z.object({
|
|
26
|
+
type: z.literal("session.update").default("session.update"),
|
|
27
|
+
session: RealtimeSpeechSessionUpdatePayload$inboundSchema,
|
|
28
|
+
});
|
|
29
|
+
/** @internal */
|
|
30
|
+
export type RealtimeSpeechSessionUpdateMessage$Outbound = {
|
|
31
|
+
type: "session.update";
|
|
32
|
+
session: RealtimeSpeechSessionUpdatePayload$Outbound;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** @internal */
|
|
36
|
+
export const RealtimeSpeechSessionUpdateMessage$outboundSchema: z.ZodType<
|
|
37
|
+
RealtimeSpeechSessionUpdateMessage$Outbound,
|
|
38
|
+
RealtimeSpeechSessionUpdateMessage
|
|
39
|
+
> = z.object({
|
|
40
|
+
type: z.literal("session.update").default("session.update" as const),
|
|
41
|
+
session: RealtimeSpeechSessionUpdatePayload$outboundSchema,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export function realtimeSpeechSessionUpdateMessageToJSON(
|
|
45
|
+
realtimeSpeechSessionUpdateMessage: RealtimeSpeechSessionUpdateMessage,
|
|
46
|
+
): string {
|
|
47
|
+
return JSON.stringify(
|
|
48
|
+
RealtimeSpeechSessionUpdateMessage$outboundSchema.parse(
|
|
49
|
+
realtimeSpeechSessionUpdateMessage,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
export function realtimeSpeechSessionUpdateMessageFromJSON(
|
|
54
|
+
jsonString: string,
|
|
55
|
+
): SafeParseResult<RealtimeSpeechSessionUpdateMessage, SDKValidationError> {
|
|
56
|
+
return safeParse(
|
|
57
|
+
jsonString,
|
|
58
|
+
(x) =>
|
|
59
|
+
RealtimeSpeechSessionUpdateMessage$inboundSchema.parse(JSON.parse(x)),
|
|
60
|
+
`Failed to parse 'RealtimeSpeechSessionUpdateMessage' from JSON`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4";
|
|
6
|
+
import { remap as remap$ } from "../../lib/primitives.js";
|
|
7
|
+
import { safeParse } from "../../lib/schemas.js";
|
|
8
|
+
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
9
|
+
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
10
|
+
import {
|
|
11
|
+
RealtimeSpeechStreamingMode,
|
|
12
|
+
RealtimeSpeechStreamingMode$inboundSchema,
|
|
13
|
+
RealtimeSpeechStreamingMode$outboundSchema,
|
|
14
|
+
} from "./realtimespeechstreamingmode.js";
|
|
15
|
+
import {
|
|
16
|
+
SpeechOutputFormat,
|
|
17
|
+
SpeechOutputFormat$inboundSchema,
|
|
18
|
+
SpeechOutputFormat$outboundSchema,
|
|
19
|
+
} from "./speechoutputformat.js";
|
|
20
|
+
|
|
21
|
+
export type RealtimeSpeechSessionUpdatePayload = {
|
|
22
|
+
/**
|
|
23
|
+
* Preset voice identifier. Mutually exclusive with ref_audio and voice_profile.
|
|
24
|
+
*/
|
|
25
|
+
voice?: string | null | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Base64-encoded reference audio. Mutually exclusive with voice and voice_profile.
|
|
28
|
+
*/
|
|
29
|
+
refAudio?: string | null | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* responsive (default): short chunks, for conversational turns. long_form: chunks grow as the text goes on, for smoother delivery of long texts.
|
|
32
|
+
*/
|
|
33
|
+
streamingMode?: RealtimeSpeechStreamingMode | null | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Audio encoding of speech.audio.delta events. pcm is raw 32-bit float little-endian mono.
|
|
36
|
+
*/
|
|
37
|
+
responseFormat?: SpeechOutputFormat | null | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Higher values make the delivery more expressive. Minimum 1.0.
|
|
40
|
+
*/
|
|
41
|
+
expressiveness?: number | null | undefined;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** @internal */
|
|
45
|
+
export const RealtimeSpeechSessionUpdatePayload$inboundSchema: z.ZodType<
|
|
46
|
+
RealtimeSpeechSessionUpdatePayload,
|
|
47
|
+
unknown
|
|
48
|
+
> = z.object({
|
|
49
|
+
voice: z.nullable(z.string()).optional(),
|
|
50
|
+
ref_audio: z.nullable(z.string()).optional(),
|
|
51
|
+
streaming_mode: z.nullable(RealtimeSpeechStreamingMode$inboundSchema)
|
|
52
|
+
.optional(),
|
|
53
|
+
response_format: z.nullable(SpeechOutputFormat$inboundSchema).optional(),
|
|
54
|
+
expressiveness: z.nullable(z.number()).optional(),
|
|
55
|
+
}).transform((v) => {
|
|
56
|
+
return remap$(v, {
|
|
57
|
+
"ref_audio": "refAudio",
|
|
58
|
+
"streaming_mode": "streamingMode",
|
|
59
|
+
"response_format": "responseFormat",
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
/** @internal */
|
|
63
|
+
export type RealtimeSpeechSessionUpdatePayload$Outbound = {
|
|
64
|
+
voice?: string | null | undefined;
|
|
65
|
+
ref_audio?: string | null | undefined;
|
|
66
|
+
streaming_mode?: string | null | undefined;
|
|
67
|
+
response_format?: string | null | undefined;
|
|
68
|
+
expressiveness?: number | null | undefined;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** @internal */
|
|
72
|
+
export const RealtimeSpeechSessionUpdatePayload$outboundSchema: z.ZodType<
|
|
73
|
+
RealtimeSpeechSessionUpdatePayload$Outbound,
|
|
74
|
+
RealtimeSpeechSessionUpdatePayload
|
|
75
|
+
> = z.object({
|
|
76
|
+
voice: z.nullable(z.string()).optional(),
|
|
77
|
+
refAudio: z.nullable(z.string()).optional(),
|
|
78
|
+
streamingMode: z.nullable(RealtimeSpeechStreamingMode$outboundSchema)
|
|
79
|
+
.optional(),
|
|
80
|
+
responseFormat: z.nullable(SpeechOutputFormat$outboundSchema).optional(),
|
|
81
|
+
expressiveness: z.nullable(z.number()).optional(),
|
|
82
|
+
}).transform((v) => {
|
|
83
|
+
return remap$(v, {
|
|
84
|
+
refAudio: "ref_audio",
|
|
85
|
+
streamingMode: "streaming_mode",
|
|
86
|
+
responseFormat: "response_format",
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export function realtimeSpeechSessionUpdatePayloadToJSON(
|
|
91
|
+
realtimeSpeechSessionUpdatePayload: RealtimeSpeechSessionUpdatePayload,
|
|
92
|
+
): string {
|
|
93
|
+
return JSON.stringify(
|
|
94
|
+
RealtimeSpeechSessionUpdatePayload$outboundSchema.parse(
|
|
95
|
+
realtimeSpeechSessionUpdatePayload,
|
|
96
|
+
),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
export function realtimeSpeechSessionUpdatePayloadFromJSON(
|
|
100
|
+
jsonString: string,
|
|
101
|
+
): SafeParseResult<RealtimeSpeechSessionUpdatePayload, SDKValidationError> {
|
|
102
|
+
return safeParse(
|
|
103
|
+
jsonString,
|
|
104
|
+
(x) =>
|
|
105
|
+
RealtimeSpeechSessionUpdatePayload$inboundSchema.parse(JSON.parse(x)),
|
|
106
|
+
`Failed to parse 'RealtimeSpeechSessionUpdatePayload' from JSON`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4";
|
|
6
|
+
import { ClosedEnum } from "../../types/enums.js";
|
|
7
|
+
|
|
8
|
+
export const RealtimeSpeechStreamingMode = {
|
|
9
|
+
Responsive: "responsive",
|
|
10
|
+
LongForm: "long_form",
|
|
11
|
+
} as const;
|
|
12
|
+
export type RealtimeSpeechStreamingMode = ClosedEnum<
|
|
13
|
+
typeof RealtimeSpeechStreamingMode
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/** @internal */
|
|
17
|
+
export const RealtimeSpeechStreamingMode$inboundSchema: z.ZodEnum<
|
|
18
|
+
typeof RealtimeSpeechStreamingMode
|
|
19
|
+
> = z.enum(RealtimeSpeechStreamingMode);
|
|
20
|
+
/** @internal */
|
|
21
|
+
export const RealtimeSpeechStreamingMode$outboundSchema: z.ZodEnum<
|
|
22
|
+
typeof RealtimeSpeechStreamingMode
|
|
23
|
+
> = RealtimeSpeechStreamingMode$inboundSchema;
|
|
@@ -15,6 +15,10 @@ export const SpeechOutputFormat = {
|
|
|
15
15
|
export type SpeechOutputFormat = ClosedEnum<typeof SpeechOutputFormat>;
|
|
16
16
|
|
|
17
17
|
/** @internal */
|
|
18
|
-
export const SpeechOutputFormat$
|
|
18
|
+
export const SpeechOutputFormat$inboundSchema: z.ZodEnum<
|
|
19
19
|
typeof SpeechOutputFormat
|
|
20
20
|
> = z.enum(SpeechOutputFormat);
|
|
21
|
+
/** @internal */
|
|
22
|
+
export const SpeechOutputFormat$outboundSchema: z.ZodEnum<
|
|
23
|
+
typeof SpeechOutputFormat
|
|
24
|
+
> = SpeechOutputFormat$inboundSchema;
|
|
@@ -25,7 +25,32 @@ export const SpeechStreamAudioDelta$inboundSchema: z.ZodType<
|
|
|
25
25
|
"audio_data": "audioData",
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
+
/** @internal */
|
|
29
|
+
export type SpeechStreamAudioDelta$Outbound = {
|
|
30
|
+
type: "speech.audio.delta";
|
|
31
|
+
audio_data: string;
|
|
32
|
+
};
|
|
28
33
|
|
|
34
|
+
/** @internal */
|
|
35
|
+
export const SpeechStreamAudioDelta$outboundSchema: z.ZodType<
|
|
36
|
+
SpeechStreamAudioDelta$Outbound,
|
|
37
|
+
SpeechStreamAudioDelta
|
|
38
|
+
> = z.object({
|
|
39
|
+
type: z.literal("speech.audio.delta"),
|
|
40
|
+
audioData: z.string(),
|
|
41
|
+
}).transform((v) => {
|
|
42
|
+
return remap$(v, {
|
|
43
|
+
audioData: "audio_data",
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export function speechStreamAudioDeltaToJSON(
|
|
48
|
+
speechStreamAudioDelta: SpeechStreamAudioDelta,
|
|
49
|
+
): string {
|
|
50
|
+
return JSON.stringify(
|
|
51
|
+
SpeechStreamAudioDelta$outboundSchema.parse(speechStreamAudioDelta),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
29
54
|
export function speechStreamAudioDeltaFromJSON(
|
|
30
55
|
jsonString: string,
|
|
31
56
|
): SafeParseResult<SpeechStreamAudioDelta, SDKValidationError> {
|
|
@@ -7,13 +7,15 @@ import { safeParse } from "../../lib/schemas.js";
|
|
|
7
7
|
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
8
8
|
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
UsageInfo,
|
|
11
|
+
UsageInfo$inboundSchema,
|
|
12
|
+
UsageInfo$Outbound,
|
|
13
|
+
UsageInfo$outboundSchema,
|
|
14
|
+
} from "./usageinfo.js";
|
|
13
15
|
|
|
14
16
|
export type SpeechStreamDone = {
|
|
15
17
|
type: "speech.audio.done";
|
|
16
|
-
usage:
|
|
18
|
+
usage: UsageInfo;
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
/** @internal */
|
|
@@ -22,9 +24,30 @@ export const SpeechStreamDone$inboundSchema: z.ZodType<
|
|
|
22
24
|
unknown
|
|
23
25
|
> = z.object({
|
|
24
26
|
type: z.literal("speech.audio.done"),
|
|
25
|
-
usage:
|
|
27
|
+
usage: UsageInfo$inboundSchema,
|
|
28
|
+
});
|
|
29
|
+
/** @internal */
|
|
30
|
+
export type SpeechStreamDone$Outbound = {
|
|
31
|
+
type: "speech.audio.done";
|
|
32
|
+
usage: UsageInfo$Outbound;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** @internal */
|
|
36
|
+
export const SpeechStreamDone$outboundSchema: z.ZodType<
|
|
37
|
+
SpeechStreamDone$Outbound,
|
|
38
|
+
SpeechStreamDone
|
|
39
|
+
> = z.object({
|
|
40
|
+
type: z.literal("speech.audio.done"),
|
|
41
|
+
usage: UsageInfo$outboundSchema,
|
|
26
42
|
});
|
|
27
43
|
|
|
44
|
+
export function speechStreamDoneToJSON(
|
|
45
|
+
speechStreamDone: SpeechStreamDone,
|
|
46
|
+
): string {
|
|
47
|
+
return JSON.stringify(
|
|
48
|
+
SpeechStreamDone$outboundSchema.parse(speechStreamDone),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
28
51
|
export function speechStreamDoneFromJSON(
|
|
29
52
|
jsonString: string,
|
|
30
53
|
): SafeParseResult<SpeechStreamDone, SDKValidationError> {
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { createServer, type Server } from "node:http";
|
|
2
|
+
import type { AddressInfo } from "node:net";
|
|
3
|
+
import { WebSocketServer, type WebSocket as ServerSocket } from "ws";
|
|
4
|
+
import {
|
|
5
|
+
RealtimeSpeech,
|
|
6
|
+
RealtimeSpeechException,
|
|
7
|
+
} from "../../src/extra/realtime/index.js";
|
|
8
|
+
|
|
9
|
+
// Uses a real ws server: the mock delivers events synchronously and hides ordering bugs.
|
|
10
|
+
|
|
11
|
+
const SESSION = {
|
|
12
|
+
request_id: "ws-1",
|
|
13
|
+
model: "m",
|
|
14
|
+
voice: "v",
|
|
15
|
+
is_ref_audio: false,
|
|
16
|
+
streaming_mode: "responsive",
|
|
17
|
+
response_format: "wav",
|
|
18
|
+
expressiveness: 2,
|
|
19
|
+
};
|
|
20
|
+
const DELTA = { type: "speech.audio.delta", audio_data: "AAAAAA==" };
|
|
21
|
+
const DONE = {
|
|
22
|
+
type: "speech.audio.done",
|
|
23
|
+
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type Message = { type: string; [key: string]: unknown };
|
|
27
|
+
|
|
28
|
+
let server: WebSocketServer;
|
|
29
|
+
let port: number;
|
|
30
|
+
let onOpen: (socket: ServerSocket) => void;
|
|
31
|
+
let onMessage: (socket: ServerSocket, message: Message) => void;
|
|
32
|
+
let received: string[];
|
|
33
|
+
let uncaught: unknown[];
|
|
34
|
+
const recordUncaught = (err: unknown) => uncaught.push(err);
|
|
35
|
+
|
|
36
|
+
beforeEach(async () => {
|
|
37
|
+
received = [];
|
|
38
|
+
uncaught = [];
|
|
39
|
+
process.on("uncaughtException", recordUncaught);
|
|
40
|
+
onOpen = (socket) => socket.send(JSON.stringify({ type: "session.created", session: SESSION }));
|
|
41
|
+
onMessage = (socket, message) => {
|
|
42
|
+
if (message.type === "input_text.end") {
|
|
43
|
+
socket.send(JSON.stringify(DELTA));
|
|
44
|
+
socket.send(JSON.stringify(DONE));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
server = new WebSocketServer({ port: 0 });
|
|
48
|
+
await new Promise<void>((resolve) => server.once("listening", () => resolve()));
|
|
49
|
+
port = (server.address() as AddressInfo).port;
|
|
50
|
+
server.on("connection", (socket) => {
|
|
51
|
+
onOpen(socket);
|
|
52
|
+
socket.on("message", (data) => {
|
|
53
|
+
const message = JSON.parse(String(data)) as Message;
|
|
54
|
+
received.push(message.type);
|
|
55
|
+
onMessage(socket, message);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
afterEach(async () => {
|
|
61
|
+
process.off("uncaughtException", recordUncaught);
|
|
62
|
+
for (const socket of server.clients) {
|
|
63
|
+
socket.terminate();
|
|
64
|
+
}
|
|
65
|
+
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
69
|
+
|
|
70
|
+
function client(): RealtimeSpeech {
|
|
71
|
+
return new RealtimeSpeech({ apiKey: "k", serverURL: `http://127.0.0.1:${port}` });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function* textOf(...chunks: string[]): AsyncIterable<string> {
|
|
75
|
+
for (const chunk of chunks) {
|
|
76
|
+
yield chunk;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function collectSlowly(stream: AsyncIterable<{ type?: string | undefined }>): Promise<string[]> {
|
|
81
|
+
const types: string[] = [];
|
|
82
|
+
for await (const event of stream) {
|
|
83
|
+
types.push(event.type ?? "?");
|
|
84
|
+
if (event.type === "speech.audio.done") {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
await sleep(20);
|
|
88
|
+
}
|
|
89
|
+
return types;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function withTimeout<T>(promise: Promise<T>, ms = 2000): Promise<T | "timed out"> {
|
|
93
|
+
return Promise.race([promise, sleep(ms).then(() => "timed out" as const)]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
it("delivers every event to a consumer that awaits between events", async () => {
|
|
97
|
+
const types = await withTimeout(collectSlowly(client().speakStream(textOf("Hi."), "m")));
|
|
98
|
+
|
|
99
|
+
expect(types).toEqual(["session.created", "speech.audio.delta", "speech.audio.done"]);
|
|
100
|
+
expect(received).toEqual(["input_text.append", "input_text.end"]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("keeps events sent before iteration starts", async () => {
|
|
104
|
+
const connection = await client().connect("m");
|
|
105
|
+
await connection.sendText("Hi.");
|
|
106
|
+
await connection.end();
|
|
107
|
+
await sleep(50);
|
|
108
|
+
|
|
109
|
+
const types = await withTimeout(collectSlowly(connection));
|
|
110
|
+
expect(types).toEqual(["session.created", "speech.audio.delta", "speech.audio.done"]);
|
|
111
|
+
await connection.close();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it.each([
|
|
115
|
+
[1000, undefined],
|
|
116
|
+
[1001, undefined],
|
|
117
|
+
[1008, "Voice 'nope' not found."],
|
|
118
|
+
[1011, "boom"],
|
|
119
|
+
])("handles a server close with code %i", async (code, message) => {
|
|
120
|
+
onMessage = (socket) => socket.close(code, message ?? "");
|
|
121
|
+
|
|
122
|
+
const outcome = await withTimeout(
|
|
123
|
+
collectSlowly(client().speakStream(textOf("Hi."), "m")).then(
|
|
124
|
+
() => "ended",
|
|
125
|
+
(err: unknown) => err,
|
|
126
|
+
),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
if (message === undefined) {
|
|
130
|
+
expect(outcome).toBe("ended");
|
|
131
|
+
} else {
|
|
132
|
+
expect(outcome).toBeInstanceOf(RealtimeSpeechException);
|
|
133
|
+
expect(outcome).toMatchObject({ message, code });
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("does not wait on a stalled text source after the server is done", async () => {
|
|
138
|
+
async function* stalled(): AsyncIterable<string> {
|
|
139
|
+
yield "Hi.";
|
|
140
|
+
await new Promise(() => undefined);
|
|
141
|
+
}
|
|
142
|
+
onMessage = (socket) => socket.send(JSON.stringify(DONE));
|
|
143
|
+
|
|
144
|
+
const types = await withTimeout(collectSlowly(client().speakStream(stalled(), "m")));
|
|
145
|
+
|
|
146
|
+
expect(types).toEqual(["session.created", "speech.audio.done"]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("raises a text stream error to a consumer that awaits", async () => {
|
|
150
|
+
async function* failing(): AsyncIterable<string> {
|
|
151
|
+
yield "Hi.";
|
|
152
|
+
throw new Error("LLM failed");
|
|
153
|
+
}
|
|
154
|
+
onMessage = () => undefined;
|
|
155
|
+
|
|
156
|
+
const outcome = await withTimeout(
|
|
157
|
+
collectSlowly(client().speakStream(failing(), "m")).then(
|
|
158
|
+
() => "ended",
|
|
159
|
+
(err: Error) => err.message,
|
|
160
|
+
),
|
|
161
|
+
);
|
|
162
|
+
expect(outcome).toBe("LLM failed");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("rejects a handshake timeout without an uncaught error", async () => {
|
|
166
|
+
const silent: Server = createServer(() => undefined);
|
|
167
|
+
await new Promise<void>((resolve) => silent.listen(0, "127.0.0.1", () => resolve()));
|
|
168
|
+
const silentPort = (silent.address() as AddressInfo).port;
|
|
169
|
+
|
|
170
|
+
const error = await new RealtimeSpeech({ apiKey: "k", serverURL: `http://127.0.0.1:${silentPort}` })
|
|
171
|
+
.connect("m", { timeoutMs: 50 })
|
|
172
|
+
.catch((err: unknown) => err);
|
|
173
|
+
await sleep(50);
|
|
174
|
+
silent.closeAllConnections();
|
|
175
|
+
silent.close();
|
|
176
|
+
|
|
177
|
+
expect(error).toBeInstanceOf(RealtimeSpeechException);
|
|
178
|
+
expect(uncaught).toEqual([]);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("keeps the serverUrl query string", async () => {
|
|
182
|
+
let url: string | undefined;
|
|
183
|
+
server.on("headers", (_headers, request) => {
|
|
184
|
+
url = request.url;
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const connection = await client().connect("m", {
|
|
188
|
+
serverUrl: `http://127.0.0.1:${port}/proxy?token=abc`,
|
|
189
|
+
});
|
|
190
|
+
await connection.close();
|
|
191
|
+
|
|
192
|
+
expect(url).toBe("/proxy/v1/audio/speech/realtime?token=abc&model=m");
|
|
193
|
+
});
|