@dxos/compute 0.8.4-main.cb12b3f963 → 0.8.4-main.dfabb4ec29

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 (74) hide show
  1. package/dist/lib/neutral/StorageService.mjs +1 -1
  2. package/dist/lib/neutral/{chunk-S24LL2D5.mjs → chunk-CXDV2FPU.mjs} +6 -5
  3. package/dist/lib/neutral/chunk-CXDV2FPU.mjs.map +7 -0
  4. package/dist/lib/neutral/{chunk-FEABF5XY.mjs → chunk-EG7VLX2F.mjs} +3 -3
  5. package/dist/lib/neutral/{chunk-N462A6NO.mjs → chunk-JTZYM2QW.mjs} +7 -1
  6. package/dist/lib/neutral/chunk-JTZYM2QW.mjs.map +7 -0
  7. package/dist/lib/neutral/{chunk-4N4JAXCP.mjs → chunk-OA7JMLJK.mjs} +3 -3
  8. package/dist/lib/neutral/{chunk-QPCDM7MF.mjs → chunk-VIRNEVFD.mjs} +22 -2
  9. package/dist/lib/neutral/chunk-VIRNEVFD.mjs.map +7 -0
  10. package/dist/lib/neutral/{chunk-DDEBBRCI.mjs → chunk-XEVFBI6S.mjs} +1 -1
  11. package/dist/lib/neutral/chunk-XEVFBI6S.mjs.map +7 -0
  12. package/dist/lib/neutral/{chunk-H6EHIVDN.mjs → chunk-YEDUHFRC.mjs} +3 -3
  13. package/dist/lib/neutral/fib-WSN4EY7R.mjs +10 -0
  14. package/dist/lib/neutral/index.mjs +186 -147
  15. package/dist/lib/neutral/index.mjs.map +4 -4
  16. package/dist/lib/neutral/meta.json +1 -1
  17. package/dist/lib/neutral/reply-XRLTFNDF.mjs +10 -0
  18. package/dist/lib/neutral/sleep-7O76LQCA.mjs +10 -0
  19. package/dist/lib/neutral/testing/index.mjs +7 -7
  20. package/dist/types/src/Blueprint.d.ts +8 -16
  21. package/dist/types/src/Blueprint.d.ts.map +1 -1
  22. package/dist/types/src/Credential.d.ts.map +1 -1
  23. package/dist/types/src/McpServer.d.ts +27 -0
  24. package/dist/types/src/McpServer.d.ts.map +1 -0
  25. package/dist/types/src/Operation.d.ts +6 -0
  26. package/dist/types/src/Operation.d.ts.map +1 -1
  27. package/dist/types/src/OperationHandlerSet.d.ts.map +1 -1
  28. package/dist/types/src/OperationRegistry.d.ts.map +1 -1
  29. package/dist/types/src/Routine.d.ts +6 -4
  30. package/dist/types/src/Routine.d.ts.map +1 -1
  31. package/dist/types/src/Script.d.ts.map +1 -1
  32. package/dist/types/src/StorageService.d.ts.map +1 -1
  33. package/dist/types/src/Template.d.ts +18 -12
  34. package/dist/types/src/Template.d.ts.map +1 -1
  35. package/dist/types/src/Template.test.d.ts +2 -0
  36. package/dist/types/src/Template.test.d.ts.map +1 -0
  37. package/dist/types/src/Trigger.d.ts.map +1 -1
  38. package/dist/types/src/TriggerEvent.d.ts.map +1 -1
  39. package/dist/types/src/errors.d.ts +69 -0
  40. package/dist/types/src/errors.d.ts.map +1 -1
  41. package/dist/types/src/index.d.ts +2 -1
  42. package/dist/types/src/index.d.ts.map +1 -1
  43. package/dist/types/src/testing/definitions.d.ts.map +1 -1
  44. package/dist/types/tsconfig.tsbuildinfo +1 -1
  45. package/package.json +10 -10
  46. package/src/Blueprint.ts +5 -19
  47. package/src/Credential.ts +2 -0
  48. package/src/McpServer.ts +44 -0
  49. package/src/Operation.ts +23 -3
  50. package/src/OperationHandlerSet.ts +2 -0
  51. package/src/OperationRegistry.ts +2 -0
  52. package/src/Routine.ts +4 -0
  53. package/src/Script.ts +2 -0
  54. package/src/StorageService.ts +2 -0
  55. package/src/Template.test.ts +151 -0
  56. package/src/Template.ts +48 -31
  57. package/src/Trigger.ts +2 -0
  58. package/src/TriggerEvent.ts +2 -0
  59. package/src/errors.ts +21 -0
  60. package/src/index.ts +3 -1
  61. package/src/testing/definitions.ts +3 -3
  62. package/dist/lib/neutral/chunk-DDEBBRCI.mjs.map +0 -7
  63. package/dist/lib/neutral/chunk-N462A6NO.mjs.map +0 -7
  64. package/dist/lib/neutral/chunk-QPCDM7MF.mjs.map +0 -7
  65. package/dist/lib/neutral/chunk-S24LL2D5.mjs.map +0 -7
  66. package/dist/lib/neutral/fib-HDHBZHPE.mjs +0 -10
  67. package/dist/lib/neutral/reply-XSQMXAPX.mjs +0 -10
  68. package/dist/lib/neutral/sleep-WHTJQ56P.mjs +0 -10
  69. /package/dist/lib/neutral/{chunk-FEABF5XY.mjs.map → chunk-EG7VLX2F.mjs.map} +0 -0
  70. /package/dist/lib/neutral/{chunk-4N4JAXCP.mjs.map → chunk-OA7JMLJK.mjs.map} +0 -0
  71. /package/dist/lib/neutral/{chunk-H6EHIVDN.mjs.map → chunk-YEDUHFRC.mjs.map} +0 -0
  72. /package/dist/lib/neutral/{fib-HDHBZHPE.mjs.map → fib-WSN4EY7R.mjs.map} +0 -0
  73. /package/dist/lib/neutral/{reply-XSQMXAPX.mjs.map → reply-XRLTFNDF.mjs.map} +0 -0
  74. /package/dist/lib/neutral/{sleep-WHTJQ56P.mjs.map → sleep-7O76LQCA.mjs.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/compute",
3
- "version": "0.8.4-main.cb12b3f963",
3
+ "version": "0.8.4-main.dfabb4ec29",
4
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",
@@ -36,15 +36,15 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@effect-atom/atom": "^0.5.1",
39
- "handlebars": "4.7.8",
40
- "@dxos/ai": "0.8.4-main.cb12b3f963",
41
- "@dxos/echo": "0.8.4-main.cb12b3f963",
42
- "@dxos/errors": "0.8.4-main.cb12b3f963",
43
- "@dxos/invariant": "0.8.4-main.cb12b3f963",
44
- "@dxos/log": "0.8.4-main.cb12b3f963",
45
- "@dxos/keys": "0.8.4-main.cb12b3f963",
46
- "@dxos/protocols": "0.8.4-main.cb12b3f963",
47
- "@dxos/schema": "0.8.4-main.cb12b3f963"
39
+ "@dxos/errors": "0.8.4-main.dfabb4ec29",
40
+ "@dxos/ai": "0.8.4-main.dfabb4ec29",
41
+ "@dxos/echo": "0.8.4-main.dfabb4ec29",
42
+ "@dxos/invariant": "0.8.4-main.dfabb4ec29",
43
+ "@dxos/keys": "0.8.4-main.dfabb4ec29",
44
+ "@dxos/log": "0.8.4-main.dfabb4ec29",
45
+ "@dxos/protocols": "0.8.4-main.dfabb4ec29",
46
+ "@dxos/schema": "0.8.4-main.dfabb4ec29",
47
+ "@dxos/vendor-kbn-handlebars": "0.8.4-main.dfabb4ec29"
48
48
  },
