@atlaskit/rovo-triggers 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/rovo-triggers
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#162886](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/162886)
8
+ [`59490f4204eea`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/59490f4204eea) -
9
+ [https://product-fabric.atlassian.net/browse/EDF-1889](EDF-1889) - add subscription to rovo agent
10
+ changes into the Editor AI plugin
11
+
12
+ ## 1.2.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#162034](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/162034)
17
+ [`b9b034c26952f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b9b034c26952f) -
18
+ Support publishing pubsub event through postMessage, and with acknowledgment receipt if the
19
+ postMessage event is published. Will be used for smart-card agent embed inside iframe, as
20
+ communication between iframe and the parent window.
21
+
3
22
  ## 1.1.0
4
23
 
5
24
  ### Minor Changes
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useRovoPostMessageToPubsub = exports.isAllowedOrigin = exports.RovoPostMessagePubsubListener = exports.ROVO_POST_MESSAGE_EVENT_TYPE = exports.ROVO_POST_MESSAGE_ACK_EVENT_TYPE = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _bindEventListener = require("bind-event-listener");
11
+ var _main = require("../../../main");
12
+ var ROVO_POST_MESSAGE_EVENT_TYPE = exports.ROVO_POST_MESSAGE_EVENT_TYPE = 'rovo-post-message';
13
+ var ROVO_POST_MESSAGE_ACK_EVENT_TYPE = exports.ROVO_POST_MESSAGE_ACK_EVENT_TYPE = 'rovo-post-message-ack';
14
+ // allow subdomains of these domains
15
+ var allowedSubdomains = ['.jira-dev.com', '.atlassian.com', '.atlassian.net', '.atl-paas.net'];
16
+ var allowedOrigins = ['bitbucket.org', 'trello.com'];
17
+ var isAllowedOrigin = exports.isAllowedOrigin = function isAllowedOrigin(origin) {
18
+ if (!origin) {
19
+ return false;
20
+ }
21
+ var url = new URL(origin);
22
+ var hostname = url.hostname;
23
+ return hostname === 'localhost' || url.protocol === 'https:' && (allowedSubdomains.some(function (subdomain) {
24
+ return hostname.endsWith(subdomain);
25
+ }) || allowedOrigins.includes(hostname));
26
+ };
27
+ var RovoPostMessagePubsubListener = exports.RovoPostMessagePubsubListener = function RovoPostMessagePubsubListener() {
28
+ var publish = (0, _main.usePublish)('ai-mate');
29
+ (0, _react.useEffect)(function () {
30
+ var handlerUnbind = (0, _bindEventListener.bind)(window, {
31
+ type: 'message',
32
+ listener: function listener(event) {
33
+ if (!isAllowedOrigin(event.origin)) {
34
+ return;
35
+ }
36
+ if (event.data.eventType === ROVO_POST_MESSAGE_EVENT_TYPE) {
37
+ var _event$source;
38
+ var eventData = event.data;
39
+ var ackPayload = {
40
+ eventType: ROVO_POST_MESSAGE_ACK_EVENT_TYPE,
41
+ payloadId: eventData.payloadId
42
+ };
43
+ (_event$source = event.source) === null || _event$source === void 0 || _event$source.postMessage(ackPayload);
44
+ publish(event.data.payload);
45
+ }
46
+ }
47
+ });
48
+ return handlerUnbind;
49
+ }, [publish]);
50
+ return null;
51
+ };
52
+ var TIMEOUT_WAIT_FOR_ACK = 100;
53
+
54
+ /**
55
+ * Hook to send a publish event to parent iframe using postMessage
56
+ * Only supports 1 pubsub event at a time and waits for acknowledgment or timed out
57
+ */
58
+ var useRovoPostMessageToPubsub = exports.useRovoPostMessageToPubsub = function useRovoPostMessageToPubsub() {
59
+ var onAcknowledgeTimeoutTimeoutRef = (0, _react.useRef)(null);
60
+ var _useState = (0, _react.useState)(false),
61
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
62
+ isWaitingForAck = _useState2[0],
63
+ setIsWaitingForAck = _useState2[1];
64
+ (0, _react.useEffect)(function () {
65
+ var handlerUnbind = (0, _bindEventListener.bind)(window, {
66
+ type: 'message',
67
+ // handler for acknowledgment from parent
68
+ listener: function listener(event) {
69
+ if (!isAllowedOrigin(event.origin)) {
70
+ return;
71
+ }
72
+ if (event.data.eventType !== ROVO_POST_MESSAGE_ACK_EVENT_TYPE || onAcknowledgeTimeoutTimeoutRef.current === null) {
73
+ return;
74
+ }
75
+ var eventData = event.data;
76
+
77
+ // if the parent acknowledges different payload (e.g. from different hook instance)
78
+ // disregard the event
79
+ if (eventData.payloadId !== onAcknowledgeTimeoutTimeoutRef.current.lastPayloadId) {
80
+ return;
81
+ }
82
+
83
+ // Clear the onAcknowledgeTimeoutTimeout if acknowledgment is received
84
+ clearTimeout(onAcknowledgeTimeoutTimeoutRef.current.timeout);
85
+ onAcknowledgeTimeoutTimeoutRef.current = null;
86
+ setIsWaitingForAck(false);
87
+ }
88
+ });
89
+ return handlerUnbind;
90
+ }, []);
91
+ var publishWithPostMessage = (0, _react.useCallback)(function (_ref) {
92
+ var _ref$targetWindow = _ref.targetWindow,
93
+ targetWindow = _ref$targetWindow === void 0 ? window.parent : _ref$targetWindow,
94
+ payload = _ref.payload,
95
+ onAcknowledgeTimeout = _ref.onAcknowledgeTimeout;
96
+ if (!targetWindow) {
97
+ return;
98
+ }
99
+ var payloadId = Math.floor(Math.random() * 1e6).toString();
100
+ targetWindow.postMessage({
101
+ eventType: ROVO_POST_MESSAGE_EVENT_TYPE,
102
+ payload: payload,
103
+ payloadId: payloadId
104
+ }, '*');
105
+
106
+ // waiting for acknowledgment from parent
107
+ // if no acknowledgment is received, call onAcknowledgeTimeout
108
+ setIsWaitingForAck(true);
109
+ var timeout = window.setTimeout(function () {
110
+ onAcknowledgeTimeout({
111
+ payload: payload
112
+ });
113
+ onAcknowledgeTimeoutTimeoutRef.current = null;
114
+ setIsWaitingForAck(false);
115
+ }, TIMEOUT_WAIT_FOR_ACK);
116
+ onAcknowledgeTimeoutTimeoutRef.current = {
117
+ timeout: timeout,
118
+ lastPayloadId: payloadId
119
+ };
120
+ }, []);
121
+ return {
122
+ publishWithPostMessage: publishWithPostMessage,
123
+ isWaitingForAck: isWaitingForAck
124
+ };
125
+ };
package/dist/cjs/index.js CHANGED
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "RovoPostMessagePubsubListener", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _postMessageToPubsub.RovoPostMessagePubsubListener;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "Subscriber", {
7
13
  enumerable: true,
8
14
  get: function get() {
@@ -51,6 +57,12 @@ Object.defineProperty(exports, "usePublish", {
51
57
  return _main.usePublish;
52
58
  }
53
59
  });
60
+ Object.defineProperty(exports, "useRovoPostMessageToPubsub", {
61
+ enumerable: true,
62
+ get: function get() {
63
+ return _postMessageToPubsub.useRovoPostMessageToPubsub;
64
+ }
65
+ });
54
66
  Object.defineProperty(exports, "useSubscribe", {
55
67
  enumerable: true,
56
68
  get: function get() {
@@ -64,4 +76,5 @@ Object.defineProperty(exports, "useSubscribeAll", {
64
76
  }
65
77
  });
66
78
  var _main = require("./main");
67
- var _params = require("./common/utils/params");
79
+ var _params = require("./common/utils/params");
80
+ var _postMessageToPubsub = require("./common/utils/post-message-to-pubsub");
@@ -0,0 +1,112 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { bind } from 'bind-event-listener';
3
+ import { usePublish } from '../../../main';
4
+ export const ROVO_POST_MESSAGE_EVENT_TYPE = 'rovo-post-message';
5
+ export const ROVO_POST_MESSAGE_ACK_EVENT_TYPE = 'rovo-post-message-ack';
6
+ // allow subdomains of these domains
7
+ const allowedSubdomains = ['.jira-dev.com', '.atlassian.com', '.atlassian.net', '.atl-paas.net'];
8
+ const allowedOrigins = ['bitbucket.org', 'trello.com'];
9
+ export const isAllowedOrigin = origin => {
10
+ if (!origin) {
11
+ return false;
12
+ }
13
+ const url = new URL(origin);
14
+ const hostname = url.hostname;
15
+ return hostname === 'localhost' || url.protocol === 'https:' && (allowedSubdomains.some(subdomain => hostname.endsWith(subdomain)) || allowedOrigins.includes(hostname));
16
+ };
17
+ export const RovoPostMessagePubsubListener = () => {
18
+ const publish = usePublish('ai-mate');
19
+ useEffect(() => {
20
+ const handlerUnbind = bind(window, {
21
+ type: 'message',
22
+ listener: event => {
23
+ if (!isAllowedOrigin(event.origin)) {
24
+ return;
25
+ }
26
+ if (event.data.eventType === ROVO_POST_MESSAGE_EVENT_TYPE) {
27
+ var _event$source;
28
+ const eventData = event.data;
29
+ const ackPayload = {
30
+ eventType: ROVO_POST_MESSAGE_ACK_EVENT_TYPE,
31
+ payloadId: eventData.payloadId
32
+ };
33
+ (_event$source = event.source) === null || _event$source === void 0 ? void 0 : _event$source.postMessage(ackPayload);
34
+ publish(event.data.payload);
35
+ }
36
+ }
37
+ });
38
+ return handlerUnbind;
39
+ }, [publish]);
40
+ return null;
41
+ };
42
+ const TIMEOUT_WAIT_FOR_ACK = 100;
43
+
44
+ /**
45
+ * Hook to send a publish event to parent iframe using postMessage
46
+ * Only supports 1 pubsub event at a time and waits for acknowledgment or timed out
47
+ */
48
+ export const useRovoPostMessageToPubsub = () => {
49
+ const onAcknowledgeTimeoutTimeoutRef = useRef(null);
50
+ const [isWaitingForAck, setIsWaitingForAck] = useState(false);
51
+ useEffect(() => {
52
+ const handlerUnbind = bind(window, {
53
+ type: 'message',
54
+ // handler for acknowledgment from parent
55
+ listener: event => {
56
+ if (!isAllowedOrigin(event.origin)) {
57
+ return;
58
+ }
59
+ if (event.data.eventType !== ROVO_POST_MESSAGE_ACK_EVENT_TYPE || onAcknowledgeTimeoutTimeoutRef.current === null) {
60
+ return;
61
+ }
62
+ const eventData = event.data;
63
+
64
+ // if the parent acknowledges different payload (e.g. from different hook instance)
65
+ // disregard the event
66
+ if (eventData.payloadId !== onAcknowledgeTimeoutTimeoutRef.current.lastPayloadId) {
67
+ return;
68
+ }
69
+
70
+ // Clear the onAcknowledgeTimeoutTimeout if acknowledgment is received
71
+ clearTimeout(onAcknowledgeTimeoutTimeoutRef.current.timeout);
72
+ onAcknowledgeTimeoutTimeoutRef.current = null;
73
+ setIsWaitingForAck(false);
74
+ }
75
+ });
76
+ return handlerUnbind;
77
+ }, []);
78
+ const publishWithPostMessage = useCallback(({
79
+ targetWindow = window.parent,
80
+ payload,
81
+ onAcknowledgeTimeout
82
+ }) => {
83
+ if (!targetWindow) {
84
+ return;
85
+ }
86
+ const payloadId = Math.floor(Math.random() * 1e6).toString();
87
+ targetWindow.postMessage({
88
+ eventType: ROVO_POST_MESSAGE_EVENT_TYPE,
89
+ payload,
90
+ payloadId
91
+ }, '*');
92
+
93
+ // waiting for acknowledgment from parent
94
+ // if no acknowledgment is received, call onAcknowledgeTimeout
95
+ setIsWaitingForAck(true);
96
+ const timeout = window.setTimeout(() => {
97
+ onAcknowledgeTimeout({
98
+ payload
99
+ });
100
+ onAcknowledgeTimeoutTimeoutRef.current = null;
101
+ setIsWaitingForAck(false);
102
+ }, TIMEOUT_WAIT_FOR_ACK);
103
+ onAcknowledgeTimeoutTimeoutRef.current = {
104
+ timeout,
105
+ lastPayloadId: payloadId
106
+ };
107
+ }, []);
108
+ return {
109
+ publishWithPostMessage,
110
+ isWaitingForAck
111
+ };
112
+ };
@@ -1,2 +1,3 @@
1
1
  export { usePublish, useSubscribe, useSubscribeAll, Subscriber } from './main';
2
- export { getRovoParams, updatePageRovoParams, addRovoParamsToUrl, assertOnlySpecificFieldsDefined, encodeRovoParams, getListOfRovoParams } from './common/utils/params';
2
+ export { getRovoParams, updatePageRovoParams, addRovoParamsToUrl, assertOnlySpecificFieldsDefined, encodeRovoParams, getListOfRovoParams } from './common/utils/params';
3
+ export { useRovoPostMessageToPubsub, RovoPostMessagePubsubListener } from './common/utils/post-message-to-pubsub';
@@ -0,0 +1,118 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { bind } from 'bind-event-listener';
4
+ import { usePublish } from '../../../main';
5
+ export var ROVO_POST_MESSAGE_EVENT_TYPE = 'rovo-post-message';
6
+ export var ROVO_POST_MESSAGE_ACK_EVENT_TYPE = 'rovo-post-message-ack';
7
+ // allow subdomains of these domains
8
+ var allowedSubdomains = ['.jira-dev.com', '.atlassian.com', '.atlassian.net', '.atl-paas.net'];
9
+ var allowedOrigins = ['bitbucket.org', 'trello.com'];
10
+ export var isAllowedOrigin = function isAllowedOrigin(origin) {
11
+ if (!origin) {
12
+ return false;
13
+ }
14
+ var url = new URL(origin);
15
+ var hostname = url.hostname;
16
+ return hostname === 'localhost' || url.protocol === 'https:' && (allowedSubdomains.some(function (subdomain) {
17
+ return hostname.endsWith(subdomain);
18
+ }) || allowedOrigins.includes(hostname));
19
+ };
20
+ export var RovoPostMessagePubsubListener = function RovoPostMessagePubsubListener() {
21
+ var publish = usePublish('ai-mate');
22
+ useEffect(function () {
23
+ var handlerUnbind = bind(window, {
24
+ type: 'message',
25
+ listener: function listener(event) {
26
+ if (!isAllowedOrigin(event.origin)) {
27
+ return;
28
+ }
29
+ if (event.data.eventType === ROVO_POST_MESSAGE_EVENT_TYPE) {
30
+ var _event$source;
31
+ var eventData = event.data;
32
+ var ackPayload = {
33
+ eventType: ROVO_POST_MESSAGE_ACK_EVENT_TYPE,
34
+ payloadId: eventData.payloadId
35
+ };
36
+ (_event$source = event.source) === null || _event$source === void 0 || _event$source.postMessage(ackPayload);
37
+ publish(event.data.payload);
38
+ }
39
+ }
40
+ });
41
+ return handlerUnbind;
42
+ }, [publish]);
43
+ return null;
44
+ };
45
+ var TIMEOUT_WAIT_FOR_ACK = 100;
46
+
47
+ /**
48
+ * Hook to send a publish event to parent iframe using postMessage
49
+ * Only supports 1 pubsub event at a time and waits for acknowledgment or timed out
50
+ */
51
+ export var useRovoPostMessageToPubsub = function useRovoPostMessageToPubsub() {
52
+ var onAcknowledgeTimeoutTimeoutRef = useRef(null);
53
+ var _useState = useState(false),
54
+ _useState2 = _slicedToArray(_useState, 2),
55
+ isWaitingForAck = _useState2[0],
56
+ setIsWaitingForAck = _useState2[1];
57
+ useEffect(function () {
58
+ var handlerUnbind = bind(window, {
59
+ type: 'message',
60
+ // handler for acknowledgment from parent
61
+ listener: function listener(event) {
62
+ if (!isAllowedOrigin(event.origin)) {
63
+ return;
64
+ }
65
+ if (event.data.eventType !== ROVO_POST_MESSAGE_ACK_EVENT_TYPE || onAcknowledgeTimeoutTimeoutRef.current === null) {
66
+ return;
67
+ }
68
+ var eventData = event.data;
69
+
70
+ // if the parent acknowledges different payload (e.g. from different hook instance)
71
+ // disregard the event
72
+ if (eventData.payloadId !== onAcknowledgeTimeoutTimeoutRef.current.lastPayloadId) {
73
+ return;
74
+ }
75
+
76
+ // Clear the onAcknowledgeTimeoutTimeout if acknowledgment is received
77
+ clearTimeout(onAcknowledgeTimeoutTimeoutRef.current.timeout);
78
+ onAcknowledgeTimeoutTimeoutRef.current = null;
79
+ setIsWaitingForAck(false);
80
+ }
81
+ });
82
+ return handlerUnbind;
83
+ }, []);
84
+ var publishWithPostMessage = useCallback(function (_ref) {
85
+ var _ref$targetWindow = _ref.targetWindow,
86
+ targetWindow = _ref$targetWindow === void 0 ? window.parent : _ref$targetWindow,
87
+ payload = _ref.payload,
88
+ onAcknowledgeTimeout = _ref.onAcknowledgeTimeout;
89
+ if (!targetWindow) {
90
+ return;
91
+ }
92
+ var payloadId = Math.floor(Math.random() * 1e6).toString();
93
+ targetWindow.postMessage({
94
+ eventType: ROVO_POST_MESSAGE_EVENT_TYPE,
95
+ payload: payload,
96
+ payloadId: payloadId
97
+ }, '*');
98
+
99
+ // waiting for acknowledgment from parent
100
+ // if no acknowledgment is received, call onAcknowledgeTimeout
101
+ setIsWaitingForAck(true);
102
+ var timeout = window.setTimeout(function () {
103
+ onAcknowledgeTimeout({
104
+ payload: payload
105
+ });
106
+ onAcknowledgeTimeoutTimeoutRef.current = null;
107
+ setIsWaitingForAck(false);
108
+ }, TIMEOUT_WAIT_FOR_ACK);
109
+ onAcknowledgeTimeoutTimeoutRef.current = {
110
+ timeout: timeout,
111
+ lastPayloadId: payloadId
112
+ };
113
+ }, []);
114
+ return {
115
+ publishWithPostMessage: publishWithPostMessage,
116
+ isWaitingForAck: isWaitingForAck
117
+ };
118
+ };
package/dist/esm/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { usePublish, useSubscribe, useSubscribeAll, Subscriber } from './main';
2
- export { getRovoParams, updatePageRovoParams, addRovoParamsToUrl, assertOnlySpecificFieldsDefined, encodeRovoParams, getListOfRovoParams } from './common/utils/params';
2
+ export { getRovoParams, updatePageRovoParams, addRovoParamsToUrl, assertOnlySpecificFieldsDefined, encodeRovoParams, getListOfRovoParams } from './common/utils/params';
3
+ export { useRovoPostMessageToPubsub, RovoPostMessagePubsubListener } from './common/utils/post-message-to-pubsub';
@@ -0,0 +1,19 @@
1
+ import { type Payload } from '../../../types';
2
+ export declare const ROVO_POST_MESSAGE_EVENT_TYPE = "rovo-post-message";
3
+ export declare const ROVO_POST_MESSAGE_ACK_EVENT_TYPE = "rovo-post-message-ack";
4
+ export declare const isAllowedOrigin: (origin: string | undefined) => boolean;
5
+ export declare const RovoPostMessagePubsubListener: () => null;
6
+ /**
7
+ * Hook to send a publish event to parent iframe using postMessage
8
+ * Only supports 1 pubsub event at a time and waits for acknowledgment or timed out
9
+ */
10
+ export declare const useRovoPostMessageToPubsub: () => {
11
+ publishWithPostMessage: ({ targetWindow, payload, onAcknowledgeTimeout, }: {
12
+ targetWindow?: Window | undefined;
13
+ payload: Payload;
14
+ onAcknowledgeTimeout: (params: {
15
+ payload: Payload;
16
+ }) => void;
17
+ }) => void;
18
+ isWaitingForAck: boolean;
19
+ };
@@ -2,3 +2,4 @@ export { usePublish, useSubscribe, useSubscribeAll, Subscriber } from './main';
2
2
  export type { Payload, Callback, Topic, EditorContextPayloadData, BrowserContextPayloadData, } from './types';
3
3
  export { getRovoParams, updatePageRovoParams, addRovoParamsToUrl, assertOnlySpecificFieldsDefined, encodeRovoParams, getListOfRovoParams, } from './common/utils/params';
4
4
  export type { RovoChatParams, RovoChatPathway } from './common/utils/params/types';
5
+ export { useRovoPostMessageToPubsub, RovoPostMessagePubsubListener, } from './common/utils/post-message-to-pubsub';
@@ -58,6 +58,13 @@ export type EditorSuggestionPayload = PayloadCore<'editor-suggestion', {
58
58
  content: string;
59
59
  agentId?: string;
60
60
  }>;
61
+ export type EditorAgentChangedPayload = PayloadCore<'agent-changed', {
62
+ agent: {
63
+ id: string;
64
+ name: string;
65
+ identityAccountId?: string | null;
66
+ } | null;
67
+ }>;
61
68
  export type ChatOpenPayload = PayloadCore<'chat-open', {
62
69
  channelId: string;
63
70
  agentId?: string;
@@ -66,7 +73,7 @@ export type ForgeAppAuthSuccess = PayloadCore<'forge-auth-success'>;
66
73
  export type ForgeAppAuthFailure = PayloadCore<'forge-auth-failure', {
67
74
  errorMessage: string | undefined;
68
75
  }>;
69
- export type Payload = MessageSendPayload | ChatNewPayload | ChatDraftPayload | EditorContextPayload | ChatOpenPayload | OpenBrowseAgentPayload | EditorSuggestionPayload | BrowserContextPayload | ForgeAppAuthSuccess | ForgeAppAuthFailure;
76
+ export type Payload = MessageSendPayload | ChatNewPayload | ChatDraftPayload | EditorContextPayload | ChatOpenPayload | OpenBrowseAgentPayload | EditorSuggestionPayload | EditorAgentChangedPayload | BrowserContextPayload | ForgeAppAuthSuccess | ForgeAppAuthFailure;
70
77
  export type Callback = (payload: Payload) => void;
71
78
  export type TopicEvents = {
72
79
  [key in Topic]?: Array<{
@@ -0,0 +1,19 @@
1
+ import { type Payload } from '../../../types';
2
+ export declare const ROVO_POST_MESSAGE_EVENT_TYPE = "rovo-post-message";
3
+ export declare const ROVO_POST_MESSAGE_ACK_EVENT_TYPE = "rovo-post-message-ack";
4
+ export declare const isAllowedOrigin: (origin: string | undefined) => boolean;
5
+ export declare const RovoPostMessagePubsubListener: () => null;
6
+ /**
7
+ * Hook to send a publish event to parent iframe using postMessage
8
+ * Only supports 1 pubsub event at a time and waits for acknowledgment or timed out
9
+ */
10
+ export declare const useRovoPostMessageToPubsub: () => {
11
+ publishWithPostMessage: ({ targetWindow, payload, onAcknowledgeTimeout, }: {
12
+ targetWindow?: Window | undefined;
13
+ payload: Payload;
14
+ onAcknowledgeTimeout: (params: {
15
+ payload: Payload;
16
+ }) => void;
17
+ }) => void;
18
+ isWaitingForAck: boolean;
19
+ };
@@ -2,3 +2,4 @@ export { usePublish, useSubscribe, useSubscribeAll, Subscriber } from './main';
2
2
  export type { Payload, Callback, Topic, EditorContextPayloadData, BrowserContextPayloadData, } from './types';
3
3
  export { getRovoParams, updatePageRovoParams, addRovoParamsToUrl, assertOnlySpecificFieldsDefined, encodeRovoParams, getListOfRovoParams, } from './common/utils/params';
4
4
  export type { RovoChatParams, RovoChatPathway } from './common/utils/params/types';
5
+ export { useRovoPostMessageToPubsub, RovoPostMessagePubsubListener, } from './common/utils/post-message-to-pubsub';
@@ -58,6 +58,13 @@ export type EditorSuggestionPayload = PayloadCore<'editor-suggestion', {
58
58
  content: string;
59
59
  agentId?: string;
60
60
  }>;
61
+ export type EditorAgentChangedPayload = PayloadCore<'agent-changed', {
62
+ agent: {
63
+ id: string;
64
+ name: string;
65
+ identityAccountId?: string | null;
66
+ } | null;
67
+ }>;
61
68
  export type ChatOpenPayload = PayloadCore<'chat-open', {
62
69
  channelId: string;
63
70
  agentId?: string;
@@ -66,7 +73,7 @@ export type ForgeAppAuthSuccess = PayloadCore<'forge-auth-success'>;
66
73
  export type ForgeAppAuthFailure = PayloadCore<'forge-auth-failure', {
67
74
  errorMessage: string | undefined;
68
75
  }>;
69
- export type Payload = MessageSendPayload | ChatNewPayload | ChatDraftPayload | EditorContextPayload | ChatOpenPayload | OpenBrowseAgentPayload | EditorSuggestionPayload | BrowserContextPayload | ForgeAppAuthSuccess | ForgeAppAuthFailure;
76
+ export type Payload = MessageSendPayload | ChatNewPayload | ChatDraftPayload | EditorContextPayload | ChatOpenPayload | OpenBrowseAgentPayload | EditorSuggestionPayload | EditorAgentChangedPayload | BrowserContextPayload | ForgeAppAuthSuccess | ForgeAppAuthFailure;
70
77
  export type Callback = (payload: Payload) => void;
71
78
  export type TopicEvents = {
72
79
  [key in Topic]?: Array<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/rovo-triggers",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Provides various trigger events to drive Rovo Chat functionality, such as a publish-subscribe and URL parameter hooks",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
@@ -32,7 +32,8 @@
32
32
  ".": "./src/index.ts"
33
33
  },
34
34
  "dependencies": {
35
- "@babel/runtime": "^7.0.0"
35
+ "@babel/runtime": "^7.0.0",
36
+ "bind-event-listener": "^3.0.0"
36
37
  },
37
38
  "peerDependencies": {
38
39
  "react": "^16.8.0 || ^17.0.0 || ^18.2.0"