@signal4/s4 2.6.1 → 2.7.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 +33 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +317 -176
- package/dist/cli.js.map +1 -1
- package/dist/cli_args.d.ts +24 -0
- package/dist/cli_args.d.ts.map +1 -0
- package/dist/cli_args.js +130 -0
- package/dist/cli_args.js.map +1 -0
- package/dist/client.d.ts +77 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +123 -22
- package/dist/client.js.map +1 -1
- package/dist/format.d.ts +76 -2
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +197 -44
- package/dist/format.js.map +1 -1
- package/dist/handler_types.d.ts +10 -0
- package/dist/handler_types.d.ts.map +1 -1
- package/dist/handler_types.js +25 -0
- package/dist/handler_types.js.map +1 -1
- package/dist/handlers/ads.js +4 -4
- package/dist/handlers/ads.js.map +1 -1
- package/dist/handlers/analyze.d.ts.map +1 -1
- package/dist/handlers/analyze.js +22 -6
- package/dist/handlers/analyze.js.map +1 -1
- package/dist/handlers/bookmarks.js +2 -2
- package/dist/handlers/bookmarks.js.map +1 -1
- package/dist/handlers/claim_detail.js +2 -2
- package/dist/handlers/claim_detail.js.map +1 -1
- package/dist/handlers/claims.d.ts.map +1 -1
- package/dist/handlers/claims.js +60 -24
- package/dist/handlers/claims.js.map +1 -1
- package/dist/handlers/count.d.ts +7 -0
- package/dist/handlers/count.d.ts.map +1 -0
- package/dist/handlers/count.js +146 -0
- package/dist/handlers/count.js.map +1 -0
- package/dist/handlers/explore.d.ts.map +1 -1
- package/dist/handlers/explore.js +53 -14
- package/dist/handlers/explore.js.map +1 -1
- package/dist/handlers/registry.d.ts.map +1 -1
- package/dist/handlers/registry.js +5 -1
- package/dist/handlers/registry.js.map +1 -1
- package/dist/handlers/reports.d.ts +1 -0
- package/dist/handlers/reports.d.ts.map +1 -1
- package/dist/handlers/reports.js +41 -12
- package/dist/handlers/reports.js.map +1 -1
- package/dist/handlers/search.d.ts.map +1 -1
- package/dist/handlers/search.js +67 -21
- package/dist/handlers/search.js.map +1 -1
- package/dist/handlers/timeline.d.ts.map +1 -1
- package/dist/handlers/timeline.js +14 -8
- package/dist/handlers/timeline.js.map +1 -1
- package/dist/http.js +25 -3
- package/dist/http.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/provenance.d.ts +29 -2
- package/dist/provenance.d.ts.map +1 -1
- package/dist/provenance.js +63 -4
- package/dist/provenance.js.map +1 -1
- package/dist/server_core.d.ts +8 -1
- package/dist/server_core.d.ts.map +1 -1
- package/dist/server_core.js +90 -8
- package/dist/server_core.js.map +1 -1
- package/dist/speed.d.ts +40 -0
- package/dist/speed.d.ts.map +1 -0
- package/dist/speed.js +196 -0
- package/dist/speed.js.map +1 -0
- package/dist/surface.d.ts +7 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +18 -0
- package/dist/surface.js.map +1 -0
- package/dist/types.d.ts +151 -8
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/server_core.js
CHANGED
|
@@ -12,6 +12,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
12
12
|
import { ListToolsRequestSchema, CallToolRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
13
13
|
import * as client from "./client.js";
|
|
14
14
|
import { HANDLERS } from "./handlers/registry.js";
|
|
15
|
+
import { decorateDescription, elapsedFooter, estimate, startNotice } from "./speed.js";
|
|
15
16
|
export const RETRY_COOLDOWN_MS = 60_000;
|
|
16
17
|
/**
|
|
17
18
|
* Manifest cache with the 60s auth-failure cooldown. One instance per key
|
|
@@ -95,10 +96,57 @@ function diagnosticToolResponse(provider) {
|
|
|
95
96
|
// ---------------------------------------------------------------------------
|
|
96
97
|
// Server construction
|
|
97
98
|
// ---------------------------------------------------------------------------
|
|
98
|
-
|
|
99
|
+
/** Appended to the server instructions, so an agent knows how to read the speed tags. */
|
|
100
|
+
export const SPEED_NOTE = "\n\nSPEED: every tool description starts with its speed at default settings — instant (<0.5s), " +
|
|
101
|
+
"fast (0.5–2.5s) or slow (>2.5s) — and, for search, counts and timelines, how it grows with the " +
|
|
102
|
+
"window (\"12 months ~3–6s, all time ~5–10s\"). A call expected to take a while sends a progress " +
|
|
103
|
+
"notice with its estimate as it starts; an answer that took over 2.5s ends with \"Took Ns\". " +
|
|
104
|
+
"Prefer a narrower window or a keyword search when time matters.";
|
|
105
|
+
export const FALLBACK_INSTRUCTIONS = "Signal4 media intelligence: searchable transcripts of podcasts, YouTube and broadcasts. " +
|
|
106
|
+
"Start here: list_collections (what you can scope to), then search_quotes (topic, optional speaker/channel/days), " +
|
|
107
|
+
"then get_segment or get_thread for context. Omit `collection` to search the whole corpus. " +
|
|
108
|
+
"Results show IDs like seg:123; pass those to get_segment. Analysis tools are slow and paid: use search first.";
|
|
109
|
+
/** Fetch the manifest's instructions, giving up after `ms` so startup never hangs. */
|
|
110
|
+
export async function loadInstructions(provider, ms = 3000) {
|
|
111
|
+
let timer;
|
|
112
|
+
try {
|
|
113
|
+
const m = await Promise.race([
|
|
114
|
+
provider.fetch(),
|
|
115
|
+
new Promise((_, rej) => { timer = setTimeout(() => rej(new Error("manifest timeout")), ms); }),
|
|
116
|
+
]);
|
|
117
|
+
return m.instructions || undefined;
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
99
126
|
const { version: PKG_VERSION } = createRequire(import.meta.url)("../package.json");
|
|
100
|
-
|
|
101
|
-
|
|
127
|
+
/** Turn a FastAPI 422 body into "parameter <loc>: <msg>". */
|
|
128
|
+
export function translate422(raw) {
|
|
129
|
+
const i = raw.indexOf("[");
|
|
130
|
+
const j = raw.indexOf("{");
|
|
131
|
+
const at = i >= 0 && (j < 0 || i < j) ? i : j;
|
|
132
|
+
if (at >= 0) {
|
|
133
|
+
try {
|
|
134
|
+
const body = JSON.parse(raw.slice(at));
|
|
135
|
+
const items = Array.isArray(body) ? body : Array.isArray(body?.detail) ? body.detail : null;
|
|
136
|
+
if (items) {
|
|
137
|
+
return items.slice(0, 3).map((e) => {
|
|
138
|
+
const loc = Array.isArray(e.loc) ? e.loc.filter((x) => x !== "body" && x !== "query").join(".") : "";
|
|
139
|
+
return `parameter ${loc || "?"}: ${e.msg ?? "invalid"}`;
|
|
140
|
+
}).join("; ");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch { /* fall through */ }
|
|
144
|
+
}
|
|
145
|
+
// A plain-text detail (e.g. a search that ran past its time limit) is the message.
|
|
146
|
+
return raw.replace(/^[\s\S]*?HTTP 422:?\s*/, "").slice(0, 400);
|
|
147
|
+
}
|
|
148
|
+
export function buildServer(provider, instructions) {
|
|
149
|
+
const server = new McpServer({ name: "Signal4", version: PKG_VERSION }, { instructions: (instructions || FALLBACK_INSTRUCTIONS) + SPEED_NOTE });
|
|
102
150
|
// Register tool capabilities and custom handlers on the underlying Server
|
|
103
151
|
// BEFORE any .tool() call — we own the tool protocol directly so we can
|
|
104
152
|
// serve raw JSON Schema from the manifest without zod conversion.
|
|
@@ -109,7 +157,8 @@ export function buildServer(provider) {
|
|
|
109
157
|
return {
|
|
110
158
|
tools: m.tools.map((t) => ({
|
|
111
159
|
name: t.name,
|
|
112
|
-
description
|
|
160
|
+
// Every description starts with how long the call takes (speed.ts).
|
|
161
|
+
description: decorateDescription(t.name, t.description),
|
|
113
162
|
inputSchema: t.inputSchema,
|
|
114
163
|
})),
|
|
115
164
|
};
|
|
@@ -118,7 +167,7 @@ export function buildServer(provider) {
|
|
|
118
167
|
return diagnosticToolList(provider);
|
|
119
168
|
}
|
|
120
169
|
});
|
|
121
|
-
server.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
170
|
+
server.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
122
171
|
try {
|
|
123
172
|
const { name, arguments: args } = request.params;
|
|
124
173
|
if (name === AUTH_DIAGNOSTIC_TOOL) {
|
|
@@ -140,19 +189,52 @@ export function buildServer(provider) {
|
|
|
140
189
|
isError: true,
|
|
141
190
|
};
|
|
142
191
|
}
|
|
143
|
-
|
|
192
|
+
// A call expected to take more than a moment says so before it starts, to
|
|
193
|
+
// clients that asked for progress (an MCP progressToken).
|
|
194
|
+
const params = (args ?? {});
|
|
195
|
+
const expected = estimate(name, params);
|
|
196
|
+
const token = request.params._meta?.progressToken;
|
|
197
|
+
if (expected.tier !== "instant" && token !== undefined) {
|
|
198
|
+
await extra.sendNotification({
|
|
199
|
+
method: "notifications/progress",
|
|
200
|
+
params: { progressToken: token, progress: 0, message: startNotice(expected) },
|
|
201
|
+
}).catch(() => { });
|
|
202
|
+
}
|
|
203
|
+
const started = Date.now();
|
|
204
|
+
const result = await handler(params);
|
|
205
|
+
// A slow answer says how long it took, so an agent can plan the next call.
|
|
206
|
+
const footer = elapsedFooter(Date.now() - started);
|
|
207
|
+
const last = result.content[result.content.length - 1];
|
|
208
|
+
if (footer && last && !result.isError && params.response_format !== "json")
|
|
209
|
+
last.text += footer;
|
|
210
|
+
return result;
|
|
144
211
|
}
|
|
145
212
|
catch (err) {
|
|
146
213
|
const raw = err instanceof Error ? err.message : String(err);
|
|
147
214
|
let msg = raw;
|
|
148
|
-
if (/HTTP
|
|
215
|
+
if (/HTTP 401/.test(raw)) {
|
|
149
216
|
msg = "API key is invalid or expired. Check the SIGNAL4_API_KEY in your MCP server config.";
|
|
150
217
|
}
|
|
218
|
+
else if (/HTTP 403/.test(raw)) {
|
|
219
|
+
const d = raw.replace(/^[\s\S]*?HTTP 403:?\s*/, "").trim();
|
|
220
|
+
msg = d ? `Forbidden: ${d.slice(0, 200)}` : "Forbidden: this key lacks access to that tool or collection.";
|
|
221
|
+
}
|
|
222
|
+
else if (/HTTP 400/.test(raw)) {
|
|
223
|
+
const d = raw.replace(/^[\s\S]*?HTTP 400:?\s*/, "").trim();
|
|
224
|
+
let detail = d;
|
|
225
|
+
try {
|
|
226
|
+
const j = JSON.parse(d);
|
|
227
|
+
if (typeof j.detail === "string")
|
|
228
|
+
detail = j.detail;
|
|
229
|
+
}
|
|
230
|
+
catch { /* raw */ }
|
|
231
|
+
msg = detail.slice(0, 300);
|
|
232
|
+
}
|
|
151
233
|
else if (/HTTP 404/.test(raw)) {
|
|
152
234
|
msg = "The requested resource was not found. Check that the ID came from a previous search or listing result.";
|
|
153
235
|
}
|
|
154
236
|
else if (/HTTP 422/.test(raw)) {
|
|
155
|
-
msg = raw
|
|
237
|
+
msg = translate422(raw);
|
|
156
238
|
}
|
|
157
239
|
else if (raw.includes("expand_query must be called before")) {
|
|
158
240
|
msg = "Analysis pipeline error — try workflow='simple_rag' or simplify your query.";
|
package/dist/server_core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server_core.js","sourceRoot":"","sources":["../src/server_core.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"server_core.js","sourceRoot":"","sources":["../src/server_core.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,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AAC;AAChB,CAAC"}
|
package/dist/speed.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** How long a call should take — one source for tool descriptions, CLI help, the
|
|
2
|
+
* progress notice a slow call sends before it starts, and the "took Ns" footer.
|
|
3
|
+
*
|
|
4
|
+
* Tiers, by the typical time (geometric mean of the range):
|
|
5
|
+
* instant < 0.5s fast 0.5–2.5s slow > 2.5s
|
|
6
|
+
*
|
|
7
|
+
* Every number is measured, not guessed: the 100-plan replay against the live API
|
|
8
|
+
* (2026-10-15/16, ~/logs/search_eval/replay-2026-10-15.jsonl — per-tool p50/p90) and the
|
|
9
|
+
* VPS before/after runs for the counting engine (signal4#292, #296). Semantic tools pay
|
|
10
|
+
* ~1s for the query embedding before they scan; a scan costs roughly 0.15–0.35s per
|
|
11
|
+
* month of window over the whole corpus. Update the table when a tool gets faster. */
|
|
12
|
+
export type Tier = "instant" | "fast" | "slow";
|
|
13
|
+
export interface Estimate {
|
|
14
|
+
tier: Tier;
|
|
15
|
+
/** seconds */
|
|
16
|
+
lo: number;
|
|
17
|
+
hi: number;
|
|
18
|
+
/** what drives the time, for the progress notice (e.g. "semantic scan over 12 months") */
|
|
19
|
+
why?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Responses that took longer than this say how long. */
|
|
22
|
+
export declare const REPORT_ELAPSED_OVER_S = 2.5;
|
|
23
|
+
export declare function tierOf(lo: number, hi: number): Tier;
|
|
24
|
+
/** Window length in months from days / start_date / end_date (YYYY, YYYY-MM, YYYY-MM-DD). */
|
|
25
|
+
export declare function windowMonths(params: Record<string, unknown>, defaultDays?: number): number;
|
|
26
|
+
/** The estimate for one call. Unknown tools are "fast" with a wide range. */
|
|
27
|
+
export declare function estimate(tool: string, params?: Record<string, unknown>): Estimate;
|
|
28
|
+
/** "instant" · "fast ~1–2s" · "slow ~3–8s". */
|
|
29
|
+
export declare function label(e: Estimate): string;
|
|
30
|
+
/** The speed line a tool description starts with, e.g. "[slow ~15–45s · paid LLM]".
|
|
31
|
+
* Tools whose time depends on the window carry a short scale ("…; 12 months ~3–6s"). */
|
|
32
|
+
export declare function descriptionTag(tool: string, paid?: boolean): string;
|
|
33
|
+
/** Replace the speed/price bracket a backend description starts with by ours,
|
|
34
|
+
* keeping the paid marker. */
|
|
35
|
+
export declare function decorateDescription(tool: string, description: string): string;
|
|
36
|
+
/** The notice a slow call sends before it starts (MCP progress, CLI stderr). */
|
|
37
|
+
export declare function startNotice(e: Estimate): string;
|
|
38
|
+
/** Footer for a response that took longer than REPORT_ELAPSED_OVER_S. */
|
|
39
|
+
export declare function elapsedFooter(ms: number): string;
|
|
40
|
+
//# sourceMappingURL=speed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speed.d.ts","sourceRoot":"","sources":["../src/speed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;sFAUsF;AAEtF,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAE/C,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,IAAI,CAAC;IACX,cAAc;IACd,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,0FAA0F;IAC1F,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAID,yDAAyD;AACzD,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAIzC,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAKnD;AA8CD,6FAA6F;AAC7F,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,SAAK,GAAG,MAAM,CAiBtF;AAoBD,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,QAAQ,CA4CrF;AAQD,+CAA+C;AAC/C,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAGzC;AAED;wFACwF;AACxF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,MAAM,CAWjE;AAED;8BAC8B;AAC9B,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAK7E;AAED,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAE/C;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|
package/dist/speed.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/** How long a call should take — one source for tool descriptions, CLI help, the
|
|
2
|
+
* progress notice a slow call sends before it starts, and the "took Ns" footer.
|
|
3
|
+
*
|
|
4
|
+
* Tiers, by the typical time (geometric mean of the range):
|
|
5
|
+
* instant < 0.5s fast 0.5–2.5s slow > 2.5s
|
|
6
|
+
*
|
|
7
|
+
* Every number is measured, not guessed: the 100-plan replay against the live API
|
|
8
|
+
* (2026-10-15/16, ~/logs/search_eval/replay-2026-10-15.jsonl — per-tool p50/p90) and the
|
|
9
|
+
* VPS before/after runs for the counting engine (signal4#292, #296). Semantic tools pay
|
|
10
|
+
* ~1s for the query embedding before they scan; a scan costs roughly 0.15–0.35s per
|
|
11
|
+
* month of window over the whole corpus. Update the table when a tool gets faster. */
|
|
12
|
+
const INSTANT_MAX = 0.5;
|
|
13
|
+
const FAST_MAX = 2.5;
|
|
14
|
+
/** Responses that took longer than this say how long. */
|
|
15
|
+
export const REPORT_ELAPSED_OVER_S = 2.5;
|
|
16
|
+
const EMBED_S = 1.0;
|
|
17
|
+
export function tierOf(lo, hi) {
|
|
18
|
+
const typical = Math.sqrt(Math.max(lo, 0.01) * Math.max(hi, 0.01));
|
|
19
|
+
if (typical < INSTANT_MAX)
|
|
20
|
+
return "instant";
|
|
21
|
+
if (typical <= FAST_MAX)
|
|
22
|
+
return "fast";
|
|
23
|
+
return "slow";
|
|
24
|
+
}
|
|
25
|
+
function est(lo, hi, why) {
|
|
26
|
+
return { tier: tierOf(lo, hi), lo, hi, why };
|
|
27
|
+
}
|
|
28
|
+
/** Fixed-cost tools: [lo, hi] seconds from the replay (p50-ish, p90). */
|
|
29
|
+
const BASE = {
|
|
30
|
+
get_segment: [0.1, 0.2],
|
|
31
|
+
get_segment_sentences: [0.1, 0.3],
|
|
32
|
+
get_thread: [0.1, 0.4],
|
|
33
|
+
get_claim: [0.1, 0.4],
|
|
34
|
+
list_collections: [0.1, 0.3],
|
|
35
|
+
manage_bookmarks: [0.1, 0.4],
|
|
36
|
+
find_speakers: [0.2, 0.8],
|
|
37
|
+
get_platform_stats: [0.2, 1],
|
|
38
|
+
get_collection_stats: [0.2, 1],
|
|
39
|
+
get_project_stats: [0.2, 1],
|
|
40
|
+
get_speaker: [0.2, 2.5],
|
|
41
|
+
claim_graph: [0.3, 1.6],
|
|
42
|
+
get_channel: [0.3, 1.2],
|
|
43
|
+
get_episode: [0.5, 2],
|
|
44
|
+
channel_dossier: [0.5, 1.6],
|
|
45
|
+
compare_channels: [0.7, 1.5],
|
|
46
|
+
get_top_channels: [0.5, 2.5],
|
|
47
|
+
analyze_claims: [0.8, 2.3],
|
|
48
|
+
contradict_claims: [0.8, 4.4],
|
|
49
|
+
compare_claims: [0.8, 4],
|
|
50
|
+
check_channel_contradictions: [0.8, 4],
|
|
51
|
+
find_entities: [0.8, 3.2],
|
|
52
|
+
trend_claims: [1, 3.5],
|
|
53
|
+
get_top_speakers: [1.5, 3.5],
|
|
54
|
+
get_speaker_network: [1, 5],
|
|
55
|
+
get_ad_analytics: [0.5, 3],
|
|
56
|
+
entity_claims: [1.5, 10],
|
|
57
|
+
top_claims: [2, 8],
|
|
58
|
+
get_topics: [3, 19],
|
|
59
|
+
// Paid LLM pipelines (their own descriptions carry these ranges).
|
|
60
|
+
get_briefing: [2, 10],
|
|
61
|
+
analyze_topic: [15, 45],
|
|
62
|
+
compare_speakers: [15, 45],
|
|
63
|
+
build_dossier: [15, 45],
|
|
64
|
+
check_contradictions: [15, 45],
|
|
65
|
+
compare_frames: [30, 60],
|
|
66
|
+
};
|
|
67
|
+
/** Window length in months from days / start_date / end_date (YYYY, YYYY-MM, YYYY-MM-DD). */
|
|
68
|
+
export function windowMonths(params, defaultDays = 30) {
|
|
69
|
+
const today = Date.now();
|
|
70
|
+
const parse = (v, edge) => {
|
|
71
|
+
if (typeof v !== "string" || !v)
|
|
72
|
+
return undefined;
|
|
73
|
+
const m = /^(\d{4})(?:-(\d{2}))?(?:-(\d{2}))?$/.exec(v.trim());
|
|
74
|
+
if (!m)
|
|
75
|
+
return undefined;
|
|
76
|
+
const y = Number(m[1]);
|
|
77
|
+
const mo = m[2] ? Number(m[2]) - 1 : edge === "start" ? 0 : 11;
|
|
78
|
+
const d = m[3] ? Number(m[3]) : edge === "start" ? 1 : 28;
|
|
79
|
+
return Date.UTC(y, mo, d);
|
|
80
|
+
};
|
|
81
|
+
const start = parse(params.start_date, "start");
|
|
82
|
+
const end = parse(params.end_date, "end") ?? today;
|
|
83
|
+
const days = start != null
|
|
84
|
+
? (end - start) / 86400000
|
|
85
|
+
: Number(params.days ?? params.baseline_days ?? defaultDays) || defaultDays;
|
|
86
|
+
return Math.max(days / 30.4, 0.25);
|
|
87
|
+
}
|
|
88
|
+
/** Whole-corpus semantic scan cost for a window: ~0.2–0.35s per month up to two years,
|
|
89
|
+
* thin before that. Measured on the VPS: 1 month 0.2–0.7s, 12 months 2.4–3.6s, all time 5–8s. */
|
|
90
|
+
function scanCost(months) {
|
|
91
|
+
const recent = Math.min(months, 24);
|
|
92
|
+
const older = Math.max(months - 24, 0);
|
|
93
|
+
const lo = 0.2 + 0.15 * recent;
|
|
94
|
+
// All time measured 4.7s warm, 7–8.5s just after cache churn (signal4#238).
|
|
95
|
+
const hi = Math.min(0.8 + 0.35 * recent + 0.02 * older, 9);
|
|
96
|
+
return [lo, hi];
|
|
97
|
+
}
|
|
98
|
+
function monthsLabel(months) {
|
|
99
|
+
if (months >= 120)
|
|
100
|
+
return "all time";
|
|
101
|
+
if (months >= 23)
|
|
102
|
+
return `${Math.round(months / 12)} years`;
|
|
103
|
+
if (months >= 1.5)
|
|
104
|
+
return `${Math.round(months)} months`;
|
|
105
|
+
return `${Math.max(1, Math.round(months * 30.4))} days`;
|
|
106
|
+
}
|
|
107
|
+
/** The estimate for one call. Unknown tools are "fast" with a wide range. */
|
|
108
|
+
export function estimate(tool, params = {}) {
|
|
109
|
+
const speaker = params.speaker ?? params.speaker_name ?? params.speaker_id;
|
|
110
|
+
const keyword = params.mode === "keyword" || typeof params.keyword === "string";
|
|
111
|
+
switch (tool) {
|
|
112
|
+
case "search_quotes": {
|
|
113
|
+
if (params.full_history)
|
|
114
|
+
return est(2, 15, "exact scan of a speaker's whole history");
|
|
115
|
+
const m = windowMonths(params);
|
|
116
|
+
if (keyword) {
|
|
117
|
+
return est(0.3, speaker ? 4 : 1.5, `keyword search, newest first, ${monthsLabel(m)}`);
|
|
118
|
+
}
|
|
119
|
+
if (!params.topic)
|
|
120
|
+
return est(0.2, 2, "listing by speaker or channel");
|
|
121
|
+
const [lo, hi] = scanCost(m);
|
|
122
|
+
return est(EMBED_S + lo, EMBED_S + hi + 0.5 + (speaker ? 4 : 0), `semantic search over ${monthsLabel(m)}${speaker ? " for one speaker" : ""}`);
|
|
123
|
+
}
|
|
124
|
+
case "count_mentions": {
|
|
125
|
+
const m = windowMonths(params);
|
|
126
|
+
if (keyword) {
|
|
127
|
+
const hi = m <= 3 ? 2 : m <= 12 ? 6 : 15;
|
|
128
|
+
return est(0.3, hi + (speaker ? 6 : 0), `exact keyword count over ${monthsLabel(m)} (very common words take longest)`);
|
|
129
|
+
}
|
|
130
|
+
if (!params.topic && !params.topics)
|
|
131
|
+
return est(0.3, m <= 3 ? 2 : 8, `count of everything in scope over ${monthsLabel(m)}`);
|
|
132
|
+
const [lo, hi] = scanCost(m);
|
|
133
|
+
return est(EMBED_S + lo, EMBED_S + hi + (speaker ? 10 : 0), `semantic count over ${monthsLabel(m)}${speaker ? " for one speaker" : ""}`);
|
|
134
|
+
}
|
|
135
|
+
case "get_timeline":
|
|
136
|
+
case "detect_trend": {
|
|
137
|
+
const m = windowMonths(params, tool === "detect_trend" ? Number(params.baseline_days ?? 30) || 30 : 30);
|
|
138
|
+
const [lo, hi] = scanCost(m);
|
|
139
|
+
return est(EMBED_S + lo, EMBED_S + hi + (speaker ? 10 : 0), `semantic count over ${monthsLabel(m)}`);
|
|
140
|
+
}
|
|
141
|
+
case "search_claims": {
|
|
142
|
+
if (params.entity)
|
|
143
|
+
return est(5, 25, "claims search filtered by entity");
|
|
144
|
+
if (keyword)
|
|
145
|
+
return est(0.3, 2, "claims keyword search");
|
|
146
|
+
return est(1.5, 10, "semantic claims search");
|
|
147
|
+
}
|
|
148
|
+
default: {
|
|
149
|
+
const b = BASE[tool];
|
|
150
|
+
return b ? est(b[0], b[1]) : est(0.5, 5);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** 0.1–0.9 to one decimal, 1–10 to the half second, then whole seconds. */
|
|
155
|
+
function secs(n) {
|
|
156
|
+
if (n < 1)
|
|
157
|
+
return Math.max(n, 0.1).toFixed(1);
|
|
158
|
+
return n < 10 ? String(Math.round(n * 2) / 2) : String(Math.round(n));
|
|
159
|
+
}
|
|
160
|
+
/** "instant" · "fast ~1–2s" · "slow ~3–8s". */
|
|
161
|
+
export function label(e) {
|
|
162
|
+
if (e.tier === "instant")
|
|
163
|
+
return "instant";
|
|
164
|
+
return `${e.tier} ~${secs(e.lo)}–${secs(e.hi)}s`;
|
|
165
|
+
}
|
|
166
|
+
/** The speed line a tool description starts with, e.g. "[slow ~15–45s · paid LLM]".
|
|
167
|
+
* Tools whose time depends on the window carry a short scale ("…; 12 months ~3–6s"). */
|
|
168
|
+
export function descriptionTag(tool, paid = false) {
|
|
169
|
+
const windowed = ["search_quotes", "count_mentions", "get_timeline", "detect_trend"].includes(tool);
|
|
170
|
+
// The usual call: a topic, default (30-day) window, semantic.
|
|
171
|
+
const base = estimate(tool, windowed ? { topic: "x" } : {});
|
|
172
|
+
let scale = "";
|
|
173
|
+
if (windowed) {
|
|
174
|
+
const year = estimate(tool, { days: 365, topic: "x" });
|
|
175
|
+
const all = estimate(tool, { start_date: "2010", topic: "x" });
|
|
176
|
+
scale = `; 12 months ${label(year).replace(/^\w+ /, "")}, all time ${label(all).replace(/^\w+ /, "")}`;
|
|
177
|
+
}
|
|
178
|
+
return `[${label(base)}${scale}${paid ? " · paid LLM" : ""}]`;
|
|
179
|
+
}
|
|
180
|
+
/** Replace the speed/price bracket a backend description starts with by ours,
|
|
181
|
+
* keeping the paid marker. */
|
|
182
|
+
export function decorateDescription(tool, description) {
|
|
183
|
+
const m = /^\[([^\]]*)\]\s*/.exec(description);
|
|
184
|
+
const paid = m ? /paid/i.test(m[1]) : false;
|
|
185
|
+
const rest = m ? description.slice(m[0].length) : description;
|
|
186
|
+
return `${descriptionTag(tool, paid)} ${rest}`;
|
|
187
|
+
}
|
|
188
|
+
/** The notice a slow call sends before it starts (MCP progress, CLI stderr). */
|
|
189
|
+
export function startNotice(e) {
|
|
190
|
+
return `Estimated ${secs(e.lo)}–${secs(e.hi)}s${e.why ? `: ${e.why}` : ""}.`;
|
|
191
|
+
}
|
|
192
|
+
/** Footer for a response that took longer than REPORT_ELAPSED_OVER_S. */
|
|
193
|
+
export function elapsedFooter(ms) {
|
|
194
|
+
return ms / 1000 > REPORT_ELAPSED_OVER_S ? `\n_Took ${(ms / 1000).toFixed(1)}s._` : "";
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=speed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speed.js","sourceRoot":"","sources":["../src/speed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;sFAUsF;AAatF,MAAM,WA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AY,EAAE,WAAmB;IACnE,MAAM,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5C,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;IAC9D,OAAO,GAAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;AACjD,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,WAAW,CAAC,CAAW;IACrC,OAAO,aAAa,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;AAC/E,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,aAAa,CAAC,EAAU;IACtC,OAAO,EAAE,GAAG,IAAI,GAAG,qBAAqB,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Which front end is rendering: next-step hints use CLI or MCP call syntax. */
|
|
2
|
+
export type Surface = "cli" | "mcp";
|
|
3
|
+
export declare function setSurface(s: Surface): void;
|
|
4
|
+
export declare function getSurface(): Surface;
|
|
5
|
+
/** Rewrite an MCP-style call hint (`get_segment seg:42`, `offset:20`) to CLI syntax when running as the CLI. */
|
|
6
|
+
export declare function hint(mcp: string): string;
|
|
7
|
+
//# sourceMappingURL=surface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAEhF,MAAM,MAAM,OAAO,GAAG,KAAK,GAAG,KAAK,CAAC;AAIpC,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,CAAiB;AAC7D,wBAAgB,UAAU,IAAI,OAAO,CAAoB;AAEzD,gHAAgH;AAChH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAUxC"}
|
package/dist/surface.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Which front end is rendering: next-step hints use CLI or MCP call syntax. */
|
|
2
|
+
let current = "mcp";
|
|
3
|
+
export function setSurface(s) { current = s; }
|
|
4
|
+
export function getSurface() { return current; }
|
|
5
|
+
/** Rewrite an MCP-style call hint (`get_segment seg:42`, `offset:20`) to CLI syntax when running as the CLI. */
|
|
6
|
+
export function hint(mcp) {
|
|
7
|
+
if (current !== "cli")
|
|
8
|
+
return mcp;
|
|
9
|
+
return mcp
|
|
10
|
+
.replace(/get_segment seg:(\d+)/g, "s4 segment $1")
|
|
11
|
+
.replace(/get_speaker speaker_id:(\d+)/g, "s4 speaker $1")
|
|
12
|
+
.replace(/get_claim claim:(\d+)( include_observations:true)?/g, (_m, id, o) => `s4 claim ${id}${o ? " --observations" : ""}`)
|
|
13
|
+
.replace(/get_thread segment_id:(\d+)( max_chars:0)?/g, "s4 thread $1")
|
|
14
|
+
.replace(/get_episode content_id:(\S+?)( include_transcript:true)?(?=$|[\s·\]])/g, (_m, id, t) => `s4 episode ${id}${t ? " --transcript" : ""}`)
|
|
15
|
+
.replace(/search_quotes topic:("[^"]*") start_date:(\S+)/g, "s4 search $1 --since $2")
|
|
16
|
+
.replace(/\boffset:(\d+)/g, "--offset $1");
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=surface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surface.js","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAIhF,IAAI,OAAO,GAAY,KAAK,CAAC;AAE7B,MAAM,UAAU,UAAU,CAAC,CAAU,IAAU,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;AAC7D,MAAM,UAAU,UAAU,KAAc,OAAO,OAAO,CAAC,CAAC,CAAC;AAEzD,gHAAgH;AAChH,MAAM,UAAU,IAAI,CAAC,GAAW;IAC9B,IAAI,OAAO,KAAK,KAAK;QAAE,OAAO,GAAG,CAAC;IAClC,OAAO,GAAG;SACP,OAAO,CAAC,wBAAwB,EAAE,eAAe,CAAC;SAClD,OAAO,CAAC,+BAA+B,EAAE,eAAe,CAAC;SACzD,OAAO,CAAC,qDAAqD,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;SAC5H,OAAO,CAAC,6CAA6C,EAAE,cAAc,CAAC;SACtE,OAAO,CAAC,wEAAwE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;SAC/I,OAAO,CAAC,iDAAiD,EAAE,yBAAyB,CAAC;SACrF,OAAO,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAC/C,CAAC"}
|