@dxos/functions 0.8.4-main.84f28bd → 0.8.4-main.b97322e

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 (73) hide show
  1. package/dist/lib/browser/{chunk-54U464M4.mjs → chunk-3NGCSUEW.mjs} +74 -106
  2. package/dist/lib/browser/chunk-3NGCSUEW.mjs.map +7 -0
  3. package/dist/lib/browser/edge/index.mjs.map +1 -1
  4. package/dist/lib/browser/index.mjs +23 -12
  5. package/dist/lib/browser/index.mjs.map +4 -4
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/testing/index.mjs +19 -7
  8. package/dist/lib/browser/testing/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/{chunk-XDSX35BS.mjs → chunk-FJ2MU7TL.mjs} +74 -106
  10. package/dist/lib/node-esm/chunk-FJ2MU7TL.mjs.map +7 -0
  11. package/dist/lib/node-esm/edge/index.mjs.map +1 -1
  12. package/dist/lib/node-esm/index.mjs +23 -12
  13. package/dist/lib/node-esm/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/testing/index.mjs +19 -7
  16. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  17. package/dist/types/src/edge/functions.d.ts +1 -1
  18. package/dist/types/src/edge/functions.d.ts.map +1 -1
  19. package/dist/types/src/errors.d.ts +68 -0
  20. package/dist/types/src/errors.d.ts.map +1 -0
  21. package/dist/types/src/handler.d.ts +7 -6
  22. package/dist/types/src/handler.d.ts.map +1 -1
  23. package/dist/types/src/index.d.ts +1 -0
  24. package/dist/types/src/index.d.ts.map +1 -1
  25. package/dist/types/src/schema.d.ts +1 -1
  26. package/dist/types/src/services/credentials.d.ts +2 -1
  27. package/dist/types/src/services/credentials.d.ts.map +1 -1
  28. package/dist/types/src/services/database.d.ts +17 -3
  29. package/dist/types/src/services/database.d.ts.map +1 -1
  30. package/dist/types/src/services/index.d.ts +0 -2
  31. package/dist/types/src/services/index.d.ts.map +1 -1
  32. package/dist/types/src/services/queues.d.ts +13 -1
  33. package/dist/types/src/services/queues.d.ts.map +1 -1
  34. package/dist/types/src/services/service-container.d.ts +26 -16
  35. package/dist/types/src/services/service-container.d.ts.map +1 -1
  36. package/dist/types/src/services/service-registry.d.ts +29 -0
  37. package/dist/types/src/services/service-registry.d.ts.map +1 -0
  38. package/dist/types/src/services/service-registry.test.d.ts +2 -0
  39. package/dist/types/src/services/service-registry.test.d.ts.map +1 -0
  40. package/dist/types/src/services/tracing.d.ts +11 -1
  41. package/dist/types/src/services/tracing.d.ts.map +1 -1
  42. package/dist/types/src/testing/index.d.ts +1 -0
  43. package/dist/types/src/testing/index.d.ts.map +1 -1
  44. package/dist/types/src/testing/layer.d.ts +10 -0
  45. package/dist/types/src/testing/layer.d.ts.map +1 -0
  46. package/dist/types/src/testing/services.d.ts +3 -4
  47. package/dist/types/src/testing/services.d.ts.map +1 -1
  48. package/dist/types/src/types.d.ts +8 -8
  49. package/dist/types/tsconfig.tsbuildinfo +1 -1
  50. package/package.json +25 -23
  51. package/src/edge/functions.ts +1 -1
  52. package/src/errors.ts +13 -0
  53. package/src/handler.ts +23 -16
  54. package/src/index.ts +1 -0
  55. package/src/services/credentials.ts +8 -2
  56. package/src/services/database.ts +27 -7
  57. package/src/services/index.ts +0 -2
  58. package/src/services/queues.ts +15 -2
  59. package/src/services/service-container.ts +37 -51
  60. package/src/services/service-registry.test.ts +42 -0
  61. package/src/services/service-registry.ts +56 -0
  62. package/src/services/tracing.ts +16 -1
  63. package/src/testing/index.ts +1 -0
  64. package/src/testing/layer.ts +31 -0
  65. package/src/testing/services.ts +2 -8
  66. package/dist/lib/browser/chunk-54U464M4.mjs.map +0 -7
  67. package/dist/lib/node-esm/chunk-XDSX35BS.mjs.map +0 -7
  68. package/dist/types/src/services/ai.d.ts +0 -12
  69. package/dist/types/src/services/ai.d.ts.map +0 -1
  70. package/dist/types/src/services/tool-resolver.d.ts +0 -14
  71. package/dist/types/src/services/tool-resolver.d.ts.map +0 -1
  72. package/src/services/ai.ts +0 -32
  73. package/src/services/tool-resolver.ts +0 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/functions",
