@player-ui/reference-assets-plugin 0.15.3 → 0.15.4--canary.881.37421

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.
@@ -204,6 +204,12 @@ var import_meta_plugin = require("@player-ui/meta-plugin");
204
204
  var import_async_node_plugin2 = require("@player-ui/async-node-plugin");
205
205
  var import_player = require("@player-ui/player");
206
206
  var import_expression_plugin = require("@player-ui/expression-plugin");
207
+ var isInChatDemo = (node) => {
208
+ if (node.parent?.parent?.type === import_player.NodeType.View && node.parent.parent.value.id === "chat-view") {
209
+ return true;
210
+ }
211
+ return node.parent?.parent?.type === import_player.NodeType.Asset && node.parent.parent.value.id.startsWith("collection-async-chat-demo");
212
+ };
207
213
  var createContentFromMessage = (message, id) => ({
208
214
  asset: {
209
215
  type: "chat-message",
@@ -217,6 +223,23 @@ var createContentFromMessage = (message, id) => ({
217
223
  }
218
224
  }
219
225
  });
226
+ var createBrokenRenderContent = (id) => ({
227
+ asset: {
228
+ id,
229
+ type: "input",
230
+ binding: "binding",
231
+ label: 100
232
+ }
233
+ });
234
+ var createBrokenTransformContent = (id) => ({
235
+ asset: {
236
+ id,
237
+ type: "input",
238
+ binding: {
239
+ prop: "value"
240
+ }
241
+ }
242
+ });
220
243
  var ChatUiDemoPlugin = class {
221
244
  constructor() {
222
245
  this.name = "chat-ui-demo-plugin";
@@ -234,7 +257,7 @@ var ChatUiDemoPlugin = class {
234
257
  let deferredPromises = {};
235
258
  let allPromiseKeys = [];
236
259
  let counter = 0;
237
- const sendMessage = (context, message, nodeId) => {
260
+ const sendMessage = (context, nodeId, getContent) => {
238
261
  if (nodeId && !(nodeId in deferredPromises)) {
239
262
  context.logger?.warn(
240
263
  `'send' expression called with unrecognized id '${nodeId}'`
@@ -247,12 +270,8 @@ var ChatUiDemoPlugin = class {
247
270
  }
248
271
  const keys = nodeId ? [nodeId] : allPromiseKeys;
249
272
  for (const id of keys) {
250
- const content = createContentFromMessage(
251
- message,
252
- `chat-demo-${counter++}`
253
- );
254
273
  const resolveFunction = deferredPromises[id];
255
- resolveFunction?.(content);
274
+ resolveFunction?.(getContent?.());
256
275
  delete deferredPromises[id];
257
276
  }
258
277
  if (nodeId) {
@@ -263,7 +282,7 @@ var ChatUiDemoPlugin = class {
263
282
  }
264
283
  };
265
284
  asyncNodePlugin.hooks.onAsyncNode.tap(this.name, (node) => {
266
- if (node.parent?.parent?.type !== import_player.NodeType.Asset && node.parent?.parent?.type !== import_player.NodeType.View || !node.parent.parent.value.id.startsWith("collection-async-chat-demo")) {
285
+ if (!isInChatDemo(node)) {
267
286
  return Promise.resolve(void 0);
268
287
  }
269
288
  return new Promise((res) => {
@@ -271,13 +290,38 @@ var ChatUiDemoPlugin = class {
271
290
  allPromiseKeys.push(node.id);
272
291
  });
273
292
  });
293
+ const sendRealMessage = (context, message, nodeId) => {
294
+ return sendMessage(
295
+ context,
296
+ nodeId,
297
+ () => createContentFromMessage(message, `chat-demo-${counter++}`)
298
+ );
299
+ };
300
+ const sendBrokenMessage = (context, _, nodeId) => {
301
+ return sendMessage(
302
+ context,
303
+ nodeId,
304
+ () => createBrokenRenderContent(`chat-demo-${counter++}`)
305
+ );
306
+ };
307
+ const sendBrokenTransformMessage = (context, _, nodeId) => {
308
+ return sendMessage(
309
+ context,
310
+ nodeId,
311
+ () => createBrokenTransformContent(`chat-demo-${counter++}`)
312
+ );
313
+ };
274
314
  player.hooks.view.tap(this.name, (_) => {
275
315
  deferredPromises = {};
276
316
  allPromiseKeys = [];
277
317
  counter = 0;
278
318
  });
279
319
  const expressionPlugin = new import_expression_plugin.ExpressionPlugin(
280
- /* @__PURE__ */ new Map([["send", sendMessage]])
320
+ /* @__PURE__ */ new Map([
321
+ ["send", sendRealMessage],
322
+ ["sendBroken", sendBrokenMessage],
323
+ ["sendBrokenTransform", sendBrokenTransformMessage]
324
+ ])
281
325
  );
282
326
  player.registerPlugin(expressionPlugin);
283
327
  }
@@ -304,16 +348,61 @@ var ReferenceAssetsTransformPlugin = class {
304
348
  };
305
349
 
306
350
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugin.ts
351
+ var import_async_node_plugin4 = require("@player-ui/async-node-plugin");
352
+
353
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugins/error-recovery-plugin.ts
307
354
  var import_async_node_plugin3 = require("@player-ui/async-node-plugin");
355
+ var ErrorRecoveryPlugin = class {
356
+ constructor() {
357
+ this.name = "ErrorRecoveryPlugin";
358
+ }
359
+ /** */
360
+ apply(player) {
361
+ player.applyTo(import_async_node_plugin3.AsyncNodePlugin.Symbol, (plugin) => {
362
+ plugin.hooks.onAsyncNodeError.tap(this.name, (err, node) => {
363
+ const playerState = player.getState();
364
+ if (playerState.status !== "in-progress") {
365
+ return;
366
+ }
367
+ const viewId = playerState.controllers.view.currentView?.initialView.id;
368
+ if (viewId !== "chat-view") {
369
+ return;
370
+ }
371
+ return {
372
+ asset: {
373
+ type: "chat-message",
374
+ id: `${node.id}-recovery`,
375
+ value: {
376
+ asset: {
377
+ id: `${node.id}-recovery-text`,
378
+ type: "text",
379
+ value: "Something went wrong, please try again."
380
+ }
381
+ }
382
+ }
383
+ };
384
+ });
385
+ });
386
+ }
387
+ };
388
+
389
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugin.ts
390
+ var import_common_types_plugin = require("@player-ui/common-types-plugin");
391
+ var import_common_expressions_plugin = require("@player-ui/common-expressions-plugin");
392
+ var import_computed_properties_plugin = require("@player-ui/computed-properties-plugin");
308
393
  var ReferenceAssetsPlugin = class {
309
394
  constructor() {
310
395
  this.name = "reference-assets-plugin";
311
396
  this.metaPlugin = new import_meta_plugin.MetaPlugin([
312
- new import_async_node_plugin3.AsyncNodePlugin({
313
- plugins: [new import_async_node_plugin3.AsyncNodePluginPlugin()]
397
+ new import_common_types_plugin.CommonTypesPlugin(),
398
+ new import_common_expressions_plugin.CommonExpressionsPlugin(),
399
+ new import_computed_properties_plugin.ComputedPropertiesPlugin(),
400
+ new import_async_node_plugin4.AsyncNodePlugin({
401
+ plugins: [new import_async_node_plugin4.AsyncNodePluginPlugin()]
314
402
  }),
315
403
  new ReferenceAssetsTransformPlugin(),
316
- new ChatUiDemoPlugin()
404
+ new ChatUiDemoPlugin(),
405
+ new ErrorRecoveryPlugin()
317
406
  ]);
318
407
  }
319
408
  apply(player) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/index.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/input/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/action/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/info/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/image/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/choice/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/chat-message/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugin.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugins/chat-ui-demo-plugin.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugins/reference-assets-transform-plugin.ts"],"sourcesContent":["export * from \"./assets\";\nexport * from \"./plugin\";\n","import type { TransformFunction } from \"@player-ui/player\";\nimport type { InputAsset, TransformedInput } from \"./types\";\n\n/**\n * Docs about the asset transform\n */\nexport const inputTransform: TransformFunction<InputAsset, TransformedInput> = (\n asset,\n options,\n) => {\n return {\n ...asset,\n format(val) {\n if (asset.binding === undefined) {\n return val;\n }\n\n return options.data.format(asset.binding, val);\n },\n set(val) {\n if (asset.binding === undefined) {\n return;\n }\n\n return options.data.model.set([[asset.binding, val]], {\n formatted: true,\n });\n },\n value:\n asset.binding === undefined\n ? \"\"\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: true,\n }),\n validation:\n asset.binding === undefined\n ? undefined\n : options.validation?.get(asset.binding, { track: true }),\n dataType:\n asset.binding === undefined\n ? undefined\n : options.validation?.type(asset.binding),\n };\n};\n","import type {\n Asset,\n TransformFunction,\n BeforeTransformFunction,\n} from \"@player-ui/player\";\nimport { compose, composeBefore } from \"@player-ui/asset-transform-plugin\";\nimport type { ActionAsset, TransformedAction } from \"./types\";\n\n/**\n * Function to find prev button\n */\nexport function isBackAction(action: ActionAsset): boolean {\n return action.value === \"Prev\";\n}\n\n/**\n * Attaches the methods to execute an action to an action\n */\nconst transform: TransformFunction<ActionAsset, TransformedAction> = (\n action,\n options,\n) => {\n return {\n ...action,\n run() {\n if (action.exp) {\n options.evaluate(action.exp);\n }\n\n if (action.value) {\n const skipValidation = action.metaData?.skipValidation;\n options.transition?.(action.value, { force: skipValidation });\n }\n },\n };\n};\n\n/**\n * De couples back button from the back icon\n */\nconst backIconTransform: TransformFunction<ActionAsset, ActionAsset> = (\n action,\n) => {\n /** For previous versions of player, the back button would already have the back icon.\n * This ensures that the old functionality does not break and back button is still visible when they update the player.\n */\n if (isBackAction(action) && action?.metaData?.role === undefined) {\n return {\n ...action,\n metaData: {\n ...action?.metaData,\n role: \"back\",\n },\n };\n }\n\n return action;\n};\n\n/**\n * Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist\n *\n * @param asset - Asset to apply the transform to\n */\nexport const expPropTransform: BeforeTransformFunction<Asset> = (asset) => {\n const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;\n\n if (skipArray && skipArray.indexOf(\"exp\") > 1) {\n return asset;\n }\n\n return {\n ...asset,\n plugins: {\n ...asset.plugins,\n stringResolver: {\n ...asset?.plugins?.stringResolver,\n propertiesToSkip: [\n ...(asset.plugins?.stringResolver?.propertiesToSkip ?? []),\n \"exp\",\n ],\n },\n },\n };\n};\n\nexport const actionTransform = compose(\n transform,\n backIconTransform,\n composeBefore(expPropTransform),\n);\n","import type { TransformFunction } from \"@player-ui/player\";\nimport type { AssetWrapper } from \"@player-ui/player\";\nimport type { InfoAsset, InfoAssetTransform } from \"./types\";\nimport type { ActionAsset } from \"../action/types\";\nimport { isBackAction } from \"../action/transform\";\n\n/**\n * This transform should add segmentedActions to the info asset.\n * Segmented actions display side by side in larger viewports. Segmented Actions is an object of next and prev actions\n */\nexport const infoTransform: TransformFunction<InfoAsset, InfoAssetTransform> = (\n infoAsset,\n) => {\n const actions = infoAsset?.actions;\n const segmentedActions = actions?.reduce(\n (segmentedActionsArray, action) => {\n segmentedActionsArray[\n isBackAction(action.asset as ActionAsset) ? \"prev\" : \"next\"\n ].push(action as AssetWrapper<ActionAsset>);\n return segmentedActionsArray;\n },\n { next: [], prev: [] } as {\n /**\n * next is an array of next actions\n */\n next: Array<AssetWrapper<ActionAsset>>;\n /**\n * prev is an array of prev actions\n */\n prev: Array<AssetWrapper<ActionAsset>>;\n },\n );\n\n return {\n ...infoAsset,\n segmentedActions,\n };\n};\n","import type { TransformFunction } from \"@player-ui/player\";\nimport type { ImageAsset, TransformedImage } from \"./types\";\n\n/**\n * Function to retrieve the desired alt text based on passed in props.\n * @param props Image props\n * @returns The alt text for the image asset\n */\nconst getImageAlt = (props: ImageAsset): string => {\n const { metaData, placeholder } = props;\n if (metaData.accessibility) return metaData.accessibility;\n\n if (placeholder) return placeholder;\n\n return \"Image\";\n};\n\n/**\n * Sets the Image's placeholder and accessibilty\n */\nexport const imageTransform: TransformFunction<ImageAsset, TransformedImage> = (\n props,\n) => {\n const altText = getImageAlt(props);\n\n const newImage = {\n ...props,\n altText,\n };\n\n return newImage;\n};\n","import type { TransformFunction } from \"@player-ui/player\";\nimport type {\n ChoiceAsset,\n TransformedChoice,\n TransformedChoiceItem,\n} from \"./types\";\n\n/**\n * Docs about the asset transform\n */\nexport const choiceTransform: TransformFunction<\n ChoiceAsset,\n TransformedChoice\n> = (asset, options) => {\n const { items, binding, ...rest } = asset;\n\n const assetHasBinding = binding !== undefined;\n\n const currentValue = assetHasBinding\n ? options.data.model.get(binding, {\n includeInvalid: true,\n })\n : undefined;\n\n const resetValue = () => {\n if (assetHasBinding) {\n return options.data.model.set([[binding, null]]);\n }\n };\n\n const transformedChoiceItems: TransformedChoiceItem[] = (items || []).map(\n (item, index) => ({\n ...item,\n id: item.id ?? `${asset.id}-choice-${index}`,\n select() {\n if (assetHasBinding) {\n return options.data.model.set([[binding, item.value]]);\n }\n },\n unselect: resetValue,\n }),\n );\n\n return {\n ...rest,\n binding,\n clearSelection: resetValue,\n items: transformedChoiceItems,\n value: currentValue,\n validation: assetHasBinding\n ? options.validation?.get(binding, { track: true })\n : undefined,\n dataType: assetHasBinding ? options.validation?.type(binding) : undefined,\n };\n};\n","import type {\n BeforeTransformFunction,\n TransformFunctions,\n} from \"@player-ui/player\";\nimport { composeBefore, compose } from \"@player-ui/asset-transform-plugin\";\nimport { createAsyncTransform } from \"@player-ui/async-node-plugin\";\nimport { ChatMessageAsset } from \"./types\";\n/**\n * In beforeTransform function, pass in flatten marker and call beforeResolve function.\n * Flatten default value is true.\n * input: ChatMessageAsset\n * @param asset - Asset to apply the transform to\n * @returns - transformed asset with async node and asset node\n */\nexport const transform: BeforeTransformFunction<ChatMessageAsset> =\n createAsyncTransform({\n transformAssetType: \"chat-message\",\n wrapperAssetType: \"collection\",\n getNestedAsset: (node) => node.children?.[0]?.value,\n });\n\nexport const chatMessageTransform: TransformFunctions = compose(\n composeBefore(transform),\n);\n","import type { Player, PlayerPlugin } from \"@player-ui/player\";\nimport { MetaPlugin } from \"@player-ui/meta-plugin\";\nimport { ChatUiDemoPlugin, ReferenceAssetsTransformPlugin } from \"./plugins\";\nimport {\n AsyncNodePlugin,\n AsyncNodePluginPlugin,\n} from \"@player-ui/async-node-plugin\";\n\n/**\n * A plugin to add transforms for the reference assets\n */\nexport class ReferenceAssetsPlugin implements PlayerPlugin {\n name = \"reference-assets-plugin\";\n\n private readonly metaPlugin = new MetaPlugin([\n new AsyncNodePlugin({\n plugins: [new AsyncNodePluginPlugin()],\n }),\n new ReferenceAssetsTransformPlugin(),\n new ChatUiDemoPlugin(),\n ]);\n\n apply(player: Player): void {\n player.registerPlugin(this.metaPlugin);\n }\n}\n","import { AsyncNodePlugin } from \"@player-ui/async-node-plugin\";\nimport {\n ExpressionContext,\n ExtendedPlayerPlugin,\n NodeType,\n Player,\n} from \"@player-ui/player\";\nimport { ExpressionPlugin } from \"@player-ui/expression-plugin\";\nimport { send } from \"./send\";\n\nconst createContentFromMessage = (message: string, id: string): any => ({\n asset: {\n type: \"chat-message\",\n id,\n value: {\n asset: {\n type: \"text\",\n id: `${id}-value`,\n value: message,\n },\n },\n },\n});\n\nexport class ChatUiDemoPlugin implements ExtendedPlayerPlugin<[], [], [send]> {\n public readonly name = \"chat-ui-demo-plugin\";\n\n public apply(player: Player): void {\n const asyncNodePlugin = player.findPlugin<AsyncNodePlugin>(\n AsyncNodePlugin.Symbol,\n );\n\n if (!asyncNodePlugin) {\n player.logger.warn(\n `Failed to apply '${this.name}'. Reason: Could not find AsyncNodePlugin.`,\n );\n return;\n }\n\n let deferredPromises: Record<string, (val: string) => void> = {};\n let allPromiseKeys: string[] = [];\n let counter = 0;\n\n const sendMessage: send = (\n context: ExpressionContext,\n message: string,\n nodeId?: string,\n ): void => {\n if (nodeId && !(nodeId in deferredPromises)) {\n context.logger?.warn(\n `'send' expression called with unrecognized id '${nodeId}'`,\n );\n return;\n }\n\n if (!nodeId && allPromiseKeys.length === 0) {\n context.logger?.warn(`'send' called with no waiting async nodes`);\n return;\n }\n\n // Either resolve the node by the id or resolve all of them if no id provided\n const keys = nodeId ? [nodeId] : allPromiseKeys;\n\n for (const id of keys) {\n const content = createContentFromMessage(\n message,\n `chat-demo-${counter++}`,\n );\n const resolveFunction = deferredPromises[id];\n resolveFunction?.(content);\n delete deferredPromises[id];\n }\n\n if (nodeId) {\n const index = allPromiseKeys.indexOf(nodeId);\n allPromiseKeys.splice(index, 1);\n } else {\n allPromiseKeys = [];\n }\n };\n\n asyncNodePlugin.hooks.onAsyncNode.tap(this.name, (node) => {\n // Ensure this is only used on the chat-ui.tsx mock to prevent the promise from setting up during tests.\n if (\n (node.parent?.parent?.type !== NodeType.Asset &&\n node.parent?.parent?.type !== NodeType.View) ||\n !node.parent.parent.value.id.startsWith(\"collection-async-chat-demo\")\n ) {\n return Promise.resolve(undefined);\n }\n\n return new Promise((res) => {\n deferredPromises[node.id] = res;\n allPromiseKeys.push(node.id);\n });\n });\n\n // Reset at the start of a new view.\n player.hooks.view.tap(this.name, (_) => {\n deferredPromises = {};\n allPromiseKeys = [];\n counter = 0;\n });\n\n // Register 'send' expression\n const expressionPlugin = new ExpressionPlugin(\n new Map([[\"send\", sendMessage]]),\n );\n player.registerPlugin(expressionPlugin);\n }\n}\n","import type { ExtendedPlayerPlugin, Player } from \"@player-ui/player\";\nimport { AssetTransformPlugin } from \"@player-ui/asset-transform-plugin\";\nimport {\n actionTransform,\n chatMessageTransform,\n choiceTransform,\n imageTransform,\n infoTransform,\n inputTransform,\n} from \"../assets\";\nimport type {\n ActionAsset,\n ChatMessageAsset,\n ChoiceAsset,\n CollectionAsset,\n ImageAsset,\n InfoAsset,\n InputAsset,\n TextAsset,\n} from \"../assets\";\n\nexport class ReferenceAssetsTransformPlugin implements ExtendedPlayerPlugin<\n [\n ActionAsset,\n InputAsset,\n ImageAsset,\n TextAsset,\n CollectionAsset,\n ChoiceAsset,\n ChatMessageAsset,\n ],\n [InfoAsset]\n> {\n name = \"reference-assets-transforms\";\n\n apply(player: Player): void {\n player.registerPlugin(\n new AssetTransformPlugin([\n [{ type: \"action\" }, actionTransform],\n [{ type: \"input\" }, inputTransform],\n [{ type: \"image\" }, imageTransform],\n [{ type: \"info\" }, infoTransform],\n [{ type: \"choice\" }, choiceTransform],\n [{ type: \"chat-message\" }, chatMessageTransform],\n ]),\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAAA;AAAA;AAAA;;;ACMO,IAAM,iBAAkE,CAC7E,OACA,YACG;AACH,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,KAAK;AACV,UAAI,MAAM,YAAY,QAAW;AAC/B,eAAO;AAAA,MACT;AAEA,aAAO,QAAQ,KAAK,OAAO,MAAM,SAAS,GAAG;AAAA,IAC/C;AAAA,IACA,IAAI,KAAK;AACP,UAAI,MAAM,YAAY,QAAW;AAC/B;AAAA,MACF;AAEA,aAAO,QAAQ,KAAK,MAAM,IAAI,CAAC,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG;AAAA,QACpD,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,IACA,OACE,MAAM,YAAY,SACd,KACA,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC;AAAA,IACP,YACE,MAAM,YAAY,SACd,SACA,QAAQ,YAAY,IAAI,MAAM,SAAS,EAAE,OAAO,KAAK,CAAC;AAAA,IAC5D,UACE,MAAM,YAAY,SACd,SACA,QAAQ,YAAY,KAAK,MAAM,OAAO;AAAA,EAC9C;AACF;;;ACvCA,oCAAuC;AAMhC,SAAS,aAAa,QAA8B;AACzD,SAAO,OAAO,UAAU;AAC1B;AAKA,IAAM,YAA+D,CACnE,QACA,YACG;AACH,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AACJ,UAAI,OAAO,KAAK;AACd,gBAAQ,SAAS,OAAO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,SAAS,GAAG,eAAe;AAAA,QACpC,CAAC,EAAE,MAAM,eAAe,GAAG,oBAAoB;AAAA,MACjD,CAAC;AAAA,IACH;AAAA,EACF;AACF;;;AF5CA,IAAAC,4BAGO;AAKA,IAAM,wBAAN,MAAoD;AAAA,EAApD;AACL,gBAAO;AAEP,SAAiB,aAAa,IAAI,8BAAW;AAAA,MAC3C,IAAI,0CAAgB;AAAA,QAClB,SAAS,CAAC,IAAI,gDAAsB,CAAC;AAAA,MACvC,CAAC;AAAA,MACD,IAAI,+BAA+B;AAAA,MACnC,IAAI,iBAAiB;AAAA,IACvB,CAAC;AAAA;AAAA,EAED,MAAM,QAAsB;AAC1B,WAAO,eAAe,KAAK,UAAU;AAAA,EACvC;AACF;","names":["transform","import_asset_transform_plugin","transform","import_async_node_plugin","import_asset_transform_plugin","import_async_node_plugin"]}
1
+ {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/index.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/input/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/action/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/info/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/image/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/choice/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/chat-message/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugin.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugins/chat-ui-demo-plugin.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugins/reference-assets-transform-plugin.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugins/error-recovery-plugin.ts"],"sourcesContent":["export * from \"./assets\";\nexport * from \"./plugin\";\n","import type { TransformFunction } from \"@player-ui/player\";\nimport type { InputAsset, TransformedInput } from \"./types\";\n\n/**\n * Docs about the asset transform\n */\nexport const inputTransform: TransformFunction<InputAsset, TransformedInput> = (\n asset,\n options,\n) => {\n return {\n ...asset,\n format(val) {\n if (asset.binding === undefined) {\n return val;\n }\n\n return options.data.format(asset.binding, val);\n },\n set(val) {\n if (asset.binding === undefined) {\n return;\n }\n\n return options.data.model.set([[asset.binding, val]], {\n formatted: true,\n });\n },\n value:\n asset.binding === undefined\n ? \"\"\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: true,\n }),\n validation:\n asset.binding === undefined\n ? undefined\n : options.validation?.get(asset.binding, { track: true }),\n dataType:\n asset.binding === undefined\n ? undefined\n : options.validation?.type(asset.binding),\n };\n};\n","import type {\n Asset,\n TransformFunction,\n BeforeTransformFunction,\n} from \"@player-ui/player\";\nimport { compose, composeBefore } from \"@player-ui/asset-transform-plugin\";\nimport type { ActionAsset, TransformedAction } from \"./types\";\n\n/**\n * Function to find prev button\n */\nexport function isBackAction(action: ActionAsset): boolean {\n return action.value === \"Prev\";\n}\n\n/**\n * Attaches the methods to execute an action to an action\n */\nconst transform: TransformFunction<ActionAsset, TransformedAction> = (\n action,\n options,\n) => {\n return {\n ...action,\n run() {\n if (action.exp) {\n options.evaluate(action.exp);\n }\n\n if (action.value) {\n const skipValidation = action.metaData?.skipValidation;\n options.transition?.(action.value, { force: skipValidation });\n }\n },\n };\n};\n\n/**\n * De couples back button from the back icon\n */\nconst backIconTransform: TransformFunction<ActionAsset, ActionAsset> = (\n action,\n) => {\n /** For previous versions of player, the back button would already have the back icon.\n * This ensures that the old functionality does not break and back button is still visible when they update the player.\n */\n if (isBackAction(action) && action?.metaData?.role === undefined) {\n return {\n ...action,\n metaData: {\n ...action?.metaData,\n role: \"back\",\n },\n };\n }\n\n return action;\n};\n\n/**\n * Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist\n *\n * @param asset - Asset to apply the transform to\n */\nexport const expPropTransform: BeforeTransformFunction<Asset> = (asset) => {\n const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;\n\n if (skipArray && skipArray.indexOf(\"exp\") > 1) {\n return asset;\n }\n\n return {\n ...asset,\n plugins: {\n ...asset.plugins,\n stringResolver: {\n ...asset?.plugins?.stringResolver,\n propertiesToSkip: [\n ...(asset.plugins?.stringResolver?.propertiesToSkip ?? []),\n \"exp\",\n ],\n },\n },\n };\n};\n\nexport const actionTransform = compose(\n transform,\n backIconTransform,\n composeBefore(expPropTransform),\n);\n","import type { TransformFunction } from \"@player-ui/player\";\nimport type { AssetWrapper } from \"@player-ui/player\";\nimport type { InfoAsset, InfoAssetTransform } from \"./types\";\nimport type { ActionAsset } from \"../action/types\";\nimport { isBackAction } from \"../action/transform\";\n\n/**\n * This transform should add segmentedActions to the info asset.\n * Segmented actions display side by side in larger viewports. Segmented Actions is an object of next and prev actions\n */\nexport const infoTransform: TransformFunction<InfoAsset, InfoAssetTransform> = (\n infoAsset,\n) => {\n const actions = infoAsset?.actions;\n const segmentedActions = actions?.reduce(\n (segmentedActionsArray, action) => {\n segmentedActionsArray[\n isBackAction(action.asset as ActionAsset) ? \"prev\" : \"next\"\n ].push(action as AssetWrapper<ActionAsset>);\n return segmentedActionsArray;\n },\n { next: [], prev: [] } as {\n /**\n * next is an array of next actions\n */\n next: Array<AssetWrapper<ActionAsset>>;\n /**\n * prev is an array of prev actions\n */\n prev: Array<AssetWrapper<ActionAsset>>;\n },\n );\n\n return {\n ...infoAsset,\n segmentedActions,\n };\n};\n","import type { TransformFunction } from \"@player-ui/player\";\nimport type { ImageAsset, TransformedImage } from \"./types\";\n\n/**\n * Function to retrieve the desired alt text based on passed in props.\n * @param props Image props\n * @returns The alt text for the image asset\n */\nconst getImageAlt = (props: ImageAsset): string => {\n const { metaData, placeholder } = props;\n if (metaData.accessibility) return metaData.accessibility;\n\n if (placeholder) return placeholder;\n\n return \"Image\";\n};\n\n/**\n * Sets the Image's placeholder and accessibilty\n */\nexport const imageTransform: TransformFunction<ImageAsset, TransformedImage> = (\n props,\n) => {\n const altText = getImageAlt(props);\n\n const newImage = {\n ...props,\n altText,\n };\n\n return newImage;\n};\n","import type { TransformFunction } from \"@player-ui/player\";\nimport type {\n ChoiceAsset,\n TransformedChoice,\n TransformedChoiceItem,\n} from \"./types\";\n\n/**\n * Docs about the asset transform\n */\nexport const choiceTransform: TransformFunction<\n ChoiceAsset,\n TransformedChoice\n> = (asset, options) => {\n const { items, binding, ...rest } = asset;\n\n const assetHasBinding = binding !== undefined;\n\n const currentValue = assetHasBinding\n ? options.data.model.get(binding, {\n includeInvalid: true,\n })\n : undefined;\n\n const resetValue = () => {\n if (assetHasBinding) {\n return options.data.model.set([[binding, null]]);\n }\n };\n\n const transformedChoiceItems: TransformedChoiceItem[] = (items || []).map(\n (item, index) => ({\n ...item,\n id: item.id ?? `${asset.id}-choice-${index}`,\n select() {\n if (assetHasBinding) {\n return options.data.model.set([[binding, item.value]]);\n }\n },\n unselect: resetValue,\n }),\n );\n\n return {\n ...rest,\n binding,\n clearSelection: resetValue,\n items: transformedChoiceItems,\n value: currentValue,\n validation: assetHasBinding\n ? options.validation?.get(binding, { track: true })\n : undefined,\n dataType: assetHasBinding ? options.validation?.type(binding) : undefined,\n };\n};\n","import type {\n BeforeTransformFunction,\n TransformFunctions,\n} from \"@player-ui/player\";\nimport { composeBefore, compose } from \"@player-ui/asset-transform-plugin\";\nimport { createAsyncTransform } from \"@player-ui/async-node-plugin\";\nimport { ChatMessageAsset } from \"./types\";\n/**\n * In beforeTransform function, pass in flatten marker and call beforeResolve function.\n * Flatten default value is true.\n * input: ChatMessageAsset\n * @param asset - Asset to apply the transform to\n * @returns - transformed asset with async node and asset node\n */\nexport const transform: BeforeTransformFunction<ChatMessageAsset> =\n createAsyncTransform({\n transformAssetType: \"chat-message\",\n wrapperAssetType: \"collection\",\n getNestedAsset: (node) => node.children?.[0]?.value,\n });\n\nexport const chatMessageTransform: TransformFunctions = compose(\n composeBefore(transform),\n);\n","import type { Player, PlayerPlugin } from \"@player-ui/player\";\nimport { MetaPlugin } from \"@player-ui/meta-plugin\";\nimport { ChatUiDemoPlugin, ReferenceAssetsTransformPlugin } from \"./plugins\";\nimport {\n AsyncNodePlugin,\n AsyncNodePluginPlugin,\n} from \"@player-ui/async-node-plugin\";\nimport { ErrorRecoveryPlugin } from \"./plugins/error-recovery-plugin\";\nimport { CommonTypesPlugin } from \"@player-ui/common-types-plugin\";\nimport { CommonExpressionsPlugin } from \"@player-ui/common-expressions-plugin\";\nimport { ComputedPropertiesPlugin } from \"@player-ui/computed-properties-plugin\";\n\n/**\n * A plugin to add transforms for the reference assets\n */\nexport class ReferenceAssetsPlugin implements PlayerPlugin {\n name = \"reference-assets-plugin\";\n\n private readonly metaPlugin = new MetaPlugin([\n new CommonTypesPlugin(),\n new CommonExpressionsPlugin(),\n new ComputedPropertiesPlugin(),\n new AsyncNodePlugin({\n plugins: [new AsyncNodePluginPlugin()],\n }),\n new ReferenceAssetsTransformPlugin(),\n new ChatUiDemoPlugin(),\n new ErrorRecoveryPlugin(),\n ]);\n\n apply(player: Player): void {\n player.registerPlugin(this.metaPlugin);\n }\n}\n","import { AsyncNodePlugin } from \"@player-ui/async-node-plugin\";\nimport {\n ExpressionContext,\n ExtendedPlayerPlugin,\n NodeType,\n Player,\n Node,\n} from \"@player-ui/player\";\nimport { ExpressionPlugin } from \"@player-ui/expression-plugin\";\nimport { send } from \"./send\";\n\nconst isInChatDemo = (node: Node.Node) => {\n if (\n node.parent?.parent?.type === NodeType.View &&\n node.parent.parent.value.id === \"chat-view\"\n ) {\n return true;\n }\n\n return (\n node.parent?.parent?.type === NodeType.Asset &&\n node.parent.parent.value.id.startsWith(\"collection-async-chat-demo\")\n );\n};\n\nconst createContentFromMessage = (message: string, id: string): any => ({\n asset: {\n type: \"chat-message\",\n id,\n value: {\n asset: {\n type: \"text\",\n id: `${id}-value`,\n value: message,\n },\n },\n },\n});\n\n/** This content will fail to display its label since it isn't a valid asset */\nconst createBrokenRenderContent = (id: string): any => ({\n asset: {\n id,\n type: \"input\",\n binding: \"binding\",\n label: 100,\n },\n});\n\n/** this content will fail to fetch from the data model since the binding is an object */\nconst createBrokenTransformContent = (id: string): any => ({\n asset: {\n id,\n type: \"input\",\n binding: {\n prop: \"value\",\n },\n },\n});\n\nexport class ChatUiDemoPlugin implements ExtendedPlayerPlugin<[], [], [send]> {\n public readonly name = \"chat-ui-demo-plugin\";\n\n public apply(player: Player): void {\n const asyncNodePlugin = player.findPlugin<AsyncNodePlugin>(\n AsyncNodePlugin.Symbol,\n );\n\n if (!asyncNodePlugin) {\n player.logger.warn(\n `Failed to apply '${this.name}'. Reason: Could not find AsyncNodePlugin.`,\n );\n return;\n }\n\n let deferredPromises: Record<string, (val: string) => void> = {};\n let allPromiseKeys: string[] = [];\n let counter = 0;\n\n const sendMessage = (\n context: ExpressionContext,\n nodeId?: string,\n getContent?: () => any,\n ): void => {\n if (nodeId && !(nodeId in deferredPromises)) {\n context.logger?.warn(\n `'send' expression called with unrecognized id '${nodeId}'`,\n );\n return;\n }\n\n if (!nodeId && allPromiseKeys.length === 0) {\n context.logger?.warn(`'send' called with no waiting async nodes`);\n return;\n }\n\n // Either resolve the node by the id or resolve all of them if no id provided\n const keys = nodeId ? [nodeId] : allPromiseKeys;\n\n for (const id of keys) {\n const resolveFunction = deferredPromises[id];\n resolveFunction?.(getContent?.());\n delete deferredPromises[id];\n }\n\n if (nodeId) {\n const index = allPromiseKeys.indexOf(nodeId);\n allPromiseKeys.splice(index, 1);\n } else {\n allPromiseKeys = [];\n }\n };\n\n asyncNodePlugin.hooks.onAsyncNode.tap(this.name, (node) => {\n // Ensure this is only used on the chat-ui.tsx mock to prevent the promise from setting up during tests.\n if (!isInChatDemo(node)) {\n return Promise.resolve(undefined);\n }\n\n return new Promise((res) => {\n deferredPromises[node.id] = res;\n allPromiseKeys.push(node.id);\n });\n });\n\n const sendRealMessage: send = (\n context: ExpressionContext,\n message: string,\n nodeId?: string,\n ) => {\n return sendMessage(context, nodeId, () =>\n createContentFromMessage(message, `chat-demo-${counter++}`),\n );\n };\n\n /** These expressions are used as examples in the storybook to allow broken content through and show the error recovery fallback pattern. */\n const sendBrokenMessage: send = (\n context: ExpressionContext,\n _: string,\n nodeId?: string,\n ) => {\n return sendMessage(context, nodeId, () =>\n createBrokenRenderContent(`chat-demo-${counter++}`),\n );\n };\n\n const sendBrokenTransformMessage: send = (\n context: ExpressionContext,\n _: string,\n nodeId?: string,\n ) => {\n return sendMessage(context, nodeId, () =>\n createBrokenTransformContent(`chat-demo-${counter++}`),\n );\n };\n\n // Reset at the start of a new view.\n player.hooks.view.tap(this.name, (_) => {\n deferredPromises = {};\n allPromiseKeys = [];\n counter = 0;\n });\n\n // Register 'send' expression\n const expressionPlugin = new ExpressionPlugin(\n new Map([\n [\"send\", sendRealMessage],\n [\"sendBroken\", sendBrokenMessage],\n [\"sendBrokenTransform\", sendBrokenTransformMessage],\n ]),\n );\n player.registerPlugin(expressionPlugin);\n }\n}\n","import type { ExtendedPlayerPlugin, Player } from \"@player-ui/player\";\nimport { AssetTransformPlugin } from \"@player-ui/asset-transform-plugin\";\nimport {\n actionTransform,\n chatMessageTransform,\n choiceTransform,\n imageTransform,\n infoTransform,\n inputTransform,\n} from \"../assets\";\nimport type {\n ActionAsset,\n ChatMessageAsset,\n ChoiceAsset,\n CollectionAsset,\n ImageAsset,\n InfoAsset,\n InputAsset,\n TextAsset,\n} from \"../assets\";\n\nexport class ReferenceAssetsTransformPlugin\n implements\n ExtendedPlayerPlugin<\n [\n ActionAsset,\n InputAsset,\n ImageAsset,\n TextAsset,\n CollectionAsset,\n ChoiceAsset,\n ChatMessageAsset,\n ],\n [InfoAsset]\n >\n{\n name = \"reference-assets-transforms\";\n\n apply(player: Player): void {\n player.registerPlugin(\n new AssetTransformPlugin([\n [{ type: \"action\" }, actionTransform],\n [{ type: \"input\" }, inputTransform],\n [{ type: \"image\" }, imageTransform],\n [{ type: \"info\" }, infoTransform],\n [{ type: \"choice\" }, choiceTransform],\n [{ type: \"chat-message\" }, chatMessageTransform],\n ]),\n );\n }\n}\n","import { AsyncNodePlugin } from \"@player-ui/async-node-plugin\";\nimport { Player, PlayerPlugin } from \"@player-ui/player\";\n\nexport class ErrorRecoveryPlugin implements PlayerPlugin {\n readonly name = \"ErrorRecoveryPlugin\";\n /** */\n apply(player: Player): void {\n player.applyTo<AsyncNodePlugin>(AsyncNodePlugin.Symbol, (plugin) => {\n plugin.hooks.onAsyncNodeError.tap(this.name, (err, node) => {\n const playerState = player.getState();\n if (playerState.status !== \"in-progress\") {\n return;\n }\n\n // Limit error recovery to chat-ui view example to avoid breaking tests.\n const viewId = playerState.controllers.view.currentView?.initialView.id;\n if (viewId !== \"chat-view\") {\n return;\n }\n\n return {\n asset: {\n type: \"chat-message\",\n id: `${node.id}-recovery`,\n value: {\n asset: {\n id: `${node.id}-recovery-text`,\n type: \"text\",\n value: \"Something went wrong, please try again.\",\n },\n },\n },\n };\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAAA;AAAA;AAAA;;;ACMO,IAAM,iBAAkE,CAC7E,OACA,YACG;AACH,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,KAAK;AACV,UAAI,MAAM,YAAY,QAAW;AAC/B,eAAO;AAAA,MACT;AAEA,aAAO,QAAQ,KAAK,OAAO,MAAM,SAAS,GAAG;AAAA,IAC/C;AAAA,IACA,IAAI,KAAK;AACP,UAAI,MAAM,YAA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AAI,8BAAW;AAAA,MAC3C,IAAI,6CAAkB;AAAA,MACtB,IAAI,yDAAwB;AAAA,MAC5B,IAAI,2DAAyB;AAAA,MAC7B,IAAI,0CAAgB;AAAA,QAClB,SAAS,CAAC,IAAI,gDAAsB,CAAC;AAAA,MACvC,CAAC;AAAA,MACD,IAAI,+BAA+B;AAAA,MACnC,IAAI,iBAAiB;AAAA,MACrB,IAAI,oBAAoB;AAAA,IAC1B,CAAC;AAAA;AAAA,EAED,MAAM,QAAsB;AAC1B,WAAO,eAAe,KAAK,UAAU;AAAA,EACvC;AACF;","names":["transform","import_asset_transform_plugin","transform","import_async_node_plugin","import_asset_transform_plugin","import_async_node_plugin","import_async_node_plugin"]}
@@ -171,6 +171,12 @@ import {
171
171
  NodeType
172
172
  } from "@player-ui/player";
173
173
  import { ExpressionPlugin } from "@player-ui/expression-plugin";
174
+ var isInChatDemo = (node) => {
175
+ if (node.parent?.parent?.type === NodeType.View && node.parent.parent.value.id === "chat-view") {
176
+ return true;
177
+ }
178
+ return node.parent?.parent?.type === NodeType.Asset && node.parent.parent.value.id.startsWith("collection-async-chat-demo");
179
+ };
174
180
  var createContentFromMessage = (message, id) => ({
175
181
  asset: {
176
182
  type: "chat-message",
@@ -184,6 +190,23 @@ var createContentFromMessage = (message, id) => ({
184
190
  }
185
191
  }
186
192
  });
193
+ var createBrokenRenderContent = (id) => ({
194
+ asset: {
195
+ id,
196
+ type: "input",
197
+ binding: "binding",
198
+ label: 100
199
+ }
200
+ });
201
+ var createBrokenTransformContent = (id) => ({
202
+ asset: {
203
+ id,
204
+ type: "input",
205
+ binding: {
206
+ prop: "value"
207
+ }
208
+ }
209
+ });
187
210
  var ChatUiDemoPlugin = class {
188
211
  constructor() {
189
212
  this.name = "chat-ui-demo-plugin";
@@ -201,7 +224,7 @@ var ChatUiDemoPlugin = class {
201
224
  let deferredPromises = {};
202
225
  let allPromiseKeys = [];
203
226
  let counter = 0;
204
- const sendMessage = (context, message, nodeId) => {
227
+ const sendMessage = (context, nodeId, getContent) => {
205
228
  if (nodeId && !(nodeId in deferredPromises)) {
206
229
  context.logger?.warn(
207
230
  `'send' expression called with unrecognized id '${nodeId}'`
@@ -214,12 +237,8 @@ var ChatUiDemoPlugin = class {
214
237
  }
215
238
  const keys = nodeId ? [nodeId] : allPromiseKeys;
216
239
  for (const id of keys) {
217
- const content = createContentFromMessage(
218
- message,
219
- `chat-demo-${counter++}`
220
- );
221
240
  const resolveFunction = deferredPromises[id];
222
- resolveFunction?.(content);
241
+ resolveFunction?.(getContent?.());
223
242
  delete deferredPromises[id];
224
243
  }
225
244
  if (nodeId) {
@@ -230,7 +249,7 @@ var ChatUiDemoPlugin = class {
230
249
  }
231
250
  };
232
251
  asyncNodePlugin.hooks.onAsyncNode.tap(this.name, (node) => {
233
- if (node.parent?.parent?.type !== NodeType.Asset && node.parent?.parent?.type !== NodeType.View || !node.parent.parent.value.id.startsWith("collection-async-chat-demo")) {
252
+ if (!isInChatDemo(node)) {
234
253
  return Promise.resolve(void 0);
235
254
  }
236
255
  return new Promise((res) => {
@@ -238,13 +257,38 @@ var ChatUiDemoPlugin = class {
238
257
  allPromiseKeys.push(node.id);
239
258
  });
240
259
  });
260
+ const sendRealMessage = (context, message, nodeId) => {
261
+ return sendMessage(
262
+ context,
263
+ nodeId,
264
+ () => createContentFromMessage(message, `chat-demo-${counter++}`)
265
+ );
266
+ };
267
+ const sendBrokenMessage = (context, _, nodeId) => {
268
+ return sendMessage(
269
+ context,
270
+ nodeId,
271
+ () => createBrokenRenderContent(`chat-demo-${counter++}`)
272
+ );
273
+ };
274
+ const sendBrokenTransformMessage = (context, _, nodeId) => {
275
+ return sendMessage(
276
+ context,
277
+ nodeId,
278
+ () => createBrokenTransformContent(`chat-demo-${counter++}`)
279
+ );
280
+ };
241
281
  player.hooks.view.tap(this.name, (_) => {
242
282
  deferredPromises = {};
243
283
  allPromiseKeys = [];
244
284
  counter = 0;
245
285
  });
246
286
  const expressionPlugin = new ExpressionPlugin(
247
- /* @__PURE__ */ new Map([["send", sendMessage]])
287
+ /* @__PURE__ */ new Map([
288
+ ["send", sendRealMessage],
289
+ ["sendBroken", sendBrokenMessage],
290
+ ["sendBrokenTransform", sendBrokenTransformMessage]
291
+ ])
248
292
  );
249
293
  player.registerPlugin(expressionPlugin);
250
294
  }
@@ -272,18 +316,63 @@ var ReferenceAssetsTransformPlugin = class {
272
316
 
273
317
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugin.ts
274
318
  import {
275
- AsyncNodePlugin as AsyncNodePlugin2,
319
+ AsyncNodePlugin as AsyncNodePlugin3,
276
320
  AsyncNodePluginPlugin
277
321
  } from "@player-ui/async-node-plugin";
322
+
323
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugins/error-recovery-plugin.ts
324
+ import { AsyncNodePlugin as AsyncNodePlugin2 } from "@player-ui/async-node-plugin";
325
+ var ErrorRecoveryPlugin = class {
326
+ constructor() {
327
+ this.name = "ErrorRecoveryPlugin";
328
+ }
329
+ /** */
330
+ apply(player) {
331
+ player.applyTo(AsyncNodePlugin2.Symbol, (plugin) => {
332
+ plugin.hooks.onAsyncNodeError.tap(this.name, (err, node) => {
333
+ const playerState = player.getState();
334
+ if (playerState.status !== "in-progress") {
335
+ return;
336
+ }
337
+ const viewId = playerState.controllers.view.currentView?.initialView.id;
338
+ if (viewId !== "chat-view") {
339
+ return;
340
+ }
341
+ return {
342
+ asset: {
343
+ type: "chat-message",
344
+ id: `${node.id}-recovery`,
345
+ value: {
346
+ asset: {
347
+ id: `${node.id}-recovery-text`,
348
+ type: "text",
349
+ value: "Something went wrong, please try again."
350
+ }
351
+ }
352
+ }
353
+ };
354
+ });
355
+ });
356
+ }
357
+ };
358
+
359
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugin.ts
360
+ import { CommonTypesPlugin } from "@player-ui/common-types-plugin";
361
+ import { CommonExpressionsPlugin } from "@player-ui/common-expressions-plugin";
362
+ import { ComputedPropertiesPlugin } from "@player-ui/computed-properties-plugin";
278
363
  var ReferenceAssetsPlugin = class {
279
364
  constructor() {
280
365
  this.name = "reference-assets-plugin";
281
366
  this.metaPlugin = new MetaPlugin([
282
- new AsyncNodePlugin2({
367
+ new CommonTypesPlugin(),
368
+ new CommonExpressionsPlugin(),
369
+ new ComputedPropertiesPlugin(),
370
+ new AsyncNodePlugin3({
283
371
  plugins: [new AsyncNodePluginPlugin()]
284
372
  }),
285
373
  new ReferenceAssetsTransformPlugin(),
286
- new ChatUiDemoPlugin()
374
+ new ChatUiDemoPlugin(),
375
+ new ErrorRecoveryPlugin()
287
376
  ]);
288
377
  }
289
378
  apply(player) {
package/dist/index.mjs CHANGED
@@ -171,6 +171,12 @@ import {
171
171
  NodeType
172
172
  } from "@player-ui/player";
173
173
  import { ExpressionPlugin } from "@player-ui/expression-plugin";
174
+ var isInChatDemo = (node) => {
175
+ if (node.parent?.parent?.type === NodeType.View && node.parent.parent.value.id === "chat-view") {
176
+ return true;
177
+ }
178
+ return node.parent?.parent?.type === NodeType.Asset && node.parent.parent.value.id.startsWith("collection-async-chat-demo");
179
+ };
174
180
  var createContentFromMessage = (message, id) => ({
175
181
  asset: {
176
182
  type: "chat-message",
@@ -184,6 +190,23 @@ var createContentFromMessage = (message, id) => ({
184
190
  }
185
191
  }
186
192
  });
193
+ var createBrokenRenderContent = (id) => ({
194
+ asset: {
195
+ id,
196
+ type: "input",
197
+ binding: "binding",
198
+ label: 100
199
+ }
200
+ });
201
+ var createBrokenTransformContent = (id) => ({
202
+ asset: {
203
+ id,
204
+ type: "input",
205
+ binding: {
206
+ prop: "value"
207
+ }
208
+ }
209
+ });
187
210
  var ChatUiDemoPlugin = class {
188
211
  constructor() {
189
212
  this.name = "chat-ui-demo-plugin";
@@ -201,7 +224,7 @@ var ChatUiDemoPlugin = class {
201
224
  let deferredPromises = {};
202
225
  let allPromiseKeys = [];
203
226
  let counter = 0;
204
- const sendMessage = (context, message, nodeId) => {
227
+ const sendMessage = (context, nodeId, getContent) => {
205
228
  if (nodeId && !(nodeId in deferredPromises)) {
206
229
  context.logger?.warn(
207
230
  `'send' expression called with unrecognized id '${nodeId}'`
@@ -214,12 +237,8 @@ var ChatUiDemoPlugin = class {
214
237
  }
215
238
  const keys = nodeId ? [nodeId] : allPromiseKeys;
216
239
  for (const id of keys) {
217
- const content = createContentFromMessage(
218
- message,
219
- `chat-demo-${counter++}`
220
- );
221
240
  const resolveFunction = deferredPromises[id];
222
- resolveFunction?.(content);
241
+ resolveFunction?.(getContent?.());
223
242
  delete deferredPromises[id];
224
243
  }
225
244
  if (nodeId) {
@@ -230,7 +249,7 @@ var ChatUiDemoPlugin = class {
230
249
  }
231
250
  };
232
251
  asyncNodePlugin.hooks.onAsyncNode.tap(this.name, (node) => {
233
- if (node.parent?.parent?.type !== NodeType.Asset && node.parent?.parent?.type !== NodeType.View || !node.parent.parent.value.id.startsWith("collection-async-chat-demo")) {
252
+ if (!isInChatDemo(node)) {
234
253
  return Promise.resolve(void 0);
235
254
  }
236
255
  return new Promise((res) => {
@@ -238,13 +257,38 @@ var ChatUiDemoPlugin = class {
238
257
  allPromiseKeys.push(node.id);
239
258
  });
240
259
  });
260
+ const sendRealMessage = (context, message, nodeId) => {
261
+ return sendMessage(
262
+ context,
263
+ nodeId,
264
+ () => createContentFromMessage(message, `chat-demo-${counter++}`)
265
+ );
266
+ };
267
+ const sendBrokenMessage = (context, _, nodeId) => {
268
+ return sendMessage(
269
+ context,
270
+ nodeId,
271
+ () => createBrokenRenderContent(`chat-demo-${counter++}`)
272
+ );
273
+ };
274
+ const sendBrokenTransformMessage = (context, _, nodeId) => {
275
+ return sendMessage(
276
+ context,
277
+ nodeId,
278
+ () => createBrokenTransformContent(`chat-demo-${counter++}`)
279
+ );
280
+ };
241
281
  player.hooks.view.tap(this.name, (_) => {
242
282
  deferredPromises = {};
243
283
  allPromiseKeys = [];
244
284
  counter = 0;
245
285
  });
246
286
  const expressionPlugin = new ExpressionPlugin(
247
- /* @__PURE__ */ new Map([["send", sendMessage]])
287
+ /* @__PURE__ */ new Map([
288
+ ["send", sendRealMessage],
289
+ ["sendBroken", sendBrokenMessage],
290
+ ["sendBrokenTransform", sendBrokenTransformMessage]
291
+ ])
248
292
  );
249
293
  player.registerPlugin(expressionPlugin);
250
294
  }
@@ -272,18 +316,63 @@ var ReferenceAssetsTransformPlugin = class {
272
316
 
273
317
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugin.ts
274
318
  import {
275
- AsyncNodePlugin as AsyncNodePlugin2,
319
+ AsyncNodePlugin as AsyncNodePlugin3,
276
320
  AsyncNodePluginPlugin
277
321
  } from "@player-ui/async-node-plugin";
322
+
323
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugins/error-recovery-plugin.ts
324
+ import { AsyncNodePlugin as AsyncNodePlugin2 } from "@player-ui/async-node-plugin";
325
+ var ErrorRecoveryPlugin = class {
326
+ constructor() {
327
+ this.name = "ErrorRecoveryPlugin";
328
+ }
329
+ /** */
330
+ apply(player) {
331
+ player.applyTo(AsyncNodePlugin2.Symbol, (plugin) => {
332
+ plugin.hooks.onAsyncNodeError.tap(this.name, (err, node) => {
333
+ const playerState = player.getState();
334
+ if (playerState.status !== "in-progress") {
335
+ return;
336
+ }
337
+ const viewId = playerState.controllers.view.currentView?.initialView.id;
338
+ if (viewId !== "chat-view") {
339
+ return;
340
+ }
341
+ return {
342
+ asset: {
343
+ type: "chat-message",
344
+ id: `${node.id}-recovery`,
345
+ value: {
346
+ asset: {
347
+ id: `${node.id}-recovery-text`,
348
+ type: "text",
349
+ value: "Something went wrong, please try again."
350
+ }
351
+ }
352
+ }
353
+ };
354
+ });
355
+ });
356
+ }
357
+ };
358
+
359
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugin.ts
360
+ import { CommonTypesPlugin } from "@player-ui/common-types-plugin";
361
+ import { CommonExpressionsPlugin } from "@player-ui/common-expressions-plugin";
362
+ import { ComputedPropertiesPlugin } from "@player-ui/computed-properties-plugin";
278
363
  var ReferenceAssetsPlugin = class {
279
364
  constructor() {
280
365
  this.name = "reference-assets-plugin";
281
366
  this.metaPlugin = new MetaPlugin([
282
- new AsyncNodePlugin2({
367
+ new CommonTypesPlugin(),
368
+ new CommonExpressionsPlugin(),
369
+ new ComputedPropertiesPlugin(),
370
+ new AsyncNodePlugin3({
283
371
  plugins: [new AsyncNodePluginPlugin()]
284
372
  }),
285
373
  new ReferenceAssetsTransformPlugin(),
286
- new ChatUiDemoPlugin()
374
+ new ChatUiDemoPlugin(),
375
+ new ErrorRecoveryPlugin()
287
376
  ]);
288
377
  }
289
378
  apply(player) {