@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.
Files changed (106) hide show
  1. package/README.md +4 -6
  2. package/dist/lib/neutral/Trace.mjs +38 -0
  3. package/dist/lib/neutral/Trace.mjs.map +7 -0
  4. package/dist/lib/neutral/chunk-5T7GOX2V.mjs +149 -0
  5. package/dist/lib/neutral/chunk-5T7GOX2V.mjs.map +7 -0
  6. package/dist/lib/neutral/chunk-IVDUS56O.mjs +49 -0
  7. package/dist/lib/neutral/chunk-IVDUS56O.mjs.map +7 -0
  8. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  9. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  10. package/dist/lib/neutral/fib-N45KAC7C.mjs +23 -0
  11. package/dist/lib/neutral/fib-N45KAC7C.mjs.map +7 -0
  12. package/dist/lib/neutral/index.mjs +1266 -0
  13. package/dist/lib/neutral/index.mjs.map +7 -0
  14. package/dist/lib/neutral/meta.json +1 -0
  15. package/dist/lib/neutral/reply-EUEPKNJF.mjs +19 -0
  16. package/dist/lib/neutral/reply-EUEPKNJF.mjs.map +7 -0
  17. package/dist/lib/neutral/sleep-PUK3D4FF.mjs +15 -0
  18. package/dist/lib/neutral/sleep-PUK3D4FF.mjs.map +7 -0
  19. package/dist/types/src/Trace.d.ts +155 -0
  20. package/dist/types/src/Trace.d.ts.map +1 -0
  21. package/dist/types/src/errors.d.ts +24 -32
  22. package/dist/types/src/errors.d.ts.map +1 -1
  23. package/dist/types/src/example/definitions.d.ts +11 -0
  24. package/dist/types/src/example/definitions.d.ts.map +1 -0
  25. package/dist/types/src/example/fib.d.ts +3 -2
  26. package/dist/types/src/example/fib.d.ts.map +1 -1
  27. package/dist/types/src/example/index.d.ts +3 -11
  28. package/dist/types/src/example/index.d.ts.map +1 -1
  29. package/dist/types/src/example/reply.d.ts +2 -1
  30. package/dist/types/src/example/reply.d.ts.map +1 -1
  31. package/dist/types/src/example/sleep.d.ts +3 -2
  32. package/dist/types/src/example/sleep.d.ts.map +1 -1
  33. package/dist/types/src/index.d.ts +4 -0
  34. package/dist/types/src/index.d.ts.map +1 -1
  35. package/dist/types/src/process/Process.d.ts +247 -0
  36. package/dist/types/src/process/Process.d.ts.map +1 -0
  37. package/dist/types/src/process/ServiceResolver.d.ts +74 -0
  38. package/dist/types/src/process/ServiceResolver.d.ts.map +1 -0
  39. package/dist/types/src/process/StorageService.d.ts +58 -0
  40. package/dist/types/src/process/StorageService.d.ts.map +1 -0
  41. package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
  42. package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
  43. package/dist/types/src/protocol/protocol.d.ts +2 -2
  44. package/dist/types/src/protocol/protocol.d.ts.map +1 -1
  45. package/dist/types/src/sdk.d.ts +4 -79
  46. package/dist/types/src/sdk.d.ts.map +1 -1
  47. package/dist/types/src/services/credentials.d.ts +6 -4
  48. package/dist/types/src/services/credentials.d.ts.map +1 -1
  49. package/dist/types/src/services/event-logger.d.ts +25 -31
  50. package/dist/types/src/services/event-logger.d.ts.map +1 -1
  51. package/dist/types/src/services/function-invocation-service.d.ts +9 -3
  52. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
  53. package/dist/types/src/services/index.d.ts +0 -1
  54. package/dist/types/src/services/index.d.ts.map +1 -1
  55. package/dist/types/src/services/queues.d.ts +8 -5
  56. package/dist/types/src/services/queues.d.ts.map +1 -1
  57. package/dist/types/src/services/tracing.d.ts +61 -4
  58. package/dist/types/src/services/tracing.d.ts.map +1 -1
  59. package/dist/types/src/types/Script.d.ts +10 -16
  60. package/dist/types/src/types/Script.d.ts.map +1 -1
  61. package/dist/types/src/types/Trigger.d.ts +57 -76
  62. package/dist/types/src/types/Trigger.d.ts.map +1 -1
  63. package/dist/types/src/types/TriggerEvent.d.ts +44 -13
  64. package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
  65. package/dist/types/src/types/index.d.ts +0 -1
  66. package/dist/types/src/types/index.d.ts.map +1 -1
  67. package/dist/types/src/types/url.d.ts +6 -5
  68. package/dist/types/src/types/url.d.ts.map +1 -1
  69. package/dist/types/tsconfig.tsbuildinfo +1 -1
  70. package/package.json +29 -17
  71. package/src/Trace.ts +202 -0
  72. package/src/errors.ts +5 -5
  73. package/src/example/definitions.ts +49 -0
  74. package/src/example/fib.ts +15 -24
  75. package/src/example/forex-effect.ts +1 -1
  76. package/src/example/index.ts +7 -8
  77. package/src/example/reply.ts +11 -13
  78. package/src/example/sleep.ts +9 -16
  79. package/src/index.ts +4 -0
  80. package/src/process/Process.ts +486 -0
  81. package/src/process/ServiceResolver.ts +174 -0
  82. package/src/process/StorageService.ts +99 -0
  83. package/src/protocol/functions-ai-http-client.ts +67 -0
  84. package/src/protocol/protocol.test.ts +0 -1
  85. package/src/protocol/protocol.ts +206 -84
  86. package/src/sdk.ts +7 -194
  87. package/src/services/credentials.ts +31 -15
  88. package/src/services/event-logger.ts +2 -2
  89. package/src/services/function-invocation-service.ts +19 -3
  90. package/src/services/index.ts +0 -2
  91. package/src/services/queues.ts +15 -8
  92. package/src/services/tracing.ts +97 -5
  93. package/src/types/Script.ts +14 -9
  94. package/src/types/Trigger.ts +33 -18
  95. package/src/types/TriggerEvent.ts +29 -29
  96. package/src/types/index.ts +0 -1
  97. package/src/types/url.ts +6 -5
  98. package/dist/lib/browser/index.mjs +0 -927
  99. package/dist/lib/browser/index.mjs.map +0 -7
  100. package/dist/lib/browser/meta.json +0 -1
  101. package/dist/lib/node-esm/index.mjs +0 -928
  102. package/dist/lib/node-esm/index.mjs.map +0 -7
  103. package/dist/lib/node-esm/meta.json +0 -1
  104. package/dist/types/src/types/Function.d.ts +0 -58
  105. package/dist/types/src/types/Function.d.ts.map +0 -1
  106. package/src/types/Function.ts +0 -62