49
49
  "devDependencies": {
50
50
  "effect": "3.20.0",
package/src/Blueprint.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Context from 'effect/Context';
6
8
  import * as Effect from 'effect/Effect';
7
9
  import * as Schema from 'effect/Schema';
@@ -11,31 +13,16 @@ import { Annotation, Database, Filter, Obj, Type } from '@dxos/echo';
11
13
  import { BaseError } from '@dxos/errors';
12
14
  import { log } from '@dxos/log';
13
15
 
16
+ import * as McpServer from './McpServer';
14
17
  import * as Operation from './Operation';
15
18
  import * as Template from './Template';
16
19
 
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
20
  /**
35
21
  * Blueprint schema defines the structure for AI assistant blueprints.
36
22
  * Blueprints contain instructions, tools, and artifacts that guide the AI's behavior.
37
23
  * Blueprints may use tools to create and read artifacts, which are managed by the assistant.
38
24
  */
25
+ // TODO(burdon): Rename Skill?
39
26
  export const Blueprint = Schema.Struct({
40
27
  /**
41
28
  * Global registry ID.
@@ -85,10 +72,9 @@ export const Blueprint = Schema.Struct({
85
72
  /**
86
73
  * Array of MCP servers that the AI assistant can use when this blueprint is active.
87
74
  */
88
- mcpServers: Schema.optional(Schema.Array(McpServer)),
75
+ mcpServers: Schema.optional(Schema.Array(McpServer.McpServer)),
89
76
  }).pipe(
90
77
  Type.object({
91
- // TODO(burdon): Is this a DXN? Need to create a Format type for these IDs.
92
78
  typename: 'org.dxos.type.blueprint',
93
79
  version: '0.1.0',
94
80
  }),
package/src/Credential.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Context from 'effect/Context';
6
8
  import * as Effect from 'effect/Effect';
7
9
  import * as Redacted from 'effect/Redacted';
@@ -0,0 +1,44 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // @import-as-namespace
6
+
7
+ import * as Schema from 'effect/Schema';
8
+
9
+ /**
10
+ * MCP server connection spec — the minimal fields needed to dial an MCP server.
11
+ *
12
+ * Used as a value type embedded in blueprints and passed to runtime session connect logic.
13
+ * The user-facing ECHO object (`@dxos/assistant-toolkit` `McpServer`) composes this struct
14
+ * and adds instance-level fields (`name`, `enabled`) and ECHO annotations.
15
+ */
16
+ export const McpServer = Schema.Struct({
17
+ name: Schema.String.pipe(Schema.optional).annotations({
18
+ description: 'Human-readable name of the MCP server',
19
+ }),
20
+
21
+ url: Schema.String.annotations({
22
+ description: 'URL of the MCP server',
23
+ }),
24
+
25
+ /**
26
+ * Transport protocol. Prefer `'http'` (Streamable HTTP) for new servers; `'sse'` is
27
+ * kept for compatibility with servers that haven't migrated and is deprecated per
28
+ * the MCP SDK. Clients support both during the migration period.
29
+ */
30
+ protocol: Schema.Union(Schema.Literal('http'), Schema.Literal('sse')).annotations({
31
+ description: 'Transport protocol of the MCP server (prefer "http"; "sse" deprecated)',
32
+ }),
33
+
34
+ /**
35
+ * Optional API key sent with requests.
36
+ * Persisted in plaintext when stored on a space-replicated ECHO object — see the
37
+ * `@dxos/assistant-toolkit` `McpServer` type for security implications.
38
+ */
39
+ apiKey: Schema.optional(Schema.String).annotations({
40
+ description: 'Optional API key sent with requests',
41
+ }),
42
+ });
43
+
44
+ export interface McpServer extends Schema.Schema.Type<typeof McpServer> {}
package/src/Operation.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Context from 'effect/Context';
6
8
  import * as Effect from 'effect/Effect';
7
9
  import * as Layer from 'effect/Layer';
@@ -14,8 +16,6 @@ import { Annotation, JsonSchema, Obj, Ref, Type, type DXN, type Key } from '@dxo
14
16
  import type { NoHandlerError } from './errors';
15
17
  import type { Operation } from './index';
16
18
 
17
- // @import-as-namespace
18
-
19
19
  /**
20
20
  * Schema type that accepts any Encoded form but requires no Context.
21
21
  * This allows ECHO object schemas where Type !== Encoded due to [KindId] symbol.
@@ -166,6 +166,21 @@ export const make = <const P extends Types.NoExcessProperties<Props<any, any>, P
166
166
  } as any;
167
167
  };
168
168
 
169
+ /**
170
+ * Marks an operation as intrinsic — provided directly by the DXOS platform runtime rather than
171
+ * deployed as a user function. The `intrinsic:<key>` deployedId routes invocations to the
172
+ * built-in implementation registered with the runtime.
173
+ */
174
+ export const intrinsic = <const O extends Operation.Definition.Any>(op: O): O => {
175
+ return {
176
+ ...op,
177
+ meta: {
178
+ ...op.meta,
179
+ deployedId: `intrinsic:${op.meta.key}`,
180
+ },
181
+ };
182
+ };
183
+
169
184
  /**
170
185
  * Attaches a handler to an Operation definition.
171
186
  * The handler may use any services declared in the operation, plus Operation.Service (always available).
@@ -330,11 +345,16 @@ export const PersistentOperation = Schema$.Struct({
330
345
  );
331
346
  export interface PersistentOperation extends Schema$.Schema.Type<typeof PersistentOperation> {}
332
347
 
348
+ const FUNCTION_META_KEY = 'org.dxos.service.function';
349
+
333
350
  /**
334
351
  * Serialize an operation definition to a persistent operation record.
335
352
  */
336
353
  export const serialize = (operation: Definition.Any): PersistentOperation => {
337
354
  return Obj.make(PersistentOperation, {
355
+ [Obj.Meta]: {
356
+ keys: operation.meta.deployedId ? [{ source: FUNCTION_META_KEY, id: operation.meta.deployedId }] : [],
357
+ },
338
358
  key: operation.meta.key,
339
359
  name: operation.meta.name ?? '',
340
360
  version: operation.meta.version ?? '0.0.0',
@@ -352,7 +372,7 @@ export const serialize = (operation: Definition.Any): PersistentOperation => {
352
372
  */
353
373
  export const deserialize = (record: PersistentOperation): Definition.Any => {
354
374
  // Extract deployed function ID from ECHO meta keys (matches FUNCTIONS_META_KEY in @dxos/functions).
355
- const deployedId = Obj.getMeta(record).keys.find((key) => key.source === 'org.dxos.service.function')?.id;
375
+ const deployedId = Obj.getMeta(record).keys.find((key) => key.source === FUNCTION_META_KEY)?.id;
356
376
  return make({
357
377
  input: record.inputSchema ? JsonSchema.toEffectSchema(record.inputSchema) : Schema$.Unknown,
358
378
  output: record.outputSchema ? JsonSchema.toEffectSchema(record.outputSchema) : Schema$.Unknown,
@@ -2,6 +2,8 @@
2
2
  // Copyright 2026 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Context from 'effect/Context';
6
8
  import * as Effect from 'effect/Effect';
7
9
  import * as Layer from 'effect/Layer';
@@ -2,6 +2,8 @@
2
2
  // Copyright 2026 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Context from 'effect/Context';
6
8
  import * as Effect from 'effect/Effect';
7
9
  import * as Layer from 'effect/Layer';
package/src/Routine.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Schema from 'effect/Schema';
6
8
 
7
9
  import { Annotation, JsonSchema, Obj, Ref, Type } from '@dxos/echo';
@@ -13,6 +15,7 @@ import * as Template from './Template';
13
15
  * Executable instructions, which may use Blueprints.
14
16
  * May reference additional context.
15
17
  */
18
+ // TODO(burdon): Name?
16
19
  export const Routine = Schema.Struct({
17
20
  /**
18
21
  * Name of the routine.
@@ -39,6 +42,7 @@ export const Routine = Schema.Struct({
39
42
  * Natural language instructions for the routine.
40
43
  * These should provide concrete course of action for the AI to follow.
41
44
  */
45
+ // TODO(burdon): Form editor.
42
46
  instructions: Template.Template.pipe(Annotation.FormInputAnnotation.set(false)),
43
47
 
44
48
  /**
package/src/Script.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Schema from 'effect/Schema';
6
8
 
7
9
  import { Annotation, Obj, Ref, Type } from '@dxos/echo';
@@ -2,6 +2,8 @@
2
2
  // Copyright 2026 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Context from 'effect/Context';
6
8
  import * as Effect from 'effect/Effect';
7
9
  import * as Option from 'effect/Option';
@@ -0,0 +1,151 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+ import * as Option from 'effect/Option';
7
+ import * as Schema from 'effect/Schema';
8
+ import { describe, expect, test } from 'vitest';
9
+
10
+ import { FunctionNotFoundError } from './errors';
11
+ import * as Operation from './Operation';
12
+ import * as OperationRegistry from './OperationRegistry';
13
+ import * as Template from './Template';
14
+
15
+ describe('Template', () => {
16
+ describe('make', () => {
17
+ test('creates a template with defaults', () => {
18
+ const template = Template.make();
19
+ expect(template.source).toBeDefined();
20
+ expect(template.inputs).toEqual([]);
21
+ });
22
+
23
+ test('wraps the source string as a Text ref', () => {
24
+ const template = Template.make({ source: 'Hello {{name}}.' });
25
+ expect(template.source.target?.content).toBe('Hello {{name}}.');
26
+ });
27
+
28
+ test('preserves inputs', () => {
29
+ const template = Template.make({
30
+ source: 'Hello {{name}}.',
31
+ inputs: [{ name: 'name', kind: 'value', default: 'world' }],
32
+ });
33
+ expect(template.inputs).toHaveLength(1);
34
+ expect(template.inputs?.[0]).toMatchObject({ name: 'name', kind: 'value', default: 'world' });
35
+ });
36
+ });
37
+
38
+ describe('schema', () => {
39
+ test('Template is a Schema', () => {
40
+ expect(Schema.isSchema(Template.Template)).toBe(true);
41
+ });
42
+
43
+ test('Input is a Schema', () => {
44
+ expect(Schema.isSchema(Template.Input)).toBe(true);
45
+ });
46
+
47
+ test('InputKind accepts all documented kinds', () => {
48
+ const decode = Schema.decodeSync(Template.InputKind);
49
+ for (const kind of ['value', 'operation']) {
50
+ expect(decode(kind as any)).toBe(kind);
51
+ }
52
+ });
53
+
54
+ test('InputKind rejects unknown kinds', () => {
55
+ expect(() => Schema.decodeSync(Template.InputKind)('nonsense' as any)).toThrow();
56
+ });
57
+ });
58
+
59
+ describe('process', () => {
60
+ test('substitutes simple variables', () => {
61
+ expect(Template.process('Hello {{name}}.', { name: 'world' })).toBe('Hello world.');
62
+ });
63
+
64
+ test('renders an empty variables object as empty placeholders', () => {
65
+ expect(Template.process('Hello {{name}}.')).toBe('Hello .');
66
+ });
67
+
68
+ test('trims leading and trailing whitespace', () => {
69
+ expect(Template.process(' \n\nHello.\n\n ')).toBe('Hello.');
70
+ });
71
+
72
+ test('collapses runs of 3+ blank lines down to one blank line', () => {
73
+ const input = 'a\n\n\n\n\nb';
74
+ expect(Template.process(input)).toBe('a\n\nb');
75
+ });
76
+
77
+ test('preserves double newlines', () => {
78
+ expect(Template.process('a\n\nb')).toBe('a\n\nb');
79
+ });
80
+
81
+ test('{{section}} helper increments on each call', () => {
82
+ expect(Template.process('{{section}} / {{section}} / {{section}}')).toBe('1 / 2 / 3');
83
+ });
84
+ });
85
+
86
+ describe('processTemplate', () => {
87
+ const greet = Operation.withHandler(
88
+ Operation.make({
89
+ input: Schema.Void,
90
+ output: Schema.String,
91
+ meta: { key: 'test.greet' },
92
+ }),
93
+ () => Effect.succeed('Alice'),
94
+ );
95
+
96
+ const stubRegistry = (operations: Record<string, Operation.Definition.Any>) =>
97
+ Effect.provideService(OperationRegistry.Service, {
98
+ resolve: (key) => Effect.succeed(Option.fromNullable(operations[key])),
99
+ });
100
+
101
+ const stubInvoker = Effect.provideService(Operation.Service, {
102
+ invoke: (op, input) => (op as any).handler(input),
103
+ schedule: () => Effect.succeed(undefined),
104
+ invokePromise: () => Promise.resolve({}),
105
+ } as Operation.OperationService);
106
+
107
+ test('resolves a value-kind input from its default', async () => {
108
+ const template = Template.make({
109
+ source: 'Hello {{name}}!',
110
+ inputs: [{ name: 'name', kind: 'value', default: 'world' }],
111
+ });
112
+
113
+ const result = await Template.processTemplate(template).pipe(stubRegistry({}), stubInvoker, Effect.runPromise);
114
+ expect(result).toBe('Hello world!');
115
+ });
116
+
117
+ test('resolves an operation-kind input and substitutes the result', async () => {
118
+ const template = Template.make({
119
+ source: 'Hello {{name}}.',
120
+ inputs: [{ name: 'name', kind: 'operation', operation: 'test.greet' }],
121
+ });
122
+
123
+ const result = await Template.processTemplate(template).pipe(
124
+ stubRegistry({ 'test.greet': greet }),
125
+ stubInvoker,
126
+ Effect.runPromise,
127
+ );
128
+
129
+ expect(result).toBe('Hello Alice.');
130
+ });
131
+
132
+ test('fails with FunctionNotFoundError when the function key cannot be resolved', async () => {
133
+ const template = Template.make({
134
+ source: 'Hello {{name}}.',
135
+ inputs: [{ name: 'name', kind: 'operation', operation: 'test.missing' }],
136
+ });
137
+
138
+ const result = await Template.processTemplate(template).pipe(
139
+ stubRegistry({}),
140
+ stubInvoker,
141
+ Effect.either,
142
+ Effect.runPromise,
143
+ );
144
+
145
+ expect(result._tag).toBe('Left');
146
+ if (result._tag === 'Left') {
147
+ expect(result.left).toBeInstanceOf(FunctionNotFoundError);
148
+ }
149
+ });
150
+ });
151
+ });
package/src/Template.ts CHANGED
@@ -2,16 +2,17 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Effect from 'effect/Effect';
6
- import * as Record from 'effect/Record';
7
8
  import * as Schema from 'effect/Schema';
8
- import handlebars from 'handlebars';
9
9
 
10
10
  import { Database, Ref } from '@dxos/echo';
11
11
  import type { ObjectNotFoundError } from '@dxos/echo/Err';
12
12
  import { invariant } from '@dxos/invariant';
13
13
  import { log } from '@dxos/log';
14
14
  import { Text } from '@dxos/schema';
15
+ import Handlebars from '@dxos/vendor-kbn-handlebars';
15
16
 
16
17
  import { FunctionNotFoundError } from './errors';
17
18
  import * as Operation from './Operation';
@@ -22,13 +23,13 @@ import * as OperationRegistry from './OperationRegistry';
22
23
  */
23
24
  export const InputKind = Schema.Literal(
24
25
  'value', // Literal value.
25
- 'pass-through',
26
- 'retriever',
27
- 'function',
28
- 'query',
29
- 'resolver',
30
- 'context',
31
- 'schema',
26
+ 'operation',
27
+ // 'pass-through',
28
+ // 'retriever',
29
+ // 'query',
30
+ // 'resolver',
31
+ // 'context',
32
+ // 'schema',
32
33
  );
33
34
 
34
35
  export type InputKind = Schema.Schema.Type<typeof InputKind>;
@@ -39,13 +40,13 @@ export type InputKind = Schema.Schema.Type<typeof InputKind>;
39
40
  */
40
41
  export const Input = Schema.Struct({
41
42
  name: Schema.String,
42
- kind: Schema.optional(InputKind),
43
+ kind: InputKind,
43
44
  default: Schema.optional(Schema.Any),
44
-
45
45
  /**
46
- * Function to call if the kind is 'function'.
46
+ * Operation key invoked when `kind === 'operation'`. The referenced operation must accept void input —
47
+ * template inputs have no mechanism for passing arguments.
47
48
  */
48
- function: Schema.optional(Schema.String),
49
+ operation: Schema.optional(Schema.String),
49
50
  });
50
51
 
51
52
  export type Input = Schema.Schema.Type<typeof Input>;
@@ -54,17 +55,19 @@ export type Input = Schema.Schema.Type<typeof Input>;
54
55
  * Template type.
55
56
  */
56
57
  export const Template = Schema.Struct({
57
- source: Ref.Ref(Text.Text).annotations({ description: 'Handlebars template source' }),
58
+ source: Ref.Ref(Text.Text).annotations({ description: 'Markdown + Handlebars template.' }),
59
+
60
+ /**
61
+ * NOTE: We use an array rather than map so that updating variable names in the template doesn't disconnect existing inputs.
62
+ */
58
63
  inputs: Schema.optional(Schema.Array(Input)),
59
64
  });
60
65
 
61
66
  export interface Template extends Schema.Schema.Type<typeof Template> {}
62
67
 
63
- export const make = ({
64
- id,
65
- source,
66
- inputs = [],
67
- }: { id?: string; source?: string; inputs?: Input[] } = {}): Template => ({
68
+ export type MakeProps = Partial<{ id: string; source: string; inputs: Input[] }>;
69
+
70
+ export const make = ({ id, source, inputs = [] }: MakeProps = {}): Template => ({
68
71
  source: Ref.make(Text.make({ id, content: source })),
69
72
  inputs,
70
73
  });
@@ -75,8 +78,9 @@ export const make = ({
75
78
  export const process = <Options extends {}>(source: string, variables: Partial<Options> = {}): string => {
76
79
  invariant(typeof source === 'string');
77
80
  let section = 0;
81
+ const handlebars = Handlebars.create();
78
82
  handlebars.registerHelper('section', () => String(++section));
79
- const template = handlebars.compile(source.trim());
83
+ const template = handlebars.compileAST(source.trim());
80
84
  const output = template(variables);
81
85
  return output.trim().replace(/(\n\s*){3,}/g, '\n\n');
82
86
  };
@@ -85,20 +89,33 @@ export const processTemplate = (
85
89
  template: Template,
86
90
  ): Effect.Effect<string, ObjectNotFoundError | FunctionNotFoundError, OperationRegistry.Service | Operation.Service> =>
87
91
  Effect.gen(function* () {
88
- const variables = yield* Effect.forEach(template.inputs ?? [], (input) =>
92
+ const entries = yield* Effect.forEach(template.inputs ?? [], (input) =>
89
93
  Effect.gen(function* () {
90
- if (input.kind === 'function') {
91
- const fn = yield* OperationRegistry.resolve(input.function!).pipe(
92
- Effect.flatten,
93
- Effect.catchTag('NoSuchElementException', () => Effect.fail(new FunctionNotFoundError(input.function!))),
94
- );
95
- const result = yield* Operation.invoke(fn, {} as any).pipe(Effect.orDie);
96
- return [input.name, result] as const;
97
- } else {
98
- return yield* Effect.dieMessage(`Unsupported input kind: ${input.kind}`);
94
+ switch (input.kind) {
95
+ case 'value': {
96
+ return [input.name, input.default] as const;
97
+ }
98
+
99
+ case 'operation': {
100
+ invariant(input.operation);
101
+ const fn = yield* OperationRegistry.resolve(input.operation).pipe(
102
+ Effect.flatten,
103
+ Effect.catchTag('NoSuchElementException', () => Effect.fail(new FunctionNotFoundError(input.operation!))),
104
+ );
105
+
106
+ // NOTE: Operations referenced by template inputs must accept void input — see `Input.operation`.
107
+ const result = yield* Operation.invoke(fn, undefined as any).pipe(Effect.orDie);
108
+ return [input.name, result] as const;
109
+ }
110
+
111
+ default: {
112
+ return yield* Effect.dieMessage(`Unsupported input kind: ${input.kind}`);
113
+ }
99
114
  }
100
115
  }),
101
- ).pipe(Effect.map(Record.fromEntries));
116
+ );
117
+
118
+ const variables = Object.fromEntries(entries);
102
119
 
103
120
  log('processTemplate', { variables });
104
121
  return process((yield* Database.load(template.source)).content, variables);
package/src/Trigger.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Schema from 'effect/Schema';
6
8
  import * as SchemaAST from 'effect/SchemaAST';
7
9
 
@@ -2,6 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Schema from 'effect/Schema';
6
8
 
7
9
  import { DXN, Obj, Ref } from '@dxos/echo';
package/src/errors.ts CHANGED
@@ -48,3 +48,24 @@ export class InvalidOperationOutputError extends BaseError.extend(
48
48
  ) {}
49
49
 
50
50
  export class TriggerStateNotFoundError extends BaseError.extend('TriggerStateNotFound', 'Trigger state not found') {}
51
+
52
+ /**
53
+ * Raised when the upstream AI gateway responds with a structured JSON error envelope
54
+ * (`{ "type": "error", "error": { "type": ..., "message": ... } }`). Surfaces as a typed
55
+ * defect from `FunctionsAiHttpClient`, bypassing `@effect/ai`'s generic `HttpResponseError`
56
+ * wrapping so callers can match on the error class directly.
57
+ */
58
+ export class FunctionsAiUpstreamError extends BaseError.extend(
59
+ 'FunctionsAiUpstreamError',
60
+ 'Upstream AI service returned an error',
61
+ ) {}
62
+
63
+ /**
64
+ * Specialized `FunctionsAiUpstreamError` for the memoization layer: the recorded fixture for a
65
+ * given cache key was not found and `ALLOW_LLM_GENERATION` is unset. The `cacheKey` is exposed
66
+ * via `context.cacheKey` to make regeneration straightforward.
67
+ */
68
+ export class FunctionsAiMemoizationMissError extends BaseError.extend(
69
+ 'FunctionsAiMemoizationMissError',
70
+ 'No memoized AI conversation found for the given cache key',
71
+ ) {}
package/src/index.ts CHANGED
@@ -2,9 +2,11 @@
2
2
  // Copyright 2026 DXOS.org
3
3
  //
4
4
 
5
+ export * from './errors';
6
+
5
7
  export * as Blueprint from './Blueprint';
6
8
  export * as Credential from './Credential';
7
- export * from './errors';
9
+ export * as McpServer from './McpServer';
8
10
  export * as Operation from './Operation';
9
11
  export * as OperationHandlerSet from './OperationHandlerSet';
10
12
  export * as OperationRegistry from './OperationRegistry';
@@ -21,7 +21,7 @@ export const Fibonacci = Operation.make({
21
21
  output: Schema.Struct({
22
22
  result: Schema.String,
23
23
  }),
24
- });
24
+ }).pipe(Operation.intrinsic);
25
25
 
26
26
  export const Reply = Operation.make({
27
27
  meta: {
@@ -31,7 +31,7 @@ export const Reply = Operation.make({
31
31
  },
32
32
  input: Schema.Any,
33
33
  output: Schema.Any,
34
- });
34
+ }).pipe(Operation.intrinsic);
35
35
 
36
36
  export const Sleep = Operation.make({
37
37
  meta: {
@@ -46,4 +46,4 @@ export const Sleep = Operation.make({
46
46
  }),
47
47
  }),
48
48
  output: Schema.Void,
49
- });
49
+ }).pipe(Operation.intrinsic);
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/StorageService.ts"],
4
- "sourcesContent": ["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\nimport * as Pipeable from 'effect/Pipeable';\nimport * as Schema from 'effect/Schema';\n\nexport interface Service {\n /** Read a value by key. Returns `None` if key does not exist. */\n get<S extends Schema.Schema<any, string, any>>(\n schema: S,\n key: string,\n ): Effect.Effect<Option.Option<Schema.Schema.Type<S>>, never, Schema.Schema.Context<S>>;\n\n /** Write a value for the given key. */\n set<S extends Schema.Schema<any, string, any>>(\n schema: S,\n key: string,\n value: Schema.Schema.Type<S>,\n ): Effect.Effect<void, never, Schema.Schema.Context<S>>;\n\n /** Remove a key. */\n delete(key: string): Effect.Effect<void>;\n\n /** List all keys, optionally filtered by prefix. */\n list(prefix?: string): Effect.Effect<readonly string[]>;\n\n /** Remove all keys managed by this scoped store. */\n clear(): Effect.Effect<void>;\n}\n\n/**\n * Scoped key-value storage service for processes.\n * Each process receives its own namespaced instance via the process manager.\n * Construct a live implementation with `StorageService.layer` from `@dxos/functions-runtime`.\n */\nexport class StorageService extends Context.Tag('@dxos/functions/StorageService')<StorageService, Service>() {}\n\nexport const get = Effect.serviceFunctionEffect(StorageService, (_) => _.get);\nexport const set = Effect.serviceFunctionEffect(StorageService, (_) => _.set);\nexport const deleteKey = Effect.serviceFunctionEffect(StorageService, (_) => _.delete);\nexport const list = Effect.serviceFunctionEffect(StorageService, (_) => _.list);\nexport const clear = Effect.serviceFunctionEffect(StorageService, (_) => _.clear);\n\n/**\n * Typed key in a storage service.\n */\nexport interface Key<T> extends Pipeable.Pipeable {\n readonly key: string;\n\n get: Effect.Effect<Option.Option<T>, never, StorageService>;\n set(value: T): Effect.Effect<void, never, StorageService>;\n delete(): Effect.Effect<void, never, StorageService>;\n}\n\n/**\n * Create a typed key in a storage service.\n */\nexport const key = <S extends Schema.Schema<any, string, any>>(schema: S, key: string): Key<Schema.Schema.Type<S>> => {\n return {\n key,\n get: get(schema, key),\n set: (value: Schema.Schema.Type<S>) => set(schema, key, value),\n delete: () => deleteKey(key),\n pipe(...args: any) {\n return Pipeable.pipeArguments(this, arguments);\n },\n };\n};\n\n/**\n * Typed key in a storage service with a default value.\n */\nexport interface KeyWithDefault<T, U> extends Pipeable.Pipeable {\n readonly key: string;\n get: Effect.Effect<T | U, never, StorageService>;\n set(value: U): Effect.Effect<void, never, StorageService>;\n delete(): Effect.Effect<void, never, StorageService>;\n}\n\n/**\n * Assign a default value to a key if it is not present.\n */\nexport const withDefault =\n <T>(getDefault: () => NoInfer<T>) =>\n (key: Key<T>): KeyWithDefault<T, T> => {\n return {\n key: key.key,\n get: key.get.pipe(Effect.map(Option.getOrElse(() => getDefault()))),\n set: (value) => key.set(value),\n delete: () => key.delete(),\n pipe(...args: any) {\n return Pipeable.pipeArguments(this, arguments);\n },\n };\n };\n"],
5
- "mappings": ";;;;;AAAA;;;;;;;;;;;AAIA,YAAYA,aAAa;AACzB,YAAYC,YAAY;AACxB,YAAYC,YAAY;AACxB,YAAYC,cAAc;AAgCnB,IAAMC,iBAAN,cAAqCC,YAAI,gCAAA,EAAA,EAAA;AAA8D;AAEvG,IAAMC,MAAaC,6BAAsBH,gBAAgB,CAACI,MAAMA,EAAEF,GAAG;AACrE,IAAMG,MAAaF,6BAAsBH,gBAAgB,CAACI,MAAMA,EAAEC,GAAG;AACrE,IAAMC,YAAmBH,6BAAsBH,gBAAgB,CAACI,MAAMA,EAAEG,MAAM;AAC9E,IAAMC,OAAcL,6BAAsBH,gBAAgB,CAACI,MAAMA,EAAEI,IAAI;AACvE,IAAMC,QAAeN,6BAAsBH,gBAAgB,CAACI,MAAMA,EAAEK,KAAK;AAgBzE,IAAMC,MAAM,CAA4CC,QAAWD,SAAAA;AACxE,SAAO;IACLA,KAAAA;IACAR,KAAKA,IAAIS,QAAQD,IAAAA;IACjBL,KAAK,CAACO,UAAiCP,IAAIM,QAAQD,MAAKE,KAAAA;IACxDL,QAAQ,MAAMD,UAAUI,IAAAA;IACxBG,QAAQC,MAAS;AACf,aAAgBC,uBAAc,MAAMC,SAAAA;IACtC;EACF;AACF;AAeO,IAAMC,cACX,CAAIC,eACJ,CAACR,SAAAA;AACC,SAAO;IACLA,KAAKA,KAAIA;IACTR,KAAKQ,KAAIR,IAAIW,KAAYM,WAAWC,iBAAU,MAAMF,WAAAA,CAAAA,CAAAA,CAAAA;IACpDb,KAAK,CAACO,UAAUF,KAAIL,IAAIO,KAAAA;IACxBL,QAAQ,MAAMG,KAAIH,OAAM;IACxBM,QAAQC,MAAS;AACf,aAAgBC,uBAAc,MAAMC,SAAAA;IACtC;EACF;AACF;",
6
- "names": ["Context", "Effect", "Option", "Pipeable", "StorageService", "Tag", "get", "serviceFunctionEffect", "_", "set", "deleteKey", "delete", "list", "clear", "key", "schema", "value", "pipe", "args", "pipeArguments", "arguments", "withDefault", "getDefault", "map", "getOrElse"]
7
- }