@dxos/functions 0.8.4-main.bc674ce → 0.8.4-main.bcb3aa67d6

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 (95) hide show
  1. package/README.md +4 -6
  2. package/dist/lib/neutral/Trace.mjs +34 -0
  3. package/dist/lib/neutral/Trace.mjs.map +7 -0
  4. package/dist/lib/neutral/chunk-BHLSCAA2.mjs +123 -0
  5. package/dist/lib/neutral/chunk-BHLSCAA2.mjs.map +7 -0
  6. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  7. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  8. package/dist/lib/neutral/chunk-Z2XDJJVH.mjs +49 -0
  9. package/dist/lib/neutral/chunk-Z2XDJJVH.mjs.map +7 -0
  10. package/dist/lib/neutral/fib-S6PPI4UW.mjs +23 -0
  11. package/dist/lib/neutral/fib-S6PPI4UW.mjs.map +7 -0
  12. package/dist/lib/{browser → neutral}/index.mjs +649 -633
  13. package/dist/lib/neutral/index.mjs.map +7 -0
  14. package/dist/lib/neutral/meta.json +1 -0
  15. package/dist/lib/neutral/reply-TOHXEG7V.mjs +19 -0
  16. package/dist/lib/neutral/reply-TOHXEG7V.mjs.map +7 -0
  17. package/dist/lib/neutral/sleep-QPSZDPEH.mjs +15 -0
  18. package/dist/lib/neutral/sleep-QPSZDPEH.mjs.map +7 -0
  19. package/dist/types/src/Trace.d.ts +135 -0
  20. package/dist/types/src/Trace.d.ts.map +1 -0
  21. package/dist/types/src/errors.d.ts.map +1 -1
  22. package/dist/types/src/example/definitions.d.ts +11 -0
  23. package/dist/types/src/example/definitions.d.ts.map +1 -0
  24. package/dist/types/src/example/fib.d.ts +3 -2
  25. package/dist/types/src/example/fib.d.ts.map +1 -1
  26. package/dist/types/src/example/index.d.ts +3 -11
  27. package/dist/types/src/example/index.d.ts.map +1 -1
  28. package/dist/types/src/example/reply.d.ts +2 -1
  29. package/dist/types/src/example/reply.d.ts.map +1 -1
  30. package/dist/types/src/example/sleep.d.ts +3 -2
  31. package/dist/types/src/example/sleep.d.ts.map +1 -1
  32. package/dist/types/src/index.d.ts +4 -0
  33. package/dist/types/src/index.d.ts.map +1 -1
  34. package/dist/types/src/process/Process.d.ts +247 -0
  35. package/dist/types/src/process/Process.d.ts.map +1 -0
  36. package/dist/types/src/process/ServiceResolver.d.ts +74 -0
  37. package/dist/types/src/process/ServiceResolver.d.ts.map +1 -0
  38. package/dist/types/src/process/StorageService.d.ts +58 -0
  39. package/dist/types/src/process/StorageService.d.ts.map +1 -0
  40. package/dist/types/src/protocol/protocol.d.ts +2 -2
  41. package/dist/types/src/protocol/protocol.d.ts.map +1 -1
  42. package/dist/types/src/sdk.d.ts +4 -104
  43. package/dist/types/src/sdk.d.ts.map +1 -1
  44. package/dist/types/src/services/event-logger.d.ts +4 -4
  45. package/dist/types/src/services/function-invocation-service.d.ts +6 -5
  46. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
  47. package/dist/types/src/services/queues.d.ts +4 -2
  48. package/dist/types/src/services/queues.d.ts.map +1 -1
  49. package/dist/types/src/services/tracing.d.ts +25 -2
  50. package/dist/types/src/services/tracing.d.ts.map +1 -1
  51. package/dist/types/src/types/Script.d.ts +4 -3
  52. package/dist/types/src/types/Script.d.ts.map +1 -1
  53. package/dist/types/src/types/Trigger.d.ts +8 -9
  54. package/dist/types/src/types/Trigger.d.ts.map +1 -1
  55. package/dist/types/src/types/TriggerEvent.d.ts +3 -2
  56. package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
  57. package/dist/types/src/types/index.d.ts +0 -1
  58. package/dist/types/src/types/index.d.ts.map +1 -1
  59. package/dist/types/src/types/url.d.ts +2 -2
  60. package/dist/types/tsconfig.tsbuildinfo +1 -1
  61. package/package.json +25 -20
  62. package/src/Trace.ts +162 -0
  63. package/src/errors.ts +1 -1
  64. package/src/example/definitions.ts +48 -0
  65. package/src/example/fib.ts +14 -24
  66. package/src/example/forex-effect.ts +1 -1
  67. package/src/example/index.ts +7 -8
  68. package/src/example/reply.ts +10 -13
  69. package/src/example/sleep.ts +8 -17
  70. package/src/index.ts +4 -0
  71. package/src/process/Process.ts +457 -0
  72. package/src/process/ServiceResolver.ts +173 -0
  73. package/src/process/StorageService.ts +99 -0
  74. package/src/protocol/protocol.ts +33 -27
  75. package/src/sdk.ts +6 -256
  76. package/src/services/event-logger.ts +1 -1
  77. package/src/services/function-invocation-service.ts +6 -5
  78. package/src/services/queues.ts +10 -2
  79. package/src/services/tracing.ts +35 -2
  80. package/src/types/Script.ts +7 -3
  81. package/src/types/Trigger.ts +17 -6
  82. package/src/types/TriggerEvent.ts +2 -2
  83. package/src/types/index.ts +0 -1
  84. package/src/types/url.ts +2 -2
  85. package/dist/lib/browser/index.mjs.map +0 -7
  86. package/dist/lib/browser/meta.json +0 -1
  87. package/dist/lib/node-esm/index.mjs +0 -1230
  88. package/dist/lib/node-esm/index.mjs.map +0 -7
  89. package/dist/lib/node-esm/meta.json +0 -1
  90. package/dist/types/src/operation-compatibility.test.d.ts +0 -2
  91. package/dist/types/src/operation-compatibility.test.d.ts.map +0 -1
  92. package/dist/types/src/types/Function.d.ts +0 -52
  93. package/dist/types/src/types/Function.d.ts.map +0 -1
  94. package/src/operation-compatibility.test.ts +0 -185
  95. package/src/types/Function.ts +0 -82
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/functions",
3
- "version": "0.8.4-main.bc674ce",
3
+ "version": "0.8.4-main.bcb3aa67d6",
4
4
  "description": "Functions API.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -16,8 +16,12 @@
