@dxos/functions 0.8.4-main.e098934 → 0.8.4-main.e8ec1fe
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 +714 -1062
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +714 -1062
- 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 +28 -36
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/{examples → example}/fib.d.ts +1 -1
- 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 +12 -0
- package/dist/types/src/example/index.d.ts.map +1 -0
- package/dist/types/src/{examples → example}/reply.d.ts +1 -1
- package/dist/types/src/example/reply.d.ts.map +1 -0
- package/dist/types/src/{examples → example}/sleep.d.ts +1 -1
- package/dist/types/src/example/sleep.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -8
- package/dist/types/src/index.d.ts.map +1 -1
- 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 +89 -0
- package/dist/types/src/sdk.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +7 -3
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/event-logger.d.ts +20 -5
- package/dist/types/src/services/event-logger.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +11 -0
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
- package/dist/types/src/services/index.d.ts +6 -6
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +3 -1
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +9 -12
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/Function.d.ts +58 -0
- package/dist/types/src/types/Function.d.ts.map +1 -0
- package/dist/types/src/types/Script.d.ts +28 -0
- package/dist/types/src/types/Script.d.ts.map +1 -0
- package/dist/types/src/types/Trigger.d.ts +139 -0
- package/dist/types/src/types/Trigger.d.ts.map +1 -0
- package/dist/types/src/types/TriggerEvent.d.ts +44 -0
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +6 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/{url.d.ts → types/url.d.ts} +1 -10
- package/dist/types/src/types/url.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -70
- package/src/{examples → example}/fib.ts +5 -3
- package/src/example/forex-effect.ts +40 -0
- package/src/example/index.ts +13 -0
- package/src/{examples → example}/reply.ts +6 -3
- package/src/{examples → example}/sleep.ts +5 -3
- package/src/index.ts +4 -8
- package/src/{executor → protocol}/index.ts +1 -1
- package/src/protocol/protocol.test.ts +59 -0
- package/src/protocol/protocol.ts +145 -0
- package/src/sdk.ts +226 -0
- package/src/services/credentials.ts +12 -6
- package/src/services/event-logger.ts +12 -3
- package/src/services/function-invocation-service.ts +23 -0
- package/src/services/index.ts +7 -6
- package/src/services/queues.ts +3 -1
- package/src/services/tracing.ts +24 -56
- package/src/{schema.ts → types/Function.ts} +20 -26
- package/src/types/Script.ts +33 -0
- package/src/types/Trigger.ts +139 -0
- package/src/types/TriggerEvent.ts +62 -0
- package/src/types/index.ts +9 -0
- package/src/types/url.ts +31 -0
- package/dist/lib/browser/bundler/index.mjs +0 -265
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-D2XO7XXY.mjs +0 -611
- package/dist/lib/browser/chunk-D2XO7XXY.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/edge/index.mjs +0 -83
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -129
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -266
- 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-Z4CJ62WS.mjs +0 -613
- package/dist/lib/node-esm/chunk-Z4CJ62WS.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 -130
- 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/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/examples/fib.d.ts.map +0 -1
- package/dist/types/src/examples/index.d.ts +0 -4
- package/dist/types/src/examples/index.d.ts.map +0 -1
- package/dist/types/src/examples/reply.d.ts.map +0 -1
- package/dist/types/src/examples/sleep.d.ts.map +0 -1
- package/dist/types/src/executor/executor.d.ts +0 -11
- 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 -94
- package/dist/types/src/handler.d.ts.map +0 -1
- package/dist/types/src/schema.d.ts +0 -43
- package/dist/types/src/schema.d.ts.map +0 -1
- package/dist/types/src/services/database.d.ts +0 -63
- package/dist/types/src/services/database.d.ts.map +0 -1
- package/dist/types/src/services/local-function-execution.d.ts +0 -25
- 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 -15
- package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
- package/dist/types/src/services/service-container.d.ts +0 -56
- package/dist/types/src/services/service-container.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.d.ts +0 -29
- 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 -15
- 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 -35
- package/dist/types/src/triggers/invocation-tracer.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.d.ts +0 -75
- 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 -27
- package/dist/types/src/triggers/trigger-state-store.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -211
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -58
- package/src/bundler/bundler.ts +0 -291
- package/src/bundler/index.ts +0 -5
- package/src/edge/functions.ts +0 -67
- package/src/edge/index.ts +0 -9
- package/src/examples/index.ts +0 -7
- package/src/executor/executor.ts +0 -54
- package/src/handler.ts +0 -201
- package/src/services/database.ts +0 -171
- package/src/services/local-function-execution.ts +0 -114
- package/src/services/remote-function-execution-service.ts +0 -46
- package/src/services/service-container.ts +0 -114
- package/src/services/service-registry.test.ts +0 -42
- package/src/services/service-registry.ts +0 -59
- package/src/testing/index.ts +0 -6
- package/src/testing/layer.ts +0 -111
- package/src/testing/logger.ts +0 -16
- 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 -99
- package/src/triggers/trigger-dispatcher.test.ts +0 -652
- package/src/triggers/trigger-dispatcher.ts +0 -512
- package/src/triggers/trigger-state-store.ts +0 -60
- package/src/types.ts +0 -200
- package/src/url.ts +0 -55
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import * as HttpClient from '@effect/platform/HttpClient';
|
|
6
|
+
import * as HttpClientRequest from '@effect/platform/HttpClientRequest';
|
|
7
|
+
import type * as Config from 'effect/Config';
|
|
8
|
+
import * as Context from 'effect/Context';
|
|
9
|
+
import * as Effect from 'effect/Effect';
|
|
10
|
+
import * as Layer from 'effect/Layer';
|
|
11
|
+
import * as Redacted from 'effect/Redacted';
|
|
7
12
|
|
|
8
13
|
import { Query } from '@dxos/echo';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { DatabaseService } from './database';
|
|
14
|
+
import { DatabaseService } from '@dxos/echo-db';
|
|
15
|
+
import { AccessToken } from '@dxos/types';
|
|
12
16
|
|
|
13
17
|
export type CredentialQuery = {
|
|
14
18
|
service?: string;
|
|
@@ -79,7 +83,7 @@ export class CredentialsService extends Context.Tag('@dxos/functions/Credentials
|
|
|
79
83
|
Effect.gen(function* () {
|
|
80
84
|
const dbService = yield* DatabaseService;
|
|
81
85
|
const queryCredentials = async (query: CredentialQuery): Promise<ServiceCredential[]> => {
|
|
82
|
-
const { objects: accessTokens } = await dbService.db.query(Query.type(
|
|
86
|
+
const { objects: accessTokens } = await dbService.db.query(Query.type(AccessToken.AccessToken)).run();
|
|
83
87
|
return accessTokens
|
|
84
88
|
.filter((accessToken) => accessToken.source === query.service)
|
|
85
89
|
.map((accessToken) => ({
|
|
@@ -93,6 +97,7 @@ export class CredentialsService extends Context.Tag('@dxos/functions/Credentials
|
|
|
93
97
|
if (credentials.length === 0) {
|
|
94
98
|
throw new Error(`Credential not found for service: ${query.service}`);
|
|
95
99
|
}
|
|
100
|
+
|
|
96
101
|
return credentials[0];
|
|
97
102
|
},
|
|
98
103
|
queryCredentials: async (query) => {
|
|
@@ -120,6 +125,7 @@ export class ConfiguredCredentialsService implements Context.Tag.Service<Credent
|
|
|
120
125
|
if (!credential) {
|
|
121
126
|
throw new Error(`Credential not found for service: ${query.service}`);
|
|
122
127
|
}
|
|
128
|
+
|
|
123
129
|
return credential;
|
|
124
130
|
}
|
|
125
131
|
}
|
|
@@ -2,7 +2,10 @@
|
|
|
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
|
|
|
7
10
|
import { Obj, Type } from '@dxos/echo';
|
|
8
11
|
import { invariant } from '@dxos/invariant';
|
|
@@ -14,12 +17,18 @@ export const ComputeEventPayload = Schema.Union(
|
|
|
14
17
|
Schema.Struct({
|
|
15
18
|
type: Schema.Literal('begin-compute'),
|
|
16
19
|
nodeId: Schema.String,
|
|
17
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Names of the inputs begin computed.
|
|
22
|
+
*/
|
|
23
|
+
inputs: Schema.Array(Schema.String),
|
|
18
24
|
}),
|
|
19
25
|
Schema.Struct({
|
|
20
26
|
type: Schema.Literal('end-compute'),
|
|
21
27
|
nodeId: Schema.String,
|
|
22
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Names of the outputs computed.
|
|
30
|
+
*/
|
|
31
|
+
outputs: Schema.Array(Schema.String),
|
|
23
32
|
}),
|
|
24
33
|
Schema.Struct({
|
|
25
34
|
type: Schema.Literal('compute-input'),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
import * as Context from 'effect/Context';
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { type FunctionDefinition, type InvocationServices } from '../sdk';
|
|
8
|
+
|
|
9
|
+
export class FunctionInvocationService extends Context.Tag('@dxos/functions/FunctionInvocationService')<
|
|
10
|
+
FunctionInvocationService,
|
|
11
|
+
{
|
|
12
|
+
invokeFunction<I, O>(
|
|
13
|
+
functionDef: FunctionDefinition<I, O, any>,
|
|
14
|
+
input: I,
|
|
15
|
+
): Effect.Effect<O, never, InvocationServices>;
|
|
16
|
+
}
|
|
17
|
+
>() {
|
|
18
|
+
static invokeFunction = <I, O>(
|
|
19
|
+
functionDef: FunctionDefinition<I, O, any>,
|
|
20
|
+
input: I,
|
|
21
|
+
): Effect.Effect<O, never, FunctionInvocationService | InvocationServices> =>
|
|
22
|
+
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.invokeFunction)(functionDef, input);
|
|
23
|
+
}
|
package/src/services/index.ts
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
export * from './service-container';
|
|
5
|
+
export { DatabaseService } from '@dxos/echo-db';
|
|
6
|
+
|
|
8
7
|
export * from './credentials';
|
|
9
|
-
export
|
|
8
|
+
export { ConfiguredCredentialsService, type ServiceCredential } from './credentials';
|
|
10
9
|
export * from './event-logger';
|
|
11
|
-
export
|
|
12
|
-
export * from './
|
|
10
|
+
export { createEventLogger, createDefectLogger } from './event-logger';
|
|
11
|
+
export * from './function-invocation-service';
|
|
12
|
+
export * from './queues';
|
|
13
|
+
export * from './tracing';
|
package/src/services/queues.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
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
9
|
import type { Obj, Relation } from '@dxos/echo';
|
|
8
10
|
import type { Queue, QueueAPI, QueueFactory } from '@dxos/echo-db';
|
package/src/services/tracing.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
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
9
|
import { AgentStatus } from '@dxos/ai';
|
|
8
10
|
import { Obj } from '@dxos/echo';
|
|
9
|
-
import type {
|
|
10
|
-
import
|
|
11
|
-
import { log } from '@dxos/log';
|
|
12
|
-
import { DataType } from '@dxos/schema';
|
|
11
|
+
import type { ObjectId } from '@dxos/echo/internal';
|
|
12
|
+
import { Message } from '@dxos/types';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Provides a way for compute primitives (functions, workflows, tools)
|
|
@@ -30,30 +30,12 @@ export class TracingService extends Context.Tag('@dxos/functions/TracingService'
|
|
|
30
30
|
write: (event: Obj.Any) => void;
|
|
31
31
|
}
|
|
32
32
|
>() {
|
|
33
|
-
static noop: Context.Tag.Service<TracingService> = {
|
|
34
|
-
|
|
35
|
-
static layerNoop = Layer.succeed(TracingService, TracingService.noop);
|
|
36
|
-
|
|
37
|
-
static console: Context.Tag.Service<TracingService> = {
|
|
38
|
-
write: (event) => {
|
|
39
|
-
// eslint-disable-next-line no-console
|
|
40
|
-
console.log(event);
|
|
41
|
-
},
|
|
33
|
+
static noop: Context.Tag.Service<TracingService> = {
|
|
42
34
|
getTraceContext: () => ({}),
|
|
35
|
+
write: () => {},
|
|
43
36
|
};
|
|
44
37
|
|
|
45
|
-
static
|
|
46
|
-
|
|
47
|
-
static layerLogInfo = () =>
|
|
48
|
-
Layer.succeed(TracingService, {
|
|
49
|
-
write: (event) => {
|
|
50
|
-
if (Obj.instanceOf(AgentStatus, event)) {
|
|
51
|
-
log.info('status', { message: event.message });
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
getTraceContext: () => ({}),
|
|
55
|
-
});
|
|
56
|
-
|
|
38
|
+
static layerNoop: Layer.Layer<TracingService> = Layer.succeed(TracingService, TracingService.noop);
|
|
57
39
|
/**
|
|
58
40
|
* Creates a TracingService layer that emits events to the parent tracing service.
|
|
59
41
|
*/
|
|
@@ -70,43 +52,29 @@ export class TracingService extends Context.Tag('@dxos/functions/TracingService'
|
|
|
70
52
|
}),
|
|
71
53
|
);
|
|
72
54
|
|
|
73
|
-
static layerQueue = (queue: Queue) =>
|
|
74
|
-
Layer.effect(
|
|
75
|
-
TracingService,
|
|
76
|
-
Effect.gen(function* () {
|
|
77
|
-
// TODO(dmaretskyi): Batching.
|
|
78
|
-
return {
|
|
79
|
-
write: (event) => queue.append([event]),
|
|
80
|
-
getTraceContext: () => ({
|
|
81
|
-
debugInfo: {
|
|
82
|
-
queue: queue.dxn.toString(),
|
|
83
|
-
},
|
|
84
|
-
}),
|
|
85
|
-
};
|
|
86
|
-
}),
|
|
87
|
-
);
|
|
88
|
-
|
|
89
55
|
/**
|
|
90
56
|
* Emit the current human-readable execution status.
|
|
91
57
|
*/
|
|
92
|
-
static emitStatus: (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
58
|
+
static emitStatus: (
|
|
59
|
+
data: Omit<Obj.MakeProps<typeof AgentStatus>, 'created'>,
|
|
60
|
+
) => Effect.Effect<void, never, TracingService> = Effect.fnUntraced(function* (data) {
|
|
61
|
+
const tracing = yield* TracingService;
|
|
62
|
+
tracing.write(
|
|
63
|
+
Obj.make(AgentStatus, {
|
|
64
|
+
parentMessage: tracing.getTraceContext().parentMessage,
|
|
65
|
+
toolCallId: tracing.getTraceContext().toolCallId,
|
|
66
|
+
created: new Date().toISOString(),
|
|
67
|
+
...data,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
});
|
|
103
71
|
|
|
104
72
|
static emitConverationMessage: (
|
|
105
|
-
data: Obj.MakeProps<typeof
|
|
73
|
+
data: Obj.MakeProps<typeof Message.Message>,
|
|
106
74
|
) => Effect.Effect<void, never, TracingService> = Effect.fnUntraced(function* (data) {
|
|
107
75
|
const tracing = yield* TracingService;
|
|
108
76
|
tracing.write(
|
|
109
|
-
Obj.make(
|
|
77
|
+
Obj.make(Message.Message, {
|
|
110
78
|
parentMessage: tracing.getTraceContext().parentMessage,
|
|
111
79
|
...data,
|
|
112
80
|
properties: {
|
|
@@ -135,6 +103,6 @@ export namespace TracingService {
|
|
|
135
103
|
}
|
|
136
104
|
|
|
137
105
|
/**
|
|
138
|
-
* Goes into {@link
|
|
106
|
+
* Goes into {@link Message['properties']}
|
|
139
107
|
*/
|
|
140
108
|
export const MESSAGE_PROPERTY_TOOL_CALL_ID = 'toolCallId' as const;
|
|
@@ -2,36 +2,17 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { Type } from '@dxos/echo';
|
|
8
|
-
import { JsonSchemaType, LabelAnnotation, Ref } from '@dxos/echo
|
|
9
|
-
import { DataType } from '@dxos/schema';
|
|
7
|
+
import { Obj, Type } from '@dxos/echo';
|
|
8
|
+
import { JsonSchemaType, LabelAnnotation, Ref } from '@dxos/echo/internal';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
* Source script.
|
|
13
|
-
*/
|
|
14
|
-
export const ScriptType = Schema.Struct({
|
|
15
|
-
name: Schema.optional(Schema.String),
|
|
16
|
-
description: Schema.optional(Schema.String),
|
|
17
|
-
// TODO(burdon): Change to hash of deployed content.
|
|
18
|
-
// Whether source has changed since last deploy.
|
|
19
|
-
changed: Schema.optional(Schema.Boolean),
|
|
20
|
-
source: Ref(DataType.Text),
|
|
21
|
-
}).pipe(
|
|
22
|
-
Type.Obj({
|
|
23
|
-
typename: 'dxos.org/type/Script',
|
|
24
|
-
version: '0.1.0',
|
|
25
|
-
}),
|
|
26
|
-
LabelAnnotation.set(['name']),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
export interface ScriptType extends Schema.Schema.Type<typeof ScriptType> {}
|
|
10
|
+
import { Script } from './Script';
|
|
30
11
|
|
|
31
12
|
/**
|
|
32
13
|
* Function deployment.
|
|
33
14
|
*/
|
|
34
|
-
export const
|
|
15
|
+
export const Function = Schema.Struct({
|
|
35
16
|
/**
|
|
36
17
|
* Global registry ID.
|
|
37
18
|
* NOTE: The `key` property refers to the original registry entry.
|
|
@@ -49,13 +30,24 @@ export const FunctionType = Schema.Struct({
|
|
|
49
30
|
|
|
50
31
|
description: Schema.optional(Schema.String),
|
|
51
32
|
|
|
33
|
+
/**
|
|
34
|
+
* ISO date string of the last deployment.
|
|
35
|
+
*/
|
|
36
|
+
updated: Schema.optional(Schema.String),
|
|
37
|
+
|
|
52
38
|
// Reference to a source script if it exists within ECHO.
|
|
53
39
|
// TODO(burdon): Don't ref ScriptType directly (core).
|
|
54
|
-
source: Schema.optional(Ref(
|
|
40
|
+
source: Schema.optional(Ref(Script)),
|
|
55
41
|
|
|
56
42
|
inputSchema: Schema.optional(JsonSchemaType),
|
|
57
43
|
outputSchema: Schema.optional(JsonSchemaType),
|
|
58
44
|
|
|
45
|
+
/**
|
|
46
|
+
* List of required services.
|
|
47
|
+
* Match the Context.Tag keys of the FunctionServices variants.
|
|
48
|
+
*/
|
|
49
|
+
services: Schema.optional(Schema.Array(Schema.String)),
|
|
50
|
+
|
|
59
51
|
// Local binding to a function name.
|
|
60
52
|
binding: Schema.optional(Schema.String),
|
|
61
53
|
}).pipe(
|
|
@@ -65,4 +57,6 @@ export const FunctionType = Schema.Struct({
|
|
|
65
57
|
}),
|
|
66
58
|
LabelAnnotation.set(['name']),
|
|
67
59
|
);
|
|
68
|
-
export interface
|
|
60
|
+
export interface Function extends Schema.Schema.Type<typeof Function> {}
|
|
61
|
+
|
|
62
|
+
export const make = (props: Obj.MakeProps<typeof Function>) => Obj.make(Function, props);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { Obj, Ref, Type } from '@dxos/echo';
|
|
8
|
+
import { FormAnnotation, LabelAnnotation } from '@dxos/echo/internal';
|
|
9
|
+
import { Text } from '@dxos/schema';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Source script.
|
|
13
|
+
*/
|
|
14
|
+
export const Script = Schema.Struct({
|
|
15
|
+
name: Schema.String.pipe(Schema.optional),
|
|
16
|
+
description: Schema.String.pipe(Schema.optional),
|
|
17
|
+
// TODO(burdon): Change to hash of deployed content.
|
|
18
|
+
// Whether source has changed since last deploy.
|
|
19
|
+
changed: Schema.Boolean.pipe(FormAnnotation.set(false), Schema.optional),
|
|
20
|
+
source: Type.Ref(Text.Text).pipe(FormAnnotation.set(false)),
|
|
21
|
+
}).pipe(
|
|
22
|
+
Type.Obj({
|
|
23
|
+
typename: 'dxos.org/type/Script',
|
|
24
|
+
version: '0.1.0',
|
|
25
|
+
}),
|
|
26
|
+
LabelAnnotation.set(['name']),
|
|
27
|
+
);
|
|
28
|
+
export interface Script extends Schema.Schema.Type<typeof Script> {}
|
|
29
|
+
|
|
30
|
+
type Props = Omit<Obj.MakeProps<typeof Script>, 'source'> & { source?: string };
|
|
31
|
+
|
|
32
|
+
export const make = ({ source = '', ...props }: Props = {}) =>
|
|
33
|
+
Obj.make(Script, { ...props, source: Ref.make(Text.make(source)) });
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
|
|
8
|
+
import { Obj, QueryAST, Type } from '@dxos/echo';
|
|
9
|
+
import { Expando, OptionsAnnotationId, Ref } from '@dxos/echo/internal';
|
|
10
|
+
import { DXN } from '@dxos/keys';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Type discriminator for TriggerType.
|
|
14
|
+
* Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
|
|
15
|
+
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
|
|
16
|
+
*/
|
|
17
|
+
export const Kinds = ['email', 'queue', 'subscription', 'timer', 'webhook'] as const;
|
|
18
|
+
export type Kind = (typeof Kinds)[number];
|
|
19
|
+
|
|
20
|
+
const kindLiteralAnnotations = { title: 'Kind' };
|
|
21
|
+
|
|
22
|
+
export const EmailSpec = Schema.Struct({
|
|
23
|
+
kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
|
|
24
|
+
}).pipe(Schema.mutable);
|
|
25
|
+
export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
|
|
26
|
+
|
|
27
|
+
export const QueueSpec = Schema.Struct({
|
|
28
|
+
kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
|
|
29
|
+
|
|
30
|
+
// TODO(dmaretskyi): Change to a reference.
|
|
31
|
+
queue: DXN.Schema,
|
|
32
|
+
}).pipe(Schema.mutable);
|
|
33
|
+
export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Subscription.
|
|
37
|
+
*/
|
|
38
|
+
export const SubscriptionSpec = Schema.Struct({
|
|
39
|
+
kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
|
|
40
|
+
query: Schema.Struct({
|
|
41
|
+
raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
|
|
42
|
+
ast: QueryAST.Query,
|
|
43
|
+
}).pipe(Schema.mutable),
|
|
44
|
+
options: Schema.optional(
|
|
45
|
+
Schema.Struct({
|
|
46
|
+
// Watch changes to object (not just creation).
|
|
47
|
+
deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
|
|
48
|
+
// Debounce changes (delay in ms).
|
|
49
|
+
delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
|
|
50
|
+
}).annotations({ title: 'Options' }),
|
|
51
|
+
),
|
|
52
|
+
}).pipe(Schema.mutable);
|
|
53
|
+
export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Cron timer.
|
|
57
|
+
*/
|
|
58
|
+
export const TimerSpec = Schema.Struct({
|
|
59
|
+
kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
|
|
60
|
+
cron: Schema.String.annotations({
|
|
61
|
+
title: 'Cron',
|
|
62
|
+
[SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
|
|
63
|
+
}),
|
|
64
|
+
}).pipe(Schema.mutable);
|
|
65
|
+
export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Webhook.
|
|
69
|
+
*/
|
|
70
|
+
export const WebhookSpec = Schema.Struct({
|
|
71
|
+
kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
|
|
72
|
+
method: Schema.optional(
|
|
73
|
+
Schema.String.annotations({
|
|
74
|
+
title: 'Method',
|
|
75
|
+
[OptionsAnnotationId]: ['GET', 'POST'],
|
|
76
|
+
}),
|
|
77
|
+
),
|
|
78
|
+
port: Schema.optional(
|
|
79
|
+
Schema.Number.annotations({
|
|
80
|
+
title: 'Port',
|
|
81
|
+
}),
|
|
82
|
+
),
|
|
83
|
+
}).pipe(Schema.mutable);
|
|
84
|
+
export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Trigger schema.
|
|
88
|
+
*/
|
|
89
|
+
export const Spec = Schema.Union(EmailSpec, QueueSpec, SubscriptionSpec, TimerSpec, WebhookSpec).annotations({
|
|
90
|
+
title: 'Trigger',
|
|
91
|
+
});
|
|
92
|
+
export type Spec = Schema.Schema.Type<typeof Spec>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Function trigger.
|
|
96
|
+
* Function is invoked with the `payload` passed as input data.
|
|
97
|
+
* The event that triggers the function is available in the function context.
|
|
98
|
+
*/
|
|
99
|
+
const Trigger_ = Schema.Struct({
|
|
100
|
+
/**
|
|
101
|
+
* Function or workflow to invoke.
|
|
102
|
+
*/
|
|
103
|
+
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
104
|
+
function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Only used for workflowSchema.
|
|
108
|
+
* Specifies the input node in the circuit.
|
|
109
|
+
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
110
|
+
*/
|
|
111
|
+
inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
|
|
112
|
+
|
|
113
|
+
enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
|
|
114
|
+
|
|
115
|
+
spec: Schema.optional(Spec),
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Passed as the input data to the function.
|
|
119
|
+
* Must match the function's input schema.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* {
|
|
123
|
+
* item: '{{$.trigger.event}}',
|
|
124
|
+
* instructions: 'Summarize and perform entity-extraction'
|
|
125
|
+
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
126
|
+
* }
|
|
127
|
+
*/
|
|
128
|
+
input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
|
|
129
|
+
}).pipe(
|
|
130
|
+
Type.Obj({
|
|
131
|
+
typename: 'dxos.org/type/Trigger',
|
|
132
|
+
version: '0.1.0',
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
export interface Trigger extends Schema.Schema.Type<typeof Trigger_> {}
|
|
136
|
+
export interface TriggerEncoded extends Schema.Schema.Encoded<typeof Trigger_> {}
|
|
137
|
+
export const Trigger: Schema.Schema<Trigger, TriggerEncoded> = Trigger_;
|
|
138
|
+
|
|
139
|
+
export const make = (props: Obj.MakeProps<typeof Trigger>) => Obj.make(Trigger, props);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { DXN, Obj, Type } from '@dxos/echo';
|
|
8
|
+
|
|
9
|
+
export type TriggerEvent = EmailEvent | QueueEvent | SubscriptionEvent | TimerEvent | WebhookEvent;
|
|
10
|
+
|
|
11
|
+
// TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
|
|
12
|
+
export const EmailEvent = Schema.mutable(
|
|
13
|
+
Schema.Struct({
|
|
14
|
+
from: Schema.String,
|
|
15
|
+
to: Schema.String,
|
|
16
|
+
subject: Schema.String,
|
|
17
|
+
created: Schema.String,
|
|
18
|
+
body: Schema.String,
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
|
|
22
|
+
|
|
23
|
+
export const QueueEvent = Schema.mutable(
|
|
24
|
+
Schema.Struct({
|
|
25
|
+
queue: DXN.Schema,
|
|
26
|
+
item: Schema.Any,
|
|
27
|
+
cursor: Schema.String,
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
|
|
31
|
+
|
|
32
|
+
export const SubscriptionEvent = Schema.Struct({
|
|
33
|
+
/**
|
|
34
|
+
* Type of the mutation.
|
|
35
|
+
*/
|
|
36
|
+
// TODO(dmaretskyi): Specify enum.
|
|
37
|
+
type: Schema.String,
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Reference to the object that was changed or created.
|
|
41
|
+
*/
|
|
42
|
+
subject: Type.Ref(Obj.Any),
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated
|
|
46
|
+
*/
|
|
47
|
+
changedObjectId: Schema.optional(Schema.String),
|
|
48
|
+
}).pipe(Schema.mutable);
|
|
49
|
+
export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
|
|
50
|
+
|
|
51
|
+
export const TimerEvent = Schema.mutable(Schema.Struct({ tick: Schema.Number }));
|
|
52
|
+
export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
|
|
53
|
+
|
|
54
|
+
export const WebhookEvent = Schema.mutable(
|
|
55
|
+
Schema.Struct({
|
|
56
|
+
url: Schema.String,
|
|
57
|
+
method: Schema.Literal('GET', 'POST'),
|
|
58
|
+
headers: Schema.Record({ key: Schema.String, value: Schema.String }),
|
|
59
|
+
bodyText: Schema.String,
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
export type WebhookEvent = Schema.Schema.Type<typeof WebhookEvent>;
|
package/src/types/url.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type ObjectMeta } from '@dxos/echo/internal';
|
|
6
|
+
|
|
7
|
+
// TODO: use URL scheme for source?
|
|
8
|
+
export const FUNCTIONS_META_KEY = 'dxos.org/service/function';
|
|
9
|
+
|
|
10
|
+
export const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* NOTE: functionId is backend ID, not ECHO object id.
|
|
14
|
+
*/
|
|
15
|
+
export const getUserFunctionIdInMetadata = (meta: ObjectMeta) => {
|
|
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
|
+
*/
|
|
22
|
+
export const setUserFunctionIdInMetadata = (meta: ObjectMeta, functionId: string) => {
|
|
23
|
+
const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
|
|
24
|
+
if (key) {
|
|
25
|
+
if (key.id !== functionId) {
|
|
26
|
+
throw new Error('Metadata mismatch');
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionId });
|
|
30
|
+
}
|
|
31
|
+
};
|