@dxos/functions 0.8.4-main.9be5663bfe → 0.8.4-main.abd8ff62ef

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 (96) hide show
  1. package/dist/lib/neutral/index.mjs +126 -917
  2. package/dist/lib/neutral/index.mjs.map +4 -4
  3. package/dist/lib/neutral/meta.json +1 -1
  4. package/dist/types/src/index.d.ts +0 -6
  5. package/dist/types/src/index.d.ts.map +1 -1
  6. package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -1
  7. package/dist/types/src/protocol/protocol.d.ts +1 -1
  8. package/dist/types/src/protocol/protocol.d.ts.map +1 -1
  9. package/dist/types/src/sdk.d.ts +3 -7
  10. package/dist/types/src/sdk.d.ts.map +1 -1
  11. package/dist/types/src/services/credentials.d.ts +15 -38
  12. package/dist/types/src/services/credentials.d.ts.map +1 -1
  13. package/dist/types/src/services/function-invocation-service.d.ts +3 -5
  14. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
  15. package/dist/types/src/services/index.d.ts +1 -4
  16. package/dist/types/src/services/index.d.ts.map +1 -1
  17. package/dist/types/src/services/queues.d.ts +1 -49
  18. package/dist/types/src/services/queues.d.ts.map +1 -1
  19. package/dist/types/src/services/tracing.d.ts +1 -107
  20. package/dist/types/src/services/tracing.d.ts.map +1 -1
  21. package/dist/types/src/types/index.d.ts +0 -3
  22. package/dist/types/src/types/index.d.ts.map +1 -1
  23. package/dist/types/src/types/url.d.ts +1 -1
  24. package/dist/types/src/types/url.d.ts.map +1 -1
  25. package/dist/types/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +15 -20
  27. package/src/index.ts +0 -6
  28. package/src/protocol/protocol.test.ts +10 -10
  29. package/src/protocol/protocol.ts +37 -12
  30. package/src/sdk.ts +5 -15
  31. package/src/services/credentials.ts +75 -118
  32. package/src/services/function-invocation-service.ts +3 -9
  33. package/src/services/index.ts +1 -4
  34. package/src/services/queues.ts +1 -87
  35. package/src/services/tracing.ts +0 -192
  36. package/src/types/index.ts +0 -3
  37. package/src/types/url.ts +1 -1
  38. package/dist/lib/neutral/Trace.mjs +0 -38
  39. package/dist/lib/neutral/Trace.mjs.map +0 -7
  40. package/dist/lib/neutral/chunk-5T7GOX2V.mjs +0 -149
  41. package/dist/lib/neutral/chunk-5T7GOX2V.mjs.map +0 -7
  42. package/dist/lib/neutral/chunk-IVDUS56O.mjs +0 -49
  43. package/dist/lib/neutral/chunk-IVDUS56O.mjs.map +0 -7
  44. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +0 -10
  45. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +0 -7
  46. package/dist/lib/neutral/fib-N45KAC7C.mjs +0 -23
  47. package/dist/lib/neutral/fib-N45KAC7C.mjs.map +0 -7
  48. package/dist/lib/neutral/reply-EUEPKNJF.mjs +0 -19
  49. package/dist/lib/neutral/reply-EUEPKNJF.mjs.map +0 -7
  50. package/dist/lib/neutral/sleep-PUK3D4FF.mjs +0 -15
  51. package/dist/lib/neutral/sleep-PUK3D4FF.mjs.map +0 -7
  52. package/dist/types/src/Trace.d.ts +0 -155
  53. package/dist/types/src/Trace.d.ts.map +0 -1
  54. package/dist/types/src/errors.d.ts +0 -121
  55. package/dist/types/src/errors.d.ts.map +0 -1
  56. package/dist/types/src/example/definitions.d.ts +0 -11
  57. package/dist/types/src/example/definitions.d.ts.map +0 -1
  58. package/dist/types/src/example/fib.d.ts +0 -8
  59. package/dist/types/src/example/fib.d.ts.map +0 -1
  60. package/dist/types/src/example/forex-effect.d.ts +0 -3
  61. package/dist/types/src/example/forex-effect.d.ts.map +0 -1
  62. package/dist/types/src/example/index.d.ts +0 -4
  63. package/dist/types/src/example/index.d.ts.map +0 -1
  64. package/dist/types/src/example/reply.d.ts +0 -4
  65. package/dist/types/src/example/reply.d.ts.map +0 -1
  66. package/dist/types/src/example/sleep.d.ts +0 -6
  67. package/dist/types/src/example/sleep.d.ts.map +0 -1
  68. package/dist/types/src/process/Process.d.ts +0 -247
  69. package/dist/types/src/process/Process.d.ts.map +0 -1
  70. package/dist/types/src/process/ServiceResolver.d.ts +0 -74
  71. package/dist/types/src/process/ServiceResolver.d.ts.map +0 -1
  72. package/dist/types/src/process/StorageService.d.ts +0 -58
  73. package/dist/types/src/process/StorageService.d.ts.map +0 -1
  74. package/dist/types/src/services/event-logger.d.ts +0 -81
  75. package/dist/types/src/services/event-logger.d.ts.map +0 -1
  76. package/dist/types/src/types/Script.d.ts +0 -22
  77. package/dist/types/src/types/Script.d.ts.map +0 -1
  78. package/dist/types/src/types/Trigger.d.ts +0 -120
  79. package/dist/types/src/types/Trigger.d.ts.map +0 -1
  80. package/dist/types/src/types/TriggerEvent.d.ts +0 -75
  81. package/dist/types/src/types/TriggerEvent.d.ts.map +0 -1
  82. package/src/Trace.ts +0 -202
  83. package/src/errors.ts +0 -21
  84. package/src/example/definitions.ts +0 -49
  85. package/src/example/fib.ts +0 -23
  86. package/src/example/forex-effect.ts +0 -40
  87. package/src/example/index.ts +0 -12
  88. package/src/example/reply.ts +0 -19
  89. package/src/example/sleep.ts +0 -17
  90. package/src/process/Process.ts +0 -486
  91. package/src/process/ServiceResolver.ts +0 -174
  92. package/src/process/StorageService.ts +0 -99
  93. package/src/services/event-logger.ts +0 -127
  94. package/src/types/Script.ts +0 -38
  95. package/src/types/Trigger.ts +0 -154
  96. package/src/types/TriggerEvent.ts +0 -62
