@dxos/shell 0.3.11-main.ec7a2b3 → 0.3.11-main.ee2b64c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/bundle/shell.mjs +15272 -13589
  2. package/dist/bundle/shell.mjs.map +1 -1
  3. package/dist/bundle/shell.umd.js +81 -75
  4. package/dist/bundle/shell.umd.js.map +1 -1
  5. package/dist/bundle/style.css +1 -1
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/react.mjs +190 -174
  8. package/dist/lib/browser/react.mjs.map +4 -4
  9. package/dist/lib/browser/testing/index.mjs +35 -14
  10. package/dist/lib/browser/testing/index.mjs.map +3 -3
  11. package/dist/types/src/components/IdentityList/SpaceMemberList.js +1 -1
  12. package/dist/types/src/components/IdentityList/SpaceMemberList.js.map +1 -1
  13. package/dist/types/src/components/Panel/Action.d.ts.map +1 -1
  14. package/dist/types/src/components/Panel/Action.js +3 -18
  15. package/dist/types/src/components/Panel/Action.js.map +1 -1
  16. package/dist/types/src/panels/IdentityPanel/IdentityPanel.d.ts.map +1 -1
  17. package/dist/types/src/panels/IdentityPanel/IdentityPanel.js +6 -2
  18. package/dist/types/src/panels/IdentityPanel/IdentityPanel.js.map +1 -1
  19. package/dist/types/src/panels/IdentityPanel/IdentityPanelProps.d.ts +9 -1
  20. package/dist/types/src/panels/IdentityPanel/IdentityPanelProps.d.ts.map +1 -1
  21. package/dist/types/src/panels/IdentityPanel/steps/AgentForm.d.ts +3 -0
  22. package/dist/types/src/panels/IdentityPanel/steps/AgentForm.d.ts.map +1 -0
  23. package/dist/types/src/panels/IdentityPanel/steps/AgentForm.js +26 -0
  24. package/dist/types/src/panels/IdentityPanel/steps/AgentForm.js.map +1 -0
  25. package/dist/types/src/panels/IdentityPanel/steps/IdentityActionChooser.d.ts.map +1 -1
  26. package/dist/types/src/panels/IdentityPanel/steps/IdentityActionChooser.js +1 -1
  27. package/dist/types/src/panels/IdentityPanel/steps/IdentityActionChooser.js.map +1 -1
  28. package/dist/types/src/panels/IdentityPanel/steps/SignOutChooser.js +2 -2
  29. package/dist/types/src/panels/IdentityPanel/steps/SignOutChooser.js.map +1 -1
  30. package/dist/types/src/panels/IdentityPanel/steps/index.d.ts +1 -1
  31. package/dist/types/src/panels/IdentityPanel/steps/index.d.ts.map +1 -1
  32. package/dist/types/src/panels/IdentityPanel/steps/index.js +1 -1
  33. package/dist/types/src/panels/IdentityPanel/steps/index.js.map +1 -1
  34. package/dist/types/src/panels/IdentityPanel/useAgentHandlers.d.ts +15 -0
  35. package/dist/types/src/panels/IdentityPanel/useAgentHandlers.d.ts.map +1 -0
  36. package/dist/types/src/panels/IdentityPanel/useAgentHandlers.js +78 -0
  37. package/dist/types/src/panels/IdentityPanel/useAgentHandlers.js.map +1 -0
  38. package/dist/types/src/panels/JoinPanel/joinMachine.d.ts +1 -1
  39. package/dist/types/src/panels/JoinPanel/joinMachine.d.ts.map +1 -1
  40. package/dist/types/src/panels/JoinPanel/joinMachine.js +14 -17
  41. package/dist/types/src/panels/JoinPanel/joinMachine.js.map +1 -1
  42. package/dist/types/src/panels/JoinPanel/steps/AdditionMethodChooser.js +3 -3
  43. package/dist/types/src/panels/JoinPanel/steps/AdditionMethodChooser.js.map +1 -1
  44. package/dist/types/src/panels/JoinPanel/steps/InvitationInput.d.ts.map +1 -1
  45. package/dist/types/src/panels/JoinPanel/steps/InvitationInput.js +13 -6
  46. package/dist/types/src/panels/JoinPanel/steps/InvitationInput.js.map +1 -1
  47. package/dist/types/src/panels/JoinPanel/steps/InvitationRescuer.js.map +1 -1
  48. package/dist/types/src/panels/JoinPanel/steps/ResetIdentity.js +1 -1
  49. package/dist/types/src/panels/JoinPanel/steps/ResetIdentity.js.map +1 -1
  50. package/dist/types/src/playwright/invitations-manager.d.ts +1 -0
  51. package/dist/types/src/playwright/invitations-manager.d.ts.map +1 -1
  52. package/dist/types/src/playwright/invitations-manager.js +4 -1
  53. package/dist/types/src/playwright/invitations-manager.js.map +1 -1
  54. package/dist/types/src/playwright/invitations.spec.js +15 -0
  55. package/dist/types/src/playwright/invitations.spec.js.map +1 -1
  56. package/dist/types/src/styles/invitationStatusStyles.d.ts.map +1 -1
  57. package/dist/types/src/styles/invitationStatusStyles.js.map +1 -1
  58. package/dist/types/src/testing/shell-manager.d.ts +5 -4
  59. package/dist/types/src/testing/shell-manager.d.ts.map +1 -1
  60. package/dist/types/src/testing/shell-manager.js +36 -12
  61. package/dist/types/src/testing/shell-manager.js.map +1 -1
  62. package/package.json +22 -22
  63. package/src/components/IdentityList/SpaceMemberList.tsx +1 -1
  64. package/src/components/Panel/Action.tsx +4 -19
  65. package/src/panels/IdentityPanel/IdentityPanel.tsx +7 -3
  66. package/src/panels/IdentityPanel/IdentityPanelProps.ts +11 -1
  67. package/src/panels/IdentityPanel/steps/AgentForm.tsx +61 -0
  68. package/src/panels/IdentityPanel/steps/IdentityActionChooser.tsx +5 -1
  69. package/src/panels/IdentityPanel/steps/SignOutChooser.tsx +2 -0
  70. package/src/panels/IdentityPanel/steps/index.ts +1 -1
  71. package/src/panels/IdentityPanel/useAgentHandlers.ts +88 -0
  72. package/src/panels/JoinPanel/joinMachine.ts +15 -18
  73. package/src/panels/JoinPanel/steps/AdditionMethodChooser.tsx +3 -3
  74. package/src/panels/JoinPanel/steps/InvitationInput.tsx +7 -1
  75. package/src/panels/JoinPanel/steps/InvitationRescuer.tsx +2 -2
  76. package/src/panels/JoinPanel/steps/ResetIdentity.tsx +1 -1
  77. package/src/playwright/invitations-manager.ts +5 -1
  78. package/src/playwright/invitations.spec.ts +19 -0
  79. package/src/styles/invitationStatusStyles.ts +6 -6
  80. package/src/testing/shell-manager.ts +40 -13
  81. package/dist/types/src/panels/IdentityPanel/steps/AgentPanel.d.ts +0 -19
  82. package/dist/types/src/panels/IdentityPanel/steps/AgentPanel.d.ts.map +0 -1
  83. package/dist/types/src/panels/IdentityPanel/steps/AgentPanel.js +0 -122
  84. package/dist/types/src/panels/IdentityPanel/steps/AgentPanel.js.map +0 -1
  85. package/src/panels/IdentityPanel/steps/AgentPanel.tsx +0 -165