16
16
  ".": {
17
17
  "source": "./src/index.ts",
18
18
  "types": "./dist/types/src/index.d.ts",
19
- "browser": "./dist/lib/browser/index.mjs",
20
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "default": "./dist/lib/neutral/index.mjs"
20
+ },
21
+ "./Trace": {
22
+ "source": "./src/Trace.ts",
23
+ "types": "./dist/types/src/Trace.d.ts",
24
+ "default": "./dist/lib/neutral/Trace.mjs"
21
25
  }
22
26
  },
23
27
  "types": "dist/types/src/index.d.ts",
@@ -27,23 +31,24 @@
27
31
  "src"
28
32
  ],
29
33
  "dependencies": {
30
- "@effect/ai-anthropic": "0.22.0",
31
- "@effect/platform": "0.93.6",
32
- "effect": "3.19.11",
33
- "@dxos/context": "0.8.4-main.bc674ce",
34
- "@dxos/ai": "0.8.4-main.bc674ce",
35
- "@dxos/echo": "0.8.4-main.bc674ce",
36
- "@dxos/echo-db": "0.8.4-main.bc674ce",
37
- "@dxos/effect": "0.8.4-main.bc674ce",
38
- "@dxos/errors": "0.8.4-main.bc674ce",
39
- "@dxos/keys": "0.8.4-main.bc674ce",
40
- "@dxos/invariant": "0.8.4-main.bc674ce",
41
- "@dxos/log": "0.8.4-main.bc674ce",
42
- "@dxos/node-std": "0.8.4-main.bc674ce",
43
- "@dxos/operation": "0.8.4-main.bc674ce",
44
- "@dxos/protocols": "0.8.4-main.bc674ce",
45
- "@dxos/schema": "0.8.4-main.bc674ce",
46
- "@dxos/types": "0.8.4-main.bc674ce"
34
+ "@effect-atom/atom": "^0.5.1",
35
+ "@effect/ai-anthropic": "0.23.0",
36
+ "@effect/platform": "0.94.4",
37
+ "effect": "3.20.0",
38
+ "@dxos/ai": "0.8.4-main.bcb3aa67d6",
39
+ "@dxos/context": "0.8.4-main.bcb3aa67d6",
40
+ "@dxos/echo-db": "0.8.4-main.bcb3aa67d6",
41
+ "@dxos/echo": "0.8.4-main.bcb3aa67d6",
42
+ "@dxos/errors": "0.8.4-main.bcb3aa67d6",
43
+ "@dxos/keys": "0.8.4-main.bcb3aa67d6",
44
+ "@dxos/invariant": "0.8.4-main.bcb3aa67d6",
45
+ "@dxos/effect": "0.8.4-main.bcb3aa67d6",
46
+ "@dxos/log": "0.8.4-main.bcb3aa67d6",
47
+ "@dxos/node-std": "0.8.4-main.bcb3aa67d6",
48
+ "@dxos/operation": "0.8.4-main.bcb3aa67d6",
49
+ "@dxos/protocols": "0.8.4-main.bcb3aa67d6",
50
+ "@dxos/types": "0.8.4-main.bcb3aa67d6",
51
+ "@dxos/schema": "0.8.4-main.bcb3aa67d6"
47
52
  },
