@kabobcompany/lift 0.4.0 → 0.5.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/README.md CHANGED
@@ -38,6 +38,10 @@ the limits Lift sets; `email()` and `sms()` say what those are and what was sent
38
38
  long connection to Lift, and `publish(channel, event, data)` says something to everyone
39
39
  listening; `listeners` and `channels` show who is connected.
40
40
 
41
+ `startVoiceCall(sdp, session)` sets up a live voice conversation between a browser and
42
+ OpenAI's Realtime models (the sound never passes through the app), and `endVoiceCall(id)`
43
+ hangs it up; calls are limited and counted by their length.
44
+
41
45
  A refusal is thrown as a `LiftError` with `status`, `code`, `message` and, on a 422,
42
46
  `issues`.
43
47
 
package/dist/index.d.ts CHANGED
@@ -570,4 +570,51 @@ export declare const channels: () => Promise<{
570
570
  }>;
571
571
  /** Forget what a channel keeps as its latest. */
572
572
  export declare const forgetKept: (channel: string) => Promise<void>;
573
+ export type VoiceCall = {
574
+ /** OpenAI's id for the call: keep it to hang up. */
575
+ id: string;
576
+ /** OpenAI's SDP answer: give it to the browser's `setRemoteDescription`. */
577
+ sdp: string;
578
+ model: string;
579
+ /** When Lift hangs the call up if nobody did. */
580
+ ends_at: string;
581
+ };
582
+ /**
583
+ * Start a voice call for a browser:
584
+ *
585
+ * voice.post("/call", requireCompany, async (c) => {
586
+ * const offer = await c.req.text(); // the browser's SDP offer
587
+ * const call = await startVoiceCall(offer, { instructions: PROMPT, audio: { output: { voice: "marin" } } },
588
+ * { who: c.get("session"), tag: `brand-${brand.id}` });
589
+ * remember(call.id, c.get("session").user.id); // to hang up later
590
+ * return c.json({ id: call.id, sdp: call.sdp, endsAt: call.ends_at });
591
+ * });
592
+ *
593
+ * `session` is OpenAI's session object (`model`, `instructions`, `tools`,
594
+ * `audio`), chosen by this server, never by the browser. Lift offers the
595
+ * models `voice()` lists and uses the small one when none is named.
596
+ *
597
+ * A call is cut off after ten minutes. Lift counts its length and the tokens
598
+ * its answers used. Hang up (`endVoiceCall`) as soon as the conversation is over. Throws a
599
+ * `LiftError`: 429 `too_many_calls` or `daily_limit`, 422 `refused` with
600
+ * OpenAI's reason.
601
+ */
602
+ export declare function startVoiceCall(sdp: string, session?: Record<string, unknown>, options?: Paid): Promise<VoiceCall>;
603
+ /** Hang a call up, and learn how many seconds it is counted as. Safe to call twice. */
604
+ export declare function endVoiceCall(id: string, options?: Paid): Promise<{
605
+ id: string;
606
+ seconds: number | null;
607
+ }>;
608
+ /** Calls going now, seconds of voice used today, and the limits (models, seconds a call, calls at once, seconds a day). */
609
+ export declare function voice(options?: Paid): Promise<{
610
+ active: number;
611
+ seconds_today: number;
612
+ limits: {
613
+ models: string[];
614
+ default_model: string;
615
+ max_seconds: number;
616
+ concurrent_per_app: number;
617
+ seconds_per_app_day: number;
618
+ };
619
+ }>;
573
620
  export {};
package/dist/index.js CHANGED
@@ -514,3 +514,34 @@ export const listeners = async (channel) => (await channelsCall("GET", `${encode
514
514
  export const channels = () => channelsCall("GET", "");
515
515
  /** Forget what a channel keeps as its latest. */
516
516
  export const forgetKept = (channel) => channelsCall("DELETE", `${encodeURIComponent(channel)}/kept`);
517
+ /**
518
+ * Start a voice call for a browser:
519
+ *
520
+ * voice.post("/call", requireCompany, async (c) => {
521
+ * const offer = await c.req.text(); // the browser's SDP offer
522
+ * const call = await startVoiceCall(offer, { instructions: PROMPT, audio: { output: { voice: "marin" } } },
523
+ * { who: c.get("session"), tag: `brand-${brand.id}` });
524
+ * remember(call.id, c.get("session").user.id); // to hang up later
525
+ * return c.json({ id: call.id, sdp: call.sdp, endsAt: call.ends_at });
526
+ * });
527
+ *
528
+ * `session` is OpenAI's session object (`model`, `instructions`, `tools`,
529
+ * `audio`), chosen by this server, never by the browser. Lift offers the
530
+ * models `voice()` lists and uses the small one when none is named.
531
+ *
532
+ * A call is cut off after ten minutes. Lift counts its length and the tokens
533
+ * its answers used. Hang up (`endVoiceCall`) as soon as the conversation is over. Throws a
534
+ * `LiftError`: 429 `too_many_calls` or `daily_limit`, 422 `refused` with
535
+ * OpenAI's reason.
536
+ */
537
+ export async function startVoiceCall(sdp, session = {}, options = {}) {
538
+ return paidAnswer(await paid("openai", "POST", "realtime/calls", { sdp, session }, { timeoutMs: 30_000, ...options }), "OpenAI");
539
+ }
540
+ /** Hang a call up, and learn how many seconds it is counted as. Safe to call twice. */
541
+ export async function endVoiceCall(id, options = {}) {
542
+ return paidAnswer(await paid("openai", "POST", `realtime/calls/${encodeURIComponent(id)}/hangup`, undefined, { timeoutMs: 20_000, ...options }), "OpenAI");
543
+ }
544
+ /** Calls going now, seconds of voice used today, and the limits (models, seconds a call, calls at once, seconds a day). */
545
+ export async function voice(options = {}) {
546
+ return paidAnswer(await paid("openai", "GET", "realtime", undefined, { timeoutMs: 20_000, ...options }), "Lift");
547
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kabobcompany/lift",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "For apps hosted on Lift: call Kabob products (Lookr) as the signed-in person, run public actions, use OpenAI and Seedance on Kabob's account, keep files in Lift's storage, run background jobs, send email and text messages, and publish to long-lived channels.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",