@lincoln504/pi-research 0.1.12 → 1.0.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/LICENSE +1 -1
- package/README.md +64 -115
- package/dist/cli.mjs +23211 -0
- package/dist/prompts/research-knowledge-relevance-triage.md +35 -0
- package/dist/prompts/research-knowledge-search-extractor.md +41 -0
- package/dist/prompts/research-tool-usage.md +92 -0
- package/dist/prompts/researcher.md +89 -0
- package/dist/prompts/system-coordinator.md +75 -0
- package/dist/prompts/system-lead-evaluator.md +118 -0
- package/dist/thread-worker.mjs +2611 -0
- package/dist/webgpu-probe.mjs +80 -0
- package/docs/AGENT-SKILL.md +102 -0
- package/docs/ARCHITECTURE.md +306 -80
- package/docs/CONFIGURATION.md +249 -0
- package/docs/KNOWLEDGE-STORE.md +213 -0
- package/docs/PI-EXTENSION.md +91 -0
- package/docs/SDK.md +113 -0
- package/docs/THIRD-PARTY-NOTICES.md +64 -0
- package/package.json +102 -36
- package/scripts/build.cjs +140 -0
- package/scripts/cleanup.cjs +149 -0
- package/scripts/prepare.cjs +28 -0
- package/scripts/setup.cjs +134 -0
- package/skills/pi-research/README.md +90 -0
- package/skills/pi-research/SKILL.md +102 -0
- package/skills/pi-research/references/configuration.md +77 -0
- package/skills/pi-research/scripts/run.mjs +237 -0
- package/src/cleanup/research-cleanup.ts +140 -0
- package/src/cli.ts +1044 -0
- package/src/config.ts +1036 -147
- package/src/constants.ts +115 -84
- package/src/core/health-check-service.ts +265 -0
- package/src/core/interfaces/health-check-interfaces.ts +50 -0
- package/src/core/interfaces/knowledge-interfaces.ts +190 -0
- package/src/core/interfaces/observer-interfaces.ts +67 -0
- package/src/core/interfaces/orchestration-interfaces.ts +86 -0
- package/src/core/interfaces/planning-interfaces.ts +100 -0
- package/src/core/interfaces/process-interfaces.ts +37 -0
- package/src/core/interfaces/research-plan-types.ts +52 -0
- package/src/core/interfaces/scheduler-interfaces.ts +91 -0
- package/src/core/interfaces/service-names.ts +39 -0
- package/src/core/interfaces/state-manager-interfaces.ts +29 -0
- package/src/core/interfaces/steering-interfaces.ts +31 -0
- package/src/core/llm/agentic-repair.ts +169 -0
- package/src/core/llm/inject-date.ts +52 -0
- package/src/core/llm/llm-timeout.ts +64 -0
- package/src/core/llm/llm-utils.ts +86 -0
- package/src/core/llm/model-registry-factory.ts +287 -0
- package/src/core/llm/pi-ai-completion.ts +29 -0
- package/src/core/llm/prompts.ts +50 -0
- package/src/core/llm/research-model-resolver.ts +91 -0
- package/src/core/planning-constants.ts +13 -0
- package/src/core/planning-service.ts +649 -0
- package/src/core/planning-utils.ts +299 -0
- package/src/core/scheduler-factory.ts +48 -0
- package/src/core/scheduler-service.ts +123 -0
- package/src/core/service-initialization.ts +194 -0
- package/src/core/service-interfaces.ts +48 -0
- package/src/core/service-registry.ts +659 -0
- package/src/healthcheck/index.ts +271 -265
- package/src/healthcheck/registry.ts +130 -0
- package/src/index.ts +639 -50
- package/src/infrastructure/browser/browser-cleanup.ts +309 -0
- package/src/infrastructure/browser/browser-client.ts +199 -0
- package/src/infrastructure/browser/browser-error-utils.ts +160 -0
- package/src/infrastructure/browser/browser-lifecycle.ts +120 -0
- package/src/infrastructure/browser/browser-server.ts +174 -0
- package/src/infrastructure/browser/browser-task-scheduler.ts +461 -0
- package/src/infrastructure/browser/cleanup-utils.ts +155 -0
- package/src/infrastructure/browser/client-agent.ts +31 -0
- package/src/infrastructure/browser/config.ts +288 -0
- package/src/infrastructure/browser/ensure-browser.ts +205 -0
- package/src/infrastructure/browser/index.ts +37 -0
- package/src/infrastructure/browser/priority-task-queue.ts +226 -0
- package/src/infrastructure/browser/scheduler-factory.ts +354 -0
- package/src/infrastructure/browser/task-execution-service.ts +209 -0
- package/src/infrastructure/browser/thread-worker-browser.ts +282 -0
- package/src/infrastructure/browser/thread-worker-lifecycle.ts +323 -0
- package/src/infrastructure/browser/thread-worker-messaging.ts +662 -0
- package/src/infrastructure/browser/thread-worker-types.ts +25 -0
- package/src/infrastructure/browser/thread-worker.mjs +2611 -0
- package/src/infrastructure/browser/thread-worker.ts +168 -0
- package/src/infrastructure/browser/worker-pool-manager.ts +449 -0
- package/src/infrastructure/embedding/embedding-client.ts +205 -0
- package/src/infrastructure/embedding/embedding-factory.ts +324 -0
- package/src/infrastructure/embedding/embedding-server.ts +535 -0
- package/src/infrastructure/file-lock-service.ts +592 -0
- package/src/infrastructure/gpu-resource-service.ts +191 -0
- package/src/infrastructure/knowledge-store-service.ts +475 -0
- package/src/infrastructure/metrics-service.ts +129 -0
- package/src/infrastructure/process-lifecycle-service.ts +253 -0
- package/src/infrastructure/scheduler-factory-service.ts +58 -0
- package/src/infrastructure/service-initialization.ts +292 -0
- package/src/infrastructure/state/state-backup-manager.ts +290 -0
- package/src/infrastructure/state/state-browser-api.ts +62 -0
- package/src/infrastructure/state/state-browser-manager.ts +70 -0
- package/src/infrastructure/state/state-manager-service.ts +264 -0
- package/src/infrastructure/state/state-manager.ts +547 -0
- package/src/infrastructure/state/state-metrics.ts +92 -0
- package/src/infrastructure/state/state-migration.ts +103 -0
- package/src/infrastructure/state/state-path-configuration.ts +119 -0
- package/src/infrastructure/state/state-session-api.ts +94 -0
- package/src/infrastructure/state/state-session-manager.ts +127 -0
- package/src/infrastructure/state/state-validator.ts +93 -0
- package/src/infrastructure/types/state-types.ts +85 -0
- package/src/knowledge/chunker.ts +157 -0
- package/src/knowledge/embedder-init.ts +413 -0
- package/src/knowledge/embedder-utils.ts +296 -0
- package/src/knowledge/embedder.ts +592 -0
- package/src/knowledge/index.ts +126 -0
- package/src/knowledge/lancedb-loader.ts +35 -0
- package/src/knowledge/migration.ts +17 -0
- package/src/knowledge/model-config.ts +132 -0
- package/src/knowledge/onnx-env.ts +48 -0
- package/src/knowledge/store-operations.ts +291 -0
- package/src/knowledge/store-schema.ts +79 -0
- package/src/knowledge/store.ts +1251 -0
- package/src/knowledge/transformers-loader.ts +31 -0
- package/src/knowledge/webgpu-probe.mjs +80 -0
- package/src/knowledge/webgpu-viability.ts +255 -0
- package/src/knowledge/writer-queue.ts +252 -0
- package/src/logger.ts +316 -122
- package/src/observers/research-observer-impl.ts +459 -0
- package/src/orchestration/deep-research-orchestrator.ts +524 -773
- package/src/orchestration/deep-research-types.ts +47 -35
- package/src/orchestration/headless-observer.ts +114 -0
- package/src/orchestration/orchestration-types.ts +33 -0
- package/src/orchestration/quick-research-orchestrator.ts +463 -0
- package/src/orchestration/research-orchestration-service.ts +549 -0
- package/src/orchestration/research-session-service.ts +178 -0
- package/src/orchestration/research-synthesis-service.ts +348 -0
- package/src/orchestration/researcher-executor.ts +394 -0
- package/src/orchestration/researcher.ts +115 -42
- package/src/orchestration/service-initialization.ts +109 -0
- package/src/orchestration/session-context.ts +7 -3
- package/src/orchestration/session-state.ts +672 -0
- package/src/prompts/research-knowledge-relevance-triage.md +35 -0
- package/src/prompts/research-knowledge-search-extractor.md +41 -0
- package/src/prompts/research-tool-usage.md +63 -16
- package/src/prompts/researcher.md +59 -136
- package/src/prompts/system-coordinator.md +64 -13
- package/src/prompts/system-lead-evaluator.md +82 -189
- package/src/research-config.ts +872 -0
- package/src/sdk.ts +847 -0
- package/src/security/cisa-kev.ts +72 -9
- package/src/security/cvss.ts +92 -0
- package/src/security/ecosystem.ts +45 -0
- package/src/security/github-advisories.ts +168 -428
- package/src/security/github-advisory-types.ts +282 -0
- package/src/security/index.ts +63 -177
- package/src/security/nvd-client.ts +550 -0
- package/src/security/nvd-types.ts +179 -0
- package/src/security/osv-client.ts +246 -0
- package/src/security/osv-types.ts +285 -0
- package/src/security/types.ts +67 -53
- package/src/skill-install/skill-installer.ts +519 -0
- package/src/stackexchange/index.ts +81 -27
- package/src/stackexchange/output/compact.ts +7 -6
- package/src/stackexchange/output/table.ts +11 -7
- package/src/stackexchange/queries.ts +0 -10
- package/src/stackexchange/rest-client.ts +141 -66
- package/src/stackexchange/types.ts +0 -17
- package/src/tool.ts +15 -423
- package/src/tools/grep.ts +32 -310
- package/src/tools/health-tool-definition.ts +101 -0
- package/src/tools/index.ts +38 -9
- package/src/tools/research-knowledge-search.ts +974 -0
- package/src/tools/research-knowledge-types.ts +77 -0
- package/src/tools/research-tool-definition.ts +494 -0
- package/src/tools/scrape.ts +286 -388
- package/src/tools/search.ts +98 -153
- package/src/tools/security.ts +107 -80
- package/src/tools/stackexchange.ts +58 -35
- package/src/tools/youtube-transcript.ts +163 -0
- package/src/tui/knowledge-search-panel.ts +86 -0
- package/src/tui/pulse.ts +86 -0
- package/src/tui/research-health.ts +124 -0
- package/src/tui/research-panel-color-utils.ts +340 -0
- package/src/tui/research-panel-format.ts +54 -0
- package/src/tui/research-panel-state.ts +404 -0
- package/src/tui/research-panel-wave.ts +280 -0
- package/src/tui/research-panel.ts +339 -435
- package/src/tui/research-tui-manager.ts +233 -0
- package/src/tui/tui-controller.ts +137 -0
- package/src/types/extension-context.ts +18 -49
- package/src/types/index.ts +61 -0
- package/src/types/llm.ts +68 -29
- package/src/types/research-panel-types.ts +61 -0
- package/src/utils/circuit-breaker.ts +146 -0
- package/src/utils/citation-utils.ts +97 -0
- package/src/utils/disk-space-checker.ts +55 -0
- package/src/utils/error-tracker.ts +265 -0
- package/src/utils/host-config.ts +45 -0
- package/src/utils/input-validation.ts +8 -10
- package/src/utils/json-utils.ts +150 -16
- package/src/utils/llm-usage.ts +54 -0
- package/src/utils/log-rotation.ts +125 -0
- package/src/utils/log-utils.ts +159 -0
- package/src/utils/make-resource-loader.ts +3 -1
- package/src/utils/metrics-summary.ts +459 -0
- package/src/utils/metrics.ts +302 -0
- package/src/utils/research-export.ts +28 -12
- package/src/utils/safe-unref.ts +31 -0
- package/src/utils/shared-links.ts +195 -90
- package/src/utils/shutdown-manager.ts +65 -0
- package/src/utils/stdio-capture.ts +407 -0
- package/src/utils/text-utils.ts +264 -7
- package/src/utils/tool-usage-tracker.ts +83 -16
- package/src/utils/url-utils.ts +255 -0
- package/src/utils/user-agent.ts +28 -0
- package/src/web-research/browser-search.ts +179 -0
- package/src/web-research/retry-utils.ts +173 -77
- package/src/web-research/scraper-types.ts +72 -0
- package/src/web-research/scraper-utils.ts +434 -0
- package/src/web-research/search.ts +78 -218
- package/src/web-research/types.ts +9 -24
- package/src/web-research/utils.ts +2 -143
- package/src/web-research/web-scraper.ts +477 -0
- package/src/youtube/index.ts +154 -0
- package/src/youtube/potoken.ts +259 -0
- package/src/youtube/transcript-client.ts +390 -0
- package/src/youtube/video-id.ts +118 -0
- package/config/searxng/default-settings.yml +0 -189
- package/config/searxng/limiter.toml +0 -34
- package/config/tooling/eslint.config.js +0 -73
- package/config/tooling/vitest.config.integration.ts +0 -17
- package/config/tooling/vitest.config.ts +0 -40
- package/config/tooling/vitest.config.unit.ts +0 -12
- package/docs/assets/README-banner.jpg +0 -0
- package/scripts/setup.js +0 -174
- package/src/infrastructure/searxng-lifecycle.ts +0 -577
- package/src/infrastructure/searxng-manager.ts +0 -1183
- package/src/infrastructure/state-manager.ts +0 -918
- package/src/orchestration/deep-research-reducer.ts +0 -129
- package/src/orchestration/id-utils.ts +0 -63
- package/src/security/nvd.ts +0 -532
- package/src/security/osv.ts +0 -487
- package/src/stackexchange/cache.ts +0 -111
- package/src/stackexchange/output/index.ts +0 -7
- package/src/stackexchange/output/json.ts +0 -21
- package/src/tui/searxng-status.ts +0 -80
- package/src/utils/inject-date.ts +0 -29
- package/src/utils/research-error.ts +0 -205
- package/src/utils/searxng-config.ts +0 -94
- package/src/utils/session-state.ts +0 -295
- package/src/web-research/dependencies.ts +0 -20
- package/src/web-research/scrapers.ts +0 -935
- package/tsconfig.json +0 -40
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State Browser Manager
|
|
3
|
+
*
|
|
4
|
+
* Handles browser server coordination within the state.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { SingletonState } from '../types/state-types.ts';
|
|
8
|
+
import { ServiceLifecycle, type IService } from '../../core/service-registry.ts';
|
|
9
|
+
import { ServiceNames } from '../../core/interfaces/service-names.ts';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Manages browser server information in state
|
|
13
|
+
*/
|
|
14
|
+
export class StateBrowserManager implements IService {
|
|
15
|
+
readonly name = ServiceNames.STATE_BROWSER_MANAGER;
|
|
16
|
+
lifecycle = ServiceLifecycle.UNINITIALIZED;
|
|
17
|
+
/**
|
|
18
|
+
* Get the current browser server information
|
|
19
|
+
* @param state The current state
|
|
20
|
+
* @returns Browser server info or null if not set
|
|
21
|
+
*/
|
|
22
|
+
getBrowserServer(state: SingletonState): { port: number; pid: number; schedulerId?: string; startTime?: number | null; authSecret?: string } | null {
|
|
23
|
+
return state.browserServer ?? null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Set the current browser server information
|
|
28
|
+
* @param state The current state
|
|
29
|
+
* @param port The browser server port
|
|
30
|
+
* @param pid The browser server process ID
|
|
31
|
+
* @param schedulerId Optional scheduler ID
|
|
32
|
+
* @param startTime Optional process start time
|
|
33
|
+
* @returns Updated state with browser server info
|
|
34
|
+
*/
|
|
35
|
+
setBrowserServer(
|
|
36
|
+
state: SingletonState,
|
|
37
|
+
port: number,
|
|
38
|
+
pid: number,
|
|
39
|
+
schedulerId?: string,
|
|
40
|
+
startTime?: number | null,
|
|
41
|
+
authSecret?: string
|
|
42
|
+
): SingletonState {
|
|
43
|
+
state.browserServer = { port, pid, schedulerId, startTime: startTime ?? undefined, authSecret };
|
|
44
|
+
return state;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Clear the browser server information
|
|
49
|
+
* @param state The current state
|
|
50
|
+
* @returns Updated state without browser server info
|
|
51
|
+
*/
|
|
52
|
+
clearBrowserServer(state: SingletonState): SingletonState {
|
|
53
|
+
delete state.browserServer;
|
|
54
|
+
return state;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async initialize(): Promise<void> {
|
|
58
|
+
if (this.lifecycle === ServiceLifecycle.INITIALIZED) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.lifecycle = ServiceLifecycle.INITIALIZED;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async dispose(): Promise<void> {
|
|
65
|
+
if (this.lifecycle === ServiceLifecycle.DISPOSED) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this.lifecycle = ServiceLifecycle.DISPOSED;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State Manager Service
|
|
3
|
+
*
|
|
4
|
+
* Service wrapper for the shared state manager functionality.
|
|
5
|
+
* Provides clean interface for cross-process state management.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ServiceLifecycle, getService, tryGetServiceContainerFromCtx } from '../../core/service-registry.ts';
|
|
9
|
+
import { logger } from '../../logger.ts';
|
|
10
|
+
import { ServiceNames } from '../../core/service-interfaces.ts';
|
|
11
|
+
import type { IStateManager, IProcessLifecycle } from '../../core/service-interfaces.ts';
|
|
12
|
+
import type {
|
|
13
|
+
StateMetrics,
|
|
14
|
+
SingletonState,
|
|
15
|
+
} from './state-manager.ts';
|
|
16
|
+
import type { GPUResourceService } from '../gpu-resource-service.ts';
|
|
17
|
+
import type { StateSessionManager } from './state-session-manager.ts';
|
|
18
|
+
import type { StateBrowserManager } from './state-browser-manager.ts';
|
|
19
|
+
import type { StateMetricsCollector } from './state-metrics.ts';
|
|
20
|
+
import type { StateValidator } from './state-validator.ts';
|
|
21
|
+
import type { FileLockService } from '../file-lock-service.ts';
|
|
22
|
+
import type { StateBackupManager } from './state-backup-manager.ts';
|
|
23
|
+
import type { StatePathConfiguration } from './state-path-configuration.ts';
|
|
24
|
+
|
|
25
|
+
// Import the actual state manager implementation (static import)
|
|
26
|
+
import { StateManager } from './state-manager.ts';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* State Manager Service Implementation
|
|
30
|
+
*/
|
|
31
|
+
export class StateManagerService implements IStateManager {
|
|
32
|
+
readonly name = ServiceNames.STATE_MANAGER;
|
|
33
|
+
lifecycle = ServiceLifecycle.UNINITIALIZED;
|
|
34
|
+
|
|
35
|
+
// The underlying state manager instance
|
|
36
|
+
private _stateManager: StateManager | null = null;
|
|
37
|
+
|
|
38
|
+
async initialize(ctx?: any): Promise<void> {
|
|
39
|
+
if (this.lifecycle === ServiceLifecycle.INITIALIZED) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.lifecycle = ServiceLifecycle.INITIALIZING;
|
|
44
|
+
logger.debug('[StateManagerService] Initializing...');
|
|
45
|
+
|
|
46
|
+
const container = tryGetServiceContainerFromCtx(ctx);
|
|
47
|
+
|
|
48
|
+
// Resolve all dependencies using the container for isolation
|
|
49
|
+
const processLifecycle = await getService<IProcessLifecycle>(ServiceNames.PROCESS_LIFECYCLE, ctx, container);
|
|
50
|
+
const fileLockService = await getService<FileLockService>(ServiceNames.FILE_LOCK_SERVICE, ctx, container);
|
|
51
|
+
const backupManager = await getService<StateBackupManager>(ServiceNames.STATE_BACKUP_MANAGER, ctx, container);
|
|
52
|
+
const gpuResourceService = await getService<GPUResourceService>(ServiceNames.GPU_RESOURCE_SERVICE, ctx, container);
|
|
53
|
+
const sessionManager = await getService<StateSessionManager>(ServiceNames.STATE_SESSION_MANAGER, ctx, container);
|
|
54
|
+
const browserManager = await getService<StateBrowserManager>(ServiceNames.STATE_BROWSER_MANAGER, ctx, container);
|
|
55
|
+
const metricsCollector = await getService<StateMetricsCollector>(ServiceNames.STATE_METRICS_COLLECTOR, ctx, container);
|
|
56
|
+
const validator = await getService<StateValidator>(ServiceNames.STATE_VALIDATOR, ctx, container);
|
|
57
|
+
|
|
58
|
+
// Resolve the state directory from StatePathConfiguration
|
|
59
|
+
const pathConfig = await getService<StatePathConfiguration>(ServiceNames.STATE_PATH_CONFIGURATION, ctx, container);
|
|
60
|
+
const stateDir = pathConfig.getStateDir();
|
|
61
|
+
|
|
62
|
+
// Instantiate state manager with injected dependencies
|
|
63
|
+
this._stateManager = new StateManager({
|
|
64
|
+
stateDir,
|
|
65
|
+
processLifecycle,
|
|
66
|
+
fileLockService,
|
|
67
|
+
backupManager,
|
|
68
|
+
gpuResourceService,
|
|
69
|
+
sessionManager,
|
|
70
|
+
browserManager,
|
|
71
|
+
metricsCollector,
|
|
72
|
+
validator,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
this.lifecycle = ServiceLifecycle.INITIALIZED;
|
|
76
|
+
logger.debug('[StateManagerService] Initialized');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async dispose(): Promise<void> {
|
|
80
|
+
if (this.lifecycle === ServiceLifecycle.DISPOSED) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.lifecycle = ServiceLifecycle.DISPOSING;
|
|
85
|
+
logger.debug('[StateManagerService] Disposing...');
|
|
86
|
+
|
|
87
|
+
// Cleanup state manager resources
|
|
88
|
+
if (this._stateManager) {
|
|
89
|
+
try {
|
|
90
|
+
await this._stateManager.cleanup();
|
|
91
|
+
} catch (err) {
|
|
92
|
+
logger.warn('[StateManagerService] Error during cleanup:', err);
|
|
93
|
+
}
|
|
94
|
+
this._stateManager = null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.lifecycle = ServiceLifecycle.DISPOSED;
|
|
98
|
+
logger.debug('[StateManagerService] Disposed');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Get the underlying state manager instance
|
|
103
|
+
*/
|
|
104
|
+
getStateManager(): StateManager {
|
|
105
|
+
if (!this._stateManager) {
|
|
106
|
+
throw new Error('[StateManagerService] State manager not initialized');
|
|
107
|
+
}
|
|
108
|
+
return this._stateManager;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Read the state from the file system
|
|
113
|
+
*/
|
|
114
|
+
async readState(): Promise<SingletonState> {
|
|
115
|
+
return this.getStateManager().readState();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Write the state to the file system
|
|
120
|
+
*/
|
|
121
|
+
async writeState(state: SingletonState): Promise<void> {
|
|
122
|
+
return this.getStateManager().writeState(state);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Update state atomically using an updater function
|
|
127
|
+
*/
|
|
128
|
+
async updateState(updater: (state: SingletonState) => SingletonState | Promise<SingletonState>): Promise<void> {
|
|
129
|
+
return this.getStateManager().updateState(updater);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Add a new session to the state
|
|
134
|
+
*/
|
|
135
|
+
async addSession(sessionId: string, param: number | string): Promise<void> {
|
|
136
|
+
return this.getStateManager().addSession(sessionId, param);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Remove a session from the state
|
|
141
|
+
*/
|
|
142
|
+
async removeSession(sessionId: string): Promise<void> {
|
|
143
|
+
return this.getStateManager().removeSession(sessionId);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Update the heartbeat timestamp for a session
|
|
148
|
+
*/
|
|
149
|
+
async updateHeartbeat(sessionId: string): Promise<void> {
|
|
150
|
+
return this.getStateManager().updateHeartbeat(sessionId);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Clean up stale sessions
|
|
155
|
+
*/
|
|
156
|
+
async cleanupStaleSessions(timeoutMs: number): Promise<number> {
|
|
157
|
+
return this.getStateManager().cleanupStaleSessions(timeoutMs);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Get metrics about the current state
|
|
162
|
+
*/
|
|
163
|
+
async getMetrics(): Promise<StateMetrics> {
|
|
164
|
+
return this.getStateManager().getMetrics();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Get the current browser server information
|
|
169
|
+
*/
|
|
170
|
+
async getBrowserServer(): Promise<{ port: number; pid: number; schedulerId?: string; authSecret?: string } | null> {
|
|
171
|
+
// Read-only query. When the state manager was never initialized — common for a
|
|
172
|
+
// run that never registered a browser server (e.g. KNOWLEDGE_STORE_MODE='none',
|
|
173
|
+
// or an early failure before browser startup) — there is simply nothing
|
|
174
|
+
// recorded. Return null instead of throwing so shutdown paths that probe for a
|
|
175
|
+
// browser server (scheduler.shutdown) degrade quietly rather than logging a
|
|
176
|
+
// misleading "State manager not initialized" error.
|
|
177
|
+
if (!this._stateManager) return null;
|
|
178
|
+
return this.getStateManager().getBrowserServer();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Set the current browser server information
|
|
183
|
+
*/
|
|
184
|
+
async setBrowserServer(port: number, pid: number, schedulerId?: string, authSecret?: string): Promise<void> {
|
|
185
|
+
return this.getStateManager().setBrowserServer(port, pid, schedulerId, authSecret);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Clear the browser server information
|
|
190
|
+
*/
|
|
191
|
+
async clearBrowserServer(): Promise<void> {
|
|
192
|
+
return this.getStateManager().clearBrowserServer();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Get the current embedding server information
|
|
197
|
+
*/
|
|
198
|
+
async getEmbeddingServer(): Promise<{ port: number; pid: number; startTime?: number; serverId: string; model?: string } | null> {
|
|
199
|
+
return this.getStateManager().getEmbeddingServer();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Clear the embedding server information
|
|
204
|
+
*/
|
|
205
|
+
async clearEmbeddingServer(): Promise<void> {
|
|
206
|
+
return this.getStateManager().clearEmbeddingServer();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Check if a process is alive
|
|
211
|
+
*/
|
|
212
|
+
async isPidAlive(pid: number, expectedSchedulerId?: string, skipLock?: boolean): Promise<boolean> {
|
|
213
|
+
return this.getStateManager().isPidAlive(pid, expectedSchedulerId, skipLock);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Acquire the global GPU resource lock
|
|
218
|
+
*/
|
|
219
|
+
async acquireGpuLock(sessionId?: string, timeoutMs?: number): Promise<boolean> {
|
|
220
|
+
return this.getStateManager().acquireGpuLock(sessionId, timeoutMs);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Release the global GPU resource lock
|
|
225
|
+
*/
|
|
226
|
+
async releaseGpuLock(pid?: number): Promise<void> {
|
|
227
|
+
return this.getStateManager().releaseGpuLock(pid);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Information about the current GPU owner
|
|
232
|
+
*/
|
|
233
|
+
async getGpuOwner(): Promise<SingletonState['gpuOwner'] | null> {
|
|
234
|
+
return this.getStateManager().getGpuOwner();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Cleanup state manager resources
|
|
239
|
+
*/
|
|
240
|
+
async cleanup(): Promise<void> {
|
|
241
|
+
return this.getStateManager().cleanup();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Get the state file path
|
|
246
|
+
*/
|
|
247
|
+
getStateFilePath(): string {
|
|
248
|
+
return this.getStateManager().getStateFilePath();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get the lock file path
|
|
253
|
+
*/
|
|
254
|
+
getLockFilePath(): string {
|
|
255
|
+
return this.getStateManager().getLockFilePath();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Get the backup directory path
|
|
260
|
+
*/
|
|
261
|
+
getBackupDirPath(): string {
|
|
262
|
+
return this.getStateManager().getBackupDirPath();
|
|
263
|
+
}
|
|
264
|
+
}
|