-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
84 lines (74 loc) · 3.64 KB
/
utils.js
File metadata and controls
84 lines (74 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* SillyAgents — shared utilities.
* Pure helpers only. No side-effects, no event listeners, no DOM.
* Every other module imports from here; nothing imports from them.
*/
export const MODULE_NAME = 'sillyagents';
// ─── chatMetadata helpers ────────────────────────────────────────────────────
// Always re-read chatMetadata from context (the reference changes on chat switch).
/**
* Returns the sillyagents config block from the current chat, or null if this
* chat is not a subroutine.
* @returns {SubroutineConfig|null}
*/
export function getSubroutineConfig() {
const meta = SillyTavern.getContext().chatMetadata;
return meta?.sillyagents ?? null;
}
/**
* Writes a full config object into the current chat's metadata and persists it.
* @param {SubroutineConfig} config
*/
export async function setSubroutineConfig(config) {
SillyTavern.getContext().chatMetadata['sillyagents'] = config;
await SillyTavern.getContext().saveMetadata();
}
/**
* Convenience: is the *current* chat a subroutine?
* @returns {boolean}
*/
export function isCurrentChatSubroutine() {
return getSubroutineConfig() !== null;
}
// ─── default config factory ──────────────────────────────────────────────────
/**
* @typedef {Object} SubroutineConfig
* @property {boolean} isSubroutine
* @property {'time'|'tool'|'api'} triggerType
* @property {number} intervalSeconds - polling interval (all trigger types)
* @property {string} toolName - tool to poll (tool-based triggers)
* @property {string} toolCondition - value that must be returned to fire
* @property {string} apiUrl - external URL to poll (api-based triggers)
* @property {boolean} autoQueue - auto-queue mode on/off
* @property {string} autoQueuePrompt - prompt sent when model goes silent
* @property {string} heartbeatMessage - message sent on each tick
* @property {boolean} useSummary - use native summariser for compression
* @property {string} color - hex color for chat list indicator
* @property {boolean} useLorebooks - include lorebooks in context
* @property {boolean} useExampleMessages- include example messages in context
* @property {boolean} running - is the loop currently active
*/
/** @returns {SubroutineConfig} */
export function defaultSubroutineConfig() {
return {
isSubroutine: true,
triggerType: 'time',
intervalSeconds: 300, // 5 min
toolName: '',
toolCondition: '',
apiUrl: '',
autoQueue: false,
autoQueuePrompt: 'Continue working on the current task. Call a tool or report your status.',
heartbeatMessage: '[heartbeat]',
useSummary: false,
color: '#4a90d9',
useLorebooks: true,
useExampleMessages: true,
running: false,
};
}
// ─── logging ─────────────────────────────────────────────────────────────────
export function log(...args) { console.log (`[${MODULE_NAME}]`, ...args); }
export function logDebug(...args) { console.debug(`[${MODULE_NAME}]`, ...args); }
export function logError(...args) { console.error(`[${MODULE_NAME}]`, ...args); }
export function logWarn(...args) { console.warn (`[${MODULE_NAME}]`, ...args); }