@dxos/compute 0.8.4-main.406dc2a → 0.8.4-main.548089c

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/compute",
3
- "version": "0.8.4-main.406dc2a",
3
+ "version": "0.8.4-main.548089c",
4
4
  "description": "Low-level compute API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -38,29 +38,30 @@
38
38
  "@preact/signals-core": "^1.12.1",
39
39
  "effect": "3.18.3",
40
40
  "lodash.defaultsdeep": "^4.6.1",
41
- "@dxos/ai": "0.8.4-main.406dc2a",
42
- "@dxos/async": "0.8.4-main.406dc2a",
43
- "@dxos/client": "0.8.4-main.406dc2a",
44
- "@dxos/echo": "0.8.4-main.406dc2a",
45
- "@dxos/context": "0.8.4-main.406dc2a",
46
- "@dxos/debug": "0.8.4-main.406dc2a",
47
- "@dxos/functions": "0.8.4-main.406dc2a",
48
- "@dxos/invariant": "0.8.4-main.406dc2a",
49
- "@dxos/keys": "0.8.4-main.406dc2a",
50
- "@dxos/log": "0.8.4-main.406dc2a",
51
- "@dxos/live-object": "0.8.4-main.406dc2a",
52
- "@dxos/protocols": "0.8.4-main.406dc2a",
53
- "@dxos/plugin-automation": "0.8.4-main.406dc2a",
54
- "@dxos/util": "0.8.4-main.406dc2a",
55
- "@dxos/vendor-hyperformula": "0.8.4-main.406dc2a",
56
- "@dxos/schema": "0.8.4-main.406dc2a"
41
+ "@dxos/ai": "0.8.4-main.548089c",
42
+ "@dxos/async": "0.8.4-main.548089c",
43
+ "@dxos/client": "0.8.4-main.548089c",
44
+ "@dxos/context": "0.8.4-main.548089c",
45
+ "@dxos/debug": "0.8.4-main.548089c",
46
+ "@dxos/echo": "0.8.4-main.548089c",
47
+ "@dxos/functions-runtime": "0.8.4-main.548089c",
48
+ "@dxos/functions": "0.8.4-main.548089c",
49
+ "@dxos/invariant": "0.8.4-main.548089c",
50
+ "@dxos/keys": "0.8.4-main.548089c",
51
+ "@dxos/live-object": "0.8.4-main.548089c",
52
+ "@dxos/plugin-automation": "0.8.4-main.548089c",
53
+ "@dxos/protocols": "0.8.4-main.548089c",
54
+ "@dxos/util": "0.8.4-main.548089c",
55
+ "@dxos/schema": "0.8.4-main.548089c",
56
+ "@dxos/vendor-hyperformula": "0.8.4-main.548089c",
57
+ "@dxos/log": "0.8.4-main.548089c"
57
58
  },
58
59
  "devDependencies": {
59
60
  "@tldraw/indices": "^2.0.0-alpha.14",
60
61
  "@types/lodash.defaultsdeep": "^4.6.6",
61
- "@dxos/echo": "0.8.4-main.406dc2a",
62
- "@dxos/echo-db": "0.8.4-main.406dc2a",
63
- "@dxos/random": "0.8.4-main.406dc2a"
62
+ "@dxos/echo": "0.8.4-main.548089c",
63
+ "@dxos/random": "0.8.4-main.548089c",
64
+ "@dxos/echo-db": "0.8.4-main.548089c"
64
65
  },