@@ -70,6 +70,10 @@ export class InvitationsManager extends ScopedShellManager {
70
70
  return this.peer(id).getByTestId('space-list-item').nth(nth).textContent();
71
71
  }
72
72
 
73
+ async getSpaceMembersCount(id: number) {
74
+ return this.peer(id).getByTestId('space-members-list').locator('li').count();
75
+ }
76
+
73
77
  async getAuthCode(): Promise<string> {
74
78
  return await this._authCode.wait();
75
79
  }
@@ -147,7 +151,7 @@ export class InvitationsManager extends ScopedShellManager {
147
151
  const peer = this.peer(id);
148
152
  // TODO(wittjosiah): Update ids.
149
153
  if (type === 'device') {
150
- await peer.getByTestId('join-identity').click();
154
+ await peer.getByTestId('identity-chooser.join-identity').click();
151
155
  }
152
156
  await peer.getByTestId(`${type === 'device' ? 'halo' : 'space'}-invitation-input`).waitFor({ timeout: 500 });
153
157
  await peer.getByTestId(`${type === 'device' ? 'halo' : 'space'}-invitation-input`).fill(invitation);
@@ -185,6 +185,25 @@ test.describe('Invitations', () => {
185
185
  expect(await manager.getSpaceName(0, 1)).to.equal(await manager.getSpaceName(1, 1));
186
186
  });
187
187
 
188
+ test('already joined', async () => {
189
+ await manager.createIdentity(0);
190
+ await manager.createSpace(0);
191
+ await manager.openPanel(0, 1);
192
+ const invitation1 = await manager.createInvitation(0, 'space', { authMethod: Invitation.AuthMethod.NONE });
193
+ const invitation2 = await manager.createInvitation(0, 'space');
194
+
195
+ await manager.createIdentity(1);
196
+ await manager.openPanel(1, 'join');
197
+ await manager.acceptInvitation(1, 'space', invitation1);
198
+ await manager.doneInvitation('space', manager.peer(1));
199
+
200
+ await manager.openPanel(1, 'join');
201
+ await manager.acceptInvitation(1, 'space', invitation2);
202
+ await manager.doneInvitation('space', manager.peer(1));
203
+
204
+ expect(await manager.getSpaceMembersCount(0)).to.equal(2);
205
+ });
206
+
188
207
  test('no auth method', async () => {
189
208
  await manager.createIdentity(0);
190
209
  await manager.createSpace(0);
@@ -26,17 +26,17 @@ export const resolvedStrokeColor = (status: Invitation.State) =>
26
26
  status === Invitation.State.ERROR
27
27
  ? errorStrokeColor
28
28
  : status === Invitation.State.CANCELLED || status === Invitation.State.TIMEOUT
29
- ? cancelledStrokeColor
30
- : successStrokeColor;
29
+ ? cancelledStrokeColor
30
+ : successStrokeColor;
31
31
  export const resolvedBgColor = (status: Invitation.State) =>
32
32
  status === Invitation.State.ERROR
33
33
  ? errorBgColor
34
34
  : status === Invitation.State.CANCELLED || status === Invitation.State.TIMEOUT
35
- ? cancelledBgColor
36
- : successBgColor;
35
+ ? cancelledBgColor
36
+ : successBgColor;
37
37
  export const resolvedTextColor = (status: Invitation.State) =>
38
38
  status === Invitation.State.ERROR
39
39
  ? errorTextColor
40
40
  : status === Invitation.State.CANCELLED || status === Invitation.State.TIMEOUT
41
- ? cancelledTextColor
42
- : successTextColor;
41
+ ? cancelledTextColor
42
+ : successTextColor;
@@ -2,12 +2,14 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import type { ConsoleMessage, Page } from '@playwright/test';
5
+ import type { ConsoleMessage, Dialog, Page } from '@playwright/test';
6
6
 
7
7
  import { sleep, Trigger } from '@dxos/async';
8
8
 
9
9
  import { ScopedShellManager } from './scoped-shell-manager';
10
10
 
11
+ // TODO(wittjosiah): Normalize data-testids between snake and camel case.
12
+
11
13
  export class ShellManager extends ScopedShellManager {
12
14
  private _invitationCode = new Trigger<string>();
13
15
  private _authCode = new Trigger<string>();
@@ -27,6 +29,10 @@ export class ShellManager extends ScopedShellManager {
27
29
 
28
30
  // Getters
29
31
 
32
+ async getDisplayName(): Promise<string | null> {
33
+ return this.shell.getByTestId('identityHeading.displayName').textContent();
34
+ }
35
+
30
36
  async isCurrentSpaceViewVisible(): Promise<boolean> {
31
37
  return await this.shell.getByTestId('current-space-view').isVisible();
32
38
  }
@@ -44,29 +50,50 @@ export class ShellManager extends ScopedShellManager {
44
50
  await this.shell.getByTestId('halo-invitation-accepted-done').click();
45
51
  }
46
52
 
47
- async closeShell() {
48
- await this.page.keyboard.press('Escape');
53
+ async createDeviceInvitation(): Promise<string> {
54
+ this._invitationCode = new Trigger<string>();
55
+ this._authCode = new Trigger<string>();
56
+ await this.shell.getByTestId('devices-panel.create-invitation').click();
57
+ return await this._invitationCode.wait();
49
58
  }
50
59
 
51
- // TODO(wittjosiah): These shortcuts are no longer within the SDK so these commands should live elsewhere.
52
- async openCurrentSpace() {
53
- await this.page.keyboard.press('Meta+.');
60
+ async resetDevice() {
61
+ const handleDialog = async (dialog: Dialog) => {
62
+ if (dialog.type() === 'confirm') {
63
+ await dialog.accept();
64
+ }
65
+ };
66
+
67
+ this.page.on('dialog', handleDialog);
68
+ await this.shell.getByTestId('devices-panel.sign-out').click();
69
+ await this.shell.getByTestId('sign-out.reset-device').click();
70
+ this.page.off('dialog', handleDialog);
54
71
  }
55
72
 
56
- async openSpaceList() {
57
- await this.page.keyboard.press('Meta+Shift+>');
73
+ async joinNewIdentity(invitationCode: string) {
74
+ await this.shell.getByTestId('devices-panel.sign-out').click();
75
+ await this.shell.getByTestId('sign-out.join-new-identity').click();
76
+ await this.shell.getByTestId('reset-identity-input').fill('CONFIRM');
77
+ await this.shell.getByTestId('reset-identity-input-confirm').click();
78
+ await this.shell.getByTestId('identity-chooser.join-identity').click();
79
+ await this.inputInvitation('device', invitationCode, this.shell);
58
80
  }
59
81
 
60
- async showAllSpaces() {
61
- await this.shell.getByTestId('show-all-spaces').click();
82
+ async authenticateDevice(authCode: string, skipDone = true) {
83
+ // Wait for focus to shift before typing.
84
+ await sleep(1500);
85
+ await this.authenticateInvitation('device', authCode, this.shell);
86
+ // TODO(wittjosiah): When "signing out" and joinging a new identity, the done step seems to be skipped.
87
+ if (!skipDone) {
88
+ await this.doneInvitation('device', this.shell);
89
+ }
62
90
  }
63
91
 
64
- async showCurrentSpace() {
65
- await this.shell.getByTestId('show-current-space').click();
92
+ async closeShell() {
93
+ await this.page.keyboard.press('Escape');
66
94
  }
67
95
 
68
96
  async createSpaceInvitation(): Promise<string> {
69
- await this.openCurrentSpace();
70
97
  this._invitationCode = new Trigger<string>();
71
98
  this._authCode = new Trigger<string>();
72
99
  await this.shell.getByTestId('spaces-panel.create-invitation').click();
@@ -1,19 +0,0 @@
1
- import { type Event, type SingleOrArray } from 'xstate';
2
- import { type Identity } from '@dxos/react-client/halo';
3
- import { type IdentityPanelStepProps } from '../IdentityPanelProps';
4
- import { type IdentityEvent } from '../identityMachine';
5
- export interface AgentFormProps extends Omit<IdentityPanelStepProps, 'send'> {
6
- send?: (event: SingleOrArray<Event<IdentityEvent>>) => void;
7
- onAgentCreate?: () => Promise<void>;
8
- onAgentDestroy?: () => Promise<void>;
9
- identity?: Identity;
10
- }
11
- export type AgentFormImplProps = AgentFormProps & {
12
- agentStatus?: string;
13
- agentActive?: boolean;
14
- agentProviderDisabled?: boolean;
15
- validationMessage?: string;
16
- };
17
- export declare const AgentForm: (props: AgentFormProps) => JSX.Element;
18
- export declare const AgentFormImpl: (props: AgentFormImplProps) => JSX.Element;
19
- //# sourceMappingURL=AgentPanel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AgentPanel.d.ts","sourceRoot":"","sources":["../../../../../../src/panels/IdentityPanel/steps/AgentPanel.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;AAIxD,OAAO,EAAE,KAAK,QAAQ,EAAsB,MAAM,yBAAyB,CAAC;AAK5E,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,sBAAsB,EAAE,MAAM,CAAC;IAC1E,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,KAAK,IAAI,CAAC;IAC5D,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,SAAS,UAAW,cAAc,gBAiF9C,CAAC;AAGF,eAAO,MAAM,aAAa,UAAW,kBAAkB,gBAiDtD,CAAC"}
@@ -1,122 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2023 DXOS.org
4
- //
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
- Object.defineProperty(o, "default", { enumerable: true, value: v });
18
- }) : function(o, v) {
19
- o["default"] = v;
20
- });
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.AgentFormImpl = exports.AgentForm = void 0;
30
- const react_1 = __importStar(require("react"));
31
- const invariant_1 = require("@dxos/invariant");
32
- const react_client_1 = require("@dxos/react-client");
33
- const halo_1 = require("@dxos/react-client/halo");
34
- const invitations_1 = require("@dxos/react-client/invitations");
35
- const react_ui_1 = require("@dxos/react-ui");
36
- const components_1 = require("../../../components");
37
- const AgentForm = (props) => {
38
- const { identity } = props;
39
- // const { t } = useTranslation('os');
40
- const [validationMessage, setValidationMessage] = (0, react_1.useState)('');
41
- const [agentStatus, setAgentStatus] = (0, react_1.useState)('');
42
- const [agentActive, setAgentActive] = (0, react_1.useState)(false);
43
- const client = (0, react_client_1.useClient)();
44
- const invitations = (0, halo_1.useHaloInvitations)();
45
- const agentHostingProviderClient = (0, react_client_1.useAgentHostingProviderClient)(client.config);
46
- (0, react_1.useEffect)(() => {
47
- const fetchAgentStatus = async () => {
48
- var _a;
49
- // TODO(nf): if agent exists, subscribe to updates instead of oneshot status
50
- if (agentHostingProviderClient) {
51
- const agentStatus = await (agentHostingProviderClient === null || agentHostingProviderClient === void 0 ? void 0 : agentHostingProviderClient.getAgent((_a = identity === null || identity === void 0 ? void 0 : identity.identityKey.truncate()) !== null && _a !== void 0 ? _a : 'foo'));
52
- if (agentStatus) {
53
- setAgentActive(true);
54
- setAgentStatus(agentStatus);
55
- }
56
- else {
57
- setAgentActive(false);
58
- setValidationMessage('No agent deployed via provider.');
59
- }
60
- }
61
- else {
62
- setValidationMessage('No agent provider configured.');
63
- }
64
- };
65
- void fetchAgentStatus();
66
- }, []);
67
- const onAgentCreateEvent = (0, react_1.useCallback)(async (invitation) => {
68
- const invitationCode = invitations_1.InvitationEncoder.encode(invitation);
69
- if (invitation.state === invitations_1.Invitation.State.CONNECTING) {
70
- console.log(JSON.stringify({ invitationCode, authCode: invitation.authCode }));
71
- (0, invariant_1.invariant)(identity, 'Identity not found');
72
- if (agentHostingProviderClient) {
73
- try {
74
- const res = await (agentHostingProviderClient === null || agentHostingProviderClient === void 0 ? void 0 : agentHostingProviderClient.createAgent(invitationCode, identity.identityKey.truncate()));
75
- // TODO(nf): human-consumable response from API
76
- setAgentStatus(res);
77
- setAgentActive(true);
78
- setValidationMessage('');
79
- }
80
- catch (err) {
81
- setValidationMessage(`error creating agent: ${err.message}`);
82
- }
83
- }
84
- }
85
- }, []);
86
- const handleAgentCreate = async () => {
87
- invitations.forEach((invitation) => invitation.cancel());
88
- // TODO(nf): do this work in the hosting provider client?
89
- const invitation = client.halo.share({ type: invitations_1.Invitation.Type.MULTIUSE, authMethod: invitations_1.Invitation.AuthMethod.NONE });
90
- invitation.subscribe(onAgentCreateEvent);
91
- };
92
- const handleAgentDestroy = async () => {
93
- const identity = client.halo.identity.get();
94
- (0, invariant_1.invariant)(identity, 'Identity not found');
95
- try {
96
- await (agentHostingProviderClient === null || agentHostingProviderClient === void 0 ? void 0 : agentHostingProviderClient.destroyAgent(identity.identityKey.truncate()));
97
- setValidationMessage('No agent deployed via provider.');
98
- setAgentStatus('');
99
- setAgentActive(false);
100
- }
101
- catch (err) {
102
- setValidationMessage(`error destroying agent: ${err.message}`);
103
- }
104
- };
105
- return (react_1.default.createElement(exports.AgentFormImpl, { ...props, onAgentCreate: handleAgentCreate, onAgentDestroy: handleAgentDestroy, validationMessage: validationMessage, agentStatus: agentStatus, agentActive: agentActive, agentProviderDisabled: !agentHostingProviderClient }));
106
- };
107
- exports.AgentForm = AgentForm;
108
- // TODO(zhenyasav): impl shouldn't need send()
109
- const AgentFormImpl = (props) => {
110
- const { active, onAgentCreate, onAgentDestroy, send, validationMessage, agentStatus, agentActive, agentProviderDisabled, } = props;
111
- const disabled = !active;
112
- const { t } = (0, react_ui_1.useTranslation)('os');
113
- return (react_1.default.createElement(react_1.default.Fragment, null,
114
- react_1.default.createElement("div", { role: 'none', className: 'grow flex flex-col justify-center' },
115
- react_1.default.createElement(components_1.Input, { validationMessage, label: react_1.default.createElement(components_1.StepHeading, null, "Agent Status"), disabled: disabled, "data-testid": 'agent-status', value: agentStatus })),
116
- react_1.default.createElement(components_1.Actions, null,
117
- react_1.default.createElement(components_1.Action, { disabled: agentActive || agentProviderDisabled, onClick: () => onAgentCreate === null || onAgentCreate === void 0 ? void 0 : onAgentCreate(), "data-testid": 'create-agent' }, "Create Agent"),
118
- react_1.default.createElement(components_1.Action, { disabled: !agentActive || agentProviderDisabled, onClick: () => onAgentDestroy === null || onAgentDestroy === void 0 ? void 0 : onAgentDestroy(), "data-testid": 'destroy-agent' }, "Destroy Agent"),
119
- react_1.default.createElement(components_1.Action, { disabled: disabled, onClick: () => send === null || send === void 0 ? void 0 : send({ type: 'unchooseAction' }), "data-testid": 'update-profile-form-back' }, t('back label')))));
120
- };
121
- exports.AgentFormImpl = AgentFormImpl;
122
- //# sourceMappingURL=AgentPanel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AgentPanel.js","sourceRoot":"","sources":["../../../../../../src/panels/IdentityPanel/steps/AgentPanel.tsx"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,+CAAgE;AAGhE,+CAA4C;AAC5C,qDAA8E;AAC9E,kDAA4E;AAC5E,gEAA+E;AAC/E,6CAAgD;AAEhD,oDAA0E;AAkBnE,MAAM,SAAS,GAAG,CAAC,KAAqB,EAAE,EAAE;IACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3B,sCAAsC;IACtC,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAG,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAC;IAC/D,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAC;IACnD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,IAAA,wBAAS,GAAE,CAAC;IAC3B,MAAM,WAAW,GAAG,IAAA,yBAAkB,GAAE,CAA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AC,cAAc,aAAd,cAAc,uBAAd,cAAc,EAAI,iBACpB,eAAe,oBAGrB;YACT,8BAAC,mBAAM,IACL,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,iBACpC,0BAA0B,IAEtC,CAAC,CAAC,YAAY,CAAC,CACT,CACD,CACT,CACJ,CAAC;AACJ,CAAC,CAAC;AAjDW,QAAA,aAAa,iBAiDxB"}
@@ -1,165 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React, { useState, useCallback, useEffect } from 'react';
6
- import { type Event, type SingleOrArray } from 'xstate';
7
-
8
- import { invariant } from '@dxos/invariant';
9
- import { useClient, useAgentHostingProviderClient } from '@dxos/react-client';
10
- import { type Identity, useHaloInvitations } from '@dxos/react-client/halo';
11
- import { Invitation, InvitationEncoder } from '@dxos/react-client/invitations';
12
- import { useTranslation } from '@dxos/react-ui';
13
-
14
- import { Action, Actions, StepHeading, Input } from '../../../components';
15
- import { type IdentityPanelStepProps } from '../IdentityPanelProps';
16
- import { type IdentityEvent } from '../identityMachine';
17
-
18
- export interface AgentFormProps extends Omit<IdentityPanelStepProps, 'send'> {
19
- send?: (event: SingleOrArray<Event<IdentityEvent>>) => void;
20
- onAgentCreate?: () => Promise<void>;
21
- onAgentDestroy?: () => Promise<void>;
22
- identity?: Identity;
23
- }
24
-
25
- export type AgentFormImplProps = AgentFormProps & {
26
- agentStatus?: string;
27
- agentActive?: boolean;
28
- agentProviderDisabled?: boolean;
29
- validationMessage?: string;
30
- };
31
-
32
- export const AgentForm = (props: AgentFormProps) => {
33
- const { identity } = props;
34
- // const { t } = useTranslation('os');
35
- const [validationMessage, setValidationMessage] = useState('');
36
- const [agentStatus, setAgentStatus] = useState('');
37
- const [agentActive, setAgentActive] = useState(false);
38
- const client = useClient();
39
- const invitations = useHaloInvitations();
40
- const agentHostingProviderClient = useAgentHostingProviderClient(client.config);
41
-
42
- useEffect(() => {
43
- const fetchAgentStatus = async () => {
44
- // TODO(nf): if agent exists, subscribe to updates instead of oneshot status
45
- if (agentHostingProviderClient) {
46
- const agentStatus = await agentHostingProviderClient?.getAgent(identity?.identityKey.truncate() ?? 'foo');
47
- if (agentStatus) {
48
- setAgentActive(true);
49
- setAgentStatus(agentStatus);
50
- } else {
51
- setAgentActive(false);
52
- setValidationMessage('No agent deployed via provider.');
53
- }
54
- } else {
55
- setValidationMessage('No agent provider configured.');
56
- }
57
- };
58
- void fetchAgentStatus();
59
- }, []);
60
-
61
- const onAgentCreateEvent = useCallback(async (invitation: Invitation) => {
62
- const invitationCode = InvitationEncoder.encode(invitation);
63
- if (invitation.state === Invitation.State.CONNECTING) {
64
- console.log(JSON.stringify({ invitationCode, authCode: invitation.authCode }));
65
- invariant(identity, 'Identity not found');
66
- if (agentHostingProviderClient) {
67
- try {
68
- const res = await agentHostingProviderClient?.createAgent(invitationCode, identity.identityKey.truncate());
69
- // TODO(nf): human-consumable response from API
70
- setAgentStatus(res);
71
- setAgentActive(true);
72
- setValidationMessage('');
73
- } catch (err: any) {
74
- setValidationMessage(`error creating agent: ${err.message}`);
75
- }
76
- }
77
- }
78
- }, []);
79
-
80
- const handleAgentCreate = async () => {
81
- invitations.forEach((invitation) => invitation.cancel());
82
-
83
- // TODO(nf): do this work in the hosting provider client?
84
- const invitation = client.halo.share({ type: Invitation.Type.MULTIUSE, authMethod: Invitation.AuthMethod.NONE });
85
-
86
- invitation.subscribe(onAgentCreateEvent);
87
- };
88
-
89
- const handleAgentDestroy = async () => {
90
- const identity = client.halo.identity.get();
91
- invariant(identity, 'Identity not found');
92
- try {
93
- await agentHostingProviderClient?.destroyAgent(identity.identityKey.truncate());
94
- setValidationMessage('No agent deployed via provider.');
95
- setAgentStatus('');
96
- setAgentActive(false);
97
- } catch (err: any) {
98
- setValidationMessage(`error destroying agent: ${err.message}`);
99
- }
100
- };
101
-
102
- return (
103
- <AgentFormImpl
104
- {...props}
105
- onAgentCreate={handleAgentCreate}
106
- onAgentDestroy={handleAgentDestroy}
107
- validationMessage={validationMessage}
108
- agentStatus={agentStatus}
109
- agentActive={agentActive}
110
- agentProviderDisabled={!agentHostingProviderClient}
111
- />
112
- );
113
- };
114
-
115
- // TODO(zhenyasav): impl shouldn't need send()
116
- export const AgentFormImpl = (props: AgentFormImplProps) => {
117
- const {
118
- active,
119
- onAgentCreate,
120
- onAgentDestroy,
121
- send,
122
- validationMessage,
123
- agentStatus,
124
- agentActive,
125
- agentProviderDisabled,
126
- } = props;
127
- const disabled = !active;
128
- const { t } = useTranslation('os');
129
- return (
130
- <>
131
- <div role='none' className='grow flex flex-col justify-center'>
132
- <Input
133
- {...{ validationMessage }}
134
- label={<StepHeading>Agent Status</StepHeading>}
135
- disabled={disabled}
136
- data-testid='agent-status'
137
- value={agentStatus}
138
- />
139
- </div>
140
- <Actions>
141
- <Action
142
- disabled={agentActive || agentProviderDisabled}
143
- onClick={() => onAgentCreate?.()}
144
- data-testid={'create-agent'}
145
- >
146
- Create Agent
147
- </Action>
148
- <Action
149
- disabled={!agentActive || agentProviderDisabled}
150
- onClick={() => onAgentDestroy?.()}
151
- data-testid={'destroy-agent'}
152
- >
153
- Destroy Agent
154
- </Action>
155
- <Action
156
- disabled={disabled}
157
- onClick={() => send?.({ type: 'unchooseAction' })}
158
- data-testid={'update-profile-form-back'}
159
- >
160
- {t('back label')}
161
- </Action>
162
- </Actions>
163
- </>
164
- );
165
- };