@dxos/shell 0.3.11-main.cf6cc01 → 0.3.11-main.d56f337

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 (63) hide show
  1. package/dist/bundle/shell.mjs +6281 -6166
  2. package/dist/bundle/shell.mjs.map +1 -1
  3. package/dist/bundle/shell.umd.js +69 -69
  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 +443 -369
  8. package/dist/lib/browser/react.mjs.map +4 -4
  9. package/dist/lib/browser/testing/index.mjs.map +1 -1
  10. package/dist/types/src/components/Panel/Action.js +1 -1
  11. package/dist/types/src/components/Panel/Action.js.map +1 -1
  12. package/dist/types/src/composites/Shell/Shell.d.ts.map +1 -1
  13. package/dist/types/src/composites/Shell/Shell.js +5 -1
  14. package/dist/types/src/composites/Shell/Shell.js.map +1 -1
  15. package/dist/types/src/panels/IdentityPanel/IdentityPanel.d.ts.map +1 -1
  16. package/dist/types/src/panels/IdentityPanel/IdentityPanel.js +10 -6
  17. package/dist/types/src/panels/IdentityPanel/IdentityPanel.js.map +1 -1
  18. package/dist/types/src/panels/IdentityPanel/IdentityPanelProps.d.ts +12 -2
  19. package/dist/types/src/panels/IdentityPanel/IdentityPanelProps.d.ts.map +1 -1
  20. package/dist/types/src/panels/IdentityPanel/identityMachine.d.ts +1 -1
  21. package/dist/types/src/panels/IdentityPanel/identityMachine.d.ts.map +1 -1
  22. package/dist/types/src/panels/IdentityPanel/identityMachine.js +2 -2
  23. package/dist/types/src/panels/IdentityPanel/identityMachine.js.map +1 -1
  24. package/dist/types/src/panels/IdentityPanel/steps/AgentForm.d.ts +3 -0
  25. package/dist/types/src/panels/IdentityPanel/steps/AgentForm.d.ts.map +1 -0
  26. package/dist/types/src/panels/IdentityPanel/steps/AgentForm.js +26 -0
  27. package/dist/types/src/panels/IdentityPanel/steps/AgentForm.js.map +1 -0
  28. package/dist/types/src/panels/IdentityPanel/steps/IdentityActionChooser.d.ts.map +1 -1
  29. package/dist/types/src/panels/IdentityPanel/steps/IdentityActionChooser.js +1 -1
  30. package/dist/types/src/panels/IdentityPanel/steps/IdentityActionChooser.js.map +1 -1
  31. package/dist/types/src/panels/IdentityPanel/steps/SignOutChooser.d.ts +16 -0
  32. package/dist/types/src/panels/IdentityPanel/steps/SignOutChooser.d.ts.map +1 -0
  33. package/dist/types/src/panels/IdentityPanel/steps/SignOutChooser.js +40 -0
  34. package/dist/types/src/panels/IdentityPanel/steps/SignOutChooser.js.map +1 -0
  35. package/dist/types/src/panels/IdentityPanel/steps/index.d.ts +2 -1
  36. package/dist/types/src/panels/IdentityPanel/steps/index.d.ts.map +1 -1
  37. package/dist/types/src/panels/IdentityPanel/steps/index.js +2 -1
  38. package/dist/types/src/panels/IdentityPanel/steps/index.js.map +1 -1
  39. package/dist/types/src/panels/IdentityPanel/useAgentHandlers.d.ts +15 -0
  40. package/dist/types/src/panels/IdentityPanel/useAgentHandlers.d.ts.map +1 -0
  41. package/dist/types/src/panels/IdentityPanel/useAgentHandlers.js +78 -0
  42. package/dist/types/src/panels/IdentityPanel/useAgentHandlers.js.map +1 -0
  43. package/dist/types/src/translations/locales/en-US.d.ts +5 -0
  44. package/dist/types/src/translations/locales/en-US.d.ts.map +1 -1
  45. package/dist/types/src/translations/locales/en-US.js +5 -0
  46. package/dist/types/src/translations/locales/en-US.js.map +1 -1
  47. package/package.json +21 -21
  48. package/src/components/Panel/Action.tsx +1 -1
  49. package/src/composites/Shell/Shell.tsx +7 -1
  50. package/src/panels/IdentityPanel/IdentityPanel.tsx +20 -9
  51. package/src/panels/IdentityPanel/IdentityPanelProps.ts +15 -2
  52. package/src/panels/IdentityPanel/identityMachine.ts +3 -3
  53. package/src/panels/IdentityPanel/steps/AgentForm.tsx +61 -0
  54. package/src/panels/IdentityPanel/steps/IdentityActionChooser.tsx +1 -6
  55. package/src/panels/IdentityPanel/steps/SignOutChooser.tsx +82 -0
  56. package/src/panels/IdentityPanel/steps/index.ts +2 -1
  57. package/src/panels/IdentityPanel/useAgentHandlers.ts +88 -0
  58. package/src/translations/locales/en-US.ts +5 -0
  59. package/dist/types/src/panels/IdentityPanel/steps/AgentPanel.d.ts +0 -19
  60. package/dist/types/src/panels/IdentityPanel/steps/AgentPanel.d.ts.map +0 -1
  61. package/dist/types/src/panels/IdentityPanel/steps/AgentPanel.js +0 -122
  62. package/dist/types/src/panels/IdentityPanel/steps/AgentPanel.js.map +0 -1
  63. package/src/panels/IdentityPanel/steps/AgentPanel.tsx +0 -165
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ //
3
+ // Copyright 2024 DXOS.org
4
+ //
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useAgentHandlers = void 0;
7
+ const react_1 = require("react");
8
+ const invariant_1 = require("@dxos/invariant");
9
+ const react_client_1 = require("@dxos/react-client");
10
+ const invitations_1 = require("@dxos/react-client/invitations");
11
+ const useAgentHandlers = ({ client, invitations, identity, }) => {
12
+ const [validationMessage, setValidationMessage] = (0, react_1.useState)('');
13
+ const [agentStatus, setAgentStatus] = (0, react_1.useState)('');
14
+ const [agentActive, setAgentActive] = (0, react_1.useState)(false);
15
+ const agentHostingProviderClient = (0, react_client_1.useAgentHostingProviderClient)(client.config);
16
+ (0, react_1.useEffect)(() => {
17
+ const fetchAgentStatus = async () => {
18
+ var _a;
19
+ // TODO(nf): if agent exists, subscribe to updates instead of oneshot status
20
+ if (agentHostingProviderClient) {
21
+ 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'));
22
+ if (agentStatus) {
23
+ setAgentActive(true);
24
+ setAgentStatus(agentStatus);
25
+ }
26
+ else {
27
+ setAgentActive(false);
28
+ setValidationMessage('No agent deployed via provider.');
29
+ }
30
+ }
31
+ else {
32
+ setValidationMessage('No agent provider configured.');
33
+ }
34
+ };
35
+ void fetchAgentStatus();
36
+ }, []);
37
+ const handleAgentCreate = (0, react_1.useCallback)(async (invitation) => {
38
+ const invitationCode = invitations_1.InvitationEncoder.encode(invitation);
39
+ if (invitation.state === invitations_1.Invitation.State.CONNECTING) {
40
+ console.log(JSON.stringify({ invitationCode, authCode: invitation.authCode }));
41
+ (0, invariant_1.invariant)(identity, 'Identity not found');
42
+ if (agentHostingProviderClient) {
43
+ try {
44
+ const res = await (agentHostingProviderClient === null || agentHostingProviderClient === void 0 ? void 0 : agentHostingProviderClient.createAgent(invitationCode, identity.identityKey.truncate()));
45
+ // TODO(nf): human-consumable response from API
46
+ setAgentStatus(res);
47
+ setAgentActive(true);
48
+ setValidationMessage('');
49
+ }
50
+ catch (err) {
51
+ setValidationMessage(`error creating agent: ${err.message}`);
52
+ }
53
+ }
54
+ }
55
+ }, []);
56
+ const onAgentCreate = async () => {
57
+ invitations.forEach((invitation) => invitation.cancel());
58
+ // TODO(nf): do this work in the hosting provider client?
59
+ const invitation = client.halo.share({ type: invitations_1.Invitation.Type.MULTIUSE, authMethod: invitations_1.Invitation.AuthMethod.NONE });
60
+ invitation.subscribe(handleAgentCreate);
61
+ };
62
+ const onAgentDestroy = async () => {
63
+ const identity = client.halo.identity.get();
64
+ (0, invariant_1.invariant)(identity, 'Identity not found');
65
+ try {
66
+ await (agentHostingProviderClient === null || agentHostingProviderClient === void 0 ? void 0 : agentHostingProviderClient.destroyAgent(identity.identityKey.truncate()));
67
+ setValidationMessage('No agent deployed via provider.');
68
+ setAgentStatus('');
69
+ setAgentActive(false);
70
+ }
71
+ catch (err) {
72
+ setValidationMessage(`error destroying agent: ${err.message}`);
73
+ }
74
+ };
75
+ return { onAgentCreate, onAgentDestroy, validationMessage, agentStatus, agentActive };
76
+ };
77
+ exports.useAgentHandlers = useAgentHandlers;
78
+ //# sourceMappingURL=useAgentHandlers.js.map
@@ -0,0 +1 @@
1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,EAAE,UAAU,EAAE,wBAAU,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QAEjH,UAAU,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;IAC1C,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,KAAK,IAAI,EAAE;QAChC,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;QAC5C,IAAA,qBAAS,EAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;QAC1C,IAAI;YACF,MAAM,CAAA,0BAA0B,aAA1B,0BAA0B,uBAA1B,0BAA0B,CAAE,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAA,CAAC;YAChF,oBAAoB,CAAC,iCAAiC,CAAC,CAAC;YACxD,cAAc,CAAC,EAAE,CAAC,CAAC;YACnB,cAAc,CAAC,KAAK,CAAC,CAAC;SACvB;QAAC,OAAO,GAAQ,EAAE;YACjB,oBAAoB,CAAC,2BAA2B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;SAChE;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AACxF,CAAC,CAAC;AA3EW,QAAA,gBAAgB,oBA2E3B"}
@@ -94,5 +94,10 @@ export declare const os: {
94
94
  'reset identity input label': string;
95
95
  'failed to reset identity message': string;
96
96
  'confirmation value': string;
97
+ 'sign out chooser title': string;
98
+ 'sign out chooser message': string;
99
+ 'join new identity label': string;
100
+ 'reset device label': string;
101
+ 'reset device confirm message': string;
97
102
  };
