@dxos/functions 0.8.4-main.69d29f4 → 0.8.4-main.6fa680abb7

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.
Files changed (35) hide show
  1. package/README.md +4 -6
  2. package/dist/lib/{browser → neutral}/index.mjs +58 -47
  3. package/dist/lib/neutral/index.mjs.map +7 -0
  4. package/dist/lib/neutral/meta.json +1 -0
  5. package/dist/types/src/example/index.d.ts +5 -5
  6. package/dist/types/src/example/index.d.ts.map +1 -1
  7. package/dist/types/src/protocol/protocol.d.ts.map +1 -1
  8. package/dist/types/src/sdk.d.ts +11 -8
  9. package/dist/types/src/sdk.d.ts.map +1 -1
  10. package/dist/types/src/services/event-logger.d.ts +2 -2
  11. package/dist/types/src/services/event-logger.d.ts.map +1 -1
  12. package/dist/types/src/types/Function.d.ts +1 -1
  13. package/dist/types/src/types/Function.d.ts.map +1 -1
  14. package/dist/types/src/types/Trigger.d.ts +5 -4
  15. package/dist/types/src/types/Trigger.d.ts.map +1 -1
  16. package/dist/types/src/types/TriggerEvent.d.ts +3 -2
  17. package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
  18. package/dist/types/src/types/url.d.ts +2 -2
  19. package/dist/types/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +19 -20
  21. package/src/example/forex-effect.ts +1 -1
  22. package/src/example/index.ts +8 -8
  23. package/src/protocol/protocol.ts +11 -15
  24. package/src/sdk.ts +20 -12
  25. package/src/services/event-logger.ts +1 -1
  26. package/src/types/Function.ts +4 -3
  27. package/src/types/Script.ts +2 -2
  28. package/src/types/Trigger.ts +14 -3
  29. package/src/types/TriggerEvent.ts +2 -2
  30. package/src/types/url.ts +2 -2
  31. package/dist/lib/browser/index.mjs.map +0 -7
  32. package/dist/lib/browser/meta.json +0 -1
  33. package/dist/lib/node-esm/index.mjs +0 -1230
  34. package/dist/lib/node-esm/index.mjs.map +0 -7
  35. package/dist/lib/node-esm/meta.json +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/functions",
3
- "version": "0.8.4-main.69d29f4",
3
+ "version": "0.8.4-main.6fa680abb7",
4
4
  "description": "Functions API.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -16,8 +16,7 @@
16
16
  ".": {
17
17
  "source": "./src/index.ts",
18
18
  "types": "./dist/types/src/index.d.ts",
19
- "browser": "./dist/lib/browser/index.mjs",
20
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "default": "./dist/lib/neutral/index.mjs"
21
20
  }
22
21
  },
23
22
  "types": "dist/types/src/index.d.ts",
@@ -27,23 +26,23 @@
27
26
  "src"
28
27
  ],
29
28
  "dependencies": {
30
- "@effect/ai-anthropic": "0.22.0",
31
- "@effect/platform": "0.93.6",
32
- "effect": "3.19.11",
33
- "@dxos/ai": "0.8.4-main.69d29f4",
34
- "@dxos/echo": "0.8.4-main.69d29f4",
35
- "@dxos/context": "0.8.4-main.69d29f4",
36
- "@dxos/errors": "0.8.4-main.69d29f4",
37
- "@dxos/echo-db": "0.8.4-main.69d29f4",
38
- "@dxos/effect": "0.8.4-main.69d29f4",
39
- "@dxos/keys": "0.8.4-main.69d29f4",
40
- "@dxos/log": "0.8.4-main.69d29f4",
41
- "@dxos/invariant": "0.8.4-main.69d29f4",
42
- "@dxos/node-std": "0.8.4-main.69d29f4",
43
- "@dxos/operation": "0.8.4-main.69d29f4",
44
- "@dxos/schema": "0.8.4-main.69d29f4",
45
- "@dxos/protocols": "0.8.4-main.69d29f4",
46
- "@dxos/types": "0.8.4-main.69d29f4"
29
+ "@effect/ai-anthropic": "0.23.0",
30
+ "@effect/platform": "0.94.4",
31
+ "effect": "3.19.16",
32
+ "@dxos/ai": "0.8.4-main.6fa680abb7",
33
+ "@dxos/echo": "0.8.4-main.6fa680abb7",
34
+ "@dxos/echo-db": "0.8.4-main.6fa680abb7",
35
+ "@dxos/invariant": "0.8.4-main.6fa680abb7",
36
+ "@dxos/effect": "0.8.4-main.6fa680abb7",
37
+ "@dxos/keys": "0.8.4-main.6fa680abb7",
38
+ "@dxos/errors": "0.8.4-main.6fa680abb7",
39
+ "@dxos/context": "0.8.4-main.6fa680abb7",
40
+ "@dxos/log": "0.8.4-main.6fa680abb7",
41
+ "@dxos/node-std": "0.8.4-main.6fa680abb7",
42
+ "@dxos/operation": "0.8.4-main.6fa680abb7",
43
+ "@dxos/protocols": "0.8.4-main.6fa680abb7",
44
+ "@dxos/schema": "0.8.4-main.6fa680abb7",
45
+ "@dxos/types": "0.8.4-main.6fa680abb7"
47
46
  },
