@lincoln504/pi-research 1.3.12 → 1.4.1
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 +2 -2
- package/dist/cli.mjs +5495 -4645
- package/dist/prompts/research-tool-usage.md +1 -1
- package/dist/prompts/researcher.md +1 -0
- package/dist/prompts/system-lead-router.md +122 -0
- package/dist/prompts/system-lead-synthesizer.md +46 -0
- package/dist/thread-worker.mjs +94 -19
- package/docs/ARCHITECTURE.md +18 -10
- package/docs/CHANGELOG.md +149 -0
- package/docs/CONFIGURATION.md +106 -7
- package/package.json +2 -2
- package/scripts/build.cjs +8 -1
- package/skills/pi-research/SKILL.md +1 -1
- package/src/cli.ts +5 -1
- package/src/config.ts +12 -8
- package/src/constants.ts +1 -1
- package/src/core/interfaces/observer-interfaces.ts +3 -3
- package/src/core/interfaces/orchestration-interfaces.ts +2 -0
- package/src/core/interfaces/planning-interfaces.ts +7 -1
- package/src/core/interfaces/scheduler-interfaces.ts +18 -2
- package/src/core/llm/agentic-repair.ts +7 -2
- package/src/core/llm/inject-date.ts +4 -1
- package/src/core/llm/llm-utils.ts +7 -0
- package/src/core/planning-service.ts +719 -91
- package/src/core/planning-utils.ts +21 -5
- package/src/core/service-initialization.ts +19 -3
- package/src/healthcheck/index.ts +11 -2
- package/src/index.ts +4 -3
- package/src/infrastructure/browser/browser-client.ts +68 -34
- package/src/infrastructure/browser/browser-task-scheduler.ts +220 -34
- package/src/infrastructure/browser/config.ts +41 -1
- package/src/infrastructure/browser/priority-task-queue.ts +55 -1
- package/src/infrastructure/browser/scheduler-factory.ts +12 -1
- package/src/infrastructure/browser/task-execution-service.ts +5 -5
- package/src/infrastructure/browser/thread-worker-browser.ts +32 -2
- package/src/infrastructure/browser/thread-worker-messaging.ts +38 -6
- package/src/infrastructure/browser/thread-worker.mjs +94 -19
- package/src/infrastructure/browser/thread-worker.ts +2 -2
- package/src/infrastructure/browser/worker-pool-manager.ts +127 -12
- package/src/infrastructure/embedding/embedding-client.ts +14 -4
- package/src/infrastructure/embedding/embedding-factory.ts +83 -15
- package/src/infrastructure/file-lock-service.ts +214 -19
- package/src/infrastructure/knowledge-store-service.ts +14 -0
- package/src/infrastructure/research-run-semaphore.ts +1 -1
- package/src/infrastructure/service-initialization.ts +7 -0
- package/src/knowledge/embedder-init.ts +43 -17
- package/src/logger.ts +11 -0
- package/src/orchestration/deep-research-orchestrator.ts +141 -87
- package/src/orchestration/quick-research-orchestrator.ts +11 -2
- package/src/orchestration/research-orchestration-service.ts +8 -0
- package/src/orchestration/research-synthesis-service.ts +53 -1
- package/src/orchestration/researcher-executor.ts +53 -2
- package/src/orchestration/researcher.ts +15 -2
- package/src/prompts/research-tool-usage.md +1 -1
- package/src/prompts/researcher.md +1 -0
- package/src/prompts/system-lead-router.md +122 -0
- package/src/prompts/system-lead-synthesizer.md +46 -0
- package/src/tools/research-knowledge-search.ts +11 -3
- package/src/tools/scrape.ts +6 -0
- package/src/tools/search.ts +7 -0
- package/src/tools/security.ts +27 -9
- package/src/tools/stackexchange.ts +13 -7
- package/src/tools/youtube-transcript.ts +26 -12
- package/src/utils/cancellation.ts +36 -0
- package/src/utils/coverage-digest.ts +204 -0
- package/src/utils/llm-usage.ts +33 -6
- package/src/utils/metrics-summary.ts +20 -4
- package/src/utils/metrics.ts +27 -1
- package/src/web-research/browser-search.ts +93 -20
- package/dist/prompts/system-lead-evaluator.md +0 -118
- package/src/prompts/system-lead-evaluator.md +0 -118
|
@@ -34,6 +34,10 @@ export interface JsonRepairOptions {
|
|
|
34
34
|
maxTokens?: number;
|
|
35
35
|
/** Thinking level for the repair pass (default 'off' — repair emits JSON, not reasoning). */
|
|
36
36
|
thinkingLevel?: ModelThinkingLevel;
|
|
37
|
+
/** Research session id, forwarded to the provider as its prompt-cache / session-affinity
|
|
38
|
+
* key (see llm-utils.buildSafeOptions). Keeps the repair pass on the same upstream
|
|
39
|
+
* replica as the call it is repairing. */
|
|
40
|
+
sessionId?: string;
|
|
37
41
|
/** Usage sink invoked once per billed LLM attempt with the raw usage object from
|
|
38
42
|
* the response. Lets callers attribute the repair pass's tokens/cost to the run
|
|
39
43
|
* (metrics + observer) exactly as they do for the primary call. Every attempt that
|
|
@@ -70,7 +74,7 @@ export async function repairJsonWithLlm<T = any>(
|
|
|
70
74
|
auth: { apiKey: string; headers?: Record<string, string | null> },
|
|
71
75
|
options: JsonRepairOptions
|
|
72
76
|
): Promise<T | null> {
|
|
73
|
-
const { model, context, schema, serviceName = 'RepairService', signal, maxTokens = 16384, thinkingLevel = 'off' } = options;
|
|
77
|
+
const { model, context, schema, serviceName = 'RepairService', signal, maxTokens = 16384, thinkingLevel = 'off', sessionId } = options;
|
|
74
78
|
|
|
75
79
|
logger.warn(`[${serviceName}] JSON parse failed; attempting agentic salvage`);
|
|
76
80
|
|
|
@@ -118,7 +122,8 @@ Return ONLY the valid JSON object. No prose before or after.`;
|
|
|
118
122
|
],
|
|
119
123
|
}, buildSafeOptions(model, {
|
|
120
124
|
...auth,
|
|
121
|
-
signal
|
|
125
|
+
signal,
|
|
126
|
+
...(sessionId ? { sessionId } : {}),
|
|
122
127
|
}, maxTokens, thinkingLevel)),
|
|
123
128
|
llmTimeout, `agentic-repair-${serviceName}`,
|
|
124
129
|
);
|
|
@@ -35,7 +35,10 @@ function getCurrentDateString(): string {
|
|
|
35
35
|
* training-cutoff defaults). The full date follows for precision. Applies to
|
|
36
36
|
* coordinator, researcher, and evaluator across all modes.
|
|
37
37
|
*/
|
|
38
|
-
export function injectCurrentDate(
|
|
38
|
+
export function injectCurrentDate(
|
|
39
|
+
prompt: string,
|
|
40
|
+
_agentType: 'coordinator' | 'researcher' | 'router' | 'synthesizer',
|
|
41
|
+
): string {
|
|
39
42
|
const monthYear = getCurrentMonthYearString();
|
|
40
43
|
const fullDate = getCurrentDateString();
|
|
41
44
|
// Derive the stale-year examples from the current year so the guidance stays correct in any
|
|
@@ -22,6 +22,13 @@ import { logger } from '../../logger.ts';
|
|
|
22
22
|
* thinking block only consumes the output-token budget (often truncating before the
|
|
23
23
|
* text block is emitted) for at most a marginal quality gain that does not justify the cost.
|
|
24
24
|
*
|
|
25
|
+
* Callers should also pass the research `sessionId` in `options`. pi-ai forwards it as the
|
|
26
|
+
* provider's prompt-cache / session-affinity key — OpenAI's `prompt_cache_key`, OpenRouter's
|
|
27
|
+
* `x-session-id` — which keeps a run's calls on the replica that warmed their cache. Without
|
|
28
|
+
* it OpenRouter falls back to hashing the first system and user messages, which every round
|
|
29
|
+
* of a research run mutates, so it re-routes and re-warms. Providers that do not implement
|
|
30
|
+
* session affinity ignore the field, so passing it is unconditionally safe.
|
|
31
|
+
*
|
|
25
32
|
* @param model - The model being called
|
|
26
33
|
* @param options - Caller-provided options (an explicit `reasoning` here wins)
|
|
27
34
|
* @param defaultCap - Default maxTokens cap (clamped to model.maxTokens)
|