@relaymessenger/sdk 0.3.6-staging.5 → 0.3.6-staging.51
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 +511 -29
- package/dist/a2ui.d.ts +111 -0
- package/dist/a2ui.d.ts.map +1 -0
- package/dist/a2ui.js +137 -0
- package/dist/a2ui.js.map +1 -0
- package/dist/buttons.d.ts +7 -2
- package/dist/buttons.d.ts.map +1 -1
- package/dist/buttons.js +13 -11
- package/dist/buttons.js.map +1 -1
- package/dist/calls/call-room.d.ts +110 -0
- package/dist/calls/call-room.d.ts.map +1 -0
- package/dist/calls/call-room.js +616 -0
- package/dist/calls/call-room.js.map +1 -0
- package/dist/calls/engine-werift-video.d.ts +83 -0
- package/dist/calls/engine-werift-video.d.ts.map +1 -0
- package/dist/calls/engine-werift-video.js +607 -0
- package/dist/calls/engine-werift-video.js.map +1 -0
- package/dist/calls/engine-werift.d.ts +48 -0
- package/dist/calls/engine-werift.d.ts.map +1 -0
- package/dist/calls/engine-werift.js +462 -0
- package/dist/calls/engine-werift.js.map +1 -0
- package/dist/calls/index.d.ts +11 -0
- package/dist/calls/index.d.ts.map +1 -0
- package/dist/calls/index.js +11 -0
- package/dist/calls/index.js.map +1 -0
- package/dist/calls/transport.d.ts +466 -0
- package/dist/calls/transport.d.ts.map +1 -0
- package/dist/calls/transport.js +1409 -0
- package/dist/calls/transport.js.map +1 -0
- package/dist/calls/video-frame.d.ts +56 -0
- package/dist/calls/video-frame.d.ts.map +1 -0
- package/dist/calls/video-frame.js +245 -0
- package/dist/calls/video-frame.js.map +1 -0
- package/dist/calls/video-presets.d.ts +39 -0
- package/dist/calls/video-presets.d.ts.map +1 -0
- package/dist/calls/video-presets.js +40 -0
- package/dist/calls/video-presets.js.map +1 -0
- package/dist/calls/video-rtp.d.ts +51 -0
- package/dist/calls/video-rtp.d.ts.map +1 -0
- package/dist/calls/video-rtp.js +294 -0
- package/dist/calls/video-rtp.js.map +1 -0
- package/dist/calls/video.d.ts +195 -0
- package/dist/calls/video.d.ts.map +1 -0
- package/dist/calls/video.js +228 -0
- package/dist/calls/video.js.map +1 -0
- package/dist/client.d.ts +197 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +437 -16
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +16 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/links.d.ts +58 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +127 -0
- package/dist/links.js.map +1 -0
- package/dist/operations.d.ts +97 -9
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +129 -10
- package/dist/operations.js.map +1 -1
- package/dist/payment.d.ts +67 -0
- package/dist/payment.d.ts.map +1 -0
- package/dist/payment.js +147 -0
- package/dist/payment.js.map +1 -0
- package/dist/reply-target.d.ts +26 -0
- package/dist/reply-target.d.ts.map +1 -0
- package/dist/reply-target.js +59 -0
- package/dist/reply-target.js.map +1 -0
- package/dist/selection.d.ts +46 -0
- package/dist/selection.d.ts.map +1 -0
- package/dist/selection.js +142 -0
- package/dist/selection.js.map +1 -0
- package/dist/types.d.ts +1075 -78
- package/dist/types.d.ts.map +1 -1
- package/dist/websocket.d.ts +6 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +29 -10
- package/dist/websocket.js.map +1 -1
- package/package.json +38 -3
- package/dist/calls-room.d.ts +0 -50
- package/dist/calls-room.d.ts.map +0 -1
- package/dist/calls-room.js +0 -319
- package/dist/calls-room.js.map +0 -1
package/dist/a2ui.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Relay } from "./client.js";
|
|
2
|
+
import type { A2uiAction, A2uiBrowserActionName, A2uiBrowserComponent, A2uiComponent, A2uiCreateSurfaceMessage, A2uiMessage, A2uiServerToClientMessage, DataPart, MessageContent, MessageSendResponse, MessageWebhookData, RelayWebhookEvent, RequestOptions } from "./types.js";
|
|
3
|
+
/** The `media_type` of a data part that carries A2UI messages. */
|
|
4
|
+
export declare const A2UI_MEDIA_TYPE = "application/a2ui+json";
|
|
5
|
+
/** The A2UI version every message these helpers write carries. */
|
|
6
|
+
export declare const A2UI_VERSION = "v0.9.1";
|
|
7
|
+
/** A2UI v0.9.1's basic catalog, by the `catalogId` its catalog file declares. */
|
|
8
|
+
export declare const A2UI_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
|
|
9
|
+
/** Relay's catalog: every basic catalog component and function, plus `PaymentRequest` and `Browser`. */
|
|
10
|
+
export declare const RELAY_A2UI_CATALOG_ID = "https://relayapp.im/a2ui/catalog/v1";
|
|
11
|
+
/**
|
|
12
|
+
* The taps a Browser card sends to the agent that created it, as an A2UI
|
|
13
|
+
* `action` whose `sourceComponentId` is the Browser's id and whose `context`
|
|
14
|
+
* is empty: "Take control of the browser", "Finish up" and "Stop the task".
|
|
15
|
+
* Pause your browser work from `takeControl` until `returnControl`; end the
|
|
16
|
+
* task on `stop`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const A2UI_BROWSER_ACTIONS: {
|
|
19
|
+
readonly takeControl: "browser.takeControl";
|
|
20
|
+
readonly returnControl: "browser.returnControl";
|
|
21
|
+
readonly stop: "browser.stop";
|
|
22
|
+
};
|
|
23
|
+
/** Whether a tap's `name` is one of a Browser card's taps. */
|
|
24
|
+
export declare const isA2uiBrowserAction: (name: string) => name is A2uiBrowserActionName;
|
|
25
|
+
/** A Browser card's properties: everything but `id` and `component`. */
|
|
26
|
+
export type A2uiBrowserCard = Omit<A2uiBrowserComponent, "id" | "component">;
|
|
27
|
+
/** The Browser component a card draws, with the id `root` unless another is given. */
|
|
28
|
+
export declare const a2uiBrowserComponent: (card: A2uiBrowserCard, id?: string) => A2uiBrowserComponent;
|
|
29
|
+
/**
|
|
30
|
+
* The A2UI message that changes a Browser card in place: `updateComponents`
|
|
31
|
+
* replaces the whole component by id, so `card` is the card as it should now
|
|
32
|
+
* be drawn, for example `{ ...card, state: "needs_you", status: "Blocked ·
|
|
33
|
+
* Waiting for confirmation" }`. A bound property changes with
|
|
34
|
+
* `updateA2uiSurface`'s `dataModel` instead.
|
|
35
|
+
*/
|
|
36
|
+
export declare const a2uiBrowserCardUpdate: (surfaceId: string, card: A2uiBrowserCard) => A2uiServerToClientMessage;
|
|
37
|
+
/**
|
|
38
|
+
* The A2UI messages of a new Browser card in Relay's catalog: `createSurface`,
|
|
39
|
+
* then `updateComponents` with the Browser as `root`, then, when `dataModel`
|
|
40
|
+
* is given (for bound properties), `updateDataModel` for the whole model.
|
|
41
|
+
*/
|
|
42
|
+
export declare const a2uiBrowserCardMessages: (surfaceId: string, card: A2uiBrowserCard, dataModel?: Record<string, unknown>) => A2uiServerToClientMessage[];
|
|
43
|
+
/** A card: the surface to create, its components, and, optionally, its first data model. */
|
|
44
|
+
export interface A2uiSurface {
|
|
45
|
+
surfaceId: string;
|
|
46
|
+
/** A catalog Relay draws: `A2UI_BASIC_CATALOG_ID` or `RELAY_A2UI_CATALOG_ID`. */
|
|
47
|
+
catalogId: string;
|
|
48
|
+
/** Every component of the card; one has the id `root`. The catalog defines each component and property. */
|
|
49
|
+
components: A2uiComponent[];
|
|
50
|
+
/** The whole data model, sent as an `updateDataModel` with no `path`. */
|
|
51
|
+
dataModel?: Record<string, unknown>;
|
|
52
|
+
theme?: A2uiCreateSurfaceMessage["createSurface"]["theme"];
|
|
53
|
+
sendDataModel?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A change to a card that is already in the chat: components to add or
|
|
57
|
+
* replace by id, and a data model value to set at `path` (a JSON Pointer; no
|
|
58
|
+
* `path` is the whole data model; no `value` removes the key at `path`).
|
|
59
|
+
*/
|
|
60
|
+
export interface A2uiSurfaceUpdate {
|
|
61
|
+
components?: A2uiComponent[];
|
|
62
|
+
dataModel?: {
|
|
63
|
+
path?: string;
|
|
64
|
+
value?: unknown;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The rest of the Message beside the data part. `text` becomes a text part
|
|
69
|
+
* before it; the chat list and notification show it. With no text, they show
|
|
70
|
+
* the card's first `Text` component. A text beside an update is a new Message,
|
|
71
|
+
* and the update still changes the card in place.
|
|
72
|
+
*/
|
|
73
|
+
export type A2uiSendOptions = Omit<MessageContent, "parts"> & {
|
|
74
|
+
text?: string;
|
|
75
|
+
};
|
|
76
|
+
/** A tap read out of `message.received`. */
|
|
77
|
+
export interface A2uiTap {
|
|
78
|
+
action: A2uiAction;
|
|
79
|
+
/** The tapped surface's data model, present when the surface set `sendDataModel`. */
|
|
80
|
+
dataModel?: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
/** Wraps A2UI messages in the data part Relay carries them in. */
|
|
83
|
+
export declare const a2uiPart: (messages: A2uiMessage[]) => DataPart;
|
|
84
|
+
/**
|
|
85
|
+
* Sends a new card into a chat: `createSurface`, `updateComponents` and, when
|
|
86
|
+
* `dataModel` is given, `updateDataModel`, in one data part. Messages Relay
|
|
87
|
+
* could not apply come back in `a2ui_errors` (`A2uiFailure`); a send it could
|
|
88
|
+
* not apply at all throws a `RelayAPIError` whose `body.a2ui_errors` lists each.
|
|
89
|
+
*/
|
|
90
|
+
export declare const sendA2uiSurface: (client: Pick<Relay, "chats">, chatID: string, surface: A2uiSurface, message?: A2uiSendOptions, options?: RequestOptions) => Promise<MessageSendResponse>;
|
|
91
|
+
/**
|
|
92
|
+
* Changes a card already in the chat, in place, for every member. With no
|
|
93
|
+
* `text`, the send adds no Message and returns the card's own Message. Any
|
|
94
|
+
* agent in the chat may update any surface in it.
|
|
95
|
+
*/
|
|
96
|
+
export declare const updateA2uiSurface: (client: Pick<Relay, "chats">, chatID: string, surfaceId: string, update: A2uiSurfaceUpdate, message?: A2uiSendOptions, options?: RequestOptions) => Promise<MessageSendResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* Removes a card for everyone. When every surface a Message draws is deleted,
|
|
99
|
+
* the Message reads back with no parts and a non-null `unsent_at`. The
|
|
100
|
+
* `surfaceId` may be created again afterwards.
|
|
101
|
+
*/
|
|
102
|
+
export declare const deleteA2uiSurface: (client: Pick<Relay, "chats">, chatID: string, surfaceId: string, message?: A2uiSendOptions, options?: RequestOptions) => Promise<MessageSendResponse>;
|
|
103
|
+
/**
|
|
104
|
+
* Reads the first A2UI `action` out of a `message.received` event (a signed
|
|
105
|
+
* webhook or a WebSocket event), or out of its `data`. Returns null for any
|
|
106
|
+
* other event and for a Message that carries no tap. When the surface set
|
|
107
|
+
* `sendDataModel`, `dataModel` is that surface's model from
|
|
108
|
+
* `metadata.a2uiClientDataModel`.
|
|
109
|
+
*/
|
|
110
|
+
export declare const readA2uiAction: (event: RelayWebhookEvent | MessageWebhookData) => A2uiTap | null;
|
|
111
|
+
//# sourceMappingURL=a2ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2ui.d.ts","sourceRoot":"","sources":["../src/a2ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EACV,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,wBAAwB,EACxB,WAAW,EACX,yBAAyB,EACzB,QAAQ,EACR,cAAc,EAEd,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,kEAAkE;AAClE,eAAO,MAAM,eAAe,0BAA0B,CAAC;AAEvD,kEAAkE;AAClE,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,oEAAoE,CAAC;AAEvG,wGAAwG;AACxG,eAAO,MAAM,qBAAqB,wCAAwC,CAAC;AAE3E;;;;;;GAMG;AACH,eAAO,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,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,4CAA4C;AAC5C,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,UAAU,CAAC;IACnB,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED,kEAAkE;AAClE,eAAO,MAAM,QAAQ,GAAI,UAAU,WAAW,EAAE,KAAG,QAIjD,CAAC;AAeH;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,QAAQ,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,EAC5B,QAAQ,MAAM,EACd,SAAS,WAAW,EACpB,UAAU,eAAe,EACzB,UAAU,cAAc,KACvB,OAAO,CAAC,mBAAmB,CAkB7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,EAC5B,QAAQ,MAAM,EACd,WAAW,MAAM,EACjB,QAAQ,iBAAiB,EACzB,UAAU,eAAe,EACzB,UAAU,cAAc,KACvB,OAAO,CAAC,mBAAmB,CAU7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,EAC5B,QAAQ,MAAM,EACd,WAAW,MAAM,EACjB,UAAU,eAAe,EACzB,UAAU,cAAc,KACvB,OAAO,CAAC,mBAAmB,CACqE,CAAC;AAEpG;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GACzB,OAAO,iBAAiB,GAAG,kBAAkB,KAC5C,OAAO,GAAG,IAkBZ,CAAC"}
|
package/dist/a2ui.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/** The `media_type` of a data part that carries A2UI messages. */
|
|
2
|
+
export const A2UI_MEDIA_TYPE = "application/a2ui+json";
|
|
3
|
+
/** The A2UI version every message these helpers write carries. */
|
|
4
|
+
export const A2UI_VERSION = "v0.9.1";
|
|
5
|
+
/** A2UI v0.9.1's basic catalog, by the `catalogId` its catalog file declares. */
|
|
6
|
+
export const A2UI_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
|
|
7
|
+
/** Relay's catalog: every basic catalog component and function, plus `PaymentRequest` and `Browser`. */
|
|
8
|
+
export const RELAY_A2UI_CATALOG_ID = "https://relayapp.im/a2ui/catalog/v1";
|
|
9
|
+
/**
|
|
10
|
+
* The taps a Browser card sends to the agent that created it, as an A2UI
|
|
11
|
+
* `action` whose `sourceComponentId` is the Browser's id and whose `context`
|
|
12
|
+
* is empty: "Take control of the browser", "Finish up" and "Stop the task".
|
|
13
|
+
* Pause your browser work from `takeControl` until `returnControl`; end the
|
|
14
|
+
* task on `stop`.
|
|
15
|
+
*/
|
|
16
|
+
export const A2UI_BROWSER_ACTIONS = {
|
|
17
|
+
takeControl: "browser.takeControl",
|
|
18
|
+
returnControl: "browser.returnControl",
|
|
19
|
+
stop: "browser.stop",
|
|
20
|
+
};
|
|
21
|
+
/** Whether a tap's `name` is one of a Browser card's taps. */
|
|
22
|
+
export const isA2uiBrowserAction = (name) => Object.values(A2UI_BROWSER_ACTIONS).includes(name);
|
|
23
|
+
/** The Browser component a card draws, with the id `root` unless another is given. */
|
|
24
|
+
export const a2uiBrowserComponent = (card, id = "root") => ({ id, component: "Browser", ...card });
|
|
25
|
+
/**
|
|
26
|
+
* The A2UI message that changes a Browser card in place: `updateComponents`
|
|
27
|
+
* replaces the whole component by id, so `card` is the card as it should now
|
|
28
|
+
* be drawn, for example `{ ...card, state: "needs_you", status: "Blocked ·
|
|
29
|
+
* Waiting for confirmation" }`. A bound property changes with
|
|
30
|
+
* `updateA2uiSurface`'s `dataModel` instead.
|
|
31
|
+
*/
|
|
32
|
+
export const a2uiBrowserCardUpdate = (surfaceId, card) => ({ version: A2UI_VERSION, updateComponents: { surfaceId, components: [a2uiBrowserComponent(card)] } });
|
|
33
|
+
/**
|
|
34
|
+
* The A2UI messages of a new Browser card in Relay's catalog: `createSurface`,
|
|
35
|
+
* then `updateComponents` with the Browser as `root`, then, when `dataModel`
|
|
36
|
+
* is given (for bound properties), `updateDataModel` for the whole model.
|
|
37
|
+
*/
|
|
38
|
+
export const a2uiBrowserCardMessages = (surfaceId, card, dataModel) => {
|
|
39
|
+
const messages = [
|
|
40
|
+
{ version: A2UI_VERSION, createSurface: { surfaceId, catalogId: RELAY_A2UI_CATALOG_ID } },
|
|
41
|
+
a2uiBrowserCardUpdate(surfaceId, card),
|
|
42
|
+
];
|
|
43
|
+
if (dataModel !== undefined)
|
|
44
|
+
messages.push({ version: A2UI_VERSION, updateDataModel: { surfaceId, value: dataModel } });
|
|
45
|
+
return messages;
|
|
46
|
+
};
|
|
47
|
+
/** Wraps A2UI messages in the data part Relay carries them in. */
|
|
48
|
+
export const a2uiPart = (messages) => ({
|
|
49
|
+
type: "data",
|
|
50
|
+
media_type: A2UI_MEDIA_TYPE,
|
|
51
|
+
data: messages,
|
|
52
|
+
});
|
|
53
|
+
const send = (client, chatID, messages, { text, ...message } = {}, options) => {
|
|
54
|
+
const parts = text === undefined
|
|
55
|
+
? [a2uiPart(messages)]
|
|
56
|
+
: [{ type: "text", value: text }, a2uiPart(messages)];
|
|
57
|
+
return client.chats.messages.send(chatID, { message: { ...message, parts } }, options);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Sends a new card into a chat: `createSurface`, `updateComponents` and, when
|
|
61
|
+
* `dataModel` is given, `updateDataModel`, in one data part. Messages Relay
|
|
62
|
+
* could not apply come back in `a2ui_errors` (`A2uiFailure`); a send it could
|
|
63
|
+
* not apply at all throws a `RelayAPIError` whose `body.a2ui_errors` lists each.
|
|
64
|
+
*/
|
|
65
|
+
export const sendA2uiSurface = (client, chatID, surface, message, options) => {
|
|
66
|
+
const { surfaceId, catalogId, components, dataModel, theme, sendDataModel } = surface;
|
|
67
|
+
const messages = [
|
|
68
|
+
{
|
|
69
|
+
version: A2UI_VERSION,
|
|
70
|
+
createSurface: {
|
|
71
|
+
surfaceId,
|
|
72
|
+
catalogId,
|
|
73
|
+
...(theme === undefined ? {} : { theme }),
|
|
74
|
+
...(sendDataModel === undefined ? {} : { sendDataModel }),
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{ version: A2UI_VERSION, updateComponents: { surfaceId, components } },
|
|
78
|
+
];
|
|
79
|
+
if (dataModel !== undefined) {
|
|
80
|
+
messages.push({ version: A2UI_VERSION, updateDataModel: { surfaceId, value: dataModel } });
|
|
81
|
+
}
|
|
82
|
+
return send(client, chatID, messages, message, options);
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Changes a card already in the chat, in place, for every member. With no
|
|
86
|
+
* `text`, the send adds no Message and returns the card's own Message. Any
|
|
87
|
+
* agent in the chat may update any surface in it.
|
|
88
|
+
*/
|
|
89
|
+
export const updateA2uiSurface = (client, chatID, surfaceId, update, message, options) => {
|
|
90
|
+
const messages = [];
|
|
91
|
+
if (update.components !== undefined) {
|
|
92
|
+
messages.push({ version: A2UI_VERSION, updateComponents: { surfaceId, components: update.components } });
|
|
93
|
+
}
|
|
94
|
+
if (update.dataModel !== undefined) {
|
|
95
|
+
messages.push({ version: A2UI_VERSION, updateDataModel: { surfaceId, ...update.dataModel } });
|
|
96
|
+
}
|
|
97
|
+
if (!messages.length)
|
|
98
|
+
throw new Error("an update needs components or a dataModel");
|
|
99
|
+
return send(client, chatID, messages, message, options);
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Removes a card for everyone. When every surface a Message draws is deleted,
|
|
103
|
+
* the Message reads back with no parts and a non-null `unsent_at`. The
|
|
104
|
+
* `surfaceId` may be created again afterwards.
|
|
105
|
+
*/
|
|
106
|
+
export const deleteA2uiSurface = (client, chatID, surfaceId, message, options) => send(client, chatID, [{ version: A2UI_VERSION, deleteSurface: { surfaceId } }], message, options);
|
|
107
|
+
/**
|
|
108
|
+
* Reads the first A2UI `action` out of a `message.received` event (a signed
|
|
109
|
+
* webhook or a WebSocket event), or out of its `data`. Returns null for any
|
|
110
|
+
* other event and for a Message that carries no tap. When the surface set
|
|
111
|
+
* `sendDataModel`, `dataModel` is that surface's model from
|
|
112
|
+
* `metadata.a2uiClientDataModel`.
|
|
113
|
+
*/
|
|
114
|
+
export const readA2uiAction = (event) => {
|
|
115
|
+
let data;
|
|
116
|
+
if ("event_type" in event) {
|
|
117
|
+
if (event.event_type !== "message.received")
|
|
118
|
+
return null;
|
|
119
|
+
data = event.data;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
data = event;
|
|
123
|
+
}
|
|
124
|
+
for (const part of data.parts ?? []) {
|
|
125
|
+
if (part.type !== "data" || part.media_type !== A2UI_MEDIA_TYPE)
|
|
126
|
+
continue;
|
|
127
|
+
for (const message of part.data) {
|
|
128
|
+
if (typeof message !== "object" || message === null || !("action" in message))
|
|
129
|
+
continue;
|
|
130
|
+
const { action } = message;
|
|
131
|
+
const dataModel = data.metadata?.a2uiClientDataModel?.surfaces[action.surfaceId];
|
|
132
|
+
return dataModel === undefined ? { action } : { action, dataModel };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=a2ui.js.map
|
package/dist/a2ui.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2ui.js","sourceRoot":"","sources":["../src/a2ui.ts"],"names":[],"mappings":"AAkBA,kEAAkE;AAClE,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEvD,kEAAkE;AAClE,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,iFAAiF;AACjF,MAAM,CAAC,MAAM,qBAAqB,GAAG,iEAAiE,CAAC;AAEvG,wGAAwG;AACxG,MAAM,CAAC,MAAM,qBAAqB,GAAG,qCAAqC,CAAC;AAE3E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,WAA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AC"}
|
package/dist/buttons.d.ts
CHANGED
|
@@ -17,7 +17,12 @@ export declare const BUTTONS_FENCE = "buttons";
|
|
|
17
17
|
* ("avoid expecting customers to type responses that could be handled with a
|
|
18
18
|
* tap", 2 to 5 options), Google's RCS suggestions ("design for the most
|
|
19
19
|
* common responses"; never "mimic phone trees"), WhatsApp's reply and
|
|
20
|
-
* call-to-action buttons (distinct options; one call to action).
|
|
20
|
+
* call-to-action buttons (distinct options; one call to action). The line
|
|
21
|
+
* between a url button and a link is Messenger's ("use URL buttons for tasks
|
|
22
|
+
* that you want completed on your website (for example, purchases, or
|
|
23
|
+
* account linking)") and Apple's ("all URLs should be sent as Rich Links";
|
|
24
|
+
* product pages, support articles, self-serve resources): a task goes on a
|
|
25
|
+
* button, a thing to look at goes out as a link card.
|
|
21
26
|
*/
|
|
22
27
|
export declare const BUTTONS_GUIDANCE: string;
|
|
23
28
|
/**
|
|
@@ -42,7 +47,7 @@ export interface SplitButtons {
|
|
|
42
47
|
* part, or explains why it cannot. The checks are the server's own, so a bad
|
|
43
48
|
* value fails here with a readable reason instead of a 400 from the API.
|
|
44
49
|
*/
|
|
45
|
-
export declare const buttonsPart: (parsed: unknown
|
|
50
|
+
export declare const buttonsPart: (parsed: unknown) => ButtonsPart | string;
|
|
46
51
|
/** Parses the body of a buttons block, JSON, into a `buttons` part. */
|
|
47
52
|
export declare const parseButtonsBlock: (body: string) => ButtonsPart | string;
|
|
48
53
|
/**
|
package/dist/buttons.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buttons.d.ts","sourceRoot":"","sources":["../src/buttons.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,YAAY,CAAC;AAE1D;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC
|
|
1
|
+
{"version":3,"file":"buttons.d.ts","sourceRoot":"","sources":["../src/buttons.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,YAAY,CAAC;AAE1D;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,QAQlB,CAAC;AAEZ;;;GAGG;AACH,eAAO,MAAM,yBAAyB,QAGwB,CAAC;AAE/D,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,qBAAqB,OAAQ,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAgCD;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,OAAO,KAAG,WAAW,GAAG,MAiB3D,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,WAAW,GAAG,MAQ9D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,YAU7C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,MAAM,EACZ,SAAS,WAAW,GAAG,SAAS,EAChC,cAAgC,KAC/B,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,CAGrD,CAAC"}
|
package/dist/buttons.js
CHANGED
|
@@ -16,15 +16,21 @@ export const BUTTONS_FENCE = "buttons";
|
|
|
16
16
|
* ("avoid expecting customers to type responses that could be handled with a
|
|
17
17
|
* tap", 2 to 5 options), Google's RCS suggestions ("design for the most
|
|
18
18
|
* common responses"; never "mimic phone trees"), WhatsApp's reply and
|
|
19
|
-
* call-to-action buttons (distinct options; one call to action).
|
|
19
|
+
* call-to-action buttons (distinct options; one call to action). The line
|
|
20
|
+
* between a url button and a link is Messenger's ("use URL buttons for tasks
|
|
21
|
+
* that you want completed on your website (for example, purchases, or
|
|
22
|
+
* account linking)") and Apple's ("all URLs should be sent as Rich Links";
|
|
23
|
+
* product pages, support articles, self-serve resources): a task goes on a
|
|
24
|
+
* button, a thing to look at goes out as a link card.
|
|
20
25
|
*/
|
|
21
26
|
export const BUTTONS_GUIDANCE = [
|
|
22
27
|
"Send buttons when your message ends with a question the person can answer by picking one of 2 to 5 short options you already know: yes or no, choosing between things you named, picking a next step, or a multiple-choice question in a quiz. Each label is a complete answer, so a tap replaces typing. Put the question in text beside the buttons.",
|
|
23
|
-
"Send one button when there is one thing to do next. A url button
|
|
28
|
+
"Send one button when there is one thing to do next. A url button is for a task the person completes on a web page: pay, sign in, connect an account, open their booking or order, track a package. Its label names the action, not the site. A plain button confirms one step: Start, Done, Continue. Do not ask \"ready?\" when a single button does the job.",
|
|
29
|
+
"A link is for something the person will look at or read: an article, a listing, a video, a place, a product page, a support article. Send it as a link on its own, so it draws as a card with the page's title and image; never paste a bare URL into your words, and send one link per message. When the page is where the person does something, send a url button; when the page is the thing you are showing them, send a link.",
|
|
24
30
|
"Do not send buttons when the answer is open-ended, when your options are not the full set of likely answers, or when you are not asking anything and there is nothing to do. One question or one action per message; never a menu of things you can do, and never as decoration.",
|
|
25
|
-
"If you would otherwise write \"reply 1, 2 or 3\"
|
|
31
|
+
"If you would otherwise write \"reply 1, 2 or 3\" or list choices for the person to type, send buttons instead. If the person asks for buttons, send them.",
|
|
26
32
|
"A tap comes back to you as an ordinary message whose text is the label. Labels are at most 80 characters.",
|
|
27
|
-
"Buttons disappear once tapped.
|
|
33
|
+
"Buttons disappear once tapped.",
|
|
28
34
|
].join(" ");
|
|
29
35
|
/**
|
|
30
36
|
* How a text-only agent puts buttons under its answer: the same words for
|
|
@@ -32,8 +38,7 @@ export const BUTTONS_GUIDANCE = [
|
|
|
32
38
|
*/
|
|
33
39
|
export const BUTTONS_BLOCK_INSTRUCTION = "To put buttons under your answer, end it with a fenced code block tagged `" + BUTTONS_FENCE + "` "
|
|
34
40
|
+ "holding a JSON array of 1 to 5 items, each {\"label\": \"...\"} or {\"label\": \"...\", \"url\": \"https://...\"}. "
|
|
35
|
-
+ "The block is removed from the text and drawn as buttons.
|
|
36
|
-
+ "To keep the buttons on screen after a tap, write the block as {\"one_time\": false, \"items\": [...]} instead of a bare array.";
|
|
41
|
+
+ "The block is removed from the text and drawn as buttons.";
|
|
37
42
|
/** The server's limits (Discord's button limits): items 1..5, label 1..80, url <= 2048. */
|
|
38
43
|
export const BUTTONS_MAX_ITEMS = 5;
|
|
39
44
|
export const BUTTON_LABEL_MAX_LENGTH = 80;
|
|
@@ -73,16 +78,13 @@ const asItem = (value, index) => {
|
|
|
73
78
|
* part, or explains why it cannot. The checks are the server's own, so a bad
|
|
74
79
|
* value fails here with a readable reason instead of a 400 from the API.
|
|
75
80
|
*/
|
|
76
|
-
export const buttonsPart = (parsed
|
|
81
|
+
export const buttonsPart = (parsed) => {
|
|
77
82
|
const wrapped = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)
|
|
78
83
|
? parsed
|
|
79
84
|
: undefined;
|
|
80
85
|
const items = Array.isArray(parsed) ? parsed : Array.isArray(wrapped?.items) ? wrapped.items : undefined;
|
|
81
86
|
if (items === undefined)
|
|
82
87
|
return "the buttons block must be a JSON array of items";
|
|
83
|
-
const one_time = oneTime ?? wrapped?.one_time;
|
|
84
|
-
if (one_time !== undefined && typeof one_time !== "boolean")
|
|
85
|
-
return "one_time must be true or false";
|
|
86
88
|
if (items.length === 0)
|
|
87
89
|
return "the buttons block has no items";
|
|
88
90
|
if (items.length > BUTTONS_MAX_ITEMS) {
|
|
@@ -95,7 +97,7 @@ export const buttonsPart = (parsed, oneTime) => {
|
|
|
95
97
|
return item;
|
|
96
98
|
result.push(item);
|
|
97
99
|
}
|
|
98
|
-
return { type: "buttons", items: result
|
|
100
|
+
return { type: "buttons", items: result };
|
|
99
101
|
};
|
|
100
102
|
/** Parses the body of a buttons block, JSON, into a `buttons` part. */
|
|
101
103
|
export const parseButtonsBlock = (body) => {
|
package/dist/buttons.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buttons.js","sourceRoot":"","sources":["../src/buttons.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC
|
|
1
|
+
{"version":3,"file":"buttons.js","sourceRoot":"","sources":["../src/buttons.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,wVAAwV;IACxV,gWAAgW;IAChW,qaAAqa;IACra,kRAAkR;IAClR,2JAA2J;IAC3J,2GAA2G;IAC3G,gCAAgC;CACjC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GACpC,4EAA4E,GAAG,aAAa,GAAG,IAAI;MACjG,qHAAqH;MACrH,0DAA0D,CAAC;AAE/D,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAW3C,MAAM,KAAK,GAAG,IAAI,MAAM,CACtB,0BAA0B,GAAG,aAAa,GAAG,iEAAiE,EAC9G,GAAG,CACJ,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,KAAa,EAAuB,EAAE;IACpE,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,K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,KAAK,CAAC;IACzE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACnC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,IAAY,EACZ,OAAgC,EAChC,KAAK,GAAG,MAAM,CAAC,iBAAiB,EACsB,EAAE,CAAC;IACzD,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACpF,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;CAC9B,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { CallRoomClientFrame, CallRoomEndedFrame, CallRoomErrorFrame, CallRoomIceServer, CallRoomIceServersFrame, CallRoomServerAnswerFrame, CallRoomServerFrame, CallRoomStateFrame, CallRoomSubscriptionOfferFrame } from "../types.js";
|
|
2
|
+
import type { WebSocketConstructor } from "../websocket.js";
|
|
3
|
+
export interface CallRoomOptions {
|
|
4
|
+
/** Abort closes the signaling socket without ending the Call. */
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
/** Override the Node WebSocket implementation, primarily for tests. */
|
|
7
|
+
WebSocket?: WebSocketConstructor;
|
|
8
|
+
/** Client heartbeat cadence. Relay's room heartbeat frame has no payload. */
|
|
9
|
+
heartbeatIntervalMs?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Called once per unknown server frame type, which the room ignores.
|
|
12
|
+
* Defaults to `console.warn`.
|
|
13
|
+
*/
|
|
14
|
+
onWarning?: (message: string) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface CallRoomCloseEvent {
|
|
17
|
+
code: number;
|
|
18
|
+
reason: string;
|
|
19
|
+
wasClean: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The room socket dropped, or an attempt to open one failed, and the room
|
|
23
|
+
* opens a new one after `delayMs`. Media rides the SFU, not this socket, so the
|
|
24
|
+
* Call and its WebRTC session continue; nothing is re-offered.
|
|
25
|
+
*/
|
|
26
|
+
export interface CallRoomReconnectingEvent {
|
|
27
|
+
/** 1 for the first retry; the count resets once a socket stays open 5 s. */
|
|
28
|
+
attempt: number;
|
|
29
|
+
delayMs: number;
|
|
30
|
+
/** The close that caused the retry; absent when an attempt failed before opening. */
|
|
31
|
+
close?: CallRoomCloseEvent;
|
|
32
|
+
/** Why the failed attempt did not open (connect timeout, handshake error). */
|
|
33
|
+
error?: Error;
|
|
34
|
+
}
|
|
35
|
+
export type CallRoomConnectionState = "idle" | "connecting" | "open" | "reconnecting" | "closed";
|
|
36
|
+
export type CallRoomEventMap = {
|
|
37
|
+
open: [];
|
|
38
|
+
reconnecting: [CallRoomReconnectingEvent];
|
|
39
|
+
/** The room's STUN/TURN servers, sent after every accepted `join`, before its `roomState`. */
|
|
40
|
+
iceServers: [CallRoomIceServersFrame];
|
|
41
|
+
roomState: [CallRoomStateFrame];
|
|
42
|
+
offer: [CallRoomSubscriptionOfferFrame];
|
|
43
|
+
answer: [CallRoomServerAnswerFrame];
|
|
44
|
+
ended: [CallRoomEndedFrame];
|
|
45
|
+
error: [CallRoomErrorFrame | Error];
|
|
46
|
+
/** The room socket closed and the room will not reopen it by itself. */
|
|
47
|
+
close: [CallRoomCloseEvent];
|
|
48
|
+
};
|
|
49
|
+
type CallRoomEvent = keyof CallRoomEventMap;
|
|
50
|
+
type Listener<K extends CallRoomEvent> = (...args: CallRoomEventMap[K]) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Validate one server frame before exposing it to application code. Returns
|
|
53
|
+
* `null` for Relay's echoed heartbeat (not part of the public server-frame
|
|
54
|
+
* union) and for a frame type this client does not know (a newer Relay's
|
|
55
|
+
* frame, ignored). Throws for a known frame type whose shape is invalid.
|
|
56
|
+
*/
|
|
57
|
+
export declare const parseCallRoomServerFrame: (value: unknown) => CallRoomServerFrame | null;
|
|
58
|
+
/**
|
|
59
|
+
* Authenticated JSON signaling socket for one Relay Call participant.
|
|
60
|
+
*
|
|
61
|
+
* The room reopens its socket after any close that neither this client nor the
|
|
62
|
+
* server asked for, with PartySocket's numbers (PROTOCOL.md section 5): first
|
|
63
|
+
* retry after 3000 ms, then x1.3, capped at 10000 ms, a 4000 ms connect
|
|
64
|
+
* timeout, the retry count reset once a socket stays open 5000 ms, and no
|
|
65
|
+
* retry limit. On every open it sends `join`, then `userUpdate` with the last
|
|
66
|
+
* muted/video state, then the frames queued while closed. Media is never
|
|
67
|
+
* re-offered by a socket-only reconnect.
|
|
68
|
+
*/
|
|
69
|
+
export declare class CallRoom {
|
|
70
|
+
#private;
|
|
71
|
+
readonly callID: string;
|
|
72
|
+
readonly url: string;
|
|
73
|
+
state: CallRoomStateFrame | null;
|
|
74
|
+
/**
|
|
75
|
+
* The STUN/TURN servers from the room's latest `iceServers` frame, or `null`
|
|
76
|
+
* before the first one. Relay sends fresh ones on every join, reconnects
|
|
77
|
+
* included, so read this again before building each new peer connection.
|
|
78
|
+
*/
|
|
79
|
+
iceServers: CallRoomIceServer[] | null;
|
|
80
|
+
constructor(callID: string, baseURL: string, apiKey: string, options?: CallRoomOptions);
|
|
81
|
+
/** `reconnecting` while the room waits to reopen a dropped socket. */
|
|
82
|
+
get connectionState(): CallRoomConnectionState;
|
|
83
|
+
on<K extends CallRoomEvent>(event: K, listener: Listener<K>): this;
|
|
84
|
+
off<K extends CallRoomEvent>(event: K, listener: Listener<K>): this;
|
|
85
|
+
/** Resolves on the first open; a failed attempt is retried, not thrown. */
|
|
86
|
+
connect(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Open a new signaling socket now, keeping application/WebRTC state alive.
|
|
89
|
+
* Relay accepts the new authenticated socket before the previous one closes,
|
|
90
|
+
* so an active Call is not interpreted as having lost its participant. Same
|
|
91
|
+
* path as the automatic reconnect (PartySocket `reconnect()`: retry count
|
|
92
|
+
* reset, no delay); if the new socket fails while the old one is still open,
|
|
93
|
+
* the old one stays and this rejects.
|
|
94
|
+
*/
|
|
95
|
+
reconnect(): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Send one frame. While the socket is reopening the frame is queued and sent
|
|
98
|
+
* after `join` on the next open (PartySocket's queue); heartbeats are dropped.
|
|
99
|
+
*/
|
|
100
|
+
send(frame: CallRoomClientFrame): void;
|
|
101
|
+
connected(): void;
|
|
102
|
+
userUpdate(update: {
|
|
103
|
+
muted: boolean;
|
|
104
|
+
video?: boolean;
|
|
105
|
+
}): void;
|
|
106
|
+
end(): void;
|
|
107
|
+
close(code?: number, reason?: string): void;
|
|
108
|
+
}
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=call-room.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-room.d.ts","sourceRoot":"","sources":["../../src/calls/call-room.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,mBAAmB,EACnB,kBAAkB,EAElB,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EAEvB,yBAAyB,EACzB,mBAAmB,EACnB,kBAAkB,EAClB,8BAA8B,EAE/B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,iBAAiB,CAAC;AA8B3E,MAAM,WAAW,eAAe;IAC9B,iEAAiE;IACjE,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,uEAAuE;IACvE,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,6EAA6E;IAC7E,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,M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