@dxos/functions 0.8.4-main.3f58842 → 0.8.4-main.548089c

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 (144) hide show
  1. package/dist/lib/browser/index.mjs +663 -363
  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 +663 -363
  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 +81 -28
  8. package/dist/types/src/errors.d.ts.map +1 -1
  9. package/dist/types/src/example/fib.d.ts +7 -0
  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/example/reply.d.ts +3 -0
  16. package/dist/types/src/example/reply.d.ts.map +1 -0
  17. package/dist/types/src/example/sleep.d.ts +5 -0
  18. package/dist/types/src/example/sleep.d.ts.map +1 -0
  19. package/dist/types/src/handler.d.ts +56 -36
  20. package/dist/types/src/handler.d.ts.map +1 -1
  21. package/dist/types/src/index.d.ts +3 -5
  22. package/dist/types/src/index.d.ts.map +1 -1
  23. package/dist/types/src/services/credentials.d.ts +20 -3
  24. package/dist/types/src/services/credentials.d.ts.map +1 -1
  25. package/dist/types/src/services/event-logger.d.ts +80 -30
  26. package/dist/types/src/services/event-logger.d.ts.map +1 -1
  27. package/dist/types/src/services/function-invocation-service.d.ts +11 -0
  28. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
  29. package/dist/types/src/services/index.d.ts +6 -5
  30. package/dist/types/src/services/index.d.ts.map +1 -1
  31. package/dist/types/src/services/queues.d.ts +23 -6
  32. package/dist/types/src/services/queues.d.ts.map +1 -1
  33. package/dist/types/src/services/tracing.d.ts +35 -6
  34. package/dist/types/src/services/tracing.d.ts.map +1 -1
  35. package/dist/types/src/types/Function.d.ts +52 -0
  36. package/dist/types/src/types/Function.d.ts.map +1 -0
  37. package/dist/types/src/types/Script.d.ts +28 -0
  38. package/dist/types/src/types/Script.d.ts.map +1 -0
  39. package/dist/types/src/types/Trigger.d.ts +139 -0
  40. package/dist/types/src/types/Trigger.d.ts.map +1 -0
  41. package/dist/types/src/types/TriggerEvent.d.ts +44 -0
  42. package/dist/types/src/types/TriggerEvent.d.ts.map +1 -0
  43. package/dist/types/src/types/index.d.ts +5 -0
  44. package/dist/types/src/types/index.d.ts.map +1 -0
  45. package/dist/types/src/url.d.ts +7 -12
  46. package/dist/types/src/url.d.ts.map +1 -1
  47. package/dist/types/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +17 -68
  49. package/src/errors.ts +13 -5
  50. package/src/example/fib.ts +32 -0
  51. package/src/example/forex-effect.ts +40 -0
  52. package/src/example/index.ts +13 -0
  53. package/src/example/reply.ts +21 -0
  54. package/src/example/sleep.ts +24 -0
  55. package/src/handler.ts +145 -64
  56. package/src/index.ts +3 -7
  57. package/src/services/credentials.ts +85 -3
  58. package/src/services/event-logger.ts +77 -37
  59. package/src/services/function-invocation-service.ts +20 -0
  60. package/src/services/index.ts +7 -5
  61. package/src/services/queues.ts +39 -10
  62. package/src/services/tracing.ts +82 -16
  63. package/src/types/Function.ts +56 -0
  64. package/src/types/Script.ts +33 -0
  65. package/src/types/Trigger.ts +139 -0
  66. package/src/types/TriggerEvent.ts +62 -0
  67. package/src/types/index.ts +8 -0
  68. package/src/url.ts +12 -33
  69. package/dist/lib/browser/bundler/index.mjs +0 -247
  70. package/dist/lib/browser/bundler/index.mjs.map +0 -7
  71. package/dist/lib/browser/chunk-3NGCSUEW.mjs +0 -328
  72. package/dist/lib/browser/chunk-3NGCSUEW.mjs.map +0 -7
  73. package/dist/lib/browser/edge/index.mjs +0 -69
  74. package/dist/lib/browser/edge/index.mjs.map +0 -7
  75. package/dist/lib/browser/testing/index.mjs +0 -91
  76. package/dist/lib/browser/testing/index.mjs.map +0 -7
  77. package/dist/lib/node-esm/bundler/index.mjs +0 -249
  78. package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
  79. package/dist/lib/node-esm/chunk-FJ2MU7TL.mjs +0 -330
  80. package/dist/lib/node-esm/chunk-FJ2MU7TL.mjs.map +0 -7
  81. package/dist/lib/node-esm/edge/index.mjs +0 -71
  82. package/dist/lib/node-esm/edge/index.mjs.map +0 -7
  83. package/dist/lib/node-esm/testing/index.mjs +0 -92
  84. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  85. package/dist/types/src/bundler/bundler.d.ts +0 -50
  86. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  87. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  88. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  89. package/dist/types/src/bundler/index.d.ts +0 -2
  90. package/dist/types/src/bundler/index.d.ts.map +0 -1
  91. package/dist/types/src/edge/functions.d.ts +0 -16
  92. package/dist/types/src/edge/functions.d.ts.map +0 -1
  93. package/dist/types/src/edge/index.d.ts +0 -2
  94. package/dist/types/src/edge/index.d.ts.map +0 -1
  95. package/dist/types/src/executor/executor.d.ts +0 -8
  96. package/dist/types/src/executor/executor.d.ts.map +0 -1
  97. package/dist/types/src/executor/index.d.ts +0 -2
  98. package/dist/types/src/executor/index.d.ts.map +0 -1
  99. package/dist/types/src/schema.d.ts +0 -38
  100. package/dist/types/src/schema.d.ts.map +0 -1
  101. package/dist/types/src/services/database.d.ts +0 -29
  102. package/dist/types/src/services/database.d.ts.map +0 -1
  103. package/dist/types/src/services/function-call-service.d.ts +0 -16
  104. package/dist/types/src/services/function-call-service.d.ts.map +0 -1
  105. package/dist/types/src/services/service-container.d.ts +0 -56
  106. package/dist/types/src/services/service-container.d.ts.map +0 -1
  107. package/dist/types/src/services/service-registry.d.ts +0 -29
  108. package/dist/types/src/services/service-registry.d.ts.map +0 -1
  109. package/dist/types/src/services/service-registry.test.d.ts +0 -2
  110. package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
  111. package/dist/types/src/testing/index.d.ts +0 -3
  112. package/dist/types/src/testing/index.d.ts.map +0 -1
  113. package/dist/types/src/testing/layer.d.ts +0 -10
  114. package/dist/types/src/testing/layer.d.ts.map +0 -1
  115. package/dist/types/src/testing/logger.d.ts +0 -5
  116. package/dist/types/src/testing/logger.d.ts.map +0 -1
  117. package/dist/types/src/testing/services.d.ts +0 -70
  118. package/dist/types/src/testing/services.d.ts.map +0 -1
  119. package/dist/types/src/trace.d.ts +0 -124
  120. package/dist/types/src/trace.d.ts.map +0 -1
  121. package/dist/types/src/translations.d.ts +0 -12
  122. package/dist/types/src/translations.d.ts.map +0 -1
  123. package/dist/types/src/types.d.ts +0 -411
  124. package/dist/types/src/types.d.ts.map +0 -1
  125. package/src/bundler/bundler.test.ts +0 -59
  126. package/src/bundler/bundler.ts +0 -292
  127. package/src/bundler/index.ts +0 -5
  128. package/src/edge/functions.ts +0 -64
  129. package/src/edge/index.ts +0 -9
  130. package/src/executor/executor.ts +0 -54
  131. package/src/executor/index.ts +0 -5
  132. package/src/schema.ts +0 -57
  133. package/src/services/database.ts +0 -70
  134. package/src/services/function-call-service.ts +0 -64
  135. package/src/services/service-container.ts +0 -113
  136. package/src/services/service-registry.test.ts +0 -42
  137. package/src/services/service-registry.ts +0 -56
  138. package/src/testing/index.ts +0 -6
  139. package/src/testing/layer.ts +0 -31
  140. package/src/testing/logger.ts +0 -16
  141. package/src/testing/services.ts +0 -168
  142. package/src/trace.ts +0 -180
  143. package/src/translations.ts +0 -20
  144. package/src/types.ts +0 -211
