@dxos/functions 0.8.4-main.5ea62a8 → 0.8.4-main.72ec0f3

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 (165) hide show
  1. package/dist/lib/browser/index.mjs +769 -407
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +769 -407
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/errors.d.ts +87 -28
  8. package/dist/types/src/errors.d.ts.map +1 -1
  9. package/dist/types/src/{examples → example}/fib.d.ts +1 -1
  10. package/dist/types/src/example/fib.d.ts.map +1 -0
  11. package/dist/types/src/example/forex-effect.d.ts +3 -0
  12. package/dist/types/src/example/forex-effect.d.ts.map +1 -0
  13. package/dist/types/src/example/index.d.ts +12 -0
  14. package/dist/types/src/example/index.d.ts.map +1 -0
  15. package/dist/types/src/{examples → example}/reply.d.ts +1 -1
  16. package/dist/types/src/example/reply.d.ts.map +1 -0
  17. package/dist/types/src/{examples → example}/sleep.d.ts +1 -1
  18. package/dist/types/src/example/sleep.d.ts.map +1 -0
  19. package/dist/types/src/index.d.ts +5 -7
  20. package/dist/types/src/index.d.ts.map +1 -1
  21. package/dist/types/src/protocol/index.d.ts +2 -0
  22. package/dist/types/src/protocol/index.d.ts.map +1 -0
  23. package/dist/types/src/protocol/protocol.d.ts +7 -0
  24. package/dist/types/src/protocol/protocol.d.ts.map +1 -0
  25. package/dist/types/src/protocol/protocol.test.d.ts +2 -0
  26. package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
  27. package/dist/types/src/sdk.d.ts +89 -0
  28. package/dist/types/src/sdk.d.ts.map +1 -0
  29. package/dist/types/src/services/credentials.d.ts +7 -3
  30. package/dist/types/src/services/credentials.d.ts.map +1 -1
  31. package/dist/types/src/services/event-logger.d.ts +20 -5
  32. package/dist/types/src/services/event-logger.d.ts.map +1 -1
  33. package/dist/types/src/services/function-invocation-service.d.ts +11 -0
  34. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
  35. package/dist/types/src/services/index.d.ts +6 -6
  36. package/dist/types/src/services/index.d.ts.map +1 -1
  37. package/dist/types/src/services/queues.d.ts +4 -1
  38. package/dist/types/src/services/queues.d.ts.map +1 -1
  39. package/dist/types/src/services/tracing.d.ts +10 -12
  40. package/dist/types/src/services/tracing.d.ts.map +1 -1
  41. package/dist/types/src/types/Function.d.ts +58 -0
  42. package/dist/types/src/types/Function.d.ts.map +1 -0
  43. package/dist/types/src/types/Script.d.ts +28 -0
  44. package/dist/types/src/types/Script.d.ts.map +1 -0
  45. package/dist/types/src/types/Trigger.d.ts +139 -0
  46. package/dist/types/src/types/Trigger.d.ts.map +1 -0
  47. package/dist/types/src/types/TriggerEvent.d.ts +44 -0
  48. package/dist/types/src/types/TriggerEvent.d.ts.map +1 -0
  49. package/dist/types/src/types/index.d.ts +6 -0
  50. package/dist/types/src/types/index.d.ts.map +1 -0
  51. package/dist/types/src/{url.d.ts → types/url.d.ts} +1 -10
  52. package/dist/types/src/types/url.d.ts.map +1 -0
  53. package/dist/types/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +17 -72
  55. package/src/errors.ts +13 -5
  56. package/src/{examples → example}/fib.ts +5 -3
  57. package/src/example/forex-effect.ts +40 -0
  58. package/src/example/index.ts +13 -0
  59. package/src/{examples → example}/reply.ts +6 -3
  60. package/src/{examples → example}/sleep.ts +5 -3
  61. package/src/index.ts +5 -9
  62. package/src/{executor → protocol}/index.ts +1 -1
  63. package/src/protocol/protocol.test.ts +59 -0
  64. package/src/protocol/protocol.ts +145 -0
  65. package/src/sdk.ts +226 -0
  66. package/src/services/credentials.ts +12 -6
  67. package/src/services/event-logger.ts +12 -3
  68. package/src/services/function-invocation-service.ts +23 -0
  69. package/src/services/index.ts +7 -6
  70. package/src/services/queues.ts +8 -1
  71. package/src/services/tracing.ts +26 -52
  72. package/src/{schema.ts → types/Function.ts} +20 -26
  73. package/src/types/Script.ts +33 -0
  74. package/src/types/Trigger.ts +139 -0
  75. package/src/types/TriggerEvent.ts +62 -0
  76. package/src/types/index.ts +9 -0
  77. package/src/types/url.ts +31 -0
  78. package/dist/lib/browser/bundler/index.mjs +0 -263
  79. package/dist/lib/browser/bundler/index.mjs.map +0 -7
  80. package/dist/lib/browser/chunk-7NQ77AIQ.mjs +0 -618
  81. package/dist/lib/browser/chunk-7NQ77AIQ.mjs.map +0 -7
  82. package/dist/lib/browser/edge/index.mjs +0 -81
  83. package/dist/lib/browser/edge/index.mjs.map +0 -7
  84. package/dist/lib/browser/testing/index.mjs +0 -122
  85. package/dist/lib/browser/testing/index.mjs.map +0 -7
  86. package/dist/lib/node-esm/bundler/index.mjs +0 -265
  87. package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
  88. package/dist/lib/node-esm/chunk-KCGC6QQT.mjs +0 -620
  89. package/dist/lib/node-esm/chunk-KCGC6QQT.mjs.map +0 -7
  90. package/dist/lib/node-esm/edge/index.mjs +0 -83
  91. package/dist/lib/node-esm/edge/index.mjs.map +0 -7
  92. package/dist/lib/node-esm/testing/index.mjs +0 -123
  93. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  94. package/dist/types/src/bundler/bundler.d.ts +0 -49
  95. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  96. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  97. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  98. package/dist/types/src/bundler/index.d.ts +0 -2
  99. package/dist/types/src/bundler/index.d.ts.map +0 -1
  100. package/dist/types/src/edge/functions.d.ts +0 -17
  101. package/dist/types/src/edge/functions.d.ts.map +0 -1
  102. package/dist/types/src/edge/index.d.ts +0 -2
  103. package/dist/types/src/edge/index.d.ts.map +0 -1
  104. package/dist/types/src/examples/fib.d.ts.map +0 -1
  105. package/dist/types/src/examples/reply.d.ts.map +0 -1
  106. package/dist/types/src/examples/sleep.d.ts.map +0 -1
  107. package/dist/types/src/executor/executor.d.ts +0 -11
  108. package/dist/types/src/executor/executor.d.ts.map +0 -1
  109. package/dist/types/src/executor/index.d.ts +0 -2
  110. package/dist/types/src/executor/index.d.ts.map +0 -1
  111. package/dist/types/src/handler.d.ts +0 -65
  112. package/dist/types/src/handler.d.ts.map +0 -1
  113. package/dist/types/src/schema.d.ts +0 -43
  114. package/dist/types/src/schema.d.ts.map +0 -1
  115. package/dist/types/src/services/database.d.ts +0 -98
  116. package/dist/types/src/services/database.d.ts.map +0 -1
  117. package/dist/types/src/services/local-function-execution.d.ts +0 -12
  118. package/dist/types/src/services/local-function-execution.d.ts.map +0 -1
  119. package/dist/types/src/services/remote-function-execution-service.d.ts +0 -15
  120. package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
  121. package/dist/types/src/services/service-container.d.ts +0 -56
  122. package/dist/types/src/services/service-container.d.ts.map +0 -1
  123. package/dist/types/src/services/service-registry.d.ts +0 -29
  124. package/dist/types/src/services/service-registry.d.ts.map +0 -1
  125. package/dist/types/src/services/service-registry.test.d.ts +0 -2
  126. package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
  127. package/dist/types/src/testing/index.d.ts +0 -3
  128. package/dist/types/src/testing/index.d.ts.map +0 -1
  129. package/dist/types/src/testing/layer.d.ts +0 -14
  130. package/dist/types/src/testing/layer.d.ts.map +0 -1
  131. package/dist/types/src/testing/logger.d.ts +0 -5
  132. package/dist/types/src/testing/logger.d.ts.map +0 -1
  133. package/dist/types/src/testing/persist-database.test.d.ts +0 -2
  134. package/dist/types/src/testing/persist-database.test.d.ts.map +0 -1
  135. package/dist/types/src/testing/services.d.ts +0 -59
  136. package/dist/types/src/testing/services.d.ts.map +0 -1
  137. package/dist/types/src/trace.d.ts +0 -150
  138. package/dist/types/src/trace.d.ts.map +0 -1
  139. package/dist/types/src/translations.d.ts +0 -12
  140. package/dist/types/src/translations.d.ts.map +0 -1
  141. package/dist/types/src/types.d.ts +0 -328
  142. package/dist/types/src/types.d.ts.map +0 -1
  143. package/dist/types/src/url.d.ts.map +0 -1
  144. package/src/bundler/bundler.test.ts +0 -58
  145. package/src/bundler/bundler.ts +0 -291
  146. package/src/bundler/index.ts +0 -5
  147. package/src/edge/functions.ts +0 -67
  148. package/src/edge/index.ts +0 -9
  149. package/src/executor/executor.ts +0 -54
  150. package/src/handler.ts +0 -122
  151. package/src/services/database.ts +0 -170
  152. package/src/services/local-function-execution.ts +0 -77
  153. package/src/services/remote-function-execution-service.ts +0 -46
  154. package/src/services/service-container.ts +0 -114
  155. package/src/services/service-registry.test.ts +0 -42
  156. package/src/services/service-registry.ts +0 -59
  157. package/src/testing/index.ts +0 -6
  158. package/src/testing/layer.ts +0 -97
  159. package/src/testing/logger.ts +0 -16
  160. package/src/testing/persist-database.test.ts +0 -87
  161. package/src/testing/services.ts +0 -115
  162. package/src/trace.ts +0 -178
  163. package/src/translations.ts +0 -20
  164. package/src/types.ts +0 -203
  165. package/src/url.ts +0 -55
