@dxos/functions 0.8.4-main.72ec0f3 → 0.8.4-main.7996785055
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/README.md +4 -6
- package/dist/lib/neutral/chunk-GEM2K7BA.mjs +56 -0
- package/dist/lib/neutral/chunk-GEM2K7BA.mjs.map +7 -0
- package/dist/lib/neutral/fib-XBUKWUUS.mjs +22 -0
- package/dist/lib/neutral/fib-XBUKWUUS.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +960 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/reply-XBQTXDLZ.mjs +18 -0
- package/dist/lib/neutral/reply-XBQTXDLZ.mjs.map +7 -0
- package/dist/lib/neutral/sleep-TLQKHAK2.mjs +14 -0
- package/dist/lib/neutral/sleep-TLQKHAK2.mjs.map +7 -0
- package/dist/types/src/errors.d.ts +24 -32
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/example/definitions.d.ts +11 -0
- package/dist/types/src/example/definitions.d.ts.map +1 -0
- package/dist/types/src/example/fib.d.ts +3 -2
- package/dist/types/src/example/fib.d.ts.map +1 -1
- package/dist/types/src/example/index.d.ts +3 -11
- package/dist/types/src/example/index.d.ts.map +1 -1
- package/dist/types/src/example/reply.d.ts +2 -1
- package/dist/types/src/example/reply.d.ts.map +1 -1
- package/dist/types/src/example/sleep.d.ts +3 -2
- package/dist/types/src/example/sleep.d.ts.map +1 -1
- package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
- package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
- 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 +2 -79
- package/dist/types/src/sdk.d.ts.map +1 -1
- package/dist/types/src/services/credentials.d.ts +6 -4
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/event-logger.d.ts +25 -31
- package/dist/types/src/services/event-logger.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +9 -3
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/index.d.ts +0 -1
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +4 -4
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +38 -3
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/Script.d.ts +9 -16
- package/dist/types/src/types/Script.d.ts.map +1 -1
- package/dist/types/src/types/Trigger.d.ts +57 -76
- package/dist/types/src/types/Trigger.d.ts.map +1 -1
- package/dist/types/src/types/TriggerEvent.d.ts +44 -13
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +0 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/url.d.ts +6 -5
- package/dist/types/src/types/url.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -17
- package/src/errors.ts +4 -4
- package/src/example/definitions.ts +48 -0
- package/src/example/fib.ts +14 -24
- package/src/example/forex-effect.ts +1 -1
- package/src/example/index.ts +7 -8
- package/src/example/reply.ts +10 -13
- package/src/example/sleep.ts +8 -17
- package/src/protocol/functions-ai-http-client.ts +67 -0
- package/src/protocol/protocol.ts +196 -84
- package/src/sdk.ts +4 -194
- package/src/services/credentials.ts +31 -15
- package/src/services/event-logger.ts +2 -2
- package/src/services/function-invocation-service.ts +18 -3
- package/src/services/index.ts +0 -2
- package/src/services/queues.ts +5 -7
- package/src/services/tracing.ts +64 -4
- package/src/types/Script.ts +13 -8
- package/src/types/Trigger.ts +31 -17
- package/src/types/TriggerEvent.ts +29 -29
- package/src/types/index.ts +0 -1
- package/src/types/url.ts +6 -5
- package/dist/lib/browser/index.mjs +0 -927
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -928
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/types/src/types/Function.d.ts +0 -58
- package/dist/types/src/types/Function.d.ts.map +0 -1
- package/src/types/Function.ts +0 -62
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/functions",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.7996785055",
|
|
4
4
|
"description": "Functions API.",
|
|
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,
|
|
@@ -12,8 +16,7 @@
|
|
|
12
16
|
".": {
|
|
13
17
|
"source": "./src/index.ts",
|
|
14
18
|
"types": "./dist/types/src/index.d.ts",
|
|
15
|
-
"
|
|
16
|
-
"node": "./dist/lib/node-esm/index.mjs"
|
|
19
|
+
"default": "./dist/lib/neutral/index.mjs"
|
|
17
20
|
}
|
|
18
21
|
},
|
|
19
22
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -23,20 +26,23 @@
|
|
|
23
26
|
"src"
|
|
24
27
|
],
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"@effect/
|
|
27
|
-
"effect": "
|
|
28
|
-
"
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/invariant": "0.8.4-main.
|
|
34
|
-
"@dxos/keys": "0.8.4-main.
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/
|
|
29
|
+
"@effect/ai-anthropic": "0.23.0",
|
|
30
|
+
"@effect/platform": "0.94.4",
|
|
31
|
+
"effect": "3.20.0",
|
|
32
|
+
"@dxos/ai": "0.8.4-main.7996785055",
|
|
33
|
+
"@dxos/context": "0.8.4-main.7996785055",
|
|
34
|
+
"@dxos/echo": "0.8.4-main.7996785055",
|
|
35
|
+
"@dxos/echo-db": "0.8.4-main.7996785055",
|
|
36
|
+
"@dxos/invariant": "0.8.4-main.7996785055",
|
|
37
|
+
"@dxos/keys": "0.8.4-main.7996785055",
|
|
38
|
+
"@dxos/effect": "0.8.4-main.7996785055",
|
|
39
|
+
"@dxos/log": "0.8.4-main.7996785055",
|
|
40
|
+
"@dxos/node-std": "0.8.4-main.7996785055",
|
|
41
|
+
"@dxos/errors": "0.8.4-main.7996785055",
|
|
42
|
+
"@dxos/operation": "0.8.4-main.7996785055",
|
|
43
|
+
"@dxos/protocols": "0.8.4-main.7996785055",
|
|
44
|
+
"@dxos/types": "0.8.4-main.7996785055",
|
|
45
|
+
"@dxos/schema": "0.8.4-main.7996785055"
|
|
40
46
|
},
|
|
41
47
|
"publishConfig": {
|
|
42
48
|
"access": "public"
|
package/src/errors.ts
CHANGED
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
import { BaseError, type BaseErrorOptions } from '@dxos/errors';
|
|
6
6
|
|
|
7
|
-
export class ServiceNotAvailableError extends BaseError.extend('
|
|
7
|
+
export class ServiceNotAvailableError extends BaseError.extend('ServiceNotAvailable', 'Service not available') {
|
|
8
8
|
constructor(service: string, options?: Omit<BaseErrorOptions, 'context'>) {
|
|
9
9
|
super({ context: { service }, ...options });
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export class FunctionNotFoundError extends BaseError.extend('
|
|
13
|
+
export class FunctionNotFoundError extends BaseError.extend('FunctionNotFound', 'Function not found') {
|
|
14
14
|
constructor(functionKey: string, options?: Omit<BaseErrorOptions, 'context'>) {
|
|
15
15
|
super({ context: { function: functionKey }, ...options });
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export class FunctionError extends BaseError.extend('
|
|
19
|
+
export class FunctionError extends BaseError.extend('FunctionError', 'Function invocation error') {}
|
|
20
20
|
|
|
21
|
-
export class TriggerStateNotFoundError extends BaseError.extend('
|
|
21
|
+
export class TriggerStateNotFoundError extends BaseError.extend('TriggerStateNotFound', 'Trigger state not found') {}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Operation } from '@dxos/operation';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
|
|
8
|
+
export const Fibonacci = Operation.make({
|
|
9
|
+
meta: {
|
|
10
|
+
key: 'example.org/function/fib',
|
|
11
|
+
name: 'Fibonacci',
|
|
12
|
+
description: 'Function that calculates a Fibonacci number',
|
|
13
|
+
},
|
|
14
|
+
input: Schema.Struct({
|
|
15
|
+
iterations: Schema.optional(Schema.Number).annotations({
|
|
16
|
+
description: 'Number of iterations',
|
|
17
|
+
default: 100_000,
|
|
18
|
+
}),
|
|
19
|
+
}),
|
|
20
|
+
output: Schema.Struct({
|
|
21
|
+
result: Schema.String,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const Reply = Operation.make({
|
|
26
|
+
meta: {
|
|
27
|
+
key: 'example.org/function/reply',
|
|
28
|
+
name: 'Reply',
|
|
29
|
+
description: 'Function that echoes the input',
|
|
30
|
+
},
|
|
31
|
+
input: Schema.Any,
|
|
32
|
+
output: Schema.Any,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const Sleep = Operation.make({
|
|
36
|
+
meta: {
|
|
37
|
+
key: 'example.org/function/sleep',
|
|
38
|
+
name: 'Sleep',
|
|
39
|
+
description: 'Function that sleeps for a given amount of time',
|
|
40
|
+
},
|
|
41
|
+
input: Schema.Struct({
|
|
42
|
+
duration: Schema.optional(Schema.Number).annotations({
|
|
43
|
+
description: 'Milliseconds to sleep',
|
|
44
|
+
default: 100_000,
|
|
45
|
+
}),
|
|
46
|
+
}),
|
|
47
|
+
output: Schema.Void,
|
|
48
|
+
});
|
package/src/example/fib.ts
CHANGED
|
@@ -3,30 +3,20 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import * as Effect from 'effect/Effect';
|
|
6
|
-
import * as Schema from 'effect/Schema';
|
|
7
6
|
|
|
8
|
-
import {
|
|
7
|
+
import { Operation } from '@dxos/operation';
|
|
8
|
+
import { Fibonacci } from './definitions';
|
|
9
9
|
|
|
10
|
-
export default
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
export default Fibonacci.pipe(
|
|
11
|
+
Operation.withHandler(
|
|
12
|
+
Effect.fn(function* ({ iterations = 100_000 }) {
|
|
13
|
+
let a = 0n;
|
|
14
|
+
let b = 1n;
|
|
15
|
+
for (let i = 0; i < iterations; i++) {
|
|
16
|
+
a += b;
|
|
17
|
+
b = a - b;
|
|
18
|
+
}
|
|
19
|
+
return { result: a.toString() };
|
|
18
20
|
}),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
result: Schema.String,
|
|
22
|
-
}),
|
|
23
|
-
handler: Effect.fn(function* ({ data: { iterations = 100_000 } }) {
|
|
24
|
-
let a = 0n;
|
|
25
|
-
let b = 1n;
|
|
26
|
-
for (let i = 0; i < iterations; i++) {
|
|
27
|
-
a += b;
|
|
28
|
-
b = a - b;
|
|
29
|
-
}
|
|
30
|
-
return { result: a.toString() };
|
|
31
|
-
}),
|
|
32
|
-
});
|
|
21
|
+
),
|
|
22
|
+
);
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import { Effect, Schedule } from 'https://esm.sh/effect@3.17.0?bundle=false';
|
|
15
15
|
|
|
16
16
|
export default defineFunction({
|
|
17
|
-
key: 'dxos.
|
|
17
|
+
key: 'org.dxos.script.forex-effect',
|
|
18
18
|
name: 'Forex Effect',
|
|
19
19
|
description: 'Returns the exchange rate between two currencies.',
|
|
20
20
|
|
package/src/example/index.ts
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { default as sleep$ } from './sleep';
|
|
5
|
+
import { OperationHandlerSet } from '@dxos/operation';
|
|
6
|
+
export * from './definitions';
|
|
8
7
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export const ExampleHandlers = OperationHandlerSet.lazy(
|
|
9
|
+
() => import('./fib'),
|
|
10
|
+
() => import('./reply'),
|
|
11
|
+
() => import('./sleep'),
|
|
12
|
+
);
|
package/src/example/reply.ts
CHANGED
|
@@ -4,18 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Console from 'effect/Console';
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
|
-
import * as Schema from 'effect/Schema';
|
|
8
7
|
|
|
9
|
-
import {
|
|
8
|
+
import { Operation } from '@dxos/operation';
|
|
9
|
+
import { Reply } from './definitions';
|
|
10
10
|
|
|
11
|
-
export default
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return data;
|
|
20
|
-
}),
|
|
21
|
-
});
|
|
11
|
+
export default Reply.pipe(
|
|
12
|
+
Operation.withHandler(
|
|
13
|
+
Effect.fn(function* (input) {
|
|
14
|
+
yield* Console.log('reply', { input });
|
|
15
|
+
return input;
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
);
|
package/src/example/sleep.ts
CHANGED
|
@@ -3,22 +3,13 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import * as Effect from 'effect/Effect';
|
|
6
|
-
import
|
|
6
|
+
import { Sleep } from './definitions';
|
|
7
|
+
import { Operation } from '@dxos/operation';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
name: 'Sleep',
|
|
13
|
-
description: 'Function that sleeps for a given amount of time',
|
|
14
|
-
inputSchema: Schema.Struct({
|
|
15
|
-
duration: Schema.optional(Schema.Number).annotations({
|
|
16
|
-
description: 'Milliseconds to sleep',
|
|
17
|
-
default: 100_000,
|
|
9
|
+
export default Sleep.pipe(
|
|
10
|
+
Operation.withHandler(
|
|
11
|
+
Effect.fn(function* ({ duration = 100_000 }) {
|
|
12
|
+
yield* Effect.sleep(duration);
|
|
18
13
|
}),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
handler: Effect.fn(function* ({ data: { duration = 100_000 } }) {
|
|
22
|
-
yield* Effect.sleep(duration);
|
|
23
|
-
}),
|
|
24
|
-
});
|
|
14
|
+
),
|
|
15
|
+
);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Headers from '@effect/platform/Headers';
|
|
6
|
+
import * as HttpClient from '@effect/platform/HttpClient';
|
|
7
|
+
import * as HttpClientError from '@effect/platform/HttpClientError';
|
|
8
|
+
import * as HttpClientResponse from '@effect/platform/HttpClientResponse';
|
|
9
|
+
import * as Effect from 'effect/Effect';
|
|
10
|
+
import * as FiberRef from 'effect/FiberRef';
|
|
11
|
+
import * as Layer from 'effect/Layer';
|
|
12
|
+
import * as Stream from 'effect/Stream';
|
|
13
|
+
|
|
14
|
+
import { log } from '@dxos/log';
|
|
15
|
+
import { type EdgeFunctionEnv, ErrorCodec } from '@dxos/protocols';
|
|
16
|
+
/**
|
|
17
|
+
* Copy pasted from https://github.com/Effect-TS/effect/blob/main/packages/platform/src/internal/fetchHttpClient.ts
|
|
18
|
+
*/
|
|
19
|
+
export const requestInitTagKey = '@effect/platform/FetchHttpClient/FetchOptions';
|
|
20
|
+
|
|
21
|
+
export class FunctionsAiHttpClient {
|
|
22
|
+
static make = (service: EdgeFunctionEnv.FunctionsAiService) =>
|
|
23
|
+
HttpClient.make((request, url, signal, fiber) => {
|
|
24
|
+
const context = fiber.getFiberRef(FiberRef.currentContext);
|
|
25
|
+
const options: RequestInit = context.unsafeMap.get(requestInitTagKey) ?? {};
|
|
26
|
+
const headers = options.headers
|
|
27
|
+
? Headers.merge(Headers.fromInput(options.headers), request.headers)
|
|
28
|
+
: request.headers;
|
|
29
|
+
|
|
30
|
+
const send = (body: BodyInit | undefined) =>
|
|
31
|
+
Effect.tryPromise({
|
|
32
|
+
try: () =>
|
|
33
|
+
service.fetch(
|
|
34
|
+
new Request(url, {
|
|
35
|
+
...options,
|
|
36
|
+
method: request.method,
|
|
37
|
+
headers,
|
|
38
|
+
body,
|
|
39
|
+
// Note: Don't pass signal - it can't be serialized through RPC
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
catch: (cause) => {
|
|
43
|
+
log.error('Failed to fetch', { errorSerialized: ErrorCodec.encode(cause as Error) });
|
|
44
|
+
return new HttpClientError.RequestError({
|
|
45
|
+
request,
|
|
46
|
+
reason: 'Transport',
|
|
47
|
+
cause,
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
}).pipe(Effect.map((response) => HttpClientResponse.fromWeb(request, response)));
|
|
51
|
+
|
|
52
|
+
switch (request.body._tag) {
|
|
53
|
+
case 'Raw':
|
|
54
|
+
case 'Uint8Array':
|
|
55
|
+
return send(request.body.body as any);
|
|
56
|
+
case 'FormData':
|
|
57
|
+
return send(request.body.formData);
|
|
58
|
+
case 'Stream':
|
|
59
|
+
return Stream.toReadableStreamEffect(request.body.stream).pipe(Effect.flatMap(send));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return send(undefined);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
static layer = (service: EdgeFunctionEnv.FunctionsAiService) =>
|
|
66
|
+
Layer.succeed(HttpClient.HttpClient, FunctionsAiHttpClient.make(service));
|
|
67
|
+
}
|