{"_id":"@131fgh/ditroy-client","_rev":"2-89da84f3bf8cf4c4c8be5598981332fe","name":"@131fgh/ditroy-client","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@131fgh/ditroy-client","version":"0.1.0","keywords":["ditroy","ai","sdk","chatbot","llm","ollama","memory","typescript"],"author":{"name":"DITroy Team"},"license":"MIT","_id":"@131fgh/ditroy-client@0.1.0","maintainers":[{"name":"131fgh","email":"keithvirgenes17@gmail.com"}],"dist":{"shasum":"dfecbce6642e39390d7ef144d152b13d01913f17","tarball":"https://registry.npmjs.org/@131fgh/ditroy-client/-/ditroy-client-0.1.0.tgz","fileCount":18,"integrity":"sha512-io/CGr1hxBTOiPln51h81RsPhaoRYWAb8je80d0CO6Qh8owUpPXQkYcYA/igCHDyTxXMbGpQ4AmsKY5jEalpog==","signatures":[{"sig":"MEUCICiNQYQ8FOQswTZ3gU4rj2lxO2guy9A2FX0+mvjDMz8yAiEA+MA4afXr2Oc643yqgVl9gp4zEY19oQXVeClC1LGd0w0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24528},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"850413a5360528cd928719e94eb6d94e9561512f","scripts":{"test":"node test_sdk.js","build":"tsc","clean":"rimraf dist","typecheck":"tsc --noEmit"},"_npmUser":{"name":"131fgh","email":"keithvirgenes17@gmail.com"},"_npmVersion":"11.19.0","description":"Universal JavaScript and TypeScript SDK for DITroy AI Backend","directories":{},"_nodeVersion":"26.7.0","_hasShrinkwrap":false,"devDependencies":{"typescript":"5.6.2"},"_npmOperationalInternal":{"tmp":"tmp/ditroy-client_0.1.0_1788099516414_0.22116311297381852","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"_id":"@131fgh/ditroy-client@0.2.0","dist":{"shasum":"50a6720878bdc9fc20c0d178e28dfe240b2461e5","tarball":"https://registry.npmjs.org/@131fgh/ditroy-client/-/ditroy-client-0.2.0.tgz","fileCount":18,"integrity":"sha512-sF8XAj4qzzyfpkx0fb8MDYlHBh3hQxXXjL/XKwN2RkVfSiWyt6TuuA0gQ6dzo2Qv82W2afZBrg8EZNUaWaSnEg==","signatures":[{"sig":"MEQCIBKomcIoTgUTyh7T1e3j8XNfKzt0dQHn6TKruvMGmLYFAiBKDtZPOlZKFuL2n3/89axxZecNCsi2Wc/Pvakro0RnOQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCxqzcUh4P7gqLrE2d91c9VwAS/uyHC0PhZVFZxkxXSNwIhAMG9roaeTg1GwXPYOYBZAMEv1RP1zL+s+B/sQ5JHdO8n"}],"unpackedSize":38996},"main":"./dist/index.js","name":"@131fgh/ditroy-client","type":"module","types":"./dist/index.d.ts","author":{"name":"DITroy Team"},"module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"a7716f595552080dba4b316ca63e5503fcab5205","license":"MIT","scripts":{"test":"node test_sdk.js","build":"tsc","clean":"rimraf dist","typecheck":"tsc --noEmit"},"version":"0.2.0","_npmUser":{"name":"131fgh","email":"keithvirgenes17@gmail.com"},"keywords":["ditroy","ai","sdk","chatbot","llm","gemini","groq","deepseek","ollama","failover","streaming","memory","typescript"],"_npmVersion":"11.19.0","description":"Universal JavaScript and TypeScript SDK for DITroy Multi-Provider AI Backend with automated failover and streaming","directories":{},"maintainers":[{"name":"131fgh","email":"keithvirgenes17@gmail.com"}],"_nodeVersion":"26.7.0","_hasShrinkwrap":false,"devDependencies":{"typescript":"5.6.2"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ditroy-client_0.2.0_1788182124556_0.9907526702077891"}}},"time":{"created":"2026-08-30T14:18:36.220Z","modified":"2026-08-31T13:15:24.781Z","0.1.0":"2026-08-30T14:18:36.528Z","0.2.0":"2026-08-31T13:15:24.632Z"},"author":{"name":"DITroy Team"},"license":"MIT","keywords":["ditroy","ai","sdk","chatbot","llm","gemini","groq","deepseek","ollama","failover","streaming","memory","typescript"],"description":"Universal JavaScript and TypeScript SDK for DITroy Multi-Provider AI Backend with automated failover and streaming","maintainers":[{"name":"131fgh","email":"keithvirgenes17@gmail.com"}],"readme":"# @131fgh/ditroy-client (v0.2.0)\n\nUniversal JavaScript and TypeScript SDK for the **DITroy Multi-Provider AI Cognitive Backend**.\n\nConnect any web, mobile, or backend application (Node.js, Next.js, React, Vue, Svelte, Express, Electron, React Native, Bun, Deno) to DITroy with complete type safety, automated multi-provider failover, real-time token streaming, and memory persistence.\n\n---\n\n## 📦 Installation\n\n```bash\nnpm install @131fgh/ditroy-client\n# or\npnpm add @131fgh/ditroy-client\n# or\nyarn add @131fgh/ditroy-client\n```\n\n---\n\n## 🚀 Quick Start\n\n### 1. Basic Chat with Persistent Memory & Automatic Fact Extraction\n\n```typescript\nimport { DitroyClient } from \"@131fgh/ditroy-client\";\n\n// Initialize client (defaults to http://localhost:8000 or process.env.DITROY_API_URL)\nconst ditroy = new DitroyClient({\n  baseUrl: \"http://localhost:8000\",\n  timeoutMs: 30000,\n});\n\nasync function main() {\n  // 1. Send a message - facts inside quotes are automatically indexed\n  const res = await ditroy.chat({\n    message: 'Please remember that our project code is \"Project Phoenix\".',\n    conversationId: \"session-1\",\n  });\n  console.log(\"DITroy:\", res.reply);\n\n  // 2. Spawn a new conversation inheriting remembered facts\n  const newSession = await ditroy.createConversation({\n    sourceConversationId: \"session-1\",\n  });\n  console.log(`Created new thread: ${newSession.conversation_id} (${newSession.inherited_facts} facts inherited)`);\n\n  // 3. Ask about the fact in the new thread\n  const followup = await ditroy.chat({\n    message: \"What is our project code?\",\n    conversationId: newSession.conversation_id,\n  });\n  console.log(\"DITroy:\", followup.reply);\n}\n\nmain();\n```\n\n---\n\n### 2. Real-Time Token-by-Token Streaming (`chatStream`)\n\nStream responses with ultra-low latency directly to your UI or console:\n\n```typescript\nimport { DitroyClient } from \"@131fgh/ditroy-client\";\n\nconst ditroy = new DitroyClient();\n\nasync function streamDemo() {\n  const stream = ditroy.chatStream({\n    message: \"Explain quantum computing in 3 sentences.\",\n    conversationId: \"stream-demo\",\n  });\n\n  process.stdout.write(\"DITroy: \");\n  for await (const token of stream) {\n    process.stdout.write(token);\n  }\n  console.log();\n}\n\nstreamDemo();\n```\n\n---\n\n### 3. Multi-Provider Diagnostics & Cascading Failover\n\nWhen DITroy backend is run with `MODEL_PROVIDER=fallback`, you can inspect active primary providers and health across all cloud and local models:\n\n```typescript\nimport { DitroyClient } from \"@131fgh/ditroy-client\";\n\nconst ditroy = new DitroyClient();\n\nconst health = await ditroy.getHealth();\nconsole.log(\"Overall Health:\", health.status);\nconsole.log(\"Active Primary Provider:\", health.active_primary); // e.g. 'groq' or 'gemini'\n\n// Inspect individual providers in the pool\nif (health.providers) {\n  for (const [provider, detail] of Object.entries(health.providers)) {\n    console.log(`- ${provider}: ${detail.status} (${detail.model || \"N/A\"})`);\n  }\n}\n```\n\n---\n\n### 4. Render / Cloud Keepalive Ping\n\nPrevent free tier backends (e.g. Render / Hugging Face) from sleeping:\n\n```typescript\nimport { DitroyClient } from \"@131fgh/ditroy-client\";\n\nconst ditroy = new DitroyClient({\n  baseUrl: \"https://your-app.onrender.com\",\n  cronSecret: \"your-optional-secret\",\n});\n\n// Send a keepalive ping\nconst keepalive = await ditroy.pingKeepalive();\nconsole.log(`Server Uptime: ${keepalive.uptime_human}, Pings Received: ${keepalive.pings_received}`);\n```\n\n---\n\n## 🛠️ API Reference\n\n### `new DitroyClient(options?)`\n\n| Option | Type | Default | Description |\n| :--- | :--- | :--- | :--- |\n| `baseUrl` | `string` | `http://localhost:8000` | Backend API base URL (or `DITROY_API_URL` / `NEXT_PUBLIC_API_URL`). |\n| `timeoutMs` | `number` | `60000` | Request timeout in milliseconds. |\n| `headers` | `Record<string, string>` | `{}` | Custom HTTP headers included with all requests. |\n| `authToken` | `string` | `undefined` | Optional Bearer JWT token for authenticated endpoints. |\n| `cronSecret` | `string` | `undefined` | Optional secret for `/api/cron/keepalive` protection. |\n| `customFetch` | `typeof fetch` | `globalThis.fetch` | Custom fetch implementation (useful for mocks or Node < 18). |\n\n### Methods\n\n| Method | Signature | Description |\n| :--- | :--- | :--- |\n| `chat` | `(request: string \\| ChatRequest) => Promise<ChatResponse>` | Sends a message prompt, executes fact extraction and memory context, returns AI reply. |\n| `chatStream` | `(request: string \\| ChatRequest, options?: ChatStreamOptions) => AsyncIterableIterator<string>` | Streams AI tokens in real-time. |\n| `createConversation` | `(request?: NewConversationRequest) => Promise<NewConversationResponse>` | Creates a new conversation thread, inheriting facts. |\n| `listConversations` | `() => Promise<ConversationListResponse>` | Returns list of recent conversations and titles. |\n| `getMessages` | `(conversationId: string, options?: { limit?: number }) => Promise<ConversationMessagesResponse>` | Retrieves message history for a conversation. |\n| `getHealth` | `() => Promise<HealthStatus>` | Returns provider statuses, active primary, and backend health. |\n| `getKeepalive` | `(secret?: string) => Promise<KeepaliveStatus>` | Queries the keepalive status and uptime of the backend. |\n| `pingKeepalive` | `(secret?: string) => Promise<KeepaliveStatus>` | Sends a keepalive ping signal. |\n\n---\n\n## ⚡ Error Handling\n\n```typescript\nimport { DitroyClient, DitroyAPIError, DitroyNetworkError } from \"@131fgh/ditroy-client\";\n\nconst ditroy = new DitroyClient();\n\ntry {\n  const response = await ditroy.chat(\"Hello!\");\n} catch (err) {\n  if (err instanceof DitroyAPIError) {\n    console.error(`API Error ${err.status}: ${err.message}`, err.data);\n  } else if (err instanceof DitroyNetworkError) {\n    console.error(`Network / Connection Error: ${err.message}`);\n  }\n}\n```\n\n---\n\n## 📄 License\n\nMIT © DITroy Team\n","readmeFilename":"README.md"}