@dxos/compute 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.
- package/README.md +36 -1
- package/dist/lib/neutral/StorageService.mjs +22 -0
- package/dist/lib/neutral/StorageService.mjs.map +7 -0
- package/dist/lib/neutral/chunk-4N4JAXCP.mjs +17 -0
- package/dist/lib/neutral/chunk-4N4JAXCP.mjs.map +7 -0
- package/dist/lib/neutral/chunk-DDEBBRCI.mjs +62 -0
- package/dist/lib/neutral/chunk-DDEBBRCI.mjs.map +7 -0
- package/dist/lib/neutral/chunk-FEABF5XY.mjs +25 -0
- package/dist/lib/neutral/chunk-FEABF5XY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-H6EHIVDN.mjs +21 -0
- package/dist/lib/neutral/chunk-H6EHIVDN.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-N462A6NO.mjs +138 -0
- package/dist/lib/neutral/chunk-N462A6NO.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QPCDM7MF.mjs +179 -0
- package/dist/lib/neutral/chunk-QPCDM7MF.mjs.map +7 -0
- package/dist/lib/neutral/chunk-S24LL2D5.mjs +52 -0
- package/dist/lib/neutral/chunk-S24LL2D5.mjs.map +7 -0
- package/dist/lib/neutral/fib-HDHBZHPE.mjs +10 -0
- package/dist/lib/neutral/fib-HDHBZHPE.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1030 -51
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/reply-XSQMXAPX.mjs +10 -0
- package/dist/lib/neutral/reply-XSQMXAPX.mjs.map +7 -0
- package/dist/lib/neutral/sleep-WHTJQ56P.mjs +10 -0
- package/dist/lib/neutral/sleep-WHTJQ56P.mjs.map +7 -0
- package/dist/lib/neutral/testing/index.mjs +27 -193
- package/dist/lib/neutral/testing/index.mjs.map +4 -4
- package/dist/types/src/Blueprint.d.ts +148 -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/Operation.d.ts +303 -0
- package/dist/types/src/Operation.d.ts.map +1 -0
- package/dist/types/src/OperationHandlerSet.d.ts +60 -0
- package/dist/types/src/OperationHandlerSet.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 +247 -0
- package/dist/types/src/Process.d.ts.map +1 -0
- package/dist/types/src/Routine.d.ts +61 -0
- package/dist/types/src/Routine.d.ts.map +1 -0
- package/dist/types/src/Script.d.ts +22 -0
- package/dist/types/src/Script.d.ts.map +1 -0
- package/dist/types/src/ServiceResolver.d.ts +74 -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 +56 -0
- package/dist/types/src/Template.d.ts.map +1 -0
- package/dist/types/src/Trace.d.ts +174 -0
- package/dist/types/src/Trace.d.ts.map +1 -0
- package/dist/types/src/Trigger.d.ts +150 -0
- package/dist/types/src/Trigger.d.ts.map +1 -0
- package/dist/types/src/TriggerEvent.d.ts +75 -0
- package/dist/types/src/TriggerEvent.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +239 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +15 -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 -4
- 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 +20 -34
- package/src/Blueprint.ts +221 -0
- package/src/Credential.ts +51 -0
- package/src/Operation.ts +513 -0
- package/src/OperationHandlerSet.ts +132 -0
- package/src/OperationRegistry.ts +48 -0
- package/src/Process.ts +490 -0
- package/src/Routine.ts +84 -0
- package/src/Script.ts +38 -0
- package/src/ServiceResolver.ts +174 -0
- package/src/StorageService.ts +99 -0
- package/src/Template.ts +105 -0
- package/src/Trace.ts +231 -0
- package/src/Trigger.ts +207 -0
- package/src/TriggerEvent.ts +62 -0
- package/src/errors.ts +50 -0
- package/src/index.ts +16 -6
- package/src/testing/definitions.ts +49 -0
- package/src/testing/fib.ts +22 -0
- package/src/testing/index.ts +13 -5
- package/src/testing/reply.ts +18 -0
- package/src/testing/sleep.ts +16 -0
- package/src/umbrella.test.ts +51 -0
- package/dist/lib/neutral/chunk-36MMQLBR.mjs +0 -3104
- package/dist/lib/neutral/chunk-36MMQLBR.mjs.map +0 -7
- package/dist/types/src/compute-graph-registry.d.ts +0 -37
- package/dist/types/src/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/compute-graph-registry.test.d.ts +0 -2
- package/dist/types/src/compute-graph-registry.test.d.ts.map +0 -1
- package/dist/types/src/compute-graph.d.ts +0 -67
- 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 -24
- package/dist/types/src/compute-node.d.ts.map +0 -1
- package/dist/types/src/functions/async-function.d.ts +0 -68
- 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 -35
- package/dist/types/src/testing/test-plugin.d.ts.map +0 -1
- package/dist/types/src/testing/test-runtime.d.ts +0 -10
- package/dist/types/src/testing/test-runtime.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 -8
- 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/src/compute-graph-registry.test.ts +0 -167
- package/src/compute-graph-registry.ts +0 -97
- package/src/compute-graph.test.ts +0 -139
- package/src/compute-graph.ts +0 -266
- package/src/compute-node.ts +0 -59
- package/src/functions/async-function.ts +0 -184
- package/src/functions/edge-function.ts +0 -113
- 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 -59
- package/src/testing/test-plugin.ts +0 -98
- package/src/testing/test-runtime.ts +0 -36
- 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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/compute",
|
|
3
|
-
"version": "0.8.4-main.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.8.4-main.abd8ff62ef",
|
|
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": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"author": "DXOS.org",
|
|
13
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
14
14
|
"type": "module",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
@@ -18,6 +18,11 @@
|
|
|
18
18
|
"types": "./dist/types/src/index.d.ts",
|
|
19
19
|
"default": "./dist/lib/neutral/index.mjs"
|
|
20
20
|
},
|
|
21
|
+
"./StorageService": {
|
|
22
|
+
"source": "./src/StorageService.ts",
|
|
23
|
+
"types": "./dist/types/src/StorageService.d.ts",
|
|
24
|
+
"default": "./dist/lib/neutral/StorageService.mjs"
|
|
25
|
+
},
|
|
21
26
|
"./testing": {
|
|
22
27
|
"source": "./src/testing/index.ts",
|
|
23
28
|
"types": "./dist/types/src/testing/index.d.ts",
|
|
@@ -25,44 +30,25 @@
|
|
|
25
30
|
}
|
|
26
31
|
},
|
|
27
32
|
"types": "dist/types/src/index.d.ts",
|
|
28
|
-
"typesVersions": {
|
|
29
|
-
"*": {
|
|
30
|
-
"testing": [
|
|
31
|
-
"dist/types/src/testing/index.d.ts"
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
33
|
"files": [
|
|
36
34
|
"dist",
|
|
37
35
|
"src"
|
|
38
36
|
],
|
|
39
37
|
"dependencies": {
|
|
40
|
-
"effect": "
|
|
41
|
-
"
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/keys": "0.8.4-main.9be5663bfe",
|
|
51
|
-
"@dxos/log": "0.8.4-main.9be5663bfe",
|
|
52
|
-
"@dxos/operation": "0.8.4-main.9be5663bfe",
|
|
53
|
-
"@dxos/invariant": "0.8.4-main.9be5663bfe",
|
|
54
|
-
"@dxos/protocols": "0.8.4-main.9be5663bfe",
|
|
55
|
-
"@dxos/plugin-automation": "0.8.4-main.9be5663bfe",
|
|
56
|
-
"@dxos/util": "0.8.4-main.9be5663bfe",
|
|
57
|
-
"@dxos/vendor-hyperformula": "0.8.4-main.9be5663bfe",
|
|
58
|
-
"@dxos/schema": "0.8.4-main.9be5663bfe"
|
|
38
|
+
"@effect-atom/atom": "^0.5.1",
|
|
39
|
+
"handlebars": "4.7.8",
|
|
40
|
+
"@dxos/echo": "0.8.4-main.abd8ff62ef",
|
|
41
|
+
"@dxos/ai": "0.8.4-main.abd8ff62ef",
|
|
42
|
+
"@dxos/errors": "0.8.4-main.abd8ff62ef",
|
|
43
|
+
"@dxos/keys": "0.8.4-main.abd8ff62ef",
|
|
44
|
+
"@dxos/log": "0.8.4-main.abd8ff62ef",
|
|
45
|
+
"@dxos/invariant": "0.8.4-main.abd8ff62ef",
|
|
46
|
+
"@dxos/protocols": "0.8.4-main.abd8ff62ef",
|
|
47
|
+
"@dxos/schema": "0.8.4-main.abd8ff62ef"
|
|
59
48
|
},
|
|
60
49
|
"devDependencies": {
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"@dxos/echo": "0.8.4-main.9be5663bfe",
|
|
64
|
-
"@dxos/random": "0.8.4-main.9be5663bfe",
|
|
65
|
-
"@dxos/echo-db": "0.8.4-main.9be5663bfe"
|
|
50
|
+
"effect": "3.20.0",
|
|
51
|
+
"vitest": "4.1.5"
|
|
66
52
|
},
|
|
67
53
|
"peerDependencies": {
|
|
68
54
|
"effect": "3.20.0"
|
package/src/Blueprint.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Context from 'effect/Context';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
|
|
9
|
+
import { ToolId } from '@dxos/ai';
|
|
10
|
+
import { Annotation, Database, Filter, Obj, Type } from '@dxos/echo';
|
|
11
|
+
import { BaseError } from '@dxos/errors';
|
|
12
|
+
import { log } from '@dxos/log';
|
|
13
|
+
|
|
14
|
+
import * as Operation from './Operation';
|
|
15
|
+
import * as Template from './Template';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* MCP server definition.
|
|
19
|
+
*/
|
|
20
|
+
export const McpServer = Schema.Struct({
|
|
21
|
+
/**
|
|
22
|
+
* URL of the MCP server.
|
|
23
|
+
*/
|
|
24
|
+
url: Schema.String.annotations({
|
|
25
|
+
description: 'URL of the MCP server',
|
|
26
|
+
}),
|
|
27
|
+
|
|
28
|
+
protocol: Schema.Union(Schema.Literal('sse'), Schema.Literal('http')).annotations({
|
|
29
|
+
description: 'Protocol of the MCP server',
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
export interface McpServer extends Schema.Schema.Type<typeof McpServer> {}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Blueprint schema defines the structure for AI assistant blueprints.
|
|
36
|
+
* Blueprints contain instructions, tools, and artifacts that guide the AI's behavior.
|
|
37
|
+
* Blueprints may use tools to create and read artifacts, which are managed by the assistant.
|
|
38
|
+
*/
|
|
39
|
+
export const Blueprint = Schema.Struct({
|
|
40
|
+
/**
|
|
41
|
+
* Global registry ID.
|
|
42
|
+
* NOTE: The `key` property refers to the original registry entry.
|
|
43
|
+
*/
|
|
44
|
+
// TODO(burdon): Create Format type for DXN-like ids, such as this and schema type.
|
|
45
|
+
key: Schema.String.annotations({
|
|
46
|
+
description: 'Unique registration key for the blueprint',
|
|
47
|
+
}),
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Human-readable name of the blueprint.
|
|
51
|
+
*/
|
|
52
|
+
name: Schema.String.annotations({
|
|
53
|
+
description: 'Human-readable name of the blueprint',
|
|
54
|
+
}),
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Description of the blueprint's purpose and functionality.
|
|
58
|
+
*/
|
|
59
|
+
description: Schema.optional(Schema.String).annotations({
|
|
60
|
+
description: "Description of the blueprint's purpose and functionality",
|
|
61
|
+
}),
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Instructions that guide the AI assistant's behavior and responses.
|
|
65
|
+
* These are system prompts or guidelines that the AI should follow.
|
|
66
|
+
*/
|
|
67
|
+
instructions: Template.Template.annotations({
|
|
68
|
+
description: "Instructions that guide the AI assistant's behavior and responses",
|
|
69
|
+
}),
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Array of tools that the AI assistant can use when this blueprint is active.
|
|
73
|
+
*/
|
|
74
|
+
tools: Schema.Array(ToolId).annotations({
|
|
75
|
+
description: 'Array of tools that the AI assistant can use when this blueprint is active',
|
|
76
|
+
}),
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Whether an agent is allowed to auto-enable this blueprint in a conversation.
|
|
80
|
+
*/
|
|
81
|
+
agentCanEnable: Schema.optional(Schema.Boolean).annotations({
|
|
82
|
+
description: 'Whether an agent is allowed to auto-enable this blueprint in a conversation.',
|
|
83
|
+
}),
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Array of MCP servers that the AI assistant can use when this blueprint is active.
|
|
87
|
+
*/
|
|
88
|
+
mcpServers: Schema.optional(Schema.Array(McpServer)),
|
|
89
|
+
}).pipe(
|
|
90
|
+
Type.object({
|
|
91
|
+
// TODO(burdon): Is this a DXN? Need to create a Format type for these IDs.
|
|
92
|
+
typename: 'org.dxos.type.blueprint',
|
|
93
|
+
version: '0.1.0',
|
|
94
|
+
}),
|
|
95
|
+
Annotation.LabelAnnotation.set(['name']),
|
|
96
|
+
Annotation.IconAnnotation.set({
|
|
97
|
+
icon: 'ph--blueprint--regular',
|
|
98
|
+
hue: 'sky',
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* TypeScript type for Blueprint.
|
|
104
|
+
*/
|
|
105
|
+
export interface Blueprint extends Schema.Schema.Type<typeof Blueprint> {}
|
|
106
|
+
|
|
107
|
+
type MakeProps = Pick<Blueprint, 'key' | 'name'> & Partial<Blueprint>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Create a new Blueprint.
|
|
111
|
+
*/
|
|
112
|
+
export const make = ({ tools = [], instructions = Template.make(), ...props }: MakeProps) =>
|
|
113
|
+
Obj.make(Blueprint, {
|
|
114
|
+
tools,
|
|
115
|
+
instructions,
|
|
116
|
+
...props,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Util to create tool definitions for a blueprint.
|
|
121
|
+
*/
|
|
122
|
+
export const toolDefinitions = ({
|
|
123
|
+
tools = [],
|
|
124
|
+
operations = [],
|
|
125
|
+
}: {
|
|
126
|
+
tools?: string[];
|
|
127
|
+
operations?: Operation.Definition.Any[];
|
|
128
|
+
}) => [...operations.map((op) => ToolId.make(op.meta.key)), ...tools.map((tool) => ToolId.make(tool))];
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Factory for the blueprints.
|
|
132
|
+
*/
|
|
133
|
+
export type Definition = {
|
|
134
|
+
key: string;
|
|
135
|
+
make: () => Blueprint;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
//
|
|
139
|
+
// Registry
|
|
140
|
+
//
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Blueprint registry.
|
|
144
|
+
*/
|
|
145
|
+
export class Registry {
|
|
146
|
+
private readonly _blueprints: Blueprint[] = [];
|
|
147
|
+
|
|
148
|
+
constructor(blueprints: Blueprint[]) {
|
|
149
|
+
const seen = new Set<string>();
|
|
150
|
+
blueprints.forEach((blueprint) => {
|
|
151
|
+
if (seen.has(blueprint.key)) {
|
|
152
|
+
log.warn('duplicate blueprint', { key: blueprint.key });
|
|
153
|
+
} else {
|
|
154
|
+
seen.add(blueprint.key);
|
|
155
|
+
this._blueprints.push(blueprint);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
this._blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
get blueprints(): Blueprint[] {
|
|
163
|
+
return this._blueprints;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
getByKey(key: string): Blueprint | undefined {
|
|
167
|
+
return this._blueprints.find((blueprint) => blueprint.key === key);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
query(): Blueprint[] {
|
|
171
|
+
return this._blueprints;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
updateBlueprints(): Effect.Effect<void, never, Database.Service> {
|
|
175
|
+
return Effect.gen(this, function* () {
|
|
176
|
+
const blueprints = yield* Database.runQuery(Filter.type(Blueprint));
|
|
177
|
+
for (const blueprint of blueprints) {
|
|
178
|
+
const registryBlueprint = this.getByKey(blueprint.key);
|
|
179
|
+
if (!registryBlueprint) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const source = Obj.clone(registryBlueprint, { deep: true });
|
|
183
|
+
Obj.update(blueprint, (blueprint) => {
|
|
184
|
+
void Obj.updateFrom(blueprint, source);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}).pipe(Effect.orDie);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export class RegistryService extends Context.Tag('@dxos/blueprints/RegistryService')<RegistryService, Registry>() {}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Resolves a blueprint from the registry.
|
|
195
|
+
* Does not check the local database for the blueprint.
|
|
196
|
+
*/
|
|
197
|
+
export const resolve = (key: string): Effect.Effect<Blueprint, NotFoundError, RegistryService> =>
|
|
198
|
+
Effect.gen(function* () {
|
|
199
|
+
const registry = yield* RegistryService;
|
|
200
|
+
const blueprint = registry.getByKey(key);
|
|
201
|
+
if (!blueprint) {
|
|
202
|
+
return yield* Effect.fail(new NotFoundError({ context: { key } }));
|
|
203
|
+
}
|
|
204
|
+
return blueprint;
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Upserts a blueprint into the database.
|
|
209
|
+
* If the blueprint already exists in the database, local blueprint is returned.
|
|
210
|
+
* Otherwise, it will be added.
|
|
211
|
+
*/
|
|
212
|
+
export const upsert = (key: string): Effect.Effect<Blueprint, NotFoundError, RegistryService | Database.Service> =>
|
|
213
|
+
Effect.gen(function* () {
|
|
214
|
+
const local = yield* Database.runQuery(Filter.type(Blueprint, { key }));
|
|
215
|
+
if (local.length > 0) {
|
|
216
|
+
return local[0];
|
|
217
|
+
}
|
|
218
|
+
return yield* Database.add(Obj.clone(yield* resolve(key), { deep: true }));
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
export class NotFoundError extends BaseError.extend('BlueprintNotFound', 'Blueprint not found') {}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Context from 'effect/Context';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Redacted from 'effect/Redacted';
|
|
8
|
+
|
|
9
|
+
export type CredentialQuery = {
|
|
10
|
+
service?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// TODO(dmaretskyi): Unify with other apis.
|
|
14
|
+
// packages/sdk/schema/src/common/access-token.ts
|
|
15
|
+
export type ServiceCredential = {
|
|
16
|
+
service: string;
|
|
17
|
+
|
|
18
|
+
// TODO(dmaretskyi): Build out.
|
|
19
|
+
apiKey?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export class CredentialsService extends Context.Tag('@dxos/functions/CredentialsService')<
|
|
23
|
+
CredentialsService,
|
|
24
|
+
{
|
|
25
|
+
/**
|
|
26
|
+
* Query all.
|
|
27
|
+
*/
|
|
28
|
+
queryCredentials: (query: CredentialQuery) => Promise<ServiceCredential[]>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get a single credential.
|
|
32
|
+
* @throws {Error} If no credential is found.
|
|
33
|
+
*/
|
|
34
|
+
getCredential: (query: CredentialQuery) => Promise<ServiceCredential>;
|
|
35
|
+
}
|
|
36
|
+
>() {
|
|
37
|
+
static getCredential = (query: CredentialQuery): Effect.Effect<ServiceCredential, never, CredentialsService> =>
|
|
38
|
+
Effect.gen(function* () {
|
|
39
|
+
const credentials = yield* CredentialsService;
|
|
40
|
+
return yield* Effect.promise(() => credentials.getCredential(query));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
static getApiKey = (query: CredentialQuery): Effect.Effect<Redacted.Redacted<string>, never, CredentialsService> =>
|
|
44
|
+
Effect.gen(function* () {
|
|
45
|
+
const credential = yield* CredentialsService.getCredential(query);
|
|
46
|
+
if (!credential.apiKey) {
|
|
47
|
+
throw new Error(`API key not found for service: ${query.service}`);
|
|
48
|
+
}
|
|
49
|
+
return Redacted.make(credential.apiKey);
|
|
50
|
+
});
|
|
51
|
+
}
|