@dxos/functions-runtime-cloudflare 0.8.4-main.3c1ae3b → 0.8.4-main.69d29f4

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 (35) hide show
  1. package/dist/lib/browser/index.mjs +503 -118
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +503 -118
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/functions-client.d.ts +1 -0
  8. package/dist/types/src/functions-client.d.ts.map +1 -1
  9. package/dist/types/src/internal/data-service-impl.d.ts +7 -6
  10. package/dist/types/src/internal/data-service-impl.d.ts.map +1 -1
  11. package/dist/types/src/internal/query-service-impl.d.ts.map +1 -1
  12. package/dist/types/src/internal/queue-service-impl.d.ts +4 -5
  13. package/dist/types/src/internal/queue-service-impl.d.ts.map +1 -1
  14. package/dist/types/src/internal/service-container.d.ts +5 -3
  15. package/dist/types/src/internal/service-container.d.ts.map +1 -1
  16. package/dist/types/src/internal/utils.d.ts +2 -0
  17. package/dist/types/src/internal/utils.d.ts.map +1 -0
  18. package/dist/types/src/logger.d.ts.map +1 -1
  19. package/dist/types/src/queues-api.d.ts +3 -3
  20. package/dist/types/src/queues-api.d.ts.map +1 -1
  21. package/dist/types/src/space-proxy.d.ts +3 -2
  22. package/dist/types/src/space-proxy.d.ts.map +1 -1
  23. package/dist/types/src/wrap-handler-for-cloudflare.d.ts.map +1 -1
  24. package/dist/types/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +20 -16
  26. package/src/functions-client.ts +8 -1
  27. package/src/internal/data-service-impl.ts +27 -10
  28. package/src/internal/query-service-impl.ts +7 -3
  29. package/src/internal/queue-service-impl.ts +32 -14
  30. package/src/internal/service-container.ts +25 -6
  31. package/src/internal/utils.ts +5 -0
  32. package/src/logger.ts +2 -0
  33. package/src/queues-api.ts +3 -3
  34. package/src/space-proxy.ts +4 -3
  35. package/src/wrap-handler-for-cloudflare.ts +3 -3
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@dxos/functions-runtime-cloudflare",
3
- "version": "0.8.4-main.3c1ae3b",
3
+ "version": "0.8.4-main.69d29f4",
4
4
  "description": "Functions runtime for Cloudflare.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "info@dxos.org",
9
13
  "sideEffects": false,
@@ -23,23 +27,23 @@
23
27
  "src"
24
28
  ],
25
29
  "dependencies": {
26
- "effect": "3.18.3",
27
- "@dxos/codec-protobuf": "0.8.4-main.3c1ae3b",
28
- "@dxos/context": "0.8.4-main.3c1ae3b",
29
- "@dxos/debug": "0.8.4-main.3c1ae3b",
30
- "@dxos/echo": "0.8.4-main.3c1ae3b",
31
- "@dxos/errors": "0.8.4-main.3c1ae3b",
32
- "@dxos/echo-db": "0.8.4-main.3c1ae3b",
33
- "@dxos/echo-protocol": "0.8.4-main.3c1ae3b",
34
- "@dxos/log": "0.8.4-main.3c1ae3b",
35
- "@dxos/protocols": "0.8.4-main.3c1ae3b",
36
- "@dxos/keys": "0.8.4-main.3c1ae3b",
37
- "@dxos/invariant": "0.8.4-main.3c1ae3b",
38
- "@dxos/util": "0.8.4-main.3c1ae3b"
30
+ "effect": "3.19.11",
31
+ "@dxos/debug": "0.8.4-main.69d29f4",
32
+ "@dxos/context": "0.8.4-main.69d29f4",
33
+ "@dxos/echo": "0.8.4-main.69d29f4",
34
+ "@dxos/echo-db": "0.8.4-main.69d29f4",
35
+ "@dxos/codec-protobuf": "0.8.4-main.69d29f4",
36
+ "@dxos/echo-protocol": "0.8.4-main.69d29f4",
37
+ "@dxos/errors": "0.8.4-main.69d29f4",
38
+ "@dxos/invariant": "0.8.4-main.69d29f4",
39
+ "@dxos/log": "0.8.4-main.69d29f4",
40
+ "@dxos/keys": "0.8.4-main.69d29f4",
41
+ "@dxos/protocols": "0.8.4-main.69d29f4",
42
+ "@dxos/util": "0.8.4-main.69d29f4"
39
43
  },
