@dxos/functions 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29
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/index.mjs +593 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/index.d.ts +3 -9
- package/dist/types/src/index.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/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/index.d.ts +2 -0
- package/dist/types/src/protocol/index.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.d.ts +19 -0
- package/dist/types/src/protocol/protocol.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.test.d.ts +2 -0
- package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
- package/dist/types/src/sdk.d.ts +10 -0
- package/dist/types/src/sdk.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +22 -39
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +15 -0
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
- package/dist/types/src/services/index.d.ts +3 -7
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +1 -44
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +2 -54
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/url.d.ts +13 -0
- package/dist/types/src/types/url.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -72
- package/src/index.ts +3 -9
- package/src/protocol/functions-ai-http-client.test.ts +105 -0
- package/src/protocol/functions-ai-http-client.ts +141 -0
- package/src/{executor → protocol}/index.ts +1 -1
- package/src/protocol/protocol.test.ts +58 -0
- package/src/protocol/protocol.ts +428 -0
- package/src/sdk.ts +31 -0
- package/src/services/credentials.ts +90 -111
- package/src/services/function-invocation-service.ts +33 -0
- package/src/services/index.ts +3 -7
- package/src/services/queues.ts +1 -78
- package/src/services/tracing.ts +1 -133
- package/src/types/index.ts +5 -0
- package/src/types/url.ts +32 -0
- package/dist/lib/browser/bundler/index.mjs +0 -265
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-ANP3DFCO.mjs +0 -623
- package/dist/lib/browser/chunk-ANP3DFCO.mjs.map +0 -7
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +0 -10
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +0 -7
- package/dist/lib/browser/edge/index.mjs +0 -83
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -1265
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs +0 -129
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -266
- package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MPKVY7ZR.mjs +0 -625
- package/dist/lib/node-esm/chunk-MPKVY7ZR.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -84
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -1266
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -130
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -49
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/edge/functions.d.ts +0 -17
- package/dist/types/src/edge/functions.d.ts.map +0 -1
- package/dist/types/src/edge/index.d.ts +0 -2
- package/dist/types/src/edge/index.d.ts.map +0 -1
- package/dist/types/src/errors.d.ts +0 -137
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/examples/fib.d.ts +0 -7
- package/dist/types/src/examples/fib.d.ts.map +0 -1
- package/dist/types/src/examples/index.d.ts +0 -4
- package/dist/types/src/examples/index.d.ts.map +0 -1
- package/dist/types/src/examples/reply.d.ts +0 -3
- package/dist/types/src/examples/reply.d.ts.map +0 -1
- package/dist/types/src/examples/sleep.d.ts +0 -5
- package/dist/types/src/examples/sleep.d.ts.map +0 -1
- package/dist/types/src/executor/executor.d.ts +0 -11
- package/dist/types/src/executor/executor.d.ts.map +0 -1
- package/dist/types/src/executor/index.d.ts +0 -2
- package/dist/types/src/executor/index.d.ts.map +0 -1
- package/dist/types/src/handler.d.ts +0 -94
- package/dist/types/src/handler.d.ts.map +0 -1
- package/dist/types/src/schema.d.ts +0 -43
- package/dist/types/src/schema.d.ts.map +0 -1
- package/dist/types/src/services/database.d.ts +0 -98
- package/dist/types/src/services/database.d.ts.map +0 -1
- package/dist/types/src/services/event-logger.d.ts +0 -72
- package/dist/types/src/services/event-logger.d.ts.map +0 -1
- package/dist/types/src/services/local-function-execution.d.ts +0 -25
- package/dist/types/src/services/local-function-execution.d.ts.map +0 -1
- package/dist/types/src/services/remote-function-execution-service.d.ts +0 -15
- package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
- package/dist/types/src/services/service-container.d.ts +0 -56
- package/dist/types/src/services/service-container.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.d.ts +0 -29
- package/dist/types/src/services/service-registry.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.test.d.ts +0 -2
- package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/layer.d.ts +0 -15
- package/dist/types/src/testing/layer.d.ts.map +0 -1
- package/dist/types/src/testing/logger.d.ts +0 -5
- package/dist/types/src/testing/logger.d.ts.map +0 -1
- package/dist/types/src/testing/persist-database.test.d.ts +0 -2
- package/dist/types/src/testing/persist-database.test.d.ts.map +0 -1
- package/dist/types/src/testing/services.d.ts +0 -59
- package/dist/types/src/testing/services.d.ts.map +0 -1
- package/dist/types/src/trace.d.ts +0 -122
- package/dist/types/src/trace.d.ts.map +0 -1
- package/dist/types/src/translations.d.ts +0 -12
- package/dist/types/src/translations.d.ts.map +0 -1
- package/dist/types/src/triggers/index.d.ts +0 -4
- package/dist/types/src/triggers/index.d.ts.map +0 -1
- package/dist/types/src/triggers/input-builder.d.ts +0 -3
- package/dist/types/src/triggers/input-builder.d.ts.map +0 -1
- package/dist/types/src/triggers/invocation-tracer.d.ts +0 -35
- package/dist/types/src/triggers/invocation-tracer.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.d.ts +0 -75
- package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.test.d.ts +0 -2
- package/dist/types/src/triggers/trigger-dispatcher.test.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-state-store.d.ts +0 -27
- package/dist/types/src/triggers/trigger-state-store.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -211
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/types/src/url.d.ts +0 -21
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -58
- package/src/bundler/bundler.ts +0 -291
- package/src/bundler/index.ts +0 -5
- package/src/edge/functions.ts +0 -67
- package/src/edge/index.ts +0 -9
- package/src/errors.ts +0 -21
- package/src/examples/fib.ts +0 -30
- package/src/examples/index.ts +0 -7
- package/src/examples/reply.ts +0 -18
- package/src/examples/sleep.ts +0 -22
- package/src/executor/executor.ts +0 -54
- package/src/handler.ts +0 -201
- package/src/schema.ts +0 -68
- package/src/services/database.ts +0 -170
- package/src/services/event-logger.ts +0 -118
- package/src/services/local-function-execution.ts +0 -114
- package/src/services/remote-function-execution-service.ts +0 -46
- package/src/services/service-container.ts +0 -114
- package/src/services/service-registry.test.ts +0 -42
- package/src/services/service-registry.ts +0 -59
- package/src/testing/index.ts +0 -6
- package/src/testing/layer.ts +0 -111
- package/src/testing/logger.ts +0 -16
- package/src/testing/persist-database.test.ts +0 -87
- package/src/testing/services.ts +0 -115
- package/src/trace.ts +0 -178
- package/src/translations.ts +0 -20
- package/src/triggers/index.ts +0 -7
- package/src/triggers/input-builder.ts +0 -35
- package/src/triggers/invocation-tracer.ts +0 -99
- package/src/triggers/trigger-dispatcher.test.ts +0 -652
- package/src/triggers/trigger-dispatcher.ts +0 -512
- package/src/triggers/trigger-state-store.ts +0 -60
- package/src/types.ts +0 -200
- package/src/url.ts +0 -55
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
import * as Context from 'effect/Context';
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as Layer from 'effect/Layer';
|
|
7
|
+
|
|
8
|
+
import { type FunctionNotFoundError, Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
export class FunctionInvocationService extends Context.Tag('@dxos/functions/FunctionInvocationService')<
|
|
11
|
+
FunctionInvocationService,
|
|
12
|
+
{
|
|
13
|
+
invokeFunction<I, O>(functionDef: Operation.Definition<I, O, any>, input: I): Effect.Effect<O>;
|
|
14
|
+
|
|
15
|
+
resolveFunction(key: string): Effect.Effect<Operation.Definition.Any, FunctionNotFoundError>;
|
|
16
|
+
}
|
|
17
|
+
>() {
|
|
18
|
+
static layerNotAvailable = Layer.succeed(FunctionInvocationService, {
|
|
19
|
+
invokeFunction: () => Effect.die('FunctionInvocationService is not avaialble.'),
|
|
20
|
+
resolveFunction: () => Effect.die('FunctionInvocationService is not available.'),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
static invokeFunction = <I, O>(
|
|
24
|
+
functionDef: Operation.Definition<I, O, any>,
|
|
25
|
+
input: I,
|
|
26
|
+
): Effect.Effect<O, never, FunctionInvocationService> =>
|
|
27
|
+
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.invokeFunction)(functionDef, input);
|
|
28
|
+
|
|
29
|
+
static resolveFunction = (
|
|
30
|
+
key: string,
|
|
31
|
+
): Effect.Effect<Operation.Definition.Any, FunctionNotFoundError, FunctionInvocationService> =>
|
|
32
|
+
Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.resolveFunction)(key);
|
|
33
|
+
}
|
package/src/services/index.ts
CHANGED
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './database';
|
|
6
|
-
export * from './queues';
|
|
7
|
-
export * from './service-container';
|
|
8
5
|
export * from './credentials';
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export
|
|
12
|
-
export * from './local-function-execution';
|
|
6
|
+
export * from './function-invocation-service';
|
|
7
|
+
export * from './queues';
|
|
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
|
-
|
|
7
|
-
import type { Obj, Relation } from '@dxos/echo';
|
|
8
|
-
import type { Queue, QueueAPI, QueueFactory } from '@dxos/echo-db';
|
|
9
|
-
import type { DXN, QueueSubspaceTag } from '@dxos/keys';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Gives access to all queues.
|
|
13
|
-
*/
|
|
14
|
-
export class QueueService extends Context.Tag('@dxos/functions/QueueService')<
|
|
15
|
-
QueueService,
|
|
16
|
-
{
|
|
17
|
-
/**
|
|
18
|
-
* API to access the queues.
|
|
19
|
-
*/
|
|
20
|
-
readonly queues: QueueAPI;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The queue that is used to store the context of the current research.
|
|
24
|
-
* @deprecated Use `ContextQueueService` instead.
|
|
25
|
-
*/
|
|
26
|
-
readonly queue: Queue | undefined;
|
|
27
|
-
}
|
|
28
|
-
>() {
|
|
29
|
-
static notAvailable = Layer.succeed(QueueService, {
|
|
30
|
-
queues: {
|
|
31
|
-
get(_dxn) {
|
|
32
|
-
throw new Error('Queues not available');
|
|
33
|
-
},
|
|
34
|
-
create() {
|
|
35
|
-
throw new Error('Queues not available');
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
queue: undefined,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
static make = (queues: QueueFactory, queue?: Queue): Context.Tag.Service<QueueService> => {
|
|
42
|
-
return {
|
|
43
|
-
queues,
|
|
44
|
-
queue,
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
static layer = (queues: QueueFactory, queue?: Queue): Layer.Layer<QueueService> =>
|
|
49
|
-
Layer.succeed(QueueService, QueueService.make(queues, queue));
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Gets a queue by its DXN.
|
|
53
|
-
*/
|
|
54
|
-
static getQueue = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(
|
|
55
|
-
dxn: DXN,
|
|
56
|
-
): Effect.Effect<Queue<T>, never, QueueService> => QueueService.pipe(Effect.map(({ queues }) => queues.get<T>(dxn)));
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Creates a new queue.
|
|
60
|
-
*/
|
|
61
|
-
static createQueue = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(options?: {
|
|
62
|
-
subspaceTag?: QueueSubspaceTag;
|
|
63
|
-
}): Effect.Effect<Queue<T>, never, QueueService> =>
|
|
64
|
-
QueueService.pipe(Effect.map(({ queues }) => queues.create<T>(options)));
|
|
65
|
-
|
|
66
|
-
static append = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(
|
|
67
|
-
queue: Queue<T>,
|
|
68
|
-
objects: T[],
|
|
69
|
-
): Effect.Effect<void> => 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,139 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Context, Effect, Layer } from 'effect';
|
|
6
|
-
|
|
7
|
-
import { AgentStatus } from '@dxos/ai';
|
|
8
|
-
import { Obj } from '@dxos/echo';
|
|
9
|
-
import type { Queue } from '@dxos/echo-db';
|
|
10
|
-
import type { ObjectId } from '@dxos/echo-schema';
|
|
11
|
-
import { log } from '@dxos/log';
|
|
12
|
-
import { DataType } from '@dxos/schema';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Provides a way for compute primitives (functions, workflows, tools)
|
|
16
|
-
* to emit an execution trace as a series of structured ECHO objects.
|
|
17
|
-
*/
|
|
18
|
-
export class TracingService extends Context.Tag('@dxos/functions/TracingService')<
|
|
19
|
-
TracingService,
|
|
20
|
-
{
|
|
21
|
-
/**
|
|
22
|
-
* Gets the parent message ID.
|
|
23
|
-
*/
|
|
24
|
-
getTraceContext: () => TracingService.TraceContext;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Write an event to the tracing queue.
|
|
28
|
-
* @param event - The event to write. Must be an a typed object.
|
|
29
|
-
*/
|
|
30
|
-
write: (event: Obj.Any) => void;
|
|
31
|
-
}
|
|
32
|
-
>() {
|
|
33
|
-
static noop: Context.Tag.Service<TracingService> = { write: () => {}, getTraceContext: () => ({}) };
|
|
34
|
-
|
|
35
|
-
static layerNoop = Layer.succeed(TracingService, TracingService.noop);
|
|
36
|
-
|
|
37
|
-
static console: Context.Tag.Service<TracingService> = {
|
|
38
|
-
write: (event) => {
|
|
39
|
-
// eslint-disable-next-line no-console
|
|
40
|
-
console.log(event);
|
|
41
|
-
},
|
|
42
|
-
getTraceContext: () => ({}),
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
static layerConsole = Layer.succeed(TracingService, TracingService.console);
|
|
46
|
-
|
|
47
|
-
static layerLogInfo = () =>
|
|
48
|
-
Layer.succeed(TracingService, {
|
|
49
|
-
write: (event) => {
|
|
50
|
-
if (Obj.instanceOf(AgentStatus, event)) {
|
|
51
|
-
log.info('status', { message: event.message });
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
getTraceContext: () => ({}),
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Creates a TracingService layer that emits events to the parent tracing service.
|
|
59
|
-
*/
|
|
60
|
-
static layerSubframe = (mapContext: (currentContext: TracingService.TraceContext) => TracingService.TraceContext) =>
|
|
61
|
-
Layer.effect(
|
|
62
|
-
TracingService,
|
|
63
|
-
Effect.gen(function* () {
|
|
64
|
-
const tracing = yield* TracingService;
|
|
65
|
-
const context = mapContext(tracing.getTraceContext());
|
|
66
|
-
return {
|
|
67
|
-
write: (event) => tracing.write(event),
|
|
68
|
-
getTraceContext: () => context,
|
|
69
|
-
};
|
|
70
|
-
}),
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
static layerQueue = (queue: Queue) =>
|
|
74
|
-
Layer.effect(
|
|
75
|
-
TracingService,
|
|
76
|
-
Effect.gen(function* () {
|
|
77
|
-
// TODO(dmaretskyi): Batching.
|
|
78
|
-
return {
|
|
79
|
-
write: (event) => queue.append([event]),
|
|
80
|
-
getTraceContext: () => ({
|
|
81
|
-
debugInfo: {
|
|
82
|
-
queue: queue.dxn.toString(),
|
|
83
|
-
},
|
|
84
|
-
}),
|
|
85
|
-
};
|
|
86
|
-
}),
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Emit the current human-readable execution status.
|
|
91
|
-
*/
|
|
92
|
-
static emitStatus: (data: Obj.MakeProps<typeof AgentStatus>) => Effect.Effect<void, never, TracingService> =
|
|
93
|
-
Effect.fnUntraced(function* (data) {
|
|
94
|
-
const tracing = yield* TracingService;
|
|
95
|
-
tracing.write(
|
|
96
|
-
Obj.make(AgentStatus, {
|
|
97
|
-
parentMessage: tracing.getTraceContext().parentMessage,
|
|
98
|
-
toolCallId: tracing.getTraceContext().toolCallId,
|
|
99
|
-
...data,
|
|
100
|
-
}),
|
|
101
|
-
);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
static emitConverationMessage: (
|
|
105
|
-
data: Obj.MakeProps<typeof DataType.Message>,
|
|
106
|
-
) => Effect.Effect<void, never, TracingService> = Effect.fnUntraced(function* (data) {
|
|
107
|
-
const tracing = yield* TracingService;
|
|
108
|
-
tracing.write(
|
|
109
|
-
Obj.make(DataType.Message, {
|
|
110
|
-
parentMessage: tracing.getTraceContext().parentMessage,
|
|
111
|
-
...data,
|
|
112
|
-
properties: {
|
|
113
|
-
[MESSAGE_PROPERTY_TOOL_CALL_ID]: tracing.getTraceContext().toolCallId,
|
|
114
|
-
...data.properties,
|
|
115
|
-
},
|
|
116
|
-
}),
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export namespace TracingService {
|
|
122
|
-
export interface TraceContext {
|
|
123
|
-
/**
|
|
124
|
-
* If this thread sprung from a tool call, this is the ID of the message containing the tool call.
|
|
125
|
-
*/
|
|
126
|
-
parentMessage?: ObjectId;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* If the current thread is a byproduct of a tool call, this is the ID of the tool call.
|
|
130
|
-
*/
|
|
131
|
-
toolCallId?: string;
|
|
132
|
-
|
|
133
|
-
debugInfo?: unknown;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
5
|
/**
|
|
138
|
-
* Goes into {@link
|
|
6
|
+
* Goes into {@link Message['properties']}
|
|
139
7
|
*/
|
|
140
8
|
export const MESSAGE_PROPERTY_TOOL_CALL_ID = 'toolCallId' as const;
|
package/src/types/url.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Obj } from '@dxos/echo';
|
|
6
|
+
|
|
7
|
+
// TODO: use URL scheme for source?
|
|
8
|
+
export const FUNCTIONS_META_KEY = 'org.dxos.service.function';
|
|
9
|
+
|
|
10
|
+
export const FUNCTIONS_PRESET_META_KEY = 'org.dxos.service.function-preset';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* NOTE: functionId is backend ID, not ECHO object id.
|
|
14
|
+
*/
|
|
15
|
+
export const getUserFunctionIdInMetadata = (meta: Obj.ReadonlyMeta) => {
|
|
16
|
+
return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* NOTE: functionId is backend ID, not ECHO object id.
|
|
21
|
+
* Must be called inside Obj.update() since it mutates the meta.
|
|
22
|
+
*/
|
|
23
|
+
export const setUserFunctionIdInMetadata = (meta: Obj.Meta, functionId: string) => {
|
|
24
|
+
const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
|
|
25
|
+
if (key) {
|
|
26
|
+
if (key.id !== functionId) {
|
|
27
|
+
throw new Error('Metadata mismatch');
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionId });
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import "../chunk-J5LGTIGS.mjs";
|
|
2
|
-
|
|
3
|
-
// src/bundler/bundler.ts
|
|
4
|
-
import { FetchHttpClient, HttpClient } from "@effect/platform";
|
|
5
|
-
import { Duration, Effect, Schedule, pipe } from "effect";
|
|
6
|
-
import { build, initialize } from "esbuild-wasm";
|
|
7
|
-
import { subtleCrypto } from "@dxos/crypto";
|
|
8
|
-
import { runAndForwardErrors } from "@dxos/effect";
|
|
9
|
-
import { invariant } from "@dxos/invariant";
|
|
10
|
-
import { log } from "@dxos/log";
|
|
11
|
-
function _define_property(obj, key, value) {
|
|
12
|
-
if (key in obj) {
|
|
13
|
-
Object.defineProperty(obj, key, {
|
|
14
|
-
value,
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true
|
|
18
|
-
});
|
|
19
|
-
} else {
|
|
20
|
-
obj[key] = value;
|
|
21
|
-
}
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/functions/src/bundler/bundler.ts";
|
|
25
|
-
var initialized;
|
|
26
|
-
var initializeBundler = async (options) => {
|
|
27
|
-
await (initialized ?? (initialized = initialize({
|
|
28
|
-
wasmURL: options.wasmUrl
|
|
29
|
-
})));
|
|
30
|
-
};
|
|
31
|
-
var Bundler = class {
|
|
32
|
-
async bundle({ source }) {
|
|
33
|
-
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
34
|
-
const sourceHash = Buffer.from(await subtleCrypto.digest("SHA-256", Buffer.from(source)));
|
|
35
|
-
if (this._options.platform === "browser") {
|
|
36
|
-
invariant(initialized, "Compiler not initialized.", {
|
|
37
|
-
F: __dxlog_file,
|
|
38
|
-
L: 66,
|
|
39
|
-
S: this,
|
|
40
|
-
A: [
|
|
41
|
-
"initialized",
|
|
42
|
-
"'Compiler not initialized.'"
|
|
43
|
-
]
|
|
44
|
-
});
|
|
45
|
-
await initialized;
|
|
46
|
-
}
|
|
47
|
-
const imports = source ? analyzeSourceFileImports(source) : [];
|
|
48
|
-
try {
|
|
49
|
-
const result = await build({
|
|
50
|
-
platform: options.platform,
|
|
51
|
-
conditions: [
|
|
52
|
-
"workerd",
|
|
53
|
-
"browser"
|
|
54
|
-
],
|
|
55
|
-
metafile: true,
|
|
56
|
-
write: false,
|
|
57
|
-
entryPoints: {
|
|
58
|
-
// Gets mapped to `userFunc.js` by esbuild.
|
|
59
|
-
userFunc: "memory:main.tsx"
|
|
60
|
-
},
|
|
61
|
-
bundle: true,
|
|
62
|
-
format: "esm",
|
|
63
|
-
plugins: [
|
|
64
|
-
{
|
|
65
|
-
name: "memory",
|
|
66
|
-
setup: (build2) => {
|
|
67
|
-
build2.onResolve({
|
|
68
|
-
filter: /^\.\/runtime\.js$/
|
|
69
|
-
}, ({ path }) => {
|
|
70
|
-
return {
|
|
71
|
-
path,
|
|
72
|
-
external: true
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
build2.onResolve({
|
|
76
|
-
filter: /^dxos:functions$/
|
|
77
|
-
}, ({ path }) => {
|
|
78
|
-
return {
|
|
79
|
-
path: "./runtime.js",
|
|
80
|
-
external: true
|
|
81
|
-
};
|
|
82
|
-
});
|
|
83
|
-
build2.onResolve({
|
|
84
|
-
filter: /^memory:/
|
|
85
|
-
}, ({ path }) => {
|
|
86
|
-
return {
|
|
87
|
-
path: path.split(":")[1],
|
|
88
|
-
namespace: "memory"
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
build2.onLoad({
|
|
92
|
-
filter: /.*/,
|
|
93
|
-
namespace: "memory"
|
|
94
|
-
}, ({ path }) => {
|
|
95
|
-
if (path === "main.tsx") {
|
|
96
|
-
return {
|
|
97
|
-
contents: source,
|
|
98
|
-
loader: "tsx"
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
for (const module of providedModules) {
|
|
103
|
-
build2.onResolve({
|
|
104
|
-
filter: new RegExp(`^${module}$`)
|
|
105
|
-
}, ({ path }) => {
|
|
106
|
-
return {
|
|
107
|
-
path,
|
|
108
|
-
namespace: "injected-module"
|
|
109
|
-
};
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
build2.onLoad({
|
|
113
|
-
filter: /.*/,
|
|
114
|
-
namespace: "injected-module"
|
|
115
|
-
}, ({ path }) => {
|
|
116
|
-
const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];
|
|
117
|
-
return {
|
|
118
|
-
contents: `
|
|
119
|
-
const { ${namedImports.join(",")} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];
|
|
120
|
-
export { ${namedImports.join(",")} };
|
|
121
|
-
export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;
|
|
122
|
-
`,
|
|
123
|
-
loader: "tsx"
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
httpPlugin
|
|
129
|
-
]
|
|
130
|
-
});
|
|
131
|
-
log("compile complete", result.metafile, {
|
|
132
|
-
F: __dxlog_file,
|
|
133
|
-
L: 133,
|
|
134
|
-
S: this,
|
|
135
|
-
C: (f, a) => f(...a)
|
|
136
|
-
});
|
|
137
|
-
const entryPoint = "userFunc.js";
|
|
138
|
-
return {
|
|
139
|
-
timestamp: Date.now(),
|
|
140
|
-
sourceHash,
|
|
141
|
-
imports: this.analyzeImports(result),
|
|
142
|
-
entryPoint,
|
|
143
|
-
asset: result.outputFiles[0].contents,
|
|
144
|
-
bundle: result.outputFiles[0].text
|
|
145
|
-
};
|
|
146
|
-
} catch (err) {
|
|
147
|
-
return {
|
|
148
|
-
timestamp: Date.now(),
|
|
149
|
-
sourceHash,
|
|
150
|
-
error: err
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
|
|
155
|
-
analyzeImports(result) {
|
|
156
|
-
invariant(result.outputFiles, void 0, {
|
|
157
|
-
F: __dxlog_file,
|
|
158
|
-
L: 151,
|
|
159
|
-
S: this,
|
|
160
|
-
A: [
|
|
161
|
-
"result.outputFiles",
|
|
162
|
-
""
|
|
163
|
-
]
|
|
164
|
-
});
|
|
165
|
-
const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
|
|
166
|
-
return Object.values(result.metafile.outputs)[0].imports.map((entry) => {
|
|
167
|
-
const namedImports = [];
|
|
168
|
-
const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
|
|
169
|
-
if (parsedImport?.[2]) {
|
|
170
|
-
NAMED_IMPORTS_REGEX.lastIndex = 0;
|
|
171
|
-
const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
|
|
172
|
-
if (namedImportsMatch) {
|
|
173
|
-
namedImportsMatch[1].split(",").forEach((importName) => {
|
|
174
|
-
namedImports.push(importName.trim());
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return {
|
|
179
|
-
moduleUrl: entry.path,
|
|
180
|
-
defaultImport: !!parsedImport?.[1],
|
|
181
|
-
namedImports
|
|
182
|
-
};
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
analyzeSourceFileImports(code) {
|
|
186
|
-
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
187
|
-
return parsedImports.map((capture) => {
|
|
188
|
-
return {
|
|
189
|
-
defaultImportName: capture[1],
|
|
190
|
-
namedImports: capture[2]?.split(",").map((importName) => importName.trim()),
|
|
191
|
-
wildcardImportName: capture[3],
|
|
192
|
-
moduleIdentifier: capture[4],
|
|
193
|
-
quotes: capture[5]
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
constructor(_options) {
|
|
198
|
-
_define_property(this, "_options", void 0);
|
|
199
|
-
this._options = _options;
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
var IMPORT_REGEX = /import(?:(?:(?:[ \n\t]+([^ *\n\t{},]+)[ \n\t]*(?:,|[ \n\t]+))?([ \n\t]*{(?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+})?[ \n\t]*)|[ \n\t]*\*[ \n\t]*as[ \n\t]+([^ \n\t{}]+)[ \n\t]+)from[ \n\t]*(?:['"])([^'"\n]+)(['"])/gm;
|
|
203
|
-
var NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
|
|
204
|
-
var allMatches = (regex, str) => {
|
|
205
|
-
let match;
|
|
206
|
-
const matches = [];
|
|
207
|
-
regex.lastIndex = 0;
|
|
208
|
-
while (match = regex.exec(str)) {
|
|
209
|
-
matches.push(match);
|
|
210
|
-
}
|
|
211
|
-
return matches;
|
|
212
|
-
};
|
|
213
|
-
var analyzeSourceFileImports = (code) => {
|
|
214
|
-
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
215
|
-
return parsedImports.map((capture) => {
|
|
216
|
-
return {
|
|
217
|
-
defaultImportName: capture[1],
|
|
218
|
-
namedImports: capture[2]?.trim().slice(1, -1).split(",").map((importName) => importName.trim()),
|
|
219
|
-
wildcardImportName: capture[3],
|
|
220
|
-
moduleIdentifier: capture[4],
|
|
221
|
-
quotes: capture[5]
|
|
222
|
-
};
|
|
223
|
-
});
|
|
224
|
-
};
|
|
225
|
-
var MAX_RETRIES = 5;
|
|
226
|
-
var INITIAL_DELAY = 1e3;
|
|
227
|
-
var httpPlugin = {
|
|
228
|
-
name: "http",
|
|
229
|
-
setup: (build2) => {
|
|
230
|
-
build2.onResolve({
|
|
231
|
-
filter: /^https?:\/\//
|
|
232
|
-
}, (args) => ({
|
|
233
|
-
path: args.path,
|
|
234
|
-
namespace: "http-url"
|
|
235
|
-
}));
|
|
236
|
-
build2.onResolve({
|
|
237
|
-
filter: /.*/,
|
|
238
|
-
namespace: "http-url"
|
|
239
|
-
}, (args) => ({
|
|
240
|
-
path: new URL(args.path, args.importer).toString(),
|
|
241
|
-
namespace: "http-url"
|
|
242
|
-
}));
|
|
243
|
-
build2.onLoad({
|
|
244
|
-
filter: /.*/,
|
|
245
|
-
namespace: "http-url"
|
|
246
|
-
}, async (args) => {
|
|
247
|
-
return Effect.gen(function* () {
|
|
248
|
-
const response = yield* HttpClient.get(args.path);
|
|
249
|
-
if (response.status !== 200) {
|
|
250
|
-
throw new Error(`failed to fetch: ${response.status}`);
|
|
251
|
-
}
|
|
252
|
-
const text = yield* response.text;
|
|
253
|
-
return {
|
|
254
|
-
contents: text,
|
|
255
|
-
loader: "jsx"
|
|
256
|
-
};
|
|
257
|
-
}).pipe(Effect.retry(pipe(Schedule.exponential(Duration.millis(INITIAL_DELAY)), Schedule.jittered, Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)))), Effect.provide(FetchHttpClient.layer), runAndForwardErrors);
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
export {
|
|
262
|
-
Bundler,
|
|
263
|
-
initializeBundler
|
|
264
|
-
};
|
|
265
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/bundler/bundler.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { FetchHttpClient, HttpClient } from '@effect/platform';\nimport { Duration, Effect, Schedule, pipe } from 'effect';\nimport { type BuildOptions, type BuildResult, type Loader, type Plugin, build, initialize } from 'esbuild-wasm';\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { runAndForwardErrors } from '@dxos/effect';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nexport type Import = {\n moduleUrl: string;\n defaultImport: boolean;\n namedImports: string[];\n};\n\nexport type BundleOptions = {\n /**\n * Source code to bundle.\n */\n source: string;\n};\n\nexport type BundleResult =\n | {\n timestamp: number;\n sourceHash: Buffer;\n error: unknown;\n }\n | {\n timestamp: number;\n sourceHash: Buffer;\n imports: Import[];\n entryPoint: string;\n asset: Uint8Array;\n bundle: string;\n };\n\nexport type BundlerOptions = {\n platform: BuildOptions['platform'];\n sandboxedModules: string[];\n remoteModules: Record<string, string>;\n};\n\nlet initialized: Promise<void>;\nexport const initializeBundler = async (options: { wasmUrl: string }) => {\n await (initialized ??= initialize({\n wasmURL: options.wasmUrl,\n }));\n};\n\n/**\n * ESBuild bundler.\n */\nexport class Bundler {\n constructor(private readonly _options: BundlerOptions) {}\n\n async bundle({ source }: BundleOptions): Promise<BundleResult> {\n const { sandboxedModules: providedModules, ...options } = this._options;\n const sourceHash = Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source)));\n\n if (this._options.platform === 'browser') {\n invariant(initialized, 'Compiler not initialized.');\n await initialized;\n }\n\n const imports = source ? analyzeSourceFileImports(source) : [];\n\n // https://esbuild.github.io/api/#build\n try {\n const result = await build({\n platform: options.platform,\n conditions: ['workerd', 'browser'],\n metafile: true,\n write: false,\n entryPoints: {\n // Gets mapped to `userFunc.js` by esbuild.\n userFunc: 'memory:main.tsx',\n },\n bundle: true,\n format: 'esm',\n plugins: [\n {\n name: 'memory',\n setup: (build) => {\n build.onResolve({ filter: /^\\.\\/runtime\\.js$/ }, ({ path }) => {\n return { path, external: true };\n });\n\n build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {\n return { path: './runtime.js', external: true };\n });\n\n build.onResolve({ filter: /^memory:/ }, ({ path }) => {\n return { path: path.split(':')[1], namespace: 'memory' };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {\n if (path === 'main.tsx') {\n return {\n contents: source,\n loader: 'tsx',\n };\n }\n });\n\n for (const module of providedModules) {\n build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {\n return { path, namespace: 'injected-module' };\n });\n }\n\n build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {\n const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];\n return {\n contents: `\n const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];\n export { ${namedImports.join(',')} };\n export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;\n `,\n loader: 'tsx',\n };\n });\n },\n },\n httpPlugin,\n ],\n });\n\n log('compile complete', result.metafile);\n\n const entryPoint = 'userFunc.js';\n return {\n timestamp: Date.now(),\n sourceHash,\n imports: this.analyzeImports(result),\n entryPoint,\n asset: result.outputFiles![0].contents,\n bundle: result.outputFiles![0].text,\n };\n } catch (err) {\n return { timestamp: Date.now(), sourceHash, error: err };\n }\n }\n\n // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.\n analyzeImports(result: BuildResult): Import[] {\n invariant(result.outputFiles);\n\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);\n return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {\n const namedImports: string[] = [];\n const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);\n if (parsedImport?.[2]) {\n NAMED_IMPORTS_REGEX.lastIndex = 0;\n const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);\n if (namedImportsMatch) {\n namedImportsMatch[1].split(',').forEach((importName) => {\n namedImports.push(importName.trim());\n });\n }\n }\n\n return {\n moduleUrl: entry.path,\n defaultImport: !!parsedImport?.[1],\n namedImports,\n };\n });\n }\n\n analyzeSourceFileImports(code: string): {\n defaultImportName: string;\n namedImports: string[];\n wildcardImportName: string;\n moduleIdentifier: string;\n quotes: string;\n }[] {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]?.split(',').map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n }\n}\n\n// https://regex101.com/r/FEN5ks/1\n// https://stackoverflow.com/a/73265022\n// $1 = default import name (can be non-existent)\n// $2 = destructured exports (can be non-existent)\n// $3 = wildcard import name (can be non-existent)\n// $4 = module identifier\n// $5 = quotes used (either ' or \")\nconst IMPORT_REGEX =\n /import(?:(?:(?:[ \\n\\t]+([^ *\\n\\t{},]+)[ \\n\\t]*(?:,|[ \\n\\t]+))?([ \\n\\t]*{(?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+})?[ \\n\\t]*)|[ \\n\\t]*\\*[ \\n\\t]*as[ \\n\\t]+([^ \\n\\t{}]+)[ \\n\\t]+)from[ \\n\\t]*(?:['\"])([^'\"\\n]+)(['\"])/gm;\n\nconst NAMED_IMPORTS_REGEX = /[ \\n\\t]*{((?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+)}[ \\n\\t]*/gm;\n\nconst allMatches = (regex: RegExp, str: string) => {\n let match;\n const matches = [];\n regex.lastIndex = 0;\n while ((match = regex.exec(str))) {\n matches.push(match);\n }\n\n return matches;\n};\n\ntype ParsedImport = {\n defaultImportName?: string;\n namedImports: string[];\n wildcardImportName?: string;\n moduleIdentifier: string;\n quotes: string;\n};\n\nconst analyzeSourceFileImports = (code: string): ParsedImport[] => {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]\n ?.trim()\n .slice(1, -1)\n .split(',')\n .map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n};\n\nconst MAX_RETRIES = 5;\nconst INITIAL_DELAY = 1_000;\n\nconst httpPlugin: Plugin = {\n name: 'http',\n setup: (build) => {\n // Intercept import paths starting with \"http:\" and \"https:\" so esbuild doesn't attempt to map them to a file system location.\n // Tag them with the \"http-url\" namespace to associate them with this plugin.\n build.onResolve({ filter: /^https?:\\/\\// }, (args) => ({\n path: args.path,\n namespace: 'http-url',\n }));\n\n // We also want to intercept all import paths inside downloaded files and resolve them against the original URL.\n // All of these files will be in the \"http-url\" namespace.\n // Make sure to keep the newly resolved URL in the \"http-url\" namespace so imports inside it will also be resolved as URLs recursively.\n build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({\n path: new URL(args.path, args.importer).toString(),\n namespace: 'http-url',\n }));\n\n // When a URL is loaded, we want to actually download the content from the internet.\n // This has just enough logic to be able to handle the example import from unpkg.com but in reality this would probably need to be more complex.\n build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {\n return Effect.gen(function* () {\n const response = yield* HttpClient.get(args.path);\n if (response.status !== 200) {\n throw new Error(`failed to fetch: ${response.status}`);\n }\n\n const text = yield* response.text;\n return { contents: text, loader: 'jsx' as Loader };\n }).pipe(\n Effect.retry(\n pipe(\n Schedule.exponential(Duration.millis(INITIAL_DELAY)),\n Schedule.jittered,\n Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)),\n ),\n ),\n Effect.provide(FetchHttpClient.layer),\n runAndForwardErrors,\n );\n });\n },\n};\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,iBAAiBC,kBAAkB;AAC5C,SAASC,UAAUC,QAAQC,UAAUC,YAAY;AACjD,SAAwEC,OAAO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SAASE,WAAW,KAAK;AAC3B,gBAAM,IAAIC,MAAM,oBAAoBH,SAASE,MAAM,EAAE;QACvD;AAEA,cAAMxC,OAAO,OAAOsC,SAAStC;AAC7B,eAAO;UAAEnB,UAAUmB;UAAMlB,QAAQ;QAAgB;MACnD,CAAA,EAAG3C,KACDF,OAAOyG,MACLvG,KACED,SAASyG,YAAY3G,SAAS4G,OAAOZ,aAAAA,CAAAA,GACrC9F,SAAS2G,UACT3G,SAAS4G,UAAU5G,SAAS6G,OAAOhB,cAAc,CAAA,CAAA,CAAA,CAAA,GAGrD9F,OAAO+G,QAAQlH,gBAAgBmH,KAAK,GACpC1G,mBAAAA;IAEJ,CAAA;EACF;AACF;",
|
|
6
|
-
"names": ["FetchHttpClient", "HttpClient", "Duration", "Effect", "Schedule", "pipe", "build", "initialize", "subtleCrypto", "runAndForwardErrors", "invariant", "log", "initialized", "initializeBundler", "options", "wasmURL", "wasmUrl", "Bundler", "bundle", "source", "sandboxedModules", "providedModules", "_options", "sourceHash", "Buffer", "from", "digest", "platform", "imports", "analyzeSourceFileImports", "result", "conditions", "metafile", "write", "entryPoints", "userFunc", "format", "plugins", "name", "setup", "onResolve", "filter", "path", "external", "split", "namespace", "onLoad", "contents", "loader", "module", "RegExp", "namedImports", "find", "entry", "moduleIdentifier", "join", "JSON", "stringify", "httpPlugin", "entryPoint", "timestamp", "Date", "now", "analyzeImports", "asset", "outputFiles", "text", "err", "error", "parsedImports", "allMatches", "IMPORT_REGEX", "Object", "values", "outputs", "map", "parsedImport", "capture", "NAMED_IMPORTS_REGEX", "lastIndex", "namedImportsMatch", "exec", "forEach", "importName", "push", "trim", "moduleUrl", "defaultImport", "code", "defaultImportName", "wildcardImportName", "quotes", "regex", "str", "match", "matches", "slice", "MAX_RETRIES", "INITIAL_DELAY", "args", "URL", "importer", "toString", "gen", "response", "get", "status", "Error", "retry", "exponential", "millis", "jittered", "intersect", "recurs", "provide", "layer"]
|
|
7
|
-
}
|