@@ -1,28 +1,26 @@
1
1
  import { BaseError, type BaseErrorOptions } from '@dxos/errors';
2
2
  declare const ServiceNotAvailableError_base: {
3
3
  new (options?: BaseErrorOptions): {
4
- code: "SERVICE_NOT_AVAILABLE";
4
+ name: "ServiceNotAvailable";
5
5
  context: Record<string, unknown>;
6
- readonly name: "SERVICE_NOT_AVAILABLE";
7
6
  readonly message: string;
8
- readonly _tag: "SERVICE_NOT_AVAILABLE";
7
+ readonly _tag: "ServiceNotAvailable";
9
8
  stack?: string;
10
9
  cause?: unknown;
11
10
  };
12
- code: "SERVICE_NOT_AVAILABLE";
11
+ name: "ServiceNotAvailable";
13
12
  is(error: unknown): error is BaseError;
14
13
  wrap(options?: Omit<BaseErrorOptions, "cause"> & {
15
14
  ifTypeDiffers?: boolean;
16
15
  }): (error: unknown) => {
17
- code: "SERVICE_NOT_AVAILABLE";
16
+ name: "ServiceNotAvailable";
18
17
  context: Record<string, unknown>;
19
- readonly name: "SERVICE_NOT_AVAILABLE";
20
18
  readonly message: string;
21
- readonly _tag: "SERVICE_NOT_AVAILABLE";
19
+ readonly _tag: "ServiceNotAvailable";
22
20
  stack?: string;
23
21
  cause?: unknown;
24
22
  };
25
- extend<Code extends string = string>(code: Code, message?: string): any;
23
+ extend<Name extends string = string>(name: Name, message?: string): any;
26
24
  isError(error: unknown): error is Error;
27
25
  captureStackTrace(targetObject: object, constructorOpt?: Function): void;
28
26
  prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
@@ -33,28 +31,26 @@ export declare class ServiceNotAvailableError extends ServiceNotAvailableError_b
33
31
  }
