@iworkforces/tracelattice 2.0.7 → 2.1.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 +88 -64
- package/dist/ServerConfig.d.ts +1 -1
- package/dist/ServerConfig.js.map +1 -1
- package/dist/cli.js +223 -254
- package/dist/cli.js.map +1 -1
- package/dist/config/ConfigLoader.d.ts +29 -26
- package/dist/config/ConfigLoader.d.ts.map +1 -1
- package/dist/config/ConfigLoader.js +40 -36
- package/dist/config/ConfigLoader.js.map +1 -1
- package/dist/contracts/PersistenceBackend.d.ts +7 -108
- package/dist/contracts/PersistenceBackend.d.ts.map +1 -1
- package/dist/contracts/PersistenceBackend.js +1 -6
- package/dist/contracts/calibrator.d.ts +6 -6
- package/dist/contracts/calibrator.d.ts.map +1 -1
- package/dist/contracts/ids.d.ts +1 -8
- package/dist/contracts/ids.d.ts.map +1 -1
- package/dist/contracts/ids.js +2 -3
- package/dist/contracts/ids.js.map +1 -1
- package/dist/contracts/interfaces.d.ts +4 -6
- package/dist/contracts/interfaces.d.ts.map +1 -1
- package/dist/contracts/persistence-work.d.ts +2 -3
- package/dist/contracts/persistence-work.d.ts.map +1 -1
- package/dist/contracts/summary.d.ts +0 -1
- package/dist/contracts/summary.d.ts.map +1 -1
- package/dist/core/HistoryManager.d.ts +12 -16
- package/dist/core/HistoryManager.d.ts.map +1 -1
- package/dist/core/HistoryManager.js +19 -40
- package/dist/core/HistoryManager.js.map +1 -1
- package/dist/core/IHistoryManager.d.ts +22 -30
- package/dist/core/IHistoryManager.d.ts.map +1 -1
- package/dist/core/InputNormalizer.d.ts +7 -24
- package/dist/core/InputNormalizer.d.ts.map +1 -1
- package/dist/core/InputNormalizer.js +3 -9
- package/dist/core/InputNormalizer.js.map +1 -1
- package/dist/core/PersistenceBuffer.d.ts +3 -20
- package/dist/core/PersistenceBuffer.d.ts.map +1 -1
- package/dist/core/PersistenceBuffer.js +1 -4
- package/dist/core/PersistenceBuffer.js.map +1 -1
- package/dist/core/PersistenceRestore.d.ts +1 -1
- package/dist/core/PersistenceRestore.d.ts.map +1 -1
- package/dist/core/PersistenceRestore.js +4 -10
- package/dist/core/PersistenceRestore.js.map +1 -1
- package/dist/core/PersistenceWriter.d.ts.map +1 -1
- package/dist/core/PersistenceWriter.js +3 -12
- package/dist/core/PersistenceWriter.js.map +1 -1
- package/dist/core/SessionErrors.d.ts +0 -11
- package/dist/core/SessionErrors.d.ts.map +1 -1
- package/dist/core/SessionErrors.js +1 -14
- package/dist/core/SessionErrors.js.map +1 -1
- package/dist/core/SessionLock.d.ts +4 -5
- package/dist/core/SessionLock.d.ts.map +1 -1
- package/dist/core/SessionLock.js +5 -10
- package/dist/core/SessionLock.js.map +1 -1
- package/dist/core/SessionManager.d.ts +0 -2
- package/dist/core/SessionManager.d.ts.map +1 -1
- package/dist/core/SessionManager.js +3 -5
- package/dist/core/SessionManager.js.map +1 -1
- package/dist/core/SessionResetCoordinator.d.ts +10 -7
- package/dist/core/SessionResetCoordinator.d.ts.map +1 -1
- package/dist/core/SessionResetCoordinator.js +10 -28
- package/dist/core/SessionResetCoordinator.js.map +1 -1
- package/dist/core/ThoughtEvaluator.d.ts +5 -5
- package/dist/core/ThoughtEvaluator.d.ts.map +1 -1
- package/dist/core/ThoughtEvaluator.js +4 -40
- package/dist/core/ThoughtEvaluator.js.map +1 -1
- package/dist/core/ThoughtFormatter.js.map +1 -1
- package/dist/core/ThoughtProcessor.d.ts +10 -3
- package/dist/core/ThoughtProcessor.d.ts.map +1 -1
- package/dist/core/ThoughtProcessor.js +34 -38
- package/dist/core/ThoughtProcessor.js.map +1 -1
- package/dist/core/VerificationOutcomeAdmission.d.ts.map +1 -1
- package/dist/core/VerificationOutcomeAdmission.js +5 -7
- package/dist/core/VerificationOutcomeAdmission.js.map +1 -1
- package/dist/core/compression/CompressionService.d.ts +2 -1
- package/dist/core/compression/CompressionService.d.ts.map +1 -1
- package/dist/core/compression/CompressionService.js.map +1 -1
- package/dist/core/compression/DehydrationPolicy.d.ts.map +1 -1
- package/dist/core/compression/DehydrationPolicy.js.map +1 -1
- package/dist/core/compression/InMemorySummaryStore.d.ts +2 -1
- package/dist/core/compression/InMemorySummaryStore.d.ts.map +1 -1
- package/dist/core/compression/InMemorySummaryStore.js.map +1 -1
- package/dist/core/evaluator/Calibrator.d.ts +2 -2
- package/dist/core/evaluator/Calibrator.d.ts.map +1 -1
- package/dist/core/evaluator/Calibrator.js +2 -5
- package/dist/core/evaluator/Calibrator.js.map +1 -1
- package/dist/core/evaluator/SignalComputer.d.ts +2 -1
- package/dist/core/evaluator/SignalComputer.d.ts.map +1 -1
- package/dist/core/evaluator/SignalComputer.js.map +1 -1
- package/dist/core/evaluator/internals.d.ts +1 -5
- package/dist/core/evaluator/internals.d.ts.map +1 -1
- package/dist/core/evaluator/internals.js +1 -3
- package/dist/core/evaluator/internals.js.map +1 -1
- package/dist/core/graph/Edge.d.ts +1 -1
- package/dist/core/graph/EdgeEmitter.d.ts +2 -4
- package/dist/core/graph/EdgeEmitter.d.ts.map +1 -1
- package/dist/core/graph/EdgeEmitter.js +2 -4
- package/dist/core/graph/EdgeEmitter.js.map +1 -1
- package/dist/core/graph/GraphView.d.ts +13 -1
- package/dist/core/graph/GraphView.d.ts.map +1 -1
- package/dist/core/graph/GraphView.js +34 -0
- package/dist/core/graph/GraphView.js.map +1 -1
- package/dist/core/reasoning/OutcomeRecorder.d.ts +0 -1
- package/dist/core/reasoning/OutcomeRecorder.d.ts.map +1 -1
- package/dist/core/reasoning/OutcomeRecorder.js.map +1 -1
- package/dist/core/reasoning/strategies/SequentialStrategy.d.ts +3 -3
- package/dist/core/reasoning/strategies/SequentialStrategy.js.map +1 -1
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts +6 -6
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts.map +1 -1
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js +16 -2
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js.map +1 -1
- package/dist/core/reasoning/strategies/totScoring.d.ts.map +1 -1
- package/dist/core/reasoning/strategies/totScoring.js.map +1 -1
- package/dist/core/reasoning.d.ts +1 -3
- package/dist/core/reasoning.d.ts.map +1 -1
- package/dist/core/thought.d.ts +3 -2
- package/dist/core/thought.d.ts.map +1 -1
- package/dist/errors.d.ts +4 -20
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -28
- package/dist/errors.js.map +1 -1
- package/dist/lib.d.ts +31 -24
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +55 -10
- package/dist/lib.js.map +1 -1
- package/dist/logger/NullLogger.d.ts +9 -11
- package/dist/logger/NullLogger.d.ts.map +1 -1
- package/dist/logger/NullLogger.js.map +1 -1
- package/dist/persistence/FilePersistence.d.ts +3 -12
- package/dist/persistence/FilePersistence.d.ts.map +1 -1
- package/dist/persistence/FilePersistence.js +9 -61
- package/dist/persistence/FilePersistence.js.map +1 -1
- package/dist/persistence/FileSnapshotV2.d.ts +2 -2
- package/dist/persistence/FileSnapshotV2.js +2 -2
- package/dist/persistence/FileSnapshotV2.js.map +1 -1
- package/dist/persistence/FileWriter.d.ts +1 -0
- package/dist/persistence/FileWriter.d.ts.map +1 -1
- package/dist/persistence/FileWriter.js +3 -3
- package/dist/persistence/FileWriter.js.map +1 -1
- package/dist/persistence/MemoryPersistence.d.ts +5 -15
- package/dist/persistence/MemoryPersistence.d.ts.map +1 -1
- package/dist/persistence/MemoryPersistence.js +6 -40
- package/dist/persistence/MemoryPersistence.js.map +1 -1
- package/dist/persistence/PersistenceCodec.js +1 -3
- package/dist/persistence/PersistenceCodec.js.map +1 -1
- package/dist/persistence/PersistenceErrors.d.ts +0 -6
- package/dist/persistence/PersistenceErrors.d.ts.map +1 -1
- package/dist/persistence/PersistenceErrors.js +1 -9
- package/dist/persistence/PersistenceErrors.js.map +1 -1
- package/dist/persistence/PersistenceScope.d.ts.map +1 -1
- package/dist/persistence/PersistenceScope.js +2 -2
- package/dist/persistence/PersistenceScope.js.map +1 -1
- package/dist/persistence/SqlitePersistence.d.ts +3 -10
- package/dist/persistence/SqlitePersistence.d.ts.map +1 -1
- package/dist/persistence/SqlitePersistence.js +2 -26
- package/dist/persistence/SqlitePersistence.js.map +1 -1
- package/dist/persistence/SqliteSchemaV2.d.ts.map +1 -1
- package/dist/persistence/SqliteSchemaV2.js +3 -12
- package/dist/persistence/SqliteSchemaV2.js.map +1 -1
- package/dist/pool/ConnectionPool.d.ts +3 -12
- package/dist/pool/ConnectionPool.d.ts.map +1 -1
- package/dist/pool/ConnectionPool.js +5 -8
- package/dist/pool/ConnectionPool.js.map +1 -1
- package/dist/pool/IConnectionPool.d.ts +3 -9
- package/dist/pool/IConnectionPool.d.ts.map +1 -1
- package/dist/registry/SkillRegistry.d.ts +1 -7
- package/dist/registry/SkillRegistry.d.ts.map +1 -1
- package/dist/registry/SkillRegistry.js +0 -15
- package/dist/registry/SkillRegistry.js.map +1 -1
- package/dist/registry/ToolRegistry.d.ts +1 -9
- package/dist/registry/ToolRegistry.d.ts.map +1 -1
- package/dist/registry/ToolRegistry.js +0 -21
- package/dist/registry/ToolRegistry.js.map +1 -1
- package/dist/schema.d.ts +2 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +3 -3
- package/dist/schema.js.map +1 -1
- package/dist/transport/BaseTransport.d.ts +0 -9
- package/dist/transport/BaseTransport.d.ts.map +1 -1
- package/dist/transport/BaseTransport.js +0 -11
- package/dist/transport/BaseTransport.js.map +1 -1
- package/dist/transport/HttpHelpers.d.ts +4 -1
- package/dist/transport/HttpHelpers.d.ts.map +1 -1
- package/dist/transport/HttpHelpers.js +61 -11
- package/dist/transport/HttpHelpers.js.map +1 -1
- package/dist/transport/HttpRequestLifecycle.d.ts +15 -1
- package/dist/transport/HttpRequestLifecycle.d.ts.map +1 -1
- package/dist/transport/HttpRequestLifecycle.js +66 -4
- package/dist/transport/HttpRequestLifecycle.js.map +1 -1
- package/dist/transport/HttpTransport.d.ts +2 -0
- package/dist/transport/HttpTransport.d.ts.map +1 -1
- package/dist/transport/HttpTransport.js +75 -38
- package/dist/transport/HttpTransport.js.map +1 -1
- package/dist/transport/StreamableHttpTransport.d.ts +5 -29
- package/dist/transport/StreamableHttpTransport.d.ts.map +1 -1
- package/dist/transport/StreamableHttpTransport.js +74 -116
- package/dist/transport/StreamableHttpTransport.js.map +1 -1
- package/dist/watchers/SkillWatcher.d.ts.map +1 -1
- package/dist/watchers/SkillWatcher.js +1 -1
- package/dist/watchers/SkillWatcher.js.map +1 -1
- package/package.json +2 -2
- package/dist/contracts/PersistenceBackend.js.map +0 -1
- package/dist/persistence/FileLegacyImport.d.ts +0 -2
- package/dist/persistence/FileLegacyImport.d.ts.map +0 -1
- package/dist/persistence/FileLegacyImport.js +0 -183
- package/dist/persistence/FileLegacyImport.js.map +0 -1
- package/dist/persistence/SessionScopedPersistence.d.ts +0 -4
- package/dist/persistence/SessionScopedPersistence.d.ts.map +0 -1
- package/dist/persistence/SessionScopedPersistence.js +0 -9
- package/dist/persistence/SessionScopedPersistence.js.map +0 -1
- package/dist/persistence/SqliteLegacyImport.d.ts +0 -14
- package/dist/persistence/SqliteLegacyImport.d.ts.map +0 -1
- package/dist/persistence/SqliteLegacyImport.js +0 -136
- package/dist/persistence/SqliteLegacyImport.js.map +0 -1
- package/dist/persistence/SqliteLegacySchema.d.ts +0 -15
- package/dist/persistence/SqliteLegacySchema.d.ts.map +0 -1
- package/dist/persistence/SqliteLegacySchema.js +0 -72
- package/dist/persistence/SqliteLegacySchema.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool/ConnectionPool.js","sources":["../../src/pool/ConnectionPool.ts"],"sourcesContent":["/**\n * Connection Pool for managing concurrent user sessions.\n *\n * This module provides session management for multi-user scenarios,\n * allowing multiple concurrent clients to each have isolated state.\n *\n * @example\n * ```typescript\n * const pool = new ConnectionPool({\n * maxSessions: 100,\n * sessionTimeout: 300000 // 5 minutes\n * });\n *\n * const sessionId = await pool.createSession();\n * await pool.process(sessionId, thought);\n * await pool.closeSession(sessionId);\n * ```\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { MaxSessionsReachedError, PoolTerminatedError } from '../errors.js';\nimport type { Logger } from '../logger/StructuredLogger.js';\nimport { asSessionId, type SessionId } from '../contracts/ids.js';\nimport { assertNever } from '../utils.js';\nimport { SessionNotActiveError, SessionNotFoundError } from './PoolErrors.js';\nimport type {\n\tConnectionPoolStats,\n\tIConnectionPool,\n\tProcessResult,\n\tSessionInfo,\n\tSessionRunResult,\n\tSessionServer,\n\tSessionThoughtInput,\n} from './IConnectionPool.js';\n\nexport interface SessionOptions {\n\t/**\n\t * Maximum number of concurrent sessions\n\t * @default 100\n\t */\n\tmaxSessions?: number;\n\n\t/**\n\t * Logger instance\n\t */\n\tlogger?: Logger;\n\n\tserverFactory?: () => Promise<SessionServer>;\n\n\t/**\n\t * Session timeout in milliseconds\n\t * @default 300000 (5 minutes)\n\t */\n\tsessionTimeout?: number;\n\n\t/**\n\t * Whether to enable automatic session cleanup\n\t * @default true\n\t */\n\tautoCleanup?: boolean;\n\n\t/**\n\t * Cleanup interval in milliseconds\n\t * @default 60000 (1 minute)\n\t */\n\tcleanupInterval?: number;\n}\n\n/**\n * Represents a user session with its own server instance.\n */\nexport class Session {\n\tprivate _server: SessionServer;\n\tprivate _id: SessionId;\n\tprivate _createdAt: number;\n\tprivate _lastActivityAt: number;\n\tprivate _isActiveValue: boolean;\n\tprivate _timeout: number;\n\tprivate _cleanupTimer: NodeJS.Timeout | null = null;\n\tprivate _logger: Logger;\n\tprivate _closePromise: Promise<void> | null = null;\n\tprivate _activeOperationCount = 0;\n\tprivate _operationDrain: PromiseWithResolvers<void> | null = null;\n\tprivate readonly _onTimeout: ((sessionId: SessionId) => void) | null;\n\n\tconstructor(\n\t\tid: SessionId,\n\t\tserver: SessionServer,\n\t\ttimeout: number,\n\t\tlogger: Logger,\n\t\tonTimeout: ((sessionId: SessionId) => void) | null = null\n\t) {\n\t\tthis._server = server;\n\t\tthis._id = id;\n\t\tthis._createdAt = Date.now();\n\t\tthis._lastActivityAt = this._createdAt;\n\t\tthis._isActiveValue = true;\n\t\tthis._timeout = timeout;\n\t\tthis._logger = logger;\n\t\tthis._onTimeout = onTimeout;\n\n\t\t// Start session timeout timer\n\t\tthis._startTimeout();\n\t}\n\n\t/**\n\t * Check if the session is active.\n\t */\n\tget isActive(): boolean {\n\t\treturn this._isActiveValue;\n\t}\n\n\t/**\n\t * Process a thought through this session's server instance.\n\t */\n\tasync process(input: SessionThoughtInput): Promise<ProcessResult> {\n\t\tif (!this.isActive) {\n\t\t\tthrow new SessionNotActiveError(this._id);\n\t\t}\n\n\t\t// Update last activity\n\t\tthis._lastActivityAt = Date.now();\n\n\t\t// Reset timeout timer\n\t\tthis._resetTimeout();\n\n\t\t// Process the thought\n\t\treturn this._server.processThought(input);\n\t}\n\n\tprocessAdmitted(input: SessionThoughtInput): Promise<ProcessResult> {\n\t\tthis._lastActivityAt = Date.now();\n\t\tif (this.isActive) this._resetTimeout();\n\t\treturn this._server.processThought(input);\n\t}\n\n\trunWhileActive<T>(operation: (session: Session) => Promise<T>): Promise<SessionRunResult<T>> {\n\t\tif (!this.isActive) return Promise.resolve({ status: 'inactive' });\n\t\tthis._activeOperationCount++;\n\t\treturn (async () => {\n\t\t\ttry {\n\t\t\t\treturn { status: 'completed', value: await operation(this) };\n\t\t\t} finally {\n\t\t\t\tthis._activeOperationCount--;\n\t\t\t\tif (this._activeOperationCount === 0) this._operationDrain?.resolve();\n\t\t\t}\n\t\t})();\n\t}\n\n\t/**\n\t * Get session information.\n\t */\n\tgetInfo(): SessionInfo {\n\t\treturn {\n\t\t\tid: this._id,\n\t\t\tserver: this._server,\n\t\t\tcreatedAt: this._createdAt,\n\t\t\tlastActivityAt: this._lastActivityAt,\n\t\t\tisActive: this.isActive,\n\t\t};\n\t}\n\n\t/**\n\t * Check if the session has timed out.\n\t */\n\tisTimedOut(): boolean {\n\t\treturn Date.now() - this._lastActivityAt > this._timeout;\n\t}\n\n\t/**\n\t * Close the session and stop the server.\n\t */\n\tclose(): Promise<void> {\n\t\tif (this._closePromise) {\n\t\t\treturn this._closePromise;\n\t\t}\n\n\t\tconst completion = Promise.withResolvers<void>();\n\t\tthis._closePromise = completion.promise;\n\t\tvoid completion.promise.then(undefined, () => {\n\t\t\tif (this._closePromise === completion.promise) this._closePromise = null;\n\t\t});\n\t\tthis._isActiveValue = false;\n\n\t\t// Stop timeout timer\n\t\tif (this._cleanupTimer) {\n\t\t\tclearTimeout(this._cleanupTimer);\n\t\t\tthis._cleanupTimer = null;\n\t\t}\n\n\t\tif (this._activeOperationCount === 0) {\n\t\t\tthis._stopServer(completion);\n\t\t} else {\n\t\t\tthis._operationDrain = Promise.withResolvers<void>();\n\t\t\tvoid this._operationDrain.promise.then(() => this._stopServer(completion));\n\t\t}\n\n\t\treturn completion.promise;\n\t}\n\n\tprivate _stopServer(completion: PromiseWithResolvers<void>): void {\n\t\ttry {\n\t\t\tPromise.resolve(this._server.stop()).then(completion.resolve, completion.reject);\n\t\t} catch (error) {\n\t\t\tcompletion.reject(\n\t\t\t\terror instanceof Error ? error : new AggregateError([error], 'Session stop failed')\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Start the session timeout timer.\n\t */\n\tprivate _startTimeout(): void {\n\t\tif (this._cleanupTimer) {\n\t\t\tclearTimeout(this._cleanupTimer);\n\t\t}\n\n\t\tthis._cleanupTimer = setTimeout(() => {\n\t\t\tif (this.isTimedOut()) {\n\t\t\t\tthis._logger.warn(`Session ${this._id} timed out, closing`);\n\t\t\t\tif (this._onTimeout) {\n\t\t\t\t\tthis._onTimeout(this._id);\n\t\t\t\t} else {\n\t\t\t\t\tthis.close().catch((err) => {\n\t\t\t\t\t\tthis._logger.error(`Error closing timed out session ${this._id}:`, err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}, this._timeout);\n\t}\n\n\t/**\n\t * Reset the timeout timer after activity.\n\t */\n\tprivate _resetTimeout(): void {\n\t\tthis._startTimeout();\n\t}\n}\n\ninterface TerminationGeneration {\n\treadonly attempts: Map<SessionId, Promise<void>>;\n\treadonly completion: PromiseWithResolvers<void>;\n}\n\n/**\n * ConnectionPool manages multiple concurrent user sessions.\n *\n * Each session has its own server instance with isolated state,\n * allowing multiple users to interact with the system simultaneously.\n */\nexport class ConnectionPool implements IConnectionPool {\n\tprivate _sessions: Map<SessionId, Session> = new Map();\n\tprivate readonly _ownedSessions = new Map<SessionId, Session>();\n\tprivate readonly _closingSessions = new Map<SessionId, Promise<void>>();\n\tprivate _createSessionLock: Promise<void> | null = null;\n\tprivate _maxSessions: number;\n\tprivate _sessionTimeout: number;\n\tprivate _autoCleanup: boolean;\n\tprivate _cleanupInterval: number;\n\tprivate _cleanupTimerId: ReturnType<typeof setInterval> | null = null;\n\tprivate _terminated: boolean = false;\n\tprivate _logger: Logger;\n\tprivate _serverFactory: (() => Promise<SessionServer>) | null;\n\tprivate _terminationGeneration: TerminationGeneration | null = null;\n\tprivate readonly _admissionContext = new AsyncLocalStorage<{\n\t\treadonly sessionId: SessionId;\n\t\treadonly session: Session;\n\t\topen: boolean;\n\t}>();\n\n\tconstructor(options: SessionOptions = {}) {\n\t\tthis._maxSessions = options.maxSessions ?? 100;\n\t\tthis._sessionTimeout = options.sessionTimeout ?? 300000; // 5 minutes\n\t\tthis._autoCleanup = options.autoCleanup ?? true;\n\t\tthis._cleanupInterval = options.cleanupInterval ?? 60000; // 1 minute\n\t\tthis._serverFactory = options.serverFactory ?? null;\n\t\tthis._logger = options.logger ?? this._createNoopLogger();\n\n\t\tif (this._autoCleanup) {\n\t\t\tthis._startCleanup();\n\t\t}\n\t}\n\n\t/**\n\t * Create a no-op logger when none is provided.\n\t */\n\tprivate _createNoopLogger(): Logger {\n\t\treturn {\n\t\t\tinfo: (): void => {},\n\t\t\twarn: (): void => {},\n\t\t\terror: (): void => {},\n\t\t\tdebug: (): void => {},\n\t\t\tsetLevel: (): void => {},\n\t\t\tgetLevel: (): 'info' => 'info',\n\t\t};\n\t}\n\n\t/**\n\t * Create a new session.\n\t *\n\t * @returns The session ID\n\t * @throws Error if max sessions reached\n\t */\n\tasync createSession(): Promise<SessionId> {\n\t\twhile (this._createSessionLock) {\n\t\t\tawait this._createSessionLock;\n\t\t}\n\n\t\tif (this._terminated) {\n\t\t\tthrow new PoolTerminatedError();\n\t\t}\n\n\t\tif (this._ownedSessions.size >= this._maxSessions) {\n\t\t\tthrow new MaxSessionsReachedError(this._maxSessions);\n\t\t}\n\n\t\tif (!this._serverFactory) {\n\t\t\tthrow new Error('ConnectionPool requires a serverFactory option to create sessions');\n\t\t}\n\n\t\tlet resolveLock!: () => void;\n\t\tthis._createSessionLock = new Promise<void>((resolve) => {\n\t\t\tresolveLock = resolve;\n\t\t});\n\n\t\ttry {\n\t\t\t// Generate unique session ID\n\t\t\tconst sessionId = asSessionId(\n\t\t\t\t`session_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`\n\t\t\t);\n\t\t\tif (this._ownedSessions.has(sessionId)) {\n\t\t\t\tthrow new Error(`Session ID collision: ${sessionId}`);\n\t\t\t}\n\n\t\t\t// Create a new server instance for this session\n\t\t\tconst server = await this._serverFactory();\n\t\t\tconst session = new Session(\n\t\t\t\tsessionId,\n\t\t\t\tserver,\n\t\t\t\tthis._sessionTimeout,\n\t\t\t\tthis._logger,\n\t\t\t\t(timedOutSessionId) => this._handleSessionTimeout(timedOutSessionId)\n\t\t\t);\n\t\t\tthis._ownedSessions.set(sessionId, session);\n\t\t\tif (this._terminated) {\n\t\t\t\tconst generation = this._terminationGeneration;\n\t\t\t\tif (generation) {\n\t\t\t\t\tawait this._coordinateCleanup(sessionId, generation);\n\t\t\t\t} else {\n\t\t\t\t\tawait this._coordinateCleanup(sessionId);\n\t\t\t\t}\n\t\t\t\tthrow new PoolTerminatedError();\n\t\t\t}\n\n\t\t\tthis._sessions.set(sessionId, session);\n\n\t\t\tthis._logger.info(\n\t\t\t\t`Created session ${sessionId} (${this._sessions.size}/${this._maxSessions} active sessions)`\n\t\t\t);\n\t\t\treturn sessionId;\n\t\t} finally {\n\t\t\tresolveLock();\n\t\t\tthis._createSessionLock = null;\n\t\t}\n\t}\n\n\t/**\n\t * Process a thought in the specified session.\n\t *\n\t * @param sessionId - The session ID\n\t * @param input - The thought data to process\n\t * @returns Promise with the processing result\n\t * @throws Error if session not found\n\t */\n\tasync process(sessionId: SessionId, input: SessionThoughtInput): Promise<ProcessResult> {\n\t\tconst result = await this._runWithSession(sessionId, (session) =>\n\t\t\tsession.processAdmitted(input)\n\t\t);\n\t\tswitch (result.status) {\n\t\t\tcase 'completed':\n\t\t\t\treturn result.value;\n\t\t\tcase 'inactive':\n\t\t\t\tthrow new SessionNotActiveError(sessionId);\n\t\t\tcase 'missing':\n\t\t\t\tthrow new SessionNotFoundError(sessionId);\n\t\t\tdefault:\n\t\t\t\treturn assertNever(result);\n\t\t}\n\t}\n\n\trunWithSession<T>(\n\t\tsessionId: SessionId,\n\t\toperation: (session: SessionServer) => Promise<T>\n\t): Promise<SessionRunResult<T>> {\n\t\treturn this._runWithSession(sessionId, (session) => operation(session.getInfo().server));\n\t}\n\n\tprivate _runWithSession<T>(\n\t\tsessionId: SessionId,\n\t\toperation: (session: Session) => Promise<T>\n\t): Promise<SessionRunResult<T>> {\n\t\tconst activeFrame = this._admissionContext.getStore();\n\t\tif (activeFrame?.open === true && activeFrame.sessionId === sessionId) {\n\t\t\treturn (async () => ({ status: 'completed', value: await operation(activeFrame.session) }))();\n\t\t}\n\n\t\tconst session = this._sessions.get(sessionId);\n\t\tif (!session) {\n\t\t\treturn Promise.resolve(\n\t\t\t\tthis._ownedSessions.has(sessionId) ? { status: 'inactive' } : { status: 'missing' }\n\t\t\t);\n\t\t}\n\n\t\treturn session.runWhileActive((capturedSession) => {\n\t\t\tconst frame = { sessionId, session: capturedSession, open: true };\n\t\t\treturn this._admissionContext.run(frame, async () => {\n\t\t\t\ttry {\n\t\t\t\t\treturn await operation(capturedSession);\n\t\t\t\t} finally {\n\t\t\t\t\tframe.open = false;\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Close a session and release resources.\n\t *\n\t * @param sessionId - The session ID to close\n\t * @throws Error if session not found\n\t */\n\tcloseSession(sessionId: SessionId): Promise<void> {\n\t\tif (!this._ownedSessions.has(sessionId)) {\n\t\t\treturn Promise.reject(new SessionNotFoundError(sessionId));\n\t\t}\n\n\t\tconst generation = this._terminationGeneration;\n\t\treturn generation\n\t\t\t? this._coordinateCleanup(sessionId, generation)\n\t\t\t: this._coordinateCleanup(sessionId);\n\t}\n\n\tprivate _coordinateCleanup(\n\t\tsessionId: SessionId,\n\t\tgeneration?: TerminationGeneration\n\t): Promise<void> {\n\t\tconst generationAttempt = generation?.attempts.get(sessionId);\n\t\tif (generationAttempt) return generationAttempt;\n\n\t\tconst session = this._ownedSessions.get(sessionId);\n\t\tif (!session) return Promise.reject(new SessionNotFoundError(sessionId));\n\n\t\tthis._sessions.delete(sessionId);\n\t\tconst currentAttempt = this._closingSessions.get(sessionId);\n\t\tconst attempt = currentAttempt ?? session.close();\n\t\tif (!currentAttempt) this._closingSessions.set(sessionId, attempt);\n\t\tgeneration?.attempts.set(sessionId, attempt);\n\n\t\tif (!currentAttempt)\n\t\t\tvoid attempt.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (this._closingSessions.get(sessionId) === attempt) {\n\t\t\t\t\t\tthis._closingSessions.delete(sessionId);\n\t\t\t\t\t}\n\t\t\t\t\tif (this._ownedSessions.get(sessionId) === session) {\n\t\t\t\t\t\tthis._ownedSessions.delete(sessionId);\n\t\t\t\t\t}\n\t\t\t\t\tthis._logger.info(\n\t\t\t\t\t\t`Closed session ${sessionId} (${this._sessions.size}/${this._maxSessions} active sessions)`\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tif (this._closingSessions.get(sessionId) === attempt) {\n\t\t\t\t\t\tthis._closingSessions.delete(sessionId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\treturn attempt;\n\t}\n\n\tprivate _handleSessionTimeout(sessionId: SessionId): void {\n\t\tconst generation = this._terminationGeneration;\n\t\tconst attempt = generation\n\t\t\t? this._coordinateCleanup(sessionId, generation)\n\t\t\t: this._coordinateCleanup(sessionId);\n\t\tvoid attempt.catch((err) => {\n\t\t\tthis._logger.error(`Error closing timed out session ${sessionId}:`, err);\n\t\t});\n\t}\n\n\t/**\n\t * Get information about a session.\n\t *\n\t * @param sessionId - The session ID\n\t * @returns Session info or undefined if not found\n\t */\n\tgetSessionInfo(sessionId: SessionId): SessionInfo | undefined {\n\t\treturn this._sessions.get(sessionId)?.getInfo();\n\t}\n\n\t/**\n\t * Get all active sessions.\n\t *\n\t * @returns Array of session information\n\t */\n\tgetActiveSessions(): SessionInfo[] {\n\t\treturn Array.from(this._sessions.values())\n\t\t\t.filter((s) => s.isActive)\n\t\t\t.map((s) => s.getInfo());\n\t}\n\n\t/**\n\t * Get connection pool statistics.\n\t */\n\tgetStats(): ConnectionPoolStats {\n\t\tconst activeSessions = this.getActiveSessions();\n\n\t\treturn {\n\t\t\ttotalSessions: this._sessions.size,\n\t\t\tactiveSessions: activeSessions.length,\n\t\t\tmaxSessions: this._maxSessions,\n\t\t\tcleanupEnabled: this._autoCleanup,\n\t\t\tsessionTimeout: this._sessionTimeout,\n\t\t};\n\t}\n\n\t/**\n\t * Start the automatic cleanup timer.\n\t */\n\tprivate _startCleanup(): void {\n\t\tif (this._cleanupTimerId !== null) {\n\t\t\tclearInterval(this._cleanupTimerId);\n\t\t}\n\n\t\tthis._cleanupTimerId = setInterval(() => {\n\t\t\tthis._cleanupTimedOutSessions();\n\t\t}, this._cleanupInterval);\n\t}\n\n\t/**\n\t * Remove timed-out sessions.\n\t */\n\tprivate _cleanupTimedOutSessions(): void {\n\t\tlet cleaned = 0;\n\n\t\tfor (const [sessionId, session] of this._ownedSessions.entries()) {\n\t\t\tif (session.isTimedOut()) {\n\t\t\t\tthis._coordinateCleanup(sessionId).catch((err) => {\n\t\t\t\t\tthis._logger.error(`Error closing timed out session ${sessionId}:`, err);\n\t\t\t\t});\n\t\t\t\tcleaned++;\n\t\t\t}\n\t\t}\n\n\t\tif (cleaned > 0) {\n\t\t\tthis._logger.info(\n\t\t\t\t`Cleaned ${cleaned} timed-out sessions (${this._sessions.size}/${this._maxSessions} active sessions)`\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Close all sessions and stop the cleanup timer.\n\t */\n\tterminate(): Promise<void> {\n\t\tif (this._terminationGeneration) {\n\t\t\treturn this._terminationGeneration.completion.promise;\n\t\t}\n\n\t\tconst completion = Promise.withResolvers<void>();\n\t\tconst generation: TerminationGeneration = { attempts: new Map(), completion };\n\t\tthis._terminationGeneration = generation;\n\t\tthis._terminated = true;\n\n\t\t// Stop cleanup timer\n\t\tif (this._cleanupTimerId !== null) {\n\t\t\tclearInterval(this._cleanupTimerId);\n\t\t\tthis._cleanupTimerId = null;\n\t\t}\n\n\t\tconst pendingCreate = this._createSessionLock;\n\t\tfor (const sessionId of this._ownedSessions.keys()) {\n\t\t\tthis._coordinateCleanup(sessionId, generation);\n\t\t}\n\n\t\tvoid this._completeTerminationGeneration(generation, pendingCreate);\n\n\t\treturn completion.promise;\n\t}\n\n\tprivate async _completeTerminationGeneration(\n\t\tgeneration: TerminationGeneration,\n\t\tpendingCreate: Promise<void> | null\n\t): Promise<void> {\n\t\tif (pendingCreate) await pendingCreate;\n\t\tconst outcomes = await Promise.allSettled(generation.attempts.values());\n\t\tconst failures = outcomes\n\t\t\t.filter((outcome): outcome is PromiseRejectedResult => outcome.status === 'rejected')\n\t\t\t.map((outcome) => outcome.reason);\n\t\tif (failures.length > 0) {\n\t\t\tif (this._terminationGeneration === generation) this._terminationGeneration = null;\n\t\t\tgeneration.completion.reject(\n\t\t\t\tnew AggregateError(failures, 'ConnectionPool termination failed')\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tthis._logger.info('ConnectionPool terminated');\n\t\tgeneration.completion.resolve();\n\t}\n\n\t/**\n\t * Dispose of the connection pool, releasing all resources.\n\t * Implements the IDisposable interface.\n\t * Delegates to terminate() for backward compatibility.\n\t */\n\tdispose(): Promise<void> {\n\t\treturn this.terminate();\n\t}\n\n\t/**\n\t * Check if the connection pool is active.\n\t */\n\tisRunning(): boolean {\n\t\treturn !this._terminated;\n\t}\n}\n\n/**\n * Create a connection pool with the given options.\n *\n * @param options - Connection pool configuration\n * @returns A configured connection pool\n *\n * @example\n * ```typescript\n * const pool = createConnectionPool({\n * maxSessions: 50,\n * sessionTimeout: 300000\n * });\n * ```\n */\nexport function createConnectionPool(options?: SessionOptions): ConnectionPool {\n\treturn new ConnectionPool(options);\n}\n"],"names":["Session","id","server","timeout","logger","onTimeout","Date","input","SessionNotActiveError","operation","Promise","completion","undefined","clearTimeout","error","Error","AggregateError","setTimeout","err","ConnectionPool","Map","AsyncLocalStorage","options","PoolTerminatedError","MaxSessionsReachedError","resolveLock","resolve","sessionId","asSessionId","Math","session","timedOutSessionId","generation","result","SessionNotFoundError","assertNever","activeFrame","capturedSession","frame","generationAttempt","currentAttempt","attempt","Array","s","activeSessions","clearInterval","setInterval","cleaned","pendingCreate","outcomes","failures","outcome","createConnectionPool"],"mappings":";;;;;AAuEO,MAAMA;IACJ,QAAuB;IACvB,IAAe;IACf,WAAmB;IACnB,gBAAwB;IACxB,eAAwB;IACxB,SAAiB;IACjB,gBAAuC,KAAK;IAC5C,QAAgB;IAChB,gBAAsC,KAAK;IAC3C,wBAAwB,EAAE;IAC1B,kBAAqD,KAAK;IACjD,WAAoD;IAErE,YACCC,EAAa,EACbC,MAAqB,EACrBC,OAAe,EACfC,MAAc,EACdC,YAAqD,IAAI,CACxD;QACD,IAAI,CAAC,OAAO,GAAGH;QACf,IAAI,CAAC,GAAG,GAAGD;QACX,IAAI,CAAC,UAAU,GAAGK,KAAK,G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,CAAC,MAAM;QACpE,MAAMkB,WAAWD,SACf,MAAM,CAAC,CAACE,UAA8CA,AAAmB,eAAnBA,QAAQ,MAAM,EACpE,GAAG,CAAC,CAACA,UAAYA,QAAQ,MAAM;QACjC,IAAID,SAAS,MAAM,GAAG,GAAG;YACxB,IAAI,IAAI,CAAC,sBAAsB,KAAKlB,YAAY,IAAI,CAAC,sBAAsB,GAAG;YAC9EA,WAAW,UAAU,CAAC,MAAM,CAC3B,IAAIhB,eAAekC,UAAU;YAE9B;QACD;QACA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QAClBlB,WAAW,UAAU,CAAC,OAAO;IAC9B;IAOA,UAAyB;QACxB,OAAO,IAAI,CAAC,SAAS;IACtB;IAKA,YAAqB;QACpB,OAAO,CAAC,IAAI,CAAC,WAAW;IACzB;AACD;AAgBO,SAASoB,qBAAqB9B,OAAwB;IAC5D,OAAO,IAAIH,eAAeG;AAC3B"}
|
|
1
|
+
{"version":3,"file":"pool/ConnectionPool.js","sources":["../../src/pool/ConnectionPool.ts"],"sourcesContent":["/**\n * Connection Pool for managing concurrent user sessions.\n *\n * This module provides session management for multi-user scenarios,\n * allowing multiple concurrent clients to each have isolated state.\n *\n * @example\n * ```typescript\n * const pool = new ConnectionPool({\n * maxSessions: 100,\n * sessionTimeout: 300000 // 5 minutes\n * });\n *\n * const sessionId = await pool.createSession();\n * await pool.process(sessionId, thought);\n * await pool.closeSession(sessionId);\n * ```\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { MaxSessionsReachedError, PoolTerminatedError } from '../errors.js';\nimport type { Logger } from '../logger/StructuredLogger.js';\nimport { asSessionId, type SessionId } from '../contracts/ids.js';\nimport { assertNever } from '../utils.js';\nimport { SessionNotActiveError, SessionNotFoundError } from './PoolErrors.js';\nimport type {\n\tConnectionPoolStats,\n\tIConnectionPool,\n\tProcessResult,\n\tSessionInfo,\n\tSessionRunResult,\n\tSessionServer,\n\tSessionThoughtInput,\n} from './IConnectionPool.js';\n\nexport interface SessionOptions {\n\t/**\n\t * Maximum number of concurrent sessions\n\t * @default 100\n\t */\n\tmaxSessions?: number;\n\n\t/**\n\t * Logger instance\n\t */\n\tlogger?: Logger;\n\n\tserverFactory?: () => Promise<SessionServer>;\n\n\t/**\n\t * Session timeout in milliseconds\n\t * @default 300000 (5 minutes)\n\t */\n\tsessionTimeout?: number;\n\n\t/**\n\t * Whether to enable automatic session cleanup\n\t * @default true\n\t */\n\tautoCleanup?: boolean;\n\n\t/**\n\t * Cleanup interval in milliseconds\n\t * @default 60000 (1 minute)\n\t */\n\tcleanupInterval?: number;\n}\n\n/**\n * Represents a user session with its own server instance.\n */\nexport class Session {\n\tprivate _server: SessionServer;\n\tprivate _id: SessionId;\n\tprivate _createdAt: number;\n\tprivate _lastActivityAt: number;\n\tprivate _isActiveValue: boolean;\n\tprivate _timeout: number;\n\tprivate _cleanupTimer: NodeJS.Timeout | null = null;\n\tprivate _logger: Logger;\n\tprivate _closePromise: Promise<void> | null = null;\n\tprivate _activeOperationCount = 0;\n\tprivate _operationDrain: PromiseWithResolvers<void> | null = null;\n\tprivate readonly _onTimeout: ((sessionId: SessionId) => void) | null;\n\n\tconstructor(\n\t\tid: SessionId,\n\t\tserver: SessionServer,\n\t\ttimeout: number,\n\t\tlogger: Logger,\n\t\tonTimeout: ((sessionId: SessionId) => void) | null = null\n\t) {\n\t\tthis._server = server;\n\t\tthis._id = id;\n\t\tthis._createdAt = Date.now();\n\t\tthis._lastActivityAt = this._createdAt;\n\t\tthis._isActiveValue = true;\n\t\tthis._timeout = timeout;\n\t\tthis._logger = logger;\n\t\tthis._onTimeout = onTimeout;\n\n\t\t// Start session timeout timer\n\t\tthis._startTimeout();\n\t}\n\n\t/**\n\t * Check if the session is active.\n\t */\n\tget isActive(): boolean {\n\t\treturn this._isActiveValue;\n\t}\n\n\t/**\n\t * Process a thought through this session's server instance.\n\t */\n\tasync process(input: SessionThoughtInput): Promise<ProcessResult> {\n\t\tif (!this.isActive) {\n\t\t\tthrow new SessionNotActiveError(this._id);\n\t\t}\n\n\t\t// Update last activity\n\t\tthis._lastActivityAt = Date.now();\n\n\t\t// Reset timeout timer\n\t\tthis._resetTimeout();\n\n\t\t// Process the thought\n\t\treturn this._server.processThought(input);\n\t}\n\n\tprocessAdmitted(input: SessionThoughtInput): Promise<ProcessResult> {\n\t\tthis._lastActivityAt = Date.now();\n\t\tif (this.isActive) this._resetTimeout();\n\t\treturn this._server.processThought(input);\n\t}\n\n\trunWhileActive<T>(operation: (session: Session) => Promise<T>): Promise<SessionRunResult<T>> {\n\t\tif (!this.isActive) return Promise.resolve({ status: 'inactive' });\n\t\tthis._activeOperationCount++;\n\t\treturn (async () => {\n\t\t\ttry {\n\t\t\t\treturn { status: 'completed', value: await operation(this) };\n\t\t\t} finally {\n\t\t\t\tthis._activeOperationCount--;\n\t\t\t\tif (this._activeOperationCount === 0) this._operationDrain?.resolve();\n\t\t\t}\n\t\t})();\n\t}\n\n\t/**\n\t * Get session information.\n\t */\n\tgetInfo(): SessionInfo {\n\t\treturn {\n\t\t\tid: this._id,\n\t\t\tserver: this._server,\n\t\t\tcreatedAt: this._createdAt,\n\t\t\tlastActivityAt: this._lastActivityAt,\n\t\t\tisActive: this.isActive,\n\t\t};\n\t}\n\n\t/**\n\t * Check if the session has timed out.\n\t */\n\tisTimedOut(): boolean {\n\t\treturn Date.now() - this._lastActivityAt > this._timeout;\n\t}\n\n\t/**\n\t * Close the session and stop the server.\n\t */\n\tclose(): Promise<void> {\n\t\tif (this._closePromise) {\n\t\t\treturn this._closePromise;\n\t\t}\n\n\t\tconst completion = Promise.withResolvers<void>();\n\t\tthis._closePromise = completion.promise;\n\t\tvoid completion.promise.then(undefined, () => {\n\t\t\tif (this._closePromise === completion.promise) this._closePromise = null;\n\t\t});\n\t\tthis._isActiveValue = false;\n\n\t\t// Stop timeout timer\n\t\tif (this._cleanupTimer) {\n\t\t\tclearTimeout(this._cleanupTimer);\n\t\t\tthis._cleanupTimer = null;\n\t\t}\n\n\t\tif (this._activeOperationCount === 0) {\n\t\t\tthis._stopServer(completion);\n\t\t} else {\n\t\t\tthis._operationDrain = Promise.withResolvers<void>();\n\t\t\tvoid this._operationDrain.promise.then(() => this._stopServer(completion));\n\t\t}\n\n\t\treturn completion.promise;\n\t}\n\n\tprivate _stopServer(completion: PromiseWithResolvers<void>): void {\n\t\ttry {\n\t\t\tPromise.resolve(this._server.stop()).then(completion.resolve, completion.reject);\n\t\t} catch (error) {\n\t\t\tcompletion.reject(\n\t\t\t\terror instanceof Error ? error : new AggregateError([error], 'Session stop failed')\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Start the session timeout timer.\n\t */\n\tprivate _startTimeout(): void {\n\t\tif (this._cleanupTimer) {\n\t\t\tclearTimeout(this._cleanupTimer);\n\t\t}\n\n\t\tthis._cleanupTimer = setTimeout(() => {\n\t\t\tif (this.isTimedOut()) {\n\t\t\t\tthis._logger.warn(`Session ${this._id} timed out, closing`);\n\t\t\t\tif (this._onTimeout) {\n\t\t\t\t\tthis._onTimeout(this._id);\n\t\t\t\t} else {\n\t\t\t\t\tthis.close().catch((err) => {\n\t\t\t\t\t\tthis._logger.error(`Error closing timed out session ${this._id}:`, err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}, this._timeout);\n\t}\n\n\t/**\n\t * Reset the timeout timer after activity.\n\t */\n\tprivate _resetTimeout(): void {\n\t\tthis._startTimeout();\n\t}\n}\n\ninterface TerminationGeneration {\n\treadonly attempts: Map<SessionId, Promise<void>>;\n\treadonly completion: PromiseWithResolvers<void>;\n}\n\n/**\n * ConnectionPool manages multiple concurrent user sessions.\n *\n * Each session has its own server instance with isolated state,\n * allowing multiple users to interact with the system simultaneously.\n */\nexport class ConnectionPool implements IConnectionPool {\n\tprivate _sessions: Map<SessionId, Session> = new Map();\n\tprivate readonly _ownedSessions = new Map<SessionId, Session>();\n\tprivate readonly _closingSessions = new Map<SessionId, Promise<void>>();\n\tprivate _createSessionLock: Promise<void> | null = null;\n\tprivate _maxSessions: number;\n\tprivate _sessionTimeout: number;\n\tprivate _autoCleanup: boolean;\n\tprivate _cleanupInterval: number;\n\tprivate _cleanupTimerId: ReturnType<typeof setInterval> | null = null;\n\tprivate _terminated: boolean = false;\n\tprivate _logger: Logger;\n\tprivate _serverFactory: (() => Promise<SessionServer>) | null;\n\tprivate _terminationGeneration: TerminationGeneration | null = null;\n\tprivate readonly _admissionContext = new AsyncLocalStorage<{\n\t\treadonly sessionId: SessionId;\n\t\treadonly session: Session;\n\t\topen: boolean;\n\t}>();\n\n\tconstructor(options: SessionOptions = {}) {\n\t\tthis._maxSessions = options.maxSessions ?? 100;\n\t\tthis._sessionTimeout = options.sessionTimeout ?? 300000; // 5 minutes\n\t\tthis._autoCleanup = options.autoCleanup ?? true;\n\t\tthis._cleanupInterval = options.cleanupInterval ?? 60000; // 1 minute\n\t\tthis._serverFactory = options.serverFactory ?? null;\n\t\tthis._logger = options.logger ?? this._createNoopLogger();\n\n\t\tif (this._autoCleanup) {\n\t\t\tthis._startCleanup();\n\t\t}\n\t}\n\n\t/**\n\t * Create a no-op logger when none is provided.\n\t */\n\tprivate _createNoopLogger(): Logger {\n\t\treturn {\n\t\t\tinfo: (): void => {},\n\t\t\twarn: (): void => {},\n\t\t\terror: (): void => {},\n\t\t\tdebug: (): void => {},\n\t\t\tsetLevel: (): void => {},\n\t\t\tgetLevel: (): 'info' => 'info',\n\t\t};\n\t}\n\n\t/**\n\t * Create a new session.\n\t *\n\t * @returns The session ID\n\t * @throws Error if max sessions reached\n\t */\n\tasync createSession(): Promise<SessionId> {\n\t\twhile (this._createSessionLock) {\n\t\t\tawait this._createSessionLock;\n\t\t}\n\n\t\tif (this._terminated) {\n\t\t\tthrow new PoolTerminatedError();\n\t\t}\n\n\t\tif (this._ownedSessions.size >= this._maxSessions) {\n\t\t\tthrow new MaxSessionsReachedError(this._maxSessions);\n\t\t}\n\n\t\tif (!this._serverFactory) {\n\t\t\tthrow new Error('ConnectionPool requires a serverFactory option to create sessions');\n\t\t}\n\n\t\tlet resolveLock!: () => void;\n\t\tthis._createSessionLock = new Promise<void>((resolve) => {\n\t\t\tresolveLock = resolve;\n\t\t});\n\n\t\ttry {\n\t\t\t// Generate unique session ID\n\t\t\tconst sessionId = asSessionId(\n\t\t\t\t`session_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`\n\t\t\t);\n\t\t\tif (this._ownedSessions.has(sessionId)) {\n\t\t\t\tthrow new Error(`Session ID collision: ${sessionId}`);\n\t\t\t}\n\n\t\t\t// Create a new server instance for this session\n\t\t\tconst server = await this._serverFactory();\n\t\t\tconst session = new Session(\n\t\t\t\tsessionId,\n\t\t\t\tserver,\n\t\t\t\tthis._sessionTimeout,\n\t\t\t\tthis._logger,\n\t\t\t\t(timedOutSessionId) => this._handleSessionTimeout(timedOutSessionId)\n\t\t\t);\n\t\t\tthis._ownedSessions.set(sessionId, session);\n\t\t\tif (this._terminated) {\n\t\t\t\tconst generation = this._terminationGeneration;\n\t\t\t\tif (generation) {\n\t\t\t\t\tawait this._coordinateCleanup(sessionId, generation);\n\t\t\t\t} else {\n\t\t\t\t\tawait this._coordinateCleanup(sessionId);\n\t\t\t\t}\n\t\t\t\tthrow new PoolTerminatedError();\n\t\t\t}\n\n\t\t\tthis._sessions.set(sessionId, session);\n\n\t\t\tthis._logger.info(\n\t\t\t\t`Created session ${sessionId} (${this._sessions.size}/${this._maxSessions} active sessions)`\n\t\t\t);\n\t\t\treturn sessionId;\n\t\t} finally {\n\t\t\tresolveLock();\n\t\t\tthis._createSessionLock = null;\n\t\t}\n\t}\n\n\t/**\n\t * Process a thought in the specified session.\n\t *\n\t * @param poolSessionId - The pool slot ID, distinct from `input.session_id`\n\t * @param input - The thought data to process\n\t * @returns Promise with the processing result\n\t * @throws Error if session not found\n\t */\n\tasync process(poolSessionId: SessionId, input: SessionThoughtInput): Promise<ProcessResult> {\n\t\tconst result = await this._runWithSession(poolSessionId, (session) =>\n\t\t\tsession.processAdmitted(input)\n\t\t);\n\t\tswitch (result.status) {\n\t\t\tcase 'completed':\n\t\t\t\treturn result.value;\n\t\t\tcase 'inactive':\n\t\t\t\tthrow new SessionNotActiveError(poolSessionId);\n\t\t\tcase 'missing':\n\t\t\t\tthrow new SessionNotFoundError(poolSessionId);\n\t\t\tdefault:\n\t\t\t\treturn assertNever(result);\n\t\t}\n\t}\n\n\trunWithSession<T>(\n\t\tsessionId: SessionId,\n\t\toperation: (session: SessionServer) => Promise<T>\n\t): Promise<SessionRunResult<T>> {\n\t\treturn this._runWithSession(sessionId, (session) => operation(session.getInfo().server));\n\t}\n\n\tprivate _runWithSession<T>(\n\t\tsessionId: SessionId,\n\t\toperation: (session: Session) => Promise<T>\n\t): Promise<SessionRunResult<T>> {\n\t\tconst activeFrame = this._admissionContext.getStore();\n\t\tif (activeFrame?.open === true && activeFrame.sessionId === sessionId) {\n\t\t\treturn (async () => ({ status: 'completed', value: await operation(activeFrame.session) }))();\n\t\t}\n\n\t\tconst session = this._sessions.get(sessionId);\n\t\tif (!session) {\n\t\t\treturn Promise.resolve(\n\t\t\t\tthis._ownedSessions.has(sessionId) ? { status: 'inactive' } : { status: 'missing' }\n\t\t\t);\n\t\t}\n\n\t\treturn session.runWhileActive((capturedSession) => {\n\t\t\tconst frame = { sessionId, session: capturedSession, open: true };\n\t\t\treturn this._admissionContext.run(frame, async () => {\n\t\t\t\ttry {\n\t\t\t\t\treturn await operation(capturedSession);\n\t\t\t\t} finally {\n\t\t\t\t\tframe.open = false;\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Close a session and release resources.\n\t *\n\t * @param sessionId - The session ID to close\n\t * @throws Error if session not found\n\t */\n\tcloseSession(sessionId: SessionId): Promise<void> {\n\t\tif (!this._ownedSessions.has(sessionId)) {\n\t\t\treturn Promise.reject(new SessionNotFoundError(sessionId));\n\t\t}\n\n\t\tconst generation = this._terminationGeneration;\n\t\treturn generation\n\t\t\t? this._coordinateCleanup(sessionId, generation)\n\t\t\t: this._coordinateCleanup(sessionId);\n\t}\n\n\tprivate _coordinateCleanup(\n\t\tsessionId: SessionId,\n\t\tgeneration?: TerminationGeneration\n\t): Promise<void> {\n\t\tconst generationAttempt = generation?.attempts.get(sessionId);\n\t\tif (generationAttempt) return generationAttempt;\n\n\t\tconst session = this._ownedSessions.get(sessionId);\n\t\tif (!session) return Promise.reject(new SessionNotFoundError(sessionId));\n\n\t\tthis._sessions.delete(sessionId);\n\t\tconst currentAttempt = this._closingSessions.get(sessionId);\n\t\tconst attempt = currentAttempt ?? session.close();\n\t\tif (!currentAttempt) this._closingSessions.set(sessionId, attempt);\n\t\tgeneration?.attempts.set(sessionId, attempt);\n\n\t\tif (!currentAttempt)\n\t\t\tvoid attempt.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (this._closingSessions.get(sessionId) === attempt) {\n\t\t\t\t\t\tthis._closingSessions.delete(sessionId);\n\t\t\t\t\t}\n\t\t\t\t\tif (this._ownedSessions.get(sessionId) === session) {\n\t\t\t\t\t\tthis._ownedSessions.delete(sessionId);\n\t\t\t\t\t}\n\t\t\t\t\tthis._logger.info(\n\t\t\t\t\t\t`Closed session ${sessionId} (${this._sessions.size}/${this._maxSessions} active sessions)`\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tif (this._closingSessions.get(sessionId) === attempt) {\n\t\t\t\t\t\tthis._closingSessions.delete(sessionId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\treturn attempt;\n\t}\n\n\tprivate _handleSessionTimeout(sessionId: SessionId): void {\n\t\tconst generation = this._terminationGeneration;\n\t\tconst attempt = generation\n\t\t\t? this._coordinateCleanup(sessionId, generation)\n\t\t\t: this._coordinateCleanup(sessionId);\n\t\tvoid attempt.catch((err) => {\n\t\t\tthis._logger.error(`Error closing timed out session ${sessionId}:`, err);\n\t\t});\n\t}\n\n\t/**\n\t * Get information about a session.\n\t *\n\t * @param sessionId - The session ID\n\t * @returns Session info or undefined if not found\n\t */\n\tgetSessionInfo(sessionId: SessionId): SessionInfo | undefined {\n\t\treturn this._sessions.get(sessionId)?.getInfo();\n\t}\n\n\t/**\n\t * Get all active sessions.\n\t *\n\t * @returns Array of session information\n\t */\n\tgetActiveSessions(): SessionInfo[] {\n\t\treturn Array.from(this._sessions.values())\n\t\t\t.filter((s) => s.isActive)\n\t\t\t.map((s) => s.getInfo());\n\t}\n\n\t/**\n\t * Get connection pool statistics.\n\t */\n\tgetStats(): ConnectionPoolStats {\n\t\tconst activeSessions = this.getActiveSessions();\n\n\t\treturn {\n\t\t\ttotalSessions: this._sessions.size,\n\t\t\tactiveSessions: activeSessions.length,\n\t\t\tmaxSessions: this._maxSessions,\n\t\t\tcleanupEnabled: this._autoCleanup,\n\t\t\tsessionTimeout: this._sessionTimeout,\n\t\t};\n\t}\n\n\t/**\n\t * Start the automatic cleanup timer.\n\t */\n\tprivate _startCleanup(): void {\n\t\tif (this._cleanupTimerId !== null) {\n\t\t\tclearInterval(this._cleanupTimerId);\n\t\t}\n\n\t\tthis._cleanupTimerId = setInterval(() => {\n\t\t\tthis._cleanupTimedOutSessions();\n\t\t}, this._cleanupInterval);\n\t}\n\n\t/**\n\t * Remove timed-out sessions.\n\t */\n\tprivate _cleanupTimedOutSessions(): void {\n\t\tlet cleaned = 0;\n\n\t\tfor (const [sessionId, session] of this._ownedSessions.entries()) {\n\t\t\tif (session.isTimedOut()) {\n\t\t\t\tthis._coordinateCleanup(sessionId).catch((err) => {\n\t\t\t\t\tthis._logger.error(`Error closing timed out session ${sessionId}:`, err);\n\t\t\t\t});\n\t\t\t\tcleaned++;\n\t\t\t}\n\t\t}\n\n\t\tif (cleaned > 0) {\n\t\t\tthis._logger.info(\n\t\t\t\t`Cleaned ${cleaned} timed-out sessions (${this._sessions.size}/${this._maxSessions} active sessions)`\n\t\t\t);\n\t\t}\n\t}\n\n\tdispose(): Promise<void> {\n\t\tif (this._terminationGeneration) {\n\t\t\treturn this._terminationGeneration.completion.promise;\n\t\t}\n\n\t\tconst completion = Promise.withResolvers<void>();\n\t\tconst generation: TerminationGeneration = { attempts: new Map(), completion };\n\t\tthis._terminationGeneration = generation;\n\t\tthis._terminated = true;\n\n\t\t// Stop cleanup timer\n\t\tif (this._cleanupTimerId !== null) {\n\t\t\tclearInterval(this._cleanupTimerId);\n\t\t\tthis._cleanupTimerId = null;\n\t\t}\n\n\t\tconst pendingCreate = this._createSessionLock;\n\t\tfor (const sessionId of this._ownedSessions.keys()) {\n\t\t\tthis._coordinateCleanup(sessionId, generation);\n\t\t}\n\n\t\tvoid this._completeTerminationGeneration(generation, pendingCreate);\n\n\t\treturn completion.promise;\n\t}\n\n\tprivate async _completeTerminationGeneration(\n\t\tgeneration: TerminationGeneration,\n\t\tpendingCreate: Promise<void> | null\n\t): Promise<void> {\n\t\tif (pendingCreate) await pendingCreate;\n\t\tconst outcomes = await Promise.allSettled(generation.attempts.values());\n\t\tconst failures = outcomes\n\t\t\t.filter((outcome): outcome is PromiseRejectedResult => outcome.status === 'rejected')\n\t\t\t.map((outcome) => outcome.reason);\n\t\tif (failures.length > 0) {\n\t\t\tif (this._terminationGeneration === generation) this._terminationGeneration = null;\n\t\t\tgeneration.completion.reject(\n\t\t\t\tnew AggregateError(failures, 'ConnectionPool termination failed')\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tthis._logger.info('ConnectionPool terminated');\n\t\tgeneration.completion.resolve();\n\t}\n\n\t/**\n\t * Check if the connection pool is active.\n\t */\n\tisRunning(): boolean {\n\t\treturn !this._terminated;\n\t}\n}\n\n/**\n * Create a connection pool with the given options.\n *\n * @param options - Connection pool configuration\n * @returns A configured connection pool\n *\n * @example\n * ```typescript\n * const pool = createConnectionPool({\n * maxSessions: 50,\n * sessionTimeout: 300000\n * });\n * ```\n */\nexport function createConnectionPool(options?: SessionOptions): ConnectionPool {\n\treturn new ConnectionPool(options);\n}\n"],"names":["Session","id","server","timeout","logger","onTimeout","Date","input","SessionNotActiveError","operation","Promise","completion","undefined","clearTimeout","error","Error","AggregateError","setTimeout","err","ConnectionPool","Map","AsyncLocalStorage","options","PoolTerminatedError","MaxSessionsReachedError","resolveLock","resolve","sessionId","asSessionId","Math","session","timedOutSessionId","generation","poolSessionId","result","SessionNotFoundError","assertNever","activeFrame","capturedSession","frame","generationAttempt","currentAttempt","attempt","Array","s","activeSessions","clearInterval","setInterval","cleaned","pendingCreate","outcomes","failures","outcome","createConnectionPool"],"mappings":";;;;;AAuEO,MAAMA;IACJ,QAAuB;IACvB,IAAe;IACf,WAAmB;IACnB,gBAAwB;IACxB,eAAwB;IACxB,SAAiB;IACjB,gBAAuC,KAAK;IAC5C,QAAgB;IAChB,gBAAsC,KAAK;IAC3C,wBAAwB,EAAE;IAC1B,kBAAqD,KAAK;IACjD,WAAoD;IAErE,YACCC,EAAa,EACbC,MAAqB,EACrBC,OAAe,EACfC,MAAc,EACdC,YAAqD,IAAI,CACxD;QACD,IAAI,CAAC,OAAO,GAAGH;QACf,IAAI,CAAC,GAAG,GAAGD;QACX,IAAI,CAAC,UAAU,GAAGK,KAAK,GAAG;QAC1B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,UAAU;QACtC,IAAI,CAAC,cAAc,GAAG;QACtB,IAAI,CAAC,QAAQ,GAAGH;QAChB,IAAI,CAAC,OAAO,GAAGC;QACf,IAAI,CAAC,UAAU,GAAGC;QAGlB,IAAI,CAAC,aAAa;IACnB;IAKA,IAAI,WAAoB;QACvB,OAAO,IAAI,CAAC,cAAc;IAC3B;IAKA,MAAM,QAAQE,KAA0B,EAA0B;QACjE,IAAI,CAAC,IAAI,CAAC,QAAQ,EACjB,MAAM,IAAIC,sBAAsB,IAAI,CAAC,GAAG;QAIzC,IAAI,CAAC,eAAe,GAAGF,KAAK,GAAG;QAG/B,IAAI,CAAC,aAAa;QAGlB,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAACC;IACpC;IAEA,gBAAgBA,KAA0B,EAA0B;QACnE,IAAI,C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12 +82,12 @@ export interface IConnectionPool extends IDisposable {
|
|
|
82
82
|
/**
|
|
83
83
|
* Process a thought in the specified session.
|
|
84
84
|
*
|
|
85
|
-
* @param
|
|
85
|
+
* @param poolSessionId - The pool slot ID, distinct from `input.session_id`
|
|
86
86
|
* @param input - The thought data to process
|
|
87
87
|
* @returns The processing result
|
|
88
88
|
* @throws SessionNotFoundError if the session does not exist
|
|
89
89
|
*/
|
|
90
|
-
process(
|
|
90
|
+
process(poolSessionId: SessionId, input: SessionThoughtInput): Promise<ProcessResult>;
|
|
91
91
|
/**
|
|
92
92
|
* Run an operation while atomically holding an active session open.
|
|
93
93
|
*
|
|
@@ -122,15 +122,9 @@ export interface IConnectionPool extends IDisposable {
|
|
|
122
122
|
* @returns A snapshot of the pool's statistics
|
|
123
123
|
*/
|
|
124
124
|
getStats(): ConnectionPoolStats;
|
|
125
|
-
/**
|
|
126
|
-
* Close all sessions and stop the cleanup timer.
|
|
127
|
-
*/
|
|
128
|
-
terminate(): Promise<void>;
|
|
129
125
|
/**
|
|
130
126
|
* Dispose of the connection pool, releasing all resources.
|
|
131
|
-
*
|
|
132
|
-
* Implements the {@link IDisposable} interface. Typically delegates
|
|
133
|
-
* to {@link IConnectionPool.terminate}.
|
|
127
|
+
* Implements the {@link IDisposable} interface.
|
|
134
128
|
*/
|
|
135
129
|
dispose(): Promise<void>;
|
|
136
130
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IConnectionPool.d.ts","sourceRoot":"","sources":["../../src/pool/IConnectionPool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,MAAM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MAAM,EAAE,SAAS,CAAA;CAAE,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,eAAgB,SAAQ,WAAW;IACnD;;;;;;OAMG;IACH,aAAa,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;IAEpC;;;;;;;OAOG;IACH,OAAO,CAAC,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAEtF;;;;;;OAMG;IACH,cAAc,CAAC,CAAC,EACf,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,GAC/C,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhC;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD;;;;;OAKG;IACH,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;IAE9D;;;;OAIG;IACH,iBAAiB,IAAI,WAAW,EAAE,CAAC;IAEnC;;;;OAIG;IACH,QAAQ,IAAI,mBAAmB,CAAC;IAEhC;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;;;OAIG;IACH,SAAS,IAAI,OAAO,CAAC;CACrB"}
|
|
@@ -43,8 +43,7 @@ export interface SkillRegistryOptions {
|
|
|
43
43
|
/**
|
|
44
44
|
* Registry for managing Claude Code skill operations.
|
|
45
45
|
*
|
|
46
|
-
* Extends `BaseRegistry<Skill>` with skill-specific frontmatter parsing
|
|
47
|
-
* and backward-compatible aliases (`addSkill`, etc.).
|
|
46
|
+
* Extends `BaseRegistry<Skill>` with skill-specific frontmatter parsing.
|
|
48
47
|
*/
|
|
49
48
|
export declare class SkillRegistry extends BaseRegistry<Skill> {
|
|
50
49
|
protected readonly _fileExtensions: string[];
|
|
@@ -58,10 +57,5 @@ export declare class SkillRegistry extends BaseRegistry<Skill> {
|
|
|
58
57
|
_error?: string;
|
|
59
58
|
};
|
|
60
59
|
protected _buildItem(parsed: Partial<Skill>): Skill | null;
|
|
61
|
-
addSkill(skill: Skill): void;
|
|
62
|
-
updateSkill(name: string, updates: Partial<Skill>): void;
|
|
63
|
-
hasSkill(name: string): boolean;
|
|
64
|
-
getSkill(name: string): Skill | undefined;
|
|
65
|
-
setSkills(skills: Skill[]): void;
|
|
66
60
|
}
|
|
67
61
|
//# sourceMappingURL=SkillRegistry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SkillRegistry.d.ts","sourceRoot":"","sources":["../../src/registry/SkillRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,oBAAoB;IACpC,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,wCAAwC;IACxC,KAAK,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;IAE9B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAErB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED
|
|
1
|
+
{"version":3,"file":"SkillRegistry.d.ts","sour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: parsed.allowed_tools
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
addSkill(skill) {
|
|
70
|
-
this.add(skill);
|
|
71
|
-
}
|
|
72
|
-
updateSkill(name, updates) {
|
|
73
|
-
this.update(name, updates);
|
|
74
|
-
}
|
|
75
|
-
hasSkill(name) {
|
|
76
|
-
return this.has(name);
|
|
77
|
-
}
|
|
78
|
-
getSkill(name) {
|
|
79
|
-
return this.get(name);
|
|
80
|
-
}
|
|
81
|
-
setSkills(skills) {
|
|
82
|
-
this.setAll(skills);
|
|
83
|
-
}
|
|
84
69
|
}
|
|
85
70
|
export { SkillRegistry };
|
|
86
71
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry/SkillRegistry.js","sources":["../../src/registry/SkillRegistry.ts"],"sourcesContent":["/**\n * Skill registry for managing and discovering Claude Code skills.\n *\n * This module provides the `SkillRegistry` class which manages skill registration,\n * discovery from filesystem directories, and CRUD operations. Skills are higher-level\n * workflows that coordinate multiple tools and operations.\n *\n * @module registry\n */\n\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\nimport type { DiscoveryCache } from '../cache/DiscoveryCache.js';\nimport { DuplicateSkillError, InvalidSkillError, SkillNotFoundError } from '../errors.js';\nimport type { Logger } from '../logger/StructuredLogger.js';\nimport type { Skill } from '../types/skill.js';\nimport { BaseRegistry } from './BaseRegistry.js';\n\n/**\n * Configuration options for creating a `SkillRegistry` instance.\n *\n * @example\n * ```typescript\n * const options: SkillRegistryOptions = {\n * logger: new StructuredLogger({ context: 'SkillRegistry' }),\n * cache: new DiscoveryCache({ ttl: 300000, maxSize: 100 }),\n * skillDirs: ['./custom-skills', '~/.claude/skills'],\n * lazyDiscovery: true\n * };\n * ```\n */\nexport interface SkillRegistryOptions {\n\t/** Optional logger for diagnostics. */\n\tlogger?: Logger;\n\n\t/** Optional cache for skill lookups. */\n\tcache?: DiscoveryCache<Skill>;\n\n\t/**\n\t * Directory paths to search for skills.\n\t * @default ['.claude/skills', '~/.claude/skills', '.agents/skills', '~/.agents/skills']\n\t */\n\tskillDirs?: string[];\n\n\t/**\n\t * Enable lazy discovery (discover on first access instead of startup).\n\t * @default false\n\t */\n\tlazyDiscovery?: boolean;\n}\n\n/**\n * Registry for managing Claude Code skill operations.\n *\n * Extends `BaseRegistry<Skill>` with skill-specific frontmatter parsing
|
|
1
|
+
{"version":3,"file":"registry/SkillRegistry.js","sources":["../../src/registry/SkillRegistry.ts"],"sourcesContent":["/**\n * Skill registry for managing and discovering Claude Code skills.\n *\n * This module provides the `SkillRegistry` class which manages skill registration,\n * discovery from filesystem directories, and CRUD operations. Skills are higher-level\n * workflows that coordinate multiple tools and operations.\n *\n * @module registry\n */\n\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\nimport type { DiscoveryCache } from '../cache/DiscoveryCache.js';\nimport { DuplicateSkillError, InvalidSkillError, SkillNotFoundError } from '../errors.js';\nimport type { Logger } from '../logger/StructuredLogger.js';\nimport type { Skill } from '../types/skill.js';\nimport { BaseRegistry } from './BaseRegistry.js';\n\n/**\n * Configuration options for creating a `SkillRegistry` instance.\n *\n * @example\n * ```typescript\n * const options: SkillRegistryOptions = {\n * logger: new StructuredLogger({ context: 'SkillRegistry' }),\n * cache: new DiscoveryCache({ ttl: 300000, maxSize: 100 }),\n * skillDirs: ['./custom-skills', '~/.claude/skills'],\n * lazyDiscovery: true\n * };\n * ```\n */\nexport interface SkillRegistryOptions {\n\t/** Optional logger for diagnostics. */\n\tlogger?: Logger;\n\n\t/** Optional cache for skill lookups. */\n\tcache?: DiscoveryCache<Skill>;\n\n\t/**\n\t * Directory paths to search for skills.\n\t * @default ['.claude/skills', '~/.claude/skills', '.agents/skills', '~/.agents/skills']\n\t */\n\tskillDirs?: string[];\n\n\t/**\n\t * Enable lazy discovery (discover on first access instead of startup).\n\t * @default false\n\t */\n\tlazyDiscovery?: boolean;\n}\n\n/**\n * Registry for managing Claude Code skill operations.\n *\n * Extends `BaseRegistry<Skill>` with skill-specific frontmatter parsing.\n */\nexport class SkillRegistry extends BaseRegistry<Skill> {\n\tprotected override readonly _fileExtensions = ['.md', '.yml', '.yaml'];\n\tprotected override readonly _entityName = 'skill';\n\n\tconstructor(options: SkillRegistryOptions = {}) {\n\t\tsuper({\n\t\t\tlogger: options.logger,\n\t\t\tcache: options.cache,\n\t\t\tsearchDirs: options.skillDirs ?? [\n\t\t\t\t'.claude/skills',\n\t\t\t\tjoin(homedir(), '.claude/skills'),\n\t\t\t\t'.agents/skills',\n\t\t\t\tjoin(homedir(), '.agents/skills'),\n\t\t\t],\n\t\t\tlazyDiscovery: options.lazyDiscovery,\n\t\t});\n\t}\n\n\t// --- Error factories ---\n\n\tprotected override _createInvalidError(reason: string): Error {\n\t\treturn new InvalidSkillError(reason);\n\t}\n\n\tprotected override _createDuplicateError(name: string): Error {\n\t\treturn new DuplicateSkillError(name);\n\t}\n\n\tprotected override _createNotFoundError(name: string, action: string): Error {\n\t\treturn new SkillNotFoundError(name, action);\n\t}\n\n\t// --- Discovery ---\n\n\tprotected override _shouldSkipFile(fileName: string): boolean {\n\t\treturn fileName === '.DS_Store';\n\t}\n\n\tprotected override _parseFrontmatter(content: string): Partial<Skill> & { _error?: string } {\n\t\tconst frontmatter = this._extractFrontmatter(content);\n\t\tif (!frontmatter) {\n\t\t\treturn {};\n\t\t}\n\n\t\ttry {\n\t\t\tconst result: Partial<Skill> = {\n\t\t\t\tname: typeof frontmatter.name === 'string' ? frontmatter.name : undefined,\n\t\t\t\tdescription: typeof frontmatter.description === 'string' ? frontmatter.description : '',\n\t\t\t\tuser_invocable: frontmatter['user-invocable'] === true,\n\t\t\t\tallowed_tools: Array.isArray(frontmatter['allowed-tools'])\n\t\t\t\t\t? frontmatter['allowed-tools'].map(String)\n\t\t\t\t\t: undefined,\n\t\t\t};\n\n\t\t\tif (!result.name) {\n\t\t\t\treturn { _error: 'Missing required field: name' };\n\t\t\t}\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthis.log('Error parsing YAML frontmatter:', {\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t\treturn { _error: 'YAML parse error' };\n\t\t}\n\t}\n\n\tprotected override _buildItem(parsed: Partial<Skill>): Skill | null {\n\t\tif (!parsed.name) {\n\t\t\treturn null;\n\t\t}\n\t\treturn {\n\t\t\tname: parsed.name,\n\t\t\tdescription: parsed.description || '',\n\t\t\tuser_invocable: parsed.user_invocable ?? false,\n\t\t\tallowed_tools: parsed.allowed_tools,\n\t\t};\n\t}\n}\n"],"names":["SkillRegistry","BaseRegistry","options","join","homedir","reason","InvalidSkillError","name","DuplicateSkillError","action","SkillNotFoundError","fileName","content","frontmatter","result","undefined","Array","String","error","Error","parsed"],"mappings":";;;;AAwDO,MAAMA,sBAAsBC;IACN,kBAAkB;QAAC;QAAO;QAAQ;KAAQ,CAAC;IAC3C,cAAc,QAAQ;IAElD,YAAYC,UAAgC,CAAC,CAAC,CAAE;QAC/C,KAAK,CAAC;YACL,QAAQA,QAAQ,MAAM;YACtB,OAAOA,QAAQ,KAAK;YACpB,YAAYA,QAAQ,SAAS,IAAI;gBAChC;gBACAC,KAAKC,WAAW;gBAChB;gBACAD,KAAKC,WAAW;aAChB;YACD,eAAeF,QAAQ,aAAa;QACrC;IACD;IAImB,oBAAoBG,MAAc,EAAS;QAC7D,OAAO,IAAIC,kBAAkBD;IAC9B;IAEmB,sBAAsBE,IAAY,EAAS;QAC7D,OAAO,IAAIC,oBAAoBD;IAChC;IAEmB,qBAAqBA,IAAY,EAAEE,MAAc,EAAS;QAC5E,OAAO,IAAIC,mBAAmBH,MAAME;IACrC;IAImB,gBAAgBE,QAAgB,EAAW;QAC7D,OAAOA,AAAa,gBAAbA;IACR;IAEmB,kBAAkBC,OAAe,EAAwC;QAC3F,MAAMC,cAAc,IAAI,CAAC,mBAAmB,CAACD;QAC7C,IAAI,CAACC,aACJ,OAAO,CAAC;QAGT,IAAI;YACH,MAAMC,SAAyB;gBAC9B,MAAM,AAA4B,YAA5B,OAAOD,YAAY,IAAI,GAAgBA,YAAY,IAAI,GAAGE;gBAChE,aAAa,AAAmC,YAAnC,OAAOF,YAAY,WAAW,GAAgBA,YAAY,WAAW,GAAG;gBACrF,gBAAgBA,AAAkC,SAAlCA,WAAW,CAAC,iBAAiB;gBAC7C,eAAeG,MAAM,OAAO,CAACH,WAAW,CAAC,gBAAgB,IACtDA,WAAW,CAAC,gBAAgB,CAAC,GAAG,CAACI,UACjCF;YACJ;YAEA,IAAI,CAACD,OAAO,IAAI,EACf,OAAO;gBAAE,QAAQ;YAA+B;YAGjD,OAAOA;QACR,EAAE,OAAOI,OAAO;YACf,IAAI,CAAC,GAAG,CAAC,mCAAmC;gBAC3C,OAAOA,iBAAiBC,QAAQD,MAAM,OAAO,GAAGD,OAAOC;YACxD;YACA,OAAO;gBAAE,QAAQ;YAAmB;QACrC;IACD;IAEmB,WAAWE,MAAsB,EAAgB;QACnE,IAAI,CAACA,OAAO,IAAI,EACf,OAAO;QAER,OAAO;YACN,MAAMA,OAAO,IAAI;YACjB,aAAaA,OAAO,WAAW,IAAI;YACnC,gBAAgBA,OAAO,cAAc,IAAI;YACzC,eAAeA,OAAO,aAAa;QACpC;IACD;AACD"}
|
|
@@ -43,8 +43,7 @@ export interface ToolRegistryOptions {
|
|
|
43
43
|
/**
|
|
44
44
|
* Registry for managing MCP tool operations.
|
|
45
45
|
*
|
|
46
|
-
* Extends `BaseRegistry<Tool>` with tool-specific frontmatter parsing
|
|
47
|
-
* and backward-compatible aliases (`addTool`, `removeTool`, etc.).
|
|
46
|
+
* Extends `BaseRegistry<Tool>` with tool-specific frontmatter parsing.
|
|
48
47
|
*/
|
|
49
48
|
export declare class ToolRegistry extends BaseRegistry<Tool> {
|
|
50
49
|
protected readonly _fileExtensions: string[];
|
|
@@ -59,12 +58,5 @@ export declare class ToolRegistry extends BaseRegistry<Tool> {
|
|
|
59
58
|
};
|
|
60
59
|
protected _buildItem(parsed: Partial<Tool>): Tool | null;
|
|
61
60
|
get(name: string): Tool | undefined;
|
|
62
|
-
addTool(tool: Tool): void;
|
|
63
|
-
removeTool(name: string): void;
|
|
64
|
-
updateTool(name: string, updates: Partial<Tool>): void;
|
|
65
|
-
hasTool(name: string): boolean;
|
|
66
|
-
getTool(name: string): Tool | undefined;
|
|
67
|
-
list(): string[];
|
|
68
|
-
setTools(tools: Tool[]): void;
|
|
69
61
|
}
|
|
70
62
|
//# sourceMappingURL=ToolRegistry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolRegistry.d.ts","sourceRoot":"","sources":["../../src/registry/ToolRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,mBAAmB;IACnC,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uCAAuC;IACvC,KAAK,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED
|
|
1
|
+
{"version":3,"file":"ToolRegistry.d.ts","sourceRoot":"","sources":["../../src/registry/ToolRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,mBAAmB;IACnC,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uCAAuC;IACvC,KAAK,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,YAAY,CAAC,IAAI,CAAC;IACnD,mBAA4B,eAAe,WAAgB;IAC3D,mBAA4B,WAAW,UAAU;gBAErC,OAAO,GAAE,mBAAwB;cAW1B,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK;cAI1C,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK;cAI1C,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK;cAMzD,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;cAI3C,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;cA0BvE,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI;IAajD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;CASnD"}
|
|
@@ -69,27 +69,6 @@ class ToolRegistry extends BaseRegistry {
|
|
|
69
69
|
}
|
|
70
70
|
return this._items.get(name);
|
|
71
71
|
}
|
|
72
|
-
addTool(tool) {
|
|
73
|
-
this.add(tool);
|
|
74
|
-
}
|
|
75
|
-
removeTool(name) {
|
|
76
|
-
this.remove(name);
|
|
77
|
-
}
|
|
78
|
-
updateTool(name, updates) {
|
|
79
|
-
this.update(name, updates);
|
|
80
|
-
}
|
|
81
|
-
hasTool(name) {
|
|
82
|
-
return this.has(name);
|
|
83
|
-
}
|
|
84
|
-
getTool(name) {
|
|
85
|
-
return this.get(name);
|
|
86
|
-
}
|
|
87
|
-
list() {
|
|
88
|
-
return this.getNames();
|
|
89
|
-
}
|
|
90
|
-
setTools(tools) {
|
|
91
|
-
this.setAll(tools);
|
|
92
|
-
}
|
|
93
72
|
}
|
|
94
73
|
export { ToolRegistry };
|
|
95
74
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry/ToolRegistry.js","sources":["../../src/registry/ToolRegistry.ts"],"sourcesContent":["/**\n * Tool registry for managing MCP tool CRUD operations.\n *\n * This module provides the `ToolRegistry` class which manages the registration,\n * retrieval, update, and removal of MCP tools. It supports optional caching\n * for improved performance, filesystem discovery, and integrates with the logging system.\n *\n * @module registry\n */\n\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\nimport type { DiscoveryCache } from '../cache/DiscoveryCache.js';\nimport { DuplicateToolError, InvalidToolError, ToolNotFoundError } from '../errors.js';\nimport type { Logger } from '../logger/StructuredLogger.js';\nimport type { Tool } from '../types/tool.js';\nimport { BaseRegistry } from './BaseRegistry.js';\n\n/**\n * Configuration options for creating a `ToolRegistry` instance.\n *\n * @example\n * ```typescript\n * const options: ToolRegistryOptions = {\n * logger: new StructuredLogger({ context: 'ToolRegistry' }),\n * cache: new DiscoveryCache({ ttl: 300000, maxSize: 100 }),\n * toolDirs: ['./custom-tools', '~/.claude/tools'],\n * lazyDiscovery: true\n * };\n * ```\n */\nexport interface ToolRegistryOptions {\n\t/** Optional logger for diagnostics. */\n\tlogger?: Logger;\n\n\t/** Optional cache for tool lookups. */\n\tcache?: DiscoveryCache<Tool>;\n\n\t/**\n\t * Directory paths to search for tools.\n\t * @default ['.claude/tools', '~/.claude/tools']\n\t */\n\ttoolDirs?: string[];\n\n\t/**\n\t * Enable lazy discovery (discover on first access instead of startup).\n\t * @default false\n\t */\n\tlazyDiscovery?: boolean;\n}\n\n/**\n * Registry for managing MCP tool operations.\n *\n * Extends `BaseRegistry<Tool>` with tool-specific frontmatter parsing
|
|
1
|
+
{"version":3,"file":"registry/ToolRegistry.js","sources":["../../src/registry/ToolRegistry.ts"],"sourcesContent":["/**\n * Tool registry for managing MCP tool CRUD operations.\n *\n * This module provides the `ToolRegistry` class which manages the registration,\n * retrieval, update, and removal of MCP tools. It supports optional caching\n * for improved performance, filesystem discovery, and integrates with the logging system.\n *\n * @module registry\n */\n\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\nimport type { DiscoveryCache } from '../cache/DiscoveryCache.js';\nimport { DuplicateToolError, InvalidToolError, ToolNotFoundError } from '../errors.js';\nimport type { Logger } from '../logger/StructuredLogger.js';\nimport type { Tool } from '../types/tool.js';\nimport { BaseRegistry } from './BaseRegistry.js';\n\n/**\n * Configuration options for creating a `ToolRegistry` instance.\n *\n * @example\n * ```typescript\n * const options: ToolRegistryOptions = {\n * logger: new StructuredLogger({ context: 'ToolRegistry' }),\n * cache: new DiscoveryCache({ ttl: 300000, maxSize: 100 }),\n * toolDirs: ['./custom-tools', '~/.claude/tools'],\n * lazyDiscovery: true\n * };\n * ```\n */\nexport interface ToolRegistryOptions {\n\t/** Optional logger for diagnostics. */\n\tlogger?: Logger;\n\n\t/** Optional cache for tool lookups. */\n\tcache?: DiscoveryCache<Tool>;\n\n\t/**\n\t * Directory paths to search for tools.\n\t * @default ['.claude/tools', '~/.claude/tools']\n\t */\n\ttoolDirs?: string[];\n\n\t/**\n\t * Enable lazy discovery (discover on first access instead of startup).\n\t * @default false\n\t */\n\tlazyDiscovery?: boolean;\n}\n\n/**\n * Registry for managing MCP tool operations.\n *\n * Extends `BaseRegistry<Tool>` with tool-specific frontmatter parsing.\n */\nexport class ToolRegistry extends BaseRegistry<Tool> {\n\tprotected override readonly _fileExtensions = ['.tool.md'];\n\tprotected override readonly _entityName = 'tool';\n\n\tconstructor(options: ToolRegistryOptions = {}) {\n\t\tsuper({\n\t\t\tlogger: options.logger,\n\t\t\tcache: options.cache,\n\t\t\tsearchDirs: options.toolDirs ?? ['.claude/tools', join(homedir(), '.claude/tools')],\n\t\t\tlazyDiscovery: options.lazyDiscovery,\n\t\t});\n\t}\n\n\t// --- Error factories ---\n\n\tprotected override _createInvalidError(reason: string): Error {\n\t\treturn new InvalidToolError(reason);\n\t}\n\n\tprotected override _createDuplicateError(name: string): Error {\n\t\treturn new DuplicateToolError(name);\n\t}\n\n\tprotected override _createNotFoundError(name: string, action: string): Error {\n\t\treturn new ToolNotFoundError(name, action);\n\t}\n\n\t// --- Discovery ---\n\n\tprotected override _shouldSkipFile(_fileName: string): boolean {\n\t\treturn false;\n\t}\n\n\tprotected override _parseFrontmatter(content: string): Partial<Tool> & { _error?: string } {\n\t\tconst frontmatter = this._extractFrontmatter(content);\n\t\tif (!frontmatter) {\n\t\t\treturn { _error: 'No YAML frontmatter found' };\n\t\t}\n\n\t\ttry {\n\t\t\tconst result: Partial<Tool> = {\n\t\t\t\tname: typeof frontmatter.name === 'string' ? frontmatter.name : undefined,\n\t\t\t\tdescription: typeof frontmatter.description === 'string' ? frontmatter.description : '',\n\t\t\t\tinputSchema: frontmatter.inputSchema as Tool['inputSchema'],\n\t\t\t};\n\n\t\t\tif (!result.name) {\n\t\t\t\treturn { _error: 'Missing required field: name' };\n\t\t\t}\n\t\t\tif (!result.inputSchema) {\n\t\t\t\treturn { _error: 'Missing required field: inputSchema' };\n\t\t\t}\n\n\t\t\treturn result;\n\t\t} catch {\n\t\t\treturn { _error: 'YAML parse error' };\n\t\t}\n\t}\n\n\tprotected override _buildItem(parsed: Partial<Tool>): Tool | null {\n\t\tif (!parsed.name || !parsed.inputSchema) {\n\t\t\treturn null;\n\t\t}\n\t\treturn {\n\t\t\tname: parsed.name,\n\t\t\tdescription: parsed.description || '',\n\t\t\tinputSchema: parsed.inputSchema,\n\t\t};\n\t}\n\n\t// --- Tool-specific get with cache lookup ---\n\n\tpublic override get(name: string): Tool | undefined {\n\t\tif (this._cache) {\n\t\t\tconst cached = this._cache.get(`tool:${name}`);\n\t\t\tif (cached && cached.length > 0) {\n\t\t\t\treturn cached[0];\n\t\t\t}\n\t\t}\n\t\treturn this._items.get(name);\n\t}\n}\n"],"names":["ToolRegistry","BaseRegistry","options","join","homedir","reason","InvalidToolError","name","DuplicateToolError","action","ToolNotFoundError","_fileName","content","frontmatter","result","undefined","parsed","cached"],"mappings":";;;;AAwDO,MAAMA,qBAAqBC;IACL,kBAAkB;QAAC;KAAW,CAAC;IAC/B,cAAc,OAAO;IAEjD,YAAYC,UAA+B,CAAC,CAAC,CAAE;QAC9C,KAAK,CAAC;YACL,QAAQA,QAAQ,MAAM;YACtB,OAAOA,QAAQ,KAAK;YACpB,YAAYA,QAAQ,QAAQ,IAAI;gBAAC;gBAAiBC,KAAKC,WAAW;aAAiB;YACnF,eAAeF,QAAQ,aAAa;QACrC;IACD;IAImB,oBAAoBG,MAAc,EAAS;QAC7D,OAAO,IAAIC,iBAAiBD;IAC7B;IAEmB,sBAAsBE,IAAY,EAAS;QAC7D,OAAO,IAAIC,mBAAmBD;IAC/B;IAEmB,qBAAqBA,IAAY,EAAEE,MAAc,EAAS;QAC5E,OAAO,IAAIC,kBAAkBH,MAAME;IACpC;IAImB,gBAAgBE,SAAiB,EAAW;QAC9D,OAAO;IACR;IAEmB,kBAAkBC,OAAe,EAAuC;QAC1F,MAAMC,cAAc,IAAI,CAAC,mBAAmB,CAACD;QAC7C,IAAI,CAACC,aACJ,OAAO;YAAE,QAAQ;QAA4B;QAG9C,IAAI;YACH,MAAMC,SAAwB;gBAC7B,MAAM,AAA4B,YAA5B,OAAOD,YAAY,IAAI,GAAgBA,YAAY,IAAI,GAAGE;gBAChE,aAAa,AAAmC,YAAnC,OAAOF,YAAY,WAAW,GAAgBA,YAAY,WAAW,GAAG;gBACrF,aAAaA,YAAY,WAAW;YACrC;YAEA,IAAI,CAACC,OAAO,IAAI,EACf,OAAO;gBAAE,QAAQ;YAA+B;YAEjD,IAAI,CAACA,OAAO,WAAW,EACtB,OAAO;gBAAE,QAAQ;YAAsC;YAGxD,OAAOA;QACR,EAAE,OAAM;YACP,OAAO;gBAAE,QAAQ;YAAmB;QACrC;IACD;IAEmB,WAAWE,MAAqB,EAAe;QACjE,IAAI,CAACA,OAAO,IAAI,IAAI,CAACA,OAAO,WAAW,EACtC,OAAO;QAER,OAAO;YACN,MAAMA,OAAO,IAAI;YACjB,aAAaA,OAAO,WAAW,IAAI;YACnC,aAAaA,OAAO,WAAW;QAChC;IACD;IAIgB,IAAIT,IAAY,EAAoB;QACnD,IAAI,IAAI,CAAC,MAAM,EAAE;YAChB,MAAMU,SAAS,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAEV,MAAM;YAC7C,IAAIU,UAAUA,OAAO,MAAM,GAAG,GAC7B,OAAOA,MAAM,CAAC,EAAE;QAElB;QACA,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAACV;IACxB;AACD"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -315,6 +315,7 @@ export declare const PartialStepRecommendationSchema: v.ObjectSchema<{
|
|
|
315
315
|
* thought: 'I need to analyze the problem',
|
|
316
316
|
* thought_number: 1,
|
|
317
317
|
* total_thoughts: 5,
|
|
318
|
+
* session_id: 'analysis-task',
|
|
318
319
|
* next_thought_needed: true,
|
|
319
320
|
* available_mcp_tools: ['Read', 'Write', 'Grep']
|
|
320
321
|
* });
|
|
@@ -479,7 +480,7 @@ export declare const SequentialThinkingSchema: v.ObjectSchema<{
|
|
|
479
480
|
readonly merge_branch_ids: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.MaxLengthAction<string, 50, undefined>]>, undefined>, v.DescriptionAction<string[], "Branch IDs being merged into current context">]>, undefined>;
|
|
480
481
|
readonly meta_observation: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "Metacognitive observation about reasoning process">]>, undefined>;
|
|
481
482
|
readonly reasoning_depth: v.OptionalSchema<v.SchemaWithPipe<readonly [v.PicklistSchema<["shallow", "moderate", "deep"], undefined>, v.DescriptionAction<"shallow" | "moderate" | "deep", "Effort signal: how deep reasoning should go">]>, undefined>;
|
|
482
|
-
readonly session_id: v.
|
|
483
|
+
readonly session_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "Session ID must contain only letters, numbers, hyphens, and underscores">, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>, v.NotValueAction<string, "__global__", "Session ID '__global__' is retired; use an explicit named session">, v.DescriptionAction<string, "Required session identifier for state isolation. Thought history, branches, and statistics are scoped to this explicit named session.">]>;
|
|
483
484
|
readonly reset_state: v.OptionalSchema<v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "When true, clears all state for the target session before processing this thought. The thought is then processed as the first in a fresh session.">]>, undefined>;
|
|
484
485
|
readonly tool_name: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.DescriptionAction<string, "Name of the tool being invoked (for tool_call thoughts)">]>, undefined>;
|
|
485
486
|
readonly tool_arguments: v.OptionalSchema<v.SchemaWithPipe<readonly [v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, v.DescriptionAction<{
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAoH5C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,wBAA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,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,wBAAwB,EAAE,IAItC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,oBAAoB;;;;;;;aAmB/B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,kWASW,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;aAetB,CAAC"}
|
package/dist/schema.js
CHANGED
|
@@ -73,8 +73,8 @@ Reasoning Enhancement Parameters:
|
|
|
73
73
|
- merge_branch_ids: Branch IDs merged into current context
|
|
74
74
|
- meta_observation: Observation about reasoning process (with thought_type 'meta')
|
|
75
75
|
- reasoning_depth: How deep to reason: 'shallow' (quick), 'moderate' (default), 'deep' (thorough)
|
|
76
|
-
- session_id:
|
|
77
|
-
- reset_state: (Optional) When true, clears all state for the
|
|
76
|
+
- session_id: Required unique identifier that scopes thought history, branches, and statistics to an explicit session. Format: alphanumeric, hyphens, underscores, 1-100 chars; the retired value __global__ is rejected.
|
|
77
|
+
- reset_state: (Optional) When true, clears all state for the required session_id before processing the current thought. Use this to start a fresh reasoning chain without accumulated state from previous chains.
|
|
78
78
|
|
|
79
79
|
Response Enrichment:
|
|
80
80
|
- When reasoning fields are set, response includes confidence_signals (depth, revision/branch count, type distribution, avg confidence, structural_quality, quality_components) and reasoning_stats (hypothesis tracking)
|
|
@@ -201,7 +201,7 @@ const SequentialThinkingSchema = __rspack_external_valibot.object({
|
|
|
201
201
|
'moderate',
|
|
202
202
|
'deep'
|
|
203
203
|
]), __rspack_external_valibot.description('Effort signal: how deep reasoning should go'))),
|
|
204
|
-
session_id: __rspack_external_valibot.
|
|
204
|
+
session_id: __rspack_external_valibot.pipe(__rspack_external_valibot.string(), __rspack_external_valibot.regex(/^[a-zA-Z0-9_-]+$/, 'Session ID must contain only letters, numbers, hyphens, and underscores'), __rspack_external_valibot.minLength(1), __rspack_external_valibot.maxLength(100), __rspack_external_valibot.notValue('__global__', "Session ID '__global__' is retired; use an explicit named session"), __rspack_external_valibot.description('Required session identifier for state isolation. Thought history, branches, and statistics are scoped to this explicit named session.')),
|
|
205
205
|
reset_state: __rspack_external_valibot.optional(__rspack_external_valibot.pipe(__rspack_external_valibot.boolean(), __rspack_external_valibot.description('When true, clears all state for the target session before processing this thought. The thought is then processed as the first in a fresh session.'))),
|
|
206
206
|
tool_name: __rspack_external_valibot.optional(__rspack_external_valibot.pipe(__rspack_external_valibot.string(), __rspack_external_valibot.minLength(1), __rspack_external_valibot.description('Name of the tool being invoked (for tool_call thoughts)'))),
|
|
207
207
|
tool_arguments: __rspack_external_valibot.optional(__rspack_external_valibot.pipe(__rspack_external_valibot.record(__rspack_external_valibot.string(), __rspack_external_valibot.unknown()), __rspack_external_valibot.description('Arguments passed to the tool (for tool_call thoughts)'))),
|