@dxos/compute 0.8.4-main.fd6878d → 0.9.0
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/LICENSE +102 -5
- package/README.md +36 -1
- package/dist/lib/neutral/StorageService.mjs +22 -0
- package/dist/lib/neutral/chunk-2B2KSJT6.mjs +17 -0
- package/dist/lib/neutral/chunk-2B2KSJT6.mjs.map +7 -0
- package/dist/lib/neutral/chunk-AFBNVFAY.mjs +25 -0
- package/dist/lib/neutral/chunk-AFBNVFAY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-JAU4E4EK.mjs +53 -0
- package/dist/lib/neutral/chunk-JAU4E4EK.mjs.map +7 -0
- package/dist/lib/neutral/chunk-MEPE4HHX.mjs +21 -0
- package/dist/lib/neutral/chunk-MEPE4HHX.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QZS4G6PE.mjs +240 -0
- package/dist/lib/neutral/chunk-QZS4G6PE.mjs.map +7 -0
- package/dist/lib/neutral/chunk-XEVFBI6S.mjs +62 -0
- package/dist/lib/neutral/chunk-XEVFBI6S.mjs.map +7 -0
- package/dist/lib/neutral/chunk-Z3Y7FQGN.mjs +174 -0
- package/dist/lib/neutral/chunk-Z3Y7FQGN.mjs.map +7 -0
- package/dist/lib/neutral/fib-HBDUGQW7.mjs +10 -0
- package/dist/lib/neutral/fib-HBDUGQW7.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1183 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/reply-RJIAJ6FV.mjs +10 -0
- package/dist/lib/neutral/reply-RJIAJ6FV.mjs.map +7 -0
- package/dist/lib/neutral/sleep-3T2CZ7RE.mjs +10 -0
- package/dist/lib/neutral/sleep-3T2CZ7RE.mjs.map +7 -0
- package/dist/lib/neutral/testing/index.mjs +32 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/Blueprint.d.ts +182 -0
- package/dist/types/src/Blueprint.d.ts.map +1 -0
- package/dist/types/src/Credential.d.ts +27 -0
- package/dist/types/src/Credential.d.ts.map +1 -0
- package/dist/types/src/Header.d.ts +9 -0
- package/dist/types/src/Header.d.ts.map +1 -0
- package/dist/types/src/Header.test.d.ts +2 -0
- package/dist/types/src/Header.test.d.ts.map +1 -0
- package/dist/types/src/LayerSpec.d.ts +56 -0
- package/dist/types/src/LayerSpec.d.ts.map +1 -0
- package/dist/types/src/McpServer.d.ts +26 -0
- package/dist/types/src/McpServer.d.ts.map +1 -0
- package/dist/types/src/Operation.d.ts +385 -0
- package/dist/types/src/Operation.d.ts.map +1 -0
- package/dist/types/src/OperationHandlerSet.d.ts +69 -0
- package/dist/types/src/OperationHandlerSet.d.ts.map +1 -0
- package/dist/types/src/OperationHandlerSet.test.d.ts +2 -0
- package/dist/types/src/OperationHandlerSet.test.d.ts.map +1 -0
- package/dist/types/src/OperationRegistry.d.ts +23 -0
- package/dist/types/src/OperationRegistry.d.ts.map +1 -0
- package/dist/types/src/Process.d.ts +255 -0
- package/dist/types/src/Process.d.ts.map +1 -0
- package/dist/types/src/Routine.d.ts +54 -0
- package/dist/types/src/Routine.d.ts.map +1 -0
- package/dist/types/src/Script.d.ts +21 -0
- package/dist/types/src/Script.d.ts.map +1 -0
- package/dist/types/src/ServiceResolver.d.ts +92 -0
- package/dist/types/src/ServiceResolver.d.ts.map +1 -0
- package/dist/types/src/StorageService.d.ts +58 -0
- package/dist/types/src/StorageService.d.ts.map +1 -0
- package/dist/types/src/Template.d.ts +61 -0
- package/dist/types/src/Template.d.ts.map +1 -0
- package/dist/types/src/Template.test.d.ts +2 -0
- package/dist/types/src/Template.test.d.ts.map +1 -0
- package/dist/types/src/Trace.d.ts +266 -0
- package/dist/types/src/Trace.d.ts.map +1 -0
- package/dist/types/src/Trigger.d.ts +192 -0
- package/dist/types/src/Trigger.d.ts.map +1 -0
- package/dist/types/src/TriggerEvent.d.ts +83 -0
- package/dist/types/src/TriggerEvent.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +308 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +18 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/definitions.d.ts +11 -0
- package/dist/types/src/testing/definitions.d.ts.map +1 -0
- package/dist/types/src/testing/fib.d.ts +8 -0
- package/dist/types/src/testing/fib.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +6 -3
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/reply.d.ts +4 -0
- package/dist/types/src/testing/reply.d.ts.map +1 -0
- package/dist/types/src/testing/sleep.d.ts +6 -0
- package/dist/types/src/testing/sleep.d.ts.map +1 -0
- package/dist/types/src/umbrella.test.d.ts +2 -0
- package/dist/types/src/umbrella.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -47
- package/src/Blueprint.ts +224 -0
- package/src/Credential.ts +53 -0
- package/src/Header.test.ts +132 -0
- package/src/Header.ts +38 -0
- package/src/LayerSpec.ts +91 -0
- package/src/McpServer.ts +44 -0
- package/src/Operation.ts +646 -0
- package/src/OperationHandlerSet.test.ts +97 -0
- package/src/OperationHandlerSet.ts +181 -0
- package/src/OperationRegistry.ts +50 -0
- package/src/Process.ts +541 -0
- package/src/Routine.ts +68 -0
- package/src/Script.ts +33 -0
- package/src/ServiceResolver.ts +200 -0
- package/src/StorageService.ts +101 -0
- package/src/Template.test.ts +164 -0
- package/src/Template.ts +125 -0
- package/src/Trace.ts +363 -0
- package/src/Trigger.ts +196 -0
- package/src/TriggerEvent.ts +64 -0
- package/src/errors.ts +71 -0
- package/src/index.ts +19 -32
- package/src/testing/definitions.ts +51 -0
- package/src/testing/fib.ts +22 -0
- package/src/testing/index.ts +13 -4
- package/src/testing/reply.ts +18 -0
- package/src/testing/sleep.ts +16 -0
- package/src/umbrella.test.ts +51 -0
- package/dist/lib/browser/chunk-X2FWMHD4.mjs +0 -3107
- package/dist/lib/browser/chunk-X2FWMHD4.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -55
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs +0 -176
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RP7HSSCA.mjs +0 -3109
- package/dist/lib/node-esm/chunk-RP7HSSCA.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -56
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -177
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/compute-graph-registry.d.ts +0 -34
- package/dist/types/src/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/compute-graph.d.ts +0 -64
- package/dist/types/src/compute-graph.d.ts.map +0 -1
- package/dist/types/src/compute-graph.test.d.ts +0 -2
- package/dist/types/src/compute-graph.test.d.ts.map +0 -1
- package/dist/types/src/compute-node.d.ts +0 -25
- package/dist/types/src/compute-node.d.ts.map +0 -1
- package/dist/types/src/functions/async-function.d.ts +0 -66
- package/dist/types/src/functions/async-function.d.ts.map +0 -1
- package/dist/types/src/functions/edge-function.d.ts +0 -20
- package/dist/types/src/functions/edge-function.d.ts.map +0 -1
- package/dist/types/src/functions/function-defs.d.ts +0 -11
- package/dist/types/src/functions/function-defs.d.ts.map +0 -1
- package/dist/types/src/functions/index.d.ts +0 -4
- package/dist/types/src/functions/index.d.ts.map +0 -1
- package/dist/types/src/hyperformula.test.d.ts +0 -2
- package/dist/types/src/hyperformula.test.d.ts.map +0 -1
- package/dist/types/src/testing/test-builder.d.ts +0 -15
- package/dist/types/src/testing/test-builder.d.ts.map +0 -1
- package/dist/types/src/testing/test-plugin.d.ts +0 -36
- package/dist/types/src/testing/test-plugin.d.ts.map +0 -1
- package/dist/types/src/testing/util.d.ts +0 -2
- package/dist/types/src/testing/util.d.ts.map +0 -1
- package/dist/types/src/types/hyperformula.d.ts +0 -11
- package/dist/types/src/types/hyperformula.d.ts.map +0 -1
- package/dist/types/src/types/index.d.ts +0 -3
- package/dist/types/src/types/index.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -20
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/dist/types/src/types/types.test.d.ts +0 -2
- package/dist/types/src/types/types.test.d.ts.map +0 -1
- package/dist/types/src/util.d.ts +0 -2
- package/dist/types/src/util.d.ts.map +0 -1
- package/dist/vendor/hyperformula.mjs +0 -36400
- package/src/compute-graph-registry.ts +0 -91
- package/src/compute-graph.test.ts +0 -89
- package/src/compute-graph.ts +0 -260
- package/src/compute-node.ts +0 -62
- package/src/functions/async-function.ts +0 -179
- package/src/functions/edge-function.ts +0 -112
- package/src/functions/function-defs.ts +0 -2427
- package/src/functions/index.ts +0 -7
- package/src/hyperformula.test.ts +0 -14
- package/src/testing/test-builder.ts +0 -54
- package/src/testing/test-plugin.ts +0 -101
- package/src/testing/util.ts +0 -9
- package/src/types/hyperformula.ts +0 -19
- package/src/types/index.ts +0 -6
- package/src/types/types.test.ts +0 -91
- package/src/types/types.ts +0 -80
- package/src/util.ts +0 -8
- /package/dist/lib/{browser/index.mjs.map → neutral/StorageService.mjs.map} +0 -0
- /package/dist/lib/{node-esm/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
package/package.json
CHANGED
|
@@ -1,76 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/compute",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Umbrella package for AI-aware DXOS compute primitives.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
-
"
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
10
14
|
"type": "module",
|
|
11
|
-
"imports": {
|
|
12
|
-
"#hyperformula": {
|
|
13
|
-
"source": "hyperformula",
|
|
14
|
-
"types": "hyperformula",
|
|
15
|
-
"default": "./dist/vendor/hyperformula.mjs"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
15
|
"exports": {
|
|
19
16
|
".": {
|
|
20
17
|
"source": "./src/index.ts",
|
|
21
18
|
"types": "./dist/types/src/index.d.ts",
|
|
22
|
-
"
|
|
23
|
-
|
|
19
|
+
"default": "./dist/lib/neutral/index.mjs"
|
|
20
|
+
},
|
|
21
|
+
"./StorageService": {
|
|
22
|
+
"source": "./src/StorageService.ts",
|
|
23
|
+
"types": "./dist/types/src/StorageService.d.ts",
|
|
24
|
+
"default": "./dist/lib/neutral/StorageService.mjs"
|
|
24
25
|
},
|
|
25
26
|
"./testing": {
|
|
26
27
|
"source": "./src/testing/index.ts",
|
|
27
28
|
"types": "./dist/types/src/testing/index.d.ts",
|
|
28
|
-
"
|
|
29
|
-
"node": "./dist/lib/node-esm/testing/index.mjs"
|
|
29
|
+
"default": "./dist/lib/neutral/testing/index.mjs"
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"types": "dist/types/src/index.d.ts",
|
|
33
|
-
"typesVersions": {
|
|
34
|
-
"*": {
|
|
35
|
-
"testing": [
|
|
36
|
-
"dist/types/src/testing/index.d.ts"
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
33
|
"files": [
|
|
41
34
|
"dist",
|
|
42
35
|
"src"
|
|
43
36
|
],
|
|
44
37
|
"dependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"effect": "
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/keys": "0.8.4-main.fd6878d",
|
|
58
|
-
"@dxos/live-object": "0.8.4-main.fd6878d",
|
|
59
|
-
"@dxos/log": "0.8.4-main.fd6878d",
|
|
60
|
-
"@dxos/schema": "0.8.4-main.fd6878d",
|
|
61
|
-
"@dxos/echo": "0.8.4-main.fd6878d",
|
|
62
|
-
"@dxos/protocols": "0.8.4-main.fd6878d",
|
|
63
|
-
"@dxos/util": "0.8.4-main.fd6878d"
|
|
38
|
+
"@effect-atom/atom": "^0.5.3",
|
|
39
|
+
"@effect/platform": "0.96.1",
|
|
40
|
+
"@dxos/ai": "0.9.0",
|
|
41
|
+
"@dxos/echo": "0.9.0",
|
|
42
|
+
"@dxos/errors": "0.9.0",
|
|
43
|
+
"@dxos/effect": "0.9.0",
|
|
44
|
+
"@dxos/invariant": "0.9.0",
|
|
45
|
+
"@dxos/keys": "0.9.0",
|
|
46
|
+
"@dxos/log": "0.9.0",
|
|
47
|
+
"@dxos/protocols": "0.9.0",
|
|
48
|
+
"@dxos/schema": "0.9.0",
|
|
49
|
+
"@dxos/vendor-kbn-handlebars": "0.9.0"
|
|
64
50
|
},
|
|
65
51
|
"devDependencies": {
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"@dxos/echo-
|
|
69
|
-
"@dxos/echo-db": "0.8.4-main.fd6878d",
|
|
70
|
-
"@dxos/random": "0.8.4-main.fd6878d"
|
|
52
|
+
"effect": "3.21.3",
|
|
53
|
+
"vitest": "4.1.7",
|
|
54
|
+
"@dxos/echo-client": "0.9.0"
|
|
71
55
|
},
|
|
72
56
|
"peerDependencies": {
|
|
73
|
-
"effect": "
|
|
57
|
+
"effect": "3.21.3"
|
|
74
58
|
},
|
|
75
59
|
"publishConfig": {
|
|
76
60
|
"access": "public"
|
package/src/Blueprint.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import * as Schema from 'effect/Schema';
|
|
9
|
+
|
|
10
|
+
import { ToolId } from '@dxos/ai';
|
|
11
|
+
import { DXN, Annotation, Database, Filter, Migration, Obj, Registry, Type, URI } from '@dxos/echo';
|
|
12
|
+
import { BaseError } from '@dxos/errors';
|
|
13
|
+
|
|
14
|
+
import * as McpServer from './McpServer';
|
|
15
|
+
import * as Operation from './Operation';
|
|
16
|
+
import * as Template from './Template';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Blueprint schema defines the structure for AI assistant blueprints.
|
|
20
|
+
* Blueprints contain instructions, tools, and artifacts that guide the AI's behavior.
|
|
21
|
+
* Blueprints may use tools to create and read artifacts, which are managed by the assistant.
|
|
22
|
+
*
|
|
23
|
+
* The registry `key` and `version` are stored in the object meta — access them via
|
|
24
|
+
* `Obj.getMeta(blueprint).key` and `Obj.getMeta(blueprint).version`.
|
|
25
|
+
*/
|
|
26
|
+
// TODO(burdon): Rename Skill?
|
|
27
|
+
export const Blueprint = Schema.Struct({
|
|
28
|
+
/**
|
|
29
|
+
* Human-readable name of the blueprint.
|
|
30
|
+
*/
|
|
31
|
+
name: Schema.String.annotations({
|
|
32
|
+
description: 'Human-readable name of the blueprint',
|
|
33
|
+
}),
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Description of the blueprint's purpose and functionality.
|
|
37
|
+
*/
|
|
38
|
+
description: Schema.optional(Schema.String).annotations({
|
|
39
|
+
description: "Description of the blueprint's purpose and functionality",
|
|
40
|
+
}),
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Instructions that guide the AI assistant's behavior and responses.
|
|
44
|
+
* These are system prompts or guidelines that the AI should follow.
|
|
45
|
+
*/
|
|
46
|
+
instructions: Template.Template.annotations({
|
|
47
|
+
description: "Instructions that guide the AI assistant's behavior and responses",
|
|
48
|
+
}),
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Array of tools that the AI assistant can use when this blueprint is active.
|
|
52
|
+
*/
|
|
53
|
+
tools: Schema.Array(ToolId).annotations({
|
|
54
|
+
description: 'Array of tools that the AI assistant can use when this blueprint is active',
|
|
55
|
+
}),
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Whether an agent is allowed to auto-enable this blueprint in a conversation.
|
|
59
|
+
*/
|
|
60
|
+
agentCanEnable: Schema.optional(Schema.Boolean).annotations({
|
|
61
|
+
description: 'Whether an agent is allowed to auto-enable this blueprint in a conversation.',
|
|
62
|
+
}),
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Array of MCP servers that the AI assistant can use when this blueprint is active.
|
|
66
|
+
*/
|
|
67
|
+
mcpServers: Schema.optional(Schema.Array(McpServer.McpServer)),
|
|
68
|
+
}).pipe(
|
|
69
|
+
Annotation.LabelAnnotation.set(['name']),
|
|
70
|
+
Annotation.IconAnnotation.set({ icon: 'ph--blueprint--regular', hue: 'sky' }),
|
|
71
|
+
Type.makeObject(DXN.make('org.dxos.type.blueprint', '0.2.0')),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* TypeScript type for Blueprint.
|
|
76
|
+
*/
|
|
77
|
+
export type Blueprint = Type.InstanceType<typeof Blueprint>;
|
|
78
|
+
|
|
79
|
+
type MakeProps = { key: string; version?: string; name: string } & Partial<Blueprint>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Create a new Blueprint.
|
|
83
|
+
* The `key` (and optional `version`) are stored in the object meta.
|
|
84
|
+
*/
|
|
85
|
+
export const make = ({ key, version, tools = [], instructions = Template.make(), ...props }: MakeProps) =>
|
|
86
|
+
Obj.make(Blueprint, {
|
|
87
|
+
[Obj.Meta]: { key, version },
|
|
88
|
+
tools,
|
|
89
|
+
instructions,
|
|
90
|
+
...props,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get the registry key for a blueprint.
|
|
95
|
+
*/
|
|
96
|
+
export const getKey = (blueprint: Blueprint): string => {
|
|
97
|
+
const key = Obj.getMeta(blueprint).key;
|
|
98
|
+
if (key === undefined) {
|
|
99
|
+
throw new Error('Blueprint is missing the meta key.');
|
|
100
|
+
}
|
|
101
|
+
return key;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get the registry version for a blueprint, if any.
|
|
106
|
+
*/
|
|
107
|
+
export const getVersion = (blueprint: Blueprint): string | undefined => Obj.getMeta(blueprint).version;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Util to create tool definitions for a blueprint.
|
|
111
|
+
*/
|
|
112
|
+
export const toolDefinitions = ({
|
|
113
|
+
tools = [],
|
|
114
|
+
operations = [],
|
|
115
|
+
}: {
|
|
116
|
+
tools?: string[];
|
|
117
|
+
operations?: Operation.Definition.Any[];
|
|
118
|
+
}) => [...operations.map((op) => ToolId.make(DXN.getName(op.meta.key))), ...tools.map((tool) => ToolId.make(tool))];
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Factory for the blueprints.
|
|
122
|
+
*/
|
|
123
|
+
export type Definition = {
|
|
124
|
+
key: string;
|
|
125
|
+
make: () => Blueprint;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Returns the canonical URI used to reference this blueprint in the registry.
|
|
130
|
+
* Valid DXN keys produce `dxn:<key>`; other keys use the raw key as a URI.
|
|
131
|
+
* Use this URI with `Ref.fromURI` to bind a blueprint without cloning it to the DB.
|
|
132
|
+
*
|
|
133
|
+
* TODO(wittjosiah): Should use Obj.getURI instead once it supports options to prefer meta key over EID.
|
|
134
|
+
*/
|
|
135
|
+
export const registryURI = (key: string): URI.URI => (DXN.tryMake(`dxn:${key}`) ?? URI.make(key)) as URI.URI;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Resolves a blueprint from the registry by its meta key.
|
|
139
|
+
* Does not check the local database for the blueprint.
|
|
140
|
+
*/
|
|
141
|
+
export const resolve = (key: string): Effect.Effect<Blueprint, NotFoundError, Registry.Service> =>
|
|
142
|
+
Effect.gen(function* () {
|
|
143
|
+
const results = yield* Registry.runQuery(Filter.and(Filter.type(Blueprint), Filter.key(key)));
|
|
144
|
+
const blueprint = results[0];
|
|
145
|
+
if (!blueprint) {
|
|
146
|
+
return yield* Effect.fail(new NotFoundError({ context: { key } }));
|
|
147
|
+
}
|
|
148
|
+
return blueprint;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Upserts a blueprint into the database.
|
|
153
|
+
* If the blueprint already exists in the database, the local (possibly forked) copy is returned as-is.
|
|
154
|
+
* Otherwise, a fresh copy is cloned from the registry and added.
|
|
155
|
+
* @deprecated Since we're using a registry we no longer need to store blueprints in the database.
|
|
156
|
+
*/
|
|
157
|
+
// TODO(dmaretskyi): Remove.
|
|
158
|
+
export const upsert = (key: string): Effect.Effect<Blueprint, NotFoundError, Registry.Service | Database.Service> =>
|
|
159
|
+
Effect.gen(function* () {
|
|
160
|
+
const local = yield* Database.query(Filter.and(Filter.type(Blueprint), Filter.key(key))).run;
|
|
161
|
+
if (local.length > 0) {
|
|
162
|
+
return local[0];
|
|
163
|
+
}
|
|
164
|
+
return yield* Database.add(Obj.clone(yield* resolve(key), { deep: true }));
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export class NotFoundError extends BaseError.extend('BlueprintNotFound', 'Blueprint not found') {}
|
|
168
|
+
|
|
169
|
+
//
|
|
170
|
+
// Legacy schemas and migrations.
|
|
171
|
+
//
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Blueprint schema v0.1.0 — `key` is stored as a data property.
|
|
175
|
+
* @deprecated Use {@link Blueprint} (v0.2.0) instead; the `key` and `version` now live in the object meta.
|
|
176
|
+
*/
|
|
177
|
+
export const Blueprint_v0_1_0 = Schema.Struct({
|
|
178
|
+
/**
|
|
179
|
+
* Global registry ID.
|
|
180
|
+
* NOTE: The `key` property refers to the original registry entry.
|
|
181
|
+
*/
|
|
182
|
+
key: Schema.String.annotations({
|
|
183
|
+
description: 'Unique registration key for the blueprint',
|
|
184
|
+
}),
|
|
185
|
+
|
|
186
|
+
name: Schema.String.annotations({
|
|
187
|
+
description: 'Human-readable name of the blueprint',
|
|
188
|
+
}),
|
|
189
|
+
|
|
190
|
+
description: Schema.optional(Schema.String),
|
|
191
|
+
|
|
192
|
+
instructions: Template.Template,
|
|
193
|
+
|
|
194
|
+
tools: Schema.Array(ToolId),
|
|
195
|
+
|
|
196
|
+
agentCanEnable: Schema.optional(Schema.Boolean),
|
|
197
|
+
|
|
198
|
+
mcpServers: Schema.optional(Schema.Array(McpServer.McpServer)),
|
|
199
|
+
}).pipe(Type.makeObject(DXN.make('org.dxos.type.blueprint', '0.1.0')));
|
|
200
|
+
|
|
201
|
+
export type Blueprint_v0_1_0 = Type.InstanceType<typeof Blueprint_v0_1_0>;
|
|
202
|
+
/**
|
|
203
|
+
* Migration from {@link Blueprint_v0_1_0} (v0.1.0) to {@link Blueprint} (v0.2.0).
|
|
204
|
+
* Moves `key` from the data section into the object meta.
|
|
205
|
+
*/
|
|
206
|
+
const _migration = Migration.define({
|
|
207
|
+
from: Blueprint_v0_1_0,
|
|
208
|
+
to: Blueprint,
|
|
209
|
+
transform: async (from) => ({
|
|
210
|
+
[Obj.Meta]: { key: from.key, version: '0.1.0' },
|
|
211
|
+
name: from.name,
|
|
212
|
+
description: from.description,
|
|
213
|
+
instructions: from.instructions,
|
|
214
|
+
tools: from.tools,
|
|
215
|
+
agentCanEnable: from.agentCanEnable,
|
|
216
|
+
mcpServers: from.mcpServers,
|
|
217
|
+
}),
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Schema migrations exported by this module.
|
|
222
|
+
* Exported as an array for extensibility — append future versions here.
|
|
223
|
+
*/
|
|
224
|
+
export const migrations = [_migration];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 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 Redacted from 'effect/Redacted';
|
|
10
|
+
|
|
11
|
+
export type CredentialQuery = {
|
|
12
|
+
service?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// TODO(dmaretskyi): Unify with other apis.
|
|
16
|
+
// packages/sdk/schema/src/common/access-token.ts
|
|
17
|
+
export type ServiceCredential = {
|
|
18
|
+
service: string;
|
|
19
|
+
|
|
20
|
+
// TODO(dmaretskyi): Build out.
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export class CredentialsService extends Context.Tag('@dxos/functions/CredentialsService')<
|
|
25
|
+
CredentialsService,
|
|
26
|
+
{
|
|
27
|
+
/**
|
|
28
|
+
* Query all.
|
|
29
|
+
*/
|
|
30
|
+
queryCredentials: (query: CredentialQuery) => Promise<ServiceCredential[]>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get a single credential.
|
|
34
|
+
* @throws {Error} If no credential is found.
|
|
35
|
+
*/
|
|
36
|
+
getCredential: (query: CredentialQuery) => Promise<ServiceCredential>;
|
|
37
|
+
}
|
|
38
|
+
>() {
|
|
39
|
+
static getCredential = (query: CredentialQuery): Effect.Effect<ServiceCredential, never, CredentialsService> =>
|
|
40
|
+
Effect.gen(function* () {
|
|
41
|
+
const credentials = yield* CredentialsService;
|
|
42
|
+
return yield* Effect.promise(() => credentials.getCredential(query));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
static getApiKey = (query: CredentialQuery): Effect.Effect<Redacted.Redacted<string>, never, CredentialsService> =>
|
|
46
|
+
Effect.gen(function* () {
|
|
47
|
+
const credential = yield* CredentialsService.getCredential(query);
|
|
48
|
+
if (!credential.apiKey) {
|
|
49
|
+
throw new Error(`API key not found for service: ${query.service}`);
|
|
50
|
+
}
|
|
51
|
+
return Redacted.make(credential.apiKey);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as HttpClient from '@effect/platform/HttpClient';
|
|
6
|
+
import * as HttpClientRequest from '@effect/platform/HttpClientRequest';
|
|
7
|
+
import * as HttpClientResponse from '@effect/platform/HttpClientResponse';
|
|
8
|
+
import * as Effect from 'effect/Effect';
|
|
9
|
+
import * as Layer from 'effect/Layer';
|
|
10
|
+
import { describe, test } from 'vitest';
|
|
11
|
+
|
|
12
|
+
import { EffectEx } from '@dxos/effect';
|
|
13
|
+
|
|
14
|
+
import * as Credential from './Credential';
|
|
15
|
+
import * as Header from './Header';
|
|
16
|
+
|
|
17
|
+
describe('Header.byokLayer', () => {
|
|
18
|
+
test('attaches X-BYOK header when a credential is found for the provider host', async ({ expect }) => {
|
|
19
|
+
const sink: { lastHeader?: string } = {};
|
|
20
|
+
|
|
21
|
+
const program = Effect.gen(function* () {
|
|
22
|
+
const client = yield* HttpClient.HttpClient;
|
|
23
|
+
yield* client.execute(HttpClientRequest.get('http://internal/provider/anthropic/messages'));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const runnable = program.pipe(
|
|
27
|
+
Effect.provide(
|
|
28
|
+
Header.byokLayer('anthropic.com').pipe(
|
|
29
|
+
Layer.provide(captureHeaderClient(sink)),
|
|
30
|
+
Layer.provide(credentialsLayer([{ service: 'anthropic.com', apiKey: 'sk-ant-user' }])),
|
|
31
|
+
),
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
await EffectEx.runAndForwardErrors(runnable as Effect.Effect<void>);
|
|
35
|
+
|
|
36
|
+
expect(sink.lastHeader).toBe('sk-ant-user');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('does not attach X-BYOK when no credential is found', async ({ expect }) => {
|
|
40
|
+
const sink: { lastHeader?: string } = {};
|
|
41
|
+
|
|
42
|
+
const program = Effect.gen(function* () {
|
|
43
|
+
const client = yield* HttpClient.HttpClient;
|
|
44
|
+
yield* client.execute(HttpClientRequest.get('http://internal/provider/anthropic/messages'));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const runnable = program.pipe(
|
|
48
|
+
Effect.provide(
|
|
49
|
+
Header.byokLayer('anthropic.com').pipe(
|
|
50
|
+
Layer.provide(captureHeaderClient(sink)),
|
|
51
|
+
Layer.provide(credentialsLayer([])),
|
|
52
|
+
),
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
await EffectEx.runAndForwardErrors(runnable as Effect.Effect<void>);
|
|
56
|
+
|
|
57
|
+
expect(sink.lastHeader).toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('does not attach X-BYOK when the matching credential has no apiKey', async ({ expect }) => {
|
|
61
|
+
const sink: { lastHeader?: string } = {};
|
|
62
|
+
|
|
63
|
+
const program = Effect.gen(function* () {
|
|
64
|
+
const client = yield* HttpClient.HttpClient;
|
|
65
|
+
yield* client.execute(HttpClientRequest.get('http://internal/provider/anthropic/messages'));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const runnable = program.pipe(
|
|
69
|
+
Effect.provide(
|
|
70
|
+
Header.byokLayer('anthropic.com').pipe(
|
|
71
|
+
Layer.provide(captureHeaderClient(sink)),
|
|
72
|
+
Layer.provide(credentialsLayer([{ service: 'anthropic.com' }])),
|
|
73
|
+
),
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
await EffectEx.runAndForwardErrors(runnable as Effect.Effect<void>);
|
|
77
|
+
|
|
78
|
+
expect(sink.lastHeader).toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('forwards the request unchanged when queryCredentials throws', async ({ expect }) => {
|
|
82
|
+
const sink: { lastHeader?: string; called?: boolean } = {};
|
|
83
|
+
const failingCredentials = Layer.succeed(Credential.CredentialsService, {
|
|
84
|
+
queryCredentials: async () => {
|
|
85
|
+
throw new Error('database unreachable');
|
|
86
|
+
},
|
|
87
|
+
getCredential: async () => {
|
|
88
|
+
throw new Error('database unreachable');
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const program = Effect.gen(function* () {
|
|
93
|
+
const client = yield* HttpClient.HttpClient;
|
|
94
|
+
sink.called = true;
|
|
95
|
+
yield* client.execute(HttpClientRequest.get('http://internal/provider/anthropic/messages'));
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const runnable = program.pipe(
|
|
99
|
+
Effect.provide(
|
|
100
|
+
Header.byokLayer('anthropic.com').pipe(
|
|
101
|
+
Layer.provide(captureHeaderClient(sink)),
|
|
102
|
+
Layer.provide(failingCredentials),
|
|
103
|
+
),
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
await EffectEx.runAndForwardErrors(runnable as Effect.Effect<void>);
|
|
107
|
+
|
|
108
|
+
expect(sink.called).toBe(true);
|
|
109
|
+
expect(sink.lastHeader).toBeUndefined();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const captureHeaderClient = (sink: { lastHeader?: string }) =>
|
|
114
|
+
Layer.succeed(
|
|
115
|
+
HttpClient.HttpClient,
|
|
116
|
+
HttpClient.make((request) => {
|
|
117
|
+
sink.lastHeader = request.headers['x-byok'];
|
|
118
|
+
return Effect.succeed(HttpClientResponse.fromWeb(request, new Response('ok')));
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const credentialsLayer = (credentials: Credential.ServiceCredential[]) =>
|
|
123
|
+
Layer.succeed(Credential.CredentialsService, {
|
|
124
|
+
queryCredentials: async ({ service }) => credentials.filter((credential) => credential.service === service),
|
|
125
|
+
getCredential: async ({ service }) => {
|
|
126
|
+
const credential = credentials.find((entry) => entry.service === service);
|
|
127
|
+
if (!credential) {
|
|
128
|
+
throw new Error(`Credential not found for service: ${service}`);
|
|
129
|
+
}
|
|
130
|
+
return credential;
|
|
131
|
+
},
|
|
132
|
+
});
|
package/src/Header.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
import * as HttpClient from '@effect/platform/HttpClient';
|
|
8
|
+
import * as HttpClientRequest from '@effect/platform/HttpClientRequest';
|
|
9
|
+
import * as Effect from 'effect/Effect';
|
|
10
|
+
import * as Layer from 'effect/Layer';
|
|
11
|
+
|
|
12
|
+
import { BYOK_HEADER } from '@dxos/protocols';
|
|
13
|
+
|
|
14
|
+
import * as Credential from './Credential';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Wraps an `HttpClient` so outbound requests carry `X-BYOK: <apiKey>` whenever the active space
|
|
18
|
+
* has an `AccessToken` for `providerHost`. Lookup failures pass the request through unchanged.
|
|
19
|
+
*/
|
|
20
|
+
export const byokLayer = (
|
|
21
|
+
providerHost: string,
|
|
22
|
+
): Layer.Layer<HttpClient.HttpClient, never, HttpClient.HttpClient | Credential.CredentialsService> =>
|
|
23
|
+
Layer.effect(
|
|
24
|
+
HttpClient.HttpClient,
|
|
25
|
+
Effect.gen(function* () {
|
|
26
|
+
const client = yield* HttpClient.HttpClient;
|
|
27
|
+
const credentials = yield* Credential.CredentialsService;
|
|
28
|
+
return HttpClient.mapRequestEffect(client, (request) =>
|
|
29
|
+
Effect.gen(function* () {
|
|
30
|
+
const matches = yield* Effect.tryPromise(() => credentials.queryCredentials({ service: providerHost })).pipe(
|
|
31
|
+
Effect.orElseSucceed((): Credential.ServiceCredential[] => []),
|
|
32
|
+
);
|
|
33
|
+
const apiKey = matches.find((credential) => credential.apiKey)?.apiKey;
|
|
34
|
+
return apiKey ? HttpClientRequest.setHeader(request, BYOK_HEADER, apiKey) : request;
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
}),
|
|
38
|
+
);
|
package/src/LayerSpec.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Context from 'effect/Context';
|
|
6
|
+
import * as Layer from 'effect/Layer';
|
|
7
|
+
import * as Types from 'effect/Types';
|
|
8
|
+
|
|
9
|
+
import { SpaceId, type URI } from '@dxos/keys';
|
|
10
|
+
|
|
11
|
+
import type * as Process from './Process';
|
|
12
|
+
|
|
13
|
+
// @import-as-namespace
|
|
14
|
+
|
|
15
|
+
export const TypeId = '~@dxos/functions/LayerSpec' as const;
|
|
16
|
+
export type TypeId = typeof TypeId;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Opaque layer with introspectable tags.
|
|
20
|
+
*/
|
|
21
|
+
export interface LayerSpec {
|
|
22
|
+
readonly [TypeId]: TypeId;
|
|
23
|
+
|
|
24
|
+
readonly affinity: Affinity;
|
|
25
|
+
readonly requires: readonly Context.Tag<any, any>[];
|
|
26
|
+
readonly provides: readonly Context.Tag<any, any>[];
|
|
27
|
+
|
|
28
|
+
// opaque service creation function, layer provides the specified services and requires the specified requirements.
|
|
29
|
+
readonly make: (context: LayerContext) => Layer.Layer<unknown, never, unknown>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Affinity defines the lifetime and scope of a service.
|
|
34
|
+
*
|
|
35
|
+
* - `application` - single service instance is available throughout the entire application.
|
|
36
|
+
* - `space` - service is instantiated per space.
|
|
37
|
+
* - `process` - separate service instance is created and destroyed for each process.
|
|
38
|
+
*/
|
|
39
|
+
export type Affinity = 'application' | 'space' | 'process';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Provides context for service resolution.
|
|
43
|
+
*/
|
|
44
|
+
// TODO(dmaretskyi): Consider making this type dependant on the specified service affinity.
|
|
45
|
+
export interface LayerContext {
|
|
46
|
+
/**
|
|
47
|
+
* Under which space the process is running.
|
|
48
|
+
* Space affinity and up only.
|
|
49
|
+
*/
|
|
50
|
+
readonly space?: SpaceId;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* URI of the conversation feed the process is running in.
|
|
54
|
+
* Process affinity only.
|
|
55
|
+
*/
|
|
56
|
+
readonly conversation?: URI.URI;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Under which process the process is running.
|
|
60
|
+
* Process affinity only.
|
|
61
|
+
*/
|
|
62
|
+
readonly process?: Process.ID;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface MakeOpts {
|
|
66
|
+
readonly affinity: Affinity;
|
|
67
|
+
readonly requires: readonly Context.Tag<any, any>[];
|
|
68
|
+
readonly provides: readonly Context.Tag<any, any>[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Make a service.
|
|
73
|
+
*/
|
|
74
|
+
export const make = <const Opts extends Types.NoExcessProperties<MakeOpts, Opts>>(
|
|
75
|
+
opts: Opts,
|
|
76
|
+
make: (
|
|
77
|
+
context: LayerContext,
|
|
78
|
+
) => Layer.Layer<
|
|
79
|
+
Context.Tag.Identifier<Opts['provides'][number]>,
|
|
80
|
+
never,
|
|
81
|
+
Context.Tag.Identifier<Opts['requires'][number]>
|
|
82
|
+
>,
|
|
83
|
+
): LayerSpec => {
|
|
84
|
+
return {
|
|
85
|
+
[TypeId]: TypeId,
|
|
86
|
+
affinity: opts.affinity,
|
|
87
|
+
requires: opts.requires,
|
|
88
|
+
provides: opts.provides,
|
|
89
|
+
make: make as any,
|
|
90
|
+
};
|
|
91
|
+
};
|