@dxos/react-client 0.4.10-next.811314d → 0.5.1-main.140276b

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 (31) hide show
  1. package/dist/lib/browser/{chunk-HJDLXXEZ.mjs → chunk-I2B4Q4HS.mjs} +55 -13
  2. package/dist/lib/browser/{chunk-HJDLXXEZ.mjs.map → chunk-I2B4Q4HS.mjs.map} +4 -4
  3. package/dist/lib/browser/devtools/index.mjs +1 -1
  4. package/dist/lib/browser/echo/index.mjs +1 -1
  5. package/dist/lib/browser/halo/index.mjs +1 -1
  6. package/dist/lib/browser/index.mjs +7 -3
  7. package/dist/lib/browser/index.mjs.map +1 -1
  8. package/dist/lib/browser/mesh/index.mjs +1 -1
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/testing/index.mjs +1 -1
  11. package/dist/lib/node/{chunk-3GRHATJ3.cjs → chunk-Y722WLDP.cjs} +59 -15
  12. package/dist/lib/node/{chunk-3GRHATJ3.cjs.map → chunk-Y722WLDP.cjs.map} +4 -4
  13. package/dist/lib/node/devtools/index.cjs +2 -2
  14. package/dist/lib/node/echo/index.cjs +3 -3
  15. package/dist/lib/node/halo/index.cjs +5 -5
  16. package/dist/lib/node/index.cjs +14 -10
  17. package/dist/lib/node/index.cjs.map +1 -1
  18. package/dist/lib/node/mesh/index.cjs +2 -2
  19. package/dist/lib/node/meta.json +1 -1
  20. package/dist/lib/node/testing/index.cjs +2 -2
  21. package/dist/types/src/client/AgentHostingProvider.d.ts +12 -0
  22. package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -0
  23. package/dist/types/src/client/index.d.ts +1 -1
  24. package/dist/types/src/client/index.d.ts.map +1 -1
  25. package/package.json +17 -17
  26. package/project.json +3 -0
  27. package/src/client/AgentHostingProvider.tsx +66 -0
  28. package/src/client/index.ts +1 -1
  29. package/dist/types/src/client/useAgentHostingProvider.d.ts +0 -4
  30. package/dist/types/src/client/useAgentHostingProvider.d.ts.map +0 -1
  31. package/src/client/useAgentHostingProvider.ts +0 -37
@@ -0,0 +1,66 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { createContext, type PropsWithChildren, useContext, useState } from 'react';
6
+
7
+ import { type Halo } from '@dxos/client/halo';
8
+ import { type AgentHostingProviderClient, AgentManagerClient, FakeAgentHostingProvider } from '@dxos/client/services';
9
+ import { type Config } from '@dxos/config';
10
+ import { log } from '@dxos/log';
11
+
12
+ import { useClient } from './ClientContext';
13
+
14
+ /*
15
+ * Interface for invoking the agent hosting provider client.
16
+ * @experimental
17
+ */
18
+
19
+ export type AgentHostingProviderProps = { config: Config; halo: Halo };
20
+
21
+ export const AgentHostingContext = createContext<AgentHostingProviderClient | null>(null);
22
+
23
+ export const AgentHostingProvider = (props: PropsWithChildren<{}>) => {
24
+ const client = useClient();
25
+ const [agentHostingProviderClient] = useState(makeClient(client));
26
+ return (
27
+ <AgentHostingContext.Provider value={agentHostingProviderClient}> {props.children}</AgentHostingContext.Provider>
28
+ );
29
+ };
30
+
31
+ export const useAgentHostingClient = () => {
32
+ return useContext(AgentHostingContext);
33
+ };
34
+
35
+ const makeClient = ({ config, halo }: AgentHostingProviderProps) => {
36
+ const agentHostingConfig = config.get('runtime.services.agentHosting');
37
+ if (!agentHostingConfig) {
38
+ log.info('no agent hosting configured');
39
+ return null;
40
+ }
41
+ // TODO: Dynamically discover based on runtime config
42
+ let agentHostingProviderClient: AgentHostingProviderClient | null = null;
43
+
44
+ switch (agentHostingConfig.type) {
45
+ case 'LOCAL_TESTING':
46
+ log.info('using FakeAgentHostingProvider');
47
+ return new FakeAgentHostingProvider(config, halo);
48
+
49
+ case 'AGENTHOSTING_API':
50
+ // TODO(nf): remove once hub agent authz is in place
51
+ if (localStorage.getItem('dxos.org/shell/features/agentHosting') !== 'true') {
52
+ log.info('dxos.org/shell/features/agentHosting not enabled');
53
+ return null;
54
+ }
55
+ agentHostingProviderClient = new AgentManagerClient(config, halo);
56
+ if (agentHostingProviderClient.init()) {
57
+ return agentHostingProviderClient;
58
+ } else {
59
+ // Not authorized or error initializing
60
+ return null;
61
+ }
62
+ default:
63
+ log.error('Unknown agent hosting provider type: ' + agentHostingConfig.type);
64
+ return null;
65
+ }
66
+ };
@@ -7,4 +7,4 @@ export * from './useClientServices';
7
7
  export * from './useConfig';
8
8
  export * from './useShell';
9
9
  export * from './useStatus';
10
- export * from './useAgentHostingProvider';
10
+ export * from './AgentHostingProvider';
@@ -1,4 +0,0 @@
1
- import { type AgentHostingProviderClient } from '@dxos/client/services';
2
- import { type Config } from '@dxos/config';
3
- export declare const useAgentHostingProviderClient: (config: Config) => AgentHostingProviderClient | null;
4
- //# sourceMappingURL=useAgentHostingProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAgentHostingProvider.d.ts","sourceRoot":"","sources":["../../../../src/client/useAgentHostingProvider.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,0BAA0B,EAGhC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAO3C,eAAO,MAAM,6BAA6B,WAAY,MAAM,KAAG,0BAA0B,GAAG,IAoB3F,CAAC"}
@@ -1,37 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import {
6
- type AgentHostingProviderClient,
7
- DXOSAgentHostingProviderClient,
8
- FakeAgentHostingProvider,
9
- } from '@dxos/client/services';
10
- import { type Config } from '@dxos/config';
11
- import { log } from '@dxos/log';
12
-
13
- /*
14
- * Interface for invoking the agent hosting provider client.
15
- * @experimental
16
- */
17
- export const useAgentHostingProviderClient = (config: Config): AgentHostingProviderClient | null => {
18
- // TODO: Dynamically discover based on runtime config
19
- if (
20
- config.get('runtime.app.env.DX_ENVIRONMENT') !== 'development' &&
21
- localStorage.getItem('dxos.org/shell/features/agentHosting') !== 'true'
22
- ) {
23
- return null;
24
- }
25
-
26
- const agentHostingConfig = config.get('runtime.services.agentHosting');
27
- if (!agentHostingConfig) {
28
- log.info('no agent hosting configured');
29
- return null;
30
- }
31
-
32
- if (agentHostingConfig.type === 'LOCAL_TESTING') {
33
- return new FakeAgentHostingProvider(config);
34
- }
35
-
36
- return new DXOSAgentHostingProviderClient(config);
37
- };