@dxos/functions 0.8.4-main.c85a9c8dae → 0.8.4-main.cb12b3f963
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/dist/lib/neutral/index.mjs +155 -920
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -1
- package/dist/types/src/protocol/protocol.d.ts +2 -2
- package/dist/types/src/protocol/protocol.d.ts.map +1 -1
- package/dist/types/src/sdk.d.ts +5 -112
- package/dist/types/src/sdk.d.ts.map +1 -1
- package/dist/types/src/services/credentials.d.ts +15 -38
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +5 -6
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/index.d.ts +1 -4
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +1 -46
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +1 -84
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +0 -4
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/url.d.ts +3 -3
- package/dist/types/src/types/url.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/index.ts +0 -2
- package/src/protocol/protocol.test.ts +9 -10
- package/src/protocol/protocol.ts +68 -34
- package/src/sdk.ts +10 -278
- package/src/services/credentials.ts +75 -118
- package/src/services/function-invocation-service.ts +6 -10
- package/src/services/index.ts +1 -4
- package/src/services/queues.ts +1 -78
- package/src/services/tracing.ts +0 -159
- package/src/types/index.ts +0 -4
- package/src/types/url.ts +3 -3
- package/dist/types/src/errors.d.ts +0 -121
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/example/fib.d.ts +0 -7
- package/dist/types/src/example/fib.d.ts.map +0 -1
- package/dist/types/src/example/forex-effect.d.ts +0 -3
- package/dist/types/src/example/forex-effect.d.ts.map +0 -1
- package/dist/types/src/example/index.d.ts +0 -12
- package/dist/types/src/example/index.d.ts.map +0 -1
- package/dist/types/src/example/reply.d.ts +0 -3
- package/dist/types/src/example/reply.d.ts.map +0 -1
- package/dist/types/src/example/sleep.d.ts +0 -5
- package/dist/types/src/example/sleep.d.ts.map +0 -1
- package/dist/types/src/operation-compatibility.test.d.ts +0 -2
- package/dist/types/src/operation-compatibility.test.d.ts.map +0 -1
- package/dist/types/src/services/event-logger.d.ts +0 -81
- package/dist/types/src/services/event-logger.d.ts.map +0 -1
- package/dist/types/src/types/Function.d.ts +0 -52
- package/dist/types/src/types/Function.d.ts.map +0 -1
- package/dist/types/src/types/Script.d.ts +0 -21
- package/dist/types/src/types/Script.d.ts.map +0 -1
- package/dist/types/src/types/Trigger.d.ts +0 -122
- package/dist/types/src/types/Trigger.d.ts.map +0 -1
- package/dist/types/src/types/TriggerEvent.d.ts +0 -75
- package/dist/types/src/types/TriggerEvent.d.ts.map +0 -1
- package/src/errors.ts +0 -21
- package/src/example/fib.ts +0 -32
- package/src/example/forex-effect.ts +0 -40
- package/src/example/index.ts +0 -13
- package/src/example/reply.ts +0 -21
- package/src/example/sleep.ts +0 -24
- package/src/operation-compatibility.test.ts +0 -185
- package/src/services/event-logger.ts +0 -127
- package/src/types/Function.ts +0 -83
- package/src/types/Script.ts +0 -34
- package/src/types/Trigger.ts +0 -153
- package/src/types/TriggerEvent.ts +0 -62
|
@@ -10,136 +10,24 @@ import * as Effect from 'effect/Effect';
|
|
|
10
10
|
import * as Layer from 'effect/Layer';
|
|
11
11
|
import * as Redacted from 'effect/Redacted';
|
|
12
12
|
|
|
13
|
+
import { Credential } from '@dxos/compute';
|
|
13
14
|
import { Query } from '@dxos/echo';
|
|
14
15
|
import { Database } from '@dxos/echo';
|
|
15
16
|
import { AccessToken } from '@dxos/types';
|
|
16
17
|
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// TODO(dmaretskyi): Unify with other apis.
|
|
22
|
-
// packages/sdk/schema/src/common/access-token.ts
|
|
23
|
-
export type ServiceCredential = {
|
|
24
|
-
service: string;
|
|
25
|
-
|
|
26
|
-
// TODO(dmaretskyi): Build out.
|
|
27
|
-
apiKey?: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export class CredentialsService extends Context.Tag('@dxos/functions/CredentialsService')<
|
|
31
|
-
CredentialsService,
|
|
32
|
-
{
|
|
33
|
-
/**
|
|
34
|
-
* Query all.
|
|
35
|
-
*/
|
|
36
|
-
queryCredentials: (query: CredentialQuery) => Promise<ServiceCredential[]>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Get a single credential.
|
|
40
|
-
* @throws {Error} If no credential is found.
|
|
41
|
-
*/
|
|
42
|
-
getCredential: (query: CredentialQuery) => Promise<ServiceCredential>;
|
|
43
|
-
}
|
|
44
|
-
>() {
|
|
45
|
-
static getCredential = (query: CredentialQuery): Effect.Effect<ServiceCredential, never, CredentialsService> =>
|
|
46
|
-
Effect.gen(function* () {
|
|
47
|
-
const credentials = yield* CredentialsService;
|
|
48
|
-
return yield* Effect.promise(() => credentials.getCredential(query));
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
static getApiKey = (query: CredentialQuery): Effect.Effect<Redacted.Redacted<string>, never, CredentialsService> =>
|
|
52
|
-
Effect.gen(function* () {
|
|
53
|
-
const credential = yield* CredentialsService.getCredential(query);
|
|
54
|
-
if (!credential.apiKey) {
|
|
55
|
-
throw new Error(`API key not found for service: ${query.service}`);
|
|
56
|
-
}
|
|
57
|
-
return Redacted.make(credential.apiKey);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
static configuredLayer = (credentials: ServiceCredential[]) =>
|
|
61
|
-
Layer.succeed(CredentialsService, new ConfiguredCredentialsService(credentials));
|
|
62
|
-
|
|
63
|
-
static layerConfig = (
|
|
64
|
-
credentials: {
|
|
65
|
-
service: string;
|
|
66
|
-
apiKey: Config.Config<Redacted.Redacted<string>>;
|
|
67
|
-
}[],
|
|
68
|
-
) =>
|
|
69
|
-
Layer.effect(
|
|
70
|
-
CredentialsService,
|
|
71
|
-
Effect.gen(function* () {
|
|
72
|
-
const serviceCredentials = yield* Effect.forEach(credentials, ({ service, apiKey }) =>
|
|
73
|
-
Effect.gen(function* () {
|
|
74
|
-
return {
|
|
75
|
-
service,
|
|
76
|
-
apiKey: Redacted.value(yield* apiKey),
|
|
77
|
-
};
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
return new ConfiguredCredentialsService(serviceCredentials);
|
|
82
|
-
}),
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
static layerFromDatabase = ({ caching = false }: { caching?: boolean } = {}) =>
|
|
86
|
-
Layer.effect(
|
|
87
|
-
CredentialsService,
|
|
88
|
-
Effect.gen(function* () {
|
|
89
|
-
const dbService = yield* Database.Service;
|
|
90
|
-
const cache = new Map<string, ServiceCredential[]>();
|
|
91
|
-
|
|
92
|
-
const queryCredentials = async (query: CredentialQuery): Promise<ServiceCredential[]> => {
|
|
93
|
-
const cacheKey = JSON.stringify(query);
|
|
94
|
-
if (caching && cache.has(cacheKey)) {
|
|
95
|
-
return cache.get(cacheKey)!;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const accessTokens = await dbService.db.query(Query.type(AccessToken.AccessToken)).run();
|
|
99
|
-
const credentials = accessTokens
|
|
100
|
-
.filter((accessToken) => accessToken.source === query.service)
|
|
101
|
-
.map((accessToken) => ({
|
|
102
|
-
service: accessToken.source,
|
|
103
|
-
apiKey: accessToken.token,
|
|
104
|
-
}));
|
|
105
|
-
|
|
106
|
-
if (caching) {
|
|
107
|
-
cache.set(cacheKey, credentials);
|
|
108
|
-
}
|
|
18
|
+
export class ConfiguredCredentialsService implements Context.Tag.Service<Credential.CredentialsService> {
|
|
19
|
+
constructor(private readonly credentials: Credential.ServiceCredential[] = []) {}
|
|
109
20
|
|
|
110
|
-
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
getCredential: async (query) => {
|
|
115
|
-
const credentials = await queryCredentials(query);
|
|
116
|
-
if (credentials.length === 0) {
|
|
117
|
-
throw new Error(`Credential not found for service: ${query.service}`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return credentials[0];
|
|
121
|
-
},
|
|
122
|
-
queryCredentials: async (query) => {
|
|
123
|
-
return queryCredentials(query);
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
}),
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export class ConfiguredCredentialsService implements Context.Tag.Service<CredentialsService> {
|
|
131
|
-
constructor(private readonly credentials: ServiceCredential[] = []) {}
|
|
132
|
-
|
|
133
|
-
addCredentials(credentials: ServiceCredential[]): ConfiguredCredentialsService {
|
|
21
|
+
addCredentials(credentials: Credential.ServiceCredential[]): ConfiguredCredentialsService {
|
|
134
22
|
this.credentials.push(...credentials);
|
|
135
23
|
return this;
|
|
136
24
|
}
|
|
137
25
|
|
|
138
|
-
async queryCredentials(query: CredentialQuery): Promise<ServiceCredential[]> {
|
|
26
|
+
async queryCredentials(query: Credential.CredentialQuery): Promise<Credential.ServiceCredential[]> {
|
|
139
27
|
return this.credentials.filter((credential) => credential.service === query.service);
|
|
140
28
|
}
|
|
141
29
|
|
|
142
|
-
async getCredential(query: CredentialQuery): Promise<ServiceCredential> {
|
|
30
|
+
async getCredential(query: Credential.CredentialQuery): Promise<Credential.ServiceCredential> {
|
|
143
31
|
const credential = this.credentials.find((credential) => credential.service === query.service);
|
|
144
32
|
if (!credential) {
|
|
145
33
|
throw new Error(`Credential not found for service: ${query.service}`);
|
|
@@ -157,3 +45,72 @@ export const withAuthorization = (token: string, kind?: 'Bearer' | 'Basic') =>
|
|
|
157
45
|
const authorization = kind ? `${kind} ${token}` : token;
|
|
158
46
|
return HttpClientRequest.setHeader(request, 'Authorization', authorization);
|
|
159
47
|
});
|
|
48
|
+
|
|
49
|
+
export const configuredCredentialsLayer = (credentials: Credential.ServiceCredential[]) =>
|
|
50
|
+
Layer.succeed(Credential.CredentialsService, new ConfiguredCredentialsService(credentials));
|
|
51
|
+
|
|
52
|
+
export const credentialsLayerConfig = (
|
|
53
|
+
credentials: {
|
|
54
|
+
service: string;
|
|
55
|
+
apiKey: Config.Config<Redacted.Redacted<string>>;
|
|
56
|
+
}[],
|
|
57
|
+
) =>
|
|
58
|
+
Layer.effect(
|
|
59
|
+
Credential.CredentialsService,
|
|
60
|
+
Effect.gen(function* () {
|
|
61
|
+
const serviceCredentials = yield* Effect.forEach(credentials, ({ service, apiKey }) =>
|
|
62
|
+
Effect.gen(function* () {
|
|
63
|
+
return {
|
|
64
|
+
service,
|
|
65
|
+
apiKey: Redacted.value(yield* apiKey),
|
|
66
|
+
};
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return new ConfiguredCredentialsService(serviceCredentials);
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
export const credentialsLayerFromDatabase = ({ caching = false }: { caching?: boolean } = {}) =>
|
|
75
|
+
Layer.effect(
|
|
76
|
+
Credential.CredentialsService,
|
|
77
|
+
Effect.gen(function* () {
|
|
78
|
+
const dbService = yield* Database.Service;
|
|
79
|
+
const cache = new Map<string, Credential.ServiceCredential[]>();
|
|
80
|
+
|
|
81
|
+
const queryCredentials = async (query: Credential.CredentialQuery): Promise<Credential.ServiceCredential[]> => {
|
|
82
|
+
const cacheKey = JSON.stringify(query);
|
|
83
|
+
if (caching && cache.has(cacheKey)) {
|
|
84
|
+
return cache.get(cacheKey)!;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const accessTokens = await dbService.db.query(Query.type(AccessToken.AccessToken)).run();
|
|
88
|
+
const credentials = accessTokens
|
|
89
|
+
.filter((accessToken) => accessToken.source === query.service)
|
|
90
|
+
.map((accessToken) => ({
|
|
91
|
+
service: accessToken.source,
|
|
92
|
+
apiKey: accessToken.token,
|
|
93
|
+
}));
|
|
94
|
+
|
|
95
|
+
if (caching) {
|
|
96
|
+
cache.set(cacheKey, credentials);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return credentials;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
getCredential: async (query) => {
|
|
104
|
+
const credentials = await queryCredentials(query);
|
|
105
|
+
if (credentials.length === 0) {
|
|
106
|
+
throw new Error(`Credential not found for service: ${query.service}`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return credentials[0];
|
|
110
|
+
},
|
|
111
|
+
queryCredentials: async (query) => {
|
|
112
|
+
return queryCredentials(query);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
@@ -5,18 +5,14 @@ import * as Context from 'effect/Context';
|
|
|
5
5
|
import * as Effect from 'effect/Effect';
|
|
6
6
|
import * as Layer from 'effect/Layer';
|
|
7
7
|
|
|
8
|
-
import type
|
|
9
|
-
import { type FunctionDefinition, type InvocationServices } from '../sdk';
|
|
8
|
+
import { type FunctionNotFoundError, Operation } from '@dxos/compute';
|
|
10
9
|
|
|
11
10
|
export class FunctionInvocationService extends Context.Tag('@dxos/functions/FunctionInvocationService')<
|
|
12
11
|
FunctionInvocationService,
|
|
13
12
|
{
|
|
14
|
-
invokeFunction<I, O>(
|
|
15
|
-
functionDef: FunctionDefinition<I, O, any>,
|
|
16
|
-
input: I,
|
|
17
|
-
): Effect.Effect<O, never, InvocationServices>;
|
|
13
|
+
invokeFunction<I, O>(functionDef: Operation.Definition<I, O, any>, input: I): Effect.Effect<O>;
|
|
18
14
|
|
|
19
|
-
resolveFunction(key: string): Effect.Effect<
|
|
15
|
+
resolveFunction(key: string): Effect.Effect<Operation.Definition.Any, FunctionNotFoundError>;
|
|
20
16
|
}
|
|
21
17
|
>() {
|
|
22
18
|
static layerNotAvailable = Layer.succeed(FunctionInvocationService, {
|
|
@@ -25,13 +21,13 @@ export class FunctionInvocationService extends Context.Tag('@dxos/functions/Func
|
|
|
25
21
|
});
|
|
26
22
|
|
|
27
23
|
static invokeFunction = <I, O>(
|
|
28
|
-
functionDef:
|
|
24
|
+
functionDef: Operation.Definition<I, O, any>,
|
|
29
25
|
input: I,
|
|
30
|
-
): Effect.Effect<O, never, FunctionInvocationService
|
|
26
|
+
): Effect.Effect<O, never, FunctionInvocationService> =>
|
|
31
27
|
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.invokeFunction)(functionDef, input);
|
|
32
28
|
|
|
33
29
|
static resolveFunction = (
|
|
34
30
|
key: string,
|
|
35
|
-
): Effect.Effect<
|
|
31
|
+
): Effect.Effect<Operation.Definition.Any, FunctionNotFoundError, FunctionInvocationService> =>
|
|
36
32
|
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.resolveFunction)(key);
|
|
37
33
|
}
|
package/src/services/index.ts
CHANGED
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
export * from './credentials';
|
|
6
|
-
export { ConfiguredCredentialsService, type ServiceCredential } from './credentials';
|
|
7
|
-
export * from './event-logger';
|
|
8
|
-
export { createEventLogger, createDefectLogger } from './event-logger';
|
|
9
6
|
export * from './function-invocation-service';
|
|
10
7
|
export * from './queues';
|
|
11
|
-
export
|
|
8
|
+
export { MESSAGE_PROPERTY_TOOL_CALL_ID } from './tracing';
|
package/src/services/queues.ts
CHANGED
|
@@ -2,81 +2,4 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
import * as Layer from 'effect/Layer';
|
|
8
|
-
|
|
9
|
-
import type { Entity } from '@dxos/echo';
|
|
10
|
-
import type { Queue, QueueAPI, QueueFactory } from '@dxos/echo-db';
|
|
11
|
-
import type { DXN, QueueSubspaceTag } from '@dxos/keys';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Gives access to all queues.
|
|
15
|
-
*/
|
|
16
|
-
export class QueueService extends Context.Tag('@dxos/functions/QueueService')<
|
|
17
|
-
QueueService,
|
|
18
|
-
{
|
|
19
|
-
/**
|
|
20
|
-
* API to access the queues.
|
|
21
|
-
*/
|
|
22
|
-
readonly queues: QueueAPI;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The queue that is used to store the context of the current research.
|
|
26
|
-
* @deprecated Use `ContextQueueService` instead.
|
|
27
|
-
*/
|
|
28
|
-
readonly queue: Queue | undefined;
|
|
29
|
-
}
|
|
30
|
-
>() {
|
|
31
|
-
static notAvailable = Layer.succeed(QueueService, {
|
|
32
|
-
queues: {
|
|
33
|
-
get(_dxn) {
|
|
34
|
-
throw new Error('Queues not available');
|
|
35
|
-
},
|
|
36
|
-
create() {
|
|
37
|
-
throw new Error('Queues not available');
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
queue: undefined,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
static make = (queues: QueueFactory, queue?: Queue): Context.Tag.Service<QueueService> => {
|
|
44
|
-
return {
|
|
45
|
-
queues,
|
|
46
|
-
queue,
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
static layer = (queues: QueueFactory, queue?: Queue): Layer.Layer<QueueService> =>
|
|
51
|
-
Layer.succeed(QueueService, QueueService.make(queues, queue));
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Gets a queue by its DXN.
|
|
55
|
-
*/
|
|
56
|
-
static getQueue = <T extends Entity.Unknown = Entity.Unknown>(
|
|
57
|
-
dxn: DXN,
|
|
58
|
-
): Effect.Effect<Queue<T>, never, QueueService> => QueueService.pipe(Effect.map(({ queues }) => queues.get<T>(dxn)));
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Creates a new queue.
|
|
62
|
-
*/
|
|
63
|
-
static createQueue = <T extends Entity.Unknown = Entity.Unknown>(options?: {
|
|
64
|
-
subspaceTag?: QueueSubspaceTag;
|
|
65
|
-
}): Effect.Effect<Queue<T>, never, QueueService> =>
|
|
66
|
-
QueueService.pipe(Effect.map(({ queues }) => queues.create<T>(options)));
|
|
67
|
-
|
|
68
|
-
static append = <T extends Entity.Unknown = Entity.Unknown>(queue: Queue<T>, objects: T[]): Effect.Effect<void> =>
|
|
69
|
-
Effect.promise(() => queue.append(objects));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Gives access to a specific queue passed as a context.
|
|
74
|
-
*/
|
|
75
|
-
export class ContextQueueService extends Context.Tag('@dxos/functions/ContextQueueService')<
|
|
76
|
-
ContextQueueService,
|
|
77
|
-
{
|
|
78
|
-
readonly queue: Queue;
|
|
79
|
-
}
|
|
80
|
-
>() {
|
|
81
|
-
static layer = (queue: Queue) => Layer.succeed(ContextQueueService, { queue });
|
|
82
|
-
}
|
|
5
|
+
export { ContextQueueService, QueueService, feedServiceFromQueueServiceLayer } from '@dxos/echo-db';
|
package/src/services/tracing.ts
CHANGED
|
@@ -2,165 +2,6 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import * as Context from 'effect/Context';
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
import * as Layer from 'effect/Layer';
|
|
8
|
-
|
|
9
|
-
import { AgentStatus } from '@dxos/ai';
|
|
10
|
-
import { type DXN, Obj } from '@dxos/echo';
|
|
11
|
-
import { ObjectId } from '@dxos/keys';
|
|
12
|
-
import { Message } from '@dxos/types';
|
|
13
|
-
|
|
14
|
-
import type { Trigger } from '../types';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Provides a way for compute primitives (functions, workflows, tools)
|
|
18
|
-
* to emit an execution trace as a series of structured ECHO objects.
|
|
19
|
-
*/
|
|
20
|
-
export class TracingService extends Context.Tag('@dxos/functions/TracingService')<
|
|
21
|
-
TracingService,
|
|
22
|
-
{
|
|
23
|
-
/**
|
|
24
|
-
* Gets the parent message ID.
|
|
25
|
-
*/
|
|
26
|
-
getTraceContext: () => TracingService.TraceContext;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Write an event to the tracing queue.
|
|
30
|
-
* @param event - The event to write. Must be an a typed object.
|
|
31
|
-
*/
|
|
32
|
-
write: (event: Obj.Unknown, traceContext: TracingService.TraceContext) => void;
|
|
33
|
-
|
|
34
|
-
traceInvocationStart({
|
|
35
|
-
payload,
|
|
36
|
-
target,
|
|
37
|
-
}: {
|
|
38
|
-
payload: TracingService.FunctionInvocationPayload;
|
|
39
|
-
target?: DXN;
|
|
40
|
-
}): Effect.Effect<TracingService.InvocationTraceData>;
|
|
41
|
-
|
|
42
|
-
traceInvocationEnd({
|
|
43
|
-
trace,
|
|
44
|
-
exception,
|
|
45
|
-
}: {
|
|
46
|
-
trace: TracingService.InvocationTraceData;
|
|
47
|
-
exception?: any;
|
|
48
|
-
}): Effect.Effect<void>;
|
|
49
|
-
}
|
|
50
|
-
>() {
|
|
51
|
-
static noop: Context.Tag.Service<TracingService> = {
|
|
52
|
-
getTraceContext: () => ({}),
|
|
53
|
-
write: () => {},
|
|
54
|
-
traceInvocationStart: () =>
|
|
55
|
-
Effect.sync(() => ({ invocationId: ObjectId.random(), invocationTraceQueue: undefined })),
|
|
56
|
-
traceInvocationEnd: () => Effect.sync(() => {}),
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
static layerNoop: Layer.Layer<TracingService> = Layer.succeed(TracingService, TracingService.noop);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Creates a TracingService layer that emits events to the parent tracing service.
|
|
63
|
-
*/
|
|
64
|
-
static layerSubframe = (mapContext: (currentContext: TracingService.TraceContext) => TracingService.TraceContext) =>
|
|
65
|
-
Layer.effect(
|
|
66
|
-
TracingService,
|
|
67
|
-
Effect.gen(function* () {
|
|
68
|
-
const tracing = yield* TracingService;
|
|
69
|
-
const context = mapContext(tracing.getTraceContext());
|
|
70
|
-
return {
|
|
71
|
-
write: (event, context) => tracing.write(event, context),
|
|
72
|
-
getTraceContext: () => context,
|
|
73
|
-
traceInvocationStart: () => Effect.die('Tracing invocation inside another invocation is not supported.'),
|
|
74
|
-
traceInvocationEnd: () => Effect.die('Tracing invocation inside another invocation is not supported.'),
|
|
75
|
-
};
|
|
76
|
-
}),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Create sublayer to trace an invocation.
|
|
81
|
-
* @param data
|
|
82
|
-
* @returns
|
|
83
|
-
*/
|
|
84
|
-
static layerInvocation = (data: TracingService.InvocationTraceData) =>
|
|
85
|
-
TracingService.layerSubframe((context) => ({
|
|
86
|
-
...context,
|
|
87
|
-
currentInvocation: data,
|
|
88
|
-
}));
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Emit the current human-readable execution status.
|
|
92
|
-
*/
|
|
93
|
-
static emitStatus: (
|
|
94
|
-
data: Omit<Obj.MakeProps<typeof AgentStatus>, 'created'>,
|
|
95
|
-
) => Effect.Effect<void, never, TracingService> = Effect.fnUntraced(function* (data) {
|
|
96
|
-
const tracing = yield* TracingService;
|
|
97
|
-
tracing.write(
|
|
98
|
-
Obj.make(AgentStatus, {
|
|
99
|
-
parentMessage: tracing.getTraceContext().parentMessage,
|
|
100
|
-
toolCallId: tracing.getTraceContext().toolCallId,
|
|
101
|
-
created: new Date().toISOString(),
|
|
102
|
-
...data,
|
|
103
|
-
}),
|
|
104
|
-
tracing.getTraceContext(),
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
static emitConverationMessage: (
|
|
109
|
-
data: Obj.MakeProps<typeof Message.Message>,
|
|
110
|
-
) => Effect.Effect<void, never, TracingService> = Effect.fnUntraced(function* (data) {
|
|
111
|
-
const tracing = yield* TracingService;
|
|
112
|
-
tracing.write(
|
|
113
|
-
Obj.make(Message.Message, {
|
|
114
|
-
parentMessage: tracing.getTraceContext().parentMessage,
|
|
115
|
-
...data,
|
|
116
|
-
properties: {
|
|
117
|
-
[MESSAGE_PROPERTY_TOOL_CALL_ID]: tracing.getTraceContext().toolCallId,
|
|
118
|
-
...data.properties,
|
|
119
|
-
},
|
|
120
|
-
}),
|
|
121
|
-
tracing.getTraceContext(),
|
|
122
|
-
);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export namespace TracingService {
|
|
127
|
-
export interface TraceContext {
|
|
128
|
-
currentInvocation?: InvocationTraceData;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* If this thread sprung from a tool call, this is the ID of the message containing the tool call.
|
|
132
|
-
*/
|
|
133
|
-
parentMessage?: ObjectId;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* If the current thread is a byproduct of a tool call, this is the ID of the tool call.
|
|
137
|
-
*/
|
|
138
|
-
toolCallId?: string;
|
|
139
|
-
|
|
140
|
-
debugInfo?: unknown;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Trace data for a function/trigger invocation.
|
|
145
|
-
*/
|
|
146
|
-
export interface InvocationTraceData {
|
|
147
|
-
invocationId: ObjectId;
|
|
148
|
-
invocationTraceQueue?: DXN.String;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Payload for a function/trigger invocation.
|
|
153
|
-
*/
|
|
154
|
-
export interface FunctionInvocationPayload {
|
|
155
|
-
data?: any;
|
|
156
|
-
inputNodeId?: string;
|
|
157
|
-
trigger?: {
|
|
158
|
-
id: string;
|
|
159
|
-
kind: Trigger.Kind;
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
5
|
/**
|
|
165
6
|
* Goes into {@link Message['properties']}
|
|
166
7
|
*/
|
package/src/types/index.ts
CHANGED
package/src/types/url.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
import { type Obj } from '@dxos/echo';
|
|
6
6
|
|
|
7
7
|
// TODO: use URL scheme for source?
|
|
8
|
-
export const FUNCTIONS_META_KEY = 'dxos.
|
|
8
|
+
export const FUNCTIONS_META_KEY = 'org.dxos.service.function';
|
|
9
9
|
|
|
10
|
-
export const FUNCTIONS_PRESET_META_KEY = 'dxos.
|
|
10
|
+
export const FUNCTIONS_PRESET_META_KEY = 'org.dxos.service.function-preset';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* NOTE: functionId is backend ID, not ECHO object id.
|
|
@@ -18,7 +18,7 @@ export const getUserFunctionIdInMetadata = (meta: Obj.ReadonlyMeta) => {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* NOTE: functionId is backend ID, not ECHO object id.
|
|
21
|
-
* Must be called inside Obj.
|
|
21
|
+
* Must be called inside Obj.update() since it mutates the meta.
|
|
22
22
|
*/
|
|
23
23
|
export const setUserFunctionIdInMetadata = (meta: Obj.Meta, functionId: string) => {
|
|
24
24
|
const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { BaseError, type BaseErrorOptions } from '@dxos/errors';
|
|
2
|
-
declare const ServiceNotAvailableError_base: {
|
|
3
|
-
new (options?: BaseErrorOptions): {
|
|
4
|
-
name: "ServiceNotAvailable";
|
|
5
|
-
context: Record<string, unknown>;
|
|
6
|
-
readonly message: string;
|
|
7
|
-
readonly _tag: "ServiceNotAvailable";
|
|
8
|
-
stack?: string;
|
|
9
|
-
cause?: unknown;
|
|
10
|
-
};
|
|
11
|
-
name: "ServiceNotAvailable";
|
|
12
|
-
is(error: unknown): error is BaseError;
|
|
13
|
-
wrap(options?: Omit<BaseErrorOptions, "cause"> & {
|
|
14
|
-
ifTypeDiffers?: boolean;
|
|
15
|
-
}): (error: unknown) => {
|
|
16
|
-
name: "ServiceNotAvailable";
|
|
17
|
-
context: Record<string, unknown>;
|
|
18
|
-
readonly message: string;
|
|
19
|
-
readonly _tag: "ServiceNotAvailable";
|
|
20
|
-
stack?: string;
|
|
21
|
-
cause?: unknown;
|
|
22
|
-
};
|
|
23
|
-
extend<Name extends string = string>(name: Name, message?: string): any;
|
|
24
|
-
isError(error: unknown): error is Error;
|
|
25
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
26
|
-
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
27
|
-
stackTraceLimit: number;
|
|
28
|
-
};
|
|
29
|
-
export declare class ServiceNotAvailableError extends ServiceNotAvailableError_base {
|
|
30
|
-
constructor(service: string, options?: Omit<BaseErrorOptions, 'context'>);
|
|
31
|
-
}
|
|
32
|
-
declare const FunctionNotFoundError_base: {
|
|
33
|
-
new (options?: BaseErrorOptions): {
|
|
34
|
-
name: "FunctionNotFound";
|
|
35
|
-
context: Record<string, unknown>;
|
|
36
|
-
readonly message: string;
|
|
37
|
-
readonly _tag: "FunctionNotFound";
|
|
38
|
-
stack?: string;
|
|
39
|
-
cause?: unknown;
|
|
40
|
-
};
|
|
41
|
-
name: "FunctionNotFound";
|
|
42
|
-
is(error: unknown): error is BaseError;
|
|
43
|
-
wrap(options?: Omit<BaseErrorOptions, "cause"> & {
|
|
44
|
-
ifTypeDiffers?: boolean;
|
|
45
|
-
}): (error: unknown) => {
|
|
46
|
-
name: "FunctionNotFound";
|
|
47
|
-
context: Record<string, unknown>;
|
|
48
|
-
readonly message: string;
|
|
49
|
-
readonly _tag: "FunctionNotFound";
|
|
50
|
-
stack?: string;
|
|
51
|
-
cause?: unknown;
|
|
52
|
-
};
|
|
53
|
-
extend<Name extends string = string>(name: Name, message?: string): any;
|
|
54
|
-
isError(error: unknown): error is Error;
|
|
55
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
56
|
-
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
57
|
-
stackTraceLimit: number;
|
|
58
|
-
};
|
|
59
|
-
export declare class FunctionNotFoundError extends FunctionNotFoundError_base {
|
|
60
|
-
constructor(functionKey: string, options?: Omit<BaseErrorOptions, 'context'>);
|
|
61
|
-
}
|
|
62
|
-
declare const FunctionError_base: {
|
|
63
|
-
new (options?: BaseErrorOptions): {
|
|
64
|
-
name: "FunctionError";
|
|
65
|
-
context: Record<string, unknown>;
|
|
66
|
-
readonly message: string;
|
|
67
|
-
readonly _tag: "FunctionError";
|
|
68
|
-
stack?: string;
|
|
69
|
-
cause?: unknown;
|
|
70
|
-
};
|
|
71
|
-
name: "FunctionError";
|
|
72
|
-
is(error: unknown): error is BaseError;
|
|
73
|
-
wrap(options?: Omit<BaseErrorOptions, "cause"> & {
|
|
74
|
-
ifTypeDiffers?: boolean;
|
|
75
|
-
}): (error: unknown) => {
|
|
76
|
-
name: "FunctionError";
|
|
77
|
-
context: Record<string, unknown>;
|
|
78
|
-
readonly message: string;
|
|
79
|
-
readonly _tag: "FunctionError";
|
|
80
|
-
stack?: string;
|
|
81
|
-
cause?: unknown;
|
|
82
|
-
};
|
|
83
|
-
extend<Name extends string = string>(name: Name, message?: string): any;
|
|
84
|
-
isError(error: unknown): error is Error;
|
|
85
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
86
|
-
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
87
|
-
stackTraceLimit: number;
|
|
88
|
-
};
|
|
89
|
-
export declare class FunctionError extends FunctionError_base {
|
|
90
|
-
}
|
|
91
|
-
declare const TriggerStateNotFoundError_base: {
|
|
92
|
-
new (options?: BaseErrorOptions): {
|
|
93
|
-
name: "TriggerStateNotFound";
|
|
94
|
-
context: Record<string, unknown>;
|
|
95
|
-
readonly message: string;
|
|
96
|
-
readonly _tag: "TriggerStateNotFound";
|
|
97
|
-
stack?: string;
|
|
98
|
-
cause?: unknown;
|
|
99
|
-
};
|
|
100
|
-
name: "TriggerStateNotFound";
|
|
101
|
-
is(error: unknown): error is BaseError;
|
|
102
|
-
wrap(options?: Omit<BaseErrorOptions, "cause"> & {
|
|
103
|
-
ifTypeDiffers?: boolean;
|
|
104
|
-
}): (error: unknown) => {
|
|
105
|
-
name: "TriggerStateNotFound";
|
|
106
|
-
context: Record<string, unknown>;
|
|
107
|
-
readonly message: string;
|
|
108
|
-
readonly _tag: "TriggerStateNotFound";
|
|
109
|
-
stack?: string;
|
|
110
|
-
cause?: unknown;
|
|
111
|
-
};
|
|
112
|
-
extend<Name extends string = string>(name: Name, message?: string): any;
|
|
113
|
-
isError(error: unknown): error is Error;
|
|
114
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
115
|
-
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
116
|
-
stackTraceLimit: number;
|
|
117
|
-
};
|
|
118
|
-
export declare class TriggerStateNotFoundError extends TriggerStateNotFoundError_base {
|
|
119
|
-
}
|
|
120
|
-
export {};
|
|
121
|
-
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;;;;;;;;;;;;;qBAiB4O,CAAC;;;;;;;;;;;;;;;AAf7S,qBAAa,wBAAyB,SAAQ,6BAAgE;gBAChG,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC;CAGzE;;;;;;;;;;;;;qBAW2S,CAAC;;;;;;;;;;;;;;;AAT7S,qBAAa,qBAAsB,SAAQ,0BAA0D;gBACvF,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC;CAG7E;;;;;;;;;;;;;qBAK2S,CAAC;;;;;;;;;;;;;;;AAH7S,qBAAa,aAAc,SAAQ,kBAA8D;CAAG;;;;;;;;;;;;;qBAGwM,CAAC;;;;;;;;;;;;;;;AAD7S,qBAAa,yBAA0B,SAAQ,8BAAmE;CAAG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fib.d.ts","sourceRoot":"","sources":["../../../../src/example/fib.ts"],"names":[],"mappings":";;;;;AASA,wBAsBG"}
|