65
66
  "peerDependencies": {
66
67
  "effect": "^3.13.3"
@@ -6,8 +6,8 @@ import * as Schema from 'effect/Schema';
6
6
  import { describe, expect, onTestFinished, test } from 'vitest';
7
7
 
8
8
  import { Trigger } from '@dxos/async';
9
- import { fullyQualifiedId } from '@dxos/client/echo';
10
- import { FunctionDefinition, FunctionType } from '@dxos/functions';
9
+ import { Obj } from '@dxos/echo';
10
+ import { Function, FunctionDefinition } from '@dxos/functions';
11
11
 
12
12
  import { ComputeGraphRegistry, defaultPlugins } from './compute-graph-registry';
13
13
  import { TestBuilder, createMockedComputeRuntimeProvider } from './testing';
@@ -23,8 +23,13 @@ describe('ComputeGraphRegistry', () => {
23
23
  });
24
24
 
25
25
  test('invokes user function through compute graph', async () => {
26
- const computeRuntime = createMockedComputeRuntimeProvider({ functions: [add] });
27
- const testBuilder = new TestBuilder({ types: [FunctionType], computeRuntime });
26
+ const computeRuntime = createMockedComputeRuntimeProvider({
27
+ functions: [add],
28
+ });
29
+ const testBuilder = new TestBuilder({
30
+ types: [Function.Function],
31
+ computeRuntime,
32
+ });
28
33
  await testBuilder.open();
29
34
  onTestFinished(async () => {
30
35
  await testBuilder.close();
@@ -33,7 +38,10 @@ describe('ComputeGraphRegistry', () => {
33
38
  const space = await testBuilder.client.spaces.create();
34
39
 
35
40
  // Register Edge function plugin and runtime in the registry.
36
- const registry = new ComputeGraphRegistry({ plugins: defaultPlugins, computeRuntime });
41
+ const registry = new ComputeGraphRegistry({
42
+ plugins: defaultPlugins,
43
+ computeRuntime,
44
+ });
37
45
  await registry.open();
38
46
  onTestFinished(async () => {
39
47
  await registry.close();
@@ -69,12 +77,17 @@ describe('ComputeGraphRegistry', () => {
69
77
 
70
78
  // Sanity check: mapping to fully qualified id works as well.
71
79
  const bindingId = graph.mapFunctionBindingToId('ADD(2, 3)');
72
- expect(bindingId.startsWith(`${fullyQualifiedId(functionObj)}`)).to.be.true;
80
+ expect(bindingId.startsWith(`${Obj.getDXN(functionObj).toString()}`)).to.be.true;
73
81
  });
74
82
 
75
83
  test('adding a function binding updates autocomplete and enables execution', async () => {
76
- const computeRuntime = createMockedComputeRuntimeProvider({ functions: [add] });
77
- const testBuilder = new TestBuilder({ types: [FunctionType], computeRuntime });
84
+ const computeRuntime = createMockedComputeRuntimeProvider({
85
+ functions: [add],
86
+ });
87
+ const testBuilder = new TestBuilder({
88
+ types: [Function.Function],
89
+ computeRuntime,
90
+ });
78
91
  await testBuilder.open();
79
92
  onTestFinished(async () => {
80
93
  await testBuilder.close();
@@ -82,7 +95,10 @@ describe('ComputeGraphRegistry', () => {
82
95
 
83
96
  const space = await testBuilder.client.spaces.create();
84
97
 
85
- const registry = new ComputeGraphRegistry({ plugins: defaultPlugins, computeRuntime });
98
+ const registry = new ComputeGraphRegistry({
99
+ plugins: defaultPlugins,
100
+ computeRuntime,
101
+ });
86
102
  await registry.open();
87
103
  onTestFinished(async () => {
88
104
  await registry.close();
@@ -114,7 +130,7 @@ describe('ComputeGraphRegistry', () => {
114
130
  await functionsUpdated.wait();
115
131
 
116
132
  // Autocomplete should now include the binding.
117
- const echoFunctions = graph.getFunctions({ standard: false, echo: true }).map((f) => f.name);
133
+ const echoFunctions = graph.getFunctions({ standard: false, echo: true }).map((fn) => fn.name);
118
134
  expect(echoFunctions).toContain('ADD');
119
135
 
120
136
  // And the binding should execute when used in a formula.
@@ -5,9 +5,8 @@
5
5
  import { afterEach, beforeEach, describe, expect, test } from 'vitest';
6
6
 
7
7
  import { Trigger } from '@dxos/async';
8
- import { fullyQualifiedId } from '@dxos/client/echo';
9
8
  import { Obj } from '@dxos/echo';
10
- import { FunctionType } from '@dxos/functions';
9
+ import { Function } from '@dxos/functions';
11
10
  import { type CellValue } from '@dxos/vendor-hyperformula';
12
11
  import { DetailedCellError } from '@dxos/vendor-hyperformula';
13
12
 
@@ -16,7 +15,7 @@ import { TestBuilder } from './testing';
16
15
  describe('ComputeGraph', () => {
17
16
  let testBuilder: TestBuilder;
18
17
  beforeEach(async () => {
19
- testBuilder = new TestBuilder({ types: [FunctionType] });
18
+ testBuilder = new TestBuilder({ types: [Function.Function] });
20
19
  await testBuilder.open();
21
20
  });
22
21
  afterEach(async () => {
@@ -31,13 +30,13 @@ describe('ComputeGraph', () => {
31
30
  // Create script.
32
31
  const trigger = new Trigger();
33
32
  graph.update.once(() => trigger.wake());
34
- const functionObject = space.db.add(Obj.make(FunctionType, { name: 'test', version: '0.0.1', binding: 'TEST' }));
33
+ const functionObject = space.db.add(Function.make({ name: 'test', version: '0.0.1', binding: 'TEST' }));
35
34
  await trigger.wait();
36
35
  const functions = graph.getFunctions({ echo: true });
37
36
  expect(functions).to.toHaveLength(1);
38
37
 
39
38
  const id = graph.mapFunctionBindingToId('TEST()');
40
- expect(id).to.eq(`${fullyQualifiedId(functionObject)}()`);
39
+ expect(id).to.eq(`${Obj.getDXN(functionObject).toString()}()`);
41
40
  });
42
41
 
43
42
  test('cross-node references', async () => {
@@ -52,22 +51,38 @@ describe('ComputeGraph', () => {
52
51
  {
53
52
  node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, [[100, 200, 300, '=SUM(A1:C1)']]);
54
53
  node2.graph.hf.setCellContents({ sheet: node2.sheetId, row: 0, col: 0 }, "='node-1'!D1");
55
- const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 3, row: 0 });
56
- const value2 = node2.graph.hf.getCellValue({ sheet: node2.sheetId, col: 0, row: 0 });
54
+ const value1 = node1.graph.hf.getCellValue({
55
+ sheet: node1.sheetId,
56
+ col: 3,
57
+ row: 0,
58
+ });
59
+ const value2 = node2.graph.hf.getCellValue({
60
+ sheet: node2.sheetId,
61
+ col: 0,
62
+ row: 0,
63
+ });
57
64
  expect(value1).to.eq(value2);
58
65
  }
59
66
 
60
67
  // Get updated event.
61
68
  const trigger = new Trigger<CellValue>();
62
69
  node2.update.on(({ change }) => {
63
- const value = node2.graph.hf.getCellValue({ sheet: node2.sheetId, col: 0, row: 0 });
70
+ const value = node2.graph.hf.getCellValue({
71
+ sheet: node2.sheetId,
72
+ col: 0,
73
+ row: 0,
74
+ });
64
75
  expect(value).to.eq(change?.newValue);
65
76
  trigger.wake(value);
66
77
  });
67
78
 
68
79
  {
69
80
  node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, 400);
70
- const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 3, row: 0 });
81
+ const value1 = node1.graph.hf.getCellValue({
82
+ sheet: node1.sheetId,
83
+ col: 3,
84
+ row: 0,
85
+ });
71
86
  const value2 = await trigger.wait();
72
87
  expect(value1).to.eq(value2);
73
88
  }
@@ -81,7 +96,11 @@ describe('ComputeGraph', () => {
81
96
 
82
97
  const node1 = await graph.getOrCreateNode('node-1').open();
83
98
  node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, "='node-2'!A1");
84
- const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 0, row: 0 });
99
+ const value1 = node1.graph.hf.getCellValue({
100
+ sheet: node1.sheetId,
101
+ col: 0,
102
+ row: 0,
103
+ });
85
104
  expect(value1).to.be.instanceof(DetailedCellError);
86
105
  expect((value1 as DetailedCellError).type).to.eq('REF');
87
106
  });
@@ -2,14 +2,16 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { effect } from '@preact/signals-core';
5
6
  import type * as ManagedRuntime from 'effect/ManagedRuntime';
6
7
 
7
8
  import { Event } from '@dxos/async';
8
- import { Filter, type Space, fullyQualifiedId } from '@dxos/client/echo';
9
+ import { Filter, type Space } from '@dxos/client/echo';
9
10
  import { FQ_ID_LENGTH } from '@dxos/client/echo';
10
11
  import { Resource } from '@dxos/context';
12
+ import { Obj } from '@dxos/echo';
11
13
  import { getTypename } from '@dxos/echo/internal';
12
- import { type FunctionInvocationService, FunctionType } from '@dxos/functions';
14
+ import { Function, type FunctionInvocationService } from '@dxos/functions';
13
15
  import { invariant } from '@dxos/invariant';
14
16
  import { PublicKey } from '@dxos/keys';
15
17
  import { log } from '@dxos/log';
@@ -60,7 +62,7 @@ export class ComputeGraph extends Resource {
60
62
  private readonly _nodes = new Map<number, ComputeNode>();
61
63
 
62
64
  // Cached function objects.
63
- private _remoteFunctions: FunctionType[] = [];
65
+ private _remoteFunctions: Function.Function[] = [];
64
66
 
65
67
  public readonly update = new Event<{ type: ComputeGraphEvent }>();
66
68
 
@@ -106,7 +108,10 @@ export class ComputeGraph extends Resource {
106
108
  }
107
109
 
108
110
  getFunctions(
109
- { standard, echo }: { standard?: boolean; echo?: boolean } = { standard: true, echo: true },
111
+ { standard, echo }: { standard?: boolean; echo?: boolean } = {
112
+ standard: true,
113
+ echo: true,
114
+ },
110
115
  ): FunctionDefinition[] {
111
116
  return [
112
117
  ...(standard
@@ -206,7 +211,7 @@ export class ComputeGraph extends Resource {
206
211
 
207
212
  const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
208
213
  if (fn) {
209
- const id = fullyQualifiedId(fn);
214
+ const id = Obj.getDXN(fn).toString();
210
215
  return `${id}(${args})`;
211
216
  } else {
212
217
  return match;
@@ -225,7 +230,7 @@ export class ComputeGraph extends Resource {
225
230
  return match;
226
231
  }
227
232
 
228
- const fn = this._remoteFunctions.find((fn) => fullyQualifiedId(fn) === id);
233
+ const fn = this._remoteFunctions.find((fn) => Obj.getDXN(fn).toString() === id);
229
234
  if (fn?.binding) {
230
235
  return `${fn.binding}(${args})`;
231
236
  } else {
@@ -243,13 +248,17 @@ export class ComputeGraph extends Resource {
243
248
  protected override async _open(): Promise<void> {
244
249
  if (this._space) {
245
250
  // Subscribe to remote function definitions.
246
- const query = this._space.db.query(Filter.type(FunctionType));
247
- const unsubscribe = query.subscribe(({ objects }) => {
248
- this._remoteFunctions = objects.filter(({ binding }) => binding);
251
+ const query = this._space.db.query(Filter.type(Function.Function));
252
+ const unsubscribe = query.subscribe();
253
+ const dispose = effect(() => {
254
+ this._remoteFunctions = query.objects.filter(({ binding }) => binding);
249
255
  this.update.emit({ type: 'functionsUpdated' });
250
256
  });
251
257
 
252
- this._ctx.onDispose(unsubscribe);
258
+ this._ctx.onDispose(() => {
259
+ unsubscribe();
260
+ dispose();
261
+ });
253
262
  }
254
263
  }
255
264
 
@@ -8,7 +8,7 @@ import * as SchemaAST from 'effect/SchemaAST';
8
8
 
9
9
  import { Filter } from '@dxos/client/echo';
10
10
  import { toEffectSchema } from '@dxos/echo/internal';
11
- import { ComputeEventLogger, FunctionInvocationService, FunctionType, TracingService } from '@dxos/functions';
11
+ import { Function, FunctionInvocationService, TracingService } from '@dxos/functions';
12
12
  import { FunctionDefinition } from '@dxos/functions';
13
13
  import { log } from '@dxos/log';
14
14
  import { isNonNullable } from '@dxos/util';
@@ -38,7 +38,7 @@ export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
38
38
 
39
39
  const {
40
40
  objects: [fn],
41
- } = await space.db.query(Filter.type(FunctionType, { binding })).run();
41
+ } = await space.db.query(Filter.type(Function.Function, { binding })).run();
42
42
  if (!fn) {
43
43
  log.info('Function not found', { binding });
44
44
  return new CellError(ErrorType.REF, 'Function not found');
@@ -74,7 +74,7 @@ export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
74
74
  const result = runtime.runPromise(
75
75
  Effect.gen(function* () {
76
76
  return yield* FunctionInvocationService.invokeFunction(functionDef, input);
77
- }).pipe(Effect.provide(ComputeEventLogger.layerFromTracing), Effect.provide(TracingService.layerNoop)),
77
+ }).pipe(Effect.provide(TracingService.layerNoop)),
78
78
  );
79
79
  return result as any;
80
80
  };
package/src/index.ts CHANGED
@@ -2,33 +2,6 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- // TODO(burdon): Separate hyperformula (client compute) from remote/edge functions.
6
-
7
- // TODO(burdon): Reconcile: types.
8
- // - dxos/graph
9
- // - dxos/compute
10
- // - dxos/functions
11
- // - dxos/assistant
12
- // - dxos/plugin-automation
13
- // - dxos/plugin-script
14
- // - dxos/plugin-sheet
15
-
16
- // TODO(burdon): Tech debt.
17
- // - move hyperformula defs from sheet to compute.
18
- // - standard from ./types exports for plugins.
19
- // - dxos/agent
20
- // - dxos/agent-functions
21
- // - dxos/mosaic, dxos-card
22
-
23
- // TODO(burdon): Reconcile UX.
24
- // - dxos/plugin-explorer
25
- // - dxos/plugin-canvas
26
- // - dxos/gem-*
27
-
28
- // TODO(burdon): Next
29
- // - dxos/plugin-search
30
- // - dxos/plugin-threads
31
-
32
5
  export * from './compute-graph';
33
6
  export * from './compute-graph-registry';
34
7
  export * from './compute-node';
@@ -7,13 +7,8 @@ import * as ManagedRuntime from 'effect/ManagedRuntime';
7
7
 
8
8
  import { AiService } from '@dxos/ai';
9
9
  import { type SpaceId } from '@dxos/client/echo';
10
- import {
11
- CredentialsService,
12
- DatabaseService,
13
- type FunctionDefinition,
14
- FunctionInvocationService,
15
- QueueService,
16
- } from '@dxos/functions';
10
+ import { CredentialsService, DatabaseService, type FunctionDefinition, QueueService } from '@dxos/functions';
11
+ import { FunctionInvocationServiceLayerTest } from '@dxos/functions-runtime/testing';
17
12
 
18
13
  import { type FunctionsRuntimeProvider } from '../compute-graph-registry';
19
14
 
@@ -27,7 +22,7 @@ export const createMockedComputeRuntimeProvider = ({
27
22
  return {
28
23
  getRuntime: (_spaceId: SpaceId) =>
29
24
  ManagedRuntime.make(
30
- FunctionInvocationService.layerTest({ functions }).pipe(
25
+ FunctionInvocationServiceLayerTest({ functions }).pipe(
31
26
  Layer.provide(AiService.notAvailable),
32
27
  Layer.provide(CredentialsService.configuredLayer([])),
33
28
  Layer.provide(DatabaseService.notAvailable),