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/src/sharedpaths.js
CHANGED
|
@@ -1,55 +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
|
-
* WHERE the CLI's shared modules are, with no side effects.
|
|
10
|
-
*
|
|
11
|
-
* This is `deps.js`'s path resolution split into its own module, and the split
|
|
12
|
-
* is load-bearing rather than cosmetic. `deps.js` eagerly requires everything
|
|
13
|
-
* it resolves — the engine, the tool registry, the client — so a module that
|
|
14
|
-
* only needs to *locate* one shared file cannot require deps.js: doing so
|
|
15
|
-
* from inside something deps.js itself requires would be a require cycle,
|
|
16
|
-
* handing one side a half-built exports object at load time.
|
|
17
|
-
*
|
|
18
|
-
* So: paths here, code in deps.js.
|
|
19
|
-
*
|
|
20
|
-
* Two layouts must work, exactly as deps.js documents:
|
|
21
|
-
*
|
|
22
|
-
* in-repo <repo>/cli/src/sharedpaths.js -> <repo>/desktop/lib/local/...
|
|
23
|
-
* npm <pkg>/src/sharedpaths.js -> <pkg>/vendor/desktop/lib/...
|
|
24
|
-
*
|
|
25
|
-
* Resolution is by existence, and a missing module is a loud error rather than
|
|
26
|
-
* a silent fallback to a second copy: duplicate implementations are how the
|
|
27
|
-
* desktop and the terminal would drift apart.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
const fs = require('node:fs');
|
|
31
|
-
const path = require('node:path');
|
|
32
|
-
|
|
33
|
-
function roots() {
|
|
34
|
-
const srcDir = __dirname; // <root>/cli/src
|
|
35
|
-
const cliDir = path.join(srcDir, '..');
|
|
36
|
-
return [
|
|
37
|
-
path.join(srcDir, '..', '..'), // repo root (in-repo layout)
|
|
38
|
-
path.join(cliDir, 'vendor'), // staged tree (published layout)
|
|
39
|
-
];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Resolve a repo-relative module path against whichever root has it. */
|
|
43
|
-
function resolveShared(relPath) {
|
|
44
|
-
for (const root of roots()) {
|
|
45
|
-
const candidate = path.join(root, relPath);
|
|
46
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
47
|
-
}
|
|
48
|
-
throw new Error(
|
|
49
|
-
`aegiscode: cannot find ${relPath}. Expected it beside cli/ (in the repo) or ` +
|
|
50
|
-
'under cli/vendor/ (installed package). Reinstall the package, or run ' +
|
|
51
|
-
'`node scripts/predist.mjs` from cli/ if this is a source checkout.'
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = { roots, resolveShared };
|
|
3
|
+
"use strict";const fs=require("node:fs"),path=require("node:path");function roots(){const e=__dirname,o=path.join(e,"..");return[path.join(e,"..",".."),path.join(o,"vendor")]}function resolveShared(e){for(const o of roots()){const r=path.join(o,e);if(fs.existsSync(r))return r}throw new Error(`aegiscode: cannot find ${e}. Expected it beside cli/ (in the repo) or under cli/vendor/ (installed package). Reinstall the package, or run \`node scripts/predist.mjs\` from cli/ if this is a source checkout.`)}module.exports={roots:roots,resolveShared:resolveShared};
|
package/src/signup.js
CHANGED
|
@@ -1,158 +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
|
-
/**
|
|
7
|
-
* The one place the CLI tells a user where to get an account key.
|
|
8
|
-
*
|
|
9
|
-
* Every prompt used to say "free at https://aegiscloud.org" — the marketing
|
|
10
|
-
* homepage. No registration panel, no route to the page that shows the key,
|
|
11
|
-
* and (because the landing URL carried no UTM) no way for aegis1 to tell the
|
|
12
|
-
* signup came from the CLI at all. That is a round trip the user has to
|
|
13
|
-
* complete unaided, at the exact moment they have already decided to keep the
|
|
14
|
-
* tool: the prompts were the top of the funnel and they dead-ended.
|
|
15
|
-
*
|
|
16
|
-
* So the prompt now prints a short, typeable deep link instead:
|
|
17
|
-
*
|
|
18
|
-
* https://aegiscloud.org/key?s=cli&c=key_screen
|
|
19
|
-
*
|
|
20
|
-
* `/key` is a real aegis1 route (app.py `key_short_link`) that expands —
|
|
21
|
-
* server-side — into the register panel plus the key page, with the channel
|
|
22
|
-
* UTMs attached. Two consequences worth knowing before editing anything here:
|
|
23
|
-
*
|
|
24
|
-
* - `s=cli` must stay in aegis1's SIGNUP_SOURCES or the signup is filed as
|
|
25
|
-
* 'direct' and this channel looks dead in the funnel. `s` is deliberately
|
|
26
|
-
* not caller-supplied: one wrong value silently zeroes the channel.
|
|
27
|
-
* - the URL is displayed, not just linked, so it has to stay short enough
|
|
28
|
-
* not to wrap in an 80-column terminal. That is the whole reason the
|
|
29
|
-
* expansion is a server-side redirect rather than a long query string: the
|
|
30
|
-
* full form is 108 chars and shears across lines.
|
|
31
|
-
*
|
|
32
|
-
* `campaign` is the prompt that printed the link, so prompts can be compared
|
|
33
|
-
* against each other instead of reported as one number. Unknown or absent
|
|
34
|
-
* campaigns are simply not sent — unattributed is a missing datapoint, never a
|
|
35
|
-
* wrong one.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
const SIGNUP_ORIGIN = 'https://aegiscloud.org';
|
|
39
|
-
|
|
40
|
-
/** The short aegis1 route that expands to "register, then show me my key". */
|
|
41
|
-
const SIGNUP_PATH = '/key';
|
|
42
|
-
|
|
43
|
-
/** The channel every CLI signup is filed under in aegis1 (SIGNUP_SOURCES). */
|
|
44
|
-
const SIGNUP_SOURCE = 'cli';
|
|
45
|
-
|
|
46
|
-
/** Bare `https://aegiscloud.org` for copy about the project rather than the
|
|
47
|
-
* key — the docs/troubleshooting links in system.js want the homepage. */
|
|
48
|
-
const HOME_URL = SIGNUP_ORIGIN;
|
|
49
|
-
|
|
50
|
-
/** Longest campaign slug aegis1 will record (`_sanitize_signup_slug`). */
|
|
51
|
-
const CAMPAIGN_RE = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* The deep link to show a user who has no key.
|
|
55
|
-
*
|
|
56
|
-
* A campaign that would not survive aegis1's slug sanitiser is dropped rather
|
|
57
|
-
* than sent: a link that records nothing is honest, a link that records the
|
|
58
|
-
* wrong prompt is not.
|
|
59
|
-
*/
|
|
60
|
-
function signupUrl(campaign) {
|
|
61
|
-
const url = new URL(SIGNUP_ORIGIN + SIGNUP_PATH);
|
|
62
|
-
url.searchParams.set('s', SIGNUP_SOURCE);
|
|
63
|
-
const slug = campaign === undefined || campaign === null ? '' : String(campaign).trim().toLowerCase();
|
|
64
|
-
if (CAMPAIGN_RE.test(slug)) url.searchParams.set('c', slug);
|
|
65
|
-
return url.toString();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Any other aegiscloud.org page the CLI links to, tagged with the same
|
|
70
|
-
* channel so the visit is attributable if it ends in a signup.
|
|
71
|
-
*
|
|
72
|
-
* aegis1's first-touch hook stores the UTMs on whichever page the visitor
|
|
73
|
-
* lands on, so a tagged link to the desktop page or the subscribe page is
|
|
74
|
-
* enough for the signup it eventually produces to be credited to the CLI —
|
|
75
|
-
* no separate route needed, unlike the key link above.
|
|
76
|
-
*/
|
|
77
|
-
function link(path, campaign) {
|
|
78
|
-
const url = new URL(SIGNUP_ORIGIN + (String(path).startsWith('/') ? path : `/${path}`));
|
|
79
|
-
url.searchParams.set('utm_source', SIGNUP_SOURCE);
|
|
80
|
-
url.searchParams.set('utm_medium', 'app');
|
|
81
|
-
const slug = campaign === undefined || campaign === null ? '' : String(campaign).trim().toLowerCase();
|
|
82
|
-
if (CAMPAIGN_RE.test(slug)) url.searchParams.set('utm_campaign', slug);
|
|
83
|
-
return url.toString();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* The printed form of the same link: scheme-less.
|
|
88
|
-
*
|
|
89
|
-
* Not cosmetic, and not a second URL — it is `signupUrl()` with the `https://`
|
|
90
|
-
* stripped, so the host, the route and the channel still come from one place.
|
|
91
|
-
* It exists because the welcome screen's connect row wraps its text at
|
|
92
|
-
* `cols - 4 - indent` (screens.js `wrapped()`), which is 75 cells at 80
|
|
93
|
-
* columns, and the row's copy already spends 45 of them:
|
|
94
|
-
*
|
|
95
|
-
* AEGIS Desktop: same engine on your machine — <url>
|
|
96
|
-
*
|
|
97
|
-
* https://aegiscloud.org/key?s=cli -> 77 cells, wraps
|
|
98
|
-
* aegiscloud.org/key?s=cli -> 69 cells, fits
|
|
99
|
-
*
|
|
100
|
-
* A wrapped row is not just ugly there: the welcome screen fills 23 of an
|
|
101
|
-
* 80x24 terminal's 24 rows, so the extra line pushes the footer hint off the
|
|
102
|
-
* bottom (test/cli-onboarding.test.mjs measures it). Given that, the scheme is
|
|
103
|
-
* the cheapest thing to lose — a browser prepends it when the user pastes, and
|
|
104
|
-
* `aegiscloud.org/teleport` is already printed this way in commands.js — while
|
|
105
|
-
* `s=cli` is not, because dropping that files the signup as 'direct'.
|
|
106
|
-
*
|
|
107
|
-
* Screens with room for the real thing (the key screen puts the link on its
|
|
108
|
-
* own row) must use `signupUrl()`.
|
|
109
|
-
*/
|
|
110
|
-
function signupDisplayUrl(campaign) {
|
|
111
|
-
return signupUrl(campaign).replace(/^https?:\/\//, '');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** aegis1's paid-prompt indirection: `/go/<page>` (app.py `GO_TARGETS`). */
|
|
115
|
-
const GO_PATH = '/go/';
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* A paid prompt's destination, in the short form `/go/<page>` documents.
|
|
119
|
-
*
|
|
120
|
-
* Deliberately NOT `link()`, and this is the whole reason the function exists.
|
|
121
|
-
* `link()` appends the wire names (`utm_source`/`utm_campaign`) because
|
|
122
|
-
* aegis1's first-touch hook reads those off whichever page the visitor lands
|
|
123
|
-
* on. `/go/<page>` is not that kind of link: it is a redirect, and it reads the
|
|
124
|
-
* short names (`s`/`c`) and re-emits the wire names itself.
|
|
125
|
-
*
|
|
126
|
-
* Sending wire names to `/go/` does not fail loudly. It fails silently, in the
|
|
127
|
-
* worst available way — the route finds no `s`, files the click as 'direct',
|
|
128
|
-
* drops the campaign, and the client that sent it reads as zero conversions
|
|
129
|
-
* while the link still visibly works. Measured against a real app instance:
|
|
130
|
-
*
|
|
131
|
-
* /go/upgrade?s=cli&c=memory_quota -> ?utm_source=cli&utm_campaign=memory_quota
|
|
132
|
-
* /go/upgrade?utm_source=cli&... -> ?utm_source=direct&utm_medium=app
|
|
133
|
-
*
|
|
134
|
-
* The route now also accepts the wire names as a fallback, so that mistake can
|
|
135
|
-
* no longer zero a channel — but the short form is still what to send, and not
|
|
136
|
-
* only for correctness: it is ~40 cells shorter, on rows that `padLine()`
|
|
137
|
-
* truncates rather than wraps (see `signupDisplayUrl()` above).
|
|
138
|
-
*/
|
|
139
|
-
function goUrl(page, campaign) {
|
|
140
|
-
const slug = String(page == null ? '' : page).trim().toLowerCase().replace(/^\/+|\/+$/g, '');
|
|
141
|
-
const url = new URL(SIGNUP_ORIGIN + GO_PATH + slug);
|
|
142
|
-
url.searchParams.set('s', SIGNUP_SOURCE);
|
|
143
|
-
const c = campaign === undefined || campaign === null ? '' : String(campaign).trim().toLowerCase();
|
|
144
|
-
if (CAMPAIGN_RE.test(c)) url.searchParams.set('c', c);
|
|
145
|
-
return url.toString();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
module.exports = {
|
|
149
|
-
signupUrl,
|
|
150
|
-
signupDisplayUrl,
|
|
151
|
-
goUrl,
|
|
152
|
-
link,
|
|
153
|
-
HOME_URL,
|
|
154
|
-
SIGNUP_SOURCE,
|
|
155
|
-
SIGNUP_PATH,
|
|
156
|
-
SIGNUP_ORIGIN,
|
|
157
|
-
CAMPAIGN_RE,
|
|
158
|
-
};
|
|
3
|
+
const SIGNUP_ORIGIN="https://aegiscloud.org",SIGNUP_PATH="/key",SIGNUP_SOURCE="cli",HOME_URL=SIGNUP_ORIGIN,CAMPAIGN_RE=/^[a-z0-9][a-z0-9_-]{0,63}$/;function signupUrl(t){const s=new URL(SIGNUP_ORIGIN+SIGNUP_PATH);s.searchParams.set("s",SIGNUP_SOURCE);const r=null==t?"":String(t).trim().toLowerCase();return CAMPAIGN_RE.test(r)&&s.searchParams.set("c",r),s.toString()}function link(t,s){const r=new URL(SIGNUP_ORIGIN+(String(t).startsWith("/")?t:`/${t}`));r.searchParams.set("utm_source",SIGNUP_SOURCE),r.searchParams.set("utm_medium","app");const n=null==s?"":String(s).trim().toLowerCase();return CAMPAIGN_RE.test(n)&&r.searchParams.set("utm_campaign",n),r.toString()}function signupDisplayUrl(t){return signupUrl(t).replace(/^https?:\/\//,"")}const GO_PATH="/go/";function goUrl(t,s){const r=String(null==t?"":t).trim().toLowerCase().replace(/^\/+|\/+$/g,""),n=new URL(SIGNUP_ORIGIN+"/go/"+r);n.searchParams.set("s",SIGNUP_SOURCE);const e=null==s?"":String(s).trim().toLowerCase();return CAMPAIGN_RE.test(e)&&n.searchParams.set("c",e),n.toString()}module.exports={signupUrl:signupUrl,signupDisplayUrl:signupDisplayUrl,goUrl:goUrl,link:link,HOME_URL:HOME_URL,SIGNUP_SOURCE:SIGNUP_SOURCE,SIGNUP_PATH:SIGNUP_PATH,SIGNUP_ORIGIN:SIGNUP_ORIGIN,CAMPAIGN_RE:CAMPAIGN_RE};
|
package/src/summarize.js
CHANGED
|
@@ -1,97 +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
|
-
* Transcript summarization for /compact and /recap.
|
|
10
|
-
*
|
|
11
|
-
* Dependency-free port of the upstream engine reference. The reference
|
|
12
|
-
* spawns `claude -p "Summarize…"` (via `resolveExecutable()` in
|
|
13
|
-
* client/platform.js — the shared module this repo actually ships, staged into
|
|
14
|
-
* cli/vendor/client/platform.js); here the
|
|
15
|
-
* backend is *injected* instead, so this module pulls in nothing but tokens.js:
|
|
16
|
-
*
|
|
17
|
-
* async summarizeTranscript(transcript, { callModel, model, signal } = {})
|
|
18
|
-
* async recapLine(transcript, { callModel, model, signal } = {})
|
|
19
|
-
*
|
|
20
|
-
* `callModel(prompt) -> string` (async) is the caller's own model seam. When
|
|
21
|
-
* `callModel` is not a function the module falls back to a purely local
|
|
22
|
-
* extraction — the first user text, the last assistant text and the turn count
|
|
23
|
-
* — and never throws. On abort (signal.aborted) it resolves null so handlers
|
|
24
|
-
* can report "cancelled"; on any other backend failure it resolves the local
|
|
25
|
-
* extraction.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
const { estimateTokens } = require('./tokens.js');
|
|
29
|
-
|
|
30
|
-
// Guard: don't push more than this many chars into a prompt.
|
|
31
|
-
const MAX_INPUT_CHARS = 120_000;
|
|
32
|
-
const MAX_REPLY_CHARS = 2_000;
|
|
33
|
-
|
|
34
|
-
function extractiveSummary(transcript) {
|
|
35
|
-
const users = transcript.filter((m) => m.role === 'user').map((m) => m.text || '');
|
|
36
|
-
const lastAsst = [...transcript].reverse().find((m) => m.role === 'assistant');
|
|
37
|
-
const topics = users.slice(0, 3).map((t) => `“${t.length > 48 ? t.slice(0, 45) + '…' : t}”`);
|
|
38
|
-
const parts = [];
|
|
39
|
-
if (users.length) parts.push(`Covered ${users.length} prompt${users.length > 1 ? 's' : ''}: ${topics.join('; ')}.`);
|
|
40
|
-
if (lastAsst) {
|
|
41
|
-
const tail = (lastAsst.text || '').split(/\s+/).slice(0, 30).join(' ');
|
|
42
|
-
parts.push(`Last reply began: ${tail.length > 100 ? tail.slice(0, 97) + '…' : tail}`);
|
|
43
|
-
}
|
|
44
|
-
if (!parts.length) return 'Session with no exchanges yet.';
|
|
45
|
-
return parts.join(' ');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function demoSummary(transcript) {
|
|
49
|
-
return `[demo summary] ${extractiveSummary(transcript)}`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Summarize the whole transcript in a few sentences. Resolves null on abort. */
|
|
53
|
-
async function summarizeTranscript(transcript, { callModel, model, signal } = {}) {
|
|
54
|
-
if (!transcript || !transcript.length) return 'Session with no exchanges yet.';
|
|
55
|
-
if (typeof callModel !== 'function') return demoSummary(transcript);
|
|
56
|
-
return callBackend('summarize', transcript, model, signal, callModel, () => demoSummary(transcript));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** A single-line recap. Resolves null on abort. */
|
|
60
|
-
async function recapLine(transcript, { callModel, model, signal } = {}) {
|
|
61
|
-
if (!transcript || !transcript.length) return 'No exchanges yet.';
|
|
62
|
-
if (typeof callModel !== 'function') return `[demo recap] ${extractiveSummary(transcript)}`;
|
|
63
|
-
return callBackend('recap', transcript, model, signal, callModel, () => `[demo recap] ${extractiveSummary(transcript)}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function callBackend(kind, transcript, model, signal, callModel, fallback) {
|
|
67
|
-
const text = transcriptToText(transcript).slice(0, MAX_INPUT_CHARS);
|
|
68
|
-
// NB: the ternary binds exactly as in the reference — the recap branch does
|
|
69
|
-
// not append the transcript text. Ported verbatim.
|
|
70
|
-
const prompt = kind === 'recap'
|
|
71
|
-
? 'Recap the following conversation in one sentence. Be factual and specific.'
|
|
72
|
-
: 'Summarize the following conversation. Preserve every requirement, decision, and open question, in 2-4 sentences.'
|
|
73
|
-
+ '\n\n' + text;
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
if (signal && signal.aborted) return null;
|
|
77
|
-
const out = await callModel(prompt, { model, signal });
|
|
78
|
-
if (signal && signal.aborted) return null;
|
|
79
|
-
if (typeof out === 'string' && out.trim()) return out.trim().slice(0, MAX_REPLY_CHARS);
|
|
80
|
-
return fallback();
|
|
81
|
-
} catch {
|
|
82
|
-
return fallback();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function transcriptToText(transcript) {
|
|
87
|
-
return transcript
|
|
88
|
-
.filter((m) => m.role === 'user' || m.role === 'assistant' || m.role === 'note')
|
|
89
|
-
.map((m) => `${m.role}: ${m.text || ''}`)
|
|
90
|
-
.join('\n\n');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
module.exports = {
|
|
94
|
-
summarizeTranscript,
|
|
95
|
-
recapLine,
|
|
96
|
-
estimateTokens,
|
|
97
|
-
};
|
|
3
|
+
"use strict";const{estimateTokens:estimateTokens}=require("./tokens.js"),MAX_INPUT_CHARS=12e4,MAX_REPLY_CHARS=2e3;function extractiveSummary(e){const n=e.filter((e=>"user"===e.role)).map((e=>e.text||"")),t=[...e].reverse().find((e=>"assistant"===e.role)),r=n.slice(0,3).map((e=>`“${e.length>48?e.slice(0,45)+"…":e}”`)),i=[];if(n.length&&i.push(`Covered ${n.length} prompt${n.length>1?"s":""}: ${r.join("; ")}.`),t){const e=(t.text||"").split(/\s+/).slice(0,30).join(" ");i.push(`Last reply began: ${e.length>100?e.slice(0,97)+"…":e}`)}return i.length?i.join(" "):"Session with no exchanges yet."}function demoSummary(e){return`[demo summary] ${extractiveSummary(e)}`}async function summarizeTranscript(e,{callModel:n,model:t,signal:r}={}){return e&&e.length?"function"!=typeof n?demoSummary(e):callBackend("summarize",e,t,r,n,(()=>demoSummary(e))):"Session with no exchanges yet."}async function recapLine(e,{callModel:n,model:t,signal:r}={}){return e&&e.length?"function"!=typeof n?`[demo recap] ${extractiveSummary(e)}`:callBackend("recap",e,t,r,n,(()=>`[demo recap] ${extractiveSummary(e)}`)):"No exchanges yet."}async function callBackend(e,n,t,r,i,s){const a=transcriptToText(n).slice(0,MAX_INPUT_CHARS),o="recap"===e?"Recap the following conversation in one sentence. Be factual and specific.":"Summarize the following conversation. Preserve every requirement, decision, and open question, in 2-4 sentences.\n\n"+a;try{if(r&&r.aborted)return null;const e=await i(o,{model:t,signal:r});return r&&r.aborted?null:"string"==typeof e&&e.trim()?e.trim().slice(0,MAX_REPLY_CHARS):s()}catch{return s()}}function transcriptToText(e){return e.filter((e=>"user"===e.role||"assistant"===e.role||"note"===e.role)).map((e=>`${e.role}: ${e.text||""}`)).join("\n\n")}module.exports={summarizeTranscript:summarizeTranscript,recapLine:recapLine,estimateTokens:estimateTokens};
|