@deepseek-insight/telegram-bot 0.1.0 → 0.1.1
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/README.md +3 -3
- package/bin/dsi-telegram.mjs +4 -3
- package/dist/attachments.js +91 -0
- package/dist/chat-map.js +71 -0
- package/dist/commands.js +20 -0
- package/dist/dsi-client.js +62 -0
- package/dist/floor-cli.js +398 -0
- package/dist/index.js +405 -0
- package/dist/reply-stream.js +116 -0
- package/dist/slot.js +56 -0
- package/dist/status-listener.js +39 -0
- package/package.json +8 -5
- package/src/attachments.ts +0 -122
- package/src/chat-map.ts +0 -86
- package/src/commands.ts +0 -37
- package/src/dsi-client.ts +0 -153
- package/src/floor-cli.ts +0 -433
- package/src/index.ts +0 -479
- package/src/reply-stream.ts +0 -148
- package/src/slot.ts +0 -73
- package/src/status-listener.ts +0 -67
package/src/attachments.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* attachments — shape Telegram media into prompt parts (ADR-0090 D5).
|
|
3
|
-
* - photo / whitelisted image document → prompt.images[] as base64 (native sight)
|
|
4
|
-
* - any other document → the guarded file route, and the prompt text is
|
|
5
|
-
* prefixed with 'Attached files:' + one '- <path>' line per landing
|
|
6
|
-
* - over Telegram's 20 MB cap → skipped with a note in the text
|
|
7
|
-
* Pure shaping + injected loaders: this module never calls fetch (the DSI
|
|
8
|
-
* door is dsi-client; the Telegram download is injected by index.ts).
|
|
9
|
-
*/
|
|
10
|
-
import { PROMPT_IMAGE_MEDIA_TYPES } from './dsi-client.ts';
|
|
11
|
-
import type { DsiClient, PromptImageMediaType, PromptImagePart } from './dsi-client.ts';
|
|
12
|
-
|
|
13
|
-
/** Telegram bot getFile download ceiling (platform limit). */
|
|
14
|
-
export const TELEGRAM_FILE_CAP_BYTES = 20 * 1024 * 1024;
|
|
15
|
-
|
|
16
|
-
export interface PhotoInput {
|
|
17
|
-
/** file_id of the largest PhotoSize in the message. */
|
|
18
|
-
fileId: string;
|
|
19
|
-
}
|
|
20
|
-
export interface DocumentInput {
|
|
21
|
-
fileId: string;
|
|
22
|
-
mimeType?: string | undefined;
|
|
23
|
-
fileName?: string | undefined;
|
|
24
|
-
/** Telegram's file_size, when it sent one. */
|
|
25
|
-
fileSize?: number | undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Loads a Telegram file's bytes — owned by index.ts (grammY + file download). */
|
|
29
|
-
export type TelegramMediaLoader = (fileId: string) => Promise<{ bytes: Buffer; size: number }>;
|
|
30
|
-
|
|
31
|
-
export interface ShapeInput {
|
|
32
|
-
photo?: PhotoInput | undefined;
|
|
33
|
-
document?: DocumentInput | undefined;
|
|
34
|
-
caption: string;
|
|
35
|
-
client: Pick<DsiClient, 'file'>;
|
|
36
|
-
sessionId: string;
|
|
37
|
-
load: TelegramMediaLoader;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface ShapedPrompt {
|
|
41
|
-
images: PromptImagePart[];
|
|
42
|
-
text: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function isPromptImageMediaType(value: string): value is PromptImageMediaType {
|
|
46
|
-
return (PROMPT_IMAGE_MEDIA_TYPES as readonly string[]).includes(value);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** The inbox is flat (file route: basename only) — fold separators to '_'. */
|
|
50
|
-
export function inboxSafeName(name: string): string {
|
|
51
|
-
return name.length === 0 ? 'file' : name.replace(/\.\./g, '__').replace(/[/\\]/g, '_') || 'file';
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function failureNote(err: unknown): string {
|
|
55
|
-
if (err instanceof Error && 'code' in err) return `(${String((err as { code: unknown }).code)})`;
|
|
56
|
-
return `(${err instanceof Error ? err.message : String(err)})`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export async function shapeAttachments(input: ShapeInput): Promise<ShapedPrompt> {
|
|
60
|
-
const images: PromptImagePart[] = [];
|
|
61
|
-
const landed: string[] = [];
|
|
62
|
-
const notes: string[] = [];
|
|
63
|
-
|
|
64
|
-
if (input.photo) {
|
|
65
|
-
try {
|
|
66
|
-
const { bytes } = await input.load(input.photo.fileId);
|
|
67
|
-
images.push({ mediaType: 'image/jpeg', data: bytes.toString('base64'), name: 'photo.jpg' });
|
|
68
|
-
} catch (err) {
|
|
69
|
-
notes.push(`photo could not be downloaded ${failureNote(err)}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const doc = input.document;
|
|
74
|
-
if (doc) {
|
|
75
|
-
const name = inboxSafeName(doc.fileName ?? 'file');
|
|
76
|
-
const type = doc.mimeType ?? '';
|
|
77
|
-
if (isPromptImageMediaType(type)) {
|
|
78
|
-
try {
|
|
79
|
-
const { bytes } = await input.load(doc.fileId);
|
|
80
|
-
images.push({ mediaType: type, data: bytes.toString('base64'), name });
|
|
81
|
-
} catch (err) {
|
|
82
|
-
notes.push(`image "${name}" could not be downloaded ${failureNote(err)}`);
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
let oversized = typeof doc.fileSize === 'number' && doc.fileSize > TELEGRAM_FILE_CAP_BYTES;
|
|
86
|
-
let bytes: Buffer | null = null;
|
|
87
|
-
if (!oversized) {
|
|
88
|
-
try {
|
|
89
|
-
const loaded = await input.load(doc.fileId);
|
|
90
|
-
bytes = loaded.bytes;
|
|
91
|
-
oversized =
|
|
92
|
-
loaded.size > TELEGRAM_FILE_CAP_BYTES || loaded.bytes.length > TELEGRAM_FILE_CAP_BYTES;
|
|
93
|
-
} catch (err) {
|
|
94
|
-
notes.push(`"${name}" could not be downloaded ${failureNote(err)}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (oversized) {
|
|
98
|
-
notes.push(`"${name}" is over 20 MB — not attached`);
|
|
99
|
-
} else if (bytes) {
|
|
100
|
-
try {
|
|
101
|
-
const out = await input.client.file(input.sessionId, {
|
|
102
|
-
name,
|
|
103
|
-
mediaType: type.length > 0 ? type : 'application/octet-stream',
|
|
104
|
-
data: bytes.toString('base64')
|
|
105
|
-
});
|
|
106
|
-
landed.push(out.path);
|
|
107
|
-
} catch (err) {
|
|
108
|
-
notes.push(`"${name}" could not be landed ${failureNote(err)}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let text = input.caption;
|
|
115
|
-
if (landed.length > 0) {
|
|
116
|
-
text = `Attached files:\n${landed.map((p) => `- ${p}`).join('\n')}\n\n${text}`;
|
|
117
|
-
}
|
|
118
|
-
if (notes.length > 0) {
|
|
119
|
-
text = `${text}${text.length > 0 ? '\n\n' : ''}${notes.join('\n')}`;
|
|
120
|
-
}
|
|
121
|
-
return { images, text };
|
|
122
|
-
}
|
package/src/chat-map.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* chat-map — the ONLY reader/writer of ~/.dsi/telegram-chats.json (ADR-0090 D4).
|
|
3
|
-
* chatId → {sessionId, cwd}. `cwd` is the NEXT /new's argument (D8): /ws
|
|
4
|
-
* updates it and never touches a live session. Atomic write (tmp + rename).
|
|
5
|
-
* A corrupt file starts empty with one console line — never a crash loop.
|
|
6
|
-
*/
|
|
7
|
-
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
8
|
-
import { homedir } from 'node:os';
|
|
9
|
-
import { dirname, join } from 'node:path';
|
|
10
|
-
|
|
11
|
-
/** Operator decision 2026-12-02: default workspace is ~/agentic-ai. */
|
|
12
|
-
export const DEFAULT_CWD = join(homedir(), 'agentic-ai');
|
|
13
|
-
export const CHAT_MAP_PATH = join(homedir(), '.dsi', 'telegram-chats.json');
|
|
14
|
-
|
|
15
|
-
export interface ChatRecord {
|
|
16
|
-
/** null until the chat's first /new or first prompt. */
|
|
17
|
-
sessionId: string | null;
|
|
18
|
-
/** cwd for the NEXT session create — never retroactive (D8). */
|
|
19
|
-
cwd: string;
|
|
20
|
-
}
|
|
21
|
-
export type ChatMap = Record<string, ChatRecord>;
|
|
22
|
-
export type ChatId = number | string;
|
|
23
|
-
|
|
24
|
-
export function loadChatMap(path = CHAT_MAP_PATH): ChatMap {
|
|
25
|
-
let text: string;
|
|
26
|
-
try {
|
|
27
|
-
text = readFileSync(path, 'utf-8');
|
|
28
|
-
} catch {
|
|
29
|
-
return {}; // missing → empty
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
const parsed: unknown = JSON.parse(text);
|
|
33
|
-
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
34
|
-
throw new Error('not an object');
|
|
35
|
-
}
|
|
36
|
-
const out: ChatMap = {};
|
|
37
|
-
for (const [key, value] of Object.entries(parsed as Record<string, unknown>)) {
|
|
38
|
-
const r = (value ?? {}) as Partial<ChatRecord>;
|
|
39
|
-
out[key] = {
|
|
40
|
-
sessionId: typeof r.sessionId === 'string' ? r.sessionId : null,
|
|
41
|
-
cwd: typeof r.cwd === 'string' && r.cwd.length > 0 ? r.cwd : DEFAULT_CWD
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return out;
|
|
45
|
-
} catch (err) {
|
|
46
|
-
console.warn(
|
|
47
|
-
`[telegram-bot] chat map at ${path} is corrupt (${err instanceof Error ? err.message : String(err)}) — starting empty`
|
|
48
|
-
);
|
|
49
|
-
return {};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Atomic: write a sibling tmp file, then rename over the target. */
|
|
54
|
-
export function saveChatMap(map: ChatMap, path = CHAT_MAP_PATH): void {
|
|
55
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
56
|
-
const tmp = `${path}.tmp-${process.pid}-${Date.now()}`;
|
|
57
|
-
writeFileSync(tmp, JSON.stringify(map, null, 2) + '\n', 'utf-8');
|
|
58
|
-
renameSync(tmp, path);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function keyOf(chatId: ChatId): string {
|
|
62
|
-
return String(chatId);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** The chat's record, created with defaults ({sessionId:null}, DEFAULT_CWD) on first touch. */
|
|
66
|
-
export function get(map: ChatMap, chatId: ChatId): ChatRecord {
|
|
67
|
-
const key = keyOf(chatId);
|
|
68
|
-
const existing = map[key];
|
|
69
|
-
if (existing) return existing;
|
|
70
|
-
const fresh: ChatRecord = { sessionId: null, cwd: DEFAULT_CWD };
|
|
71
|
-
map[key] = fresh;
|
|
72
|
-
return fresh;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function setSession(map: ChatMap, chatId: ChatId, sessionId: string): ChatRecord {
|
|
76
|
-
const rec = get(map, chatId);
|
|
77
|
-
rec.sessionId = sessionId;
|
|
78
|
-
return rec;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** D8 — cwd only. The record's sessionId is left exactly as it was. */
|
|
82
|
-
export function setCwd(map: ChatMap, chatId: ChatId, cwd: string): ChatRecord {
|
|
83
|
-
const rec = get(map, chatId);
|
|
84
|
-
rec.cwd = cwd;
|
|
85
|
-
return rec;
|
|
86
|
-
}
|
package/src/commands.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* commands — THE command list (ADR-0092 D2). One owner, four readers, zero
|
|
3
|
-
* typists: the Telegram menu (pushed at boot by index.ts pushCommandMenu),
|
|
4
|
-
* the `unknown command` hint, the README table (pinned by tests/commands.test.ts)
|
|
5
|
-
* and the router's `switch` (pinned: every entry is routed). Pure — no grammy
|
|
6
|
-
* runtime, no side effects; nothing here knows Telegram's API beyond BotCommand's shape.
|
|
7
|
-
*/
|
|
8
|
-
import type { BotCommand } from 'grammy/types';
|
|
9
|
-
|
|
10
|
-
export interface CommandRow {
|
|
11
|
-
command: string;
|
|
12
|
-
description: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** README order. `/1` stands for the /N pattern (D3) — the hint and README keep the `/N` spelling. */
|
|
16
|
-
export const COMMANDS: readonly CommandRow[] = [
|
|
17
|
-
{ command: '/id', description: 'print the chat id and your user id' },
|
|
18
|
-
{ command: '/new', description: "fresh session in the chat's current cwd" },
|
|
19
|
-
{ command: '/ws', description: 'set the cwd for the next /new (never moves a live session)' },
|
|
20
|
-
{ command: '/status', description: 'is the agent running?' },
|
|
21
|
-
{ command: '/cancel', description: 'stop the running turn' },
|
|
22
|
-
{ command: '/1', description: 'answer the pending question with option 1 (/2, /3 …)' },
|
|
23
|
-
{ command: '/skills', description: "list the host's skills for this chat's session, or run one: /skills <name> [args] (ADR-0092)" }
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
export const PATTERN_COMMAND = '/N';
|
|
27
|
-
|
|
28
|
-
/** The rows as Telegram's setMyCommands takes them: the command without its slash (D1). */
|
|
29
|
-
export function menuCommands(): BotCommand[] {
|
|
30
|
-
return COMMANDS.map((c) => ({ command: c.command.slice(1), description: c.description }));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** `unknown command — /id /new … /N /skills` — derived, never typed (D2). */
|
|
34
|
-
export function unknownCommandHint(): string {
|
|
35
|
-
const names = COMMANDS.map((c) => c.command).filter((c) => c !== '/1');
|
|
36
|
-
return `unknown command — ${[...names.slice(0, -1), PATTERN_COMMAND, names[names.length - 1]].join(' ')}`;
|
|
37
|
-
}
|
package/src/dsi-client.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dsi-client — the ONLY module in this package that speaks HTTP to DSI
|
|
3
|
-
* (ADR-0090 D1: an ordinary client of /api/dsh/*; no Telegram namespace).
|
|
4
|
-
* Every call carries the bridge bearer; every non-2xx answer is a
|
|
5
|
-
* DsiClientError{status, code}. Nothing here knows Telegram; nothing else
|
|
6
|
-
* in the package knows DSI's URLs.
|
|
7
|
-
* ADR-0092 D5: `catalog()` reads the composer's own route per invocation — no cache, no retry.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export const API_ROOT = '/api/dsh';
|
|
11
|
-
|
|
12
|
-
export type FetchLike = typeof fetch;
|
|
13
|
-
|
|
14
|
-
export interface DsiClientOptions {
|
|
15
|
-
/** DSI origin, e.g. http://127.0.0.1:5201 (trailing slash tolerated). */
|
|
16
|
-
baseUrl: string;
|
|
17
|
-
/** settings.telegram.token — the bridge bearer (ADR-0090 D3). */
|
|
18
|
-
token: string;
|
|
19
|
-
/** Injected for tests; defaults to globalThis.fetch. */
|
|
20
|
-
fetch?: FetchLike;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class DsiClientError extends Error {
|
|
24
|
-
readonly status: number;
|
|
25
|
-
readonly code: string;
|
|
26
|
-
|
|
27
|
-
constructor(status: number, code: string, message: string) {
|
|
28
|
-
super(`DSI ${status} ${code}: ${message}`);
|
|
29
|
-
this.name = 'DsiClientError';
|
|
30
|
-
this.status = status;
|
|
31
|
-
this.code = code;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Host prompt-image whitelist (dsh-rpc.ts:595) — mirrored, never widened (ADR-0090 D2). */
|
|
36
|
-
export const PROMPT_IMAGE_MEDIA_TYPES = ['image/png', 'image/jpeg', 'image/webp', 'image/gif'] as const;
|
|
37
|
-
export type PromptImageMediaType = (typeof PROMPT_IMAGE_MEDIA_TYPES)[number];
|
|
38
|
-
export interface PromptImagePart {
|
|
39
|
-
mediaType: PromptImageMediaType;
|
|
40
|
-
/** base64 */
|
|
41
|
-
data: string;
|
|
42
|
-
name?: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** The events poll's subset this package reads (types.ts DsiEntry / rpc-relay PendingAnswerFrame). */
|
|
46
|
-
export interface DsiAssistantEntry {
|
|
47
|
-
kind: 'assistant-message';
|
|
48
|
-
id: string;
|
|
49
|
-
seq: number;
|
|
50
|
-
time: number;
|
|
51
|
-
text: string;
|
|
52
|
-
streaming: boolean;
|
|
53
|
-
reasoning?: string;
|
|
54
|
-
}
|
|
55
|
-
export interface DsiPendingAnswer {
|
|
56
|
-
rpcId: string;
|
|
57
|
-
sessionId: string;
|
|
58
|
-
kind: 'approval' | 'question';
|
|
59
|
-
body: Record<string, unknown>;
|
|
60
|
-
receivedAt: number;
|
|
61
|
-
}
|
|
62
|
-
export interface DsiLiveStreamTail {
|
|
63
|
-
id: string;
|
|
64
|
-
turn: number;
|
|
65
|
-
step: number;
|
|
66
|
-
seq: number;
|
|
67
|
-
time: number;
|
|
68
|
-
text: string;
|
|
69
|
-
reasoning: string;
|
|
70
|
-
}
|
|
71
|
-
export interface DsiEventsResult {
|
|
72
|
-
ok: true;
|
|
73
|
-
entries: Array<Record<string, unknown>>;
|
|
74
|
-
lastSeq: number;
|
|
75
|
-
running: boolean;
|
|
76
|
-
gap?: boolean;
|
|
77
|
-
liveStream?: DsiLiveStreamTail | null;
|
|
78
|
-
pendingAnswers: DsiPendingAnswer[];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Mirror of dsh-rpc.ts DshSkillRow — the host's skill catalog row (ADR-0092 D5). */
|
|
82
|
-
export interface DsiSkillRow {
|
|
83
|
-
name: string;
|
|
84
|
-
description: string;
|
|
85
|
-
whenToUse?: string;
|
|
86
|
-
modelInvocable: boolean;
|
|
87
|
-
}
|
|
88
|
-
/** The catalog route's body: commands/list + skills/list for one session (either leg failing fails the whole catalog). */
|
|
89
|
-
export interface DsiCatalog {
|
|
90
|
-
ok: true;
|
|
91
|
-
commands: Array<Record<string, unknown>>;
|
|
92
|
-
skills: DsiSkillRow[];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export interface DsiClient {
|
|
96
|
-
createSession(cwd: string): Promise<{ sessionId: string }>;
|
|
97
|
-
prompt(sessionId: string, input: { text: string; images?: PromptImagePart[] }): Promise<{ accepted: boolean }>;
|
|
98
|
-
events(sessionId: string, since: number): Promise<DsiEventsResult>;
|
|
99
|
-
respond(sessionId: string, rpcId: string, payload: Record<string, unknown>): Promise<{ ok: boolean; accepted: boolean }>;
|
|
100
|
-
cancel(sessionId: string): Promise<{ ok: boolean; accepted: boolean }>;
|
|
101
|
-
/** The guarded landing route (ADR-0090 D2/D5). */
|
|
102
|
-
file(sessionId: string, input: { name: string; mediaType: string; data: string }): Promise<{ ok: boolean; path: string }>;
|
|
103
|
-
/** The guarded long-poll (ADR-0090 D2/D6). */
|
|
104
|
-
turn(sessionId: string): Promise<{ ok: boolean; running: boolean }>;
|
|
105
|
-
/** The composer's catalog route, read per invocation (ADR-0092 D5). */
|
|
106
|
-
catalog(sessionId: string): Promise<DsiCatalog>;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
type Method = 'GET' | 'POST';
|
|
110
|
-
|
|
111
|
-
export function createDsiClient(options: DsiClientOptions): DsiClient {
|
|
112
|
-
const baseUrl = options.baseUrl.replace(/\/+$/, '');
|
|
113
|
-
const doFetch = options.fetch ?? fetch;
|
|
114
|
-
|
|
115
|
-
/** The one HTTP door. `path` is always relative to API_ROOT. */
|
|
116
|
-
async function call<T>(method: Method, path: string, body?: unknown): Promise<T> {
|
|
117
|
-
const headers: Record<string, string> = { authorization: `Bearer ${options.token}` };
|
|
118
|
-
if (body !== undefined) headers['content-type'] = 'application/json';
|
|
119
|
-
const res = await doFetch(baseUrl + path, {
|
|
120
|
-
method,
|
|
121
|
-
headers,
|
|
122
|
-
...(body === undefined ? {} : { body: JSON.stringify(body) })
|
|
123
|
-
});
|
|
124
|
-
let parsed: unknown = null;
|
|
125
|
-
try {
|
|
126
|
-
parsed = await res.json();
|
|
127
|
-
} catch {
|
|
128
|
-
parsed = null;
|
|
129
|
-
}
|
|
130
|
-
if (!res.ok) {
|
|
131
|
-
const rec = (parsed ?? {}) as { error?: { code?: unknown; message?: unknown } };
|
|
132
|
-
const code = typeof rec.error?.code === 'string' ? rec.error.code : `http-${res.status}`;
|
|
133
|
-
const message = typeof rec.error?.message === 'string' ? rec.error.message : res.statusText;
|
|
134
|
-
throw new DsiClientError(res.status, code, message);
|
|
135
|
-
}
|
|
136
|
-
return parsed as T;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const enc = encodeURIComponent;
|
|
140
|
-
const session = (id: string): string => `${API_ROOT}/session/${enc(id)}`;
|
|
141
|
-
|
|
142
|
-
return {
|
|
143
|
-
createSession: (cwd) => call('POST', `${API_ROOT}/sessions`, { cwd }),
|
|
144
|
-
prompt: (id, { text, images }) =>
|
|
145
|
-
call('POST', `${session(id)}/prompt`, { text, ...(images === undefined ? {} : { images }) }),
|
|
146
|
-
events: (id, since) => call('GET', `${session(id)}/events?since=${since}`),
|
|
147
|
-
respond: (id, rpcId, payload) => call('POST', `${session(id)}/respond`, { rpcId, payload }),
|
|
148
|
-
cancel: (id) => call('POST', `${session(id)}/cancel`, {}),
|
|
149
|
-
file: (id, { name, mediaType, data }) => call('POST', `${session(id)}/file`, { name, mediaType, data }),
|
|
150
|
-
turn: (id) => call('GET', `${session(id)}/turn`),
|
|
151
|
-
catalog: (id) => call('GET', `${session(id)}/catalog`)
|
|
152
|
-
};
|
|
153
|
-
}
|