@copilotkit/shared 2.0.0-rc.0 → 2.0.0-rc.10
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/README.md +3 -14
- package/dist/a2ui-prompts.cjs +21 -62
- package/dist/a2ui-prompts.cjs.map +1 -1
- package/dist/a2ui-prompts.d.cts +8 -1
- package/dist/a2ui-prompts.d.cts.map +1 -1
- package/dist/a2ui-prompts.d.mts +8 -1
- package/dist/a2ui-prompts.d.mts.map +1 -1
- package/dist/a2ui-prompts.mjs +22 -62
- package/dist/a2ui-prompts.mjs.map +1 -1
- package/dist/generative-ui/basic-functions.cjs +1 -1
- package/dist/generative-ui/basic-functions.cjs.map +1 -1
- package/dist/generative-ui/basic-functions.mjs +1 -1
- package/dist/generative-ui/basic-functions.mjs.map +1 -1
- package/dist/generative-ui/compact-schema.cjs +187 -0
- package/dist/generative-ui/compact-schema.cjs.map +1 -0
- package/dist/generative-ui/compact-schema.d.cts +55 -0
- package/dist/generative-ui/compact-schema.d.cts.map +1 -0
- package/dist/generative-ui/compact-schema.d.mts +55 -0
- package/dist/generative-ui/compact-schema.d.mts.map +1 -0
- package/dist/generative-ui/compact-schema.mjs +185 -0
- package/dist/generative-ui/compact-schema.mjs.map +1 -0
- package/dist/generative-ui/prompt-spec.cjs +225 -0
- package/dist/generative-ui/prompt-spec.cjs.map +1 -0
- package/dist/generative-ui/prompt-spec.d.cts +94 -0
- package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
- package/dist/generative-ui/prompt-spec.d.mts +94 -0
- package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
- package/dist/generative-ui/prompt-spec.mjs +220 -0
- package/dist/generative-ui/prompt-spec.mjs.map +1 -0
- package/dist/generative-ui/prompt.cjs +10 -36
- package/dist/generative-ui/prompt.cjs.map +1 -1
- package/dist/generative-ui/prompt.d.cts +2 -1
- package/dist/generative-ui/prompt.d.cts.map +1 -1
- package/dist/generative-ui/prompt.d.mts +2 -1
- package/dist/generative-ui/prompt.d.mts.map +1 -1
- package/dist/generative-ui/prompt.mjs +12 -38
- package/dist/generative-ui/prompt.mjs.map +1 -1
- package/dist/generative-ui/schema-render.cjs +242 -0
- package/dist/generative-ui/schema-render.cjs.map +1 -0
- package/dist/generative-ui/schema-render.d.cts +44 -0
- package/dist/generative-ui/schema-render.d.cts.map +1 -0
- package/dist/generative-ui/schema-render.d.mts +44 -0
- package/dist/generative-ui/schema-render.d.mts.map +1 -0
- package/dist/generative-ui/schema-render.mjs +239 -0
- package/dist/generative-ui/schema-render.mjs.map +1 -0
- package/dist/index.cjs +17 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -9
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +9 -7
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +808 -438
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/standard-schema.cjs +20 -7
- package/dist/standard-schema.cjs.map +1 -1
- package/dist/standard-schema.d.cts +15 -16
- package/dist/standard-schema.d.cts.map +1 -1
- package/dist/standard-schema.d.mts +15 -16
- package/dist/standard-schema.d.mts.map +1 -1
- package/dist/standard-schema.mjs +20 -8
- package/dist/standard-schema.mjs.map +1 -1
- package/dist/telemetry/lambda-client.cjs.map +1 -1
- package/dist/telemetry/lambda-client.d.cts.map +1 -1
- package/dist/telemetry/lambda-client.d.mts.map +1 -1
- package/dist/telemetry/lambda-client.mjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.cjs +3 -6
- package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.cts +0 -5
- package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.mts +0 -5
- package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
- package/dist/telemetry/telemetry-disabled.mjs +4 -6
- package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
- package/dist/types/message.d.cts +1 -18
- package/dist/types/message.d.cts.map +1 -1
- package/dist/types/message.d.mts +1 -18
- package/dist/types/message.d.mts.map +1 -1
- package/dist/utils/errors.cjs +4 -42
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.d.cts +16 -34
- package/dist/utils/errors.d.cts.map +1 -1
- package/dist/utils/errors.d.mts +16 -34
- package/dist/utils/errors.d.mts.map +1 -1
- package/dist/utils/errors.mjs +5 -41
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/index.cjs +1 -2
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +4 -5
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +4 -5
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +4 -5
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/json-schema.cjs +0 -79
- package/dist/utils/json-schema.cjs.map +1 -1
- package/dist/utils/json-schema.d.cts +1 -4
- package/dist/utils/json-schema.d.cts.map +1 -1
- package/dist/utils/json-schema.d.mts +1 -4
- package/dist/utils/json-schema.d.mts.map +1 -1
- package/dist/utils/json-schema.mjs +1 -78
- package/dist/utils/json-schema.mjs.map +1 -1
- package/dist/utils/process-env.cjs +14 -0
- package/dist/utils/process-env.cjs.map +1 -0
- package/dist/utils/process-env.d.cts +10 -0
- package/dist/utils/process-env.d.cts.map +1 -0
- package/dist/utils/process-env.d.mts +10 -0
- package/dist/utils/process-env.d.mts.map +1 -0
- package/dist/utils/process-env.mjs +13 -0
- package/dist/utils/process-env.mjs.map +1 -0
- package/dist/utils/random-id.cjs +13 -26
- package/dist/utils/random-id.cjs.map +1 -1
- package/dist/utils/random-id.d.cts +6 -3
- package/dist/utils/random-id.d.cts.map +1 -1
- package/dist/utils/random-id.d.mts +6 -3
- package/dist/utils/random-id.d.mts.map +1 -1
- package/dist/utils/random-id.mjs +14 -25
- package/dist/utils/random-id.mjs.map +1 -1
- package/package.json +7 -31
- package/src/__tests__/a2ui-prompts.test.ts +42 -9
- package/src/__tests__/fixtures/prompt-goldens.json +354 -0
- package/src/__tests__/prompt-spec.test.ts +191 -0
- package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
- package/src/__tests__/schema-render.test.ts +245 -0
- package/src/__tests__/standard-schema.test.ts +61 -101
- package/src/a2ui-prompts.ts +47 -96
- package/src/generative-ui/basic-functions.ts +1 -1
- package/src/generative-ui/compact-schema.ts +277 -0
- package/src/generative-ui/index.ts +3 -0
- package/src/generative-ui/prompt-spec.ts +335 -0
- package/src/generative-ui/prompt.ts +25 -75
- package/src/generative-ui/schema-render.ts +374 -0
- package/src/index.ts +3 -16
- package/src/standard-schema.ts +24 -27
- package/src/telemetry/lambda-client.ts +3 -2
- package/src/telemetry/telemetry-disabled.ts +7 -12
- package/src/types/message.ts +1 -19
- package/src/utils/__tests__/errors.test.ts +44 -0
- package/src/utils/__tests__/json-schema.test.ts +3 -479
- package/src/utils/__tests__/process-env.test.ts +22 -0
- package/src/utils/__tests__/random-id.test.ts +37 -0
- package/src/utils/errors.ts +27 -85
- package/src/utils/index.ts +1 -2
- package/src/utils/json-schema.ts +1 -152
- package/src/utils/process-env.ts +14 -0
- package/src/utils/random-id.ts +17 -37
- package/tsdown.config.ts +2 -19
- package/dist/event-transforms/index.cjs +0 -15
- package/dist/event-transforms/index.d.cts +0 -4
- package/dist/event-transforms/index.d.mts +0 -4
- package/dist/event-transforms/index.mjs +0 -5
- package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
- package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
- package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
- package/dist/event-transforms/recorded-events.cjs +0 -59
- package/dist/event-transforms/recorded-events.cjs.map +0 -1
- package/dist/event-transforms/recorded-events.d.cts +0 -23
- package/dist/event-transforms/recorded-events.d.cts.map +0 -1
- package/dist/event-transforms/recorded-events.d.mts +0 -23
- package/dist/event-transforms/recorded-events.d.mts.map +0 -1
- package/dist/event-transforms/recorded-events.mjs +0 -58
- package/dist/event-transforms/recorded-events.mjs.map +0 -1
- package/dist/telemetry/events.d.cts +0 -72
- package/dist/telemetry/events.d.cts.map +0 -1
- package/dist/telemetry/events.d.mts +0 -72
- package/dist/telemetry/events.d.mts.map +0 -1
- package/dist/telemetry/index.cjs +0 -18
- package/dist/telemetry/index.d.cts +0 -5
- package/dist/telemetry/index.d.mts +0 -5
- package/dist/telemetry/index.mjs +0 -6
- package/dist/telemetry/telemetry-client.cjs +0 -165
- package/dist/telemetry/telemetry-client.cjs.map +0 -1
- package/dist/telemetry/telemetry-client.d.cts +0 -87
- package/dist/telemetry/telemetry-client.d.cts.map +0 -1
- package/dist/telemetry/telemetry-client.d.mts +0 -87
- package/dist/telemetry/telemetry-client.d.mts.map +0 -1
- package/dist/telemetry/telemetry-client.mjs +0 -164
- package/dist/telemetry/telemetry-client.mjs.map +0 -1
- package/dist/telemetry/utils.cjs +0 -14
- package/dist/telemetry/utils.cjs.map +0 -1
- package/dist/telemetry/utils.mjs +0 -13
- package/dist/telemetry/utils.mjs.map +0 -1
- package/dist/utils/conditions.cjs +0 -32
- package/dist/utils/conditions.cjs.map +0 -1
- package/dist/utils/conditions.d.cts +0 -31
- package/dist/utils/conditions.d.cts.map +0 -1
- package/dist/utils/conditions.d.mts +0 -31
- package/dist/utils/conditions.d.mts.map +0 -1
- package/dist/utils/conditions.mjs +0 -31
- package/dist/utils/conditions.mjs.map +0 -1
- package/dist/utils/console-styling.cjs +0 -91
- package/dist/utils/console-styling.cjs.map +0 -1
- package/dist/utils/console-styling.d.cts +0 -65
- package/dist/utils/console-styling.d.cts.map +0 -1
- package/dist/utils/console-styling.d.mts +0 -65
- package/dist/utils/console-styling.d.mts.map +0 -1
- package/dist/utils/console-styling.mjs +0 -85
- package/dist/utils/console-styling.mjs.map +0 -1
- package/src/__tests__/zod-regression.test.ts +0 -319
- package/src/event-transforms/index.ts +0 -5
- package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
- package/src/event-transforms/recorded-events.test.ts +0 -166
- package/src/event-transforms/recorded-events.ts +0 -74
- package/src/telemetry/events.ts +0 -68
- package/src/telemetry/index.ts +0 -9
- package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
- package/src/telemetry/telemetry-client.test.ts +0 -798
- package/src/telemetry/telemetry-client.ts +0 -328
- package/src/telemetry/utils.ts +0 -15
- package/src/utils/__tests__/conditions.test.ts +0 -161
- package/src/utils/conditions.ts +0 -116
- package/src/utils/console-styling.ts +0 -126
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitShared = {}), global.
|
|
5
|
-
})(this, function(exports,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('partial-json'), require('@ag-ui/client')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'partial-json', '@ag-ui/client'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitShared = {}), global.PartialJSON,global.AgUIClient));
|
|
5
|
+
})(this, function(exports, partial_json, _ag_ui_client) {
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
7
7
|
//#region \0rolldown/runtime.js
|
|
8
8
|
var __create = Object.create;
|
|
@@ -58,118 +58,6 @@ partial_json = __toESM(partial_json);
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/utils/conditions.ts
|
|
63
|
-
function executeConditions({ conditions, value }) {
|
|
64
|
-
if (!(conditions === null || conditions === void 0 ? void 0 : conditions.length)) return true;
|
|
65
|
-
return conditions.every((condition) => executeCondition(condition, value));
|
|
66
|
-
}
|
|
67
|
-
function executeCondition(condition, value) {
|
|
68
|
-
const targetValue = condition.path ? getValueFromPath(value, condition.path) : value;
|
|
69
|
-
switch (condition.rule) {
|
|
70
|
-
case "AND": return condition.conditions.every((c) => executeCondition(c, value));
|
|
71
|
-
case "OR": return condition.conditions.some((c) => executeCondition(c, value));
|
|
72
|
-
case "NOT": return !condition.conditions.every((c) => executeCondition(c, value));
|
|
73
|
-
case "EQUALS": return targetValue === condition.value;
|
|
74
|
-
case "NOT_EQUALS": return targetValue !== condition.value;
|
|
75
|
-
case "GREATER_THAN": return targetValue > condition.value;
|
|
76
|
-
case "LESS_THAN": return targetValue < condition.value;
|
|
77
|
-
case "CONTAINS": return Array.isArray(targetValue) && targetValue.includes(condition.value);
|
|
78
|
-
case "NOT_CONTAINS": return Array.isArray(targetValue) && !targetValue.includes(condition.value);
|
|
79
|
-
case "MATCHES": return new RegExp(condition.value).test(String(targetValue));
|
|
80
|
-
case "STARTS_WITH": return String(targetValue).startsWith(condition.value);
|
|
81
|
-
case "ENDS_WITH": return String(targetValue).endsWith(condition.value);
|
|
82
|
-
case "EXISTS": return targetValue !== void 0 && targetValue !== null;
|
|
83
|
-
case "NOT_EXISTS": return targetValue === void 0 || targetValue === null;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function getValueFromPath(obj, path) {
|
|
87
|
-
return path.split(".").reduce((acc, part) => acc === null || acc === void 0 ? void 0 : acc[part], obj);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/utils/console-styling.ts
|
|
92
|
-
/**
|
|
93
|
-
* Console styling utilities for CopilotKit branded messages
|
|
94
|
-
* Provides consistent, readable colors across light and dark console themes
|
|
95
|
-
*/
|
|
96
|
-
/**
|
|
97
|
-
* Color palette optimized for console readability
|
|
98
|
-
*/
|
|
99
|
-
const ConsoleColors = {
|
|
100
|
-
primary: "#007acc",
|
|
101
|
-
success: "#22c55e",
|
|
102
|
-
feature: "#a855f7",
|
|
103
|
-
cta: "#ef4444",
|
|
104
|
-
info: "#06b6d4",
|
|
105
|
-
inherit: "inherit",
|
|
106
|
-
warning: "#f59e0b"
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Console style templates for common patterns
|
|
110
|
-
*/
|
|
111
|
-
const ConsoleStyles = {
|
|
112
|
-
header: `color: ${ConsoleColors.warning}; font-weight: bold; font-size: 16px;`,
|
|
113
|
-
section: `color: ${ConsoleColors.success}; font-weight: bold;`,
|
|
114
|
-
highlight: `color: ${ConsoleColors.feature}; font-weight: bold;`,
|
|
115
|
-
cta: `color: ${ConsoleColors.success}; font-weight: bold;`,
|
|
116
|
-
info: `color: ${ConsoleColors.info}; font-weight: bold;`,
|
|
117
|
-
link: `color: ${ConsoleColors.primary}; text-decoration: underline;`,
|
|
118
|
-
body: `color: ${ConsoleColors.inherit};`,
|
|
119
|
-
warning: `color: ${ConsoleColors.cta}; font-weight: bold;`
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* Styled console message for CopilotKit Platform promotion
|
|
123
|
-
* Displays a beautiful, branded advertisement in the console
|
|
124
|
-
*/
|
|
125
|
-
function logCopilotKitPlatformMessage() {
|
|
126
|
-
console.log(`%cCopilotKit Warning%c
|
|
127
|
-
|
|
128
|
-
useCopilotChatHeadless_c provides full compatibility with CopilotKit's newly released Headless UI feature set. Headless UI requires a CopilotKit Intelligence license key, available for free at:
|
|
129
|
-
|
|
130
|
-
%chttps://dashboard.operations.copilotkit.ai%c
|
|
131
|
-
|
|
132
|
-
Alternatively, useCopilotChat is available for basic programmatic control, and does not require a license key.
|
|
133
|
-
|
|
134
|
-
To learn more about CopilotKit Intelligence, read the documentation here:
|
|
135
|
-
|
|
136
|
-
%chttps://docs.copilotkit.ai/intelligence/overview%c`, ConsoleStyles.header, ConsoleStyles.body, ConsoleStyles.cta, ConsoleStyles.body, ConsoleStyles.link, ConsoleStyles.body);
|
|
137
|
-
}
|
|
138
|
-
function publicApiKeyRequired(feature) {
|
|
139
|
-
console.log(`
|
|
140
|
-
%cCopilotKit Warning%c \n
|
|
141
|
-
In order to use ${feature}, you need to add your CopilotKit license key, available for free at https://dashboard.operations.copilotkit.ai.
|
|
142
|
-
`.trim(), ConsoleStyles.header, ConsoleStyles.body);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Create a styled console message with custom content
|
|
146
|
-
*
|
|
147
|
-
* @param template - Template string with %c placeholders
|
|
148
|
-
* @param styles - Array of style strings matching the %c placeholders
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* logStyled(
|
|
153
|
-
* '%cCopilotKit%c Welcome to the platform!',
|
|
154
|
-
* [ConsoleStyles.header, ConsoleStyles.body]
|
|
155
|
-
* );
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
function logStyled(template, styles) {
|
|
159
|
-
console.log(template, ...styles);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Quick styled console methods for common use cases
|
|
163
|
-
*/
|
|
164
|
-
const styledConsole = {
|
|
165
|
-
success: (message) => logStyled(`%c✅ ${message}`, [ConsoleStyles.section]),
|
|
166
|
-
info: (message) => logStyled(`%cℹ️ ${message}`, [ConsoleStyles.info]),
|
|
167
|
-
feature: (message) => logStyled(`%c✨ ${message}`, [ConsoleStyles.highlight]),
|
|
168
|
-
cta: (message) => logStyled(`%c🚀 ${message}`, [ConsoleStyles.cta]),
|
|
169
|
-
logCopilotKitPlatformMessage,
|
|
170
|
-
publicApiKeyRequired
|
|
171
|
-
};
|
|
172
|
-
|
|
173
61
|
//#endregion
|
|
174
62
|
//#region src/utils/errors.ts
|
|
175
63
|
let Severity = /* @__PURE__ */ function(Severity) {
|
|
@@ -191,7 +79,6 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
191
79
|
COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError",
|
|
192
80
|
COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError",
|
|
193
81
|
COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError",
|
|
194
|
-
COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError",
|
|
195
82
|
RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError",
|
|
196
83
|
CONFIGURATION_ERROR: "ConfigurationError",
|
|
197
84
|
MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError",
|
|
@@ -296,7 +183,7 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
296
183
|
severity: Severity.INFO
|
|
297
184
|
}
|
|
298
185
|
};
|
|
299
|
-
var CopilotKitError = class extends
|
|
186
|
+
var CopilotKitError = class extends Error {
|
|
300
187
|
constructor({ message = "Unknown error occurred", code, severity, visibility }) {
|
|
301
188
|
var _ref;
|
|
302
189
|
const name = ERROR_NAMES.COPILOT_ERROR;
|
|
@@ -304,7 +191,8 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
304
191
|
const { statusCode } = config;
|
|
305
192
|
const resolvedVisibility = (_ref = visibility !== null && visibility !== void 0 ? visibility : config.visibility) !== null && _ref !== void 0 ? _ref : ErrorVisibility.TOAST;
|
|
306
193
|
const resolvedSeverity = severity !== null && severity !== void 0 ? severity : "severity" in config ? config.severity : void 0;
|
|
307
|
-
super(message
|
|
194
|
+
super(message);
|
|
195
|
+
this.extensions = {
|
|
308
196
|
name,
|
|
309
197
|
statusCode,
|
|
310
198
|
code,
|
|
@@ -315,7 +203,7 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
315
203
|
message,
|
|
316
204
|
stack: (/* @__PURE__ */ new Error()).stack
|
|
317
205
|
}
|
|
318
|
-
}
|
|
206
|
+
};
|
|
319
207
|
this.code = code;
|
|
320
208
|
this.name = name;
|
|
321
209
|
this.statusCode = statusCode;
|
|
@@ -340,26 +228,6 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
340
228
|
this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
|
|
341
229
|
}
|
|
342
230
|
};
|
|
343
|
-
const getVersionMismatchErrorMessage = ({ reactCoreVersion, runtimeVersion, runtimeClientGqlVersion }) => `Version mismatch detected: @copilotkit/runtime@${runtimeVersion !== null && runtimeVersion !== void 0 ? runtimeVersion : ""} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;
|
|
344
|
-
/**
|
|
345
|
-
* Error thrown when CPK versions does not match
|
|
346
|
-
*
|
|
347
|
-
* @extends CopilotKitError
|
|
348
|
-
*/
|
|
349
|
-
var CopilotKitVersionMismatchError = class extends CopilotKitError {
|
|
350
|
-
constructor({ reactCoreVersion, runtimeVersion, runtimeClientGqlVersion }) {
|
|
351
|
-
const code = CopilotKitErrorCode.VERSION_MISMATCH;
|
|
352
|
-
super({
|
|
353
|
-
message: getVersionMismatchErrorMessage({
|
|
354
|
-
reactCoreVersion,
|
|
355
|
-
runtimeVersion,
|
|
356
|
-
runtimeClientGqlVersion
|
|
357
|
-
}),
|
|
358
|
-
code
|
|
359
|
-
});
|
|
360
|
-
this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
231
|
/**
|
|
364
232
|
* Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.
|
|
365
233
|
* This typically occurs when:
|
|
@@ -550,19 +418,6 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
550
418
|
function ensureStructuredError(error, converter) {
|
|
551
419
|
return isStructuredCopilotKitError(error) ? error : converter(error);
|
|
552
420
|
}
|
|
553
|
-
async function getPossibleVersionMismatch({ runtimeVersion, runtimeClientGqlVersion }) {
|
|
554
|
-
if (!runtimeVersion || runtimeVersion === "" || !runtimeClientGqlVersion) return;
|
|
555
|
-
if (COPILOTKIT_VERSION !== runtimeVersion || COPILOTKIT_VERSION !== runtimeClientGqlVersion || runtimeVersion !== runtimeClientGqlVersion) return {
|
|
556
|
-
runtimeVersion,
|
|
557
|
-
runtimeClientGqlVersion,
|
|
558
|
-
reactCoreVersion: COPILOTKIT_VERSION,
|
|
559
|
-
message: getVersionMismatchErrorMessage({
|
|
560
|
-
runtimeVersion,
|
|
561
|
-
runtimeClientGqlVersion,
|
|
562
|
-
reactCoreVersion: COPILOTKIT_VERSION
|
|
563
|
-
})
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
421
|
const resolveLowLevelErrorMessage = ({ errorCode, url }) => {
|
|
567
422
|
const troubleshootingLink = ERROR_CONFIG[CopilotKitErrorCode.NETWORK_ERROR].troubleshootingUrl;
|
|
568
423
|
const genericMessage = (description = `Failed to fetch from url ${url}.`) => `${description}.
|
|
@@ -720,82 +575,6 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
720
575
|
};
|
|
721
576
|
}
|
|
722
577
|
}
|
|
723
|
-
function convertJsonSchemaToZodSchema(jsonSchema, required, definitions, visitedRefs) {
|
|
724
|
-
var _ref, _jsonSchema$anyOf, _jsonSchema$type;
|
|
725
|
-
if (jsonSchema.$ref && definitions) {
|
|
726
|
-
const refPath = jsonSchema.$ref.replace(/^#\/\$defs\/|^#\/definitions\//, "");
|
|
727
|
-
const refs = visitedRefs !== null && visitedRefs !== void 0 ? visitedRefs : /* @__PURE__ */ new Set();
|
|
728
|
-
if (refs.has(refPath)) {
|
|
729
|
-
console.warn(`[CopilotKit] Circular $ref detected for "${refPath}" — falling back to z.any()`);
|
|
730
|
-
let schema = zod.z.any();
|
|
731
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
732
|
-
return required ? schema : schema.optional();
|
|
733
|
-
}
|
|
734
|
-
const resolved = definitions[refPath];
|
|
735
|
-
if (resolved) {
|
|
736
|
-
const nextRefs = new Set(refs);
|
|
737
|
-
nextRefs.add(refPath);
|
|
738
|
-
return convertJsonSchemaToZodSchema(resolved, required, definitions, nextRefs);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
const defs = (_ref = definitions !== null && definitions !== void 0 ? definitions : jsonSchema.$defs) !== null && _ref !== void 0 ? _ref : jsonSchema.definitions;
|
|
742
|
-
if (Array.isArray(jsonSchema.type)) {
|
|
743
|
-
const types = jsonSchema.type;
|
|
744
|
-
const hasNull = types.includes("null");
|
|
745
|
-
const nonNullTypes = types.filter((t) => t !== "null");
|
|
746
|
-
const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : "string";
|
|
747
|
-
const innerSchema = convertJsonSchemaToZodSchema({
|
|
748
|
-
...jsonSchema,
|
|
749
|
-
type: resolvedType
|
|
750
|
-
}, true, defs, visitedRefs);
|
|
751
|
-
let schema = hasNull ? zod.z.union([innerSchema, zod.z.null()]) : innerSchema;
|
|
752
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
753
|
-
return required ? schema : schema.optional();
|
|
754
|
-
}
|
|
755
|
-
const unionVariants = (_jsonSchema$anyOf = jsonSchema.anyOf) !== null && _jsonSchema$anyOf !== void 0 ? _jsonSchema$anyOf : jsonSchema.oneOf;
|
|
756
|
-
if (Array.isArray(unionVariants) && unionVariants.length > 0) {
|
|
757
|
-
if (unionVariants.length === 1) return convertJsonSchemaToZodSchema(unionVariants[0], required, defs, visitedRefs);
|
|
758
|
-
const schemas = unionVariants.map((v) => convertJsonSchemaToZodSchema(v, true, defs, visitedRefs));
|
|
759
|
-
let schema = zod.z.union(schemas);
|
|
760
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
761
|
-
return required ? schema : schema.optional();
|
|
762
|
-
}
|
|
763
|
-
if (jsonSchema.type === "object") {
|
|
764
|
-
const spec = {};
|
|
765
|
-
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) return !required ? zod.z.object(spec).optional() : zod.z.object(spec);
|
|
766
|
-
for (const [key, value] of Object.entries(jsonSchema.properties)) spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false, defs, visitedRefs);
|
|
767
|
-
let schema = zod.z.object(spec).describe(jsonSchema.description);
|
|
768
|
-
return required ? schema : schema.optional();
|
|
769
|
-
} else if (jsonSchema.type === "string") {
|
|
770
|
-
if (jsonSchema.enum && jsonSchema.enum.length > 0) {
|
|
771
|
-
let schema = zod.z.enum(jsonSchema.enum).describe(jsonSchema.description);
|
|
772
|
-
return required ? schema : schema.optional();
|
|
773
|
-
}
|
|
774
|
-
let schema = zod.z.string().describe(jsonSchema.description);
|
|
775
|
-
return required ? schema : schema.optional();
|
|
776
|
-
} else if (jsonSchema.type === "number" || jsonSchema.type === "integer") {
|
|
777
|
-
let schema = zod.z.number().describe(jsonSchema.description);
|
|
778
|
-
return required ? schema : schema.optional();
|
|
779
|
-
} else if (jsonSchema.type === "boolean") {
|
|
780
|
-
let schema = zod.z.boolean().describe(jsonSchema.description);
|
|
781
|
-
return required ? schema : schema.optional();
|
|
782
|
-
} else if (jsonSchema.type === "array") {
|
|
783
|
-
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true, defs, visitedRefs);
|
|
784
|
-
let schema = zod.z.array(itemSchema).describe(jsonSchema.description);
|
|
785
|
-
return required ? schema : schema.optional();
|
|
786
|
-
} else if (jsonSchema.type === "null") {
|
|
787
|
-
let schema = zod.z.null().describe(jsonSchema.description);
|
|
788
|
-
return required ? schema : schema.optional();
|
|
789
|
-
}
|
|
790
|
-
console.warn(`[CopilotKit] Unsupported JSON schema type "${(_jsonSchema$type = jsonSchema.type) !== null && _jsonSchema$type !== void 0 ? _jsonSchema$type : "unknown"}" — falling back to z.any()`);
|
|
791
|
-
let schema = zod.z.any();
|
|
792
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
793
|
-
return required ? schema : schema.optional();
|
|
794
|
-
}
|
|
795
|
-
function getZodParameters(parameters) {
|
|
796
|
-
if (!parameters) return zod.z.object({});
|
|
797
|
-
return convertJsonSchemaToZodSchema(actionParametersToJsonSchema(parameters), true);
|
|
798
|
-
}
|
|
799
578
|
|
|
800
579
|
//#endregion
|
|
801
580
|
//#region src/utils/dashboard-url.ts
|
|
@@ -815,7 +594,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
815
594
|
|
|
816
595
|
//#endregion
|
|
817
596
|
//#region src/utils/inspector-metadata.ts
|
|
818
|
-
function isRecord$
|
|
597
|
+
function isRecord$3(value) {
|
|
819
598
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
820
599
|
try {
|
|
821
600
|
const prototype = Object.getPrototypeOf(value);
|
|
@@ -838,7 +617,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
838
617
|
return parsed.length > 0 ? parsed : void 0;
|
|
839
618
|
}
|
|
840
619
|
function parseIdentity(value) {
|
|
841
|
-
if (!isRecord$
|
|
620
|
+
if (!isRecord$3(value)) return;
|
|
842
621
|
const organizationName = parseNonBlankString(value.organizationName);
|
|
843
622
|
const projectName = parseNonBlankString(value.projectName);
|
|
844
623
|
if (organizationName === void 0 || projectName === void 0) return;
|
|
@@ -848,7 +627,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
848
627
|
};
|
|
849
628
|
}
|
|
850
629
|
function parsePlan(value) {
|
|
851
|
-
if (!isRecord$
|
|
630
|
+
if (!isRecord$3(value)) return;
|
|
852
631
|
const code = parseNonBlankString(value.code);
|
|
853
632
|
const label = parseNonBlankString(value.label);
|
|
854
633
|
if (code === void 0 || label === void 0) return;
|
|
@@ -858,7 +637,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
858
637
|
};
|
|
859
638
|
}
|
|
860
639
|
function parseLicense(value) {
|
|
861
|
-
if (!isRecord$
|
|
640
|
+
if (!isRecord$3(value)) return;
|
|
862
641
|
switch (value.state) {
|
|
863
642
|
case "valid":
|
|
864
643
|
case "none":
|
|
@@ -893,7 +672,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
893
672
|
return isSafeDashboardUrl(parsed) ? url : void 0;
|
|
894
673
|
}
|
|
895
674
|
function parseAction(value) {
|
|
896
|
-
if (!isRecord$
|
|
675
|
+
if (!isRecord$3(value)) return;
|
|
897
676
|
const kind = parseActionKind(value.kind);
|
|
898
677
|
const url = parseSafeActionUrl(value.url);
|
|
899
678
|
if (kind === void 0 || url === void 0) return;
|
|
@@ -906,7 +685,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
906
685
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
907
686
|
}
|
|
908
687
|
function parseUsageLimit(value) {
|
|
909
|
-
if (!isRecord$
|
|
688
|
+
if (!isRecord$3(value)) return;
|
|
910
689
|
if (value.kind === "finite") {
|
|
911
690
|
if (typeof value.value !== "number" || !Number.isSafeInteger(value.value) || value.value < 1) return;
|
|
912
691
|
return {
|
|
@@ -918,7 +697,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
918
697
|
if (value.kind === "unknown") return { kind: "unknown" };
|
|
919
698
|
}
|
|
920
699
|
function parseUsage(value) {
|
|
921
|
-
if (!isRecord$
|
|
700
|
+
if (!isRecord$3(value)) return;
|
|
922
701
|
const limit = parseUsageLimit(value.limit);
|
|
923
702
|
const used = value.used;
|
|
924
703
|
if (!isFiniteNonnegativeInteger(used) || limit === void 0) return;
|
|
@@ -939,7 +718,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
939
718
|
* top-level payload.
|
|
940
719
|
*/
|
|
941
720
|
function parseInspectorMetadataV1(value) {
|
|
942
|
-
if (!isRecord$
|
|
721
|
+
if (!isRecord$3(value) || value.schemaVersion !== 1) return;
|
|
943
722
|
const identity = parseIdentity(value.identity);
|
|
944
723
|
const plan = parsePlan(value.plan);
|
|
945
724
|
const license = parseLicense(value.license);
|
|
@@ -1184,31 +963,34 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1184
963
|
//#endregion
|
|
1185
964
|
//#region src/utils/random-id.ts
|
|
1186
965
|
function randomId() {
|
|
1187
|
-
return "ck-" + (
|
|
1188
|
-
}
|
|
1189
|
-
function randomUUID() {
|
|
1190
|
-
return (0, uuid.v4)();
|
|
966
|
+
return "ck-" + randomUUID();
|
|
1191
967
|
}
|
|
1192
968
|
/**
|
|
1193
|
-
*
|
|
969
|
+
* Returns an RFC 4122 version 4 UUID. Uses `crypto.randomUUID()` when it
|
|
970
|
+
* exists, and builds the UUID from `crypto.getRandomValues()` when it does not
|
|
971
|
+
* (React Native's Hermes has no `randomUUID`).
|
|
1194
972
|
*/
|
|
1195
|
-
function
|
|
1196
|
-
|
|
1197
|
-
if (
|
|
1198
|
-
if (
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
return
|
|
1204
|
-
}
|
|
1205
|
-
function dataToUUID(input, namespace) {
|
|
1206
|
-
const BASE_NAMESPACE = "e4b01160-ff74-4c6e-9b27-d53cd930fe8e";
|
|
1207
|
-
const boundNamespace = namespace ? (0, uuid.v5)(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;
|
|
1208
|
-
return (0, uuid.v5)(typeof input === "string" ? input : JSON.stringify(toSerializable(input)), boundNamespace);
|
|
973
|
+
function randomUUID() {
|
|
974
|
+
const crypto = globalThis.crypto;
|
|
975
|
+
if (typeof (crypto === null || crypto === void 0 ? void 0 : crypto.randomUUID) === "function") return crypto.randomUUID();
|
|
976
|
+
if (typeof (crypto === null || crypto === void 0 ? void 0 : crypto.getRandomValues) !== "function") throw new Error("crypto.getRandomValues() is not available. In React Native, install a polyfill such as react-native-get-random-values.");
|
|
977
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
978
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
979
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
980
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
|
|
981
|
+
return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
|
|
1209
982
|
}
|
|
1210
|
-
|
|
1211
|
-
|
|
983
|
+
|
|
984
|
+
//#endregion
|
|
985
|
+
//#region src/utils/process-env.ts
|
|
986
|
+
/**
|
|
987
|
+
* The process environment, or an empty object where there is no `process`
|
|
988
|
+
* (Cloudflare Workers without `nodejs_compat`, browsers). Read it on each use
|
|
989
|
+
* rather than caching it, so later changes to `process.env` are seen.
|
|
990
|
+
*/
|
|
991
|
+
function processEnv() {
|
|
992
|
+
var _process$env, _process;
|
|
993
|
+
return (_process$env = (_process = globalThis.process) === null || _process === void 0 ? void 0 : _process.env) !== null && _process$env !== void 0 ? _process$env : {};
|
|
1212
994
|
}
|
|
1213
995
|
|
|
1214
996
|
//#endregion
|
|
@@ -1575,14 +1357,10 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1575
1357
|
* Users can opt out by setting:
|
|
1576
1358
|
* - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1
|
|
1577
1359
|
* - DO_NOT_TRACK=true or DO_NOT_TRACK=1
|
|
1578
|
-
*
|
|
1579
|
-
* Lives in its own module so that the browser-facing root entry can
|
|
1580
|
-
* re-export it without pulling in `telemetry-client.ts`, whose
|
|
1581
|
-
* `@segment/analytics-node` import drags Node built-ins into browser
|
|
1582
|
-
* bundler module graphs. See the note in `../index.ts`.
|
|
1583
1360
|
*/
|
|
1584
1361
|
function isTelemetryDisabled() {
|
|
1585
|
-
|
|
1362
|
+
const env = processEnv();
|
|
1363
|
+
return env.COPILOTKIT_TELEMETRY_DISABLED === "true" || env.COPILOTKIT_TELEMETRY_DISABLED === "1" || env.DO_NOT_TRACK === "true" || env.DO_NOT_TRACK === "1";
|
|
1586
1364
|
}
|
|
1587
1365
|
|
|
1588
1366
|
//#endregion
|
|
@@ -1854,6 +1632,18 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1854
1632
|
//#endregion
|
|
1855
1633
|
//#region src/standard-schema.ts
|
|
1856
1634
|
/**
|
|
1635
|
+
* A Standard Schema that accepts any value and returns it unchanged.
|
|
1636
|
+
*
|
|
1637
|
+
* Wildcard tool call renderers use it when they declare no `args` schema.
|
|
1638
|
+
*
|
|
1639
|
+
* @internal Application authors must not depend on this contract.
|
|
1640
|
+
*/
|
|
1641
|
+
const ɵanySchema = { "~standard": {
|
|
1642
|
+
version: 1,
|
|
1643
|
+
vendor: "copilotkit",
|
|
1644
|
+
validate: (value) => ({ value })
|
|
1645
|
+
} };
|
|
1646
|
+
/**
|
|
1857
1647
|
* Check whether a schema implements the Standard JSON Schema V1 protocol.
|
|
1858
1648
|
*/
|
|
1859
1649
|
function hasStandardJsonSchema(schema) {
|
|
@@ -1866,17 +1656,17 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1866
1656
|
* Strategy:
|
|
1867
1657
|
* 1. If the schema implements Standard JSON Schema V1 (`~standard.jsonSchema`),
|
|
1868
1658
|
* call `schema['~standard'].jsonSchema.input({ target: 'draft-07' })`.
|
|
1869
|
-
* 2
|
|
1870
|
-
*
|
|
1871
|
-
*
|
|
1872
|
-
*
|
|
1659
|
+
* Zod 4.2+, ArkType 2.1.28+ and Valibot (via `toStandardJsonSchema`) do.
|
|
1660
|
+
* 2. If the schema exposes a `toJSONSchema()` method, call it directly.
|
|
1661
|
+
* 3. Otherwise throw a descriptive error. Zod 3 schemas land here: they
|
|
1662
|
+
* implement Standard Schema validation but cannot describe themselves as
|
|
1663
|
+
* JSON Schema.
|
|
1873
1664
|
*/
|
|
1874
|
-
function schemaToJsonSchema(schema
|
|
1665
|
+
function schemaToJsonSchema(schema) {
|
|
1875
1666
|
if (hasStandardJsonSchema(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-07" });
|
|
1876
1667
|
if (typeof schema.toJSONSchema === "function") return schema.toJSONSchema();
|
|
1877
1668
|
const vendor = schema["~standard"].vendor;
|
|
1878
|
-
|
|
1879
|
-
throw new Error(`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1 and no zodToJsonSchema fallback is available. Use a library that supports Standard JSON Schema (e.g., Zod 3.24+, Valibot v1+, ArkType v2+) or pass a zodToJsonSchema function in options.`);
|
|
1669
|
+
throw new Error(`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1. Use a library that does: Zod 4.2+ (Zod 3 is not supported), Valibot v1+ wrapped with toStandardJsonSchema() from @valibot/to-json-schema, or ArkType v2.1.28+.`);
|
|
1880
1670
|
}
|
|
1881
1671
|
|
|
1882
1672
|
//#endregion
|
|
@@ -2323,7 +2113,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2323
2113
|
|
|
2324
2114
|
//#endregion
|
|
2325
2115
|
//#region package.json
|
|
2326
|
-
var version = "2.0.0-rc.
|
|
2116
|
+
var version = "2.0.0-rc.10";
|
|
2327
2117
|
|
|
2328
2118
|
//#endregion
|
|
2329
2119
|
//#region src/generative-ui/basic-functions.ts
|
|
@@ -2451,7 +2241,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2451
2241
|
*/
|
|
2452
2242
|
const COPILOTKIT_FUNCTIONS = rendererOnly({
|
|
2453
2243
|
calc: {
|
|
2454
|
-
description: "The value of an arithmetic expression over the other args, by name: + - * / % ( ), comparisons, && || !, cond ? a : b, min max round floor ceil abs, 'text' + name",
|
|
2244
|
+
description: "The value of an arithmetic expression over the other args, by name: + - * / % ( ), x ^ y (power), comparisons, && || !, cond ? a : b, min max round floor ceil abs pow sqrt exp ln log10, the constants pi and e, 'text' + name",
|
|
2455
2245
|
parameters: "{ expression: string; [name: string]: number | string | boolean }",
|
|
2456
2246
|
returnType: "any",
|
|
2457
2247
|
extension: true
|
|
@@ -2494,7 +2284,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2494
2284
|
//#endregion
|
|
2495
2285
|
//#region src/generative-ui/is-record.ts
|
|
2496
2286
|
/** True for a plain object: not null, not an array. Internal, not exported. */
|
|
2497
|
-
function isRecord(value) {
|
|
2287
|
+
function isRecord$2(value) {
|
|
2498
2288
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2499
2289
|
}
|
|
2500
2290
|
|
|
@@ -2540,7 +2330,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2540
2330
|
const visit = (node) => {
|
|
2541
2331
|
var _marked;
|
|
2542
2332
|
if (Array.isArray(node)) return node.map(visit);
|
|
2543
|
-
if (!isRecord(node)) return node;
|
|
2333
|
+
if (!isRecord$2(node)) return node;
|
|
2544
2334
|
const reference = (_marked = marked(node.description, A2UI_COMPONENT_ID_MARK, A2UI_COMPONENT_ID_REF)) !== null && _marked !== void 0 ? _marked : marked(node.description, A2UI_CHILD_LIST_MARK, A2UI_CHILD_LIST_REF);
|
|
2545
2335
|
if (reference) return reference;
|
|
2546
2336
|
return Object.fromEntries(Object.entries(node).map(([key, value]) => [key, visit(value)]));
|
|
@@ -2567,12 +2357,12 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2567
2357
|
});
|
|
2568
2358
|
};
|
|
2569
2359
|
const visit = (node, path) => {
|
|
2570
|
-
if (!isRecord(node)) return;
|
|
2360
|
+
if (!isRecord$2(node)) return;
|
|
2571
2361
|
const kind = childRefKind(node);
|
|
2572
2362
|
if (kind) return add(path, kind);
|
|
2573
2363
|
for (const list of [node.anyOf, node.oneOf]) {
|
|
2574
2364
|
if (!Array.isArray(list) || list.length === 0) continue;
|
|
2575
|
-
const kinds = list.map((variant) => isRecord(variant) ? childRefKind(variant) : void 0);
|
|
2365
|
+
const kinds = list.map((variant) => isRecord$2(variant) ? childRefKind(variant) : void 0);
|
|
2576
2366
|
const [first] = kinds;
|
|
2577
2367
|
if (first && kinds.every((k) => k === first)) add(path, first);
|
|
2578
2368
|
else if (kinds.every((k) => k === void 0)) {
|
|
@@ -2582,8 +2372,8 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2582
2372
|
}
|
|
2583
2373
|
}
|
|
2584
2374
|
if (Array.isArray(node.allOf)) node.allOf.forEach((variant) => visit(variant, path));
|
|
2585
|
-
if (isRecord(node.properties)) for (const [key, value] of Object.entries(node.properties)) visit(value, [...path, key]);
|
|
2586
|
-
if (isRecord(node.items)) visit(node.items, [...path, "*"]);
|
|
2375
|
+
if (isRecord$2(node.properties)) for (const [key, value] of Object.entries(node.properties)) visit(value, [...path, key]);
|
|
2376
|
+
if (isRecord$2(node.items)) visit(node.items, [...path, "*"]);
|
|
2587
2377
|
};
|
|
2588
2378
|
visit(schema, []);
|
|
2589
2379
|
return refs;
|
|
@@ -2598,7 +2388,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2598
2388
|
const collect = (value) => {
|
|
2599
2389
|
if (typeof value === "string") ids.push(value);
|
|
2600
2390
|
else if (Array.isArray(value)) value.forEach((id) => typeof id === "string" && ids.push(id));
|
|
2601
|
-
else if (isRecord(value) && typeof value.componentId === "string") ids.push(value.componentId);
|
|
2391
|
+
else if (isRecord$2(value) && typeof value.componentId === "string") ids.push(value.componentId);
|
|
2602
2392
|
};
|
|
2603
2393
|
const visit = (value, path) => {
|
|
2604
2394
|
if (path.length === 0) return collect(value);
|
|
@@ -2607,7 +2397,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2607
2397
|
if (Array.isArray(value)) value.forEach((item) => visit(item, rest));
|
|
2608
2398
|
return;
|
|
2609
2399
|
}
|
|
2610
|
-
if (isRecord(value) && Object.prototype.hasOwnProperty.call(value, head)) visit(value[head], rest);
|
|
2400
|
+
if (isRecord$2(value) && Object.prototype.hasOwnProperty.call(value, head)) visit(value[head], rest);
|
|
2611
2401
|
};
|
|
2612
2402
|
for (const ref of refs) visit(component, ref.path);
|
|
2613
2403
|
return ids;
|
|
@@ -2618,13 +2408,13 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2618
2408
|
* at render time.
|
|
2619
2409
|
*/
|
|
2620
2410
|
function hasBoundChildRef(component, refs) {
|
|
2621
|
-
const isDynamic = (value) => isRecord(value) && ("@path" in value || "@call" in value);
|
|
2411
|
+
const isDynamic = (value) => isRecord$2(value) && ("@path" in value || "@call" in value);
|
|
2622
2412
|
const visit = (value, path) => {
|
|
2623
2413
|
if (isDynamic(value)) return true;
|
|
2624
2414
|
if (path.length === 0) return false;
|
|
2625
2415
|
const [head, ...rest] = path;
|
|
2626
2416
|
if (head === "*") return Array.isArray(value) && value.some((item) => visit(item, rest));
|
|
2627
|
-
return isRecord(value) && Object.prototype.hasOwnProperty.call(value, head) && visit(value[head], rest);
|
|
2417
|
+
return isRecord$2(value) && Object.prototype.hasOwnProperty.call(value, head) && visit(value[head], rest);
|
|
2628
2418
|
};
|
|
2629
2419
|
return refs.some((ref) => visit(component, ref.path));
|
|
2630
2420
|
}
|
|
@@ -2640,7 +2430,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2640
2430
|
if (!Array.isArray(value)) return value;
|
|
2641
2431
|
return value.map((item) => mapAtChildRef(item, rest, replace));
|
|
2642
2432
|
}
|
|
2643
|
-
if (!isRecord(value) || !Object.prototype.hasOwnProperty.call(value, head)) return value;
|
|
2433
|
+
if (!isRecord$2(value) || !Object.prototype.hasOwnProperty.call(value, head)) return value;
|
|
2644
2434
|
return {
|
|
2645
2435
|
...value,
|
|
2646
2436
|
[head]: mapAtChildRef(value[head], rest, replace)
|
|
@@ -2732,6 +2522,222 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2732
2522
|
};
|
|
2733
2523
|
}
|
|
2734
2524
|
|
|
2525
|
+
//#endregion
|
|
2526
|
+
//#region src/generative-ui/prompt-spec.ts
|
|
2527
|
+
/**
|
|
2528
|
+
* When UI helps the user, for both transports: a light nudge to reach for UI
|
|
2529
|
+
* where it conveys the answer better than prose, and to stay in prose
|
|
2530
|
+
* otherwise.
|
|
2531
|
+
*/
|
|
2532
|
+
const GENERATIVE_UI_WHEN_TO_SHOW = "Show UI when it conveys the answer better than prose: to illustrate a concept (a diagram, a chart of how something changes), to compare options side by side, to let the user explore or adjust values, or to collect input. A small, focused surface next to your explanation often lands better than a long description. Reply in prose alone for a quick fact, a short answer, or conversation, and never add UI only as decoration.";
|
|
2533
|
+
/**
|
|
2534
|
+
* When and how to show UI in the markdown transport: the answer first, a
|
|
2535
|
+
* map from tasks to components, real interactivity, honest data and
|
|
2536
|
+
* restraint. Measured with tools/genui-eval against the earlier text.
|
|
2537
|
+
*/
|
|
2538
|
+
const GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW = "Answer first: lead with the result or the recommendation in a sentence or two, then show the UI that supports it.\n\nShow UI whenever it makes the answer easier to use, and do not wait for the user to ask for a chart, a calculator or a form. A markdown table or list is not enough when the user would want to change a value, see a shape or a trend, or pick between options. Reply in prose alone only for a greeting or thanks, a one-line fact, a definition, code, or a text the user asked you to write (an email, a message, an update).\n\nMatch the UI to the task:\n- A number that depends on inputs (a price, a loan or mortgage, savings, a conversion, a recipe for N people): a calculator, always. Bind a Slider, TextField or SegmentedControl to the data model and compute the results with calc, so they follow the input. calc has powers, roots and logs, so every input can be a control, also a rate or a term: a monthly payment is rate == 0 ? loan / (years * 12) : loan * (rate / 1200) / (1 - (1 + rate / 1200) ^ -(years * 12)).\n- Choosing between options that share attributes: a Table, or a Grid of EntityCards when each option has a photo, a price or a rating. Plans or offers to pick from: one card each, ending with a Button to choose it.\n- Items with a status, a category or a level: a Badge on each item.\n- Shares, patterns, trends, change over time: a Chart.\n- Places, routes, what is nearby: a Map with the places as markers, next to cards or a List with their details.\n- A sequence or a history: a timeline surface, a List of dated items with a Badge for each era, not a markdown list.\n- How something works, a process, a structure: a diagram drawn with Svg. Draw the real objects as shapes (a cylinder and its piston, a leaf, a server), with arrows for movement or flow and short labels. Labelled boxes of text are not a diagram.\n- A formula or an equation: Math. Solving a math problem: the steps in prose with Math, plus a Chart of the function and a Slider to try values of x.\n- A broad topic (\"tell me about X\"): an overview surface with the key facts, an Image, and a Table or Chart that compares the parts, ending with FollowUp suggestions for what to ask next.\n- Options to choose from (algorithms, products, plans): a Table, plus a SegmentedControl or Select that shows the best option for the user's situation.\n- Research or evidence: a Table of the studies, with a Citation for each source.\n- Things whose look matters (places, products, food): an Image, or the image of an EntityCard.\n- Several inputs, or an action with a side effect (sign-up, booking, contact, scheduling): a Form with fields, checks and a Button. A field with a fixed list of answers (a team size, a topic, a country) is a Select.\n- Practice and learning: a quiz with RadioGroup or ChoicePicker that gives feedback as soon as the user answers, or FlashcardFlip cards. Ask in one language and offer the answers in the other.\n- A plan to follow or tick off: CheckBox items with a progress count that updates as items are ticked.\n- Parallel views (the days of a trip, alternatives): Tabs.\n\nMake interactivity real:\n- Expose the few inputs that change the outcome, with sensible defaults from what the user said.\n- Bind every control to the data model and derive what depends on it with calc or formatString. Controls about the same scenario share the same paths.\n- Every Button does what its label says, and a Link takes \"href\".\n- Never pretend an action happened. For booking, sending or subscribing, show the form and let the user confirm, and say that nothing is sent until they do.\n\nKeep the data honest:\n- Use the facts, places, photos and numbers of the app context when it has them. Never invent prices, availability, ratings, sources or image URLs.\n- Label estimates and assumptions, keep units and currencies consistent, and cite the sources you rely on with Citation.\n\nDesign with restraint:\n- One clear surface beats several. Put the most important result first and make it stand out with a Title, or a Text with size \"lg\". Text sizes go from \"3xs\" to \"lg\"; there is no \"xl\" or \"2xl\".\n- Keep explanations in prose around the surface, not inside it. No decoration, and no surface that only holds text.\n\nBefore you reply, check: does the UI answer the actual question, does every control do something, are the numbers right?";
|
|
2539
|
+
/** The prompts that ship, as a spec. A new object on each call. */
|
|
2540
|
+
/**
|
|
2541
|
+
* The standard components that the default markdown guide names. A guide
|
|
2542
|
+
* line that names one the catalog lacks is left out of the prompt.
|
|
2543
|
+
*/
|
|
2544
|
+
const GUIDE_COMPONENTS = new Set([
|
|
2545
|
+
"Grid",
|
|
2546
|
+
"Card",
|
|
2547
|
+
"Tabs",
|
|
2548
|
+
"Title",
|
|
2549
|
+
"Text",
|
|
2550
|
+
"Label",
|
|
2551
|
+
"Badge",
|
|
2552
|
+
"Math",
|
|
2553
|
+
"Link",
|
|
2554
|
+
"Button",
|
|
2555
|
+
"Form",
|
|
2556
|
+
"TextField",
|
|
2557
|
+
"Select",
|
|
2558
|
+
"CheckBox",
|
|
2559
|
+
"RadioGroup",
|
|
2560
|
+
"Slider",
|
|
2561
|
+
"SegmentedControl",
|
|
2562
|
+
"ChoicePicker",
|
|
2563
|
+
"FlashcardFlip",
|
|
2564
|
+
"Table",
|
|
2565
|
+
"List",
|
|
2566
|
+
"Chart",
|
|
2567
|
+
"Map",
|
|
2568
|
+
"Image",
|
|
2569
|
+
"Svg",
|
|
2570
|
+
"Citation",
|
|
2571
|
+
"FollowUp",
|
|
2572
|
+
"EntityCard"
|
|
2573
|
+
]);
|
|
2574
|
+
function defaultGenerativeUIPromptSpec() {
|
|
2575
|
+
return {
|
|
2576
|
+
markdown: {
|
|
2577
|
+
intro: "You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.",
|
|
2578
|
+
whenToShow: GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW,
|
|
2579
|
+
rules: [
|
|
2580
|
+
"Write explanations as normal markdown prose outside the fences.",
|
|
2581
|
+
"Open a fence with ```a2ui to show the surface in the chat, at the place of the fence.",
|
|
2582
|
+
"Open a fence with ```a2ui target=<id> to show the surface in a named target. Use only target ids from the schema. When a target limits its components, its surfaces can use only those components.",
|
|
2583
|
+
"Inside a fence, write one JSON object per line and nothing else. No comments, no trailing commas, no pretty-printing.",
|
|
2584
|
+
"Keep each operation whole on its line.",
|
|
2585
|
+
"Give every operation \"version\":\"v1.0\".",
|
|
2586
|
+
"Start a surface with one createSurface. Put all the initial data in \"dataModel\" and the \"root\" component in \"components\". Then write the children in updateComponents lines, so that they show while you write:\n ```a2ui\n {\"version\":\"v1.0\",\"createSurface\":{\"surfaceId\":\"plan-picker\",\"dataModel\":{ ...initial data... },\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"seats\",\"pick\"]}]}}\n {\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"plan-picker\",\"components\":[ ...the children... ]}}\n ```",
|
|
2587
|
+
"Keep \"dataModel\" flat: top-level keys such as \"seats\" or \"form\", never one wrapper object around everything. Check that every { and [ you open in a line is closed.",
|
|
2588
|
+
"Every surface renders from the component with id \"root\". Make every other component reachable from \"root\" through slots.",
|
|
2589
|
+
"Send every component you reference in the same reply. If a surface gets long, make it smaller rather than leave components out.",
|
|
2590
|
+
"Use unique ids. Do not make cycles. A component cannot be its own child.",
|
|
2591
|
+
"Write a component as one flat object: {\"id\":\"title\",\"component\":\"<Name>\",\"text\":\"Hello\"}.",
|
|
2592
|
+
"Close each component with exactly one }, also when its last prop is a list: {\"id\":\"map\",\"component\":\"Map\",\"markers\":[{\"label\":\"A\",\"lat\":48.2,\"lng\":16.4}]}. A createSurface or updateComponents line ends with }]}} : the last component, the \"components\" list, the operation, the line.",
|
|
2593
|
+
"A prop that holds a call closes with }} : its \"args\", then the call. The component closes with its own single } after its last prop. With a prop after the call: {\"id\":\"count\",\"component\":\"Text\",\"text\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} items\"}},\"size\":\"lg\"}. With the call last: {\"id\":\"count\",\"component\":\"Text\",\"size\":\"lg\",\"text\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} items\"}}}.",
|
|
2594
|
+
"Deep props close every level they open, then the component closes with its own }. An event with a context: \"onSubmit\":{\"event\":{\"name\":\"send\",\"context\":{\"email\":{\"@path\":\"/email\"}}}}} ends with }}}}} : the path, \"context\", \"event\", the prop, the component. A Table: \"rows\":[[\"Mon\",\"9°C\"],[\"Tue\",\"7°C\"]]} ends with ]]} : the last row, \"rows\", the component, and nothing more. A list item with a call: \"items\":[{\"label\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} cups\"}}}]} ends with }}}]} : \"args\", the call, the item, the list, the component.",
|
|
2595
|
+
"Put the component name in \"component\" (never \"type\"). Put props next to it, never inside a \"props\" object.",
|
|
2596
|
+
"A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component. \"live\":\"polite\" goes only inside \"accessibility\" ({\"accessibility\":{\"live\":\"polite\"}}), only on text that changes by itself, never as a prop of the component.",
|
|
2597
|
+
"Use only the components, props, events, and slots in the schema. A component marked +common also takes every common prop. A component with a prop that is not in its schema, or a value outside its enum, is dropped with everything inside it, so check each prop against the schema.",
|
|
2598
|
+
"Give a prop a literal value, or bind it to the data model with {\"@path\":\"/x\"}. Never write {\"path\":\"/x\"} as a binding.",
|
|
2599
|
+
"A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Use only the functions in the schema. Write a literal when the value never changes.",
|
|
2600
|
+
"formatString interpolates ${...}: {\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} × ${formatCurrency(value: /price, currency: 'EUR')}\"}}. Inside ${...}, a path has no quotes, a string has single quotes, and a function takes named args.",
|
|
2601
|
+
"${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}. Inside formatString: ${formatCurrency(value: calc(expression: 'seats * 29', seats: /seats), currency: 'USD')}. The UI then follows the user's input with no round trip.",
|
|
2602
|
+
"Inside ${...}, close every ( you open, and write no operators and no ?: : compute with calc. To round a computed number, round inside calc instead of wrapping it in formatNumber: ${calc(expression: 'round(servings * 0.5 * 10) / 10', servings: /servings)} cups. calc has ^ (power), sqrt, exp and ln.",
|
|
2603
|
+
"To show one of two texts, let calc choose: \"text\":{\"@call\":\"calc\",\"args\":{\"expression\":\"billing == 'yearly' ? 'per year' : 'per month'\",\"billing\":{\"@path\":\"/billing\"}}}.",
|
|
2604
|
+
"For a computed list (chart data, template items) use series. Its description under Functions in the schema gives the rules and an example. Bind the \"data\" of a Chart or the \"items\" of a List to it; a template path stays a literal path.",
|
|
2605
|
+
"Bind a writable prop to let the user edit it: \"value\":{\"@path\":\"/form/email\"}. The user's input goes to that path.",
|
|
2606
|
+
"The value of a ChoicePicker is a list of strings, also for one choice. SegmentedControl, RadioGroup and Select take one string. Option values are always strings: for a yes/no choice use \"yes\" and \"no\", not true and false.",
|
|
2607
|
+
"To change data, write updateDataModel with a \"path\" and a \"value\": {\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"plan-picker\",\"path\":\"/seats\",\"value\":12}}. Always give \"value\".",
|
|
2608
|
+
"Set \"value\":null to delete the key at \"path\".",
|
|
2609
|
+
{
|
|
2610
|
+
when: ["events"],
|
|
2611
|
+
items: ["Give an event prop an object: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} or {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}}. Never a flat {\"event\":\"<name>\"}.", "Put the action of a Button in its \"onClick\": {\"event\":{...}} to send it back to you, or {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"...\"}}}. Never write \"event\" or \"functionCall\" as a prop of its own."]
|
|
2612
|
+
},
|
|
2613
|
+
{
|
|
2614
|
+
when: ["events", "functions"],
|
|
2615
|
+
items: ["Use {\"functionCall\": ...} to run a function in the browser when the user clicks: an app function from the schema, or openUrl: {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"https://example.com\"}}}. You are not told about the call."]
|
|
2616
|
+
},
|
|
2617
|
+
{
|
|
2618
|
+
when: ["events", "noFunctions"],
|
|
2619
|
+
items: ["Use {\"functionCall\": ...} to open a URL when the user clicks: {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"https://example.com\"}}}. You are not told about the call."]
|
|
2620
|
+
},
|
|
2621
|
+
{
|
|
2622
|
+
when: ["events"],
|
|
2623
|
+
items: [
|
|
2624
|
+
"Use {\"event\": ...} to send the interaction back to you as a user message. Put the text of that message in \"userMessage\": {\"event\":{\"name\":\"choose\",\"userMessage\":\"Show me the Team plan\"}}. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\".",
|
|
2625
|
+
"To send input values with an event, bind them in the context: \"context\":{\"email\":{\"@path\":\"/form/email\"}}.",
|
|
2626
|
+
"A button or other event prop without an event or functionCall does nothing."
|
|
2627
|
+
]
|
|
2628
|
+
},
|
|
2629
|
+
{
|
|
2630
|
+
when: ["checks"],
|
|
2631
|
+
items: ["Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email; a condition can also be a boolean {\"@path\"}. A failed check shows the message under the input and disables a Button that has the same checks."]
|
|
2632
|
+
},
|
|
2633
|
+
"A prop typed componentId takes the id of another component, and a childList takes ids [\"a\",\"b\"]: \"child\":\"card\", \"children\":[\"a\",\"b\"], \"tabs\":[{\"title\":\"Specs\",\"child\":\"specs\"}].",
|
|
2634
|
+
{
|
|
2635
|
+
when: ["templates"],
|
|
2636
|
+
items: [
|
|
2637
|
+
"To repeat a component for each item of a list, give a childList a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}.",
|
|
2638
|
+
"Inside a template, paths are relative to the item (\"name\", not \"/name\").",
|
|
2639
|
+
"Inside a template, {\"@call\":\"@index\"} gives the position of the item, from 0. To count from 1, write {\"@call\":\"@index\",\"args\":{\"offset\":1}}."
|
|
2640
|
+
]
|
|
2641
|
+
},
|
|
2642
|
+
"Updating a component replaces all of its props. Send every prop again.",
|
|
2643
|
+
"To change a surface in this reply, write another fence with the same surfaceId. Do not send createSurface again. The surface changes where it already is. A surface in a target can also be changed from a later reply; a chat surface cannot, because the chat is a transcript: a later reply with the same surfaceId makes a new surface.",
|
|
2644
|
+
"Use a new surfaceId for a different view. Never use a surfaceId again, also after the surface is deleted.",
|
|
2645
|
+
{
|
|
2646
|
+
when: ["agentCalls"],
|
|
2647
|
+
items: [
|
|
2648
|
+
"To run an app function now, with no click, write a callRendererFunction line in a fence: {\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}. It needs no surface.",
|
|
2649
|
+
"Give every callRendererFunction a new functionCallId. Call only a function that the schema marks UI or agent, or agent only; a function with no mark is for the UI only. A function marked agent only is only for callRendererFunction: do not bind an event to it.",
|
|
2650
|
+
"The result of a callRendererFunction comes back to you as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Then you get a new turn.",
|
|
2651
|
+
"Do not guess the result of a callRendererFunction. Wait for the developer message."
|
|
2652
|
+
]
|
|
2653
|
+
},
|
|
2654
|
+
"The schema lists the surfaces that already exist. \"dataModel\" holds the values that the user entered: read them, and do not write those paths. \"rejected\" lists operations that the client dropped: send corrected operations in a new fence for that surfaceId. \"status\":\"deleted\" means the surface is gone: never use its id again. \"status\":\"failed\" means its createSurface was rejected: send a corrected createSurface with that id.",
|
|
2655
|
+
"Never make a surface that is only prose. Write headings, paragraphs, lists of text, intros, and summaries as markdown outside the fences, also between two fences.",
|
|
2656
|
+
"Put in a fence only what markdown cannot show: charts, tables, maps, images, badges, inputs, buttons, cards with controls.",
|
|
2657
|
+
"Use Card only for an interactive panel (controls, a form, a configurator). Put everything else in a plain layout component.",
|
|
2658
|
+
"Never wrap the whole reply in a fence."
|
|
2659
|
+
]
|
|
2660
|
+
},
|
|
2661
|
+
tool: {
|
|
2662
|
+
intro: `Call \`${GENERATIVE_UI_RENDER_TOOL}\` to show UI. Arguments: \`target\` first, then \`operations\` (A2UI v1.0 operations, applied in order).`,
|
|
2663
|
+
whenToShow: GENERATIVE_UI_WHEN_TO_SHOW,
|
|
2664
|
+
operations: [
|
|
2665
|
+
"{\"version\":\"v1.0\",\"createSurface\":{\"surfaceId\":\"<new id>\",\"dataModel\":{...},\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"<child id>\"]}]}}: the first operation of a new surface. \"dataModel\" and \"components\" are optional.",
|
|
2666
|
+
"{\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.",
|
|
2667
|
+
"{\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".",
|
|
2668
|
+
"{\"version\":\"v1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.",
|
|
2669
|
+
{
|
|
2670
|
+
when: ["agentCalls"],
|
|
2671
|
+
items: ["{\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface."]
|
|
2672
|
+
}
|
|
2673
|
+
],
|
|
2674
|
+
rules: [
|
|
2675
|
+
"Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.",
|
|
2676
|
+
"A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.",
|
|
2677
|
+
"Stream progressively: put the initial data in \"dataModel\" and the root in \"components\" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example \"children\":[\"card-1\",\"card-2\"]), even though the children come later. A component that no slot references is never shown.",
|
|
2678
|
+
"Updating a component replaces all of its props, so resend every prop.",
|
|
2679
|
+
"Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.",
|
|
2680
|
+
{
|
|
2681
|
+
when: ["events", "functions"],
|
|
2682
|
+
items: ["Event props take an action. {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}} runs an app function in the browser immediately, and you are not told about it. {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\". Only call functions listed below."]
|
|
2683
|
+
},
|
|
2684
|
+
{
|
|
2685
|
+
when: ["events", "noFunctions"],
|
|
2686
|
+
items: ["Event props take an action: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\"."]
|
|
2687
|
+
},
|
|
2688
|
+
"To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.",
|
|
2689
|
+
"Never use a surfaceId again, also after deleteSurface.",
|
|
2690
|
+
"A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.",
|
|
2691
|
+
"${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}.",
|
|
2692
|
+
"For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.",
|
|
2693
|
+
{
|
|
2694
|
+
when: ["checks"],
|
|
2695
|
+
items: ["Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email. A failed check shows the message under the input and disables a Button that has the same checks."]
|
|
2696
|
+
},
|
|
2697
|
+
{
|
|
2698
|
+
when: ["templates"],
|
|
2699
|
+
items: ["To repeat a component for each item of a list, give a multiple slot a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}. Inside the template, paths are relative to the item (\"name\", not \"/name\"). {\"@call\":\"@index\"} gives the position of the item, from 0; {\"@call\":\"@index\",\"args\":{\"offset\":1}} counts from 1."]
|
|
2700
|
+
},
|
|
2701
|
+
{
|
|
2702
|
+
when: ["agentCalls"],
|
|
2703
|
+
items: ["Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it."]
|
|
2704
|
+
}
|
|
2705
|
+
]
|
|
2706
|
+
},
|
|
2707
|
+
schema: {
|
|
2708
|
+
markdown: {
|
|
2709
|
+
notation: "lines",
|
|
2710
|
+
propDescriptions: true,
|
|
2711
|
+
commonProps: true
|
|
2712
|
+
},
|
|
2713
|
+
tool: {
|
|
2714
|
+
notation: "json-schema",
|
|
2715
|
+
propDescriptions: true,
|
|
2716
|
+
commonProps: false
|
|
2717
|
+
}
|
|
2718
|
+
},
|
|
2719
|
+
descriptions: {}
|
|
2720
|
+
};
|
|
2721
|
+
}
|
|
2722
|
+
/** The rules of `items` whose block conditions hold, in order. */
|
|
2723
|
+
function selectPromptItems(items, features) {
|
|
2724
|
+
return items.flatMap((item) => typeof item === "string" ? [item] : item.when.every((feature) => features[feature]) ? item.items : []);
|
|
2725
|
+
}
|
|
2726
|
+
/**
|
|
2727
|
+
* The prompt features of a run, from the guide features of its manifest
|
|
2728
|
+
* (`generativeUIGuideFeatures`).
|
|
2729
|
+
*/
|
|
2730
|
+
function generativeUIPromptFeatures(guide) {
|
|
2731
|
+
return {
|
|
2732
|
+
functions: guide.functions,
|
|
2733
|
+
noFunctions: !guide.functions,
|
|
2734
|
+
events: guide.events,
|
|
2735
|
+
templates: guide.templates,
|
|
2736
|
+
checks: guide.checks,
|
|
2737
|
+
agentCalls: guide.functions && GENERATIVE_UI_AGENT_FUNCTION_CALLS
|
|
2738
|
+
};
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2735
2741
|
//#endregion
|
|
2736
2742
|
//#region src/a2ui-prompts.ts
|
|
2737
2743
|
/**
|
|
@@ -2847,12 +2853,6 @@ Design principles:
|
|
|
2847
2853
|
action context should reference the same paths to capture user input.
|
|
2848
2854
|
|
|
2849
2855
|
Use the SAME surfaceId as the main surface. Match action names to button action event names.`;
|
|
2850
|
-
/**
|
|
2851
|
-
* When UI helps the user, for both transports: a light nudge to reach for UI
|
|
2852
|
-
* where it conveys the answer better than prose, and to stay in prose
|
|
2853
|
-
* otherwise.
|
|
2854
|
-
*/
|
|
2855
|
-
const GENERATIVE_UI_WHEN_TO_SHOW = "Show UI when it conveys the answer better than prose: to illustrate a concept (a diagram, a chart of how something changes), to compare options side by side, to let the user explore or adjust values, or to collect input. A small, focused surface next to your explanation often lands better than a long description. Reply in prose alone for a quick fact, a short answer, or conversation, and never add UI only as decoration.";
|
|
2856
2856
|
/** Description of the context entry that carries `GENERATIVE_UI_MARKDOWN_GUIDELINES`. */
|
|
2857
2857
|
const GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION = "Generative UI markdown guide: how to write UI surfaces inside ```a2ui code fences in a normal markdown reply.";
|
|
2858
2858
|
/**
|
|
@@ -2898,6 +2898,7 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
2898
2898
|
return Object.values(node).some(hasChildList);
|
|
2899
2899
|
};
|
|
2900
2900
|
return {
|
|
2901
|
+
components: Object.keys(manifest.components),
|
|
2901
2902
|
functions: Object.keys(manifest.functions).some((name) => !isA2UIBasicFunction(name)),
|
|
2902
2903
|
events: components.some((c) => {
|
|
2903
2904
|
var _c$events;
|
|
@@ -2913,43 +2914,21 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
2913
2914
|
})
|
|
2914
2915
|
};
|
|
2915
2916
|
}
|
|
2916
|
-
/**
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
"Use unique ids. Do not make cycles. A component cannot be its own child.",
|
|
2932
|
-
"Write a component as one flat object: {\"id\":\"title\",\"component\":\"<Name>\",\"text\":\"Hello\"}.",
|
|
2933
|
-
"Put the component name in \"component\" (never \"type\"). Put props next to it, never inside a \"props\" object.",
|
|
2934
|
-
"A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.",
|
|
2935
|
-
"Use only the components, props, events, and slots in the schema. A component with \"includesCommonProps\" also takes every prop in \"commonProps\".",
|
|
2936
|
-
"Give a prop a literal value, or bind it to the data model with {\"@path\":\"/x\"}. Never write {\"path\":\"/x\"} as a binding.",
|
|
2937
|
-
"A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Use only the functions under \"functions\" in the schema. Write a literal when the value never changes.",
|
|
2938
|
-
"formatString interpolates ${...}: {\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} × ${formatCurrency(value: /price, currency: 'EUR')}\"}}. Inside ${...}, a path has no quotes, a string has single quotes, and a function takes named args.",
|
|
2939
|
-
"${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}. Inside formatString: ${formatCurrency(value: calc(expression: 'seats * 29', seats: /seats), currency: 'USD')}. The UI then follows the user's input with no round trip.",
|
|
2940
|
-
"For a computed list (chart data, template items) use series. Its description under \"functions\" in the schema gives the rules and an example. Bind the \"data\" of a Chart or the \"items\" of a List to it; a template path stays a literal path.",
|
|
2941
|
-
"Bind a writable prop to let the user edit it: \"value\":{\"@path\":\"/form/email\"}. The user's input goes to that path.",
|
|
2942
|
-
"To change data, write updateDataModel with a \"path\" and a \"value\": {\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"plan-picker\",\"path\":\"/seats\",\"value\":12}}. Always give \"value\".",
|
|
2943
|
-
"Set \"value\":null to delete the key at \"path\"."
|
|
2944
|
-
];
|
|
2945
|
-
/** The last rules of every markdown guideline, after the optional groups. */
|
|
2946
|
-
const MARKDOWN_CLOSING_RULES = [
|
|
2947
|
-
"The schema lists the surfaces that already exist under \"surfaces\". \"dataModel\" holds the values that the user entered: read them, and do not write those paths. \"rejected\" lists operations that the client dropped: send corrected operations in a new fence for that surfaceId. \"status\":\"deleted\" means the surface is gone: never use its id again. \"status\":\"failed\" means its createSurface was rejected: send a corrected createSurface with that id.",
|
|
2948
|
-
"Never make a surface that is only prose. Write headings, paragraphs, lists of text, intros, and summaries as markdown outside the fences, also between two fences.",
|
|
2949
|
-
"Put in a fence only what markdown cannot show: charts, tables, maps, images, badges, inputs, buttons, cards with controls.",
|
|
2950
|
-
"Use Card only for an interactive panel (controls, a form, a configurator). Put everything else in a plain layout component.",
|
|
2951
|
-
"Never wrap the whole reply in a fence."
|
|
2952
|
-
];
|
|
2917
|
+
/**
|
|
2918
|
+
* Whether a guide line names only standard components (`GUIDE_COMPONENTS`,
|
|
2919
|
+
* also in the plural) that the catalog has. With no catalog, every line fits.
|
|
2920
|
+
*/
|
|
2921
|
+
function namesOnlyCatalogComponents(catalog) {
|
|
2922
|
+
if (!catalog) return () => true;
|
|
2923
|
+
const has = new Set(catalog);
|
|
2924
|
+
return (line) => {
|
|
2925
|
+
var _line$match;
|
|
2926
|
+
return ((_line$match = line.match(/\b[A-Z][A-Za-z0-9]*\b/g)) !== null && _line$match !== void 0 ? _line$match : []).every((word) => {
|
|
2927
|
+
const name = !GUIDE_COMPONENTS.has(word) && word.endsWith("s") ? word.slice(0, -1) : word;
|
|
2928
|
+
return !GUIDE_COMPONENTS.has(name) || has.has(name);
|
|
2929
|
+
});
|
|
2930
|
+
};
|
|
2931
|
+
}
|
|
2953
2932
|
/**
|
|
2954
2933
|
* Builds the markdown-transport guideline. The model writes A2UI v1.0
|
|
2955
2934
|
* operations inside ```a2ui fences between normal markdown prose. The rules
|
|
@@ -2957,25 +2936,15 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
2957
2936
|
* none of them, so the guideline stays small.
|
|
2958
2937
|
*
|
|
2959
2938
|
* @param features - The optional rule groups to include. Defaults to all.
|
|
2939
|
+
* @param spec - The wording. Defaults to the prompts that ship.
|
|
2960
2940
|
* @returns The guideline text, one rule per line.
|
|
2961
2941
|
*/
|
|
2962
|
-
function buildGenerativeUIMarkdownGuidelines(features = ALL_GENERATIVE_UI_GUIDE_FEATURES) {
|
|
2963
|
-
const {
|
|
2964
|
-
const
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
if (templates) rules.push("To repeat a component for each item of a list, give a childList a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}.", "Inside a template, paths are relative to the item (\"name\", not \"/name\").", "Inside a template, {\"@call\":\"@index\"} gives the position of the item, from 0. To count from 1, write {\"@call\":\"@index\",\"args\":{\"offset\":1}}.");
|
|
2969
|
-
rules.push("Updating a component replaces all of its props. Send every prop again.", "To change a surface in this reply, write another fence with the same surfaceId. Do not send createSurface again. The surface changes where it already is. A surface in a target can also be changed from a later reply; a chat surface cannot, because the chat is a transcript: a later reply with the same surfaceId makes a new surface.", "Use a new surfaceId for a different view. Never use a surfaceId again, also after the surface is deleted.");
|
|
2970
|
-
if (functions && GENERATIVE_UI_AGENT_FUNCTION_CALLS) rules.push("To run an app function now, with no click, write a callRendererFunction line in a fence: {\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}. It needs no surface.", "Give every callRendererFunction a new functionCallId. Call only a function from the schema with \"callers\": \"UI or agent\" or \"agent only\"; a function without \"callers\" is for the UI only. A function with \"callers\": \"agent only\" is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Then you get a new turn.", "Do not guess the result of a callRendererFunction. Wait for the developer message.");
|
|
2971
|
-
rules.push(...MARKDOWN_CLOSING_RULES);
|
|
2972
|
-
return `You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.
|
|
2973
|
-
|
|
2974
|
-
${GENERATIVE_UI_WHEN_TO_SHOW}
|
|
2975
|
-
|
|
2976
|
-
RULES
|
|
2977
|
-
${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
2978
|
-
`;
|
|
2942
|
+
function buildGenerativeUIMarkdownGuidelines(features = ALL_GENERATIVE_UI_GUIDE_FEATURES, spec = defaultGenerativeUIPromptSpec()) {
|
|
2943
|
+
const { intro, rules } = spec.markdown;
|
|
2944
|
+
const fits = namesOnlyCatalogComponents(features.components);
|
|
2945
|
+
const selected = selectPromptItems(rules, generativeUIPromptFeatures(features)).filter(fits);
|
|
2946
|
+
const whenToShow = spec.markdown.whenToShow.split("\n").filter(fits).join("\n");
|
|
2947
|
+
return `${intro}\n\n${whenToShow ? `${whenToShow}\n\n` : ""}RULES\n${selected.map((rule) => `- ${rule}`).join("\n")}\n`;
|
|
2979
2948
|
}
|
|
2980
2949
|
/**
|
|
2981
2950
|
* The markdown-transport guideline with every rule group. A run sends
|
|
@@ -3003,11 +2972,11 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3003
2972
|
return typeof value === "string" && value !== "";
|
|
3004
2973
|
}
|
|
3005
2974
|
function isRecordOf(value, isEntry) {
|
|
3006
|
-
return isRecord(value) && Object.values(value).every(isEntry);
|
|
2975
|
+
return isRecord$2(value) && Object.values(value).every(isEntry);
|
|
3007
2976
|
}
|
|
3008
2977
|
/** A function, or an event of a component: a description and a parameter schema. */
|
|
3009
2978
|
function isSchemaEntry(value) {
|
|
3010
|
-
return isRecord(value) && isRecord(value.parameters) && isOptionalString(value.description);
|
|
2979
|
+
return isRecord$2(value) && isRecord$2(value.parameters) && isOptionalString(value.description);
|
|
3011
2980
|
}
|
|
3012
2981
|
function isSlotKind(value) {
|
|
3013
2982
|
return value === "single" || value === "multiple";
|
|
@@ -3017,11 +2986,11 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3017
2986
|
* so those two must have the right shape when they are there.
|
|
3018
2987
|
*/
|
|
3019
2988
|
function isPropsSchema(value) {
|
|
3020
|
-
return isRecord(value) && (value.properties === void 0 || isRecord(value.properties)) && (value.required === void 0 || Array.isArray(value.required) && value.required.every((name) => typeof name === "string"));
|
|
2989
|
+
return isRecord$2(value) && (value.properties === void 0 || isRecord$2(value.properties)) && (value.required === void 0 || Array.isArray(value.required) && value.required.every((name) => typeof name === "string"));
|
|
3021
2990
|
}
|
|
3022
2991
|
function isComponentManifest(value) {
|
|
3023
2992
|
var _value$props$properti, _value$slots, _value$events;
|
|
3024
|
-
if (!isRecord(value) || !isPropsSchema(value.props) || !isOptionalString(value.description) || value.events !== void 0 && !isRecordOf(value.events, isSchemaEntry) || value.slots !== void 0 && !isRecordOf(value.slots, isSlotKind)) return false;
|
|
2993
|
+
if (!isRecord$2(value) || !isPropsSchema(value.props) || !isOptionalString(value.description) || value.events !== void 0 && !isRecordOf(value.events, isSchemaEntry) || value.slots !== void 0 && !isRecordOf(value.slots, isSlotKind)) return false;
|
|
3025
2994
|
const order = value.parameterOrder;
|
|
3026
2995
|
if (order === void 0) return true;
|
|
3027
2996
|
const keys = new Set([
|
|
@@ -3032,31 +3001,31 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3032
3001
|
return Array.isArray(order) && new Set(order).size === order.length && order.every((key) => typeof key === "string" && keys.has(key));
|
|
3033
3002
|
}
|
|
3034
3003
|
function isInlineCatalog(value) {
|
|
3035
|
-
return isRecord(value) && isNonEmptyString(value.catalogId) && value.protocolVersion === "1.0" && (value.components === void 0 || isRecordOf(value.components, isComponentManifest)) && isRecordOf(value.functions, isSchemaEntry) && isOptionalString(value.instructions);
|
|
3004
|
+
return isRecord$2(value) && isNonEmptyString(value.catalogId) && value.protocolVersion === "1.0" && (value.components === void 0 || isRecordOf(value.components, isComponentManifest)) && isRecordOf(value.functions, isSchemaEntry) && isOptionalString(value.instructions);
|
|
3036
3005
|
}
|
|
3037
3006
|
function isCapabilities(value) {
|
|
3038
|
-
return isRecord(value) && Array.isArray(value.supportedCatalogIds) && value.supportedCatalogIds.length > 0 && value.supportedCatalogIds.every(isNonEmptyString) && (value.inlineCatalogs === void 0 || Array.isArray(value.inlineCatalogs) && value.inlineCatalogs.every(isInlineCatalog));
|
|
3007
|
+
return isRecord$2(value) && Array.isArray(value.supportedCatalogIds) && value.supportedCatalogIds.length > 0 && value.supportedCatalogIds.every(isNonEmptyString) && (value.inlineCatalogs === void 0 || Array.isArray(value.inlineCatalogs) && value.inlineCatalogs.every(isInlineCatalog));
|
|
3039
3008
|
}
|
|
3040
3009
|
/** A short list of component names. */
|
|
3041
3010
|
function isComponentNameList(value) {
|
|
3042
3011
|
return Array.isArray(value) && value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS && value.every(isNonEmptyString);
|
|
3043
3012
|
}
|
|
3044
3013
|
function isTarget(value) {
|
|
3045
|
-
return isRecord(value) && isNonEmptyString(value.id) && (value.kind === "chat" || value.kind === "inline") && isOptionalString(value.description) && (value.components === void 0 || isComponentNameList(value.components));
|
|
3014
|
+
return isRecord$2(value) && isNonEmptyString(value.id) && (value.kind === "chat" || value.kind === "inline") && isOptionalString(value.description) && (value.components === void 0 || isComponentNameList(value.components));
|
|
3046
3015
|
}
|
|
3047
3016
|
/** A short list of short strings. The summary limits keep the guide small. */
|
|
3048
3017
|
function isRejectionList(value) {
|
|
3049
3018
|
return Array.isArray(value) && value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS && value.every((entry) => typeof entry === "string" && entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH);
|
|
3050
3019
|
}
|
|
3051
3020
|
function isSurfaceEntry(value) {
|
|
3052
|
-
return isRecord(value) && isNonEmptyString(value.target) && (value.dataModel === void 0 || isRecord(value.dataModel)) && (value.rejected === void 0 || isRejectionList(value.rejected)) && (value.status === void 0 || value.status === "deleted" || value.status === "failed");
|
|
3021
|
+
return isRecord$2(value) && isNonEmptyString(value.target) && (value.dataModel === void 0 || isRecord$2(value.dataModel)) && (value.rejected === void 0 || isRejectionList(value.rejected)) && (value.status === void 0 || value.status === "deleted" || value.status === "failed");
|
|
3053
3022
|
}
|
|
3054
3023
|
/** Checks the `copilotkit_` keys only. Other extensions can be there too. */
|
|
3055
3024
|
function isExtensions(value) {
|
|
3056
|
-
return isRecord(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
|
|
3025
|
+
return isRecord$2(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
|
|
3057
3026
|
}
|
|
3058
3027
|
function isEnvelope(value) {
|
|
3059
|
-
return isRecord(value) && isCapabilities(value["v1.0"]) && isRecord(value.metadata) && isExtensions(value.metadata.extensions);
|
|
3028
|
+
return isRecord$2(value) && isCapabilities(value["v1.0"]) && isRecord$2(value.metadata) && isExtensions(value.metadata.extensions);
|
|
3060
3029
|
}
|
|
3061
3030
|
/**
|
|
3062
3031
|
* Reads the generative UI envelope from the `forwardedProps` of a run.
|
|
@@ -3077,9 +3046,9 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3077
3046
|
* ```
|
|
3078
3047
|
*/
|
|
3079
3048
|
function readCopilotKitUIEnvelope(forwardedProps) {
|
|
3080
|
-
if (!isRecord(forwardedProps)) return void 0;
|
|
3049
|
+
if (!isRecord$2(forwardedProps)) return void 0;
|
|
3081
3050
|
const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];
|
|
3082
|
-
if (!isRecord(namespace)) return void 0;
|
|
3051
|
+
if (!isRecord$2(namespace)) return void 0;
|
|
3083
3052
|
const envelope = namespace.ui;
|
|
3084
3053
|
return isEnvelope(envelope) ? envelope : void 0;
|
|
3085
3054
|
}
|
|
@@ -3152,7 +3121,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3152
3121
|
});
|
|
3153
3122
|
/** Models write the v0.9 binding from habit. The reason names the v1.0 form. */
|
|
3154
3123
|
const V09_PATH_REASON = "bind data with {\"@path\": \"/x\"}, not {\"path\": \"/x\"}";
|
|
3155
|
-
function hasOwn(record, key) {
|
|
3124
|
+
function hasOwn$1(record, key) {
|
|
3156
3125
|
return Object.prototype.hasOwnProperty.call(record, key);
|
|
3157
3126
|
}
|
|
3158
3127
|
/**
|
|
@@ -3160,42 +3129,42 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3160
3129
|
* "toString" must not resolve to Object.prototype members.
|
|
3161
3130
|
*/
|
|
3162
3131
|
function ownValue(record, key) {
|
|
3163
|
-
return record && hasOwn(record, key) ? record[key] : void 0;
|
|
3132
|
+
return record && hasOwn$1(record, key) ? record[key] : void 0;
|
|
3164
3133
|
}
|
|
3165
3134
|
function getOperationKind(op) {
|
|
3166
|
-
if (!isRecord(op)) return void 0;
|
|
3135
|
+
if (!isRecord$2(op)) return void 0;
|
|
3167
3136
|
const kinds = OPERATION_KINDS.filter((kind) => kind in op);
|
|
3168
3137
|
return kinds.length === 1 ? kinds[0] : void 0;
|
|
3169
3138
|
}
|
|
3170
3139
|
/** The `surfaceId` of a surface operation. `callRendererFunction` has none. */
|
|
3171
3140
|
function getOperationSurfaceId(op) {
|
|
3172
|
-
if (!isRecord(op)) return void 0;
|
|
3141
|
+
if (!isRecord$2(op)) return void 0;
|
|
3173
3142
|
const kind = getOperationKind(op);
|
|
3174
3143
|
if (!kind) return void 0;
|
|
3175
3144
|
const payload = op[kind];
|
|
3176
|
-
return isRecord(payload) && typeof payload.surfaceId === "string" ? payload.surfaceId : void 0;
|
|
3145
|
+
return isRecord$2(payload) && typeof payload.surfaceId === "string" ? payload.surfaceId : void 0;
|
|
3177
3146
|
}
|
|
3178
3147
|
/** `{ "@path": "/x" }`: a data-model binding. */
|
|
3179
3148
|
function isPathBinding(value) {
|
|
3180
|
-
return isRecord(value) && typeof value["@path"] === "string" && Object.keys(value).length === 1;
|
|
3149
|
+
return isRecord$2(value) && typeof value["@path"] === "string" && Object.keys(value).length === 1;
|
|
3181
3150
|
}
|
|
3182
3151
|
/** `{ "path": "/x" }`: the v0.9 binding, which v1.0 does not accept. */
|
|
3183
3152
|
function isV09PathBinding(value) {
|
|
3184
|
-
return isRecord(value) && typeof value.path === "string" && Object.keys(value).length === 1;
|
|
3153
|
+
return isRecord$2(value) && typeof value.path === "string" && Object.keys(value).length === 1;
|
|
3185
3154
|
}
|
|
3186
3155
|
/**
|
|
3187
3156
|
* `{ "@call": "@index" }` or `{ "@call": "@index", "args": { "offset": 1 } }`:
|
|
3188
3157
|
* the 0-based position of the item in a template, plus `offset`.
|
|
3189
3158
|
*/
|
|
3190
3159
|
function isIndexCall(value) {
|
|
3191
|
-
if (!isRecord(value) || value["@call"] !== "@index") return false;
|
|
3160
|
+
if (!isRecord$2(value) || value["@call"] !== "@index") return false;
|
|
3192
3161
|
if (!Object.keys(value).every((key) => key === "@call" || key === "args")) return false;
|
|
3193
3162
|
const { args } = value;
|
|
3194
3163
|
if (args === void 0) return true;
|
|
3195
|
-
return isRecord(args) && Object.keys(args).every((key) => key === "offset") && (args.offset === void 0 || Number.isFinite(args.offset));
|
|
3164
|
+
return isRecord$2(args) && Object.keys(args).every((key) => key === "offset") && (args.offset === void 0 || Number.isFinite(args.offset));
|
|
3196
3165
|
}
|
|
3197
3166
|
function isActionBinding(value) {
|
|
3198
|
-
return isRecord(value) && Object.keys(value).length === 1 && (isRecord(value.functionCall) || isRecord(value.event));
|
|
3167
|
+
return isRecord$2(value) && Object.keys(value).length === 1 && (isRecord$2(value.functionCall) || isRecord$2(value.event));
|
|
3199
3168
|
}
|
|
3200
3169
|
/**
|
|
3201
3170
|
* Checks one A2UI v1.0 operation against the catalog and the surfaces that
|
|
@@ -3213,7 +3182,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3213
3182
|
* ```
|
|
3214
3183
|
*/
|
|
3215
3184
|
function validateOperation(op, options) {
|
|
3216
|
-
if (!isRecord(op)) return fail("operation must be a JSON object");
|
|
3185
|
+
if (!isRecord$2(op)) return fail("operation must be a JSON object");
|
|
3217
3186
|
if (op.version !== A2UI_VERSION) return fail(versionProblem(op.version));
|
|
3218
3187
|
const kind = getOperationKind(op);
|
|
3219
3188
|
if (!kind) return fail(`operation must contain exactly one of ${OPERATION_KINDS.join(", ")}`);
|
|
@@ -3222,7 +3191,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3222
3191
|
if (!GENERATIVE_UI_AGENT_FUNCTION_CALLS) return fail(GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON);
|
|
3223
3192
|
return validateRendererFunctionCall(payload, options);
|
|
3224
3193
|
}
|
|
3225
|
-
if (!isRecord(payload) || typeof payload.surfaceId !== "string" || !payload.surfaceId) return fail(`${kind}.surfaceId is required`);
|
|
3194
|
+
if (!isRecord$2(payload) || typeof payload.surfaceId !== "string" || !payload.surfaceId) return fail(`${kind}.surfaceId is required`);
|
|
3226
3195
|
const surfaceId = payload.surfaceId;
|
|
3227
3196
|
if (kind === "createSurface") return validateCreateSurface(payload, surfaceId, options);
|
|
3228
3197
|
if (!options.knownSurfaces.has(surfaceId)) return fail(`surface "${surfaceId}" does not exist; send createSurface first`);
|
|
@@ -3251,12 +3220,12 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3251
3220
|
const catalogReason = catalogProblem(payload.catalogId, options.manifest);
|
|
3252
3221
|
if (catalogReason) return fail(catalogReason);
|
|
3253
3222
|
const { dataModel, components } = payload;
|
|
3254
|
-
if (dataModel !== void 0 && !isRecord(dataModel)) return fail("createSurface.dataModel must be a JSON object");
|
|
3223
|
+
if (dataModel !== void 0 && !isRecord$2(dataModel)) return fail("createSurface.dataModel must be a JSON object");
|
|
3255
3224
|
if (components === void 0) return OK;
|
|
3256
3225
|
return validateComponents(components, "createSurface.components", options);
|
|
3257
3226
|
}
|
|
3258
3227
|
function validateRendererFunctionCall(payload, options) {
|
|
3259
|
-
if (!(isRecord(payload) && typeof payload.functionCallId === "string" && payload.functionCallId !== "")) return fail("callRendererFunction.functionCallId must be a non-empty string");
|
|
3228
|
+
if (!(isRecord$2(payload) && typeof payload.functionCallId === "string" && payload.functionCallId !== "")) return fail("callRendererFunction.functionCallId must be a non-empty string");
|
|
3260
3229
|
const reason = functionCallProblem(payload.callFunction, "callRendererFunction.callFunction", options);
|
|
3261
3230
|
return reason ? fail(reason) : OK;
|
|
3262
3231
|
}
|
|
@@ -3274,7 +3243,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3274
3243
|
const path = (_payload$path = payload.path) !== null && _payload$path !== void 0 ? _payload$path : "/";
|
|
3275
3244
|
if (typeof path !== "string" || !path.startsWith("/")) return fail("updateDataModel.path must be an absolute JSON pointer");
|
|
3276
3245
|
if (path === "/") {
|
|
3277
|
-
if (!isRecord(payload.value)) return fail("a root updateDataModel value must be a JSON object");
|
|
3246
|
+
if (!isRecord$2(payload.value)) return fail("a root updateDataModel value must be a JSON object");
|
|
3278
3247
|
return OK;
|
|
3279
3248
|
}
|
|
3280
3249
|
const reason = pathProblem(path, "updateDataModel.path");
|
|
@@ -3294,7 +3263,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3294
3263
|
if (!Array.isArray(components) || components.length === 0) return fail(`${label} must be a non-empty array`);
|
|
3295
3264
|
const ids = /* @__PURE__ */ new Set();
|
|
3296
3265
|
for (const node of components) {
|
|
3297
|
-
if (!isRecord(node)) return fail("component must be a JSON object");
|
|
3266
|
+
if (!isRecord$2(node)) return fail("component must be a JSON object");
|
|
3298
3267
|
const { id } = node;
|
|
3299
3268
|
if (typeof id !== "string" || !id) return fail("id is required");
|
|
3300
3269
|
const reason = nodeProblem(node, id, options);
|
|
@@ -3314,7 +3283,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3314
3283
|
return `"${node.component}" is not allowed in target "${allowedComponents.target}"; use one of: ${names}`;
|
|
3315
3284
|
}
|
|
3316
3285
|
const { properties, required } = entry.props;
|
|
3317
|
-
const propNames = isRecord(properties) ? Object.keys(properties) : [];
|
|
3286
|
+
const propNames = isRecord$2(properties) ? Object.keys(properties) : [];
|
|
3318
3287
|
const props = Object.entries(node);
|
|
3319
3288
|
for (const [key, value] of props) {
|
|
3320
3289
|
if (key === "id" || key === "component") continue;
|
|
@@ -3324,7 +3293,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3324
3293
|
continue;
|
|
3325
3294
|
}
|
|
3326
3295
|
if (key === "metadata") {
|
|
3327
|
-
if (!(isRecord(value) && (value.extensions === void 0 || isRecord(value.extensions)))) return "metadata must be { \"extensions\": { ... } }";
|
|
3296
|
+
if (!(isRecord$2(value) && (value.extensions === void 0 || isRecord$2(value.extensions)))) return "metadata must be { \"extensions\": { ... } }";
|
|
3328
3297
|
continue;
|
|
3329
3298
|
}
|
|
3330
3299
|
if (key === "accessibility") {
|
|
@@ -3372,7 +3341,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3372
3341
|
* values, `hidden` is a boolean or a dynamic value.
|
|
3373
3342
|
*/
|
|
3374
3343
|
function accessibilityProblem(value) {
|
|
3375
|
-
if (!isRecord(value)) return "must be { \"label\": \"...\", \"description\": \"...\", \"live\": \"polite\", \"hidden\": false }";
|
|
3344
|
+
if (!isRecord$2(value)) return "must be { \"label\": \"...\", \"description\": \"...\", \"live\": \"polite\", \"hidden\": false }";
|
|
3376
3345
|
const isDynamic = (field) => isPathBinding(field) || isCallBinding(field);
|
|
3377
3346
|
for (const [key, field] of Object.entries(value)) {
|
|
3378
3347
|
if (!ACCESSIBILITY_KEYS.includes(key)) return `unknown key "${key}"`;
|
|
@@ -3390,7 +3359,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3390
3359
|
}
|
|
3391
3360
|
}
|
|
3392
3361
|
function actionBindingProblem(value, options) {
|
|
3393
|
-
if (!isRecord(value)) return "must be an action object";
|
|
3362
|
+
if (!isRecord$2(value)) return "must be an action object";
|
|
3394
3363
|
const keys = Object.keys(value);
|
|
3395
3364
|
if (!(keys.length === 1 && (keys[0] === "functionCall" || keys[0] === "event"))) return "must be { \"event\": ... } or { \"functionCall\": ... }";
|
|
3396
3365
|
if (keys[0] === "functionCall") return functionCallProblem(value.functionCall, "functionCall", options);
|
|
@@ -3401,18 +3370,18 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3401
3370
|
* field in the reason.
|
|
3402
3371
|
*/
|
|
3403
3372
|
function functionCallProblem(call, label, options) {
|
|
3404
|
-
if (!isRecord(call)) return `${label} must be { "@call": "<function>", "args": { ... } }`;
|
|
3373
|
+
if (!isRecord$2(call)) return `${label} must be { "@call": "<function>", "args": { ... } }`;
|
|
3405
3374
|
const name = call["@call"];
|
|
3406
3375
|
if (typeof name !== "string" || !name) return typeof call.call === "string" ? `${label} names the function with "@call", not "call"` : `${label}["@call"] must be a function name`;
|
|
3407
3376
|
const { args } = call;
|
|
3408
|
-
if (args !== void 0 && !isRecord(args)) return `${label}.args must be an object`;
|
|
3377
|
+
if (args !== void 0 && !isRecord$2(args)) return `${label}.args must be an object`;
|
|
3409
3378
|
const catalogReason = catalogProblem(call.catalogId, options.manifest);
|
|
3410
3379
|
if (catalogReason) return `${label}: ${catalogReason}`;
|
|
3411
3380
|
const argEntries = Object.entries(args !== null && args !== void 0 ? args : {});
|
|
3412
3381
|
for (const [key, arg] of argEntries) if (isV09PathBinding(arg)) return `${label}.args.${key}: ${V09_PATH_REASON}`;
|
|
3413
3382
|
const appFunctions = options.functions;
|
|
3414
|
-
const declared = appFunctions !== void 0 && hasOwn(appFunctions, name) ? appFunctions[name] : void 0;
|
|
3415
|
-
const builtIn = declared === void 0 && hasOwn(GENERATIVE_UI_FUNCTIONS, name) ? GENERATIVE_UI_FUNCTIONS[name] : void 0;
|
|
3383
|
+
const declared = appFunctions !== void 0 && hasOwn$1(appFunctions, name) ? appFunctions[name] : void 0;
|
|
3384
|
+
const builtIn = declared === void 0 && hasOwn$1(GENERATIVE_UI_FUNCTIONS, name) ? GENERATIVE_UI_FUNCTIONS[name] : void 0;
|
|
3416
3385
|
if (declared === void 0 && builtIn === void 0) return appFunctions === void 0 ? void 0 : `function "${name}" is not exposed to generative UI`;
|
|
3417
3386
|
if (declared === void 0 && appFunctions === void 0) return void 0;
|
|
3418
3387
|
return callerProblem(name, declared !== null && declared !== void 0 ? declared : builtIn, label.startsWith("callRendererFunction") ? "agent" : "renderer");
|
|
@@ -3428,11 +3397,11 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3428
3397
|
if (caller === "renderer" && !callers.renderer) return `function "${name}" runs only for the agent (allowedCallers "agentOnly"); the UI cannot call it`;
|
|
3429
3398
|
}
|
|
3430
3399
|
function eventProblem(event) {
|
|
3431
|
-
if (!isRecord(event) || typeof event.name !== "string" || !event.name) return "event.name is required";
|
|
3400
|
+
if (!isRecord$2(event) || typeof event.name !== "string" || !event.name) return "event.name is required";
|
|
3432
3401
|
const { userMessage, context } = event;
|
|
3433
|
-
if (!(userMessage === void 0 || typeof userMessage === "string" || isPathBinding(userMessage) || isRecord(userMessage) && typeof userMessage["@call"] === "string" && findForbiddenCall(userMessage, { allowValueFunctions: true }) === void 0)) return isV09PathBinding(userMessage) ? `event.userMessage: ${V09_PATH_REASON}` : "event.userMessage must be a string, {\"@path\": \"/x\"} or a function value";
|
|
3402
|
+
if (!(userMessage === void 0 || typeof userMessage === "string" || isPathBinding(userMessage) || isRecord$2(userMessage) && typeof userMessage["@call"] === "string" && findForbiddenCall(userMessage, { allowValueFunctions: true }) === void 0)) return isV09PathBinding(userMessage) ? `event.userMessage: ${V09_PATH_REASON}` : "event.userMessage must be a string, {\"@path\": \"/x\"} or a function value";
|
|
3434
3403
|
if (context === void 0) return void 0;
|
|
3435
|
-
if (!isRecord(context)) return "event.context must be an object";
|
|
3404
|
+
if (!isRecord$2(context)) return "event.context must be an object";
|
|
3436
3405
|
const entries = Object.entries(context);
|
|
3437
3406
|
for (const [key, entry] of entries) {
|
|
3438
3407
|
if (isV09PathBinding(entry)) return `event.context.${key}: ${V09_PATH_REASON}`;
|
|
@@ -3441,7 +3410,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3441
3410
|
}
|
|
3442
3411
|
}
|
|
3443
3412
|
function slotProblem(value, kind, ownId) {
|
|
3444
|
-
const isTemplate = isRecord(value) && "componentId" in value;
|
|
3413
|
+
const isTemplate = isRecord$2(value) && "componentId" in value;
|
|
3445
3414
|
if (kind === "single" && isTemplate) return "a template { \"componentId\", \"path\" } is only allowed in a \"multiple\" slot";
|
|
3446
3415
|
if (kind === "multiple" && isTemplate) return templateProblem(value, ownId);
|
|
3447
3416
|
if (kind === "multiple" && !Array.isArray(value)) return "must be an array of component ids or a template { \"componentId\", \"path\" }";
|
|
@@ -3475,7 +3444,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3475
3444
|
}
|
|
3476
3445
|
return;
|
|
3477
3446
|
}
|
|
3478
|
-
if (!isRecord(value)) return void 0;
|
|
3447
|
+
if (!isRecord$2(value)) return void 0;
|
|
3479
3448
|
if (isIndexCall(value)) return void 0;
|
|
3480
3449
|
if (value["@call"] === "@index") return "@index takes only an offset";
|
|
3481
3450
|
if (typeof value.call === "string") return "name the function with \"@call\", not \"call\"";
|
|
@@ -3484,7 +3453,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3484
3453
|
if (typeof name === "string") {
|
|
3485
3454
|
if (!options.allowValueFunctions || !isA2UIValueFunction(name)) return isA2UIBasicFunction(name) ? `"${name}" runs only from an event` : `"${name}" is not a basic function`;
|
|
3486
3455
|
const args = value.args;
|
|
3487
|
-
if (args !== void 0 && !isRecord(args)) return `the args of "${name}" must be an object`;
|
|
3456
|
+
if (args !== void 0 && !isRecord$2(args)) return `the args of "${name}" must be an object`;
|
|
3488
3457
|
return args === void 0 ? void 0 : findForbiddenCall(args, options);
|
|
3489
3458
|
}
|
|
3490
3459
|
for (const item of Object.values(value)) {
|
|
@@ -3509,7 +3478,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3509
3478
|
*/
|
|
3510
3479
|
function childRefProblem(node, ref, ownId) {
|
|
3511
3480
|
const label = ref.path.filter((step) => step !== "*").join(".");
|
|
3512
|
-
const isDynamic = (value) => isPathBinding(value) || isRecord(value) && "@call" in value;
|
|
3481
|
+
const isDynamic = (value) => isPathBinding(value) || isRecord$2(value) && "@call" in value;
|
|
3513
3482
|
const visit = (value, steps) => {
|
|
3514
3483
|
if (isDynamic(value)) return void 0;
|
|
3515
3484
|
if (steps.length === 0) {
|
|
@@ -3525,7 +3494,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3525
3494
|
}
|
|
3526
3495
|
return;
|
|
3527
3496
|
}
|
|
3528
|
-
if (!isRecord(value) || !hasOwn(value, head)) return void 0;
|
|
3497
|
+
if (!isRecord$2(value) || !hasOwn$1(value, head)) return void 0;
|
|
3529
3498
|
return visit(value[head], rest);
|
|
3530
3499
|
};
|
|
3531
3500
|
return visit(node, ref.path);
|
|
@@ -3649,7 +3618,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3649
3618
|
function parseObject(raw) {
|
|
3650
3619
|
try {
|
|
3651
3620
|
const value = JSON.parse(raw);
|
|
3652
|
-
return isRecord(value) ? value : null;
|
|
3621
|
+
return isRecord$2(value) ? value : null;
|
|
3653
3622
|
} catch (_unused3) {
|
|
3654
3623
|
return null;
|
|
3655
3624
|
}
|
|
@@ -3686,6 +3655,434 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3686
3655
|
}
|
|
3687
3656
|
};
|
|
3688
3657
|
|
|
3658
|
+
//#endregion
|
|
3659
|
+
//#region src/generative-ui/compact-schema.ts
|
|
3660
|
+
/** Objects nested deeper than this show as `object`. */
|
|
3661
|
+
const MAX_OBJECT_DEPTH = 2;
|
|
3662
|
+
/** A prop must appear verbatim in at least this many components to be hoisted. */
|
|
3663
|
+
const COMMON_PROP_MIN_COMPONENTS = 8;
|
|
3664
|
+
function isRecord$1(value) {
|
|
3665
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3666
|
+
}
|
|
3667
|
+
/** A JSON Schema of a list of schemas (`anyOf`, `oneOf`), else an empty list. */
|
|
3668
|
+
function schemaList(value) {
|
|
3669
|
+
return Array.isArray(value) ? value.filter(isRecord$1) : [];
|
|
3670
|
+
}
|
|
3671
|
+
/**
|
|
3672
|
+
* Puts a top-level union in parentheses, so that `[]` applies to all of
|
|
3673
|
+
* it. A union inside braces needs none.
|
|
3674
|
+
*/
|
|
3675
|
+
function asArrayItem(type) {
|
|
3676
|
+
let outside = type;
|
|
3677
|
+
for (let inner = outside.replace(/\{[^{}]*\}/g, ""); inner !== outside;) {
|
|
3678
|
+
outside = inner;
|
|
3679
|
+
inner = outside.replace(/\{[^{}]*\}/g, "");
|
|
3680
|
+
}
|
|
3681
|
+
return outside.includes(" | ") ? `(${type})[]` : `${type}[]`;
|
|
3682
|
+
}
|
|
3683
|
+
/**
|
|
3684
|
+
* A JSON Schema as a short TypeScript-like type, for example
|
|
3685
|
+
* `{ label: string; size?: "sm" | "md" }`.
|
|
3686
|
+
*/
|
|
3687
|
+
function compactType(schema, depth) {
|
|
3688
|
+
const ref = childRefKind(schema);
|
|
3689
|
+
if (ref === "single") return "componentId";
|
|
3690
|
+
if (ref === "multiple") return "componentId[] | { componentId: string; path: string }";
|
|
3691
|
+
if ("const" in schema) return JSON.stringify(schema.const);
|
|
3692
|
+
if (Array.isArray(schema.enum)) return schema.enum.map((value) => JSON.stringify(value)).join(" | ");
|
|
3693
|
+
const variants = [...schemaList(schema.anyOf), ...schemaList(schema.oneOf)];
|
|
3694
|
+
if (variants.length > 0) return variants.map((variant) => compactType(variant, depth)).join(" | ");
|
|
3695
|
+
return (Array.isArray(schema.type) ? schema.type : [schema.type]).map((type) => {
|
|
3696
|
+
switch (type) {
|
|
3697
|
+
case "string":
|
|
3698
|
+
case "boolean":
|
|
3699
|
+
case "null": return type;
|
|
3700
|
+
case "number":
|
|
3701
|
+
case "integer": return "number";
|
|
3702
|
+
case "array": return isRecord$1(schema.items) ? asArrayItem(compactType(schema.items, depth)) : "unknown[]";
|
|
3703
|
+
case "object": return compactObject(schema, depth);
|
|
3704
|
+
default: return "unknown";
|
|
3705
|
+
}
|
|
3706
|
+
}).join(" | ");
|
|
3707
|
+
}
|
|
3708
|
+
/** An object schema as `{ key: type; other?: type }`. */
|
|
3709
|
+
function compactObject(schema, depth) {
|
|
3710
|
+
const properties = isRecord$1(schema.properties) ? schema.properties : {};
|
|
3711
|
+
const entries = Object.entries(properties);
|
|
3712
|
+
if (entries.length === 0) return isRecord$1(schema.additionalProperties) ? `Record<string, ${compactType(schema.additionalProperties, depth + 1)}>` : "object";
|
|
3713
|
+
if (depth >= MAX_OBJECT_DEPTH) return "object";
|
|
3714
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
3715
|
+
return `{ ${entries.map(([key, value]) => {
|
|
3716
|
+
const type = isRecord$1(value) ? compactType(value, depth + 1) : "unknown";
|
|
3717
|
+
return `${key}${required.includes(key) ? "" : "?"}: ${type}`;
|
|
3718
|
+
}).join("; ")} }`;
|
|
3719
|
+
}
|
|
3720
|
+
/** A schema as its type, with its description after `//`. */
|
|
3721
|
+
function describedType(schema, depth) {
|
|
3722
|
+
const type = compactType(schema, depth);
|
|
3723
|
+
return typeof schema.description === "string" ? `${type} // ${schema.description}` : type;
|
|
3724
|
+
}
|
|
3725
|
+
/**
|
|
3726
|
+
* The props of a component: `{ "label": "string", "size?": "..." }`. With
|
|
3727
|
+
* `descriptions`, each type carries its description after `//`.
|
|
3728
|
+
*/
|
|
3729
|
+
function compactProps(schema, descriptions = true) {
|
|
3730
|
+
const properties = isRecord$1(schema.properties) ? schema.properties : {};
|
|
3731
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
3732
|
+
const props = {};
|
|
3733
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
3734
|
+
if (!isRecord$1(value)) continue;
|
|
3735
|
+
const name = required.includes(key) ? key : `${key}?`;
|
|
3736
|
+
props[name] = descriptions ? describedType(value, 1) : compactType(value, 1);
|
|
3737
|
+
}
|
|
3738
|
+
return props;
|
|
3739
|
+
}
|
|
3740
|
+
/**
|
|
3741
|
+
* The prop set worth listing once. Candidates are (key, type) pairs that at
|
|
3742
|
+
* least {@link COMMON_PROP_MIN_COMPONENTS} components carry verbatim. The
|
|
3743
|
+
* candidate subset of each component is a possible common set, scored by
|
|
3744
|
+
* the characters it saves (set size times the components that contain all
|
|
3745
|
+
* of it). `undefined` when no set is shared by enough components.
|
|
3746
|
+
*/
|
|
3747
|
+
function findCommonProps(propsList) {
|
|
3748
|
+
const pairKey = (key, type) => `${key}\u0000${type}`;
|
|
3749
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3750
|
+
for (const props of propsList) for (const [key, type] of Object.entries(props)) {
|
|
3751
|
+
var _counts$get;
|
|
3752
|
+
const id = pairKey(key, type);
|
|
3753
|
+
counts.set(id, ((_counts$get = counts.get(id)) !== null && _counts$get !== void 0 ? _counts$get : 0) + 1);
|
|
3754
|
+
}
|
|
3755
|
+
let best;
|
|
3756
|
+
let bestScore = 0;
|
|
3757
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3758
|
+
for (const props of propsList) {
|
|
3759
|
+
const subset = Object.entries(props).filter(([key, type]) => {
|
|
3760
|
+
var _counts$get2;
|
|
3761
|
+
return ((_counts$get2 = counts.get(pairKey(key, type))) !== null && _counts$get2 !== void 0 ? _counts$get2 : 0) >= COMMON_PROP_MIN_COMPONENTS;
|
|
3762
|
+
});
|
|
3763
|
+
if (subset.length < 2) continue;
|
|
3764
|
+
const signature = subset.map(([key, type]) => pairKey(key, type)).join("\n");
|
|
3765
|
+
if (seen.has(signature)) continue;
|
|
3766
|
+
seen.add(signature);
|
|
3767
|
+
const members = propsList.filter((other) => subset.every(([key, type]) => other[key] === type)).length;
|
|
3768
|
+
if (members < COMMON_PROP_MIN_COMPONENTS) continue;
|
|
3769
|
+
const score = subset.reduce((total, [key, type]) => total + key.length + type.length, 0) * (members - 1);
|
|
3770
|
+
if (score > bestScore) {
|
|
3771
|
+
bestScore = score;
|
|
3772
|
+
best = Object.fromEntries(subset);
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
return best;
|
|
3776
|
+
}
|
|
3777
|
+
/**
|
|
3778
|
+
* The component schema of the markdown transport, from the per-run
|
|
3779
|
+
* manifest. It is smaller than the manifest: each prop is one short type,
|
|
3780
|
+
* and the props that many components share verbatim (the layout props of
|
|
3781
|
+
* the containers) are listed once in `commonProps`; a component that takes
|
|
3782
|
+
* them is flagged `includesCommonProps`.
|
|
3783
|
+
* It has the catalog id, the targets with their descriptions and their
|
|
3784
|
+
* component lists, the functions with their parameters, the components
|
|
3785
|
+
* with their props, events and slots, and the surfaces of the thread. A surface lists the
|
|
3786
|
+
* values that the user set and the operations that the client dropped.
|
|
3787
|
+
*
|
|
3788
|
+
* @param manifest - The manifest from `buildGenerativeUIManifest`.
|
|
3789
|
+
* @param options - `propDescriptions` (default true) writes each prop's
|
|
3790
|
+
* description; `commonProps` (default true) lists shared props once.
|
|
3791
|
+
* @returns A JSON-ready object.
|
|
3792
|
+
*
|
|
3793
|
+
* @example
|
|
3794
|
+
* ```ts
|
|
3795
|
+
* const value = JSON.stringify(
|
|
3796
|
+
* buildCompactGenerativeUISchema(buildGenerativeUIManifest(runtime, threadId)),
|
|
3797
|
+
* );
|
|
3798
|
+
* ```
|
|
3799
|
+
*/
|
|
3800
|
+
function buildCompactGenerativeUISchema(manifest, options = {}) {
|
|
3801
|
+
const { propDescriptions = true, commonProps = true } = options;
|
|
3802
|
+
const components = {};
|
|
3803
|
+
for (const [name, component] of Object.entries(manifest.components)) {
|
|
3804
|
+
var _component$events;
|
|
3805
|
+
const events = Object.entries((_component$events = component.events) !== null && _component$events !== void 0 ? _component$events : {}).map(([event, definition]) => {
|
|
3806
|
+
var _definition$descripti;
|
|
3807
|
+
return [event, (_definition$descripti = definition.description) !== null && _definition$descripti !== void 0 ? _definition$descripti : compactType(definition.parameters, 0)];
|
|
3808
|
+
});
|
|
3809
|
+
components[name] = {
|
|
3810
|
+
...component.description ? { description: component.description } : {},
|
|
3811
|
+
props: compactProps(component.props, propDescriptions),
|
|
3812
|
+
...events.length > 0 ? { events: Object.fromEntries(events) } : {},
|
|
3813
|
+
...component.slots ? { slots: component.slots } : {}
|
|
3814
|
+
};
|
|
3815
|
+
}
|
|
3816
|
+
const common = commonProps ? findCommonProps(Object.values(components).map((component) => component.props)) : void 0;
|
|
3817
|
+
if (common) {
|
|
3818
|
+
const commonKeys = Object.keys(common);
|
|
3819
|
+
for (const component of Object.values(components)) {
|
|
3820
|
+
if (!commonKeys.every((key) => component.props[key] === common[key])) continue;
|
|
3821
|
+
component.includesCommonProps = true;
|
|
3822
|
+
component.props = Object.fromEntries(Object.entries(component.props).filter(([key]) => !(key in common)));
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
const functions = Object.fromEntries(Object.entries(manifest.functions).map(([name, fn]) => {
|
|
3826
|
+
const signature = fn.parameters.description;
|
|
3827
|
+
const hasSignature = typeof signature === "string" && signature.startsWith("{") && Object.keys(fn.parameters).length === 2;
|
|
3828
|
+
const callers = functionCallers(fn);
|
|
3829
|
+
return [name, {
|
|
3830
|
+
...fn.description ? { description: fn.description } : {},
|
|
3831
|
+
parameters: hasSignature ? signature : compactType(fn.parameters, 0),
|
|
3832
|
+
...callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS ? { callers: callers.renderer ? "UI or agent" : "agent only" } : {}
|
|
3833
|
+
}];
|
|
3834
|
+
}));
|
|
3835
|
+
return {
|
|
3836
|
+
catalogId: manifest.catalogId,
|
|
3837
|
+
targets: manifest.targets,
|
|
3838
|
+
functions,
|
|
3839
|
+
...common ? { commonProps: common } : {},
|
|
3840
|
+
components,
|
|
3841
|
+
surfaces: manifest.surfaces
|
|
3842
|
+
};
|
|
3843
|
+
}
|
|
3844
|
+
|
|
3845
|
+
//#endregion
|
|
3846
|
+
//#region src/generative-ui/schema-render.ts
|
|
3847
|
+
/** An own key (shared compiles to ES2017, which has no Object.hasOwn). */
|
|
3848
|
+
const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
3849
|
+
function isRecord(value) {
|
|
3850
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3851
|
+
}
|
|
3852
|
+
/** The props schema without the description of each prop. */
|
|
3853
|
+
function withoutPropDescriptions(schema) {
|
|
3854
|
+
if (!isRecord(schema.properties)) return schema;
|
|
3855
|
+
return {
|
|
3856
|
+
...schema,
|
|
3857
|
+
properties: Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => {
|
|
3858
|
+
if (!isRecord(value)) return [key, value];
|
|
3859
|
+
const { description: _description, ...rest } = value;
|
|
3860
|
+
return [key, rest];
|
|
3861
|
+
}))
|
|
3862
|
+
};
|
|
3863
|
+
}
|
|
3864
|
+
/** The short signature of a function: its built-in signature, or its schema made short. */
|
|
3865
|
+
function functionSignature(fn) {
|
|
3866
|
+
const signature = fn.parameters.description;
|
|
3867
|
+
return typeof signature === "string" && signature.startsWith("{") && Object.keys(fn.parameters).length === 2 ? signature : compactType(fn.parameters, 0);
|
|
3868
|
+
}
|
|
3869
|
+
/**
|
|
3870
|
+
* A function name with its parameters: `pick{ id: string }`, `clearCart{}`
|
|
3871
|
+
* for no arguments, `setVolume(number)` for a parameter that is not an object.
|
|
3872
|
+
*/
|
|
3873
|
+
function nameWithParameters(name, parameters) {
|
|
3874
|
+
if (parameters.startsWith("{")) return `${name}${parameters}`;
|
|
3875
|
+
if (parameters === "object") return `${name}{}`;
|
|
3876
|
+
return `${name}(${parameters})`;
|
|
3877
|
+
}
|
|
3878
|
+
/**
|
|
3879
|
+
* One component as a TypeScript-like signature line, with its events and
|
|
3880
|
+
* slots on the lines below:
|
|
3881
|
+
* `- Text(text?: string // The text): Shows text`.
|
|
3882
|
+
*/
|
|
3883
|
+
function signatureLines(name, component, settings) {
|
|
3884
|
+
var _component$events, _component$slots;
|
|
3885
|
+
const lines = [`- ${name}(${Object.entries(compactProps(component.props, settings.propDescriptions)).map(([key, type]) => `${key}: ${type}`).join(", ")})${component.description ? `: ${oneLine(component.description)}` : ""}`];
|
|
3886
|
+
const events = Object.entries((_component$events = component.events) !== null && _component$events !== void 0 ? _component$events : {}).map(([event, definition]) => `${event}(${definition.description ? oneLine(definition.description) : compactType(definition.parameters, 0)})`);
|
|
3887
|
+
if (events.length > 0) lines.push(` events: ${events.join(", ")}`);
|
|
3888
|
+
const slots = Object.entries((_component$slots = component.slots) !== null && _component$slots !== void 0 ? _component$slots : {}).map(([slot, kind]) => `${slot} (${kind})`);
|
|
3889
|
+
if (slots.length > 0) lines.push(` slots: ${slots.join(", ")}`);
|
|
3890
|
+
return lines;
|
|
3891
|
+
}
|
|
3892
|
+
/** The whole schema as signature text: targets, functions, components, surfaces. */
|
|
3893
|
+
function signatureSchema(manifest, settings) {
|
|
3894
|
+
const targets = manifest.targets.map((t) => {
|
|
3895
|
+
const limit = t.components ? `; only ${t.components.join(", ")}` : "";
|
|
3896
|
+
return `- ${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : ""}`;
|
|
3897
|
+
});
|
|
3898
|
+
const functions = Object.entries(manifest.functions).map(([name, fn]) => {
|
|
3899
|
+
const callers = functionCallers(fn);
|
|
3900
|
+
const who = callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS ? callers.renderer ? " (UI or agent)" : " (agent only)" : "";
|
|
3901
|
+
return `- ${nameWithParameters(name, functionSignature(fn))}${who}${fn.description ? `: ${oneLine(fn.description)}` : ""}`;
|
|
3902
|
+
});
|
|
3903
|
+
const components = Object.entries(manifest.components).flatMap(([name, component]) => signatureLines(name, component, settings));
|
|
3904
|
+
const surfaces = Object.entries(manifest.surfaces).map(([id, s]) => {
|
|
3905
|
+
var _s$rejected;
|
|
3906
|
+
return `- ${id} (target ${s.target})${s.status ? ` status: ${s.status}` : ""}${s.dataModel ? ` user values: ${JSON.stringify(s.dataModel)}` : ""}${((_s$rejected = s.rejected) !== null && _s$rejected !== void 0 ? _s$rejected : []).map((r) => ` rejected: ${r}`).join("")}`;
|
|
3907
|
+
});
|
|
3908
|
+
return [
|
|
3909
|
+
`Catalog: ${manifest.catalogId}`,
|
|
3910
|
+
`Targets:\n${targets.join("\n") || "- none"}`,
|
|
3911
|
+
`Functions:\n${functions.join("\n") || "- none"}`,
|
|
3912
|
+
`Components:\n${components.join("\n") || "- none"}`,
|
|
3913
|
+
`Surfaces:\n${surfaces.join("\n") || "- none"}`
|
|
3914
|
+
].join("\n\n");
|
|
3915
|
+
}
|
|
3916
|
+
/** A description on one line, so its lines cannot read as new entries. */
|
|
3917
|
+
function oneLine(text) {
|
|
3918
|
+
return text.replace(/\s*\n\s*/g, " ");
|
|
3919
|
+
}
|
|
3920
|
+
/** Values that would read as a type or a number once their quotes are gone. */
|
|
3921
|
+
const AMBIGUOUS_VALUE = /^(?:string|number|integer|boolean|true|false|null|object|array|unknown|any|-?\d[\d.]*)$/;
|
|
3922
|
+
/**
|
|
3923
|
+
* A compact type with bare enum values and tight unions:
|
|
3924
|
+
* `"sm" | "md" | "lg"` becomes `sm|md|lg`. A union keeps its quotes when it
|
|
3925
|
+
* also holds a type (`"sm" | number`) or a value that reads as a type or a
|
|
3926
|
+
* number (`"number" | "currency"`, `"1" | "2"`), and so do values that are
|
|
3927
|
+
* not plain words.
|
|
3928
|
+
*/
|
|
3929
|
+
function bareType(type) {
|
|
3930
|
+
return type.replace(/"[A-Za-z0-9_#%.-]+"(?: \| "[A-Za-z0-9_#%.-]+")*(?! \|)/g, (union, offset, whole) => {
|
|
3931
|
+
if (whole.slice(offset - 2, offset) === "| ") return union;
|
|
3932
|
+
const values = union.split(" | ").map((v) => v.slice(1, -1));
|
|
3933
|
+
if (values.some((v) => AMBIGUOUS_VALUE.test(v))) return union;
|
|
3934
|
+
return values.join("|");
|
|
3935
|
+
}).replace(/ \| /g, "|");
|
|
3936
|
+
}
|
|
3937
|
+
/** A compact prop (`type // description`) as `name: type - description`. */
|
|
3938
|
+
function propLine(key, value) {
|
|
3939
|
+
const name = key.endsWith("?") ? key.slice(0, -1) : `${key}*`;
|
|
3940
|
+
const cut = value.indexOf(" // ");
|
|
3941
|
+
const type = bareType(cut < 0 ? value : value.slice(0, cut));
|
|
3942
|
+
const text = cut < 0 ? "" : value.slice(cut + 4).trim();
|
|
3943
|
+
return ` ${name}: ${type}${text ? ` - ${oneLine(text)}` : ""}`;
|
|
3944
|
+
}
|
|
3945
|
+
/**
|
|
3946
|
+
* The whole schema as plain lines: a header line per component and one
|
|
3947
|
+
* indented line per prop: events are `action` props and slots `componentId`
|
|
3948
|
+
* or `childList` props. Props are optional unless marked `*`, enum values
|
|
3949
|
+
* are bare, and the common props are listed once. It carries the same names, types and descriptions as
|
|
3950
|
+
* `compact`, in fewer tokens.
|
|
3951
|
+
*/
|
|
3952
|
+
function linesSchema(manifest, settings) {
|
|
3953
|
+
const compact = buildCompactGenerativeUISchema(manifest, {
|
|
3954
|
+
propDescriptions: settings.propDescriptions,
|
|
3955
|
+
commonProps: settings.commonProps
|
|
3956
|
+
});
|
|
3957
|
+
const targets = compact.targets.map((t) => {
|
|
3958
|
+
const limit = t.components ? `, only ${t.components.join(", ")}` : "";
|
|
3959
|
+
return `${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : ""}`;
|
|
3960
|
+
}).join("; ");
|
|
3961
|
+
const functions = Object.entries(compact.functions).map(([name, fn]) => `${nameWithParameters(name, fn.parameters)}${"callers" in fn ? ` (${fn.callers})` : ""}${fn.description ? `: ${oneLine(fn.description)}` : ""}`);
|
|
3962
|
+
const common = compact.commonProps ? Object.entries(compact.commonProps).map(([k, v]) => propLine(k, v)) : [];
|
|
3963
|
+
const components = Object.entries(compact.components).map(([name, c]) => {
|
|
3964
|
+
var _c$events;
|
|
3965
|
+
return {
|
|
3966
|
+
name,
|
|
3967
|
+
c,
|
|
3968
|
+
own: [...Object.entries(c.props).map(([k, v]) => propLine(k, v)), ...Object.entries((_c$events = c.events) !== null && _c$events !== void 0 ? _c$events : {}).map(([e, d]) => ` ${e}: action - ${oneLine(d)}`)]
|
|
3969
|
+
};
|
|
3970
|
+
}).flatMap(({ name, c, own }) => {
|
|
3971
|
+
var _c$slots;
|
|
3972
|
+
const lines = [`${name}${c.includesCommonProps ? " +common" : ""}${c.description ? `: ${oneLine(c.description)}` : ""}`, ...own];
|
|
3973
|
+
for (const [slot, kind] of Object.entries((_c$slots = c.slots) !== null && _c$slots !== void 0 ? _c$slots : {})) lines.push(` ${slot}: ${kind === "single" ? "componentId" : "childList"}`);
|
|
3974
|
+
return lines;
|
|
3975
|
+
});
|
|
3976
|
+
const surfaces = Object.keys(compact.surfaces).length ? JSON.stringify(compact.surfaces) : "none";
|
|
3977
|
+
return [
|
|
3978
|
+
`Catalog ${compact.catalogId}. Targets: ${targets || "none"}`,
|
|
3979
|
+
"Props are optional unless marked *. a|b|c is one of those strings, quoted when one reads as a type or a number. A component marked +common also takes every common prop. A prop of type action is an event prop: give it {\"event\":{...}} or {\"functionCall\":{...}}. A componentId prop takes one component id; a childList prop takes a list of ids or a template.",
|
|
3980
|
+
`Functions:\n${functions.join("\n")}`,
|
|
3981
|
+
...common.length ? [`Common props:\n${common.join("\n")}`] : [],
|
|
3982
|
+
`Components:\n${components.join("\n")}`,
|
|
3983
|
+
`Surfaces: ${surfaces}`
|
|
3984
|
+
].join("\n\n");
|
|
3985
|
+
}
|
|
3986
|
+
/**
|
|
3987
|
+
* The component schema of the markdown transport, as the text of its
|
|
3988
|
+
* context entry, in the notation of `settings`. `compact` is the schema that
|
|
3989
|
+
* ships (`buildCompactGenerativeUISchema`), `json-schema` the manifest parts
|
|
3990
|
+
* as JSON, `ts-signature` one line per component, `lines` one line per
|
|
3991
|
+
* prop with bare enums (the fewest tokens).
|
|
3992
|
+
*
|
|
3993
|
+
* @example
|
|
3994
|
+
* ```ts
|
|
3995
|
+
* const value = renderGenerativeUISchema(manifest, spec.schema.markdown);
|
|
3996
|
+
* ```
|
|
3997
|
+
*/
|
|
3998
|
+
function renderGenerativeUISchema(manifest, settings) {
|
|
3999
|
+
switch (settings.notation) {
|
|
4000
|
+
case "compact": return JSON.stringify(buildCompactGenerativeUISchema(manifest, {
|
|
4001
|
+
propDescriptions: settings.propDescriptions,
|
|
4002
|
+
commonProps: settings.commonProps
|
|
4003
|
+
}));
|
|
4004
|
+
case "json-schema": {
|
|
4005
|
+
const components = Object.fromEntries(Object.entries(manifest.components).map(([name, c]) => [name, settings.propDescriptions ? c : {
|
|
4006
|
+
...c,
|
|
4007
|
+
props: withoutPropDescriptions(c.props)
|
|
4008
|
+
}]));
|
|
4009
|
+
return JSON.stringify({
|
|
4010
|
+
catalogId: manifest.catalogId,
|
|
4011
|
+
targets: manifest.targets,
|
|
4012
|
+
functions: manifest.functions,
|
|
4013
|
+
components,
|
|
4014
|
+
surfaces: manifest.surfaces
|
|
4015
|
+
});
|
|
4016
|
+
}
|
|
4017
|
+
case "ts-signature": return signatureSchema(manifest, settings);
|
|
4018
|
+
case "lines": return linesSchema(manifest, settings);
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
4021
|
+
/**
|
|
4022
|
+
* The component list of the tool guide, one entry per component, in the
|
|
4023
|
+
* notation of `settings`. `json-schema` is the list that ships.
|
|
4024
|
+
*/
|
|
4025
|
+
function renderGenerativeUIComponentList(components, settings) {
|
|
4026
|
+
return Object.entries(components).map(([name, c]) => {
|
|
4027
|
+
if (settings.notation === "ts-signature" || settings.notation === "lines") return signatureLines(name, c, settings).join("\n");
|
|
4028
|
+
const props = settings.notation === "compact" ? compactProps(c.props, settings.propDescriptions) : settings.propDescriptions ? c.props : withoutPropDescriptions(c.props);
|
|
4029
|
+
const lines = [`- **${name}**${c.description ? `: ${oneLine(c.description)}` : ""}`, ` props: ${JSON.stringify(props)}`];
|
|
4030
|
+
if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);
|
|
4031
|
+
if (c.slots) lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);
|
|
4032
|
+
return lines.join("\n");
|
|
4033
|
+
}).join("\n");
|
|
4034
|
+
}
|
|
4035
|
+
/**
|
|
4036
|
+
* The manifest with replaced descriptions: `"Name"` replaces the
|
|
4037
|
+
* description of a component, `"Name.prop"` the description of one of its
|
|
4038
|
+
* props. Keys that name no component or prop are left out of the result
|
|
4039
|
+
* and listed in `unknown`. The manifest is not changed.
|
|
4040
|
+
*/
|
|
4041
|
+
function applyDescriptionOverrides(manifest, overrides) {
|
|
4042
|
+
const components = structuredClone(manifest.components);
|
|
4043
|
+
const unknown = [];
|
|
4044
|
+
for (const [key, description] of Object.entries(overrides)) {
|
|
4045
|
+
const [name, prop, ...rest] = key.split(".");
|
|
4046
|
+
const component = hasOwn(components, name) ? components[name] : void 0;
|
|
4047
|
+
if (!component || rest.length > 0) {
|
|
4048
|
+
unknown.push(key);
|
|
4049
|
+
continue;
|
|
4050
|
+
}
|
|
4051
|
+
if (prop === void 0) {
|
|
4052
|
+
component.description = description;
|
|
4053
|
+
continue;
|
|
4054
|
+
}
|
|
4055
|
+
const properties = component.props.properties;
|
|
4056
|
+
const property = isRecord(properties) && hasOwn(properties, prop) ? properties[prop] : void 0;
|
|
4057
|
+
if (!isRecord(property)) {
|
|
4058
|
+
unknown.push(key);
|
|
4059
|
+
continue;
|
|
4060
|
+
}
|
|
4061
|
+
property.description = description;
|
|
4062
|
+
}
|
|
4063
|
+
return {
|
|
4064
|
+
manifest: {
|
|
4065
|
+
...manifest,
|
|
4066
|
+
components
|
|
4067
|
+
},
|
|
4068
|
+
unknown
|
|
4069
|
+
};
|
|
4070
|
+
}
|
|
4071
|
+
/**
|
|
4072
|
+
* The components and props of `manifest` whose names do not appear in
|
|
4073
|
+
* `rendered`. A schema notation that leaves one out would hide part of the
|
|
4074
|
+
* catalog from the model.
|
|
4075
|
+
*/
|
|
4076
|
+
function schemaCoverage(manifest, rendered) {
|
|
4077
|
+
const missing = [];
|
|
4078
|
+
for (const [name, component] of Object.entries(manifest.components)) {
|
|
4079
|
+
if (!rendered.includes(name)) missing.push(name);
|
|
4080
|
+
const properties = isRecord(component.props.properties) ? component.props.properties : {};
|
|
4081
|
+
for (const prop of Object.keys(properties)) if (!rendered.includes(prop)) missing.push(`${name}.${prop}`);
|
|
4082
|
+
}
|
|
4083
|
+
return { missing };
|
|
4084
|
+
}
|
|
4085
|
+
|
|
3689
4086
|
//#endregion
|
|
3690
4087
|
//#region src/generative-ui/prompt.ts
|
|
3691
4088
|
const GENERATIVE_UI_CONTEXT_DESCRIPTION = "Generative UI guide: available components, functions, targets, and how to call render_ui.";
|
|
@@ -3700,19 +4097,15 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3700
4097
|
* the `render_ui` rules, the targets, components, functions, and surfaces of
|
|
3701
4098
|
* the manifest. It is in shared so that the inspector shows the same text.
|
|
3702
4099
|
*/
|
|
3703
|
-
function buildGenerativeUIPrompt(manifest) {
|
|
4100
|
+
function buildGenerativeUIPrompt(manifest, spec = defaultGenerativeUIPromptSpec()) {
|
|
4101
|
+
var _spec$tool$operations;
|
|
3704
4102
|
const targets = manifest.targets.map((t) => {
|
|
3705
4103
|
const place = t.kind === "chat" ? "inside the chat transcript" : "a named area of the app";
|
|
3706
4104
|
const limit = t.components ? `; only ${t.components.join(", ") || "no components"}` : "";
|
|
3707
4105
|
const description = t.description ? `: ${t.description}` : "";
|
|
3708
4106
|
return `- "${t.id}" (${place}${limit})${description}`;
|
|
3709
4107
|
}).join("\n");
|
|
3710
|
-
const components =
|
|
3711
|
-
const lines = [`- **${name}**${c.description ? `: ${c.description}` : ""}`, ` props: ${JSON.stringify(c.props)}`];
|
|
3712
|
-
if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);
|
|
3713
|
-
if (c.slots) lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);
|
|
3714
|
-
return lines.join("\n");
|
|
3715
|
-
}).join("\n");
|
|
4108
|
+
const components = renderGenerativeUIComponentList(manifest.components, spec.schema.tool);
|
|
3716
4109
|
const functions = Object.entries(manifest.functions).map(([name, f]) => {
|
|
3717
4110
|
const signature = f.parameters.description;
|
|
3718
4111
|
const args = typeof signature === "string" && signature.startsWith("{") && Object.keys(f.parameters).length === 2 ? signature : JSON.stringify(f.parameters);
|
|
@@ -3731,38 +4124,15 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3731
4124
|
var _s$rejected$length, _s$rejected2;
|
|
3732
4125
|
return s.dataModel !== void 0 || ((_s$rejected$length = (_s$rejected2 = s.rejected) === null || _s$rejected2 === void 0 ? void 0 : _s$rejected2.length) !== null && _s$rejected$length !== void 0 ? _s$rejected$length : 0) > 0;
|
|
3733
4126
|
}) ? "User values are what the user entered, by path. Your writes to those paths are ignored. Rejected operations were dropped: send them again with the problem fixed.\n" : "";
|
|
3734
|
-
const
|
|
3735
|
-
const
|
|
3736
|
-
const operations = [
|
|
3737
|
-
|
|
3738
|
-
"{\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.",
|
|
3739
|
-
"{\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".",
|
|
3740
|
-
"{\"version\":\"v1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.",
|
|
3741
|
-
...agentCalls ? ["{\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface."] : []
|
|
3742
|
-
];
|
|
3743
|
-
const rules = [
|
|
3744
|
-
"Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.",
|
|
3745
|
-
"A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.",
|
|
3746
|
-
"Stream progressively: put the initial data in \"dataModel\" and the root in \"components\" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example \"children\":[\"card-1\",\"card-2\"]), even though the children come later. A component that no slot references is never shown.",
|
|
3747
|
-
"Updating a component replaces all of its props, so resend every prop.",
|
|
3748
|
-
"Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.",
|
|
3749
|
-
...events ? [hasFunctions ? "Event props take an action. {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}} runs an app function in the browser immediately, and you are not told about it. {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\". Only call functions listed below." : "Event props take an action: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\"."] : [],
|
|
3750
|
-
"To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.",
|
|
3751
|
-
"Never use a surfaceId again, also after deleteSurface.",
|
|
3752
|
-
"A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.",
|
|
3753
|
-
"${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}.",
|
|
3754
|
-
"For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.",
|
|
3755
|
-
...checks ? ["Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email. A failed check shows the message under the input and disables a Button that has the same checks."] : [],
|
|
3756
|
-
...templates ? ["To repeat a component for each item of a list, give a multiple slot a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}. Inside the template, paths are relative to the item (\"name\", not \"/name\"). {\"@call\":\"@index\"} gives the position of the item, from 0; {\"@call\":\"@index\",\"args\":{\"offset\":1}} counts from 1."] : [],
|
|
3757
|
-
...agentCalls ? ["Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it."] : []
|
|
3758
|
-
];
|
|
4127
|
+
const features = generativeUIPromptFeatures(generativeUIGuideFeatures(manifest));
|
|
4128
|
+
const { intro, whenToShow } = spec.tool;
|
|
4129
|
+
const operations = selectPromptItems((_spec$tool$operations = spec.tool.operations) !== null && _spec$tool$operations !== void 0 ? _spec$tool$operations : [], features);
|
|
4130
|
+
const rules = selectPromptItems(spec.tool.rules, features);
|
|
3759
4131
|
return [
|
|
3760
4132
|
`## Generative UI
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
${GENERATIVE_UI_WHEN_TO_SHOW}
|
|
4133
|
+
${intro}
|
|
3764
4134
|
|
|
3765
|
-
Every operation has "version":"v1.0" and exactly one of:
|
|
4135
|
+
${whenToShow ? `${whenToShow}\n\n` : ""}Every operation has "version":"v1.0" and exactly one of:
|
|
3766
4136
|
${operations.map((op) => `- ${op}`).join("\n")}
|
|
3767
4137
|
|
|
3768
4138
|
Rules:
|
|
@@ -3844,8 +4214,6 @@ exports.COPILOT_CLOUD_ERROR_NAMES = COPILOT_CLOUD_ERROR_NAMES;
|
|
|
3844
4214
|
exports.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = COPILOT_CLOUD_PUBLIC_API_KEY_HEADER;
|
|
3845
4215
|
exports.COPILOT_CLOUD_VERSION = COPILOT_CLOUD_VERSION;
|
|
3846
4216
|
exports.ConfigurationError = ConfigurationError;
|
|
3847
|
-
exports.ConsoleColors = ConsoleColors;
|
|
3848
|
-
exports.ConsoleStyles = ConsoleStyles;
|
|
3849
4217
|
exports.CopilotKitAgentDiscoveryError = CopilotKitAgentDiscoveryError;
|
|
3850
4218
|
exports.CopilotKitApiDiscoveryError = CopilotKitApiDiscoveryError;
|
|
3851
4219
|
exports.CopilotKitError = CopilotKitError;
|
|
@@ -3853,7 +4221,6 @@ exports.CopilotKitErrorCode = CopilotKitErrorCode;
|
|
|
3853
4221
|
exports.CopilotKitLowLevelError = CopilotKitLowLevelError;
|
|
3854
4222
|
exports.CopilotKitMisuseError = CopilotKitMisuseError;
|
|
3855
4223
|
exports.CopilotKitRemoteEndpointDiscoveryError = CopilotKitRemoteEndpointDiscoveryError;
|
|
3856
|
-
exports.CopilotKitVersionMismatchError = CopilotKitVersionMismatchError;
|
|
3857
4224
|
exports.DEFAULT_AGENT_ID = DEFAULT_AGENT_ID;
|
|
3858
4225
|
exports.ERROR_CONFIG = ERROR_CONFIG;
|
|
3859
4226
|
exports.ERROR_NAMES = ERROR_NAMES;
|
|
@@ -3870,11 +4237,14 @@ exports.GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE = GENERATIVE_UI_FUNCTION_CALL_
|
|
|
3870
4237
|
exports.GENERATIVE_UI_MARKDOWN_GUIDELINES = GENERATIVE_UI_MARKDOWN_GUIDELINES;
|
|
3871
4238
|
exports.GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION = GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION;
|
|
3872
4239
|
exports.GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION = GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION;
|
|
4240
|
+
exports.GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW = GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW;
|
|
3873
4241
|
exports.GENERATIVE_UI_MAX_REJECTION_LENGTH = GENERATIVE_UI_MAX_REJECTION_LENGTH;
|
|
3874
4242
|
exports.GENERATIVE_UI_MAX_SUMMARY_REJECTIONS = GENERATIVE_UI_MAX_SUMMARY_REJECTIONS;
|
|
3875
4243
|
exports.GENERATIVE_UI_MAX_TARGET_COMPONENTS = GENERATIVE_UI_MAX_TARGET_COMPONENTS;
|
|
3876
4244
|
exports.GENERATIVE_UI_RENDER_TOOL = GENERATIVE_UI_RENDER_TOOL;
|
|
3877
4245
|
exports.GENERATIVE_UI_ROOT_ID = GENERATIVE_UI_ROOT_ID;
|
|
4246
|
+
exports.GENERATIVE_UI_WHEN_TO_SHOW = GENERATIVE_UI_WHEN_TO_SHOW;
|
|
4247
|
+
exports.GUIDE_COMPONENTS = GUIDE_COMPONENTS;
|
|
3878
4248
|
exports.MODEL_HOST_CLASSES = MODEL_HOST_CLASSES;
|
|
3879
4249
|
exports.MissingPublicApiKeyError = MissingPublicApiKeyError;
|
|
3880
4250
|
exports.RUNTIME_MODE_INTELLIGENCE = RUNTIME_MODE_INTELLIGENCE;
|
|
@@ -3893,6 +4263,8 @@ exports.UNSAMPLED_RATE = UNSAMPLED_RATE;
|
|
|
3893
4263
|
exports.UpgradeRequiredError = UpgradeRequiredError;
|
|
3894
4264
|
exports.actionParametersToJsonSchema = actionParametersToJsonSchema;
|
|
3895
4265
|
exports.applyChildRefMarks = applyChildRefMarks;
|
|
4266
|
+
exports.applyDescriptionOverrides = applyDescriptionOverrides;
|
|
4267
|
+
exports.buildCompactGenerativeUISchema = buildCompactGenerativeUISchema;
|
|
3896
4268
|
exports.buildGenerativeUIMarkdownGuidelines = buildGenerativeUIMarkdownGuidelines;
|
|
3897
4269
|
exports.buildGenerativeUIPrompt = buildGenerativeUIPrompt;
|
|
3898
4270
|
exports.callerProblem = callerProblem;
|
|
@@ -3902,17 +4274,15 @@ exports.classifyModelHost = classifyModelHost;
|
|
|
3902
4274
|
exports.collectChildRefs = collectChildRefs;
|
|
3903
4275
|
exports.commitRowKeyStore = commitRowKeyStore;
|
|
3904
4276
|
exports.computeSamplingMeta = computeSamplingMeta;
|
|
3905
|
-
exports.convertJsonSchemaToZodSchema = convertJsonSchemaToZodSchema;
|
|
3906
4277
|
exports.copyToClipboard = copyToClipboard;
|
|
3907
4278
|
exports.createAttachmentContent = createAttachmentContent;
|
|
3908
4279
|
exports.createLicenseContextValue = createLicenseContextValue;
|
|
3909
4280
|
exports.createRowKeyStore = createRowKeyStore;
|
|
3910
4281
|
exports.createRunEventFinalizer = createRunEventFinalizer;
|
|
3911
|
-
exports.
|
|
4282
|
+
exports.defaultGenerativeUIPromptSpec = defaultGenerativeUIPromptSpec;
|
|
3912
4283
|
exports.ensureStructuredError = ensureStructuredError;
|
|
3913
4284
|
exports.envelopeToManifest = envelopeToManifest;
|
|
3914
4285
|
exports.exceedsMaxSize = exceedsMaxSize;
|
|
3915
|
-
exports.executeConditions = executeConditions;
|
|
3916
4286
|
exports.extractRenderUIArgs = extractRenderUIArgs;
|
|
3917
4287
|
exports.finalizeRunEvents = finalizeRunEvents;
|
|
3918
4288
|
exports.firstNonBlankTelemetryId = firstNonBlankTelemetryId;
|
|
@@ -3921,14 +4291,13 @@ exports.functionCallers = functionCallers;
|
|
|
3921
4291
|
exports.generateVideoThumbnail = generateVideoThumbnail;
|
|
3922
4292
|
exports.generativeUIFunctionCallMessageId = generativeUIFunctionCallMessageId;
|
|
3923
4293
|
exports.generativeUIGuideFeatures = generativeUIGuideFeatures;
|
|
4294
|
+
exports.generativeUIPromptFeatures = generativeUIPromptFeatures;
|
|
3924
4295
|
exports.generativeUISurfaceMessageId = generativeUISurfaceMessageId;
|
|
3925
4296
|
exports.getDocumentIcon = getDocumentIcon;
|
|
3926
4297
|
exports.getModalityFromMimeType = getModalityFromMimeType;
|
|
3927
4298
|
exports.getOperationKind = getOperationKind;
|
|
3928
4299
|
exports.getOperationSurfaceId = getOperationSurfaceId;
|
|
3929
|
-
exports.getPossibleVersionMismatch = getPossibleVersionMismatch;
|
|
3930
4300
|
exports.getSourceUrl = getSourceUrl;
|
|
3931
|
-
exports.getZodParameters = getZodParameters;
|
|
3932
4301
|
exports.hasBoundChildRef = hasBoundChildRef;
|
|
3933
4302
|
exports.isA2UIBasicFunction = isA2UIBasicFunction;
|
|
3934
4303
|
exports.isA2UIValueFunction = isA2UIValueFunction;
|
|
@@ -3939,12 +4308,9 @@ exports.isMacOS = isMacOS;
|
|
|
3939
4308
|
exports.isPathBinding = isPathBinding;
|
|
3940
4309
|
exports.isStructuredCopilotKitError = isStructuredCopilotKitError;
|
|
3941
4310
|
exports.isTelemetryDisabled = isTelemetryDisabled;
|
|
3942
|
-
exports.isValidUUID = isValidUUID;
|
|
3943
4311
|
exports.isValidationResult = isValidationResult;
|
|
3944
4312
|
exports.jsonSchemaToActionParameters = jsonSchemaToActionParameters;
|
|
3945
4313
|
exports.lambdaClient = lambdaClient;
|
|
3946
|
-
exports.logCopilotKitPlatformMessage = logCopilotKitPlatformMessage;
|
|
3947
|
-
exports.logStyled = logStyled;
|
|
3948
4314
|
exports.logger = logger;
|
|
3949
4315
|
exports.mapAtChildRef = mapAtChildRef;
|
|
3950
4316
|
exports.matchesAcceptFilter = matchesAcceptFilter;
|
|
@@ -3957,23 +4323,27 @@ exports.parseJson = parseJson;
|
|
|
3957
4323
|
exports.parseTelemetryIdFromLicense = parseTelemetryIdFromLicense;
|
|
3958
4324
|
exports.partialJSONParse = partialJSONParse;
|
|
3959
4325
|
exports.phoenixExponentialBackoff = phoenixExponentialBackoff;
|
|
4326
|
+
exports.processEnv = processEnv;
|
|
3960
4327
|
exports.pruneRowKeyStore = pruneRowKeyStore;
|
|
3961
|
-
exports.publicApiKeyRequired = publicApiKeyRequired;
|
|
3962
4328
|
exports.randomId = randomId;
|
|
3963
4329
|
exports.randomUUID = randomUUID;
|
|
3964
4330
|
exports.readBody = readBody;
|
|
3965
4331
|
exports.readCopilotKitUIEnvelope = readCopilotKitUIEnvelope;
|
|
3966
4332
|
exports.readFileAsBase64 = readFileAsBase64;
|
|
4333
|
+
exports.renderGenerativeUIComponentList = renderGenerativeUIComponentList;
|
|
4334
|
+
exports.renderGenerativeUISchema = renderGenerativeUISchema;
|
|
3967
4335
|
exports.resolveDebugConfig = resolveDebugConfig;
|
|
3968
4336
|
exports.resolveRowRenderKeys = resolveRowRenderKeys;
|
|
3969
4337
|
exports.resolveRowRenderKeysById = resolveRowRenderKeysById;
|
|
3970
4338
|
exports.safeParseToolArgs = safeParseToolArgs;
|
|
4339
|
+
exports.schemaCoverage = schemaCoverage;
|
|
3971
4340
|
exports.schemaToJsonSchema = schemaToJsonSchema;
|
|
4341
|
+
exports.selectPromptItems = selectPromptItems;
|
|
3972
4342
|
exports.shouldEnableInspector = shouldEnableInspector;
|
|
3973
4343
|
exports.stripIntelligenceRoutingFields = stripIntelligenceRoutingFields;
|
|
3974
|
-
exports.styledConsole = styledConsole;
|
|
3975
4344
|
exports.toA2UIActionMessage = toA2UIActionMessage;
|
|
3976
4345
|
exports.tryMap = tryMap;
|
|
3977
4346
|
exports.validateOperation = validateOperation;
|
|
4347
|
+
exports.ɵanySchema = ɵanySchema;
|
|
3978
4348
|
});
|
|
3979
4349
|
//# sourceMappingURL=index.umd.js.map
|