@dxos/shell 0.3.11-main.9fa973d → 0.3.11-main.a53382c

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
@@ -99,4 +99,9 @@ export const os = {
99
99
  'This will clear this device and all associated data. Type {{confirmationValue}} and confirm to continue.',
100
100
  'failed to reset identity message': 'Failed to reset identity.',
101
101
  'confirmation value': 'CONFIRM',
102
+ 'sign out chooser title': 'DANGER ZONE',
103
+ 'sign out chooser message': 'Proceeding with either action below will erase all data on this device.',
104
+ 'join new identity label': 'Join a new identity',
105
+ 'reset device label': 'Reset device',
106
+ 'reset device confirm message': 'Are you sure you want to reset your device? All data will be lost.',
102
107
  };
@@ -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;A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yBAAc,EAAC,IAAI,CAAC,CAAC;IACnC,OAAO,CACL;QACE,uCAAK,IAAI,EAAC,MAAM,EAAC,SAAS,EAAC,mCAAmC;YAC5D,8BAAC,kBAAK,IACE,iBAAiB,EACvB,KAAK,EAAE,8BAAC,wBAAW,uBAA2B,EAC9C,QAAQ,EAAE,QAAQ,iBACN,cAAc,EAC1B,KAAK,EAAE,WAAW,GAClB,CACE;QACN,8BAAC,oBAAO;YACN,8BAAC,mBAAM,IACL,QAAQ,EAAE,WAAW,IAAI,qBAAqB,EAC9C,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,aAAb,aAAa,uBAAb,aAAa,EAAI,iBACnB,cAAc,mBAGpB;YACT,8BAAC,mBAAM,IACL,QAAQ,EAAE,CAAC,WAAW,IAAI,qBAAqB,EAC/C,OAAO,EAAE,GAAG,EAAE,CAAC,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
- };