hello-realtimeutils.ts8 matches
1const MODEL = "gpt-realtime";
2const INSTRUCTIONS = `
3Greet the user in English, and thank them for trying the new OpenAI Realtime API.
4Give them a brief summary based on the list below, and then ask if they have any questions.
5Answer questions using the information below. For questions outside this scope,
7---
8Short summary:
9- The Realtime API is now generally available, and has improved instruction following, voice naturalness, and audio quality.
10There are two new voices and it's easier to develop for. There's also a new telephony integration for phone scenarios.
11Full list of improvements:
16- higher audio quality
17- improved handling of alphanumerics (eg, properly understanding credit card and phone numbers)
18- support for the OpenAI Prompts API
19- support for MCP-based tools
20- auto-truncation to reduce context size
21- native telephony support, making it simple to connect voice calls to existing Realtime API applications
22- when using WebRTC, you can connect without needing an ephemeral token
23- when using WebRTC, you can now control sessions (including tool calls) from the server
27const VOICE = "marin";
2829const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
30if (!OPENAI_API_KEY) {
31throw new Error("🔴 OpenAI API key not configured");
32}
3334export function makeHeaders(contentType?: string) {
35const obj: Record<string, string> = {
36Authorization: `Bearer ${OPENAI_API_KEY}`,
37};
38if (contentType) obj["Content-Type"] = contentType;
hello-realtimesip.ts1 match
2728// Accept the call.
29const url = `https://api.openai.com/v1/realtime/calls/${callId}/accept`;
30const headers = makeHeaders("application/json");
31const body = JSON.stringify(makeSession());
hello-realtimertc.ts1 match
7rtc.post("/", async (c) => {
8// Create the call.
9const url = "https://api.openai.com/v1/realtime/calls";
10const headers = makeHeaders();
11const fd = new FormData();
hello-realtimeREADME.md2 matches
4You can access the app via WebRTC at https://hello-realtime.val.run, or via SIP by calling 425-800-0042.
56This demo shows off the new SIP API, the new all-in-one WebRTC API, and the new server-side websocket interface.
78If you remix the app, you'll just need to pop in your own OPENAI_API_KEY (from platform.openai.com), and also the OPENAI_SIGNING_SECRET if you want to use the SIP interface.
hello-realtimeobserver.ts1 match
8observer.post("/:callId", async (c) => {
9const callId = c.req.param("callId");
10const url = `wss://api.openai.com/v1/realtime?call_id=${callId}`;
11const ws = new WebSocket(url, { headers: makeHeaders() });
12ws.on("open", () => {
hello-realtimeindex.html1 match
4<meta charset="utf-8" />
5<meta name="viewport" content="width=device-width, initial-scale=1" />
6<title>OpenAI Realtime API Voice Agent</title>
7<style>
8:root {
ncaa-football-liveboardmain.tsx3 matches
5// ===============================
67// [REPO-SWAP #1]: replace this stub with: import { logger } from "@api/shared/logger"
8const logger = {
9child: (x?: any) => console,
13const log = logger.child?.({ label: "tool:topic:ncaaf-liveboard" }) || console;
1415// [REPO-SWAP #2]: replace this local helper with: import { fromUnixTime } from "@api/shared/utils"
16function fromUnixTime(input?: number | string) {
17let date: Date;
33// [REPO-SWAP #3]: in repo, use ESPN_ENDPOINTS.NCAAF_SCOREBOARD from your config
34const ESPN_SCOREBOARD =
35"https://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard";
3637// ====== toggles ======
weekly-schedDelegationPage.tsx3 matches
42const fetchResponsibilities = async () => {
43try {
44const response = await fetch("/api/responsibilities");
45const result = await response.json();
46if (result.success) {
7576const response = await fetch(
77`/api/tasks/week?start=${startDate}&end=${endDate}`,
78);
79const result = await response.json();
145146await fetch(
147`/api/tasks/by-responsibility/${responsibilityId}%23${date}`,
148{
149method: "PUT",
weekly-schedREADME.md13 matches
1920### Backend
21- Hono API framework
22- SQLite database
23- RESTful API endpoints
24- SPA routing support
25973. View and manage the schedule in the "Calendar" view
9899## API Endpoints
100101- `GET /api/responsibilities` - Get all active responsibilities
102- `POST /api/responsibilities` - Create new responsibility
103- `PUT /api/responsibilities/:id` - Update responsibility
104- `DELETE /api/responsibilities/:id` - Archive responsibility
105- `GET /api/tasks/week?start=YYYY-MM-DD&end=YYYY-MM-DD` - Get tasks for week
106- `POST /api/tasks` - Create new task assignment
107- `PUT /api/tasks/:id` - Update task (owner/notes)
108- `PUT /api/tasks/by-responsibility/{responsibilityId}#{date}` - Create or update task by responsibility and date (upsert)
109- `DELETE /api/tasks/:id` - Delete task assignment
110111### Task Management
112113The app now supports a unified PUT endpoint for creating or updating tasks:
114- **Endpoint**: `PUT /api/tasks/by-responsibility/{responsibilityId}#{date}`
115- **Format**: The ID is formatted as `{responsibilityId}#{date}` (e.g., `1#2024-01-15`)
116- **Behavior**: Creates a new task if it doesn't exist, updates if it does
weekly-schedtasks.ts35 matches
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { ApiResponse, CreateTaskData, UpdateTaskData, UpsertTaskData } from "../../shared/types.ts";
3import {
4getTasksForWeek,
13const app = new Hono();
1415// GET /api/tasks/week?start=YYYY-MM-DD&end=YYYY-MM-DD - Get tasks for a week
16app.get("/week", async (c) => {
17try {
20
21if (!startDate || !endDate) {
22return c.json({ success: false, error: "Start and end dates are required" } as ApiResponse<never>, 400);
23}
2425const tasks = await getTasksForWeek(startDate, endDate);
26return c.json({ success: true, data: tasks } as ApiResponse<typeof tasks>);
27} catch (error) {
28console.error("Error fetching tasks for week:", error);
29return c.json({ success: false, error: "Failed to fetch tasks" } as ApiResponse<never>, 500);
30}
31});
3233// GET /api/tasks/:id - Get task by ID
34app.get("/:id", async (c) => {
35try {
36const id = parseInt(c.req.param("id"));
37if (isNaN(id)) {
38return c.json({ success: false, error: "Invalid task ID" } as ApiResponse<never>, 400);
39}
4041const task = await getTaskById(id);
42if (!task) {
43return c.json({ success: false, error: "Task not found" } as ApiResponse<never>, 404);
44}
4546return c.json({ success: true, data: task } as ApiResponse<typeof task>);
47} catch (error) {
48console.error("Error fetching task:", error);
49return c.json({ success: false, error: "Failed to fetch task" } as ApiResponse<never>, 500);
50}
51});
5253// POST /api/tasks - Create new task
54app.post("/", async (c) => {
55try {
58// Validate required fields
59if (!body.responsibilityId || !body.date || !body.owner) {
60return c.json({ success: false, error: "ResponsibilityId, date, and owner are required" } as ApiResponse<never>, 400);
61}
6263// Validate owner enum
64if (!['Jeff', 'Tara'].includes(body.owner)) {
65return c.json({ success: false, error: "Invalid owner value" } as ApiResponse<never>, 400);
66}
6769const existingTask = await getTaskByResponsibilityAndDate(body.responsibilityId, body.date);
70if (existingTask) {
71return c.json({ success: false, error: "Task already exists for this responsibility and date" } as ApiResponse<never>, 409);
72}
7374const task = await createTask(body);
75return c.json({ success: true, data: task } as ApiResponse<typeof task>, 201);
76} catch (error) {
77console.error("Error creating task:", error);
78return c.json({ success: false, error: "Failed to create task" } as ApiResponse<never>, 500);
79}
80});
8182// PUT /api/tasks/:id - Update task
83app.put("/:id", async (c) => {
84try {
85const id = parseInt(c.req.param("id"));
86if (isNaN(id)) {
87return c.json({ success: false, error: "Invalid task ID" } as ApiResponse<never>, 400);
88}
8992// Validate owner enum if provided
93if (body.owner && !['Jeff', 'Tara'].includes(body.owner)) {
94return c.json({ success: false, error: "Invalid owner value" } as ApiResponse<never>, 400);
95}
9697const task = await updateTask(id, body);
98if (!task) {
99return c.json({ success: false, error: "Task not found" } as ApiResponse<never>, 404);
100}
101102return c.json({ success: true, data: task } as ApiResponse<typeof task>);
103} catch (error) {
104console.error("Error updating task:", error);
105return c.json({ success: false, error: "Failed to update task" } as ApiResponse<never>, 500);
106}
107});
108109// PUT /api/tasks/by-responsibility/{responsibilityId}#{date} - Create or update task by responsibility and date
110app.put("/by-responsibility/:compositeId", async (c) => {
111try {
117
118if (parts.length !== 2) {
119return c.json({ success: false, error: "Invalid task ID format. Use {responsibilityId}#{date}" } as ApiResponse<never>, 400);
120}
121
124
125if (isNaN(responsibilityId)) {
126return c.json({ success: false, error: "Invalid responsibility ID" } as ApiResponse<never>, 400);
127}
128
129// Validate date format (YYYY-MM-DD)
130if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
131return c.json({ success: false, error: "Invalid date format. Use YYYY-MM-DD" } as ApiResponse<never>, 400);
132}
133136// Validate required fields
137if (!body.owner) {
138return c.json({ success: false, error: "Owner is required" } as ApiResponse<never>, 400);
139}
140
141// Validate owner enum
142if (!['Jeff', 'Tara'].includes(body.owner)) {
143return c.json({ success: false, error: "Invalid owner value" } as ApiResponse<never>, 400);
144}
145149});
150
151return c.json({ success: true, data: task } as ApiResponse<typeof task>);
152} catch (error) {
153console.error("Error upserting task:", error);
154return c.json({ success: false, error: "Failed to create or update task" } as ApiResponse<never>, 500);
155}
156});
157158// DELETE /api/tasks/:id - Delete task
159app.delete("/:id", async (c) => {
160try {
161const id = parseInt(c.req.param("id"));
162if (isNaN(id)) {
163return c.json({ success: false, error: "Invalid task ID" } as ApiResponse<never>, 400);
164}
165166const success = await deleteTask(id);
167if (!success) {
168return c.json({ success: false, error: "Task not found" } as ApiResponse<never>, 404);
169}
170171return c.json({ success: true } as ApiResponse<never>);
172} catch (error) {
173console.error("Error deleting task:", error);
174return c.json({ success: false, error: "Failed to delete task" } as ApiResponse<never>, 500);
175}
176});