@copilotkit/shared 1.55.0-next.9 → 1.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/dist/a2ui-prompts.cjs +106 -0
  3. package/dist/a2ui-prompts.cjs.map +1 -0
  4. package/dist/a2ui-prompts.d.cts +20 -0
  5. package/dist/a2ui-prompts.d.cts.map +1 -0
  6. package/dist/a2ui-prompts.d.mts +20 -0
  7. package/dist/a2ui-prompts.d.mts.map +1 -0
  8. package/dist/a2ui-prompts.mjs +104 -0
  9. package/dist/a2ui-prompts.mjs.map +1 -0
  10. package/dist/attachments/types.d.cts +54 -0
  11. package/dist/attachments/types.d.cts.map +1 -0
  12. package/dist/attachments/types.d.mts +54 -0
  13. package/dist/attachments/types.d.mts.map +1 -0
  14. package/dist/attachments/utils.cjs +134 -0
  15. package/dist/attachments/utils.cjs.map +1 -0
  16. package/dist/attachments/utils.d.cts +42 -0
  17. package/dist/attachments/utils.d.cts.map +1 -0
  18. package/dist/attachments/utils.d.mts +42 -0
  19. package/dist/attachments/utils.d.mts.map +1 -0
  20. package/dist/attachments/utils.mjs +126 -0
  21. package/dist/attachments/utils.mjs.map +1 -0
  22. package/dist/index.cjs +29 -8
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +20 -3
  25. package/dist/index.d.cts.map +1 -1
  26. package/dist/index.d.mts +20 -3
  27. package/dist/index.d.mts.map +1 -1
  28. package/dist/index.mjs +19 -3
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/index.umd.js +259 -9
  31. package/dist/index.umd.js.map +1 -1
  32. package/dist/package.cjs +1 -1
  33. package/dist/package.mjs +1 -1
  34. package/dist/types/message.d.cts +15 -4
  35. package/dist/types/message.d.cts.map +1 -1
  36. package/dist/types/message.d.mts +15 -4
  37. package/dist/types/message.d.mts.map +1 -1
  38. package/dist/utils/types.cjs.map +1 -1
  39. package/dist/utils/types.d.cts +1 -0
  40. package/dist/utils/types.d.cts.map +1 -1
  41. package/dist/utils/types.d.mts +1 -0
  42. package/dist/utils/types.d.mts.map +1 -1
  43. package/dist/utils/types.mjs.map +1 -1
  44. package/package.json +33 -34
  45. package/src/a2ui-prompts.ts +101 -0
  46. package/src/attachments/__tests__/utils.test.ts +198 -0
  47. package/src/attachments/index.ts +19 -0
  48. package/src/attachments/types.ts +67 -0
  49. package/src/attachments/utils.ts +164 -0
  50. package/src/index.ts +43 -1
  51. package/src/types/__tests__/message.test.ts +62 -0
  52. package/src/types/message.ts +27 -3
  53. package/src/utils/types.ts +1 -0
package/dist/index.umd.js CHANGED
@@ -911,7 +911,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
911
911
 
912
912
  //#endregion
913
913
  //#region package.json
914
- var version = "1.55.0-next.9";
914
+ var version = "1.55.0";
915
915
 
916
916
  //#endregion
917
917
  //#region src/telemetry/scarf-client.ts
