@opencode/codemode 0.0.0-dev-1266 → 0.0.0-dev-1274
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/extension.d.ts +6 -0
- package/dist/extension.js +9 -0
- package/dist/runtime/extensions.js +38 -3
- package/package.json +1 -1
package/dist/extension.d.ts
CHANGED
|
@@ -37,6 +37,12 @@ export type Services<E> = E extends {
|
|
|
37
37
|
type GlobalServices<Global> = Global extends (...args: never) => unknown ? Requirements<Global> : Global extends object ? Requirements<Global[keyof Global]> : never;
|
|
38
38
|
type Requirements<F> = F extends (...args: never) => infer Result ? Effect.Services<Result> : never;
|
|
39
39
|
export declare const make: <const Globals extends Readonly<Record<string, unknown>>>(options: Extension<Globals>) => Extension<Globals>;
|
|
40
|
+
/** A live fetch response whose I/O is owned by the host for the lifetime of the program. */
|
|
41
|
+
export declare class StreamingResponse {
|
|
42
|
+
readonly response: Response;
|
|
43
|
+
readonly redirected: boolean;
|
|
44
|
+
constructor(response: Response, redirected?: boolean);
|
|
45
|
+
}
|
|
40
46
|
/** Marks a global that returns a Promise or an Effect, so a denied call rejects its promise instead of throwing. */
|
|
41
47
|
export declare const async: <F extends Function>(global: F) => F;
|
|
42
48
|
export declare const isAsync: (global: Function) => boolean;
|
package/dist/extension.js
CHANGED
|
@@ -12,6 +12,15 @@ export const make = (options) => {
|
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
const asyncGlobals = new WeakSet();
|
|
15
|
+
/** A live fetch response whose I/O is owned by the host for the lifetime of the program. */
|
|
16
|
+
export class StreamingResponse {
|
|
17
|
+
response;
|
|
18
|
+
redirected;
|
|
19
|
+
constructor(response, redirected = response.redirected) {
|
|
20
|
+
this.response = response;
|
|
21
|
+
this.redirected = redirected;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
15
24
|
const AsyncFunction = (async () => { }).constructor;
|
|
16
25
|
/** Marks a global that returns a Promise or an Effect, so a denied call rejects its promise instead of throwing. */
|
|
17
26
|
export const async = (global) => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { isAsync } from "../extension.js";
|
|
2
|
+
import { isAsync, StreamingResponse } from "../extension.js";
|
|
3
3
|
import { hooked } from "../tool-runtime.js";
|
|
4
4
|
import { errorMessage, errorType } from "./errors.js";
|
|
5
5
|
import { createErrorValue } from "./intrinsics.js";
|
|
6
6
|
import { MAX_ARRAY_LENGTH, MAX_VALUE_DEPTH } from "./limits.js";
|
|
7
|
-
import { PendingThrow, rangeError, Throw, typeError } from "./model.js";
|
|
7
|
+
import { AsyncIteratorSymbol, PendingThrow, rangeError, Throw, typeError } from "./model.js";
|
|
8
8
|
import { native } from "./native.js";
|
|
9
|
-
import { define, get, has, hidden, keys, Arr, Bytes, DateObj, ErrorObj, HeadersObj, PromiseObj, MapObj, Obj, RegExpObj, SetObj, URLObj, URLSearchParamsObj, coerceToString, } from "./objects.js";
|
|
9
|
+
import { define, defineAccessor, get, has, hidden, keys, Arr, Bytes, DateObj, ErrorObj, HeadersObj, PromiseObj, MapObj, Obj, RegExpObj, SetObj, URLObj, URLSearchParamsObj, coerceToString, } from "./objects.js";
|
|
10
10
|
import { describeValue, isOpaque } from "./references.js";
|
|
11
11
|
import { Push } from "./signals.js";
|
|
12
12
|
import { SnapshotError } from "../snapshot/codec.js";
|
|
@@ -74,6 +74,41 @@ export const extensionGlobals = (ctx, extensions) => {
|
|
|
74
74
|
// method could hand back host storage or an object (`getTime`, `slice`, `map`), its internal data is read.
|
|
75
75
|
if (value instanceof Date)
|
|
76
76
|
return new DateObj(builtins.Date, Date.prototype.getTime.call(value));
|
|
77
|
+
if (value instanceof StreamingResponse) {
|
|
78
|
+
const response = value.response;
|
|
79
|
+
const body = response.body;
|
|
80
|
+
const stream = new Obj(builtins.Object);
|
|
81
|
+
if (body) {
|
|
82
|
+
defineAccessor(stream, "locked", () => body.locked);
|
|
83
|
+
define(stream, "cancel", next(async (reason) => body.cancel(reason), `${label}.body.cancel`));
|
|
84
|
+
define(stream, "getReader", next((options) => {
|
|
85
|
+
if (options?.mode !== undefined)
|
|
86
|
+
throw new TypeError("Only the default stream reader is supported.");
|
|
87
|
+
const reader = body.getReader();
|
|
88
|
+
return {
|
|
89
|
+
read: async () => reader.read(),
|
|
90
|
+
cancel: async (reason) => reader.cancel(reason),
|
|
91
|
+
releaseLock: () => reader.releaseLock(),
|
|
92
|
+
};
|
|
93
|
+
}, `${label}.body.getReader`));
|
|
94
|
+
define(stream, AsyncIteratorSymbol, next(() => {
|
|
95
|
+
const iterator = body.values();
|
|
96
|
+
return {
|
|
97
|
+
next: async () => iterator.next(),
|
|
98
|
+
return: async () => iterator.return(),
|
|
99
|
+
};
|
|
100
|
+
}, `${label}.body[Symbol.asyncIterator]`));
|
|
101
|
+
}
|
|
102
|
+
const result = new Obj(builtins.Object);
|
|
103
|
+
for (const key of ["url", "status", "statusText", "ok", "headers"])
|
|
104
|
+
define(result, key, next(response[key], `${label}.${key}`));
|
|
105
|
+
define(result, "redirected", value.redirected);
|
|
106
|
+
define(result, "body", body ? stream : null);
|
|
107
|
+
defineAccessor(result, "bodyUsed", () => response.bodyUsed);
|
|
108
|
+
for (const key of ["text", "json", "bytes", "arrayBuffer"])
|
|
109
|
+
define(result, key, next(async () => response[key](), `${label}.${key}`));
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
77
112
|
if (value instanceof RegExp)
|
|
78
113
|
return new RegExpObj(builtins.RegExp, value.source, value.flags);
|
|
79
114
|
if (value instanceof Uint8Array)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode/codemode",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-1274",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|