{"_id":"@0latency/sdk","name":"@0latency/sdk","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@0latency/sdk","version":"0.1.0","description":"JavaScript/TypeScript SDK for 0Latency agent memory API","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"jest","prepublishOnly":"npm run build","lint":"eslint src --ext .ts"},"keywords":["0latency","memory","ai","agent","llm","vector","semantic-search"],"author":{"name":"Justin Ghiglia","email":"justin@0latency.ai"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/0latency/javascript-sdk.git"},"bugs":{"url":"https://github.com/0latency/javascript-sdk/issues"},"homepage":"https://0latency.ai","devDependencies":{"@types/jest":"^29.5.12","@types/node":"^20.11.24","@typescript-eslint/eslint-plugin":"^7.1.0","@typescript-eslint/parser":"^7.1.0","eslint":"^8.57.0","jest":"^29.7.0","ts-jest":"^29.1.2","typescript":"^5.3.3"},"dependencies":{},"_id":"@0latency/sdk@0.1.0","gitHead":"d0ab89607db692a7af2a236402981f3afe68ef92","_nodeVersion":"22.22.1","_npmVersion":"10.9.4","dist":{"integrity":"sha512-xjlPKyOR0zrPs31WuNxlsFfyZ9ad9zLAJlU4ORD4hl6DtSPX4xf3O023GuWbskTZJj90epXP+bbOp1ZlyDEg/A==","shasum":"e0f21d7b20653cfc75853ebe9b7db6ff2383c953","tarball":"https://registry.npmjs.org/@0latency/sdk/-/sdk-0.1.0.tgz","fileCount":19,"unpackedSize":30891,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIG98LrheFo4uWlJ0tgNY50UborWaieu0YnB9OdC3x/NkAiEA0rvFcarF0eUC4EHnUokZ8ddfoTvr4RXLPmxYuogOMxs="}]},"_npmUser":{"name":"jghiglia","email":"jghiglia@gmail.com"},"directories":{},"maintainers":[{"name":"jghiglia","email":"jghiglia@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk_0.1.0_1774515043511_0.5252170608330788"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-26T08:50:43.413Z","0.1.0":"2026-03-26T08:50:43.652Z","modified":"2026-03-26T08:50:44.082Z"},"maintainers":[{"name":"jghiglia","email":"jghiglia@gmail.com"}],"description":"JavaScript/TypeScript SDK for 0Latency agent memory API","homepage":"https://0latency.ai","keywords":["0latency","memory","ai","agent","llm","vector","semantic-search"],"repository":{"type":"git","url":"git+https://github.com/0latency/javascript-sdk.git"},"author":{"name":"Justin Ghiglia","email":"justin@0latency.ai"},"bugs":{"url":"https://github.com/0latency/javascript-sdk/issues"},"license":"MIT","readme":"# 0Latency JavaScript/TypeScript SDK\n\nA lightweight JavaScript/TypeScript client for the [0Latency](https://0latency.ai) agent memory API.\n\n## Installation\n\n```bash\nnpm install @0latency/sdk\n```\n\n## Quick Start\n\n```typescript\nimport { Memory } from '@0latency/sdk';\n\n// Initialize the client\nconst memory = new Memory({ apiKey: 'your-api-key' });\n\n// Add a memory\nawait memory.add('User prefers dark mode');\n\n// Recall relevant memories\nconst results = await memory.recall('What are the user preferences?');\nconsole.log(results);\n```\n\n## Features\n\n- **TypeScript-first**: Full type safety and IntelliSense support\n- **Zero dependencies**: Uses native fetch API (Node.js 18+, all modern browsers)\n- **Simple API**: Intuitive methods matching the Python SDK\n- **Error handling**: Custom error classes for different failure modes\n- **Timeout support**: Configurable request timeouts\n\n## API Reference\n\n### Constructor\n\n```typescript\nconst memory = new Memory({\n  apiKey: 'your-api-key',          // Required\n  baseUrl?: 'https://custom.api',  // Optional, defaults to api.0latency.ai\n  timeout?: 30000                   // Optional, defaults to 30000ms\n});\n```\n\n### Methods\n\n#### `add(content, options?)`\n\nStore a new memory.\n\n```typescript\nawait memory.add('User loves coffee', {\n  agentId: 'assistant-1',\n  metadata: { category: 'preferences', confidence: 0.95 }\n});\n```\n\n**Parameters:**\n- `content` (string): The text content to remember\n- `options` (optional):\n  - `agentId` (string): Agent identifier for scoping\n  - `metadata` (object): Key-value metadata to attach\n\n**Returns:** API confirmation payload\n\n---\n\n#### `recall(query, options?)`\n\nRetrieve relevant memories using semantic search.\n\n```typescript\nconst results = await memory.recall('What does the user like?', {\n  agentId: 'assistant-1',\n  limit: 5\n});\n```\n\n**Parameters:**\n- `query` (string): Natural-language search query\n- `options` (optional):\n  - `agentId` (string): Agent identifier for scoping\n  - `limit` (number): Maximum results (default: 10)\n\n**Returns:** Matching memories from the API\n\n---\n\n#### `extract(conversation, options?)`\n\nStart async memory extraction from a conversation.\n\n```typescript\nconst result = await memory.extract([\n  { role: 'user', content: 'I love hiking in the mountains' },\n  { role: 'assistant', content: 'That sounds wonderful!' }\n], { agentId: 'assistant-1' });\n\nconsole.log('Job ID:', result.job_id);\n```\n\n**Parameters:**\n- `conversation` (array): List of message objects with `role` and `content`\n- `options` (optional):\n  - `agentId` (string): Agent identifier\n\n**Returns:** Object containing `job_id` for status polling\n\n---\n\n#### `extractStatus(jobId)`\n\nCheck the status of an extraction job.\n\n```typescript\nconst status = await memory.extractStatus('job-123');\nconsole.log('Status:', status);\n```\n\n**Parameters:**\n- `jobId` (string): The job identifier returned by `extract()`\n\n**Returns:** Job status payload\n\n---\n\n#### `health()`\n\nCheck API health.\n\n```typescript\nconst health = await memory.health();\nconsole.log('API status:', health);\n```\n\n**Returns:** Health status payload\n\n## Usage Examples\n\n### Simple Chatbot Memory\n\n```typescript\nimport { Memory } from '@0latency/sdk';\n\nconst memory = new Memory({ apiKey: process.env.ZEROLATENCY_API_KEY });\n\nasync function chatWithMemory(userMessage: string) {\n  // Recall relevant context\n  const context = await memory.recall(userMessage, {\n    agentId: 'chatbot-1',\n    limit: 3\n  });\n\n  // Generate response using context (pseudo-code)\n  const response = await generateResponse(userMessage, context);\n\n  // Store the conversation for future recall\n  await memory.extract([\n    { role: 'user', content: userMessage },\n    { role: 'assistant', content: response }\n  ], { agentId: 'chatbot-1' });\n\n  return response;\n}\n```\n\n### Coding Agent with Project Memory\n\n```typescript\nimport { Memory } from '@0latency/sdk';\n\nconst memory = new Memory({ apiKey: process.env.ZEROLATENCY_API_KEY });\n\nasync function codingAgent(projectId: string, userRequest: string) {\n  // Recall project-specific knowledge\n  const projectKnowledge = await memory.recall(\n    `${userRequest} in the context of this project`,\n    { agentId: `project-${projectId}`, limit: 5 }\n  );\n\n  // Store important facts about the project\n  await memory.add('User prefers functional programming style', {\n    agentId: `project-${projectId}`,\n    metadata: { \n      category: 'coding-style',\n      project: projectId,\n      timestamp: Date.now()\n    }\n  });\n\n  return projectKnowledge;\n}\n```\n\n### Background Extraction\n\n```typescript\nimport { Memory } from '@0latency/sdk';\n\nconst memory = new Memory({ apiKey: process.env.ZEROLATENCY_API_KEY });\n\nasync function extractAndPoll(conversation: any[]) {\n  // Start extraction job\n  const { job_id } = await memory.extract(conversation, {\n    agentId: 'assistant-1'\n  });\n\n  // Poll for completion\n  let status;\n  do {\n    await new Promise(resolve => setTimeout(resolve, 1000)); // Wait 1 second\n    status = await memory.extractStatus(job_id);\n  } while (status.state === 'processing');\n\n  console.log('Extraction complete:', status);\n}\n```\n\n## Error Handling\n\nThe SDK provides custom error classes for different failure modes:\n\n```typescript\nimport { \n  Memory, \n  AuthenticationError, \n  RateLimitError, \n  ZeroLatencyError \n} from '@0latency/sdk';\n\nconst memory = new Memory({ apiKey: 'your-api-key' });\n\ntry {\n  await memory.add('Some content');\n} catch (error) {\n  if (error instanceof AuthenticationError) {\n    console.error('Invalid API key');\n  } else if (error instanceof RateLimitError) {\n    console.error('Rate limit exceeded, retry later');\n  } else if (error instanceof ZeroLatencyError) {\n    console.error('API error:', error.message, error.statusCode);\n  } else {\n    console.error('Unexpected error:', error);\n  }\n}\n```\n\n## TypeScript Support\n\nFull TypeScript definitions are included. Import types as needed:\n\n```typescript\nimport type { \n  MemoryConfig, \n  AddMemoryOptions,\n  RecallOptions,\n  ConversationMessage \n} from '@0latency/sdk';\n```\n\n## Requirements\n\n- **Node.js**: 18.0.0 or higher (for native fetch support)\n- **Browsers**: All modern browsers with fetch support\n\nFor older Node.js versions, you can polyfill fetch using `node-fetch` or `undici`.\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Support\n\n- **Email**: justin@0latency.ai\n- **Documentation**: [docs.0latency.ai](https://docs.0latency.ai)\n- **Issues**: [GitHub Issues](https://github.com/0latency/javascript-sdk/issues)\n\n## Contributing\n\nContributions welcome! Please open an issue or PR on GitHub.\n","readmeFilename":"README.md","_rev":"1-a92856e10da34a6e6191f255fbde4327"}