@runtypelabs/persona-proxy 3.22.0 → 3.31.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/dist/index.cjs +120 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -1
- package/dist/index.d.ts +58 -1
- package/dist/index.js +118 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/flows/bakery-assistant.ts +1 -1
- package/src/flows/components.ts +1 -1
- package/src/flows/conversational.ts +1 -1
- package/src/flows/index.ts +2 -0
- package/src/flows/page-context.ts +1 -1
- package/src/flows/scheduling.ts +1 -1
- package/src/flows/shopping-assistant.ts +2 -2
- package/src/flows/storefront-assistant.ts +1 -1
- package/src/flows/webmcp-calendar.ts +60 -0
- package/src/flows/webmcp-storefront.ts +63 -0
- package/src/index.test.ts +95 -0
- package/src/index.ts +81 -4
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/flows/conversational.ts","../src/flows/scheduling.ts","../src/flows/shopping-assistant.ts","../src/flows/components.ts","../src/flows/bakery-assistant.ts","../src/flows/storefront-assistant.ts","../src/flows/page-context.ts","../src/utils/stripe.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { Context } from \"hono\";\nimport { handle } from \"hono/vercel\";\n\nexport type RuntypeFlowStep = {\n id: string;\n name: string;\n type: string;\n enabled: boolean;\n config: Record<string, unknown>;\n};\n\nexport type RuntypeFlowConfig = {\n name: string;\n description: string;\n steps: RuntypeFlowStep[];\n};\n\ntype RuntimeEnv = Record<string, string | undefined>;\n\n/**\n * Payload for message feedback (upvote/downvote)\n */\nexport type FeedbackPayload = {\n type: \"upvote\" | \"downvote\";\n messageId: string;\n content?: string;\n timestamp?: string;\n sessionId?: string;\n metadata?: Record<string, unknown>;\n};\n\n/**\n * Handler function for processing feedback\n */\nexport type FeedbackHandler = (feedback: FeedbackPayload) => Promise<void> | void;\n\nexport type ChatProxyOptions = {\n upstreamUrl?: string;\n apiKey?: string;\n path?: string;\n allowedOrigins?: string[];\n flowId?: string;\n flowConfig?: RuntypeFlowConfig;\n /**\n * Path for the feedback endpoint (default: \"/api/feedback\")\n */\n feedbackPath?: string;\n /**\n * Custom handler for processing feedback.\n * Use this to store feedback in a database or send to analytics.\n * \n * @example\n * ```ts\n * onFeedback: async (feedback) => {\n * await db.feedback.create({ data: feedback });\n * }\n * ```\n */\n onFeedback?: FeedbackHandler;\n};\n\nconst DEFAULT_ENDPOINT = \"https://api.runtype.com/v1/dispatch\";\nconst DEFAULT_PATH = \"/api/chat/dispatch\";\n\nconst getRuntimeEnv = (): RuntimeEnv | undefined => {\n const maybeProcess = (\n globalThis as typeof globalThis & { process?: { env?: RuntimeEnv } }\n ).process;\n return maybeProcess?.env;\n};\n\n/** True only when `NODE_ENV` is exactly `\"development\"` (unset = production). Safe when `process` is missing (e.g. some Workers runtimes). */\nconst isDevelopmentRuntime = (): boolean =>\n getRuntimeEnv()?.NODE_ENV === \"development\";\n\nconst DEFAULT_FLOW: RuntypeFlowConfig = {\n name: \"Streaming Prompt Flow\",\n description: \"Streaming chat generated by the widget\",\n steps: [\n {\n id: \"widget_prompt\",\n name: \"Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"mercury-2\",\n responseFormat: \"markdown\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: \"you are a helpful assistant, chatting with a user\",\n // tools: {\n // toolIds: [\n // \"builtin:dalle\"\n // ]\n // },\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n\nconst withCors =\n (allowedOrigins: string[] | undefined) =>\n async (c: Context, next: () => Promise<void>) => {\n const origin = c.req.header(\"origin\");\n const isDevelopment = isDevelopmentRuntime();\n \n // Determine the CORS origin to allow\n let corsOrigin: string;\n if (!allowedOrigins || allowedOrigins.length === 0) {\n // No restrictions - allow any origin (or use the request origin)\n corsOrigin = origin || \"*\";\n } else if (allowedOrigins.includes(origin || \"\")) {\n // Origin is in the allowed list\n corsOrigin = origin || \"*\";\n } else if (isDevelopment && origin) {\n // In development, allow the actual origin even if not in the list\n // This helps with local development where ports might vary\n corsOrigin = origin;\n } else {\n // Production: origin not allowed - reject by not setting CORS headers\n // Return error for preflight, or continue without CORS headers\n if (c.req.method === \"OPTIONS\") {\n return c.json({ error: \"CORS policy violation: origin not allowed\" }, 403);\n }\n // For non-preflight requests, continue but browser will block due to missing CORS headers\n await next();\n return;\n }\n\n const headers: Record<string, string> = {\n \"Access-Control-Allow-Origin\": corsOrigin,\n \"Access-Control-Allow-Headers\": \"Content-Type, Authorization\",\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n Vary: \"Origin\"\n };\n\n if (c.req.method === \"OPTIONS\") {\n return new Response(null, { status: 204, headers });\n }\n\n await next();\n Object.entries(headers).forEach(([key, value]) =>\n c.header(key, value, { append: false })\n );\n };\n\nexport const createChatProxyApp = (options: ChatProxyOptions = {}) => {\n const app = new Hono();\n const path = options.path ?? DEFAULT_PATH;\n const feedbackPath = options.feedbackPath ?? \"/api/feedback\";\n const upstream = options.upstreamUrl ?? DEFAULT_ENDPOINT;\n\n app.use(\"*\", withCors(options.allowedOrigins));\n\n // Feedback endpoint for collecting upvote/downvote data\n app.post(feedbackPath, async (c) => {\n let payload: FeedbackPayload;\n try {\n payload = await c.req.json();\n } catch (error) {\n return c.json({ error: \"Invalid JSON body\" }, 400);\n }\n\n // Validate payload\n if (!payload.type || ![\"upvote\", \"downvote\"].includes(payload.type)) {\n return c.json(\n { error: \"Invalid feedback type. Must be 'upvote' or 'downvote'\" },\n 400\n );\n }\n if (!payload.messageId) {\n return c.json({ error: \"Missing messageId\" }, 400);\n }\n\n // Add timestamp if not provided\n payload.timestamp = payload.timestamp ?? new Date().toISOString();\n\n const isDevelopment = isDevelopmentRuntime();\n\n if (isDevelopment) {\n console.log(\"\\n=== Feedback Received ===\");\n console.log(\"Type:\", payload.type);\n console.log(\"Message ID:\", payload.messageId);\n console.log(\"Content Length:\", payload.content?.length ?? 0);\n console.log(\"Timestamp:\", payload.timestamp);\n console.log(\"=== End Feedback ===\\n\");\n }\n\n // Call custom handler if provided\n if (options.onFeedback) {\n try {\n await options.onFeedback(payload);\n } catch (error) {\n console.error(\"[Feedback] Handler error:\", error);\n return c.json({ error: \"Feedback handler failed\" }, 500);\n }\n }\n\n return c.json({\n success: true,\n message: \"Feedback recorded\",\n feedback: {\n type: payload.type,\n messageId: payload.messageId,\n timestamp: payload.timestamp\n }\n });\n });\n\n // Chat dispatch endpoint\n app.post(path, async (c) => {\n const apiKey = options.apiKey ?? getRuntimeEnv()?.RUNTYPE_API_KEY;\n if (!apiKey) {\n return c.json(\n { error: \"Missing API key. Set RUNTYPE_API_KEY.\" },\n 401\n );\n }\n\n let clientPayload: Record<string, unknown>;\n try {\n clientPayload = await c.req.json();\n } catch (error) {\n return c.json(\n { error: \"Invalid JSON body\", details: error },\n 400\n );\n }\n\n const isDevelopment = isDevelopmentRuntime();\n\n // Detect agent mode: if the payload contains an `agent` field, forward it directly\n const isAgentMode = !!clientPayload.agent;\n\n let runtypePayload: Record<string, unknown>;\n\n if (isAgentMode) {\n // Agent dispatch - forward the payload as-is to the upstream API\n runtypePayload = clientPayload;\n } else {\n // Flow dispatch - build the Runtype flow payload\n const messages = (clientPayload.messages ?? []) as Array<{ role: string; content: string; createdAt?: string }>;\n const sortedMessages = [...messages].sort((a, b) => {\n const timeA = a.createdAt ? new Date(a.createdAt).getTime() : 0;\n const timeB = b.createdAt ? new Date(b.createdAt).getTime() : 0;\n return timeA - timeB;\n });\n const formattedMessages = sortedMessages.map((message) => ({\n role: message.role,\n content: message.content\n }));\n\n const flowId = (clientPayload.flowId as string | undefined) ?? options.flowId;\n const flowConfig = options.flowConfig ?? DEFAULT_FLOW;\n\n runtypePayload = {\n record: {\n name: \"Streaming Chat Widget\",\n type: \"standalone\",\n metadata: (clientPayload.metadata as Record<string, unknown>) || {}\n },\n messages: formattedMessages,\n options: {\n streamResponse: true,\n recordMode: \"virtual\",\n flowMode: flowId ? \"existing\" : \"virtual\",\n autoAppendMetadata: false\n }\n };\n\n const clientInputs = clientPayload.inputs;\n if (clientInputs && typeof clientInputs === \"object\" && !Array.isArray(clientInputs)) {\n runtypePayload.inputs = clientInputs;\n }\n\n if (flowId) {\n runtypePayload.flow = { id: flowId };\n } else {\n runtypePayload.flow = flowConfig;\n }\n\n // WebMCP: forward page-discovered tools so the upstream flow's agent step\n // can call them. The widget snapshots `document.modelContext` per turn and\n // ships them as `clientTools[]`; the flow-dispatch payload is rebuilt from\n // scratch above, so without this they'd be silently dropped and the agent\n // would never see the page tools. (Agent mode forwards the payload as-is,\n // so it already carries `clientTools`.) The matching results come back via\n // the `${path}/resume` endpoint below.\n if (\n Array.isArray(clientPayload.clientTools) &&\n clientPayload.clientTools.length > 0\n ) {\n runtypePayload.clientTools = clientPayload.clientTools;\n }\n }\n\n // Development only: do not log key material or full bodies in production.\n if (isDevelopment) {\n console.log(`\\n=== Runtype Proxy Request (${isAgentMode ? \"agent\" : \"flow\"}) ===`);\n console.log(\"URL:\", upstream);\n console.log(\"API Key Used:\", apiKey ? \"Yes\" : \"No\");\n console.log(\"API Key (first 12 chars):\", apiKey ? apiKey.substring(0, 12) : \"N/A\");\n console.log(\"Request Payload:\", JSON.stringify(runtypePayload, null, 2));\n }\n\n const response = await fetch(upstream, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(runtypePayload)\n });\n\n if (isDevelopment) {\n console.log(\"Response Status:\", response.status);\n console.log(\"Response Status Text:\", response.statusText);\n\n // If there's an error, try to read and log the response body\n if (!response.ok) {\n const clonedResponse = response.clone();\n try {\n const errorBody = await clonedResponse.text();\n console.log(\"Error Response Body:\", errorBody);\n } catch (e) {\n console.log(\"Could not read error response body:\", e);\n }\n }\n console.log(\"=== End Runtype Proxy Request ===\\n\");\n }\n\n return new Response(response.body, {\n status: response.status,\n headers: {\n \"Content-Type\":\n response.headers.get(\"content-type\") ?? \"application/json\",\n \"Cache-Control\": \"no-store\"\n }\n });\n });\n\n // Resume endpoint — forwards client-executed (LOCAL) tool results back to\n // the Runtype upstream so a paused flow execution can continue. Mounted as\n // a child of the dispatch path so the widget can derive its URL by\n // appending \"/resume\" to whatever `apiUrl` it was configured with.\n app.post(`${path}/resume`, async (c) => {\n const apiKey = options.apiKey ?? getRuntimeEnv()?.RUNTYPE_API_KEY;\n if (!apiKey) {\n return c.json(\n { error: \"Missing API key. Set RUNTYPE_API_KEY.\" },\n 401\n );\n }\n\n let body: Record<string, unknown>;\n try {\n body = await c.req.json();\n } catch (error) {\n return c.json(\n { error: \"Invalid JSON body\", details: error },\n 400\n );\n }\n\n const isDevelopment = isDevelopmentRuntime();\n const upstreamResumeUrl = `${upstream.replace(/\\/+$/, '')}/resume`;\n\n if (isDevelopment) {\n console.log(\"\\n=== Runtype Proxy Resume ===\");\n console.log(\"URL:\", upstreamResumeUrl);\n console.log(\n \"executionId:\",\n typeof body.executionId === \"string\" ? body.executionId : \"(missing)\"\n );\n console.log(\n \"toolOutputs keys:\",\n body.toolOutputs && typeof body.toolOutputs === \"object\"\n ? Object.keys(body.toolOutputs)\n : \"(none)\"\n );\n console.log(\"=== End Runtype Proxy Resume ===\\n\");\n }\n\n const response = await fetch(upstreamResumeUrl, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(body)\n });\n\n return new Response(response.body, {\n status: response.status,\n headers: {\n \"Content-Type\":\n response.headers.get(\"content-type\") ?? \"application/json\",\n \"Cache-Control\": \"no-store\"\n }\n });\n });\n\n return app;\n};\n\nexport const createVercelHandler = (options?: ChatProxyOptions) =>\n handle(createChatProxyApp(options));\n\n// Export pre-configured flows\nexport * from \"./flows/index.js\";\n\n// Export utility functions\nexport * from \"./utils/index.js\";\n\nexport default createChatProxyApp;\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Basic conversational assistant flow\n * This is the default flow for simple chat interactions\n */\nexport const CONVERSATIONAL_FLOW: RuntypeFlowConfig = {\n name: \"Streaming Prompt Flow\",\n description: \"Streaming chat generated by the widget\",\n steps: [\n {\n id: \"widget_prompt\",\n name: \"Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"mercury-2\",\n responseFormat: \"markdown\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: \"you are a helpful assistant, chatting with a user\",\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Dynamic Form flow configuration\n * This flow returns forms as component directives for the widget to render\n */\nexport const FORM_DIRECTIVE_FLOW: RuntypeFlowConfig = {\n name: \"Dynamic Form Flow\",\n description: \"Returns dynamic forms as component directives\",\n steps: [\n {\n id: \"form_prompt\",\n name: \"Form Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"mercury-2\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful assistant that can have conversations and collect user information via forms.\n\nRESPONSE FORMAT:\nAlways respond with valid JSON. Choose the appropriate format:\n\n1. For CONVERSATIONAL responses or text answers:\n {\"text\": \"Your response here\"}\n\n2. When the user wants to SCHEDULE, BOOK, SIGN UP, or provide DETAILS (show a form):\n {\"component\": \"DynamicForm\", \"props\": {\"title\": \"Form Title\", \"description\": \"Optional description\", \"fields\": [...], \"submit_text\": \"Submit\"}}\n\n3. For BOTH explanation AND form:\n {\"text\": \"Your explanation\", \"component\": \"DynamicForm\", \"props\": {...}}\n\nFORM FIELD FORMAT:\nEach field in the \"fields\" array should have:\n- label (required): Display name for the field\n- name (optional): Field identifier (defaults to lowercase label with underscores)\n- type (optional): \"text\", \"email\", \"tel\", \"date\", \"time\", \"textarea\", \"number\" (defaults to \"text\")\n- placeholder (optional): Placeholder text\n- required (optional): true/false\n- width (optional): \"full\" or \"half\" — pair short related fields side-by-side with \"half\" (e.g. Phone + Company, City + Zip, First + Last name); use \"full\" or omit for everything else (especially textareas, emails, and standalone fields). Two consecutive \"half\" fields render in one row.\n\nEXAMPLES:\n\nUser: \"Schedule a demo for me\"\nResponse: {\"text\": \"I'd be happy to help you schedule a demo! Please fill out the form below:\", \"component\": \"DynamicForm\", \"props\": {\"title\": \"Schedule a Demo\", \"description\": \"Share your details and we'll follow up with a confirmation.\", \"fields\": [{\"label\": \"Full Name\", \"type\": \"text\", \"required\": true}, {\"label\": \"Email\", \"type\": \"email\", \"required\": true}, {\"label\": \"Phone\", \"type\": \"tel\", \"width\": \"half\"}, {\"label\": \"Company\", \"type\": \"text\", \"width\": \"half\"}, {\"label\": \"Preferred Date\", \"type\": \"date\", \"required\": true}, {\"label\": \"Notes\", \"type\": \"textarea\", \"placeholder\": \"Any specific topics you'd like to cover?\"}], \"submit_text\": \"Request Demo\"}}\n\nUser: \"What is AI?\"\nResponse: {\"text\": \"AI (Artificial Intelligence) refers to computer systems designed to perform tasks that typically require human intelligence, such as learning, reasoning, problem-solving, and understanding language.\"}\n\nUser: \"Collect my contact details\"\nResponse: {\"component\": \"DynamicForm\", \"props\": {\"title\": \"Contact Details\", \"fields\": [{\"label\": \"Name\", \"type\": \"text\", \"required\": true}, {\"label\": \"Email\", \"type\": \"email\", \"required\": true}, {\"label\": \"Phone\", \"type\": \"tel\"}], \"submit_text\": \"Save Details\"}}\n\nIMPORTANT:\n- Use {\"text\": \"...\"} for questions, explanations, and general conversation\n- Show a DynamicForm when user wants to provide information, schedule, book, or sign up\n- Create contextually appropriate form fields based on what the user is trying to do\n- Keep forms focused with only the relevant fields needed`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Shopping assistant flow configuration\n * This flow returns JSON actions for page interaction including:\n * - Simple messages\n * - Navigation with messages\n * - Element clicks with messages\n * - Stripe checkout\n */\nexport const SHOPPING_ASSISTANT_FLOW: RuntypeFlowConfig = {\n name: \"Shopping Assistant Flow\",\n description: \"Returns JSON actions for page interaction\",\n steps: [\n {\n id: \"action_prompt\",\n name: \"Action Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"mercury-2\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful shopping assistant that can interact with web pages.\nYou will receive information about the current page's elements (class names and text content)\nand user messages. You must respond with JSON in one of these formats:\n\n1. Simple message:\n{\n \"action\": \"message\",\n \"text\": \"Your response text here\"\n}\n\n2. Navigate then show message (for navigation to another page):\n{\n \"action\": \"nav_then_click\",\n \"page\": \"http://site.com/page-url\",\n \"on_load_text\": \"Message to show after navigation\"\n}\n\n3. Show message and click an element:\n{\n \"action\": \"message_and_click\",\n \"element\": \".className-of-element\",\n \"text\": \"Your message text\"\n}\n\n4. Create Stripe checkout:\n{\n \"action\": \"checkout\",\n \"text\": \"Your message text\",\n \"items\": [\n {\"name\": \"Product Name\", \"price\": 2999, \"quantity\": 1}\n ]\n}\n\nGuidelines:\n- Use \"message\" for simple conversational responses\n- Use \"nav_then_click\" when you need to navigate to a different page (like a product detail page)\n- Use \"message_and_click\" when you want to click a button or element on the current page\n- Use \"checkout\" when the user wants to proceed to checkout/payment. Include items array with name (string), price (number in cents), and quantity (number)\n- When selecting elements, use the class names provided in the page context\n- Always respond with valid JSON only, no additional text\n- For product searches, format results as markdown links: [Product Name](url)\n- Be helpful and conversational in your messages\n- Product prices: Black Shirt - Medium: $29.99 (2999 cents), Blue Shirt - Large: $34.99 (3499 cents), Red T-Shirt - Small: $19.99 (1999 cents), Jeans - Medium: $49.99 (4999 cents)\n\nExample conversation flow:\n- User: \"I am looking for a black shirt in medium\"\n- You: {\"action\": \"message\", \"text\": \"Here are the products I found:\\\\n1. [Black Shirt - Medium](/products.html?product=black-shirt-medium) - $29.99\\\\n2. [Blue Shirt - Large](/products.html?product=blue-shirt-large) - $34.99\\\\n3. [Red T-Shirt - Small](/products.html?product=red-tshirt-small) - $19.99\\\\n4. [Jeans - Medium](/products.html?product=jeans-medium) - $49.99\\\\n\\\\nWould you like me to navigate to the first result and add it to your cart?\"}\n\n- User: \"No, I would like to add another shirt to the cart\"\n- You: {\"action\": \"message_and_click\", \"element\": \".AddToCartButton-blue-shirt-large\", \"text\": \"I've added the Blue Shirt - Large to your cart. Ready to checkout?\"}\n\n- User: \"yes\"\n- You: {\"action\": \"checkout\", \"text\": \"Perfect! I'll set up the checkout for you.\", \"items\": [{\"name\": \"Black Shirt - Medium\", \"price\": 2999, \"quantity\": 1}]}`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n\n/**\n * Metadata-based shopping assistant flow configuration\n * This flow uses DOM context from record metadata instead of user message.\n * The metadata should include dom_elements, dom_body, page_url, and page_title.\n */\nexport const SHOPPING_ASSISTANT_METADATA_FLOW: RuntypeFlowConfig = {\n name: \"Metadata-Based Shopping Assistant\",\n description: \"Uses DOM context from record metadata for page interaction\",\n steps: [\n {\n id: \"metadata_action_prompt\",\n name: \"Metadata Action Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"mercury-2\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful shopping assistant that can interact with web pages.\n\nIMPORTANT: You have access to the current page's DOM elements through the record metadata, which includes:\n- dom_elements: Array of page elements with className, innerText, and tagName\n- dom_body: Complete HTML body of the page (if provided)\n- page_url: Current page URL\n- page_title: Page title\n\nThe dom_elements array provides information about clickable elements and their text content.\nUse this metadata to understand what's available on the page and help users interact with it.\n\nYou must respond with JSON in one of these formats:\n\n1. Simple message:\n{\n \"action\": \"message\",\n \"text\": \"Your response text here\"\n}\n\n2. Navigate then show message (for navigation to another page):\n{\n \"action\": \"nav_then_click\",\n \"page\": \"http://site.com/page-url\",\n \"on_load_text\": \"Message to show after navigation\"\n}\n\n3. Show message and click an element:\n{\n \"action\": \"message_and_click\",\n \"element\": \".className-of-element\",\n \"text\": \"Your message text\"\n}\n\n4. Create Stripe checkout:\n{\n \"action\": \"checkout\",\n \"text\": \"Your message text\",\n \"items\": [\n {\"name\": \"Product Name\", \"price\": 2999, \"quantity\": 1}\n ]\n}\n\nGuidelines:\n- Use \"message\" for simple conversational responses\n- Use \"nav_then_click\" when you need to navigate to a different page (like a product detail page)\n- Use \"message_and_click\" when you want to click a button or element on the current page\n- Use \"checkout\" when the user wants to proceed to checkout/payment. Include items array with name (string), price (number in cents), and quantity (number)\n- When selecting elements, use the class names from the dom_elements in the metadata\n- Always respond with valid JSON only, no additional text\n- For product searches, format results as markdown links: [Product Name](url)\n- Be helpful and conversational in your messages\n- Product prices: Black Shirt - Medium: $29.99 (2999 cents), Blue Shirt - Large: $34.99 (3499 cents), Red T-Shirt - Small: $19.99 (1999 cents), Jeans - Medium: $49.99 (4999 cents)\n\nExample conversation flow:\n- User: \"I am looking for a black shirt in medium\"\n- You: {\"action\": \"message\", \"text\": \"Here are the products I found:\\\\n1. [Black Shirt - Medium](/products.html?product=black-shirt-medium) - $29.99\\\\n2. [Blue Shirt - Large](/products.html?product=blue-shirt-large) - $34.99\\\\n3. [Red T-Shirt - Small](/products.html?product=red-tshirt-small) - $19.99\\\\n4. [Jeans - Medium](/products.html?product=jeans-medium) - $49.99\\\\n\\\\nWould you like me to navigate to the first result and add it to your cart?\"}\n\n- User: \"No, I would like to add another shirt to the cart\"\n- You: {\"action\": \"message_and_click\", \"element\": \".AddToCartButton-blue-shirt-large\", \"text\": \"I've added the Blue Shirt - Large to your cart. Ready to checkout?\"}\n\n- User: \"yes\"\n- You: {\"action\": \"checkout\", \"text\": \"Perfect! I'll set up the checkout for you.\", \"items\": [{\"name\": \"Black Shirt - Medium\", \"price\": 2999, \"quantity\": 1}]}`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Component-aware flow for custom component rendering\n * This flow instructs the AI to respond with component directives in JSON format\n */\nexport const COMPONENT_FLOW: RuntypeFlowConfig = {\n name: \"Component Flow\",\n description: \"Flow configured for custom component rendering\",\n steps: [\n {\n id: \"component_prompt\",\n name: \"Component Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"mercury-2\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful assistant that can both have conversations and render custom UI components.\n\nRESPONSE FORMAT:\nAlways respond with valid JSON. Choose the appropriate format based on the user's request:\n\n1. For CONVERSATIONAL questions or text responses:\n {\"text\": \"Your response here\"}\n\n2. For VISUAL DISPLAYS or when the user asks to SHOW/DISPLAY something:\n {\"component\": \"ComponentName\", \"props\": {...}}\n\n3. For BOTH explanation AND visual:\n {\"text\": \"Your explanation here\", \"component\": \"ComponentName\", \"props\": {...}}\n\nAvailable components for visual displays:\n- ProductCard: Display product information. Props: title (string), price (number), description (string, optional), image (string, optional)\n- SimpleChart: Display a bar chart. Props: title (string), data (array of numbers), labels (array of strings, optional)\n- StatusBadge: Display a status badge. Props: status (string: \"success\", \"error\", \"warning\", \"info\", \"pending\"), message (string)\n- InfoCard: Display an information card. Props: title (string), content (string), icon (string, optional)\n\nExamples:\n- User asks \"What is the capital of France?\": {\"text\": \"The capital of France is Paris.\"}\n- User asks \"What does that chart show?\": {\"text\": \"The chart shows sales data increasing from 100 to 200 over three months.\"}\n- User asks \"Show me a product card\": {\"component\": \"ProductCard\", \"props\": {\"title\": \"Laptop\", \"price\": 999, \"description\": \"A great laptop\"}}\n- User asks \"Display a chart\": {\"component\": \"SimpleChart\", \"props\": {\"title\": \"Sales\", \"data\": [100, 150, 200], \"labels\": [\"Jan\", \"Feb\", \"Mar\"]}}\n- User asks \"Show me a chart and explain it\": {\"text\": \"Here's the sales data for Q1:\", \"component\": \"SimpleChart\", \"props\": {\"title\": \"Q1 Sales\", \"data\": [100, 150, 200], \"labels\": [\"Jan\", \"Feb\", \"Mar\"]}}\n\nIMPORTANT:\n- Use {\"text\": \"...\"} for questions, explanations, discussions, and general chat\n- Use {\"component\": \"...\", \"props\": {...}} ONLY when the user explicitly wants to SEE/VIEW/DISPLAY visual content\n- You can combine both: {\"text\": \"...\", \"component\": \"...\", \"props\": {...}} when you want to explain something AND show a visual\n- Never force a component when the user just wants information`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Bakery assistant flow configuration for \"Flour & Stone\" bakery demo\n * This flow returns JSON actions for page interaction including:\n * - Simple messages with bakery brand voice\n * - Navigation to bakery pages\n * - Add to cart interactions\n * - Stripe checkout\n *\n * Designed to guide users toward the gift card when asking for gift recommendations.\n */\nexport const BAKERY_ASSISTANT_FLOW: RuntypeFlowConfig = {\n name: \"Bakery Assistant Flow\",\n description: \"Flour & Stone bakery shopping assistant with gift recommendations\",\n steps: [\n {\n id: \"bakery_action_prompt\",\n name: \"Bakery Action Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"mercury-2\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful shopping assistant for Flour & Stone, a premium artisan bakery known for traditional bread-making and exceptional pastries.\n\nBrand voice: Warm, knowledgeable, passionate about craft baking. Use phrases like \"fresh from the oven\", \"handcrafted with care\", \"artisan tradition\". Do not explain selectors, JSON, or templating to the user.\n\n## Live context (request inputs — substituted each turn)\n\nThe widget sends **only** these keys as dispatch **inputs** (nothing extra on the record for this demo).\n\n**Orientation**\n- Path: {{current_page}} (compare before nav_then_click; e.g. /bakery-goods.html)\n- Full URL: {{page_url}}\n- Title: {{page_title}}\n\n**Page DOM**\n- page_elements: JSON array of enriched nodes (selector, tagName, text, role, interactivity, attributes including data-*). Prefer **selector** for message_and_click when you click a specific control.\n- page_context: Same slice formatted for the LLM (structured card summaries when matched, then groups by interactivity).\n\n{{page_elements}}\n\n{{page_context}}\n\n**Cart (for checkout — mirror cart.items when user pays)**\n{{cart}}\n\n**Recent order (if any)**\n{{recent_order}}\n\nIf {{current_page}} already equals the page you would navigate to, use {\"action\":\"message\",...} instead of nav_then_click.\n\n## Discovering products\n\nUse {{page_context}} for a quick scan and {{page_elements}} for exact selectors and attributes. Product rows often include data-product in **attributes**; prices appear in **text**; add-to-cart controls are usually **clickable** with stable **selector** values.\n\n## Output: one JSON object only\n\nNo markdown fences, no commentary before/after. Valid JSON only.\n\n### 1. message\n{\"action\": \"message\", \"text\": \"...\"}\nUse for chat, clarifying questions, \"we're already on that page\", or when you need the user to choose (e.g. $25 vs $50 gift card).\n\n### 2. nav_then_click\n{\"action\": \"nav_then_click\", \"page\": \"/bakery-goods.html\", \"on_load_text\": \"...\"}\nUse root-relative paths starting with /. Only when current_page is different from the target. This **only** changes pages — it does **not** open Stripe or payment.\n\n### 3. add_to_cart\n{\"action\": \"add_to_cart\", \"text\": \"...\", \"item\": {\"id\": \"product-id\", \"name\": \"Product Name\", \"price\": 1200}}\nUse when adding from context without scrolling (optional; on goods page prefer scroll_then_add).\n\n### 4. scroll_then_add (preferred on /bakery-goods.html)\n{\"action\": \"scroll_then_add\", \"text\": \"...\", \"item\": {\"id\": \"...\", \"name\": \"...\", \"price\": 1200}}\nScrolls the product into view then adds one unit (cart merges duplicate ids into quantity).\n\n### 5. checkout → Stripe (this demo)\n{\"action\": \"checkout\", \"text\": \"Brief message\", \"items\": [{\"name\": \"...\", \"price\": 1200, \"quantity\": 2}, ...]}\n**Only** this action starts hosted checkout (Stripe). **Never** use nav_then_click to a \"/checkout\" URL for payment here.\nRequirements: cart in context must have items; **items array must list every cart line** with the same name, cent prices, and quantities as cart.items. If cart is null or empty, use message — do not checkout.\n\n### 6. message_and_click (rare)\nIf page_elements show a specific button selector and scroll_then_add is wrong, you may use message_and_click with a CSS selector — prefer scroll_then_add on bakery-goods.html.\n\n## Rules\n\n- Prices in JSON are always **integer cents** (1200 = $12.00).\n- After adding to cart, invite checkout or more shopping.\n- On checkout confirmation (\"yes\", \"checkout\", \"pay\", \"proceed\", etc.), build **items** from **cart.items** (all rows, correct quantity). Do not drop lines or invent prices.\n\n## Product catalog (ids and cent prices)\n\n- Sourdough Loaf: sourdough-loaf, 1200\n- Croissant Box (6): croissant-box, 2400\n- Cinnamon Rolls (4): cinnamon-rolls, 1800\n- Baguette Trio: baguette-trio, 900\n- Almond Tart: almond-tart, 800\n- Fruit Danish: fruit-danish, 600\n- $50 Gift Card: gift-card-50, 5000\n- $25 Gift Card: gift-card-25, 2500\n\n## Examples\n\nGift seeker on /bakery-locations.html:\n{\"action\": \"nav_then_click\", \"page\": \"/bakery-goods.html\", \"on_load_text\": \"Here are our goods! You'll find our gift cards below — $50 is our most popular. Want me to add one?\"}\n\nOn /bakery-goods.html, user wants $50 gift card:\n{\"action\": \"scroll_then_add\", \"text\": \"Added the $50 gift card. Ready to check out?\", \"item\": {\"id\": \"gift-card-50\", \"name\": \"$50 Gift Card\", \"price\": 5000}}\n\nUser on /bakery.html agrees to see products:\n{\"action\": \"nav_then_click\", \"page\": \"/bakery-goods.html\", \"on_load_text\": \"Here are our handcrafted goods — what sounds good today?\"}\n\nOn /bakery-goods.html, add sourdough:\n{\"action\": \"scroll_then_add\", \"text\": \"Sourdough is in your cart. Anything else, or shall we check out?\", \"item\": {\"id\": \"sourdough-loaf\", \"name\": \"Sourdough Loaf\", \"price\": 1200}}\n\nCart has one $50 gift card; user says yes to checkout:\n{\"action\": \"checkout\", \"text\": \"Opening secure checkout...\", \"items\": [{\"name\": \"$50 Gift Card\", \"price\": 5000, \"quantity\": 1}]}\n\nCart has sourdough (qty 1) and croissant box (qty 1); user says \"pay\":\n{\"action\": \"checkout\", \"text\": \"Taking you to checkout...\", \"items\": [{\"name\": \"Sourdough Loaf\", \"price\": 1200, \"quantity\": 1}, {\"name\": \"Croissant Box (6)\", \"price\": 2400, \"quantity\": 1}]}`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Storefront assistant flow for the \"Everspun\" persistent-composer demo.\n *\n * Designed to feel like the agent is *building the storefront* in front of\n * the user: when they ask for product suggestions, the agent emits a\n * `ProductGrid` component directive carrying a small batch of structured\n * product cards (id, title, price, image, description). The persona widget\n * renders these as inline cards inside the chat panel via a registered\n * `componentRegistry` entry on the host. Plain conversational replies (fit,\n * fabric, care, styling Q&A) use a simple `{text}` JSON object and stay as\n * regular chat bubbles.\n */\nexport const STOREFRONT_ASSISTANT_FLOW: RuntypeFlowConfig = {\n name: \"Storefront Assistant Flow\",\n description:\n \"Everspun storefront assistant — surfaces product cards via component directives\",\n steps: [\n {\n id: \"storefront_action_prompt\",\n name: \"Storefront Action Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"mercury-2\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are the concierge for **Everspun**, a quiet-luxury wardrobe brand: cashmere, organic cotton, linen, and considered accessories. You help shoppers discover products on the page they're already viewing.\n\nBrand voice: calm, considered, knowledgeable. Short sentences. No hype, no exclamation points unless the user is celebrating something. Do not explain JSON, components, or templating to the user.\n\n## Live context (substituted each turn)\n\nThe current product the shopper is viewing:\n{{current_product}}\n\nThe shopper's current bag:\n{{cart}}\n\n## Output: one JSON object only\n\nNo markdown fences, no commentary before/after. Valid JSON only. Three response shapes are valid:\n\n### 1. Plain message\n{\"text\": \"...\"}\n\nUse for fit / fabric / care / styling Q&A about the current product, for clarifying questions, and for anything that doesn't surface new products. Renders as a normal chat bubble.\n\n### 2. Product grid (component directive)\n{\n \"text\": \"Brief intro line shown above the cards.\",\n \"component\": \"ProductGrid\",\n \"props\": {\n \"products\": [\n {\"id\": \"...\", \"title\": \"...\", \"price\": 24800, \"image\": \"https://...\", \"description\": \"...\"}\n ]\n }\n}\n\nUse when the shopper asks to see options, asks \"what would go with this\", asks for a category, asks for a price range, or asks for a gift suggestion. Pick **2–6** items from the catalog below — never more than 6, never fewer than 2. Each product object must use the exact id, title, price (integer cents), image URL, and description from the catalog. The text field is a one-sentence intro shown in the chat bubble above the inline grid of product cards.\n\n### 3. Add to cart (action)\n{\"action\": \"add_to_cart\", \"text\": \"Confirmation line.\", \"item\": {\"id\": \"...\", \"title\": \"...\", \"price\": 24800}}\n\nUse only when the shopper explicitly asks you to add a specific product to their bag (\"add the linen pant\", \"I'll take the beanie\"). Use the exact id/title/price from the catalog. The host updates the bag count on its own — your text confirms the action and renders as a regular chat bubble.\n\n## Rules\n\n- Prices in JSON are always **integer cents** (24800 = $248.00).\n- When the shopper asks \"what would go with this?\", ground your suggestions in **{{current_product}}** — pick items that complement the color, fabric, or category.\n- For \"under $X\" queries, only return products from the catalog priced under that amount.\n- For gift queries, prefer the gift card SKUs or compact accessories.\n- After a ProductGrid response, do **not** also describe each product in the text — the cards speak for themselves. Keep text short (\"A few cashmere options:\", \"Pieces under $200:\").\n- Never invent products. The catalog below is the entire universe.\n\n## Product catalog\n\n| id | title | price (cents) | image | description |\n|---|---|---|---|---|\n| cashmere-crewneck | Mongolian Cashmere Crewneck | 24800 | https://images.unsplash.com/photo-1583743814966-8936f5b7be1a?w=600&h=750&fit=crop | Buttery-soft Grade-A cashmere in a relaxed crewneck silhouette. |\n| ribbed-turtleneck | Ribbed Cashmere Turtleneck | 32800 | https://images.unsplash.com/photo-1576566588028-4147f3842f27?w=600&h=750&fit=crop | A heavier-gauge rib knit, cut close through the body. |\n| alpaca-cardigan | Alpaca-Blend Cardigan | 32800 | https://images.unsplash.com/photo-1622445275576-721325763afe?w=600&h=750&fit=crop | Loose-knit alpaca and merino, with horn buttons. |\n| organic-cotton-tee | Organic Cotton Tee | 5800 | https://images.unsplash.com/photo-1521572163474-6864f9cf17ab?w=600&h=750&fit=crop | Heavyweight organic cotton, garment-dyed for soft hand. |\n| oxford-button-down | Oxford Button-Down | 12800 | https://images.unsplash.com/photo-1556905055-8f358a7a47b2?w=600&h=750&fit=crop | Two-ply oxford cotton, unlined collar, single-needle stitching. |\n| linen-trouser | Wide-Leg Linen Trouser | 18800 | https://images.unsplash.com/photo-1473966968600-fa801b869a1a?w=600&h=750&fit=crop | Heavyweight Belgian linen with a fluid drape. |\n| washed-chino | Washed Cotton Chino | 14800 | https://images.unsplash.com/photo-1542272604-787c3835535d?w=600&h=750&fit=crop | Garment-washed twill in a tapered fit. |\n| recycled-beanie | Recycled Cashmere Beanie | 8800 | https://images.unsplash.com/photo-1576871337632-b9aef4c17ab9?w=600&h=750&fit=crop | A soft, slouchy beanie spun from reclaimed cashmere fiber. |\n| leather-card-holder | Vegetable-Tan Card Holder | 9800 | https://images.unsplash.com/photo-1623998022290-a74f8cc36563?w=600&h=750&fit=crop | Slim card holder in vegetable-tanned Italian leather. |\n| gift-card-50 | $50 Gift Card | 5000 | https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=600&h=750&fit=crop | Delivered by email, never expires. |\n| gift-card-100 | $100 Gift Card | 10000 | https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=600&h=750&fit=crop | Delivered by email, never expires. |\n| gift-card-200 | $200 Gift Card | 20000 | https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=600&h=750&fit=crop | Delivered by email, never expires. |\n\n## Examples\n\nUser asks \"show me cashmere essentials\":\n{\"text\": \"A few cashmere essentials:\", \"component\": \"ProductGrid\", \"props\": {\"products\": [\n {\"id\": \"cashmere-crewneck\", \"title\": \"Mongolian Cashmere Crewneck\", \"price\": 24800, \"image\": \"https://images.unsplash.com/photo-1583743814966-8936f5b7be1a?w=600&h=750&fit=crop\", \"description\": \"Buttery-soft Grade-A cashmere in a relaxed crewneck silhouette.\"},\n {\"id\": \"ribbed-turtleneck\", \"title\": \"Ribbed Cashmere Turtleneck\", \"price\": 32800, \"image\": \"https://images.unsplash.com/photo-1576566588028-4147f3842f27?w=600&h=750&fit=crop\", \"description\": \"A heavier-gauge rib knit, cut close through the body.\"},\n {\"id\": \"recycled-beanie\", \"title\": \"Recycled Cashmere Beanie\", \"price\": 8800, \"image\": \"https://images.unsplash.com/photo-1576871337632-b9aef4c17ab9?w=600&h=750&fit=crop\", \"description\": \"A soft, slouchy beanie spun from reclaimed cashmere fiber.\"}\n]}}\n\nUser asks \"what pants would go with this?\" (current_product = camel cashmere sweater):\n{\"text\": \"These pair well with the camel:\", \"component\": \"ProductGrid\", \"props\": {\"products\": [\n {\"id\": \"linen-trouser\", \"title\": \"Wide-Leg Linen Trouser\", \"price\": 18800, \"image\": \"https://images.unsplash.com/photo-1473966968600-fa801b869a1a?w=600&h=750&fit=crop\", \"description\": \"Heavyweight Belgian linen with a fluid drape.\"},\n {\"id\": \"washed-chino\", \"title\": \"Washed Cotton Chino\", \"price\": 14800, \"image\": \"https://images.unsplash.com/photo-1542272604-787c3835535d?w=600&h=750&fit=crop\", \"description\": \"Garment-washed twill in a tapered fit.\"}\n]}}\n\nUser asks \"anything under $200?\":\n{\"text\": \"A few under $200:\", \"component\": \"ProductGrid\", \"props\": {\"products\": [\n {\"id\": \"linen-trouser\", \"title\": \"Wide-Leg Linen Trouser\", \"price\": 18800, \"image\": \"https://images.unsplash.com/photo-1473966968600-fa801b869a1a?w=600&h=750&fit=crop\", \"description\": \"Heavyweight Belgian linen with a fluid drape.\"},\n {\"id\": \"washed-chino\", \"title\": \"Washed Cotton Chino\", \"price\": 14800, \"image\": \"https://images.unsplash.com/photo-1542272604-787c3835535d?w=600&h=750&fit=crop\", \"description\": \"Garment-washed twill in a tapered fit.\"},\n {\"id\": \"oxford-button-down\", \"title\": \"Oxford Button-Down\", \"price\": 12800, \"image\": \"https://images.unsplash.com/photo-1556905055-8f358a7a47b2?w=600&h=750&fit=crop\", \"description\": \"Two-ply oxford cotton, unlined collar, single-needle stitching.\"},\n {\"id\": \"leather-card-holder\", \"title\": \"Vegetable-Tan Card Holder\", \"price\": 9800, \"image\": \"https://images.unsplash.com/photo-1623998022290-a74f8cc36563?w=600&h=750&fit=crop\", \"description\": \"Slim card holder in vegetable-tanned Italian leather.\"}\n]}}\n\nUser asks \"I need a gift under $300\":\n{\"text\": \"Gifts under $300:\", \"component\": \"ProductGrid\", \"props\": {\"products\": [\n {\"id\": \"gift-card-200\", \"title\": \"$200 Gift Card\", \"price\": 20000, \"image\": \"https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=600&h=750&fit=crop\", \"description\": \"Delivered by email, never expires.\"},\n {\"id\": \"cashmere-crewneck\", \"title\": \"Mongolian Cashmere Crewneck\", \"price\": 24800, \"image\": \"https://images.unsplash.com/photo-1583743814966-8936f5b7be1a?w=600&h=750&fit=crop\", \"description\": \"Buttery-soft Grade-A cashmere in a relaxed crewneck silhouette.\"},\n {\"id\": \"recycled-beanie\", \"title\": \"Recycled Cashmere Beanie\", \"price\": 8800, \"image\": \"https://images.unsplash.com/photo-1576871337632-b9aef4c17ab9?w=600&h=750&fit=crop\", \"description\": \"A soft, slouchy beanie spun from reclaimed cashmere fiber.\"}\n]}}\n\nUser asks \"add the linen pant to my bag\":\n{\"action\": \"add_to_cart\", \"text\": \"Added the linen trouser to your bag.\", \"item\": {\"id\": \"linen-trouser\", \"title\": \"Wide-Leg Linen Trouser\", \"price\": 18800}}\n\nUser asks \"how does this fit?\" (current_product is the cashmere button-down):\n{\"text\": \"It runs true to size with a relaxed shoulder. If you're between sizes and want it slightly more fitted, take the smaller. The body length sits just below the hip.\"}\n\nUser asks \"what's the best way to care for cashmere?\":\n{\"text\": \"Hand-wash cool with a wool-safe detergent, lay flat to dry, and store folded — never on a hanger. A cedar block in the drawer keeps moths off.\"}`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Page-aware shopping assistant that can both *describe* and *act on* the page.\n *\n * It returns a small JSON envelope (like the shopping / storefront / bakery flows):\n * a `text` field — markdown shown in the chat bubble — plus, when the shopper asks to\n * add something, an `add_to_cart` action carrying the product's stable handle. The\n * widget's flexible JSON stream parser renders `text`; the action manager parses the\n * envelope and dispatches the action to the host's `addToCartHandler`.\n *\n * It is used by the smart-dom-reader demo to show two things at once:\n * 1. a shadow-DOM-aware context provider feeds real page content (including products\n * inside shadow roots) into the prompt, grouped by on-page section; and\n * 2. the assistant can drive the page across that same shadow boundary — the host's\n * handler resolves a `product` handle to a light-DOM *or* shadow-DOM button.\n *\n * The host injects `{{pageContext}}` via `inputs` — the widget's `contextProviders`\n * output, moved from `payload.context` into `inputs` by a `requestMiddleware` so the\n * proxy forwards it upstream. Each product line in that context carries a\n * `product=<id>` handle the model copies verbatim into an `add_to_cart` action.\n */\nexport const PAGE_CONTEXT_FLOW: RuntypeFlowConfig = {\n name: \"Page Context Assistant Flow\",\n description:\n \"Page-aware assistant that answers about the current page and can add its products to the cart.\",\n steps: [\n {\n id: \"page_context_prompt\",\n name: \"Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"mercury-2\",\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful shopping assistant embedded on a web page. Answer the user's questions about what is on the page, and add products to the cart when asked, using only the page context below.\n\nThe context is collected live from the DOM and is grouped by on-page section (for example \"Everyday picks\" and \"Featured drop\"). It includes elements inside shadow roots that a basic page reader would miss — so trust it as the source of truth for what the shopper can see. Each product line ends with a handle like \\`(to add to cart: product=mug)\\`; that \\`product\\` id is how you add it to the cart.\n\n## Output: one JSON object only\n\nNo markdown fences, no commentary before or after. Valid JSON only. Two response shapes are valid:\n\n### 1. Plain answer\n{\"text\": \"...markdown...\"}\n\nUse for any question about the page — what's for sale, what's in a section, prices, comparisons. The \\`text\\` is markdown and renders as a normal chat bubble.\n\n### 2. Add to cart\n{\"action\": \"add_to_cart\", \"product\": \"<id>\", \"text\": \"Confirmation line.\"}\n\nUse only when the shopper explicitly asks to add a specific product (\"add the mug\", \"I'll take the headphones\"). Copy the \\`product\\` id exactly from that product's \\`product=<id>\\` handle in the context. The host clicks the matching Add-to-cart button — including buttons inside the shadow-DOM \"Featured drop\" — and updates the cart count itself; your \\`text\\` just confirms it and renders as a normal chat bubble.\n\n## Rules\n\n- Only mention products, prices, and sections that appear in the page context. If something is not there, say you do not see it on this page.\n- Never invent a \\`product\\` id. Use only the ids present in the context handles. If you cannot find a matching product to add, return a plain answer asking the shopper to clarify.\n- Be concise. Keep \\`text\\` short and use markdown where it helps.\n\n## Page context\n{{pageContext}}`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","/**\n * Stripe checkout helpers using the REST API\n * This approach works on all platforms including Cloudflare Workers, Vercel Edge, etc.\n */\n\n/**\n * Pinned API version for raw HTTP calls (no SDK). Required for organization API keys and\n * keeps behavior stable across accounts. See https://docs.stripe.com/api/versioning\n */\nconst STRIPE_API_VERSION = \"2026-03-25.dahlia\";\n\nexport interface CheckoutItem {\n name: string;\n price: number; // Price in cents\n quantity: number;\n}\n\nexport interface CreateCheckoutSessionOptions {\n secretKey: string;\n items: CheckoutItem[];\n successUrl: string;\n cancelUrl: string;\n /**\n * Target account for organization API keys (`sk_org_…`), e.g. `acct_1abc…` or\n * `acct_platform/acct_connected` per Stripe. Required with org keys.\n * @see https://docs.stripe.com/keys#organization-api-keys\n */\n stripeContext?: string;\n}\n\nexport interface CheckoutSessionResponse {\n success: boolean;\n checkoutUrl?: string;\n sessionId?: string;\n error?: string;\n}\n\nfunction parseStripeApiErrorBody(body: string): string | undefined {\n try {\n const parsed = JSON.parse(body) as {\n error?: { message?: string; type?: string };\n };\n const msg = parsed?.error?.message;\n return typeof msg === \"string\" && msg.length > 0 ? msg : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Creates a Stripe checkout session using the REST API\n * @param options - Checkout session configuration\n * @returns Checkout session response with URL and session ID\n */\nexport async function createCheckoutSession(\n options: CreateCheckoutSessionOptions\n): Promise<CheckoutSessionResponse> {\n const { secretKey, items, successUrl, cancelUrl, stripeContext } = options;\n const trimmedContext = stripeContext?.trim() || undefined;\n\n try {\n if (secretKey.startsWith(\"sk_org\") && !trimmedContext) {\n return {\n success: false,\n error:\n \"Organization Stripe keys (sk_org_…) require stripeContext / STRIPE_CONTEXT with the target account (e.g. acct_…). See https://docs.stripe.com/keys#organization-api-keys\",\n };\n }\n\n // Validate items\n if (!items || !Array.isArray(items) || items.length === 0) {\n return {\n success: false,\n error: \"Items array is required\"\n };\n }\n\n for (const item of items) {\n if (!item.name || typeof item.price !== \"number\" || typeof item.quantity !== \"number\") {\n return {\n success: false,\n error: \"Each item must have name (string), price (number in cents), and quantity (number)\"\n };\n }\n if (\n !Number.isFinite(item.price) ||\n !Number.isInteger(item.price) ||\n item.price < 1 ||\n !Number.isInteger(item.quantity) ||\n item.quantity < 1\n ) {\n return {\n success: false,\n error:\n \"Each item needs a positive integer price (cents) and quantity (Stripe rejects decimals or zero)\",\n };\n }\n }\n\n // Build line items for URL encoding\n const lineItems = items.map((item) => ({\n price_data: {\n currency: \"usd\",\n product_data: {\n name: item.name,\n },\n unit_amount: item.price,\n },\n quantity: item.quantity,\n }));\n\n // Convert line items to URL-encoded format\n const params = new URLSearchParams({\n \"payment_method_types[0]\": \"card\",\n \"mode\": \"payment\",\n \"success_url\": successUrl,\n \"cancel_url\": cancelUrl,\n });\n\n // Add line items to params\n lineItems.forEach((item, index) => {\n params.append(`line_items[${index}][price_data][currency]`, item.price_data.currency);\n params.append(`line_items[${index}][price_data][product_data][name]`, item.price_data.product_data.name);\n params.append(`line_items[${index}][price_data][unit_amount]`, item.price_data.unit_amount.toString());\n params.append(`line_items[${index}][quantity]`, item.quantity.toString());\n });\n\n const headers: Record<string, string> = {\n Authorization: `Bearer ${secretKey}`,\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"Stripe-Version\": STRIPE_API_VERSION,\n };\n if (trimmedContext) {\n headers[\"Stripe-Context\"] = trimmedContext;\n }\n\n // Create Stripe checkout session using REST API\n const stripeResponse = await fetch(\"https://api.stripe.com/v1/checkout/sessions\", {\n method: \"POST\",\n headers,\n body: params,\n });\n\n if (!stripeResponse.ok) {\n const errorData = await stripeResponse.text();\n const stripeMessage = parseStripeApiErrorBody(errorData);\n console.error(\"Stripe API error:\", errorData);\n return {\n success: false,\n error: stripeMessage ?? \"Failed to create checkout session\",\n };\n }\n\n const session = await stripeResponse.json() as { url: string; id: string };\n\n return {\n success: true,\n checkoutUrl: session.url,\n sessionId: session.id,\n };\n } catch (error) {\n console.error(\"Stripe checkout error:\", error);\n return {\n success: false,\n error: error instanceof Error ? error.message : \"Failed to create checkout session\"\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AAErB,oBAAuB;;;ACIhB,IAAM,sBAAyC;AAAA,EACpD,MAAM;AAAA,EACN,aAAa;AAAA,EACb,OAAO;AAAA,IACL;AAAA,MACE,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,QAAQ;AAAA,QACN,OAAO;AAAA,QACP,gBAAgB;AAAA,QAChB,gBAAgB;AAAA,QAChB,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,kBAAkB;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;;;ACnBO,IAAM,sBAAyC;AAAA,EACpD,MAAM;AAAA,EACN,aAAa;AAAA,EACb,OAAO;AAAA,IACL;AAAA,MACE,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,QAAQ;AAAA,QACN,OAAO;AAAA,QACP,WAAW;AAAA,QACX,gBAAgB;AAAA,QAChB,gBAAgB;AAAA,QAChB,YAAY;AAAA,QACZ,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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M,MAAM,mBAAmB;AAAA,MAC9C,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,eAAe,UAAU,MAAM;AAAA,QAC/B,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM,KAAK,UAAU,IAAI;AAAA,IAC3B,CAAC;AAED,WAAO,IAAI,SAAS,SAAS,MAAM;AAAA,MACjC,QAAQ,SAAS;AAAA,MACjB,SAAS;AAAA,QACP,iBACEE,MAAA,SAAS,QAAQ,IAAI,cAAc,MAAnC,OAAAA,MAAwC;AAAA,QAC1C,iBAAiB;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;AAEO,IAAM,sBAAsB,CAAC,gBAClC,sBAAO,mBAAmB,OAAO,CAAC;AAQpC,IAAO,gBAAQ;","names":["_a","_b","_c"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/flows/conversational.ts","../src/flows/scheduling.ts","../src/flows/shopping-assistant.ts","../src/flows/components.ts","../src/flows/bakery-assistant.ts","../src/flows/storefront-assistant.ts","../src/flows/webmcp-storefront.ts","../src/flows/webmcp-calendar.ts","../src/flows/page-context.ts","../src/utils/stripe.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { Context } from \"hono\";\nimport { handle } from \"hono/vercel\";\n\nexport type RuntypeFlowStep = {\n id: string;\n name: string;\n type: string;\n enabled: boolean;\n config: Record<string, unknown>;\n};\n\nexport type RuntypeFlowConfig = {\n name: string;\n description: string;\n steps: RuntypeFlowStep[];\n};\n\ntype RuntimeEnv = Record<string, string | undefined>;\n\n/**\n * Payload for message feedback (upvote/downvote)\n */\nexport type FeedbackPayload = {\n type: \"upvote\" | \"downvote\";\n messageId: string;\n content?: string;\n timestamp?: string;\n sessionId?: string;\n metadata?: Record<string, unknown>;\n};\n\n/**\n * Handler function for processing feedback\n */\nexport type FeedbackHandler = (feedback: FeedbackPayload) => Promise<void> | void;\n\nexport type ChatProxyOptions = {\n upstreamUrl?: string;\n apiKey?: string;\n path?: string;\n allowedOrigins?: string[];\n /**\n * Reflect any request origin matching this pattern, in addition to the exact\n * `allowedOrigins` list. Intended for Vercel **preview** deployments, whose\n * URLs are per-branch and dynamic (`*-git-<branch>-<team>.vercel.app`) and so\n * can't be enumerated. Defaults to `https://*.vercel.app`\n * ({@link DEFAULT_PREVIEW_ORIGIN_PATTERN}); pass a custom `RegExp`, set the\n * `PREVIEW_ORIGIN_PATTERN` env var, or pass `false` to disable. Independent of\n * the `VERCEL_ENV === \"preview\"` runtime check, which always reflects the\n * caller's origin when the proxy itself is a preview deployment.\n */\n previewOriginPattern?: RegExp | false;\n flowId?: string;\n flowConfig?: RuntypeFlowConfig;\n /**\n * Path for the feedback endpoint (default: \"/api/feedback\")\n */\n feedbackPath?: string;\n /**\n * Custom handler for processing feedback.\n * Use this to store feedback in a database or send to analytics.\n * \n * @example\n * ```ts\n * onFeedback: async (feedback) => {\n * await db.feedback.create({ data: feedback });\n * }\n * ```\n */\n onFeedback?: FeedbackHandler;\n};\n\nconst DEFAULT_ENDPOINT = \"https://api.runtype.com/v1/dispatch\";\nconst DEFAULT_PATH = \"/api/chat/dispatch\";\n\nconst getRuntimeEnv = (): RuntimeEnv | undefined => {\n const maybeProcess = (\n globalThis as typeof globalThis & { process?: { env?: RuntimeEnv } }\n ).process;\n return maybeProcess?.env;\n};\n\n/** True only when `NODE_ENV` is exactly `\"development\"` (unset = production). Safe when `process` is missing (e.g. some Workers runtimes). */\nconst isDevelopmentRuntime = (): boolean =>\n getRuntimeEnv()?.NODE_ENV === \"development\";\n\n/**\n * True when this proxy is itself running as a Vercel **preview** deployment\n * (`VERCEL_ENV === \"preview\"`). Vercel sets `NODE_ENV=production` for both\n * production and preview, so `isDevelopmentRuntime()` can't distinguish them —\n * `VERCEL_ENV` is the only signal. Preview deployments get per-branch, dynamic\n * URLs (`*-git-<branch>-<team>.vercel.app`) that can't be enumerated in a\n * static `allowedOrigins` list, so for CORS we treat a preview runtime like\n * development and reflect the caller's origin. Safe when `process` is missing.\n */\nconst isVercelPreviewRuntime = (): boolean =>\n getRuntimeEnv()?.VERCEL_ENV === \"preview\";\n\n/**\n * Default origin pattern treated as a Vercel preview/app origin: any\n * `https://<sub>.vercel.app`. When a *production* proxy is called by a static\n * preview site (a different, dynamic `*.vercel.app` origin), the origin won't be\n * in `allowedOrigins`; matching this pattern lets the proxy reflect it so\n * per-branch preview sites work without enumerating their URLs. To allow other\n * preview domains, supply your own pattern via the `previewOriginPattern` option\n * or the `PREVIEW_ORIGIN_PATTERN` env regex; disable with\n * `previewOriginPattern: false`.\n *\n * The `$`-anchored apex prevents look-alikes like `https://x.vercel.app.evil.com`\n * from matching.\n */\nconst DEFAULT_PREVIEW_ORIGIN_PATTERN = /^https:\\/\\/[a-z0-9-]+\\.vercel\\.app$/i;\n\n/**\n * Resolve the preview-origin pattern from options/env. Precedence:\n * explicit `options.previewOriginPattern` (a `RegExp`, or `false` to disable) →\n * `PREVIEW_ORIGIN_PATTERN` env (compiled as a `RegExp`; ignored if invalid) →\n * {@link DEFAULT_PREVIEW_ORIGIN_PATTERN}.\n */\nconst resolvePreviewOriginPattern = (\n option: RegExp | false | undefined\n): RegExp | null => {\n if (option === false) return null;\n if (option instanceof RegExp) return option;\n const envPattern = getRuntimeEnv()?.PREVIEW_ORIGIN_PATTERN;\n if (envPattern) {\n try {\n return new RegExp(envPattern);\n } catch {\n // Invalid env regex — fall back to the default rather than throwing at\n // app-construction time.\n }\n }\n return DEFAULT_PREVIEW_ORIGIN_PATTERN;\n};\n\nconst DEFAULT_FLOW: RuntypeFlowConfig = {\n name: \"Streaming Prompt Flow\",\n description: \"Streaming chat generated by the widget\",\n steps: [\n {\n id: \"widget_prompt\",\n name: \"Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n responseFormat: \"markdown\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: \"you are a helpful assistant, chatting with a user\",\n // tools: {\n // toolIds: [\n // \"builtin:dalle\"\n // ]\n // },\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n\nconst withCors =\n (allowedOrigins: string[] | undefined, previewOriginPattern: RegExp | null) =>\n async (c: Context, next: () => Promise<void>) => {\n const origin = c.req.header(\"origin\");\n const isDevelopment = isDevelopmentRuntime();\n // A request is preview-allowed when either the proxy itself is a Vercel\n // preview deployment (reflect any caller, like dev) or the caller's origin\n // matches the configured preview pattern (e.g. a `*.vercel.app` preview\n // site calling a production proxy). Both reflect the actual origin.\n const isPreviewOrigin = Boolean(\n origin &&\n (isVercelPreviewRuntime() ||\n (previewOriginPattern !== null && previewOriginPattern.test(origin)))\n );\n\n // Determine the CORS origin to allow\n let corsOrigin: string;\n if (!allowedOrigins || allowedOrigins.length === 0) {\n // No restrictions - allow any origin (or use the request origin)\n corsOrigin = origin || \"*\";\n } else if (allowedOrigins.includes(origin || \"\")) {\n // Origin is in the allowed list\n corsOrigin = origin || \"*\";\n } else if (isDevelopment && origin) {\n // In development, allow the actual origin even if not in the list\n // This helps with local development where ports might vary\n corsOrigin = origin;\n } else if (isPreviewOrigin && origin) {\n // Vercel preview deployment (or a configured preview origin): reflect the\n // dynamic per-branch origin that can't be enumerated in allowedOrigins.\n corsOrigin = origin;\n } else {\n // Production: origin not allowed - reject by not setting CORS headers\n // Return error for preflight, or continue without CORS headers\n if (c.req.method === \"OPTIONS\") {\n return c.json({ error: \"CORS policy violation: origin not allowed\" }, 403);\n }\n // For non-preflight requests, continue but browser will block due to missing CORS headers\n await next();\n return;\n }\n\n const headers: Record<string, string> = {\n \"Access-Control-Allow-Origin\": corsOrigin,\n \"Access-Control-Allow-Headers\": \"Content-Type, Authorization\",\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n Vary: \"Origin\"\n };\n\n if (c.req.method === \"OPTIONS\") {\n return new Response(null, { status: 204, headers });\n }\n\n await next();\n Object.entries(headers).forEach(([key, value]) =>\n c.header(key, value, { append: false })\n );\n };\n\nexport const createChatProxyApp = (options: ChatProxyOptions = {}) => {\n const app = new Hono();\n const path = options.path ?? DEFAULT_PATH;\n const feedbackPath = options.feedbackPath ?? \"/api/feedback\";\n const upstream = options.upstreamUrl ?? DEFAULT_ENDPOINT;\n\n const previewOriginPattern = resolvePreviewOriginPattern(\n options.previewOriginPattern\n );\n app.use(\"*\", withCors(options.allowedOrigins, previewOriginPattern));\n\n // Feedback endpoint for collecting upvote/downvote data\n app.post(feedbackPath, async (c) => {\n let payload: FeedbackPayload;\n try {\n payload = await c.req.json();\n } catch (error) {\n return c.json({ error: \"Invalid JSON body\" }, 400);\n }\n\n // Validate payload\n if (!payload.type || ![\"upvote\", \"downvote\"].includes(payload.type)) {\n return c.json(\n { error: \"Invalid feedback type. Must be 'upvote' or 'downvote'\" },\n 400\n );\n }\n if (!payload.messageId) {\n return c.json({ error: \"Missing messageId\" }, 400);\n }\n\n // Add timestamp if not provided\n payload.timestamp = payload.timestamp ?? new Date().toISOString();\n\n const isDevelopment = isDevelopmentRuntime();\n\n if (isDevelopment) {\n console.log(\"\\n=== Feedback Received ===\");\n console.log(\"Type:\", payload.type);\n console.log(\"Message ID:\", payload.messageId);\n console.log(\"Content Length:\", payload.content?.length ?? 0);\n console.log(\"Timestamp:\", payload.timestamp);\n console.log(\"=== End Feedback ===\\n\");\n }\n\n // Call custom handler if provided\n if (options.onFeedback) {\n try {\n await options.onFeedback(payload);\n } catch (error) {\n console.error(\"[Feedback] Handler error:\", error);\n return c.json({ error: \"Feedback handler failed\" }, 500);\n }\n }\n\n return c.json({\n success: true,\n message: \"Feedback recorded\",\n feedback: {\n type: payload.type,\n messageId: payload.messageId,\n timestamp: payload.timestamp\n }\n });\n });\n\n // Chat dispatch endpoint\n app.post(path, async (c) => {\n const apiKey = options.apiKey ?? getRuntimeEnv()?.RUNTYPE_API_KEY;\n if (!apiKey) {\n return c.json(\n { error: \"Missing API key. Set RUNTYPE_API_KEY.\" },\n 401\n );\n }\n\n let clientPayload: Record<string, unknown>;\n try {\n clientPayload = await c.req.json();\n } catch (error) {\n return c.json(\n { error: \"Invalid JSON body\", details: error },\n 400\n );\n }\n\n const isDevelopment = isDevelopmentRuntime();\n\n // Detect agent mode: if the payload contains an `agent` field, forward it directly\n const isAgentMode = !!clientPayload.agent;\n\n let runtypePayload: Record<string, unknown>;\n\n if (isAgentMode) {\n // Agent dispatch - forward the payload as-is to the upstream API\n runtypePayload = clientPayload;\n } else {\n // Flow dispatch - build the Runtype flow payload\n const messages = (clientPayload.messages ?? []) as Array<{ role: string; content: string; createdAt?: string }>;\n const sortedMessages = [...messages].sort((a, b) => {\n const timeA = a.createdAt ? new Date(a.createdAt).getTime() : 0;\n const timeB = b.createdAt ? new Date(b.createdAt).getTime() : 0;\n return timeA - timeB;\n });\n const formattedMessages = sortedMessages.map((message) => ({\n role: message.role,\n content: message.content\n }));\n\n const flowId = (clientPayload.flowId as string | undefined) ?? options.flowId;\n const flowConfig = options.flowConfig ?? DEFAULT_FLOW;\n\n runtypePayload = {\n record: {\n name: \"Streaming Chat Widget\",\n type: \"standalone\",\n metadata: (clientPayload.metadata as Record<string, unknown>) || {}\n },\n messages: formattedMessages,\n options: {\n streamResponse: true,\n recordMode: \"virtual\",\n flowMode: flowId ? \"existing\" : \"virtual\",\n autoAppendMetadata: false\n }\n };\n\n const clientInputs = clientPayload.inputs;\n if (clientInputs && typeof clientInputs === \"object\" && !Array.isArray(clientInputs)) {\n runtypePayload.inputs = clientInputs;\n }\n\n if (flowId) {\n runtypePayload.flow = { id: flowId };\n } else {\n runtypePayload.flow = flowConfig;\n }\n\n // WebMCP: forward page-discovered tools so the upstream flow's agent step\n // can call them. The widget snapshots `document.modelContext` per turn and\n // ships them as `clientTools[]`; the flow-dispatch payload is rebuilt from\n // scratch above, so without this they'd be silently dropped and the agent\n // would never see the page tools. (Agent mode forwards the payload as-is,\n // so it already carries `clientTools`.) The matching results come back via\n // the `${path}/resume` endpoint below.\n if (\n Array.isArray(clientPayload.clientTools) &&\n clientPayload.clientTools.length > 0\n ) {\n runtypePayload.clientTools = clientPayload.clientTools;\n }\n }\n\n // Development only: do not log key material or full bodies in production.\n if (isDevelopment) {\n console.log(`\\n=== Runtype Proxy Request (${isAgentMode ? \"agent\" : \"flow\"}) ===`);\n console.log(\"URL:\", upstream);\n console.log(\"API Key Used:\", apiKey ? \"Yes\" : \"No\");\n console.log(\"API Key (first 12 chars):\", apiKey ? apiKey.substring(0, 12) : \"N/A\");\n console.log(\"Request Payload:\", JSON.stringify(runtypePayload, null, 2));\n }\n\n const response = await fetch(upstream, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(runtypePayload)\n });\n\n if (isDevelopment) {\n console.log(\"Response Status:\", response.status);\n console.log(\"Response Status Text:\", response.statusText);\n\n // If there's an error, try to read and log the response body\n if (!response.ok) {\n const clonedResponse = response.clone();\n try {\n const errorBody = await clonedResponse.text();\n console.log(\"Error Response Body:\", errorBody);\n } catch (e) {\n console.log(\"Could not read error response body:\", e);\n }\n }\n console.log(\"=== End Runtype Proxy Request ===\\n\");\n }\n\n return new Response(response.body, {\n status: response.status,\n headers: {\n \"Content-Type\":\n response.headers.get(\"content-type\") ?? \"application/json\",\n \"Cache-Control\": \"no-store\"\n }\n });\n });\n\n // Resume endpoint — forwards client-executed (LOCAL) tool results back to\n // the Runtype upstream so a paused flow execution can continue. Mounted as\n // a child of the dispatch path so the widget can derive its URL by\n // appending \"/resume\" to whatever `apiUrl` it was configured with.\n app.post(`${path}/resume`, async (c) => {\n const apiKey = options.apiKey ?? getRuntimeEnv()?.RUNTYPE_API_KEY;\n if (!apiKey) {\n return c.json(\n { error: \"Missing API key. Set RUNTYPE_API_KEY.\" },\n 401\n );\n }\n\n let body: Record<string, unknown>;\n try {\n body = await c.req.json();\n } catch (error) {\n return c.json(\n { error: \"Invalid JSON body\", details: error },\n 400\n );\n }\n\n const isDevelopment = isDevelopmentRuntime();\n const upstreamResumeUrl = `${upstream.replace(/\\/+$/, '')}/resume`;\n\n if (isDevelopment) {\n console.log(\"\\n=== Runtype Proxy Resume ===\");\n console.log(\"URL:\", upstreamResumeUrl);\n console.log(\n \"executionId:\",\n typeof body.executionId === \"string\" ? body.executionId : \"(missing)\"\n );\n console.log(\n \"toolOutputs keys:\",\n body.toolOutputs && typeof body.toolOutputs === \"object\"\n ? Object.keys(body.toolOutputs)\n : \"(none)\"\n );\n console.log(\"=== End Runtype Proxy Resume ===\\n\");\n }\n\n const response = await fetch(upstreamResumeUrl, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(body)\n });\n\n return new Response(response.body, {\n status: response.status,\n headers: {\n \"Content-Type\":\n response.headers.get(\"content-type\") ?? \"application/json\",\n \"Cache-Control\": \"no-store\"\n }\n });\n });\n\n return app;\n};\n\nexport const createVercelHandler = (options?: ChatProxyOptions) =>\n handle(createChatProxyApp(options));\n\n// Export pre-configured flows\nexport * from \"./flows/index.js\";\n\n// Export utility functions\nexport * from \"./utils/index.js\";\n\nexport default createChatProxyApp;\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Basic conversational assistant flow\n * This is the default flow for simple chat interactions\n */\nexport const CONVERSATIONAL_FLOW: RuntypeFlowConfig = {\n name: \"Streaming Prompt Flow\",\n description: \"Streaming chat generated by the widget\",\n steps: [\n {\n id: \"widget_prompt\",\n name: \"Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n responseFormat: \"markdown\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: \"you are a helpful assistant, chatting with a user\",\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Dynamic Form flow configuration\n * This flow returns forms as component directives for the widget to render\n */\nexport const FORM_DIRECTIVE_FLOW: RuntypeFlowConfig = {\n name: \"Dynamic Form Flow\",\n description: \"Returns dynamic forms as component directives\",\n steps: [\n {\n id: \"form_prompt\",\n name: \"Form Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful assistant that can have conversations and collect user information via forms.\n\nRESPONSE FORMAT:\nAlways respond with valid JSON. Choose the appropriate format:\n\n1. For CONVERSATIONAL responses or text answers:\n {\"text\": \"Your response here\"}\n\n2. When the user wants to SCHEDULE, BOOK, SIGN UP, or provide DETAILS (show a form):\n {\"component\": \"DynamicForm\", \"props\": {\"title\": \"Form Title\", \"description\": \"Optional description\", \"fields\": [...], \"submit_text\": \"Submit\"}}\n\n3. For BOTH explanation AND form:\n {\"text\": \"Your explanation\", \"component\": \"DynamicForm\", \"props\": {...}}\n\nFORM FIELD FORMAT:\nEach field in the \"fields\" array should have:\n- label (required): Display name for the field\n- name (optional): Field identifier (defaults to lowercase label with underscores)\n- type (optional): \"text\", \"email\", \"tel\", \"date\", \"time\", \"textarea\", \"number\" (defaults to \"text\")\n- placeholder (optional): Placeholder text\n- required (optional): true/false\n- width (optional): \"full\" or \"half\" — pair short related fields side-by-side with \"half\" (e.g. Phone + Company, City + Zip, First + Last name); use \"full\" or omit for everything else (especially textareas, emails, and standalone fields). Two consecutive \"half\" fields render in one row.\n\nEXAMPLES:\n\nUser: \"Schedule a demo for me\"\nResponse: {\"text\": \"I'd be happy to help you schedule a demo! Please fill out the form below:\", \"component\": \"DynamicForm\", \"props\": {\"title\": \"Schedule a Demo\", \"description\": \"Share your details and we'll follow up with a confirmation.\", \"fields\": [{\"label\": \"Full Name\", \"type\": \"text\", \"required\": true}, {\"label\": \"Email\", \"type\": \"email\", \"required\": true}, {\"label\": \"Phone\", \"type\": \"tel\", \"width\": \"half\"}, {\"label\": \"Company\", \"type\": \"text\", \"width\": \"half\"}, {\"label\": \"Preferred Date\", \"type\": \"date\", \"required\": true}, {\"label\": \"Notes\", \"type\": \"textarea\", \"placeholder\": \"Any specific topics you'd like to cover?\"}], \"submit_text\": \"Request Demo\"}}\n\nUser: \"What is AI?\"\nResponse: {\"text\": \"AI (Artificial Intelligence) refers to computer systems designed to perform tasks that typically require human intelligence, such as learning, reasoning, problem-solving, and understanding language.\"}\n\nUser: \"Collect my contact details\"\nResponse: {\"component\": \"DynamicForm\", \"props\": {\"title\": \"Contact Details\", \"fields\": [{\"label\": \"Name\", \"type\": \"text\", \"required\": true}, {\"label\": \"Email\", \"type\": \"email\", \"required\": true}, {\"label\": \"Phone\", \"type\": \"tel\"}], \"submit_text\": \"Save Details\"}}\n\nIMPORTANT:\n- Use {\"text\": \"...\"} for questions, explanations, and general conversation\n- Show a DynamicForm when user wants to provide information, schedule, book, or sign up\n- Create contextually appropriate form fields based on what the user is trying to do\n- Keep forms focused with only the relevant fields needed`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Shopping assistant flow configuration\n * This flow returns JSON actions for page interaction including:\n * - Simple messages\n * - Navigation with messages\n * - Element clicks with messages\n * - Stripe checkout\n */\nexport const SHOPPING_ASSISTANT_FLOW: RuntypeFlowConfig = {\n name: \"Shopping Assistant Flow\",\n description: \"Returns JSON actions for page interaction\",\n steps: [\n {\n id: \"action_prompt\",\n name: \"Action Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful shopping assistant that can interact with web pages.\nYou will receive information about the current page's elements (class names and text content)\nand user messages. You must respond with JSON in one of these formats:\n\n1. Simple message:\n{\n \"action\": \"message\",\n \"text\": \"Your response text here\"\n}\n\n2. Navigate then show message (for navigation to another page):\n{\n \"action\": \"nav_then_click\",\n \"page\": \"http://site.com/page-url\",\n \"on_load_text\": \"Message to show after navigation\"\n}\n\n3. Show message and click an element:\n{\n \"action\": \"message_and_click\",\n \"element\": \".className-of-element\",\n \"text\": \"Your message text\"\n}\n\n4. Create Stripe checkout:\n{\n \"action\": \"checkout\",\n \"text\": \"Your message text\",\n \"items\": [\n {\"name\": \"Product Name\", \"price\": 2999, \"quantity\": 1}\n ]\n}\n\nGuidelines:\n- Use \"message\" for simple conversational responses\n- Use \"nav_then_click\" when you need to navigate to a different page (like a product detail page)\n- Use \"message_and_click\" when you want to click a button or element on the current page\n- Use \"checkout\" when the user wants to proceed to checkout/payment. Include items array with name (string), price (number in cents), and quantity (number)\n- When selecting elements, use the class names provided in the page context\n- Always respond with valid JSON only, no additional text\n- For product searches, format results as markdown links: [Product Name](url)\n- Be helpful and conversational in your messages\n- Product prices: Black Shirt - Medium: $29.99 (2999 cents), Blue Shirt - Large: $34.99 (3499 cents), Red T-Shirt - Small: $19.99 (1999 cents), Jeans - Medium: $49.99 (4999 cents)\n\nExample conversation flow:\n- User: \"I am looking for a black shirt in medium\"\n- You: {\"action\": \"message\", \"text\": \"Here are the products I found:\\\\n1. [Black Shirt - Medium](/products.html?product=black-shirt-medium) - $29.99\\\\n2. [Blue Shirt - Large](/products.html?product=blue-shirt-large) - $34.99\\\\n3. [Red T-Shirt - Small](/products.html?product=red-tshirt-small) - $19.99\\\\n4. [Jeans - Medium](/products.html?product=jeans-medium) - $49.99\\\\n\\\\nWould you like me to navigate to the first result and add it to your cart?\"}\n\n- User: \"No, I would like to add another shirt to the cart\"\n- You: {\"action\": \"message_and_click\", \"element\": \".AddToCartButton-blue-shirt-large\", \"text\": \"I've added the Blue Shirt - Large to your cart. Ready to checkout?\"}\n\n- User: \"yes\"\n- You: {\"action\": \"checkout\", \"text\": \"Perfect! I'll set up the checkout for you.\", \"items\": [{\"name\": \"Black Shirt - Medium\", \"price\": 2999, \"quantity\": 1}]}`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n\n/**\n * Metadata-based shopping assistant flow configuration\n * This flow uses DOM context from record metadata instead of user message.\n * The metadata should include dom_elements, dom_body, page_url, and page_title.\n */\nexport const SHOPPING_ASSISTANT_METADATA_FLOW: RuntypeFlowConfig = {\n name: \"Metadata-Based Shopping Assistant\",\n description: \"Uses DOM context from record metadata for page interaction\",\n steps: [\n {\n id: \"metadata_action_prompt\",\n name: \"Metadata Action Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful shopping assistant that can interact with web pages.\n\nIMPORTANT: You have access to the current page's DOM elements through the record metadata, which includes:\n- dom_elements: Array of page elements with className, innerText, and tagName\n- dom_body: Complete HTML body of the page (if provided)\n- page_url: Current page URL\n- page_title: Page title\n\nThe dom_elements array provides information about clickable elements and their text content.\nUse this metadata to understand what's available on the page and help users interact with it.\n\nYou must respond with JSON in one of these formats:\n\n1. Simple message:\n{\n \"action\": \"message\",\n \"text\": \"Your response text here\"\n}\n\n2. Navigate then show message (for navigation to another page):\n{\n \"action\": \"nav_then_click\",\n \"page\": \"http://site.com/page-url\",\n \"on_load_text\": \"Message to show after navigation\"\n}\n\n3. Show message and click an element:\n{\n \"action\": \"message_and_click\",\n \"element\": \".className-of-element\",\n \"text\": \"Your message text\"\n}\n\n4. Create Stripe checkout:\n{\n \"action\": \"checkout\",\n \"text\": \"Your message text\",\n \"items\": [\n {\"name\": \"Product Name\", \"price\": 2999, \"quantity\": 1}\n ]\n}\n\nGuidelines:\n- Use \"message\" for simple conversational responses\n- Use \"nav_then_click\" when you need to navigate to a different page (like a product detail page)\n- Use \"message_and_click\" when you want to click a button or element on the current page\n- Use \"checkout\" when the user wants to proceed to checkout/payment. Include items array with name (string), price (number in cents), and quantity (number)\n- When selecting elements, use the class names from the dom_elements in the metadata\n- Always respond with valid JSON only, no additional text\n- For product searches, format results as markdown links: [Product Name](url)\n- Be helpful and conversational in your messages\n- Product prices: Black Shirt - Medium: $29.99 (2999 cents), Blue Shirt - Large: $34.99 (3499 cents), Red T-Shirt - Small: $19.99 (1999 cents), Jeans - Medium: $49.99 (4999 cents)\n\nExample conversation flow:\n- User: \"I am looking for a black shirt in medium\"\n- You: {\"action\": \"message\", \"text\": \"Here are the products I found:\\\\n1. [Black Shirt - Medium](/products.html?product=black-shirt-medium) - $29.99\\\\n2. [Blue Shirt - Large](/products.html?product=blue-shirt-large) - $34.99\\\\n3. [Red T-Shirt - Small](/products.html?product=red-tshirt-small) - $19.99\\\\n4. [Jeans - Medium](/products.html?product=jeans-medium) - $49.99\\\\n\\\\nWould you like me to navigate to the first result and add it to your cart?\"}\n\n- User: \"No, I would like to add another shirt to the cart\"\n- You: {\"action\": \"message_and_click\", \"element\": \".AddToCartButton-blue-shirt-large\", \"text\": \"I've added the Blue Shirt - Large to your cart. Ready to checkout?\"}\n\n- User: \"yes\"\n- You: {\"action\": \"checkout\", \"text\": \"Perfect! I'll set up the checkout for you.\", \"items\": [{\"name\": \"Black Shirt - Medium\", \"price\": 2999, \"quantity\": 1}]}`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Component-aware flow for custom component rendering\n * This flow instructs the AI to respond with component directives in JSON format\n */\nexport const COMPONENT_FLOW: RuntypeFlowConfig = {\n name: \"Component Flow\",\n description: \"Flow configured for custom component rendering\",\n steps: [\n {\n id: \"component_prompt\",\n name: \"Component Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful assistant that can both have conversations and render custom UI components.\n\nRESPONSE FORMAT:\nAlways respond with valid JSON. Choose the appropriate format based on the user's request:\n\n1. For CONVERSATIONAL questions or text responses:\n {\"text\": \"Your response here\"}\n\n2. For VISUAL DISPLAYS or when the user asks to SHOW/DISPLAY something:\n {\"component\": \"ComponentName\", \"props\": {...}}\n\n3. For BOTH explanation AND visual:\n {\"text\": \"Your explanation here\", \"component\": \"ComponentName\", \"props\": {...}}\n\nAvailable components for visual displays:\n- ProductCard: Display product information. Props: title (string), price (number), description (string, optional), image (string, optional)\n- SimpleChart: Display a bar chart. Props: title (string), data (array of numbers), labels (array of strings, optional)\n- StatusBadge: Display a status badge. Props: status (string: \"success\", \"error\", \"warning\", \"info\", \"pending\"), message (string)\n- InfoCard: Display an information card. Props: title (string), content (string), icon (string, optional)\n\nExamples:\n- User asks \"What is the capital of France?\": {\"text\": \"The capital of France is Paris.\"}\n- User asks \"What does that chart show?\": {\"text\": \"The chart shows sales data increasing from 100 to 200 over three months.\"}\n- User asks \"Show me a product card\": {\"component\": \"ProductCard\", \"props\": {\"title\": \"Laptop\", \"price\": 999, \"description\": \"A great laptop\"}}\n- User asks \"Display a chart\": {\"component\": \"SimpleChart\", \"props\": {\"title\": \"Sales\", \"data\": [100, 150, 200], \"labels\": [\"Jan\", \"Feb\", \"Mar\"]}}\n- User asks \"Show me a chart and explain it\": {\"text\": \"Here's the sales data for Q1:\", \"component\": \"SimpleChart\", \"props\": {\"title\": \"Q1 Sales\", \"data\": [100, 150, 200], \"labels\": [\"Jan\", \"Feb\", \"Mar\"]}}\n\nIMPORTANT:\n- Use {\"text\": \"...\"} for questions, explanations, discussions, and general chat\n- Use {\"component\": \"...\", \"props\": {...}} ONLY when the user explicitly wants to SEE/VIEW/DISPLAY visual content\n- You can combine both: {\"text\": \"...\", \"component\": \"...\", \"props\": {...}} when you want to explain something AND show a visual\n- Never force a component when the user just wants information`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Bakery assistant flow configuration for \"Flour & Stone\" bakery demo\n * This flow returns JSON actions for page interaction including:\n * - Simple messages with bakery brand voice\n * - Navigation to bakery pages\n * - Add to cart interactions\n * - Stripe checkout\n *\n * Designed to guide users toward the gift card when asking for gift recommendations.\n */\nexport const BAKERY_ASSISTANT_FLOW: RuntypeFlowConfig = {\n name: \"Bakery Assistant Flow\",\n description: \"Flour & Stone bakery shopping assistant with gift recommendations\",\n steps: [\n {\n id: \"bakery_action_prompt\",\n name: \"Bakery Action Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful shopping assistant for Flour & Stone, a premium artisan bakery known for traditional bread-making and exceptional pastries.\n\nBrand voice: Warm, knowledgeable, passionate about craft baking. Use phrases like \"fresh from the oven\", \"handcrafted with care\", \"artisan tradition\". Do not explain selectors, JSON, or templating to the user.\n\n## Live context (request inputs — substituted each turn)\n\nThe widget sends **only** these keys as dispatch **inputs** (nothing extra on the record for this demo).\n\n**Orientation**\n- Path: {{current_page}} (compare before nav_then_click; e.g. /bakery-goods.html)\n- Full URL: {{page_url}}\n- Title: {{page_title}}\n\n**Page DOM**\n- page_elements: JSON array of enriched nodes (selector, tagName, text, role, interactivity, attributes including data-*). Prefer **selector** for message_and_click when you click a specific control.\n- page_context: Same slice formatted for the LLM (structured card summaries when matched, then groups by interactivity).\n\n{{page_elements}}\n\n{{page_context}}\n\n**Cart (for checkout — mirror cart.items when user pays)**\n{{cart}}\n\n**Recent order (if any)**\n{{recent_order}}\n\nIf {{current_page}} already equals the page you would navigate to, use {\"action\":\"message\",...} instead of nav_then_click.\n\n## Discovering products\n\nUse {{page_context}} for a quick scan and {{page_elements}} for exact selectors and attributes. Product rows often include data-product in **attributes**; prices appear in **text**; add-to-cart controls are usually **clickable** with stable **selector** values.\n\n## Output: one JSON object only\n\nNo markdown fences, no commentary before/after. Valid JSON only.\n\n### 1. message\n{\"action\": \"message\", \"text\": \"...\"}\nUse for chat, clarifying questions, \"we're already on that page\", or when you need the user to choose (e.g. $25 vs $50 gift card).\n\n### 2. nav_then_click\n{\"action\": \"nav_then_click\", \"page\": \"/bakery-goods.html\", \"on_load_text\": \"...\"}\nUse root-relative paths starting with /. Only when current_page is different from the target. This **only** changes pages — it does **not** open Stripe or payment.\n\n### 3. add_to_cart\n{\"action\": \"add_to_cart\", \"text\": \"...\", \"item\": {\"id\": \"product-id\", \"name\": \"Product Name\", \"price\": 1200}}\nUse when adding from context without scrolling (optional; on goods page prefer scroll_then_add).\n\n### 4. scroll_then_add (preferred on /bakery-goods.html)\n{\"action\": \"scroll_then_add\", \"text\": \"...\", \"item\": {\"id\": \"...\", \"name\": \"...\", \"price\": 1200}}\nScrolls the product into view then adds one unit (cart merges duplicate ids into quantity).\n\n### 5. checkout → Stripe (this demo)\n{\"action\": \"checkout\", \"text\": \"Brief message\", \"items\": [{\"name\": \"...\", \"price\": 1200, \"quantity\": 2}, ...]}\n**Only** this action starts hosted checkout (Stripe). **Never** use nav_then_click to a \"/checkout\" URL for payment here.\nRequirements: cart in context must have items; **items array must list every cart line** with the same name, cent prices, and quantities as cart.items. If cart is null or empty, use message — do not checkout.\n\n### 6. message_and_click (rare)\nIf page_elements show a specific button selector and scroll_then_add is wrong, you may use message_and_click with a CSS selector — prefer scroll_then_add on bakery-goods.html.\n\n## Rules\n\n- Prices in JSON are always **integer cents** (1200 = $12.00).\n- After adding to cart, invite checkout or more shopping.\n- On checkout confirmation (\"yes\", \"checkout\", \"pay\", \"proceed\", etc.), build **items** from **cart.items** (all rows, correct quantity). Do not drop lines or invent prices.\n\n## Product catalog (ids and cent prices)\n\n- Sourdough Loaf: sourdough-loaf, 1200\n- Croissant Box (6): croissant-box, 2400\n- Cinnamon Rolls (4): cinnamon-rolls, 1800\n- Baguette Trio: baguette-trio, 900\n- Almond Tart: almond-tart, 800\n- Fruit Danish: fruit-danish, 600\n- $50 Gift Card: gift-card-50, 5000\n- $25 Gift Card: gift-card-25, 2500\n\n## Examples\n\nGift seeker on /bakery-locations.html:\n{\"action\": \"nav_then_click\", \"page\": \"/bakery-goods.html\", \"on_load_text\": \"Here are our goods! You'll find our gift cards below — $50 is our most popular. Want me to add one?\"}\n\nOn /bakery-goods.html, user wants $50 gift card:\n{\"action\": \"scroll_then_add\", \"text\": \"Added the $50 gift card. Ready to check out?\", \"item\": {\"id\": \"gift-card-50\", \"name\": \"$50 Gift Card\", \"price\": 5000}}\n\nUser on /bakery.html agrees to see products:\n{\"action\": \"nav_then_click\", \"page\": \"/bakery-goods.html\", \"on_load_text\": \"Here are our handcrafted goods — what sounds good today?\"}\n\nOn /bakery-goods.html, add sourdough:\n{\"action\": \"scroll_then_add\", \"text\": \"Sourdough is in your cart. Anything else, or shall we check out?\", \"item\": {\"id\": \"sourdough-loaf\", \"name\": \"Sourdough Loaf\", \"price\": 1200}}\n\nCart has one $50 gift card; user says yes to checkout:\n{\"action\": \"checkout\", \"text\": \"Opening secure checkout...\", \"items\": [{\"name\": \"$50 Gift Card\", \"price\": 5000, \"quantity\": 1}]}\n\nCart has sourdough (qty 1) and croissant box (qty 1); user says \"pay\":\n{\"action\": \"checkout\", \"text\": \"Taking you to checkout...\", \"items\": [{\"name\": \"Sourdough Loaf\", \"price\": 1200, \"quantity\": 1}, {\"name\": \"Croissant Box (6)\", \"price\": 2400, \"quantity\": 1}]}`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Storefront assistant flow for the \"Everspun\" persistent-composer demo.\n *\n * Designed to feel like the agent is *building the storefront* in front of\n * the user: when they ask for product suggestions, the agent emits a\n * `ProductGrid` component directive carrying a small batch of structured\n * product cards (id, title, price, image, description). The persona widget\n * renders these as inline cards inside the chat panel via a registered\n * `componentRegistry` entry on the host. Plain conversational replies (fit,\n * fabric, care, styling Q&A) use a simple `{text}` JSON object and stay as\n * regular chat bubbles.\n */\nexport const STOREFRONT_ASSISTANT_FLOW: RuntypeFlowConfig = {\n name: \"Storefront Assistant Flow\",\n description:\n \"Everspun storefront assistant — surfaces product cards via component directives\",\n steps: [\n {\n id: \"storefront_action_prompt\",\n name: \"Storefront Action Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n reasoning: false,\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are the concierge for **Everspun**, a quiet-luxury wardrobe brand: cashmere, organic cotton, linen, and considered accessories. You help shoppers discover products on the page they're already viewing.\n\nBrand voice: calm, considered, knowledgeable. Short sentences. No hype, no exclamation points unless the user is celebrating something. Do not explain JSON, components, or templating to the user.\n\n## Live context (substituted each turn)\n\nThe current product the shopper is viewing:\n{{current_product}}\n\nThe shopper's current bag:\n{{cart}}\n\n## Output: one JSON object only\n\nNo markdown fences, no commentary before/after. Valid JSON only. Three response shapes are valid:\n\n### 1. Plain message\n{\"text\": \"...\"}\n\nUse for fit / fabric / care / styling Q&A about the current product, for clarifying questions, and for anything that doesn't surface new products. Renders as a normal chat bubble.\n\n### 2. Product grid (component directive)\n{\n \"text\": \"Brief intro line shown above the cards.\",\n \"component\": \"ProductGrid\",\n \"props\": {\n \"products\": [\n {\"id\": \"...\", \"title\": \"...\", \"price\": 24800, \"image\": \"https://...\", \"description\": \"...\"}\n ]\n }\n}\n\nUse when the shopper asks to see options, asks \"what would go with this\", asks for a category, asks for a price range, or asks for a gift suggestion. Pick **2–6** items from the catalog below — never more than 6, never fewer than 2. Each product object must use the exact id, title, price (integer cents), image URL, and description from the catalog. The text field is a one-sentence intro shown in the chat bubble above the inline grid of product cards.\n\n### 3. Add to cart (action)\n{\"action\": \"add_to_cart\", \"text\": \"Confirmation line.\", \"item\": {\"id\": \"...\", \"title\": \"...\", \"price\": 24800}}\n\nUse only when the shopper explicitly asks you to add a specific product to their bag (\"add the linen pant\", \"I'll take the beanie\"). Use the exact id/title/price from the catalog. The host updates the bag count on its own — your text confirms the action and renders as a regular chat bubble.\n\n## Rules\n\n- Prices in JSON are always **integer cents** (24800 = $248.00).\n- When the shopper asks \"what would go with this?\", ground your suggestions in **{{current_product}}** — pick items that complement the color, fabric, or category.\n- For \"under $X\" queries, only return products from the catalog priced under that amount.\n- For gift queries, prefer the gift card SKUs or compact accessories.\n- After a ProductGrid response, do **not** also describe each product in the text — the cards speak for themselves. Keep text short (\"A few cashmere options:\", \"Pieces under $200:\").\n- Never invent products. The catalog below is the entire universe.\n\n## Product catalog\n\n| id | title | price (cents) | image | description |\n|---|---|---|---|---|\n| cashmere-crewneck | Mongolian Cashmere Crewneck | 24800 | https://images.unsplash.com/photo-1583743814966-8936f5b7be1a?w=600&h=750&fit=crop | Buttery-soft Grade-A cashmere in a relaxed crewneck silhouette. |\n| ribbed-turtleneck | Ribbed Cashmere Turtleneck | 32800 | https://images.unsplash.com/photo-1576566588028-4147f3842f27?w=600&h=750&fit=crop | A heavier-gauge rib knit, cut close through the body. |\n| alpaca-cardigan | Alpaca-Blend Cardigan | 32800 | https://images.unsplash.com/photo-1622445275576-721325763afe?w=600&h=750&fit=crop | Loose-knit alpaca and merino, with horn buttons. |\n| organic-cotton-tee | Organic Cotton Tee | 5800 | https://images.unsplash.com/photo-1521572163474-6864f9cf17ab?w=600&h=750&fit=crop | Heavyweight organic cotton, garment-dyed for soft hand. |\n| oxford-button-down | Oxford Button-Down | 12800 | https://images.unsplash.com/photo-1556905055-8f358a7a47b2?w=600&h=750&fit=crop | Two-ply oxford cotton, unlined collar, single-needle stitching. |\n| linen-trouser | Wide-Leg Linen Trouser | 18800 | https://images.unsplash.com/photo-1473966968600-fa801b869a1a?w=600&h=750&fit=crop | Heavyweight Belgian linen with a fluid drape. |\n| washed-chino | Washed Cotton Chino | 14800 | https://images.unsplash.com/photo-1542272604-787c3835535d?w=600&h=750&fit=crop | Garment-washed twill in a tapered fit. |\n| recycled-beanie | Recycled Cashmere Beanie | 8800 | https://images.unsplash.com/photo-1576871337632-b9aef4c17ab9?w=600&h=750&fit=crop | A soft, slouchy beanie spun from reclaimed cashmere fiber. |\n| leather-card-holder | Vegetable-Tan Card Holder | 9800 | https://images.unsplash.com/photo-1623998022290-a74f8cc36563?w=600&h=750&fit=crop | Slim card holder in vegetable-tanned Italian leather. |\n| gift-card-50 | $50 Gift Card | 5000 | https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=600&h=750&fit=crop | Delivered by email, never expires. |\n| gift-card-100 | $100 Gift Card | 10000 | https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=600&h=750&fit=crop | Delivered by email, never expires. |\n| gift-card-200 | $200 Gift Card | 20000 | https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=600&h=750&fit=crop | Delivered by email, never expires. |\n\n## Examples\n\nUser asks \"show me cashmere essentials\":\n{\"text\": \"A few cashmere essentials:\", \"component\": \"ProductGrid\", \"props\": {\"products\": [\n {\"id\": \"cashmere-crewneck\", \"title\": \"Mongolian Cashmere Crewneck\", \"price\": 24800, \"image\": \"https://images.unsplash.com/photo-1583743814966-8936f5b7be1a?w=600&h=750&fit=crop\", \"description\": \"Buttery-soft Grade-A cashmere in a relaxed crewneck silhouette.\"},\n {\"id\": \"ribbed-turtleneck\", \"title\": \"Ribbed Cashmere Turtleneck\", \"price\": 32800, \"image\": \"https://images.unsplash.com/photo-1576566588028-4147f3842f27?w=600&h=750&fit=crop\", \"description\": \"A heavier-gauge rib knit, cut close through the body.\"},\n {\"id\": \"recycled-beanie\", \"title\": \"Recycled Cashmere Beanie\", \"price\": 8800, \"image\": \"https://images.unsplash.com/photo-1576871337632-b9aef4c17ab9?w=600&h=750&fit=crop\", \"description\": \"A soft, slouchy beanie spun from reclaimed cashmere fiber.\"}\n]}}\n\nUser asks \"what pants would go with this?\" (current_product = camel cashmere sweater):\n{\"text\": \"These pair well with the camel:\", \"component\": \"ProductGrid\", \"props\": {\"products\": [\n {\"id\": \"linen-trouser\", \"title\": \"Wide-Leg Linen Trouser\", \"price\": 18800, \"image\": \"https://images.unsplash.com/photo-1473966968600-fa801b869a1a?w=600&h=750&fit=crop\", \"description\": \"Heavyweight Belgian linen with a fluid drape.\"},\n {\"id\": \"washed-chino\", \"title\": \"Washed Cotton Chino\", \"price\": 14800, \"image\": \"https://images.unsplash.com/photo-1542272604-787c3835535d?w=600&h=750&fit=crop\", \"description\": \"Garment-washed twill in a tapered fit.\"}\n]}}\n\nUser asks \"anything under $200?\":\n{\"text\": \"A few under $200:\", \"component\": \"ProductGrid\", \"props\": {\"products\": [\n {\"id\": \"linen-trouser\", \"title\": \"Wide-Leg Linen Trouser\", \"price\": 18800, \"image\": \"https://images.unsplash.com/photo-1473966968600-fa801b869a1a?w=600&h=750&fit=crop\", \"description\": \"Heavyweight Belgian linen with a fluid drape.\"},\n {\"id\": \"washed-chino\", \"title\": \"Washed Cotton Chino\", \"price\": 14800, \"image\": \"https://images.unsplash.com/photo-1542272604-787c3835535d?w=600&h=750&fit=crop\", \"description\": \"Garment-washed twill in a tapered fit.\"},\n {\"id\": \"oxford-button-down\", \"title\": \"Oxford Button-Down\", \"price\": 12800, \"image\": \"https://images.unsplash.com/photo-1556905055-8f358a7a47b2?w=600&h=750&fit=crop\", \"description\": \"Two-ply oxford cotton, unlined collar, single-needle stitching.\"},\n {\"id\": \"leather-card-holder\", \"title\": \"Vegetable-Tan Card Holder\", \"price\": 9800, \"image\": \"https://images.unsplash.com/photo-1623998022290-a74f8cc36563?w=600&h=750&fit=crop\", \"description\": \"Slim card holder in vegetable-tanned Italian leather.\"}\n]}}\n\nUser asks \"I need a gift under $300\":\n{\"text\": \"Gifts under $300:\", \"component\": \"ProductGrid\", \"props\": {\"products\": [\n {\"id\": \"gift-card-200\", \"title\": \"$200 Gift Card\", \"price\": 20000, \"image\": \"https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=600&h=750&fit=crop\", \"description\": \"Delivered by email, never expires.\"},\n {\"id\": \"cashmere-crewneck\", \"title\": \"Mongolian Cashmere Crewneck\", \"price\": 24800, \"image\": \"https://images.unsplash.com/photo-1583743814966-8936f5b7be1a?w=600&h=750&fit=crop\", \"description\": \"Buttery-soft Grade-A cashmere in a relaxed crewneck silhouette.\"},\n {\"id\": \"recycled-beanie\", \"title\": \"Recycled Cashmere Beanie\", \"price\": 8800, \"image\": \"https://images.unsplash.com/photo-1576871337632-b9aef4c17ab9?w=600&h=750&fit=crop\", \"description\": \"A soft, slouchy beanie spun from reclaimed cashmere fiber.\"}\n]}}\n\nUser asks \"add the linen pant to my bag\":\n{\"action\": \"add_to_cart\", \"text\": \"Added the linen trouser to your bag.\", \"item\": {\"id\": \"linen-trouser\", \"title\": \"Wide-Leg Linen Trouser\", \"price\": 18800}}\n\nUser asks \"how does this fit?\" (current_product is the cashmere button-down):\n{\"text\": \"It runs true to size with a relaxed shoulder. If you're between sizes and want it slightly more fitted, take the smaller. The body length sits just below the hip.\"}\n\nUser asks \"what's the best way to care for cashmere?\":\n{\"text\": \"Hand-wash cool with a wool-safe detergent, lay flat to dry, and store folded — never on a hanger. A cedar block in the drawer keeps moths off.\"}`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * WebMCP storefront flow for the \"Switchback\" trail/road running demo\n * (`examples/embedded-app/webmcp-demo.html`).\n *\n * Unlike the other example flows, this agent owns **no** tools of its own. The\n * demo page registers its tools on `document.modelContext` via WebMCP\n * (`search_products`, `view_product`, `add_to_cart`, `remove_from_cart`,\n * `apply_promo`); the widget snapshots them every turn and the proxy forwards\n * them on the dispatch payload as `clientTools[]`. The Runtype runtime threads\n * those into this prompt step's tool set, so the model calls them by name and\n * the widget executes them **on the page**, posting results back via `/resume`.\n *\n * That means the agent definition that drives the WebMCP demo lives entirely in\n * this repo — no hosted Runtype agent / client token required. The flow just\n * needs a tool-capable model and a system prompt that knows how to shop the\n * (page-provided) catalog.\n *\n * Model: `nemotron-3-ultra-550b-a55b`. WebMCP depends on the model\n * emitting **native** tool calls (each surfaces as a `step_await` the widget\n * resumes), so a tool-reliable model is required here. `responseFormat` is\n * markdown (not JSON) so the model is free to interleave tool calls with a\n * natural-language summary instead of being constrained to a JSON envelope.\n */\nexport const WEBMCP_STOREFRONT_FLOW: RuntypeFlowConfig = {\n name: \"WebMCP Storefront Flow\",\n description:\n \"Switchback running-store assistant — drives page-provided WebMCP tools (clientTools[])\",\n steps: [\n {\n id: \"webmcp_storefront_prompt\",\n name: \"WebMCP Storefront Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n reasoning: false,\n responseFormat: \"markdown\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are the shopping assistant for **Switchback**, a trail & road running store. You help shoppers find gear, inspect products, and manage their cart.\n\nBrand voice: friendly, outdoorsy, concise. Knowledgeable about running shoes, apparel, and trail gear. No hype, no emoji. Keep replies short — a sentence or two around the actions you take.\n\n## Your tools come from the page\n\nThis storefront exposes its own tools to you (search the catalog, view a product, add/remove from the cart, apply a promo code). Always **use the tools** to act on the catalog and cart — never invent products, SKUs, prices, or cart contents from memory.\n\nRules:\n- Before referencing or adding any SKU, call **search_products** (or view_product) first to confirm it exists and to get the canonical SKU, title, and price. Do not guess SKUs.\n- When the shopper asks to add, remove, or change the cart, call the matching tool. The page renders the cart — after a cart change, confirm what changed and the running total from the tool's result, briefly.\n- If the shopper asks to add two (or more) specific items \"at the same time\" / \"both\", emit the add_to_cart calls together in one turn so they batch.\n- Only apply a promo code the shopper actually gives you; if it's rejected, say so and suggest they double-check the code.\n- If a tool reports an item wasn't found or isn't in the cart, relay that plainly and offer to search.\n- Tool results include product \\`imageUrl\\` and \\`imageAlt\\`. When you recommend, compare, or describe specific products, include Markdown product images when it helps the shopper decide: \\`\\`. Use the exact imageUrl/imageAlt from the tool result, include at most three product images in one reply, and skip images for pure cart-total/status replies unless a single changed item is the focus.\n\nAfter your tool calls resolve, summarize the outcome in plain language (what you found, what's in the cart, the total). Do not describe tools, JSON, SKUs, or the WebMCP mechanism to the shopper.`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * WebMCP calendar flow for the calendar copilot demo\n * (`examples/embedded-app/webmcp-calendar.html`).\n *\n * Like WEBMCP_STOREFRONT_FLOW, this agent owns **no** tools of its own. The\n * demo page registers ten calendar tools on `document.modelContext` via WebMCP\n * (`get_calendar_state`, `get_events`, `get_users`, `get_event_colors`,\n * `find_availability`, `select_date`, `create_event`, `update_event`,\n * `delete_event`, `get_page_title`); the widget snapshots them every turn and\n * the proxy forwards them on the dispatch payload as `clientTools[]`. The\n * model calls them by name and the widget executes them **on the page**,\n * posting results back via `/resume` — so the calendar UI updates live.\n *\n * The page's tool contract is timezone-safe by design: all date-times are\n * LOCAL wall-clock strings (`YYYY-MM-DDTHH:mm`, no \"Z\"/UTC offset), and\n * `get_calendar_state` reports the current local date-time and timezone. The\n * system prompt reinforces that contract so \"8am\" always lands at 8am on the\n * visible calendar.\n */\nexport const WEBMCP_CALENDAR_FLOW: RuntypeFlowConfig = {\n name: \"WebMCP Calendar Flow\",\n description:\n \"Calendar copilot — drives page-provided WebMCP calendar tools (clientTools[])\",\n steps: [\n {\n id: \"webmcp_calendar_prompt\",\n name: \"WebMCP Calendar Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n reasoning: false,\n responseFormat: \"markdown\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are the Calendar Copilot for a team scheduling dashboard. You help the user inspect availability, create, move, and delete events — the calendar on the page updates live as your tools run.\n\nVoice: helpful, concise, plain language. Keep replies short — a sentence or two around the actions you take.\n\n## Your tools come from the page\n\nThe dashboard exposes its own calendar tools to you. Always **use the tools** to read or change the calendar — never invent events, IDs, owners, or availability from memory.\n\nRules:\n- Start by calling **get_calendar_state** to learn today's date, the current local time, the timezone, and the visible week before resolving relative dates like \"tomorrow\" or \"Thursday\".\n- All date-times are LOCAL wall-clock strings in the calendar's timezone, formatted \\`YYYY-MM-DDTHH:mm\\`. Never append \"Z\" or a UTC offset — write the clock time the user said.\n- Use a real userId from **get_users** and a color from **get_event_colors** when creating events. Do not guess IDs.\n- Before proposing a meeting time, check **find_availability** for that date; the workday is 9am–5pm local.\n- To change or remove an event, find its eventId via **get_events** or **get_calendar_state** first.\n- After a mutation, confirm briefly what changed (title, day, time) — the page renders the calendar, so don't repeat the full schedule unless asked.\n- If a tool reports an error (invalid time, missing event), relay it plainly and suggest a fix.\n\nAfter your tool calls resolve, summarize the outcome in plain language. Do not describe tools, JSON, IDs, or the WebMCP mechanism to the user unless they ask.`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","import type { RuntypeFlowConfig } from \"../index.js\";\n\n/**\n * Page-aware shopping assistant that can both *describe* and *act on* the page.\n *\n * It returns a small JSON envelope (like the shopping / storefront / bakery flows):\n * a `text` field — markdown shown in the chat bubble — plus, when the shopper asks to\n * add something, an `add_to_cart` action carrying the product's stable handle. The\n * widget's flexible JSON stream parser renders `text`; the action manager parses the\n * envelope and dispatches the action to the host's `addToCartHandler`.\n *\n * It is used by the smart-dom-reader demo to show two things at once:\n * 1. a shadow-DOM-aware context provider feeds real page content (including products\n * inside shadow roots) into the prompt, grouped by on-page section; and\n * 2. the assistant can drive the page across that same shadow boundary — the host's\n * handler resolves a `product` handle to a light-DOM *or* shadow-DOM button.\n *\n * The host injects `{{pageContext}}` via `inputs` — the widget's `contextProviders`\n * output, moved from `payload.context` into `inputs` by a `requestMiddleware` so the\n * proxy forwards it upstream. Each product line in that context carries a\n * `product=<id>` handle the model copies verbatim into an `add_to_cart` action.\n */\nexport const PAGE_CONTEXT_FLOW: RuntypeFlowConfig = {\n name: \"Page Context Assistant Flow\",\n description:\n \"Page-aware assistant that answers about the current page and can add its products to the cart.\",\n steps: [\n {\n id: \"page_context_prompt\",\n name: \"Prompt\",\n type: \"prompt\",\n enabled: true,\n config: {\n model: \"nemotron-3-ultra-550b-a55b\",\n responseFormat: \"JSON\",\n outputVariable: \"prompt_result\",\n userPrompt: \"{{user_message}}\",\n systemPrompt: `You are a helpful shopping assistant embedded on a web page. Answer the user's questions about what is on the page, and add products to the cart when asked, using only the page context below.\n\nThe context is collected live from the DOM and is grouped by on-page section (for example \"Everyday picks\" and \"Featured drop\"). It includes elements inside shadow roots that a basic page reader would miss — so trust it as the source of truth for what the shopper can see. Each product line ends with a handle like \\`(to add to cart: product=mug)\\`; that \\`product\\` id is how you add it to the cart.\n\n## Output: one JSON object only\n\nNo markdown fences, no commentary before or after. Valid JSON only. Two response shapes are valid:\n\n### 1. Plain answer\n{\"text\": \"...markdown...\"}\n\nUse for any question about the page — what's for sale, what's in a section, prices, comparisons. The \\`text\\` is markdown and renders as a normal chat bubble.\n\n### 2. Add to cart\n{\"action\": \"add_to_cart\", \"product\": \"<id>\", \"text\": \"Confirmation line.\"}\n\nUse only when the shopper explicitly asks to add a specific product (\"add the mug\", \"I'll take the headphones\"). Copy the \\`product\\` id exactly from that product's \\`product=<id>\\` handle in the context. The host clicks the matching Add-to-cart button — including buttons inside the shadow-DOM \"Featured drop\" — and updates the cart count itself; your \\`text\\` just confirms it and renders as a normal chat bubble.\n\n## Rules\n\n- Only mention products, prices, and sections that appear in the page context. If something is not there, say you do not see it on this page.\n- Never invent a \\`product\\` id. Use only the ids present in the context handles. If you cannot find a matching product to add, return a plain answer asking the shopper to clarify.\n- Be concise. Keep \\`text\\` short and use markdown where it helps.\n\n## Page context\n{{pageContext}}`,\n previousMessages: \"{{messages}}\"\n }\n }\n ]\n};\n","/**\n * Stripe checkout helpers using the REST API\n * This approach works on all platforms including Cloudflare Workers, Vercel Edge, etc.\n */\n\n/**\n * Pinned API version for raw HTTP calls (no SDK). Required for organization API keys and\n * keeps behavior stable across accounts. See https://docs.stripe.com/api/versioning\n */\nconst STRIPE_API_VERSION = \"2026-03-25.dahlia\";\n\nexport interface CheckoutItem {\n name: string;\n price: number; // Price in cents\n quantity: number;\n}\n\nexport interface CreateCheckoutSessionOptions {\n secretKey: string;\n items: CheckoutItem[];\n successUrl: string;\n cancelUrl: string;\n /**\n * Target account for organization API keys (`sk_org_…`), e.g. `acct_1abc…` or\n * `acct_platform/acct_connected` per Stripe. Required with org keys.\n * @see https://docs.stripe.com/keys#organization-api-keys\n */\n stripeContext?: string;\n}\n\nexport interface CheckoutSessionResponse {\n success: boolean;\n checkoutUrl?: string;\n sessionId?: string;\n error?: string;\n}\n\nfunction parseStripeApiErrorBody(body: string): string | undefined {\n try {\n const parsed = JSON.parse(body) as {\n error?: { message?: string; type?: string };\n };\n const msg = parsed?.error?.message;\n return typeof msg === \"string\" && msg.length > 0 ? msg : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Creates a Stripe checkout session using the REST API\n * @param options - Checkout session configuration\n * @returns Checkout session response with URL and session ID\n */\nexport async function createCheckoutSession(\n options: CreateCheckoutSessionOptions\n): Promise<CheckoutSessionResponse> {\n const { secretKey, items, successUrl, cancelUrl, stripeContext } = options;\n const trimmedContext = stripeContext?.trim() || undefined;\n\n try {\n if (secretKey.startsWith(\"sk_org\") && !trimmedContext) {\n return {\n success: false,\n error:\n \"Organization Stripe keys (sk_org_…) require stripeContext / STRIPE_CONTEXT with the target account (e.g. acct_…). See https://docs.stripe.com/keys#organization-api-keys\",\n };\n }\n\n // Validate items\n if (!items || !Array.isArray(items) || items.length === 0) {\n return {\n success: false,\n error: \"Items array is required\"\n };\n }\n\n for (const item of items) {\n if (!item.name || typeof item.price !== \"number\" || typeof item.quantity !== \"number\") {\n return {\n success: false,\n error: \"Each item must have name (string), price (number in cents), and quantity (number)\"\n };\n }\n if (\n !Number.isFinite(item.price) ||\n !Number.isInteger(item.price) ||\n item.price < 1 ||\n !Number.isInteger(item.quantity) ||\n item.quantity < 1\n ) {\n return {\n success: false,\n error:\n \"Each item needs a positive integer price (cents) and quantity (Stripe rejects decimals or zero)\",\n };\n }\n }\n\n // Build line items for URL encoding\n const lineItems = items.map((item) => ({\n price_data: {\n currency: \"usd\",\n product_data: {\n name: item.name,\n },\n unit_amount: item.price,\n },\n quantity: item.quantity,\n }));\n\n // Convert line items to URL-encoded format\n const params = new URLSearchParams({\n \"payment_method_types[0]\": \"card\",\n \"mode\": \"payment\",\n \"success_url\": successUrl,\n \"cancel_url\": cancelUrl,\n });\n\n // Add line items to params\n lineItems.forEach((item, index) => {\n params.append(`line_items[${index}][price_data][currency]`, item.price_data.currency);\n params.append(`line_items[${index}][price_data][product_data][name]`, item.price_data.product_data.name);\n params.append(`line_items[${index}][price_data][unit_amount]`, item.price_data.unit_amount.toString());\n params.append(`line_items[${index}][quantity]`, item.quantity.toString());\n });\n\n const headers: Record<string, string> = {\n Authorization: `Bearer ${secretKey}`,\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"Stripe-Version\": STRIPE_API_VERSION,\n };\n if (trimmedContext) {\n headers[\"Stripe-Context\"] = trimmedContext;\n }\n\n // Create Stripe checkout session using REST API\n const stripeResponse = await fetch(\"https://api.stripe.com/v1/checkout/sessions\", {\n method: \"POST\",\n headers,\n body: params,\n });\n\n if (!stripeResponse.ok) {\n const errorData = await stripeResponse.text();\n const stripeMessage = parseStripeApiErrorBody(errorData);\n console.error(\"Stripe API error:\", errorData);\n return {\n success: false,\n error: stripeMessage ?? \"Failed to create checkout session\",\n };\n }\n\n const session = await stripeResponse.json() as { url: string; id: string };\n\n return {\n success: true,\n checkoutUrl: session.url,\n sessionId: session.id,\n };\n } catch (error) {\n console.error(\"Stripe checkout error:\", error);\n return {\n success: false,\n error: error instanceof Error ? error.message : \"Failed to create checkout session\"\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AAErB,oBAAuB;;;ACIhB,IAAM,sBAAyC;AA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AAED,SAAO;AACT;AAEO,IAAM,sBAAsB,CAAC,gBAClC,sBAAO,mBAAmB,OAAO,CAAC;AAQpC,IAAO,gBAAQ;","names":["_a","_b","_c"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -61,6 +61,52 @@ declare const BAKERY_ASSISTANT_FLOW: RuntypeFlowConfig;
|
|
|
61
61
|
*/
|
|
62
62
|
declare const STOREFRONT_ASSISTANT_FLOW: RuntypeFlowConfig;
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* WebMCP storefront flow for the "Switchback" trail/road running demo
|
|
66
|
+
* (`examples/embedded-app/webmcp-demo.html`).
|
|
67
|
+
*
|
|
68
|
+
* Unlike the other example flows, this agent owns **no** tools of its own. The
|
|
69
|
+
* demo page registers its tools on `document.modelContext` via WebMCP
|
|
70
|
+
* (`search_products`, `view_product`, `add_to_cart`, `remove_from_cart`,
|
|
71
|
+
* `apply_promo`); the widget snapshots them every turn and the proxy forwards
|
|
72
|
+
* them on the dispatch payload as `clientTools[]`. The Runtype runtime threads
|
|
73
|
+
* those into this prompt step's tool set, so the model calls them by name and
|
|
74
|
+
* the widget executes them **on the page**, posting results back via `/resume`.
|
|
75
|
+
*
|
|
76
|
+
* That means the agent definition that drives the WebMCP demo lives entirely in
|
|
77
|
+
* this repo — no hosted Runtype agent / client token required. The flow just
|
|
78
|
+
* needs a tool-capable model and a system prompt that knows how to shop the
|
|
79
|
+
* (page-provided) catalog.
|
|
80
|
+
*
|
|
81
|
+
* Model: `nemotron-3-ultra-550b-a55b`. WebMCP depends on the model
|
|
82
|
+
* emitting **native** tool calls (each surfaces as a `step_await` the widget
|
|
83
|
+
* resumes), so a tool-reliable model is required here. `responseFormat` is
|
|
84
|
+
* markdown (not JSON) so the model is free to interleave tool calls with a
|
|
85
|
+
* natural-language summary instead of being constrained to a JSON envelope.
|
|
86
|
+
*/
|
|
87
|
+
declare const WEBMCP_STOREFRONT_FLOW: RuntypeFlowConfig;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* WebMCP calendar flow for the calendar copilot demo
|
|
91
|
+
* (`examples/embedded-app/webmcp-calendar.html`).
|
|
92
|
+
*
|
|
93
|
+
* Like WEBMCP_STOREFRONT_FLOW, this agent owns **no** tools of its own. The
|
|
94
|
+
* demo page registers ten calendar tools on `document.modelContext` via WebMCP
|
|
95
|
+
* (`get_calendar_state`, `get_events`, `get_users`, `get_event_colors`,
|
|
96
|
+
* `find_availability`, `select_date`, `create_event`, `update_event`,
|
|
97
|
+
* `delete_event`, `get_page_title`); the widget snapshots them every turn and
|
|
98
|
+
* the proxy forwards them on the dispatch payload as `clientTools[]`. The
|
|
99
|
+
* model calls them by name and the widget executes them **on the page**,
|
|
100
|
+
* posting results back via `/resume` — so the calendar UI updates live.
|
|
101
|
+
*
|
|
102
|
+
* The page's tool contract is timezone-safe by design: all date-times are
|
|
103
|
+
* LOCAL wall-clock strings (`YYYY-MM-DDTHH:mm`, no "Z"/UTC offset), and
|
|
104
|
+
* `get_calendar_state` reports the current local date-time and timezone. The
|
|
105
|
+
* system prompt reinforces that contract so "8am" always lands at 8am on the
|
|
106
|
+
* visible calendar.
|
|
107
|
+
*/
|
|
108
|
+
declare const WEBMCP_CALENDAR_FLOW: RuntypeFlowConfig;
|
|
109
|
+
|
|
64
110
|
/**
|
|
65
111
|
* Page-aware shopping assistant that can both *describe* and *act on* the page.
|
|
66
112
|
*
|
|
@@ -149,6 +195,17 @@ type ChatProxyOptions = {
|
|
|
149
195
|
apiKey?: string;
|
|
150
196
|
path?: string;
|
|
151
197
|
allowedOrigins?: string[];
|
|
198
|
+
/**
|
|
199
|
+
* Reflect any request origin matching this pattern, in addition to the exact
|
|
200
|
+
* `allowedOrigins` list. Intended for Vercel **preview** deployments, whose
|
|
201
|
+
* URLs are per-branch and dynamic (`*-git-<branch>-<team>.vercel.app`) and so
|
|
202
|
+
* can't be enumerated. Defaults to `https://*.vercel.app`
|
|
203
|
+
* ({@link DEFAULT_PREVIEW_ORIGIN_PATTERN}); pass a custom `RegExp`, set the
|
|
204
|
+
* `PREVIEW_ORIGIN_PATTERN` env var, or pass `false` to disable. Independent of
|
|
205
|
+
* the `VERCEL_ENV === "preview"` runtime check, which always reflects the
|
|
206
|
+
* caller's origin when the proxy itself is a preview deployment.
|
|
207
|
+
*/
|
|
208
|
+
previewOriginPattern?: RegExp | false;
|
|
152
209
|
flowId?: string;
|
|
153
210
|
flowConfig?: RuntypeFlowConfig;
|
|
154
211
|
/**
|
|
@@ -171,4 +228,4 @@ type ChatProxyOptions = {
|
|
|
171
228
|
declare const createChatProxyApp: (options?: ChatProxyOptions) => Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
172
229
|
declare const createVercelHandler: (options?: ChatProxyOptions) => (req: Request) => Response | Promise<Response>;
|
|
173
230
|
|
|
174
|
-
export { BAKERY_ASSISTANT_FLOW, COMPONENT_FLOW, CONVERSATIONAL_FLOW, type ChatProxyOptions, type CheckoutItem, type CheckoutSessionResponse, type CreateCheckoutSessionOptions, FORM_DIRECTIVE_FLOW, type FeedbackHandler, type FeedbackPayload, PAGE_CONTEXT_FLOW, type RuntypeFlowConfig, type RuntypeFlowStep, SHOPPING_ASSISTANT_FLOW, SHOPPING_ASSISTANT_METADATA_FLOW, STOREFRONT_ASSISTANT_FLOW, createChatProxyApp, createCheckoutSession, createVercelHandler, createChatProxyApp as default };
|
|
231
|
+
export { BAKERY_ASSISTANT_FLOW, COMPONENT_FLOW, CONVERSATIONAL_FLOW, type ChatProxyOptions, type CheckoutItem, type CheckoutSessionResponse, type CreateCheckoutSessionOptions, FORM_DIRECTIVE_FLOW, type FeedbackHandler, type FeedbackPayload, PAGE_CONTEXT_FLOW, type RuntypeFlowConfig, type RuntypeFlowStep, SHOPPING_ASSISTANT_FLOW, SHOPPING_ASSISTANT_METADATA_FLOW, STOREFRONT_ASSISTANT_FLOW, WEBMCP_CALENDAR_FLOW, WEBMCP_STOREFRONT_FLOW, createChatProxyApp, createCheckoutSession, createVercelHandler, createChatProxyApp as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -61,6 +61,52 @@ declare const BAKERY_ASSISTANT_FLOW: RuntypeFlowConfig;
|
|
|
61
61
|
*/
|
|
62
62
|
declare const STOREFRONT_ASSISTANT_FLOW: RuntypeFlowConfig;
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* WebMCP storefront flow for the "Switchback" trail/road running demo
|
|
66
|
+
* (`examples/embedded-app/webmcp-demo.html`).
|
|
67
|
+
*
|
|
68
|
+
* Unlike the other example flows, this agent owns **no** tools of its own. The
|
|
69
|
+
* demo page registers its tools on `document.modelContext` via WebMCP
|
|
70
|
+
* (`search_products`, `view_product`, `add_to_cart`, `remove_from_cart`,
|
|
71
|
+
* `apply_promo`); the widget snapshots them every turn and the proxy forwards
|
|
72
|
+
* them on the dispatch payload as `clientTools[]`. The Runtype runtime threads
|
|
73
|
+
* those into this prompt step's tool set, so the model calls them by name and
|
|
74
|
+
* the widget executes them **on the page**, posting results back via `/resume`.
|
|
75
|
+
*
|
|
76
|
+
* That means the agent definition that drives the WebMCP demo lives entirely in
|
|
77
|
+
* this repo — no hosted Runtype agent / client token required. The flow just
|
|
78
|
+
* needs a tool-capable model and a system prompt that knows how to shop the
|
|
79
|
+
* (page-provided) catalog.
|
|
80
|
+
*
|
|
81
|
+
* Model: `nemotron-3-ultra-550b-a55b`. WebMCP depends on the model
|
|
82
|
+
* emitting **native** tool calls (each surfaces as a `step_await` the widget
|
|
83
|
+
* resumes), so a tool-reliable model is required here. `responseFormat` is
|
|
84
|
+
* markdown (not JSON) so the model is free to interleave tool calls with a
|
|
85
|
+
* natural-language summary instead of being constrained to a JSON envelope.
|
|
86
|
+
*/
|
|
87
|
+
declare const WEBMCP_STOREFRONT_FLOW: RuntypeFlowConfig;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* WebMCP calendar flow for the calendar copilot demo
|
|
91
|
+
* (`examples/embedded-app/webmcp-calendar.html`).
|
|
92
|
+
*
|
|
93
|
+
* Like WEBMCP_STOREFRONT_FLOW, this agent owns **no** tools of its own. The
|
|
94
|
+
* demo page registers ten calendar tools on `document.modelContext` via WebMCP
|
|
95
|
+
* (`get_calendar_state`, `get_events`, `get_users`, `get_event_colors`,
|
|
96
|
+
* `find_availability`, `select_date`, `create_event`, `update_event`,
|
|
97
|
+
* `delete_event`, `get_page_title`); the widget snapshots them every turn and
|
|
98
|
+
* the proxy forwards them on the dispatch payload as `clientTools[]`. The
|
|
99
|
+
* model calls them by name and the widget executes them **on the page**,
|
|
100
|
+
* posting results back via `/resume` — so the calendar UI updates live.
|
|
101
|
+
*
|
|
102
|
+
* The page's tool contract is timezone-safe by design: all date-times are
|
|
103
|
+
* LOCAL wall-clock strings (`YYYY-MM-DDTHH:mm`, no "Z"/UTC offset), and
|
|
104
|
+
* `get_calendar_state` reports the current local date-time and timezone. The
|
|
105
|
+
* system prompt reinforces that contract so "8am" always lands at 8am on the
|
|
106
|
+
* visible calendar.
|
|
107
|
+
*/
|
|
108
|
+
declare const WEBMCP_CALENDAR_FLOW: RuntypeFlowConfig;
|
|
109
|
+
|
|
64
110
|
/**
|
|
65
111
|
* Page-aware shopping assistant that can both *describe* and *act on* the page.
|
|
66
112
|
*
|
|
@@ -149,6 +195,17 @@ type ChatProxyOptions = {
|
|
|
149
195
|
apiKey?: string;
|
|
150
196
|
path?: string;
|
|
151
197
|
allowedOrigins?: string[];
|
|
198
|
+
/**
|
|
199
|
+
* Reflect any request origin matching this pattern, in addition to the exact
|
|
200
|
+
* `allowedOrigins` list. Intended for Vercel **preview** deployments, whose
|
|
201
|
+
* URLs are per-branch and dynamic (`*-git-<branch>-<team>.vercel.app`) and so
|
|
202
|
+
* can't be enumerated. Defaults to `https://*.vercel.app`
|
|
203
|
+
* ({@link DEFAULT_PREVIEW_ORIGIN_PATTERN}); pass a custom `RegExp`, set the
|
|
204
|
+
* `PREVIEW_ORIGIN_PATTERN` env var, or pass `false` to disable. Independent of
|
|
205
|
+
* the `VERCEL_ENV === "preview"` runtime check, which always reflects the
|
|
206
|
+
* caller's origin when the proxy itself is a preview deployment.
|
|
207
|
+
*/
|
|
208
|
+
previewOriginPattern?: RegExp | false;
|
|
152
209
|
flowId?: string;
|
|
153
210
|
flowConfig?: RuntypeFlowConfig;
|
|
154
211
|
/**
|
|
@@ -171,4 +228,4 @@ type ChatProxyOptions = {
|
|
|
171
228
|
declare const createChatProxyApp: (options?: ChatProxyOptions) => Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
172
229
|
declare const createVercelHandler: (options?: ChatProxyOptions) => (req: Request) => Response | Promise<Response>;
|
|
173
230
|
|
|
174
|
-
export { BAKERY_ASSISTANT_FLOW, COMPONENT_FLOW, CONVERSATIONAL_FLOW, type ChatProxyOptions, type CheckoutItem, type CheckoutSessionResponse, type CreateCheckoutSessionOptions, FORM_DIRECTIVE_FLOW, type FeedbackHandler, type FeedbackPayload, PAGE_CONTEXT_FLOW, type RuntypeFlowConfig, type RuntypeFlowStep, SHOPPING_ASSISTANT_FLOW, SHOPPING_ASSISTANT_METADATA_FLOW, STOREFRONT_ASSISTANT_FLOW, createChatProxyApp, createCheckoutSession, createVercelHandler, createChatProxyApp as default };
|
|
231
|
+
export { BAKERY_ASSISTANT_FLOW, COMPONENT_FLOW, CONVERSATIONAL_FLOW, type ChatProxyOptions, type CheckoutItem, type CheckoutSessionResponse, type CreateCheckoutSessionOptions, FORM_DIRECTIVE_FLOW, type FeedbackHandler, type FeedbackPayload, PAGE_CONTEXT_FLOW, type RuntypeFlowConfig, type RuntypeFlowStep, SHOPPING_ASSISTANT_FLOW, SHOPPING_ASSISTANT_METADATA_FLOW, STOREFRONT_ASSISTANT_FLOW, WEBMCP_CALENDAR_FLOW, WEBMCP_STOREFRONT_FLOW, createChatProxyApp, createCheckoutSession, createVercelHandler, createChatProxyApp as default };
|