@ganju/utils 0.0.10 → 0.0.11
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/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +63 -0
- package/dist/index.d.ts +140 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/schema.d.ts +67 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +30 -4
- package/dist/syncableResource.d.ts +5 -0
- package/dist/syncableResource.d.ts.map +1 -1
- package/dist/syncableResource.js +13 -1
- package/dist/toolCatalog.d.ts +69 -0
- package/dist/toolCatalog.d.ts.map +1 -1
- package/dist/toolCatalog.js +150 -62
- package/dist/toolConfirmation.d.ts +47 -0
- package/dist/toolConfirmation.d.ts.map +1 -0
- package/dist/toolConfirmation.js +217 -0
- package/package.json +1 -1
- package/src/constants.ts +68 -0
- package/src/index.ts +34 -1
- package/src/schema.ts +41 -6
- package/src/syncableResource.ts +20 -0
- package/src/toolCatalog.ts +169 -62
- package/src/toolConfirmation.ts +261 -0
package/dist/constants.d.ts
CHANGED
|
@@ -324,6 +324,7 @@ export declare const constants: {
|
|
|
324
324
|
};
|
|
325
325
|
RESOURCE_SYNC_BATCH_SIZE: number;
|
|
326
326
|
RESOURCE_SYNC_MANUAL_COOLDOWN_MS: number;
|
|
327
|
+
RESOURCE_SYNC_STALE_MS: number;
|
|
327
328
|
CRAWL_RENDERER_CHEERIO: "cheerio";
|
|
328
329
|
CRAWL_RENDERER_PLAYWRIGHT: "playwright";
|
|
329
330
|
CRAWL_RENDERERS: ("cheerio" | "playwright")[];
|
|
@@ -386,6 +387,11 @@ export declare const constants: {
|
|
|
386
387
|
SHARED_KEY_HISTORY_LIMIT: number;
|
|
387
388
|
SHARED_KEY_MAX_TOOL_LOOPS: number;
|
|
388
389
|
CHANNEL_MAX_TOOLS: number;
|
|
390
|
+
TOOL_CONFIRMATION_TTL_MS: number;
|
|
391
|
+
TOOL_CONFIRMATION_REQUIRED_RESULT: string;
|
|
392
|
+
TOOL_CONFIRMATION_FALLBACK_QUESTION: string;
|
|
393
|
+
TOOL_CONFIRMATION_ASK_INSTRUCTION: string;
|
|
394
|
+
TOOL_CONFIRMATION_SYSTEM_NOTE: string;
|
|
389
395
|
CHANNEL_DEBOUNCE_DEFAULT_MS: number;
|
|
390
396
|
CHANNEL_DEBOUNCE_MIN_MS: number;
|
|
391
397
|
CHANNEL_DEBOUNCE_MAX_MS: number;
|
|
@@ -418,8 +424,10 @@ export declare const constants: {
|
|
|
418
424
|
DISCORD_TIMESTAMP_HEADER: string;
|
|
419
425
|
DISCORD_INTERACTION_TYPE_PING: number;
|
|
420
426
|
DISCORD_INTERACTION_TYPE_APPLICATION_COMMAND: number;
|
|
427
|
+
DISCORD_INTERACTION_TYPE_MESSAGE_COMPONENT: number;
|
|
421
428
|
DISCORD_INTERACTION_RESPONSE_PONG: number;
|
|
422
429
|
DISCORD_INTERACTION_RESPONSE_DEFERRED: number;
|
|
430
|
+
DISCORD_INTERACTION_RESPONSE_UPDATE_MESSAGE: number;
|
|
423
431
|
DISCORD_CHANNEL_TYPE_DM: number;
|
|
424
432
|
DISCORD_CHANNEL_TYPE_GROUP_DM: number;
|
|
425
433
|
DISCORD_GATEWAY_OP_DISPATCH: number;
|
|
@@ -434,6 +442,7 @@ export declare const constants: {
|
|
|
434
442
|
WHATSAPP_API_BASE: string;
|
|
435
443
|
WHATSAPP_API_VERSION: string;
|
|
436
444
|
WHATSAPP_MESSAGE_LIMIT: number;
|
|
445
|
+
WHATSAPP_INTERACTIVE_BODY_LIMIT: number;
|
|
437
446
|
WHATSAPP_SIGNATURE_HEADER: string;
|
|
438
447
|
WHATSAPP_SIGNATURE_PREFIX: string;
|
|
439
448
|
WHATSAPP_HUB_MODE_PARAM: string;
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sour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;;;eAoTwB,MAAM,GAAG,MAAM;cAAQ,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAm9DnE,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -234,6 +234,16 @@ const RESOURCE_SYNC_BATCH_SIZE = 50;
|
|
|
234
234
|
// plan, and a website sync re-crawls every page, so it can't be a button to
|
|
235
235
|
// press in a loop.
|
|
236
236
|
const RESOURCE_SYNC_MANUAL_COOLDOWN_MS = 5 * 60 * 1000;
|
|
237
|
+
// How long a sync may stay PENDING before it counts as stuck rather than
|
|
238
|
+
// running. A lost queue message or a job that exhausted its retries never
|
|
239
|
+
// completes its root, and a root that stays PENDING would otherwise be skipped
|
|
240
|
+
// by the hourly job and refused by "Sync now" forever. Twelve hours outlasts
|
|
241
|
+
// any realistic wait: the crawl-page queue runs 5 at a time for every org, and
|
|
242
|
+
// one hourly run can queue 50 sites — thousands of pages, hours of backlog. A
|
|
243
|
+
// shorter window restarts syncs that are merely queued, re-fetching every page
|
|
244
|
+
// into the same backlog; a longer one leaves a stuck daily source missing more
|
|
245
|
+
// than one sync.
|
|
246
|
+
const RESOURCE_SYNC_STALE_MS = 12 * 60 * 60 * 1000;
|
|
237
247
|
const CRAWL_RENDERER_CHEERIO = 'cheerio';
|
|
238
248
|
const CRAWL_RENDERER_PLAYWRIGHT = 'playwright';
|
|
239
249
|
const CRAWL_RENDERERS = [CRAWL_RENDERER_CHEERIO, CRAWL_RENDERER_PLAYWRIGHT];
|
|
@@ -620,6 +630,44 @@ const CHANNEL_DEBOUNCE_JOIN = '\n';
|
|
|
620
630
|
// and how many times it tries before dropping the batch rather than looping.
|
|
621
631
|
const CHANNEL_DEBOUNCE_RETRY_MS = 5000;
|
|
622
632
|
const CHANNEL_DEBOUNCE_MAX_ATTEMPTS = 3;
|
|
633
|
+
// Confirming sensitive actions, for organizations that turn it on. A channel
|
|
634
|
+
// bot that wants to run a tool annotated `destructiveHint` asks first, and the
|
|
635
|
+
// call runs only if the participant's next message is a plain yes.
|
|
636
|
+
//
|
|
637
|
+
// How long the question stays open. An answer after that is read as a new
|
|
638
|
+
// message, never as consent to something asked long ago.
|
|
639
|
+
const TOOL_CONFIRMATION_TTL_MS = 30 * 60 * 1000;
|
|
640
|
+
// The tool result the model gets instead of running the call. It is what makes
|
|
641
|
+
// the model write the question — in the participant's language, naming what
|
|
642
|
+
// the call would do — rather than claiming the action happened.
|
|
643
|
+
// The call's exact arguments are listed under the model's question by the
|
|
644
|
+
// runner, so the model only has to say what it is about to do.
|
|
645
|
+
const TOOL_CONFIRMATION_REQUIRED_RESULT = 'Not run yet: this action needs the user to confirm it first. In one or ' +
|
|
646
|
+
'two sentences, tell them what it will do (who it goes to, what will be ' +
|
|
647
|
+
'changed or deleted) and ask them to answer yes to go ahead or no to ' +
|
|
648
|
+
'cancel — in their own language, never quoting English words at someone ' +
|
|
649
|
+
'writing in another one. The exact details are listed for them under your ' +
|
|
650
|
+
'message. It runs only if their next message is yes. Do not say it was done.';
|
|
651
|
+
// Told to the model on every turn of an organization that confirms: the
|
|
652
|
+
// asking is done for it, so it calls the tool when asked instead of asking
|
|
653
|
+
// first itself — and calls every action a request needs in one step, since
|
|
654
|
+
// the turn stops at the first held call and each later one would be a
|
|
655
|
+
// question of its own.
|
|
656
|
+
const TOOL_CONFIRMATION_SYSTEM_NOTE = 'Actions that send, change or delete something are confirmed with the ' +
|
|
657
|
+
'user by the system before they run. Ask for any detail you are missing, ' +
|
|
658
|
+
'but once you have what the action needs, call the tool — do not ask the ' +
|
|
659
|
+
'user to confirm it yourself; the system asks them and runs it on their ' +
|
|
660
|
+
'yes. When a request needs several such actions (say, delete an event ' +
|
|
661
|
+
'and create its replacement), call them all in the same step, so the ' +
|
|
662
|
+
'user confirms them together once.';
|
|
663
|
+
// The system-prompt addition for the step that writes the question, with the
|
|
664
|
+
// held actions' names in place of {{actions}}.
|
|
665
|
+
const TOOL_CONFIRMATION_ASK_INSTRUCTION = 'IMPORTANT: these actions have NOT been done: {{actions}}. They are ' +
|
|
666
|
+
'waiting for the user to confirm them. Your reply must ask the user to ' +
|
|
667
|
+
'confirm, and must not say or suggest that they were done, nor describe ' +
|
|
668
|
+
'or make up any result from them.';
|
|
669
|
+
// The question when the model wrote none, above the runner's own summary.
|
|
670
|
+
const TOOL_CONFIRMATION_FALLBACK_QUESTION = 'Before I do this, please confirm. Reply yes to go ahead, or no to cancel.';
|
|
623
671
|
const TELEGRAM_SECRET_HEADER = 'x-telegram-bot-api-secret-token';
|
|
624
672
|
const TELEGRAM_API_BASE = 'https://api.telegram.org';
|
|
625
673
|
const TELEGRAM_MESSAGE_LIMIT = 3500;
|
|
@@ -676,8 +724,12 @@ const DISCORD_TIMESTAMP_HEADER = 'x-signature-timestamp';
|
|
|
676
724
|
// Interaction request types and response types (Discord API).
|
|
677
725
|
const DISCORD_INTERACTION_TYPE_PING = 1;
|
|
678
726
|
const DISCORD_INTERACTION_TYPE_APPLICATION_COMMAND = 2;
|
|
727
|
+
// A tap on a message button — the Yes/No under a confirmation question.
|
|
728
|
+
const DISCORD_INTERACTION_TYPE_MESSAGE_COMPONENT = 3;
|
|
679
729
|
const DISCORD_INTERACTION_RESPONSE_PONG = 1;
|
|
680
730
|
const DISCORD_INTERACTION_RESPONSE_DEFERRED = 5;
|
|
731
|
+
// Edits the message the tapped button is on, in the same response.
|
|
732
|
+
const DISCORD_INTERACTION_RESPONSE_UPDATE_MESSAGE = 7;
|
|
681
733
|
// Channel types we map to conversation scopes: DM (1) / group DM (3) = private;
|
|
682
734
|
// everything else (guild text channels, threads) = channel.
|
|
683
735
|
const DISCORD_CHANNEL_TYPE_DM = 1;
|
|
@@ -705,6 +757,8 @@ const WHATSAPP_API_BASE = 'https://graph.facebook.com';
|
|
|
705
757
|
const WHATSAPP_API_VERSION = 'v25.0';
|
|
706
758
|
// A WhatsApp text message body caps at 4096 chars; we chunk a bit under that.
|
|
707
759
|
const WHATSAPP_MESSAGE_LIMIT = 4000;
|
|
760
|
+
// The body of an interactive (reply-button) message holds at most this much.
|
|
761
|
+
const WHATSAPP_INTERACTIVE_BODY_LIMIT = 1024;
|
|
708
762
|
const WHATSAPP_SIGNATURE_HEADER = 'x-hub-signature-256';
|
|
709
763
|
const WHATSAPP_SIGNATURE_PREFIX = 'sha256=';
|
|
710
764
|
// GET-handshake query params + the expected hub.mode value.
|
|
@@ -2179,6 +2233,7 @@ exports.constants = {
|
|
|
2179
2233
|
RESOURCE_SYNC_INTERVAL_MS,
|
|
2180
2234
|
RESOURCE_SYNC_BATCH_SIZE,
|
|
2181
2235
|
RESOURCE_SYNC_MANUAL_COOLDOWN_MS,
|
|
2236
|
+
RESOURCE_SYNC_STALE_MS,
|
|
2182
2237
|
CRAWL_RENDERER_CHEERIO,
|
|
2183
2238
|
CRAWL_RENDERER_PLAYWRIGHT,
|
|
2184
2239
|
CRAWL_RENDERERS,
|
|
@@ -2237,6 +2292,11 @@ exports.constants = {
|
|
|
2237
2292
|
SHARED_KEY_HISTORY_LIMIT,
|
|
2238
2293
|
SHARED_KEY_MAX_TOOL_LOOPS,
|
|
2239
2294
|
CHANNEL_MAX_TOOLS,
|
|
2295
|
+
TOOL_CONFIRMATION_TTL_MS,
|
|
2296
|
+
TOOL_CONFIRMATION_REQUIRED_RESULT,
|
|
2297
|
+
TOOL_CONFIRMATION_FALLBACK_QUESTION,
|
|
2298
|
+
TOOL_CONFIRMATION_ASK_INSTRUCTION,
|
|
2299
|
+
TOOL_CONFIRMATION_SYSTEM_NOTE,
|
|
2240
2300
|
CHANNEL_DEBOUNCE_DEFAULT_MS,
|
|
2241
2301
|
CHANNEL_DEBOUNCE_MIN_MS,
|
|
2242
2302
|
CHANNEL_DEBOUNCE_MAX_MS,
|
|
@@ -2269,8 +2329,10 @@ exports.constants = {
|
|
|
2269
2329
|
DISCORD_TIMESTAMP_HEADER,
|
|
2270
2330
|
DISCORD_INTERACTION_TYPE_PING,
|
|
2271
2331
|
DISCORD_INTERACTION_TYPE_APPLICATION_COMMAND,
|
|
2332
|
+
DISCORD_INTERACTION_TYPE_MESSAGE_COMPONENT,
|
|
2272
2333
|
DISCORD_INTERACTION_RESPONSE_PONG,
|
|
2273
2334
|
DISCORD_INTERACTION_RESPONSE_DEFERRED,
|
|
2335
|
+
DISCORD_INTERACTION_RESPONSE_UPDATE_MESSAGE,
|
|
2274
2336
|
DISCORD_CHANNEL_TYPE_DM,
|
|
2275
2337
|
DISCORD_CHANNEL_TYPE_GROUP_DM,
|
|
2276
2338
|
DISCORD_GATEWAY_OP_DISPATCH,
|
|
@@ -2285,6 +2347,7 @@ exports.constants = {
|
|
|
2285
2347
|
WHATSAPP_API_BASE,
|
|
2286
2348
|
WHATSAPP_API_VERSION,
|
|
2287
2349
|
WHATSAPP_MESSAGE_LIMIT,
|
|
2350
|
+
WHATSAPP_INTERACTIVE_BODY_LIMIT,
|
|
2288
2351
|
WHATSAPP_SIGNATURE_HEADER,
|
|
2289
2352
|
WHATSAPP_SIGNATURE_PREFIX,
|
|
2290
2353
|
WHATSAPP_HUB_MODE_PARAM,
|