48
47
  "publishConfig": {
49
48
  "access": "public"
@@ -14,7 +14,7 @@ import {
14
14
  import { Effect, Schedule } from 'https://esm.sh/effect@3.17.0?bundle=false';
15
15
 
16
16
  export default defineFunction({
17
- key: 'dxos.org/script/forex-effect',
17
+ key: 'org.dxos.script.forex-effect',
18
18
  name: 'Forex Effect',
19
19
  description: 'Returns the exchange rate between two currencies.',
20
20
 
@@ -2,12 +2,12 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { default as fib$ } from './fib';
6
- import { default as reply$ } from './reply';
7
- import { default as sleep$ } from './sleep';
5
+ import Fibonacci from './fib';
6
+ import Reply from './reply';
7
+ import Sleep from './sleep';
8
8
 
9
- export namespace Example {
10
- export const fib = fib$;
11
- export const reply = reply$;
12
- export const sleep = sleep$;
13
- }
9
+ export const ExampleFunctions = {
10
+ Fibonacci,
11
+ Reply,
12
+ Sleep,
13
+ };
@@ -11,9 +11,9 @@ import * as SchemaAST from 'effect/SchemaAST';
11
11
  import { AiModelResolver, AiService } from '@dxos/ai';
12
12
  import { AnthropicResolver } from '@dxos/ai/resolvers';
13
13
  import { LifecycleState, Resource } from '@dxos/context';
14
- import { Database, Ref, Type } from '@dxos/echo';
14
+ import { Database, Feed, JsonSchema, Ref, type Type } from '@dxos/echo';
15
15
  import { refFromEncodedReference } from '@dxos/echo/internal';
16
- import { EchoClient, type EchoDatabaseImpl, type QueueFactory } from '@dxos/echo-db';
16
+ import { EchoClient, type EchoDatabaseImpl, type QueueFactory, createFeedServiceLayer } from '@dxos/echo-db';
17
17
  import { runAndForwardErrors } from '@dxos/effect';
18
18
  import { assertState, failedInvariant, invariant } from '@dxos/invariant';
19
19
  import { PublicKey } from '@dxos/keys';
@@ -38,13 +38,15 @@ export const wrapFunctionHandler = (func: FunctionDefinition): FunctionProtocol.
38
38
  key: func.key,
39
39
  name: func.name,
40
40
  description: func.description,
41
- inputSchema: Type.toJsonSchema(func.inputSchema),
42
- outputSchema: func.outputSchema === undefined ? undefined : Type.toJsonSchema(func.outputSchema),
41
+ inputSchema: JsonSchema.toJsonSchema(func.inputSchema),
42
+ outputSchema: func.outputSchema === undefined ? undefined : JsonSchema.toJsonSchema(func.outputSchema),
43
43
  services: func.services,
44
44
  },
45
45
  handler: async ({ data, context }) => {
46
46
  if (
47
- (func.services.includes(Database.Service.key) || func.services.includes(QueueService.key)) &&
47
+ (func.services.includes(Database.Service.key) ||
48
+ func.services.includes(QueueService.key) ||
49
+ func.services.includes(Feed.Service.key)) &&
48
50
  (!context.services.dataService || !context.services.queryService)
49
51
  ) {
50
52
  throw new FunctionError({
@@ -66,7 +68,7 @@ export const wrapFunctionHandler = (func: FunctionDefinition): FunctionProtocol.
66
68
 
67
69
  if (func.types.length > 0) {
68
70
  invariant(funcContext.db, 'Database is required for functions with types');
69
- await funcContext.db.graph.schemaRegistry.register(func.types as Type.Entity.Any[]);
71
+ await funcContext.db.graph.schemaRegistry.register(func.types as Type.AnyEntity[]);
70
72
  }
71
73
 
72
74
  const dataWithDecodedRefs =
@@ -149,8 +151,9 @@ class FunctionContext extends Resource {
149
151
  createLayer(): Layer.Layer<FunctionServices> {
150
152
  assertState(this._lifecycleState === LifecycleState.OPEN, 'FunctionContext is not open');
151
153
 
152
- const dbLayer = this.db ? Database.Service.layer(this.db) : Database.Service.notAvailable;
154
+ const dbLayer = this.db ? Database.layer(this.db) : Database.notAvailable;
153
155
  const queuesLayer = this.queues ? QueueService.layer(this.queues) : QueueService.notAvailable;
156
+ const feedLayer = this.queues ? createFeedServiceLayer(this.queues) : Feed.notAvailable;
154
157
  const credentials = dbLayer
155
158
  ? CredentialsService.layerFromDatabase({ caching: true }).pipe(Layer.provide(dbLayer))
156
159
  : CredentialsService.configuredLayer([]);
@@ -172,14 +175,7 @@ class FunctionContext extends Resource {
172
175
  )
173
176
  : AiService.notAvailable;
174
177
 
175
- return Layer.mergeAll(
176
- dbLayer, //
177
- queuesLayer,
178
- credentials,
179
- functionInvocationService,
180
- aiLayer,
181
- tracing,
182
- );
178
+ return Layer.mergeAll(dbLayer, queuesLayer, feedLayer, credentials, functionInvocationService, aiLayer, tracing);
183
179
  }
184
180
  }
185
181
 
package/src/sdk.ts CHANGED
@@ -7,7 +7,7 @@ import * as Effect from 'effect/Effect';
7
7
  import * as Schema from 'effect/Schema';
8
8
 
9
9
  import { type AiService } from '@dxos/ai';
10
- import { Obj, Type } from '@dxos/echo';
10
+ import { type Feed, JsonSchema, Obj, type Type } from '@dxos/echo';
11
11
  import { type Database } from '@dxos/echo';
12
12
  import { assertArgument, failedInvariant } from '@dxos/invariant';
13
13
  import { Operation } from '@dxos/operation';
@@ -39,7 +39,9 @@ export type FunctionServices =
39
39
  | AiService.AiService
40
40
  | CredentialsService
41
41
  | Database.Service
42
+ // TODO(wittjosiah): Remove QueueService — use Feed.Service instead.
42
43
  | QueueService
44
+ | Feed.Service
43
45
  | FunctionInvocationService;
44
46
 
45
47
  /**
@@ -68,26 +70,29 @@ export interface FunctionContext {
68
70
 
69
71
  const typeId = Symbol.for('@dxos/functions/FunctionDefinition');
70
72
 
71
- export type FunctionDefinition<T = any, O = any, S extends FunctionServices = FunctionServices> = {
73
+ /**
74
+ * Deployable function definition.
75
+ */
76
+ export type FunctionDefinition<TInput = any, TOutput = any, S extends FunctionServices = FunctionServices> = {
72
77
  [typeId]: true;
78
+
73
79
  key: string;
74
80
  name: string;
75
81
  description?: string;
76
- inputSchema: Schema.Schema<T, any>;
77
- outputSchema?: Schema.Schema<O, any>;
82
+ inputSchema: Schema.Schema<TInput, any>;
83
+ outputSchema?: Schema.Schema<TOutput, any>;
78
84
 
79
85
  /**
80
86
  * List of types the function uses.
81
87
  * This is used to ensure that the types are available when the function is executed.
82
88
  */
83
- types: readonly Type.Entity.Any[];
89
+ types: readonly Type.AnyEntity[];
84
90
 
85
91
  /**
86
92
  * Keys of the required services.
87
93
  */
88
94
  services: readonly string[];
89
95
 
90
- handler: FunctionHandler<T, O, S>;
91
96
  meta?: {
92
97
  /**
93
98
  * Tools that are projected from functions have this annotation.
@@ -100,6 +105,8 @@ export type FunctionDefinition<T = any, O = any, S extends FunctionServices = Fu
100
105
  */
101
106
  deployedFunctionId?: string;
102
107
  };
108
+
109
+ handler: FunctionHandler<TInput, TOutput, S>;
103
110
  };
104
111
 
105
112
  export declare namespace FunctionDefinition {
@@ -120,7 +127,8 @@ export type FunctionProps<T, O> = {
120
127
  * List of types the function uses.
121
128
  * This is used to ensure that the types are available when the function is executed.
122
129
  */
123
- types?: readonly Type.Entity.Any[];
130
+ types?: readonly Type.AnyEntity[];
131
+
124
132
  // TODO(dmaretskyi): This currently doesn't cause a compile-time error if the handler requests a service that is not specified
125
133
  services?: readonly Context.Tag<any, any>[];
126
134
 
@@ -177,7 +185,7 @@ export const defineFunction: {
177
185
  handler: handlerWithSpan,
178
186
  types: types ?? [],
179
187
  services: !services ? [] : getServiceKeys(services),
180
- } satisfies FunctionDefinition.Any;
188
+ };
181
189
  };
182
190
 
183
191
  const getServiceKeys = (services: readonly Context.Tag<any, any>[]) => {
@@ -259,8 +267,8 @@ export const serializeFunction = (functionDef: FunctionDefinition.Any): Function
259
267
  name: functionDef.name,
260
268
  version: '0.1.0',
261
269
  description: functionDef.description,
262
- inputSchema: Type.toJsonSchema(functionDef.inputSchema),
263
- outputSchema: !functionDef.outputSchema ? undefined : Type.toJsonSchema(functionDef.outputSchema),
270
+ inputSchema: JsonSchema.toJsonSchema(functionDef.inputSchema),
271
+ outputSchema: !functionDef.outputSchema ? undefined : JsonSchema.toJsonSchema(functionDef.outputSchema),
264
272
  services: functionDef.services,
265
273
  });
266
274
  if (functionDef.meta?.deployedFunctionId) {
@@ -276,8 +284,8 @@ export const deserializeFunction = (functionObj: Function.Function): FunctionDef
276
284
  key: functionObj.key ?? functionObj.name,
277
285
  name: functionObj.name,
278
286
  description: functionObj.description,
279
- inputSchema: !functionObj.inputSchema ? Schema.Unknown : Type.toEffectSchema(functionObj.inputSchema),
280
- outputSchema: !functionObj.outputSchema ? undefined : Type.toEffectSchema(functionObj.outputSchema),
287
+ inputSchema: !functionObj.inputSchema ? Schema.Unknown : JsonSchema.toEffectSchema(functionObj.inputSchema),
288
+ outputSchema: !functionObj.outputSchema ? undefined : JsonSchema.toEffectSchema(functionObj.outputSchema),
281
289
  // TODO(dmaretskyi): This should throw error.
282
290
  handler: () => {},
283
291
  services: functionObj.services ?? [],
@@ -52,7 +52,7 @@ export type ComputeEventPayload = Schema.Schema.Type<typeof ComputeEventPayload>
52
52
 
53
53
  export const ComputeEvent = Schema.Struct({
54
54
  payload: ComputeEventPayload,
55
- }).pipe(Type.object({ typename: 'dxos.org/type/ComputeEvent', version: '0.1.0' }));
55
+ }).pipe(Type.object({ typename: 'org.dxos.type.compute-event', version: '0.1.0' }));
56
56
 
57
57
  /**
58
58
  * Logs event for the compute workflows.
@@ -4,7 +4,7 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { Annotation, JsonSchema, Obj, Type } from '@dxos/echo';
7
+ import { Annotation, JsonSchema, Obj, Ref, Type } from '@dxos/echo';
8
8
  import { SystemTypeAnnotation } from '@dxos/echo/internal';
9
9
 
10
10
  import { Script } from './Script';
@@ -36,7 +36,7 @@ export const Function = Schema.Struct({
36
36
 
37
37
  // Reference to a source script if it exists within ECHO.
38
38
  // TODO(burdon): Don't ref ScriptType directly (core).
39
- source: Schema.optional(Type.Ref(Script)),
39
+ source: Schema.optional(Ref.Ref(Script)),
40
40
 
41
41
  inputSchema: Schema.optional(JsonSchema.JsonSchema),
42
42
  outputSchema: Schema.optional(JsonSchema.JsonSchema),
@@ -51,10 +51,11 @@ export const Function = Schema.Struct({
51
51
  binding: Schema.optional(Schema.String),
52
52
  }).pipe(
53
53
  Type.object({
54
- typename: 'dxos.org/type/Function',
54
+ typename: 'org.dxos.type.function',
55
55
  version: '0.1.0',
56
56
  }),
57
57
  Annotation.LabelAnnotation.set(['name']),
58
+ Annotation.IconAnnotation.set({ icon: 'ph--function--regular', hue: 'blue' }),
58
59
  SystemTypeAnnotation.set(true),
59
60
  );
60
61
 
@@ -17,10 +17,10 @@ export const Script = Schema.Struct({
17
17
  // TODO(burdon): Change to hash of deployed content.
18
18
  // Whether source has changed since last deploy.
19
19
  changed: Schema.Boolean.pipe(FormInputAnnotation.set(false), Schema.optional),
20
- source: Type.Ref(Text.Text).pipe(FormInputAnnotation.set(false)),
20
+ source: Ref.Ref(Text.Text).pipe(FormInputAnnotation.set(false)),
21
21
  }).pipe(
22
22
  Type.object({
23
- typename: 'dxos.org/type/Script',
23
+ typename: 'org.dxos.type.script',
24
24
  version: '0.1.0',
25
25
  }),
26
26
  Annotation.LabelAnnotation.set(['name']),
@@ -5,7 +5,7 @@
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';
8
+ import { Annotation, Obj, QueryAST, Ref, Type } from '@dxos/echo';
9
9
  import { OptionsAnnotationId, SystemTypeAnnotation } from '@dxos/echo/internal';
10
10
  import { DXN } from '@dxos/keys';
11
11
  import { Expando } from '@dxos/schema';
@@ -25,6 +25,7 @@ export const EmailSpec = Schema.Struct({
25
25
  });
26
26
  export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
27
27
 
28
+ // TODO(wittjosiah): Remove. Migrate to Subscription triggers once EDGE supports them for feed queries.
28
29
  export const QueueSpec = Schema.Struct({
29
30
  kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
30
31
 
@@ -102,7 +103,7 @@ const TriggerSchema = Schema.Struct({
102
103
  * Function or workflow to invoke.
103
104
  */
104
105
  // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
105
- function: Schema.optional(Type.Ref(Expando.Expando).annotations({ title: 'Function' })),
106
+ function: Schema.optional(Ref.Ref(Expando.Expando).annotations({ title: 'Function' })),
106
107
 
107
108
  /**
108
109
  * Only used for workflowSchema.
@@ -117,6 +118,15 @@ const TriggerSchema = Schema.Struct({
117
118
 
118
119
  spec: Schema.optional(Spec),
119
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 queue triggers, this will process queue items in parallel.',
127
+ }),
128
+ ),
129
+
120
130
  /**
121
131
  * Passed as the input data to the function.
122
132
  * Must match the function's input schema.
@@ -131,9 +141,10 @@ const TriggerSchema = Schema.Struct({
131
141
  input: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
132
142
  }).pipe(
133
143
  Type.object({
134
- typename: 'dxos.org/type/Trigger',
144
+ typename: 'org.dxos.type.trigger',
135
145
  version: '0.1.0',
136
146
  }),
147
+ Annotation.IconAnnotation.set({ icon: 'ph--lightning--regular', hue: 'yellow' }),
137
148
  SystemTypeAnnotation.set(true),
138
149
  );
139
150
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { DXN, Type } from '@dxos/echo';
7
+ import { DXN, Obj, Ref } from '@dxos/echo';
8
8
 
9
9
  // TODO(wittjosiah): Review this type.
10
10
  // - Should be discriminated union.
@@ -38,7 +38,7 @@ export const SubscriptionEvent = Schema.Struct({
38
38
  /**
39
39
  * Reference to the object that was changed or created.
40
40
  */
41
- subject: Type.Ref(Type.Obj),
41
+ subject: Ref.Ref(Obj.Unknown),
42
42
 
43
43
  /**
44
44
  * @deprecated
package/src/types/url.ts CHANGED
@@ -5,9 +5,9 @@
5
5
  import { type Obj } from '@dxos/echo';
6
6
 
7
7
  // TODO: use URL scheme for source?
8
- export const FUNCTIONS_META_KEY = 'dxos.org/service/function';
8
+ export const FUNCTIONS_META_KEY = 'org.dxos.service.function';
9
9
 
10
- export const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
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.