@livekit/agents-plugin-openai 0.0.0-next-20260624041820
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/LICENSE +201 -0
- package/README.md +18 -0
- package/dist/index.cjs +74 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/llm.cjs +382 -0
- package/dist/llm.cjs.map +1 -0
- package/dist/llm.d.cts +230 -0
- package/dist/llm.d.ts +230 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +357 -0
- package/dist/llm.js.map +1 -0
- package/dist/llm.test.cjs +36 -0
- package/dist/llm.test.cjs.map +1 -0
- package/dist/llm.test.d.cts +2 -0
- package/dist/llm.test.d.ts +2 -0
- package/dist/llm.test.d.ts.map +1 -0
- package/dist/llm.test.js +35 -0
- package/dist/llm.test.js.map +1 -0
- package/dist/models.cjs +50 -0
- package/dist/models.cjs.map +1 -0
- package/dist/models.d.cts +26 -0
- package/dist/models.d.ts +26 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +25 -0
- package/dist/models.js.map +1 -0
- package/dist/realtime/api_proto.cjs +41 -0
- package/dist/realtime/api_proto.cjs.map +1 -0
- package/dist/realtime/api_proto.d.cts +501 -0
- package/dist/realtime/api_proto.d.ts +501 -0
- package/dist/realtime/api_proto.d.ts.map +1 -0
- package/dist/realtime/api_proto.js +13 -0
- package/dist/realtime/api_proto.js.map +1 -0
- package/dist/realtime/index.cjs +25 -0
- package/dist/realtime/index.cjs.map +1 -0
- package/dist/realtime/index.d.cts +3 -0
- package/dist/realtime/index.d.ts +3 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +3 -0
- package/dist/realtime/index.js.map +1 -0
- package/dist/realtime/realtime_model.cjs +1658 -0
- package/dist/realtime/realtime_model.cjs.map +1 -0
- package/dist/realtime/realtime_model.d.cts +202 -0
- package/dist/realtime/realtime_model.d.ts +202 -0
- package/dist/realtime/realtime_model.d.ts.map +1 -0
- package/dist/realtime/realtime_model.js +1637 -0
- package/dist/realtime/realtime_model.js.map +1 -0
- package/dist/realtime/realtime_model.test.cjs +596 -0
- package/dist/realtime/realtime_model.test.cjs.map +1 -0
- package/dist/realtime/realtime_model.test.d.cts +2 -0
- package/dist/realtime/realtime_model.test.d.ts +2 -0
- package/dist/realtime/realtime_model.test.d.ts.map +1 -0
- package/dist/realtime/realtime_model.test.js +600 -0
- package/dist/realtime/realtime_model.test.js.map +1 -0
- package/dist/responses/index.cjs +23 -0
- package/dist/responses/index.cjs.map +1 -0
- package/dist/responses/index.d.cts +2 -0
- package/dist/responses/index.d.ts +2 -0
- package/dist/responses/index.d.ts.map +1 -0
- package/dist/responses/index.js +2 -0
- package/dist/responses/index.js.map +1 -0
- package/dist/responses/llm.cjs +353 -0
- package/dist/responses/llm.cjs.map +1 -0
- package/dist/responses/llm.d.cts +52 -0
- package/dist/responses/llm.d.ts +52 -0
- package/dist/responses/llm.d.ts.map +1 -0
- package/dist/responses/llm.js +327 -0
- package/dist/responses/llm.js.map +1 -0
- package/dist/responses/llm.test.cjs +37 -0
- package/dist/responses/llm.test.cjs.map +1 -0
- package/dist/responses/llm.test.d.cts +2 -0
- package/dist/responses/llm.test.d.ts +2 -0
- package/dist/responses/llm.test.d.ts.map +1 -0
- package/dist/responses/llm.test.js +36 -0
- package/dist/responses/llm.test.js.map +1 -0
- package/dist/stt.cjs +627 -0
- package/dist/stt.cjs.map +1 -0
- package/dist/stt.d.cts +105 -0
- package/dist/stt.d.ts +105 -0
- package/dist/stt.d.ts.map +1 -0
- package/dist/stt.js +605 -0
- package/dist/stt.js.map +1 -0
- package/dist/stt.test.cjs +132 -0
- package/dist/stt.test.cjs.map +1 -0
- package/dist/stt.test.d.cts +2 -0
- package/dist/stt.test.d.ts +2 -0
- package/dist/stt.test.d.ts.map +1 -0
- package/dist/stt.test.js +131 -0
- package/dist/stt.test.js.map +1 -0
- package/dist/tool_utils.cjs +53 -0
- package/dist/tool_utils.cjs.map +1 -0
- package/dist/tool_utils.d.cts +4 -0
- package/dist/tool_utils.d.ts +4 -0
- package/dist/tool_utils.d.ts.map +1 -0
- package/dist/tool_utils.js +29 -0
- package/dist/tool_utils.js.map +1 -0
- package/dist/tool_utils.test.cjs +77 -0
- package/dist/tool_utils.test.cjs.map +1 -0
- package/dist/tool_utils.test.d.cts +2 -0
- package/dist/tool_utils.test.d.ts +2 -0
- package/dist/tool_utils.test.d.ts.map +1 -0
- package/dist/tool_utils.test.js +76 -0
- package/dist/tool_utils.test.js.map +1 -0
- package/dist/tools.cjs +117 -0
- package/dist/tools.cjs.map +1 -0
- package/dist/tools.d.cts +88 -0
- package/dist/tools.d.ts +88 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +90 -0
- package/dist/tools.js.map +1 -0
- package/dist/tts.cjs +141 -0
- package/dist/tts.cjs.map +1 -0
- package/dist/tts.d.cts +42 -0
- package/dist/tts.d.ts +42 -0
- package/dist/tts.d.ts.map +1 -0
- package/dist/tts.js +116 -0
- package/dist/tts.js.map +1 -0
- package/dist/tts.test.cjs +17 -0
- package/dist/tts.test.cjs.map +1 -0
- package/dist/tts.test.d.cts +2 -0
- package/dist/tts.test.d.ts +2 -0
- package/dist/tts.test.d.ts.map +1 -0
- package/dist/tts.test.js +16 -0
- package/dist/tts.test.js.map +1 -0
- package/dist/ws/index.cjs +29 -0
- package/dist/ws/index.cjs.map +1 -0
- package/dist/ws/index.d.cts +3 -0
- package/dist/ws/index.d.ts +3 -0
- package/dist/ws/index.d.ts.map +1 -0
- package/dist/ws/index.js +5 -0
- package/dist/ws/index.js.map +1 -0
- package/dist/ws/llm.cjs +523 -0
- package/dist/ws/llm.cjs.map +1 -0
- package/dist/ws/llm.d.cts +96 -0
- package/dist/ws/llm.d.ts +96 -0
- package/dist/ws/llm.d.ts.map +1 -0
- package/dist/ws/llm.js +505 -0
- package/dist/ws/llm.js.map +1 -0
- package/dist/ws/llm.test.cjs +69 -0
- package/dist/ws/llm.test.cjs.map +1 -0
- package/dist/ws/llm.test.d.cts +2 -0
- package/dist/ws/llm.test.d.ts +2 -0
- package/dist/ws/llm.test.d.ts.map +1 -0
- package/dist/ws/llm.test.js +68 -0
- package/dist/ws/llm.test.js.map +1 -0
- package/dist/ws/types.cjs +129 -0
- package/dist/ws/types.cjs.map +1 -0
- package/dist/ws/types.d.cts +172 -0
- package/dist/ws/types.d.ts +172 -0
- package/dist/ws/types.d.ts.map +1 -0
- package/dist/ws/types.js +96 -0
- package/dist/ws/types.js.map +1 -0
- package/package.json +56 -0
- package/src/index.ts +25 -0
- package/src/llm.test.ts +38 -0
- package/src/llm.ts +553 -0
- package/src/models.ts +235 -0
- package/src/realtime/api_proto.ts +714 -0
- package/src/realtime/index.ts +5 -0
- package/src/realtime/realtime_model.test.ts +793 -0
- package/src/realtime/realtime_model.ts +2116 -0
- package/src/responses/index.ts +4 -0
- package/src/responses/llm.test.ts +39 -0
- package/src/responses/llm.ts +452 -0
- package/src/stt.test.ts +167 -0
- package/src/stt.ts +793 -0
- package/src/tool_utils.test.ts +84 -0
- package/src/tool_utils.ts +46 -0
- package/src/tools.ts +166 -0
- package/src/tts.test.ts +19 -0
- package/src/tts.ts +158 -0
- package/src/ws/index.ts +17 -0
- package/src/ws/llm.test.ts +83 -0
- package/src/ws/llm.ts +710 -0
- package/src/ws/types.ts +132 -0
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_agents = require("@livekit/agents");
|
|
3
|
+
var import_vitest = require("vitest");
|
|
4
|
+
var import_realtime_model = require("./realtime_model.cjs");
|
|
5
|
+
function createSessionForTest() {
|
|
6
|
+
const session = Object.create(import_realtime_model.RealtimeSession.prototype);
|
|
7
|
+
session.responseCreatedFutures = {};
|
|
8
|
+
session.sendEvent = import_vitest.vi.fn();
|
|
9
|
+
session.textModeRecoveryRetries = 0;
|
|
10
|
+
session._options = {};
|
|
11
|
+
return session;
|
|
12
|
+
}
|
|
13
|
+
function stubTaskRuntime() {
|
|
14
|
+
import_vitest.vi.spyOn(import_agents.Task, "from").mockReturnValue({
|
|
15
|
+
cancel: import_vitest.vi.fn(),
|
|
16
|
+
done: true,
|
|
17
|
+
result: Promise.resolve(void 0)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
(0, import_vitest.describe)("RealtimeSession.generateReply", () => {
|
|
21
|
+
(0, import_vitest.it)("preserves session instructions when generating with per-response instructions", async () => {
|
|
22
|
+
const session = createSessionForTest();
|
|
23
|
+
await session.updateInstructions("Your name is Kelly. Always respond in English.");
|
|
24
|
+
const abortController = new AbortController();
|
|
25
|
+
const promise = session.generateReply("Tell the user what your name is.", {
|
|
26
|
+
signal: abortController.signal
|
|
27
|
+
});
|
|
28
|
+
abortController.abort();
|
|
29
|
+
await (0, import_vitest.expect)(promise).rejects.toThrow("generateReply aborted");
|
|
30
|
+
(0, import_vitest.expect)(session.instructions).toBe("Your name is Kelly. Always respond in English.");
|
|
31
|
+
(0, import_vitest.expect)(session.sendEvent).toHaveBeenCalledWith(
|
|
32
|
+
import_vitest.expect.objectContaining({
|
|
33
|
+
type: "session.update",
|
|
34
|
+
session: import_vitest.expect.objectContaining({
|
|
35
|
+
instructions: "Your name is Kelly. Always respond in English."
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
(0, import_vitest.expect)(session.sendEvent).toHaveBeenCalledWith(
|
|
40
|
+
import_vitest.expect.objectContaining({
|
|
41
|
+
type: "response.create",
|
|
42
|
+
response: import_vitest.expect.objectContaining({
|
|
43
|
+
instructions: "Your name is Kelly. Always respond in English.\nTell the user what your name is."
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
(0, import_vitest.it)("cancels an in-flight response when aborted before response.created", async () => {
|
|
49
|
+
const session = createSessionForTest();
|
|
50
|
+
const abortController = new AbortController();
|
|
51
|
+
const promise = session.generateReply("say pineapple", { signal: abortController.signal });
|
|
52
|
+
abortController.abort();
|
|
53
|
+
await (0, import_vitest.expect)(promise).rejects.toThrow("generateReply aborted");
|
|
54
|
+
(0, import_vitest.expect)(Object.keys(session.responseCreatedFutures)).toHaveLength(0);
|
|
55
|
+
(0, import_vitest.expect)(session.sendEvent).toHaveBeenCalledWith(
|
|
56
|
+
import_vitest.expect.objectContaining({ type: "response.create" })
|
|
57
|
+
);
|
|
58
|
+
(0, import_vitest.expect)(session.sendEvent).toHaveBeenCalledWith({ type: "response.cancel" });
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
(0, import_vitest.describe)("RealtimeSession response.done status handling", () => {
|
|
62
|
+
(0, import_vitest.afterEach)(() => {
|
|
63
|
+
import_vitest.vi.restoreAllMocks();
|
|
64
|
+
});
|
|
65
|
+
function createResponseDoneSession() {
|
|
66
|
+
stubTaskRuntime();
|
|
67
|
+
const model = new import_realtime_model.RealtimeModel({ apiKey: "test-key" });
|
|
68
|
+
const session = model.session();
|
|
69
|
+
session.currentGeneration = {
|
|
70
|
+
messageChannel: import_agents.stream.createStreamChannel(),
|
|
71
|
+
functionChannel: import_agents.stream.createStreamChannel(),
|
|
72
|
+
messages: /* @__PURE__ */ new Map(),
|
|
73
|
+
_doneFut: new import_agents.Future(),
|
|
74
|
+
_createdTimestamp: Date.now()
|
|
75
|
+
};
|
|
76
|
+
return session;
|
|
77
|
+
}
|
|
78
|
+
(0, import_vitest.it)("emits a recoverable APIError when response.done reports failed", () => {
|
|
79
|
+
const session = createResponseDoneSession();
|
|
80
|
+
const errors = [];
|
|
81
|
+
session.on("error", (error) => errors.push(error));
|
|
82
|
+
session.handleResponseDone({
|
|
83
|
+
type: "response.done",
|
|
84
|
+
event_id: "evt_response_failed",
|
|
85
|
+
response: {
|
|
86
|
+
id: "resp_failed",
|
|
87
|
+
object: "realtime.response",
|
|
88
|
+
status: "failed",
|
|
89
|
+
status_details: {
|
|
90
|
+
type: "failed",
|
|
91
|
+
error: {
|
|
92
|
+
code: "rate_limit_exceeded",
|
|
93
|
+
message: "rate limited"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
output: []
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
(0, import_vitest.expect)(errors).toHaveLength(1);
|
|
100
|
+
(0, import_vitest.expect)(errors[0].recoverable).toBe(true);
|
|
101
|
+
(0, import_vitest.expect)(errors[0].error).toBeInstanceOf(import_agents.APIError);
|
|
102
|
+
(0, import_vitest.expect)(errors[0].error.message).toBe(
|
|
103
|
+
"OpenAI Realtime API response failed with error type: unknown"
|
|
104
|
+
);
|
|
105
|
+
(0, import_vitest.expect)(errors[0].error.body).toEqual({
|
|
106
|
+
code: "rate_limit_exceeded",
|
|
107
|
+
message: "rate limited"
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
(0, import_vitest.it)("handles string response.done status details", () => {
|
|
111
|
+
const session = createResponseDoneSession();
|
|
112
|
+
(0, import_vitest.expect)(
|
|
113
|
+
() => session.handleResponseDone({
|
|
114
|
+
type: "response.done",
|
|
115
|
+
event_id: "evt_response_incomplete",
|
|
116
|
+
response: {
|
|
117
|
+
id: "resp_incomplete",
|
|
118
|
+
object: "realtime.response",
|
|
119
|
+
status: "incomplete",
|
|
120
|
+
status_details: "incomplete",
|
|
121
|
+
output: []
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
).not.toThrow();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
(0, import_vitest.describe)("RealtimeSession input_audio_transcription delta handling", () => {
|
|
128
|
+
function createTranscriptSession(opts) {
|
|
129
|
+
const session = Object.create(import_realtime_model.RealtimeSession.prototype);
|
|
130
|
+
session.inputTranscriptAccumulators = /* @__PURE__ */ new Map();
|
|
131
|
+
session.audioCapableItemIds = /* @__PURE__ */ new Set();
|
|
132
|
+
session.itemDeleteFutures = {};
|
|
133
|
+
const chatItems = new Map(Object.entries((opts == null ? void 0 : opts.chatItems) ?? {}));
|
|
134
|
+
session.remoteChatCtx = {
|
|
135
|
+
get: (id) => {
|
|
136
|
+
const item = chatItems.get(id);
|
|
137
|
+
return item ? { item } : void 0;
|
|
138
|
+
},
|
|
139
|
+
delete: (id) => {
|
|
140
|
+
chatItems.delete(id);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return session;
|
|
144
|
+
}
|
|
145
|
+
function delta(item_id, delta2, content_index = 0) {
|
|
146
|
+
return {
|
|
147
|
+
type: "conversation.item.input_audio_transcription.delta",
|
|
148
|
+
event_id: `evt_${item_id}_${delta2}_${content_index}`,
|
|
149
|
+
item_id,
|
|
150
|
+
content_index,
|
|
151
|
+
delta: delta2
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function completed(item_id, transcript, content_index = 0) {
|
|
155
|
+
return {
|
|
156
|
+
type: "conversation.item.input_audio_transcription.completed",
|
|
157
|
+
event_id: `evt_${item_id}_done`,
|
|
158
|
+
item_id,
|
|
159
|
+
content_index,
|
|
160
|
+
transcript
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
(0, import_vitest.it)("accumulates partial transcripts across delta events for the same item_id", () => {
|
|
164
|
+
const session = createTranscriptSession();
|
|
165
|
+
const emissions = [];
|
|
166
|
+
session.on("input_audio_transcription_completed", (ev) => emissions.push(ev));
|
|
167
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "Hello"));
|
|
168
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", ", world"));
|
|
169
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "!"));
|
|
170
|
+
(0, import_vitest.expect)(emissions).toEqual([
|
|
171
|
+
{ itemId: "item_a", transcript: "Hello", isFinal: false },
|
|
172
|
+
{ itemId: "item_a", transcript: "Hello, world", isFinal: false },
|
|
173
|
+
{ itemId: "item_a", transcript: "Hello, world!", isFinal: false }
|
|
174
|
+
]);
|
|
175
|
+
});
|
|
176
|
+
(0, import_vitest.it)("keeps accumulators isolated across concurrent item_ids", () => {
|
|
177
|
+
const session = createTranscriptSession();
|
|
178
|
+
const emissions = [];
|
|
179
|
+
session.on("input_audio_transcription_completed", (ev) => emissions.push(ev));
|
|
180
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "Aaa"));
|
|
181
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_b", "Bbb"));
|
|
182
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "Aaa"));
|
|
183
|
+
(0, import_vitest.expect)(emissions).toEqual([
|
|
184
|
+
{ itemId: "item_a", transcript: "Aaa", isFinal: false },
|
|
185
|
+
{ itemId: "item_b", transcript: "Bbb", isFinal: false },
|
|
186
|
+
{ itemId: "item_a", transcript: "AaaAaa", isFinal: false }
|
|
187
|
+
]);
|
|
188
|
+
});
|
|
189
|
+
(0, import_vitest.it)("keeps accumulators isolated across content_index within the same item_id", () => {
|
|
190
|
+
const session = createTranscriptSession();
|
|
191
|
+
const emissions = [];
|
|
192
|
+
session.on("input_audio_transcription_completed", (ev) => emissions.push(ev));
|
|
193
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "idx0-", 0));
|
|
194
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "idx1-", 1));
|
|
195
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "more0", 0));
|
|
196
|
+
(0, import_vitest.expect)(emissions).toEqual([
|
|
197
|
+
{ itemId: "item_a", transcript: "idx0-", isFinal: false },
|
|
198
|
+
{ itemId: "item_a", transcript: "idx1-", isFinal: false },
|
|
199
|
+
{ itemId: "item_a", transcript: "idx0-more0", isFinal: false }
|
|
200
|
+
]);
|
|
201
|
+
});
|
|
202
|
+
(0, import_vitest.it)("clears the accumulator on .completed so a subsequent delta does not inherit prior state", () => {
|
|
203
|
+
var _a;
|
|
204
|
+
const session = createTranscriptSession({
|
|
205
|
+
chatItems: { item_a: new import_agents.llm.ChatMessage({ role: "user", content: "", id: "item_a" }) }
|
|
206
|
+
});
|
|
207
|
+
const emissions = [];
|
|
208
|
+
session.on("input_audio_transcription_completed", (ev) => emissions.push(ev));
|
|
209
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "first turn "));
|
|
210
|
+
session.handleConversationItemInputAudioTranscriptionCompleted(
|
|
211
|
+
completed("item_a", "first turn complete.")
|
|
212
|
+
);
|
|
213
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "second"));
|
|
214
|
+
(0, import_vitest.expect)((_a = session.inputTranscriptAccumulators.get("item_a")) == null ? void 0 : _a.get(0)).toBe("second");
|
|
215
|
+
(0, import_vitest.expect)(emissions).toEqual([
|
|
216
|
+
{ itemId: "item_a", transcript: "first turn ", isFinal: false },
|
|
217
|
+
{ itemId: "item_a", transcript: "first turn complete.", isFinal: true },
|
|
218
|
+
{ itemId: "item_a", transcript: "second", isFinal: false }
|
|
219
|
+
]);
|
|
220
|
+
});
|
|
221
|
+
(0, import_vitest.it)("pushes the final transcript onto the matching ChatMessage exactly once on .completed", () => {
|
|
222
|
+
const chatMessage = new import_agents.llm.ChatMessage({ role: "user", content: "", id: "item_a" });
|
|
223
|
+
const session = createTranscriptSession({ chatItems: { item_a: chatMessage } });
|
|
224
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "partial-only"));
|
|
225
|
+
(0, import_vitest.expect)(chatMessage.content).toEqual([""]);
|
|
226
|
+
session.handleConversationItemInputAudioTranscriptionCompleted(completed("item_a", "final."));
|
|
227
|
+
(0, import_vitest.expect)(chatMessage.content).toEqual(["", "final."]);
|
|
228
|
+
});
|
|
229
|
+
(0, import_vitest.it)("emits isFinal:true on .completed even when remoteChatCtx has no matching item", () => {
|
|
230
|
+
const session = createTranscriptSession();
|
|
231
|
+
const emissions = [];
|
|
232
|
+
session.on("input_audio_transcription_completed", (ev) => emissions.push(ev));
|
|
233
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "partial"));
|
|
234
|
+
session.handleConversationItemInputAudioTranscriptionCompleted(completed("item_a", "final."));
|
|
235
|
+
(0, import_vitest.expect)(emissions).toEqual([
|
|
236
|
+
{ itemId: "item_a", transcript: "partial", isFinal: false },
|
|
237
|
+
{ itemId: "item_a", transcript: "final.", isFinal: true }
|
|
238
|
+
]);
|
|
239
|
+
(0, import_vitest.expect)(session.inputTranscriptAccumulators.size).toBe(0);
|
|
240
|
+
});
|
|
241
|
+
(0, import_vitest.it)("treats .completed as a no-op cleanup when no deltas preceded it (non-streaming STT model)", () => {
|
|
242
|
+
const session = createTranscriptSession({
|
|
243
|
+
chatItems: { item_a: new import_agents.llm.ChatMessage({ role: "user", content: "", id: "item_a" }) }
|
|
244
|
+
});
|
|
245
|
+
const emissions = [];
|
|
246
|
+
session.on("input_audio_transcription_completed", (ev) => emissions.push(ev));
|
|
247
|
+
session.handleConversationItemInputAudioTranscriptionCompleted(
|
|
248
|
+
completed("item_a", "one-shot whisper-1 transcript")
|
|
249
|
+
);
|
|
250
|
+
(0, import_vitest.expect)(session.inputTranscriptAccumulators.size).toBe(0);
|
|
251
|
+
(0, import_vitest.expect)(emissions).toEqual([
|
|
252
|
+
{ itemId: "item_a", transcript: "one-shot whisper-1 transcript", isFinal: true }
|
|
253
|
+
]);
|
|
254
|
+
});
|
|
255
|
+
(0, import_vitest.it)("skips emission for empty or missing deltas and does not create an accumulator", () => {
|
|
256
|
+
var _a;
|
|
257
|
+
const session = createTranscriptSession();
|
|
258
|
+
const emissions = [];
|
|
259
|
+
session.on("input_audio_transcription_completed", (ev) => emissions.push(ev));
|
|
260
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", ""));
|
|
261
|
+
session.handleConversationItemInputAudioTranscriptionDelta({
|
|
262
|
+
type: "conversation.item.input_audio_transcription.delta",
|
|
263
|
+
event_id: "evt_no_delta",
|
|
264
|
+
item_id: "item_a"
|
|
265
|
+
});
|
|
266
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "real"));
|
|
267
|
+
(0, import_vitest.expect)((_a = session.inputTranscriptAccumulators.get("item_a")) == null ? void 0 : _a.get(0)).toBe("real");
|
|
268
|
+
(0, import_vitest.expect)(emissions).toEqual([{ itemId: "item_a", transcript: "real", isFinal: false }]);
|
|
269
|
+
});
|
|
270
|
+
(0, import_vitest.it)("clears the accumulator and emits a closing isFinal:true on transcription failure when partials had streamed", () => {
|
|
271
|
+
const session = createTranscriptSession();
|
|
272
|
+
const emissions = [];
|
|
273
|
+
session.on("input_audio_transcription_completed", (ev) => emissions.push(ev));
|
|
274
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "partial "));
|
|
275
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "text"));
|
|
276
|
+
session.finalizePartialOnTranscriptionFailure("item_a", 0);
|
|
277
|
+
(0, import_vitest.expect)(session.inputTranscriptAccumulators.size).toBe(0);
|
|
278
|
+
(0, import_vitest.expect)(emissions).toEqual([
|
|
279
|
+
{ itemId: "item_a", transcript: "partial ", isFinal: false },
|
|
280
|
+
{ itemId: "item_a", transcript: "partial text", isFinal: false },
|
|
281
|
+
{ itemId: "item_a", transcript: "partial text", isFinal: true }
|
|
282
|
+
]);
|
|
283
|
+
});
|
|
284
|
+
(0, import_vitest.it)("emits nothing on transcription failure when no partials had streamed for that item", () => {
|
|
285
|
+
const session = createTranscriptSession();
|
|
286
|
+
const emissions = [];
|
|
287
|
+
session.on("input_audio_transcription_completed", (ev) => emissions.push(ev));
|
|
288
|
+
session.finalizePartialOnTranscriptionFailure("item_a", 0);
|
|
289
|
+
(0, import_vitest.expect)(emissions).toEqual([]);
|
|
290
|
+
(0, import_vitest.expect)(session.inputTranscriptAccumulators.size).toBe(0);
|
|
291
|
+
});
|
|
292
|
+
(0, import_vitest.it)("clears the accumulator when the conversation item is deleted", () => {
|
|
293
|
+
var _a;
|
|
294
|
+
const session = createTranscriptSession();
|
|
295
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "partial "));
|
|
296
|
+
session.handleConversationItemInputAudioTranscriptionDelta(delta("item_a", "more", 1));
|
|
297
|
+
(0, import_vitest.expect)((_a = session.inputTranscriptAccumulators.get("item_a")) == null ? void 0 : _a.size).toBe(2);
|
|
298
|
+
session.handleConversationItemDeleted({
|
|
299
|
+
type: "conversation.item.deleted",
|
|
300
|
+
event_id: "evt_del",
|
|
301
|
+
item_id: "item_a"
|
|
302
|
+
});
|
|
303
|
+
(0, import_vitest.expect)(session.inputTranscriptAccumulators.has("item_a")).toBe(false);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
(0, import_vitest.describe)("livekitItemToOpenAIItem", () => {
|
|
307
|
+
(0, import_vitest.describe)("message items", () => {
|
|
308
|
+
(0, import_vitest.it)("should use output_text type for assistant messages", async () => {
|
|
309
|
+
const assistantMessage = new import_agents.llm.ChatMessage({
|
|
310
|
+
role: "assistant",
|
|
311
|
+
content: "Hello, how can I help you?",
|
|
312
|
+
id: "test-assistant-msg"
|
|
313
|
+
});
|
|
314
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(assistantMessage);
|
|
315
|
+
(0, import_vitest.expect)(result.type).toBe("message");
|
|
316
|
+
(0, import_vitest.expect)(result.role).toBe("assistant");
|
|
317
|
+
(0, import_vitest.expect)(result.content).toHaveLength(1);
|
|
318
|
+
const content = result.content[0];
|
|
319
|
+
(0, import_vitest.expect)(content.type).toBe("output_text");
|
|
320
|
+
(0, import_vitest.expect)(content.text).toBe("Hello, how can I help you?");
|
|
321
|
+
});
|
|
322
|
+
(0, import_vitest.it)("should use input_text type for user messages", async () => {
|
|
323
|
+
const userMessage = new import_agents.llm.ChatMessage({
|
|
324
|
+
role: "user",
|
|
325
|
+
content: "What is the weather like?",
|
|
326
|
+
id: "test-user-msg"
|
|
327
|
+
});
|
|
328
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(userMessage);
|
|
329
|
+
(0, import_vitest.expect)(result.type).toBe("message");
|
|
330
|
+
(0, import_vitest.expect)(result.role).toBe("user");
|
|
331
|
+
(0, import_vitest.expect)(result.content).toHaveLength(1);
|
|
332
|
+
const content = result.content[0];
|
|
333
|
+
(0, import_vitest.expect)(content.type).toBe("input_text");
|
|
334
|
+
(0, import_vitest.expect)(content.text).toBe("What is the weather like?");
|
|
335
|
+
});
|
|
336
|
+
(0, import_vitest.it)("should use input_text type for system messages", async () => {
|
|
337
|
+
const systemMessage = new import_agents.llm.ChatMessage({
|
|
338
|
+
role: "system",
|
|
339
|
+
content: "You are a helpful assistant.",
|
|
340
|
+
id: "test-system-msg"
|
|
341
|
+
});
|
|
342
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(systemMessage);
|
|
343
|
+
(0, import_vitest.expect)(result.type).toBe("message");
|
|
344
|
+
(0, import_vitest.expect)(result.role).toBe("system");
|
|
345
|
+
(0, import_vitest.expect)(result.content).toHaveLength(1);
|
|
346
|
+
const content = result.content[0];
|
|
347
|
+
(0, import_vitest.expect)(content.type).toBe("input_text");
|
|
348
|
+
});
|
|
349
|
+
(0, import_vitest.it)("should convert developer role to system role", async () => {
|
|
350
|
+
const developerMessage = new import_agents.llm.ChatMessage({
|
|
351
|
+
role: "developer",
|
|
352
|
+
content: "System instructions.",
|
|
353
|
+
id: "test-developer-msg"
|
|
354
|
+
});
|
|
355
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(developerMessage);
|
|
356
|
+
(0, import_vitest.expect)(result.type).toBe("message");
|
|
357
|
+
(0, import_vitest.expect)(result.role).toBe("system");
|
|
358
|
+
const content = result.content[0];
|
|
359
|
+
(0, import_vitest.expect)(content.type).toBe("input_text");
|
|
360
|
+
});
|
|
361
|
+
(0, import_vitest.it)("should handle multiple content items for assistant", async () => {
|
|
362
|
+
const multiContentMessage = new import_agents.llm.ChatMessage({
|
|
363
|
+
role: "assistant",
|
|
364
|
+
content: ["First part.", "Second part."],
|
|
365
|
+
id: "test-multi-msg"
|
|
366
|
+
});
|
|
367
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(
|
|
368
|
+
multiContentMessage
|
|
369
|
+
);
|
|
370
|
+
(0, import_vitest.expect)(result.content).toHaveLength(2);
|
|
371
|
+
const content0 = result.content[0];
|
|
372
|
+
const content1 = result.content[1];
|
|
373
|
+
(0, import_vitest.expect)(content0.type).toBe("output_text");
|
|
374
|
+
(0, import_vitest.expect)(content1.type).toBe("output_text");
|
|
375
|
+
});
|
|
376
|
+
(0, import_vitest.it)("should convert image content to input_image for user messages", async () => {
|
|
377
|
+
const base64Data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==";
|
|
378
|
+
const imageContent = import_agents.llm.createImageContent({
|
|
379
|
+
image: `data:image/png;base64,${base64Data}`,
|
|
380
|
+
mimeType: "image/png"
|
|
381
|
+
});
|
|
382
|
+
const userMessage = new import_agents.llm.ChatMessage({
|
|
383
|
+
role: "user",
|
|
384
|
+
content: [imageContent],
|
|
385
|
+
id: "test-image-msg"
|
|
386
|
+
});
|
|
387
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(userMessage);
|
|
388
|
+
(0, import_vitest.expect)(result.type).toBe("message");
|
|
389
|
+
(0, import_vitest.expect)(result.role).toBe("user");
|
|
390
|
+
(0, import_vitest.expect)(result.content).toHaveLength(1);
|
|
391
|
+
const content = result.content[0];
|
|
392
|
+
(0, import_vitest.expect)(content.type).toBe("input_image");
|
|
393
|
+
(0, import_vitest.expect)(content.image_url).toBe(
|
|
394
|
+
`data:image/png;base64,${base64Data}`
|
|
395
|
+
);
|
|
396
|
+
});
|
|
397
|
+
(0, import_vitest.it)("should ignore image content for assistant messages", async () => {
|
|
398
|
+
const base64Data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==";
|
|
399
|
+
const imageContent = import_agents.llm.createImageContent({
|
|
400
|
+
image: `data:image/png;base64,${base64Data}`,
|
|
401
|
+
mimeType: "image/png"
|
|
402
|
+
});
|
|
403
|
+
const assistantMessage = new import_agents.llm.ChatMessage({
|
|
404
|
+
role: "assistant",
|
|
405
|
+
content: [imageContent],
|
|
406
|
+
id: "test-assistant-image-msg"
|
|
407
|
+
});
|
|
408
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(assistantMessage);
|
|
409
|
+
(0, import_vitest.expect)(result.type).toBe("message");
|
|
410
|
+
(0, import_vitest.expect)(result.role).toBe("assistant");
|
|
411
|
+
(0, import_vitest.expect)(result.content).toHaveLength(0);
|
|
412
|
+
});
|
|
413
|
+
(0, import_vitest.it)("should ignore image content for system messages", async () => {
|
|
414
|
+
const base64Data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==";
|
|
415
|
+
const imageContent = import_agents.llm.createImageContent({
|
|
416
|
+
image: `data:image/png;base64,${base64Data}`,
|
|
417
|
+
mimeType: "image/png"
|
|
418
|
+
});
|
|
419
|
+
const systemMessage = new import_agents.llm.ChatMessage({
|
|
420
|
+
role: "system",
|
|
421
|
+
content: [imageContent],
|
|
422
|
+
id: "test-system-image-msg"
|
|
423
|
+
});
|
|
424
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(systemMessage);
|
|
425
|
+
(0, import_vitest.expect)(result.type).toBe("message");
|
|
426
|
+
(0, import_vitest.expect)(result.role).toBe("system");
|
|
427
|
+
(0, import_vitest.expect)(result.content).toHaveLength(0);
|
|
428
|
+
});
|
|
429
|
+
(0, import_vitest.it)("should ignore image content for developer messages mapped to system", async () => {
|
|
430
|
+
const base64Data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==";
|
|
431
|
+
const imageContent = import_agents.llm.createImageContent({
|
|
432
|
+
image: `data:image/png;base64,${base64Data}`,
|
|
433
|
+
mimeType: "image/png"
|
|
434
|
+
});
|
|
435
|
+
const developerMessage = new import_agents.llm.ChatMessage({
|
|
436
|
+
role: "developer",
|
|
437
|
+
content: [imageContent],
|
|
438
|
+
id: "test-developer-image-msg"
|
|
439
|
+
});
|
|
440
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(developerMessage);
|
|
441
|
+
(0, import_vitest.expect)(result.type).toBe("message");
|
|
442
|
+
(0, import_vitest.expect)(result.role).toBe("system");
|
|
443
|
+
(0, import_vitest.expect)(result.content).toHaveLength(0);
|
|
444
|
+
});
|
|
445
|
+
(0, import_vitest.it)("should handle mixed text and image content", async () => {
|
|
446
|
+
const base64Data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==";
|
|
447
|
+
const imageContent = import_agents.llm.createImageContent({
|
|
448
|
+
image: `data:image/png;base64,${base64Data}`,
|
|
449
|
+
mimeType: "image/png"
|
|
450
|
+
});
|
|
451
|
+
const userMessage = new import_agents.llm.ChatMessage({
|
|
452
|
+
role: "user",
|
|
453
|
+
content: ["Describe this image:", imageContent],
|
|
454
|
+
id: "test-mixed-msg"
|
|
455
|
+
});
|
|
456
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(userMessage);
|
|
457
|
+
(0, import_vitest.expect)(result.type).toBe("message");
|
|
458
|
+
(0, import_vitest.expect)(result.content).toHaveLength(2);
|
|
459
|
+
(0, import_vitest.expect)(result.content[0].type).toBe("input_text");
|
|
460
|
+
(0, import_vitest.expect)(result.content[1].type).toBe("input_image");
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
(0, import_vitest.describe)("function_call items", () => {
|
|
464
|
+
(0, import_vitest.it)("should convert function call items correctly", async () => {
|
|
465
|
+
const functionCall = new import_agents.llm.FunctionCall({
|
|
466
|
+
callId: "call-123",
|
|
467
|
+
name: "get_weather",
|
|
468
|
+
args: '{"location": "San Francisco"}',
|
|
469
|
+
id: "test-func-call"
|
|
470
|
+
});
|
|
471
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(functionCall);
|
|
472
|
+
(0, import_vitest.expect)(result.type).toBe("function_call");
|
|
473
|
+
(0, import_vitest.expect)(result.id).toBe("test-func-call");
|
|
474
|
+
(0, import_vitest.expect)(result.call_id).toBe("call-123");
|
|
475
|
+
(0, import_vitest.expect)(result.name).toBe("get_weather");
|
|
476
|
+
(0, import_vitest.expect)(result.arguments).toBe('{"location": "San Francisco"}');
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
(0, import_vitest.describe)("function_call_output items", () => {
|
|
480
|
+
(0, import_vitest.it)("should convert function call output items correctly", async () => {
|
|
481
|
+
const functionOutput = new import_agents.llm.FunctionCallOutput({
|
|
482
|
+
callId: "call-123",
|
|
483
|
+
output: "The weather in San Francisco is sunny.",
|
|
484
|
+
isError: false,
|
|
485
|
+
id: "test-func-output"
|
|
486
|
+
});
|
|
487
|
+
const result = await (0, import_realtime_model.livekitItemToOpenAIItem)(
|
|
488
|
+
functionOutput
|
|
489
|
+
);
|
|
490
|
+
(0, import_vitest.expect)(result.type).toBe("function_call_output");
|
|
491
|
+
(0, import_vitest.expect)(result.id).toBe("test-func-output");
|
|
492
|
+
(0, import_vitest.expect)(result.call_id).toBe("call-123");
|
|
493
|
+
(0, import_vitest.expect)(result.output).toBe("The weather in San Francisco is sunny.");
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
(0, import_vitest.describe)("RealtimeSession.updateOptions", () => {
|
|
498
|
+
(0, import_vitest.afterEach)(() => {
|
|
499
|
+
import_vitest.vi.restoreAllMocks();
|
|
500
|
+
});
|
|
501
|
+
(0, import_vitest.it)("emits session.update when toolChoice changes", () => {
|
|
502
|
+
stubTaskRuntime();
|
|
503
|
+
const model = new import_realtime_model.RealtimeModel({ apiKey: "test-key" });
|
|
504
|
+
const session = model.session();
|
|
505
|
+
const sendEventSpy = import_vitest.vi.spyOn(session, "sendEvent");
|
|
506
|
+
sendEventSpy.mockClear();
|
|
507
|
+
session.updateOptions({ toolChoice: "required" });
|
|
508
|
+
(0, import_vitest.expect)(sendEventSpy).toHaveBeenCalledTimes(1);
|
|
509
|
+
(0, import_vitest.expect)(sendEventSpy).toHaveBeenCalledWith(
|
|
510
|
+
import_vitest.expect.objectContaining({
|
|
511
|
+
type: "session.update",
|
|
512
|
+
session: import_vitest.expect.objectContaining({
|
|
513
|
+
type: "realtime",
|
|
514
|
+
tool_choice: "required"
|
|
515
|
+
})
|
|
516
|
+
})
|
|
517
|
+
);
|
|
518
|
+
});
|
|
519
|
+
(0, import_vitest.it)("does not emit session.update when toolChoice is unchanged", () => {
|
|
520
|
+
stubTaskRuntime();
|
|
521
|
+
const model = new import_realtime_model.RealtimeModel({ apiKey: "test-key" });
|
|
522
|
+
const session = model.session();
|
|
523
|
+
const sendEventSpy = import_vitest.vi.spyOn(session, "sendEvent");
|
|
524
|
+
sendEventSpy.mockClear();
|
|
525
|
+
session.updateOptions({ toolChoice: "auto" });
|
|
526
|
+
(0, import_vitest.expect)(sendEventSpy).not.toHaveBeenCalled();
|
|
527
|
+
});
|
|
528
|
+
(0, import_vitest.it)("keeps toolChoice state isolated across sessions from same model", () => {
|
|
529
|
+
stubTaskRuntime();
|
|
530
|
+
const model = new import_realtime_model.RealtimeModel({ apiKey: "test-key" });
|
|
531
|
+
const sessionA = model.session();
|
|
532
|
+
const sessionB = model.session();
|
|
533
|
+
const sendEventSpyA = import_vitest.vi.spyOn(sessionA, "sendEvent");
|
|
534
|
+
const sendEventSpyB = import_vitest.vi.spyOn(sessionB, "sendEvent");
|
|
535
|
+
sendEventSpyA.mockClear();
|
|
536
|
+
sendEventSpyB.mockClear();
|
|
537
|
+
sessionA.updateOptions({ toolChoice: "required" });
|
|
538
|
+
(0, import_vitest.expect)(sessionA._options.toolChoice).toBe("required");
|
|
539
|
+
(0, import_vitest.expect)(sessionB._options.toolChoice).toBe("auto");
|
|
540
|
+
(0, import_vitest.expect)(sendEventSpyA).toHaveBeenCalledTimes(1);
|
|
541
|
+
(0, import_vitest.expect)(sendEventSpyB).toHaveBeenCalledTimes(0);
|
|
542
|
+
sessionB.updateOptions({ toolChoice: "required" });
|
|
543
|
+
(0, import_vitest.expect)(sendEventSpyB).toHaveBeenCalledTimes(1);
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
(0, import_vitest.describe)("processBaseURL", () => {
|
|
547
|
+
(0, import_vitest.it)("upgrades https baseURL to wss and appends /realtime with model", () => {
|
|
548
|
+
const url = new URL(
|
|
549
|
+
(0, import_realtime_model.processBaseURL)({
|
|
550
|
+
baseURL: "https://gateway.example.com/v1",
|
|
551
|
+
model: "gpt-4o-realtime-preview",
|
|
552
|
+
isAzure: false
|
|
553
|
+
})
|
|
554
|
+
);
|
|
555
|
+
(0, import_vitest.expect)(url.protocol).toBe("wss:");
|
|
556
|
+
(0, import_vitest.expect)(url.host).toBe("gateway.example.com");
|
|
557
|
+
(0, import_vitest.expect)(url.pathname).toBe("/v1/realtime");
|
|
558
|
+
(0, import_vitest.expect)(url.searchParams.get("model")).toBe("gpt-4o-realtime-preview");
|
|
559
|
+
});
|
|
560
|
+
(0, import_vitest.it)("downgrades http baseURL to ws (not wss)", () => {
|
|
561
|
+
const url = new URL(
|
|
562
|
+
(0, import_realtime_model.processBaseURL)({
|
|
563
|
+
baseURL: "http://gateway.example.com/v1",
|
|
564
|
+
model: "gpt-4o-realtime-preview",
|
|
565
|
+
isAzure: false
|
|
566
|
+
})
|
|
567
|
+
);
|
|
568
|
+
(0, import_vitest.expect)(url.protocol).toBe("ws:");
|
|
569
|
+
(0, import_vitest.expect)(url.host).toBe("gateway.example.com");
|
|
570
|
+
(0, import_vitest.expect)(url.pathname).toBe("/v1/realtime");
|
|
571
|
+
(0, import_vitest.expect)(url.searchParams.get("model")).toBe("gpt-4o-realtime-preview");
|
|
572
|
+
});
|
|
573
|
+
(0, import_vitest.it)("passes through an already-wss baseURL unchanged", () => {
|
|
574
|
+
const url = new URL(
|
|
575
|
+
(0, import_realtime_model.processBaseURL)({
|
|
576
|
+
baseURL: "wss://gateway.example.com/v1",
|
|
577
|
+
model: "gpt-4o-realtime-preview",
|
|
578
|
+
isAzure: false
|
|
579
|
+
})
|
|
580
|
+
);
|
|
581
|
+
(0, import_vitest.expect)(url.protocol).toBe("wss:");
|
|
582
|
+
(0, import_vitest.expect)(url.pathname).toBe("/v1/realtime");
|
|
583
|
+
});
|
|
584
|
+
(0, import_vitest.it)("passes through an already-ws baseURL unchanged", () => {
|
|
585
|
+
const url = new URL(
|
|
586
|
+
(0, import_realtime_model.processBaseURL)({
|
|
587
|
+
baseURL: "ws://gateway.example.com/v1",
|
|
588
|
+
model: "gpt-4o-realtime-preview",
|
|
589
|
+
isAzure: false
|
|
590
|
+
})
|
|
591
|
+
);
|
|
592
|
+
(0, import_vitest.expect)(url.protocol).toBe("ws:");
|
|
593
|
+
(0, import_vitest.expect)(url.pathname).toBe("/v1/realtime");
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
//# sourceMappingURL=realtime_model.test.cjs.map
|