{"id":46868667,"url":"https://github.com/jsmithdenverdev/knowledgebase","last_synced_at":"2026-03-10T19:13:17.425Z","repository":{"id":341740797,"uuid":"1171287921","full_name":"jsmithdenverdev/knowledgebase","owner":"jsmithdenverdev","description":"POC Typescript Bedrock chat with integrated S3 KnowledgeBase","archived":false,"fork":false,"pushed_at":"2026-03-03T05:23:10.000Z","size":12,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-03T08:34:52.323Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsmithdenverdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-03-03T04:08:31.000Z","updated_at":"2026-03-03T04:24:10.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/jsmithdenverdev/knowledgebase","commit_stats":null,"previous_names":["jsmithdenverdev/knowledgebase"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/jsmithdenverdev/knowledgebase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsmithdenverdev%2Fknowledgebase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsmithdenverdev%2Fknowledgebase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsmithdenverdev%2Fknowledgebase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsmithdenverdev%2Fknowledgebase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsmithdenverdev","download_url":"https://codeload.github.com/jsmithdenverdev/knowledgebase/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsmithdenverdev%2Fknowledgebase/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30349302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T15:55:29.454Z","status":"ssl_error","status_checked_at":"2026-03-10T15:54:58.440Z","response_time":106,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-03-10T19:13:16.104Z","updated_at":"2026-03-10T19:13:17.417Z","avatar_url":"https://github.com/jsmithdenverdev.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# knowledgebase\n\nPOC TypeScript Bedrock chat stack that exposes a single chat completion endpoint through API Gateway + Lambda. The interface is intentionally aligned with the OpenAI Chat Completions API so frontend vendors can reuse their existing clients with minimal changes.\n\n## Chat API\n\n- **Endpoint:** `POST /chat`\n- **Protocol:** API Gateway streaming (server-sent events). `stream` must be `true` (default) and the backend always returns SSE chunks that mirror `chat.completion.chunk` objects.\n- **Agent orchestration:** all traffic routes through the Bedrock agent provisioned by CDK. Clients cannot select alternate models; the agent references a single Bedrock foundation model defined by the stack.\n\n### Request Body (subset of OpenAI spec)\n\n```json\n{\n  \"messages\": [\n    { \"role\": \"user\", \"content\": \"Summarize the attached policy.\" },\n    { \"role\": \"assistant\", \"content\": \"Here's the current summary...\" },\n    { \"role\": \"user\", \"content\": \"Tighten that to one paragraph.\" }\n  ]\n}\n```\n\nContract constraints:\n\n- `messages` is the **only** accepted field; requests containing `model`, `temperature`, `tools`, etc. are rejected with an OpenAI-style `invalid_request_error`.\n- Each message must use the OpenAI `user` or `assistant` role (no client-provided `system` role) with plain string content; the backend injects the canonical agent instructions configured via CDK.\n- The final message must be a `user` turn so the agent always responds to an explicit customer input.\n- Whitespace-only content is rejected to avoid empty turns.\n\n### Streaming Response\n\n```\ndata: {\"id\":\"chatcmpl-123\",\"object\":\"chat.completion.chunk\",\"created\":1710000000,\"model\":\"anthropic.claude\",\"system_fingerprint\":\"bedrock:anthropic.claude\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":[{\"type\":\"text\",\"text\":\"Hello\"}]},\"finish_reason\":null}]}\n\n...\n\ndata: {\"id\":\"chatcmpl-123\",\"object\":\"chat.completion.chunk\",\"created\":1710000000,\"model\":\"anthropic.claude\",\"system_fingerprint\":\"bedrock:anthropic.claude\",\"choices\":[{\"index\":0,\"delta\":{},\"finish_reason\":\"stop\"}]}\n\ndata: [DONE]\n```\n\n### Error Format\n\nNon-2xx responses and SSE error events follow the OpenAI error envelope:\n\n```json\n{\n  \"error\": {\n    \"message\": \"frequency_penalty is not supported.\",\n    \"type\": \"invalid_request_error\",\n    \"param\": null,\n    \"code\": null\n  }\n}\n```\n\n## Development\n\nInstall dependencies and run tests just like any TypeScript CDK repo:\n\n```bash\nnpm install\nnpm run build\nnpm run test\n```\n\n### Infrastructure Parameters\n\n- `AgentSystemPrompt` (CDK parameter): optional override for the agent's instruction block. If omitted, the stack uses the repo default prompt (`You are an enterprise knowledge base assistant...`). Supply a new prompt at deploy time via `cdk deploy -c AgentSystemPrompt=\"Your instructions\"` (quote to preserve whitespace).\n\n### CLI Chat Utility\n\nUse the Node-based streaming helper to manually exercise the API Gateway endpoint:\n\n```bash\nnpm run chat -- \"Summarize our SOC 2 controls\"\n\n# or point at a different stage/stack\nCHAT_API_URL=\"https://example.execute-api.us-east-1.amazonaws.com/prod/chat\" npm run chat -- \"Hello\"\n```\n\nThe script sends a minimal OpenAI-style request (`{ messages: [{ role: \"user\", content: \"...\" }] }`) and prints streamed chunks as they arrive, plus any OpenAI-formatted errors.\n\n## MVP Deployment Flow\n\n1. `cdk deploy` the stack. Deployment outputs now include `ChatAgentId`, which is the value you will pass to Bedrock runtime and preparedness APIs.\n2. After each deploy (or any change to prompts/knowledge-base wiring) run `aws bedrock-agent prepare-agent --agentId \u003cChatAgentId\u003e` so the agent’s `DRAFT` build reflects the latest configuration. You can use the console “Prepare” button if you prefer clicks.\n3. The chat Lambda always invokes the built-in Bedrock alias `TSTALIASID`, which automatically points at the prepared draft. No manual alias or version management is required for this thin-slice MVP.\n\nOnce you need stricter version gating, reintroduce an explicit `AWS::Bedrock::AgentAlias` resource and feed it a published version; the chat Lambda simply needs the alias ID updated in its environment variables.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsmithdenverdev%2Fknowledgebase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsmithdenverdev%2Fknowledgebase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsmithdenverdev%2Fknowledgebase/lists"}