Import packages/plugin/src/codex/session-id.ts

This commit is contained in:
QQ 2026-11-14 14:54:34 +08:00
parent 4d6bab9022
commit ce31dacf72
1 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,14 @@
import { RpcError } from '../safe-error.js'
/** Parse the public CodeX session identity without treating it as a Harness agent id. */
export function parseCodexSessionId(value: unknown): { sessionId: string; threadId: string } | undefined {
if (typeof value !== 'string') return undefined
const match = /^codex:([A-Za-z0-9][A-Za-z0-9._-]{0,255})$/.exec(value)
return match === null ? undefined : { sessionId: value, threadId: match[1]! }
}
export function requireCodexSessionId(value: unknown): { sessionId: string; threadId: string } {
const parsed = parseCodexSessionId(value)
if (parsed === undefined) throw new RpcError('CODEX_SESSION_INVALID', 'The CodeX session identifier is invalid.')
return parsed
}