@dxos/functions 0.8.4-main.ef1bc66f44 → 0.8.4-main.effb148878
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/LICENSE +102 -5
- package/README.md +5 -7
- package/dist/lib/neutral/index.mjs +291 -925
- 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/functions-ai-http-client.test.d.ts +2 -0
- package/dist/types/src/protocol/functions-ai-http-client.test.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.d.ts +19 -2
- package/dist/types/src/protocol/protocol.d.ts.map +1 -1
- package/dist/types/src/sdk.d.ts +5 -109
- 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 +8 -6
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/index.d.ts +1 -5
- package/dist/types/src/services/index.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 +18 -17
- package/src/index.ts +0 -2
- package/src/protocol/functions-ai-http-client.test.ts +105 -0
- package/src/protocol/functions-ai-http-client.ts +75 -1
- package/src/protocol/protocol.test.ts +9 -10
- package/src/protocol/protocol.ts +244 -60
- package/src/sdk.ts +11 -271
- package/src/services/credentials.ts +76 -120
- package/src/services/function-invocation-service.ts +9 -10
- package/src/services/index.ts +1 -5
- 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/services/queues.d.ts +0 -47
- package/dist/types/src/services/queues.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 -121
- package/dist/types/src/types/Trigger.d.ts.map +0 -1
- package/dist/types/src/types/TriggerEvent.d.ts +0 -74
- 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/services/queues.ts +0 -82
- package/src/types/Function.ts +0 -82
- package/src/types/Script.ts +0 -34
- package/src/types/Trigger.ts +0 -143
- package/src/types/TriggerEvent.ts +0 -62
|
@@ -10,136 +10,23 @@ 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 {
|
|
14
|
-
import { Database } from '@dxos/echo';
|
|
13
|
+
import { Credential } from '@dxos/compute';
|
|
14
|
+
import { Database, Query } from '@dxos/echo';
|
|
15
15
|
import { AccessToken } from '@dxos/types';
|
|
16
16
|
|
|
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
|
-
}
|
|
17
|
+
export class ConfiguredCredentialsService implements Context.Tag.Service<Credential.CredentialsService> {
|
|
18
|
+
constructor(private readonly credentials: Credential.ServiceCredential[] = []) {}
|
|
109
19
|
|
|
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 {
|
|
20
|
+
addCredentials(credentials: Credential.ServiceCredential[]): ConfiguredCredentialsService {
|
|
134
21
|
this.credentials.push(...credentials);
|
|
135
22
|
return this;
|
|
136
23
|
}
|
|
137
24
|
|
|
138
|
-
async queryCredentials(query: CredentialQuery): Promise<ServiceCredential[]> {
|
|
25
|
+
async queryCredentials(query: Credential.CredentialQuery): Promise<Credential.ServiceCredential[]> {
|
|
139
26
|
return this.credentials.filter((credential) => credential.service === query.service);
|
|
140
27
|
}
|
|
141
28
|
|
|
142
|
-
async getCredential(query: CredentialQuery): Promise<ServiceCredential> {
|
|
29
|
+
async getCredential(query: Credential.CredentialQuery): Promise<Credential.ServiceCredential> {
|
|
143
30
|
const credential = this.credentials.find((credential) => credential.service === query.service);
|
|
144
31
|
if (!credential) {
|
|
145
32
|
throw new Error(`Credential not found for service: ${query.service}`);
|
|
@@ -157,3 +44,72 @@ export const withAuthorization = (token: string, kind?: 'Bearer' | 'Basic') =>
|
|
|
157
44
|
const authorization = kind ? `${kind} ${token}` : token;
|
|
158
45
|
return HttpClientRequest.setHeader(request, 'Authorization', authorization);
|
|
159
46
|
});
|
|
47
|
+
|
|
48
|
+
export const configuredCredentialsLayer = (credentials: Credential.ServiceCredential[]) =>
|
|
49
|
+
Layer.succeed(Credential.CredentialsService, new ConfiguredCredentialsService(credentials));
|
|
50
|
+
|
|
51
|
+
export const credentialsLayerConfig = (
|
|
52
|
+
credentials: {
|
|
53
|
+
service: string;
|
|
54
|
+
apiKey: Config.Config<Redacted.Redacted<string>>;
|
|
55
|
+
}[],
|
|
56
|
+
) =>
|
|
57
|
+
Layer.effect(
|
|
58
|
+
Credential.CredentialsService,
|
|
59
|
+
Effect.gen(function* () {
|
|
60
|
+
const serviceCredentials = yield* Effect.forEach(credentials, ({ service, apiKey }) =>
|
|
61
|
+
Effect.gen(function* () {
|
|
62
|
+
return {
|
|
63
|
+
service,
|
|
64
|
+
apiKey: Redacted.value(yield* apiKey),
|
|
65
|
+
};
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return new ConfiguredCredentialsService(serviceCredentials);
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
export const credentialsLayerFromDatabase = ({ caching = false }: { caching?: boolean } = {}) =>
|
|
74
|
+
Layer.effect(
|
|
75
|
+
Credential.CredentialsService,
|
|
76
|
+
Effect.gen(function* () {
|
|
77
|
+
const dbService = yield* Database.Service;
|
|
78
|
+
const cache = new Map<string, Credential.ServiceCredential[]>();
|
|
79
|
+
|
|
80
|
+
const queryCredentials = async (query: Credential.CredentialQuery): Promise<Credential.ServiceCredential[]> => {
|
|
81
|
+
const cacheKey = JSON.stringify(query);
|
|
82
|
+
if (caching && cache.has(cacheKey)) {
|
|
83
|
+
return cache.get(cacheKey)!;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const accessTokens = await dbService.db.query(Query.type(AccessToken.AccessToken)).run();
|
|
87
|
+
const credentials = accessTokens
|
|
88
|
+
.filter((accessToken) => accessToken.source === query.service)
|
|
89
|
+
.map((accessToken) => ({
|
|
90
|
+
service: accessToken.source,
|
|
91
|
+
apiKey: accessToken.token,
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
if (caching) {
|
|
95
|
+
cache.set(cacheKey, credentials);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return credentials;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
getCredential: async (query) => {
|
|
103
|
+
const credentials = await queryCredentials(query);
|
|
104
|
+
if (credentials.length === 0) {
|
|
105
|
+
throw new Error(`Credential not found for service: ${query.service}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return credentials[0];
|
|
109
|
+
},
|
|
110
|
+
queryCredentials: async (query) => {
|
|
111
|
+
return queryCredentials(query);
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
@@ -5,18 +5,17 @@ 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
|
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
11
13
|
export class FunctionInvocationService extends Context.Tag('@dxos/functions/FunctionInvocationService')<
|
|
12
14
|
FunctionInvocationService,
|
|
13
15
|
{
|
|
14
|
-
invokeFunction<I, O>(
|
|
15
|
-
functionDef: FunctionDefinition<I, O, any>,
|
|
16
|
-
input: I,
|
|
17
|
-
): Effect.Effect<O, never, InvocationServices>;
|
|
16
|
+
invokeFunction<I, O>(functionDef: Operation.Definition<I, O, any>, input: I): Effect.Effect<O>;
|
|
18
17
|
|
|
19
|
-
resolveFunction(key: string): Effect.Effect<
|
|
18
|
+
resolveFunction(key: string): Effect.Effect<Operation.Definition.Any, FunctionNotFoundError>;
|
|
20
19
|
}
|
|
21
20
|
>() {
|
|
22
21
|
static layerNotAvailable = Layer.succeed(FunctionInvocationService, {
|
|
@@ -25,13 +24,13 @@ export class FunctionInvocationService extends Context.Tag('@dxos/functions/Func
|
|
|
25
24
|
});
|
|
26
25
|
|
|
27
26
|
static invokeFunction = <I, O>(
|
|
28
|
-
functionDef:
|
|
27
|
+
functionDef: Operation.Definition<I, O, any>,
|
|
29
28
|
input: I,
|
|
30
|
-
): Effect.Effect<O, never, FunctionInvocationService
|
|
29
|
+
): Effect.Effect<O, never, FunctionInvocationService> =>
|
|
31
30
|
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.invokeFunction)(functionDef, input);
|
|
32
31
|
|
|
33
32
|
static resolveFunction = (
|
|
34
33
|
key: string,
|
|
35
|
-
): Effect.Effect<
|
|
34
|
+
): Effect.Effect<Operation.Definition.Any, FunctionNotFoundError, FunctionInvocationService> =>
|
|
36
35
|
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.resolveFunction)(key);
|
|
37
36
|
}
|
package/src/services/index.ts
CHANGED
|
@@ -3,9 +3,5 @@
|
|
|
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
|
-
export
|
|
11
|
-
export * from './tracing';
|
|
7
|
+
export { MESSAGE_PROPERTY_TOOL_CALL_ID } from './tracing';
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forex-effect.d.ts","sourceRoot":"","sources":["../../../../src/example/forex-effect.ts"],"names":[],"mappings":";AAeA,wBAwBG"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare namespace Example {
|
|
2
|
-
const fib: import("..").FunctionDefinition<{
|
|
3
|
-
readonly iterations?: number | undefined;
|
|
4
|
-
}, {
|
|
5
|
-
readonly result: string;
|
|
6
|
-
}, import("..").FunctionServices>;
|
|
7
|
-
const reply: import("..").FunctionDefinition<any, any, import("..").FunctionServices>;
|
|
8
|
-
const sleep: import("..").FunctionDefinition<{
|
|
9
|
-
readonly duration?: number | undefined;
|
|
10
|
-
}, void, import("..").FunctionServices>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/example/index.ts"],"names":[],"mappings":"AAQA,yBAAiB,OAAO,CAAC;IAChB,MAAM,GAAG;;;;qCAAO,CAAC;IACjB,MAAM,KAAK,0EAAS,CAAC;IACrB,MAAM,KAAK;;2CAAS,CAAC;CAC7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reply.d.ts","sourceRoot":"","sources":["../../../../src/example/reply.ts"],"names":[],"mappings":";AAUA,wBAUG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../../../src/example/sleep.ts"],"names":[],"mappings":";;;AASA,wBAcG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operation-compatibility.test.d.ts","sourceRoot":"","sources":["../../../src/operation-compatibility.test.ts"],"names":[],"mappings":""}
|