@@ -1042,6 +1042,135 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
1042
1042
  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.`);
1043
1043
  }
1044
1044
 
1045
+ //#endregion
1046
+ //#region src/attachments/utils.ts
1047
+ const DEFAULT_MAX_SIZE = 20 * 1024 * 1024;
1048
+ /**
1049
+ * Derive the attachment modality from a MIME type string.
1050
+ */
1051
+ function getModalityFromMimeType(mimeType) {
1052
+ if (mimeType.startsWith("image/")) return "image";
1053
+ if (mimeType.startsWith("audio/")) return "audio";
1054
+ if (mimeType.startsWith("video/")) return "video";
1055
+ return "document";
1056
+ }
1057
+ /**
1058
+ * Format a byte count as a human-readable file size string.
1059
+ */
1060
+ function formatFileSize(bytes) {
1061
+ if (bytes < 1024) return `${bytes} B`;
1062
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
1063
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
1064
+ }
1065
+ /**
1066
+ * Check if a file exceeds the maximum allowed size.
1067
+ */
1068
+ function exceedsMaxSize(file, maxSize = DEFAULT_MAX_SIZE) {
1069
+ return file.size > maxSize;
1070
+ }
1071
+ /**
1072
+ * Read a File as a base64 string (without the data URL prefix).
1073
+ */
1074
+ function readFileAsBase64(file) {
1075
+ return new Promise((resolve, reject) => {
1076
+ const reader = new FileReader();
1077
+ reader.onload = (e) => {
1078
+ var _e$target;
1079
+ const result = (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.result;
1080
+ const base64 = result === null || result === void 0 ? void 0 : result.split(",")[1];
1081
+ if (base64) resolve(base64);
1082
+ else reject(/* @__PURE__ */ new Error("Failed to read file as base64"));
1083
+ };
1084
+ reader.onerror = reject;
1085
+ reader.readAsDataURL(file);
1086
+ });
1087
+ }
1088
+ /**
1089
+ * Generate a thumbnail data URL from a video file by capturing a frame near the start (at 0.1s).
1090
+ * Returns undefined if thumbnail generation fails or if called outside a browser environment.
1091
+ */
1092
+ function generateVideoThumbnail(file) {
1093
+ if (typeof document === "undefined") return Promise.resolve(void 0);
1094
+ return new Promise((resolve) => {
1095
+ let resolved = false;
1096
+ const video = document.createElement("video");
1097
+ const canvas = document.createElement("canvas");
1098
+ const url = URL.createObjectURL(file);
1099
+ const cleanup = (result) => {
1100
+ if (resolved) return;
1101
+ resolved = true;
1102
+ URL.revokeObjectURL(url);
1103
+ resolve(result);
1104
+ };
1105
+ const timeout = setTimeout(() => {
1106
+ console.warn(`[CopilotKit] generateVideoThumbnail: timed out for file "${file.name}"`);
1107
+ cleanup(void 0);
1108
+ }, 1e4);
1109
+ video.preload = "metadata";
1110
+ video.muted = true;
1111
+ video.playsInline = true;
1112
+ video.onloadeddata = () => {
1113
+ video.currentTime = .1;
1114
+ };
1115
+ video.onseeked = () => {
1116
+ clearTimeout(timeout);
1117
+ canvas.width = video.videoWidth;
1118
+ canvas.height = video.videoHeight;
1119
+ const ctx = canvas.getContext("2d");
1120
+ if (ctx) {
1121
+ ctx.drawImage(video, 0, 0);
1122
+ cleanup(canvas.toDataURL("image/jpeg", .7));
1123
+ } else {
1124
+ console.warn("[CopilotKit] generateVideoThumbnail: could not get 2d canvas context");
1125
+ cleanup(void 0);
1126
+ }
1127
+ };
1128
+ video.onerror = () => {
1129
+ clearTimeout(timeout);
1130
+ console.warn(`[CopilotKit] generateVideoThumbnail: video element error for file "${file.name}"`);
1131
+ cleanup(void 0);
1132
+ };
1133
+ video.src = url;
1134
+ });
1135
+ }
1136
+ /**
1137
+ * Check if a file's MIME type matches an accept filter string.
1138
+ * Handles file extensions (e.g. ".pdf"), MIME wildcards ("image/*"), and comma-separated lists.
1139
+ */
1140
+ function matchesAcceptFilter(file, accept) {
1141
+ if (!accept || accept === "*/*") return true;
1142
+ return accept.split(",").map((f) => f.trim()).some((filter) => {
1143
+ if (filter.startsWith(".")) {
1144
+ var _file$name;
1145
+ return ((_file$name = file.name) !== null && _file$name !== void 0 ? _file$name : "").toLowerCase().endsWith(filter.toLowerCase());
1146
+ }
1147
+ if (filter.endsWith("/*")) {
1148
+ const prefix = filter.slice(0, -2);
1149
+ return file.type.startsWith(prefix + "/");
1150
+ }
1151
+ return file.type === filter;
1152
+ });
1153
+ }
1154
+ /**
1155
+ * Convert an InputContentSource to a usable URL string.
1156
+ * For data sources, returns a base64 data URL; for URL sources, returns the URL directly.
1157
+ */
1158
+ function getSourceUrl(source) {
1159
+ if (source.type === "url") return source.value;
1160
+ return `data:${source.mimeType};base64,${source.value}`;
1161
+ }
1162
+ /**
1163
+ * Return a short human-readable label for a document MIME type (e.g. "PDF", "DOC").
1164
+ */
1165
+ function getDocumentIcon(mimeType) {
1166
+ if (mimeType.includes("pdf")) return "PDF";
1167
+ if (mimeType.includes("sheet") || mimeType.includes("excel")) return "XLS";
1168
+ if (mimeType.includes("presentation") || mimeType.includes("powerpoint")) return "PPT";
1169
+ if (mimeType.includes("word") || mimeType.includes("document")) return "DOC";
1170
+ if (mimeType.includes("text/")) return "TXT";
1171
+ return "FILE";
1172
+ }
1173
+
1045
1174
  //#endregion
1046
1175
  //#region src/logger.ts
1047
1176
  const logger = console;
@@ -1226,11 +1355,131 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
1226
1355
  })
1227
1356
  };
1228
1357
 
1358
+ //#endregion
1359
+ //#region src/a2ui-prompts.ts
1360
+ /**
1361
+ * Default A2UI generation and design guideline prompts.
1362
+ *
1363
+ * These are the canonical prompt fragments that instruct an LLM how to call
1364
+ * the render_a2ui tool, how to bind data, and how to style surfaces.
1365
+ */
1366
+ /**
1367
+ * Generation guidelines — protocol rules, tool arguments, path rules,
1368
+ * data model format, and form/two-way-binding instructions.
1369
+ */
1370
+ const A2UI_DEFAULT_GENERATION_GUIDELINES = `\
1371
+ Generate A2UI v0.9 JSON.
1372
+
1373
+ ## A2UI Protocol Instructions
1374
+
1375
+ A2UI (Agent to UI) is a protocol for rendering rich UI surfaces from agent responses.
1376
+
1377
+ CRITICAL: You MUST call the render_a2ui tool with ALL of these arguments:
1378
+ - surfaceId: A unique ID for the surface (e.g. "product-comparison")
1379
+ - components: REQUIRED — the A2UI component array. NEVER omit this. Only use
1380
+ components listed in the Available Components schema provided as context.
1381
+ - data: OPTIONAL — a JSON object written to the root of the surface data model.
1382
+ Use for pre-filling form values or providing data for path-bound components.
1383
+ - every component must have the "component" field specifying the component type.
1384
+ ONLY use component names from the Available Components schema — do NOT invent
1385
+ component names or use names not in the schema.
1386
+
1387
+ COMPONENT ID RULES:
1388
+ - Every component ID must be unique within the surface.
1389
+ - A component MUST NOT reference itself as child/children. This causes a
1390
+ circular dependency error. For example, if a component has id="avatar",
1391
+ its child must be a DIFFERENT id (e.g. "avatar-img"), never "avatar".
1392
+ - The child/children tree must be a DAG — no cycles allowed.
1393
+
1394
+ REPEATING CONTENT (TEMPLATES):
1395
+ To repeat a component for each item in an array, use the structural children format:
1396
+ children: { componentId: "card-id", path: "/items" }
1397
+ This tells the renderer to create one instance of "card-id" per item in the "/items" array.
1398
+
1399
+ PATH RULES FOR TEMPLATES:
1400
+ Components inside a repeating template use RELATIVE paths (no leading slash).
1401
+ The path is resolved relative to each array item automatically.
1402
+ If a container has children: { componentId: "card", path: "/items" } and each item
1403
+ has a key "name", use { "path": "name" } (NO leading slash — relative to item).
1404
+ CRITICAL: Do NOT use "/name" (absolute) inside templates — use "name" (relative).
1405
+ The container's path ("/items") uses a leading slash (absolute), but all
1406
+ components INSIDE the template use paths WITHOUT leading slash.
1407
+
1408
+ DATA MODEL:
1409
+ The "data" key in the tool args is a plain JSON object that initializes the surface
1410
+ data model. Components bound to paths (e.g. "value": { "path": "/form/name" })
1411
+ read from and write to this data model. Examples:
1412
+ For forms: "data": { "form": { "name": "Alice", "email": "" } }
1413
+ For lists: "data": { "items": [{"name": "Product A"}, {"name": "Product B"}] }
1414
+ For mixed: "data": { "form": { "query": "" }, "results": [...] }
1415
+
1416
+ FORMS AND TWO-WAY DATA BINDING:
1417
+ To create editable forms, bind input components to data model paths using { "path": "..." }.
1418
+ The client automatically writes user input back to the data model at the bound path.
1419
+ CRITICAL: Using a literal value (e.g. "value": "") makes the field READ-ONLY.
1420
+ You MUST use { "path": "..." } to make inputs editable.
1421
+
1422
+ Input components use "value" as the binding property:
1423
+ "value": { "path": "/form/fieldName" }
1424
+
1425
+ To retrieve form values when a button is clicked, include "context" with path references
1426
+ in the button's action. Paths are resolved to their current values at click time:
1427
+ "action": { "event": { "name": "submit", "context": { "userName": { "path": "/form/name" } } } }
1428
+
1429
+ To pre-fill form values, pass initial data via the "data" tool argument:
1430
+ "data": { "form": { "name": "Markus" } }`;
1431
+ /**
1432
+ * Design guidelines — visual design rules, component hierarchy tips,
1433
+ * and action handler patterns.
1434
+ */
1435
+ const A2UI_DEFAULT_DESIGN_GUIDELINES = `\
1436
+ Create polished, visually appealing interfaces. ONLY use components listed in the
1437
+ Available Components schema — do NOT use component names that are not in the schema.
1438
+
1439
+ Design principles:
1440
+ - Create clear visual hierarchy within cards and layouts.
1441
+ - Keep cards clean — avoid clutter. Whitespace is good.
1442
+ - Use consistent surfaceIds (lowercase, hyphenated).
1443
+ - NEVER use the same ID for a component and its child — this creates a
1444
+ circular dependency. E.g. if id="avatar", child must NOT be "avatar".
1445
+ - For side-by-side comparisons, use a container with structural children
1446
+ (children: { componentId, path }) to repeat a card template per data item.
1447
+ - Include images when relevant (logos, icons, product photos):
1448
+ - Prefer company logos via Google favicons: https://www.google.com/s2/favicons?domain=example.com&sz=128
1449
+ - Do NOT invent Unsplash photo-IDs — they will 404. Only use real, known URLs.
1450
+ - For buttons: action MUST use this exact nested format:
1451
+ "action": { "event": { "name": "myAction", "context": { "key": "value" } } }
1452
+ The "event" key holds an OBJECT with "name" (required) and "context" (optional).
1453
+ Do NOT use a flat format like {"event": "name"} — "event" must be an object.
1454
+ - For forms: every input MUST use path binding on the "value" property
1455
+ (e.g. "value": { "path": "/form/name" }) to be editable. The submit button's
1456
+ action context MUST reference the same paths to capture the user's input.
1457
+
1458
+ Use the SAME surfaceId as the main surface. Match action names to button action event names.`;
1459
+
1229
1460
  //#endregion
1230
1461
  //#region src/index.ts
1231
1462
  const COPILOTKIT_VERSION = version;
1463
+ /**
1464
+ * Client-safe license context factory.
1465
+ *
1466
+ * When status is null (no token provided), all features return true
1467
+ * (unlicensed = unrestricted, with branding). This is inlined here to
1468
+ * avoid importing the full license-verifier bundle (which depends on
1469
+ * Node's `crypto`) into browser bundles.
1470
+ */
1471
+ function createLicenseContextValue(status) {
1472
+ return {
1473
+ status: null,
1474
+ license: null,
1475
+ checkFeature: () => true,
1476
+ getLimit: () => null
1477
+ };
1478
+ }
1232
1479
 
1233
1480
  //#endregion
1481
+ exports.A2UI_DEFAULT_DESIGN_GUIDELINES = A2UI_DEFAULT_DESIGN_GUIDELINES;
1482
+ exports.A2UI_DEFAULT_GENERATION_GUIDELINES = A2UI_DEFAULT_GENERATION_GUIDELINES;
1234
1483
  exports.AG_UI_CHANNEL_EVENT = AG_UI_CHANNEL_EVENT;
1235
1484
  exports.BANNER_ERROR_NAMES = BANNER_ERROR_NAMES;
1236
1485
  exports.COPILOTKIT_VERSION = COPILOTKIT_VERSION;
@@ -1265,11 +1514,18 @@ exports.TranscriptionErrors = TranscriptionErrors;
1265
1514
  exports.UpgradeRequiredError = UpgradeRequiredError;
1266
1515
  exports.actionParametersToJsonSchema = actionParametersToJsonSchema;
1267
1516
  exports.convertJsonSchemaToZodSchema = convertJsonSchemaToZodSchema;
1517
+ exports.createLicenseContextValue = createLicenseContextValue;
1268
1518
  exports.dataToUUID = dataToUUID;
1269
1519
  exports.ensureStructuredError = ensureStructuredError;
1520
+ exports.exceedsMaxSize = exceedsMaxSize;
1270
1521
  exports.executeConditions = executeConditions;
1271
1522
  exports.finalizeRunEvents = finalizeRunEvents;
1523
+ exports.formatFileSize = formatFileSize;
1524
+ exports.generateVideoThumbnail = generateVideoThumbnail;
1525
+ exports.getDocumentIcon = getDocumentIcon;
1526
+ exports.getModalityFromMimeType = getModalityFromMimeType;
1272
1527
  exports.getPossibleVersionMismatch = getPossibleVersionMismatch;
1528
+ exports.getSourceUrl = getSourceUrl;
1273
1529
  exports.getZodParameters = getZodParameters;
1274
1530
  exports.isMacOS = isMacOS;
1275
1531
  exports.isStructuredCopilotKitError = isStructuredCopilotKitError;
@@ -1279,6 +1535,7 @@ exports.jsonSchemaToActionParameters = jsonSchemaToActionParameters;
1279
1535
  exports.logCopilotKitPlatformMessage = logCopilotKitPlatformMessage;
1280
1536
  exports.logStyled = logStyled;
1281
1537
  exports.logger = logger;
1538
+ exports.matchesAcceptFilter = matchesAcceptFilter;
1282
1539
  exports.parseJson = parseJson;
1283
1540
  exports.partialJSONParse = partialJSONParse;
1284
1541
  exports.phoenixExponentialBackoff = phoenixExponentialBackoff;
@@ -1286,17 +1543,10 @@ exports.publicApiKeyRequired = publicApiKeyRequired;
1286
1543
  exports.randomId = randomId;
1287
1544
  exports.randomUUID = randomUUID;
1288
1545
  exports.readBody = readBody;
1546
+ exports.readFileAsBase64 = readFileAsBase64;
1289
1547
  exports.safeParseToolArgs = safeParseToolArgs;
1290
1548
  exports.schemaToJsonSchema = schemaToJsonSchema;
1291
1549
  exports.styledConsole = styledConsole;
1292
1550
  exports.tryMap = tryMap;
1293
- var _copilotkit_license_verifier = require("@copilotkit/license-verifier");
1294
- Object.keys(_copilotkit_license_verifier).forEach(function (k) {
1295
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1296
- enumerable: true,
1297
- get: function () { return _copilotkit_license_verifier[k]; }
1298
- });
1299
- });
1300
-
1301
1551
  });
1302
1552
  //# sourceMappingURL=index.umd.js.map