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,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC5C,OAAO,GAAE,oCAAyC,GAChD,sBAAsB,GAAG,SAAS,CAsDpC","sourcesContent":["/**\n * Shared inference runtime resolution (3.0.0 cross-host bridge).\n *\n * Activation is configuration-driven and now DEFAULT-ON for configured shared\n * resources: a model that resolves to a configured `SharedInferenceResource`\n * automatically uses admission scheduling (no per-caller env flag). Cloud /\n * non-shared providers pass through unchanged. Explicit opt-out for diagnostic\n * direct access: `JENSEN_SHARED_INFERENCE=0`.\n *\n * Local processes run the scheduler in-process over the durable cross-process\n * ledger. Remote runtimes (when `JENSEN_SHARED_INFERENCE_ADMISSION_URL` is set)\n * use a `RemoteSchedulerAdmissionClient` that delegates to the central admission\n * service — never a second scheduler, never direct backend fallback.\n */\n\nimport type { StreamFn } from \"@apholdings/jensen-agent-core\";\nimport { governancePolicyFromEnv } from \"../governance/evaluator.js\";\nimport { GovernanceService } from \"../governance/service.js\";\nimport { LocalSchedulerAdmissionClient, type SharedInferenceAdmissionPort } from \"./admission-port.js\";\nimport { createFileInferenceQueueStore } from \"./file-inference-queue-store.js\";\nimport { createFileLogicalAgentStore } from \"./file-logical-agent-store.js\";\nimport { RemoteSchedulerAdmissionClient } from \"./remote-admission-client.js\";\nimport { LocalSubagentRuntime } from \"./runtime.js\";\nimport { SharedInferenceScheduler } from \"./scheduler.js\";\nimport { createScheduledStreamFn } from \"./stream-fn.js\";\nimport type { InferencePriority, InferenceRequestDependency, SharedInferenceResource } from \"./types.js\";\n\nexport const DEFAULT_SHARED_INFERENCE_RESOURCES: readonly SharedInferenceResource[] = [\n\t{\n\t\tresourceId: \"qwen38-bucephalus\",\n\t\tbackend: \"llamacpp-qwen38-bucephalus\",\n\t\tmodel: \"qwen3.8-27b\",\n\t\tlocation: \"bucephalus\",\n\t\tcapacity: 1,\n\t\tcontextWindow: 196608,\n\t\tmaxOutputTokens: 8192,\n\t\tstate: \"available\",\n\t},\n];\n\nexport interface SharedInferenceRuntime {\n\tadmission: SharedInferenceAdmissionPort;\n\truntime?: LocalSubagentRuntime;\n\tstreamFn: StreamFn;\n\tresources: SharedInferenceResource[];\n}\n\nfunction isTruthy(value: string | undefined): boolean {\n\tif (!value) return false;\n\treturn value === \"1\" || value.toLowerCase() === \"true\" || value.toLowerCase() === \"yes\";\n}\n\nfunction parseResourcesFromEnv(): SharedInferenceResource[] | undefined {\n\tconst raw = process.env.JENSEN_SHARED_INFERENCE_RESOURCES;\n\tif (!raw?.trim()) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(raw) as unknown;\n\t\tif (!Array.isArray(parsed)) return undefined;\n\t\treturn parsed.map((entry): SharedInferenceResource => {\n\t\t\tconst r = entry as Record<string, unknown>;\n\t\t\treturn {\n\t\t\t\tresourceId: String(r.resourceId),\n\t\t\t\tbackend: String(r.backend),\n\t\t\t\tmodel: String(r.model),\n\t\t\t\tlocation: String(r.location ?? \"\"),\n\t\t\t\tcapacity: typeof r.capacity === \"number\" ? r.capacity : 1,\n\t\t\t\tcontextWindow: typeof r.contextWindow === \"number\" ? r.contextWindow : undefined,\n\t\t\t\tmaxOutputTokens: typeof r.maxOutputTokens === \"number\" ? r.maxOutputTokens : undefined,\n\t\t\t\tstate: (r.state as SharedInferenceResource[\"state\"]) ?? \"available\",\n\t\t\t\tbaseUrl: typeof r.baseUrl === \"string\" ? r.baseUrl : undefined,\n\t\t\t};\n\t\t});\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function sharedInferenceResources(): SharedInferenceResource[] {\n\treturn parseResourcesFromEnv() ?? [...DEFAULT_SHARED_INFERENCE_RESOURCES];\n}\n\nexport interface SharedInferenceAdmissionEndpoint {\n\turl?: string;\n\ttoken?: string;\n\texecutionId?: string;\n}\n\n/** Remote admission endpoint propagated into the runtime environment (never argv). */\nexport function resolveAdmissionEndpoint(): SharedInferenceAdmissionEndpoint {\n\treturn {\n\t\turl: process.env.JENSEN_SHARED_INFERENCE_ADMISSION_URL,\n\t\ttoken: process.env.JENSEN_SHARED_INFERENCE_TOKEN,\n\t\texecutionId: process.env.JENSEN_SHARED_INFERENCE_EXECUTION_ID,\n\t};\n}\n\nexport function isSharedInferenceEnabled(): boolean {\n\t// Remote runtime with a propagated admission endpoint is always scheduled.\n\tif (resolveAdmissionEndpoint().url) return true;\n\tconst explicit = process.env.JENSEN_SHARED_INFERENCE;\n\tif (explicit !== undefined) return isTruthy(explicit);\n\t// Default-on: a configured shared resource implies scheduling.\n\treturn sharedInferenceResources().length > 0;\n}\n\nexport interface ResolveSharedInferenceRuntimeOptions {\n\tsessionId?: string;\n\tmissionId?: string;\n\tassignmentId?: string;\n\texecutionId?: string;\n\tpriority?: InferencePriority;\n\tdependency?: InferenceRequestDependency;\n\tqueueDir?: string;\n\tagentDir?: string;\n\townerId?: string;\n\tnow?: () => number;\n\tgovernance?: GovernanceService;\n}\n\n/**\n * Build the shared admission + logical-agent runtime + provider seam.\n *\n * - Remote runtime (`JENSEN_SHARED_INFERENCE_ADMISSION_URL`): a remote admission\n *   client delegating to the central service (fail-closed, no direct backend).\n * - Local runtime: the in-process scheduler over the shared durable ledger.\n *\n * Returns `undefined` when shared inference is disabled.\n */\nexport function resolveSharedInferenceRuntime(\n\toptions: ResolveSharedInferenceRuntimeOptions = {},\n): SharedInferenceRuntime | undefined {\n\tif (!isSharedInferenceEnabled()) return undefined;\n\n\tconst resources = sharedInferenceResources();\n\tconst envPriority = Number(process.env.JENSEN_INFERENCE_PRIORITY);\n\tconst envUnblocks = Number(process.env.JENSEN_INFERENCE_UNBLOCKS);\n\tconst priority =\n\t\toptions.priority ?? (Number.isSafeInteger(envPriority) && envPriority >= 0 ? { base: envPriority } : undefined);\n\tconst dependency =\n\t\toptions.dependency ??\n\t\t(Number.isSafeInteger(envUnblocks) && envUnblocks >= 0 ? { unblocksCount: envUnblocks } : undefined);\n\tconst verification = process.env.JENSEN_INFERENCE_VERIFICATION === \"1\";\n\tconst endpoint = resolveAdmissionEndpoint();\n\n\tlet admission: SharedInferenceAdmissionPort;\n\tlet runtime: LocalSubagentRuntime;\n\n\tif (endpoint.url) {\n\t\tadmission = new RemoteSchedulerAdmissionClient({\n\t\t\tbaseUrl: endpoint.url,\n\t\t\ttoken: endpoint.token ?? \"\",\n\t\t\texecutionId: endpoint.executionId ?? options.executionId ?? \"unknown\",\n\t\t\tresources,\n\t\t});\n\t\truntime = new LocalSubagentRuntime({ store: createFileLogicalAgentStore(options.agentDir) });\n\t} else {\n\t\tconst queueStore = createFileInferenceQueueStore(options.queueDir);\n\t\tconst scheduler = new SharedInferenceScheduler({ store: queueStore, ownerId: options.ownerId, now: options.now });\n\t\tvoid Promise.all(resources.map((resource) => scheduler.registerResource(resource))).catch(() => {\n\t\t\t// Ledger registration is idempotent; a corrupt pre-existing ledger is\n\t\t\t// surfaced structurally by later acquire/status calls, never masked here.\n\t\t});\n\t\tadmission = new LocalSchedulerAdmissionClient(scheduler);\n\t\truntime = new LocalSubagentRuntime({ store: createFileLogicalAgentStore(options.agentDir) });\n\t}\n\n\tconst governance =\n\t\toptions.governance ??\n\t\t(options.missionId ? new GovernanceService({ policy: governancePolicyFromEnv() }) : undefined);\n\tconst streamFn = createScheduledStreamFn({\n\t\tadmission,\n\t\truntime,\n\t\tgetCorrelation: () => ({\n\t\t\tlogicalAgentId: options.sessionId ?? process.env.JENSEN_SESSION_ID ?? \"unknown\",\n\t\t\tmissionId: options.missionId ?? process.env.JENSEN_MISSION_ID,\n\t\t\tassignmentId: options.assignmentId ?? process.env.JENSEN_ASSIGNMENT_ID,\n\t\t\texecutionId: options.executionId ?? process.env.JENSEN_EXECUTION_ID,\n\t\t\tpriority: verification ? { ...(priority ?? { base: 0 }), verification: true } : priority,\n\t\t\tdependency,\n\t\t}),\n\t\tgovernance,\n\t});\n\n\treturn { admission, runtime, streamFn, resources };\n}\n"]}