@dxos/functions 0.8.4-main.ae835ea → 0.8.4-main.bc674ce
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/dist/lib/browser/index.mjs +767 -884
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +767 -884
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/errors.d.ts +44 -60
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/example/fib.d.ts +1 -1
- package/dist/types/src/example/index.d.ts +3 -3
- package/dist/types/src/example/index.d.ts.map +1 -1
- package/dist/types/src/example/reply.d.ts +1 -1
- package/dist/types/src/example/sleep.d.ts +1 -1
- package/dist/types/src/index.d.ts +2 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/operation-compatibility.test.d.ts +2 -0
- package/dist/types/src/operation-compatibility.test.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 +114 -0
- package/dist/types/src/sdk.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +6 -4
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/event-logger.d.ts +33 -27
- package/dist/types/src/services/event-logger.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +7 -19
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/index.d.ts +2 -4
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +4 -4
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +41 -12
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/Function.d.ts +40 -35
- package/dist/types/src/types/Function.d.ts.map +1 -1
- package/dist/types/src/types/Script.d.ts +9 -16
- package/dist/types/src/types/Script.d.ts.map +1 -1
- package/dist/types/src/types/Trigger.d.ts +58 -76
- package/dist/types/src/types/Trigger.d.ts.map +1 -1
- package/dist/types/src/types/TriggerEvent.d.ts +43 -13
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- 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 +23 -58
- package/src/errors.ts +4 -4
- package/src/example/fib.ts +1 -1
- package/src/example/reply.ts +1 -1
- package/src/example/sleep.ts +1 -1
- package/src/index.ts +2 -5
- package/src/operation-compatibility.test.ts +185 -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 +59 -0
- package/src/protocol/protocol.ts +262 -0
- package/src/{handler.ts → sdk.ts} +129 -66
- package/src/services/credentials.ts +32 -17
- package/src/services/event-logger.ts +10 -4
- package/src/services/function-invocation-service.ts +23 -70
- package/src/services/index.ts +2 -4
- package/src/services/queues.ts +5 -7
- package/src/services/tracing.ts +68 -44
- package/src/types/Function.ts +39 -8
- package/src/types/Script.ts +10 -9
- package/src/types/Trigger.ts +18 -14
- package/src/types/TriggerEvent.ts +29 -29
- package/src/types/index.ts +1 -0
- package/src/types/url.ts +32 -0
- package/dist/lib/browser/bundler/index.mjs +0 -256
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +0 -10
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +0 -7
- package/dist/lib/browser/chunk-M6EXIREF.mjs +0 -610
- package/dist/lib/browser/chunk-M6EXIREF.mjs.map +0 -7
- package/dist/lib/browser/edge/index.mjs +0 -83
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -131
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -257
- package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-P3IATZMZ.mjs +0 -612
- package/dist/lib/node-esm/chunk-P3IATZMZ.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -84
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -132
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -49
- 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/e2e/deploy.test.d.ts +0 -2
- package/dist/types/src/e2e/deploy.test.d.ts.map +0 -1
- package/dist/types/src/edge/functions.d.ts +0 -17
- 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 -14
- 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 -102
- package/dist/types/src/handler.d.ts.map +0 -1
- package/dist/types/src/services/database.d.ts +0 -67
- package/dist/types/src/services/database.d.ts.map +0 -1
- package/dist/types/src/services/function-invocation-service.test.d.ts +0 -2
- package/dist/types/src/services/function-invocation-service.test.d.ts.map +0 -1
- package/dist/types/src/services/local-function-execution.d.ts +0 -34
- package/dist/types/src/services/local-function-execution.d.ts.map +0 -1
- package/dist/types/src/services/remote-function-execution-service.d.ts +0 -22
- package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
- package/dist/types/src/services/service-container.d.ts +0 -57
- package/dist/types/src/services/service-container.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.d.ts +0 -31
- package/dist/types/src/services/service-registry.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.test.d.ts +0 -2
- package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/layer.d.ts +0 -18
- package/dist/types/src/testing/layer.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/persist-database.test.d.ts +0 -2
- package/dist/types/src/testing/persist-database.test.d.ts.map +0 -1
- package/dist/types/src/testing/services.d.ts +0 -59
- package/dist/types/src/testing/services.d.ts.map +0 -1
- package/dist/types/src/trace.d.ts +0 -122
- 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/triggers/index.d.ts +0 -4
- package/dist/types/src/triggers/index.d.ts.map +0 -1
- package/dist/types/src/triggers/input-builder.d.ts +0 -3
- package/dist/types/src/triggers/input-builder.d.ts.map +0 -1
- package/dist/types/src/triggers/invocation-tracer.d.ts +0 -37
- package/dist/types/src/triggers/invocation-tracer.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.d.ts +0 -78
- package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.test.d.ts +0 -2
- package/dist/types/src/triggers/trigger-dispatcher.test.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-state-store.d.ts +0 -28
- package/dist/types/src/triggers/trigger-state-store.d.ts.map +0 -1
- package/dist/types/src/url.d.ts +0 -21
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -58
- package/src/bundler/bundler.ts +0 -295
- package/src/bundler/index.ts +0 -5
- package/src/e2e/deploy.test.ts +0 -69
- package/src/edge/functions.ts +0 -67
- package/src/edge/index.ts +0 -9
- package/src/executor/executor.ts +0 -58
- package/src/services/database.ts +0 -175
- package/src/services/function-invocation-service.test.ts +0 -81
- package/src/services/local-function-execution.ts +0 -153
- package/src/services/remote-function-execution-service.ts +0 -63
- package/src/services/service-container.ts +0 -115
- package/src/services/service-registry.test.ts +0 -45
- package/src/services/service-registry.ts +0 -63
- package/src/testing/index.ts +0 -6
- package/src/testing/layer.ts +0 -114
- package/src/testing/logger.ts +0 -17
- package/src/testing/persist-database.test.ts +0 -87
- package/src/testing/services.ts +0 -115
- package/src/trace.ts +0 -178
- package/src/translations.ts +0 -20
- package/src/triggers/index.ts +0 -7
- package/src/triggers/input-builder.ts +0 -35
- package/src/triggers/invocation-tracer.ts +0 -101
- package/src/triggers/trigger-dispatcher.test.ts +0 -664
- package/src/triggers/trigger-dispatcher.ts +0 -521
- package/src/triggers/trigger-state-store.ts +0 -61
- package/src/url.ts +0 -55
|
@@ -5,80 +5,33 @@ import * as Context from 'effect/Context';
|
|
|
5
5
|
import * as Effect from 'effect/Effect';
|
|
6
6
|
import * as Layer from 'effect/Layer';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import { type FunctionDefinition } from '../handler';
|
|
11
|
-
|
|
12
|
-
import { CredentialsService } from './credentials';
|
|
13
|
-
import { DatabaseService } from './database';
|
|
14
|
-
import {
|
|
15
|
-
FunctionImplementationResolver,
|
|
16
|
-
type InvocationServices,
|
|
17
|
-
LocalFunctionExecutionService,
|
|
18
|
-
} from './local-function-execution';
|
|
19
|
-
import { QueueService } from './queues';
|
|
20
|
-
import { RemoteFunctionExecutionService } from './remote-function-execution-service';
|
|
8
|
+
import type { FunctionNotFoundError } from '../errors';
|
|
9
|
+
import { type FunctionDefinition, type InvocationServices } from '../sdk';
|
|
21
10
|
|
|
22
11
|
export class FunctionInvocationService extends Context.Tag('@dxos/functions/FunctionInvocationService')<
|
|
23
12
|
FunctionInvocationService,
|
|
24
13
|
{
|
|
25
|
-
invokeFunction<I, O>(
|
|
14
|
+
invokeFunction<I, O>(
|
|
15
|
+
functionDef: FunctionDefinition<I, O, any>,
|
|
16
|
+
input: I,
|
|
17
|
+
): Effect.Effect<O, never, InvocationServices>;
|
|
18
|
+
|
|
19
|
+
resolveFunction(key: string): Effect.Effect<FunctionDefinition.Any, FunctionNotFoundError>;
|
|
26
20
|
}
|
|
27
21
|
>() {
|
|
28
|
-
static
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return yield* remoteExecutioner.callFunction<I, O>(functionDef.meta.deployedFunctionId, input);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return yield* localExecutioner.invokeFunction(functionDef, input);
|
|
47
|
-
}),
|
|
48
|
-
} satisfies Context.Tag.Service<FunctionInvocationService>;
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
// TODO(dmaretskyi): Don't provide `FunctionImplementationResolver`.
|
|
53
|
-
static layerTest = ({
|
|
54
|
-
functions = [],
|
|
55
|
-
}: {
|
|
56
|
-
functions?: readonly FunctionDefinition<any, any>[];
|
|
57
|
-
} = {}): Layer.Layer<
|
|
58
|
-
FunctionInvocationService,
|
|
59
|
-
never,
|
|
60
|
-
AiService.AiService | CredentialsService | DatabaseService | QueueService
|
|
61
|
-
> =>
|
|
62
|
-
FunctionInvocationService.layer.pipe(
|
|
63
|
-
Layer.provide(LocalFunctionExecutionService.layerLive),
|
|
64
|
-
Layer.provide(FunctionImplementationResolver.layerTest({ functions })),
|
|
65
|
-
Layer.provide(RemoteFunctionExecutionService.layerMock),
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
// TODO(dmaretskyi): This shouldn't default to all services being not available.
|
|
69
|
-
// TODO(dmaretskyi): Don't provide `FunctionImplementationResolver`.
|
|
70
|
-
/**
|
|
71
|
-
* @deprecated Use {@link layerTest} instead.
|
|
72
|
-
*/
|
|
73
|
-
static layerTestMocked = ({
|
|
74
|
-
functions,
|
|
75
|
-
}: {
|
|
76
|
-
functions?: readonly FunctionDefinition<any, any>[];
|
|
77
|
-
}): Layer.Layer<FunctionInvocationService> =>
|
|
78
|
-
FunctionInvocationService.layerTest({ functions }).pipe(
|
|
79
|
-
Layer.provide(AiService.notAvailable),
|
|
80
|
-
Layer.provide(CredentialsService.configuredLayer([])),
|
|
81
|
-
Layer.provide(DatabaseService.notAvailable),
|
|
82
|
-
Layer.provide(QueueService.notAvailable),
|
|
83
|
-
);
|
|
22
|
+
static layerNotAvailable = Layer.succeed(FunctionInvocationService, {
|
|
23
|
+
invokeFunction: () => Effect.die('FunctionInvocationService is not avaialble.'),
|
|
24
|
+
resolveFunction: () => Effect.die('FunctionInvocationService is not available.'),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
static invokeFunction = <I, O>(
|
|
28
|
+
functionDef: FunctionDefinition<I, O, any>,
|
|
29
|
+
input: I,
|
|
30
|
+
): Effect.Effect<O, never, FunctionInvocationService | InvocationServices> =>
|
|
31
|
+
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.invokeFunction)(functionDef, input);
|
|
32
|
+
|
|
33
|
+
static resolveFunction = (
|
|
34
|
+
key: string,
|
|
35
|
+
): Effect.Effect<FunctionDefinition.Any, FunctionNotFoundError, FunctionInvocationService> =>
|
|
36
|
+
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.resolveFunction)(key);
|
|
84
37
|
}
|
package/src/services/index.ts
CHANGED
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
export * from './credentials';
|
|
6
|
-
export
|
|
6
|
+
export { ConfiguredCredentialsService, type ServiceCredential } from './credentials';
|
|
7
7
|
export * from './event-logger';
|
|
8
|
+
export { createEventLogger, createDefectLogger } from './event-logger';
|
|
8
9
|
export * from './function-invocation-service';
|
|
9
|
-
export * from './local-function-execution';
|
|
10
10
|
export * from './queues';
|
|
11
|
-
export * from './service-container';
|
|
12
11
|
export * from './tracing';
|
|
13
|
-
export * from './remote-function-execution-service';
|
package/src/services/queues.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as Context from 'effect/Context';
|
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
7
|
import * as Layer from 'effect/Layer';
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { Entity } from '@dxos/echo';
|
|
10
10
|
import type { Queue, QueueAPI, QueueFactory } from '@dxos/echo-db';
|
|
11
11
|
import type { DXN, QueueSubspaceTag } from '@dxos/keys';
|
|
12
12
|
|
|
@@ -53,22 +53,20 @@ export class QueueService extends Context.Tag('@dxos/functions/QueueService')<
|
|
|
53
53
|
/**
|
|
54
54
|
* Gets a queue by its DXN.
|
|
55
55
|
*/
|
|
56
|
-
static getQueue = <T extends
|
|
56
|
+
static getQueue = <T extends Entity.Unknown = Entity.Unknown>(
|
|
57
57
|
dxn: DXN,
|
|
58
58
|
): Effect.Effect<Queue<T>, never, QueueService> => QueueService.pipe(Effect.map(({ queues }) => queues.get<T>(dxn)));
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* Creates a new queue.
|
|
62
62
|
*/
|
|
63
|
-
static createQueue = <T extends
|
|
63
|
+
static createQueue = <T extends Entity.Unknown = Entity.Unknown>(options?: {
|
|
64
64
|
subspaceTag?: QueueSubspaceTag;
|
|
65
65
|
}): Effect.Effect<Queue<T>, never, QueueService> =>
|
|
66
66
|
QueueService.pipe(Effect.map(({ queues }) => queues.create<T>(options)));
|
|
67
67
|
|
|
68
|
-
static append = <T extends
|
|
69
|
-
queue
|
|
70
|
-
objects: T[],
|
|
71
|
-
): Effect.Effect<void> => Effect.promise(() => queue.append(objects));
|
|
68
|
+
static append = <T extends Entity.Unknown = Entity.Unknown>(queue: Queue<T>, objects: T[]): Effect.Effect<void> =>
|
|
69
|
+
Effect.promise(() => queue.append(objects));
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
/**
|
package/src/services/tracing.ts
CHANGED
|
@@ -7,11 +7,11 @@ import * as Effect from 'effect/Effect';
|
|
|
7
7
|
import * as Layer from 'effect/Layer';
|
|
8
8
|
|
|
9
9
|
import { AgentStatus } from '@dxos/ai';
|
|
10
|
-
import { Obj } from '@dxos/echo';
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
import {
|
|
10
|
+
import { type DXN, Obj } from '@dxos/echo';
|
|
11
|
+
import { ObjectId } from '@dxos/keys';
|
|
12
|
+
import { Message } from '@dxos/types';
|
|
13
|
+
|
|
14
|
+
import type { Trigger } from '../types';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Provides a way for compute primitives (functions, workflows, tools)
|
|
@@ -29,31 +29,34 @@ export class TracingService extends Context.Tag('@dxos/functions/TracingService'
|
|
|
29
29
|
* Write an event to the tracing queue.
|
|
30
30
|
* @param event - The event to write. Must be an a typed object.
|
|
31
31
|
*/
|
|
32
|
-
write: (event: Obj.
|
|
32
|
+
write: (event: Obj.Unknown, traceContext: TracingService.TraceContext) => void;
|
|
33
|
+
|
|
34
|
+
traceInvocationStart({
|
|
35
|
+
payload,
|
|
36
|
+
target,
|
|
37
|
+
}: {
|
|
38
|
+
payload: TracingService.FunctionInvocationPayload;
|
|
39
|
+
target?: DXN;
|
|
40
|
+
}): Effect.Effect<TracingService.InvocationTraceData>;
|
|
41
|
+
|
|
42
|
+
traceInvocationEnd({
|
|
43
|
+
trace,
|
|
44
|
+
exception,
|
|
45
|
+
}: {
|
|
46
|
+
trace: TracingService.InvocationTraceData;
|
|
47
|
+
exception?: any;
|
|
48
|
+
}): Effect.Effect<void>;
|
|
33
49
|
}
|
|
34
50
|
>() {
|
|
35
|
-
static noop: Context.Tag.Service<TracingService> = {
|
|
36
|
-
|
|
37
|
-
static layerNoop = Layer.succeed(TracingService, TracingService.noop);
|
|
38
|
-
|
|
39
|
-
static console: Context.Tag.Service<TracingService> = {
|
|
40
|
-
write: (event) => {
|
|
41
|
-
console.log(event);
|
|
42
|
-
},
|
|
51
|
+
static noop: Context.Tag.Service<TracingService> = {
|
|
43
52
|
getTraceContext: () => ({}),
|
|
53
|
+
write: () => {},
|
|
54
|
+
traceInvocationStart: () =>
|
|
55
|
+
Effect.sync(() => ({ invocationId: ObjectId.random(), invocationTraceQueue: undefined })),
|
|
56
|
+
traceInvocationEnd: () => Effect.sync(() => {}),
|
|
44
57
|
};
|
|
45
58
|
|
|
46
|
-
static
|
|
47
|
-
|
|
48
|
-
static layerLogInfo = () =>
|
|
49
|
-
Layer.succeed(TracingService, {
|
|
50
|
-
write: (event) => {
|
|
51
|
-
if (Obj.instanceOf(AgentStatus, event)) {
|
|
52
|
-
log.info('status', { message: event.message });
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
getTraceContext: () => ({}),
|
|
56
|
-
});
|
|
59
|
+
static layerNoop: Layer.Layer<TracingService> = Layer.succeed(TracingService, TracingService.noop);
|
|
57
60
|
|
|
58
61
|
/**
|
|
59
62
|
* Creates a TracingService layer that emits events to the parent tracing service.
|
|
@@ -65,27 +68,24 @@ export class TracingService extends Context.Tag('@dxos/functions/TracingService'
|
|
|
65
68
|
const tracing = yield* TracingService;
|
|
66
69
|
const context = mapContext(tracing.getTraceContext());
|
|
67
70
|
return {
|
|
68
|
-
write: (event) => tracing.write(event),
|
|
71
|
+
write: (event, context) => tracing.write(event, context),
|
|
69
72
|
getTraceContext: () => context,
|
|
73
|
+
traceInvocationStart: () => Effect.die('Tracing invocation inside another invocation is not supported.'),
|
|
74
|
+
traceInvocationEnd: () => Effect.die('Tracing invocation inside another invocation is not supported.'),
|
|
70
75
|
};
|
|
71
76
|
}),
|
|
72
77
|
);
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
}),
|
|
86
|
-
};
|
|
87
|
-
}),
|
|
88
|
-
);
|
|
79
|
+
/**
|
|
80
|
+
* Create sublayer to trace an invocation.
|
|
81
|
+
* @param data
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
static layerInvocation = (data: TracingService.InvocationTraceData) =>
|
|
85
|
+
TracingService.layerSubframe((context) => ({
|
|
86
|
+
...context,
|
|
87
|
+
currentInvocation: data,
|
|
88
|
+
}));
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* Emit the current human-readable execution status.
|
|
@@ -101,15 +101,16 @@ export class TracingService extends Context.Tag('@dxos/functions/TracingService'
|
|
|
101
101
|
created: new Date().toISOString(),
|
|
102
102
|
...data,
|
|
103
103
|
}),
|
|
104
|
+
tracing.getTraceContext(),
|
|
104
105
|
);
|
|
105
106
|
});
|
|
106
107
|
|
|
107
108
|
static emitConverationMessage: (
|
|
108
|
-
data: Obj.MakeProps<typeof
|
|
109
|
+
data: Obj.MakeProps<typeof Message.Message>,
|
|
109
110
|
) => Effect.Effect<void, never, TracingService> = Effect.fnUntraced(function* (data) {
|
|
110
111
|
const tracing = yield* TracingService;
|
|
111
112
|
tracing.write(
|
|
112
|
-
Obj.make(
|
|
113
|
+
Obj.make(Message.Message, {
|
|
113
114
|
parentMessage: tracing.getTraceContext().parentMessage,
|
|
114
115
|
...data,
|
|
115
116
|
properties: {
|
|
@@ -117,12 +118,15 @@ export class TracingService extends Context.Tag('@dxos/functions/TracingService'
|
|
|
117
118
|
...data.properties,
|
|
118
119
|
},
|
|
119
120
|
}),
|
|
121
|
+
tracing.getTraceContext(),
|
|
120
122
|
);
|
|
121
123
|
});
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
export namespace TracingService {
|
|
125
127
|
export interface TraceContext {
|
|
128
|
+
currentInvocation?: InvocationTraceData;
|
|
129
|
+
|
|
126
130
|
/**
|
|
127
131
|
* If this thread sprung from a tool call, this is the ID of the message containing the tool call.
|
|
128
132
|
*/
|
|
@@ -135,9 +139,29 @@ export namespace TracingService {
|
|
|
135
139
|
|
|
136
140
|
debugInfo?: unknown;
|
|
137
141
|
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Trace data for a function/trigger invocation.
|
|
145
|
+
*/
|
|
146
|
+
export interface InvocationTraceData {
|
|
147
|
+
invocationId: ObjectId;
|
|
148
|
+
invocationTraceQueue?: DXN.String;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Payload for a function/trigger invocation.
|
|
153
|
+
*/
|
|
154
|
+
export interface FunctionInvocationPayload {
|
|
155
|
+
data?: any;
|
|
156
|
+
inputNodeId?: string;
|
|
157
|
+
trigger?: {
|
|
158
|
+
id: string;
|
|
159
|
+
kind: Trigger.Kind;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
138
162
|
}
|
|
139
163
|
|
|
140
164
|
/**
|
|
141
|
-
* Goes into {@link
|
|
165
|
+
* Goes into {@link Message['properties']}
|
|
142
166
|
*/
|
|
143
167
|
export const MESSAGE_PROPERTY_TOOL_CALL_ID = 'toolCallId' as const;
|
package/src/types/Function.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { Obj, Type } from '@dxos/echo';
|
|
8
|
-
import {
|
|
7
|
+
import { Annotation, JsonSchema, Obj, Type } from '@dxos/echo';
|
|
8
|
+
import { SystemTypeAnnotation } from '@dxos/echo/internal';
|
|
9
9
|
|
|
10
10
|
import { Script } from './Script';
|
|
11
11
|
|
|
@@ -24,28 +24,59 @@ export const Function = Schema.Struct({
|
|
|
24
24
|
description: 'Unique registration key for the blueprint',
|
|
25
25
|
}),
|
|
26
26
|
|
|
27
|
-
// TODO(burdon): Rename to id/uri?
|
|
28
27
|
name: Schema.NonEmptyString,
|
|
29
28
|
version: Schema.String,
|
|
30
29
|
|
|
31
30
|
description: Schema.optional(Schema.String),
|
|
32
31
|
|
|
32
|
+
/**
|
|
33
|
+
* ISO date string of the last deployment.
|
|
34
|
+
*/
|
|
35
|
+
updated: Schema.optional(Schema.String),
|
|
36
|
+
|
|
33
37
|
// Reference to a source script if it exists within ECHO.
|
|
34
38
|
// TODO(burdon): Don't ref ScriptType directly (core).
|
|
35
|
-
source: Schema.optional(Ref(Script)),
|
|
39
|
+
source: Schema.optional(Type.Ref(Script)),
|
|
36
40
|
|
|
37
|
-
inputSchema: Schema.optional(
|
|
38
|
-
outputSchema: Schema.optional(
|
|
41
|
+
inputSchema: Schema.optional(JsonSchema.JsonSchema),
|
|
42
|
+
outputSchema: Schema.optional(JsonSchema.JsonSchema),
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* List of required services.
|
|
46
|
+
* Match the Context.Tag keys of the FunctionServices variants.
|
|
47
|
+
*/
|
|
48
|
+
services: Schema.optional(Schema.Array(Schema.String)),
|
|
39
49
|
|
|
40
50
|
// Local binding to a function name.
|
|
41
51
|
binding: Schema.optional(Schema.String),
|
|
42
52
|
}).pipe(
|
|
43
|
-
Type.
|
|
53
|
+
Type.object({
|
|
44
54
|
typename: 'dxos.org/type/Function',
|
|
45
55
|
version: '0.1.0',
|
|
46
56
|
}),
|
|
47
|
-
LabelAnnotation.set(['name']),
|
|
57
|
+
Annotation.LabelAnnotation.set(['name']),
|
|
58
|
+
SystemTypeAnnotation.set(true),
|
|
48
59
|
);
|
|
60
|
+
|
|
49
61
|
export interface Function extends Schema.Schema.Type<typeof Function> {}
|
|
50
62
|
|
|
51
63
|
export const make = (props: Obj.MakeProps<typeof Function>) => Obj.make(Function, props);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Copies properties from source to target.
|
|
67
|
+
* @param target - Target object to copy properties to.
|
|
68
|
+
* @param source - Source object to copy properties from.
|
|
69
|
+
*/
|
|
70
|
+
export const setFrom = (target: Function, source: Function) => {
|
|
71
|
+
Obj.change(target, (t) => {
|
|
72
|
+
t.key = source.key ?? target.key;
|
|
73
|
+
t.name = source.name ?? target.name;
|
|
74
|
+
t.version = source.version;
|
|
75
|
+
t.description = source.description;
|
|
76
|
+
t.updated = source.updated;
|
|
77
|
+
// TODO(dmaretskyi): A workaround for an ECHO bug.
|
|
78
|
+
t.inputSchema = source.inputSchema ? JSON.parse(JSON.stringify(source.inputSchema)) : undefined;
|
|
79
|
+
t.outputSchema = source.outputSchema ? JSON.parse(JSON.stringify(source.outputSchema)) : undefined;
|
|
80
|
+
Obj.getMeta(t).keys = JSON.parse(JSON.stringify(Obj.getMeta(source).keys));
|
|
81
|
+
});
|
|
82
|
+
};
|
package/src/types/Script.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { Obj, Ref, Type } from '@dxos/echo';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { Annotation, Obj, Ref, Type } from '@dxos/echo';
|
|
8
|
+
import { FormInputAnnotation } from '@dxos/echo/internal';
|
|
9
|
+
import { Text } from '@dxos/schema';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Source script.
|
|
@@ -16,18 +16,19 @@ export const Script = Schema.Struct({
|
|
|
16
16
|
description: Schema.String.pipe(Schema.optional),
|
|
17
17
|
// TODO(burdon): Change to hash of deployed content.
|
|
18
18
|
// Whether source has changed since last deploy.
|
|
19
|
-
changed: Schema.Boolean.pipe(
|
|
20
|
-
source: Type.Ref(
|
|
19
|
+
changed: Schema.Boolean.pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
20
|
+
source: Type.Ref(Text.Text).pipe(FormInputAnnotation.set(false)),
|
|
21
21
|
}).pipe(
|
|
22
|
-
Type.
|
|
22
|
+
Type.object({
|
|
23
23
|
typename: 'dxos.org/type/Script',
|
|
24
24
|
version: '0.1.0',
|
|
25
25
|
}),
|
|
26
|
-
LabelAnnotation.set(['name']),
|
|
26
|
+
Annotation.LabelAnnotation.set(['name']),
|
|
27
27
|
);
|
|
28
|
+
|
|
28
29
|
export interface Script extends Schema.Schema.Type<typeof Script> {}
|
|
29
30
|
|
|
30
31
|
type Props = Omit<Obj.MakeProps<typeof Script>, 'source'> & { source?: string };
|
|
31
32
|
|
|
32
|
-
export const make = ({ source = '', ...props }: Props = {}) =>
|
|
33
|
-
Obj.make(Script, { ...props, source: Ref.make(
|
|
33
|
+
export const make = ({ source = '', ...props }: Props = {}): Script =>
|
|
34
|
+
Obj.make(Script, { ...props, source: Ref.make(Text.make(source)) });
|
package/src/types/Trigger.ts
CHANGED
|
@@ -6,8 +6,9 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
7
|
|
|
8
8
|
import { Obj, QueryAST, Type } from '@dxos/echo';
|
|
9
|
-
import {
|
|
9
|
+
import { OptionsAnnotationId, SystemTypeAnnotation } from '@dxos/echo/internal';
|
|
10
10
|
import { DXN } from '@dxos/keys';
|
|
11
|
+
import { Expando } from '@dxos/schema';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Type discriminator for TriggerType.
|
|
@@ -21,7 +22,7 @@ const kindLiteralAnnotations = { title: 'Kind' };
|
|
|
21
22
|
|
|
22
23
|
export const EmailSpec = Schema.Struct({
|
|
23
24
|
kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
|
|
24
|
-
})
|
|
25
|
+
});
|
|
25
26
|
export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
|
|
26
27
|
|
|
27
28
|
export const QueueSpec = Schema.Struct({
|
|
@@ -29,7 +30,7 @@ export const QueueSpec = Schema.Struct({
|
|
|
29
30
|
|
|
30
31
|
// TODO(dmaretskyi): Change to a reference.
|
|
31
32
|
queue: DXN.Schema,
|
|
32
|
-
})
|
|
33
|
+
});
|
|
33
34
|
export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
|
|
34
35
|
|
|
35
36
|
/**
|
|
@@ -40,7 +41,7 @@ export const SubscriptionSpec = Schema.Struct({
|
|
|
40
41
|
query: Schema.Struct({
|
|
41
42
|
raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
|
|
42
43
|
ast: QueryAST.Query,
|
|
43
|
-
})
|
|
44
|
+
}),
|
|
44
45
|
options: Schema.optional(
|
|
45
46
|
Schema.Struct({
|
|
46
47
|
// Watch changes to object (not just creation).
|
|
@@ -49,7 +50,7 @@ export const SubscriptionSpec = Schema.Struct({
|
|
|
49
50
|
delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
|
|
50
51
|
}).annotations({ title: 'Options' }),
|
|
51
52
|
),
|
|
52
|
-
})
|
|
53
|
+
});
|
|
53
54
|
export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
|
|
54
55
|
|
|
55
56
|
/**
|
|
@@ -61,7 +62,7 @@ export const TimerSpec = Schema.Struct({
|
|
|
61
62
|
title: 'Cron',
|
|
62
63
|
[SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
|
|
63
64
|
}),
|
|
64
|
-
})
|
|
65
|
+
});
|
|
65
66
|
export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
|
|
66
67
|
|
|
67
68
|
/**
|
|
@@ -80,7 +81,7 @@ export const WebhookSpec = Schema.Struct({
|
|
|
80
81
|
title: 'Port',
|
|
81
82
|
}),
|
|
82
83
|
),
|
|
83
|
-
})
|
|
84
|
+
});
|
|
84
85
|
export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
|
|
85
86
|
|
|
86
87
|
/**
|
|
@@ -96,12 +97,12 @@ export type Spec = Schema.Schema.Type<typeof Spec>;
|
|
|
96
97
|
* Function is invoked with the `payload` passed as input data.
|
|
97
98
|
* The event that triggers the function is available in the function context.
|
|
98
99
|
*/
|
|
99
|
-
const
|
|
100
|
+
const TriggerSchema = Schema.Struct({
|
|
100
101
|
/**
|
|
101
102
|
* Function or workflow to invoke.
|
|
102
103
|
*/
|
|
103
104
|
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
104
|
-
function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
|
|
105
|
+
function: Schema.optional(Type.Ref(Expando.Expando).annotations({ title: 'Function' })),
|
|
105
106
|
|
|
106
107
|
/**
|
|
107
108
|
* Only used for workflowSchema.
|
|
@@ -110,6 +111,8 @@ const Trigger_ = Schema.Struct({
|
|
|
110
111
|
*/
|
|
111
112
|
inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
|
|
112
113
|
|
|
114
|
+
// TODO(burdon): NO BOOLEAN PROPERTIES (enabld/disabled/paused, etc.)
|
|
115
|
+
// Need lint rule; or agent rule to require PR review for "boolean" key word.
|
|
113
116
|
enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
|
|
114
117
|
|
|
115
118
|
spec: Schema.optional(Spec),
|
|
@@ -125,15 +128,16 @@ const Trigger_ = Schema.Struct({
|
|
|
125
128
|
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
126
129
|
* }
|
|
127
130
|
*/
|
|
128
|
-
input: Schema.optional(Schema.
|
|
131
|
+
input: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
129
132
|
}).pipe(
|
|
130
|
-
Type.
|
|
133
|
+
Type.object({
|
|
131
134
|
typename: 'dxos.org/type/Trigger',
|
|
132
135
|
version: '0.1.0',
|
|
133
136
|
}),
|
|
137
|
+
SystemTypeAnnotation.set(true),
|
|
134
138
|
);
|
|
135
|
-
|
|
136
|
-
export interface
|
|
137
|
-
export const Trigger:
|
|
139
|
+
|
|
140
|
+
export interface Trigger extends Schema.Schema.Type<typeof TriggerSchema> {}
|
|
141
|
+
export const Trigger: Type.Obj<Trigger> = TriggerSchema as any;
|
|
138
142
|
|
|
139
143
|
export const make = (props: Obj.MakeProps<typeof Trigger>) => Obj.make(Trigger, props);
|
|
@@ -4,29 +4,28 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { DXN,
|
|
7
|
+
import { DXN, Type } from '@dxos/echo';
|
|
8
8
|
|
|
9
|
-
|
|
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.
|
|
10
13
|
|
|
11
14
|
// TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
|
|
12
|
-
export const EmailEvent = Schema.
|
|
13
|
-
Schema.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}),
|
|
20
|
-
);
|
|
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
|
+
});
|
|
21
22
|
export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
|
|
22
23
|
|
|
23
|
-
export const QueueEvent = Schema.
|
|
24
|
-
Schema
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}),
|
|
29
|
-
);
|
|
24
|
+
export const QueueEvent = Schema.Struct({
|
|
25
|
+
queue: DXN.Schema,
|
|
26
|
+
item: Schema.Any,
|
|
27
|
+
cursor: Schema.String,
|
|
28
|
+
});
|
|
30
29
|
export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
|
|
31
30
|
|
|
32
31
|
export const SubscriptionEvent = Schema.Struct({
|
|
@@ -39,24 +38,25 @@ export const SubscriptionEvent = Schema.Struct({
|
|
|
39
38
|
/**
|
|
40
39
|
* Reference to the object that was changed or created.
|
|
41
40
|
*/
|
|
42
|
-
subject: Type.Ref(Obj
|
|
41
|
+
subject: Type.Ref(Type.Obj),
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
* @deprecated
|
|
46
45
|
*/
|
|
47
46
|
changedObjectId: Schema.optional(Schema.String),
|
|
48
|
-
})
|
|
47
|
+
});
|
|
49
48
|
export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
|
|
50
49
|
|
|
51
|
-
export const TimerEvent = Schema.
|
|
50
|
+
export const TimerEvent = Schema.Struct({ tick: Schema.Number });
|
|
52
51
|
export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
|
|
53
52
|
|
|
54
|
-
export const WebhookEvent = Schema.
|
|
55
|
-
Schema.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}),
|
|
61
|
-
);
|
|
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
|
+
});
|
|
62
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/index.ts
CHANGED