@mcp-b/do-runtime 0.3.3 → 0.3.4
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/CHANGELOG.md +6 -0
- package/dist/gate.js +45 -13
- package/dist/gate.js.map +1 -1
- package/dist/src/gate.d.ts +19 -0
- package/dist/vite.js +4 -2
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/gate.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { c as tryCurrentSlice } from "./chunks/io-context-BV4kxxAv.js";
|
|
1
|
+
import { c as tryCurrentSlice, n as atCheckpointEnd } from "./chunks/io-context-BV4kxxAv.js";
|
|
2
2
|
//#region src/gate.ts
|
|
3
3
|
var continuationContext;
|
|
4
|
+
var TRANSFORMED_AWAIT = Symbol("@mcp-b/do-runtime/transformed-await");
|
|
4
5
|
function isThenable(value) {
|
|
5
6
|
return (typeof value === "object" && value !== null || typeof value === "function") && typeof Reflect.get(value, "then") === "function";
|
|
6
7
|
}
|
|
@@ -11,7 +12,33 @@ function __gate(value) {
|
|
|
11
12
|
if (context === void 0) return value;
|
|
12
13
|
return resumeWithContext(context, Promise.resolve(value));
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
/** Capture an actor await without publishing its context before the continuation runs. */
|
|
16
|
+
function __gateAwait(value) {
|
|
17
|
+
const context = tryCurrentSlice() ?? continuationContext?.context;
|
|
18
|
+
if (context === void 0) return value;
|
|
19
|
+
return resumeAwaitWithContext(context, Promise.resolve(value));
|
|
20
|
+
}
|
|
21
|
+
/** Restore the captured actor at the first instruction after a transformed await. */
|
|
22
|
+
function __resumeAwait(value) {
|
|
23
|
+
if (!isTransformedAwait(value)) return value;
|
|
24
|
+
restoreContinuation(value.context);
|
|
25
|
+
if (value.outcome.ok) return value.outcome.value;
|
|
26
|
+
throw value.outcome.exception;
|
|
27
|
+
}
|
|
28
|
+
function isTransformedAwait(value) {
|
|
29
|
+
return Reflect.get(Object(value), TRANSFORMED_AWAIT) === true;
|
|
30
|
+
}
|
|
31
|
+
function restoreContinuation(context) {
|
|
32
|
+
const token = {};
|
|
33
|
+
continuationContext = {
|
|
34
|
+
context,
|
|
35
|
+
token
|
|
36
|
+
};
|
|
37
|
+
atCheckpointEnd(() => {
|
|
38
|
+
if (continuationContext?.token === token) continuationContext = void 0;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function publishOutcome(context, promise, finish) {
|
|
15
42
|
return new Promise((resolve, reject) => {
|
|
16
43
|
const publish = context.makeTransformReentryCallback((outcome) => {
|
|
17
44
|
if (continuationContext !== void 0) {
|
|
@@ -21,16 +48,7 @@ function resumeWithContext(context, promise) {
|
|
|
21
48
|
});
|
|
22
49
|
return;
|
|
23
50
|
}
|
|
24
|
-
|
|
25
|
-
continuationContext = {
|
|
26
|
-
context,
|
|
27
|
-
token
|
|
28
|
-
};
|
|
29
|
-
if (outcome.ok) resolve(outcome.value);
|
|
30
|
-
else reject(outcome.exception);
|
|
31
|
-
queueMicrotask(() => {
|
|
32
|
-
if (continuationContext?.token === token) continuationContext = void 0;
|
|
33
|
-
});
|
|
51
|
+
resolve(finish(outcome));
|
|
34
52
|
});
|
|
35
53
|
promise.then((value) => {
|
|
36
54
|
schedulePublication({
|
|
@@ -51,6 +69,20 @@ function resumeWithContext(context, promise) {
|
|
|
51
69
|
});
|
|
52
70
|
});
|
|
53
71
|
}
|
|
72
|
+
function resumeAwaitWithContext(context, promise) {
|
|
73
|
+
return publishOutcome(context, promise, (outcome) => ({
|
|
74
|
+
[TRANSFORMED_AWAIT]: true,
|
|
75
|
+
context,
|
|
76
|
+
outcome
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
function resumeWithContext(context, promise) {
|
|
80
|
+
return publishOutcome(context, promise, (outcome) => {
|
|
81
|
+
restoreContinuation(context);
|
|
82
|
+
if (outcome.ok) return outcome.value;
|
|
83
|
+
throw outcome.exception;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
54
86
|
/**
|
|
55
87
|
* Resolve one transformed await per task, inside a fresh actor slice. Admission
|
|
56
88
|
* attempts are independent so a blocked actor cannot stall the actor that will
|
|
@@ -101,6 +133,6 @@ function __gateAsyncIterable(iterable) {
|
|
|
101
133
|
} });
|
|
102
134
|
}
|
|
103
135
|
//#endregion
|
|
104
|
-
export { __gate, __gateAsyncIterable };
|
|
136
|
+
export { __gate, __gateAsyncIterable, __gateAwait, __resumeAwait };
|
|
105
137
|
|
|
106
138
|
//# sourceMappingURL=gate.js.map
|
package/dist/gate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate.js","names":[],"sources":["../src/gate.ts"],"sourcesContent":["/* @do-runtime-gated */\n\nimport { tryCurrentSlice, type IoContext } from \"./io/io-context\";\n\ntype ContinuationContext = {\n readonly context: IoContext;\n readonly token: object;\n};\n\nlet continuationContext: ContinuationContext | undefined;\n\ntype Publication = {\n readonly publish: () => Promise<void>;\n readonly reject: (exception: unknown) => void;\n};\n\ntype Outcome<T> =\n | { readonly ok: true; readonly value: T }\n | { readonly ok: false; readonly exception: unknown };\n\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n (typeof value === \"object\" && value !== null) ||\n typeof value === \"function\"\n ) && typeof Reflect.get(value, \"then\") === \"function\";\n}\n\n/** Re-enter the actor that owns this transformed await; fail open outside actors. */\nexport function __gate<T>(value: T): T | Promise<Awaited<T>> {\n const context = tryCurrentSlice() ?? continuationContext?.context;\n if (!isThenable(value) && context === undefined) return value;\n if (context === undefined) return value;\n return resumeWithContext(context, Promise.resolve(value));\n}\n\
|
|
1
|
+
{"version":3,"file":"gate.js","names":[],"sources":["../src/gate.ts"],"sourcesContent":["/* @do-runtime-gated */\n\nimport { atCheckpointEnd, tryCurrentSlice, type IoContext } from \"./io/io-context\";\n\ntype ContinuationContext = {\n readonly context: IoContext;\n readonly token: object;\n};\n\nlet continuationContext: ContinuationContext | undefined;\n\ntype Publication = {\n readonly publish: () => Promise<void>;\n readonly reject: (exception: unknown) => void;\n};\n\ntype Outcome<T> =\n | { readonly ok: true; readonly value: T }\n | { readonly ok: false; readonly exception: unknown };\n\nconst TRANSFORMED_AWAIT = Symbol(\"@mcp-b/do-runtime/transformed-await\");\n\ntype TransformedAwait<T> = {\n readonly [TRANSFORMED_AWAIT]: true;\n readonly context: IoContext;\n readonly outcome: Outcome<T>;\n};\n\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n (typeof value === \"object\" && value !== null) ||\n typeof value === \"function\"\n ) && typeof Reflect.get(value, \"then\") === \"function\";\n}\n\n/** Re-enter the actor that owns this transformed await; fail open outside actors. */\nexport function __gate<T>(value: T): T | Promise<Awaited<T>> {\n const context = tryCurrentSlice() ?? continuationContext?.context;\n if (!isThenable(value) && context === undefined) return value;\n if (context === undefined) return value;\n return resumeWithContext(context, Promise.resolve(value));\n}\n\n/** Capture an actor await without publishing its context before the continuation runs. */\nexport function __gateAwait<T>(value: T): T | Promise<TransformedAwait<Awaited<T>>> {\n const context = tryCurrentSlice() ?? continuationContext?.context;\n if (context === undefined) return value;\n return resumeAwaitWithContext(context, Promise.resolve(value));\n}\n\n/** Restore the captured actor at the first instruction after a transformed await. */\nexport function __resumeAwait<T>(value: T | TransformedAwait<T>): T {\n if (!isTransformedAwait(value)) return value as T;\n\n restoreContinuation(value.context);\n if (value.outcome.ok) return value.outcome.value;\n throw value.outcome.exception;\n}\n\nfunction isTransformedAwait<T>(value: T | TransformedAwait<T>): value is TransformedAwait<T> {\n return Reflect.get(Object(value), TRANSFORMED_AWAIT) === true;\n}\n\nfunction restoreContinuation(context: IoContext): void {\n const token = {};\n continuationContext = { context, token };\n atCheckpointEnd(() => {\n if (continuationContext?.token === token) continuationContext = undefined;\n });\n}\n\nfunction publishOutcome<T, Result>(\n context: IoContext,\n promise: Promise<T>,\n finish: (outcome: Outcome<T>) => Result,\n): Promise<Result> {\n return new Promise<Result>((resolve, reject) => {\n const publish = context.makeTransformReentryCallback((outcome: Outcome<T>) => {\n if (continuationContext !== undefined) {\n schedulePublication({ publish: () => publish(outcome), reject });\n return;\n }\n resolve(finish(outcome));\n });\n void promise.then(\n (value) => {\n schedulePublication({ publish: () => publish({ ok: true, value }), reject });\n },\n (exception: unknown) => {\n schedulePublication({ publish: () => publish({ ok: false, exception }), reject });\n },\n );\n });\n}\n\nfunction resumeAwaitWithContext<T>(\n context: IoContext,\n promise: Promise<T>,\n): Promise<TransformedAwait<T>> {\n return publishOutcome(context, promise, (outcome) => ({\n [TRANSFORMED_AWAIT]: true,\n context,\n outcome,\n }));\n}\n\nfunction resumeWithContext<T>(context: IoContext, promise: Promise<T>): Promise<T> {\n return publishOutcome(context, promise, (outcome) => {\n restoreContinuation(context);\n if (outcome.ok) return outcome.value;\n throw outcome.exception;\n });\n}\n\n/**\n * Resolve one transformed await per task, inside a fresh actor slice. Admission\n * attempts are independent so a blocked actor cannot stall the actor that will\n * unblock it. The task boundary keeps each continuation ambient isolated.\n */\nfunction schedulePublication(publication: Publication): void {\n const channel = new MessageChannel();\n channel.port1.onmessage = () => {\n channel.port1.close();\n channel.port2.close();\n\n void publication.publish().catch((exception: unknown) => {\n publication.reject(exception);\n });\n };\n channel.port2.postMessage(undefined);\n}\n\nfunction iteratorFor<T>(iterable: AsyncIterable<T> | Iterable<T>): AsyncIterator<T> | Iterator<T> {\n const subject = Object(iterable);\n const asyncIterator: unknown = Reflect.get(subject, Symbol.asyncIterator);\n if (typeof asyncIterator === \"function\") return Reflect.apply(asyncIterator, iterable, []);\n const iterator: unknown = Reflect.get(subject, Symbol.iterator);\n if (typeof iterator === \"function\") return Reflect.apply(iterator, iterable, []);\n throw new TypeError(\"value is not async iterable or iterable\");\n}\n\nfunction gatedIterator<T>(iterable: AsyncIterable<T> | Iterable<T>): AsyncIterator<T> {\n const iterator = iteratorFor(iterable);\n\n function invoke(methodName: \"next\" | \"return\" | \"throw\", args: unknown[]): Promise<IteratorResult<T>> {\n const method: unknown = Reflect.get(iterator, methodName);\n if (typeof method === \"function\") {\n return Promise.resolve(__gate(Reflect.apply(method, iterator, args)));\n }\n if (methodName === \"throw\") return Promise.reject(args[0]);\n return Promise.resolve({ done: true, value: args[0] });\n }\n\n return {\n next: (...args: [] | [unknown]) => invoke(\"next\", args),\n return: (value?: unknown) => invoke(\"return\", [value]),\n throw: (exception?: unknown) => invoke(\"throw\", [exception]),\n };\n}\n\n/** Gate every operation used by `for await`, including early return and throw. */\nexport function __gateAsyncIterable<T, IterableType extends AsyncIterable<T> | Iterable<T>>(\n iterable: IterableType,\n): IterableType;\nexport function __gateAsyncIterable<T>(\n iterable: AsyncIterable<T> | Iterable<T>,\n): AsyncIterable<T> | Iterable<T> {\n const wrapper: AsyncIterable<T> = {\n [Symbol.asyncIterator]: () => gatedIterator(iterable),\n };\n if ((typeof iterable !== \"object\" || iterable === null) && typeof iterable !== \"function\") {\n return wrapper;\n }\n return new Proxy(iterable, {\n get(target, property, receiver): unknown {\n if (property === Symbol.asyncIterator) return wrapper[Symbol.asyncIterator];\n return Reflect.get(target, property, receiver);\n },\n });\n}\n"],"mappings":";;AASA,IAAI;AAWJ,IAAM,oBAAoB,OAAO,qCAAqC;AAQtE,SAAS,WAAW,OAA+C;CACjE,QACG,OAAO,UAAU,YAAY,UAAU,QACxC,OAAO,UAAU,eACd,OAAO,QAAQ,IAAI,OAAO,MAAM,MAAM;AAC7C;;AAGA,SAAgB,OAAU,OAAmC;CAC3D,MAAM,UAAU,gBAAgB,KAAK,qBAAqB;CAC1D,IAAI,CAAC,WAAW,KAAK,KAAK,YAAY,KAAA,GAAW,OAAO;CACxD,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,OAAO,kBAAkB,SAAS,QAAQ,QAAQ,KAAK,CAAC;AAC1D;;AAGA,SAAgB,YAAe,OAAqD;CAClF,MAAM,UAAU,gBAAgB,KAAK,qBAAqB;CAC1D,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,OAAO,uBAAuB,S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sBAAsB,cAAc,QAAQ,EACtD;CACA,KAAK,OAAO,aAAa,YAAY,aAAa,SAAS,OAAO,aAAa,YAC7E,OAAO;CAET,OAAO,IAAI,MAAM,UAAU,EACzB,IAAI,QAAQ,UAAU,UAAmB;EACvC,IAAI,aAAa,OAAO,eAAe,OAAO,QAAQ,OAAO;EAC7D,OAAO,QAAQ,IAAI,QAAQ,UAAU,QAAQ;CAC/C,EACF,CAAC;AACH"}
|
package/dist/src/gate.d.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
|
+
import { type IoContext } from "./io/io-context.js";
|
|
2
|
+
type Outcome<T> = {
|
|
3
|
+
readonly ok: true;
|
|
4
|
+
readonly value: T;
|
|
5
|
+
} | {
|
|
6
|
+
readonly ok: false;
|
|
7
|
+
readonly exception: unknown;
|
|
8
|
+
};
|
|
9
|
+
declare const TRANSFORMED_AWAIT: unique symbol;
|
|
10
|
+
type TransformedAwait<T> = {
|
|
11
|
+
readonly [TRANSFORMED_AWAIT]: true;
|
|
12
|
+
readonly context: IoContext;
|
|
13
|
+
readonly outcome: Outcome<T>;
|
|
14
|
+
};
|
|
1
15
|
/** Re-enter the actor that owns this transformed await; fail open outside actors. */
|
|
2
16
|
export declare function __gate<T>(value: T): T | Promise<Awaited<T>>;
|
|
17
|
+
/** Capture an actor await without publishing its context before the continuation runs. */
|
|
18
|
+
export declare function __gateAwait<T>(value: T): T | Promise<TransformedAwait<Awaited<T>>>;
|
|
19
|
+
/** Restore the captured actor at the first instruction after a transformed await. */
|
|
20
|
+
export declare function __resumeAwait<T>(value: T | TransformedAwait<T>): T;
|
|
3
21
|
/** Gate every operation used by `for await`, including early return and throw. */
|
|
4
22
|
export declare function __gateAsyncIterable<T, IterableType extends AsyncIterable<T> | Iterable<T>>(iterable: IterableType): IterableType;
|
|
23
|
+
export {};
|
package/dist/vite.js
CHANGED
|
@@ -2,7 +2,7 @@ import MagicString from "magic-string";
|
|
|
2
2
|
import { Visitor, createFilter } from "vite";
|
|
3
3
|
//#region src/vite.ts
|
|
4
4
|
var MARKER = "/* @do-runtime-gated */";
|
|
5
|
-
var IMPORT = "import {
|
|
5
|
+
var IMPORT = "import { __gateAsyncIterable, __gateAwait, __resumeAwait } from \"@mcp-b/do-runtime/gate\";";
|
|
6
6
|
function patterns(pattern) {
|
|
7
7
|
if (pattern === void 0 || pattern === null) return [];
|
|
8
8
|
return typeof pattern === "string" || pattern instanceof RegExp ? [pattern] : pattern;
|
|
@@ -24,8 +24,10 @@ function doRuntimeAwaitTransform(options) {
|
|
|
24
24
|
const program = this.parse(code);
|
|
25
25
|
new Visitor({
|
|
26
26
|
AwaitExpression(node) {
|
|
27
|
-
source.prependLeft(node.
|
|
27
|
+
source.prependLeft(node.start, "__resumeAwait((");
|
|
28
|
+
source.prependLeft(node.argument.start, "__gateAwait((");
|
|
28
29
|
source.appendRight(node.argument.end, "))");
|
|
30
|
+
source.appendRight(node.end, "))");
|
|
29
31
|
transformed = true;
|
|
30
32
|
},
|
|
31
33
|
ForOfStatement(node) {
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import MagicString from \"magic-string\";\nimport {\n createFilter,\n Visitor,\n type FilterPattern,\n type Plugin,\n} from \"vite\";\n\nconst MARKER = \"/* @do-runtime-gated */\";\nconst IMPORT =\n 'import {
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import MagicString from \"magic-string\";\nimport {\n createFilter,\n Visitor,\n type FilterPattern,\n type Plugin,\n} from \"vite\";\n\nconst MARKER = \"/* @do-runtime-gated */\";\nconst IMPORT =\n 'import { __gateAsyncIterable, __gateAwait, __resumeAwait } from \"@mcp-b/do-runtime/gate\";';\n\nexport interface DoRuntimeAwaitTransformOptions {\n include?: FilterPattern;\n exclude?: FilterPattern;\n}\n\nfunction patterns(pattern: FilterPattern | undefined): readonly (string | RegExp)[] {\n if (pattern === undefined || pattern === null) return [];\n return typeof pattern === \"string\" || pattern instanceof RegExp ? [pattern] : pattern;\n}\n\n/** Rewrite syntactic awaits in selected actor-bundled modules to re-enter their input gate. */\nexport function doRuntimeAwaitTransform(options?: DoRuntimeAwaitTransformOptions): Plugin {\n const filter = createFilter(options?.include, [\n \"**/node_modules/@mcp-b/do-runtime/**\",\n \"**/@mcp-b/do-runtime/gate\",\n ...patterns(options?.exclude),\n ]);\n\n return {\n name: \"do-runtime-await-transform\",\n enforce: \"post\",\n transform(code, id) {\n if (!code.includes(\"await\") || code.includes(MARKER) || !filter(id)) return null;\n\n const source = new MagicString(code);\n let transformed = false;\n const program = this.parse(code);\n new Visitor({\n AwaitExpression(node) {\n source.prependLeft(node.start, \"__resumeAwait((\");\n source.prependLeft(node.argument.start, \"__gateAwait((\");\n source.appendRight(node.argument.end, \"))\");\n source.appendRight(node.end, \"))\");\n transformed = true;\n },\n ForOfStatement(node) {\n if (!node.await) return;\n source.prependLeft(node.right.start, \"__gateAsyncIterable((\");\n source.appendRight(node.right.end, \"))\");\n transformed = true;\n },\n }).visit(program);\n if (!transformed) return null;\n\n const insertionPoint = code.startsWith(\"#!\") ? code.indexOf(\"\\n\") + 1 : 0;\n source.appendLeft(insertionPoint, `${MARKER}\\n${IMPORT}\\n`);\n return {\n code: source.toString(),\n map: source.generateMap({ hires: \"boundary\", includeContent: true, source: id }),\n };\n },\n };\n}\n"],"mappings":";;;AAQA,IAAM,SAAS;AACf,IAAM,SACJ;AAOF,SAAS,SAAS,SAAkE;CAClF,IAAI,YAAY,KAAA,KAAa,YAAY,MAAM,OAAO,CAAC;CACvD,OAAO,OAAO,YAAY,YAAY,mBAAmB,SAAS,CAAC,OAAO,IAAI;AAChF;;AAGA,SAAgB,wBAAwB,SAAkD;CACxF,MAAM,SAAS,aAAa,SAAS,SAAS;EAC5C;EACA;EACA,GAAG,SAAS,SAAS,OAAO;CAC9B,CAAC;CAED,OAAO;EACL,MAAM;EACN,SAAS;EACT,UAAU,MAAM,IAAI;GAClB,IAAI,CAAC,KAAK,SAAS,OAAO,KAAK,KAAK,SAAS,MAAM,KAAK,CAAC,OAAO,EAAE,GAAG,OAAO;GAE5E,MAAM,SAAS,IAAI,YAAY,IAAI;GACnC,IAAI,cAAc;GAClB,MAAM,UAAU,KAAK,MAAM,IAAI;GAC/B,IAAI,QAAQ;IACV,gBAAgB,MAAM;KACpB,OAAO,YAAY,KAAK,OAAO,iBAAiB;KAChD,OAAO,YAAY,KAAK,SAAS,OAAO,eAAe;KACvD,OAAO,YAAY,KAAK,SAAS,KAAK,IAAI;KAC1C,OAAO,YAAY,KAAK,KAAK,IAAI;KACjC,cAAc;IAChB;IACA,eAAe,MAAM;KACnB,IAAI,CAAC,KAAK,OAAO;KACjB,OAAO,YAAY,KAAK,MAAM,OAAO,uBAAuB;KAC5D,OAAO,YAAY,KAAK,MAAM,KAAK,IAAI;KACvC,cAAc;IAChB;GACF,CAAC,CAAC,CAAC,MAAM,OAAO;GAChB,IAAI,CAAC,aAAa,OAAO;GAEzB,MAAM,iBAAiB,KAAK,WAAW,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,IAAI;GACxE,OAAO,WAAW,gBAAgB,GAAG,OAAO,IAAI,OAAO,GAAG;GAC1D,OAAO;IACL,MAAM,OAAO,SAAS;IACtB,KAAK,OAAO,YAAY;KAAE,OAAO;KAAY,gBAAgB;KAAM,QAAQ;IAAG,CAAC;GACjF;EACF;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-b/do-runtime",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Cloudflare's Durable Object runtime (workerd), ported to TypeScript: actors with input/output gates, SQLite storage, facets and alarms, running in the browser and in Node.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"actors",
|