@dxos/functions 0.8.3 → 0.8.4-main.3a94e84
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/browser/bundler/index.mjs +21 -10
- package/dist/lib/browser/bundler/index.mjs.map +3 -3
- package/dist/lib/browser/{chunk-WEFZUEL2.mjs → chunk-3NGCSUEW.mjs} +106 -78
- package/dist/lib/browser/chunk-3NGCSUEW.mjs.map +7 -0
- package/dist/lib/browser/edge/index.mjs +2 -2
- package/dist/lib/browser/edge/index.mjs.map +1 -1
- package/dist/lib/browser/index.mjs +40 -23
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +71 -8
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/bundler/index.mjs +21 -10
- package/dist/lib/node-esm/bundler/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-LIYPMWNQ.mjs → chunk-FJ2MU7TL.mjs} +106 -78
- package/dist/lib/node-esm/chunk-FJ2MU7TL.mjs.map +7 -0
- package/dist/lib/node-esm/edge/index.mjs +2 -2
- package/dist/lib/node-esm/edge/index.mjs.map +1 -1
- package/dist/lib/node-esm/index.mjs +40 -23
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +71 -8
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/bundler/bundler.d.ts +1 -2
- package/dist/types/src/bundler/bundler.d.ts.map +1 -1
- package/dist/types/src/edge/functions.d.ts +1 -1
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +68 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/executor/executor.d.ts.map +1 -1
- package/dist/types/src/handler.d.ts +10 -12
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/schema.d.ts +4 -4
- package/dist/types/src/services/credentials.d.ts +3 -2
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/database.d.ts +20 -2
- package/dist/types/src/services/database.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 +15 -3
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/service-container.d.ts +27 -15
- package/dist/types/src/services/service-container.d.ts.map +1 -1
- package/dist/types/src/services/service-registry.d.ts +29 -0
- package/dist/types/src/services/service-registry.d.ts.map +1 -0
- package/dist/types/src/services/service-registry.test.d.ts +2 -0
- package/dist/types/src/services/service-registry.test.d.ts.map +1 -0
- package/dist/types/src/services/tracing.d.ts +11 -1
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/layer.d.ts +10 -0
- package/dist/types/src/testing/layer.d.ts.map +1 -0
- package/dist/types/src/testing/services.d.ts +66 -9
- package/dist/types/src/testing/services.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +9 -9
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +8 -8
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -26
- package/src/bundler/bundler.test.ts +1 -1
- package/src/bundler/bundler.ts +26 -4
- package/src/edge/functions.ts +1 -1
- package/src/errors.ts +13 -0
- package/src/executor/executor.ts +15 -8
- package/src/handler.ts +28 -21
- package/src/index.ts +1 -0
- package/src/services/credentials.ts +9 -3
- package/src/services/database.ts +44 -2
- package/src/services/index.ts +0 -1
- package/src/services/queues.ts +24 -6
- package/src/services/service-container.ts +39 -35
- package/src/services/service-registry.test.ts +42 -0
- package/src/services/service-registry.ts +56 -0
- package/src/services/tracing.ts +16 -1
- package/src/testing/index.ts +1 -0
- package/src/testing/layer.ts +31 -0
- package/src/testing/services.ts +150 -14
- package/src/translations.ts +4 -4
- package/dist/lib/browser/chunk-WEFZUEL2.mjs.map +0 -7
- package/dist/lib/node/bundler/index.cjs +0 -260
- package/dist/lib/node/bundler/index.cjs.map +0 -7
- package/dist/lib/node/chunk-IJAE7FZK.cjs +0 -320
- package/dist/lib/node/chunk-IJAE7FZK.cjs.map +0 -7
- package/dist/lib/node/edge/index.cjs +0 -94
- package/dist/lib/node/edge/index.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -522
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -43
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-LIYPMWNQ.mjs.map +0 -7
- package/dist/types/src/services/ai.d.ts +0 -12
- package/dist/types/src/services/ai.d.ts.map +0 -1
- package/src/services/ai.ts +0 -32
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Context, Effect, flow, type Option } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { ServiceNotAvailableError } from '../errors';
|
|
8
|
+
|
|
9
|
+
export namespace ServiceRegistry {
|
|
10
|
+
export interface Service {
|
|
11
|
+
resolve: <T extends Context.Tag<any, any>>(tag: T) => Option.Option<Context.Tag.Service<T>>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class ServiceRegistry extends Context.Tag('ServiceRegistry')<ServiceRegistry, ServiceRegistry.Service>() {
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the service from the registry.
|
|
18
|
+
* @param tag Service tag to resolve.
|
|
19
|
+
* @throws {@link ServiceNotAvailableError} if the service is not found.
|
|
20
|
+
* @returns Effect that resolve to the service.
|
|
21
|
+
*/
|
|
22
|
+
static resolve: <T extends Context.Tag<any, any>>(
|
|
23
|
+
tag: T,
|
|
24
|
+
) => Effect.Effect<T, ServiceNotAvailableError, ServiceRegistry> = (tag) =>
|
|
25
|
+
ServiceRegistry.pipe(
|
|
26
|
+
Effect.flatMap((_) => _.resolve(tag)),
|
|
27
|
+
Effect.mapError(() => new ServiceNotAvailableError(tag.key)),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
static provide: {
|
|
31
|
+
<Tags extends [Context.Tag<any, any>, ...Context.Tag<any, any>[]]>(
|
|
32
|
+
...tags: Tags
|
|
33
|
+
): <A, E, R>(
|
|
34
|
+
effect: Effect.Effect<A, E, R>,
|
|
35
|
+
) => Effect.Effect<
|
|
36
|
+
A,
|
|
37
|
+
E | ServiceNotAvailableError,
|
|
38
|
+
Exclude<R, { [K in keyof Tags]: Context.Tag.Identifier<Tags[K]> }[number]> | ServiceRegistry
|
|
39
|
+
>;
|
|
40
|
+
} = (...tags) => (flow as any)(...tags.map((tag) => Effect.provideServiceEffect(tag, ServiceRegistry.resolve(tag))));
|
|
41
|
+
|
|
42
|
+
static provideOrDie: {
|
|
43
|
+
<Tags extends [Context.Tag<any, any>, ...Context.Tag<any, any>[]]>(
|
|
44
|
+
...tags: Tags
|
|
45
|
+
): <A, E, R>(
|
|
46
|
+
effect: Effect.Effect<A, E, R>,
|
|
47
|
+
) => Effect.Effect<
|
|
48
|
+
A,
|
|
49
|
+
E,
|
|
50
|
+
Exclude<R, { [K in keyof Tags]: Context.Tag.Identifier<Tags[K]> }[number]> | ServiceRegistry
|
|
51
|
+
>;
|
|
52
|
+
} = (...tags) =>
|
|
53
|
+
(flow as any)(
|
|
54
|
+
...tags.map((tag) => Effect.provideServiceEffect(tag, ServiceRegistry.resolve(tag).pipe(Effect.orDie))),
|
|
55
|
+
);
|
|
56
|
+
}
|
package/src/services/tracing.ts
CHANGED
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Context } from 'effect';
|
|
5
|
+
import { Context, Effect } from 'effect';
|
|
6
6
|
|
|
7
|
+
import { AgentStatus } from '@dxos/ai';
|
|
8
|
+
import { Obj } from '@dxos/echo';
|
|
7
9
|
import type { AnyEchoObject } from '@dxos/echo-schema';
|
|
8
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Provides a way for compute primitives (functions, workflows, tools)
|
|
13
|
+
* to emit an execution trace as a series of structured ECHO objects.
|
|
14
|
+
*/
|
|
9
15
|
export class TracingService extends Context.Tag('TracingService')<
|
|
10
16
|
TracingService,
|
|
11
17
|
{
|
|
@@ -24,4 +30,13 @@ export class TracingService extends Context.Tag('TracingService')<
|
|
|
24
30
|
console.log(event);
|
|
25
31
|
},
|
|
26
32
|
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Emit the current human-readable execution status.
|
|
36
|
+
*/
|
|
37
|
+
static emitStatus: (data: Obj.MakeProps<typeof AgentStatus>) => Effect.Effect<unknown, never, void> =
|
|
38
|
+
Effect.fnUntraced(function* (data) {
|
|
39
|
+
const tracing = yield* TracingService;
|
|
40
|
+
tracing.write(Obj.make(AgentStatus, data));
|
|
41
|
+
});
|
|
27
42
|
}
|
package/src/testing/index.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Context, Effect, Layer } from 'effect';
|
|
6
|
+
import type { Schema } from 'effect';
|
|
7
|
+
|
|
8
|
+
import { EchoTestBuilder } from '@dxos/echo-db/testing';
|
|
9
|
+
import type { EchoHostIndexingConfig } from '@dxos/echo-pipeline';
|
|
10
|
+
import { accuireReleaseResource } from '@dxos/effect';
|
|
11
|
+
|
|
12
|
+
import { DatabaseService, QueueService } from '../services';
|
|
13
|
+
|
|
14
|
+
const testBuilder = accuireReleaseResource(() => new EchoTestBuilder());
|
|
15
|
+
|
|
16
|
+
export type TestDatabaseOptions = {
|
|
17
|
+
indexing?: Partial<EchoHostIndexingConfig>;
|
|
18
|
+
types?: Schema.Schema.AnyNoContext[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const TestDatabaseLayer = ({ indexing, types }: TestDatabaseOptions = {}) =>
|
|
22
|
+
Layer.scopedContext(
|
|
23
|
+
Effect.gen(function* () {
|
|
24
|
+
const builder = yield* testBuilder;
|
|
25
|
+
const { db, queues } = yield* Effect.promise(() => builder.createDatabase({ indexing, types }));
|
|
26
|
+
return Context.mergeAll(
|
|
27
|
+
Context.make(DatabaseService, DatabaseService.make(db)),
|
|
28
|
+
Context.make(QueueService, QueueService.make(queues, undefined)),
|
|
29
|
+
);
|
|
30
|
+
}),
|
|
31
|
+
);
|
package/src/testing/services.ts
CHANGED
|
@@ -4,29 +4,165 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Context } from 'effect';
|
|
6
6
|
|
|
7
|
-
import type
|
|
8
|
-
import
|
|
7
|
+
import { AiService, type AiServiceClient, type AiServiceEdgeClientOptions, EdgeAiServiceClient } from '@dxos/ai';
|
|
8
|
+
import { AI_SERVICE_ENDPOINT, createTestAiServiceClient } from '@dxos/ai/testing';
|
|
9
|
+
import type { Space } from '@dxos/client/echo';
|
|
10
|
+
import type { EchoDatabase, QueueFactory } from '@dxos/echo-db';
|
|
11
|
+
import { assertArgument } from '@dxos/invariant';
|
|
9
12
|
|
|
10
13
|
import { consoleLogger, noopLogger } from './logger';
|
|
11
|
-
import {
|
|
12
|
-
|
|
14
|
+
import {
|
|
15
|
+
ConfiguredCredentialsService,
|
|
16
|
+
type CredentialsService,
|
|
17
|
+
DatabaseService,
|
|
18
|
+
type EventLogger,
|
|
19
|
+
QueueService,
|
|
20
|
+
ServiceContainer,
|
|
21
|
+
type ServiceCredential,
|
|
22
|
+
type TracingService,
|
|
23
|
+
} from '../services';
|
|
24
|
+
|
|
25
|
+
// TODO(burdon): Factor out.
|
|
26
|
+
export type OneOf<T> = {
|
|
27
|
+
[K in keyof T]: { [P in K]: T[P] } & { [P in Exclude<keyof T, K>]?: never };
|
|
28
|
+
}[keyof T];
|
|
29
|
+
|
|
30
|
+
export type AiServiceProvider = 'dev' | 'edge' | 'ollama' | 'lmstudio';
|
|
13
31
|
|
|
14
32
|
export type TestServiceOptions = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
33
|
+
/**
|
|
34
|
+
* AI service configuration.
|
|
35
|
+
*/
|
|
36
|
+
ai?: OneOf<{
|
|
37
|
+
/**
|
|
38
|
+
* Custom AI service client.
|
|
39
|
+
*/
|
|
40
|
+
client?: AiServiceClient;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Edge AI service at specified endpoint.
|
|
44
|
+
*/
|
|
45
|
+
endpoint?: AiServiceEdgeClientOptions['endpoint'];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Predefined AI service configuration.
|
|
49
|
+
*/
|
|
50
|
+
// TODO(burdon): 'dev' and 'edge' are redundant with providing an endpoint.
|
|
51
|
+
provider?: AiServiceProvider;
|
|
52
|
+
}>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Credentials service configuration.
|
|
56
|
+
*/
|
|
57
|
+
credentials?: OneOf<{
|
|
58
|
+
/**
|
|
59
|
+
* Predefined credentials list.
|
|
60
|
+
*/
|
|
61
|
+
services?: ServiceCredential[];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Custom credentials service.
|
|
65
|
+
*/
|
|
66
|
+
service?: Context.Tag.Service<CredentialsService>;
|
|
67
|
+
}>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Database configuration.
|
|
71
|
+
*/
|
|
72
|
+
db?: EchoDatabase;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Gets database and queue services from the space.
|
|
76
|
+
* Exclusive with: `db`, `queues`
|
|
77
|
+
*/
|
|
78
|
+
space?: Space;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Logging configuration.
|
|
82
|
+
*/
|
|
83
|
+
logging?: {
|
|
84
|
+
enabled?: boolean;
|
|
85
|
+
logger?: Context.Tag.Service<EventLogger>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Queue service configuration.
|
|
90
|
+
*/
|
|
91
|
+
queues?: QueueFactory;
|
|
92
|
+
|
|
93
|
+
tracing?: {
|
|
94
|
+
service?: Context.Tag.Service<TracingService>;
|
|
95
|
+
};
|
|
19
96
|
};
|
|
20
97
|
|
|
21
98
|
export const createTestServices = ({
|
|
22
99
|
ai,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
100
|
+
credentials,
|
|
101
|
+
db,
|
|
102
|
+
logging,
|
|
103
|
+
queues,
|
|
104
|
+
space,
|
|
105
|
+
tracing,
|
|
26
106
|
}: TestServiceOptions = {}): ServiceContainer => {
|
|
107
|
+
assertArgument(!(!!space && (!!db || !!queues)), 'space can be provided only if db and queues are not');
|
|
108
|
+
|
|
27
109
|
return new ServiceContainer().setServices({
|
|
28
|
-
ai:
|
|
29
|
-
|
|
30
|
-
|
|
110
|
+
ai: createAiService(ai),
|
|
111
|
+
credentials: createCredentialsService(credentials),
|
|
112
|
+
database: space || db ? DatabaseService.make(space?.db || db!) : undefined,
|
|
113
|
+
eventLogger: (logging?.logger ?? logging?.enabled) ? consoleLogger : noopLogger,
|
|
114
|
+
queues: space || queues ? QueueService.make(space?.queues || queues!, undefined) : undefined,
|
|
115
|
+
tracing: tracing?.service,
|
|
31
116
|
});
|
|
32
117
|
};
|
|
118
|
+
|
|
119
|
+
// TODO(burdon): Enable model configuration.
|
|
120
|
+
const createAiService = (ai: TestServiceOptions['ai']): Context.Tag.Service<AiService> | undefined => {
|
|
121
|
+
if (ai?.client != null) {
|
|
122
|
+
return AiService.make(ai.client);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (ai?.endpoint != null) {
|
|
126
|
+
return AiService.make(new EdgeAiServiceClient({ endpoint: ai.endpoint }));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
switch (ai?.provider) {
|
|
130
|
+
case 'dev':
|
|
131
|
+
return AiService.make(
|
|
132
|
+
new EdgeAiServiceClient({
|
|
133
|
+
endpoint: AI_SERVICE_ENDPOINT.LOCAL,
|
|
134
|
+
defaultGenerationOptions: {
|
|
135
|
+
model: '@anthropic/claude-3-5-sonnet-20241022',
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
case 'edge':
|
|
141
|
+
return AiService.make(
|
|
142
|
+
new EdgeAiServiceClient({
|
|
143
|
+
endpoint: AI_SERVICE_ENDPOINT.REMOTE,
|
|
144
|
+
defaultGenerationOptions: {
|
|
145
|
+
model: '@anthropic/claude-3-5-sonnet-20241022',
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
case 'ollama':
|
|
151
|
+
return AiService.make(createTestAiServiceClient());
|
|
152
|
+
|
|
153
|
+
case 'lmstudio':
|
|
154
|
+
throw new Error('LMStudio is not supported');
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const createCredentialsService = (
|
|
159
|
+
credentials: TestServiceOptions['credentials'] | undefined,
|
|
160
|
+
): Context.Tag.Service<CredentialsService> | undefined => {
|
|
161
|
+
if (credentials?.services) {
|
|
162
|
+
return new ConfiguredCredentialsService(credentials.services);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (credentials?.service) {
|
|
166
|
+
return credentials.service;
|
|
167
|
+
}
|
|
168
|
+
};
|
package/src/translations.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type Resource } from 'i18next';
|
|
6
6
|
|
|
7
7
|
import { ScriptType } from './schema';
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export const translations = [
|
|
10
10
|
{
|
|
11
11
|
'en-US': {
|
|
12
|
-
[
|
|
12
|
+
[ScriptType.typename]: {
|
|
13
13
|
'typename label': 'Script',
|
|
14
14
|
'typename label_zero': 'Scripts',
|
|
15
15
|
'typename label_one': 'Script',
|
|
@@ -17,4 +17,4 @@ export default [
|
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
|
-
];
|
|
20
|
+
] as const satisfies Resource[];
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/services/ai.ts", "../../../src/services/database.ts", "../../../src/services/queues.ts", "../../../src/services/credentials.ts", "../../../src/services/event-logger.ts", "../../../src/services/function-call-service.ts", "../../../src/services/tracing.ts", "../../../src/services/service-container.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Context, Layer } from 'effect';\n\nimport type { AiServiceClient } from '@dxos/ai';\n\n// TODO(burdon): Move to @dxos/ai.\nexport class AiService extends Context.Tag('AiService')<\n AiService,\n {\n readonly client: AiServiceClient;\n }\n>() {\n static make = (client: AiServiceClient): Context.Tag.Service<AiService> => {\n return {\n get client() {\n return client;\n },\n };\n };\n\n static makeLayer = (client: AiServiceClient): Layer.Layer<AiService> =>\n Layer.succeed(AiService, AiService.make(client));\n\n static notAvailable = Layer.succeed(AiService, {\n get client(): AiServiceClient {\n throw new Error('AiService not available');\n },\n });\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Context, Layer } from 'effect';\n\nimport type { EchoDatabase } from '@dxos/echo-db';\n\nexport class DatabaseService extends Context.Tag('DatabaseService')<\n DatabaseService,\n {\n readonly db: EchoDatabase;\n }\n>() {\n static notAvailable = Layer.succeed(DatabaseService, {\n get db(): EchoDatabase {\n throw new Error('Database not available');\n },\n });\n\n static make = (db: EchoDatabase): Context.Tag.Service<DatabaseService> => {\n return {\n get db() {\n return db;\n },\n };\n };\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Context, Layer } from 'effect';\n\nimport type { Queue, QueueFactory } from '@dxos/echo-db';\n\nexport class QueueService extends Context.Tag('QueueService')<\n QueueService,\n {\n /**\n * API to access the queues.\n */\n readonly queues: QueueFactory;\n\n /**\n * The queue that is used to store the context of the current research.\n */\n // TODO(dmaretskyi): Is this really part of the queue service?\n readonly contextQueue: Queue | undefined;\n }\n>() {\n static notAvailable = Layer.succeed(QueueService, {\n get queues(): QueueFactory {\n throw new Error('Queues not available');\n },\n contextQueue: undefined,\n });\n\n static make = (queues: QueueFactory, contextQueue: Queue | undefined): Context.Tag.Service<QueueService> => {\n return {\n queues,\n contextQueue,\n };\n };\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Context } from 'effect';\n\ntype CredentialQuery = {\n service?: string;\n};\n\n// TODO(dmaretskyi): Unify with other apis.\n// packages/sdk/schema/src/common/access-token.ts\ntype ServiceCredential = {\n service: string;\n\n // TODO(dmaretskyi): Build out.\n apiKey?: string;\n};\n\nexport class CredentialsService extends Context.Tag('CredentialsService')<\n CredentialsService,\n {\n /**\n * Query all.\n */\n queryCredentials: (query: CredentialQuery) => Promise<ServiceCredential[]>;\n\n /**\n * Get a single credential.\n * @throws {Error} If no credential is found.\n */\n getCredential: (query: CredentialQuery) => Promise<ServiceCredential>;\n }\n>() {}\n\nexport class ConfiguredCredentialsService implements Context.Tag.Service<CredentialsService> {\n constructor(private readonly credentials: ServiceCredential[] = []) {}\n\n addCredentials(credentials: ServiceCredential[]): ConfiguredCredentialsService {\n this.credentials.push(...credentials);\n return this;\n }\n\n async queryCredentials(query: CredentialQuery): Promise<ServiceCredential[]> {\n return this.credentials.filter((credential) => credential.service === query.service);\n }\n\n async getCredential(query: CredentialQuery): Promise<ServiceCredential> {\n const credential = this.credentials.find((credential) => credential.service === query.service);\n if (!credential) {\n throw new Error(`Credential not found for service: ${query.service}`);\n }\n return credential;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Effect, Context } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { log, LogLevel } from '@dxos/log';\n\nexport type ComputeEvent =\n | {\n type: 'begin-compute';\n nodeId: string;\n inputs: Record<string, any>;\n }\n | {\n type: 'end-compute';\n nodeId: string;\n outputs: Record<string, any>;\n }\n | {\n type: 'compute-input';\n nodeId: string;\n property: string;\n value: any;\n }\n | {\n type: 'compute-output';\n nodeId: string;\n property: string;\n value: any;\n }\n | {\n type: 'custom';\n nodeId: string;\n event: any;\n };\n\nexport class EventLogger extends Context.Tag('EventLogger')<\n EventLogger,\n { readonly log: (event: ComputeEvent) => void; readonly nodeId: string | undefined }\n>() {\n static noop: Context.Tag.Service<EventLogger> = {\n log: () => {},\n nodeId: undefined,\n };\n}\n\nexport const logCustomEvent = (data: any) =>\n Effect.gen(function* () {\n const logger = yield* EventLogger;\n if (!logger.nodeId) {\n throw new Error('logCustomEvent must be called within a node compute function');\n }\n logger.log({\n type: 'custom',\n nodeId: logger.nodeId,\n event: data,\n });\n });\n\nexport const createDefectLogger = <A, E, R>(): ((self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>) =>\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n log.error('unhandled effect error', { error });\n throw error;\n }),\n );\n\nexport const createEventLogger = (level: LogLevel, message: string = 'event'): Context.Tag.Service<EventLogger> => {\n const logFunction = (\n {\n [LogLevel.WARN]: log.warn,\n [LogLevel.VERBOSE]: log.verbose,\n [LogLevel.DEBUG]: log.debug,\n [LogLevel.INFO]: log.info,\n [LogLevel.ERROR]: log.error,\n } as any\n )[level];\n invariant(logFunction);\n return {\n log: (event: ComputeEvent) => {\n logFunction(message, event);\n },\n nodeId: undefined,\n };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Context } from 'effect';\n\nimport type { SpaceId } from '@dxos/keys';\n\n/**\n * Allows calling into other functions.\n */\nexport class FunctionCallService extends Context.Tag('FunctionCallService')<\n FunctionCallService,\n {\n callFunction(deployedFunctionId: string, input: any, spaceId?: SpaceId): Promise<any>;\n }\n>() {\n static fromClient(baseUrl: string, spaceId: SpaceId): Context.Tag.Service<FunctionCallService> {\n return {\n callFunction: async (deployedFunctionId: string, input: any) => {\n const url = getInvocationUrl(deployedFunctionId, baseUrl, { spaceId });\n const result = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(input),\n });\n if (result.status >= 300 || result.status < 200) {\n throw new Error('Failed to invoke function', { cause: new Error(`HTTP error: ${await result.text()}`) });\n }\n return await result.json();\n },\n };\n }\n\n static mock = () => {\n return {\n callFunction: async (deployedFunctionId: string, input: any) => {\n return input;\n },\n };\n };\n}\n\n// TODO(dmaretskyi): Reconcile with `getInvocationUrl` in `@dxos/functions/edge`.\nconst getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {\n const baseUrl = new URL('functions/', edgeUrl);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = functionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n options.spaceId && url.searchParams.set('spaceId', options.spaceId);\n options.subjectId && url.searchParams.set('subjectId', options.subjectId);\n url.protocol = isSecure(url.protocol) ? 'https' : 'http';\n return url.toString();\n};\n\nconst isSecure = (protocol: string) => {\n return protocol === 'https:' || protocol === 'wss:';\n};\n\ntype InvocationOptions = {\n spaceId?: SpaceId;\n subjectId?: string;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Context } from 'effect';\n\nimport type { AnyEchoObject } from '@dxos/echo-schema';\n\nexport class TracingService extends Context.Tag('TracingService')<\n TracingService,\n {\n /**\n * Write an event to the tracing queue.\n * @param event - The event to write. Must be an a typed object.\n */\n write(event: AnyEchoObject): void;\n }\n>() {\n static noop: Context.Tag.Service<TracingService> = { write: () => {} };\n\n static console: Context.Tag.Service<TracingService> = {\n write: (event) => {\n // eslint-disable-next-line no-console\n console.log(event);\n },\n };\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Layer, type Context } from 'effect';\n\nimport { AiService } from './ai';\nimport { ConfiguredCredentialsService, CredentialsService } from './credentials';\nimport { DatabaseService } from './database';\nimport { EventLogger } from './event-logger';\nimport { FunctionCallService } from './function-call-service';\nimport { QueueService } from './queues';\nimport { TracingService } from './tracing';\n\n/**\n * List of all service tags and their names.\n */\nexport interface ServiceTagRecord {\n ai: AiService;\n credentials: CredentialsService;\n database: DatabaseService;\n eventLogger: EventLogger;\n functionCallService: FunctionCallService;\n tracing: TracingService;\n queues: QueueService;\n}\n\n/**\n * List of all services and their runtime types.\n */\nexport type ServiceRecord = {\n [K in keyof ServiceTagRecord]: Context.Tag.Service<ServiceTagRecord[K]>;\n};\n\n/**\n * Union of all services.\n */\nexport type Services = ServiceTagRecord[keyof ServiceTagRecord];\n\nconst SERVICE_MAPPING: Record<string, keyof ServiceRecord> = {\n [AiService.key]: 'ai',\n [CredentialsService.key]: 'credentials',\n [DatabaseService.key]: 'database',\n [EventLogger.key]: 'eventLogger',\n [FunctionCallService.key]: 'functionCallService',\n [QueueService.key]: 'queues',\n [TracingService.key]: 'tracing',\n};\n\nexport const SERVICE_TAGS: Context.Tag<any, any>[] = [\n AiService,\n CredentialsService,\n DatabaseService,\n EventLogger,\n FunctionCallService,\n TracingService,\n QueueService,\n];\n\nconst DEFAULT_SERVICES: Partial<ServiceRecord> = {\n tracing: TracingService.noop,\n};\n\nexport class ServiceContainer {\n private _services: Partial<ServiceRecord> = { ...DEFAULT_SERVICES };\n\n /**\n * Set services.\n * @param services - Services to set.\n * @returns The container instance.\n */\n setServices(services: Partial<ServiceRecord>): this {\n this._services = { ...this._services, ...services };\n return this;\n }\n\n getService<T extends Context.Tag<any, any>>(tag: T): Context.Tag.Service<T> {\n const serviceKey = SERVICE_MAPPING[tag.key];\n const service = serviceKey != null ? this._services[serviceKey] : undefined;\n if (!service) {\n throw new Error(`Service not available: ${tag.key}`);\n }\n return service as Context.Tag.Service<T>;\n }\n\n clone(): ServiceContainer {\n return new ServiceContainer().setServices({ ...this._services });\n }\n\n // TODO(dmaretskyi): `getService` is designed to error at runtime if the service is not available, but layer forces us to provide all services and makes stubs for the ones that are not available.\n createLayer(): Layer.Layer<Services> {\n const ai = this._services.ai != null ? Layer.succeed(AiService, this._services.ai) : AiService.notAvailable;\n const credentials = Layer.succeed(CredentialsService, new ConfiguredCredentialsService());\n const database =\n this._services.database != null\n ? Layer.succeed(DatabaseService, this._services.database)\n : DatabaseService.notAvailable;\n const queues =\n this._services.queues != null ? Layer.succeed(QueueService, this._services.queues) : QueueService.notAvailable;\n const tracing = Layer.succeed(TracingService, this._services.tracing ?? TracingService.noop);\n const eventLogger = Layer.succeed(EventLogger, this._services.eventLogger ?? EventLogger.noop);\n const functionCallService = Layer.succeed(\n FunctionCallService,\n this._services.functionCallService ?? FunctionCallService.mock(),\n );\n\n return Layer.mergeAll(ai, credentials, database, queues, tracing, eventLogger, functionCallService);\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,SAASC,aAAa;AAKxB,IAAMC,YAAN,MAAMA,mBAAkBC,QAAQC,IAAI,WAAA,EAAA,EAAA;EAMzC;SAAOC,OAAO,CAACC,WAAAA;AACb,aAAO;QACL,IAAIA,SAAS;AACX,iBAAOA;QACT;MACF;IACF;;EAEA;SAAOC,YAAY,CAACD,WAClBE,MAAMC,QAAQP,YAAWA,WAAUG,KAAKC,MAAAA,CAAAA;;EAE1C;SAAOI,eAAeF,MAAMC,QAAQP,YAAW;MAC7C,IAAII,SAA0B;AAC5B,cAAM,IAAIK,MAAM,yBAAA;MAClB;IACF,CAAA;;AACF;;;AC3BA,SAASC,WAAAA,UAASC,SAAAA,cAAa;AAIxB,IAAMC,kBAAN,MAAMA,yBAAwBC,SAAQC,IAAI,iBAAA,EAAA,EAAA;EAM/C;SAAOC,eAAeC,OAAMC,QAAQL,kBAAiB;MACnD,IAAIM,KAAmB;AACrB,cAAM,IAAIC,MAAM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qB;AACpG,UAAMjB,UAAUe,OAAMC,QAAQnB,gBAAgB,KAAKM,UAAUH,WAAWH,eAAeI,IAAI;AAC3F,UAAMqB,cAAcP,OAAMC,QAAQtB,aAAa,KAAKS,UAAUmB,eAAe5B,YAAYO,IAAI;AAC7F,UAAMsB,sBAAsBR,OAAMC,QAChCrB,qBACA,KAAKQ,UAAUoB,uBAAuB5B,oBAAoB6B,KAAI,CAAA;AAGhE,WAAOT,OAAMU,SAASX,IAAII,aAAaE,UAAUC,QAAQrB,SAASsB,aAAaC,mBAAAA;EACjF;AACF;",
|
|
6
|
-
"names": ["Context", "Layer", "AiService", "Context", "Tag", "make", "client", "makeLayer", "Layer", "succeed", "notAvailable", "Error", "Context", "Layer", "DatabaseService", "Context", "Tag", "notAvailable", "Layer", "succeed", "db", "Error", "make", "Context", "Layer", "QueueService", "Context", "Tag", "notAvailable", "Layer", "succeed", "queues", "Error", "contextQueue", "undefined", "make", "Context", "CredentialsService", "Context", "Tag", "ConfiguredCredentialsService", "credentials", "addCredentials", "push", "queryCredentials", "query", "filter", "credential", "service", "getCredential", "find", "Error", "Effect", "Context", "invariant", "log", "LogLevel", "EventLogger", "Tag", "noop", "nodeId", "undefined", "logCustomEvent", "data", "gen", "logger", "Error", "type", "event", "createDefectLogger", "catchAll", "error", "createEventLogger", "level", "message", "logFunction", "WARN", "warn", "VERBOSE", "verbose", "DEBUG", "debug", "INFO", "info", "ERROR", "Context", "FunctionCallService", "Context", "Tag", "fromClient", "baseUrl", "spaceId", "callFunction", "deployedFunctionId", "input", "url", "getInvocationUrl", "result", "fetch", "method", "headers", "body", "JSON", "stringify", "status", "Error", "cause", "text", "json", "mock", "functionUrl", "edgeUrl", "options", "URL", "relativeUrl", "replace", "toString", "searchParams", "set", "subjectId", "protocol", "isSecure", "Context", "TracingService", "Context", "Tag", "noop", "write", "console", "event", "log", "Layer", "SERVICE_MAPPING", "AiService", "key", "CredentialsService", "DatabaseService", "EventLogger", "FunctionCallService", "QueueService", "TracingService", "SERVICE_TAGS", "DEFAULT_SERVICES", "tracing", "noop", "ServiceContainer", "_services", "setServices", "services", "getService", "tag", "serviceKey", "service", "undefined", "Error", "clone", "createLayer", "ai", "Layer", "succeed", "notAvailable", "credentials", "ConfiguredCredentialsService", "database", "queues", "eventLogger", "functionCallService", "mock", "mergeAll"]
|
|
7
|
-
}
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var bundler_exports = {};
|
|
20
|
-
__export(bundler_exports, {
|
|
21
|
-
Bundler: () => Bundler,
|
|
22
|
-
initializeBundler: () => initializeBundler
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(bundler_exports);
|
|
25
|
-
var import_esbuild_wasm = require("esbuild-wasm");
|
|
26
|
-
var import_crypto = require("@dxos/crypto");
|
|
27
|
-
var import_invariant = require("@dxos/invariant");
|
|
28
|
-
var import_log = require("@dxos/log");
|
|
29
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/bundler/bundler.ts";
|
|
30
|
-
var initialized;
|
|
31
|
-
var initializeBundler = async (options) => {
|
|
32
|
-
await (initialized ??= (0, import_esbuild_wasm.initialize)({
|
|
33
|
-
wasmURL: options.wasmUrl
|
|
34
|
-
}));
|
|
35
|
-
};
|
|
36
|
-
var Bundler = class {
|
|
37
|
-
constructor(_options) {
|
|
38
|
-
this._options = _options;
|
|
39
|
-
}
|
|
40
|
-
async bundle({ path, source }) {
|
|
41
|
-
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
42
|
-
const createResult = async (result) => {
|
|
43
|
-
return {
|
|
44
|
-
timestamp: Date.now(),
|
|
45
|
-
sourceHash: source ? Buffer.from(await import_crypto.subtleCrypto.digest("SHA-256", Buffer.from(source))) : void 0,
|
|
46
|
-
...result
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
if (this._options.platform === "browser") {
|
|
50
|
-
(0, import_invariant.invariant)(initialized, "Compiler not initialized.", {
|
|
51
|
-
F: __dxlog_file,
|
|
52
|
-
L: 71,
|
|
53
|
-
S: this,
|
|
54
|
-
A: [
|
|
55
|
-
"initialized",
|
|
56
|
-
"'Compiler not initialized.'"
|
|
57
|
-
]
|
|
58
|
-
});
|
|
59
|
-
await initialized;
|
|
60
|
-
}
|
|
61
|
-
const imports = source ? analyzeSourceFileImports(source) : [];
|
|
62
|
-
try {
|
|
63
|
-
const result = await (0, import_esbuild_wasm.build)({
|
|
64
|
-
platform: options.platform,
|
|
65
|
-
conditions: [
|
|
66
|
-
"workerd",
|
|
67
|
-
"browser"
|
|
68
|
-
],
|
|
69
|
-
metafile: true,
|
|
70
|
-
write: false,
|
|
71
|
-
entryPoints: [
|
|
72
|
-
path ?? "memory:main.tsx"
|
|
73
|
-
],
|
|
74
|
-
bundle: true,
|
|
75
|
-
format: "esm",
|
|
76
|
-
plugins: [
|
|
77
|
-
{
|
|
78
|
-
name: "memory",
|
|
79
|
-
setup: (build2) => {
|
|
80
|
-
build2.onResolve({
|
|
81
|
-
filter: /^\.\/runtime\.js$/
|
|
82
|
-
}, ({ path: path2 }) => {
|
|
83
|
-
return {
|
|
84
|
-
path: path2,
|
|
85
|
-
external: true
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
build2.onResolve({
|
|
89
|
-
filter: /^dxos:functions$/
|
|
90
|
-
}, ({ path: path2 }) => {
|
|
91
|
-
return {
|
|
92
|
-
path: "./runtime.js",
|
|
93
|
-
external: true
|
|
94
|
-
};
|
|
95
|
-
});
|
|
96
|
-
build2.onResolve({
|
|
97
|
-
filter: /^memory:/
|
|
98
|
-
}, ({ path: path2 }) => {
|
|
99
|
-
return {
|
|
100
|
-
path: path2.split(":")[1],
|
|
101
|
-
namespace: "memory"
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
build2.onLoad({
|
|
105
|
-
filter: /.*/,
|
|
106
|
-
namespace: "memory"
|
|
107
|
-
}, ({ path: path2 }) => {
|
|
108
|
-
if (path2 === "main.tsx") {
|
|
109
|
-
return {
|
|
110
|
-
contents: source,
|
|
111
|
-
loader: "tsx"
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
for (const module2 of providedModules) {
|
|
116
|
-
build2.onResolve({
|
|
117
|
-
filter: new RegExp(`^${module2}$`)
|
|
118
|
-
}, ({ path: path2 }) => {
|
|
119
|
-
return {
|
|
120
|
-
path: path2,
|
|
121
|
-
namespace: "injected-module"
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
build2.onLoad({
|
|
126
|
-
filter: /.*/,
|
|
127
|
-
namespace: "injected-module"
|
|
128
|
-
}, ({ path: path2 }) => {
|
|
129
|
-
const namedImports = imports.find((entry) => entry.moduleIdentifier === path2)?.namedImports ?? [];
|
|
130
|
-
return {
|
|
131
|
-
contents: `
|
|
132
|
-
const { ${namedImports.join(",")} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path2)}];
|
|
133
|
-
export { ${namedImports.join(",")} };
|
|
134
|
-
export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path2)}].default;
|
|
135
|
-
`,
|
|
136
|
-
loader: "tsx"
|
|
137
|
-
};
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
httpPlugin
|
|
142
|
-
]
|
|
143
|
-
});
|
|
144
|
-
(0, import_log.log)("compile complete", result.metafile, {
|
|
145
|
-
F: __dxlog_file,
|
|
146
|
-
L: 135,
|
|
147
|
-
S: this,
|
|
148
|
-
C: (f, a) => f(...a)
|
|
149
|
-
});
|
|
150
|
-
return await createResult({
|
|
151
|
-
imports: this.analyzeImports(result),
|
|
152
|
-
bundle: result.outputFiles[0].text
|
|
153
|
-
});
|
|
154
|
-
} catch (err) {
|
|
155
|
-
return await createResult({
|
|
156
|
-
error: err
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
|
|
161
|
-
analyzeImports(result) {
|
|
162
|
-
(0, import_invariant.invariant)(result.outputFiles, void 0, {
|
|
163
|
-
F: __dxlog_file,
|
|
164
|
-
L: 148,
|
|
165
|
-
S: this,
|
|
166
|
-
A: [
|
|
167
|
-
"result.outputFiles",
|
|
168
|
-
""
|
|
169
|
-
]
|
|
170
|
-
});
|
|
171
|
-
const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
|
|
172
|
-
return Object.values(result.metafile.outputs)[0].imports.map((entry) => {
|
|
173
|
-
const namedImports = [];
|
|
174
|
-
const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
|
|
175
|
-
if (parsedImport?.[2]) {
|
|
176
|
-
NAMED_IMPORTS_REGEX.lastIndex = 0;
|
|
177
|
-
const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
|
|
178
|
-
if (namedImportsMatch) {
|
|
179
|
-
namedImportsMatch[1].split(",").forEach((importName) => {
|
|
180
|
-
namedImports.push(importName.trim());
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return {
|
|
185
|
-
moduleUrl: entry.path,
|
|
186
|
-
defaultImport: !!parsedImport?.[1],
|
|
187
|
-
namedImports
|
|
188
|
-
};
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
analyzeSourceFileImports(code) {
|
|
192
|
-
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
193
|
-
return parsedImports.map((capture) => {
|
|
194
|
-
return {
|
|
195
|
-
defaultImportName: capture[1],
|
|
196
|
-
namedImports: capture[2]?.split(",").map((importName) => importName.trim()),
|
|
197
|
-
wildcardImportName: capture[3],
|
|
198
|
-
moduleIdentifier: capture[4],
|
|
199
|
-
quotes: capture[5]
|
|
200
|
-
};
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
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;
|
|
205
|
-
var NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
|
|
206
|
-
var allMatches = (regex, str) => {
|
|
207
|
-
regex.lastIndex = 0;
|
|
208
|
-
let match;
|
|
209
|
-
const matches = [];
|
|
210
|
-
while (match = regex.exec(str)) {
|
|
211
|
-
matches.push(match);
|
|
212
|
-
}
|
|
213
|
-
return matches;
|
|
214
|
-
};
|
|
215
|
-
var analyzeSourceFileImports = (code) => {
|
|
216
|
-
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
217
|
-
return parsedImports.map((capture) => {
|
|
218
|
-
return {
|
|
219
|
-
defaultImportName: capture[1],
|
|
220
|
-
namedImports: capture[2]?.trim().slice(1, -1).split(",").map((importName) => importName.trim()),
|
|
221
|
-
wildcardImportName: capture[3],
|
|
222
|
-
moduleIdentifier: capture[4],
|
|
223
|
-
quotes: capture[5]
|
|
224
|
-
};
|
|
225
|
-
});
|
|
226
|
-
};
|
|
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
|
-
const response = await fetch(args.path);
|
|
248
|
-
return {
|
|
249
|
-
contents: await response.text(),
|
|
250
|
-
loader: "jsx"
|
|
251
|
-
};
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
256
|
-
0 && (module.exports = {
|
|
257
|
-
Bundler,
|
|
258
|
-
initializeBundler
|
|
259
|
-
});
|
|
260
|
-
//# sourceMappingURL=index.cjs.map
|