{"record":{"id":"4537b41baba1df1f","repo":"jackwener/OpenCLI","slug":"must-be-a-non-empty-yuanbao-chat-url-or-agentid","errorCode":null,"errorMessage":"must be a non-empty Yuanbao chat URL or \"<agentId>/<convId>\" pair","messagePattern":"must be a non-empty Yuanbao chat URL or \"<agentId>/<convId>\" pair","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/yuanbao/shared.js","lineNumber":87,"sourceCode":"/**\n * Extract Yuanbao session identity from a raw input.\n *\n * Yuanbao chat URLs are `/chat/<agentId>/<convId>`. Both parts are required\n * to navigate — there is no stable default agentId we can fall back to. So we\n * only accept inputs that resolve a complete `{agentId, convId}` pair:\n *   - full `https://yuanbao.tencent.com/chat/<agentId>/<convId>` URL\n *   - bare slash form `<agentId>/<convId>`\n *\n * A bare convId UUID is rejected with an actionable message — opening the\n * wrong agent silently is a much worse failure mode than throwing.\n *\n * The trailing `(?:[/?#]|$)` boundary in the URL regex prevents over-long\n * suffixes (e.g. `<id>extra`) from silently truncating to a valid-looking ID.\n */\nexport function parseYuanbaoSessionId(input) {\n    const raw = String(input ?? '').trim();\n    if (!raw) {\n        throw new ArgumentError(\n            'id',\n            'must be a non-empty Yuanbao chat URL or \"<agentId>/<convId>\" pair',\n        );\n    }\n    const urlMatch = raw.match(/yuanbao\\.tencent\\.com\\/chat\\/([A-Za-z0-9_-]+)\\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:[/?#]|$)/i);\n    if (urlMatch) {\n        const [, agentId, convId] = urlMatch;\n        if (!AGENT_ID_RE.test(agentId) || !CONV_ID_RE.test(convId)) {\n            throw new ArgumentError(\n                'id',\n                `not a valid Yuanbao chat URL (got \"${input}\"); expected https://yuanbao.tencent.com/chat/<agentId>/<convId>`,\n            );\n        }\n        return { agentId, convId: convId.toLowerCase() };\n    }\n    const slashMatch = raw.match(/^([A-Za-z0-9_-]+)\\/([0-9a-f-]{36})$/i);\n    if (slashMatch) {\n        const [, agentId, convId] = slashMatch;","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/yuanbao/shared.js#L69-L105","documentation":"parseYuanbaoSessionId rejects an empty session reference. It trims String(input ?? '') and throws ArgumentError with the id parameter name when nothing remains. The function accepts either a full Yuanbao chat URL or a bare <agentId>/<convId> pair, and '' matches neither.","triggerScenarios":"Calling a command that resolves a session (open/show) with an empty string, null, or undefined id — e.g. a script variable holding the session id was never set, or a previous history command returned no AgentId to forward.","commonSituations":"Chaining commands where the upstream lookup failed silently and '' was piped forward; config files with an empty yuanbao.session key; JSON payloads omitting the id field (null/undefined coalesced to '').","solutions":["Pass a full chat URL like https://yuanbao.tencent.com/chat/<agentId>/<convId>","Or pass the bare pair: `<agentId>/<convId>` (convId is a UUID)","If the id comes from a variable/config, check it is non-empty before invoking","Capture a real AgentId/SessionId from `yuanbao history` output first"],"exampleFix":"// before\nconst id = cfg.yuanbaoSession || '';\nawait cli.open(id);\n// after\nconst id = cfg.yuanbaoSession;\nif (!id) throw new Error('yuanbaoSession is not configured');\nawait cli.open(id);","handlingStrategy":"validation","validationCode":"if (!input || !String(input).trim()) {\n  throw new Error('session id must be a non-empty Yuanbao chat URL or <agentId>/<convId> pair');\n}","typeGuard":"const hasSessionRef = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  await cli.yuanbaoOpen(id);\n} catch (e) {\n  if (e.name === 'ArgumentError' && e.param === 'id') {\n    console.error('Provide a full chat URL or <agentId>/<convId>');\n  } else throw e;\n}","preventionTips":["Fail fast in scripts when the id variable is empty before calling the CLI","Capture AgentId/SessionId from `yuanbao history` rather than hand-building ids","Store full chat URLs in config instead of bare fragments"],"tags":["validation","argument-error","session-id"],"backgroundTag":"invalid-session-reference","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}