@@ -1,42 +0,0 @@
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
- });
@@ -1,59 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Context, Effect, type Option, flow } 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('@dxos/functions/ServiceRegistry')<
16
- ServiceRegistry,
17
- ServiceRegistry.Service
18
- >() {
19
- /**
20
- * Resolves the service from the registry.
21
- * @param tag Service tag to resolve.
22
- * @throws {@link ServiceNotAvailableError} if the service is not found.
23
- * @returns Effect that resolve to the service.
24
- */
25
- static resolve: <T extends Context.Tag<any, any>>(
26
- tag: T,
27
- ) => Effect.Effect<T, ServiceNotAvailableError, ServiceRegistry> = (tag) =>
28
- ServiceRegistry.pipe(
29
- Effect.flatMap((_) => _.resolve(tag)),
30
- Effect.mapError(() => new ServiceNotAvailableError(tag.key)),
31
- );
32
-
33
- static provide: {
34
- <Tags extends [Context.Tag<any, any>, ...Context.Tag<any, any>[]]>(
35
- ...tags: Tags
36
- ): <A, E, R>(
37
- effect: Effect.Effect<A, E, R>,
38
- ) => Effect.Effect<
39
- A,
40
- E | ServiceNotAvailableError,
41
- Exclude<R, { [K in keyof Tags]: Context.Tag.Identifier<Tags[K]> }[number]> | ServiceRegistry
42
- >;
43
- } = (...tags) => (flow as any)(...tags.map((tag) => Effect.provideServiceEffect(tag, ServiceRegistry.resolve(tag))));
44
-
45
- static provideOrDie: {
46
- <Tags extends [Context.Tag<any, any>, ...Context.Tag<any, any>[]]>(
47
- ...tags: Tags
48
- ): <A, E, R>(
49
- effect: Effect.Effect<A, E, R>,
50
- ) => Effect.Effect<
51
- A,
52
- E,
53
- Exclude<R, { [K in keyof Tags]: Context.Tag.Identifier<Tags[K]> }[number]> | ServiceRegistry
54
- >;
55
- } = (...tags) =>
56
- (flow as any)(
57
- ...tags.map((tag) => Effect.provideServiceEffect(tag, ServiceRegistry.resolve(tag).pipe(Effect.orDie))),
58
- );
59
- }
@@ -1,6 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- export * from './services';
6
- export * from './layer';
@@ -1,97 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import type { Schema } from 'effect';
6
- import { Context, Effect, Layer } from 'effect';
7
-
8
- import type { EchoDatabaseImpl, QueueFactory } from '@dxos/echo-db';
9
- import { EchoTestBuilder } from '@dxos/echo-db/testing';
10
- import type { EchoHostIndexingConfig } from '@dxos/echo-pipeline';
11
- import { accuireReleaseResource } from '@dxos/effect';
12
- import { PublicKey } from '@dxos/keys';
13
- import type { LevelDB } from '@dxos/kv-store';
14
- import { createTestLevel } from '@dxos/kv-store/testing';
15
- import { log } from '@dxos/log';
16
-
17
- import { DatabaseService, QueueService } from '../services';
18
-
19
- const testBuilder = accuireReleaseResource(() => new EchoTestBuilder());
20
-
21
- export const testStoragePath = ({ name = PublicKey.random().toHex() }: { name?: string }) => {
22
- return `/tmp/dxos-${name}`;
23
- };
24
-
25
- export type TestDatabaseOptions = {
26
- indexing?: Partial<EchoHostIndexingConfig>;
27
- types?: Schema.Schema.AnyNoContext[];
28
- storagePath?: string;
29
- };
30
-
31
- export const TestDatabaseLayer = ({ indexing, types, storagePath }: TestDatabaseOptions = {}) =>
32
- Layer.scopedContext(
33
- Effect.gen(function* () {
34
- const builder = yield* testBuilder;
35
-
36
- let kv: LevelDB | undefined;
37
- if (storagePath) {
38
- kv = createTestLevel(storagePath);
39
- yield* Effect.promise(() => kv!.open());
40
- // const keyCount = yield* Effect.promise(async () => (await kv!.iterator({ values: false }).all()).length);
41
- // log.info('opened test db', { storagePath, keyCount });
42
- }
43
- const peer = yield* Effect.promise(() => builder.createPeer({ indexing, types, kv }));
44
-
45
- let db: EchoDatabaseImpl | undefined;
46
- let queues: QueueFactory | undefined;
47
-
48
- if (storagePath) {
49
- const testMetadata = yield* Effect.promise(async () => {
50
- try {
51
- return await kv!.get('test-metadata', { valueEncoding: 'json' });
52
- } catch (e) {
53
- if ((e as any).code === 'LEVEL_NOT_FOUND') {
54
- return undefined;
55
- }
56
- throw e;
57
- }
58
- });
59
- log('starting persistant test db', { storagePath, testMetadata });
60
- if (!testMetadata) {
61
- const key = PublicKey.random();
62
- db = yield* Effect.promise(() => peer.createDatabase(key));
63
- queues = peer.client.constructQueueFactory(db.spaceId);
64
-
65
- yield* Effect.promise(() =>
66
- kv!.put('test-metadata', { key: key.toHex(), rootUrl: db!.rootUrl }, { valueEncoding: 'json' }),
67
- );
68
- } else {
69
- const key = PublicKey.from((testMetadata as any).key);
70
- const rootUrl = (testMetadata as any).rootUrl;
71
- db = yield* Effect.promise(() => peer.openDatabase(key, rootUrl));
72
- queues = peer.client.constructQueueFactory(db.spaceId);
73
- }
74
- } else {
75
- db = yield* Effect.promise(() => peer.createDatabase());
76
- queues = peer.client.constructQueueFactory(db.spaceId);
77
- }
78
-
79
- yield* Effect.addFinalizer(() =>
80
- Effect.promise(async () => {
81
- if (kv) {
82
- // {
83
- // const keyCount = (await kv.iterator({ values: false }).all()).length;
84
- // log.info('closing persistant test db', { storagePath, keyCount });
85
- // }
86
-
87
- await kv.close();
88
- }
89
- }),
90
- );
91
-
92
- return Context.mergeAll(
93
- Context.make(DatabaseService, DatabaseService.make(db)),
94
- Context.make(QueueService, QueueService.make(queues, undefined)),
95
- );
96
- }),
97
- );
@@ -1,16 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type Context, Effect } from 'effect';
6
-
7
- import { LogLevel } from '@dxos/log';
8
-
9
- import { type ComputeEventLogger, createEventLogger } from '../services';
10
-
11
- export const noopLogger: Context.Tag.Service<ComputeEventLogger> = {
12
- log: () => Effect.succeed(undefined),
13
- nodeId: undefined,
14
- };
15
-
16
- export const consoleLogger: Context.Tag.Service<ComputeEventLogger> = createEventLogger(LogLevel.INFO);
@@ -1,87 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { describe, expect, it } from '@effect/vitest';
6
- import { Effect } from 'effect';
7
-
8
- import { Filter, Obj, Query, Type } from '@dxos/echo';
9
- import { DataType } from '@dxos/schema';
10
-
11
- import { DatabaseService } from '../services';
12
-
13
- import { TestDatabaseLayer, testStoragePath } from './layer';
14
-
15
- describe('TestDatabaseLayer', { timeout: 600_000 }, () => {
16
- it.effect(
17
- 'persist database to disk',
18
- Effect.fnUntraced(function* ({ expect: _ }) {
19
- const DbLayer = TestDatabaseLayer({
20
- storagePath: testStoragePath({ name: `feed-test-${Date.now()}` }),
21
- });
22
-
23
- yield* Effect.gen(function* () {
24
- yield* DatabaseService.add(Obj.make(Type.Expando, { label: 'test' }));
25
- yield* DatabaseService.flush({ indexes: true });
26
- }).pipe(Effect.provide(DbLayer));
27
-
28
- yield* Effect.gen(function* () {
29
- const { objects } = yield* DatabaseService.runQuery(Query.select(Filter.everything()));
30
- expect(objects[0]?.label).toEqual('test');
31
- }).pipe(Effect.provide(DbLayer));
32
- }),
33
- );
34
-
35
- it.effect(
36
- 'reload database -- save index before restart',
37
- Effect.fnUntraced(function* ({ expect: _ }) {
38
- const NUM_OBJECTS = 500;
39
- const DbLayer = TestDatabaseLayer({
40
- types: [DataType.Person],
41
- storagePath: testStoragePath({ name: `reload-test-${Date.now()}` }),
42
- });
43
-
44
- yield* Effect.gen(function* () {
45
- for (let i = 0; i < NUM_OBJECTS; i++) {
46
- yield* DatabaseService.add(Obj.make(DataType.Person, { nickname: `Person ${i}` }));
47
- }
48
- yield* DatabaseService.flush({ indexes: true });
49
- }).pipe(Effect.provide(DbLayer));
50
-
51
- yield* Effect.gen(function* () {
52
- const { objects } = yield* DatabaseService.runQuery(Query.select(Filter.type(DataType.Person)));
53
- expect(objects.length).toEqual(NUM_OBJECTS);
54
- }).pipe(Effect.provide(DbLayer));
55
- }),
56
- );
57
-
58
- it.effect.skip(
59
- 'reload database -- save index before restart [manual]',
60
- Effect.fnUntraced(
61
- function* ({ expect: _ }) {
62
- const NUM_OBJECTS = 500;
63
-
64
- {
65
- const { objects } = yield* DatabaseService.runQuery(Query.select(Filter.type(DataType.Person)));
66
- console.log({ count: objects.length });
67
- }
68
-
69
- for (let i = 0; i < NUM_OBJECTS; i++) {
70
- yield* DatabaseService.add(Obj.make(DataType.Person, { nickname: `Person ${i}` }));
71
- }
72
- yield* DatabaseService.flush({ indexes: true });
73
-
74
- {
75
- const { objects } = yield* DatabaseService.runQuery(Query.select(Filter.type(DataType.Person)));
76
- console.log({ count: objects.length });
77
- }
78
- },
79
- Effect.provide(
80
- TestDatabaseLayer({
81
- types: [DataType.Person],
82
- storagePath: testStoragePath({ name: `reload-test` }),
83
- }),
84
- ),
85
- ),
86
- );
87
- });
@@ -1,115 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type Context } from 'effect';
6
-
7
- import type { Space } from '@dxos/client/echo';
8
- import type { EchoDatabase, QueueFactory } from '@dxos/echo-db';
9
- import { assertArgument } from '@dxos/invariant';
10
-
11
- import {
12
- type ComputeEventLogger,
13
- ConfiguredCredentialsService,
14
- type CredentialsService,
15
- DatabaseService,
16
- QueueService,
17
- ServiceContainer,
18
- type ServiceCredential,
19
- type TracingService,
20
- } from '../services';
21
-
22
- import { consoleLogger, noopLogger } from './logger';
23
-
24
- // TODO(burdon): Factor out.
25
- export type OneOf<T> = {
26
- [K in keyof T]: { [P in K]: T[P] } & { [P in Exclude<keyof T, K>]?: never };
27
- }[keyof T];
28
-
29
- export type AiServiceProvider = 'dev' | 'edge' | 'ollama' | 'lmstudio';
30
-
31
- export type TestServiceOptions = {
32
- /**
33
- * AI service configuration.
34
- */
35
- ai?: any;
36
-
37
- /**
38
- * Credentials service configuration.
39
- */
40
- credentials?: OneOf<{
41
- /**
42
- * Predefined credentials list.
43
- */
44
- services?: ServiceCredential[];
45
-
46
- /**
47
- * Custom credentials service.
48
- */
49
- service?: Context.Tag.Service<CredentialsService>;
50
- }>;
51
-
52
- /**
53
- * Database configuration.
54
- */
55
- db?: EchoDatabase;
56
-
57
- /**
58
- * Gets database and queue services from the space.
59
- * Exclusive with: `db`, `queues`
60
- */
61
- space?: Space;
62
-
63
- /**
64
- * Logging configuration.
65
- */
66
- logging?: {
67
- enabled?: boolean;
68
- logger?: Context.Tag.Service<ComputeEventLogger>;
69
- };
70
-
71
- /**
72
- * Queue service configuration.
73
- */
74
- queues?: QueueFactory;
75
-
76
- tracing?: {
77
- service?: Context.Tag.Service<TracingService>;
78
- };
79
- };
80
-
81
- /**
82
- * @deprecated
83
- */
84
- export const createTestServices = ({
85
- ai,
86
- credentials,
87
- db,
88
- logging,
89
- queues,
90
- space,
91
- tracing,
92
- }: TestServiceOptions = {}): ServiceContainer => {
93
- assertArgument(!(!!space && (!!db || !!queues)), 'space can be provided only if db and queues are not');
94
-
95
- return new ServiceContainer().setServices({
96
- // ai: createAiService(ai),
97
- credentials: createCredentialsService(credentials),
98
- database: space || db ? DatabaseService.make(space?.db || db!) : undefined,
99
- eventLogger: (logging?.logger ?? logging?.enabled) ? consoleLogger : noopLogger,
100
- queues: space || queues ? QueueService.make(space?.queues || queues!, undefined) : undefined,
101
- tracing: tracing?.service,
102
- });
103
- };
104
-
105
- const createCredentialsService = (
106
- credentials: TestServiceOptions['credentials'] | undefined,
107
- ): Context.Tag.Service<CredentialsService> | undefined => {
108
- if (credentials?.services) {
109
- return new ConfiguredCredentialsService(credentials.services);
110
- }
111
-
112
- if (credentials?.service) {
113
- return credentials.service;
114
- }
115
- };
package/src/trace.ts DELETED
@@ -1,178 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import { type Ref, Type } from '@dxos/echo';
8
- import { Queue } from '@dxos/echo-db';
9
- import { ObjectId } from '@dxos/echo-schema';
10
- import { log } from '@dxos/log';
11
-
12
- import { FunctionTrigger } from './types';
13
-
14
- export enum InvocationOutcome {
15
- SUCCESS = 'success',
16
- FAILURE = 'failure',
17
- PENDING = 'pending',
18
- }
19
-
20
- // TODO(burdon): Convert to extensible discriminated union of EDGE events.
21
- export enum InvocationTraceEventType {
22
- START = 'start',
23
- END = 'end',
24
- }
25
-
26
- export const TraceEventException = Schema.Struct({
27
- timestampMs: Schema.Number,
28
- message: Schema.String,
29
- name: Schema.String,
30
- stack: Schema.optional(Schema.String),
31
- });
32
- export type TraceEventException = Schema.Schema.Type<typeof TraceEventException>;
33
-
34
- export const InvocationTraceStartEvent = Schema.Struct({
35
- /**
36
- * Queue message id.
37
- */
38
- id: ObjectId,
39
- type: Schema.Literal(InvocationTraceEventType.START),
40
- /**
41
- * Invocation id, the same for invocation start and end events.
42
- */
43
- invocationId: ObjectId,
44
- /**
45
- * Event generation time.
46
- */
47
- timestampMs: Schema.Number,
48
- /**
49
- * Data passed to function / workflow as an argument.
50
- */
51
- // TODO(burdon): Input schema?
52
- input: Schema.Object,
53
- /**
54
- * Queue for function/workflow invocation events.
55
- */
56
- invocationTraceQueue: Type.Ref(Queue),
57
- /**
58
- * DXN of the invoked function/workflow.
59
- */
60
- invocationTarget: Type.Ref(Type.Expando),
61
- /**
62
- * Present for automatic invocations.
63
- */
64
- trigger: Schema.optional(Type.Ref(FunctionTrigger)),
65
- }).pipe(Type.Obj({ typename: 'dxos.org/type/InvocationTraceStart', version: '0.1.0' }));
66
-
67
- export type InvocationTraceStartEvent = Schema.Schema.Type<typeof InvocationTraceStartEvent>;
68
-
69
- export const InvocationTraceEndEvent = Schema.Struct({
70
- /**
71
- * Trace event id.
72
- */
73
- id: ObjectId,
74
- type: Schema.Literal(InvocationTraceEventType.END),
75
- /**
76
- * Invocation id, will be the same for invocation start and end.
77
- */
78
- invocationId: ObjectId,
79
- /**
80
- * Event generation time.
81
- */
82
- // TODO(burdon): Remove ms suffix.
83
- timestampMs: Schema.Number,
84
- outcome: Schema.Enums(InvocationOutcome),
85
- exception: Schema.optional(TraceEventException),
86
- }).pipe(Type.Obj({ typename: 'dxos.org/type/InvocationTraceEnd', version: '0.1.0' }));
87
-
88
- export type InvocationTraceEndEvent = Schema.Schema.Type<typeof InvocationTraceEndEvent>;
89
-
90
- export type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;
91
-
92
- export const TraceEventLog = Schema.Struct({
93
- timestampMs: Schema.Number,
94
- level: Schema.String,
95
- message: Schema.String,
96
- context: Schema.optional(Schema.Object),
97
- });
98
-
99
- export const TraceEvent = Schema.Struct({
100
- id: ObjectId,
101
- // TODO(burdon): Need enum/numeric result (not string).
102
- outcome: Schema.String,
103
- truncated: Schema.Boolean,
104
- /** Time when the event was persisted. */
105
- ingestionTimestamp: Schema.Number,
106
- logs: Schema.Array(TraceEventLog),
107
- exceptions: Schema.Array(TraceEventException),
108
- }).pipe(Type.Obj({ typename: 'dxos.org/type/TraceEvent', version: '0.1.0' }));
109
-
110
- export type TraceEvent = Schema.Schema.Type<typeof TraceEvent>;
111
-
112
- /**
113
- * InvocationTrace event format.
114
- * This is the combined format of InvocationTraceStartEvent and InvocationTraceEndEvents for UI consumption.
115
- */
116
- export type InvocationSpan = {
117
- id: string;
118
- timestampMs: number;
119
- outcome: InvocationOutcome;
120
- input: object;
121
- durationMs: number;
122
- invocationTraceQueue: Ref.Ref<Queue>;
123
- invocationTarget: Ref.Ref<Type.Expando>;
124
- trigger?: Ref.Ref<FunctionTrigger>;
125
- exception?: TraceEventException;
126
- };
127
-
128
- export const createInvocationSpans = (items?: InvocationTraceEvent[]): InvocationSpan[] => {
129
- if (!items) {
130
- return [];
131
- }
132
-
133
- const eventsByInvocationId = new Map<string, { start?: InvocationTraceStartEvent; end?: InvocationTraceEndEvent }>();
134
- for (const event of items) {
135
- if (!('invocationId' in event)) {
136
- // Skip legacy format entries.
137
- continue;
138
- }
139
-
140
- const invocationId = event.invocationId;
141
- const entry = eventsByInvocationId.get(invocationId) || { start: undefined, end: undefined };
142
- if (event.type === InvocationTraceEventType.START) {
143
- entry.start = event as InvocationTraceStartEvent;
144
- } else if (event.type === InvocationTraceEventType.END) {
145
- entry.end = event as InvocationTraceEndEvent;
146
- }
147
-
148
- eventsByInvocationId.set(invocationId, entry);
149
- }
150
-
151
- const now = Date.now();
152
- const result: InvocationSpan[] = [];
153
-
154
- // Create spans for each invocation
155
- for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {
156
- if (!start) {
157
- // No start event, can't create a meaningful span
158
- log.warn('found end event without matching start', { invocationId });
159
- continue;
160
- }
161
-
162
- const isInProgress = end === undefined;
163
-
164
- result.push({
165
- id: invocationId,
166
- timestampMs: start.timestampMs,
167
- durationMs: isInProgress ? now - start.timestampMs : end!.timestampMs - start.timestampMs,
168
- outcome: end?.outcome ?? InvocationOutcome.PENDING,
169
- exception: end?.exception,
170
- input: start.input,
171
- invocationTraceQueue: start.invocationTraceQueue,
172
- invocationTarget: start.invocationTarget,
173
- trigger: start.trigger,
174
- });
175
- }
176
-
177
- return result;
178
- };
@@ -1,20 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { type Resource } from 'i18next';
6
-
7
- import { ScriptType } from './schema';
8
-
9
- export const translations = [
10
- {
11
- 'en-US': {
12
- [ScriptType.typename]: {
13
- 'typename label': 'Script',
14
- 'typename label_zero': 'Scripts',
15
- 'typename label_one': 'Script',
16
- 'typename label_other': 'Scripts',
17
- },
18
- },
19
- },
20
- ] as const satisfies Resource[];