@dxos/functions 0.8.4-main.d05539e30a → 0.8.4-main.d9fc60f731
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/dist/lib/neutral/index.mjs +12 -19
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/protocol/protocol.d.ts +1 -6
- package/dist/types/src/protocol/protocol.d.ts.map +1 -1
- package/dist/types/src/sdk.d.ts +2 -2
- package/dist/types/src/sdk.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/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -19
- package/src/protocol/protocol.test.ts +3 -2
- package/src/protocol/protocol.ts +16 -26
- package/src/sdk.ts +1 -3
- package/src/services/index.ts +0 -1
- package/dist/types/src/services/queues.d.ts +0 -2
- package/dist/types/src/services/queues.d.ts.map +0 -1
- package/src/services/queues.ts +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/functions",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.d9fc60f731",
|
|
4
4
|
"description": "Functions API.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -26,24 +26,24 @@
|
|
|
26
26
|
"src"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@effect-atom/atom": "^0.5.
|
|
30
|
-
"@effect/ai-anthropic": "0.
|
|
31
|
-
"@effect/platform": "0.
|
|
32
|
-
"effect": "3.
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/context": "0.8.4-main.
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
29
|
+
"@effect-atom/atom": "^0.5.3",
|
|
30
|
+
"@effect/ai-anthropic": "0.25.0",
|
|
31
|
+
"@effect/platform": "0.96.1",
|
|
32
|
+
"effect": "3.21.2",
|
|
33
|
+
"@dxos/ai": "0.8.4-main.d9fc60f731",
|
|
34
|
+
"@dxos/compute": "0.8.4-main.d9fc60f731",
|
|
35
|
+
"@dxos/context": "0.8.4-main.d9fc60f731",
|
|
36
|
+
"@dxos/effect": "0.8.4-main.d9fc60f731",
|
|
37
|
+
"@dxos/errors": "0.8.4-main.d9fc60f731",
|
|
38
|
+
"@dxos/echo-db": "0.8.4-main.d9fc60f731",
|
|
39
|
+
"@dxos/invariant": "0.8.4-main.d9fc60f731",
|
|
40
|
+
"@dxos/echo": "0.8.4-main.d9fc60f731",
|
|
41
|
+
"@dxos/node-std": "0.8.4-main.d9fc60f731",
|
|
42
|
+
"@dxos/log": "0.8.4-main.d9fc60f731",
|
|
43
|
+
"@dxos/protocols": "0.8.4-main.d9fc60f731",
|
|
44
|
+
"@dxos/types": "0.8.4-main.d9fc60f731",
|
|
45
|
+
"@dxos/schema": "0.8.4-main.d9fc60f731",
|
|
46
|
+
"@dxos/keys": "0.8.4-main.d9fc60f731"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
@@ -6,6 +6,7 @@ import { describe, test } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { InvalidOperationInputError } from '@dxos/compute';
|
|
8
8
|
import { FibonacciHandler, ReplyHandler } from '@dxos/compute/testing';
|
|
9
|
+
import { DXN } from '@dxos/keys';
|
|
9
10
|
|
|
10
11
|
import { wrapFunctionHandler } from './protocol';
|
|
11
12
|
|
|
@@ -13,7 +14,7 @@ describe('wrapFunctionHandler', () => {
|
|
|
13
14
|
test('wraps reply function and executes handler', async ({ expect }) => {
|
|
14
15
|
const wrapped = wrapFunctionHandler(ReplyHandler);
|
|
15
16
|
|
|
16
|
-
expect(wrapped.meta.key).toBe('org.example.function.reply');
|
|
17
|
+
expect(wrapped.meta.key).toBe(DXN.make('org.example.function.reply'));
|
|
17
18
|
expect(wrapped.meta.name).toBe('Reply');
|
|
18
19
|
|
|
19
20
|
const testData = { message: 'hello' };
|
|
@@ -30,7 +31,7 @@ describe('wrapFunctionHandler', () => {
|
|
|
30
31
|
test('wraps fibonacci function with valid input', async ({ expect }) => {
|
|
31
32
|
const wrapped = wrapFunctionHandler(FibonacciHandler);
|
|
32
33
|
|
|
33
|
-
expect(wrapped.meta.key).toBe('org.example.function.fib');
|
|
34
|
+
expect(wrapped.meta.key).toBe(DXN.make('org.example.function.fib'));
|
|
34
35
|
expect(wrapped.meta.name).toBe('Fibonacci');
|
|
35
36
|
|
|
36
37
|
const result = await wrapped.handler({
|
package/src/protocol/protocol.ts
CHANGED
|
@@ -12,7 +12,6 @@ import * as SchemaAST from 'effect/SchemaAST';
|
|
|
12
12
|
import { AiModelResolver, AiService, OpaqueToolkit } from '@dxos/ai';
|
|
13
13
|
import { AnthropicResolver } from '@dxos/ai/resolvers';
|
|
14
14
|
import {
|
|
15
|
-
Blueprint,
|
|
16
15
|
FunctionError,
|
|
17
16
|
InvalidOperationInputError,
|
|
18
17
|
InvalidOperationOutputError,
|
|
@@ -21,8 +20,14 @@ import {
|
|
|
21
20
|
Trace,
|
|
22
21
|
} from '@dxos/compute';
|
|
23
22
|
import { LifecycleState, Resource } from '@dxos/context';
|
|
24
|
-
import { Database, Feed, JsonSchema, Ref, type Type } from '@dxos/echo';
|
|
25
|
-
import {
|
|
23
|
+
import { Database, Feed, JsonSchema, Ref, Registry, type Type } from '@dxos/echo';
|
|
24
|
+
import {
|
|
25
|
+
createFeedServiceLayer,
|
|
26
|
+
EchoClient,
|
|
27
|
+
type EchoDatabaseImpl,
|
|
28
|
+
makeRegistry,
|
|
29
|
+
type QueueFactory,
|
|
30
|
+
} from '@dxos/echo-db';
|
|
26
31
|
import { refFromEncodedReference } from '@dxos/echo/internal';
|
|
27
32
|
import { runAndForwardErrors } from '@dxos/effect';
|
|
28
33
|
import { assertState, failedInvariant, invariant } from '@dxos/invariant';
|
|
@@ -31,12 +36,7 @@ import { log } from '@dxos/log';
|
|
|
31
36
|
import { EdgeFunctionEnv, ErrorCodec, type FunctionProtocol, type TraceProtocol } from '@dxos/protocols';
|
|
32
37
|
|
|
33
38
|
import { type FunctionServices } from '../sdk';
|
|
34
|
-
import {
|
|
35
|
-
configuredCredentialsLayer,
|
|
36
|
-
credentialsLayerFromDatabase,
|
|
37
|
-
FunctionInvocationService,
|
|
38
|
-
QueueService,
|
|
39
|
-
} from '../services';
|
|
39
|
+
import { configuredCredentialsLayer, credentialsLayerFromDatabase, FunctionInvocationService } from '../services';
|
|
40
40
|
import { FunctionsAiHttpClient } from './functions-ai-http-client';
|
|
41
41
|
|
|
42
42
|
export interface FunctionWrappingOptions {
|
|
@@ -49,12 +49,6 @@ export interface FunctionWrappingOptions {
|
|
|
49
49
|
* Toolkits to make available via the `OpaqueToolkitProvider`.
|
|
50
50
|
*/
|
|
51
51
|
toolkits?: OpaqueToolkit.OpaqueToolkit[];
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Blueprint registry to expose as `Blueprint.RegistryService` inside handler Effects.
|
|
55
|
-
* Required for operations that declare `Blueprint.RegistryService` in their `services` list.
|
|
56
|
-
*/
|
|
57
|
-
blueprintRegistry?: Blueprint.Registry;
|
|
58
52
|
}
|
|
59
53
|
|
|
60
54
|
/**
|
|
@@ -81,9 +75,7 @@ export const wrapFunctionHandler = (
|
|
|
81
75
|
},
|
|
82
76
|
handler: async ({ data, context }) => {
|
|
83
77
|
if (
|
|
84
|
-
(serviceTags.includes(Database.Service.key) ||
|
|
85
|
-
serviceTags.includes(QueueService.key) ||
|
|
86
|
-
serviceTags.includes(Feed.FeedService.key)) &&
|
|
78
|
+
(serviceTags.includes(Database.Service.key) || serviceTags.includes(Feed.FeedService.key)) &&
|
|
87
79
|
(!context.services.dataService || !context.services.queryService)
|
|
88
80
|
) {
|
|
89
81
|
throw new FunctionError({
|
|
@@ -109,7 +101,7 @@ export const wrapFunctionHandler = (
|
|
|
109
101
|
const types = [...(opts.types ?? []), ...(func.types ?? [])];
|
|
110
102
|
if (types.length > 0) {
|
|
111
103
|
invariant(funcContext.db, 'Database is required for functions with types');
|
|
112
|
-
|
|
104
|
+
funcContext.db.graph.registry.add(types);
|
|
113
105
|
}
|
|
114
106
|
|
|
115
107
|
const dataWithDecodedRefs =
|
|
@@ -210,7 +202,6 @@ class FunctionContext extends Resource {
|
|
|
210
202
|
assertState(this._lifecycleState === LifecycleState.OPEN, 'FunctionContext is not open');
|
|
211
203
|
|
|
212
204
|
const dbLayer = this.db ? Database.layer(this.db) : Database.notAvailable;
|
|
213
|
-
const queuesLayer = this.queues ? QueueService.layer(this.queues) : QueueService.notAvailable;
|
|
214
205
|
const feedLayer = this.queues ? createFeedServiceLayer(this.queues) : Feed.notAvailable;
|
|
215
206
|
const credentials = dbLayer
|
|
216
207
|
? credentialsLayerFromDatabase({ caching: true }).pipe(Layer.provide(dbLayer))
|
|
@@ -242,13 +233,12 @@ class FunctionContext extends Resource {
|
|
|
242
233
|
types: this.opts.types?.length ?? 0,
|
|
243
234
|
});
|
|
244
235
|
|
|
245
|
-
const
|
|
246
|
-
? Layer.succeed(
|
|
247
|
-
:
|
|
236
|
+
const registryLayer = this.db
|
|
237
|
+
? Layer.succeed(Registry.Service, this.db.graph.registry)
|
|
238
|
+
: Layer.succeed(Registry.Service, makeRegistry());
|
|
248
239
|
|
|
249
240
|
return Layer.mergeAll(
|
|
250
241
|
dbLayer,
|
|
251
|
-
queuesLayer,
|
|
252
242
|
feedLayer,
|
|
253
243
|
credentials,
|
|
254
244
|
operationServiceLayer,
|
|
@@ -256,7 +246,7 @@ class FunctionContext extends Resource {
|
|
|
256
246
|
aiLayer,
|
|
257
247
|
OpaqueToolkit.providerLayer(OpaqueToolkit.merge(...(this.opts.toolkits ?? []))),
|
|
258
248
|
traceWriterLayer,
|
|
259
|
-
|
|
249
|
+
registryLayer,
|
|
260
250
|
|
|
261
251
|
// `FunctionInvocationService` is deprecated; new code should yield `Operation.Service`.
|
|
262
252
|
// The cloudflare wrapper provides only the unavailable layer to satisfy the (still-present)
|
|
@@ -337,7 +327,7 @@ const makeOperationServiceLayer = (
|
|
|
337
327
|
outcome.error ? Effect.die(outcome.error) : Effect.succeed(outcome.data as never),
|
|
338
328
|
),
|
|
339
329
|
)) as Operation.OperationService['invoke'],
|
|
340
|
-
schedule: ((op: Operation.Definition.Any, input: unknown) =>
|
|
330
|
+
schedule: ((op: Operation.Definition.Any, input: unknown, _options?: Operation.InvokeOptions) =>
|
|
341
331
|
Effect.sync(() => {
|
|
342
332
|
invariant(op.meta.deployedId, `Operation '${op.meta.key}' has no deployedId; cannot schedule remotely.`);
|
|
343
333
|
// Fire and forget — schedule is intentionally non-awaiting.
|
package/src/sdk.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type AiService } from '@dxos/ai';
|
|
|
6
6
|
import { type Credential, type Operation, type Trace } from '@dxos/compute';
|
|
7
7
|
import { type Database, type Feed } from '@dxos/echo';
|
|
8
8
|
|
|
9
|
-
import { type FunctionInvocationService
|
|
9
|
+
import { type FunctionInvocationService } from './services';
|
|
10
10
|
|
|
11
11
|
// TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.
|
|
12
12
|
// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html
|
|
@@ -21,8 +21,6 @@ export type FunctionServices =
|
|
|
21
21
|
| AiService.AiService
|
|
22
22
|
| Credential.CredentialsService
|
|
23
23
|
| Database.Service
|
|
24
|
-
// TODO(wittjosiah): Remove QueueService — use Feed.FeedService instead.
|
|
25
|
-
| QueueService
|
|
26
24
|
| Feed.FeedService
|
|
27
25
|
| Trace.TraceService
|
|
28
26
|
// TODO(dmaretskyi): `FunctionInvocationService` is being phased out in favour of `Operation.Service`;
|
package/src/services/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queues.d.ts","sourceRoot":"","sources":["../../../../src/services/queues.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC"}
|