48
53
  "publishConfig": {
49
54
  "access": "public"
package/src/Trace.ts ADDED
@@ -0,0 +1,162 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ // @import-as-namespace
6
+
7
+ import { Annotation, Obj, Type } from '@dxos/echo';
8
+ import * as Layer from 'effect/Layer';
9
+ import * as Context from 'effect/Context';
10
+ import * as Effect from 'effect/Effect';
11
+ import * as Schema from 'effect/Schema';
12
+
13
+ /**
14
+ * Writes ephemeral or persistent events to the trace.
15
+ * Exposed to processes and operations to record events to the trace.
16
+ */
17
+ export interface TraceWriter {
18
+ write<T>(eventType: EventType<T>, payload: NoInfer<T>): void;
19
+ }
20
+
21
+ /**
22
+ * Service that writes events to the trace.
23
+ * Exposed to processes and operations to record events to the trace.
24
+ */
25
+ export class TraceService extends Context.Tag('@dxos/functions/TraceService')<TraceService, TraceWriter>() {}
26
+
27
+ /**
28
+ * Writes an event to the trace.
29
+ */
30
+ export const write: <T>(eventType: EventType<T>, payload: NoInfer<T>) => Effect.Effect<void, never, TraceService> =
31
+ Effect.serviceFunction(TraceService, (_) => _.write);
32
+
33
+ /**
34
+ * Defines an event type for the trace.
35
+ */
36
+ export interface EventType<T> {
37
+ readonly key: string;
38
+ readonly schema: Schema.Schema<T, any>;
39
+ readonly isEphemeral: boolean;
40
+ }
41
+
42
+ export const EventType = <T>(
43
+ key: string,
44
+ opts: { schema: Schema.Schema<T, any>; isEphemeral: boolean },
45
+ ): EventType<T> => {
46
+ return {
47
+ key,
48
+ schema: opts.schema,
49
+ isEphemeral: opts.isEphemeral,
50
+ };
51
+ };
52
+
53
+ /**
54
+ * Extracts the payload type from an event type.
55
+ */
56
+ export type PayloadType<E extends EventType<any>> = E extends EventType<infer T> ? T : never;
57
+
58
+ export const Event = Schema.Struct({
59
+ timestamp: Schema.Number,
60
+ type: Schema.String,
61
+ data: Schema.Unknown, // Type-specific payload;
62
+ });
63
+ export interface Event extends Schema.Schema.Type<typeof Event> {}
64
+
65
+ /**
66
+ * Checks if an event is of a given type.
67
+ */
68
+ export const isOfType = <T, E extends Event>(eventType: EventType<T>, event: E): event is E & { data: T } => {
69
+ return event.type === eventType.key;
70
+ };
71
+
72
+ /**
73
+ * Metadata on the context of a trace message.
74
+ */
75
+ // TODO(dmaretskyi): Expand on this: conversation id, tool call id, etc.
76
+ export const Meta = Schema.Struct({
77
+ pid: Schema.optional(Schema.String), // NOTE: Not Process.ID to avoid circular dependency.
78
+ parentPid: Schema.optional(Schema.String),
79
+ processName: Schema.optional(Schema.String),
80
+ /**
81
+ * ID of the conversation feed object if present.
82
+ */
83
+ conversationId: Schema.optional(Obj.ID),
84
+
85
+ /**
86
+ * ID of the trigger object if invocation resulted from a trigger.
87
+ */
88
+ triggerId: Schema.optional(Obj.ID),
89
+ });
90
+ export interface Meta extends Schema.Schema.Type<typeof Meta> {}
91
+
92
+ /**
93
+ * Envelope for a set of events.
94
+ */
95
+ export const MessageData = Schema.Struct({
96
+ meta: Meta,
97
+
98
+ isEphemeral: Schema.Boolean,
99
+ events: Schema.Array(Event),
100
+ });
101
+ export interface MessageData extends Schema.Schema.Type<typeof MessageData> {}
102
+
103
+ export const Message = MessageData.pipe(
104
+ Type.object({
105
+ typename: 'org.dxos.type.traceMessage',
106
+ version: '0.1.0',
107
+ }),
108
+ Annotation.IconAnnotation.set({
109
+ icon: 'ph--note--regular',
110
+ hue: 'rose',
111
+ }),
112
+ );
113
+ export interface Message extends Schema.Schema.Type<typeof Message> {}
114
+
115
+ /**
116
+ * Sink for complete trace messages.
117
+ */
118
+ export interface Sink {
119
+ write(message: Message): void;
120
+ }
121
+
122
+ /**
123
+ * Sink for complete trace messages.
124
+ * The Process Manager forwards trace messages to it.
125
+ */
126
+ // TODO(dmaretskyi): Consider moving sink to the Process Manager.
127
+ export class TraceSink extends Context.Tag('@dxos/functions/TraceSink')<TraceSink, Sink>() {}
128
+
129
+ export const noopWriter: TraceWriter = {
130
+ write: () => {},
131
+ };
132
+
133
+ export const writerLayerNoop: Layer.Layer<TraceService> = Layer.succeed(TraceService, noopWriter);
134
+
135
+ export const layerNoop: Layer.Layer<TraceSink> = Layer.succeed(TraceSink, {
136
+ write: () => {},
137
+ });
138
+
139
+ export const layerConsole: Layer.Layer<TraceSink> = Layer.succeed(TraceSink, {
140
+ write: (message) => {
141
+ console.log(message);
142
+ },
143
+ });
144
+
145
+ export const testTraceService = (opts: { meta?: Meta } = {}): Layer.Layer<TraceService, never, TraceSink> =>
146
+ Layer.effect(
147
+ TraceService,
148
+ Effect.gen(function* () {
149
+ const sink = yield* TraceSink;
150
+ return {
151
+ write: (event, data) => {
152
+ sink.write(
153
+ Obj.make(Message, {
154
+ meta: opts.meta ?? {},
155
+ isEphemeral: event.isEphemeral,
156
+ events: [{ type: event.key, timestamp: Date.now(), data }],
157
+ }),
158
+ );
159
+ },
160
+ };
161
+ }),
162
+ );
package/src/errors.ts CHANGED
@@ -6,7 +6,7 @@ import { BaseError, type BaseErrorOptions } from '@dxos/errors';
6
6
 
7
7
  export class ServiceNotAvailableError extends BaseError.extend('ServiceNotAvailable', 'Service not available') {
8
8
  constructor(service: string, options?: Omit<BaseErrorOptions, 'context'>) {
9
- super({ context: { service }, ...options });
9
+ super({ context: { service }, ...options, message: `Service not available: ${service}` });
10
10
  }
11
11
  }
12
12
 
@@ -0,0 +1,48 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { Operation } from '@dxos/operation';
6
+ import * as Schema from 'effect/Schema';
7
+
8
+ export const Fibonacci = Operation.make({
9
+ meta: {
10
+ key: 'example.org/function/fib',
11
+ name: 'Fibonacci',
12
+ description: 'Function that calculates a Fibonacci number',
13
+ },
14
+ input: Schema.Struct({
15
+ iterations: Schema.optional(Schema.Number).annotations({
16
+ description: 'Number of iterations',
17
+ default: 100_000,
18
+ }),
19
+ }),
20
+ output: Schema.Struct({
21
+ result: Schema.String,
22
+ }),
23
+ });
24
+
25
+ export const Reply = Operation.make({
26
+ meta: {
27
+ key: 'example.org/function/reply',
28
+ name: 'Reply',
29
+ description: 'Function that echoes the input',
30
+ },
31
+ input: Schema.Any,
32
+ output: Schema.Any,
33
+ });
34
+
35
+ export const Sleep = Operation.make({
36
+ meta: {
37
+ key: 'example.org/function/sleep',
38
+ name: 'Sleep',
39
+ description: 'Function that sleeps for a given amount of time',
40
+ },
41
+ input: Schema.Struct({
42
+ duration: Schema.optional(Schema.Number).annotations({
43
+ description: 'Milliseconds to sleep',
44
+ default: 100_000,
45
+ }),
46
+ }),
47
+ output: Schema.Void,
48
+ });
@@ -3,30 +3,20 @@
3
3
  //
4
4
 
5
5
  import * as Effect from 'effect/Effect';
6
- import * as Schema from 'effect/Schema';
7
6
 
8
- import { defineFunction } from '../sdk';
7
+ import { Operation } from '@dxos/operation';
8
+ import { Fibonacci } from './definitions';
9
9
 
10
- export default defineFunction({
11
- key: 'example.org/function/fib',
12
- name: 'Fibonacci',
13
- description: 'Function that calculates a Fibonacci number',
14
- inputSchema: Schema.Struct({
15
- iterations: Schema.optional(Schema.Number).annotations({
16
- description: 'Number of iterations',
17
- default: 100_000,
10
+ export default Fibonacci.pipe(
11
+ Operation.withHandler(
12
+ Effect.fn(function* ({ iterations = 100_000 }) {
13
+ let a = 0n;
14
+ let b = 1n;
15
+ for (let i = 0; i < iterations; i++) {
16
+ a += b;
17
+ b = a - b;
18
+ }
19
+ return { result: a.toString() };
18
20
  }),
19
- }),
20
- outputSchema: Schema.Struct({
21
- result: Schema.String,
22
- }),
23
- handler: Effect.fn(function* ({ data: { iterations = 100_000 } }) {
24
- let a = 0n;
25
- let b = 1n;
26
- for (let i = 0; i < iterations; i++) {
27
- a += b;
28
- b = a - b;
29
- }
30
- return { result: a.toString() };
31
- }),
32
- });
21
+ ),
22
+ );
@@ -14,7 +14,7 @@ import {
14
14
  import { Effect, Schedule } from 'https://esm.sh/effect@3.17.0?bundle=false';
15
15
 
16
16
  export default defineFunction({
17
- key: 'dxos.org/script/forex-effect',
17
+ key: 'org.dxos.script.forex-effect',
18
18
  name: 'Forex Effect',
19
19
  description: 'Returns the exchange rate between two currencies.',
20
20
 
@@ -2,12 +2,11 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { default as fib$ } from './fib';
6
- import { default as reply$ } from './reply';
7
- import { default as sleep$ } from './sleep';
5
+ import { OperationHandlerSet } from '@dxos/operation';
6
+ export * from './definitions';
8
7
 
9
- export namespace Example {
10
- export const fib = fib$;
11
- export const reply = reply$;
12
- export const sleep = sleep$;
13
- }
8
+ export const ExampleHandlers = OperationHandlerSet.lazy(
9
+ () => import('./fib'),
10
+ () => import('./reply'),
11
+ () => import('./sleep'),
12
+ );
@@ -4,18 +4,15 @@
4
4
 
5
5
  import * as Console from 'effect/Console';
6
6
  import * as Effect from 'effect/Effect';
7
- import * as Schema from 'effect/Schema';
8
7
 
9
- import { defineFunction } from '../sdk';
8
+ import { Operation } from '@dxos/operation';
9
+ import { Reply } from './definitions';
10
10
 
11
- export default defineFunction({
12
- key: 'example.org/function/reply',
13
- name: 'Reply',
14
- description: 'Function that echoes the input',
15
- inputSchema: Schema.Any,
16
- outputSchema: Schema.Any,
17
- handler: Effect.fn(function* ({ data }) {
18
- yield* Console.log('reply', { data });
19
- return data;
20
- }),
21
- });
11
+ export default Reply.pipe(
12
+ Operation.withHandler(
13
+ Effect.fn(function* (input) {
14
+ yield* Console.log('reply', { input });
15
+ return input;
16
+ }),
17
+ ),
18
+ );
@@ -3,22 +3,13 @@
3
3
  //
4
4
 
5
5
  import * as Effect from 'effect/Effect';
6
- import * as Schema from 'effect/Schema';
6
+ import { Sleep } from './definitions';
7
+ import { Operation } from '@dxos/operation';
7
8
 
8
- import { defineFunction } from '../sdk';
9
-
10
- export default defineFunction({
11
- key: 'example.org/function/sleep',
12
- name: 'Sleep',
13
- description: 'Function that sleeps for a given amount of time',
14
- inputSchema: Schema.Struct({
15
- duration: Schema.optional(Schema.Number).annotations({
16
- description: 'Milliseconds to sleep',
17
- default: 100_000,
9
+ export default Sleep.pipe(
10
+ Operation.withHandler(
11
+ Effect.fn(function* ({ duration = 100_000 }) {
12
+ yield* Effect.sleep(duration);
18
13
  }),
19
- }),
20
- outputSchema: Schema.Void,
21
- handler: Effect.fn(function* ({ data: { duration = 100_000 } }) {
22
- yield* Effect.sleep(duration);
23
- }),
24
- });
14
+ ),
15
+ );
package/src/index.ts CHANGED
@@ -4,7 +4,11 @@
4
4
 
5
5
  export * from './errors';
6
6
  export * from './example';
7
+ export * as Process from './process/Process';
8
+ export * as ServiceResolver from './process/ServiceResolver';
9
+ export * from './process/StorageService';
7
10
  export * from './sdk';
8
11
  export * from './services';
9
12
  export * from './types';
10
13
  export * from './protocol';
14
+ export * as Trace from './Trace';