@diegoaltoworks/chatter 0.61.0 → 0.62.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/README.md +55 -17
- package/dist/auth/secretStrength.d.ts +1 -1
- package/dist/auth/secretStrength.d.ts.map +1 -1
- package/dist/bin/create-apikey.js +45 -28
- package/dist/bin/wa-pair.js +113 -46
- package/dist/channels/backoff.d.ts +10 -0
- package/dist/channels/backoff.d.ts.map +1 -0
- package/dist/channels/gates.d.ts +15 -8
- package/dist/channels/gates.d.ts.map +1 -1
- package/dist/channels/index.d.ts +1 -1
- package/dist/channels/index.d.ts.map +1 -1
- package/dist/channels/index.js +38 -5
- package/dist/channels/index.mjs +37 -5
- package/dist/channels/matrix/api.d.ts +25 -6
- package/dist/channels/matrix/api.d.ts.map +1 -1
- package/dist/channels/matrix/channel.d.ts +4 -56
- package/dist/channels/matrix/channel.d.ts.map +1 -1
- package/dist/channels/matrix/handler.d.ts +16 -9
- package/dist/channels/matrix/handler.d.ts.map +1 -1
- package/dist/channels/matrix/index.d.ts +2 -2
- package/dist/channels/matrix/index.d.ts.map +1 -1
- package/dist/channels/matrix/index.js +196 -40
- package/dist/channels/matrix/index.mjs +189 -39
- package/dist/channels/matrix/sync.d.ts +4 -1
- package/dist/channels/matrix/sync.d.ts.map +1 -1
- package/dist/channels/matrix/updates.d.ts +39 -10
- package/dist/channels/matrix/updates.d.ts.map +1 -1
- package/dist/channels/pipeline.d.ts +14 -14
- package/dist/channels/pipeline.d.ts.map +1 -1
- package/dist/channels/polling.d.ts +67 -0
- package/dist/channels/polling.d.ts.map +1 -0
- package/dist/channels/telegram/channel.d.ts +2 -56
- package/dist/channels/telegram/channel.d.ts.map +1 -1
- package/dist/channels/telegram/index.js +53 -23
- package/dist/channels/telegram/index.mjs +53 -23
- package/dist/channels/telegram/poll.d.ts +5 -1
- package/dist/channels/telegram/poll.d.ts.map +1 -1
- package/dist/channels/telegram/webhook.d.ts +2 -10
- package/dist/channels/telegram/webhook.d.ts.map +1 -1
- package/dist/channels/whatsapp/authState.d.ts +40 -9
- package/dist/channels/whatsapp/authState.d.ts.map +1 -1
- package/dist/channels/whatsapp/channel.d.ts +25 -4
- package/dist/channels/whatsapp/channel.d.ts.map +1 -1
- package/dist/channels/whatsapp/inbound.d.ts +23 -25
- package/dist/channels/whatsapp/inbound.d.ts.map +1 -1
- package/dist/channels/whatsapp/index.d.ts +3 -3
- package/dist/channels/whatsapp/index.d.ts.map +1 -1
- package/dist/channels/whatsapp/index.js +123 -41
- package/dist/channels/whatsapp/index.mjs +120 -41
- package/dist/channels/whatsapp/pairing.d.ts.map +1 -1
- package/dist/client/src/Chat.d.ts.map +1 -1
- package/dist/client/src/ChatButton.d.ts.map +1 -1
- package/dist/client/src/browser.d.ts.map +1 -1
- package/dist/core/answer.d.ts +8 -0
- package/dist/core/answer.d.ts.map +1 -1
- package/dist/core/buildLock.d.ts +52 -0
- package/dist/core/buildLock.d.ts.map +1 -0
- package/dist/core/pipeline.d.ts +42 -5
- package/dist/core/pipeline.d.ts.map +1 -1
- package/dist/core/prompts.d.ts +2 -0
- package/dist/core/prompts.d.ts.map +1 -1
- package/dist/core/retrieval.d.ts +100 -25
- package/dist/core/retrieval.d.ts.map +1 -1
- package/dist/core/session.d.ts +8 -0
- package/dist/core/session.d.ts.map +1 -1
- package/dist/flows/index.d.ts +1 -1
- package/dist/flows/index.d.ts.map +1 -1
- package/dist/flows/index.js +8 -6
- package/dist/flows/index.mjs +7 -6
- package/dist/flows/intent.d.ts +1 -1
- package/dist/flows/intent.d.ts.map +1 -1
- package/dist/flows/loader.d.ts +1 -2
- package/dist/flows/loader.d.ts.map +1 -1
- package/dist/flows/params.d.ts +1 -1
- package/dist/flows/params.d.ts.map +1 -1
- package/dist/flows/session.d.ts +4 -2
- package/dist/flows/session.d.ts.map +1 -1
- package/dist/flows/types.d.ts +2 -3
- package/dist/flows/types.d.ts.map +1 -1
- package/dist/history/index.d.ts +1 -1
- package/dist/history/index.d.ts.map +1 -1
- package/dist/history/index.js +6 -3
- package/dist/history/index.mjs +5 -3
- package/dist/history/tursoStore.d.ts +6 -4
- package/dist/history/tursoStore.d.ts.map +1 -1
- package/dist/images/index.js +2 -2
- package/dist/images/index.mjs +2 -2
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +596 -295
- package/dist/index.mjs +595 -295
- package/dist/mcp-server/index.d.ts +5 -5
- package/dist/mcp-server/index.d.ts.map +1 -1
- package/dist/mcp-server/logger.d.ts +12 -2
- package/dist/mcp-server/logger.d.ts.map +1 -1
- package/dist/mcp-server/rate-limiter.d.ts +10 -3
- package/dist/mcp-server/rate-limiter.d.ts.map +1 -1
- package/dist/mcp-server/types.d.ts +20 -5
- package/dist/mcp-server/types.d.ts.map +1 -1
- package/dist/mcp-server.js +479 -244
- package/dist/mcp-server.mjs +485 -244
- package/dist/middleware/apiKey.d.ts +10 -0
- package/dist/middleware/apiKey.d.ts.map +1 -0
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/cors.d.ts.map +1 -1
- package/dist/middleware/ratelimit.d.ts.map +1 -1
- package/dist/middleware/referrer.d.ts.map +1 -1
- package/dist/middleware/session.d.ts +1 -1
- package/dist/middleware/session.d.ts.map +1 -1
- package/dist/routes/demo.d.ts.map +1 -1
- package/dist/routes/openai.d.ts.map +1 -1
- package/dist/routes/private.d.ts.map +1 -1
- package/dist/routes/public.d.ts.map +1 -1
- package/dist/scheduler/index.js +1 -1
- package/dist/scheduler/index.mjs +1 -1
- package/dist/scheduler/scheduler.d.ts +9 -1
- package/dist/scheduler/scheduler.d.ts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +491 -268
- package/dist/server.mjs +497 -268
- package/dist/shortener.d.ts +5 -4
- package/dist/shortener.d.ts.map +1 -1
- package/dist/types.d.ts +129 -75
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared config surface for a long-poll style channel (Telegram, Matrix): the
|
|
3
|
+
* gates/persona/history/rate-limit knobs `createInboundPipeline` accepts, the
|
|
4
|
+
* brain hooks (via `BrainHooks`), and the sleep/now/logger overrides tests
|
|
5
|
+
* use. Each transport extends this with its own protocol specifics (poll
|
|
6
|
+
* timeout vs. sync timeout, bot token vs. homeserver credentials, ...): see
|
|
7
|
+
* `./telegram/channel.ts` and `./matrix/channel.ts`.
|
|
8
|
+
*/
|
|
9
|
+
import type { Logger } from "../core/logger";
|
|
10
|
+
import type { HistoryCompactionOptions } from "../history/compaction";
|
|
11
|
+
import type { HistoryStore } from "../history/types";
|
|
12
|
+
import type { BrainHooks } from "../types";
|
|
13
|
+
export interface PollingChannelConfig extends BrainHooks {
|
|
14
|
+
/** Channel and sender-registry name. Override to run more than one bot in one process. */
|
|
15
|
+
name?: string;
|
|
16
|
+
/** Group chats eligible for a reply. Empty (default) = every group/room. Has no effect on DMs, which always reply. */
|
|
17
|
+
allowedChats?: string[];
|
|
18
|
+
model?: string;
|
|
19
|
+
/** Extra system-prompt section describing the delivery channel; passed through to `prepareChat`. */
|
|
20
|
+
channelHint?: string;
|
|
21
|
+
/** A throw/rejection is treated as "no persona" for that turn. */
|
|
22
|
+
personaResolver?: (ctx: {
|
|
23
|
+
sender: string;
|
|
24
|
+
text: string;
|
|
25
|
+
}) => string | undefined | Promise<string | undefined>;
|
|
26
|
+
/** Off by default — the channel stays single-turn until a store is configured. */
|
|
27
|
+
history?: {
|
|
28
|
+
store: HistoryStore;
|
|
29
|
+
/** Most recent turns to load per reply. @default 20 */
|
|
30
|
+
limit?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Excludes a sender from history entirely — see
|
|
33
|
+
* `InboundPipelineConfig.history.historyEnabledFor` in `./channels`.
|
|
34
|
+
* @default every sender is enabled
|
|
35
|
+
*/
|
|
36
|
+
historyEnabledFor?: (sender: string) => boolean | Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Summarize-then-truncate compaction — see
|
|
39
|
+
* `InboundPipelineConfig.history.compaction` in `./channels`.
|
|
40
|
+
* @default off
|
|
41
|
+
*/
|
|
42
|
+
compaction?: HistoryCompactionOptions;
|
|
43
|
+
};
|
|
44
|
+
muteRegex?: RegExp;
|
|
45
|
+
unmuteRegex?: RegExp;
|
|
46
|
+
/** Neutral, overridable acknowledgements — this module ships no bot personality; unset = silent mute/unmute. */
|
|
47
|
+
muteReply?: string;
|
|
48
|
+
unmuteReply?: string;
|
|
49
|
+
dmRateLimit?: {
|
|
50
|
+
max: number;
|
|
51
|
+
windowMs: number;
|
|
52
|
+
};
|
|
53
|
+
groupRateLimit?: {
|
|
54
|
+
max: number;
|
|
55
|
+
windowMs: number;
|
|
56
|
+
};
|
|
57
|
+
/** Overridable for tests and for hosts routing through a proxy; defaults to `globalThis.fetch`. */
|
|
58
|
+
fetch?: typeof fetch;
|
|
59
|
+
/** Overridable for tests; defaults to a `setTimeout`-based sleep. */
|
|
60
|
+
sleep?: (ms: number) => Promise<void>;
|
|
61
|
+
now?: () => number;
|
|
62
|
+
/** Logger for poll/gate diagnostics. Falls back to the host's `deps.logger`, then a console logger. */
|
|
63
|
+
logger?: Logger;
|
|
64
|
+
}
|
|
65
|
+
/** `setTimeout`-based sleep, `unref`'d where supported so a pending sleep never keeps the process alive on its own. */
|
|
66
|
+
export declare function defaultSleep(ms: number): Promise<void>;
|
|
67
|
+
//# sourceMappingURL=polling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../src/channels/polling.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACtD,0FAA0F;IAC1F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sHAAsH;IACtH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oGAAoG;IACpG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACvD,kFAAkF;IAClF,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,YAAY,CAAC;QACpB,uDAAuD;QACvD,KAAK,CAAC,EAAE,MAAM,CAAC;QACf;;;;WAIG;QACH,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QACnE;;;;WAIG;QACH,UAAU,CAAC,EAAE,wBAAwB,CAAC;KACvC,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gHAAgH;IAChH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,cAAc,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,mGAAmG;IACnG,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,qEAAqE;IACrE,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,uGAAuG;IACvG,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,uHAAuH;AACvH,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKtD"}
|
|
@@ -20,30 +20,14 @@
|
|
|
20
20
|
* Telegram's privacy mode means it only receives messages that address it —
|
|
21
21
|
* which is the same policy `decideChannelAction` applies anyway.
|
|
22
22
|
*/
|
|
23
|
-
import type { AnswerFn, TransformReply } from "../../core/answer";
|
|
24
|
-
import type { BucketsFor } from "../../core/buckets";
|
|
25
|
-
import { type Logger } from "../../core/logger";
|
|
26
|
-
import type { RerankContext, RewriteQuery } from "../../core/pipeline";
|
|
27
|
-
import type { HistoryCompactionOptions } from "../../history/compaction";
|
|
28
|
-
import type { HistoryStore } from "../../history/types";
|
|
29
23
|
import type { Channel } from "../index";
|
|
24
|
+
import { type PollingChannelConfig } from "../polling";
|
|
30
25
|
import { type TelegramApi } from "./api";
|
|
31
|
-
export interface TelegramChannelConfig {
|
|
26
|
+
export interface TelegramChannelConfig extends PollingChannelConfig {
|
|
32
27
|
/** From @BotFather. A credential — pass it from the environment, never commit it. */
|
|
33
28
|
botToken: string;
|
|
34
29
|
/** Channel and sender-registry name. Override to run more than one bot in one process. @default "telegram" */
|
|
35
30
|
name?: string;
|
|
36
|
-
/** Group chats eligible for a reply. Empty (default) = every group. Has no effect on DMs, which always reply. */
|
|
37
|
-
allowedChats?: string[];
|
|
38
|
-
answerFn?: AnswerFn;
|
|
39
|
-
bucketsFor?: BucketsFor;
|
|
40
|
-
/** Rewrites the retrieval query before it reaches the vector store — see `ChatterConfig.rewriteQuery`. Falls back to the server's own. */
|
|
41
|
-
rewriteQuery?: RewriteQuery;
|
|
42
|
-
/** Post-processes retrieved chunks before they're folded into the prompt — see `ChatterConfig.rerankContext`. Falls back to the server's own. */
|
|
43
|
-
rerankContext?: RerankContext;
|
|
44
|
-
/** Modifies or vetoes the produced reply before delivery — see `ChatterConfig.transformReply`. Falls back to the server's own. */
|
|
45
|
-
transformReply?: TransformReply;
|
|
46
|
-
model?: string;
|
|
47
31
|
/** Extra system-prompt section describing the delivery channel; passed through to `prepareChat`. @default "Channel: Telegram." */
|
|
48
32
|
channelHint?: string;
|
|
49
33
|
/** A throw/rejection is treated as "no persona" for that turn. `sender` is the namespaced `tg:<id>` key. */
|
|
@@ -51,54 +35,16 @@ export interface TelegramChannelConfig {
|
|
|
51
35
|
sender: string;
|
|
52
36
|
text: string;
|
|
53
37
|
}) => string | undefined | Promise<string | undefined>;
|
|
54
|
-
/** Off by default — the channel stays single-turn until a store is configured. */
|
|
55
|
-
history?: {
|
|
56
|
-
store: HistoryStore;
|
|
57
|
-
/** Most recent turns to load per reply. @default 20 */
|
|
58
|
-
limit?: number;
|
|
59
|
-
/**
|
|
60
|
-
* Excludes a sender from history entirely — see
|
|
61
|
-
* `InboundPipelineConfig.history.historyEnabledFor` in `./channels`.
|
|
62
|
-
* @default every sender is enabled
|
|
63
|
-
*/
|
|
64
|
-
historyEnabledFor?: (sender: string) => boolean | Promise<boolean>;
|
|
65
|
-
/**
|
|
66
|
-
* Summarize-then-truncate compaction — see
|
|
67
|
-
* `InboundPipelineConfig.history.compaction` in `./channels`.
|
|
68
|
-
* @default off
|
|
69
|
-
*/
|
|
70
|
-
compaction?: HistoryCompactionOptions;
|
|
71
|
-
};
|
|
72
|
-
muteRegex?: RegExp;
|
|
73
|
-
unmuteRegex?: RegExp;
|
|
74
|
-
/** Neutral, overridable acknowledgements — this module ships no bot personality; unset = silent mute/unmute. */
|
|
75
|
-
muteReply?: string;
|
|
76
|
-
unmuteReply?: string;
|
|
77
|
-
dmRateLimit?: {
|
|
78
|
-
max: number;
|
|
79
|
-
windowMs: number;
|
|
80
|
-
};
|
|
81
|
-
groupRateLimit?: {
|
|
82
|
-
max: number;
|
|
83
|
-
windowMs: number;
|
|
84
|
-
};
|
|
85
38
|
/** @default 30 */
|
|
86
39
|
pollTimeoutSeconds?: number;
|
|
87
40
|
/** Resume point for `getUpdates`. Omitted = whatever Telegram still has queued (see docs/telegram.md). */
|
|
88
41
|
initialOffset?: number;
|
|
89
42
|
/** Called with each acknowledged offset, for a host that wants to persist it across restarts. */
|
|
90
43
|
onOffset?: (offset: number) => void;
|
|
91
|
-
/** Overridable for tests and for hosts routing through a proxy; defaults to `globalThis.fetch`. */
|
|
92
|
-
fetch?: typeof fetch;
|
|
93
44
|
/** Self-hosted Bot API server origin. */
|
|
94
45
|
apiBaseUrl?: string;
|
|
95
46
|
/** Overridable for tests, which fake the Bot API instead of calling it; defaults to a `fetch` client over {@link TelegramChannelConfig.botToken}. */
|
|
96
47
|
api?: TelegramApi;
|
|
97
|
-
/** Overridable for tests; defaults to a `setTimeout`-based sleep. */
|
|
98
|
-
sleep?: (ms: number) => Promise<void>;
|
|
99
|
-
now?: () => number;
|
|
100
|
-
/** Logger for poll/gate diagnostics. Falls back to the host's `deps.logger`, then a console logger. */
|
|
101
|
-
logger?: Logger;
|
|
102
48
|
}
|
|
103
49
|
export declare function createTelegramChannel(config: TelegramChannelConfig): Channel;
|
|
104
50
|
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../../src/channels/telegram/channel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../../src/channels/telegram/channel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAgB,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,OAAO,CAAC;AAQ5D,MAAM,WAAW,qBAAsB,SAAQ,oBAAoB;IACjE,qFAAqF;IACrF,QAAQ,EAAE,MAAM,CAAC;IACjB,8GAA8G;IAC9G,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kIAAkI;IAClI,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4GAA4G;IAC5G,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACvD,kBAAkB;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,0GAA0G;IAC1G,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iGAAiG;IACjG,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qJAAqJ;IACrJ,GAAG,CAAC,EAAE,WAAW,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAmG5E"}
|
|
@@ -294,7 +294,8 @@ async function answerOnce({
|
|
|
294
294
|
async function applyTransformReply(transformReply, input, logger) {
|
|
295
295
|
if (!transformReply) return input.text;
|
|
296
296
|
try {
|
|
297
|
-
|
|
297
|
+
const result = await transformReply(input);
|
|
298
|
+
return typeof result === "string" ? result : null;
|
|
298
299
|
} catch (error) {
|
|
299
300
|
logger?.error(
|
|
300
301
|
`transformReply threw for channel "${input.channel}"; sending the original reply`,
|
|
@@ -356,6 +357,7 @@ async function prepareChat({
|
|
|
356
357
|
sender,
|
|
357
358
|
rewriteQuery,
|
|
358
359
|
rerankContext,
|
|
360
|
+
fallbackFn,
|
|
359
361
|
logger
|
|
360
362
|
}) {
|
|
361
363
|
const lastUserMsg = lastUserMessage(messages);
|
|
@@ -372,21 +374,39 @@ async function prepareChat({
|
|
|
372
374
|
logger?.error("rewriteQuery threw; falling back to the original query", error);
|
|
373
375
|
}
|
|
374
376
|
}
|
|
375
|
-
|
|
377
|
+
const resolvedBuckets = buckets ?? defaultBuckets(mode);
|
|
378
|
+
const retrievedChunks = await store.query(query, topK, resolvedBuckets);
|
|
379
|
+
let ctx = retrievedChunks;
|
|
376
380
|
if (rerankContext) {
|
|
377
381
|
try {
|
|
378
|
-
const reranked = await rerankContext({ query, chunks: ctx });
|
|
382
|
+
const reranked = await rerankContext({ query, chunks: [...ctx] });
|
|
379
383
|
if (Array.isArray(reranked) && reranked.every((c) => typeof c === "string")) ctx = reranked;
|
|
380
384
|
} catch (error) {
|
|
381
385
|
logger?.error("rerankContext threw; falling back to the original chunks", error);
|
|
382
386
|
}
|
|
383
387
|
}
|
|
388
|
+
let fallback;
|
|
389
|
+
if (ctx.length === 0 && fallbackFn) {
|
|
390
|
+
try {
|
|
391
|
+
const guidance = await fallbackFn({
|
|
392
|
+
query,
|
|
393
|
+
mode,
|
|
394
|
+
buckets: resolvedBuckets,
|
|
395
|
+
sender,
|
|
396
|
+
retrievedChunks
|
|
397
|
+
});
|
|
398
|
+
if (typeof guidance === "string" && guidance.trim()) fallback = guidance.trim();
|
|
399
|
+
} catch (error) {
|
|
400
|
+
logger?.error("fallbackFn threw; proceeding without fallback guidance", error);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
384
403
|
const persona = personaLayer?.trim() || (mode === "private" ? prompts.privatePersona : prompts.publicPersona);
|
|
385
404
|
const hint = channelHint?.trim();
|
|
386
405
|
const system = [
|
|
387
406
|
prompts.baseSystemRules,
|
|
388
407
|
persona,
|
|
389
408
|
...hint ? [hint] : [],
|
|
409
|
+
...fallback ? [fallback] : [],
|
|
390
410
|
`${label}:
|
|
391
411
|
${ctx.join("\n\n")}`
|
|
392
412
|
].join("\n\n");
|
|
@@ -394,7 +414,7 @@ ${ctx.join("\n\n")}`
|
|
|
394
414
|
}
|
|
395
415
|
|
|
396
416
|
// src/history/compaction.ts
|
|
397
|
-
var
|
|
417
|
+
var COMPACTION_TIMEOUT_MS = 8e3;
|
|
398
418
|
var LOAD_ALL = Number.MAX_SAFE_INTEGER;
|
|
399
419
|
var SUMMARY_PREFIX = "Summary of earlier conversation: ";
|
|
400
420
|
function defaultSummarize(client, model) {
|
|
@@ -422,7 +442,7 @@ function createHistoryCompactor(deps, options) {
|
|
|
422
442
|
throw new Error(`Invalid history compaction keep: ${keep}`);
|
|
423
443
|
}
|
|
424
444
|
const summarize = options.summarize ?? defaultSummarize(deps.client, options.model);
|
|
425
|
-
const timeoutMs = options.timeoutMs ??
|
|
445
|
+
const timeoutMs = options.timeoutMs ?? COMPACTION_TIMEOUT_MS;
|
|
426
446
|
return {
|
|
427
447
|
async maybeCompact(store, conversationId) {
|
|
428
448
|
const turns = await store.load(conversationId, LOAD_ALL);
|
|
@@ -513,6 +533,16 @@ function underReplyRateLimit(msg, limiters) {
|
|
|
513
533
|
}
|
|
514
534
|
|
|
515
535
|
// src/channels/pipeline.ts
|
|
536
|
+
function resolveBrainHooks(config, fallback) {
|
|
537
|
+
return {
|
|
538
|
+
answerFn: config.answerFn ?? fallback?.answerFn,
|
|
539
|
+
bucketsFor: config.bucketsFor ?? fallback?.bucketsFor,
|
|
540
|
+
rewriteQuery: config.rewriteQuery ?? fallback?.rewriteQuery,
|
|
541
|
+
rerankContext: config.rerankContext ?? fallback?.rerankContext,
|
|
542
|
+
fallbackFn: config.fallbackFn ?? fallback?.fallbackFn,
|
|
543
|
+
transformReply: config.transformReply ?? fallback?.transformReply
|
|
544
|
+
};
|
|
545
|
+
}
|
|
516
546
|
var DEFAULT_HISTORY_LIMIT = 20;
|
|
517
547
|
var DEFAULT_GROUP_RATE_LIMIT = { max: 30, windowMs: 60 * 60 * 1e3 };
|
|
518
548
|
var DEFAULT_DM_RATE_LIMIT = { max: 20, windowMs: 60 * 60 * 1e3 };
|
|
@@ -597,6 +627,7 @@ function createInboundPipeline(deps, config) {
|
|
|
597
627
|
sender,
|
|
598
628
|
rewriteQuery: config.rewriteQuery,
|
|
599
629
|
rerankContext: config.rerankContext,
|
|
630
|
+
fallbackFn: config.fallbackFn,
|
|
600
631
|
logger: config.logger
|
|
601
632
|
});
|
|
602
633
|
const { content: produced } = await answerOnce({
|
|
@@ -633,6 +664,14 @@ function createInboundPipeline(deps, config) {
|
|
|
633
664
|
};
|
|
634
665
|
}
|
|
635
666
|
|
|
667
|
+
// src/channels/polling.ts
|
|
668
|
+
function defaultSleep(ms) {
|
|
669
|
+
return new Promise((resolve) => {
|
|
670
|
+
const timer = setTimeout(resolve, ms);
|
|
671
|
+
if (typeof timer === "object" && "unref" in timer) timer.unref();
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
|
|
636
675
|
// src/channels/telegram/updates.ts
|
|
637
676
|
function messageText(message) {
|
|
638
677
|
return message.text ?? message.caption ?? "";
|
|
@@ -711,11 +750,16 @@ function createTelegramSender(api) {
|
|
|
711
750
|
};
|
|
712
751
|
}
|
|
713
752
|
|
|
753
|
+
// src/channels/backoff.ts
|
|
754
|
+
function exponentialBackoffMs(baseMs, maxMs, n) {
|
|
755
|
+
return Math.min(baseMs * 2 ** Math.max(0, Math.min(n, 20)), maxMs);
|
|
756
|
+
}
|
|
757
|
+
|
|
714
758
|
// src/channels/telegram/poll.ts
|
|
715
759
|
var BASE_DELAY_MS = 1e3;
|
|
716
760
|
var MAX_DELAY_MS = 6e4;
|
|
717
761
|
function pollBackoffMs(failures) {
|
|
718
|
-
return
|
|
762
|
+
return exponentialBackoffMs(BASE_DELAY_MS, MAX_DELAY_MS, failures);
|
|
719
763
|
}
|
|
720
764
|
function retryDelayMs(error, failures) {
|
|
721
765
|
const retryAfterMs = error instanceof TelegramApiError ? error.retryAfterMs : void 0;
|
|
@@ -740,9 +784,9 @@ async function runLongPoll(deps) {
|
|
|
740
784
|
}
|
|
741
785
|
failures = 0;
|
|
742
786
|
for (const update of updates) {
|
|
787
|
+
if (deps.isStopped()) break;
|
|
743
788
|
offset = nextOffset(update);
|
|
744
789
|
deps.onOffset?.(offset);
|
|
745
|
-
if (deps.isStopped()) break;
|
|
746
790
|
try {
|
|
747
791
|
await deps.handleUpdate(update);
|
|
748
792
|
} catch (error) {
|
|
@@ -755,12 +799,6 @@ async function runLongPoll(deps) {
|
|
|
755
799
|
|
|
756
800
|
// src/channels/telegram/channel.ts
|
|
757
801
|
var DEFAULT_POLL_TIMEOUT_SECONDS = 30;
|
|
758
|
-
function defaultSleep(ms) {
|
|
759
|
-
return new Promise((resolve) => {
|
|
760
|
-
const timer = setTimeout(resolve, ms);
|
|
761
|
-
if (typeof timer === "object" && "unref" in timer) timer.unref();
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
802
|
function createTelegramChannel(config) {
|
|
765
803
|
const channelName = config.name ?? "telegram";
|
|
766
804
|
const allowedChats = config.allowedChats ?? [];
|
|
@@ -788,11 +826,7 @@ function createTelegramChannel(config) {
|
|
|
788
826
|
{ client: deps.client, store: deps.store, prompts: deps.prompts },
|
|
789
827
|
{
|
|
790
828
|
channel: channelName,
|
|
791
|
-
|
|
792
|
-
bucketsFor: config.bucketsFor ?? deps.config.bucketsFor,
|
|
793
|
-
rewriteQuery: config.rewriteQuery ?? deps.config.rewriteQuery,
|
|
794
|
-
rerankContext: config.rerankContext ?? deps.config.rerankContext,
|
|
795
|
-
transformReply: config.transformReply ?? deps.config.transformReply,
|
|
829
|
+
...resolveBrainHooks(config, deps.config),
|
|
796
830
|
model: config.model,
|
|
797
831
|
channelHint: config.channelHint ?? "Channel: Telegram.",
|
|
798
832
|
personaResolver: config.personaResolver,
|
|
@@ -971,11 +1005,7 @@ function createTelegramWebhookRoute(config) {
|
|
|
971
1005
|
{ client: deps.client, store: deps.store, prompts: deps.prompts },
|
|
972
1006
|
{
|
|
973
1007
|
channel: channelName,
|
|
974
|
-
|
|
975
|
-
bucketsFor: config.bucketsFor ?? deps.config.bucketsFor,
|
|
976
|
-
rewriteQuery: config.rewriteQuery ?? deps.config.rewriteQuery,
|
|
977
|
-
rerankContext: config.rerankContext ?? deps.config.rerankContext,
|
|
978
|
-
transformReply: config.transformReply ?? deps.config.transformReply,
|
|
1008
|
+
...resolveBrainHooks(config, deps.config),
|
|
979
1009
|
model: config.model,
|
|
980
1010
|
channelHint: config.channelHint ?? "Channel: Telegram.",
|
|
981
1011
|
personaResolver: config.personaResolver,
|
|
@@ -249,7 +249,8 @@ async function answerOnce({
|
|
|
249
249
|
async function applyTransformReply(transformReply, input, logger) {
|
|
250
250
|
if (!transformReply) return input.text;
|
|
251
251
|
try {
|
|
252
|
-
|
|
252
|
+
const result = await transformReply(input);
|
|
253
|
+
return typeof result === "string" ? result : null;
|
|
253
254
|
} catch (error) {
|
|
254
255
|
logger?.error(
|
|
255
256
|
`transformReply threw for channel "${input.channel}"; sending the original reply`,
|
|
@@ -311,6 +312,7 @@ async function prepareChat({
|
|
|
311
312
|
sender,
|
|
312
313
|
rewriteQuery,
|
|
313
314
|
rerankContext,
|
|
315
|
+
fallbackFn,
|
|
314
316
|
logger
|
|
315
317
|
}) {
|
|
316
318
|
const lastUserMsg = lastUserMessage(messages);
|
|
@@ -327,21 +329,39 @@ async function prepareChat({
|
|
|
327
329
|
logger?.error("rewriteQuery threw; falling back to the original query", error);
|
|
328
330
|
}
|
|
329
331
|
}
|
|
330
|
-
|
|
332
|
+
const resolvedBuckets = buckets ?? defaultBuckets(mode);
|
|
333
|
+
const retrievedChunks = await store.query(query, topK, resolvedBuckets);
|
|
334
|
+
let ctx = retrievedChunks;
|
|
331
335
|
if (rerankContext) {
|
|
332
336
|
try {
|
|
333
|
-
const reranked = await rerankContext({ query, chunks: ctx });
|
|
337
|
+
const reranked = await rerankContext({ query, chunks: [...ctx] });
|
|
334
338
|
if (Array.isArray(reranked) && reranked.every((c) => typeof c === "string")) ctx = reranked;
|
|
335
339
|
} catch (error) {
|
|
336
340
|
logger?.error("rerankContext threw; falling back to the original chunks", error);
|
|
337
341
|
}
|
|
338
342
|
}
|
|
343
|
+
let fallback;
|
|
344
|
+
if (ctx.length === 0 && fallbackFn) {
|
|
345
|
+
try {
|
|
346
|
+
const guidance = await fallbackFn({
|
|
347
|
+
query,
|
|
348
|
+
mode,
|
|
349
|
+
buckets: resolvedBuckets,
|
|
350
|
+
sender,
|
|
351
|
+
retrievedChunks
|
|
352
|
+
});
|
|
353
|
+
if (typeof guidance === "string" && guidance.trim()) fallback = guidance.trim();
|
|
354
|
+
} catch (error) {
|
|
355
|
+
logger?.error("fallbackFn threw; proceeding without fallback guidance", error);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
339
358
|
const persona = personaLayer?.trim() || (mode === "private" ? prompts.privatePersona : prompts.publicPersona);
|
|
340
359
|
const hint = channelHint?.trim();
|
|
341
360
|
const system = [
|
|
342
361
|
prompts.baseSystemRules,
|
|
343
362
|
persona,
|
|
344
363
|
...hint ? [hint] : [],
|
|
364
|
+
...fallback ? [fallback] : [],
|
|
345
365
|
`${label}:
|
|
346
366
|
${ctx.join("\n\n")}`
|
|
347
367
|
].join("\n\n");
|
|
@@ -349,7 +369,7 @@ ${ctx.join("\n\n")}`
|
|
|
349
369
|
}
|
|
350
370
|
|
|
351
371
|
// src/history/compaction.ts
|
|
352
|
-
var
|
|
372
|
+
var COMPACTION_TIMEOUT_MS = 8e3;
|
|
353
373
|
var LOAD_ALL = Number.MAX_SAFE_INTEGER;
|
|
354
374
|
var SUMMARY_PREFIX = "Summary of earlier conversation: ";
|
|
355
375
|
function defaultSummarize(client, model) {
|
|
@@ -377,7 +397,7 @@ function createHistoryCompactor(deps, options) {
|
|
|
377
397
|
throw new Error(`Invalid history compaction keep: ${keep}`);
|
|
378
398
|
}
|
|
379
399
|
const summarize = options.summarize ?? defaultSummarize(deps.client, options.model);
|
|
380
|
-
const timeoutMs = options.timeoutMs ??
|
|
400
|
+
const timeoutMs = options.timeoutMs ?? COMPACTION_TIMEOUT_MS;
|
|
381
401
|
return {
|
|
382
402
|
async maybeCompact(store, conversationId) {
|
|
383
403
|
const turns = await store.load(conversationId, LOAD_ALL);
|
|
@@ -468,6 +488,16 @@ function underReplyRateLimit(msg, limiters) {
|
|
|
468
488
|
}
|
|
469
489
|
|
|
470
490
|
// src/channels/pipeline.ts
|
|
491
|
+
function resolveBrainHooks(config, fallback) {
|
|
492
|
+
return {
|
|
493
|
+
answerFn: config.answerFn ?? fallback?.answerFn,
|
|
494
|
+
bucketsFor: config.bucketsFor ?? fallback?.bucketsFor,
|
|
495
|
+
rewriteQuery: config.rewriteQuery ?? fallback?.rewriteQuery,
|
|
496
|
+
rerankContext: config.rerankContext ?? fallback?.rerankContext,
|
|
497
|
+
fallbackFn: config.fallbackFn ?? fallback?.fallbackFn,
|
|
498
|
+
transformReply: config.transformReply ?? fallback?.transformReply
|
|
499
|
+
};
|
|
500
|
+
}
|
|
471
501
|
var DEFAULT_HISTORY_LIMIT = 20;
|
|
472
502
|
var DEFAULT_GROUP_RATE_LIMIT = { max: 30, windowMs: 60 * 60 * 1e3 };
|
|
473
503
|
var DEFAULT_DM_RATE_LIMIT = { max: 20, windowMs: 60 * 60 * 1e3 };
|
|
@@ -552,6 +582,7 @@ function createInboundPipeline(deps, config) {
|
|
|
552
582
|
sender,
|
|
553
583
|
rewriteQuery: config.rewriteQuery,
|
|
554
584
|
rerankContext: config.rerankContext,
|
|
585
|
+
fallbackFn: config.fallbackFn,
|
|
555
586
|
logger: config.logger
|
|
556
587
|
});
|
|
557
588
|
const { content: produced } = await answerOnce({
|
|
@@ -588,6 +619,14 @@ function createInboundPipeline(deps, config) {
|
|
|
588
619
|
};
|
|
589
620
|
}
|
|
590
621
|
|
|
622
|
+
// src/channels/polling.ts
|
|
623
|
+
function defaultSleep(ms) {
|
|
624
|
+
return new Promise((resolve) => {
|
|
625
|
+
const timer = setTimeout(resolve, ms);
|
|
626
|
+
if (typeof timer === "object" && "unref" in timer) timer.unref();
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
|
|
591
630
|
// src/channels/telegram/updates.ts
|
|
592
631
|
function messageText(message) {
|
|
593
632
|
return message.text ?? message.caption ?? "";
|
|
@@ -666,11 +705,16 @@ function createTelegramSender(api) {
|
|
|
666
705
|
};
|
|
667
706
|
}
|
|
668
707
|
|
|
708
|
+
// src/channels/backoff.ts
|
|
709
|
+
function exponentialBackoffMs(baseMs, maxMs, n) {
|
|
710
|
+
return Math.min(baseMs * 2 ** Math.max(0, Math.min(n, 20)), maxMs);
|
|
711
|
+
}
|
|
712
|
+
|
|
669
713
|
// src/channels/telegram/poll.ts
|
|
670
714
|
var BASE_DELAY_MS = 1e3;
|
|
671
715
|
var MAX_DELAY_MS = 6e4;
|
|
672
716
|
function pollBackoffMs(failures) {
|
|
673
|
-
return
|
|
717
|
+
return exponentialBackoffMs(BASE_DELAY_MS, MAX_DELAY_MS, failures);
|
|
674
718
|
}
|
|
675
719
|
function retryDelayMs(error, failures) {
|
|
676
720
|
const retryAfterMs = error instanceof TelegramApiError ? error.retryAfterMs : void 0;
|
|
@@ -695,9 +739,9 @@ async function runLongPoll(deps) {
|
|
|
695
739
|
}
|
|
696
740
|
failures = 0;
|
|
697
741
|
for (const update of updates) {
|
|
742
|
+
if (deps.isStopped()) break;
|
|
698
743
|
offset = nextOffset(update);
|
|
699
744
|
deps.onOffset?.(offset);
|
|
700
|
-
if (deps.isStopped()) break;
|
|
701
745
|
try {
|
|
702
746
|
await deps.handleUpdate(update);
|
|
703
747
|
} catch (error) {
|
|
@@ -710,12 +754,6 @@ async function runLongPoll(deps) {
|
|
|
710
754
|
|
|
711
755
|
// src/channels/telegram/channel.ts
|
|
712
756
|
var DEFAULT_POLL_TIMEOUT_SECONDS = 30;
|
|
713
|
-
function defaultSleep(ms) {
|
|
714
|
-
return new Promise((resolve) => {
|
|
715
|
-
const timer = setTimeout(resolve, ms);
|
|
716
|
-
if (typeof timer === "object" && "unref" in timer) timer.unref();
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
757
|
function createTelegramChannel(config) {
|
|
720
758
|
const channelName = config.name ?? "telegram";
|
|
721
759
|
const allowedChats = config.allowedChats ?? [];
|
|
@@ -743,11 +781,7 @@ function createTelegramChannel(config) {
|
|
|
743
781
|
{ client: deps.client, store: deps.store, prompts: deps.prompts },
|
|
744
782
|
{
|
|
745
783
|
channel: channelName,
|
|
746
|
-
|
|
747
|
-
bucketsFor: config.bucketsFor ?? deps.config.bucketsFor,
|
|
748
|
-
rewriteQuery: config.rewriteQuery ?? deps.config.rewriteQuery,
|
|
749
|
-
rerankContext: config.rerankContext ?? deps.config.rerankContext,
|
|
750
|
-
transformReply: config.transformReply ?? deps.config.transformReply,
|
|
784
|
+
...resolveBrainHooks(config, deps.config),
|
|
751
785
|
model: config.model,
|
|
752
786
|
channelHint: config.channelHint ?? "Channel: Telegram.",
|
|
753
787
|
personaResolver: config.personaResolver,
|
|
@@ -926,11 +960,7 @@ function createTelegramWebhookRoute(config) {
|
|
|
926
960
|
{ client: deps.client, store: deps.store, prompts: deps.prompts },
|
|
927
961
|
{
|
|
928
962
|
channel: channelName,
|
|
929
|
-
|
|
930
|
-
bucketsFor: config.bucketsFor ?? deps.config.bucketsFor,
|
|
931
|
-
rewriteQuery: config.rewriteQuery ?? deps.config.rewriteQuery,
|
|
932
|
-
rerankContext: config.rerankContext ?? deps.config.rerankContext,
|
|
933
|
-
transformReply: config.transformReply ?? deps.config.transformReply,
|
|
963
|
+
...resolveBrainHooks(config, deps.config),
|
|
934
964
|
model: config.model,
|
|
935
965
|
channelHint: config.channelHint ?? "Channel: Telegram.",
|
|
936
966
|
personaResolver: config.personaResolver,
|
|
@@ -41,7 +41,11 @@ export interface LongPollDeps {
|
|
|
41
41
|
*
|
|
42
42
|
* The offset advances BEFORE the update is handled: a handler that throws on
|
|
43
43
|
* one specific update must not make Telegram redeliver it forever, which would
|
|
44
|
-
* wedge the loop on a single poison message and starve every later one.
|
|
44
|
+
* wedge the loop on a single poison message and starve every later one. It
|
|
45
|
+
* advances only for an update this loop is actually going to handle, though:
|
|
46
|
+
* a stop that lands mid-batch leaves the offset where it was, so a restart
|
|
47
|
+
* resumes at the unhandled update rather than past it (matching
|
|
48
|
+
* `../matrix/sync.ts`'s `since`-token ordering).
|
|
45
49
|
*/
|
|
46
50
|
export declare function runLongPoll(deps: LongPollDeps): Promise<number | undefined>;
|
|
47
51
|
//# sourceMappingURL=poll.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poll.d.ts","sourceRoot":"","sources":["../../../src/channels/telegram/poll.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAuB,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"poll.d.ts","sourceRoot":"","sources":["../../../src/channels/telegram/poll.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAuB,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAM9D,mHAAmH;AACnH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGrE;AAED,MAAM,WAAW,YAAY;IAC3B,iFAAiF;IACjF,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAClE,4FAA4F;IAC5F,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,+HAA+H;IAC/H,SAAS,IAAI,OAAO,CAAC;IACrB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,qFAAqF;IACrF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuCjF"}
|
|
@@ -19,15 +19,12 @@
|
|
|
19
19
|
* });
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
import type { AnswerFn, TransformReply } from "../../core/answer";
|
|
23
|
-
import type { BucketsFor } from "../../core/buckets";
|
|
24
22
|
import { type Logger } from "../../core/logger";
|
|
25
|
-
import type { RerankContext, RewriteQuery } from "../../core/pipeline";
|
|
26
23
|
import type { HistoryCompactionOptions } from "../../history/compaction";
|
|
27
24
|
import type { HistoryStore } from "../../history/types";
|
|
28
|
-
import type { CustomRoutes } from "../../types";
|
|
25
|
+
import type { BrainHooks, CustomRoutes } from "../../types";
|
|
29
26
|
import { type TelegramApi } from "./api";
|
|
30
|
-
export interface TelegramWebhookConfig {
|
|
27
|
+
export interface TelegramWebhookConfig extends BrainHooks {
|
|
31
28
|
/** From @BotFather. A credential — pass it from the environment, never commit it. */
|
|
32
29
|
botToken: string;
|
|
33
30
|
/**
|
|
@@ -44,11 +41,6 @@ export interface TelegramWebhookConfig {
|
|
|
44
41
|
name?: string;
|
|
45
42
|
/** Group chats eligible for a reply. Empty (default) = every group. Has no effect on DMs, which always reply. */
|
|
46
43
|
allowedChats?: string[];
|
|
47
|
-
answerFn?: AnswerFn;
|
|
48
|
-
bucketsFor?: BucketsFor;
|
|
49
|
-
rewriteQuery?: RewriteQuery;
|
|
50
|
-
rerankContext?: RerankContext;
|
|
51
|
-
transformReply?: TransformReply;
|
|
52
44
|
model?: string;
|
|
53
45
|
/** Extra system-prompt section describing the delivery channel; passed through to `prepareChat`. @default "Channel: Telegram." */
|
|
54
46
|
channelHint?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../src/channels/telegram/webhook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../src/channels/telegram/webhook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAuB,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAqB,KAAK,WAAW,EAAuB,MAAM,OAAO,CAAC;AAMjF,MAAM,WAAW,qBAAsB,SAAQ,UAAU;IACvD,qFAAqF;IACrF,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8GAA8G;IAC9G,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iHAAiH;IACjH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kIAAkI;IAClI,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4GAA4G;IAC5G,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACvD,kFAAkF;IAClF,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,YAAY,CAAC;QACpB,uDAAuD;QACvD,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QACnE;;;;WAIG;QACH,UAAU,CAAC,EAAE,wBAAwB,CAAC;KACvC,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,cAAc,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,mGAAmG;IACnG,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qJAAqJ;IACrJ,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAeD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,qBAAqB,GAAG,YAAY,CA8GtF"}
|