@dxos/functions 0.8.4-main.8360d9e660 → 0.8.4-main.8baae0fced

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 (79) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/neutral/index.mjs +294 -935
  4. package/dist/lib/neutral/index.mjs.map +4 -4
  5. package/dist/lib/neutral/meta.json +1 -1
  6. package/dist/types/src/index.d.ts +0 -2
  7. package/dist/types/src/index.d.ts.map +1 -1
  8. package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -1
  9. package/dist/types/src/protocol/functions-ai-http-client.test.d.ts +2 -0
  10. package/dist/types/src/protocol/functions-ai-http-client.test.d.ts.map +1 -0
  11. package/dist/types/src/protocol/protocol.d.ts +19 -2
  12. package/dist/types/src/protocol/protocol.d.ts.map +1 -1
  13. package/dist/types/src/sdk.d.ts +5 -112
  14. package/dist/types/src/sdk.d.ts.map +1 -1
  15. package/dist/types/src/services/credentials.d.ts +15 -38
  16. package/dist/types/src/services/credentials.d.ts.map +1 -1
  17. package/dist/types/src/services/function-invocation-service.d.ts +8 -6
  18. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
  19. package/dist/types/src/services/index.d.ts +1 -4
  20. package/dist/types/src/services/index.d.ts.map +1 -1
  21. package/dist/types/src/services/queues.d.ts +1 -46
  22. package/dist/types/src/services/queues.d.ts.map +1 -1
  23. package/dist/types/src/services/tracing.d.ts +1 -84
  24. package/dist/types/src/services/tracing.d.ts.map +1 -1
  25. package/dist/types/src/types/index.d.ts +0 -4
  26. package/dist/types/src/types/index.d.ts.map +1 -1
  27. package/dist/types/src/types/url.d.ts +1 -1
  28. package/dist/types/src/types/url.d.ts.map +1 -1
  29. package/dist/types/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +18 -17
  31. package/src/index.ts +0 -2
  32. package/src/protocol/functions-ai-http-client.test.ts +105 -0
  33. package/src/protocol/functions-ai-http-client.ts +75 -1
  34. package/src/protocol/protocol.test.ts +9 -10
  35. package/src/protocol/protocol.ts +255 -58
  36. package/src/sdk.ts +12 -278
  37. package/src/services/credentials.ts +76 -120
  38. package/src/services/function-invocation-service.ts +9 -10
  39. package/src/services/index.ts +1 -4
  40. package/src/services/queues.ts +1 -78
  41. package/src/services/tracing.ts +0 -159
  42. package/src/types/index.ts +0 -4
  43. package/src/types/url.ts +1 -1
  44. package/dist/types/src/errors.d.ts +0 -121
  45. package/dist/types/src/errors.d.ts.map +0 -1
  46. package/dist/types/src/example/fib.d.ts +0 -7
  47. package/dist/types/src/example/fib.d.ts.map +0 -1
  48. package/dist/types/src/example/forex-effect.d.ts +0 -3
  49. package/dist/types/src/example/forex-effect.d.ts.map +0 -1
  50. package/dist/types/src/example/index.d.ts +0 -12
  51. package/dist/types/src/example/index.d.ts.map +0 -1
  52. package/dist/types/src/example/reply.d.ts +0 -3
  53. package/dist/types/src/example/reply.d.ts.map +0 -1
  54. package/dist/types/src/example/sleep.d.ts +0 -5
  55. package/dist/types/src/example/sleep.d.ts.map +0 -1
  56. package/dist/types/src/operation-compatibility.test.d.ts +0 -2
  57. package/dist/types/src/operation-compatibility.test.d.ts.map +0 -1
  58. package/dist/types/src/services/event-logger.d.ts +0 -81
  59. package/dist/types/src/services/event-logger.d.ts.map +0 -1
  60. package/dist/types/src/types/Function.d.ts +0 -52
  61. package/dist/types/src/types/Function.d.ts.map +0 -1
  62. package/dist/types/src/types/Script.d.ts +0 -21
  63. package/dist/types/src/types/Script.d.ts.map +0 -1
  64. package/dist/types/src/types/Trigger.d.ts +0 -122
  65. package/dist/types/src/types/Trigger.d.ts.map +0 -1
  66. package/dist/types/src/types/TriggerEvent.d.ts +0 -75
  67. package/dist/types/src/types/TriggerEvent.d.ts.map +0 -1
  68. package/src/errors.ts +0 -21
  69. package/src/example/fib.ts +0 -32
  70. package/src/example/forex-effect.ts +0 -40
  71. package/src/example/index.ts +0 -13
  72. package/src/example/reply.ts +0 -21
  73. package/src/example/sleep.ts +0 -24
  74. package/src/operation-compatibility.test.ts +0 -185
  75. package/src/services/event-logger.ts +0 -127
  76. package/src/types/Function.ts +0 -83
  77. package/src/types/Script.ts +0 -38
  78. package/src/types/Trigger.ts +0 -154
  79. package/src/types/TriggerEvent.ts +0 -62
