Search
Code3,897
const urls = [ "https://console.groq.com/docs/quickstart", "https://console.groq.com/docs/openai", "https://console.groq.com/docs/models", "https://console.groq.com/docs/rate-limits",Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// @ts-ignoreimport { blob } from "https://esm.town/v/std/blob?v=11"; * * Notes: * - Uses std/openai (Val credentials) and std/blob for persistence * - UI polls and triggers small "work ticks" to progress jobs * - Keep prompts deterministic, temperature low, JSON-only outputs ========================= */const OPENAI_MODEL = "gpt-4o-mini"; // adjust as preferredconst JSON_RESPONSE_FORMAT = { type: "json_object" as const };const EXTRACTION_CONCURRENCY_PER_TICK = 4; // 24 lenses processed over ~6 ticks ========================= */const client = new OpenAI();/** Persist and load helpers */ const resp = await client.chat.completions.create({ model: OPENAI_MODEL, temperature: 0.1, response_format: JSON_RESPONSE_FORMAT, const resp = await client.chat.completions.create({ model: OPENAI_MODEL, temperature: 0.2, response_format: JSON_RESPONSE_FORMAT, const resp = await client.chat.completions.create({ model: OPENAI_MODEL, temperature: 0.1, response_format: JSON_RESPONSE_FORMAT, const resp = await client.chat.completions.create({ model: OPENAI_MODEL, temperature: 0.2, response_format: JSON_RESPONSE_FORMAT,- **Backend**: Hono + MCP Lite + Drizzle ORM + SQLite + Cloudinary- **Widget**: React 19 + TanStack Router + OpenAI App SDK## Quick Start## Message ScopingMessages are automatically scoped using the `openai/subject` field that ChatGPT includes in request metadata. This provides authless data isolation - each subject gets its own message board.The scoping happens in tool handlers:```typescriptconst subject = ctx.request.params._meta?.["openai/subject"];const messages = await getMessages(subject);```The exact semantics of `openai/subject` are determined by ChatGPT.## Where do I go from here?function widgetMeta(invoking?: string, invoked?: string) { return { "openai/outputTemplate": WIDGET_URI, "openai/toolInvocation/invoking": invoking, "openai/toolInvocation/invoked": invoked, "openai/widgetAccessible": true, "openai/resultCanProduceWidget": true, } as const;} _meta: { ...widgetMeta(), "openai/widgetCSP": { connect_domains: [baseUrl, "https://esm.sh", "https://cdn.jsdelivr.net"], resource_domains: [baseUrl, "https://esm.sh", "https://cdn.jsdelivr.net"], _meta: { ...widgetMeta(), "openai/widgetCSP": { connect_domains: [baseUrl, "https://esm.sh", "https://cdn.jsdelivr.net"], resource_domains: [baseUrl, "https://esm.sh", "https://cdn.jsdelivr.net"], _meta: { ...widgetMeta(), "openai/widgetCSP": { connect_domains: [baseUrl, "https://esm.sh", "https://cdn.jsdelivr.net"], resource_domains: [baseUrl, "https://esm.sh", "https://cdn.jsdelivr.net"], _meta: { ...widgetMeta(), "openai/widgetCSP": { connect_domains: [baseUrl, "https://esm.sh", "https://cdn.jsdelivr.net"], resource_domains: [baseUrl, "https://esm.sh", "https://cdn.jsdelivr.net"], _meta: widgetMeta("Loading messages...", "Messages loaded"), handler: async (args, ctx) => { const subject = ctx.request.params._meta?.["openai/subject"]; if (!subject) { throw new Error("Missing openai/subject in request metadata"); } _meta: widgetMeta("Loading message...", "Message loaded"), handler: async ({ id }, ctx) => { const subject = ctx.request.params._meta?.["openai/subject"]; if (!subject) { throw new Error("Missing openai/subject in request metadata"); } } const subject = ctx.request.params._meta?.["openai/subject"]; if (!subject) { throw new Error("Missing openai/subject in request metadata"); } _meta: { ...widgetMeta("Loading item...", "Item loaded"), "openai/outputTemplate": ITEM_CARD_URI, }, handler: async ({ category }) => { _meta: { ...widgetMeta(), "openai/outputTemplate": ITEM_CARD_URI, }, }; _meta: { ...widgetMeta("Loading items...", "Items loaded"), "openai/outputTemplate": MULTI_ITEM_CARD_URI, }, handler: async ({ count }) => { _meta: { ...widgetMeta(), "openai/outputTemplate": MULTI_ITEM_CARD_URI, }, }; _meta: { ...widgetMeta("Creating outfit...", "Outfit ready"), "openai/outputTemplate": OUTFIT_CARD_URI, }, handler: async () => { _meta: { ...widgetMeta(), "openai/outputTemplate": OUTFIT_CARD_URI, }, }; outputSchema: CaptureItemsOutput, _meta: { "openai/toolInvocation/invoking": "Scanning & uploading…", "openai/toolInvocation/invoked": "Saved to your closet.", "openai/widgetAccessible": true, "openai/resultCanProduceWidget": true, }, handler: async (args) => { structuredContent: isMultiple ? { items: added } : { item: added[0] }, _meta: { "openai/outputTemplate": isMultiple ? MULTI_ITEM_CARD_URI : ITEM_CARD_URI, "openai/toolInvocation/invoking": "Scanning & uploading…", "openai/toolInvocation/invoked": "Saved to your closet.", "openai/widgetAccessible": true, "openai/resultCanProduceWidget": true, }, }; outputSchema: SuggestOutfitOutput, _meta: { "openai/outputTemplate": OUTFIT_CARD_URI, "openai/toolInvocation/invoking": "Picking pieces…", "openai/toolInvocation/invoked": "Outfit ready.", "openai/widgetAccessible": true, "openai/resultCanProduceWidget": true, }, handler: async () => { structuredContent: { top, bottom }, _meta: { "openai/outputTemplate": OUTFIT_CARD_URI, "openai/toolInvocation/invoking": "Picking pieces…", "openai/toolInvocation/invoked": "Outfit ready.", "openai/widgetAccessible": true, "openai/resultCanProduceWidget": true, }, }; }), _meta: { "openai/outputTemplate": MULTI_ITEM_CARD_URI, "openai/toolInvocation/invoking": "Loading closet…", "openai/toolInvocation/invoked": "Closet loaded.", "openai/widgetAccessible": true, "openai/resultCanProduceWidget": true, }, handler: async ({ category }) => { structuredContent: { items }, _meta: { "openai/outputTemplate": MULTI_ITEM_CARD_URI, "openai/toolInvocation/invoking": "Loading closet…", "openai/toolInvocation/invoked": "Closet loaded.", "openai/widgetAccessible": true, "openai/resultCanProduceWidget": true, }, };Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },### Widget Integration- Each tool specifies `openai/outputTemplate` in metadata- Widgets automatically render based on structured content- Consistent styling across all clothing-related widgets1. **Cloudinary upload fails**: Check environment variables2. **No outfit suggestions**: Ensure both tops and bottoms are in closet3. **Widget not displaying**: Verify `openai/outputTemplate` metadata### Debug Tips- All widgets use the `useToolOutput` hook to access structured data- Theme support via `useTheme` hook (light/dark mode)- Interactive actions send follow-up messages to ChatGPT via `getOpenAI().sendFollowUpMessage()`### Styling- Displays a single wardrobe item with image and category- Uses inline styles for consistent appearance- Accesses data via `globalThis.openai?.toolOutput?.structuredContent`### 2. MultiItemCard (`/frontend/widgets/components/MultiItemCard.tsx`)### MCP Integration- Proper `_meta` configuration with `openai/outputTemplate`- Structured content matching component expectations- Error handling for missing data### Data Access Pattern- Uses `globalThis.openai?.toolOutput?.structuredContent`- Direct access to structured data (no hooks needed)- Matches the original component specifications exactlyreconsumeralization
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
/**
* Practical Implementation of Collective Content Intelligence
* Bridging advanced AI with collaborative content creation
*/
exp
kwhinnery_openai
lost1991
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
No docs found