@runtypelabs/persona-proxy 3.19.0 → 3.26.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 +128 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -1
- package/dist/index.d.ts +59 -1
- package/dist/index.js +126 -10
- 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 +68 -0
- 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-storefront.ts +62 -0
- package/src/index.test.ts +173 -1
- package/src/index.ts +95 -4
package/dist/index.d.cts
CHANGED
|
@@ -61,6 +61,53 @@ 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
|
+
* Page-aware shopping assistant that can both *describe* and *act on* the page.
|
|
91
|
+
*
|
|
92
|
+
* It returns a small JSON envelope (like the shopping / storefront / bakery flows):
|
|
93
|
+
* a `text` field — markdown shown in the chat bubble — plus, when the shopper asks to
|
|
94
|
+
* add something, an `add_to_cart` action carrying the product's stable handle. The
|
|
95
|
+
* widget's flexible JSON stream parser renders `text`; the action manager parses the
|
|
96
|
+
* envelope and dispatches the action to the host's `addToCartHandler`.
|
|
97
|
+
*
|
|
98
|
+
* It is used by the smart-dom-reader demo to show two things at once:
|
|
99
|
+
* 1. a shadow-DOM-aware context provider feeds real page content (including products
|
|
100
|
+
* inside shadow roots) into the prompt, grouped by on-page section; and
|
|
101
|
+
* 2. the assistant can drive the page across that same shadow boundary — the host's
|
|
102
|
+
* handler resolves a `product` handle to a light-DOM *or* shadow-DOM button.
|
|
103
|
+
*
|
|
104
|
+
* The host injects `{{pageContext}}` via `inputs` — the widget's `contextProviders`
|
|
105
|
+
* output, moved from `payload.context` into `inputs` by a `requestMiddleware` so the
|
|
106
|
+
* proxy forwards it upstream. Each product line in that context carries a
|
|
107
|
+
* `product=<id>` handle the model copies verbatim into an `add_to_cart` action.
|
|
108
|
+
*/
|
|
109
|
+
declare const PAGE_CONTEXT_FLOW: RuntypeFlowConfig;
|
|
110
|
+
|
|
64
111
|
/**
|
|
65
112
|
* Stripe checkout helpers using the REST API
|
|
66
113
|
* This approach works on all platforms including Cloudflare Workers, Vercel Edge, etc.
|
|
@@ -127,6 +174,17 @@ type ChatProxyOptions = {
|
|
|
127
174
|
apiKey?: string;
|
|
128
175
|
path?: string;
|
|
129
176
|
allowedOrigins?: string[];
|
|
177
|
+
/**
|
|
178
|
+
* Reflect any request origin matching this pattern, in addition to the exact
|
|
179
|
+
* `allowedOrigins` list. Intended for Vercel **preview** deployments, whose
|
|
180
|
+
* URLs are per-branch and dynamic (`*-git-<branch>-<team>.vercel.app`) and so
|
|
181
|
+
* can't be enumerated. Defaults to `https://*.vercel.app`
|
|
182
|
+
* ({@link DEFAULT_PREVIEW_ORIGIN_PATTERN}); pass a custom `RegExp`, set the
|
|
183
|
+
* `PREVIEW_ORIGIN_PATTERN` env var, or pass `false` to disable. Independent of
|
|
184
|
+
* the `VERCEL_ENV === "preview"` runtime check, which always reflects the
|
|
185
|
+
* caller's origin when the proxy itself is a preview deployment.
|
|
186
|
+
*/
|
|
187
|
+
previewOriginPattern?: RegExp | false;
|
|
130
188
|
flowId?: string;
|
|
131
189
|
flowConfig?: RuntypeFlowConfig;
|
|
132
190
|
/**
|
|
@@ -149,4 +207,4 @@ type ChatProxyOptions = {
|
|
|
149
207
|
declare const createChatProxyApp: (options?: ChatProxyOptions) => Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
150
208
|
declare const createVercelHandler: (options?: ChatProxyOptions) => (req: Request) => Response | Promise<Response>;
|
|
151
209
|
|
|
152
|
-
export { BAKERY_ASSISTANT_FLOW, COMPONENT_FLOW, CONVERSATIONAL_FLOW, type ChatProxyOptions, type CheckoutItem, type CheckoutSessionResponse, type CreateCheckoutSessionOptions, FORM_DIRECTIVE_FLOW, type FeedbackHandler, type FeedbackPayload, type RuntypeFlowConfig, type RuntypeFlowStep, SHOPPING_ASSISTANT_FLOW, SHOPPING_ASSISTANT_METADATA_FLOW, STOREFRONT_ASSISTANT_FLOW, createChatProxyApp, createCheckoutSession, createVercelHandler, createChatProxyApp as default };
|
|
210
|
+
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_STOREFRONT_FLOW, createChatProxyApp, createCheckoutSession, createVercelHandler, createChatProxyApp as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -61,6 +61,53 @@ 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
|
+
* Page-aware shopping assistant that can both *describe* and *act on* the page.
|
|
91
|
+
*
|
|
92
|
+
* It returns a small JSON envelope (like the shopping / storefront / bakery flows):
|
|
93
|
+
* a `text` field — markdown shown in the chat bubble — plus, when the shopper asks to
|
|
94
|
+
* add something, an `add_to_cart` action carrying the product's stable handle. The
|
|
95
|
+
* widget's flexible JSON stream parser renders `text`; the action manager parses the
|
|
96
|
+
* envelope and dispatches the action to the host's `addToCartHandler`.
|
|
97
|
+
*
|
|
98
|
+
* It is used by the smart-dom-reader demo to show two things at once:
|
|
99
|
+
* 1. a shadow-DOM-aware context provider feeds real page content (including products
|
|
100
|
+
* inside shadow roots) into the prompt, grouped by on-page section; and
|
|
101
|
+
* 2. the assistant can drive the page across that same shadow boundary — the host's
|
|
102
|
+
* handler resolves a `product` handle to a light-DOM *or* shadow-DOM button.
|
|
103
|
+
*
|
|
104
|
+
* The host injects `{{pageContext}}` via `inputs` — the widget's `contextProviders`
|
|
105
|
+
* output, moved from `payload.context` into `inputs` by a `requestMiddleware` so the
|
|
106
|
+
* proxy forwards it upstream. Each product line in that context carries a
|
|
107
|
+
* `product=<id>` handle the model copies verbatim into an `add_to_cart` action.
|
|
108
|
+
*/
|
|
109
|
+
declare const PAGE_CONTEXT_FLOW: RuntypeFlowConfig;
|
|
110
|
+
|
|
64
111
|
/**
|
|
65
112
|
* Stripe checkout helpers using the REST API
|
|
66
113
|
* This approach works on all platforms including Cloudflare Workers, Vercel Edge, etc.
|
|
@@ -127,6 +174,17 @@ type ChatProxyOptions = {
|
|
|
127
174
|
apiKey?: string;
|
|
128
175
|
path?: string;
|
|
129
176
|
allowedOrigins?: string[];
|
|
177
|
+
/**
|
|
178
|
+
* Reflect any request origin matching this pattern, in addition to the exact
|
|
179
|
+
* `allowedOrigins` list. Intended for Vercel **preview** deployments, whose
|
|
180
|
+
* URLs are per-branch and dynamic (`*-git-<branch>-<team>.vercel.app`) and so
|
|
181
|
+
* can't be enumerated. Defaults to `https://*.vercel.app`
|
|
182
|
+
* ({@link DEFAULT_PREVIEW_ORIGIN_PATTERN}); pass a custom `RegExp`, set the
|
|
183
|
+
* `PREVIEW_ORIGIN_PATTERN` env var, or pass `false` to disable. Independent of
|
|
184
|
+
* the `VERCEL_ENV === "preview"` runtime check, which always reflects the
|
|
185
|
+
* caller's origin when the proxy itself is a preview deployment.
|
|
186
|
+
*/
|
|
187
|
+
previewOriginPattern?: RegExp | false;
|
|
130
188
|
flowId?: string;
|
|
131
189
|
flowConfig?: RuntypeFlowConfig;
|
|
132
190
|
/**
|
|
@@ -149,4 +207,4 @@ type ChatProxyOptions = {
|
|
|
149
207
|
declare const createChatProxyApp: (options?: ChatProxyOptions) => Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
150
208
|
declare const createVercelHandler: (options?: ChatProxyOptions) => (req: Request) => Response | Promise<Response>;
|
|
151
209
|
|
|
152
|
-
export { BAKERY_ASSISTANT_FLOW, COMPONENT_FLOW, CONVERSATIONAL_FLOW, type ChatProxyOptions, type CheckoutItem, type CheckoutSessionResponse, type CreateCheckoutSessionOptions, FORM_DIRECTIVE_FLOW, type FeedbackHandler, type FeedbackPayload, type RuntypeFlowConfig, type RuntypeFlowStep, SHOPPING_ASSISTANT_FLOW, SHOPPING_ASSISTANT_METADATA_FLOW, STOREFRONT_ASSISTANT_FLOW, createChatProxyApp, createCheckoutSession, createVercelHandler, createChatProxyApp as default };
|
|
210
|
+
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_STOREFRONT_FLOW, createChatProxyApp, createCheckoutSession, createVercelHandler, createChatProxyApp as default };
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var CONVERSATIONAL_FLOW = {
|
|
|
13
13
|
type: "prompt",
|
|
14
14
|
enabled: true,
|
|
15
15
|
config: {
|
|
16
|
-
model: "
|
|
16
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
17
17
|
responseFormat: "markdown",
|
|
18
18
|
outputVariable: "prompt_result",
|
|
19
19
|
userPrompt: "{{user_message}}",
|
|
@@ -35,7 +35,7 @@ var FORM_DIRECTIVE_FLOW = {
|
|
|
35
35
|
type: "prompt",
|
|
36
36
|
enabled: true,
|
|
37
37
|
config: {
|
|
38
|
-
model: "
|
|
38
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
39
39
|
reasoning: false,
|
|
40
40
|
responseFormat: "JSON",
|
|
41
41
|
outputVariable: "prompt_result",
|
|
@@ -96,7 +96,7 @@ var SHOPPING_ASSISTANT_FLOW = {
|
|
|
96
96
|
type: "prompt",
|
|
97
97
|
enabled: true,
|
|
98
98
|
config: {
|
|
99
|
-
model: "
|
|
99
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
100
100
|
reasoning: false,
|
|
101
101
|
responseFormat: "JSON",
|
|
102
102
|
outputVariable: "prompt_result",
|
|
@@ -169,7 +169,7 @@ var SHOPPING_ASSISTANT_METADATA_FLOW = {
|
|
|
169
169
|
type: "prompt",
|
|
170
170
|
enabled: true,
|
|
171
171
|
config: {
|
|
172
|
-
model: "
|
|
172
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
173
173
|
reasoning: false,
|
|
174
174
|
responseFormat: "JSON",
|
|
175
175
|
outputVariable: "prompt_result",
|
|
@@ -253,7 +253,7 @@ var COMPONENT_FLOW = {
|
|
|
253
253
|
type: "prompt",
|
|
254
254
|
enabled: true,
|
|
255
255
|
config: {
|
|
256
|
-
model: "
|
|
256
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
257
257
|
reasoning: false,
|
|
258
258
|
responseFormat: "JSON",
|
|
259
259
|
outputVariable: "prompt_result",
|
|
@@ -307,7 +307,7 @@ var BAKERY_ASSISTANT_FLOW = {
|
|
|
307
307
|
type: "prompt",
|
|
308
308
|
enabled: true,
|
|
309
309
|
config: {
|
|
310
|
-
model: "
|
|
310
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
311
311
|
reasoning: false,
|
|
312
312
|
responseFormat: "JSON",
|
|
313
313
|
outputVariable: "prompt_result",
|
|
@@ -426,7 +426,7 @@ var STOREFRONT_ASSISTANT_FLOW = {
|
|
|
426
426
|
type: "prompt",
|
|
427
427
|
enabled: true,
|
|
428
428
|
config: {
|
|
429
|
-
model: "
|
|
429
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
430
430
|
reasoning: false,
|
|
431
431
|
responseFormat: "JSON",
|
|
432
432
|
outputVariable: "prompt_result",
|
|
@@ -540,6 +540,91 @@ User asks "what's the best way to care for cashmere?":
|
|
|
540
540
|
]
|
|
541
541
|
};
|
|
542
542
|
|
|
543
|
+
// src/flows/webmcp-storefront.ts
|
|
544
|
+
var WEBMCP_STOREFRONT_FLOW = {
|
|
545
|
+
name: "WebMCP Storefront Flow",
|
|
546
|
+
description: "Switchback running-store assistant \u2014 drives page-provided WebMCP tools (clientTools[])",
|
|
547
|
+
steps: [
|
|
548
|
+
{
|
|
549
|
+
id: "webmcp_storefront_prompt",
|
|
550
|
+
name: "WebMCP Storefront Prompt",
|
|
551
|
+
type: "prompt",
|
|
552
|
+
enabled: true,
|
|
553
|
+
config: {
|
|
554
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
555
|
+
reasoning: false,
|
|
556
|
+
responseFormat: "markdown",
|
|
557
|
+
outputVariable: "prompt_result",
|
|
558
|
+
userPrompt: "{{user_message}}",
|
|
559
|
+
systemPrompt: `You are the shopping assistant for **Switchback**, a trail & road running store. You help shoppers find gear, inspect products, and manage their cart.
|
|
560
|
+
|
|
561
|
+
Brand voice: friendly, outdoorsy, concise. Knowledgeable about running shoes, apparel, and trail gear. No hype, no emoji. Keep replies short \u2014 a sentence or two around the actions you take.
|
|
562
|
+
|
|
563
|
+
## Your tools come from the page
|
|
564
|
+
|
|
565
|
+
This 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 \u2014 never invent products, SKUs, prices, or cart contents from memory.
|
|
566
|
+
|
|
567
|
+
Rules:
|
|
568
|
+
- 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.
|
|
569
|
+
- When the shopper asks to add, remove, or change the cart, call the matching tool. The page renders the cart \u2014 after a cart change, confirm what changed and the running total from the tool's result, briefly.
|
|
570
|
+
- 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.
|
|
571
|
+
- Only apply a promo code the shopper actually gives you; if it's rejected, say so and suggest they double-check the code.
|
|
572
|
+
- If a tool reports an item wasn't found or isn't in the cart, relay that plainly and offer to search.
|
|
573
|
+
|
|
574
|
+
After 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.`,
|
|
575
|
+
previousMessages: "{{messages}}"
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
]
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
// src/flows/page-context.ts
|
|
582
|
+
var PAGE_CONTEXT_FLOW = {
|
|
583
|
+
name: "Page Context Assistant Flow",
|
|
584
|
+
description: "Page-aware assistant that answers about the current page and can add its products to the cart.",
|
|
585
|
+
steps: [
|
|
586
|
+
{
|
|
587
|
+
id: "page_context_prompt",
|
|
588
|
+
name: "Prompt",
|
|
589
|
+
type: "prompt",
|
|
590
|
+
enabled: true,
|
|
591
|
+
config: {
|
|
592
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
593
|
+
responseFormat: "JSON",
|
|
594
|
+
outputVariable: "prompt_result",
|
|
595
|
+
userPrompt: "{{user_message}}",
|
|
596
|
+
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.
|
|
597
|
+
|
|
598
|
+
The 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 \u2014 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.
|
|
599
|
+
|
|
600
|
+
## Output: one JSON object only
|
|
601
|
+
|
|
602
|
+
No markdown fences, no commentary before or after. Valid JSON only. Two response shapes are valid:
|
|
603
|
+
|
|
604
|
+
### 1. Plain answer
|
|
605
|
+
{"text": "...markdown..."}
|
|
606
|
+
|
|
607
|
+
Use for any question about the page \u2014 what's for sale, what's in a section, prices, comparisons. The \`text\` is markdown and renders as a normal chat bubble.
|
|
608
|
+
|
|
609
|
+
### 2. Add to cart
|
|
610
|
+
{"action": "add_to_cart", "product": "<id>", "text": "Confirmation line."}
|
|
611
|
+
|
|
612
|
+
Use 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 \u2014 including buttons inside the shadow-DOM "Featured drop" \u2014 and updates the cart count itself; your \`text\` just confirms it and renders as a normal chat bubble.
|
|
613
|
+
|
|
614
|
+
## Rules
|
|
615
|
+
|
|
616
|
+
- 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.
|
|
617
|
+
- 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.
|
|
618
|
+
- Be concise. Keep \`text\` short and use markdown where it helps.
|
|
619
|
+
|
|
620
|
+
## Page context
|
|
621
|
+
{{pageContext}}`,
|
|
622
|
+
previousMessages: "{{messages}}"
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
]
|
|
626
|
+
};
|
|
627
|
+
|
|
543
628
|
// src/utils/stripe.ts
|
|
544
629
|
var STRIPE_API_VERSION = "2026-03-25.dahlia";
|
|
545
630
|
function parseStripeApiErrorBody(body) {
|
|
@@ -652,6 +737,24 @@ var isDevelopmentRuntime = () => {
|
|
|
652
737
|
var _a;
|
|
653
738
|
return ((_a = getRuntimeEnv()) == null ? void 0 : _a.NODE_ENV) === "development";
|
|
654
739
|
};
|
|
740
|
+
var isVercelPreviewRuntime = () => {
|
|
741
|
+
var _a;
|
|
742
|
+
return ((_a = getRuntimeEnv()) == null ? void 0 : _a.VERCEL_ENV) === "preview";
|
|
743
|
+
};
|
|
744
|
+
var DEFAULT_PREVIEW_ORIGIN_PATTERN = /^https:\/\/[a-z0-9-]+\.vercel\.app$/i;
|
|
745
|
+
var resolvePreviewOriginPattern = (option) => {
|
|
746
|
+
var _a;
|
|
747
|
+
if (option === false) return null;
|
|
748
|
+
if (option instanceof RegExp) return option;
|
|
749
|
+
const envPattern = (_a = getRuntimeEnv()) == null ? void 0 : _a.PREVIEW_ORIGIN_PATTERN;
|
|
750
|
+
if (envPattern) {
|
|
751
|
+
try {
|
|
752
|
+
return new RegExp(envPattern);
|
|
753
|
+
} catch {
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return DEFAULT_PREVIEW_ORIGIN_PATTERN;
|
|
757
|
+
};
|
|
655
758
|
var DEFAULT_FLOW = {
|
|
656
759
|
name: "Streaming Prompt Flow",
|
|
657
760
|
description: "Streaming chat generated by the widget",
|
|
@@ -662,7 +765,7 @@ var DEFAULT_FLOW = {
|
|
|
662
765
|
type: "prompt",
|
|
663
766
|
enabled: true,
|
|
664
767
|
config: {
|
|
665
|
-
model: "
|
|
768
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
666
769
|
responseFormat: "markdown",
|
|
667
770
|
outputVariable: "prompt_result",
|
|
668
771
|
userPrompt: "{{user_message}}",
|
|
@@ -677,9 +780,12 @@ var DEFAULT_FLOW = {
|
|
|
677
780
|
}
|
|
678
781
|
]
|
|
679
782
|
};
|
|
680
|
-
var withCors = (allowedOrigins) => async (c, next) => {
|
|
783
|
+
var withCors = (allowedOrigins, previewOriginPattern) => async (c, next) => {
|
|
681
784
|
const origin = c.req.header("origin");
|
|
682
785
|
const isDevelopment = isDevelopmentRuntime();
|
|
786
|
+
const isPreviewOrigin = Boolean(
|
|
787
|
+
origin && (isVercelPreviewRuntime() || previewOriginPattern !== null && previewOriginPattern.test(origin))
|
|
788
|
+
);
|
|
683
789
|
let corsOrigin;
|
|
684
790
|
if (!allowedOrigins || allowedOrigins.length === 0) {
|
|
685
791
|
corsOrigin = origin || "*";
|
|
@@ -687,6 +793,8 @@ var withCors = (allowedOrigins) => async (c, next) => {
|
|
|
687
793
|
corsOrigin = origin || "*";
|
|
688
794
|
} else if (isDevelopment && origin) {
|
|
689
795
|
corsOrigin = origin;
|
|
796
|
+
} else if (isPreviewOrigin && origin) {
|
|
797
|
+
corsOrigin = origin;
|
|
690
798
|
} else {
|
|
691
799
|
if (c.req.method === "OPTIONS") {
|
|
692
800
|
return c.json({ error: "CORS policy violation: origin not allowed" }, 403);
|
|
@@ -714,7 +822,10 @@ var createChatProxyApp = (options = {}) => {
|
|
|
714
822
|
const path = (_a = options.path) != null ? _a : DEFAULT_PATH;
|
|
715
823
|
const feedbackPath = (_b = options.feedbackPath) != null ? _b : "/api/feedback";
|
|
716
824
|
const upstream = (_c = options.upstreamUrl) != null ? _c : DEFAULT_ENDPOINT;
|
|
717
|
-
|
|
825
|
+
const previewOriginPattern = resolvePreviewOriginPattern(
|
|
826
|
+
options.previewOriginPattern
|
|
827
|
+
);
|
|
828
|
+
app.use("*", withCors(options.allowedOrigins, previewOriginPattern));
|
|
718
829
|
app.post(feedbackPath, async (c) => {
|
|
719
830
|
var _a2, _b2, _c2;
|
|
720
831
|
let payload;
|
|
@@ -819,6 +930,9 @@ var createChatProxyApp = (options = {}) => {
|
|
|
819
930
|
} else {
|
|
820
931
|
runtypePayload.flow = flowConfig;
|
|
821
932
|
}
|
|
933
|
+
if (Array.isArray(clientPayload.clientTools) && clientPayload.clientTools.length > 0) {
|
|
934
|
+
runtypePayload.clientTools = clientPayload.clientTools;
|
|
935
|
+
}
|
|
822
936
|
}
|
|
823
937
|
if (isDevelopment) {
|
|
824
938
|
console.log(`
|
|
@@ -916,9 +1030,11 @@ export {
|
|
|
916
1030
|
COMPONENT_FLOW,
|
|
917
1031
|
CONVERSATIONAL_FLOW,
|
|
918
1032
|
FORM_DIRECTIVE_FLOW,
|
|
1033
|
+
PAGE_CONTEXT_FLOW,
|
|
919
1034
|
SHOPPING_ASSISTANT_FLOW,
|
|
920
1035
|
SHOPPING_ASSISTANT_METADATA_FLOW,
|
|
921
1036
|
STOREFRONT_ASSISTANT_FLOW,
|
|
1037
|
+
WEBMCP_STOREFRONT_FLOW,
|
|
922
1038
|
createChatProxyApp,
|
|
923
1039
|
createCheckoutSession,
|
|
924
1040
|
createVercelHandler,
|