@@ -1,83 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
-
7
- import { Annotation, JsonSchema, Obj, Ref, Type } from '@dxos/echo';
8
- import { SystemTypeAnnotation } from '@dxos/echo/internal';
9
-
10
- import { Script } from './Script';
11
-
12
- /**
13
- * Function deployment.
14
- */
15
- export const Function = Schema.Struct({
16
- /**
17
- * Global registry ID.
18
- * NOTE: The `key` property refers to the original registry entry.
19
- */
20
- // TODO(burdon): Create Format type for DXN-like ids, such as this and schema type.
21
- // TODO(dmaretskyi): Consider making it part of ECHO meta.
22
- // TODO(dmaretskyi): Make required.
23
- key: Schema.optional(Schema.String).annotations({
24
- description: 'Unique registration key for the blueprint',
25
- }),
26
-
27
- name: Schema.NonEmptyString,
28
- version: Schema.String,
29
-
30
- description: Schema.optional(Schema.String),
31
-
32
- /**
33
- * ISO date string of the last deployment.
34
- */
35
- updated: Schema.optional(Schema.String),
36
-
37
- // Reference to a source script if it exists within ECHO.
38
- // TODO(burdon): Don't ref ScriptType directly (core).
39
- source: Schema.optional(Ref.Ref(Script)),
40
-
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)),
49
-
50
- // Local binding to a function name.
51
- binding: Schema.optional(Schema.String),
52
- }).pipe(
53
- Type.object({
54
- typename: 'org.dxos.type.function',
55
- version: '0.1.0',
56
- }),
57
- Annotation.LabelAnnotation.set(['name']),
58
- Annotation.IconAnnotation.set({ icon: 'ph--function--regular', hue: 'blue' }),
59
- SystemTypeAnnotation.set(true),
60
- );
61
-
62
- export interface Function extends Schema.Schema.Type<typeof Function> {}
63
-
64
- export const make = (props: Obj.MakeProps<typeof Function>) => Obj.make(Function, props);
65
-
66
- /**
67
- * Copies properties from source to target.
68
- * @param target - Target object to copy properties to.
69
- * @param source - Source object to copy properties from.
70
- */
71
- export const setFrom = (target: Function, source: Function) => {
72
- Obj.change(target, (t) => {
73
- t.key = source.key ?? target.key;
74
- t.name = source.name ?? target.name;
75
- t.version = source.version;
76
- t.description = source.description;
77
- t.updated = source.updated;
78
- // TODO(dmaretskyi): A workaround for an ECHO bug.
79
- t.inputSchema = source.inputSchema ? JSON.parse(JSON.stringify(source.inputSchema)) : undefined;
80
- t.outputSchema = source.outputSchema ? JSON.parse(JSON.stringify(source.outputSchema)) : undefined;
81
- Obj.getMeta(t).keys = JSON.parse(JSON.stringify(Obj.getMeta(source).keys));
82
- });
83
- };
@@ -1,38 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
-
7
- import { Annotation, Obj, Ref, Type } from '@dxos/echo';
8
- import { FormInputAnnotation } from '@dxos/echo/internal';
9
- import { Text } from '@dxos/schema';
10
-
11
- /**
12
- * Source script.
13
- */
14
- export const Script = Schema.Struct({
15
- name: Schema.String.pipe(Schema.optional),
16
- description: Schema.String.pipe(Schema.optional),
17
- // TODO(burdon): Change to hash of deployed content.
18
- // Whether source has changed since last deploy.
19
- changed: Schema.Boolean.pipe(FormInputAnnotation.set(false), Schema.optional),
20
- source: Ref.Ref(Text.Text).pipe(FormInputAnnotation.set(false)),
21
- }).pipe(
22
- Type.object({
23
- typename: 'org.dxos.type.script',
24
- version: '0.1.0',
25
- }),
26
- Annotation.LabelAnnotation.set(['name']),
27
- Annotation.IconAnnotation.set({
28
- icon: 'ph--code--regular',
29
- hue: 'sky',
30
- }),
31
- );
32
-
33
- export interface Script extends Schema.Schema.Type<typeof Script> {}
34
-
35
- type Props = Omit<Obj.MakeProps<typeof Script>, 'source'> & { source?: string };
36
-
37
- export const make = ({ source = '', ...props }: Props = {}): Script =>
38
- Obj.make(Script, { ...props, source: Ref.make(Text.make(source)) });
@@ -1,154 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
- import * as SchemaAST from 'effect/SchemaAST';
7
-
8
- import { Annotation, Obj, QueryAST, Ref, Type } from '@dxos/echo';
9
- import { OptionsAnnotationId, SystemTypeAnnotation } from '@dxos/echo/internal';
10
- import { DXN } from '@dxos/keys';
11
- import { Expando } from '@dxos/schema';
12
-
13
- /**
14
- * Type discriminator for TriggerType.
15
- * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
16
- * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
17
- */
18
- export const Kinds = ['email', 'queue', 'subscription', 'timer', 'webhook'] as const;
19
- export type Kind = (typeof Kinds)[number];
20
-
21
- const kindLiteralAnnotations = { title: 'Kind' };
22
-
23
- export const EmailSpec = Schema.Struct({
24
- kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
25
- });
26
- export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
27
-
28
- // TODO(wittjosiah): Remove. Migrate to Subscription triggers once EDGE supports them for feed queries.
29
- export const QueueSpec = Schema.Struct({
30
- kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
31
-
32
- // TODO(dmaretskyi): Change to a reference.
33
- queue: DXN.Schema,
34
- });
35
- export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
36
-
37
- /**
38
- * Subscription.
39
- */
40
- export const SubscriptionSpec = Schema.Struct({
41
- kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
42
- query: Schema.Struct({
43
- raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
44
- ast: QueryAST.Query,
45
- }),
46
- options: Schema.optional(
47
- Schema.Struct({
48
- // Watch changes to object (not just creation).
49
- deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
50
- // Debounce changes (delay in ms).
51
- delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
52
- }).annotations({ title: 'Options' }),
53
- ),
54
- });
55
- export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
56
-
57
- /**
58
- * Cron timer.
59
- */
60
- export const TimerSpec = Schema.Struct({
61
- kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
62
- cron: Schema.String.annotations({
63
- title: 'Cron',
64
- [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
65
- }),
66
- });
67
- export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
68
-
69
- /**
70
- * Webhook.
71
- */
72
- export const WebhookSpec = Schema.Struct({
73
- kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
74
- method: Schema.optional(
75
- Schema.String.annotations({
76
- title: 'Method',
77
- [OptionsAnnotationId]: ['GET', 'POST'],
78
- }),
79
- ),
80
- port: Schema.optional(
81
- Schema.Number.annotations({
82
- title: 'Port',
83
- }),
84
- ),
85
- });
86
- export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
87
-
88
- /**
89
- * Trigger schema.
90
- */
91
- export const Spec = Schema.Union(EmailSpec, QueueSpec, SubscriptionSpec, TimerSpec, WebhookSpec).annotations({
92
- title: 'Trigger',
93
- });
94
- export type Spec = Schema.Schema.Type<typeof Spec>;
95
-
96
- /**
97
- * Function trigger.
98
- * Function is invoked with the `payload` passed as input data.
99
- * The event that triggers the function is available in the function context.
100
- */
101
- const TriggerSchema = Schema.Struct({
102
- /**
103
- * Function or workflow to invoke.
104
- */
105
- // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
106
- function: Schema.optional(Ref.Ref(Expando.Expando).annotations({ title: 'Function' })),
107
-
108
- /**
109
- * Only used for workflowSchema.
110
- * Specifies the input node in the circuit.
111
- * @deprecated Remove and enforce a single input node in all compute graphSchema.
112
- */
113
- inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
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.
117
- enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
118
-
119
- spec: Schema.optional(Spec),
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
-
130
- /**
131
- * Passed as the input data to the function.
132
- * Must match the function's input schema.
133
- *
134
- * @example
135
- * {
136
- * item: '{{event.item}}',
137
- * instructions: 'Summarize and perform entity-extraction'
138
- * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
139
- * }
140
- */
141
- input: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
142
- }).pipe(
143
- Type.object({
144
- typename: 'org.dxos.type.trigger',
145
- version: '0.1.0',
146
- }),
147
- Annotation.IconAnnotation.set({ icon: 'ph--lightning--regular', hue: 'yellow' }),
148
- SystemTypeAnnotation.set(true),
149
- );
150
-
151
- export interface Trigger extends Schema.Schema.Type<typeof TriggerSchema> {}
152
- export const Trigger: Type.Obj<Trigger> = TriggerSchema as any;
153
-
154
- export const make = (props: Obj.MakeProps<typeof Trigger>) => Obj.make(Trigger, props);
@@ -1,62 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
-
7
- import { DXN, Obj, Ref } from '@dxos/echo';
8
-
9
- // TODO(wittjosiah): Review this type.
10
- // - Should be discriminated union.
11
- // - Should be more consistent (e.g. subject vs item).
12
- // - Should re-use schemas if possible.
13
-
14
- // TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
15
- export const EmailEvent = Schema.Struct({
16
- from: Schema.String,
17
- to: Schema.String,
18
- subject: Schema.String,
19
- created: Schema.String,
20
- body: Schema.String,
21
- });
22
- export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
23
-
24
- export const QueueEvent = Schema.Struct({
25
- queue: DXN.Schema,
26
- item: Schema.Any,
27
- cursor: Schema.String,
28
- });
29
- export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
30
-
31
- export const SubscriptionEvent = Schema.Struct({
32
- /**
33
- * Type of the mutation.
34
- */
35
- // TODO(dmaretskyi): Specify enum.
36
- type: Schema.String,
37
-
38
- /**
39
- * Reference to the object that was changed or created.
40
- */
41
- subject: Ref.Ref(Obj.Unknown),
42
-
43
- /**
44
- * @deprecated
45
- */
46
- changedObjectId: Schema.optional(Schema.String),
47
- });
48
- export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
49
-
50
- export const TimerEvent = Schema.Struct({ tick: Schema.Number });
51
- export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
52
-
53
- export const WebhookEvent = Schema.Struct({
54
- url: Schema.String,
55
- method: Schema.Literal('GET', 'POST'),
56
- headers: Schema.Record({ key: Schema.String, value: Schema.String }),
57
- bodyText: Schema.String,
58
- });
59
- export type WebhookEvent = Schema.Schema.Type<typeof WebhookEvent>;
60
-
61
- export const TriggerEvent = Schema.Union(EmailEvent, QueueEvent, SubscriptionEvent, TimerEvent, WebhookEvent);
62
- export type TriggerEvent = Schema.Schema.Type<typeof TriggerEvent>;