opencode-gateway 0.1.0
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/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/binding/execution.d.ts +24 -0
- package/dist/binding/execution.js +1 -0
- package/dist/binding/gateway.d.ts +71 -0
- package/dist/binding/gateway.js +1 -0
- package/dist/binding/index.d.ts +15 -0
- package/dist/binding/index.js +4 -0
- package/dist/binding/opencode.d.ts +123 -0
- package/dist/binding/opencode.js +1 -0
- package/dist/cli/args.d.ts +9 -0
- package/dist/cli/args.js +53 -0
- package/dist/cli/doctor.d.ts +6 -0
- package/dist/cli/doctor.js +59 -0
- package/dist/cli/init.d.ts +6 -0
- package/dist/cli/init.js +35 -0
- package/dist/cli/opencode-config.d.ts +10 -0
- package/dist/cli/opencode-config.js +62 -0
- package/dist/cli/paths.d.ts +7 -0
- package/dist/cli/paths.js +22 -0
- package/dist/cli/templates.d.ts +1 -0
- package/dist/cli/templates.js +26 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +314 -0
- package/dist/config/cron.d.ts +7 -0
- package/dist/config/cron.js +52 -0
- package/dist/config/gateway.d.ts +26 -0
- package/dist/config/gateway.js +142 -0
- package/dist/config/paths.d.ts +10 -0
- package/dist/config/paths.js +33 -0
- package/dist/config/telegram.d.ts +13 -0
- package/dist/config/telegram.js +91 -0
- package/dist/cron/runtime.d.ts +40 -0
- package/dist/cron/runtime.js +237 -0
- package/dist/delivery/telegram.d.ts +16 -0
- package/dist/delivery/telegram.js +75 -0
- package/dist/delivery/text.d.ts +21 -0
- package/dist/delivery/text.js +175 -0
- package/dist/gateway.d.ts +33 -0
- package/dist/gateway.js +105 -0
- package/dist/host/file-sender.d.ts +16 -0
- package/dist/host/file-sender.js +59 -0
- package/dist/host/noop.d.ts +4 -0
- package/dist/host/noop.js +14 -0
- package/dist/host/transport.d.ts +9 -0
- package/dist/host/transport.js +35 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +52 -0
- package/dist/mailbox/router.d.ts +7 -0
- package/dist/mailbox/router.js +16 -0
- package/dist/media/mime.d.ts +2 -0
- package/dist/media/mime.js +45 -0
- package/dist/opencode/adapter.d.ts +19 -0
- package/dist/opencode/adapter.js +291 -0
- package/dist/opencode/driver-hub.d.ts +15 -0
- package/dist/opencode/driver-hub.js +82 -0
- package/dist/opencode/event-normalize.d.ts +48 -0
- package/dist/opencode/event-normalize.js +48 -0
- package/dist/opencode/event-stream.d.ts +23 -0
- package/dist/opencode/event-stream.js +65 -0
- package/dist/opencode/events.d.ts +2 -0
- package/dist/opencode/events.js +1 -0
- package/dist/questions/client.d.ts +5 -0
- package/dist/questions/client.js +36 -0
- package/dist/questions/format.d.ts +3 -0
- package/dist/questions/format.js +36 -0
- package/dist/questions/normalize.d.ts +10 -0
- package/dist/questions/normalize.js +45 -0
- package/dist/questions/parser.d.ts +11 -0
- package/dist/questions/parser.js +96 -0
- package/dist/questions/runtime.d.ts +53 -0
- package/dist/questions/runtime.js +195 -0
- package/dist/questions/types.d.ts +22 -0
- package/dist/questions/types.js +1 -0
- package/dist/runtime/attachments.d.ts +3 -0
- package/dist/runtime/attachments.js +12 -0
- package/dist/runtime/executor.d.ts +24 -0
- package/dist/runtime/executor.js +188 -0
- package/dist/runtime/mailbox.d.ts +25 -0
- package/dist/runtime/mailbox.js +112 -0
- package/dist/runtime/opencode-runner.d.ts +26 -0
- package/dist/runtime/opencode-runner.js +79 -0
- package/dist/session/context.d.ts +10 -0
- package/dist/session/context.js +44 -0
- package/dist/session/conversation-key.d.ts +3 -0
- package/dist/session/conversation-key.js +3 -0
- package/dist/session/switcher.d.ts +25 -0
- package/dist/session/switcher.js +59 -0
- package/dist/store/migrations.d.ts +2 -0
- package/dist/store/migrations.js +183 -0
- package/dist/store/sqlite.d.ts +127 -0
- package/dist/store/sqlite.js +678 -0
- package/dist/telegram/client.d.ts +35 -0
- package/dist/telegram/client.js +179 -0
- package/dist/telegram/media.d.ts +13 -0
- package/dist/telegram/media.js +65 -0
- package/dist/telegram/normalize.d.ts +47 -0
- package/dist/telegram/normalize.js +119 -0
- package/dist/telegram/poller.d.ts +29 -0
- package/dist/telegram/poller.js +97 -0
- package/dist/telegram/runtime.d.ts +51 -0
- package/dist/telegram/runtime.js +133 -0
- package/dist/telegram/state.d.ts +36 -0
- package/dist/telegram/state.js +128 -0
- package/dist/telegram/types.d.ts +80 -0
- package/dist/telegram/types.js +1 -0
- package/dist/tools/channel-new-session.d.ts +4 -0
- package/dist/tools/channel-new-session.js +27 -0
- package/dist/tools/channel-send-file.d.ts +9 -0
- package/dist/tools/channel-send-file.js +27 -0
- package/dist/tools/channel-target.d.ts +7 -0
- package/dist/tools/channel-target.js +28 -0
- package/dist/tools/cron-list.d.ts +3 -0
- package/dist/tools/cron-list.js +34 -0
- package/dist/tools/cron-remove.d.ts +3 -0
- package/dist/tools/cron-remove.js +12 -0
- package/dist/tools/cron-run.d.ts +3 -0
- package/dist/tools/cron-run.js +20 -0
- package/dist/tools/cron-upsert.d.ts +3 -0
- package/dist/tools/cron-upsert.js +37 -0
- package/dist/tools/gateway-dispatch-cron.d.ts +3 -0
- package/dist/tools/gateway-dispatch-cron.js +33 -0
- package/dist/tools/gateway-status.d.ts +3 -0
- package/dist/tools/gateway-status.js +25 -0
- package/dist/tools/telegram-send-test.d.ts +3 -0
- package/dist/tools/telegram-send-test.js +26 -0
- package/dist/tools/telegram-status.d.ts +3 -0
- package/dist/tools/telegram-status.js +49 -0
- package/dist/tools/time.d.ts +3 -0
- package/dist/tools/time.js +25 -0
- package/dist/utils/error.d.ts +1 -0
- package/dist/utils/error.js +57 -0
- package/generated/wasm/pkg/opencode_gateway_ffi.d.ts +23 -0
- package/generated/wasm/pkg/opencode_gateway_ffi.js +574 -0
- package/generated/wasm/pkg/opencode_gateway_ffi_bg.wasm +0 -0
- package/generated/wasm/pkg/opencode_gateway_ffi_bg.wasm.d.ts +22 -0
- package/package.json +61 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin";
|
|
2
|
+
export function createGatewayStatusTool(runtime) {
|
|
3
|
+
return tool({
|
|
4
|
+
description: "Return the current Rust gateway contract status",
|
|
5
|
+
args: {},
|
|
6
|
+
async execute() {
|
|
7
|
+
return formatGatewayStatus(runtime.status());
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function formatGatewayStatus(status) {
|
|
12
|
+
return [
|
|
13
|
+
`runtime_mode=${status.runtimeMode}`,
|
|
14
|
+
`supports_telegram=${status.supportsTelegram}`,
|
|
15
|
+
`supports_cron=${status.supportsCron}`,
|
|
16
|
+
`has_web_ui=${status.hasWebUi}`,
|
|
17
|
+
`cron_timezone=${status.cronTimezone}`,
|
|
18
|
+
`cron_enabled=${status.cronEnabled}`,
|
|
19
|
+
`cron_polling=${status.cronPolling}`,
|
|
20
|
+
`cron_running_jobs=${status.cronRunningJobs}`,
|
|
21
|
+
`telegram_enabled=${status.telegramEnabled}`,
|
|
22
|
+
`telegram_polling=${status.telegramPolling}`,
|
|
23
|
+
`telegram_allowlist_mode=${status.telegramAllowlistMode}`,
|
|
24
|
+
].join("\n");
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin";
|
|
2
|
+
import { formatUnixMsAsUtc } from "./time";
|
|
3
|
+
export function createTelegramSendTestTool(runtime) {
|
|
4
|
+
return tool({
|
|
5
|
+
description: "Send a Telegram test message to an explicit chat_id and optional topic",
|
|
6
|
+
args: {
|
|
7
|
+
chat_id: tool.schema.string().min(1),
|
|
8
|
+
topic: tool.schema.string().optional(),
|
|
9
|
+
text: tool.schema.string().optional(),
|
|
10
|
+
mode: tool.schema.enum(["auto", "oneshot", "stream"]).optional(),
|
|
11
|
+
},
|
|
12
|
+
async execute(args) {
|
|
13
|
+
return formatTelegramSendTestResult(await runtime.sendTest(args.chat_id, args.topic ?? null, args.text ?? null, args.mode ?? "auto"));
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function formatTelegramSendTestResult(result) {
|
|
18
|
+
return [
|
|
19
|
+
`chat_id=${result.chatId}`,
|
|
20
|
+
`topic=${result.topic ?? "none"}`,
|
|
21
|
+
`mode=${result.mode}`,
|
|
22
|
+
`sent_at_ms=${result.sentAtMs}`,
|
|
23
|
+
`sent_at_utc=${formatUnixMsAsUtc(result.sentAtMs)}`,
|
|
24
|
+
`text=${result.text}`,
|
|
25
|
+
].join("\n");
|
|
26
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin";
|
|
2
|
+
import { formatOptionalUnixMsAsUtc } from "./time";
|
|
3
|
+
export function createTelegramStatusTool(runtime) {
|
|
4
|
+
return tool({
|
|
5
|
+
description: "Return Telegram gateway status, cached health, and a live Bot API probe",
|
|
6
|
+
args: {},
|
|
7
|
+
async execute() {
|
|
8
|
+
return formatTelegramStatus(await runtime.status());
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function formatTelegramStatus(status) {
|
|
13
|
+
return [
|
|
14
|
+
`enabled=${status.enabled}`,
|
|
15
|
+
`polling=${status.polling}`,
|
|
16
|
+
`allowlist_mode=${status.allowlistMode}`,
|
|
17
|
+
`allowed_chats_count=${status.allowedChatsCount}`,
|
|
18
|
+
`allowed_users_count=${status.allowedUsersCount}`,
|
|
19
|
+
`update_offset=${status.updateOffset ?? "none"}`,
|
|
20
|
+
`last_poll_success_ms=${status.lastPollSuccessMs ?? "none"}`,
|
|
21
|
+
`last_poll_success_utc=${formatOptionalUnixMsAsUtc(status.lastPollSuccessMs)}`,
|
|
22
|
+
`last_poll_error_at_ms=${status.lastPollErrorAtMs ?? "none"}`,
|
|
23
|
+
`last_poll_error=${status.lastPollErrorMessage ?? "none"}`,
|
|
24
|
+
`last_send_success_ms=${status.lastSendSuccessMs ?? "none"}`,
|
|
25
|
+
`last_send_success_utc=${formatOptionalUnixMsAsUtc(status.lastSendSuccessMs)}`,
|
|
26
|
+
`last_send_error_at_ms=${status.lastSendErrorAtMs ?? "none"}`,
|
|
27
|
+
`last_send_error=${status.lastSendErrorMessage ?? "none"}`,
|
|
28
|
+
`last_probe_success_ms=${status.lastProbeSuccessMs ?? "none"}`,
|
|
29
|
+
`last_probe_success_utc=${formatOptionalUnixMsAsUtc(status.lastProbeSuccessMs)}`,
|
|
30
|
+
`last_probe_error_at_ms=${status.lastProbeErrorAtMs ?? "none"}`,
|
|
31
|
+
`last_probe_error=${status.lastProbeErrorMessage ?? "none"}`,
|
|
32
|
+
`live_probe=${status.liveProbe}`,
|
|
33
|
+
`live_probe_error=${status.liveProbeError ?? "none"}`,
|
|
34
|
+
`bot_id=${status.liveBotId ?? status.lastBotId ?? "none"}`,
|
|
35
|
+
`bot_username=${status.liveBotUsername ?? status.lastBotUsername ?? "none"}`,
|
|
36
|
+
`streaming_enabled=${status.streamingEnabled}`,
|
|
37
|
+
`opencode_event_stream_connected=${status.opencodeEventStreamConnected}`,
|
|
38
|
+
`last_event_stream_error=${status.lastEventStreamError ?? "none"}`,
|
|
39
|
+
`last_draft_success_ms=${status.lastDraftSuccessMs ?? "none"}`,
|
|
40
|
+
`last_draft_success_utc=${formatOptionalUnixMsAsUtc(status.lastDraftSuccessMs)}`,
|
|
41
|
+
`last_draft_error_at_ms=${status.lastDraftErrorAtMs ?? "none"}`,
|
|
42
|
+
`last_draft_error=${status.lastDraftErrorMessage ?? "none"}`,
|
|
43
|
+
`last_preview_emit_ms=${status.lastPreviewEmitMs ?? "none"}`,
|
|
44
|
+
`last_preview_emit_utc=${formatOptionalUnixMsAsUtc(status.lastPreviewEmitMs)}`,
|
|
45
|
+
`last_stream_fallback_at_ms=${status.lastStreamFallbackAtMs ?? "none"}`,
|
|
46
|
+
`last_stream_fallback_utc=${formatOptionalUnixMsAsUtc(status.lastStreamFallbackAtMs)}`,
|
|
47
|
+
`last_stream_fallback_reason=${status.lastStreamFallbackReason ?? "none"}`,
|
|
48
|
+
].join("\n");
|
|
49
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function formatUnixMsAsUtc(value) {
|
|
2
|
+
return new Date(value).toISOString();
|
|
3
|
+
}
|
|
4
|
+
export function formatOptionalUnixMsAsUtc(value) {
|
|
5
|
+
return value === null ? "none" : formatUnixMsAsUtc(value);
|
|
6
|
+
}
|
|
7
|
+
export function formatUnixMsInTimeZone(value, timeZone) {
|
|
8
|
+
const formatter = new Intl.DateTimeFormat("en-CA", {
|
|
9
|
+
timeZone,
|
|
10
|
+
year: "numeric",
|
|
11
|
+
month: "2-digit",
|
|
12
|
+
day: "2-digit",
|
|
13
|
+
hour: "2-digit",
|
|
14
|
+
minute: "2-digit",
|
|
15
|
+
second: "2-digit",
|
|
16
|
+
hour12: false,
|
|
17
|
+
});
|
|
18
|
+
const parts = formatter.formatToParts(new Date(value));
|
|
19
|
+
const values = new Map(parts.map((part) => [part.type, part.value]));
|
|
20
|
+
return [
|
|
21
|
+
`${values.get("year")}-${values.get("month")}-${values.get("day")}`,
|
|
22
|
+
`${values.get("hour")}:${values.get("minute")}:${values.get("second")}`,
|
|
23
|
+
`[${timeZone}]`,
|
|
24
|
+
].join(" ");
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatError(error: unknown): string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export function formatError(error) {
|
|
2
|
+
if (error instanceof Error) {
|
|
3
|
+
const errorLike = error;
|
|
4
|
+
const nestedMessage = extractNestedDataMessage(errorLike.data);
|
|
5
|
+
if (nestedMessage !== null) {
|
|
6
|
+
return nestedMessage;
|
|
7
|
+
}
|
|
8
|
+
return error.message;
|
|
9
|
+
}
|
|
10
|
+
if (typeof error === "string") {
|
|
11
|
+
return error;
|
|
12
|
+
}
|
|
13
|
+
if (typeof error === "object" && error !== null) {
|
|
14
|
+
const errorLike = error;
|
|
15
|
+
const nestedMessage = extractNestedDataMessage(errorLike.data);
|
|
16
|
+
if (nestedMessage !== null) {
|
|
17
|
+
return nestedMessage;
|
|
18
|
+
}
|
|
19
|
+
if (typeof errorLike.message === "string" && errorLike.message.length > 0) {
|
|
20
|
+
const detail = compactObject({
|
|
21
|
+
name: errorLike.name,
|
|
22
|
+
code: errorLike.code,
|
|
23
|
+
status: errorLike.status,
|
|
24
|
+
cause: errorLike.cause,
|
|
25
|
+
});
|
|
26
|
+
return detail === null ? errorLike.message : `${errorLike.message} (${detail})`;
|
|
27
|
+
}
|
|
28
|
+
const serialized = safeJsonStringify(error);
|
|
29
|
+
if (serialized !== null) {
|
|
30
|
+
return serialized;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return String(error);
|
|
34
|
+
}
|
|
35
|
+
function extractNestedDataMessage(value) {
|
|
36
|
+
if (typeof value !== "object" || value === null) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const message = value.message;
|
|
40
|
+
return typeof message === "string" && message.length > 0 ? message : null;
|
|
41
|
+
}
|
|
42
|
+
function compactObject(value) {
|
|
43
|
+
const entries = Object.entries(value).filter(([, fieldValue]) => fieldValue !== undefined && fieldValue !== null);
|
|
44
|
+
if (entries.length === 0) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const serialized = safeJsonStringify(Object.fromEntries(entries));
|
|
48
|
+
return serialized ?? entries.map(([key, fieldValue]) => `${key}=${String(fieldValue)}`).join(", ");
|
|
49
|
+
}
|
|
50
|
+
function safeJsonStringify(value) {
|
|
51
|
+
try {
|
|
52
|
+
return JSON.stringify(value);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class OpencodeExecutionDriver {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
constructor(input: any);
|
|
8
|
+
observeEvent(observation: any, now_ms: number): any;
|
|
9
|
+
resume(result: any): any;
|
|
10
|
+
start(): any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function conversationKeyForDeliveryTarget(target: any): string;
|
|
14
|
+
|
|
15
|
+
export function gatewayStatus(): any;
|
|
16
|
+
|
|
17
|
+
export function nextCronRunAt(job: any, after_ms: number, time_zone: string): number;
|
|
18
|
+
|
|
19
|
+
export function normalizeCronTimeZone(time_zone: string): string;
|
|
20
|
+
|
|
21
|
+
export function prepareCronExecution(job: any): any;
|
|
22
|
+
|
|
23
|
+
export function prepareInboundExecution(message: any): any;
|