98
103
  //# sourceMappingURL=en-US.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"en-US.d.ts","sourceRoot":"","sources":["../../../../../src/translations/locales/en-US.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiGd,CAAC"}
1
+ {"version":3,"file":"en-US.d.ts","sourceRoot":"","sources":["../../../../../src/translations/locales/en-US.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsGd,CAAC"}
@@ -100,5 +100,10 @@ exports.os = {
100
100
  'reset identity input label': 'This will clear this device and all associated data. Type {{confirmationValue}} and confirm to continue.',
101
101
  'failed to reset identity message': 'Failed to reset identity.',
102
102
  'confirmation value': 'CONFIRM',
103
+ 'sign out chooser title': 'DANGER ZONE',
104
+ 'sign out chooser message': 'Proceeding with either action below will erase all data on this device.',
105
+ 'join new identity label': 'Join a new identity',
106
+ 'reset device label': 'Reset device',
107
+ 'reset device confirm message': 'Are you sure you want to reset your device? All data will be lost.',
103
108
  };
104
109
  //# sourceMappingURL=en-US.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"en-US.js","sourceRoot":"","sources":["../../../../../src/translations/locales/en-US.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEW,QAAA,EAAE,GAAG;IAChB,sBAAsB,EAAE,iBAAiB;IACzC,8BAA8B,EAAE,SAAS;IACzC,eAAe,EAAE,cAAc;IAC/B,4BAA4B,EAAE,UAAU;IACxC,oCAAoC,EAAE,QAAQ;IAC9C,wBAAwB,EAAE,cAAc;IACxC,uBAAuB,EAAE,eAAe;IACxC,oBAAoB,EAAE,wBAAwB;IAC9C,cAAc,EAAE,4BAA4B;IAC5C,YAAY,EAAE,MAAM;IACpB,yBAAyB,EAAE,SAAS;IACpC,4BAA4B,EAAE,+DAA+D;IAC7F,oBAAoB,EAAE,KAAK;IAC3B,gBAAgB,EAAE,UAAU;IAC5B,YAAY,EAAE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BAAsB,EAAE,kCAAkC;IAC1D,eAAe,EAAE,SAAS;IAC1B,4BAA4B,EAC1B,0GAA0G;IAC5G,kCAAkC,EAAE,2BAA2B;IAC/D,oBAAoB,EAAE,SAAS;IAC/B,wBAAwB,EAAE,aAAa;IACvC,0BAA0B,EAAE,yEAAyE;IACrG,yBAAyB,EAAE,qBAAqB;IAChD,oBAAoB,EAAE,cAAc;IACpC,8BAA8B,EAAE,oEAAoE;CACrG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/shell",
3
- "version": "0.3.11-main.cf6cc01",
3
+ "version": "0.3.11-main.d56f337",
4
4
  "description": "DXOS’s OS experiences",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -39,35 +39,35 @@
39
39
  "react-qr-rounded": "^1.0.0",
40
40
  "url-join": "^5.0.0",
41
41
  "xstate": "^4.37.0",
42
- "@dxos/async": "0.3.11-main.cf6cc01",
43
- "@dxos/client-services": "0.3.11-main.cf6cc01",
44
- "@dxos/client-protocol": "0.3.11-main.cf6cc01",
45
- "@dxos/debug": "0.3.11-main.cf6cc01",
46
- "@dxos/display-name": "0.3.11-main.cf6cc01",
47
- "@dxos/invariant": "0.3.11-main.cf6cc01",
48
- "@dxos/react-client": "0.3.11-main.cf6cc01",
49
- "@dxos/log": "0.3.11-main.cf6cc01",
50
- "@dxos/react-ui": "0.3.11-main.cf6cc01",
51
- "@dxos/react-ui-types": "0.3.11-main.cf6cc01",
52
- "@dxos/react-ui-theme": "0.3.11-main.cf6cc01",
53
- "@dxos/rpc-tunnel": "0.3.11-main.cf6cc01",
54
- "@dxos/util": "0.3.11-main.cf6cc01"
42
+ "@dxos/async": "0.3.11-main.d56f337",
43
+ "@dxos/client-protocol": "0.3.11-main.d56f337",
44
+ "@dxos/debug": "0.3.11-main.d56f337",
45
+ "@dxos/client-services": "0.3.11-main.d56f337",
46
+ "@dxos/display-name": "0.3.11-main.d56f337",
47
+ "@dxos/invariant": "0.3.11-main.d56f337",
48
+ "@dxos/react-client": "0.3.11-main.d56f337",
49
+ "@dxos/react-ui": "0.3.11-main.d56f337",
50
+ "@dxos/react-ui-types": "0.3.11-main.d56f337",
51
+ "@dxos/react-ui-theme": "0.3.11-main.d56f337",
52
+ "@dxos/log": "0.3.11-main.d56f337",
53
+ "@dxos/util": "0.3.11-main.d56f337",
54
+ "@dxos/rpc-tunnel": "0.3.11-main.d56f337"
55
55
  },