@@ -2,53 +2,90 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Effect, Context } from 'effect';
5
+ import * as Context from 'effect/Context';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Layer from 'effect/Layer';
8
+ import * as Schema from 'effect/Schema';
6
9
 
10
+ import { Obj, Type } from '@dxos/echo';
7
11
  import { invariant } from '@dxos/invariant';
8
- import { log, LogLevel } from '@dxos/log';
12
+ import { LogLevel, log } from '@dxos/log';
9
13
 
10
- export type ComputeEvent =
11
- | {
12
- type: 'begin-compute';
13
- nodeId: string;
14
- inputs: Record<string, any>;
15
- }
16
- | {
17
- type: 'end-compute';
18
- nodeId: string;
19
- outputs: Record<string, any>;
20
- }
21
- | {
22
- type: 'compute-input';
23
- nodeId: string;
24
- property: string;
25
- value: any;
26
- }
27
- | {
28
- type: 'compute-output';
29
- nodeId: string;
30
- property: string;
31
- value: any;
32
- }
33
- | {
34
- type: 'custom';
35
- nodeId: string;
36
- event: any;
37
- };
14
+ import { TracingService } from './tracing';
15
+
16
+ export const ComputeEventPayload = Schema.Union(
17
+ Schema.Struct({
18
+ type: Schema.Literal('begin-compute'),
19
+ nodeId: Schema.String,
20
+ /**
21
+ * Names of the inputs begin computed.
22
+ */
23
+ inputs: Schema.Array(Schema.String),
24
+ }),
25
+ Schema.Struct({
26
+ type: Schema.Literal('end-compute'),
27
+ nodeId: Schema.String,
28
+ /**
29
+ * Names of the outputs computed.
30
+ */
31
+ outputs: Schema.Array(Schema.String),
32
+ }),
33
+ Schema.Struct({
34
+ type: Schema.Literal('compute-input'),
35
+ nodeId: Schema.String,
36
+ property: Schema.String,
37
+ value: Schema.Any,
38
+ }),
39
+ Schema.Struct({
40
+ type: Schema.Literal('compute-output'),
41
+ nodeId: Schema.String,
42
+ property: Schema.String,
43
+ value: Schema.Any,
44
+ }),
45
+ Schema.Struct({
46
+ type: Schema.Literal('custom'),
47
+ nodeId: Schema.String,
48
+ event: Schema.Any,
49
+ }),
50
+ );
51
+ export type ComputeEventPayload = Schema.Schema.Type<typeof ComputeEventPayload>;
38
52
 