3
- "version": "0.8.4-main.84f28bd",
3
+ "version": "0.8.4-main.b97322e",
4
4
  "description": "Functions API and runtime.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -47,41 +47,43 @@
47
47
  "src"
48
48
  ],
49
49
  "dependencies": {
50
- "@effect/platform": "0.88.0",
50
+ "@effect/platform": "0.89.0",
51
51
  "@preact/signals-core": "^1.9.0",
52
52
  "cron": "^3.1.6",
53
53
  "cron-schedule": "^5.0.4",
54
- "effect": "3.16.13",
54
+ "effect": "3.17.0",
55
55
  "esbuild-wasm": "^0.16.14",
56
56
  "express": "^4.19.2",
57
57
  "get-port-please": "^3.1.1",
58
58
  "i18next": "^24.2.1",
59
59
  "iso-did": "^1.6.0",
60
60
  "ws": "^8.14.2",
61
- "@dxos/ai": "0.8.4-main.84f28bd",
62
- "@dxos/client": "0.8.4-main.84f28bd",
63
- "@dxos/async": "0.8.4-main.84f28bd",
64
- "@dxos/context": "0.8.4-main.84f28bd",
65
- "@dxos/crypto": "0.8.4-main.84f28bd",
66
- "@dxos/echo": "0.8.4-main.84f28bd",
67
- "@dxos/echo-db": "0.8.4-main.84f28bd",
68
- "@dxos/echo-protocol": "0.8.4-main.84f28bd",
69
- "@dxos/echo-schema": "0.8.4-main.84f28bd",
70
- "@dxos/edge-client": "0.8.4-main.84f28bd",
71
- "@dxos/effect": "0.8.4-main.84f28bd",
72
- "@dxos/invariant": "0.8.4-main.84f28bd",
73
- "@dxos/keys": "0.8.4-main.84f28bd",
74
- "@dxos/live-object": "0.8.4-main.84f28bd",
75
- "@dxos/log": "0.8.4-main.84f28bd",
76
- "@dxos/node-std": "0.8.4-main.84f28bd",
77
- "@dxos/protocols": "0.8.4-main.84f28bd",
78
- "@dxos/schema": "0.8.4-main.84f28bd",
79
- "@dxos/util": "0.8.4-main.84f28bd"
61
+ "@dxos/ai": "0.8.4-main.b97322e",
62
+ "@dxos/async": "0.8.4-main.b97322e",
63
+ "@dxos/client": "0.8.4-main.b97322e",
64
+ "@dxos/crypto": "0.8.4-main.b97322e",
65
+ "@dxos/context": "0.8.4-main.b97322e",
66
+ "@dxos/echo-db": "0.8.4-main.b97322e",
67
+ "@dxos/echo": "0.8.4-main.b97322e",
68
+ "@dxos/echo-pipeline": "0.8.4-main.b97322e",
69
+ "@dxos/echo-protocol": "0.8.4-main.b97322e",
70
+ "@dxos/echo-schema": "0.8.4-main.b97322e",
71
+ "@dxos/effect": "0.8.4-main.b97322e",
72
+ "@dxos/edge-client": "0.8.4-main.b97322e",
73
+ "@dxos/errors": "0.8.4-main.b97322e",
74
+ "@dxos/invariant": "0.8.4-main.b97322e",
75
+ "@dxos/keys": "0.8.4-main.b97322e",
76
+ "@dxos/live-object": "0.8.4-main.b97322e",
77
+ "@dxos/log": "0.8.4-main.b97322e",
78
+ "@dxos/node-std": "0.8.4-main.b97322e",
79
+ "@dxos/protocols": "0.8.4-main.b97322e",
80
+ "@dxos/schema": "0.8.4-main.b97322e",
81
+ "@dxos/util": "0.8.4-main.b97322e"
80
82
  },
