@dxos/functions 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5
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 +42 -0
- package/dist/lib/neutral/Trace.mjs.map +7 -0
- package/dist/lib/neutral/chunk-27Y24OTY.mjs +167 -0
- package/dist/lib/neutral/chunk-27Y24OTY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-IVDUS56O.mjs +49 -0
- package/dist/lib/neutral/chunk-IVDUS56O.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/fib-N45KAC7C.mjs +23 -0
- package/dist/lib/neutral/fib-N45KAC7C.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1218 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/reply-EUEPKNJF.mjs +19 -0
- package/dist/lib/neutral/reply-EUEPKNJF.mjs.map +7 -0
- package/dist/lib/neutral/sleep-PUK3D4FF.mjs +15 -0
- package/dist/lib/neutral/sleep-PUK3D4FF.mjs.map +7 -0
- package/dist/types/src/Trace.d.ts +174 -0
- package/dist/types/src/Trace.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +121 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- 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 +8 -0
- package/dist/types/src/example/fib.d.ts.map +1 -0
- package/dist/types/src/example/forex-effect.d.ts +3 -0
- package/dist/types/src/example/forex-effect.d.ts.map +1 -0
- package/dist/types/src/example/index.d.ts +4 -0
- package/dist/types/src/example/index.d.ts.map +1 -0
- package/dist/types/src/example/reply.d.ts +4 -0
- package/dist/types/src/example/reply.d.ts.map +1 -0
- package/dist/types/src/example/sleep.d.ts +6 -0
- package/dist/types/src/example/sleep.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +9 -6
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/process/Process.d.ts +246 -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/functions-ai-http-client.d.ts +12 -0
- package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
- package/dist/types/src/protocol/index.d.ts +2 -0
- package/dist/types/src/protocol/index.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.d.ts +7 -0
- package/dist/types/src/protocol/protocol.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.test.d.ts +2 -0
- package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
- package/dist/types/src/sdk.d.ts +11 -0
- package/dist/types/src/sdk.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +23 -3
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/event-logger.d.ts +70 -30
- package/dist/types/src/services/event-logger.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +16 -0
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
- package/dist/types/src/services/index.d.ts +5 -7
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +37 -5
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +4 -14
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/Script.d.ts +22 -0
- package/dist/types/src/types/Script.d.ts.map +1 -0
- package/dist/types/src/types/Trigger.d.ts +150 -0
- package/dist/types/src/types/Trigger.d.ts.map +1 -0
- package/dist/types/src/types/TriggerEvent.d.ts +75 -0
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +5 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/url.d.ts +13 -0
- package/dist/types/src/types/url.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -67
- package/src/Trace.ts +225 -0
- package/src/errors.ts +21 -0
- package/src/example/definitions.ts +49 -0
- package/src/example/fib.ts +23 -0
- package/src/example/forex-effect.ts +40 -0
- package/src/example/index.ts +12 -0
- package/src/example/reply.ts +19 -0
- package/src/example/sleep.ts +17 -0
- package/src/index.ts +9 -8
- package/src/process/Process.ts +487 -0
- package/src/process/ServiceResolver.ts +174 -0
- package/src/process/StorageService.ts +99 -0
- package/src/protocol/functions-ai-http-client.ts +67 -0
- package/src/{executor → protocol}/index.ts +1 -1
- package/src/protocol/protocol.test.ts +58 -0
- package/src/protocol/protocol.ts +273 -0
- package/src/sdk.ts +30 -0
- package/src/services/credentials.ts +108 -4
- package/src/services/event-logger.ts +61 -37
- package/src/services/function-invocation-service.ts +35 -0
- package/src/services/index.ts +5 -7
- package/src/services/queues.ts +58 -9
- package/src/services/tracing.ts +4 -23
- package/src/types/Script.ts +38 -0
- package/src/types/Trigger.ts +207 -0
- package/src/types/TriggerEvent.ts +62 -0
- package/src/types/index.ts +8 -0
- package/src/types/url.ts +32 -0
- package/dist/lib/browser/bundler/index.mjs +0 -247
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-54U464M4.mjs +0 -360
- package/dist/lib/browser/chunk-54U464M4.mjs.map +0 -7
- package/dist/lib/browser/edge/index.mjs +0 -69
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -492
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs +0 -79
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -249
- package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XDSX35BS.mjs +0 -362
- package/dist/lib/node-esm/chunk-XDSX35BS.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -71
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -493
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -80
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -50
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/edge/functions.d.ts +0 -16
- package/dist/types/src/edge/functions.d.ts.map +0 -1
- package/dist/types/src/edge/index.d.ts +0 -2
- package/dist/types/src/edge/index.d.ts.map +0 -1
- package/dist/types/src/executor/executor.d.ts +0 -8
- package/dist/types/src/executor/executor.d.ts.map +0 -1
- package/dist/types/src/executor/index.d.ts +0 -2
- package/dist/types/src/executor/index.d.ts.map +0 -1
- package/dist/types/src/handler.d.ts +0 -61
- package/dist/types/src/handler.d.ts.map +0 -1
- package/dist/types/src/schema.d.ts +0 -38
- package/dist/types/src/schema.d.ts.map +0 -1
- package/dist/types/src/services/ai.d.ts +0 -12
- package/dist/types/src/services/ai.d.ts.map +0 -1
- package/dist/types/src/services/database.d.ts +0 -15
- package/dist/types/src/services/database.d.ts.map +0 -1
- package/dist/types/src/services/function-call-service.d.ts +0 -16
- package/dist/types/src/services/function-call-service.d.ts.map +0 -1
- package/dist/types/src/services/service-container.d.ts +0 -46
- package/dist/types/src/services/service-container.d.ts.map +0 -1
- package/dist/types/src/services/tool-resolver.d.ts +0 -14
- package/dist/types/src/services/tool-resolver.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/logger.d.ts +0 -5
- package/dist/types/src/testing/logger.d.ts.map +0 -1
- package/dist/types/src/testing/services.d.ts +0 -71
- package/dist/types/src/testing/services.d.ts.map +0 -1
- package/dist/types/src/trace.d.ts +0 -124
- package/dist/types/src/trace.d.ts.map +0 -1
- package/dist/types/src/translations.d.ts +0 -12
- package/dist/types/src/translations.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -411
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/types/src/url.d.ts +0 -17
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -59
- package/src/bundler/bundler.ts +0 -292
- package/src/bundler/index.ts +0 -5
- package/src/edge/functions.ts +0 -64
- package/src/edge/index.ts +0 -9
- package/src/executor/executor.ts +0 -54
- package/src/handler.ts +0 -113
- package/src/schema.ts +0 -57
- package/src/services/ai.ts +0 -32
- package/src/services/database.ts +0 -50
- package/src/services/function-call-service.ts +0 -64
- package/src/services/service-container.ts +0 -127
- package/src/services/tool-resolver.ts +0 -31
- package/src/testing/index.ts +0 -5
- package/src/testing/logger.ts +0 -16
- package/src/testing/services.ts +0 -174
- package/src/trace.ts +0 -180
- package/src/translations.ts +0 -20
- package/src/types.ts +0 -211
- package/src/url.ts +0 -52
|
@@ -2,53 +2,74 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
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 { Type } from '@dxos/echo';
|
|
7
11
|
import { invariant } from '@dxos/invariant';
|
|
8
|
-
import {
|
|
12
|
+
import { LogLevel, log } from '@dxos/log';
|
|
9
13
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
14
|
+
export const ComputeEventPayload = Schema.Union(
|
|
15
|
+
Schema.Struct({
|
|
16
|
+
type: Schema.Literal('begin-compute'),
|
|
17
|
+
nodeId: Schema.String,
|
|
18
|
+
/**
|
|
19
|
+
* Names of the inputs begin computed.
|
|
20
|
+
*/
|
|
21
|
+
inputs: Schema.Array(Schema.String),
|
|
22
|
+
}),
|
|
23
|
+
Schema.Struct({
|
|
24
|
+
type: Schema.Literal('end-compute'),
|
|
25
|
+
nodeId: Schema.String,
|
|
26
|
+
/**
|
|
27
|
+
* Names of the outputs computed.
|
|
28
|
+
*/
|
|
29
|
+
outputs: Schema.Array(Schema.String),
|
|
30
|
+
}),
|
|
31
|
+
Schema.Struct({
|
|
32
|
+
type: Schema.Literal('compute-input'),
|
|
33
|
+
nodeId: Schema.String,
|
|
34
|
+
property: Schema.String,
|
|
35
|
+
value: Schema.Any,
|
|
36
|
+
}),
|
|
37
|
+
Schema.Struct({
|
|
38
|
+
type: Schema.Literal('compute-output'),
|
|
39
|
+
nodeId: Schema.String,
|
|
40
|
+
property: Schema.String,
|
|
41
|
+
value: Schema.Any,
|
|
42
|
+
}),
|
|
43
|
+
Schema.Struct({
|
|
44
|
+
type: Schema.Literal('custom'),
|
|
45
|
+
nodeId: Schema.String,
|
|
46
|
+
event: Schema.Any,
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
export type ComputeEventPayload = Schema.Schema.Type<typeof ComputeEventPayload>;
|
|
50
|
+
|
|
51
|
+
export const ComputeEvent = Schema.Struct({
|
|
52
|
+
payload: ComputeEventPayload,
|
|
53
|
+
}).pipe(Type.object({ typename: 'org.dxos.type.computeEvent', version: '0.1.0' }));
|
|
38
54
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Logs event for the compute workflows.
|
|
57
|
+
*/
|
|
58
|
+
export class ComputeEventLogger extends Context.Tag('@dxos/functions/ComputeEventLogger')<
|
|
59
|
+
ComputeEventLogger,
|
|
60
|
+
{ readonly log: (event: ComputeEventPayload) => void; readonly nodeId: string | undefined }
|
|
42
61
|
>() {
|
|
43
|
-
static noop: Context.Tag.Service<
|
|
62
|
+
static noop: Context.Tag.Service<ComputeEventLogger> = {
|
|
44
63
|
log: () => {},
|
|
45
64
|
nodeId: undefined,
|
|
46
65
|
};
|
|
66
|
+
|
|
67
|
+
static layerNoop: Layer.Layer<ComputeEventLogger> = Layer.succeed(ComputeEventLogger, ComputeEventLogger.noop);
|
|
47
68
|
}
|
|
48
69
|
|
|
49
70
|
export const logCustomEvent = (data: any) =>
|
|
50
71
|
Effect.gen(function* () {
|
|
51
|
-
const logger = yield*
|
|
72
|
+
const logger = yield* ComputeEventLogger;
|
|
52
73
|
if (!logger.nodeId) {
|
|
53
74
|
throw new Error('logCustomEvent must be called within a node compute function');
|
|
54
75
|
}
|
|
@@ -67,7 +88,10 @@ export const createDefectLogger = <A, E, R>(): ((self: Effect.Effect<A, E, R>) =
|
|
|
67
88
|
}),
|
|
68
89
|
);
|
|
69
90
|
|
|
70
|
-
export const createEventLogger = (
|
|
91
|
+
export const createEventLogger = (
|
|
92
|
+
level: LogLevel,
|
|
93
|
+
message: string = 'event',
|
|
94
|
+
): Context.Tag.Service<ComputeEventLogger> => {
|
|
71
95
|
const logFunction = (
|
|
72
96
|
{
|
|
73
97
|
[LogLevel.WARN]: log.warn,
|
|
@@ -79,7 +103,7 @@ export const createEventLogger = (level: LogLevel, message: string = 'event'): C
|
|
|
79
103
|
)[level];
|
|
80
104
|
invariant(logFunction);
|
|
81
105
|
return {
|
|
82
|
-
log: (event:
|
|
106
|
+
log: (event: ComputeEventPayload) => {
|
|
83
107
|
logFunction(message, event);
|
|
84
108
|
},
|
|
85
109
|
nodeId: undefined,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
import * as Context from 'effect/Context';
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as Layer from 'effect/Layer';
|
|
7
|
+
|
|
8
|
+
import { Operation } from '@dxos/operation';
|
|
9
|
+
|
|
10
|
+
import type { FunctionNotFoundError } from '../errors';
|
|
11
|
+
|
|
12
|
+
export class FunctionInvocationService extends Context.Tag('@dxos/functions/FunctionInvocationService')<
|
|
13
|
+
FunctionInvocationService,
|
|
14
|
+
{
|
|
15
|
+
invokeFunction<I, O>(functionDef: Operation.Definition<I, O, any>, input: I): Effect.Effect<O>;
|
|
16
|
+
|
|
17
|
+
resolveFunction(key: string): Effect.Effect<Operation.Definition.Any, FunctionNotFoundError>;
|
|
18
|
+
}
|
|
19
|
+
>() {
|
|
20
|
+
static layerNotAvailable = Layer.succeed(FunctionInvocationService, {
|
|
21
|
+
invokeFunction: () => Effect.die('FunctionInvocationService is not avaialble.'),
|
|
22
|
+
resolveFunction: () => Effect.die('FunctionInvocationService is not available.'),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
static invokeFunction = <I, O>(
|
|
26
|
+
functionDef: Operation.Definition<I, O, any>,
|
|
27
|
+
input: I,
|
|
28
|
+
): Effect.Effect<O, never, FunctionInvocationService> =>
|
|
29
|
+
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.invokeFunction)(functionDef, input);
|
|
30
|
+
|
|
31
|
+
static resolveFunction = (
|
|
32
|
+
key: string,
|
|
33
|
+
): Effect.Effect<Operation.Definition.Any, FunctionNotFoundError, FunctionInvocationService> =>
|
|
34
|
+
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.resolveFunction)(key);
|
|
35
|
+
}
|
package/src/services/index.ts
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './ai';
|
|
6
|
-
export * from './database';
|
|
7
|
-
export * from './queues';
|
|
8
|
-
export * from './service-container';
|
|
9
5
|
export * from './credentials';
|
|
10
|
-
export
|
|
6
|
+
export { ConfiguredCredentialsService, type ServiceCredential } from './credentials';
|
|
11
7
|
export * from './event-logger';
|
|
12
|
-
export
|
|
13
|
-
export * from './
|
|
8
|
+
export { createEventLogger, createDefectLogger } from './event-logger';
|
|
9
|
+
export * from './function-invocation-service';
|
|
10
|
+
export * from './queues';
|
|
11
|
+
export { MESSAGE_PROPERTY_TOOL_CALL_ID } from './tracing';
|
package/src/services/queues.ts
CHANGED
|
@@ -2,11 +2,19 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Context from 'effect/Context';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Layer from 'effect/Layer';
|
|
6
8
|
|
|
7
|
-
import
|
|
9
|
+
import { type Entity } from '@dxos/echo';
|
|
10
|
+
import { createFeedServiceLayer, type Queue, type QueueAPI, type QueueFactory } from '@dxos/echo-db';
|
|
11
|
+
import type { DXN, QueueSubspaceTag } from '@dxos/keys';
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Gives access to all queues.
|
|
15
|
+
* @deprecated Use Feed.FeedService instead.
|
|
16
|
+
*/
|
|
17
|
+
export class QueueService extends Context.Tag('@dxos/functions/QueueService')<
|
|
10
18
|
QueueService,
|
|
11
19
|
{
|
|
12
20
|
/**
|
|
@@ -16,27 +24,68 @@ export class QueueService extends Context.Tag('QueueService')<
|
|
|
16
24
|
|
|
17
25
|
/**
|
|
18
26
|
* The queue that is used to store the context of the current research.
|
|
27
|
+
* @deprecated Use `ContextQueueService` instead.
|
|
19
28
|
*/
|
|
20
|
-
|
|
21
|
-
readonly contextQueue: Queue | undefined;
|
|
29
|
+
readonly queue: Queue | undefined;
|
|
22
30
|
}
|
|
23
31
|
>() {
|
|
24
32
|
static notAvailable = Layer.succeed(QueueService, {
|
|
25
33
|
queues: {
|
|
26
|
-
get(
|
|
34
|
+
get(_dxn) {
|
|
27
35
|
throw new Error('Queues not available');
|
|
28
36
|
},
|
|
29
37
|
create() {
|
|
30
38
|
throw new Error('Queues not available');
|
|
31
39
|
},
|
|
32
40
|
},
|
|
33
|
-
|
|
41
|
+
queue: undefined,
|
|
34
42
|
});
|
|
35
43
|
|
|
36
|
-
static make = (queues: QueueFactory,
|
|
44
|
+
static make = (queues: QueueFactory, queue?: Queue): Context.Tag.Service<QueueService> => {
|
|
37
45
|
return {
|
|
38
46
|
queues,
|
|
39
|
-
|
|
47
|
+
queue,
|
|
40
48
|
};
|
|
41
49
|
};
|
|
50
|
+
|
|
51
|
+
static layer = (queues: QueueFactory, queue?: Queue): Layer.Layer<QueueService> =>
|
|
52
|
+
Layer.succeed(QueueService, QueueService.make(queues, queue));
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Gets a queue by its DXN.
|
|
56
|
+
*/
|
|
57
|
+
static getQueue = <T extends Entity.Unknown = Entity.Unknown>(
|
|
58
|
+
dxn: DXN,
|
|
59
|
+
): Effect.Effect<Queue<T>, never, QueueService> => QueueService.pipe(Effect.map(({ queues }) => queues.get<T>(dxn)));
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new queue.
|
|
63
|
+
*/
|
|
64
|
+
static createQueue = <T extends Entity.Unknown = Entity.Unknown>(options?: {
|
|
65
|
+
subspaceTag?: QueueSubspaceTag;
|
|
66
|
+
}): Effect.Effect<Queue<T>, never, QueueService> =>
|
|
67
|
+
QueueService.pipe(Effect.map(({ queues }) => queues.create<T>(options)));
|
|
68
|
+
|
|
69
|
+
static append = <T extends Entity.Unknown = Entity.Unknown>(queue: Queue<T>, objects: T[]): Effect.Effect<void> =>
|
|
70
|
+
Effect.promise(() => queue.append(objects));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gives access to a specific queue passed as a context.
|
|
75
|
+
* @deprecated Use Feed.FeedService instead.
|
|
76
|
+
*/
|
|
77
|
+
export class ContextQueueService extends Context.Tag('@dxos/functions/ContextQueueService')<
|
|
78
|
+
ContextQueueService,
|
|
79
|
+
{
|
|
80
|
+
readonly queue: Queue;
|
|
81
|
+
}
|
|
82
|
+
>() {
|
|
83
|
+
static layer = (queue: Queue) => Layer.succeed(ContextQueueService, { queue });
|
|
42
84
|
}
|
|
85
|
+
|
|
86
|
+
export const feedServiceFromQueueServiceLayer = Layer.unwrapEffect(
|
|
87
|
+
Effect.gen(function* () {
|
|
88
|
+
const { queues } = yield* QueueService;
|
|
89
|
+
return createFeedServiceLayer(queues);
|
|
90
|
+
}),
|
|
91
|
+
);
|
package/src/services/tracing.ts
CHANGED
|
@@ -2,26 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export class TracingService extends Context.Tag('TracingService')<
|
|
10
|
-
TracingService,
|
|
11
|
-
{
|
|
12
|
-
/**
|
|
13
|
-
* Write an event to the tracing queue.
|
|
14
|
-
* @param event - The event to write. Must be an a typed object.
|
|
15
|
-
*/
|
|
16
|
-
write(event: AnyEchoObject): void;
|
|
17
|
-
}
|
|
18
|
-
>() {
|
|
19
|
-
static noop: Context.Tag.Service<TracingService> = { write: () => {} };
|
|
20
|
-
|
|
21
|
-
static console: Context.Tag.Service<TracingService> = {
|
|
22
|
-
write: (event) => {
|
|
23
|
-
// eslint-disable-next-line no-console
|
|
24
|
-
console.log(event);
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
5
|
+
/**
|
|
6
|
+
* Goes into {@link Message['properties']}
|
|
7
|
+
*/
|
|
8
|
+
export const MESSAGE_PROPERTY_TOOL_CALL_ID = 'toolCallId' as const;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { Annotation, Obj, Ref, Type } from '@dxos/echo';
|
|
8
|
+
import { FormInputAnnotation } 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(FormInputAnnotation.set(false), Schema.optional),
|
|
20
|
+
source: Ref.Ref(Text.Text).pipe(FormInputAnnotation.set(false)),
|
|
21
|
+
}).pipe(
|
|
22
|
+
Type.object({
|
|
23
|
+
typename: 'org.dxos.type.script',
|
|
24
|
+
version: '0.1.0',
|
|
25
|
+
}),
|
|
26
|
+
Annotation.LabelAnnotation.set(['name']),
|
|
27
|
+
Annotation.IconAnnotation.set({
|
|
28
|
+
icon: 'ph--code--regular',
|
|
29
|
+
hue: 'sky',
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export interface Script extends Schema.Schema.Type<typeof Script> {}
|
|
34
|
+
|
|
35
|
+
type Props = Omit<Obj.MakeProps<typeof Script>, 'source'> & { source?: string };
|
|
36
|
+
|
|
37
|
+
export const make = ({ source = '', ...props }: Props = {}): Script =>
|
|
38
|
+
Obj.make(Script, { ...props, source: Ref.make(Text.make({ content: source })) });
|
|
@@ -0,0 +1,207 @@
|
|
|
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 { Annotation, Feed, Obj, QueryAST, Ref, Type, type Query } from '@dxos/echo';
|
|
9
|
+
import { OptionsAnnotationId, SystemTypeAnnotation } from '@dxos/echo/internal';
|
|
10
|
+
import { failedInvariant } from '@dxos/invariant';
|
|
11
|
+
import { DXN } from '@dxos/keys';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Type discriminator for TriggerType.
|
|
15
|
+
* Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
|
|
16
|
+
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
|
|
17
|
+
*/
|
|
18
|
+
export const Kinds = ['email', 'queue', 'subscription', 'timer', 'webhook'] as const;
|
|
19
|
+
export type Kind = (typeof Kinds)[number];
|
|
20
|
+
|
|
21
|
+
const kindLiteralAnnotations = { title: 'Kind' };
|
|
22
|
+
|
|
23
|
+
export const EmailSpec = Schema.Struct({
|
|
24
|
+
kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
|
|
25
|
+
});
|
|
26
|
+
export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Construct an Email trigger spec.
|
|
30
|
+
*/
|
|
31
|
+
export const specEmail = (): EmailSpec => ({ kind: 'email' });
|
|
32
|
+
|
|
33
|
+
// TODO(burdon): Change to Feed.
|
|
34
|
+
// TODO(wittjosiah): Remove. Migrate to Subscription triggers once EDGE supports them for feed queries.
|
|
35
|
+
export const QueueSpec = Schema.Struct({
|
|
36
|
+
kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
|
|
37
|
+
|
|
38
|
+
// TODO(dmaretskyi): Rename to `feed` and change to a reference.
|
|
39
|
+
queue: DXN.Schema,
|
|
40
|
+
});
|
|
41
|
+
export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Construct a Queue trigger spec from a queue DXN string.
|
|
45
|
+
*/
|
|
46
|
+
export const specQueue = (queueDxn: string): QueueSpec => ({
|
|
47
|
+
kind: 'queue',
|
|
48
|
+
queue: queueDxn,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Construct a Queue trigger spec from a Feed object.
|
|
53
|
+
*/
|
|
54
|
+
export const specFeed = (feed: Feed.Feed): QueueSpec =>
|
|
55
|
+
specQueue(Feed.getQueueDxn(feed)?.toString() ?? failedInvariant(new Error('Could not extract DXN from feed')));
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Subscription.
|
|
59
|
+
*/
|
|
60
|
+
export const SubscriptionSpec = Schema.Struct({
|
|
61
|
+
kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
|
|
62
|
+
query: Schema.Struct({
|
|
63
|
+
raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
|
|
64
|
+
ast: QueryAST.Query,
|
|
65
|
+
}),
|
|
66
|
+
options: Schema.optional(
|
|
67
|
+
Schema.Struct({
|
|
68
|
+
// Watch changes to object (not just creation).
|
|
69
|
+
deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
|
|
70
|
+
// Debounce changes (delay in ms).
|
|
71
|
+
delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
|
|
72
|
+
}).annotations({ title: 'Options' }),
|
|
73
|
+
),
|
|
74
|
+
});
|
|
75
|
+
export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Construct a Subscription trigger spec from a Query object.
|
|
79
|
+
*/
|
|
80
|
+
export const specSubscription = (
|
|
81
|
+
query: Query.Query<any>,
|
|
82
|
+
options?: { deep?: boolean; delay?: number },
|
|
83
|
+
): SubscriptionSpec => ({
|
|
84
|
+
kind: 'subscription',
|
|
85
|
+
query: {
|
|
86
|
+
ast: query.ast,
|
|
87
|
+
},
|
|
88
|
+
options: options
|
|
89
|
+
? {
|
|
90
|
+
deep: options.deep,
|
|
91
|
+
delay: options.delay,
|
|
92
|
+
}
|
|
93
|
+
: undefined,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Cron timer.
|
|
98
|
+
*/
|
|
99
|
+
export const TimerSpec = Schema.Struct({
|
|
100
|
+
kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
|
|
101
|
+
cron: Schema.String.annotations({
|
|
102
|
+
title: 'Cron',
|
|
103
|
+
[SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Construct a Timer trigger spec from a cron string.
|
|
110
|
+
*/
|
|
111
|
+
export const specTimer = (cron: string): TimerSpec => ({ kind: 'timer', cron });
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Webhook.
|
|
115
|
+
*/
|
|
116
|
+
export const WebhookSpec = Schema.Struct({
|
|
117
|
+
kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
|
|
118
|
+
method: Schema.optional(
|
|
119
|
+
Schema.String.annotations({
|
|
120
|
+
title: 'Method',
|
|
121
|
+
[OptionsAnnotationId]: ['GET', 'POST'],
|
|
122
|
+
}),
|
|
123
|
+
),
|
|
124
|
+
port: Schema.optional(
|
|
125
|
+
Schema.Number.annotations({
|
|
126
|
+
title: 'Port',
|
|
127
|
+
}),
|
|
128
|
+
),
|
|
129
|
+
});
|
|
130
|
+
export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Construct a Webhook trigger spec from a method and port.
|
|
134
|
+
*/
|
|
135
|
+
export const specWebhook = (opts?: { method?: string; port?: number }): WebhookSpec => ({
|
|
136
|
+
kind: 'webhook',
|
|
137
|
+
method: opts?.method,
|
|
138
|
+
port: opts?.port,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Trigger schema.
|
|
143
|
+
*/
|
|
144
|
+
export const Spec = Schema.Union(EmailSpec, QueueSpec, SubscriptionSpec, TimerSpec, WebhookSpec).annotations({
|
|
145
|
+
title: 'Trigger',
|
|
146
|
+
});
|
|
147
|
+
export type Spec = Schema.Schema.Type<typeof Spec>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Function trigger.
|
|
151
|
+
* Function is invoked with the `payload` passed as input data.
|
|
152
|
+
* The event that triggers the function is available in the function context.
|
|
153
|
+
*/
|
|
154
|
+
const TriggerSchema = Schema.Struct({
|
|
155
|
+
/**
|
|
156
|
+
* Function or workflow to invoke.
|
|
157
|
+
*/
|
|
158
|
+
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
159
|
+
function: Schema.optional(Ref.Ref(Obj.Unknown).annotations({ title: 'Function' })),
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Only used for workflowSchema.
|
|
163
|
+
* Specifies the input node in the circuit.
|
|
164
|
+
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
165
|
+
*/
|
|
166
|
+
inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
|
|
167
|
+
|
|
168
|
+
// TODO(burdon): NO BOOLEAN PROPERTIES (enabld/disabled/paused, etc.)
|
|
169
|
+
// Need lint rule; or agent rule to require PR review for "boolean" key word.
|
|
170
|
+
enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
|
|
171
|
+
|
|
172
|
+
spec: Schema.optional(Spec),
|
|
173
|
+
|
|
174
|
+
concurrency: Schema.optional(
|
|
175
|
+
Schema.Number.annotations({
|
|
176
|
+
title: 'Concurrency',
|
|
177
|
+
default: 1,
|
|
178
|
+
description:
|
|
179
|
+
'Maximum number of concurrent invocations of the trigger. For Feed triggers, this will process Feed items in parallel.',
|
|
180
|
+
}),
|
|
181
|
+
),
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Passed as the input data to the function.
|
|
185
|
+
* Must match the function's input schema.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* {
|
|
189
|
+
* item: '{{event.item}}',
|
|
190
|
+
* instructions: 'Summarize and perform entity-extraction'
|
|
191
|
+
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
192
|
+
* }
|
|
193
|
+
*/
|
|
194
|
+
input: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
195
|
+
}).pipe(
|
|
196
|
+
Type.object({
|
|
197
|
+
typename: 'org.dxos.type.trigger',
|
|
198
|
+
version: '0.1.0',
|
|
199
|
+
}),
|
|
200
|
+
Annotation.IconAnnotation.set({ icon: 'ph--lightning--regular', hue: 'yellow' }),
|
|
201
|
+
SystemTypeAnnotation.set(true),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
export interface Trigger extends Schema.Schema.Type<typeof TriggerSchema> {}
|
|
205
|
+
export const Trigger: Type.Obj<Trigger> = TriggerSchema as any;
|
|
206
|
+
|
|
207
|
+
export const make = (props: Obj.MakeProps<typeof Trigger>) => Obj.make(Trigger, props);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { DXN, Obj, Ref } from '@dxos/echo';
|
|
8
|
+
|
|
9
|
+
// TODO(wittjosiah): Review this type.
|
|
10
|
+
// - Should be discriminated union.
|
|
11
|
+
// - Should be more consistent (e.g. subject vs item).
|
|
12
|
+
// - Should re-use schemas if possible.
|
|
13
|
+
|
|
14
|
+
// TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
|
|
15
|
+
export const EmailEvent = Schema.Struct({
|
|
16
|
+
from: Schema.String,
|
|
17
|
+
to: Schema.String,
|
|
18
|
+
subject: Schema.String,
|
|
19
|
+
created: Schema.String,
|
|
20
|
+
body: Schema.String,
|
|
21
|
+
});
|
|
22
|
+
export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
|
|
23
|
+
|
|
24
|
+
export const QueueEvent = Schema.Struct({
|
|
25
|
+
queue: DXN.Schema,
|
|
26
|
+
item: Schema.Any,
|
|
27
|
+
cursor: Schema.String,
|
|
28
|
+
});
|
|
29
|
+
export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
|
|
30
|
+
|
|
31
|
+
export const SubscriptionEvent = Schema.Struct({
|
|
32
|
+
/**
|
|
33
|
+
* Type of the mutation.
|
|
34
|
+
*/
|
|
35
|
+
// TODO(dmaretskyi): Specify enum.
|
|
36
|
+
type: Schema.String,
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Reference to the object that was changed or created.
|
|
40
|
+
*/
|
|
41
|
+
subject: Ref.Ref(Obj.Unknown),
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated
|
|
45
|
+
*/
|
|
46
|
+
changedObjectId: Schema.optional(Schema.String),
|
|
47
|
+
});
|
|
48
|
+
export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
|
|
49
|
+
|
|
50
|
+
export const TimerEvent = Schema.Struct({ tick: Schema.Number });
|
|
51
|
+
export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
|
|
52
|
+
|
|
53
|
+
export const WebhookEvent = Schema.Struct({
|
|
54
|
+
url: Schema.String,
|
|
55
|
+
method: Schema.Literal('GET', 'POST'),
|
|
56
|
+
headers: Schema.Record({ key: Schema.String, value: Schema.String }),
|
|
57
|
+
bodyText: Schema.String,
|
|
58
|
+
});
|
|
59
|
+
export type WebhookEvent = Schema.Schema.Type<typeof WebhookEvent>;
|
|
60
|
+
|
|
61
|
+
export const TriggerEvent = Schema.Union(EmailEvent, QueueEvent, SubscriptionEvent, TimerEvent, WebhookEvent);
|
|
62
|
+
export type TriggerEvent = Schema.Schema.Type<typeof TriggerEvent>;
|
package/src/types/url.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Obj } from '@dxos/echo';
|
|
6
|
+
|
|
7
|
+
// TODO: use URL scheme for source?
|
|
8
|
+
export const FUNCTIONS_META_KEY = 'org.dxos.service.function';
|
|
9
|
+
|
|
10
|
+
export const FUNCTIONS_PRESET_META_KEY = 'org.dxos.service.function-preset';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* NOTE: functionId is backend ID, not ECHO object id.
|
|
14
|
+
*/
|
|
15
|
+
export const getUserFunctionIdInMetadata = (meta: Obj.ReadonlyMeta) => {
|
|
16
|
+
return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* NOTE: functionId is backend ID, not ECHO object id.
|
|
21
|
+
* Must be called inside Obj.changeMeta() since it mutates the meta.
|
|
22
|
+
*/
|
|
23
|
+
export const setUserFunctionIdInMetadata = (meta: Obj.Meta, functionId: string) => {
|
|
24
|
+
const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
|
|
25
|
+
if (key) {
|
|
26
|
+
if (key.id !== functionId) {
|
|
27
|
+
throw new Error('Metadata mismatch');
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionId });
|
|
31
|
+
}
|
|
32
|
+
};
|