40
44
  "devDependencies": {
41
- "@cloudflare/workers-types": "4.20251202.0",
42
- "@dxos/types": "0.8.4-main.3c1ae3b"
45
+ "@cloudflare/workers-types": "^4.20251210.0",
46
+ "@dxos/types": "0.8.4-main.69d29f4"
43
47
  },
44
48
  "publishConfig": {
45
49
  "access": "public"
@@ -14,6 +14,7 @@ import { SpaceProxy } from './space-proxy';
14
14
  type Services = {
15
15
  dataService: EdgeFunctionEnv.DataService;
16
16
  queueService: EdgeFunctionEnv.QueueService;
17
+ functionsAiService: EdgeFunctionEnv.FunctionsAiService;
17
18
  };
18
19
 
19
20
  /**
@@ -31,7 +32,12 @@ export class FunctionsClient extends Resource {
31
32
  super();
32
33
  invariant(typeof services.dataService !== 'undefined', 'DataService is required');
33
34
  invariant(typeof services.queueService !== 'undefined', 'QueueService is required');
34
- this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService);
35
+ this._serviceContainer = new ServiceContainer(
36
+ this._executionContext,
37
+ services.dataService,
38
+ services.queueService,
39
+ services.functionsAiService,
40
+ );
35
41
  this._echoClient = new EchoClient({});
36
42
  }
37
43
 
@@ -69,6 +75,7 @@ export const createClientFromEnv = async (env: any): Promise<FunctionsClient> =>
69
75
  const client = new FunctionsClient({
70
76
  dataService: env.DATA_SERVICE,
71
77
  queueService: env.QUEUE_SERVICE,
78
+ functionsAiService: env.FUNCTIONS_AI_SERVICE,
72
79
  });
73
80
  await client.open();
74
81
  return client;
@@ -12,6 +12,8 @@ import { log } from '@dxos/log';
12
12
  import { type EdgeFunctionEnv } from '@dxos/protocols';
13
13
  import type {
14
14
  BatchedDocumentUpdates,
15
+ CreateDocumentRequest,
16
+ CreateDocumentResponse,
15
17
  DataService as DataServiceProto,
16
18
  GetDocumentHeadsRequest,
17
19
  GetDocumentHeadsResponse,
@@ -22,6 +24,8 @@ import type {
22
24
  UpdateSubscriptionRequest,
23
25
  } from '@dxos/protocols/proto/dxos/echo/service';
24
26
 
27
+ import { copyUint8Array } from './utils';
28
+
25
29
  export class DataServiceImpl implements DataServiceProto {
26
30
  private dataSubscriptions = new Map<string, { spaceId: SpaceId; next: (msg: BatchedDocumentUpdates) => void }>();
27
31
 
@@ -41,7 +45,7 @@ export class DataServiceImpl implements DataServiceProto {
41
45
  });
42
46
  }
43
47
 
44
- async updateSubscription({ subscriptionId, addIds, removeIds }: UpdateSubscriptionRequest): Promise<void> {
48
+ async updateSubscription({ subscriptionId, addIds }: UpdateSubscriptionRequest): Promise<void> {
45
49
  const sub =
46
50
  this.dataSubscriptions.get(subscriptionId) ??
47
51
  raise(
@@ -55,17 +59,31 @@ export class DataServiceImpl implements DataServiceProto {
55
59
  log.info('request documents', { count: addIds.length });
56
60
  // TODO(dmaretskyi): Batch.
57
61
  for (const documentId of addIds) {
58
- const document = await this._dataService.getDocument(this._executionContext, sub.spaceId, documentId);
62
+ using document = await this._dataService.getDocument(this._executionContext, sub.spaceId, documentId);
59
63
  log.info('document loaded', { documentId, spaceId: sub.spaceId, found: !!document });
60
64
  if (!document) {
61
65
  log.warn('not found', { documentId });
62
66
  continue;
63
67
  }
64
- sub.next({ updates: [{ documentId, mutation: document.data }] });
68
+ sub.next({
69
+ updates: [
70
+ {
71
+ documentId,
72
+ // Copy returned object to avoid hanging RPC stub
73
+ // See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
74
+ mutation: copyUint8Array(document.data),
75
+ },
76
+ ],
77
+ });
65
78
  }
66
79
  }
67
80
  }
68
81
 
82
+ async createDocument({ spaceId, initialValue }: CreateDocumentRequest): Promise<CreateDocumentResponse> {
83
+ using response = await this._dataService.createDocument(this._executionContext, { spaceId, initialValue });
84
+ return { documentId: response.documentId };
85
+ }
86
+
69
87
  async update({ updates, subscriptionId }: UpdateRequest): Promise<void> {
70
88
  const sub =
71
89
  this.dataSubscriptions.get(subscriptionId) ??
@@ -93,31 +111,30 @@ export class DataServiceImpl implements DataServiceProto {
93
111
  // No-op.
94
112
  }
95
113
 
96
- subscribeSpaceSyncState(request: GetSpaceSyncStateRequest, options?: RequestOptions): Stream<SpaceSyncState> {
114
+ subscribeSpaceSyncState(_request: GetSpaceSyncStateRequest, _options?: RequestOptions): Stream<SpaceSyncState> {
97
115
  throw new NotImplementedError({
98
116
  message: 'subscribeSpaceSyncState is not implemented.',
99
117
  });
100
118
  }
101
119
 
102
- async getDocumentHeads({ documentIds }: GetDocumentHeadsRequest): Promise<GetDocumentHeadsResponse> {
120
+ async getDocumentHeads({ documentIds: _documentIds }: GetDocumentHeadsRequest): Promise<GetDocumentHeadsResponse> {
103
121
  throw new NotImplementedError({
104
122
  message: 'getDocumentHeads is not implemented.',
105
123
  });
106
124
  }
107
125
 
108
- async reIndexHeads({ documentIds }: ReIndexHeadsRequest): Promise<void> {
126
+ async reIndexHeads({ documentIds: _documentIds }: ReIndexHeadsRequest): Promise<void> {
109
127
  throw new NotImplementedError({
110
128
  message: 'reIndexHeads is not implemented.',
111
129
  });
112
130
  }
113
131
 
114
132
  async updateIndexes(): Promise<void> {
115
- throw new NotImplementedError({
116
- message: 'updateIndexes is not implemented.',
117
- });
133
+ log.error('updateIndexes is not available in EDGE env.');
134
+ // No-op.
118
135
  }
119
136
 
120
- async waitUntilHeadsReplicated({ heads }: { heads: any }): Promise<void> {
137
+ async waitUntilHeadsReplicated({ heads: _heads }: { heads: any }): Promise<void> {
121
138
  throw new NotImplementedError({
122
139
  message: 'waitUntilHeadsReplicated is not implemented.',
123
140
  });
@@ -20,6 +20,7 @@ import {
20
20
  } from '@dxos/protocols/proto/dxos/echo/query';
21
21
 
22
22
  import { queryToDataServiceRequest } from './adapter';
23
+ import { copyUint8Array } from './utils';
23
24
 
24
25
  export class QueryServiceImpl implements QueryServiceProto {
25
26
  private _queryCount = 0;
@@ -41,7 +42,7 @@ export class QueryServiceImpl implements QueryServiceProto {
41
42
  try {
42
43
  this._queryCount++;
43
44
  log.info('begin query', { spaceId });
44
- const queryResponse = await this._dataService.queryDocuments(
45
+ using queryResponse = await this._dataService.queryDocuments(
45
46
  this._executionContext,
46
47
  queryToDataServiceRequest(query),
47
48
  );
@@ -53,8 +54,11 @@ export class QueryServiceImpl implements QueryServiceProto {
53
54
  spaceId,
54
55
  spaceKey: PublicKey.ZERO,
55
56
  documentId: object.document.documentId,
56
- rank: 0,
57
- documentAutomerge: object.document.data,
57
+ // Rank 1 for predicate matches where ranking is not determined.
58
+ rank: 1,
59
+ // Copy returned object to avoid hanging RPC stub.
60
+ // See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
61
+ documentAutomerge: copyUint8Array(object.document.data),
58
62
  }),
59
63
  ),
60
64
  } satisfies QueryResponse;
@@ -3,36 +3,53 @@
3
3
  //
4
4
 
5
5
  import { NotImplementedError, RuntimeServiceError } from '@dxos/errors';
6
- import type { ObjectId, SpaceId } from '@dxos/keys';
6
+ import { invariant } from '@dxos/invariant';
7
7
  import { type QueueService as QueueServiceProto } from '@dxos/protocols';
8
- import type { EdgeFunctionEnv, QueryResult, QueueQuery } from '@dxos/protocols';
8
+ import type {
9
+ DeleteFromQueueRequest,
10
+ EdgeFunctionEnv,
11
+ InsertIntoQueueRequest,
12
+ QueryQueueRequest,
13
+ QueryResult,
14
+ } from '@dxos/protocols';
9
15
 
10
16
  export class QueueServiceImpl implements QueueServiceProto {
11
17
  constructor(
12
18
  protected _ctx: EdgeFunctionEnv.ExecutionContext,
13
19
  private readonly _queueService: EdgeFunctionEnv.QueueService,
14
20
  ) {}
15
- async queryQueue(subspaceTag: string, spaceId: SpaceId, { queueId, ...query }: QueueQuery): Promise<QueryResult> {
21
+ async queryQueue(request: QueryQueueRequest): Promise<QueryResult> {
22
+ const { query } = request;
23
+ const { queueIds, ...filter } = query!;
24
+ const spaceId = query!.spaceId;
25
+ const queueId = queueIds?.[0];
26
+ invariant(request.query.queuesNamespace);
16
27
  try {
17
- const result = await this._queueService.query(this._ctx, `dxn:queue:${subspaceTag}:${spaceId}:${queueId}`, query);
18
- return result;
28
+ using result = await this._queueService.query(
29
+ this._ctx,
30
+ `dxn:queue:${request.query.queuesNamespace}:${spaceId}:${queueId}`,
31
+ filter,
32
+ );
33
+ return {
34
+ // Copy returned object to avoid hanging RPC stub
35
+ // See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
36
+ objects: structuredClone(result.objects),
37
+ nextCursor: result.nextCursor,
38
+ prevCursor: result.prevCursor,
39
+ };
19
40
  } catch (error) {
20
41
  throw RuntimeServiceError.wrap({
21
42
  message: 'Queue query failed.',
22
- context: { subspaceTag, spaceId, queueId },
43
+ context: { subspaceTag: request.query.queuesNamespace, spaceId, queueId },
23
44
  ifTypeDiffers: true,
24
45
  })(error);
25
46
  }
26
47
  }
27
48
 
28
- async insertIntoQueue(subspaceTag: string, spaceId: SpaceId, queueId: ObjectId, objects: unknown[]): Promise<void> {
49
+ async insertIntoQueue(request: InsertIntoQueueRequest): Promise<void> {
50
+ const { subspaceTag, spaceId, queueId, objects } = request;
29
51
  try {
30
- const result = await this._queueService.append(
31
- this._ctx,
32
- `dxn:queue:${subspaceTag}:${spaceId}:${queueId}`,
33
- objects,
34
- );
35
- return result;
52
+ await this._queueService.append(this._ctx, `dxn:queue:${subspaceTag}:${spaceId}:${queueId}`, objects ?? []);
36
53
  } catch (error) {
37
54
  throw RuntimeServiceError.wrap({
38
55
  message: 'Queue append failed.',
@@ -42,7 +59,8 @@ export class QueueServiceImpl implements QueueServiceProto {
42
59
  }
43
60
  }
44
61
 
45
- deleteFromQueue(subspaceTag: string, spaceId: SpaceId, queueId: ObjectId, _objectIds: ObjectId[]): Promise<void> {
62
+ deleteFromQueue(request: DeleteFromQueueRequest): Promise<void> {
63
+ const { subspaceTag, spaceId, queueId } = request;
46
64
  throw new NotImplementedError({
47
65
  message: 'Deleting from queue is not supported.',
48
66
  context: { subspaceTag, spaceId, queueId },
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import type { HasId } from '@dxos/echo/internal';
5
+ import { type AnyEntity } from '@dxos/echo/internal';
6
6
  import { type DXN, type SpaceId } from '@dxos/keys';
7
7
  import type { QueryResult } from '@dxos/protocols';
8
8
  import { type EdgeFunctionEnv } from '@dxos/protocols';
@@ -22,16 +22,26 @@ export class ServiceContainer {
22
22
  private readonly _executionContext: EdgeFunctionEnv.ExecutionContext,
23
23
  private readonly _dataService: EdgeFunctionEnv.DataService,
24
24
  private readonly _queueService: EdgeFunctionEnv.QueueService,
25
+ private readonly _functionsService: EdgeFunctionEnv.FunctionsAiService,
25
26
  ) {}
26
27
 
27
28
  async getSpaceMeta(spaceId: SpaceId): Promise<EdgeFunctionEnv.SpaceMeta | undefined> {
28
- return this._dataService.getSpaceMeta(this._executionContext, spaceId);
29
+ using result = await this._dataService.getSpaceMeta(this._executionContext, spaceId);
30
+ // Copy returned object to avoid hanging RPC stub
31
+ // See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
32
+ return result
33
+ ? {
34
+ spaceKey: result.spaceKey,
35
+ rootDocumentId: result.rootDocumentId,
36
+ }
37
+ : undefined;
29
38
  }
30
39
 
31
40
  async createServices(): Promise<{
32
41
  dataService: DataServiceProto;
33
42
  queryService: QueryServiceProto;
34
43
  queueService: QueueServiceProto;
44
+ functionsAiService: EdgeFunctionEnv.FunctionsAiService;
35
45
  }> {
36
46
  const dataService = new DataServiceImpl(this._executionContext, this._dataService);
37
47
  const queryService = new QueryServiceImpl(this._executionContext, this._dataService);
@@ -41,14 +51,23 @@ export class ServiceContainer {
41
51
  dataService,
42
52
  queryService,
43
53
  queueService,
54
+ functionsAiService: this._functionsService,
44
55
  };
45
56
  }
46
57
 
47
- queryQueue(queue: DXN): Promise<QueryResult> {
48
- return this._queueService.query({}, queue.toString(), {});
58
+ async queryQueue(queue: DXN): Promise<QueryResult> {
59
+ const { spaceId } = queue.asQueueDXN() ?? {};
60
+ using result = (await this._queueService.query({}, queue.toString(), { spaceId: spaceId! })) as any;
61
+ // Copy returned object to avoid hanging RPC stub
62
+ // See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
63
+ return {
64
+ objects: structuredClone(result.objects),
65
+ nextCursor: result.nextCursor ?? null,
66
+ prevCursor: result.prevCursor ?? null,
67
+ };
49
68
  }
50
69
 
51
- insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void> {
52
- return this._queueService.append({}, queue.toString(), objects);
70
+ async insertIntoQueue(queue: DXN, objects: AnyEntity[]): Promise<void> {
71
+ await this._queueService.append({}, queue.toString(), objects);
53
72
  }
54
73
  }
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export const copyUint8Array = (value: Uint8Array): Uint8Array => new Uint8Array(value);
package/src/logger.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ /* eslint-disable no-console */
6
+
5
7
  import { LogLevel, type LogProcessor, log, shouldLog } from '@dxos/log';
6
8
 
7
9
  export const setupFunctionsLogger = () => {
package/src/queues-api.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import type { HasId } from '@dxos/echo/internal';
5
+ import { type AnyEntity } from '@dxos/echo/internal';
6
6
  import type { DXN, SpaceId } from '@dxos/keys';
7
7
  import type { QueryResult } from '@dxos/protocols';
8
8
 
@@ -15,7 +15,7 @@ import type { ServiceContainer } from './internal';
15
15
  */
16
16
  export interface QueuesAPI {
17
17
  queryQueue(queue: DXN, options?: {}): Promise<QueryResult>;
18
- insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void>;
18
+ insertIntoQueue(queue: DXN, objects: AnyEntity[]): Promise<void>;
19
19
  }
20
20
 
21
21
  /**
@@ -31,7 +31,7 @@ export class QueuesAPIImpl implements QueuesAPI {
31
31
  return this._serviceContainer.queryQueue(queue);
32
32
  }
33
33
 
34
- insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void> {
34
+ insertIntoQueue(queue: DXN, objects: AnyEntity[]): Promise<void> {
35
35
  // TODO(dmaretskyi): Ugly.
36
36
  return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));
37
37
  }
@@ -3,7 +3,8 @@
3
3
  //
4
4
 
5
5
  import { Resource } from '@dxos/context';
6
- import { type CoreDatabase, type EchoClient, type EchoDatabase } from '@dxos/echo-db';
6
+ import { type Database } from '@dxos/echo';
7
+ import { type CoreDatabase, type EchoClient, type EchoDatabaseImpl } from '@dxos/echo-db';
7
8
  import { invariant } from '@dxos/invariant';
8
9
  import { PublicKey, type SpaceId } from '@dxos/keys';
9
10
 
@@ -14,7 +15,7 @@ import { type QueuesAPI, QueuesAPIImpl } from './queues-api';
14
15
  * @deprecated
15
16
  */
16
17
  export class SpaceProxy extends Resource {
17
- private _db?: EchoDatabase = undefined;
18
+ private _db?: EchoDatabaseImpl = undefined;
18
19
  private _queuesApi: QueuesAPIImpl;
19
20
 
20
21
  constructor(
@@ -30,7 +31,7 @@ export class SpaceProxy extends Resource {
30
31
  return this._id;
31
32
  }
32
33
 
33
- get db(): EchoDatabase {
34
+ get db(): Database.Database {
34
35
  invariant(this._db);
35
36
  return this._db;
36
37
  }
@@ -22,7 +22,6 @@ export const wrapHandlerForCloudflare = (func: FunctionProtocol.Func): ExportedH
22
22
  // TODO(mykola): Wrap in withNewExecutionContext;
23
23
  // Meta route is used to get the input schema of the function by the functions service.
24
24
  if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
25
- log.info('>>> meta', { func });
26
25
  return handleFunctionMetaCall(func, request);
27
26
  }
28
27
 
@@ -34,7 +33,7 @@ export const wrapHandlerForCloudflare = (func: FunctionProtocol.Func): ExportedH
34
33
  }
35
34
  }
36
35
 
37
- const serviceContainer = new ServiceContainer({}, env.DATA_SERVICE, env.QUEUE_SERVICE);
36
+ const serviceContainer = new ServiceContainer({}, env.DATA_SERVICE, env.QUEUE_SERVICE, env.FUNCTIONS_AI_SERVICE);
38
37
  const context = await createFunctionContext({
39
38
  serviceContainer,
40
39
  contextSpaceId: spaceId as SpaceId | undefined,
@@ -105,7 +104,7 @@ const createFunctionContext = async ({
105
104
  serviceContainer: ServiceContainer;
106
105
  contextSpaceId: SpaceId | undefined;
107
106
  }): Promise<FunctionProtocol.Context> => {
108
- const { dataService, queryService, queueService } = await serviceContainer.createServices();
107
+ const { dataService, queryService, queueService, functionsAiService } = await serviceContainer.createServices();
109
108
 
110
109
  let spaceKey: string | undefined;
111
110
  let rootUrl: string | undefined;
@@ -124,6 +123,7 @@ const createFunctionContext = async ({
124
123
  dataService,
125
124
  queryService,
126
125
  queueService,
126
+ functionsAiService,
127
127
  },
128
128
  spaceId: contextSpaceId,
129
129
  spaceKey,