opencode-gateway 0.2.4 → 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.
@@ -0,0 +1 @@
1
+ export declare function delay(durationMs: number): Promise<void>;
@@ -0,0 +1,22 @@
1
+ export type SqliteQueryStatementLike<Row, Params extends unknown[]> = {
2
+ get(...params: Params): Row | undefined;
3
+ all(...params: Params): Row[];
4
+ run(...params: Params): {
5
+ changes: number;
6
+ lastInsertRowid: bigint | number;
7
+ };
8
+ };
9
+ export type SqliteDatabaseLike = {
10
+ exec(source: string): void;
11
+ query<Row, Params extends unknown[]>(source: string): SqliteQueryStatementLike<Row, Params>;
12
+ transaction<Args extends unknown[], Result>(handler: (...args: Args) => Result): (...args: Args) => Result;
13
+ close(): void;
14
+ };
15
+ export declare class SqliteDatabase implements SqliteDatabaseLike {
16
+ private readonly db;
17
+ constructor(path: string);
18
+ exec(source: string): void;
19
+ query<Row, Params extends unknown[]>(source: string): SqliteQueryStatementLike<Row, Params>;
20
+ transaction<Args extends unknown[], Result>(handler: (...args: Args) => Result): (...args: Args) => Result;
21
+ close(): void;
22
+ }
@@ -1,2 +1,2 @@
1
- import type { Database } from "bun:sqlite";
2
- export declare function migrateGatewayDatabase(db: Database): void;
1
+ import type { SqliteDatabaseLike } from "./database";
2
+ export declare function migrateGatewayDatabase(db: SqliteDatabaseLike): void;
@@ -1,6 +1,6 @@
1
- import { Database } from "bun:sqlite";
2
1
  import type { BindingDeliveryTarget } from "../binding";
3
2
  import type { GatewayQuestionInfo, PendingQuestionRecord } from "../questions/types";
3
+ import type { SqliteDatabaseLike } from "./database";
4
4
  export type RuntimeJournalKind = "inbound_message" | "cron_dispatch" | "delivery" | "mailbox_enqueue" | "mailbox_flush";
5
5
  export type CronRunStatus = "running" | "succeeded" | "failed" | "abandoned";
6
6
  export type ScheduleJobKind = "cron" | "once";
@@ -103,7 +103,7 @@ export type PersistPendingQuestionInput = {
103
103
  };
104
104
  export declare class SqliteStore {
105
105
  private readonly db;
106
- constructor(db: Database);
106
+ constructor(db: SqliteDatabaseLike);
107
107
  getSessionBinding(conversationKey: string): string | null;
108
108
  putSessionBinding(conversationKey: string, sessionId: string, recordedAtMs: number): void;
109
109
  putSessionBindingIfUnchanged(conversationKey: string, expectedSessionId: string | null, nextSessionId: string, recordedAtMs: number): boolean;
@@ -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
- const wasmPath = `${__dirname}/opencode_gateway_ffi_bg.wasm`;
571
- const wasmBytes = require('fs').readFileSync(wasmPath);
572
- const wasmModule = new WebAssembly.Module(wasmBytes);
573
- let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
574
- wasm.__wbindgen_start();
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-gateway",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Gateway plugin for OpenCode",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "scripts": {
26
26
  "build": "node ./scripts/build.mjs",
27
27
  "build:wasm": "node ../../scripts/build-binding.mjs",
28
- "check": "tsc --noEmit --project tsconfig.json && bun test src",
28
+ "check": "tsc --noEmit --project tsconfig.json && bun test src && node ./scripts/build.mjs && node ./scripts/smoke-node-import.mjs",
29
29
  "prepack": "npm run build:wasm && npm run build",
30
30
  "test": "bun test src"
31
31
  },
@@ -53,9 +53,15 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@opencode-ai/plugin": "~1.3.0",
56
- "@opencode-ai/sdk": "~1.3.0"
56
+ "@opencode-ai/sdk": "~1.3.0",
57
+ "better-sqlite3": "^12.8.0",
58
+ "fast-glob": "^3.3.3",
59
+ "mime-types": "^3.0.2",
60
+ "smol-toml": "^1.6.1"
57
61
  },
58
62
  "devDependencies": {
63
+ "@types/better-sqlite3": "^7.6.13",
64
+ "@types/mime-types": "^3.0.1",
59
65
  "bun-types": "^1.3.11"
60
66
  }
61
67
  }