package/src/Trace.ts DELETED
@@ -1,202 +0,0 @@
1
- //
2
- // Copyright 2026 DXOS.org
3
- //
4
-
5
- // @import-as-namespace
6
-
7
- import * as Context from 'effect/Context';
8
- import * as Effect from 'effect/Effect';
9
- import * as Layer from 'effect/Layer';
10
- import * as Schema from 'effect/Schema';
11
-
12
- import { Annotation, Obj, Type } from '@dxos/echo';
13
-
14
- /**
15
- * Writes ephemeral or persistent events to the trace.
16
- * Exposed to processes and operations to record events to the trace.
17
- */
18
- export interface TraceWriter {
19
- write<T>(eventType: EventType<T>, payload: NoInfer<T>): void;
20
- }
21
-
22
- /**
23
- * Service that writes events to the trace.
24
- * Exposed to processes and operations to record events to the trace.
25
- */
26
- export class TraceService extends Context.Tag('@dxos/functions/TraceService')<TraceService, TraceWriter>() {}
27
-
28
- /**
29
- * Writes an event to the trace.
30
- */
31
- export const write: <T>(eventType: EventType<T>, payload: NoInfer<T>) => Effect.Effect<void, never, TraceService> =
32
- Effect.serviceFunction(TraceService, (_) => _.write);
33
-
34
- /**
35
- * Defines an event type for the trace.
36
- */
37
- export interface EventType<T> {
38
- readonly key: string;
39
- readonly schema: Schema.Schema<T, any>;
40
- readonly isEphemeral: boolean;
41
- }
42
-
43
- export const EventType = <T>(
44
- key: string,
45
- opts: { schema: Schema.Schema<T, any>; isEphemeral: boolean },
46
- ): EventType<T> => {
47
- return {
48
- key,
49
- schema: opts.schema,
50
- isEphemeral: opts.isEphemeral,
51
- };
52
- };
53
-
54
- /**
55
- * Extracts the payload type from an event type.
56
- */
57
- export type PayloadType<E extends EventType<any>> = E extends EventType<infer T> ? T : never;
58
-
59
- export const Event = Schema.Struct({
60
- timestamp: Schema.Number,
61
- type: Schema.String,
62
- data: Schema.Unknown, // Type-specific payload;
63
- });
64
- export interface Event extends Schema.Schema.Type<typeof Event> {}
65
-
66
- /**
67
- * Checks if an event is of a given type.
68
- */
69
- export const isOfType = <T, E extends Event>(eventType: EventType<T>, event: E): event is E & { data: T } => {
70
- return event.type === eventType.key;
71
- };
72
-
73
- /**
74
- * Metadata on the context of a trace message.
75
- */
76
- // TODO(dmaretskyi): Expand on this: conversation id, tool call id, etc.
77
- export const Meta = Schema.Struct({
78
- pid: Schema.optional(Schema.String), // NOTE: Not Process.ID to avoid circular dependency.
79
- parentPid: Schema.optional(Schema.String),
80
- processName: Schema.optional(Schema.String),
81
- /**
82
- * ID of the conversation feed object if present.
83
- */
84
- conversationId: Schema.optional(Obj.ID),
85
-
86
- /**
87
- * ID of the trigger object if invocation resulted from a trigger.
88
- */
89
- triggerId: Schema.optional(Obj.ID),
90
- });
91
- export interface Meta extends Schema.Schema.Type<typeof Meta> {}
92
-
93
- /**
94
- * Envelope for a set of events.
95
- */
96
- export const MessageData = Schema.Struct({
97
- meta: Meta,
98
-
99
- isEphemeral: Schema.Boolean,
100
- events: Schema.Array(Event),
101
- });
102
- export interface MessageData extends Schema.Schema.Type<typeof MessageData> {}
103
-
104
- export const Message = MessageData.pipe(
105
- Type.object({
106
- typename: 'org.dxos.type.traceMessage',
107
- version: '0.1.0',
108
- }),
109
- Annotation.IconAnnotation.set({
110
- icon: 'ph--note--regular',
111
- hue: 'rose',
112
- }),
113
- );
114
- export interface Message extends Schema.Schema.Type<typeof Message> {}
115
-
116
- /**
117
- * Sink for complete trace messages.
118
- */
119
- export interface Sink {
120
- write(message: Message): void;
121
- }
122
-
123
- /**
124
- * Sink for complete trace messages.
125
- * The Process Manager forwards trace messages to it.
126
- */
127
- // TODO(dmaretskyi): Consider moving sink to the Process Manager.
128
- export class TraceSink extends Context.Tag('@dxos/functions/TraceSink')<TraceSink, Sink>() {}
129
-
130
- export const noopWriter: TraceWriter = {
131
- write: () => {},
132
- };
133
-
134
- export const writerLayerNoop: Layer.Layer<TraceService> = Layer.succeed(TraceService, noopWriter);
135
-
136
- export const layerNoop: Layer.Layer<TraceSink> = Layer.succeed(TraceSink, {
137
- write: () => {},
138
- });
139
-
140
- export const layerConsole: Layer.Layer<TraceSink> = Layer.succeed(TraceSink, {
141
- write: (message) => {
142
- console.log(message);
143
- },
144
- });
145
-
146
- export const testTraceService = (opts: { meta?: Meta } = {}): Layer.Layer<TraceService, never, TraceSink> =>
147
- Layer.effect(
148
- TraceService,
149
- Effect.gen(function* () {
150
- const sink = yield* TraceSink;
151
- return {
152
- write: (event, data) => {
153
- sink.write(
154
- Obj.make(Message, {
155
- meta: opts.meta ?? {},
156
- isEphemeral: event.isEphemeral,
157
- events: [{ type: event.key, timestamp: Date.now(), data }],
158
- }),
159
- );
160
- },
161
- };
162
- }),
163
- );
164
-
165
- //
166
- // Operation Trace Events
167
- //
168
-
169
- /**
170
- * Outcome of an operation invocation.
171
- */
172
- export type OperationOutcome = 'success' | 'failure';
173
-
174
- /**
175
- * Operation invocation started.
176
- */
177
- export const OperationStart = EventType('operation.start', {
178
- schema: Schema.Struct({
179
- /** Operation key. */
180
- key: Schema.String,
181
- /** Human-readable operation name. */
182
- name: Schema.optional(Schema.String),
183
- }),
184
- isEphemeral: false,
185
- });
186
-
187
- /**
188
- * Operation invocation ended.
189
- */
190
- export const OperationEnd = EventType('operation.end', {
191
- schema: Schema.Struct({
192
- /** Operation key. */
193
- key: Schema.String,
194
- /** Human-readable operation name. */
195
- name: Schema.optional(Schema.String),
196
- /** Outcome of the operation. */
197
- outcome: Schema.Literal('success', 'failure'),
198
- /** Error message if the operation failed. */
199
- error: Schema.optional(Schema.String),
200
- }),
201
- isEphemeral: false,
202
- });
package/src/errors.ts DELETED
@@ -1,21 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { BaseError, type BaseErrorOptions } from '@dxos/errors';
6
-
7
- export class ServiceNotAvailableError extends BaseError.extend('ServiceNotAvailable', 'Service not available') {
8
- constructor(service: string, options?: Omit<BaseErrorOptions, 'context'>) {
9
- super({ context: { service }, ...options, message: `Service not available: ${service}` });
10
- }
11
- }
12
-
13
- export class FunctionNotFoundError extends BaseError.extend('FunctionNotFound', 'Function not found') {
14
- constructor(functionKey: string, options?: Omit<BaseErrorOptions, 'context'>) {
15
- super({ context: { function: functionKey }, ...options });
16
- }
17
- }
18
-
19
- export class FunctionError extends BaseError.extend('FunctionError', 'Function invocation error') {}
20
-
21
- export class TriggerStateNotFoundError extends BaseError.extend('TriggerStateNotFound', 'Trigger state not found') {}
@@ -1,49 +0,0 @@
1
- //
2
- // Copyright 2026 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
-
7
- import { Operation } from '@dxos/operation';
8
-
9
- export const Fibonacci = Operation.make({
10
- meta: {
11
- key: 'example.org/function/fib',
12
- name: 'Fibonacci',
13
- description: 'Function that calculates a Fibonacci number',
14
- },
15
- input: Schema.Struct({
16
- iterations: Schema.optional(Schema.Number).annotations({
17
- description: 'Number of iterations',
18
- default: 100_000,
19
- }),
20
- }),
21
- output: Schema.Struct({
22
- result: Schema.String,
23
- }),
24
- });
25
-
26
- export const Reply = Operation.make({
27
- meta: {
28
- key: 'example.org/function/reply',
29
- name: 'Reply',
30
- description: 'Function that echoes the input',
31
- },
32
- input: Schema.Any,
33
- output: Schema.Any,
34
- });
35
-
36
- export const Sleep = Operation.make({
37
- meta: {
38
- key: 'example.org/function/sleep',
39
- name: 'Sleep',
40
- description: 'Function that sleeps for a given amount of time',
41
- },
42
- input: Schema.Struct({
43
- duration: Schema.optional(Schema.Number).annotations({
44
- description: 'Milliseconds to sleep',
45
- default: 100_000,
46
- }),
47
- }),
48
- output: Schema.Void,
49
- });
@@ -1,23 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Effect from 'effect/Effect';
6
-
7
- import { Operation } from '@dxos/operation';
8
-
9
- import { Fibonacci } from './definitions';
10
-
11
- export default Fibonacci.pipe(
12
- Operation.withHandler(
13
- Effect.fn(function* ({ iterations = 100_000 }) {
14
- let a = 0n;
15
- let b = 1n;
16
- for (let i = 0; i < iterations; i++) {
17
- a += b;
18
- b = a - b;
19
- }
20
- return { result: a.toString() };
21
- }),
22
- ),
23
- );
@@ -1,40 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- // @ts-ignore
6
- import { S, defineFunction } from 'dxos:functions';
7
- import {
8
- FetchHttpClient,
9
- HttpClient,
10
- HttpClientRequest,
11
- // @ts-ignore
12
- } from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';
13
- // @ts-ignore
14
- import { Effect, Schedule } from 'https://esm.sh/effect@3.17.0?bundle=false';
15
-
16
- export default defineFunction({
17
- key: 'org.dxos.script.forex-effect',
18
- name: 'Forex Effect',
19
- description: 'Returns the exchange rate between two currencies.',
20
-
21
- inputSchema: S.Struct({
22
- from: S.String.annotations({ description: 'The source currency' }),
23
- to: S.String.annotations({ description: 'The target currency' }),
24
- }),
25
-
26
- outputSchema: S.String.annotations({ description: 'The exchange rate between the two currencies' }),
27
-
28
- handler: async ({ data: { from, to } }: any) =>
29
- Effect.gen(function* () {
30
- const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(
31
- HttpClient.execute,
32
- Effect.flatMap((res: any) => res.json),
33
- Effect.timeout('1 second'),
34
- Effect.retry(Schedule.exponential(1_000).pipe(Schedule.compose(Schedule.recurs(3)))),
35
- Effect.scoped,
36
- );
37
-
38
- return res.data.rates[to].toString();
39
- }).pipe(Effect.provide(FetchHttpClient.layer)),
40
- });
@@ -1,12 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { OperationHandlerSet } from '@dxos/operation';
6
- export * from './definitions';
7
-
8
- export const ExampleHandlers = OperationHandlerSet.lazy(
9
- () => import('./fib'),
10
- () => import('./reply'),
11
- () => import('./sleep'),
12
- );
@@ -1,19 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Console from 'effect/Console';
6
- import * as Effect from 'effect/Effect';
7
-
8
- import { Operation } from '@dxos/operation';
9
-
10
- import { Reply } from './definitions';
11
-
12
- export default Reply.pipe(
13
- Operation.withHandler(
14
- Effect.fn(function* (input) {
15
- yield* Console.log('reply', { input });
16
- return input;
17
- }),
18
- ),
19
- );
@@ -1,17 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Effect from 'effect/Effect';
6
-
7
- import { Operation } from '@dxos/operation';
8
-
9
- import { Sleep } from './definitions';
10
-
11
- export default Sleep.pipe(
12
- Operation.withHandler(
13
- Effect.fn(function* ({ duration = 100_000 }) {
14
- yield* Effect.sleep(duration);
15
- }),
16
- ),
17
- );