omp-superagent 0.0.0-stage → 0.1.2
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/DESIGN.md +1502 -0
- package/LICENSE +21 -0
- package/README.ko.md +198 -0
- package/README.md +224 -2
- package/THIRD_PARTY_NOTICES.md +388 -0
- package/assets/architecture.mmd +24 -0
- package/assets/architecture.svg +126 -0
- package/assets/superagent-avatar.jpg +0 -0
- package/assets/superagent-mascot.webp +0 -0
- package/config.example.json +26 -0
- package/docs/OPERATIONS.md +1178 -0
- package/docs/discord-voice.md +96 -0
- package/docs/releases/0.1.0.md +222 -0
- package/docs/releases/0.1.1.md +60 -0
- package/docs/releases/0.1.2.md +53 -0
- package/package.json +65 -4
- package/scripts/ci.ts +33 -0
- package/scripts/prepare-ulw.ts +18 -0
- package/scripts/release.ts +58 -0
- package/scripts/setup.sh +25 -0
- package/scripts/test-omp.sh +36 -0
- package/skills/head/SKILL.md +100 -0
- package/skills/head/references/model-selection.md +83 -0
- package/skills/head/references/routing.md +181 -0
- package/skills/head/references/supervision.md +122 -0
- package/skills/lane/SKILL.md +66 -0
- package/skills/lane/references/workflow.md +95 -0
- package/src/autostart.ts +295 -0
- package/src/board-extension.ts +217 -0
- package/src/board.ts +396 -0
- package/src/cli.ts +253 -0
- package/src/codex-live-bridge.py +73 -0
- package/src/codex-live.ts +244 -0
- package/src/codex-voice-requirements.txt +5 -0
- package/src/codex_live_auth.py +192 -0
- package/src/codex_live_media.py +219 -0
- package/src/codex_live_provider.py +192 -0
- package/src/config.ts +266 -0
- package/src/contracts.ts +381 -0
- package/src/credentials.ts +172 -0
- package/src/decision-tool.ts +59 -0
- package/src/decisions.ts +143 -0
- package/src/delivery.ts +17 -0
- package/src/dialog.ts +73 -0
- package/src/discord-command-registration.ts +201 -0
- package/src/discord-commands.ts +29 -0
- package/src/discord-context.ts +118 -0
- package/src/discord-markdown.ts +172 -0
- package/src/discord-voice-draft.ts +124 -0
- package/src/discord-voice-link.ts +270 -0
- package/src/discord-voice.ts +150 -0
- package/src/discord.ts +1012 -0
- package/src/extension.ts +446 -0
- package/src/gateway-client.ts +229 -0
- package/src/gateway-protocol.ts +85 -0
- package/src/gateway-restart.ts +151 -0
- package/src/gateway-server.ts +440 -0
- package/src/gateway-store.ts +251 -0
- package/src/gateway.ts +654 -0
- package/src/head-recovery.ts +61 -0
- package/src/host-broker-services.ts +108 -0
- package/src/host-extension.ts +561 -0
- package/src/host-owner.ts +366 -0
- package/src/host-protocol.ts +144 -0
- package/src/host-services.ts +54 -0
- package/src/host.ts +415 -0
- package/src/installed-omp.ts +71 -0
- package/src/lane-extension.ts +184 -0
- package/src/lane-models.ts +75 -0
- package/src/lane-report.ts +70 -0
- package/src/lane-rows.ts +12 -0
- package/src/managed-ulw-probe.ts +172 -0
- package/src/managed-ulw.ts +471 -0
- package/src/message-order.ts +21 -0
- package/src/messenger-commands.ts +16 -0
- package/src/messengers.ts +143 -0
- package/src/native-presets.ts +370 -0
- package/src/native-sessions.ts +32 -0
- package/src/native-settings.ts +131 -0
- package/src/openai-live.ts +377 -0
- package/src/pr-github-schema.ts +110 -0
- package/src/pr-github.ts +170 -0
- package/src/pr-watch.ts +200 -0
- package/src/repository.ts +12 -0
- package/src/runtime.ts +4229 -0
- package/src/setup-judge.ts +34 -0
- package/src/setup-memory.ts +39 -0
- package/src/setup-profiles.ts +84 -0
- package/src/setup.ts +300 -0
- package/src/slack-command-registration.ts +217 -0
- package/src/slack-commands.ts +18 -0
- package/src/slack.ts +779 -0
- package/src/store.ts +862 -0
- package/src/telegram-command-registration.ts +155 -0
- package/src/telegram.ts +677 -0
- package/src/workflow.ts +94 -0
- package/upstream/ulw.json +9 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Api } from "grammy";
|
|
2
|
+
import type { BotCommand, BotCommandScopeChat, BotCommandScopeChatMember, LanguageCode } from "grammy/types";
|
|
3
|
+
import type { Config } from "./config";
|
|
4
|
+
import { loadCredentials, validateCredential } from "./credentials";
|
|
5
|
+
import { MESSENGER_COMMANDS } from "./messenger-commands";
|
|
6
|
+
|
|
7
|
+
type CommandApi = Pick<Api, "getMe" | "getChat" | "getChatMember" | "getMyCommands" | "setMyCommands">;
|
|
8
|
+
type OwnerScope = BotCommandScopeChat | BotCommandScopeChatMember;
|
|
9
|
+
|
|
10
|
+
// The SDK exports its language mapping as declarations only, not runtime data.
|
|
11
|
+
// Keep validation tied to its actual union rather than asserting any two letters.
|
|
12
|
+
const LANGUAGE_CODES = [
|
|
13
|
+
"aa", "ab", "ae", "af", "ak", "am", "an", "ar", "as", "av", "ay", "az",
|
|
14
|
+
"ba", "be", "bg", "bi", "bm", "bn", "bo", "br", "bs",
|
|
15
|
+
"ca", "ce", "ch", "co", "cr", "cs", "cu", "cv", "cy",
|
|
16
|
+
"da", "de", "dv", "dz", "ee", "el", "en", "eo", "es", "et", "eu",
|
|
17
|
+
"fa", "ff", "fi", "fj", "fo", "fr", "fy", "ga", "gd", "gl", "gn", "gu", "gv",
|
|
18
|
+
"ha", "he", "hi", "ho", "hr", "ht", "hu", "hy", "hz",
|
|
19
|
+
"ia", "id", "ie", "ig", "ii", "ik", "io", "is", "it", "iu",
|
|
20
|
+
"ja", "jv", "ka", "kg", "ki", "kj", "kk", "kl", "km", "kn", "ko", "kr", "ks", "ku", "kv", "kw", "ky",
|
|
21
|
+
"la", "lb", "lg", "li", "ln", "lo", "lt", "lu", "lv",
|
|
22
|
+
"mg", "mh", "mi", "mk", "ml", "mn", "mr", "ms", "mt", "my",
|
|
23
|
+
"na", "nb", "nd", "ne", "ng", "nl", "nn", "no", "nr", "nv", "ny",
|
|
24
|
+
"oc", "oj", "om", "or", "os", "pa", "pi", "pl", "ps", "pt", "qu",
|
|
25
|
+
"rm", "rn", "ro", "ru", "rw", "sa", "sc", "sd", "se", "sg", "si", "sk", "sl", "sm", "sn", "so", "sq", "sr", "ss", "st", "su", "sv", "sw",
|
|
26
|
+
"ta", "te", "tg", "th", "ti", "tk", "tl", "tn", "to", "tr", "ts", "tt", "tw", "ty",
|
|
27
|
+
"ug", "uk", "ur", "uz", "ve", "vi", "vo", "wa", "wo", "xh", "yi", "yo", "za", "zh", "zu",
|
|
28
|
+
] as const satisfies readonly LanguageCode[];
|
|
29
|
+
|
|
30
|
+
function normalizeLanguageCode(value: string | undefined): LanguageCode | undefined {
|
|
31
|
+
// Omission and the API's empty-string selector both select the default list.
|
|
32
|
+
// Omit both because the installed SDK does not include "" in LanguageCode.
|
|
33
|
+
if (value === undefined || value === "") return undefined;
|
|
34
|
+
const language = LANGUAGE_CODES.find(code => code === value);
|
|
35
|
+
if (language === undefined) throw new Error("Telegram command language must be an empty string or a two-letter lowercase ISO 639-1 code");
|
|
36
|
+
return language;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface TelegramCommandRegistrationOptions {
|
|
40
|
+
apply?: boolean;
|
|
41
|
+
/** Omit for the default language list; Telegram cannot enumerate language overrides. */
|
|
42
|
+
languageCode?: string;
|
|
43
|
+
createApi?: (token: string) => CommandApi;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface TelegramCommandRegistrationReport {
|
|
47
|
+
status: "dry-run" | "applied";
|
|
48
|
+
botId: string;
|
|
49
|
+
languageCode: string | null;
|
|
50
|
+
plannedCommands: BotCommand[];
|
|
51
|
+
scopes: { scope: OwnerScope; current: BotCommand[]; changed: boolean }[];
|
|
52
|
+
note: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function commands(value: unknown): BotCommand[] {
|
|
56
|
+
if (!Array.isArray(value) || value.length > 100) throw new Error("Invalid command list");
|
|
57
|
+
return value.map(row => {
|
|
58
|
+
if (!row || typeof row !== "object" || typeof row.command !== "string" ||
|
|
59
|
+
!/^[a-z0-9_]{1,32}$/.test(row.command) || typeof row.description !== "string" ||
|
|
60
|
+
row.description.length < 1 || row.description.length > 256) throw new Error("Invalid command definition");
|
|
61
|
+
return { command: row.command, description: row.description };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function exact(actual: BotCommand[], expected: BotCommand[]): boolean {
|
|
66
|
+
// Order also defines the visible picker, so a reordered list is not exact.
|
|
67
|
+
return JSON.stringify(actual) === JSON.stringify(expected);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** API-only, opt-in menus. Never polls, manages webhooks, or imports the runtime. */
|
|
71
|
+
export async function registerTelegramCommands(
|
|
72
|
+
config: Config, options: TelegramCommandRegistrationOptions = {},
|
|
73
|
+
): Promise<TelegramCommandRegistrationReport> {
|
|
74
|
+
const policy = config.telegram;
|
|
75
|
+
if (!policy) throw new Error("telegram-commands requires configured Telegram credentials and policy");
|
|
76
|
+
if (!/^[1-9][0-9]*$/.test(policy.ownerId) || !Number.isSafeInteger(Number(policy.ownerId)) ||
|
|
77
|
+
policy.allowedChatIds.some(id => !/^-[1-9][0-9]*$/.test(id) || !Number.isSafeInteger(Number(id)))) {
|
|
78
|
+
throw new Error("Telegram command menus require a positive owner ID and negative allowed group IDs");
|
|
79
|
+
}
|
|
80
|
+
const languageCode = normalizeLanguageCode(options.languageCode);
|
|
81
|
+
try {
|
|
82
|
+
// Preserve the existing explicit-environment/private-file precedence while
|
|
83
|
+
// neither loading nor requiring any other platform's credentials.
|
|
84
|
+
loadCredentials({ ...config, discord: undefined, slack: undefined });
|
|
85
|
+
} catch { throw new Error("Cannot safely load the configured Telegram credential; details suppressed"); }
|
|
86
|
+
const token = process.env[policy.tokenEnv];
|
|
87
|
+
if (!token) throw new Error("Configured Telegram credential is missing");
|
|
88
|
+
try { validateCredential(token); }
|
|
89
|
+
catch { throw new Error("Configured Telegram credential is invalid; value suppressed"); }
|
|
90
|
+
|
|
91
|
+
let api: CommandApi;
|
|
92
|
+
try {
|
|
93
|
+
// No retry transformer. Redirects must not forward the token-bearing URL.
|
|
94
|
+
api = (options.createApi ?? (credential => new Api(credential, {
|
|
95
|
+
sensitiveLogs: false, timeoutSeconds: 45, baseFetchConfig: { redirect: "error" },
|
|
96
|
+
})))(token);
|
|
97
|
+
} catch { throw new Error("Telegram API initialization failed; details suppressed"); }
|
|
98
|
+
|
|
99
|
+
const plannedCommands = MESSENGER_COMMANDS.map(command => ({ command: command.name, description: command.description }));
|
|
100
|
+
const language = languageCode === undefined ? {} : { language_code: languageCode };
|
|
101
|
+
const scopes: TelegramCommandRegistrationReport["scopes"] = [];
|
|
102
|
+
let botId: string;
|
|
103
|
+
try {
|
|
104
|
+
const bot = await api.getMe();
|
|
105
|
+
if (!bot.is_bot || !Number.isSafeInteger(bot.id) || bot.id <= 0 || String(bot.id) === policy.ownerId) throw new Error("Invalid bot identity");
|
|
106
|
+
botId = String(bot.id);
|
|
107
|
+
const ownerChat = await api.getChat(policy.ownerId);
|
|
108
|
+
if (String(ownerChat.id) !== policy.ownerId || ownerChat.type !== "private") throw new Error("Invalid owner DM");
|
|
109
|
+
const targets: OwnerScope[] = [{ type: "chat", chat_id: policy.ownerId }];
|
|
110
|
+
for (const chatId of new Set(policy.allowedChatIds)) {
|
|
111
|
+
const chat = await api.getChat(chatId);
|
|
112
|
+
if (String(chat.id) !== chatId || (chat.type !== "group" && chat.type !== "supergroup") ||
|
|
113
|
+
("is_direct_messages" in chat && chat.is_direct_messages === true)) throw new Error("Invalid allowed group");
|
|
114
|
+
const member = await api.getChatMember(chatId, Number(policy.ownerId));
|
|
115
|
+
if (String(member.user.id) !== policy.ownerId || member.user.is_bot ||
|
|
116
|
+
!(member.status === "creator" || member.status === "administrator" || member.status === "member" ||
|
|
117
|
+
(member.status === "restricted" && member.is_member))) throw new Error("Owner membership not verified");
|
|
118
|
+
targets.push({ type: "chat_member", chat_id: chatId, user_id: Number(policy.ownerId) });
|
|
119
|
+
}
|
|
120
|
+
// Finish every ownership and menu read before attempting any mutation.
|
|
121
|
+
for (const scope of targets) {
|
|
122
|
+
const current = commands(await api.getMyCommands({ scope, ...language }));
|
|
123
|
+
scopes.push({ scope, current, changed: !exact(current, plannedCommands) });
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
throw new Error("Telegram command inspection failed: bot identity, owner DM, allowed-group membership, or menu response could not be verified. No mutation was attempted; raw API details suppressed. No automatic retry was attempted.");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (options.apply === true) {
|
|
130
|
+
for (const target of scopes) {
|
|
131
|
+
if (!target.changed) continue;
|
|
132
|
+
try {
|
|
133
|
+
const result = await api.setMyCommands(plannedCommands, { scope: target.scope, ...language });
|
|
134
|
+
if (result !== true) throw new Error("Missing success receipt");
|
|
135
|
+
} catch {
|
|
136
|
+
throw new Error("Telegram command menu update is unresolved: the request failed and may have reached Telegram; earlier scopes may already have changed. No automatic retry was attempted; raw API details suppressed. Inspect with telegram-commands without --apply before deciding any further mutation.");
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const actual = commands(await api.getMyCommands({ scope: target.scope, ...language }));
|
|
140
|
+
if (!exact(actual, plannedCommands)) throw new Error("Menu readback differs");
|
|
141
|
+
} catch {
|
|
142
|
+
throw new Error("Telegram command menu update is unresolved: authoritative getMyCommands did not verify the exact supported names, descriptions, and order; earlier scopes may already have changed. No automatic retry was attempted; raw API details suppressed. Inspect with telegram-commands without --apply before deciding any further mutation.");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const redact = (text: string) => text.replaceAll(token, "[redacted]").replace(/https?:\/\/\S+/gi, "[redacted-url]");
|
|
147
|
+
return {
|
|
148
|
+
status: options.apply === true ? "applied" : "dry-run", botId, languageCode: options.languageCode ?? null,
|
|
149
|
+
plannedCommands,
|
|
150
|
+
scopes: scopes.map(target => ({ ...target, current: target.current.map(command => ({
|
|
151
|
+
command: command.command, description: redact(command.description),
|
|
152
|
+
})) })),
|
|
153
|
+
note: `${options.apply === true ? "Owner-scoped command menus verified by getMyCommands, including exact supported names, descriptions, and order." : "Read-only plan; no mutation was attempted. --apply replaces only these owner-scoped command lists."} Only the selected language list is inspected or changed. Other scopes and bot configuration are untouched. Language-specific menus not selected here are unknown and untouched: Telegram cannot enumerate them, and they may override the default-language menu. No polling, webhooks, or native runtime was started.`,
|
|
154
|
+
};
|
|
155
|
+
}
|