opencode-gateway 0.2.5 → 0.2.6
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/index.js
CHANGED
|
@@ -14975,18 +14975,29 @@ function toSqliteParams(params) {
|
|
|
14975
14975
|
var init_database = () => {};
|
|
14976
14976
|
|
|
14977
14977
|
// src/binding/index.ts
|
|
14978
|
-
import { access } from "node:fs/promises";
|
|
14979
|
-
var
|
|
14978
|
+
import { access, readFile } from "node:fs/promises";
|
|
14979
|
+
var GENERATED_WASM_ENTRYPOINT_CANDIDATES = [
|
|
14980
14980
|
new URL("../generated/wasm/pkg/opencode_gateway_ffi.js", import.meta.url),
|
|
14981
14981
|
new URL("../../generated/wasm/pkg/opencode_gateway_ffi.js", import.meta.url)
|
|
14982
14982
|
];
|
|
14983
|
+
var cachedBindingModulePromise = null;
|
|
14983
14984
|
async function loadGatewayBindingModule() {
|
|
14984
|
-
|
|
14985
|
-
|
|
14986
|
-
|
|
14985
|
+
if (cachedBindingModulePromise !== null) {
|
|
14986
|
+
return await cachedBindingModulePromise;
|
|
14987
|
+
}
|
|
14988
|
+
cachedBindingModulePromise = loadGatewayBindingModuleOnce();
|
|
14989
|
+
return await cachedBindingModulePromise;
|
|
14990
|
+
}
|
|
14991
|
+
async function loadGatewayBindingModuleOnce() {
|
|
14992
|
+
for (const entrypointUrl of GENERATED_WASM_ENTRYPOINT_CANDIDATES) {
|
|
14993
|
+
if (!await canReadFile(entrypointUrl)) {
|
|
14994
|
+
continue;
|
|
14987
14995
|
}
|
|
14996
|
+
const module = await import(entrypointUrl.href);
|
|
14997
|
+
await initializeGatewayBindingModule(module, entrypointUrl);
|
|
14998
|
+
return module;
|
|
14988
14999
|
}
|
|
14989
|
-
throw new Error(`Unable to locate generated gateway wasm entrypoint. Checked: ${
|
|
15000
|
+
throw new Error(`Unable to locate generated gateway wasm entrypoint. Checked: ${GENERATED_WASM_ENTRYPOINT_CANDIDATES.map((candidate) => candidate.pathname).join(", ")}`);
|
|
14990
15001
|
}
|
|
14991
15002
|
async function canReadFile(candidate) {
|
|
14992
15003
|
try {
|
|
@@ -14996,13 +15007,21 @@ async function canReadFile(candidate) {
|
|
|
14996
15007
|
return false;
|
|
14997
15008
|
}
|
|
14998
15009
|
}
|
|
15010
|
+
async function initializeGatewayBindingModule(module, entrypointUrl) {
|
|
15011
|
+
if (module.initSync === undefined) {
|
|
15012
|
+
return;
|
|
15013
|
+
}
|
|
15014
|
+
const wasmUrl = new URL("./opencode_gateway_ffi_bg.wasm", entrypointUrl);
|
|
15015
|
+
const wasmBytes = await readFile(wasmUrl);
|
|
15016
|
+
module.initSync({ module: wasmBytes });
|
|
15017
|
+
}
|
|
14999
15018
|
|
|
15000
15019
|
// src/gateway.ts
|
|
15001
15020
|
import { mkdir as mkdir3 } from "node:fs/promises";
|
|
15002
15021
|
|
|
15003
15022
|
// src/config/gateway.ts
|
|
15004
15023
|
import { existsSync } from "node:fs";
|
|
15005
|
-
import { readFile } from "node:fs/promises";
|
|
15024
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
15006
15025
|
import { dirname as dirname2, isAbsolute, join as join2, resolve as resolve3 } from "node:path";
|
|
15007
15026
|
|
|
15008
15027
|
// ../../node_modules/.bun/smol-toml@1.6.1/node_modules/smol-toml/dist/error.js
|
|
@@ -16331,7 +16350,7 @@ async function readGatewayConfigFile(path) {
|
|
|
16331
16350
|
if (!existsSync(path)) {
|
|
16332
16351
|
return null;
|
|
16333
16352
|
}
|
|
16334
|
-
const source = await
|
|
16353
|
+
const source = await readFile2(path, "utf8");
|
|
16335
16354
|
const parsed = parse(source);
|
|
16336
16355
|
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
16337
16356
|
throw new Error(`gateway config must decode to a table: ${path}`);
|
|
@@ -17523,7 +17542,7 @@ class GatewayMailboxRouter {
|
|
|
17523
17542
|
|
|
17524
17543
|
// src/memory/prompt.ts
|
|
17525
17544
|
var import_fast_glob = __toESM(require_out4(), 1);
|
|
17526
|
-
import { readFile as
|
|
17545
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
17527
17546
|
import { extname as extname2, relative } from "node:path";
|
|
17528
17547
|
var MARKDOWN_GLOBS = ["**/*.md", "**/*.markdown"];
|
|
17529
17548
|
var UTF8_TEXT_DECODER = new TextDecoder("utf-8", { fatal: true });
|
|
@@ -17604,7 +17623,7 @@ function addMatchingFiles(result, cwd, pattern) {
|
|
|
17604
17623
|
async function readTextFile(path, logger) {
|
|
17605
17624
|
let bytes;
|
|
17606
17625
|
try {
|
|
17607
|
-
bytes = await
|
|
17626
|
+
bytes = await readFile3(path);
|
|
17608
17627
|
} catch (error) {
|
|
17609
17628
|
logger.log("warn", `memory file could not be read and will be skipped: ${path}: ${formatError2(error)}`);
|
|
17610
17629
|
return null;
|
|
@@ -23292,7 +23311,7 @@ async function openSqliteStore(path) {
|
|
|
23292
23311
|
}
|
|
23293
23312
|
|
|
23294
23313
|
// src/telegram/client.ts
|
|
23295
|
-
import { readFile as
|
|
23314
|
+
import { readFile as readFile4, writeFile } from "node:fs/promises";
|
|
23296
23315
|
class TelegramApiError extends Error {
|
|
23297
23316
|
retryable;
|
|
23298
23317
|
constructor(message, retryable) {
|
|
@@ -23436,7 +23455,7 @@ class TelegramBotClient {
|
|
|
23436
23455
|
}
|
|
23437
23456
|
}
|
|
23438
23457
|
async function readLocalFileBlob(filePath, mimeType) {
|
|
23439
|
-
const bytes = await
|
|
23458
|
+
const bytes = await readFile4(filePath);
|
|
23440
23459
|
return new Blob([bytes], { type: mimeType });
|
|
23441
23460
|
}
|
|
23442
23461
|
function inferUploadFileName(filePath) {
|
|
@@ -21,3 +21,50 @@ export function normalizeCronTimeZone(time_zone: string): string;
|
|
|
21
21
|
export function prepareCronExecution(job: any): any;
|
|
22
22
|
|
|
23
23
|
export function prepareInboundExecution(message: any): any;
|
|
24
|
+
|
|
25
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
26
|
+
|
|
27
|
+
export interface InitOutput {
|
|
28
|
+
readonly memory: WebAssembly.Memory;
|
|
29
|
+
readonly conversationKeyForDeliveryTarget: (a: any) => [number, number, number, number];
|
|
30
|
+
readonly gatewayStatus: () => [number, number, number];
|
|
31
|
+
readonly nextCronRunAt: (a: any, b: number, c: number, d: number) => [number, number, number];
|
|
32
|
+
readonly normalizeCronTimeZone: (a: number, b: number) => [number, number, number, number];
|
|
33
|
+
readonly __wbg_opencodeexecutiondriver_free: (a: number, b: number) => void;
|
|
34
|
+
readonly opencodeexecutiondriver_new: (a: any) => [number, number, number];
|
|
35
|
+
readonly opencodeexecutiondriver_observeEvent: (a: number, b: any, c: number) => [number, number, number];
|
|
36
|
+
readonly opencodeexecutiondriver_resume: (a: number, b: any) => [number, number, number];
|
|
37
|
+
readonly opencodeexecutiondriver_start: (a: number) => [number, number, number];
|
|
38
|
+
readonly prepareCronExecution: (a: any) => [number, number, number];
|
|
39
|
+
readonly prepareInboundExecution: (a: any) => [number, number, number];
|
|
40
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
41
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
42
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
43
|
+
readonly __externref_table_alloc: () => number;
|
|
44
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
45
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
46
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
47
|
+
readonly __wbindgen_start: () => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
54
|
+
* a precompiled `WebAssembly.Module`.
|
|
55
|
+
*
|
|
56
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
57
|
+
*
|
|
58
|
+
* @returns {InitOutput}
|
|
59
|
+
*/
|
|
60
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
64
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
65
|
+
*
|
|
66
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
67
|
+
*
|
|
68
|
+
* @returns {Promise<InitOutput>}
|
|
69
|
+
*/
|
|
70
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* @ts-self-types="./opencode_gateway_ffi.d.ts" */
|
|
2
2
|
|
|
3
|
-
class OpencodeExecutionDriver {
|
|
3
|
+
export class OpencodeExecutionDriver {
|
|
4
4
|
__destroy_into_raw() {
|
|
5
5
|
const ptr = this.__wbg_ptr;
|
|
6
6
|
this.__wbg_ptr = 0;
|
|
@@ -58,13 +58,12 @@ class OpencodeExecutionDriver {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
if (Symbol.dispose) OpencodeExecutionDriver.prototype[Symbol.dispose] = OpencodeExecutionDriver.prototype.free;
|
|
61
|
-
exports.OpencodeExecutionDriver = OpencodeExecutionDriver;
|
|
62
61
|
|
|
63
62
|
/**
|
|
64
63
|
* @param {any} target
|
|
65
64
|
* @returns {string}
|
|
66
65
|
*/
|
|
67
|
-
function conversationKeyForDeliveryTarget(target) {
|
|
66
|
+
export function conversationKeyForDeliveryTarget(target) {
|
|
68
67
|
let deferred2_0;
|
|
69
68
|
let deferred2_1;
|
|
70
69
|
try {
|
|
@@ -82,19 +81,17 @@ function conversationKeyForDeliveryTarget(target) {
|
|
|
82
81
|
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
|
-
exports.conversationKeyForDeliveryTarget = conversationKeyForDeliveryTarget;
|
|
86
84
|
|
|
87
85
|
/**
|
|
88
86
|
* @returns {any}
|
|
89
87
|
*/
|
|
90
|
-
function gatewayStatus() {
|
|
88
|
+
export function gatewayStatus() {
|
|
91
89
|
const ret = wasm.gatewayStatus();
|
|
92
90
|
if (ret[2]) {
|
|
93
91
|
throw takeFromExternrefTable0(ret[1]);
|
|
94
92
|
}
|
|
95
93
|
return takeFromExternrefTable0(ret[0]);
|
|
96
94
|
}
|
|
97
|
-
exports.gatewayStatus = gatewayStatus;
|
|
98
95
|
|
|
99
96
|
/**
|
|
100
97
|
* @param {any} job
|
|
@@ -102,7 +99,7 @@ exports.gatewayStatus = gatewayStatus;
|
|
|
102
99
|
* @param {string} time_zone
|
|
103
100
|
* @returns {number}
|
|
104
101
|
*/
|
|
105
|
-
function nextCronRunAt(job, after_ms, time_zone) {
|
|
102
|
+
export function nextCronRunAt(job, after_ms, time_zone) {
|
|
106
103
|
const ptr0 = passStringToWasm0(time_zone, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
107
104
|
const len0 = WASM_VECTOR_LEN;
|
|
108
105
|
const ret = wasm.nextCronRunAt(job, after_ms, ptr0, len0);
|
|
@@ -111,13 +108,12 @@ function nextCronRunAt(job, after_ms, time_zone) {
|
|
|
111
108
|
}
|
|
112
109
|
return ret[0];
|
|
113
110
|
}
|
|
114
|
-
exports.nextCronRunAt = nextCronRunAt;
|
|
115
111
|
|
|
116
112
|
/**
|
|
117
113
|
* @param {string} time_zone
|
|
118
114
|
* @returns {string}
|
|
119
115
|
*/
|
|
120
|
-
function normalizeCronTimeZone(time_zone) {
|
|
116
|
+
export function normalizeCronTimeZone(time_zone) {
|
|
121
117
|
let deferred3_0;
|
|
122
118
|
let deferred3_1;
|
|
123
119
|
try {
|
|
@@ -137,33 +133,30 @@ function normalizeCronTimeZone(time_zone) {
|
|
|
137
133
|
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
138
134
|
}
|
|
139
135
|
}
|
|
140
|
-
exports.normalizeCronTimeZone = normalizeCronTimeZone;
|
|
141
136
|
|
|
142
137
|
/**
|
|
143
138
|
* @param {any} job
|
|
144
139
|
* @returns {any}
|
|
145
140
|
*/
|
|
146
|
-
function prepareCronExecution(job) {
|
|
141
|
+
export function prepareCronExecution(job) {
|
|
147
142
|
const ret = wasm.prepareCronExecution(job);
|
|
148
143
|
if (ret[2]) {
|
|
149
144
|
throw takeFromExternrefTable0(ret[1]);
|
|
150
145
|
}
|
|
151
146
|
return takeFromExternrefTable0(ret[0]);
|
|
152
147
|
}
|
|
153
|
-
exports.prepareCronExecution = prepareCronExecution;
|
|
154
148
|
|
|
155
149
|
/**
|
|
156
150
|
* @param {any} message
|
|
157
151
|
* @returns {any}
|
|
158
152
|
*/
|
|
159
|
-
function prepareInboundExecution(message) {
|
|
153
|
+
export function prepareInboundExecution(message) {
|
|
160
154
|
const ret = wasm.prepareInboundExecution(message);
|
|
161
155
|
if (ret[2]) {
|
|
162
156
|
throw takeFromExternrefTable0(ret[1]);
|
|
163
157
|
}
|
|
164
158
|
return takeFromExternrefTable0(ret[0]);
|
|
165
159
|
}
|
|
166
|
-
exports.prepareInboundExecution = prepareInboundExecution;
|
|
167
160
|
|
|
168
161
|
function __wbg_get_imports() {
|
|
169
162
|
const import0 = {
|
|
@@ -548,7 +541,15 @@ function takeFromExternrefTable0(idx) {
|
|
|
548
541
|
|
|
549
542
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
550
543
|
cachedTextDecoder.decode();
|
|
544
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
545
|
+
let numBytesDecoded = 0;
|
|
551
546
|
function decodeText(ptr, len) {
|
|
547
|
+
numBytesDecoded += len;
|
|
548
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
549
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
550
|
+
cachedTextDecoder.decode();
|
|
551
|
+
numBytesDecoded = len;
|
|
552
|
+
}
|
|
552
553
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
553
554
|
}
|
|
554
555
|
|
|
@@ -567,8 +568,95 @@ if (!('encodeInto' in cachedTextEncoder)) {
|
|
|
567
568
|
|
|
568
569
|
let WASM_VECTOR_LEN = 0;
|
|
569
570
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
571
|
+
let wasmModule, wasm;
|
|
572
|
+
function __wbg_finalize_init(instance, module) {
|
|
573
|
+
wasm = instance.exports;
|
|
574
|
+
wasmModule = module;
|
|
575
|
+
cachedDataViewMemory0 = null;
|
|
576
|
+
cachedUint8ArrayMemory0 = null;
|
|
577
|
+
wasm.__wbindgen_start();
|
|
578
|
+
return wasm;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
async function __wbg_load(module, imports) {
|
|
582
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
583
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
584
|
+
try {
|
|
585
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
586
|
+
} catch (e) {
|
|
587
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
588
|
+
|
|
589
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
590
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
591
|
+
|
|
592
|
+
} else { throw e; }
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const bytes = await module.arrayBuffer();
|
|
597
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
598
|
+
} else {
|
|
599
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
600
|
+
|
|
601
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
602
|
+
return { instance, module };
|
|
603
|
+
} else {
|
|
604
|
+
return instance;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function expectedResponseType(type) {
|
|
609
|
+
switch (type) {
|
|
610
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
611
|
+
}
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function initSync(module) {
|
|
617
|
+
if (wasm !== undefined) return wasm;
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
if (module !== undefined) {
|
|
621
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
622
|
+
({module} = module)
|
|
623
|
+
} else {
|
|
624
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
const imports = __wbg_get_imports();
|
|
629
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
630
|
+
module = new WebAssembly.Module(module);
|
|
631
|
+
}
|
|
632
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
633
|
+
return __wbg_finalize_init(instance, module);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
async function __wbg_init(module_or_path) {
|
|
637
|
+
if (wasm !== undefined) return wasm;
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
if (module_or_path !== undefined) {
|
|
641
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
642
|
+
({module_or_path} = module_or_path)
|
|
643
|
+
} else {
|
|
644
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
if (module_or_path === undefined) {
|
|
649
|
+
module_or_path = new URL('opencode_gateway_ffi_bg.wasm', import.meta.url);
|
|
650
|
+
}
|
|
651
|
+
const imports = __wbg_get_imports();
|
|
652
|
+
|
|
653
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
654
|
+
module_or_path = fetch(module_or_path);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
658
|
+
|
|
659
|
+
return __wbg_finalize_init(instance, module);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
export { initSync, __wbg_init as default };
|