@livekit/agents-plugin-openai 1.9.5 → 1.10.1
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/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/realtime/gpt_live_model.cjs.map +1 -1
- package/dist/realtime/gpt_live_model.d.cts +1 -1
- package/dist/realtime/gpt_live_model.d.ts +1 -1
- package/dist/realtime/gpt_live_model.d.ts.map +1 -1
- package/dist/realtime/gpt_live_model.js.map +1 -1
- package/dist/realtime/gpt_live_model.test.cjs +147 -0
- package/dist/realtime/gpt_live_model.test.cjs.map +1 -1
- package/dist/realtime/gpt_live_model.test.js +147 -0
- package/dist/realtime/gpt_live_model.test.js.map +1 -1
- package/package.json +7 -7
- package/src/realtime/gpt_live_model.test.ts +149 -0
- package/src/realtime/gpt_live_model.ts +3 -0
|
@@ -409,6 +409,7 @@ describe("GPTLiveModel", () => {
|
|
|
409
409
|
]);
|
|
410
410
|
server.sockets[0].terminate();
|
|
411
411
|
await vi.waitFor(() => expect(session.sessionId).toBe("live_1"));
|
|
412
|
+
await waitCount(2, 1);
|
|
412
413
|
expect(server.events(1).map((event) => event.type)).toEqual([
|
|
413
414
|
"session.start",
|
|
414
415
|
"session.input_audio.mute"
|
|
@@ -454,6 +455,152 @@ describe("GPTLiveModel", () => {
|
|
|
454
455
|
{ type: "session.thinking.append", delegation_id: "d1", content: "Still checking." }
|
|
455
456
|
]);
|
|
456
457
|
});
|
|
458
|
+
it("supports Decisions delegation and manual evaluation", async () => {
|
|
459
|
+
const decisionsOptions = {
|
|
460
|
+
model: "gpt-6-luna",
|
|
461
|
+
questions: [
|
|
462
|
+
{
|
|
463
|
+
type: "choice",
|
|
464
|
+
name: "mood",
|
|
465
|
+
instructions: "Mood?",
|
|
466
|
+
choices: [{ value: "happy" }, { value: "sad" }]
|
|
467
|
+
}
|
|
468
|
+
]
|
|
469
|
+
};
|
|
470
|
+
const session = create({ delegation: "decisions", decisionsOptions });
|
|
471
|
+
const events = [];
|
|
472
|
+
session.on("decision_event", (event) => events.push(event));
|
|
473
|
+
await ready(session);
|
|
474
|
+
const eventId = session.createDecision();
|
|
475
|
+
await waitCount(2);
|
|
476
|
+
expect(startConfig().delegation).toEqual({ type: "decisions", decisions: decisionsOptions });
|
|
477
|
+
expect(server.events()).toContainEqual({ type: "decision.create", event_id: eventId });
|
|
478
|
+
const payload = {
|
|
479
|
+
type: "decision.completed",
|
|
480
|
+
decision: {
|
|
481
|
+
model: "gpt-6-luna",
|
|
482
|
+
answers: [{ name: "mood", value: "happy" }],
|
|
483
|
+
usage: { input_tokens: 10 }
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
await server.send(session, {
|
|
487
|
+
type: "decision.event",
|
|
488
|
+
event_id: "result-1",
|
|
489
|
+
event: payload
|
|
490
|
+
});
|
|
491
|
+
expect(events).toEqual([{ type: "decision.event", event_id: "result-1", event: payload }]);
|
|
492
|
+
await expect(session._updateTools(tools)).rejects.toThrow("no tool channel");
|
|
493
|
+
});
|
|
494
|
+
it("rejects manual Decisions evaluation while a connection drains", async () => {
|
|
495
|
+
server.autoClose = false;
|
|
496
|
+
const session = create({
|
|
497
|
+
delegation: "decisions",
|
|
498
|
+
decisionsOptions: { model: "gpt-6-luna" },
|
|
499
|
+
maxSessionDuration: 300
|
|
500
|
+
});
|
|
501
|
+
try {
|
|
502
|
+
await ready(session);
|
|
503
|
+
await vi.waitFor(() => {
|
|
504
|
+
var _a;
|
|
505
|
+
return expect((_a = server.events().at(-1)) == null ? void 0 : _a.type).toBe("session.close");
|
|
506
|
+
});
|
|
507
|
+
expect(() => session.createDecision()).toThrow("closing");
|
|
508
|
+
await server.send(session, { type: "session.closed", reason: "expired" });
|
|
509
|
+
await vi.waitFor(() => expect(session.sessionId).toBe("live_1"));
|
|
510
|
+
const eventId = session.createDecision();
|
|
511
|
+
await vi.waitFor(
|
|
512
|
+
() => expect(server.events(1)).toContainEqual({ type: "decision.create", event_id: eventId })
|
|
513
|
+
);
|
|
514
|
+
expect(server.events(1)).toMatchObject([
|
|
515
|
+
{ type: "session.start" },
|
|
516
|
+
{ type: "decision.create", event_id: eventId }
|
|
517
|
+
]);
|
|
518
|
+
} finally {
|
|
519
|
+
server.autoClose = true;
|
|
520
|
+
const closing = session.close();
|
|
521
|
+
for (const socket of server.sockets) {
|
|
522
|
+
if (socket.readyState === WebSocket.OPEN)
|
|
523
|
+
socket.send(JSON.stringify({ type: "session.closed" }));
|
|
524
|
+
}
|
|
525
|
+
await closing;
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
it("rejects manual Decisions evaluation while the session closes and after closing", async () => {
|
|
529
|
+
const session = create({
|
|
530
|
+
delegation: "decisions",
|
|
531
|
+
decisionsOptions: { model: "gpt-6-luna" }
|
|
532
|
+
});
|
|
533
|
+
await ready(session);
|
|
534
|
+
const closing = session.close();
|
|
535
|
+
expect(() => session.createDecision()).toThrow("closing");
|
|
536
|
+
await closing;
|
|
537
|
+
expect(() => session.createDecision()).toThrow("closing");
|
|
538
|
+
expect(server.events().some((event) => event.type === "decision.create")).toBe(false);
|
|
539
|
+
});
|
|
540
|
+
it("does not replay manual Decisions evaluation after a failed startup", async () => {
|
|
541
|
+
server.autoStart = false;
|
|
542
|
+
const session = create({
|
|
543
|
+
delegation: "decisions",
|
|
544
|
+
decisionsOptions: { model: "gpt-6-luna" },
|
|
545
|
+
connOptions: { maxRetry: 1, retryIntervalMs: 10, timeoutMs: 1e3 }
|
|
546
|
+
});
|
|
547
|
+
await session._updateSession();
|
|
548
|
+
await waitCount(1);
|
|
549
|
+
session.createDecision();
|
|
550
|
+
server.sockets[0].terminate();
|
|
551
|
+
await waitCount(1, 1);
|
|
552
|
+
const eventId = session.createDecision();
|
|
553
|
+
await server.send(session, { type: "session.started", session: { id: "live_1" } });
|
|
554
|
+
await vi.waitFor(
|
|
555
|
+
() => expect(server.events(1)).toContainEqual({ type: "decision.create", event_id: eventId })
|
|
556
|
+
);
|
|
557
|
+
expect(server.events(1)).toMatchObject([
|
|
558
|
+
{ type: "session.start" },
|
|
559
|
+
{ type: "decision.create", event_id: eventId }
|
|
560
|
+
]);
|
|
561
|
+
});
|
|
562
|
+
it.each(["client", "responses"])(
|
|
563
|
+
"serializes Decisions triggers but rejects manual evaluation under %s delegation",
|
|
564
|
+
async (delegation) => {
|
|
565
|
+
var _a;
|
|
566
|
+
const triggers = [
|
|
567
|
+
{
|
|
568
|
+
type: "decisions",
|
|
569
|
+
eventType: "session.output_transcript.delta",
|
|
570
|
+
decisions: {
|
|
571
|
+
questions: [
|
|
572
|
+
{
|
|
573
|
+
name: "mood",
|
|
574
|
+
type: "choice",
|
|
575
|
+
instructions: "Mood?",
|
|
576
|
+
choices: [{ value: "happy" }]
|
|
577
|
+
}
|
|
578
|
+
]
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
];
|
|
582
|
+
const session = create({ delegation, triggers });
|
|
583
|
+
await ready(session);
|
|
584
|
+
expect(startConfig().triggers).toEqual([
|
|
585
|
+
{
|
|
586
|
+
type: "decisions",
|
|
587
|
+
event_type: "session.output_transcript.delta",
|
|
588
|
+
decisions: triggers[0].decisions
|
|
589
|
+
}
|
|
590
|
+
]);
|
|
591
|
+
expect((_a = startConfig().delegation) == null ? void 0 : _a.type).toBe(delegation);
|
|
592
|
+
expect(() => session.createDecision()).toThrow("Decisions delegation");
|
|
593
|
+
expect(server.events().some((event) => event.type === "decision.create")).toBe(false);
|
|
594
|
+
}
|
|
595
|
+
);
|
|
596
|
+
it("requires Decisions configuration to match Decisions delegation", () => {
|
|
597
|
+
expect(() => new GPTLiveModel({ apiKey: "sk-test", delegation: "decisions" })).toThrow(
|
|
598
|
+
"decisionsOptions"
|
|
599
|
+
);
|
|
600
|
+
expect(
|
|
601
|
+
() => new GPTLiveModel({ apiKey: "sk-test", decisionsOptions: { model: "gpt-6-luna" } })
|
|
602
|
+
).toThrow("decisionsOptions");
|
|
603
|
+
});
|
|
457
604
|
it("drops old delegation answers during drain, startup, and after reconnect", async () => {
|
|
458
605
|
server.autoClose = false;
|
|
459
606
|
const session = create({ delegation: "client", maxSessionDuration: 300 });
|