@player-ui/reference-assets-plugin 0.15.5--canary.888.37918 → 0.15.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ReferenceAssetsPlugin.native.js +3734 -5558
- package/dist/ReferenceAssetsPlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs +11 -100
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +11 -100
- package/dist/index.mjs +11 -100
- package/dist/index.mjs.map +1 -1
- package/dist/xlr/Assets.ActionAsset.json +2 -2
- package/dist/xlr/Assets.ChatMessageAsset.json +1 -1
- package/dist/xlr/Assets.ChoiceAsset.json +5 -5
- package/dist/xlr/Assets.CollectionAsset.json +1 -1
- package/dist/xlr/Assets.ImageAsset.json +2 -2
- package/dist/xlr/Assets.InputAsset.json +2 -2
- package/dist/xlr/Assets.TextAsset.json +4 -4
- package/dist/xlr/Expressions.send.json +1 -1
- package/dist/xlr/Views.InfoAsset.json +1 -1
- package/package.json +9 -11
- package/src/__tests__/plugin.test.ts +2 -162
- package/src/assets/action/types.ts +3 -2
- package/src/assets/choice/types.ts +3 -2
- package/src/assets/input/types.ts +3 -2
- package/src/plugin.ts +0 -8
- package/src/plugins/chat-ui-demo-plugin.ts +13 -76
- package/src/plugins/reference-assets-transform-plugin.ts +12 -15
- package/src/plugins/error-recovery-plugin.ts +0 -37
- package/types/plugins/error-recovery-plugin.d.ts +0 -7
|
@@ -4,25 +4,10 @@ import {
|
|
|
4
4
|
ExtendedPlayerPlugin,
|
|
5
5
|
NodeType,
|
|
6
6
|
Player,
|
|
7
|
-
Node,
|
|
8
7
|
} from "@player-ui/player";
|
|
9
8
|
import { ExpressionPlugin } from "@player-ui/expression-plugin";
|
|
10
9
|
import { send } from "./send";
|
|
11
10
|
|
|
12
|
-
const isInChatDemo = (node: Node.Node) => {
|
|
13
|
-
if (
|
|
14
|
-
node.parent?.parent?.type === NodeType.View &&
|
|
15
|
-
node.parent.parent.value.id === "chat-view"
|
|
16
|
-
) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
node.parent?.parent?.type === NodeType.Asset &&
|
|
22
|
-
node.parent.parent.value.id.startsWith("collection-async-chat-demo")
|
|
23
|
-
);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
11
|
const createContentFromMessage = (message: string, id: string): any => ({
|
|
27
12
|
asset: {
|
|
28
13
|
type: "chat-message",
|
|
@@ -37,27 +22,6 @@ const createContentFromMessage = (message: string, id: string): any => ({
|
|
|
37
22
|
},
|
|
38
23
|
});
|
|
39
24
|
|
|
40
|
-
/** This content will fail to display its label since it isn't a valid asset */
|
|
41
|
-
const createBrokenRenderContent = (id: string): any => ({
|
|
42
|
-
asset: {
|
|
43
|
-
id,
|
|
44
|
-
type: "input",
|
|
45
|
-
binding: "binding",
|
|
46
|
-
label: 100,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
/** this content will fail to fetch from the data model since the binding is an object */
|
|
51
|
-
const createBrokenTransformContent = (id: string): any => ({
|
|
52
|
-
asset: {
|
|
53
|
-
id,
|
|
54
|
-
type: "input",
|
|
55
|
-
binding: {
|
|
56
|
-
prop: "value",
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
|
|
61
25
|
export class ChatUiDemoPlugin implements ExtendedPlayerPlugin<[], [], [send]> {
|
|
62
26
|
public readonly name = "chat-ui-demo-plugin";
|
|
63
27
|
|
|
@@ -77,10 +41,10 @@ export class ChatUiDemoPlugin implements ExtendedPlayerPlugin<[], [], [send]> {
|
|
|
77
41
|
let allPromiseKeys: string[] = [];
|
|
78
42
|
let counter = 0;
|
|
79
43
|
|
|
80
|
-
const sendMessage = (
|
|
44
|
+
const sendMessage: send = (
|
|
81
45
|
context: ExpressionContext,
|
|
46
|
+
message: string,
|
|
82
47
|
nodeId?: string,
|
|
83
|
-
getContent?: () => any,
|
|
84
48
|
): void => {
|
|
85
49
|
if (nodeId && !(nodeId in deferredPromises)) {
|
|
86
50
|
context.logger?.warn(
|
|
@@ -98,8 +62,12 @@ export class ChatUiDemoPlugin implements ExtendedPlayerPlugin<[], [], [send]> {
|
|
|
98
62
|
const keys = nodeId ? [nodeId] : allPromiseKeys;
|
|
99
63
|
|
|
100
64
|
for (const id of keys) {
|
|
65
|
+
const content = createContentFromMessage(
|
|
66
|
+
message,
|
|
67
|
+
`chat-demo-${counter++}`,
|
|
68
|
+
);
|
|
101
69
|
const resolveFunction = deferredPromises[id];
|
|
102
|
-
resolveFunction?.(
|
|
70
|
+
resolveFunction?.(content);
|
|
103
71
|
delete deferredPromises[id];
|
|
104
72
|
}
|
|
105
73
|
|
|
@@ -113,7 +81,11 @@ export class ChatUiDemoPlugin implements ExtendedPlayerPlugin<[], [], [send]> {
|
|
|
113
81
|
|
|
114
82
|
asyncNodePlugin.hooks.onAsyncNode.tap(this.name, (node) => {
|
|
115
83
|
// Ensure this is only used on the chat-ui.tsx mock to prevent the promise from setting up during tests.
|
|
116
|
-
if (
|
|
84
|
+
if (
|
|
85
|
+
(node.parent?.parent?.type !== NodeType.Asset &&
|
|
86
|
+
node.parent?.parent?.type !== NodeType.View) ||
|
|
87
|
+
!node.parent.parent.value.id.startsWith("collection-async-chat-demo")
|
|
88
|
+
) {
|
|
117
89
|
return Promise.resolve(undefined);
|
|
118
90
|
}
|
|
119
91
|
|
|
@@ -123,37 +95,6 @@ export class ChatUiDemoPlugin implements ExtendedPlayerPlugin<[], [], [send]> {
|
|
|
123
95
|
});
|
|
124
96
|
});
|
|
125
97
|
|
|
126
|
-
const sendRealMessage: send = (
|
|
127
|
-
context: ExpressionContext,
|
|
128
|
-
message: string,
|
|
129
|
-
nodeId?: string,
|
|
130
|
-
) => {
|
|
131
|
-
return sendMessage(context, nodeId, () =>
|
|
132
|
-
createContentFromMessage(message, `chat-demo-${counter++}`),
|
|
133
|
-
);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
/** These expressions are used as examples in the storybook to allow broken content through and show the error recovery fallback pattern. */
|
|
137
|
-
const sendBrokenMessage: send = (
|
|
138
|
-
context: ExpressionContext,
|
|
139
|
-
_: string,
|
|
140
|
-
nodeId?: string,
|
|
141
|
-
) => {
|
|
142
|
-
return sendMessage(context, nodeId, () =>
|
|
143
|
-
createBrokenRenderContent(`chat-demo-${counter++}`),
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const sendBrokenTransformMessage: send = (
|
|
148
|
-
context: ExpressionContext,
|
|
149
|
-
_: string,
|
|
150
|
-
nodeId?: string,
|
|
151
|
-
) => {
|
|
152
|
-
return sendMessage(context, nodeId, () =>
|
|
153
|
-
createBrokenTransformContent(`chat-demo-${counter++}`),
|
|
154
|
-
);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
98
|
// Reset at the start of a new view.
|
|
158
99
|
player.hooks.view.tap(this.name, (_) => {
|
|
159
100
|
deferredPromises = {};
|
|
@@ -163,11 +104,7 @@ export class ChatUiDemoPlugin implements ExtendedPlayerPlugin<[], [], [send]> {
|
|
|
163
104
|
|
|
164
105
|
// Register 'send' expression
|
|
165
106
|
const expressionPlugin = new ExpressionPlugin(
|
|
166
|
-
new Map([
|
|
167
|
-
["send", sendRealMessage],
|
|
168
|
-
["sendBroken", sendBrokenMessage],
|
|
169
|
-
["sendBrokenTransform", sendBrokenTransformMessage],
|
|
170
|
-
]),
|
|
107
|
+
new Map([["send", sendMessage]]),
|
|
171
108
|
);
|
|
172
109
|
player.registerPlugin(expressionPlugin);
|
|
173
110
|
}
|
|
@@ -19,21 +19,18 @@ import type {
|
|
|
19
19
|
TextAsset,
|
|
20
20
|
} from "../assets";
|
|
21
21
|
|
|
22
|
-
export class ReferenceAssetsTransformPlugin
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
[InfoAsset]
|
|
35
|
-
>
|
|
36
|
-
{
|
|
22
|
+
export class ReferenceAssetsTransformPlugin implements ExtendedPlayerPlugin<
|
|
23
|
+
[
|
|
24
|
+
ActionAsset,
|
|
25
|
+
InputAsset,
|
|
26
|
+
ImageAsset,
|
|
27
|
+
TextAsset,
|
|
28
|
+
CollectionAsset,
|
|
29
|
+
ChoiceAsset,
|
|
30
|
+
ChatMessageAsset,
|
|
31
|
+
],
|
|
32
|
+
[InfoAsset]
|
|
33
|
+
> {
|
|
37
34
|
name = "reference-assets-transforms";
|
|
38
35
|
|
|
39
36
|
apply(player: Player): void {
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { AsyncNodePlugin } from "@player-ui/async-node-plugin";
|
|
2
|
-
import { Player, PlayerPlugin } from "@player-ui/player";
|
|
3
|
-
|
|
4
|
-
export class ErrorRecoveryPlugin implements PlayerPlugin {
|
|
5
|
-
readonly name = "ErrorRecoveryPlugin";
|
|
6
|
-
/** */
|
|
7
|
-
apply(player: Player): void {
|
|
8
|
-
player.applyTo<AsyncNodePlugin>(AsyncNodePlugin.Symbol, (plugin) => {
|
|
9
|
-
plugin.hooks.onAsyncNodeError.tap(this.name, (err, node) => {
|
|
10
|
-
const playerState = player.getState();
|
|
11
|
-
if (playerState.status !== "in-progress") {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Limit error recovery to chat-ui view example to avoid breaking tests.
|
|
16
|
-
const viewId = playerState.controllers.view.currentView?.initialView.id;
|
|
17
|
-
if (viewId !== "chat-view") {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
asset: {
|
|
23
|
-
type: "chat-message",
|
|
24
|
-
id: `${node.id}-recovery`,
|
|
25
|
-
value: {
|
|
26
|
-
asset: {
|
|
27
|
-
id: `${node.id}-recovery-text`,
|
|
28
|
-
type: "text",
|
|
29
|
-
value: "Something went wrong, please try again.",
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|