{"_id":"@aiassist-secure/core","name":"@aiassist-secure/core","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@aiassist-secure/core","version":"1.0.0","description":"AiAssist Secure TypeScript SDK - Framework-agnostic API client","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"build":"tsup src/index.ts --format cjs,esm --dts --clean","dev":"tsup src/index.ts --format cjs,esm --dts --watch","typecheck":"tsc --noEmit"},"devDependencies":{"tsup":"^8.0.0","typescript":"^5.0.0"},"keywords":["aiassist","aiassist-secure","ai","llm","openai","groq","chat","api","sdk"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/aiassistsecure/aiassist-js.git"},"homepage":"https://aiassist.net","bugs":{"url":"https://github.com/aiassistsecure/aiassist-js/issues"},"engines":{"node":">=18.0.0"},"_id":"@aiassist-secure/core@1.0.0","gitHead":"688713b3df643bda59749f063c08a5d5461cdb07","_nodeVersion":"20.19.3","_npmVersion":"10.8.2","dist":{"integrity":"sha512-JdFxUeb3duZaaIzlGk+R0fpS75gLO/Pqxk/EKh/IOfoizI+ibYOwfXcUBZTJYbvwg0mtvaR2Oqu98cRLnz9p9Q==","shasum":"da88b9c4ca244a8af042bc339fc38cd51480330c","tarball":"https://registry.npmjs.org/@aiassist-secure/core/-/core-1.0.0.tgz","fileCount":7,"unpackedSize":43759,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDOnnUXhnSOsGSin/dXIohvspLXjN5oSjjlCEzxsfOywgIgPJAShN7+RipK5551IYN2hKu186JPqPsy13xrIWHkQQk="}]},"_npmUser":{"name":"interchained","email":"interchained@gmail.com"},"directories":{},"maintainers":[{"name":"interchained","email":"interchained@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/core_1.0.0_1767913853067_0.8994736590354386"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-08T23:10:52.931Z","1.0.0":"2026-01-08T23:10:53.213Z","modified":"2026-01-08T23:10:53.565Z"},"maintainers":[{"name":"interchained","email":"interchained@gmail.com"}],"description":"AiAssist Secure TypeScript SDK - Framework-agnostic API client","homepage":"https://aiassist.net","keywords":["aiassist","aiassist-secure","ai","llm","openai","groq","chat","api","sdk"],"repository":{"type":"git","url":"git+https://github.com/aiassistsecure/aiassist-js.git"},"bugs":{"url":"https://github.com/aiassistsecure/aiassist-js/issues"},"license":"MIT","readme":"# @aiassist-secure/core\n\n[![npm version](https://img.shields.io/npm/v/@aiassist-secure/core.svg)](https://www.npmjs.com/package/@aiassist-secure/core)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n\n**Framework-agnostic TypeScript SDK for AiAssist Secure** - The enterprise AI orchestration platform with shadow mode, human-in-the-loop, and real-time typing indicators.\n\nWorks in **Node.js 18+** and **modern browsers**.\n\n---\n\n## Features\n\n- **OpenAI-Compatible API** - Drop-in replacement syntax\n- **Shadow Mode** - AI drafts require human approval before sending\n- **Human-in-the-Loop** - Seamless AI-to-human handoff detection\n- **Typing Preview** - Real-time \"AI is typing...\" indicators\n- **Streaming** - Server-sent events for token-by-token output\n- **Managed Workspaces** - Persistent conversation threads with context\n- **Full TypeScript** - Complete type definitions included\n\n---\n\n## Installation\n\n```bash\nnpm install @aiassist-secure/core\n# or\nyarn add @aiassist-secure/core\n# or\npnpm add @aiassist-secure/core\n```\n\n---\n\n## Quick Start\n\n```typescript\nimport { AiAssistClient } from '@aiassist-secure/core';\n\nconst client = new AiAssistClient({ apiKey: 'aai_your_key' });\n\n// Simple chat completion (OpenAI-compatible)\nconst response = await client.chat.completions.create({\n  messages: [{ role: 'user', content: 'Hello!' }]\n});\n\nconsole.log(response.choices[0].message.content);\n```\n\n---\n\n## Streaming Responses\n\nGet real-time token-by-token output:\n\n```typescript\nconst stream = await client.chat.completions.create({\n  messages: [{ role: 'user', content: 'Write a haiku about coding' }],\n  stream: true\n});\n\nfor await (const chunk of stream) {\n  const content = chunk.choices[0]?.delta?.content;\n  if (content) {\n    process.stdout.write(content); // Print each token as it arrives\n  }\n}\n```\n\n---\n\n## Managed Workspaces\n\nCreate persistent conversation threads with full context:\n\n```typescript\n// Create a workspace with system prompt and context\nconst { workspace, messages } = await client.workspaces.create({\n  clientId: 'user_123',\n  initial_message: 'Hello!',\n  system_prompt: 'You are a helpful customer support agent for Acme Inc.',\n  context: {\n    user_plan: 'enterprise',\n    previous_tickets: 3\n  }\n});\n\nconsole.log('Workspace ID:', workspace.id);\nconsole.log('AI Response:', messages[0].content);\n\n// Continue the conversation\nconst response = await client.workspaces.sendMessage(\n  workspace.id,\n  'I need help with my billing'\n);\n\nconsole.log('Mode:', response.mode); // 'ai' | 'shadow' | 'takeover'\nconsole.log('Response:', response.responses[0].content);\n\n// Get full conversation history\nconst history = await client.workspaces.getMessages(workspace.id);\n```\n\n---\n\n## Shadow Mode (Enterprise)\n\nIn shadow mode, AI drafts require manager approval before being sent to the client. Perfect for training, compliance, and quality assurance:\n\n```typescript\nconst response = await client.workspaces.sendMessage(workspace.id, 'Process my refund');\n\nif (response.pending_approval) {\n  console.log('AI drafted a response - awaiting manager approval');\n  console.log('Draft:', response.responses[0].content);\n  \n  // The message won't be visible to the end-user until approved\n  // Your manager dashboard can approve/reject/edit the draft\n}\n\n// Check workspace mode\nconsole.log('Current mode:', response.mode);\n// 'ai'      - Fully autonomous\n// 'shadow'  - AI drafts, human approves  \n// 'takeover' - Human control only\n```\n\n---\n\n## Human-in-the-Loop Detection\n\nDetect when a human agent takes over the conversation:\n\n```typescript\nconst response = await client.workspaces.sendMessage(workspace.id, 'I want to speak to a human');\n\nswitch (response.mode) {\n  case 'ai':\n    console.log('AI is handling this conversation');\n    break;\n  case 'shadow':\n    console.log('AI is drafting, but a human will review');\n    break;\n  case 'takeover':\n    console.log('A human agent has taken control');\n    // Update your UI to show \"Speaking with Support Agent\"\n    break;\n}\n```\n\n---\n\n## Typing Preview\n\nShow real-time \"AI is typing...\" indicators in your UI:\n\n```typescript\n// Poll for typing status (useful for chat UIs)\nconst status = await client.workspaces.getTypingStatus(workspace.id);\n\nif (status.is_typing) {\n  showTypingIndicator();\n  console.log('AI is composing a response...');\n} else {\n  hideTypingIndicator();\n}\n```\n\n---\n\n## End Conversation\n\nGracefully close conversations with optional feedback:\n\n```typescript\n// End the conversation\nawait client.workspaces.endConversation(workspace.id);\n\n// Or end with a reason/feedback\nawait client.workspaces.endConversation(workspace.id, {\n  reason: 'resolved',\n  feedback: 'Issue was resolved successfully'\n});\n```\n\n---\n\n## Configuration Options\n\n```typescript\nconst client = new AiAssistClient({\n  apiKey: 'aai_your_key',           // Required: Your API key\n  baseURL: 'https://api.aiassist.net', // Custom endpoint\n  timeout: 30000,                    // Request timeout (ms)\n  maxRetries: 3,                     // Retry failed requests\n  defaultHeaders: {                  // Custom headers\n    'X-Custom-Header': 'value'\n  }\n});\n```\n\n---\n\n## Error Handling\n\nTyped errors for precise error handling:\n\n```typescript\nimport {\n  AiAssistClient,\n  AuthenticationError,\n  RateLimitError,\n  APIError\n} from '@aiassist-secure/core';\n\ntry {\n  const response = await client.chat.completions.create({\n    messages: [{ role: 'user', content: 'Hello' }]\n  });\n} catch (error) {\n  if (error instanceof AuthenticationError) {\n    console.error('Invalid API key - check your credentials');\n  } else if (error instanceof RateLimitError) {\n    console.error(`Rate limited. Retry after ${error.retryAfter} seconds`);\n    // Implement exponential backoff\n  } else if (error instanceof APIError) {\n    console.error(`API error ${error.status}: ${error.message}`);\n  }\n}\n```\n\n---\n\n## List Available Models\n\n```typescript\nconst models = await client.models.list();\n\nconsole.log('Available models:');\nmodels.forEach(model => {\n  console.log(`- ${model.id}: ${model.context_length} tokens`);\n});\n\n// Example output:\n// - llama-3.3-70b-versatile: 128000 tokens\n// - llama-3.1-8b-instant: 131072 tokens\n// - mixtral-8x7b-32768: 32768 tokens\n```\n\n---\n\n## TypeScript Types\n\nFull type definitions included:\n\n```typescript\nimport type {\n  // Core types\n  Message,\n  ChatCompletion,\n  ChatCompletionChunk,\n  ChatCompletionCreateParams,\n  \n  // Workspace types\n  Workspace,\n  WorkspaceMessage,\n  WorkspaceCreateParams,\n  WorkspaceCreateResponse,\n  SendMessageResponse,\n  WorkspaceMode,        // 'ai' | 'shadow' | 'takeover'\n  WorkspaceStatus,      // 'active' | 'ended'\n  \n  // Client types\n  AiAssistClientOptions,\n} from '@aiassist-secure/core';\n```\n\n---\n\n## Browser Usage\n\nWorks directly in modern browsers via ESM:\n\n```html\n<script type=\"module\">\n  import { AiAssistClient } from 'https://esm.sh/@aiassist-secure/core';\n  \n  const client = new AiAssistClient({ \n    apiKey: 'aai_pub_your_domain_scoped_key' \n  });\n  \n  const response = await client.chat.completions.create({\n    messages: [{ role: 'user', content: 'Hello from the browser!' }]\n  });\n  \n  document.getElementById('output').textContent = \n    response.choices[0].message.content;\n</script>\n```\n\n**Note:** Use domain-scoped public keys (`aai_pub_*`) for browser environments.\n\n---\n\n## Related Packages\n\n| Package | Description |\n|---------|-------------|\n| [@aiassist-secure/react](https://www.npmjs.com/package/@aiassist-secure/react) | React components with built-in UI |\n| [@aiassist-secure/vanilla](https://www.npmjs.com/package/@aiassist-secure/vanilla) | Drop-in widget for any website |\n\n---\n\n## Links\n\n- [Documentation](https://aiassist.net/developer-docs/typescript)\n- [API Reference](https://aiassist.net/api-reference)\n- [GitHub](https://github.com/aiassistsecure/aiassist-js)\n- [Discord Community](https://discord.gg/aiassist)\n\n---\n\n## License\n\nMIT License - [Interchained LLC](https://interchained.com)\n","readmeFilename":"README.md","_rev":"1-d923121b5ee477ef825f41c366bce1a6"}