@dxos/shell 0.6.13-main.ed424a1 → 0.6.13-staging.1e988a3
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/dist/bundle/shell.mjs +10165 -9870
- package/dist/bundle/shell.mjs.map +1 -1
- package/dist/bundle/shell.umd.js +78 -76
- package/dist/bundle/shell.umd.js.map +1 -1
- package/dist/bundle/style.css +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react.mjs +96 -195
- package/dist/lib/browser/react.mjs.map +4 -4
- package/dist/types/src/composites/Shell/run-shell.js +1 -1
- package/dist/types/src/composites/Shell/run-shell.js.map +1 -1
- package/dist/types/src/panels/IdentityPanel/IdentityPanel.stories.d.ts.map +1 -1
- package/dist/types/src/panels/IdentityPanel/IdentityPanel.stories.js +1 -6
- package/dist/types/src/panels/IdentityPanel/IdentityPanel.stories.js.map +1 -1
- package/dist/types/src/panels/IdentityPanel/useAgentHandlers.d.ts +1 -1
- package/dist/types/src/panels/IdentityPanel/useAgentHandlers.d.ts.map +1 -1
- package/dist/types/src/panels/IdentityPanel/useAgentHandlers.js +108 -10
- package/dist/types/src/panels/IdentityPanel/useAgentHandlers.js.map +1 -1
- package/dist/types/src/playwright/invitations-manager.d.ts +1 -1
- package/dist/types/src/playwright/invitations-manager.d.ts.map +1 -1
- package/dist/types/src/playwright/invitations-manager.js +10 -4
- package/dist/types/src/playwright/invitations-manager.js.map +1 -1
- package/dist/types/src/playwright/invitations.spec.js +32 -31
- package/dist/types/src/playwright/invitations.spec.js.map +1 -1
- package/dist/types/src/playwright/playwright.config.d.ts +2 -2
- package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
- package/dist/types/src/playwright/playwright.config.js +2 -12
- package/dist/types/src/playwright/playwright.config.js.map +1 -1
- package/package.json +26 -27
- package/src/composites/Shell/run-shell.tsx +1 -1
- package/src/panels/IdentityPanel/IdentityPanel.stories.tsx +1 -6
- package/src/panels/IdentityPanel/useAgentHandlers.ts +114 -9
- package/src/playwright/invitations-manager.ts +8 -4
- package/src/playwright/invitations.spec.ts +33 -32
- package/src/playwright/playwright.config.ts +2 -13
- package/dist/types/src/panels/IdentityPanel/useEdgeAgentsHandlers.d.ts +0 -8
- package/dist/types/src/panels/IdentityPanel/useEdgeAgentsHandlers.d.ts.map +0 -1
- package/dist/types/src/panels/IdentityPanel/useEdgeAgentsHandlers.js +0 -84
- package/dist/types/src/panels/IdentityPanel/useEdgeAgentsHandlers.js.map +0 -1
- package/dist/types/src/panels/IdentityPanel/useKubeAgentHandlers.d.ts +0 -8
- package/dist/types/src/panels/IdentityPanel/useKubeAgentHandlers.d.ts.map +0 -1
- package/dist/types/src/panels/IdentityPanel/useKubeAgentHandlers.js +0 -119
- package/dist/types/src/panels/IdentityPanel/useKubeAgentHandlers.js.map +0 -1
- package/src/panels/IdentityPanel/useEdgeAgentsHandlers.ts +0 -96
- package/src/panels/IdentityPanel/useKubeAgentHandlers.ts +0 -128
|
@@ -1,128 +0,0 @@
|
|
|
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 { log } from '@dxos/log';
|
|
10
|
-
import { useClient, useAgentHostingClient } from '@dxos/react-client';
|
|
11
|
-
import { type Identity } from '@dxos/react-client/halo';
|
|
12
|
-
import { Invitation, InvitationEncoder } from '@dxos/react-client/invitations';
|
|
13
|
-
|
|
14
|
-
import { type AgentFormProps } from '../../components';
|
|
15
|
-
|
|
16
|
-
export const useKubeAgentHandlers = ({
|
|
17
|
-
invitations,
|
|
18
|
-
identity,
|
|
19
|
-
}: {
|
|
20
|
-
invitations: CancellableInvitation[];
|
|
21
|
-
identity: Identity | null;
|
|
22
|
-
}): AgentFormProps => {
|
|
23
|
-
const [validationMessage, setValidationMessage] = useState('');
|
|
24
|
-
const [agentStatus, setAgentStatus] = useState<AgentFormProps['agentStatus']>('getting');
|
|
25
|
-
const agentHostingProviderClient = useAgentHostingClient();
|
|
26
|
-
const client = useClient();
|
|
27
|
-
|
|
28
|
-
const updateAgentStatus = async () => {
|
|
29
|
-
// TODO(nf): if agent exists, subscribe to updates instead of oneshot status
|
|
30
|
-
if (agentHostingProviderClient) {
|
|
31
|
-
setAgentStatus('getting');
|
|
32
|
-
try {
|
|
33
|
-
const agentId = await agentHostingProviderClient?.getAgent(identity?.identityKey.truncate() ?? 'never');
|
|
34
|
-
if (agentId) {
|
|
35
|
-
setAgentStatus('created');
|
|
36
|
-
} else {
|
|
37
|
-
setAgentStatus('creatable');
|
|
38
|
-
}
|
|
39
|
-
} catch (err: any) {
|
|
40
|
-
setAgentStatus('error');
|
|
41
|
-
setValidationMessage(`Couldn’t check agent status: ${err.message}`);
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
setAgentStatus('error');
|
|
45
|
-
setValidationMessage('No agent provider configured.');
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const createAgent = async (invitationCode: string) => {
|
|
50
|
-
invariant(identity, 'Identity not found');
|
|
51
|
-
if (agentHostingProviderClient) {
|
|
52
|
-
setAgentStatus('creating');
|
|
53
|
-
setValidationMessage('');
|
|
54
|
-
try {
|
|
55
|
-
const agentId = await agentHostingProviderClient?.createAgent(invitationCode, identity.identityKey.truncate());
|
|
56
|
-
if (agentId) {
|
|
57
|
-
setAgentStatus('created');
|
|
58
|
-
} else {
|
|
59
|
-
setAgentStatus('creatable');
|
|
60
|
-
setValidationMessage('Error creating agent.');
|
|
61
|
-
}
|
|
62
|
-
} catch (err: any) {
|
|
63
|
-
setValidationMessage(`Error creating agent: ${err.message}`);
|
|
64
|
-
return updateAgentStatus();
|
|
65
|
-
}
|
|
66
|
-
} else {
|
|
67
|
-
setAgentStatus('error');
|
|
68
|
-
setValidationMessage('No agent provider configured.');
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const destroyAgent = async () => {
|
|
73
|
-
invariant(identity, 'Identity not found');
|
|
74
|
-
if (agentHostingProviderClient) {
|
|
75
|
-
setAgentStatus('destroying');
|
|
76
|
-
setValidationMessage('');
|
|
77
|
-
try {
|
|
78
|
-
await agentHostingProviderClient?.destroyAgent(identity.identityKey.truncate());
|
|
79
|
-
setAgentStatus('creatable');
|
|
80
|
-
} catch (err: any) {
|
|
81
|
-
setValidationMessage(`Error destroying agent: ${err.message}`);
|
|
82
|
-
return updateAgentStatus();
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
setAgentStatus('error');
|
|
86
|
-
setValidationMessage('No agent provider configured.');
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
void updateAgentStatus();
|
|
92
|
-
}, []);
|
|
93
|
-
|
|
94
|
-
const handleAgentCreate = useCallback(async (invitation: Invitation) => {
|
|
95
|
-
const invitationCode = InvitationEncoder.encode(invitation);
|
|
96
|
-
if (invitation.state === Invitation.State.CONNECTING) {
|
|
97
|
-
log.info(JSON.stringify({ invitationCode, authCode: invitation.authCode }));
|
|
98
|
-
return createAgent(invitationCode);
|
|
99
|
-
}
|
|
100
|
-
}, []);
|
|
101
|
-
|
|
102
|
-
const onAgentCreate = async () => {
|
|
103
|
-
invitations.forEach((invitation) => invitation.cancel());
|
|
104
|
-
|
|
105
|
-
// TODO(nf): do this work in the hosting provider client?
|
|
106
|
-
const invitation = client.halo.share({
|
|
107
|
-
type: Invitation.Type.INTERACTIVE,
|
|
108
|
-
authMethod: Invitation.AuthMethod.NONE,
|
|
109
|
-
multiUse: true,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
invitation.subscribe(handleAgentCreate);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const onAgentRefresh = async () => {
|
|
116
|
-
setValidationMessage('');
|
|
117
|
-
await updateAgentStatus();
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
onAgentCreate,
|
|
122
|
-
onAgentDestroy: destroyAgent,
|
|
123
|
-
onAgentRefresh,
|
|
124
|
-
validationMessage,
|
|
125
|
-
agentStatus,
|
|
126
|
-
agentHostingEnabled: !!agentHostingProviderClient,
|
|
127
|
-
};
|
|
128
|
-
};
|