56
56
  "devDependencies": {
57
- "@faker-js/faker": "^8.0.2",
57
+ "@faker-js/faker": "^8.3.1",
58
58
  "@phosphor-icons/react": "^2.0.5",
59
59
  "@types/lodash.toarray": "^4.4.7",
60
60
  "@types/react": "^18.0.21",
61
61
  "@types/react-dom": "^18.0.6",
62
- "@vitejs/plugin-react": "^3.0.1",
62
+ "@vitejs/plugin-react": "^4.2.1",
63
63
  "react": "^18.2.0",
64
64
  "react-dom": "^18.2.0",
65
- "vite": "^4.3.9",
65
+ "vite": "^5.0.11",
66
66
  "vite-plugin-turbosnap": "^1.0.2",
67
- "@dxos/config": "0.3.11-main.cf6cc01",
68
- "@dxos/react-async": "0.3.11-main.cf6cc01",
69
- "@dxos/storybook-utils": "0.3.11-main.cf6cc01",
70
- "@dxos/react-ui-theme": "0.3.11-main.cf6cc01"
67
+ "@dxos/config": "0.3.11-main.d56f337",
68
+ "@dxos/react-async": "0.3.11-main.d56f337",
69
+ "@dxos/react-ui-theme": "0.3.11-main.d56f337",
70
+ "@dxos/storybook-utils": "0.3.11-main.d56f337"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "@phosphor-icons/react": "^2.0.5",
@@ -132,7 +132,7 @@ export const Action = forwardRef<HTMLButtonElement, LargeButtonProps>((props, fo
132
132
  return (
133
133
  <Button
134
134
  {...rest}
135
- classNames={[isFull && 'is-full', 'bs-11 flex gap-2 mbs-2', classNames, ...buttonColorFragment(props)]}
135
+ classNames={[isFull && 'is-full', 'bs-11 flex gap-2 mbs-2', ...buttonColorFragment(props), classNames]}
136
136
  ref={forwardedRef}
137
137
  variant={variant}
138
138
  >
@@ -5,7 +5,7 @@
5
5
  import React, { useEffect, useState } from 'react';
6
6
 
7
7
  import { log } from '@dxos/log';
8
- import { type LayoutRequest, ShellDisplay, ShellLayout, type ShellRuntime } from '@dxos/react-client';
8
+ import { type LayoutRequest, ShellDisplay, ShellLayout, type ShellRuntime, useClient } from '@dxos/react-client';
9
9
  import { useSpace } from '@dxos/react-client/echo';
10
10
 
11
11
  import { IdentityDialog } from '../IdentityDialog';
@@ -20,6 +20,7 @@ export const Shell = ({ runtime, origin }: { runtime: ShellRuntime; origin: stri
20
20
  target: runtime.target,
21
21
  });
22
22
 
23
+ const client = useClient();
23
24
  const space = useSpace(spaceKey);
24
25
 
25
26
  useEffect(() => {
@@ -59,6 +60,11 @@ export const Shell = ({ runtime, origin }: { runtime: ShellRuntime; origin: stri
59
60
  return (
60
61
  <IdentityDialog
61
62
  createInvitationUrl={(invitationCode) => `${origin}?deviceInvitationCode=${invitationCode}`}
63
+ onResetDevice={async () => {
64
+ await client.reset();
65
+ await runtime.setAppContext({ display: ShellDisplay.NONE, reload: true });
66
+ }}
67
+ onJoinNewIdentity={() => runtime.setLayout({ layout: ShellLayout.INITIALIZE_IDENTITY })}
62
68
  onDone={async () => {
63
69
  await runtime.setAppContext({ display: ShellDisplay.NONE });
64
70
  runtime.setLayout({ layout: ShellLayout.DEFAULT });
@@ -6,7 +6,7 @@ import React, { useEffect, useMemo } from 'react';
6
6
  import { generateName } from '@dxos/display-name';
7
7
  import { log } from '@dxos/log';
8
8
  import { useClient } from '@dxos/react-client';
9
- import { type Identity, useIdentity, useDevices } from '@dxos/react-client/halo';
9
+ import { type Identity, useIdentity, useDevices, useHaloInvitations } from '@dxos/react-client/halo';
10
10
  import { useInvitationStatus } from '@dxos/react-client/invitations';
11
11
  import type { CancellableInvitationObservable } from '@dxos/react-client/invitations';
12
12
  import { Avatar, DensityProvider, useId, useJdenticonHref, useTranslation } from '@dxos/react-ui';
@@ -17,7 +17,8 @@ import {
17
17
  type IdentityPanelProps,
18
18
  } from './IdentityPanelProps';
19
19
  import { useIdentityMachine } from './identityMachine';
20
- import { DeviceManager, IdentityActionChooser, ProfileForm, AgentForm } from './steps';
20
+ import { AgentForm, DeviceManager, IdentityActionChooser, ProfileForm, SignOutChooser } from './steps';
21
+ import { useAgentHandlers } from './useAgentHandlers';
21
22
  import { Viewport, Heading, CloseButton } from '../../components';
22
23
  import { InvitationManager } from '../../steps';
23
24
 
@@ -45,6 +46,8 @@ export const IdentityPanelImpl = (props: IdentityPanelImplProps) => {
45
46
  titleId,
46
47
  activeView,
47
48
  onUpdateProfile,
49
+ onResetDevice,
50
+ onJoinNewIdentity,
48
51
  IdentityActionChooser: IdentityActionChooserComponent = IdentityActionChooser,
49
52
  InvitationManager: InvitationManagerComponent = InvitationManager,
50
53
  onDone,
@@ -61,7 +64,7 @@ export const IdentityPanelImpl = (props: IdentityPanelImplProps) => {
61
64
  return t('identity heading');
62
65
  }
63
66
  }, [activeView, t]);
64
- console.log('[IdentityPanelImpl]', { activeView });
67
+
65
68
  return (
66
69
  <DensityProvider density='fine'>
67
70
  <IdentityHeading {...{ identity, titleId, title, onDone }} />
@@ -88,10 +91,17 @@ export const IdentityPanelImpl = (props: IdentityPanelImplProps) => {
88
91
  onUpdateProfile={onUpdateProfile}
89
92
  />
90
93
  </Viewport.View>
94
+ <Viewport.View classNames={viewStyles} id='signing out'>
95
+ <SignOutChooser
96
+ send={rest.send}
97
+ active={activeView === 'signing out'}
98
+ onResetDevice={onResetDevice}
99
+ onJoinNewIdentity={onJoinNewIdentity}
100
+ />
101
+ </Viewport.View>
91
102
  <Viewport.View classNames={viewStyles} id='agent manager'>
92
- <AgentForm send={rest.send} active={activeView === 'agent manager'} identity={identity} />
103
+ <AgentForm send={rest.send} active={activeView === 'agent manager'} {...rest} />
93
104
  </Viewport.View>
94
- {/* <Viewport.View id='signing out'></Viewport.View> */}
95
105
  </Viewport.Views>
96
106
  </Viewport.Root>
97
107
  </DensityProvider>
@@ -115,6 +125,8 @@ export const IdentityPanel = ({
115
125
  const client = useClient();
116
126
  const devices = useDevices();
117
127
  const identity = useIdentity();
128
+ const invitations = useHaloInvitations();
129
+ const agentProps = useAgentHandlers({ client, identity, invitations });
118
130
  if (!identity) {
119
131
  console.error('IdentityPanel rendered with no active identity.');
120
132
  return null;
@@ -139,17 +151,15 @@ export const IdentityPanel = ({
139
151
  return 'device manager';
140
152
  case [{ managingProfile: 'idle' }, { managingProfile: 'pending' }].some(identityState.matches):
141
153
  return 'update profile form';
154
+ case identityState.matches('signingOut'):
155
+ return 'signing out';
142
156
  case [{ managingAgent: 'idle' }, { managingAgent: 'pending' }].some(identityState.matches):
143
157
  return 'agent manager';
144
- // case identityState.matches('signingOut'):
145
- // return 'identity exit';
146
158
  default:
147
159
  return 'identity action chooser';
148
160
  }
149
161
  }, [identityState]);
150
162
 
151
- console.log({ activeView, identityState });
152
-
153
163
  const onUpdateProfile = async (profile: NonNullable<Identity['profile']>) => {
154
164
  identitySend({ type: 'updateProfile' });
155
165
  await client.halo.updateProfile(profile);
@@ -164,6 +174,7 @@ export const IdentityPanel = ({
164
174
  titleId,
165
175
  createInvitationUrl,
166
176
  onUpdateProfile,
177
+ ...agentProps,
167
178
  } satisfies IdentityPanelImplProps;
168
179
 
169
180
  return identityState.context.invitation ? (
@@ -11,6 +11,15 @@ import type { InvitationStatus } from '@dxos/react-client/invitations';
11
11
  import type { IdentityEvent } from './identityMachine';
12
12
  import type { InvitationManagerProps } from '../../steps';
13
13
 
14
+ export type AgentFormProps = {
15
+ onAgentCreate?: () => Promise<void>;
16
+ onAgentDestroy?: () => Promise<void>;
17
+ agentStatus?: string;
18
+ agentActive?: boolean;
19
+ agentProviderDisabled?: boolean;
20
+ validationMessage?: string;
21
+ };
22
+
14
23
  export type IdentityPanelImplProps = {
15
24
  titleId: string;
16
25
  activeView:
@@ -18,10 +27,13 @@ export type IdentityPanelImplProps = {
18
27
  | 'agent manager'
19
28
  | 'update profile form'
20
29
  | 'device invitation manager'
21
- | 'identity action chooser';
30
+ | 'identity action chooser'
31
+ | 'signing out';
22
32
  identity: Identity;
23
33
  devices: Device[];
24
34
  onUpdateProfile?: (profile: NonNullable<Identity['profile']>) => Promise<void>;
35
+ onResetDevice?: () => Promise<void>;
36
+ onJoinNewIdentity?: () => void;
25
37
  createInvitationUrl: (invitationCode: string) => string;
26
38
  send?: (event: SingleOrArray<Event<IdentityEvent>>) => void;
27
39
  onDone?: () => void;
@@ -29,7 +41,8 @@ export type IdentityPanelImplProps = {
29
41
  invitationUrl?: string;
30
42
  IdentityActionChooser?: React.FC<IdentityPanelStepProps>;
31
43
  InvitationManager?: React.FC<InvitationManagerProps>;
32
- } & Partial<InvitationStatus>;
44
+ } & Partial<InvitationStatus> &
45
+ Partial<AgentFormProps>;
33
46
 
34
47
  export type IdentityPanelProps = Partial<Omit<IdentityPanelImplProps, 'send' | 'activeView' | 'identity'>>;
35
48
 
@@ -19,7 +19,7 @@ type IdentityMachineContext = {
19
19
  };
20
20
 
21
21
  type IdentityChooseActionEvent = {
22
- type: 'chooseDevices' | 'chooseAgent' | 'chooseProfile' | /* 'chooseSignOut' | */ 'unchooseAction';
22
+ type: 'chooseDevices' | 'chooseAgent' | 'chooseProfile' | 'chooseSignOut' | 'sigingOut' | 'unchooseAction';
23
23
  };
24
24
 
25
25
  type IdentitySelectDeviceInvitationEvent = {
@@ -77,7 +77,7 @@ const identityMachine = createMachine<IdentityMachineContext, IdentityEvent>(
77
77
  updateProfile: { target: '.pending', actions: 'log' },
78
78
  },
79
79
  },
80
- // signingOut: {},
80
+ signingOut: {},
81
81
  },
82
82
  on: {
83
83
  unchooseAction: { target: '.choosingAction', actions: ['unsetInvitation', 'log'] },
@@ -85,8 +85,8 @@ const identityMachine = createMachine<IdentityMachineContext, IdentityEvent>(
85
85
  selectInvitation: { target: '.managingDeviceInvitation', actions: ['setInvitation', 'log'] },
86
86
  chooseDevices: { target: '.managingDevices', actions: 'log' },
87
87
  chooseProfile: { target: '.managingProfile', actions: 'log' },
88
+ chooseSignOut: { target: '.signingOut', actions: 'log' },
88
89
  chooseAgent: { target: '.managingAgent', actions: 'log' },
89
- // chooseSignOut: { target: '.signingOut', actions: 'log' },
90
90
  },
91
91
  },
92
92
  {
@@ -0,0 +1,61 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { useTranslation } from '@dxos/react-ui';
8
+
9
+ import { Action, Actions, StepHeading, Input } from '../../../components';
10
+ import { type AgentFormProps, type IdentityPanelStepProps } from '../IdentityPanelProps';
11
+
12
+ export const AgentForm = (props: IdentityPanelStepProps & AgentFormProps) => {
13
+ const {
14
+ active,
15
+ onAgentCreate,
16
+ onAgentDestroy,
17
+ send,
18
+ validationMessage,
19
+ agentStatus,
20
+ agentActive,
21
+ agentProviderDisabled,
22
+ } = props;
23
+ const disabled = !active;
24
+ const { t } = useTranslation('os');
25
+ return (
26
+ <>
27
+ <div role='none' className='grow flex flex-col justify-center'>
28
+ <Input
29
+ {...{ validationMessage }}
30
+ label={<StepHeading>Agent Status</StepHeading>}
31
+ disabled={disabled}
32
+ data-testid='agent-status'
33
+ value={agentStatus}
34
+ />
35
+ </div>
36
+ <Actions>
37
+ <Action
38
+ disabled={agentActive || agentProviderDisabled}
39
+ onClick={() => onAgentCreate?.()}
40
+ data-testid={'create-agent'}
41
+ >
42
+ Create Agent
43
+ </Action>
44
+ <Action
45
+ disabled={!agentActive || agentProviderDisabled}
46
+ onClick={() => onAgentDestroy?.()}
47
+ data-testid={'destroy-agent'}
48
+ >
49
+ Destroy Agent
50
+ </Action>
51
+ <Action
52
+ disabled={disabled}
53
+ onClick={() => send?.({ type: 'unchooseAction' })}
54
+ data-testid={'update-profile-form-back'}
55
+ >
56
+ {t('back label')}
57
+ </Action>
58
+ </Actions>
59
+ </>
60
+ );
61
+ };
@@ -88,12 +88,7 @@ export const IdentityActionChooserImpl = ({
88
88
  <span className='grow mli-3'>{t('choose profile label')}</span>
89
89
  <CaretRight weight='bold' className={getSize(4)} />
90
90
  </Action>
91
- <Action
92
- disabled
93
- data-testid='sign-out'
94
- onClick={() => {} /* send({ type: 'chooseSignOut' }) */}
95
- classNames='plb-4'
96
- >
91
+ <Action data-testid='sign-out' onClick={() => send?.({ type: 'chooseSignOut' })} classNames='plb-4'>
97
92
  <Power className={getSize(6)} />
98
93
  <span className='grow mli-3'>{t('choose sign out label')}</span>
99
94
  <CaretRight weight='bold' className={getSize(4)} />
@@ -0,0 +1,82 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { Warning } from '@phosphor-icons/react';
6
+ import React from 'react';
7
+ import { type Event, type SingleOrArray } from 'xstate';
8
+
9
+ import { Message, useTranslation } from '@dxos/react-ui';
10
+ import { getSize, mx } from '@dxos/react-ui-theme';
11
+
12
+ import { Action, Actions } from '../../../components';
13
+ import { type IdentityPanelStepProps } from '../IdentityPanelProps';
14
+ import { type IdentityEvent } from '../identityMachine';
15
+
16
+ export interface SignOutChooserProps extends Omit<IdentityPanelStepProps, 'send'> {
17
+ send?: (event: SingleOrArray<Event<IdentityEvent>>) => void;
18
+ onResetDevice?: () => Promise<void>;
19
+ onJoinNewIdentity?: () => void;
20
+ }
21
+
22
+ export const SignOutChooser = (props: SignOutChooserProps) => {
23
+ const { t } = useTranslation('os');
24
+ const onResetDevice = () => {
25
+ if (window.confirm(t('reset device confirm message'))) {
26
+ void props.onResetDevice?.();
27
+ }
28
+ };
29
+ return (
30
+ <SignOutChooserImpl
31
+ disabled={!props.active}
32
+ onBack={() => props.send?.({ type: 'unchooseAction' })}
33
+ onResetDevice={onResetDevice}
34
+ onJoinNewIdentity={props.onJoinNewIdentity}
35
+ />
36
+ );
37
+ };
38
+
39
+ export type SignOutChooserImplProps = {
40
+ disabled?: boolean;
41
+ onResetDevice?: () => void;
42
+ onJoinNewIdentity?: () => void;
43
+ onBack?: () => void;
44
+ };
45
+
46
+ const SignOutChooserImpl = ({ disabled, onResetDevice, onJoinNewIdentity, onBack }: SignOutChooserImplProps) => {
47
+ const { t } = useTranslation('os');
48
+ return (
49
+ <>
50
+ <div role='none' className='grow flex flex-col justify-center'>
51
+ <Message.Root valence='error'>
52
+ <Message.Title>
53
+ <Warning className={mx(getSize(6), 'inline mie-2')} />
54
+ {t('sign out chooser title')}
55
+ </Message.Title>
56
+ <Message.Body>{t('sign out chooser message')}</Message.Body>
57
+ </Message.Root>
58
+ </div>
59
+ <Actions>
60
+ <Action disabled={disabled} onClick={onBack}>
61
+ {t('back label')}
62
+ </Action>
63
+ <Action
64
+ variant='primary'
65
+ classNames='!bg-error-500 hover:!bg-error-550'
66
+ disabled={disabled}
67
+ onClick={onJoinNewIdentity}
68
+ >
69
+ {t('join new identity label')}
70
+ </Action>
71
+ <Action
72
+ variant='primary'
73
+ classNames='!bg-error-500 hover:!bg-error-550'
74
+ disabled={disabled}
75
+ onClick={onResetDevice}
76
+ >
77
+ {t('reset device label')}
78
+ </Action>
79
+ </Actions>
80
+ </>
81
+ );
82
+ };
@@ -2,7 +2,8 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ export * from './AgentForm';
5
6
  export * from './DeviceManager';
6
7
  export * from './IdentityActionChooser';
7
8
  export * from './ProfileForm';
8
- export * from './AgentPanel';
9
+ export * from './SignOutChooser';
@@ -0,0 +1,88 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { useCallback, useEffect, useState } from 'react';
6
+
7
+ import { type CancellableInvitation } from '@dxos/client-protocol';
8
+ import { invariant } from '@dxos/invariant';
9
+ import { useAgentHostingProviderClient, type Client } from '@dxos/react-client';
10
+ import { type Identity } from '@dxos/react-client/halo';
11
+ import { Invitation, InvitationEncoder } from '@dxos/react-client/invitations';
12
+
13
+ export const useAgentHandlers = ({
14
+ client,
15
+ invitations,
16
+ identity,
17
+ }: {
18
+ client: Client;
19
+ invitations: CancellableInvitation[];
20
+ identity: Identity | null;
21
+ }) => {
22
+ const [validationMessage, setValidationMessage] = useState('');
23
+ const [agentStatus, setAgentStatus] = useState('');
24
+ const [agentActive, setAgentActive] = useState(false);
25
+ const agentHostingProviderClient = useAgentHostingProviderClient(client.config);
26
+
27
+ useEffect(() => {
28
+ const fetchAgentStatus = async () => {
29
+ // TODO(nf): if agent exists, subscribe to updates instead of oneshot status
30
+ if (agentHostingProviderClient) {
31
+ const agentStatus = await agentHostingProviderClient?.getAgent(identity?.identityKey.truncate() ?? 'foo');
32
+ if (agentStatus) {
33
+ setAgentActive(true);
34
+ setAgentStatus(agentStatus);
35
+ } else {
36
+ setAgentActive(false);
37
+ setValidationMessage('No agent deployed via provider.');
38
+ }
39
+ } else {
40
+ setValidationMessage('No agent provider configured.');
41
+ }
42
+ };
43
+ void fetchAgentStatus();
44
+ }, []);
45
+
46
+ const handleAgentCreate = useCallback(async (invitation: Invitation) => {
47
+ const invitationCode = InvitationEncoder.encode(invitation);
48
+ if (invitation.state === Invitation.State.CONNECTING) {
49
+ console.log(JSON.stringify({ invitationCode, authCode: invitation.authCode }));
50
+ invariant(identity, 'Identity not found');
51
+ if (agentHostingProviderClient) {
52
+ try {
53
+ const res = await agentHostingProviderClient?.createAgent(invitationCode, identity.identityKey.truncate());
54
+ // TODO(nf): human-consumable response from API
55
+ setAgentStatus(res);
56
+ setAgentActive(true);
57
+ setValidationMessage('');
58
+ } catch (err: any) {
59
+ setValidationMessage(`error creating agent: ${err.message}`);
60
+ }
61
+ }
62
+ }
63
+ }, []);
64
+
65
+ const onAgentCreate = async () => {
66
+ invitations.forEach((invitation) => invitation.cancel());
67
+
68
+ // TODO(nf): do this work in the hosting provider client?
69
+ const invitation = client.halo.share({ type: Invitation.Type.MULTIUSE, authMethod: Invitation.AuthMethod.NONE });
70
+
71
+ invitation.subscribe(handleAgentCreate);
72
+ };
73
+
74
+ const onAgentDestroy = async () => {
75
+ const identity = client.halo.identity.get();
76
+ invariant(identity, 'Identity not found');
77
+ try {
78
+ await agentHostingProviderClient?.destroyAgent(identity.identityKey.truncate());
79
+ setValidationMessage('No agent deployed via provider.');
80
+ setAgentStatus('');
81
+ setAgentActive(false);
82
+ } catch (err: any) {
83
+ setValidationMessage(`error destroying agent: ${err.message}`);
84
+ }
85
+ };
86
+
87
+ return { onAgentCreate, onAgentDestroy, validationMessage, agentStatus, agentActive };
88
+ };