@dxos/functions 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0
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 +38 -0
- package/dist/lib/neutral/Trace.mjs.map +7 -0
- package/dist/lib/neutral/chunk-5T7GOX2V.mjs +149 -0
- package/dist/lib/neutral/chunk-5T7GOX2V.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 +1266 -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 +155 -0
- package/dist/types/src/Trace.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +24 -32
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/example/definitions.d.ts +11 -0
- package/dist/types/src/example/definitions.d.ts.map +1 -0
- package/dist/types/src/example/fib.d.ts +3 -2
- package/dist/types/src/example/fib.d.ts.map +1 -1
- package/dist/types/src/example/index.d.ts +3 -11
- package/dist/types/src/example/index.d.ts.map +1 -1
- package/dist/types/src/example/reply.d.ts +2 -1
- package/dist/types/src/example/reply.d.ts.map +1 -1
- package/dist/types/src/example/sleep.d.ts +3 -2
- package/dist/types/src/example/sleep.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/process/Process.d.ts +247 -0
- package/dist/types/src/process/Process.d.ts.map +1 -0
- package/dist/types/src/process/ServiceResolver.d.ts +74 -0
- package/dist/types/src/process/ServiceResolver.d.ts.map +1 -0
- package/dist/types/src/process/StorageService.d.ts +58 -0
- package/dist/types/src/process/StorageService.d.ts.map +1 -0
- package/dist/types/src/protocol/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/protocol.d.ts +2 -2
- package/dist/types/src/protocol/protocol.d.ts.map +1 -1
- package/dist/types/src/sdk.d.ts +4 -79
- package/dist/types/src/sdk.d.ts.map +1 -1
- 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 +25 -31
- package/dist/types/src/services/event-logger.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +9 -3
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/index.d.ts +0 -1
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +8 -5
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +61 -4
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/Script.d.ts +10 -16
- package/dist/types/src/types/Script.d.ts.map +1 -1
- package/dist/types/src/types/Trigger.d.ts +57 -76
- package/dist/types/src/types/Trigger.d.ts.map +1 -1
- package/dist/types/src/types/TriggerEvent.d.ts +44 -13
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +0 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/url.d.ts +6 -5
- package/dist/types/src/types/url.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -17
- package/src/Trace.ts +202 -0
- package/src/errors.ts +5 -5
- package/src/example/definitions.ts +49 -0
- package/src/example/fib.ts +15 -24
- package/src/example/forex-effect.ts +1 -1
- package/src/example/index.ts +7 -8
- package/src/example/reply.ts +11 -13
- package/src/example/sleep.ts +9 -16
- package/src/index.ts +4 -0
- package/src/process/Process.ts +486 -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/protocol/protocol.test.ts +0 -1
- package/src/protocol/protocol.ts +206 -84
- package/src/sdk.ts +7 -194
- package/src/services/credentials.ts +31 -15
- package/src/services/event-logger.ts +2 -2
- package/src/services/function-invocation-service.ts +19 -3
- package/src/services/index.ts +0 -2
- package/src/services/queues.ts +15 -8
- package/src/services/tracing.ts +97 -5
- package/src/types/Script.ts +14 -9
- package/src/types/Trigger.ts +33 -18
- package/src/types/TriggerEvent.ts +29 -29
- package/src/types/index.ts +0 -1
- package/src/types/url.ts +6 -5
- package/dist/lib/browser/index.mjs +0 -927
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -928
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/types/src/types/Function.d.ts +0 -58
- package/dist/types/src/types/Function.d.ts.map +0 -1
- package/src/types/Function.ts +0 -62
package/src/types/Trigger.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
7
|
|
|
8
|
-
import { Obj, QueryAST, Type } from '@dxos/echo';
|
|
9
|
-
import {
|
|
8
|
+
import { Annotation, Obj, QueryAST, Ref, Type } from '@dxos/echo';
|
|
9
|
+
import { OptionsAnnotationId, SystemTypeAnnotation } from '@dxos/echo/internal';
|
|
10
10
|
import { DXN } from '@dxos/keys';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -21,15 +21,17 @@ const kindLiteralAnnotations = { title: 'Kind' };
|
|
|
21
21
|
|
|
22
22
|
export const EmailSpec = Schema.Struct({
|
|
23
23
|
kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
|
|
24
|
-
})
|
|
24
|
+
});
|
|
25
25
|
export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
|
|
26
26
|
|
|
27
|
+
// TODO(burdon): Change to Feed.
|
|
28
|
+
// TODO(wittjosiah): Remove. Migrate to Subscription triggers once EDGE supports them for feed queries.
|
|
27
29
|
export const QueueSpec = Schema.Struct({
|
|
28
30
|
kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
|
|
29
31
|
|
|
30
|
-
// TODO(dmaretskyi):
|
|
32
|
+
// TODO(dmaretskyi): Rename to `feed` and change to a reference.
|
|
31
33
|
queue: DXN.Schema,
|
|
32
|
-
})
|
|
34
|
+
});
|
|
33
35
|
export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
|
|
34
36
|
|
|
35
37
|
/**
|
|
@@ -40,7 +42,7 @@ export const SubscriptionSpec = Schema.Struct({
|
|
|
40
42
|
query: Schema.Struct({
|
|
41
43
|
raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
|
|
42
44
|
ast: QueryAST.Query,
|
|
43
|
-
})
|
|
45
|
+
}),
|
|
44
46
|
options: Schema.optional(
|
|
45
47
|
Schema.Struct({
|
|
46
48
|
// Watch changes to object (not just creation).
|
|
@@ -49,7 +51,7 @@ export const SubscriptionSpec = Schema.Struct({
|
|
|
49
51
|
delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
|
|
50
52
|
}).annotations({ title: 'Options' }),
|
|
51
53
|
),
|
|
52
|
-
})
|
|
54
|
+
});
|
|
53
55
|
export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
|
|
54
56
|
|
|
55
57
|
/**
|
|
@@ -61,7 +63,7 @@ export const TimerSpec = Schema.Struct({
|
|
|
61
63
|
title: 'Cron',
|
|
62
64
|
[SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
|
|
63
65
|
}),
|
|
64
|
-
})
|
|
66
|
+
});
|
|
65
67
|
export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
|
|
66
68
|
|
|
67
69
|
/**
|
|
@@ -80,7 +82,7 @@ export const WebhookSpec = Schema.Struct({
|
|
|
80
82
|
title: 'Port',
|
|
81
83
|
}),
|
|
82
84
|
),
|
|
83
|
-
})
|
|
85
|
+
});
|
|
84
86
|
export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
|
|
85
87
|
|
|
86
88
|
/**
|
|
@@ -96,12 +98,12 @@ export type Spec = Schema.Schema.Type<typeof Spec>;
|
|
|
96
98
|
* Function is invoked with the `payload` passed as input data.
|
|
97
99
|
* The event that triggers the function is available in the function context.
|
|
98
100
|
*/
|
|
99
|
-
const
|
|
101
|
+
const TriggerSchema = Schema.Struct({
|
|
100
102
|
/**
|
|
101
103
|
* Function or workflow to invoke.
|
|
102
104
|
*/
|
|
103
105
|
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
104
|
-
function: Schema.optional(Ref(
|
|
106
|
+
function: Schema.optional(Ref.Ref(Obj.Unknown).annotations({ title: 'Function' })),
|
|
105
107
|
|
|
106
108
|
/**
|
|
107
109
|
* Only used for workflowSchema.
|
|
@@ -110,30 +112,43 @@ const Trigger_ = Schema.Struct({
|
|
|
110
112
|
*/
|
|
111
113
|
inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
|
|
112
114
|
|
|
115
|
+
// TODO(burdon): NO BOOLEAN PROPERTIES (enabld/disabled/paused, etc.)
|
|
116
|
+
// Need lint rule; or agent rule to require PR review for "boolean" key word.
|
|
113
117
|
enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
|
|
114
118
|
|
|
115
119
|
spec: Schema.optional(Spec),
|
|
116
120
|
|
|
121
|
+
concurrency: Schema.optional(
|
|
122
|
+
Schema.Number.annotations({
|
|
123
|
+
title: 'Concurrency',
|
|
124
|
+
default: 1,
|
|
125
|
+
description:
|
|
126
|
+
'Maximum number of concurrent invocations of the trigger. For Feed triggers, this will process Feed items in parallel.',
|
|
127
|
+
}),
|
|
128
|
+
),
|
|
129
|
+
|
|
117
130
|
/**
|
|
118
131
|
* Passed as the input data to the function.
|
|
119
132
|
* Must match the function's input schema.
|
|
120
133
|
*
|
|
121
134
|
* @example
|
|
122
135
|
* {
|
|
123
|
-
* item: '{{
|
|
136
|
+
* item: '{{event.item}}',
|
|
124
137
|
* instructions: 'Summarize and perform entity-extraction'
|
|
125
138
|
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
126
139
|
* }
|
|
127
140
|
*/
|
|
128
|
-
input: Schema.optional(Schema.
|
|
141
|
+
input: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
129
142
|
}).pipe(
|
|
130
|
-
Type.
|
|
131
|
-
typename: 'dxos.
|
|
143
|
+
Type.object({
|
|
144
|
+
typename: 'org.dxos.type.trigger',
|
|
132
145
|
version: '0.1.0',
|
|
133
146
|
}),
|
|
147
|
+
Annotation.IconAnnotation.set({ icon: 'ph--lightning--regular', hue: 'yellow' }),
|
|
148
|
+
SystemTypeAnnotation.set(true),
|
|
134
149
|
);
|
|
135
|
-
|
|
136
|
-
export interface
|
|
137
|
-
export const Trigger:
|
|
150
|
+
|
|
151
|
+
export interface Trigger extends Schema.Schema.Type<typeof TriggerSchema> {}
|
|
152
|
+
export const Trigger: Type.Obj<Trigger> = TriggerSchema as any;
|
|
138
153
|
|
|
139
154
|
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, Obj,
|
|
7
|
+
import { DXN, Obj, Ref } 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:
|
|
41
|
+
subject: Ref.Ref(Obj.Unknown),
|
|
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
package/src/types/url.ts
CHANGED
|
@@ -2,24 +2,25 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Obj } from '@dxos/echo';
|
|
6
6
|
|
|
7
7
|
// TODO: use URL scheme for source?
|
|
8
|
-
export const FUNCTIONS_META_KEY = 'dxos.
|
|
8
|
+
export const FUNCTIONS_META_KEY = 'org.dxos.service.function';
|
|
9
9
|
|
|
10
|
-
export const FUNCTIONS_PRESET_META_KEY = 'dxos.
|
|
10
|
+
export const FUNCTIONS_PRESET_META_KEY = 'org.dxos.service.function-preset';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* NOTE: functionId is backend ID, not ECHO object id.
|
|
14
14
|
*/
|
|
15
|
-
export const getUserFunctionIdInMetadata = (meta:
|
|
15
|
+
export const getUserFunctionIdInMetadata = (meta: Obj.ReadonlyMeta) => {
|
|
16
16
|
return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* NOTE: functionId is backend ID, not ECHO object id.
|
|
21
|
+
* Must be called inside Obj.changeMeta() since it mutates the meta.
|
|
21
22
|
*/
|
|
22
|
-
export const setUserFunctionIdInMetadata = (meta:
|
|
23
|
+
export const setUserFunctionIdInMetadata = (meta: Obj.Meta, functionId: string) => {
|
|
23
24
|
const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
|
|
24
25
|
if (key) {
|
|
25
26
|
if (key.id !== functionId) {
|