39
- export class EventLogger extends Context.Tag('EventLogger')<
40
- EventLogger,
41
- { readonly log: (event: ComputeEvent) => void; readonly nodeId: string | undefined }
53
+ export const ComputeEvent = Schema.Struct({
54
+ payload: ComputeEventPayload,
55
+ }).pipe(Type.Obj({ typename: 'dxos.org/type/ComputeEvent', version: '0.1.0' }));
56
+
57
+ /**
58
+ * Logs event for the compute workflows.
59
+ */
60
+ export class ComputeEventLogger extends Context.Tag('@dxos/functions/ComputeEventLogger')<
61
+ ComputeEventLogger,
62
+ { readonly log: (event: ComputeEventPayload) => void; readonly nodeId: string | undefined }
42
63
  >() {
43
- static noop: Context.Tag.Service<EventLogger> = {
64
+ static noop: Context.Tag.Service<ComputeEventLogger> = {
44
65
  log: () => {},
45
66
  nodeId: undefined,
46
67
  };
68
+
69
+ /**
70
+ * Implements ComputeEventLogger using TracingService.
71
+ */
72
+ static layerFromTracing = Layer.effect(
73
+ ComputeEventLogger,
74
+ Effect.gen(function* () {
75
+ const tracing = yield* TracingService;
76
+ return {
77
+ log: (event: ComputeEventPayload) => {
78
+ tracing.write(Obj.make(ComputeEvent, { payload: event }));
79
+ },
80
+ nodeId: undefined,
81
+ };
82
+ }),
83
+ );
47
84
  }
48
85
 
49
86
  export const logCustomEvent = (data: any) =>
50
87
  Effect.gen(function* () {
51
- const logger = yield* EventLogger;
88
+ const logger = yield* ComputeEventLogger;
52
89
  if (!logger.nodeId) {
53
90
  throw new Error('logCustomEvent must be called within a node compute function');
54
91
  }
@@ -67,7 +104,10 @@ export const createDefectLogger = <A, E, R>(): ((self: Effect.Effect<A, E, R>) =
67
104
  }),
68
105
  );
69
106
 
70
- export const createEventLogger = (level: LogLevel, message: string = 'event'): Context.Tag.Service<EventLogger> => {
107
+ export const createEventLogger = (
108
+ level: LogLevel,
109
+ message: string = 'event',
110
+ ): Context.Tag.Service<ComputeEventLogger> => {
71
111
  const logFunction = (
72
112
  {
73
113
  [LogLevel.WARN]: log.warn,
@@ -79,7 +119,7 @@ export const createEventLogger = (level: LogLevel, message: string = 'event'): C
79
119
  )[level];
80
120
  invariant(logFunction);
81
121
  return {
82
- log: (event: ComputeEvent) => {
122
+ log: (event: ComputeEventPayload) => {
83
123
  logFunction(message, event);
84
124
  },
85
125
  nodeId: undefined,
@@ -0,0 +1,20 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+ import * as Context from 'effect/Context';
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { type FunctionDefinition, type InvocationServices } from '../handler';
8
+
9
+ export class FunctionInvocationService extends Context.Tag('@dxos/functions/FunctionInvocationService')<
10
+ FunctionInvocationService,
11
+ {
12
+ invokeFunction<I, O>(functionDef: FunctionDefinition<I, O>, input: I): Effect.Effect<O, never, InvocationServices>;
13
+ }
14
+ >() {
15
+ static invokeFunction = <I, O>(
16
+ functionDef: FunctionDefinition<I, O>,
17
+ input: I,
18
+ ): Effect.Effect<O, never, FunctionInvocationService | InvocationServices> =>
19
+ Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.invokeFunction)(functionDef, input);
20
+ }
@@ -2,10 +2,12 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './database';
6
- export * from './queues';
7
- export * from './service-container';
5
+ export { DatabaseService } from '@dxos/echo-db';
6
+
8
7
  export * from './credentials';
9
- export * from './tracing';
8
+ export { ConfiguredCredentialsService, type ServiceCredential } from './credentials';
10
9
  export * from './event-logger';
11
- export * from './function-call-service';
10
+ export { createEventLogger, createDefectLogger } from './event-logger';
11
+ export * from './function-invocation-service';
12
+ export * from './queues';
13
+ export * from './tracing';
@@ -2,14 +2,18 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Context, Layer } from 'effect';
5
+ import * as Context from 'effect/Context';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Layer from 'effect/Layer';
6
8
 
9
+ import type { Obj, Relation } from '@dxos/echo';
7
10
  import type { Queue, QueueAPI, QueueFactory } from '@dxos/echo-db';
11
+ import type { DXN, QueueSubspaceTag } from '@dxos/keys';
8
12
 
9
13
  /**
10
14
  * Gives access to all queues.
11
15
  */
12
- export class QueueService extends Context.Tag('QueueService')<
16
+ export class QueueService extends Context.Tag('@dxos/functions/QueueService')<
13
17
  QueueService,
14
18
  {
15
19
  /**
@@ -21,35 +25,60 @@ export class QueueService extends Context.Tag('QueueService')<
21
25
  * The queue that is used to store the context of the current research.
22
26
  * @deprecated Use `ContextQueueService` instead.
23
27
  */
24
- readonly contextQueue: Queue | undefined;
28
+ readonly queue: Queue | undefined;
25
29
  }
26
30
  >() {
27
31
  static notAvailable = Layer.succeed(QueueService, {
28
32
  queues: {
29
- get(dxn) {
33
+ get(_dxn) {
30
34
  throw new Error('Queues not available');
31
35
  },
32
36
  create() {
33
37
  throw new Error('Queues not available');
34
38
  },
35
39
  },
36
- contextQueue: undefined,
40
+ queue: undefined,
37
41
  });
38
42
 
39
- static make = (queues: QueueFactory, contextQueue?: Queue): Context.Tag.Service<QueueService> => {
43
+ static make = (queues: QueueFactory, queue?: Queue): Context.Tag.Service<QueueService> => {
40
44
  return {
41
45
  queues,
42
- contextQueue,
46
+ queue,
43
47
  };
44
48
  };
49
+
50
+ static layer = (queues: QueueFactory, queue?: Queue): Layer.Layer<QueueService> =>
51
+ Layer.succeed(QueueService, QueueService.make(queues, queue));
52
+
53
+ /**
54
+ * Gets a queue by its DXN.
55
+ */
56
+ static getQueue = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(
57
+ dxn: DXN,
58
+ ): Effect.Effect<Queue<T>, never, QueueService> => QueueService.pipe(Effect.map(({ queues }) => queues.get<T>(dxn)));
59
+
60
+ /**
61
+ * Creates a new queue.
62
+ */
63
+ static createQueue = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(options?: {
64
+ subspaceTag?: QueueSubspaceTag;
65
+ }): Effect.Effect<Queue<T>, never, QueueService> =>
66
+ QueueService.pipe(Effect.map(({ queues }) => queues.create<T>(options)));
67
+
68
+ static append = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(
69
+ queue: Queue<T>,
70
+ objects: T[],
71
+ ): Effect.Effect<void> => Effect.promise(() => queue.append(objects));
45
72
  }
46
73
 
47
74
  /**
48
75
  * Gives access to a specific queue passed as a context.
49
76
  */
50
- export class ContextQueueService extends Context.Tag('ContextQueueService')<
77
+ export class ContextQueueService extends Context.Tag('@dxos/functions/ContextQueueService')<
51
78
  ContextQueueService,
52
79
  {
53
- readonly contextQueue: Queue;
80
+ readonly queue: Queue;
54
81
  }
55
- >() {}
82
+ >() {
83
+ static layer = (queue: Queue) => Layer.succeed(ContextQueueService, { queue });
84
+ }
@@ -2,41 +2,107 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Context, Effect } from 'effect';
5
+ import * as Context from 'effect/Context';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Layer from 'effect/Layer';
6
8
 
7
9
  import { AgentStatus } from '@dxos/ai';
8
10
  import { Obj } from '@dxos/echo';
9
- import type { AnyEchoObject } from '@dxos/echo-schema';
11
+ import type { ObjectId } from '@dxos/echo/internal';
12
+ import { Message } from '@dxos/types';
10
13
 
11
14
  /**
12
15
  * Provides a way for compute primitives (functions, workflows, tools)
13
16
  * to emit an execution trace as a series of structured ECHO objects.
14
17
  */
15
- export class TracingService extends Context.Tag('TracingService')<
18
+ export class TracingService extends Context.Tag('@dxos/functions/TracingService')<
16
19
  TracingService,
17
20
  {
21
+ /**
22
+ * Gets the parent message ID.
23
+ */
24
+ getTraceContext: () => TracingService.TraceContext;
25
+
18
26
  /**
19
27
  * Write an event to the tracing queue.
20
28
  * @param event - The event to write. Must be an a typed object.
21
29
  */
22
- write(event: AnyEchoObject): void;
30
+ write: (event: Obj.Any) => void;
23
31
  }
24
32
  >() {
25
- static noop: Context.Tag.Service<TracingService> = { write: () => {} };
26
-
27
- static console: Context.Tag.Service<TracingService> = {
28
- write: (event) => {
29
- // eslint-disable-next-line no-console
30
- console.log(event);
31
- },
33
+ static noop: Context.Tag.Service<TracingService> = {
34
+ getTraceContext: () => ({}),
35
+ write: () => {},
32
36
  };
33
37
 
38
+ static layerNoop: Layer.Layer<TracingService> = Layer.succeed(TracingService, TracingService.noop);
39
+ /**
40
+ * Creates a TracingService layer that emits events to the parent tracing service.
41
+ */
42
+ static layerSubframe = (mapContext: (currentContext: TracingService.TraceContext) => TracingService.TraceContext) =>
43
+ Layer.effect(
44
+ TracingService,
45
+ Effect.gen(function* () {
46
+ const tracing = yield* TracingService;
47
+ const context = mapContext(tracing.getTraceContext());
48
+ return {
49
+ write: (event) => tracing.write(event),
50
+ getTraceContext: () => context,
51
+ };
52
+ }),
53
+ );
54
+
34
55
  /**
35
56
  * Emit the current human-readable execution status.
36
57
  */
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
- });
58
+ static emitStatus: (
59
+ data: Omit<Obj.MakeProps<typeof AgentStatus>, 'created'>,
60
+ ) => Effect.Effect<void, never, TracingService> = Effect.fnUntraced(function* (data) {
61
+ const tracing = yield* TracingService;
62
+ tracing.write(
63
+ Obj.make(AgentStatus, {
64
+ parentMessage: tracing.getTraceContext().parentMessage,
65
+ toolCallId: tracing.getTraceContext().toolCallId,
66
+ created: new Date().toISOString(),
67
+ ...data,
68
+ }),
69
+ );
70
+ });
71
+
72
+ static emitConverationMessage: (
73
+ data: Obj.MakeProps<typeof Message.Message>,
74
+ ) => Effect.Effect<void, never, TracingService> = Effect.fnUntraced(function* (data) {
75
+ const tracing = yield* TracingService;
76
+ tracing.write(
77
+ Obj.make(Message.Message, {
78
+ parentMessage: tracing.getTraceContext().parentMessage,
79
+ ...data,
80
+ properties: {
81
+ [MESSAGE_PROPERTY_TOOL_CALL_ID]: tracing.getTraceContext().toolCallId,
82
+ ...data.properties,
83
+ },
84
+ }),
85
+ );
86
+ });
87
+ }
88
+
89
+ export namespace TracingService {
90
+ export interface TraceContext {
91
+ /**
92
+ * If this thread sprung from a tool call, this is the ID of the message containing the tool call.
93
+ */
94
+ parentMessage?: ObjectId;
95
+
96
+ /**
97
+ * If the current thread is a byproduct of a tool call, this is the ID of the tool call.
98
+ */
99
+ toolCallId?: string;
100
+
101
+ debugInfo?: unknown;
102
+ }
42
103
  }
104
+
105
+ /**
106
+ * Goes into {@link Message['properties']}
107
+ */
108
+ export const MESSAGE_PROPERTY_TOOL_CALL_ID = 'toolCallId' as const;
@@ -0,0 +1,56 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { Obj, Type } from '@dxos/echo';
8
+ import { JsonSchemaType, LabelAnnotation, Ref } from '@dxos/echo/internal';
9
+
10
+ import { Script } from './Script';
11
+
12
+ /**
13
+ * Function deployment.
14
+ */
15
+ export const Function = Schema.Struct({
16
+ /**
17
+ * Global registry ID.
18
+ * NOTE: The `key` property refers to the original registry entry.
19
+ */
20
+ // TODO(burdon): Create Format type for DXN-like ids, such as this and schema type.
21
+ // TODO(dmaretskyi): Consider making it part of ECHO meta.
22
+ // TODO(dmaretskyi): Make required.
23
+ key: Schema.optional(Schema.String).annotations({
24
+ description: 'Unique registration key for the blueprint',
25
+ }),
26
+
27
+ // TODO(burdon): Rename to id/uri?
28
+ name: Schema.NonEmptyString,
29
+ version: Schema.String,
30
+
31
+ description: Schema.optional(Schema.String),
32
+
33
+ /**
34
+ * ISO date string of the last deployment.
35
+ */
36
+ updated: Schema.optional(Schema.String),
37
+
38
+ // Reference to a source script if it exists within ECHO.
39
+ // TODO(burdon): Don't ref ScriptType directly (core).
40
+ source: Schema.optional(Ref(Script)),
41
+
42
+ inputSchema: Schema.optional(JsonSchemaType),
43
+ outputSchema: Schema.optional(JsonSchemaType),
44
+
45
+ // Local binding to a function name.
46
+ binding: Schema.optional(Schema.String),
47
+ }).pipe(
48
+ Type.Obj({
49
+ typename: 'dxos.org/type/Function',
50
+ version: '0.1.0',
51
+ }),
52
+ LabelAnnotation.set(['name']),
53
+ );
54
+ export interface Function extends Schema.Schema.Type<typeof Function> {}
55
+
56
+ export const make = (props: Obj.MakeProps<typeof Function>) => Obj.make(Function, props);
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { Obj, Ref, Type } from '@dxos/echo';
8
+ import { FormAnnotation, LabelAnnotation } from '@dxos/echo/internal';
9
+ import { Text } from '@dxos/schema';
10
+
11
+ /**
12
+ * Source script.
13
+ */
14
+ export const Script = Schema.Struct({
15
+ name: Schema.String.pipe(Schema.optional),
16
+ description: Schema.String.pipe(Schema.optional),
17
+ // TODO(burdon): Change to hash of deployed content.
18
+ // Whether source has changed since last deploy.
19
+ changed: Schema.Boolean.pipe(FormAnnotation.set(false), Schema.optional),
20
+ source: Type.Ref(Text.Text).pipe(FormAnnotation.set(false)),
21
+ }).pipe(
22
+ Type.Obj({
23
+ typename: 'dxos.org/type/Script',
24
+ version: '0.1.0',
25
+ }),
26
+ LabelAnnotation.set(['name']),
27
+ );
28
+ export interface Script extends Schema.Schema.Type<typeof Script> {}
29
+
30
+ type Props = Omit<Obj.MakeProps<typeof Script>, 'source'> & { source?: string };
31
+
32
+ export const make = ({ source = '', ...props }: Props = {}) =>
33
+ Obj.make(Script, { ...props, source: Ref.make(Text.make(source)) });
@@ -0,0 +1,139 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+ import * as SchemaAST from 'effect/SchemaAST';
7
+
8
+ import { Obj, QueryAST, Type } from '@dxos/echo';
9
+ import { Expando, OptionsAnnotationId, Ref } from '@dxos/echo/internal';
10
+ import { DXN } from '@dxos/keys';
11
+
12
+ /**
13
+ * Type discriminator for TriggerType.
14
+ * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
15
+ * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
16
+ */
17
+ export const Kinds = ['email', 'queue', 'subscription', 'timer', 'webhook'] as const;
18
+ export type Kind = (typeof Kinds)[number];
19
+
20
+ const kindLiteralAnnotations = { title: 'Kind' };
21
+
22
+ export const EmailSpec = Schema.Struct({
23
+ kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
24
+ }).pipe(Schema.mutable);
25
+ export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
26
+
27
+ export const QueueSpec = Schema.Struct({
28
+ kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
29
+
30
+ // TODO(dmaretskyi): Change to a reference.
31
+ queue: DXN.Schema,
32
+ }).pipe(Schema.mutable);
33
+ export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
34
+
35
+ /**
36
+ * Subscription.
37
+ */
38
+ export const SubscriptionSpec = Schema.Struct({
39
+ kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
40
+ query: Schema.Struct({
41
+ raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
42
+ ast: QueryAST.Query,
43
+ }).pipe(Schema.mutable),
44
+ options: Schema.optional(
45
+ Schema.Struct({
46
+ // Watch changes to object (not just creation).
47
+ deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
48
+ // Debounce changes (delay in ms).
49
+ delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
50
+ }).annotations({ title: 'Options' }),
51
+ ),
52
+ }).pipe(Schema.mutable);
53
+ export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
54
+
55
+ /**
56
+ * Cron timer.
57
+ */
58
+ export const TimerSpec = Schema.Struct({
59
+ kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
60
+ cron: Schema.String.annotations({
61
+ title: 'Cron',
62
+ [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
63
+ }),
64
+ }).pipe(Schema.mutable);
65
+ export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
66
+
67
+ /**
68
+ * Webhook.
69
+ */
70
+ export const WebhookSpec = Schema.Struct({
71
+ kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
72
+ method: Schema.optional(
73
+ Schema.String.annotations({
74
+ title: 'Method',
75
+ [OptionsAnnotationId]: ['GET', 'POST'],
76
+ }),
77
+ ),
78
+ port: Schema.optional(
79
+ Schema.Number.annotations({
80
+ title: 'Port',
81
+ }),
82
+ ),
83
+ }).pipe(Schema.mutable);
84
+ export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
85
+
86
+ /**
87
+ * Trigger schema.
88
+ */
89
+ export const Spec = Schema.Union(EmailSpec, QueueSpec, SubscriptionSpec, TimerSpec, WebhookSpec).annotations({
90
+ title: 'Trigger',
91
+ });
92
+ export type Spec = Schema.Schema.Type<typeof Spec>;
93
+
94
+ /**
95
+ * Function trigger.
96
+ * Function is invoked with the `payload` passed as input data.
97
+ * The event that triggers the function is available in the function context.
98
+ */
99
+ const Trigger_ = Schema.Struct({
100
+ /**
101
+ * Function or workflow to invoke.
102
+ */
103
+ // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
104
+ function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
105
+
106
+ /**
107
+ * Only used for workflowSchema.
108
+ * Specifies the input node in the circuit.
109
+ * @deprecated Remove and enforce a single input node in all compute graphSchema.
110
+ */
111
+ inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
112
+
113
+ enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
114
+
115
+ spec: Schema.optional(Spec),
116
+
117
+ /**
118
+ * Passed as the input data to the function.
119
+ * Must match the function's input schema.
120
+ *
121
+ * @example
122
+ * {
123
+ * item: '{{$.trigger.event}}',
124
+ * instructions: 'Summarize and perform entity-extraction'
125
+ * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
126
+ * }
127
+ */
128
+ input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
129
+ }).pipe(
130
+ Type.Obj({
131
+ typename: 'dxos.org/type/Trigger',
132
+ version: '0.1.0',
133
+ }),
134
+ );
135
+ export interface Trigger extends Schema.Schema.Type<typeof Trigger_> {}
136
+ export interface TriggerEncoded extends Schema.Schema.Encoded<typeof Trigger_> {}
137
+ export const Trigger: Schema.Schema<Trigger, TriggerEncoded> = Trigger_;
138
+
139
+ export const make = (props: Obj.MakeProps<typeof Trigger>) => Obj.make(Trigger, props);