34
32
  declare const FunctionNotFoundError_base: {
35
33
  new (options?: BaseErrorOptions): {
36
- code: "FUNCTION_NOT_FOUND";
34
+ name: "FunctionNotFound";
37
35
  context: Record<string, unknown>;
38
- readonly name: "FUNCTION_NOT_FOUND";
39
36
  readonly message: string;
40
- readonly _tag: "FUNCTION_NOT_FOUND";
37
+ readonly _tag: "FunctionNotFound";
41
38
  stack?: string;
42
39
  cause?: unknown;
43
40
  };
44
- code: "FUNCTION_NOT_FOUND";
41
+ name: "FunctionNotFound";
45
42
  is(error: unknown): error is BaseError;
46
43
  wrap(options?: Omit<BaseErrorOptions, "cause"> & {
47
44
  ifTypeDiffers?: boolean;
48
45
  }): (error: unknown) => {
49
- code: "FUNCTION_NOT_FOUND";
46
+ name: "FunctionNotFound";
50
47
  context: Record<string, unknown>;
51
- readonly name: "FUNCTION_NOT_FOUND";
52
48
  readonly message: string;
53
- readonly _tag: "FUNCTION_NOT_FOUND";
49
+ readonly _tag: "FunctionNotFound";
54
50
  stack?: string;
55
51
  cause?: unknown;
56
52
  };
57
- extend<Code extends string = string>(code: Code, message?: string): any;
53
+ extend<Name extends string = string>(name: Name, message?: string): any;
58
54
  isError(error: unknown): error is Error;
59
55
  captureStackTrace(targetObject: object, constructorOpt?: Function): void;
60
56
  prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
@@ -65,28 +61,26 @@ export declare class FunctionNotFoundError extends FunctionNotFoundError_base {
65
61
  }
66
62
  declare const FunctionError_base: {
67
63
  new (options?: BaseErrorOptions): {
68
- code: "FUNCTION_ERROR";
64
+ name: "FunctionError";
69
65
  context: Record<string, unknown>;
70
- readonly name: "FUNCTION_ERROR";
71
66
  readonly message: string;
72
- readonly _tag: "FUNCTION_ERROR";
67
+ readonly _tag: "FunctionError";
73
68
  stack?: string;
74
69
  cause?: unknown;
75
70
  };
76
- code: "FUNCTION_ERROR";
71
+ name: "FunctionError";
77
72
  is(error: unknown): error is BaseError;
78
73
  wrap(options?: Omit<BaseErrorOptions, "cause"> & {
79
74
  ifTypeDiffers?: boolean;
80
75
  }): (error: unknown) => {
81
- code: "FUNCTION_ERROR";
76
+ name: "FunctionError";
82
77
  context: Record<string, unknown>;
83
- readonly name: "FUNCTION_ERROR";
84
78
  readonly message: string;
85
- readonly _tag: "FUNCTION_ERROR";
79
+ readonly _tag: "FunctionError";
86
80
  stack?: string;
87
81
  cause?: unknown;
88
82
  };
89
- extend<Code extends string = string>(code: Code, message?: string): any;
83
+ extend<Name extends string = string>(name: Name, message?: string): any;
90
84
  isError(error: unknown): error is Error;
91
85
  captureStackTrace(targetObject: object, constructorOpt?: Function): void;
92
86
  prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
@@ -96,28 +90,26 @@ export declare class FunctionError extends FunctionError_base {
96
90
  }
97
91
  declare const TriggerStateNotFoundError_base: {
98
92
  new (options?: BaseErrorOptions): {
99
- code: "TRIGGER_STATE_NOT_FOUND";
93
+ name: "TriggerStateNotFound";
100
94
  context: Record<string, unknown>;
101
- readonly name: "TRIGGER_STATE_NOT_FOUND";
102
95
  readonly message: string;
103
- readonly _tag: "TRIGGER_STATE_NOT_FOUND";
96
+ readonly _tag: "TriggerStateNotFound";
104
97
  stack?: string;
105
98
  cause?: unknown;
106
99
  };
107
- code: "TRIGGER_STATE_NOT_FOUND";
100
+ name: "TriggerStateNotFound";
108
101
  is(error: unknown): error is BaseError;
109
102
  wrap(options?: Omit<BaseErrorOptions, "cause"> & {
110
103
  ifTypeDiffers?: boolean;
111
104
  }): (error: unknown) => {
112
- code: "TRIGGER_STATE_NOT_FOUND";
105
+ name: "TriggerStateNotFound";
113
106
  context: Record<string, unknown>;
114
- readonly name: "TRIGGER_STATE_NOT_FOUND";
115
107
  readonly message: string;
116
- readonly _tag: "TRIGGER_STATE_NOT_FOUND";
108
+ readonly _tag: "TriggerStateNotFound";
117
109
  stack?: string;
118
110
  cause?: unknown;
119
111
  };
120
- extend<Code extends string = string>(code: Code, message?: string): any;
112
+ extend<Name extends string = string>(name: Name, message?: string): any;
121
113
  isError(error: unknown): error is Error;
122
114
  captureStackTrace(targetObject: object, constructorOpt?: Function): void;
123
115
  prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,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,8BAAmE;CAAG"}
@@ -0,0 +1,11 @@
1
+ import { Operation } from '@dxos/operation';
2
+ export declare const Fibonacci: Operation.Definition<{
3
+ readonly iterations?: number | undefined;
4
+ }, {
5
+ readonly result: string;
6
+ }, never>;
7
+ export declare const Reply: Operation.Definition<any, any, never>;
8
+ export declare const Sleep: Operation.Definition<{
9
+ readonly duration?: number | undefined;
10
+ }, void, never>;
11
+ //# sourceMappingURL=definitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../../../src/example/definitions.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,eAAO,MAAM,SAAS;;;;SAepB,CAAC;AAEH,eAAO,MAAM,KAAK,uCAQhB,CAAC;AAEH,eAAO,MAAM,KAAK;;eAahB,CAAC"}
@@ -1,7 +1,8 @@
1
- declare const _default: import("..").FunctionDefinition<{
1
+ import { Operation } from '@dxos/operation';
2
+ declare const _default: Operation.WithHandler<Operation.Definition<{
2
3
  readonly iterations?: number | undefined;
3
4
  }, {
4
5
  readonly result: string;
5
- }, import("..").FunctionServices>;
6
+ }, never>>;
6
7
  export default _default;
7
8
  //# sourceMappingURL=fib.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fib.d.ts","sourceRoot":"","sources":["../../../../src/example/fib.ts"],"names":[],"mappings":";;;;;AASA,wBAsBG"}
1
+ {"version":3,"file":"fib.d.ts","sourceRoot":"","sources":["../../../../src/example/fib.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;;;;;;AAI5C,wBAYE"}
@@ -1,12 +1,4 @@
1
- export declare namespace Example {
2
- const fib: import("..").FunctionDefinition<{
3
- readonly iterations?: number | undefined;
4
- }, {
5
- readonly result: string;
6
- }, import("..").FunctionServices>;
7
- const reply: import("..").FunctionDefinition<any, any, import("..").FunctionServices>;
8
- const sleep: import("..").FunctionDefinition<{
9
- readonly duration?: number | undefined;
10
- }, void, import("..").FunctionServices>;
11
- }
1
+ import { OperationHandlerSet } from '@dxos/operation';
2
+ export * from './definitions';
3
+ export declare const ExampleHandlers: OperationHandlerSet.OperationHandlerSet;
12
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/example/index.ts"],"names":[],"mappings":"AAQA,yBAAiB,OAAO,CAAC;IAChB,MAAM,GAAG;;;;qCAAO,CAAC;IACjB,MAAM,KAAK,0EAAS,CAAC;IACrB,MAAM,KAAK;;2CAAS,CAAC;CAC7B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/example/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,cAAc,eAAe,CAAC;AAE9B,eAAO,MAAM,eAAe,yCAI3B,CAAC"}
@@ -1,3 +1,4 @@
1
- declare const _default: import("..").FunctionDefinition<any, any, import("..").FunctionServices>;
1
+ import { Operation } from '@dxos/operation';
2
+ declare const _default: Operation.WithHandler<Operation.Definition<any, any, never>>;
2
3
  export default _default;
3
4
  //# sourceMappingURL=reply.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reply.d.ts","sourceRoot":"","sources":["../../../../src/example/reply.ts"],"names":[],"mappings":";AAUA,wBAUG"}
1
+ {"version":3,"file":"reply.d.ts","sourceRoot":"","sources":["../../../../src/example/reply.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;;AAI5C,wBAOE"}
@@ -1,5 +1,6 @@
1
- declare const _default: import("..").FunctionDefinition<{
1
+ import { Operation } from '@dxos/operation';
2
+ declare const _default: Operation.WithHandler<Operation.Definition<{
2
3
  readonly duration?: number | undefined;
3
- }, void, import("..").FunctionServices>;
4
+ }, void, never>>;
4
5
  export default _default;
5
6
  //# sourceMappingURL=sleep.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../../../src/example/sleep.ts"],"names":[],"mappings":";;;AASA,wBAcG"}
1
+ {"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../../../src/example/sleep.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;;;;AAI5C,wBAME"}
@@ -1,7 +1,11 @@
1
1
  export * from './errors';
2
2
  export * from './example';
3
+ export * as Process from './process/Process';
4
+ export * as ServiceResolver from './process/ServiceResolver';
5
+ export * from './process/StorageService';
3
6
  export * from './sdk';
4
7
  export * from './services';
5
8
  export * from './types';
6
9
  export * from './protocol';
10
+ export * as Trace from './Trace';
7
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,eAAe,MAAM,2BAA2B,CAAC;AAC7D,cAAc,0BAA0B,CAAC;AACzC,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC"}
@@ -0,0 +1,247 @@
1
+ import type { Atom } from '@effect-atom/atom';
2
+ import * as Context from 'effect/Context';
3
+ import * as Effect from 'effect/Effect';
4
+ import type * as Exit from 'effect/Exit';
5
+ import * as Option from 'effect/Option';
6
+ import * as Schema from 'effect/Schema';
7
+ import * as Scope from 'effect/Scope';
8
+ import type * as Types from 'effect/Types';
9
+ import { Operation, OperationHandlerSet } from '@dxos/operation';
10
+ import type { ObjectId } from '@dxos/protocols';
11
+ import type { TracingService } from '../services/tracing';
12
+ import * as Trace from '../Trace';
13
+ /** Opaque process id (arbitrary string). */
14
+ export declare const ID: Schema.brand<typeof Schema.String, "ProcessId">;
15
+ export type ID = Schema.Schema.Type<typeof ID>;
16
+ /**
17
+ * A running process callbacks.
18
+ *
19
+ * Process lifecycle: Initial -> Running <-> Suspended -> Terminated.
20
+ *
21
+ * - onSpawn -> called once when the process is spawned.
22
+ * - onInput -> called for every input submitted to the process.
23
+ * - onAlarm -> called for processes scheduling alarms.
24
+ * - onChildEvent -> called when child process produces output or exits.
25
+ */
26
+ export interface Callbacks<I, O, R> {
27
+ /**
28
+ * Called when the process is spawned.
29
+ * Not called for processes that are resumed from a previously suspended state.
30
+ *
31
+ * @returns A signal indicating to the runtime whether the process is finished, or should be resumed later.
32
+ * @throws Throwing in the handler will terminate the process with an error.
33
+ *
34
+ * Note: This function should aim to complete in under 5 seconds to avoid exceeding limits in serverless environments.
35
+ */
36
+ onSpawn(): Effect.Effect<void, never, R | BaseServices>;
37
+ /**
38
+ * Called when there's input available to process.
39
+ *
40
+ * The function can be called in parallel.
41
+ *
42
+ * @returns A signal indicating to the runtime whether the process is finished, or should be resumed later.
43
+ * @throws Throwing in the handler will terminate the process with an error.
44
+ *
45
+ * Note: This function should aim to complete in under 5 seconds to avoid exceeding limits in serverless environments.
46
+ */
47
+ onInput(input: I): Effect.Effect<void, never, R | BaseServices>;
48
+ /**
49
+ * Called when the process's alarm is triggered.
50
+ *
51
+ * @throws Throwing in the handler will terminate the process with an error.
52
+ */
53
+ onAlarm(): Effect.Effect<void, never, R | BaseServices>;
54
+ /**
55
+ * Called when the process's child process produces output or exits.
56
+ *
57
+ * This allows the parent process to hibernate while a long-running child process is running.
58
+ */
59
+ onChildEvent(event: ChildEvent<unknown>): Effect.Effect<void, never, R | BaseServices>;
60
+ }
61
+ /**
62
+ * Services that are always available to all processes.
63
+ */
64
+ export type BaseServices = TracingService | Trace.TraceService;
65
+ export type ChildEvent<T> = {
66
+ readonly _tag: 'output';
67
+ readonly pid: ID;
68
+ readonly data: T;
69
+ } | {
70
+ readonly _tag: 'exited';
71
+ readonly pid: ID;
72
+ readonly result: Exit.Exit<void>;
73
+ };
74
+ export interface ProcessContext<I, O> {
75
+ readonly id: ID;
76
+ /**
77
+ * Parameters assigned during process creation.
78
+ */
79
+ readonly params: Params;
80
+ /**
81
+ * Complete this process with sucessful result.
82
+ * No additional events will be pushed to the process.
83
+ */
84
+ succeed(): void;
85
+ /**
86
+ * Complete this process with an error.
87
+ * No additional events will be pushed to the process.
88
+ */
89
+ fail(error: Error): void;
90
+ /**
91
+ * Submit output of the process.
92
+ */
93
+ submitOutput(output: O): void;
94
+ /**
95
+ * Set an alarm for the process to be woken up later.
96
+ *
97
+ * @param timeout - Optional timeout in milliseconds. If not provided, the process is woken up as soon as possible.
98
+ */
99
+ setAlarm(timeout?: number): void;
100
+ }
101
+ /**
102
+ * Generic parameters for a all processes.
103
+ */
104
+ export interface Params {
105
+ /**
106
+ * Process name for debugging purposes.
107
+ */
108
+ readonly name: string | null;
109
+ /**
110
+ * Target object that this process is assigned to.
111
+ */
112
+ readonly target: ObjectId | null;
113
+ }
114
+ export declare const ProcessTypeId: "~@dxos/functions/Process";
115
+ export type ProcessTypeId = typeof ProcessTypeId;
116
+ /**
117
+ * A process (factory).
118
+ * Can be instantiated mutlitple times to produce new runtime instance with separate state and callbacks.
119
+ * `create` is used to instantiate a new process.
120
+ * Can store runtime state in scope of `create` function.
121
+ */
122
+ export interface Process<I, O, R> extends Process.Variance<I, O, R> {
123
+ /**
124
+ * Unique identifier for the executable in the reverse DNS format.
125
+ */
126
+ readonly key: string;
127
+ /**
128
+ * Human-readable label from {@link MakeExecutableOpts.name} when provided.
129
+ */
130
+ readonly name?: string;
131
+ readonly services: readonly Context.Tag<any, any>[];
132
+ /**
133
+ * Create a new instance of the process.
134
+ */
135
+ create(ctx: ProcessContext<I, O>): Effect.Effect<Callbacks<I, O, R>, never, R | BaseServices | Scope.Scope>;
136
+ }
137
+ export declare const isProcess: (executable: unknown) => executable is Process.Any;
138
+ export declare namespace Process {
139
+ interface Variance<I, O, R> {
140
+ readonly [ProcessTypeId]: {
141
+ readonly _Input: Types.Contravariant<I>;
142
+ readonly _Output: Types.Covariant<O>;
143
+ readonly _Requirements: Types.Covariant<R>;
144
+ };
145
+ }
146
+ type Any = Process<any, any, never>;
147
+ }
148
+ export interface MakeProcessOpts {
149
+ /**
150
+ * Unique identifier for the process in the reverse DNS format.
151
+ */
152
+ readonly key: string;
153
+ readonly input: Schema.Schema.AnyNoContext;
154
+ readonly output: Schema.Schema.AnyNoContext;
155
+ readonly services: readonly Context.Tag<any, any>[];
156
+ }
157
+ export declare const make: <const Opts extends Types.NoExcessProperties<MakeProcessOpts, Opts>>(opts: Opts, create: (ctx: ProcessContext<Schema.Schema.Type<Opts["input"]>, Schema.Schema.Type<Opts["output"]>>) => Effect.Effect<Partial<Callbacks<Schema.Schema.Type<Opts["input"]>, Schema.Schema.Type<Opts["output"]>, Context.Tag.Identifier<NonNullable<Opts["services"]>[number]>>>, never, Context.Tag.Identifier<NonNullable<Opts["services"]>[number]> | BaseServices | Scope.Scope>) => Process<Schema.Schema.Type<Opts["input"]>, Schema.Schema.Type<Opts["output"]>, Context.Tag.Identifier<NonNullable<Opts["services"]>[number]>>;
158
+ export declare const fromOperation: <const Op extends Operation.Definition.Any>(op: Op, handler: OperationHandlerSet.OperationHandlerSet) => Process<Operation.Definition.Input<Op>, Operation.Definition.Output<Op>, Operation.Definition.Services<Op>>;
159
+ /**
160
+ * Runtime state of a process.
161
+ */
162
+ export declare enum State {
163
+ RUNNING = "RUNNING",
164
+ HYBERNATING = "HYBERNATING",
165
+ IDLE = "IDLE",
166
+ TERMINATING = "TERMINATING",
167
+ TERMINATED = "TERMINATED",
168
+ SUCCEEDED = "SUCCEEDED",
169
+ FAILED = "FAILED"
170
+ }
171
+ /**
172
+ * Read-only view of a process tree
173
+ */
174
+ export interface Monitor {
175
+ /**
176
+ * Get the current state of the process tree.
177
+ */
178
+ processTree: Effect.Effect<readonly Info[]>;
179
+ /**
180
+ * Atom for the process tree.
181
+ */
182
+ processTreeAtom: Atom.Atom<readonly Info[]>;
183
+ }
184
+ declare const ProcessMonitorService_base: Context.TagClass<ProcessMonitorService, "@dxos/functions/ProcessMonitorService", Monitor>;
185
+ export declare class ProcessMonitorService extends ProcessMonitorService_base {
186
+ }
187
+ export interface Info {
188
+ readonly pid: ID;
189
+ readonly parentPid: ID | null;
190
+ /**
191
+ * Key of the process.
192
+ *
193
+ * NOTE: There might be multiple running processes with the same key.
194
+ */
195
+ readonly key: string;
196
+ /**
197
+ * Parameters of the process.
198
+ */
199
+ readonly params: Params;
200
+ /**
201
+ * State of the process.
202
+ */
203
+ readonly state: State;
204
+ /**
205
+ * Error of the process.
206
+ * Only for process in FAILED state.
207
+ */
208
+ readonly error: string | null;
209
+ /**
210
+ * UNIX timestamp in milliseconds.
211
+ */
212
+ readonly startedAt: number;
213
+ /**
214
+ * UNIX timestamp in milliseconds.
215
+ */
216
+ readonly completedAt: Option.Option<number>;
217
+ readonly metrics: {
218
+ /**
219
+ * Total wall time of all handler invocations of the process in milliseconds.
220
+ */
221
+ readonly wallTime: number;
222
+ /**
223
+ * Total number of inputs submitted to the process.
224
+ */
225
+ readonly inputCount: number;
226
+ /**
227
+ * Total number of outputs submitted to the process.
228
+ */
229
+ readonly outputCount: number;
230
+ };
231
+ }
232
+ /**
233
+ * New process is spawned.
234
+ */
235
+ export declare const SpawnedEvent: Trace.EventType<void>;
236
+ /**
237
+ * Process has reached a terminal state.
238
+ */
239
+ export declare const ExitedEvent: Trace.EventType<{
240
+ readonly outcome: "succeeded" | "failed" | "terminated";
241
+ }>;
242
+ /**
243
+ * Renders spawned processes as a forest: top-level rows use "- ", nested rows use ├── / └── / │.
244
+ */
245
+ export declare const prettyProcessTree: (tree: readonly Info[]) => string;
246
+ export {};
247
+ //# sourceMappingURL=Process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Process.d.ts","sourceRoot":"","sources":["../../../../src/process/Process.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,IAAI,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAMlC,4CAA4C;AAC5C,eAAO,MAAM,EAAE,iDAAgD,CAAC;AAChE,MAAM,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAChC;;;;;;;;OAQG;IACH,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC;IAExD;;;;;;;;;OASG;IACH,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAA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AC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAE5C,QAAQ,CAAC,OAAO,EAAE;QAChB;;WAEG;QACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAE1B;;WAEG;QACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAE5B;;WAEG;QACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;KAC9B,CAAC;CACH;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,uBAGvB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW;;EAKtB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,SAAS,IAAI,EAAE,KAAG,MA+DzD,CAAC"}
@@ -0,0 +1,74 @@
1
+ import * as Context from 'effect/Context';
2
+ import * as Effect from 'effect/Effect';
3
+ import * as Layer from 'effect/Layer';
4
+ import * as Scope from 'effect/Scope';
5
+ import type { DXN, SpaceId } from '@dxos/keys';
6
+ import { ServiceNotAvailableError } from '../errors';
7
+ import * as Process from './Process';
8
+ declare const ServiceResolverTypeId: "~@dxos/functions/ServiceResolver";
9
+ type ServiceResolverTypeId = typeof ServiceResolverTypeId;
10
+ export interface ServiceResolver {
11
+ readonly [ServiceResolverTypeId]: ServiceResolverTypeId;
12
+ /**
13
+ * Resolve a set of services identified by their tags.
14
+ * Returns a Context containing all requested services, or fails with ServiceNotAvailableError.
15
+ */
16
+ resolve<Tag extends Context.Tag<any, any>>(tag: Tag, context: ResolutionContext): Effect.Effect<Context.Tag.Service<Tag>, ServiceNotAvailableError, Scope.Scope>;
17
+ }
18
+ /**
19
+ * Tag for the ServiceResolver service.
20
+ */
21
+ export declare const ServiceResolver: Context.Tag<ServiceResolver, ServiceResolver>;
22
+ export declare const resolve: <Tag extends Context.Tag<any, any>>(tag: Tag, context: ResolutionContext) => Effect.Effect<Context.Tag.Service<Tag>, ServiceNotAvailableError, Scope.Scope | ServiceResolver>;
23
+ export declare const resolveAll: <const Tags extends readonly Context.Tag<any, any>[]>(tags: Tags, context: ResolutionContext) => Effect.Effect<Context.Context<Tags[number]>, ServiceNotAvailableError, Scope.Scope | ServiceResolver>;
24
+ /**
25
+ * Provides context for service resolution.
26
+ */
27
+ export interface ResolutionContext {
28
+ /**
29
+ * Under which identity the process is running.
30
+ */
31
+ readonly identity?: string;
32
+ /**
33
+ * Under which space the process is running.
34
+ */
35
+ readonly space?: SpaceId;
36
+ /**
37
+ * DXN of the conversation feed the process is running in.
38
+ */
39
+ readonly conversation?: DXN.String;
40
+ /**
41
+ * Under which process the process is running.
42
+ */
43
+ readonly process?: Process.ID;
44
+ }
45
+ export declare const succeed: <I, S>(tag: Context.Tag<I, S>, getService: (context: ResolutionContext) => Effect.Effect<S, ServiceNotAvailableError, Scope.Scope>) => ServiceResolver;
46
+ /**
47
+ * Create a ServiceResolver from a custom resolution function.
48
+ */
49
+ export declare const make: (resolveFn: <I, S>(tag: Context.Tag<I, S>, context: ResolutionContext) => Effect.Effect<S, ServiceNotAvailableError, Scope.Scope>) => ServiceResolver;
50
+ /**
51
+ * Create a ServiceResolver backed by a static Context.
52
+ * Tags present in the context are resolved; missing tags fail with ServiceNotAvailableError.
53
+ */
54
+ export declare const fromContext: (ctx: Context.Context<any>) => ServiceResolver;
55
+ /**
56
+ * Create a ServiceResolver that resolves tags from the current Effect context.
57
+ * Only the specified tags are available; requests for other tags fail.
58
+ */
59
+ export declare const fromRequirements: <const Tags extends readonly Context.Tag<any, any>[]>(...tags: Tags) => Effect.Effect<ServiceResolver, never, Context.Tag.Identifier<Tags[number]>>;
60
+ /**
61
+ * Like {@link fromRequirements} but returns a Layer that provides ServiceResolver.
62
+ */
63
+ export declare const layerRequirements: <const Tags extends readonly Context.Tag<any, any>[]>(...tags: Tags) => Layer.Layer<ServiceResolver, never, Context.Tag.Identifier<Tags[number]>>;
64
+ /**
65
+ * Compose multiple resolvers left to right. Earlier resolvers take precedence:
66
+ * the first resolver that can satisfy a tag wins.
67
+ */
68
+ export declare const compose: (...resolvers: readonly ServiceResolver[]) => ServiceResolver;
69
+ /**
70
+ * An empty resolver that fails for any requested service.
71
+ */
72
+ export declare const empty: ServiceResolver;
73
+ export {};
74
+ //# sourceMappingURL=ServiceResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServiceResolver.d.ts","sourceRoot":"","sources":["../../../../src/process/ServiceResolver.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,QAAA,MAAM,qBAAqB,EAAG,kCAA2C,CAAC;AAC1E,KAAK,qBAAqB,GAAG,OAAO,qBAAqB,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,CAAC,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAExD;;;OAGG;IACH,OAAO,CAAC,GAAG,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,EACvC,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,iBAAiB,GACzB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,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,OAAO,EAAE,iBAAiB,KACvB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,wBAAwB,EAAE,KAAK,CAAC,KAAK,CAAC,KAC3D,eAGD,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAG,eASrD,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,CAAC,IAAI,SAAS,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAClF,GAAG,MAAM,IAAI,KACZ,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAgBzE,CAAC;AAEL;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,CAAC,IAAI,SAAS,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EACnF,GAAG,MAAM,IAAI,KACZ,KAAK,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CACjB,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,GAAG,WAAW,SAAS,eAAe,EAAE,KAAG,eAYhE,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,KAAK,EAAE,eAElB,CAAC"}
@@ -0,0 +1,58 @@
1
+ import * as Context from 'effect/Context';
2
+ import * as Effect from 'effect/Effect';
3
+ import * as Option from 'effect/Option';
4
+ import * as Pipeable from 'effect/Pipeable';
5
+ import * as Schema from 'effect/Schema';
6
+ export interface Service {
7
+ /** Read a value by key. Returns `None` if key does not exist. */
8
+ get<S extends Schema.Schema<any, string, any>>(schema: S, key: string): Effect.Effect<Option.Option<Schema.Schema.Type<S>>, never, Schema.Schema.Context<S>>;
9
+ /** Write a value for the given key. */
10
+ set<S extends Schema.Schema<any, string, any>>(schema: S, key: string, value: Schema.Schema.Type<S>): Effect.Effect<void, never, Schema.Schema.Context<S>>;
11
+ /** Remove a key. */
12
+ delete(key: string): Effect.Effect<void>;
13
+ /** List all keys, optionally filtered by prefix. */
14
+ list(prefix?: string): Effect.Effect<readonly string[]>;
15
+ /** Remove all keys managed by this scoped store. */
16
+ clear(): Effect.Effect<void>;
17
+ }
18
+ declare const StorageService_base: Context.TagClass<StorageService, "@dxos/functions/StorageService", Service>;
19
+ /**
20
+ * Scoped key-value storage service for processes.
21
+ * Each process receives its own namespaced instance via the process manager.
22
+ * Construct a live implementation with `StorageService.layer` from `@dxos/functions-runtime`.
23
+ */
24
+ export declare class StorageService extends StorageService_base {
25
+ }
26
+ export declare const get: <S extends Schema.Schema<any, string, any>>(schema: S, key: string) => Effect.Effect<Option.Option<Schema.Schema.Type<S>>, never, Schema.Schema.Context<S> | StorageService>;
27
+ export declare const set: <S extends Schema.Schema<any, string, any>>(schema: S, key: string, value: Schema.Schema.Type<S>) => Effect.Effect<void, never, Schema.Schema.Context<S> | StorageService>;
28
+ export declare const deleteKey: (key: string) => Effect.Effect<void, never, StorageService>;
29
+ export declare const list: (prefix?: string | undefined) => Effect.Effect<readonly string[], never, StorageService>;
30
+ export declare const clear: () => Effect.Effect<void, never, StorageService>;
31
+ /**
32
+ * Typed key in a storage service.
33
+ */
34
+ export interface Key<T> extends Pipeable.Pipeable {
35
+ readonly key: string;
36
+ get: Effect.Effect<Option.Option<T>, never, StorageService>;
37
+ set(value: T): Effect.Effect<void, never, StorageService>;
38
+ delete(): Effect.Effect<void, never, StorageService>;
39
+ }
40
+ /**
41
+ * Create a typed key in a storage service.
42
+ */
43
+ export declare const key: <S extends Schema.Schema<any, string, any>>(schema: S, key: string) => Key<Schema.Schema.Type<S>>;
44
+ /**
45
+ * Typed key in a storage service with a default value.
46
+ */
47
+ export interface KeyWithDefault<T, U> extends Pipeable.Pipeable {
48
+ readonly key: string;
49
+ get: Effect.Effect<T | U, never, StorageService>;
50
+ set(value: U): Effect.Effect<void, never, StorageService>;
51
+ delete(): Effect.Effect<void, never, StorageService>;
52
+ }
53
+ /**
54
+ * Assign a default value to a key if it is not present.
55
+ */
56
+ export declare const withDefault: <T>(getDefault: () => NoInfer<T>) => (key: Key<T>) => KeyWithDefault<T, T>;
57
+ export {};
58
+ //# sourceMappingURL=StorageService.d.ts.map