opencode-gateway 0.2.6 → 0.2.7
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 +59 -24
- package/package.json +1 -1
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) {
|
|
@@ -15017,7 +15017,7 @@ async function initializeGatewayBindingModule(module, entrypointUrl) {
|
|
|
15017
15017
|
}
|
|
15018
15018
|
|
|
15019
15019
|
// src/gateway.ts
|
|
15020
|
-
import { mkdir as
|
|
15020
|
+
import { mkdir as mkdir4 } from "node:fs/promises";
|
|
15021
15021
|
|
|
15022
15022
|
// src/config/gateway.ts
|
|
15023
15023
|
import { existsSync } from "node:fs";
|
|
@@ -16081,8 +16081,8 @@ function readOptionalString(value, field) {
|
|
|
16081
16081
|
}
|
|
16082
16082
|
|
|
16083
16083
|
// src/config/memory.ts
|
|
16084
|
-
import { stat } from "node:fs/promises";
|
|
16085
|
-
import { resolve } from "node:path";
|
|
16084
|
+
import { mkdir, stat, writeFile } from "node:fs/promises";
|
|
16085
|
+
import { basename, extname, resolve } from "node:path";
|
|
16086
16086
|
async function parseMemoryConfig(value, workspaceDirPath) {
|
|
16087
16087
|
const table = readMemoryTable(value);
|
|
16088
16088
|
const entries = await readMemoryEntries(table.entries, workspaceDirPath);
|
|
@@ -16115,7 +16115,7 @@ async function readMemoryEntry(value, index, workspaceDirPath) {
|
|
|
16115
16115
|
const displayPath = readRequiredString(entry.path, `${field}.path`);
|
|
16116
16116
|
const description = readRequiredString(entry.description, `${field}.description`);
|
|
16117
16117
|
const resolvedPath = resolve(workspaceDirPath, displayPath);
|
|
16118
|
-
const metadata = await
|
|
16118
|
+
const metadata = await ensurePathMetadata(resolvedPath, displayPath, entry, `${field}.path`);
|
|
16119
16119
|
if (metadata.isFile()) {
|
|
16120
16120
|
ensureDirectoryOnlyFieldIsAbsent(entry.inject_markdown_contents, `${field}.inject_markdown_contents`);
|
|
16121
16121
|
ensureDirectoryOnlyFieldIsAbsent(entry.globs, `${field}.globs`);
|
|
@@ -16140,12 +16140,47 @@ async function readMemoryEntry(value, index, workspaceDirPath) {
|
|
|
16140
16140
|
}
|
|
16141
16141
|
throw new Error(`${field}.path must point to a regular file or directory`);
|
|
16142
16142
|
}
|
|
16143
|
-
async function
|
|
16143
|
+
async function ensurePathMetadata(path, displayPath, entry, field) {
|
|
16144
16144
|
try {
|
|
16145
16145
|
return await stat(path);
|
|
16146
16146
|
} catch (error) {
|
|
16147
|
-
|
|
16147
|
+
if (!isMissingPathError(error)) {
|
|
16148
|
+
throw error;
|
|
16149
|
+
}
|
|
16150
|
+
const kind = inferMissingEntryKind(displayPath, entry);
|
|
16151
|
+
await createMissingEntryPath(path, kind);
|
|
16152
|
+
return await stat(path);
|
|
16153
|
+
}
|
|
16154
|
+
}
|
|
16155
|
+
function isMissingPathError(error) {
|
|
16156
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
16157
|
+
}
|
|
16158
|
+
function inferMissingEntryKind(displayPath, entry) {
|
|
16159
|
+
if (entry.inject_content !== undefined) {
|
|
16160
|
+
return "file";
|
|
16161
|
+
}
|
|
16162
|
+
if (entry.inject_markdown_contents !== undefined || entry.globs !== undefined) {
|
|
16163
|
+
return "directory";
|
|
16148
16164
|
}
|
|
16165
|
+
const trimmedPath = displayPath.trim();
|
|
16166
|
+
if (trimmedPath.endsWith("/") || trimmedPath.endsWith("\\")) {
|
|
16167
|
+
return "directory";
|
|
16168
|
+
}
|
|
16169
|
+
const name = basename(trimmedPath);
|
|
16170
|
+
if (name.startsWith(".") || extname(name).length > 0) {
|
|
16171
|
+
return "file";
|
|
16172
|
+
}
|
|
16173
|
+
return "directory";
|
|
16174
|
+
}
|
|
16175
|
+
async function createMissingEntryPath(path, kind) {
|
|
16176
|
+
if (kind === "directory") {
|
|
16177
|
+
await mkdir(path, { recursive: true });
|
|
16178
|
+
return;
|
|
16179
|
+
}
|
|
16180
|
+
const lastSlash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
16181
|
+
const parentPath = lastSlash >= 0 ? path.slice(0, lastSlash) : ".";
|
|
16182
|
+
await mkdir(parentPath, { recursive: true });
|
|
16183
|
+
await writeFile(path, "", { flag: "a" });
|
|
16149
16184
|
}
|
|
16150
16185
|
function ensureDirectoryOnlyFieldIsAbsent(value, field) {
|
|
16151
16186
|
if (value !== undefined) {
|
|
@@ -17324,7 +17359,7 @@ import { open } from "node:fs/promises";
|
|
|
17324
17359
|
* MIT Licensed
|
|
17325
17360
|
*/
|
|
17326
17361
|
var db = require_db();
|
|
17327
|
-
var
|
|
17362
|
+
var extname2 = __require("path").extname;
|
|
17328
17363
|
var mimeScore = require_mimeScore();
|
|
17329
17364
|
var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
|
|
17330
17365
|
var $extensions = Object.create(null);
|
|
@@ -17347,7 +17382,7 @@ function lookup(path) {
|
|
|
17347
17382
|
if (!path || typeof path !== "string") {
|
|
17348
17383
|
return false;
|
|
17349
17384
|
}
|
|
17350
|
-
var extension2 =
|
|
17385
|
+
var extension2 = extname2("x." + path).toLowerCase().slice(1);
|
|
17351
17386
|
if (!extension2) {
|
|
17352
17387
|
return false;
|
|
17353
17388
|
}
|
|
@@ -17543,7 +17578,7 @@ class GatewayMailboxRouter {
|
|
|
17543
17578
|
// src/memory/prompt.ts
|
|
17544
17579
|
var import_fast_glob = __toESM(require_out4(), 1);
|
|
17545
17580
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
17546
|
-
import { extname as
|
|
17581
|
+
import { extname as extname3, relative } from "node:path";
|
|
17547
17582
|
var MARKDOWN_GLOBS = ["**/*.md", "**/*.markdown"];
|
|
17548
17583
|
var UTF8_TEXT_DECODER = new TextDecoder("utf-8", { fatal: true });
|
|
17549
17584
|
|
|
@@ -17649,7 +17684,7 @@ function relativeDisplayPath(rootPath, rootDisplayPath, filePath) {
|
|
|
17649
17684
|
return `${rootDisplayPath}/${suffix.replaceAll("\\", "/")}`;
|
|
17650
17685
|
}
|
|
17651
17686
|
function inferFenceInfoString(path) {
|
|
17652
|
-
const extension2 =
|
|
17687
|
+
const extension2 = extname3(path).slice(1).toLowerCase();
|
|
17653
17688
|
if (!/^[a-z0-9_+-]+$/.test(extension2)) {
|
|
17654
17689
|
return "";
|
|
17655
17690
|
}
|
|
@@ -17668,7 +17703,7 @@ function formatError2(error) {
|
|
|
17668
17703
|
}
|
|
17669
17704
|
|
|
17670
17705
|
// src/opencode/adapter.ts
|
|
17671
|
-
import { basename } from "node:path";
|
|
17706
|
+
import { basename as basename2 } from "node:path";
|
|
17672
17707
|
import { pathToFileURL } from "node:url";
|
|
17673
17708
|
|
|
17674
17709
|
// src/runtime/delay.ts
|
|
@@ -17910,7 +17945,7 @@ function toSessionPromptPart(part) {
|
|
|
17910
17945
|
type: "file",
|
|
17911
17946
|
mime: part.mimeType,
|
|
17912
17947
|
url: pathToFileURL(part.localPath).href,
|
|
17913
|
-
filename: part.fileName ??
|
|
17948
|
+
filename: part.fileName ?? basename2(part.localPath)
|
|
17914
17949
|
};
|
|
17915
17950
|
}
|
|
17916
17951
|
}
|
|
@@ -22388,7 +22423,7 @@ function buildGatewayContextPrompt(targets) {
|
|
|
22388
22423
|
}
|
|
22389
22424
|
|
|
22390
22425
|
// src/store/sqlite.ts
|
|
22391
|
-
import { mkdir } from "node:fs/promises";
|
|
22426
|
+
import { mkdir as mkdir2 } from "node:fs/promises";
|
|
22392
22427
|
import { dirname as dirname3 } from "node:path";
|
|
22393
22428
|
|
|
22394
22429
|
// src/store/migrations.ts
|
|
@@ -23303,7 +23338,7 @@ function readBooleanField(value, field, fallback) {
|
|
|
23303
23338
|
return raw;
|
|
23304
23339
|
}
|
|
23305
23340
|
async function openSqliteStore(path) {
|
|
23306
|
-
await
|
|
23341
|
+
await mkdir2(dirname3(path), { recursive: true });
|
|
23307
23342
|
const { SqliteDatabase: SqliteDatabase2 } = await Promise.resolve().then(() => (init_database(), exports_database));
|
|
23308
23343
|
const db2 = new SqliteDatabase2(path);
|
|
23309
23344
|
migrateGatewayDatabase(db2);
|
|
@@ -23311,7 +23346,7 @@ async function openSqliteStore(path) {
|
|
|
23311
23346
|
}
|
|
23312
23347
|
|
|
23313
23348
|
// src/telegram/client.ts
|
|
23314
|
-
import { readFile as readFile4, writeFile } from "node:fs/promises";
|
|
23349
|
+
import { readFile as readFile4, writeFile as writeFile2 } from "node:fs/promises";
|
|
23315
23350
|
class TelegramApiError extends Error {
|
|
23316
23351
|
retryable;
|
|
23317
23352
|
constructor(message, retryable) {
|
|
@@ -23356,7 +23391,7 @@ class TelegramBotClient {
|
|
|
23356
23391
|
if (!response.ok) {
|
|
23357
23392
|
throw new TelegramApiError(`Telegram file download failed (${response.status}): ${response.statusText}`, isRetryableError(response.status, response.status));
|
|
23358
23393
|
}
|
|
23359
|
-
await
|
|
23394
|
+
await writeFile2(localPath, new Uint8Array(await response.arrayBuffer()));
|
|
23360
23395
|
}
|
|
23361
23396
|
async sendMessage(chatId, text, messageThreadId) {
|
|
23362
23397
|
await this.call("sendMessage", {
|
|
@@ -23500,8 +23535,8 @@ function isRetryableError(errorCode, httpStatus) {
|
|
|
23500
23535
|
}
|
|
23501
23536
|
|
|
23502
23537
|
// src/telegram/media.ts
|
|
23503
|
-
import { mkdir as
|
|
23504
|
-
import { basename as
|
|
23538
|
+
import { mkdir as mkdir3 } from "node:fs/promises";
|
|
23539
|
+
import { basename as basename3, extname as extname4, join as join3 } from "node:path";
|
|
23505
23540
|
class TelegramInboundMediaStore {
|
|
23506
23541
|
client;
|
|
23507
23542
|
mediaRootPath;
|
|
@@ -23530,9 +23565,9 @@ class TelegramInboundMediaStore {
|
|
|
23530
23565
|
if (!remotePath) {
|
|
23531
23566
|
throw new Error(`Telegram file ${attachment.fileId} did not include file_path`);
|
|
23532
23567
|
}
|
|
23533
|
-
const fileName = normalizeOptionalFileName(attachment.fileName) ?? normalizeOptionalFileName(
|
|
23568
|
+
const fileName = normalizeOptionalFileName(attachment.fileName) ?? normalizeOptionalFileName(basename3(remotePath)) ?? `telegram-image-${ordinal + 1}${extensionFromRemotePath(remotePath)}`;
|
|
23534
23569
|
const localPath = join3(this.mediaRootPath, "telegram", sanitizePathSegment(sourceKind), sanitizePathSegment(externalId), `${ordinal}-${sanitizePathSegment(fileName)}`);
|
|
23535
|
-
await
|
|
23570
|
+
await mkdir3(join3(this.mediaRootPath, "telegram", sanitizePathSegment(sourceKind), sanitizePathSegment(externalId)), {
|
|
23536
23571
|
recursive: true
|
|
23537
23572
|
});
|
|
23538
23573
|
await this.client.downloadFile(remotePath, localPath);
|
|
@@ -23555,7 +23590,7 @@ function normalizeOptionalFileName(value) {
|
|
|
23555
23590
|
return trimmed.length === 0 ? null : trimmed;
|
|
23556
23591
|
}
|
|
23557
23592
|
function extensionFromRemotePath(remotePath) {
|
|
23558
|
-
const extension2 =
|
|
23593
|
+
const extension2 = extname4(remotePath);
|
|
23559
23594
|
return extension2.length === 0 ? ".bin" : extension2;
|
|
23560
23595
|
}
|
|
23561
23596
|
|
|
@@ -24063,7 +24098,7 @@ class GatewayPluginRuntime {
|
|
|
24063
24098
|
async function createGatewayRuntime(module, input) {
|
|
24064
24099
|
const config = await loadGatewayConfig();
|
|
24065
24100
|
return await getOrCreateRuntimeSingleton(config.configPath, async () => {
|
|
24066
|
-
await
|
|
24101
|
+
await mkdir4(config.workspaceDirPath, { recursive: true });
|
|
24067
24102
|
const logger = new ConsoleLoggerHost(config.logLevel);
|
|
24068
24103
|
if (config.hasLegacyGatewayTimezone) {
|
|
24069
24104
|
const suffix = config.legacyGatewayTimezone === null ? "" : ` (${config.legacyGatewayTimezone})`;
|