aegiscode 7.0.26 → 7.0.28
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/SOURCE-OFFER.txt +9 -0
- package/package.json +4 -7
- package/scripts/check.mjs +1 -52
- package/scripts/demo.mjs +1 -94
- package/scripts/predist.mjs +1 -75
- package/scripts/runtests.mjs +1 -56
- package/scripts/seal-gate.mjs +1 -74
- package/src/agents.js +1 -139
- package/src/app.js +1 -2957
- package/src/art.js +1 -289
- package/src/chatflow.js +1 -3023
- package/src/checkpoint.js +1 -90
- package/src/clipboard.js +1 -424
- package/src/cloudsync.js +1 -528
- package/src/commands.js +1 -4089
- package/src/config.js +1 -581
- package/src/connect.js +1 -349
- package/src/credentials.js +1 -33
- package/src/deps.js +1 -232
- package/src/devrun.js +1 -187
- package/src/diff.js +1 -333
- package/src/diffview.js +1 -296
- package/src/engine.js +1 -297
- package/src/entitlement.js +1 -355
- package/src/events.js +1 -707
- package/src/export.js +1 -67
- package/src/filepreview.js +1 -153
- package/src/fingerprint.js +1 -592
- package/src/format.js +1 -259
- package/src/fuzzy.js +1 -119
- package/src/history.js +1 -423
- package/src/init.js +1 -175
- package/src/input.js +1 -139
- package/src/keys.js +1 -183
- package/src/markdown.js +1 -306
- package/src/models.js +1 -507
- package/src/naming.js +1 -57
- package/src/overlays.js +1 -462
- package/src/panels.js +1 -1418
- package/src/ping.js +1 -226
- package/src/presence.js +1 -238
- package/src/render.js +1 -516
- package/src/screen.js +1 -518
- package/src/screens.js +1 -896
- package/src/secret.js +1 -59
- package/src/securefs.js +1 -359
- package/src/settings.js +1 -155
- package/src/shared.js +1 -52
- package/src/sharedpaths.js +1 -53
- package/src/signup.js +1 -156
- package/src/summarize.js +1 -95
- package/src/sysdiag.js +1 -585
- package/src/system.js +1 -40
- package/src/theme.js +1 -570
- package/src/title.js +1 -220
- package/src/todos.js +1 -115
- package/src/tokens.js +1 -263
- package/src/topup.js +1 -210
- package/src/update.js +1 -191
- package/vendor/client/aegis.js +1 -2441
- package/vendor/client/attest.js +1 -518
- package/vendor/client/authorship-key.js +1 -410
- package/vendor/client/auto-provision.js +1 -134
- package/vendor/client/brain-catalog.js +1 -268
- package/vendor/client/byok-catalog.js +1 -199
- package/vendor/client/catalog-client.js +1 -487
- package/vendor/client/conversation-export.js +1 -177
- package/vendor/client/credentials.js +1 -494
- package/vendor/client/device-fingerprint.js +1 -141
- package/vendor/client/drive-connect.js +1 -110
- package/vendor/client/drive-upload.js +1 -234
- package/vendor/client/env-file.js +1 -1273
- package/vendor/client/fingerprint.js +1 -1064
- package/vendor/client/foreign-memory.js +1 -669
- package/vendor/client/google-signin.js +1 -133
- package/vendor/client/hooks.js +1 -430
- package/vendor/client/model-discovery.js +1 -373
- package/vendor/client/naming.js +1 -283
- package/vendor/client/platform.js +1 -937
- package/vendor/client/prefs.js +1 -351
- package/vendor/client/presence-constants.js +1 -107
- package/vendor/client/presence.js +1 -438
- package/vendor/client/record-vault.js +3 -1055
- package/vendor/client/session-store.js +1 -575
- package/vendor/client/topup.js +1 -297
- package/vendor/client/touch.js +1 -458
- package/vendor/client/update.js +1 -763
- package/vendor/client/user-models.js +1 -381
- package/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/desktop/lib/local/attachments.js +1 -276
- package/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/desktop/lib/local/claude-pro.js +1 -1028
- package/vendor/desktop/lib/local/context.js +1 -125
- package/vendor/desktop/lib/local/engine.js +1 -3666
- package/vendor/desktop/lib/local/entitlement.js +1 -660
- package/vendor/desktop/lib/local/exec-plan.js +1 -269
- package/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/desktop/lib/local/integrity.js +1 -163
- package/vendor/desktop/lib/local/local.js +1 -2145
- package/vendor/desktop/lib/local/prompt.js +1 -280
- package/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/desktop/lib/local/session-rounds.js +1 -238
- package/vendor/desktop/lib/local/shell.js +1 -712
- package/vendor/desktop/lib/local/spill.js +1 -75
- package/vendor/desktop/lib/local/tools.js +1 -1328
- package/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/desktop/lib/settings.js +1 -890
- package/vendor/desktop/main.js +1 -4890
- package/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/hosts/install.js +1 -638
- package/vendor/hosts/openai-shim.js +1 -515
- package/vendor/hosts/spec.js +1 -164
- package/vendor/hosts/targets.js +1 -346
- package/vendor/mcp/server.js +1 -221
- package/vendor/mcp/tools.js +1 -408
- package/vendor/one/src/child.js +1 -285
- package/vendor/one/src/permissions.js +1 -383
package/vendor/client/naming.js
CHANGED
|
@@ -1,285 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
4
|
-
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
-
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Naming a conversation — the ONE implementation, for every host.
|
|
10
|
-
*
|
|
11
|
-
* `cli/src/naming.js` documented the ladder and the desktop face never got it:
|
|
12
|
-
* the window named a thread with `prompt.slice(0, 60)` (renderer/app.js
|
|
13
|
-
* `sync.save`) and `session-store.js`'s `recordExchange` seeds every CLI
|
|
14
|
-
* session the same way. So a desktop thread called its first message a name —
|
|
15
|
-
* "heey" in the sidebar, "can you fix the binaries for aegis-desktop. why is
|
|
16
|
-
* old version kicking in" clipped mid-word — while the same conversation in a
|
|
17
|
-
* terminal was named "Fix the desktop binaries". Same conversation, two names,
|
|
18
|
-
* depending on which host you opened it in.
|
|
19
|
-
*
|
|
20
|
-
* This module is that ladder moved to `client/` so both faces share one
|
|
21
|
-
* implementation instead of the desktop re-deriving it:
|
|
22
|
-
*
|
|
23
|
-
* 1. topicless first message (a greeting) → GENERIC_TITLE, and NO model call.
|
|
24
|
-
* Asking just makes the model echo the prompt back ("heey" → "Heey
|
|
25
|
-
* There"), so it is both cheaper and more deterministic to answer locally.
|
|
26
|
-
* 2. the session's own model, one no-tool round, asked to name the
|
|
27
|
-
* conversation (2–6 words, never the user's words verbatim).
|
|
28
|
-
* 3. a purely local derivation from the prompt (capitalized head, stopwords
|
|
29
|
-
* trimmed) when no model answered.
|
|
30
|
-
*
|
|
31
|
-
* Two guarantees carry over, and both are load-bearing:
|
|
32
|
-
*
|
|
33
|
-
* · a title that merely echoes the prompt ("fix bug" → "Fix The Bug") is not a
|
|
34
|
-
* name — it is replaced by GENERIC_TITLE, and the caller keeps re-asking on
|
|
35
|
-
* later turns until a real topic lands.
|
|
36
|
-
* · naming is best-effort and never on the critical path: `nameConversation`
|
|
37
|
-
* resolves (never throws) and its caller is free to ignore the result.
|
|
38
|
-
*
|
|
39
|
-
* The model round is *injected* (`callModel`), not spawned here: each host's
|
|
40
|
-
* turn path already knows how to talk to whichever backend the session uses
|
|
41
|
-
* (pooled, BYOK or the reference CLI), and a naming round must not become a
|
|
42
|
-
* second, differently-authenticated client.
|
|
43
|
-
*
|
|
44
|
-
* `cli/src/naming.js` is now a thin re-export of this file, so the CLI's
|
|
45
|
-
* existing callers and its test keep working while there is exactly one copy
|
|
46
|
-
* of the rules. A fork here is how the two hosts' names would drift apart
|
|
47
|
-
* again.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
/** The name a conversation gets before it has a topic. Deliberately generic and
|
|
51
|
-
* deliberately NOT the raw prompt — the whole point is that "heey" is not a
|
|
52
|
-
* name, and the caller re-asks until a real one lands. */
|
|
53
|
-
const GENERIC_TITLE = 'New conversation';
|
|
54
|
-
|
|
55
|
-
const TITLE_SYSTEM =
|
|
56
|
-
'You name conversations. Write a short descriptive title (2 to 6 words) that captures the topic of the conversation. Never repeat the user\'s words verbatim — if the message is just a greeting or has no clear topic, name it something like "New conversation". Sentence case, no quotes, no markdown, no trailing punctuation, no explanation.';
|
|
57
|
-
|
|
58
|
-
const isGenericTitle = (t) => !t || String(t).trim().toLowerCase() === GENERIC_TITLE.toLowerCase();
|
|
59
|
-
|
|
60
|
-
// A greeting / topicless first message has no topic to name — asking the model
|
|
61
|
-
// just makes it echo the prompt back ("heey" -> "Heey There"). Detect those up
|
|
62
|
-
// front and skip the round entirely: it is cheaper and deterministic.
|
|
63
|
-
const GREETINGS = new Set([
|
|
64
|
-
'hey', 'heey', 'heyy', 'heyyy', 'hi', 'hii', 'hello', 'hej', 'hejj', 'yo',
|
|
65
|
-
'sup', 'hola', 'howdy', 'hai', 'heyo', 'hiya', 'wassup', 'greetings',
|
|
66
|
-
'namaste', 'ahoy', 'hallo',
|
|
67
|
-
]);
|
|
68
|
-
|
|
69
|
-
function isTopicless(raw) {
|
|
70
|
-
const p = String(raw).trim().toLowerCase().replace(/[^a-z0-9\s]/g, ' ').replace(/\s+/g, ' ').trim();
|
|
71
|
-
if (!p) return true;
|
|
72
|
-
const words = p.split(' ');
|
|
73
|
-
if (/^(good (morning|afternoon|evening)|whats up|wassup|hey there|hello there|hi there|how are you)\b/.test(p)) return true;
|
|
74
|
-
// A lone greeting word, or a short greeting phrase (<=2 words, <=12 chars)
|
|
75
|
-
// whose first word is a greeting, has no discernible topic.
|
|
76
|
-
return words.length <= 2 && p.length <= 12 && GREETINGS.has(words[0]);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** The model sometimes still echoes a short prompt despite the instruction
|
|
80
|
-
* ("fix bug" -> "Fix The Bug"). That is not a rename; treat it as topicless. */
|
|
81
|
-
function looksLikeEcho(title, prompt) {
|
|
82
|
-
const norm = (s) => String(s).toLowerCase().replace(/[^a-z0-9\s]/g, '').replace(/\s+/g, ' ').trim();
|
|
83
|
-
const t = norm(title);
|
|
84
|
-
const p = norm(prompt);
|
|
85
|
-
if (!t || !p) return false;
|
|
86
|
-
if (t === p) return true;
|
|
87
|
-
// Short prompt that the title merely prefixes with a trivial continuation.
|
|
88
|
-
if (p.length <= 14 && (t.startsWith(p) || p.startsWith(t))) return true;
|
|
89
|
-
// …and the rule the engine's own comment names but its test misses. The
|
|
90
|
-
// engine compares raw prefixes, so its documented example — "fix bug" ->
|
|
91
|
-
// "Fix The Bug" — slips through: the model inserted "the", `t.startsWith(p)`
|
|
92
|
-
// is false, and the session keeps a title that is just the prompt again.
|
|
93
|
-
// Compare the CONTENT words instead (function words dropped on both sides),
|
|
94
|
-
// for short prompts only, where the risk of discarding a genuine title is
|
|
95
|
-
// negligible and the benefit is the case the rule exists for.
|
|
96
|
-
if (p.length <= 24) {
|
|
97
|
-
const words = (s) => new Set((String(s).toLowerCase().match(/[a-z0-9]+/g) || []).filter((w) => !ECHO_STOP.has(w)));
|
|
98
|
-
const a = words(title);
|
|
99
|
-
const b = words(prompt);
|
|
100
|
-
if (a.size && a.size === b.size && [...a].every((w) => b.has(w))) return true;
|
|
101
|
-
}
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** Function words that carry no topic, dropped before the echo comparison. */
|
|
106
|
-
const ECHO_STOP = new Set([
|
|
107
|
-
'the', 'a', 'an', 'to', 'of', 'in', 'on', 'at', 'for', 'and', 'or', 'is',
|
|
108
|
-
'are', 'be', 'it', 'its', 'my', 'our', 'please', 'can', 'you', 'just', 'do',
|
|
109
|
-
'that', 'this',
|
|
110
|
-
]);
|
|
111
|
-
|
|
112
|
-
/** One-line cleanup of whatever the model answered: no quotes, no markdown, no
|
|
113
|
-
* trailing punctuation, clipped. '' means "unusable".
|
|
114
|
-
*
|
|
115
|
-
* Order matters: a model asked not to quote often answers `"Title: Fixing the
|
|
116
|
-
* slow request."` anyway, and stripping the label prefix BEFORE the quotes
|
|
117
|
-
* leaves it in place (the `^` never sees past the opening quote) — measured.
|
|
118
|
-
* Quotes and markdown come off first, then the label. */
|
|
119
|
-
function cleanTitle(raw) {
|
|
120
|
-
return String(raw == null ? '' : raw)
|
|
121
|
-
.replace(/\s+/g, ' ')
|
|
122
|
-
.trim()
|
|
123
|
-
.replace(/["'`“”‘’]/g, '')
|
|
124
|
-
.replace(/[*_#]/g, '')
|
|
125
|
-
.replace(/^\s*(?:title|name)\s*[:\-–]\s*/i, '')
|
|
126
|
-
.replace(/[.\s]+$/g, '')
|
|
127
|
-
.slice(0, 60)
|
|
128
|
-
.trim();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** The naming instruction the model is asked to answer (never the user's task). */
|
|
132
|
-
const titlePromptOf = (prompt) =>
|
|
133
|
-
`Write a short title for a conversation that begins with: "${String(prompt).slice(0, 500)}"`;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Politeness and throat-clearing, stripped from the front of a prompt, so the
|
|
137
|
-
* fallback name says "Do the thing" instead of "Please Can You Just Do". Same
|
|
138
|
-
* list the terminal title uses for its topic — one habit, stripped once.
|
|
139
|
-
*/
|
|
140
|
-
const FILLER =
|
|
141
|
-
/^(?:please|pls|plz|hey|hi|hello|ok(?:ay)?|so|now|just|also|and|then|maybe|well|um|uh|can you|could you|would you|will you|i want you to|i want to|i need you to|i need to|i'?d like you to|i would like you to|i'?d like to|help me|help|let'?s|lets|go ahead and)\b[\s,:;-]*/i;
|
|
142
|
-
|
|
143
|
-
/** Words that carry no topic when trimming the tail of a derived name. */
|
|
144
|
-
const TRAILING_STOP = new Set([
|
|
145
|
-
'the', 'a', 'an', 'in', 'on', 'at', 'to', 'for', 'of', 'and', 'or', 'with',
|
|
146
|
-
'is', 'are', 'my', 'our', 'this', 'that', 'please', 'can', 'you', 'could',
|
|
147
|
-
'would', 'i', 'we', 'just', 'do', 'it',
|
|
148
|
-
]);
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Last rung: a name derived from the prompt, used only when no model answered.
|
|
152
|
-
* Never the bare product name, and never the raw prompt verbatim.
|
|
153
|
-
*
|
|
154
|
-
* Sentence case, not Title Case: that is what TITLE_SYSTEM asks the model for,
|
|
155
|
-
* so the fallback matches the names around it. (The engine's derivation
|
|
156
|
-
* capitalizes every word — "Add A Retry To The Fetcher" — which reads like a
|
|
157
|
-
* heading next to the model's own answers.)
|
|
158
|
-
*/
|
|
159
|
-
function deriveTitle(prompt) {
|
|
160
|
-
let body = String(prompt == null ? '' : prompt).trim().replace(/\s+/g, ' ');
|
|
161
|
-
if (!body) return GENERIC_TITLE;
|
|
162
|
-
for (let i = 0; i < 6; i++) {
|
|
163
|
-
const next = body.replace(FILLER, '').trim();
|
|
164
|
-
if (next === body) break;
|
|
165
|
-
body = next;
|
|
166
|
-
}
|
|
167
|
-
const words = body.split(' ').filter(Boolean);
|
|
168
|
-
if (!words.length) return GENERIC_TITLE;
|
|
169
|
-
const head = words.slice(0, 6);
|
|
170
|
-
while (head.length > 2 && TRAILING_STOP.has(head[head.length - 1].toLowerCase().replace(/[^a-z0-9]/g, ''))) head.pop();
|
|
171
|
-
let out = head.join(' ').replace(/[.,!?;:]+$/, '').trim();
|
|
172
|
-
if (!out) return GENERIC_TITLE;
|
|
173
|
-
out = out[0].toUpperCase() + out.slice(1);
|
|
174
|
-
return out.slice(0, 60).trim() || GENERIC_TITLE;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Name a conversation from its first user prompt.
|
|
179
|
-
*
|
|
180
|
-
* `callModel(prompt, { system, signal, naming })` (async) is the caller's own
|
|
181
|
-
* model seam and must return a string (or null). With no `callModel` — demo
|
|
182
|
-
* mode, or a caller that has no backend — it answers from the local
|
|
183
|
-
* derivation. Never throws; resolves '' only when there was no prompt at all
|
|
184
|
-
* (the caller keeps whatever it had).
|
|
185
|
-
*
|
|
186
|
-
* `{ signal }` is honoured between rounds and passed through, so aborting a turn
|
|
187
|
-
* abandons a naming round in flight rather than leaving it running.
|
|
188
|
-
*/
|
|
189
|
-
async function nameConversation(prompt, { callModel, signal } = {}) {
|
|
190
|
-
const raw = prompt == null ? '' : String(prompt);
|
|
191
|
-
if (!raw.trim()) return '';
|
|
192
|
-
if (isTopicless(raw)) return GENERIC_TITLE;
|
|
193
|
-
if (typeof callModel === 'function' && !(signal && signal.aborted)) {
|
|
194
|
-
let answer = null;
|
|
195
|
-
try {
|
|
196
|
-
answer = await callModel(titlePromptOf(raw), { system: TITLE_SYSTEM, signal, naming: true });
|
|
197
|
-
} catch {
|
|
198
|
-
answer = null;
|
|
199
|
-
}
|
|
200
|
-
const title = cleanTitle(answer);
|
|
201
|
-
if (title) return looksLikeEcho(title, raw) ? GENERIC_TITLE : title;
|
|
202
|
-
}
|
|
203
|
-
return deriveTitle(raw);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* The title a session should carry after a later prompt, given the one it has.
|
|
208
|
-
*
|
|
209
|
-
* While the session is still wearing GENERIC_TITLE (the user opened with "heey"
|
|
210
|
-
* and has now said what they actually want) the next real ask renames it; once
|
|
211
|
-
* a real title exists it is kept, so a follow-up does not rename a session away
|
|
212
|
-
* from its topic. `null` means "no opinion, keep what you have".
|
|
213
|
-
*
|
|
214
|
-
* `{ seeded: true }` covers the other way a session can still be unnamed: the
|
|
215
|
-
* desktop's `prompt.slice(0, 60)` seed and `recordExchange`'s, which are
|
|
216
|
-
* neither GENERIC_TITLE nor a name. The store records that distinction
|
|
217
|
-
* (`session.named`), so the caller passes it rather than this module guessing
|
|
218
|
-
* from the string.
|
|
219
|
-
*/
|
|
220
|
-
async function refineTitle(currentTitle, prompt, opts = {}) {
|
|
221
|
-
const named = opts && opts.named === true;
|
|
222
|
-
const seeded = opts && opts.seeded === true;
|
|
223
|
-
if (named) return null;
|
|
224
|
-
if (!seeded && !isGenericTitle(currentTitle)) return null;
|
|
225
|
-
if (!String(prompt || '').trim() || isTopicless(prompt)) return null;
|
|
226
|
-
const next = await nameConversation(prompt, opts);
|
|
227
|
-
const cleaned = cleanTitle(next);
|
|
228
|
-
if (!cleaned || isGenericTitle(cleaned)) return null;
|
|
229
|
-
return cleaned;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Name a session in place, through the store both hosts read.
|
|
234
|
-
*
|
|
235
|
-
* This is the ONE entry point a host needs: it derives the name from the
|
|
236
|
-
* prompt, skips a session that already has a real name, writes it to
|
|
237
|
-
* `sessions.json` with `named: true`, and returns the name (or null when it
|
|
238
|
-
* had no opinion). Best-effort — a store that cannot be written costs a label,
|
|
239
|
-
* never a turn. `store` is injected so this module stays free of the store's
|
|
240
|
-
* own locking and so a test can pass a stub.
|
|
241
|
-
*/
|
|
242
|
-
async function nameSession(store, dir, sessionId, prompt, opts = {}) {
|
|
243
|
-
if (!store || typeof store.setTitle !== 'function') return null;
|
|
244
|
-
if (!sessionId) return null;
|
|
245
|
-
const session = typeof store.getSession === 'function' ? store.getSession(dir, sessionId) : null;
|
|
246
|
-
const current = session && session.title;
|
|
247
|
-
const structured = { ...opts, seeded: !!(session && !session.named) };
|
|
248
|
-
const next = await refineTitle(current, prompt, structured);
|
|
249
|
-
if (next) {
|
|
250
|
-
try {
|
|
251
|
-
store.setTitle(dir, sessionId, next, { named: true });
|
|
252
|
-
} catch {
|
|
253
|
-
return null;
|
|
254
|
-
}
|
|
255
|
-
return next;
|
|
256
|
-
}
|
|
257
|
-
// A greeting names nothing, but the row should still say so instead of
|
|
258
|
-
// wearing the raw prompt. The CLI does this too: `nameConversation` answers
|
|
259
|
-
// GENERIC_TITLE and `setSessionTitle` writes it. Marked unnamed (`setTitle`
|
|
260
|
-
// without `named`), so the next real ask still renames it — which is the
|
|
261
|
-
// whole point of the ladder's first rung.
|
|
262
|
-
if (isTopicless(prompt) && session && !session.named && !isGenericTitle(current)) {
|
|
263
|
-
try {
|
|
264
|
-
store.setTitle(dir, sessionId, GENERIC_TITLE);
|
|
265
|
-
} catch {
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
return GENERIC_TITLE;
|
|
269
|
-
}
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
module.exports = {
|
|
274
|
-
GENERIC_TITLE,
|
|
275
|
-
TITLE_SYSTEM,
|
|
276
|
-
isGenericTitle,
|
|
277
|
-
isTopicless,
|
|
278
|
-
looksLikeEcho,
|
|
279
|
-
cleanTitle,
|
|
280
|
-
titlePromptOf,
|
|
281
|
-
deriveTitle,
|
|
282
|
-
nameConversation,
|
|
283
|
-
refineTitle,
|
|
284
|
-
nameSession,
|
|
285
|
-
};
|
|
3
|
+
const e="New conversation",t='You name conversations. Write a short descriptive title (2 to 6 words) that captures the topic of the conversation. Never repeat the user\'s words verbatim — if the message is just a greeting or has no clear topic, name it something like "New conversation". Sentence case, no quotes, no markdown, no trailing punctuation, no explanation.',n=t=>!t||String(t).trim().toLowerCase()===e.toLowerCase(),i=new Set(["hey","heey","heyy","heyyy","hi","hii","hello","hej","hejj","yo","sup","hola","howdy","hai","heyo","hiya","wassup","greetings","namaste","ahoy","hallo"]);function o(e){const t=String(e).trim().toLowerCase().replace(/[^a-z0-9\s]/g," ").replace(/\s+/g," ").trim();if(!t)return!0;const n=t.split(" ");return!!/^(good (morning|afternoon|evening)|whats up|wassup|hey there|hello there|hi there|how are you)\b/.test(t)||n.length<=2&&t.length<=12&&i.has(n[0])}function r(e,t){const n=e=>String(e).toLowerCase().replace(/[^a-z0-9\s]/g,"").replace(/\s+/g," ").trim(),i=n(e),o=n(t);if(!i||!o)return!1;if(i===o)return!0;if(o.length<=14&&(i.startsWith(o)||o.startsWith(i)))return!0;if(o.length<=24){const n=e=>new Set((String(e).toLowerCase().match(/[a-z0-9]+/g)||[]).filter((e=>!s.has(e)))),i=n(e),o=n(t);if(i.size&&i.size===o.size&&[...i].every((e=>o.has(e))))return!0}return!1}const s=new Set(["the","a","an","to","of","in","on","at","for","and","or","is","are","be","it","its","my","our","please","can","you","just","do","that","this"]);function a(e){return String(null==e?"":e).replace(/\s+/g," ").trim().replace(/["'`“”‘’]/g,"").replace(/[*_#]/g,"").replace(/^\s*(?:title|name)\s*[:\-–]\s*/i,"").replace(/[.\s]+$/g,"").slice(0,60).trim()}const l=e=>`Write a short title for a conversation that begins with: "${String(e).slice(0,500)}"`,u=/^(?:please|pls|plz|hey|hi|hello|ok(?:ay)?|so|now|just|also|and|then|maybe|well|um|uh|can you|could you|would you|will you|i want you to|i want to|i need you to|i need to|i'?d like you to|i would like you to|i'?d like to|help me|help|let'?s|lets|go ahead and)\b[\s,:;-]*/i,c=new Set(["the","a","an","in","on","at","to","for","of","and","or","with","is","are","my","our","this","that","please","can","you","could","would","i","we","just","do","it"]);function h(t){let n=String(null==t?"":t).trim().replace(/\s+/g," ");if(!n)return e;for(let e=0;e<6;e++){const e=n.replace(u,"").trim();if(e===n)break;n=e}const i=n.split(" ").filter(Boolean);if(!i.length)return e;const o=i.slice(0,6);for(;o.length>2&&c.has(o[o.length-1].toLowerCase().replace(/[^a-z0-9]/g,""));)o.pop();let r=o.join(" ").replace(/[.,!?;:]+$/,"").trim();return r?(r=r[0].toUpperCase()+r.slice(1),r.slice(0,60).trim()||e):e}async function f(n,{callModel:i,signal:s}={}){const u=null==n?"":String(n);if(!u.trim())return"";if(o(u))return e;if(!("function"!=typeof i||s&&s.aborted)){let n=null;try{n=await i(l(u),{system:t,signal:s,naming:!0})}catch{n=null}const o=a(n);if(o)return r(o,u)?e:o}return h(u)}async function g(e,t,i={}){const r=i&&!0===i.named,s=i&&!0===i.seeded;if(r)return null;if(!s&&!n(e))return null;if(!String(t||"").trim()||o(t))return null;const l=a(await f(t,i));return!l||n(l)?null:l}module.exports={GENERIC_TITLE:e,TITLE_SYSTEM:t,isGenericTitle:n,isTopicless:o,looksLikeEcho:r,cleanTitle:a,titlePromptOf:l,deriveTitle:h,nameConversation:f,refineTitle:g,nameSession:async function(t,i,r,a,s={}){if(!t||"function"!=typeof t.setTitle)return null;if(!r)return null;const l="function"==typeof t.getSession?t.getSession(i,r):null,u=l&&l.title,c={...s,seeded:!(!l||l.named)},h=await g(u,a,c);if(h){try{t.setTitle(i,r,h,{named:!0})}catch{return null}return h}if(o(a)&&l&&!l.named&&!n(u)){try{t.setTitle(i,r,e)}catch{return null}return e}return null}};
|