@dxos/react-client 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae
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/.storybook/main.mts +2 -4
- package/.storybook/preview.mts +2 -2
- package/dist/lib/browser/chunk-5UKA2BMA.mjs +179 -0
- package/dist/lib/browser/chunk-5UKA2BMA.mjs.map +7 -0
- package/dist/lib/browser/chunk-PFF63FPR.mjs +16 -0
- package/dist/lib/browser/chunk-PFF63FPR.mjs.map +7 -0
- package/dist/lib/browser/chunk-TSF6Y5VB.mjs +8 -0
- package/dist/lib/browser/chunk-TSF6Y5VB.mjs.map +7 -0
- package/dist/lib/browser/devtools/index.mjs +2 -1
- package/dist/lib/browser/devtools/index.mjs.map +1 -1
- package/dist/lib/browser/echo/index.mjs +44 -94
- package/dist/lib/browser/echo/index.mjs.map +4 -4
- package/dist/lib/browser/halo/index.mjs +7 -20
- package/dist/lib/browser/halo/index.mjs.map +2 -2
- package/dist/lib/browser/index.mjs +114 -12
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/mesh/index.mjs +2 -1
- package/dist/lib/browser/mesh/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +83 -110
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-373DPHEQ.mjs +10 -0
- package/dist/lib/node-esm/chunk-373DPHEQ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NETTSER2.mjs +17 -0
- package/dist/lib/node-esm/chunk-NETTSER2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-T3QTQHBD.mjs +180 -0
- package/dist/lib/node-esm/chunk-T3QTQHBD.mjs.map +7 -0
- package/dist/lib/node-esm/devtools/index.mjs +2 -1
- package/dist/lib/node-esm/devtools/index.mjs.map +1 -1
- package/dist/lib/node-esm/echo/index.mjs +44 -94
- package/dist/lib/node-esm/echo/index.mjs.map +4 -4
- package/dist/lib/node-esm/halo/index.mjs +7 -20
- package/dist/lib/node-esm/halo/index.mjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +114 -12
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/mesh/index.mjs +2 -1
- package/dist/lib/node-esm/mesh/index.mjs.map +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +83 -110
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/client/ClientProvider.d.ts +0 -10
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
- package/dist/types/src/echo/index.d.ts +2 -2
- package/dist/types/src/echo/index.d.ts.map +1 -1
- package/dist/types/src/echo/useMembers.d.ts +2 -2
- package/dist/types/src/echo/useMembers.d.ts.map +1 -1
- package/dist/types/src/echo/useQueue.d.ts +2 -2
- package/dist/types/src/echo/useQueue.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaceInvitations.d.ts +3 -2
- package/dist/types/src/echo/useSpaceInvitations.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaceProperties.d.ts +13 -0
- package/dist/types/src/echo/useSpaceProperties.d.ts.map +1 -0
- package/dist/types/src/echo/useSpaces.d.ts +17 -8
- package/dist/types/src/echo/useSpaces.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.d.ts +5 -4
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -1
- package/dist/types/src/testing/context.d.ts +4 -2
- package/dist/types/src/testing/context.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.d.ts +0 -3
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.stories.d.ts +1 -0
- package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/docs/README.md +38 -38
- package/moon.yml +2 -5
- package/package.json +35 -32
- package/src/client/ClientProvider.tsx +12 -26
- package/src/echo/index.ts +2 -2
- package/src/echo/useMembers.ts +5 -3
- package/src/echo/useQueue.ts +2 -2
- package/src/echo/useSpaceInvitations.ts +9 -4
- package/src/echo/useSpaceProperties.ts +28 -0
- package/src/echo/useSpaces.test.tsx +1 -1
- package/src/echo/useSpaces.ts +33 -12
- package/src/echo/useSyncState.ts +2 -2
- package/src/halo/Passkey.stories.tsx +3 -3
- package/src/testing/ClientRepeater.stories.tsx +9 -4
- package/src/testing/ClientRepeater.tsx +9 -12
- package/src/testing/context.tsx +4 -3
- package/src/testing/withClientProvider.stories.tsx +14 -9
- package/src/testing/withClientProvider.tsx +62 -79
- package/tsconfig.json +3 -3
- package/typedoc.json +1 -1
- package/vitest.config.ts +1 -1
- package/dist/lib/browser/chunk-TA2HGRAF.mjs +0 -309
- package/dist/lib/browser/chunk-TA2HGRAF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZJMNF7GC.mjs +0 -311
- package/dist/lib/node-esm/chunk-ZJMNF7GC.mjs.map +0 -7
- package/dist/types/src/echo/useQuery.d.ts +0 -11
- package/dist/types/src/echo/useQuery.d.ts.map +0 -1
- package/dist/types/src/echo/useQuery.test.d.ts +0 -2
- package/dist/types/src/echo/useQuery.test.d.ts.map +0 -1
- package/dist/types/src/echo/useSchema.d.ts +0 -8
- package/dist/types/src/echo/useSchema.d.ts.map +0 -1
- package/dist/types/src/playwright/playwright.config.d.ts +0 -3
- package/dist/types/src/playwright/playwright.config.d.ts.map +0 -1
- package/dist/types/src/playwright/smoke.spec.d.ts +0 -2
- package/dist/types/src/playwright/smoke.spec.d.ts.map +0 -1
- package/src/echo/useQuery.test.tsx +0 -129
- package/src/echo/useQuery.ts +0 -72
- package/src/echo/useSchema.ts +0 -54
- package/src/playwright/playwright.config.ts +0 -17
- package/src/playwright/smoke.spec.ts +0 -24
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, { type FC,
|
|
5
|
+
import React, { type FC, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import { Client
|
|
7
|
+
import { Client } from '@dxos/client';
|
|
8
8
|
import { TestBuilder, performInvitation } from '@dxos/client/testing';
|
|
9
|
-
import { type
|
|
10
|
-
import { registerSignalsRuntime } from '@dxos/echo-signals/react';
|
|
9
|
+
import { type Type } from '@dxos/echo';
|
|
11
10
|
import { faker } from '@dxos/random';
|
|
12
11
|
import { useAsyncEffect } from '@dxos/react-hooks';
|
|
13
12
|
|
|
14
13
|
import { ClientProvider } from '../client';
|
|
14
|
+
import { type SpaceId } from '../echo';
|
|
15
15
|
|
|
16
16
|
import { type WithClientProviderProps } from './withClientProvider';
|
|
17
17
|
|
|
18
|
-
export type ClientRepeatedComponentProps = { id: number; count: number;
|
|
18
|
+
export type ClientRepeatedComponentProps = { id: number; count: number; spaceId?: SpaceId };
|
|
19
19
|
|
|
20
20
|
export type ClientRepeaterControlsProps = { clients: Client[] };
|
|
21
21
|
|
|
@@ -26,7 +26,7 @@ export type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {
|
|
|
26
26
|
controls?: FC<ClientRepeaterControlsProps>;
|
|
27
27
|
count?: number;
|
|
28
28
|
clients?: Client[];
|
|
29
|
-
types?:
|
|
29
|
+
types?: Type.AnyObj[];
|
|
30
30
|
args?: Omit<P, 'id' | 'count'>;
|
|
31
31
|
} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onCreateSpace'>;
|
|
32
32
|
|
|
@@ -50,12 +50,9 @@ export const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: Cl
|
|
|
50
50
|
createSpace,
|
|
51
51
|
onCreateSpace,
|
|
52
52
|
} = props;
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
registerSignalsRuntime();
|
|
55
|
-
}, []);
|
|
56
53
|
|
|
57
54
|
const [clients, setClients] = useState(props.clients ?? []);
|
|
58
|
-
const [
|
|
55
|
+
const [spaceId, setSpaceId] = useState<SpaceId>();
|
|
59
56
|
|
|
60
57
|
const testBuilder = useRef(new TestBuilder());
|
|
61
58
|
useAsyncEffect(async () => {
|
|
@@ -71,7 +68,7 @@ export const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: Cl
|
|
|
71
68
|
if (createSpace) {
|
|
72
69
|
const client = clients[0];
|
|
73
70
|
const space = await client.spaces.create({ name: faker.commerce.productName() });
|
|
74
|
-
|
|
71
|
+
setSpaceId(space.id);
|
|
75
72
|
await onCreateSpace?.({ client, space }, {});
|
|
76
73
|
await Promise.all(clients.slice(1).flatMap((client) => performInvitation({ host: space, guest: client.spaces })));
|
|
77
74
|
}
|
|
@@ -88,7 +85,7 @@ export const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: Cl
|
|
|
88
85
|
{Controls && <Controls clients={clients} />}
|
|
89
86
|
{clients.map((client, index) => (
|
|
90
87
|
<ClientProvider key={index} client={client}>
|
|
91
|
-
<Component id={index} count={clients.length}
|
|
88
|
+
<Component id={index} count={clients.length} spaceId={spaceId} {...{ ...props.args }} />
|
|
92
89
|
</ClientProvider>
|
|
93
90
|
))}
|
|
94
91
|
</>
|
package/src/testing/context.tsx
CHANGED
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import { createContext, useContext } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type Space } from '@dxos/client/echo';
|
|
7
|
+
import { type Space, type SpaceId } from '@dxos/client/echo';
|
|
8
8
|
import { raise } from '@dxos/debug';
|
|
9
9
|
|
|
10
10
|
export type ClientStory = {
|
|
11
|
+
index?: number;
|
|
12
|
+
spaceId?: SpaceId;
|
|
11
13
|
space?: Space;
|
|
12
14
|
};
|
|
13
15
|
|
|
14
|
-
// TODO(wittjosiah): Add to multi-client as well.
|
|
15
16
|
export const ClientStory = createContext<ClientStory | undefined>(undefined);
|
|
16
17
|
|
|
17
|
-
export const
|
|
18
|
+
export const useClientStory = (): ClientStory => {
|
|
18
19
|
return useContext(ClientStory) ?? raise(new Error('Missing ClientStory'));
|
|
19
20
|
};
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React from 'react';
|
|
7
|
+
import { expect, within } from 'storybook/test';
|
|
7
8
|
|
|
8
9
|
import { log } from '@dxos/log';
|
|
9
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
10
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
11
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
11
12
|
import { render } from '@dxos/storybook-utils';
|
|
12
13
|
|
|
@@ -40,7 +41,8 @@ const DefaultStory = () => {
|
|
|
40
41
|
const meta = {
|
|
41
42
|
title: 'sdk/react-client/withClientProvider',
|
|
42
43
|
render: render(DefaultStory),
|
|
43
|
-
decorators: [withTheme],
|
|
44
|
+
decorators: [withTheme()],
|
|
45
|
+
tags: ['test'],
|
|
44
46
|
} satisfies Meta<typeof DefaultStory>;
|
|
45
47
|
|
|
46
48
|
export default meta;
|
|
@@ -63,14 +65,17 @@ export const Default: Story = {
|
|
|
63
65
|
parameters: {
|
|
64
66
|
layout: 'centered',
|
|
65
67
|
},
|
|
68
|
+
play: async ({ canvasElement }) => {
|
|
69
|
+
const canvas = within(canvasElement);
|
|
70
|
+
const initializedText = await canvas.findByText(/"initialized": true/i, {}, { timeout: 30_000 });
|
|
71
|
+
await expect(initializedText).toBeVisible();
|
|
72
|
+
},
|
|
66
73
|
};
|
|
67
74
|
|
|
68
75
|
export const Multiple: Story = {
|
|
69
|
-
decorators: [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
+
decorators: [
|
|
77
|
+
withTheme(),
|
|
78
|
+
withLayout({ classNames: 'grid grid-cols-3' }),
|
|
79
|
+
withMultiClientProvider({ ...clientProps, numClients: 3 }),
|
|
80
|
+
],
|
|
76
81
|
};
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Decorator, type StoryContext } from '@storybook/react';
|
|
6
|
-
import React, {
|
|
7
|
-
import { type FallbackProps, ErrorBoundary as NaturalErrorBoundary } from 'react-error-boundary';
|
|
6
|
+
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
8
7
|
|
|
9
8
|
import { Trigger } from '@dxos/async';
|
|
10
9
|
import { type Client } from '@dxos/client';
|
|
11
|
-
import { type Space } from '@dxos/client/echo';
|
|
10
|
+
import { type Space, type SpaceId } from '@dxos/client/echo';
|
|
12
11
|
import { TestBuilder, performInvitation } from '@dxos/client/testing';
|
|
13
12
|
import { log } from '@dxos/log';
|
|
13
|
+
import { ErrorBoundary } from '@dxos/react-ui';
|
|
14
14
|
import { type MaybePromise } from '@dxos/util';
|
|
15
15
|
|
|
16
16
|
import { ClientProvider, type ClientProviderProps } from '../client';
|
|
@@ -52,7 +52,7 @@ const initializeClient = async (
|
|
|
52
52
|
await onCreateSpace?.({ client, space }, context);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
return { space };
|
|
55
|
+
return { space, spaceId: space?.id };
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
export type WithClientProviderProps = InitializeProps & Omit<ClientProviderProps, 'onInitialized'>;
|
|
@@ -87,7 +87,7 @@ export const withClientProvider = ({
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
return (
|
|
90
|
-
<ErrorBoundary>
|
|
90
|
+
<ErrorBoundary name='client-provider'>
|
|
91
91
|
<ClientProvider onInitialized={handleInitialized} {...props}>
|
|
92
92
|
<ClientStory.Provider value={data}>
|
|
93
93
|
<Story />
|
|
@@ -104,10 +104,6 @@ export const withClientProvider = ({
|
|
|
104
104
|
export type WithMultiClientProviderProps = InitializeProps &
|
|
105
105
|
Omit<ClientProviderProps, 'onInitialized'> & { numClients?: number };
|
|
106
106
|
|
|
107
|
-
const MultiClientContext = createContext<{ id: number }>({ id: 0 });
|
|
108
|
-
|
|
109
|
-
export const useMultiClient = () => useContext(MultiClientContext);
|
|
110
|
-
|
|
111
107
|
/**
|
|
112
108
|
* Decorator that creates a scaffold for multiple clients.
|
|
113
109
|
* Orchestrates invitations between a randomly selected host and the remaining clients.
|
|
@@ -122,86 +118,73 @@ export const withMultiClientProvider = ({
|
|
|
122
118
|
...props
|
|
123
119
|
}: WithMultiClientProviderProps): Decorator => {
|
|
124
120
|
return (Story, context) => {
|
|
125
|
-
const builder = useRef(new TestBuilder());
|
|
126
|
-
const hostRef = useRef<Client>(null);
|
|
127
121
|
const spaceReady = useRef(new Trigger<Space | undefined>());
|
|
122
|
+
const [spaceId, setSpaceId] = useState<SpaceId>();
|
|
123
|
+
|
|
124
|
+
const clients = useMemo(() => {
|
|
125
|
+
const buidler = new TestBuilder();
|
|
126
|
+
return Array.from({ length: numClients }).map(() => {
|
|
127
|
+
return {
|
|
128
|
+
services: buidler.createLocalClientServices(),
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}, [numClients]);
|
|
128
132
|
|
|
129
133
|
// Handle invitations.
|
|
130
134
|
// NOTE: The zeroth client isn't necessarily the first to be initialized.
|
|
131
|
-
const handleInitialized = async (client: Client, index: number) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
135
|
+
const handleInitialized = useCallback(async (client: Client, index: number) => {
|
|
136
|
+
if (index === 0) {
|
|
137
|
+
// Initialize host.
|
|
138
|
+
const { space } = await initializeClient(
|
|
139
|
+
client,
|
|
140
|
+
{
|
|
141
|
+
createIdentity,
|
|
142
|
+
createSpace,
|
|
143
|
+
onCreateSpace,
|
|
144
|
+
onCreateIdentity,
|
|
145
|
+
onInitialized,
|
|
146
|
+
},
|
|
147
|
+
context,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
log.info('inviting', { index, spaceId: space?.id });
|
|
151
|
+
setSpaceId(space?.id);
|
|
152
|
+
spaceReady.current.wake(space);
|
|
153
|
+
} else {
|
|
154
|
+
// Initialize guest.
|
|
155
|
+
await initializeClient(client, { createIdentity, onInitialized }, context);
|
|
156
|
+
|
|
157
|
+
log.info('waiting', { index });
|
|
158
|
+
const space = await spaceReady.current.wait();
|
|
159
|
+
if (space) {
|
|
160
|
+
log.info('joining', { index, spaceId: space.id });
|
|
161
|
+
await Promise.all(
|
|
162
|
+
performInvitation({
|
|
163
|
+
host: space,
|
|
164
|
+
guest: client.spaces,
|
|
165
|
+
}),
|
|
146
166
|
);
|
|
147
|
-
|
|
148
|
-
spaceReady.current.wake(space);
|
|
149
|
-
log.info('inviting', { index });
|
|
150
|
-
} else {
|
|
151
|
-
await initializeClient(client, { createIdentity, onInitialized }, context);
|
|
152
|
-
const space = await spaceReady.current.wait();
|
|
153
|
-
if (space) {
|
|
154
|
-
log.info('joining', { index });
|
|
155
|
-
await Promise.all(performInvitation({ host: space, guest: client.spaces }));
|
|
156
|
-
}
|
|
157
167
|
}
|
|
158
168
|
}
|
|
159
|
-
};
|
|
169
|
+
}, []);
|
|
160
170
|
|
|
161
171
|
return (
|
|
162
|
-
<
|
|
163
|
-
{
|
|
164
|
-
<
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
<div className='absolute inset-0 grid grid-flow-col auto-cols-fr gap-4 overflow-hidden'>
|
|
173
|
+
{clients.map((client, index) => (
|
|
174
|
+
<ClientProvider
|
|
175
|
+
key={index}
|
|
176
|
+
services={client.services}
|
|
177
|
+
onInitialized={(client) => handleInitialized(client, index)}
|
|
178
|
+
{...props}
|
|
179
|
+
>
|
|
180
|
+
<ClientStory.Provider value={{ index, spaceId }}>
|
|
181
|
+
<ErrorBoundary name='client-provider'>
|
|
182
|
+
<Story />
|
|
183
|
+
</ErrorBoundary>
|
|
184
|
+
</ClientStory.Provider>
|
|
185
|
+
</ClientProvider>
|
|
173
186
|
))}
|
|
174
|
-
</
|
|
187
|
+
</div>
|
|
175
188
|
);
|
|
176
189
|
};
|
|
177
190
|
};
|
|
178
|
-
|
|
179
|
-
const ErrorBoundary = ({ children }: PropsWithChildren) => {
|
|
180
|
-
const [error, setError] = useState<Error>();
|
|
181
|
-
useEffect(() => {
|
|
182
|
-
const handleError = (event: PromiseRejectionEvent) => {
|
|
183
|
-
setError(event.reason);
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
window.addEventListener('unhandledrejection', handleError);
|
|
187
|
-
return () => window.removeEventListener('unhandledrejection', handleError);
|
|
188
|
-
}, []);
|
|
189
|
-
|
|
190
|
-
if (error) {
|
|
191
|
-
return <ErrorFallback error={error} resetErrorBoundary={() => setError(undefined)} />;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return <NaturalErrorBoundary FallbackComponent={ErrorFallback}>{children}</NaturalErrorBoundary>;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const ErrorFallback = ({ error }: FallbackProps) => {
|
|
198
|
-
const { name, message, stack } =
|
|
199
|
-
error instanceof Error ? error : { name: 'Error', message: String(error), stack: undefined };
|
|
200
|
-
return (
|
|
201
|
-
<div role='alert' className='flex flex-col p-4 gap-4 overflow-auto'>
|
|
202
|
-
<h1 className='text-xl text-red-500'>{name}</h1>
|
|
203
|
-
<div className='text-lg'>{message}</div>
|
|
204
|
-
{stack && <pre className='whitespace-pre-wrap text-sm text-subdued'>{stack}</pre>}
|
|
205
|
-
</div>
|
|
206
|
-
);
|
|
207
|
-
};
|
package/tsconfig.json
CHANGED
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"path": "../../core/echo/echo"
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
|
-
"path": "../../core/echo/echo-
|
|
48
|
+
"path": "../../core/echo/echo-react"
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
"path": "../../core/protocols"
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
|
-
"path": "../../ui/primitives/react-hooks"
|
|
54
|
+
"path": "../../ui/react-primitives/react-hooks"
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
57
|
"path": "../../ui/react-ui"
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"path": "../../ui/react-ui-syntax-highlighter"
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
|
-
"path": "../../ui/
|
|
63
|
+
"path": "../../ui/ui-theme"
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
"path": "../client"
|
package/typedoc.json
CHANGED
package/vitest.config.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { createConfig } from '../../../vitest.base.config';
|
|
|
10
10
|
export default createConfig({
|
|
11
11
|
dirname: typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url)),
|
|
12
12
|
node: {
|
|
13
|
-
environment: '
|
|
13
|
+
environment: 'happy-dom',
|
|
14
14
|
// TODO(dmaretskyi): Enabled because client tests were flaky. Remove when that's not the case.
|
|
15
15
|
retry: 2,
|
|
16
16
|
},
|
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
// src/client/AgentHostingProvider.tsx
|
|
2
|
-
import React2, { createContext as createContext2, useContext as useContext4, useState as useState4 } from "react";
|
|
3
|
-
import { AgentManagerClient, FakeAgentHostingProvider } from "@dxos/client";
|
|
4
|
-
import { log as log2 } from "@dxos/log";
|
|
5
|
-
|
|
6
|
-
// src/client/ClientProvider.tsx
|
|
7
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
|
8
|
-
import { Client, SystemStatus } from "@dxos/client";
|
|
9
|
-
import { registerSignalsRuntime } from "@dxos/echo-signals/react";
|
|
10
|
-
import { log } from "@dxos/log";
|
|
11
|
-
import { useAsyncEffect, useControlledState } from "@dxos/react-hooks";
|
|
12
|
-
import { getAsyncProviderValue } from "@dxos/util";
|
|
13
|
-
|
|
14
|
-
// src/banner.ts
|
|
15
|
-
var BANNER = (client) => {
|
|
16
|
-
const commitHash = client.config.get("runtime.app.build.commitHash");
|
|
17
|
-
const hash = commitHash ? ` App Commit ${commitHash}
|
|
18
|
-
` : "";
|
|
19
|
-
return `
|
|
20
|
-
_/\\/\\/\\/\\/\\____/\\/\\____/\\/\\____/\\/\\/\\/\\______/\\/\\/\\/\\/\\_
|
|
21
|
-
_/\\/\\____/\\/\\____/\\/\\/\\/\\____/\\/\\____/\\/\\__/\\/\\_________
|
|
22
|
-
_/\\/\\____/\\/\\______/\\/\\______/\\/\\____/\\/\\____/\\/\\/\\/\\___
|
|
23
|
-
_/\\/\\____/\\/\\____/\\/\\/\\/\\____/\\/\\____/\\/\\__________/\\/\\_
|
|
24
|
-
_/\\/\\/\\/\\/\\____/\\/\\____/\\/\\____/\\/\\/\\/\\____/\\/\\/\\/\\/\\___
|
|
25
|
-
|
|
26
|
-
DXOS Client ${client.version}
|
|
27
|
-
${hash}`;
|
|
28
|
-
};
|
|
29
|
-
var bannerPrinted = false;
|
|
30
|
-
var printBanner = (client) => {
|
|
31
|
-
if (bannerPrinted || window.location.hostname === "localhost") {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
bannerPrinted = true;
|
|
35
|
-
console.log(`%c${BANNER(client)}`, "font-family: monospace;");
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// src/client/context.ts
|
|
39
|
-
import { createContext } from "react";
|
|
40
|
-
var ClientContext = createContext(void 0);
|
|
41
|
-
|
|
42
|
-
// src/client/ClientProvider.tsx
|
|
43
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/client/ClientProvider.tsx";
|
|
44
|
-
var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config: configParam, client: clientParam, services: servicesParam, status: statusParam, fallback: Fallback = () => null, signalsRuntime = true, noBanner, onInitialized, ...options }, forwardedRef) => {
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
signalsRuntime && registerSignalsRuntime();
|
|
47
|
-
}, []);
|
|
48
|
-
const [error, setError] = useState();
|
|
49
|
-
if (error) {
|
|
50
|
-
throw error;
|
|
51
|
-
}
|
|
52
|
-
const [client, setClient] = useState(clientParam instanceof Client ? clientParam : void 0);
|
|
53
|
-
useImperativeHandle(forwardedRef, () => client, [
|
|
54
|
-
client
|
|
55
|
-
]);
|
|
56
|
-
const [status, setStatus] = useControlledState(statusParam);
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (!client) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const subscription = client.status.subscribe((status2) => setStatus(status2));
|
|
62
|
-
return () => subscription.unsubscribe();
|
|
63
|
-
}, [
|
|
64
|
-
client
|
|
65
|
-
]);
|
|
66
|
-
useAsyncEffect(async () => {
|
|
67
|
-
let disposed = false;
|
|
68
|
-
const initialize = async (client3) => {
|
|
69
|
-
if (!client3.initialized) {
|
|
70
|
-
await client3.initialize().catch((err) => {
|
|
71
|
-
if (!disposed) {
|
|
72
|
-
setError(err);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
log("client ready", void 0, {
|
|
76
|
-
F: __dxlog_file,
|
|
77
|
-
L: 138,
|
|
78
|
-
S: void 0,
|
|
79
|
-
C: (f, a) => f(...a)
|
|
80
|
-
});
|
|
81
|
-
await onInitialized?.(client3);
|
|
82
|
-
log("initialization complete", void 0, {
|
|
83
|
-
F: __dxlog_file,
|
|
84
|
-
L: 140,
|
|
85
|
-
S: void 0,
|
|
86
|
-
C: (f, a) => f(...a)
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
setClient(client3);
|
|
90
|
-
if (!noBanner) {
|
|
91
|
-
printBanner(client3);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
let client2;
|
|
95
|
-
try {
|
|
96
|
-
if (clientParam) {
|
|
97
|
-
client2 = await getAsyncProviderValue(clientParam);
|
|
98
|
-
await initialize(client2);
|
|
99
|
-
} else {
|
|
100
|
-
const config = await getAsyncProviderValue(configParam);
|
|
101
|
-
log("resolved config", {
|
|
102
|
-
config
|
|
103
|
-
}, {
|
|
104
|
-
F: __dxlog_file,
|
|
105
|
-
L: 158,
|
|
106
|
-
S: void 0,
|
|
107
|
-
C: (f, a) => f(...a)
|
|
108
|
-
});
|
|
109
|
-
const services = await getAsyncProviderValue(servicesParam, config);
|
|
110
|
-
log("created services", {
|
|
111
|
-
services
|
|
112
|
-
}, {
|
|
113
|
-
F: __dxlog_file,
|
|
114
|
-
L: 160,
|
|
115
|
-
S: void 0,
|
|
116
|
-
C: (f, a) => f(...a)
|
|
117
|
-
});
|
|
118
|
-
client2 = new Client({
|
|
119
|
-
config,
|
|
120
|
-
services,
|
|
121
|
-
...options
|
|
122
|
-
});
|
|
123
|
-
log("created client", void 0, {
|
|
124
|
-
F: __dxlog_file,
|
|
125
|
-
L: 162,
|
|
126
|
-
S: void 0,
|
|
127
|
-
C: (f, a) => f(...a)
|
|
128
|
-
});
|
|
129
|
-
await initialize(client2);
|
|
130
|
-
}
|
|
131
|
-
} catch (err) {
|
|
132
|
-
if (!disposed) {
|
|
133
|
-
log.catch(err, void 0, {
|
|
134
|
-
F: __dxlog_file,
|
|
135
|
-
L: 167,
|
|
136
|
-
S: void 0,
|
|
137
|
-
C: (f, a) => f(...a)
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return () => {
|
|
142
|
-
log("clean up", void 0, {
|
|
143
|
-
F: __dxlog_file,
|
|
144
|
-
L: 172,
|
|
145
|
-
S: void 0,
|
|
146
|
-
C: (f, a) => f(...a)
|
|
147
|
-
});
|
|
148
|
-
disposed = true;
|
|
149
|
-
if (!clientParam) {
|
|
150
|
-
void client2?.destroy().then(() => {
|
|
151
|
-
log("destroyed", void 0, {
|
|
152
|
-
F: __dxlog_file,
|
|
153
|
-
L: 179,
|
|
154
|
-
S: void 0,
|
|
155
|
-
C: (f, a) => f(...a)
|
|
156
|
-
});
|
|
157
|
-
}).catch((err) => log.catch(err, void 0, {
|
|
158
|
-
F: __dxlog_file,
|
|
159
|
-
L: 181,
|
|
160
|
-
S: void 0,
|
|
161
|
-
C: (f, a) => f(...a)
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}, [
|
|
166
|
-
configParam,
|
|
167
|
-
clientParam,
|
|
168
|
-
servicesParam,
|
|
169
|
-
noBanner
|
|
170
|
-
]);
|
|
171
|
-
if (!client?.initialized || status !== SystemStatus.ACTIVE) {
|
|
172
|
-
return /* @__PURE__ */ React.createElement(Fallback, {
|
|
173
|
-
client,
|
|
174
|
-
status
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
return /* @__PURE__ */ React.createElement(ClientContext.Provider, {
|
|
178
|
-
value: {
|
|
179
|
-
client,
|
|
180
|
-
status
|
|
181
|
-
}
|
|
182
|
-
}, children);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// src/client/useClient.ts
|
|
186
|
-
import { useContext } from "react";
|
|
187
|
-
import { raise } from "@dxos/debug";
|
|
188
|
-
var useClient = () => {
|
|
189
|
-
const { client } = useContext(ClientContext) ?? raise(new Error("Missing ClientContext."));
|
|
190
|
-
return client;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// src/client/useClientStatus.ts
|
|
194
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
195
|
-
var useClientStatus = (client) => {
|
|
196
|
-
const [status, setStatus] = useState2();
|
|
197
|
-
useEffect2(() => {
|
|
198
|
-
if (!client) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const subscription = client.status.subscribe((status2) => setStatus(status2));
|
|
202
|
-
return () => subscription.unsubscribe();
|
|
203
|
-
}, [
|
|
204
|
-
client,
|
|
205
|
-
setStatus
|
|
206
|
-
]);
|
|
207
|
-
return status;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
// src/client/useConfig.ts
|
|
211
|
-
import { useContext as useContext2 } from "react";
|
|
212
|
-
import { raise as raise2 } from "@dxos/debug";
|
|
213
|
-
var useConfig = () => {
|
|
214
|
-
const { client } = useContext2(ClientContext) ?? raise2(new Error("Missing ClientContext."));
|
|
215
|
-
return client.config;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
// src/client/useShell.ts
|
|
219
|
-
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
220
|
-
var useShell = () => {
|
|
221
|
-
const client = useClient();
|
|
222
|
-
return client.shell;
|
|
223
|
-
};
|
|
224
|
-
var useShellDisplay = () => {
|
|
225
|
-
const client = useClient();
|
|
226
|
-
const [display, setDisplay] = useState3(client.shell.display);
|
|
227
|
-
useEffect3(() => client.shell.onDisplayChange(setDisplay), [
|
|
228
|
-
client
|
|
229
|
-
]);
|
|
230
|
-
return display;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
// src/client/useStatus.ts
|
|
234
|
-
import { useContext as useContext3 } from "react";
|
|
235
|
-
import { raise as raise3 } from "@dxos/debug";
|
|
236
|
-
var useStatus = () => {
|
|
237
|
-
const { status } = useContext3(ClientContext) ?? raise3(new Error("Missing ClientContext."));
|
|
238
|
-
return status;
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// src/client/AgentHostingProvider.tsx
|
|
242
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/react-client/src/client/AgentHostingProvider.tsx";
|
|
243
|
-
var AgentHostingContext = /* @__PURE__ */ createContext2(null);
|
|
244
|
-
var AgentHostingProvider = (props) => {
|
|
245
|
-
const client = useClient();
|
|
246
|
-
const [agentHostingProviderClient] = useState4(makeClient(client));
|
|
247
|
-
return /* @__PURE__ */ React2.createElement(AgentHostingContext.Provider, {
|
|
248
|
-
value: agentHostingProviderClient
|
|
249
|
-
}, " ", props.children);
|
|
250
|
-
};
|
|
251
|
-
var useAgentHostingClient = () => {
|
|
252
|
-
return useContext4(AgentHostingContext);
|
|
253
|
-
};
|
|
254
|
-
var makeClient = ({ config, halo }) => {
|
|
255
|
-
const agentHostingConfig = config.get("runtime.services.agentHosting");
|
|
256
|
-
if (!agentHostingConfig) {
|
|
257
|
-
log2("no agent hosting configured", void 0, {
|
|
258
|
-
F: __dxlog_file2,
|
|
259
|
-
L: 39,
|
|
260
|
-
S: void 0,
|
|
261
|
-
C: (f, a) => f(...a)
|
|
262
|
-
});
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
let agentHostingProviderClient = null;
|
|
266
|
-
switch (agentHostingConfig.type) {
|
|
267
|
-
case "LOCAL_TESTING": {
|
|
268
|
-
log2("using FakeAgentHostingProvider", void 0, {
|
|
269
|
-
F: __dxlog_file2,
|
|
270
|
-
L: 47,
|
|
271
|
-
S: void 0,
|
|
272
|
-
C: (f, a) => f(...a)
|
|
273
|
-
});
|
|
274
|
-
return new FakeAgentHostingProvider();
|
|
275
|
-
}
|
|
276
|
-
case "AGENTHOSTING_API": {
|
|
277
|
-
agentHostingProviderClient = new AgentManagerClient(config, halo);
|
|
278
|
-
if (agentHostingProviderClient.init()) {
|
|
279
|
-
return agentHostingProviderClient;
|
|
280
|
-
} else {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
default: {
|
|
285
|
-
log2.error("Unknown agent hosting provider type: " + agentHostingConfig.type, void 0, {
|
|
286
|
-
F: __dxlog_file2,
|
|
287
|
-
L: 62,
|
|
288
|
-
S: void 0,
|
|
289
|
-
C: (f, a) => f(...a)
|
|
290
|
-
});
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
export {
|
|
297
|
-
AgentHostingContext,
|
|
298
|
-
AgentHostingProvider,
|
|
299
|
-
useAgentHostingClient,
|
|
300
|
-
ClientContext,
|
|
301
|
-
ClientProvider,
|
|
302
|
-
useClient,
|
|
303
|
-
useClientStatus,
|
|
304
|
-
useConfig,
|
|
305
|
-
useShell,
|
|
306
|
-
useShellDisplay,
|
|
307
|
-
useStatus
|
|
308
|
-
};
|
|
309
|
-
//# sourceMappingURL=chunk-TA2HGRAF.mjs.map
|