@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.
- package/README.md +4 -6
- package/dist/lib/neutral/Trace.mjs +34 -0
- package/dist/lib/neutral/Trace.mjs.map +7 -0
- package/dist/lib/neutral/chunk-BHLSCAA2.mjs +123 -0
- package/dist/lib/neutral/chunk-BHLSCAA2.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-Z2XDJJVH.mjs +49 -0
- package/dist/lib/neutral/chunk-Z2XDJJVH.mjs.map +7 -0
- package/dist/lib/neutral/fib-S6PPI4UW.mjs +23 -0
- package/dist/lib/neutral/fib-S6PPI4UW.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/index.mjs +649 -633
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/reply-TOHXEG7V.mjs +19 -0
- package/dist/lib/neutral/reply-TOHXEG7V.mjs.map +7 -0
- package/dist/lib/neutral/sleep-QPSZDPEH.mjs +15 -0
- package/dist/lib/neutral/sleep-QPSZDPEH.mjs.map +7 -0
- package/dist/types/src/Trace.d.ts +135 -0
- package/dist/types/src/Trace.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/example/definitions.d.ts +11 -0
- package/dist/types/src/example/definitions.d.ts.map +1 -0
- package/dist/types/src/example/fib.d.ts +3 -2
- package/dist/types/src/example/fib.d.ts.map +1 -1
- package/dist/types/src/example/index.d.ts +3 -11
- package/dist/types/src/example/index.d.ts.map +1 -1
- package/dist/types/src/example/reply.d.ts +2 -1
- package/dist/types/src/example/reply.d.ts.map +1 -1
- package/dist/types/src/example/sleep.d.ts +3 -2
- package/dist/types/src/example/sleep.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/process/Process.d.ts +247 -0
- package/dist/types/src/process/Process.d.ts.map +1 -0
- package/dist/types/src/process/ServiceResolver.d.ts +74 -0
- package/dist/types/src/process/ServiceResolver.d.ts.map +1 -0
- package/dist/types/src/process/StorageService.d.ts +58 -0
- package/dist/types/src/process/StorageService.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.d.ts +2 -2
- package/dist/types/src/protocol/protocol.d.ts.map +1 -1
- package/dist/types/src/sdk.d.ts +4 -104
- package/dist/types/src/sdk.d.ts.map +1 -1
- package/dist/types/src/services/event-logger.d.ts +4 -4
- package/dist/types/src/services/function-invocation-service.d.ts +6 -5
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +4 -2
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +25 -2
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/Script.d.ts +4 -3
- package/dist/types/src/types/Script.d.ts.map +1 -1
- package/dist/types/src/types/Trigger.d.ts +8 -9
- package/dist/types/src/types/Trigger.d.ts.map +1 -1
- package/dist/types/src/types/TriggerEvent.d.ts +3 -2
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +0 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/url.d.ts +2 -2
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -20
- package/src/Trace.ts +162 -0
- package/src/errors.ts +1 -1
- package/src/example/definitions.ts +48 -0
- package/src/example/fib.ts +14 -24
- package/src/example/forex-effect.ts +1 -1
- package/src/example/index.ts +7 -8
- package/src/example/reply.ts +10 -13
- package/src/example/sleep.ts +8 -17
- package/src/index.ts +4 -0
- package/src/process/Process.ts +457 -0
- package/src/process/ServiceResolver.ts +173 -0
- package/src/process/StorageService.ts +99 -0
- package/src/protocol/protocol.ts +33 -27
- package/src/sdk.ts +6 -256
- package/src/services/event-logger.ts +1 -1
- package/src/services/function-invocation-service.ts +6 -5
- package/src/services/queues.ts +10 -2
- package/src/services/tracing.ts +35 -2
- package/src/types/Script.ts +7 -3
- package/src/types/Trigger.ts +17 -6
- package/src/types/TriggerEvent.ts +2 -2
- package/src/types/index.ts +0 -1
- package/src/types/url.ts +2 -2
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -1230
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/types/src/operation-compatibility.test.d.ts +0 -2
- package/dist/types/src/operation-compatibility.test.d.ts.map +0 -1
- package/dist/types/src/types/Function.d.ts +0 -52
- package/dist/types/src/types/Function.d.ts.map +0 -1
- package/src/operation-compatibility.test.ts +0 -185
- 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.
|
|
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
|
-
"
|
|
20
|
-
|
|
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/
|
|
31
|
-
"@effect/
|
|
32
|
-
"effect": "
|
|
33
|
-
"
|
|
34
|
-
"@dxos/ai": "0.8.4-main.
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/echo-db": "0.8.4-main.
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/errors": "0.8.4-main.
|
|
39
|
-
"@dxos/keys": "0.8.4-main.
|
|
40
|
-
"@dxos/invariant": "0.8.4-main.
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/types": "0.8.4-main.
|
|
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
|
+
});
|
package/src/example/fib.ts
CHANGED
|
@@ -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 {
|
|
7
|
+
import { Operation } from '@dxos/operation';
|
|
8
|
+
import { Fibonacci } from './definitions';
|
|
9
9
|
|
|
10
|
-
export default
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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.
|
|
17
|
+
key: 'org.dxos.script.forex-effect',
|
|
18
18
|
name: 'Forex Effect',
|
|
19
19
|
description: 'Returns the exchange rate between two currencies.',
|
|
20
20
|
|
package/src/example/index.ts
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { default as sleep$ } from './sleep';
|
|
5
|
+
import { OperationHandlerSet } from '@dxos/operation';
|
|
6
|
+
export * from './definitions';
|
|
8
7
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export const ExampleHandlers = OperationHandlerSet.lazy(
|
|
9
|
+
() => import('./fib'),
|
|
10
|
+
() => import('./reply'),
|
|
11
|
+
() => import('./sleep'),
|
|
12
|
+
);
|
package/src/example/reply.ts
CHANGED
|
@@ -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 {
|
|
8
|
+
import { Operation } from '@dxos/operation';
|
|
9
|
+
import { Reply } from './definitions';
|
|
10
10
|
|
|
11
|
-
export default
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
);
|
package/src/example/sleep.ts
CHANGED
|
@@ -3,22 +3,13 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import * as Effect from 'effect/Effect';
|
|
6
|
-
import
|
|
6
|
+
import { Sleep } from './definitions';
|
|
7
|
+
import { Operation } from '@dxos/operation';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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';
|