@runtypelabs/persona-proxy 3.22.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 +77 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +76 -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 +1 -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-storefront.ts +62 -0
- package/src/index.test.ts +95 -0
- package/src/index.ts +81 -4
package/dist/index.d.cts
CHANGED
|
@@ -61,6 +61,31 @@ 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
|
+
|
|
64
89
|
/**
|
|
65
90
|
* Page-aware shopping assistant that can both *describe* and *act on* the page.
|
|
66
91
|
*
|
|
@@ -149,6 +174,17 @@ type ChatProxyOptions = {
|
|
|
149
174
|
apiKey?: string;
|
|
150
175
|
path?: string;
|
|
151
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;
|
|
152
188
|
flowId?: string;
|
|
153
189
|
flowConfig?: RuntypeFlowConfig;
|
|
154
190
|
/**
|
|
@@ -171,4 +207,4 @@ type ChatProxyOptions = {
|
|
|
171
207
|
declare const createChatProxyApp: (options?: ChatProxyOptions) => Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
172
208
|
declare const createVercelHandler: (options?: ChatProxyOptions) => (req: Request) => Response | Promise<Response>;
|
|
173
209
|
|
|
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 };
|
|
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,31 @@ 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
|
+
|
|
64
89
|
/**
|
|
65
90
|
* Page-aware shopping assistant that can both *describe* and *act on* the page.
|
|
66
91
|
*
|
|
@@ -149,6 +174,17 @@ type ChatProxyOptions = {
|
|
|
149
174
|
apiKey?: string;
|
|
150
175
|
path?: string;
|
|
151
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;
|
|
152
188
|
flowId?: string;
|
|
153
189
|
flowConfig?: RuntypeFlowConfig;
|
|
154
190
|
/**
|
|
@@ -171,4 +207,4 @@ type ChatProxyOptions = {
|
|
|
171
207
|
declare const createChatProxyApp: (options?: ChatProxyOptions) => Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
172
208
|
declare const createVercelHandler: (options?: ChatProxyOptions) => (req: Request) => Response | Promise<Response>;
|
|
173
209
|
|
|
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 };
|
|
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,44 @@ 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
|
+
|
|
543
581
|
// src/flows/page-context.ts
|
|
544
582
|
var PAGE_CONTEXT_FLOW = {
|
|
545
583
|
name: "Page Context Assistant Flow",
|
|
@@ -551,7 +589,7 @@ var PAGE_CONTEXT_FLOW = {
|
|
|
551
589
|
type: "prompt",
|
|
552
590
|
enabled: true,
|
|
553
591
|
config: {
|
|
554
|
-
model: "
|
|
592
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
555
593
|
responseFormat: "JSON",
|
|
556
594
|
outputVariable: "prompt_result",
|
|
557
595
|
userPrompt: "{{user_message}}",
|
|
@@ -699,6 +737,24 @@ var isDevelopmentRuntime = () => {
|
|
|
699
737
|
var _a;
|
|
700
738
|
return ((_a = getRuntimeEnv()) == null ? void 0 : _a.NODE_ENV) === "development";
|
|
701
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
|
+
};
|
|
702
758
|
var DEFAULT_FLOW = {
|
|
703
759
|
name: "Streaming Prompt Flow",
|
|
704
760
|
description: "Streaming chat generated by the widget",
|
|
@@ -709,7 +765,7 @@ var DEFAULT_FLOW = {
|
|
|
709
765
|
type: "prompt",
|
|
710
766
|
enabled: true,
|
|
711
767
|
config: {
|
|
712
|
-
model: "
|
|
768
|
+
model: "nemotron-3-ultra-550b-a55b",
|
|
713
769
|
responseFormat: "markdown",
|
|
714
770
|
outputVariable: "prompt_result",
|
|
715
771
|
userPrompt: "{{user_message}}",
|
|
@@ -724,9 +780,12 @@ var DEFAULT_FLOW = {
|
|
|
724
780
|
}
|
|
725
781
|
]
|
|
726
782
|
};
|
|
727
|
-
var withCors = (allowedOrigins) => async (c, next) => {
|
|
783
|
+
var withCors = (allowedOrigins, previewOriginPattern) => async (c, next) => {
|
|
728
784
|
const origin = c.req.header("origin");
|
|
729
785
|
const isDevelopment = isDevelopmentRuntime();
|
|
786
|
+
const isPreviewOrigin = Boolean(
|
|
787
|
+
origin && (isVercelPreviewRuntime() || previewOriginPattern !== null && previewOriginPattern.test(origin))
|
|
788
|
+
);
|
|
730
789
|
let corsOrigin;
|
|
731
790
|
if (!allowedOrigins || allowedOrigins.length === 0) {
|
|
732
791
|
corsOrigin = origin || "*";
|
|
@@ -734,6 +793,8 @@ var withCors = (allowedOrigins) => async (c, next) => {
|
|
|
734
793
|
corsOrigin = origin || "*";
|
|
735
794
|
} else if (isDevelopment && origin) {
|
|
736
795
|
corsOrigin = origin;
|
|
796
|
+
} else if (isPreviewOrigin && origin) {
|
|
797
|
+
corsOrigin = origin;
|
|
737
798
|
} else {
|
|
738
799
|
if (c.req.method === "OPTIONS") {
|
|
739
800
|
return c.json({ error: "CORS policy violation: origin not allowed" }, 403);
|
|
@@ -761,7 +822,10 @@ var createChatProxyApp = (options = {}) => {
|
|
|
761
822
|
const path = (_a = options.path) != null ? _a : DEFAULT_PATH;
|
|
762
823
|
const feedbackPath = (_b = options.feedbackPath) != null ? _b : "/api/feedback";
|
|
763
824
|
const upstream = (_c = options.upstreamUrl) != null ? _c : DEFAULT_ENDPOINT;
|
|
764
|
-
|
|
825
|
+
const previewOriginPattern = resolvePreviewOriginPattern(
|
|
826
|
+
options.previewOriginPattern
|
|
827
|
+
);
|
|
828
|
+
app.use("*", withCors(options.allowedOrigins, previewOriginPattern));
|
|
765
829
|
app.post(feedbackPath, async (c) => {
|
|
766
830
|
var _a2, _b2, _c2;
|
|
767
831
|
let payload;
|
|
@@ -970,6 +1034,7 @@ export {
|
|
|
970
1034
|
SHOPPING_ASSISTANT_FLOW,
|
|
971
1035
|
SHOPPING_ASSISTANT_METADATA_FLOW,
|
|
972
1036
|
STOREFRONT_ASSISTANT_FLOW,
|
|
1037
|
+
WEBMCP_STOREFRONT_FLOW,
|
|
973
1038
|
createChatProxyApp,
|
|
974
1039
|
createCheckoutSession,
|
|
975
1040
|
createVercelHandler,
|