opencode-gateway 0.2.6 → 0.2.8
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 +131 -57
- package/dist/store/database.d.ts +1 -8
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -12688,8 +12688,8 @@ var require_pattern = __commonJS((exports) => {
|
|
|
12688
12688
|
}
|
|
12689
12689
|
exports.endsWithSlashGlobStar = endsWithSlashGlobStar;
|
|
12690
12690
|
function isAffectDepthOfReadingPattern(pattern) {
|
|
12691
|
-
const
|
|
12692
|
-
return endsWithSlashGlobStar(pattern) || isStaticPattern(
|
|
12691
|
+
const basename2 = path.basename(pattern);
|
|
12692
|
+
return endsWithSlashGlobStar(pattern) || isStaticPattern(basename2);
|
|
12693
12693
|
}
|
|
12694
12694
|
exports.isAffectDepthOfReadingPattern = isAffectDepthOfReadingPattern;
|
|
12695
12695
|
function expandPatternsWithBraceExpansion(patterns) {
|
|
@@ -14931,38 +14931,74 @@ var require_out4 = __commonJS((exports, module) => {
|
|
|
14931
14931
|
// src/store/database.ts
|
|
14932
14932
|
var exports_database = {};
|
|
14933
14933
|
__export(exports_database, {
|
|
14934
|
-
|
|
14934
|
+
openRuntimeSqliteDatabase: () => openRuntimeSqliteDatabase
|
|
14935
14935
|
});
|
|
14936
|
-
|
|
14937
|
-
|
|
14938
|
-
|
|
14939
|
-
db;
|
|
14940
|
-
constructor(path) {
|
|
14941
|
-
this.db = new BetterSqlite3(path);
|
|
14942
|
-
}
|
|
14943
|
-
exec(source) {
|
|
14944
|
-
this.db.exec(source);
|
|
14945
|
-
}
|
|
14946
|
-
query(source) {
|
|
14947
|
-
const statement = this.db.prepare(source);
|
|
14948
|
-
return {
|
|
14949
|
-
get: (...params) => statement.get(...toSqliteParams(params)),
|
|
14950
|
-
all: (...params) => statement.all(...toSqliteParams(params)),
|
|
14951
|
-
run: (...params) => {
|
|
14952
|
-
const result = statement.run(...toSqliteParams(params));
|
|
14953
|
-
return {
|
|
14954
|
-
changes: result.changes,
|
|
14955
|
-
lastInsertRowid: result.lastInsertRowid
|
|
14956
|
-
};
|
|
14957
|
-
}
|
|
14958
|
-
};
|
|
14959
|
-
}
|
|
14960
|
-
transaction(handler) {
|
|
14961
|
-
return this.db.transaction((...args) => handler(...args));
|
|
14962
|
-
}
|
|
14963
|
-
close() {
|
|
14964
|
-
this.db.close();
|
|
14936
|
+
async function openRuntimeSqliteDatabase(path) {
|
|
14937
|
+
if (isBunRuntime()) {
|
|
14938
|
+
return await openBunSqliteDatabase(path);
|
|
14965
14939
|
}
|
|
14940
|
+
return await openNodeSqliteDatabase(path);
|
|
14941
|
+
}
|
|
14942
|
+
async function openNodeSqliteDatabase(path) {
|
|
14943
|
+
const module = await dynamicImport("better-sqlite3");
|
|
14944
|
+
const db2 = new module.default(path);
|
|
14945
|
+
return {
|
|
14946
|
+
exec(source) {
|
|
14947
|
+
db2.exec(source);
|
|
14948
|
+
},
|
|
14949
|
+
query(source) {
|
|
14950
|
+
const statement = db2.prepare(source);
|
|
14951
|
+
return {
|
|
14952
|
+
get: (...params) => statement.get(...toSqliteParams(params)),
|
|
14953
|
+
all: (...params) => statement.all(...toSqliteParams(params)),
|
|
14954
|
+
run: (...params) => {
|
|
14955
|
+
const result = statement.run(...toSqliteParams(params));
|
|
14956
|
+
return {
|
|
14957
|
+
changes: result.changes,
|
|
14958
|
+
lastInsertRowid: result.lastInsertRowid
|
|
14959
|
+
};
|
|
14960
|
+
}
|
|
14961
|
+
};
|
|
14962
|
+
},
|
|
14963
|
+
transaction(handler) {
|
|
14964
|
+
return db2.transaction((...args) => handler(...args));
|
|
14965
|
+
},
|
|
14966
|
+
close() {
|
|
14967
|
+
db2.close();
|
|
14968
|
+
}
|
|
14969
|
+
};
|
|
14970
|
+
}
|
|
14971
|
+
async function openBunSqliteDatabase(path) {
|
|
14972
|
+
const module = await dynamicImport("bun:sqlite");
|
|
14973
|
+
const db2 = new module.Database(path);
|
|
14974
|
+
return {
|
|
14975
|
+
exec(source) {
|
|
14976
|
+
db2.exec(source);
|
|
14977
|
+
},
|
|
14978
|
+
query(source) {
|
|
14979
|
+
const statement = db2.query(source);
|
|
14980
|
+
return {
|
|
14981
|
+
get(...params) {
|
|
14982
|
+
return statement.get(...params);
|
|
14983
|
+
},
|
|
14984
|
+
all(...params) {
|
|
14985
|
+
return statement.all(...params);
|
|
14986
|
+
},
|
|
14987
|
+
run(...params) {
|
|
14988
|
+
return statement.run(...params);
|
|
14989
|
+
}
|
|
14990
|
+
};
|
|
14991
|
+
},
|
|
14992
|
+
transaction(handler) {
|
|
14993
|
+
return db2.transaction((...args) => handler(...args));
|
|
14994
|
+
},
|
|
14995
|
+
close() {
|
|
14996
|
+
db2.close();
|
|
14997
|
+
}
|
|
14998
|
+
};
|
|
14999
|
+
}
|
|
15000
|
+
function isBunRuntime() {
|
|
15001
|
+
return typeof globalThis === "object" && globalThis !== null && "Bun" in globalThis;
|
|
14966
15002
|
}
|
|
14967
15003
|
function toSqliteParams(params) {
|
|
14968
15004
|
return params.map((param) => {
|
|
@@ -14972,7 +15008,10 @@ function toSqliteParams(params) {
|
|
|
14972
15008
|
throw new Error(`unsupported SQLite parameter type: ${typeof param}`);
|
|
14973
15009
|
});
|
|
14974
15010
|
}
|
|
14975
|
-
var
|
|
15011
|
+
var dynamicImport;
|
|
15012
|
+
var init_database = __esm(() => {
|
|
15013
|
+
dynamicImport = new Function("specifier", "return import(specifier)");
|
|
15014
|
+
});
|
|
14976
15015
|
|
|
14977
15016
|
// src/binding/index.ts
|
|
14978
15017
|
import { access, readFile } from "node:fs/promises";
|
|
@@ -15017,7 +15056,7 @@ async function initializeGatewayBindingModule(module, entrypointUrl) {
|
|
|
15017
15056
|
}
|
|
15018
15057
|
|
|
15019
15058
|
// src/gateway.ts
|
|
15020
|
-
import { mkdir as
|
|
15059
|
+
import { mkdir as mkdir4 } from "node:fs/promises";
|
|
15021
15060
|
|
|
15022
15061
|
// src/config/gateway.ts
|
|
15023
15062
|
import { existsSync } from "node:fs";
|
|
@@ -16081,8 +16120,8 @@ function readOptionalString(value, field) {
|
|
|
16081
16120
|
}
|
|
16082
16121
|
|
|
16083
16122
|
// src/config/memory.ts
|
|
16084
|
-
import { stat } from "node:fs/promises";
|
|
16085
|
-
import { resolve } from "node:path";
|
|
16123
|
+
import { mkdir, stat, writeFile } from "node:fs/promises";
|
|
16124
|
+
import { basename, extname, resolve } from "node:path";
|
|
16086
16125
|
async function parseMemoryConfig(value, workspaceDirPath) {
|
|
16087
16126
|
const table = readMemoryTable(value);
|
|
16088
16127
|
const entries = await readMemoryEntries(table.entries, workspaceDirPath);
|
|
@@ -16115,7 +16154,7 @@ async function readMemoryEntry(value, index, workspaceDirPath) {
|
|
|
16115
16154
|
const displayPath = readRequiredString(entry.path, `${field}.path`);
|
|
16116
16155
|
const description = readRequiredString(entry.description, `${field}.description`);
|
|
16117
16156
|
const resolvedPath = resolve(workspaceDirPath, displayPath);
|
|
16118
|
-
const metadata = await
|
|
16157
|
+
const metadata = await ensurePathMetadata(resolvedPath, displayPath, entry, `${field}.path`);
|
|
16119
16158
|
if (metadata.isFile()) {
|
|
16120
16159
|
ensureDirectoryOnlyFieldIsAbsent(entry.inject_markdown_contents, `${field}.inject_markdown_contents`);
|
|
16121
16160
|
ensureDirectoryOnlyFieldIsAbsent(entry.globs, `${field}.globs`);
|
|
@@ -16140,13 +16179,48 @@ async function readMemoryEntry(value, index, workspaceDirPath) {
|
|
|
16140
16179
|
}
|
|
16141
16180
|
throw new Error(`${field}.path must point to a regular file or directory`);
|
|
16142
16181
|
}
|
|
16143
|
-
async function
|
|
16182
|
+
async function ensurePathMetadata(path, displayPath, entry, field) {
|
|
16144
16183
|
try {
|
|
16145
16184
|
return await stat(path);
|
|
16146
16185
|
} catch (error) {
|
|
16147
|
-
|
|
16186
|
+
if (!isMissingPathError(error)) {
|
|
16187
|
+
throw error;
|
|
16188
|
+
}
|
|
16189
|
+
const kind = inferMissingEntryKind(displayPath, entry);
|
|
16190
|
+
await createMissingEntryPath(path, kind);
|
|
16191
|
+
return await stat(path);
|
|
16148
16192
|
}
|
|
16149
16193
|
}
|
|
16194
|
+
function isMissingPathError(error) {
|
|
16195
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
16196
|
+
}
|
|
16197
|
+
function inferMissingEntryKind(displayPath, entry) {
|
|
16198
|
+
if (entry.inject_content !== undefined) {
|
|
16199
|
+
return "file";
|
|
16200
|
+
}
|
|
16201
|
+
if (entry.inject_markdown_contents !== undefined || entry.globs !== undefined) {
|
|
16202
|
+
return "directory";
|
|
16203
|
+
}
|
|
16204
|
+
const trimmedPath = displayPath.trim();
|
|
16205
|
+
if (trimmedPath.endsWith("/") || trimmedPath.endsWith("\\")) {
|
|
16206
|
+
return "directory";
|
|
16207
|
+
}
|
|
16208
|
+
const name = basename(trimmedPath);
|
|
16209
|
+
if (name.startsWith(".") || extname(name).length > 0) {
|
|
16210
|
+
return "file";
|
|
16211
|
+
}
|
|
16212
|
+
return "directory";
|
|
16213
|
+
}
|
|
16214
|
+
async function createMissingEntryPath(path, kind) {
|
|
16215
|
+
if (kind === "directory") {
|
|
16216
|
+
await mkdir(path, { recursive: true });
|
|
16217
|
+
return;
|
|
16218
|
+
}
|
|
16219
|
+
const lastSlash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
16220
|
+
const parentPath = lastSlash >= 0 ? path.slice(0, lastSlash) : ".";
|
|
16221
|
+
await mkdir(parentPath, { recursive: true });
|
|
16222
|
+
await writeFile(path, "", { flag: "a" });
|
|
16223
|
+
}
|
|
16150
16224
|
function ensureDirectoryOnlyFieldIsAbsent(value, field) {
|
|
16151
16225
|
if (value !== undefined) {
|
|
16152
16226
|
throw new Error(`${field} is only valid for directory entries`);
|
|
@@ -17324,7 +17398,7 @@ import { open } from "node:fs/promises";
|
|
|
17324
17398
|
* MIT Licensed
|
|
17325
17399
|
*/
|
|
17326
17400
|
var db = require_db();
|
|
17327
|
-
var
|
|
17401
|
+
var extname2 = __require("path").extname;
|
|
17328
17402
|
var mimeScore = require_mimeScore();
|
|
17329
17403
|
var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
|
|
17330
17404
|
var $extensions = Object.create(null);
|
|
@@ -17347,7 +17421,7 @@ function lookup(path) {
|
|
|
17347
17421
|
if (!path || typeof path !== "string") {
|
|
17348
17422
|
return false;
|
|
17349
17423
|
}
|
|
17350
|
-
var extension2 =
|
|
17424
|
+
var extension2 = extname2("x." + path).toLowerCase().slice(1);
|
|
17351
17425
|
if (!extension2) {
|
|
17352
17426
|
return false;
|
|
17353
17427
|
}
|
|
@@ -17543,7 +17617,7 @@ class GatewayMailboxRouter {
|
|
|
17543
17617
|
// src/memory/prompt.ts
|
|
17544
17618
|
var import_fast_glob = __toESM(require_out4(), 1);
|
|
17545
17619
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
17546
|
-
import { extname as
|
|
17620
|
+
import { extname as extname3, relative } from "node:path";
|
|
17547
17621
|
var MARKDOWN_GLOBS = ["**/*.md", "**/*.markdown"];
|
|
17548
17622
|
var UTF8_TEXT_DECODER = new TextDecoder("utf-8", { fatal: true });
|
|
17549
17623
|
|
|
@@ -17649,7 +17723,7 @@ function relativeDisplayPath(rootPath, rootDisplayPath, filePath) {
|
|
|
17649
17723
|
return `${rootDisplayPath}/${suffix.replaceAll("\\", "/")}`;
|
|
17650
17724
|
}
|
|
17651
17725
|
function inferFenceInfoString(path) {
|
|
17652
|
-
const extension2 =
|
|
17726
|
+
const extension2 = extname3(path).slice(1).toLowerCase();
|
|
17653
17727
|
if (!/^[a-z0-9_+-]+$/.test(extension2)) {
|
|
17654
17728
|
return "";
|
|
17655
17729
|
}
|
|
@@ -17668,7 +17742,7 @@ function formatError2(error) {
|
|
|
17668
17742
|
}
|
|
17669
17743
|
|
|
17670
17744
|
// src/opencode/adapter.ts
|
|
17671
|
-
import { basename } from "node:path";
|
|
17745
|
+
import { basename as basename2 } from "node:path";
|
|
17672
17746
|
import { pathToFileURL } from "node:url";
|
|
17673
17747
|
|
|
17674
17748
|
// src/runtime/delay.ts
|
|
@@ -17910,7 +17984,7 @@ function toSessionPromptPart(part) {
|
|
|
17910
17984
|
type: "file",
|
|
17911
17985
|
mime: part.mimeType,
|
|
17912
17986
|
url: pathToFileURL(part.localPath).href,
|
|
17913
|
-
filename: part.fileName ??
|
|
17987
|
+
filename: part.fileName ?? basename2(part.localPath)
|
|
17914
17988
|
};
|
|
17915
17989
|
}
|
|
17916
17990
|
}
|
|
@@ -22388,7 +22462,7 @@ function buildGatewayContextPrompt(targets) {
|
|
|
22388
22462
|
}
|
|
22389
22463
|
|
|
22390
22464
|
// src/store/sqlite.ts
|
|
22391
|
-
import { mkdir } from "node:fs/promises";
|
|
22465
|
+
import { mkdir as mkdir2 } from "node:fs/promises";
|
|
22392
22466
|
import { dirname as dirname3 } from "node:path";
|
|
22393
22467
|
|
|
22394
22468
|
// src/store/migrations.ts
|
|
@@ -23303,15 +23377,15 @@ function readBooleanField(value, field, fallback) {
|
|
|
23303
23377
|
return raw;
|
|
23304
23378
|
}
|
|
23305
23379
|
async function openSqliteStore(path) {
|
|
23306
|
-
await
|
|
23307
|
-
const {
|
|
23308
|
-
const db2 =
|
|
23380
|
+
await mkdir2(dirname3(path), { recursive: true });
|
|
23381
|
+
const { openRuntimeSqliteDatabase: openRuntimeSqliteDatabase2 } = await Promise.resolve().then(() => (init_database(), exports_database));
|
|
23382
|
+
const db2 = await openRuntimeSqliteDatabase2(path);
|
|
23309
23383
|
migrateGatewayDatabase(db2);
|
|
23310
23384
|
return new SqliteStore(db2);
|
|
23311
23385
|
}
|
|
23312
23386
|
|
|
23313
23387
|
// src/telegram/client.ts
|
|
23314
|
-
import { readFile as readFile4, writeFile } from "node:fs/promises";
|
|
23388
|
+
import { readFile as readFile4, writeFile as writeFile2 } from "node:fs/promises";
|
|
23315
23389
|
class TelegramApiError extends Error {
|
|
23316
23390
|
retryable;
|
|
23317
23391
|
constructor(message, retryable) {
|
|
@@ -23356,7 +23430,7 @@ class TelegramBotClient {
|
|
|
23356
23430
|
if (!response.ok) {
|
|
23357
23431
|
throw new TelegramApiError(`Telegram file download failed (${response.status}): ${response.statusText}`, isRetryableError(response.status, response.status));
|
|
23358
23432
|
}
|
|
23359
|
-
await
|
|
23433
|
+
await writeFile2(localPath, new Uint8Array(await response.arrayBuffer()));
|
|
23360
23434
|
}
|
|
23361
23435
|
async sendMessage(chatId, text, messageThreadId) {
|
|
23362
23436
|
await this.call("sendMessage", {
|
|
@@ -23500,8 +23574,8 @@ function isRetryableError(errorCode, httpStatus) {
|
|
|
23500
23574
|
}
|
|
23501
23575
|
|
|
23502
23576
|
// src/telegram/media.ts
|
|
23503
|
-
import { mkdir as
|
|
23504
|
-
import { basename as
|
|
23577
|
+
import { mkdir as mkdir3 } from "node:fs/promises";
|
|
23578
|
+
import { basename as basename3, extname as extname4, join as join3 } from "node:path";
|
|
23505
23579
|
class TelegramInboundMediaStore {
|
|
23506
23580
|
client;
|
|
23507
23581
|
mediaRootPath;
|
|
@@ -23530,9 +23604,9 @@ class TelegramInboundMediaStore {
|
|
|
23530
23604
|
if (!remotePath) {
|
|
23531
23605
|
throw new Error(`Telegram file ${attachment.fileId} did not include file_path`);
|
|
23532
23606
|
}
|
|
23533
|
-
const fileName = normalizeOptionalFileName(attachment.fileName) ?? normalizeOptionalFileName(
|
|
23607
|
+
const fileName = normalizeOptionalFileName(attachment.fileName) ?? normalizeOptionalFileName(basename3(remotePath)) ?? `telegram-image-${ordinal + 1}${extensionFromRemotePath(remotePath)}`;
|
|
23534
23608
|
const localPath = join3(this.mediaRootPath, "telegram", sanitizePathSegment(sourceKind), sanitizePathSegment(externalId), `${ordinal}-${sanitizePathSegment(fileName)}`);
|
|
23535
|
-
await
|
|
23609
|
+
await mkdir3(join3(this.mediaRootPath, "telegram", sanitizePathSegment(sourceKind), sanitizePathSegment(externalId)), {
|
|
23536
23610
|
recursive: true
|
|
23537
23611
|
});
|
|
23538
23612
|
await this.client.downloadFile(remotePath, localPath);
|
|
@@ -23555,7 +23629,7 @@ function normalizeOptionalFileName(value) {
|
|
|
23555
23629
|
return trimmed.length === 0 ? null : trimmed;
|
|
23556
23630
|
}
|
|
23557
23631
|
function extensionFromRemotePath(remotePath) {
|
|
23558
|
-
const extension2 =
|
|
23632
|
+
const extension2 = extname4(remotePath);
|
|
23559
23633
|
return extension2.length === 0 ? ".bin" : extension2;
|
|
23560
23634
|
}
|
|
23561
23635
|
|
|
@@ -24063,7 +24137,7 @@ class GatewayPluginRuntime {
|
|
|
24063
24137
|
async function createGatewayRuntime(module, input) {
|
|
24064
24138
|
const config = await loadGatewayConfig();
|
|
24065
24139
|
return await getOrCreateRuntimeSingleton(config.configPath, async () => {
|
|
24066
|
-
await
|
|
24140
|
+
await mkdir4(config.workspaceDirPath, { recursive: true });
|
|
24067
24141
|
const logger = new ConsoleLoggerHost(config.logLevel);
|
|
24068
24142
|
if (config.hasLegacyGatewayTimezone) {
|
|
24069
24143
|
const suffix = config.legacyGatewayTimezone === null ? "" : ` (${config.legacyGatewayTimezone})`;
|
package/dist/store/database.d.ts
CHANGED
|
@@ -12,11 +12,4 @@ export type SqliteDatabaseLike = {
|
|
|
12
12
|
transaction<Args extends unknown[], Result>(handler: (...args: Args) => Result): (...args: Args) => Result;
|
|
13
13
|
close(): void;
|
|
14
14
|
};
|
|
15
|
-
export declare
|
|
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
|
-
}
|
|
15
|
+
export declare function openRuntimeSqliteDatabase(path: string): Promise<SqliteDatabaseLike>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-gateway",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
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 && node ./scripts/build.mjs && node ./scripts/smoke-node-import.mjs",
|
|
28
|
+
"check": "tsc --noEmit --project tsconfig.json && bun test src && node ./scripts/build.mjs && node ./scripts/smoke-node-import.mjs && bun ./scripts/smoke-bun-import.mjs",
|
|
29
29
|
"prepack": "npm run build:wasm && npm run build",
|
|
30
30
|
"test": "bun test src"
|
|
31
31
|
},
|