{"_id":"@braingrid/prompts","name":"@braingrid/prompts","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@braingrid/prompts","version":"1.0.0","description":"Prompt management with context interpolation, token calculation, and metrics","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"keywords":["ai","prompts","llm","templates","tokens","metrics"],"author":{"name":"BrainGrid AI, Inc."},"license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/BrainGridAI/ai-kit.git","directory":"packages/prompts"},"homepage":"https://github.com/BrainGridAI/ai-kit/tree/main/packages/prompts#readme","bugs":{"url":"https://github.com/BrainGridAI/ai-kit/issues"},"dependencies":{"tiktoken":"^1.0.0","zod":"^3.22.0"},"devDependencies":{"@types/node":"^22.0.0","tsup":"^8.0.0","typescript":"^5.6.0","vitest":"^3.2.4"},"publishConfig":{"access":"public"},"scripts":{"build":"tsup","dev":"tsup --watch","type-check":"tsc --noEmit","test":"vitest run","test:watch":"vitest","clean":"rm -rf dist"},"_id":"@braingrid/prompts@1.0.0","_integrity":"sha512-DHt68iwyXwMKVGjpdsZoiG/4ebWNHR9WEDQSxfrmdfn4Rg92r2aZslpGL/eflCDYQc0Ma8Oax18dqKLAAeVBBQ==","_resolved":"/private/var/folders/mt/c41k7_b167q49y0dr5z1yp040000gn/T/bd174b1f8ae1e204877887e6416dd001/braingrid-prompts-1.0.0.tgz","_from":"file:braingrid-prompts-1.0.0.tgz","_nodeVersion":"22.17.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-DHt68iwyXwMKVGjpdsZoiG/4ebWNHR9WEDQSxfrmdfn4Rg92r2aZslpGL/eflCDYQc0Ma8Oax18dqKLAAeVBBQ==","shasum":"5926e81f9949f5d2b309e11655ec89d4876a67f0","tarball":"https://registry.npmjs.org/@braingrid/prompts/-/prompts-1.0.0.tgz","fileCount":9,"unpackedSize":57901,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDrCM2GrR3KeNaoOYkEjLmCYmKzQkzHK1U64n9kUwqLxwIgFUhGeil3e20l/zVCUFji4sNXAc78aZZa/eFY3s3UKqQ="}]},"_npmUser":{"name":"braingrid_tyler","email":"tyler@braingrid.ai"},"directories":{},"maintainers":[{"name":"acossta","email":"nico@acosta.io"},{"name":"braingrid_tyler","email":"tyler@braingrid.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/prompts_1.0.0_1762647515178_0.2331936785826605"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-09T00:18:35.086Z","1.0.0":"2025-11-09T00:18:35.378Z","modified":"2025-11-09T00:18:35.687Z"},"maintainers":[{"name":"acossta","email":"nico@acosta.io"},{"name":"braingrid_tyler","email":"tyler@braingrid.ai"}],"description":"Prompt management with context interpolation, token calculation, and metrics","homepage":"https://github.com/BrainGridAI/ai-kit/tree/main/packages/prompts#readme","keywords":["ai","prompts","llm","templates","tokens","metrics"],"repository":{"type":"git","url":"git+https://github.com/BrainGridAI/ai-kit.git","directory":"packages/prompts"},"author":{"name":"BrainGrid AI, Inc."},"bugs":{"url":"https://github.com/BrainGridAI/ai-kit/issues"},"license":"Apache-2.0","readme":"# @braingrid/prompts\n\nPrompt management with context interpolation, token calculation, and metrics.\n\n## Features\n\n- **Pluggable Storage** - Memory, filesystem, or custom backends\n- **Token Calculation** - Accurate token counting with tiktoken\n- **Context Interpolation** - `{{variable}}` template syntax\n- **Metrics** - Track tokens, characters, words, lines\n- **Caching** - Performance optimization for repeated access\n\n## Installation\n\n```bash\npnpm add @braingrid/prompts\n```\n\n## Quick Start\n\n```typescript\nimport { PromptService, MemoryPromptStorage } from '@braingrid/prompts';\n\n// 1. Create storage\nconst storage = new MemoryPromptStorage({\n  chat_system: 'You are a helpful assistant for {{userName}}.',\n  research_system: 'You are a research assistant for {{userName}} at {{companyName}}.',\n});\n\n// 2. Create service\nconst prompts = new PromptService({ storage });\n\n// 3. Get prompt\nconst prompt = await prompts.getPrompt('chat_system');\n\n// 4. Get prompt with context\nconst interpolated = await prompts.getPromptWithContext('chat_system', {\n  userName: 'Alice',\n});\n// => \"You are a helpful assistant for Alice.\"\n\n// 5. Get metrics\nconst metrics = await prompts.getPromptWithMetrics('chat_system');\nconsole.log(metrics);\n// => { name: 'chat_system', content: '...', tokens: 12, characters: 45, words: 8, lines: 1 }\n```\n\n## Storage Backends\n\n### MemoryPromptStorage\n\n```typescript\nimport { MemoryPromptStorage } from '@braingrid/prompts';\n\nconst storage = new MemoryPromptStorage({\n  chat_system: 'You are a chat assistant.',\n  research_system: 'You are a research assistant.',\n});\n\nstorage.set('new_prompt', 'You are...');\nstorage.has('chat_system'); // true\nstorage.list(); // ['chat_system', 'research_system', 'new_prompt']\n```\n\n### FileSystemPromptStorage\n\n```typescript\nimport { FileSystemPromptStorage } from '@braingrid/prompts';\n\nconst storage = new FileSystemPromptStorage('./prompts');\n\n// Reads from:\n// ./prompts/chat_system.txt\n// ./prompts/chat_system.md\n// ./prompts/research_system.txt\n// etc.\n```\n\n### Custom Storage\n\n```typescript\nimport { type PromptStorage } from '@braingrid/prompts';\n\nclass DatabasePromptStorage implements PromptStorage {\n  async get(name: string): Promise<string | undefined> {\n    const row = await db.query('SELECT content FROM prompts WHERE name = $1', [name]);\n    return row?.content;\n  }\n\n  async list(): Promise<string[]> {\n    const rows = await db.query('SELECT name FROM prompts');\n    return rows.map(r => r.name);\n  }\n}\n\nconst storage = new DatabasePromptStorage(db);\nconst service = new PromptService({ storage });\n```\n\n## Token Calculation\n\n```typescript\nimport { PromptService, TiktokenCalculator, ApproximateTokenCalculator } from '@braingrid/prompts';\n\n// Accurate token counting (requires tiktoken)\nconst service = new PromptService({\n  storage,\n  tokenCalculator: new TiktokenCalculator('gpt-4'),\n});\n\n// Fast approximation (no dependencies)\nconst service2 = new PromptService({\n  storage,\n  tokenCalculator: new ApproximateTokenCalculator(),\n});\n```\n\n## Context Interpolation\n\n```typescript\nconst storage = new MemoryPromptStorage({\n  greeting: 'Hello {{userName}}, welcome to {{companyName}}!',\n  nested: 'User {{user.firstName}} {{user.lastName}} from {{user.company.name}}',\n});\n\nconst service = new PromptService({ storage });\n\nconst prompt1 = await service.getPromptWithContext('greeting', {\n  userName: 'Alice',\n  companyName: 'ACME Corp',\n});\n// => \"Hello Alice, welcome to ACME Corp!\"\n\nconst prompt2 = await service.getPromptWithContext('nested', {\n  user: {\n    firstName: 'Bob',\n    lastName: 'Smith',\n    company: { name: 'TechCo' },\n  },\n});\n// => \"User Bob Smith from TechCo\"\n```\n\n## Integration with Agents\n\n```typescript\nimport { PromptService, FileSystemPromptStorage } from '@braingrid/prompts';\nimport { PromptManager } from '@braingrid/agents';\n\nconst storage = new FileSystemPromptStorage('./prompts');\nconst promptService = new PromptService({ storage });\n\n// Use with PromptManager\nconst manager = new PromptManager({\n  agentType: 'chat',\n  storage,\n});\n\nconst prompt = await manager.getPrompt({ userName: 'Alice' });\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-8f57328dd151ed51c263b61931845b9d"}