81
83
  "devDependencies": {
82
84
  "@types/express": "^4.17.17",
83
85
  "@types/ws": "^7.4.0",
84
- "@dxos/agent": "0.8.4-main.84f28bd"
86
+ "@dxos/agent": "0.8.4-main.b97322e"
85
87
  },
86
88
  "publishConfig": {
87
89
  "access": "public"
@@ -8,7 +8,7 @@ import { type Client } from '@dxos/client';
8
8
  import { createEdgeIdentity } from '@dxos/client/edge';
9
9
  import { EdgeHttpClient } from '@dxos/edge-client';
10
10
  import { invariant } from '@dxos/invariant';
11
- import type { PublicKey } from '@dxos/keys';
11
+ import { type PublicKey } from '@dxos/keys';
12
12
  import { log } from '@dxos/log';
13
13
  import { type UploadFunctionResponseBody } from '@dxos/protocols';
14
14
 
package/src/errors.ts ADDED
@@ -0,0 +1,13 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { BaseError } from '@dxos/errors';
6
+
7
+ export class ServiceNotAvailableError extends BaseError.extend('SERVICE_NOT_AVAILABLE') {
8
+ constructor(serviceName: string) {
9
+ super(`Service not available: ${serviceName}`);
10
+ }
11
+ }
12
+
13
+ export class FunctionError extends BaseError.extend('FUNCTION_ERROR') {}
package/src/handler.ts CHANGED
@@ -40,19 +40,19 @@ export type FunctionHandler<TData = {}, TOutput = any> = (params: {
40
40
  */
41
41
  export interface FunctionContext {
42
42
  /**
43
- * Resolves a service available to the function.
44
- * @throws if the service is not available.
43
+ * Space from which the function was invoked.
45
44
  */
46
- getService: <T extends Context.Tag<any, any>>(tag: T) => Context.Tag.Service<T>;
45
+ space: SpaceAPI | undefined;
47
46
 
48
- getSpace: (spaceId: SpaceId) => Promise<SpaceAPI>;
47
+ ai: AiServiceClient;
49
48
 
50
49
  /**
51
- * Space from which the function was invoked.
50
+ * Resolves a service available to the function.
51
+ * @throws if the service is not available.
52
52
  */
53
- space: SpaceAPI | undefined;
53
+ getService: <T extends Context.Tag<any, any>>(tag: T) => Context.Tag.Service<T>;
54
54
 
55
- ai: AiServiceClient;
55
+ getSpace: (spaceId: SpaceId) => Promise<SpaceAPI>;
56
56
  }
57
57
 
58
58
  export interface FunctionContextAi {
@@ -76,10 +76,9 @@ export interface QueuesAPI {
76
76
  */
77
77
  export interface SpaceAPI {
78
78
  get id(): SpaceId;
79
-
80
79
  get db(): EchoDatabase;
81
80
 
82
- // TODO(dmaretskyi): Align with echo api --- queues.get(id).append(items);
81
+ // TODO(dmaretskyi): Align with echo api: queues.get(id).append(items);
83
82
  get queues(): QueuesAPI;
84
83
  }
85
84
 
@@ -89,6 +88,7 @@ const __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {
89
88
  };
90
89
 
91
90
  export type FunctionDefinition<T = {}, O = any> = {
91
+ name: string;
92
92
  description?: string;
93
93
  inputSchema: Schema.Schema<T, any>;
94
94
  outputSchema?: Schema.Schema<O, any>;
@@ -96,18 +96,25 @@ export type FunctionDefinition<T = {}, O = any> = {
96
96
  };
97
97
 
98
98
  // TODO(dmaretskyi): Bind input type to function handler.
99
- export const defineFunction = <T, O>(params: FunctionDefinition<T, O>): FunctionDefinition<T, O> => {
100
- if (!Schema.isSchema(params.inputSchema)) {
99
+ export const defineFunction = <T, O>({
100
+ name,
101
+ description,
102
+ inputSchema,
103
+ outputSchema = Schema.Any,
104
+ handler,
105
+ }: FunctionDefinition<T, O>): FunctionDefinition<T, O> => {
106
+ if (!Schema.isSchema(inputSchema)) {
101
107
  throw new Error('Input schema must be a valid schema');
102
108
  }
103
- if (typeof params.handler !== 'function') {
109
+ if (typeof handler !== 'function') {
104
110
  throw new Error('Handler must be a function');
105
111
  }
106
112
 
107
113
  return {
108
- description: params.description,
109
- inputSchema: params.inputSchema,
110
- outputSchema: params.outputSchema ?? Schema.Any,
111
- handler: params.handler,
114
+ name,
115
+ description,
116
+ inputSchema,
117
+ outputSchema,
118
+ handler,
112
119
  };
113
120
  };
package/src/index.ts CHANGED
@@ -9,5 +9,6 @@ export * from './types';
9
9
  export * from './url';
10
10
  export * from './services';
11
11
  export * from './executor';
12
+ export * from './errors';
12
13
 
13
14
  // Blow up cache
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Context } from 'effect';
5
+ import { Context, Effect } from 'effect';
6
6
 
7
7
  type CredentialQuery = {
8
8
  service?: string;
@@ -31,7 +31,13 @@ export class CredentialsService extends Context.Tag('CredentialsService')<
31
31
  */
32
32
  getCredential: (query: CredentialQuery) => Promise<ServiceCredential>;
33
33
  }
34
- >() {}
34
+ >() {
35
+ static getCredential = (query: CredentialQuery): Effect.Effect<ServiceCredential, never, CredentialsService> =>
36
+ Effect.gen(function* () {
37
+ const credentials = yield* CredentialsService;
38
+ return yield* Effect.promise(() => credentials.getCredential(query));
39
+ });
40
+ }
35
41
 
36
42
  export class ConfiguredCredentialsService implements Context.Tag.Service<CredentialsService> {
37
43
  constructor(private readonly credentials: ServiceCredential[] = []) {}
@@ -4,8 +4,8 @@
4
4
 
5
5
  import { Context, Effect, Layer } from 'effect';
6
6
 
7
- import type { Obj, Ref, Relation } from '@dxos/echo';
8
- import type { EchoDatabase } from '@dxos/echo-db';
7
+ import type { Filter, Live, Obj, Query, Ref, Relation } from '@dxos/echo';
8
+ import type { EchoDatabase, OneShotQueryResult, QueryResult } from '@dxos/echo-db';
9
9
  import type { DXN } from '@dxos/keys';
10
10
 
11
11
  export class DatabaseService extends Context.Tag('DatabaseService')<
@@ -41,10 +41,30 @@ export class DatabaseService extends Context.Tag('DatabaseService')<
41
41
  },
42
42
  );
43
43
 
44
- static loadRef: <T>(ref: Ref.Ref<T>) => Effect.Effect<T, Error, never> = Effect.fn(function* (ref) {
45
- return yield* Effect.tryPromise({
46
- try: () => ref.load(),
47
- catch: (error) => error as Error,
48
- });
44
+ static loadRef: <T>(ref: Ref.Ref<T>) => Effect.Effect<T, never, never> = Effect.fn(function* (ref) {
45
+ return yield* Effect.promise(() => ref.load());
49
46
  });
47
+
48
+ /**
49
+ * Creates a `QueryResult` object that can be subscribed to.
50
+ */
51
+ static query: {
52
+ <Q extends Query.Any>(query: Q): Effect.Effect<QueryResult<Live<Query.Type<Q>>>, never, DatabaseService>;
53
+ <F extends Filter.Any>(filter: F): Effect.Effect<QueryResult<Live<Filter.Type<F>>>, never, DatabaseService>;
54
+ } = (queryOrFilter: Query.Any | Filter.Any) =>
55
+ DatabaseService.pipe(
56
+ Effect.map(({ db }) => db.query(queryOrFilter as any)),
57
+ Effect.withSpan('DatabaseService.query'),
58
+ );
59
+
60
+ /**
61
+ * Executes the query once and returns the results.
62
+ */
63
+ static runQuery: {
64
+ <Q extends Query.Any>(query: Q): Effect.Effect<OneShotQueryResult<Live<Query.Type<Q>>>, never, DatabaseService>;
65
+ <F extends Filter.Any>(filter: F): Effect.Effect<OneShotQueryResult<Live<Filter.Type<F>>>, never, DatabaseService>;
66
+ } = (queryOrFilter: Query.Any | Filter.Any) =>
67
+ DatabaseService.query(queryOrFilter as any).pipe(
68
+ Effect.flatMap((queryResult) => Effect.promise(() => queryResult.run())),
69
+ );
50
70
  }
@@ -2,7 +2,6 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './ai';
6
5
  export * from './database';
7
6
  export * from './queues';
8
7
  export * from './service-container';
@@ -10,4 +9,3 @@ export * from './credentials';
10
9
  export * from './tracing';
11
10
  export * from './event-logger';
12
11
  export * from './function-call-service';
13
- export * from './tool-resolver';
@@ -6,6 +6,9 @@ import { Context, Layer } from 'effect';
6
6
 
7
7
  import type { Queue, QueueAPI, QueueFactory } from '@dxos/echo-db';
8
8
 
9
+ /**
10
+ * Gives access to all queues.
11
+ */
9
12
  export class QueueService extends Context.Tag('QueueService')<
10
13
  QueueService,
11
14
  {
@@ -16,8 +19,8 @@ export class QueueService extends Context.Tag('QueueService')<
16
19
 
17
20
  /**
18
21
  * The queue that is used to store the context of the current research.
22
+ * @deprecated Use `ContextQueueService` instead.
19
23
  */
20
- // TODO(dmaretskyi): Is this really part of the queue service?
21
24
  readonly contextQueue: Queue | undefined;
22
25
  }
23
26
  >() {
@@ -33,10 +36,20 @@ export class QueueService extends Context.Tag('QueueService')<
33
36
  contextQueue: undefined,
34
37
  });
35
38
 
36
- static make = (queues: QueueFactory, contextQueue: Queue | undefined): Context.Tag.Service<QueueService> => {
39
+ static make = (queues: QueueFactory, contextQueue?: Queue): Context.Tag.Service<QueueService> => {
37
40
  return {
38
41
  queues,
39
42
  contextQueue,
40
43
  };
41
44
  };
42
45
  }
46
+
47
+ /**
48
+ * Gives access to a specific queue passed as a context.
49
+ */
50
+ export class ContextQueueService extends Context.Tag('ContextQueueService')<
51
+ ContextQueueService,
52
+ {
53
+ readonly contextQueue: Queue;
54
+ }
55
+ >() {}
@@ -2,68 +2,65 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Layer, type Context } from 'effect';
5
+ import { type Context, Layer } from 'effect';
6
+
7
+ import { AiService } from '@dxos/ai';
8
+ import { entries } from '@dxos/util';
6
9
 
7
- import { AiService } from './ai';
8
10
  import { ConfiguredCredentialsService, CredentialsService } from './credentials';
9
11
  import { DatabaseService } from './database';
10
12
  import { EventLogger } from './event-logger';
11
13
  import { FunctionCallService } from './function-call-service';
12
14
  import { QueueService } from './queues';
13
- import { ToolResolverService } from './tool-resolver';
14
15
  import { TracingService } from './tracing';
15
16
 
17
+ // TODO(dmaretskyi): Refactor this module to only rely on tags and not the human-assigned names.
18
+
16
19
  /**
17
- * List of all service tags and their names.
20
+ * List of all services.
18
21
  */
19
- export interface ServiceTagRecord {
20
- ai: AiService;
21
- credentials: CredentialsService;
22
- database: DatabaseService;
23
- eventLogger: EventLogger;
24
- functionCallService: FunctionCallService;
25
- tracing: TracingService;
26
- queues: QueueService;
27
- toolResolver: ToolResolverService;
28
- }
22
+ const SERVICES = {
23
+ ai: AiService,
24
+ credentials: CredentialsService,
25
+ database: DatabaseService,
26
+ eventLogger: EventLogger,
27
+ functionCallService: FunctionCallService,
28
+ queues: QueueService,
29
+ tracing: TracingService,
30
+ } as const satisfies Record<string, Context.TagClass<any, string, any>>;
31
+
32
+ /**
33
+ * Mapping of service names to their tags.
34
+ */
35
+ export type ServiceTagRecord = {
36
+ [K in keyof typeof SERVICES]: (typeof SERVICES)[K] extends { new (_: never): infer T } ? T : never;
37
+ };
29
38
 
30
39
  /**
31
- * List of all services and their runtime types.
40
+ * Mapping of service names to their runtime types.
32
41
  */
33
42
  export type ServiceRecord = {
34
43
  [K in keyof ServiceTagRecord]: Context.Tag.Service<ServiceTagRecord[K]>;
35
44
  };
36
45
 
37
46
  /**
38
- * Union of all services.
47
+ * Union of all services tags.
39
48
  */
40
49
  export type Services = ServiceTagRecord[keyof ServiceTagRecord];
41
50
 
42
- const SERVICE_MAPPING: Record<string, keyof ServiceRecord> = {
43
- [AiService.key]: 'ai',
44
- [CredentialsService.key]: 'credentials',
45
- [DatabaseService.key]: 'database',
46
- [EventLogger.key]: 'eventLogger',
47
- [FunctionCallService.key]: 'functionCallService',
48
- [QueueService.key]: 'queues',
49
- [TracingService.key]: 'tracing',
50
- [ToolResolverService.key]: 'toolResolver',
51
- };
51
+ const SERVICE_MAPPING: Record<string, keyof ServiceRecord> = Object.fromEntries(
52
+ entries(SERVICES).map(([name, tag]) => [tag.key, name]),
53
+ );
52
54
 
53
- export const SERVICE_TAGS: Context.Tag<any, any>[] = [
54
- AiService,
55
- CredentialsService,
56
- DatabaseService,
57
- EventLogger,
58
- FunctionCallService,
59
- TracingService,
60
- QueueService,
61
- ];
55
+ export const SERVICE_TAGS: Context.Tag<any, any>[] = Object.values(SERVICES);
62
56
 
63
57
  const DEFAULT_SERVICES: Partial<ServiceRecord> = {
64
58
  tracing: TracingService.noop,
65
59
  };
66
60
 
61
+ /**
62
+ * @deprecated
63
+ */
67
64
  export class ServiceContainer {
68
65
  private _services: Partial<ServiceRecord> = { ...DEFAULT_SERVICES };
69
66
 
@@ -94,7 +91,10 @@ export class ServiceContainer {
94
91
  // TODO(dmaretskyi): `getService` is designed to error at runtime if the service is not available, but layer forces us to provide all services and makes stubs for the ones that are not available.
95
92
  createLayer(): Layer.Layer<Services> {
96
93
  const ai = this._services.ai != null ? Layer.succeed(AiService, this._services.ai) : AiService.notAvailable;
97
- const credentials = Layer.succeed(CredentialsService, new ConfiguredCredentialsService());
94
+ const credentials = Layer.succeed(
95
+ CredentialsService,
96
+ this._services.credentials ?? new ConfiguredCredentialsService(),
97
+ );
98
98
  const database =
99
99
  this._services.database != null
100
100
  ? Layer.succeed(DatabaseService, this._services.database)
@@ -107,21 +107,7 @@ export class ServiceContainer {
107
107
  FunctionCallService,
108
108
  this._services.functionCallService ?? FunctionCallService.mock(),
109
109
  );
110
- const toolResolver = Layer.succeed(
111
- ToolResolverService,
112
- this._services.toolResolver ?? ToolResolverService.notAvailable,
113
- );
114
110
 
115
- return Layer.mergeAll(
116
- //
117
- ai,
118
- credentials,
119
- database,
120
- queues,
121
- tracing,
122
- eventLogger,
123
- functionCallService,
124
- toolResolver,
125
- );
111
+ return Layer.mergeAll(ai, credentials, database, queues, tracing, eventLogger, functionCallService);
126
112
  }
127
113
  }
@@ -0,0 +1,42 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { describe, it } from '@effect/vitest';
6
+ import { Context, Effect, Layer, Option } from 'effect';
7
+
8
+ import { ServiceRegistry } from './service-registry';
9
+
10
+ class MyTag extends Context.Tag('MyTag')<MyTag, { value: string }>() {}
11
+
12
+ const mockRegistry = Layer.succeed(ServiceRegistry, {
13
+ resolve: (tag) => ((tag as any) === MyTag ? Option.some({ value: 'test' } as any) : Option.none()),
14
+ });
15
+
16
+ describe('ServiceRegistry', () => {
17
+ it.effect(
18
+ 'provide',
19
+ Effect.fn(function* ({ expect }) {
20
+ const body = Effect.gen(function* () {
21
+ const { value } = yield* MyTag;
22
+ expect(value).toEqual('test');
23
+ });
24
+
25
+ const eff = body.pipe(ServiceRegistry.provide(MyTag));
26
+ yield* eff;
27
+ }, Effect.provide(mockRegistry)),
28
+ );
29
+
30
+ it.effect(
31
+ 'provide or die',
32
+ Effect.fn(function* ({ expect }) {
33
+ const body = Effect.gen(function* () {
34
+ const { value } = yield* MyTag;
35
+ expect(value).toEqual('test');
36
+ });
37
+
38
+ const eff = body.pipe(ServiceRegistry.provideOrDie(MyTag));
39
+ yield* eff;
40
+ }, Effect.provide(mockRegistry)),
41
+ );
42
+ });
@@ -0,0 +1,56 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Context, Effect, flow, type Option } from 'effect';
6
+
7
+ import { ServiceNotAvailableError } from '../errors';
8
+
9
+ export namespace ServiceRegistry {
10
+ export interface Service {
11
+ resolve: <T extends Context.Tag<any, any>>(tag: T) => Option.Option<Context.Tag.Service<T>>;
12
+ }
13
+ }
14
+
15
+ export class ServiceRegistry extends Context.Tag('ServiceRegistry')<ServiceRegistry, ServiceRegistry.Service>() {
16
+ /**
17
+ * Resolves the service from the registry.
18
+ * @param tag Service tag to resolve.
19
+ * @throws {@link ServiceNotAvailableError} if the service is not found.
20
+ * @returns Effect that resolve to the service.
21
+ */
22
+ static resolve: <T extends Context.Tag<any, any>>(
23
+ tag: T,
24
+ ) => Effect.Effect<T, ServiceNotAvailableError, ServiceRegistry> = (tag) =>
25
+ ServiceRegistry.pipe(
26
+ Effect.flatMap((_) => _.resolve(tag)),
27
+ Effect.mapError(() => new ServiceNotAvailableError(tag.key)),
28
+ );
29
+
30
+ static provide: {
31
+ <Tags extends [Context.Tag<any, any>, ...Context.Tag<any, any>[]]>(
32
+ ...tags: Tags
33
+ ): <A, E, R>(
34
+ effect: Effect.Effect<A, E, R>,
35
+ ) => Effect.Effect<
36
+ A,
37
+ E | ServiceNotAvailableError,
38
+ Exclude<R, { [K in keyof Tags]: Context.Tag.Identifier<Tags[K]> }[number]> | ServiceRegistry
39
+ >;
40
+ } = (...tags) => (flow as any)(...tags.map((tag) => Effect.provideServiceEffect(tag, ServiceRegistry.resolve(tag))));
41
+
42
+ static provideOrDie: {
43
+ <Tags extends [Context.Tag<any, any>, ...Context.Tag<any, any>[]]>(
44
+ ...tags: Tags
45
+ ): <A, E, R>(
46
+ effect: Effect.Effect<A, E, R>,
47
+ ) => Effect.Effect<
48
+ A,
49
+ E,
50
+ Exclude<R, { [K in keyof Tags]: Context.Tag.Identifier<Tags[K]> }[number]> | ServiceRegistry
51
+ >;
52
+ } = (...tags) =>
53
+ (flow as any)(
54
+ ...tags.map((tag) => Effect.provideServiceEffect(tag, ServiceRegistry.resolve(tag).pipe(Effect.orDie))),
55
+ );
56
+ }
@@ -2,10 +2,16 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Context } from 'effect';
5
+ import { Context, Effect } from 'effect';
6
6
 
7
+ import { AgentStatus } from '@dxos/ai';
8
+ import { Obj } from '@dxos/echo';
7
9
  import type { AnyEchoObject } from '@dxos/echo-schema';
8
10
 
11
+ /**
12
+ * Provides a way for compute primitives (functions, workflows, tools)
13
+ * to emit an execution trace as a series of structured ECHO objects.
14
+ */
9
15
  export class TracingService extends Context.Tag('TracingService')<
10
16
  TracingService,
11
17
  {
@@ -24,4 +30,13 @@ export class TracingService extends Context.Tag('TracingService')<
24
30
  console.log(event);
25
31
  },
26
32
  };
33
+
34
+ /**
35
+ * Emit the current human-readable execution status.
36
+ */
37
+ static emitStatus: (data: Obj.MakeProps<typeof AgentStatus>) => Effect.Effect<unknown, never, void> =
38
+ Effect.fnUntraced(function* (data) {
39
+ const tracing = yield* TracingService;
40
+ tracing.write(Obj.make(AgentStatus, data));
41
+ });
27
42
  }
@@ -3,3 +3,4 @@
3
3
  //
4
4
 
5
5
  export * from './services';
6
+ export * from './layer';
@@ -0,0 +1,31 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Context, Effect, Layer } from 'effect';
6
+ import type { Schema } from 'effect';
7
+
8
+ import { EchoTestBuilder } from '@dxos/echo-db/testing';
9
+ import type { EchoHostIndexingConfig } from '@dxos/echo-pipeline';
10
+ import { accuireReleaseResource } from '@dxos/effect';
11
+
12
+ import { DatabaseService, QueueService } from '../services';
13
+
14
+ const testBuilder = accuireReleaseResource(() => new EchoTestBuilder());
15
+
16
+ export type TestDatabaseOptions = {
17
+ indexing?: Partial<EchoHostIndexingConfig>;
18
+ types?: Schema.Schema.AnyNoContext[];
19
+ };
20
+
21
+ export const TestDatabaseLayer = ({ indexing, types }: TestDatabaseOptions = {}) =>
22
+ Layer.scopedContext(
23
+ Effect.gen(function* () {
24
+ const builder = yield* testBuilder;
25
+ const { db, queues } = yield* Effect.promise(() => builder.createDatabase({ indexing, types }));
26
+ return Context.mergeAll(
27
+ Context.make(DatabaseService, DatabaseService.make(db)),
28
+ Context.make(QueueService, QueueService.make(queues, undefined)),
29
+ );
30
+ }),
31
+ );
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { type Context } from 'effect';
6
6
 
7
- import { type AiServiceEdgeClientOptions, EdgeAiServiceClient, type AiServiceClient, ToolRegistry } from '@dxos/ai';
7
+ import { AiService, type AiServiceClient, type AiServiceEdgeClientOptions, EdgeAiServiceClient } from '@dxos/ai';
8
8
  import { AI_SERVICE_ENDPOINT, createTestAiServiceClient } from '@dxos/ai/testing';
9
9
  import type { Space } from '@dxos/client/echo';
10
10
  import type { EchoDatabase, QueueFactory } from '@dxos/echo-db';
@@ -12,7 +12,6 @@ import { assertArgument } from '@dxos/invariant';
12
12
 
13
13
  import { consoleLogger, noopLogger } from './logger';
14
14
  import {
15
- AiService,
16
15
  ConfiguredCredentialsService,
17
16
  type CredentialsService,
18
17
  DatabaseService,
@@ -20,7 +19,6 @@ import {
20
19
  QueueService,
21
20
  ServiceContainer,
22
21
  type ServiceCredential,
23
- ToolResolverService,
24
22
  type TracingService,
25
23
  } from '../services';
26
24
 
@@ -95,8 +93,6 @@ export type TestServiceOptions = {
95
93
  tracing?: {
96
94
  service?: Context.Tag.Service<TracingService>;
97
95
  };
98
-
99
- toolResolver?: Context.Tag.Service<ToolResolverService>;
100
96
  };
101
97
 
102
98
  export const createTestServices = ({
@@ -107,7 +103,6 @@ export const createTestServices = ({
107
103
  queues,
108
104
  space,
109
105
  tracing,
110
- toolResolver,
111
106
  }: TestServiceOptions = {}): ServiceContainer => {
112
107
  assertArgument(!(!!space && (!!db || !!queues)), 'space can be provided only if db and queues are not');
113
108
 
@@ -115,10 +110,9 @@ export const createTestServices = ({
115
110
  ai: createAiService(ai),
116
111
  credentials: createCredentialsService(credentials),
117
112
  database: space || db ? DatabaseService.make(space?.db || db!) : undefined,
118
- eventLogger: logging?.logger ?? logging?.enabled ? consoleLogger : noopLogger,
113
+ eventLogger: (logging?.logger ?? logging?.enabled) ? consoleLogger : noopLogger,
119
114
  queues: space || queues ? QueueService.make(space?.queues || queues!, undefined) : undefined,
120
115
  tracing: tracing?.service,
121
- toolResolver: toolResolver ?? ToolResolverService.make(new ToolRegistry([])),
122
116
  });
123
117
  };
124
118