{"record":{"id":"b41b9133ea0ea8a8","repo":"paperclipai/paperclip","slug":"failed-to-create-agent-token","errorCode":null,"errorMessage":"Failed to create agent token","messagePattern":"Failed to create agent token","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/connect.ts","lineNumber":132,"sourceCode":"      profile: profileName,\n      persona: \"board\",\n      apiBase,\n      companyId: company?.id ?? null,\n      key: publicKeyResult(key),\n      exports: buildExports({ apiBase, companyId: company?.id, agentId: undefined, envName: apiKeyEnvVarName, token: key.token }),\n    };\n  }\n\n  const company = await chooseCompany(companies, opts.companyId ?? resolvedProfile.profile.companyId, {\n    optional: false,\n  });\n  if (!company) throw new Error(\"Company is required for agent profiles\");\n  const agents = (await boardApi.get<Agent[]>(apiPath`/api/companies/${company.id}/agents`)) ?? [];\n  if (agents.length === 0) throw new Error(`Company '${company.name}' has no agents to connect.`);\n  const agent = await chooseAgent(agents, resolvedProfile.profile.agentId);\n  const tokenName = opts.tokenName?.trim() || `cli-agent-${new Date().toISOString()}`;\n  const key = await boardApi.post<CreatedAgentKey>(apiPath`/api/agents/${agent.id}/keys`, createAgentKeySchema.parse({ name: tokenName }));\n  if (!key) throw new Error(\"Failed to create agent token\");\n  upsertProfile(profileName, {\n    apiBase,\n    companyId: company.id,\n    persona: \"agent\",\n    agentId: agent.id,\n    agentName: agent.name,\n    apiKeyEnvVarName,\n    tokenName: key.name,\n    tokenId: key.id,\n    tokenCreatedAt: key.createdAt,\n  }, opts.context);\n  setCurrentProfile(profileName, opts.context);\n  p.outro(pc.green(`Connected profile '${profileName}' as ${agent.name}.`));\n  return {\n    ok: true,\n    profile: profileName,\n    persona: \"agent\",\n    apiBase,","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/cli/src/commands/client/connect.ts#L114-L150","documentation":"The agent API key creation call in connectWizard returned a falsy result, so the wizard cannot complete the agent profile; a sentinel null-guard on the API response.","triggerScenarios":"Thrown at cli/src/commands/client/connect.ts:132 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify board credentials and server reachability, then retry."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}