{"_id":"@aliyun-rds/rag-agent-sdk","_rev":"2-68e0fb44184141131999cc8769904253","name":"@aliyun-rds/rag-agent-sdk","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.1":{"name":"@aliyun-rds/rag-agent-sdk","version":"0.1.1","keywords":["rag","retrieval-augmented-generation","knowledge-graph","lightrag","sdk","api-client","typescript"],"author":{"name":"RAG Agent Team"},"license":"MIT","_id":"@aliyun-rds/rag-agent-sdk@0.1.1","maintainers":[{"name":"aiyi200","email":"aiyongpeng.ayp@alibaba-inc.com"},{"name":"lemontreen","email":"2305465291@qq.com"},{"name":"muxin414","email":"yanghaolei.yhl@alibaba-inc.com"}],"homepage":"https://github.com/rag-agent/rag-agent-sdk#readme","bugs":{"url":"https://github.com/rag-agent/rag-agent-sdk/issues"},"dist":{"shasum":"e973ff88e0d08af85f885dd24e442fd0ade218a9","tarball":"https://registry.npmjs.org/@aliyun-rds/rag-agent-sdk/-/rag-agent-sdk-0.1.1.tgz","fileCount":6,"integrity":"sha512-lpFrfWuNDLM9m6s7X/d2w5ljw8JkUtF+CuXojdccRxwwEr900eWfMuuaeqWl/OMJyD3IfJz5x3EsHQ3jEIcFfA==","signatures":[{"sig":"MEYCIQCw6DT0WdAFxMSopxS0mZcllOCcW5eivyxNIeTAqWNBMQIhAJSKhCkjuUSHO0vnbIqFV4K47Il/tKBBHd7TXZJLXReN","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":156809},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"4c38d265491a17257037e7d2a4575a044c271679","scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","lint":"eslint src --ext .ts","test":"vitest run","build":"tsup src/index.ts --format cjs,esm --dts --clean","lint:fix":"eslint src --ext .ts --fix","typecheck":"tsc --noEmit","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"aiyi200","email":"aiyongpeng.ayp@alibaba-inc.com"},"repository":{"url":"git+https://github.com/rag-agent/rag-agent-sdk.git","type":"git"},"_npmVersion":"11.6.0","description":"TypeScript SDK for RAG Agent API - A comprehensive client library for RAG Agent services","directories":{},"_nodeVersion":"23.10.0","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","eslint":"^8.54.0","vitest":"^1.0.0","typescript":"^5.3.0","@types/node":"^20.10.0","@typescript-eslint/parser":"^6.13.0","@typescript-eslint/eslint-plugin":"^6.13.0"},"peerDependencies":{"typescript":">=4.7.0"},"peerDependenciesMeta":{"typescript":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/rag-agent-sdk_0.1.1_1769183613287_0.9406696080253374","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2026-01-23T15:53:33.158Z","modified":"2026-03-10T12:09:06.009Z","0.1.1":"2026-01-23T15:53:33.527Z"},"bugs":{"url":"https://github.com/rag-agent/rag-agent-sdk/issues"},"author":{"name":"RAG Agent Team"},"license":"MIT","homepage":"https://github.com/rag-agent/rag-agent-sdk#readme","keywords":["rag","retrieval-augmented-generation","knowledge-graph","lightrag","sdk","api-client","typescript"],"repository":{"url":"git+https://github.com/rag-agent/rag-agent-sdk.git","type":"git"},"description":"TypeScript SDK for RAG Agent API - A comprehensive client library for RAG Agent services","maintainers":[{"email":"aiyongpeng.ayp@alibaba-inc.com","name":"aiyi200"},{"email":"archarload@gmail.com","name":"rds_memory"},{"email":"2305465291@qq.com","name":"lemontreen"},{"email":"yanghaolei.yhl@alibaba-inc.com","name":"muxin414"}],"readme":"# RAG Agent SDK for TypeScript/JavaScript\n\nA comprehensive TypeScript SDK for interacting with RAG Agent API services.\n\n## Installation\n\n```bash\nnpm install @rag-agent/sdk\n# or\nyarn add @rag-agent/sdk\n# or\npnpm add @rag-agent/sdk\n```\n\n## Quick Start\n\n```typescript\nimport { RagAgentClient } from '@rag-agent/sdk';\n\nconst client = new RagAgentClient({\n  baseUrl: 'http://localhost:9621',\n  apiKey: 'your-api-key',\n});\n\n// Create a dataset\nconst dataset = await client.datasets.create({\n  name: 'my-knowledge-base',\n  description: 'My first knowledge base',\n});\nconsole.log(`Created dataset: ${dataset.dataset_uuid}`);\n\n// Upload a document\nconst file = new File(['document content'], 'doc.txt', { type: 'text/plain' });\nconst result = await client.documents.upload(dataset.dataset_uuid, file);\nconsole.log(`Upload status: ${result.status}`);\n\n// Query the dataset\nconst response = await client.query.query(\n  dataset.dataset_uuid,\n  'What is this document about?',\n  { mode: 'mix' }\n);\nconsole.log(`Answer: ${response.response}`);\n```\n\n## Authentication\n\nThe SDK supports multiple authentication methods:\n\n### API Key Authentication\n\n```typescript\nconst client = new RagAgentClient({\n  baseUrl: 'http://localhost:9621',\n  apiKey: 'your-api-key',\n});\n```\n\n### JWT Token Authentication\n\n```typescript\nconst client = new RagAgentClient({\n  baseUrl: 'http://localhost:9621',\n  jwtToken: 'your-jwt-token',\n});\n```\n\n### Supabase Authentication\n\n```typescript\nconst client = new RagAgentClient({\n  baseUrl: 'http://localhost:9621',\n  supabaseUrl: 'https://xxx.supabase.co',\n  supabaseAnonKey: 'your-anon-key',\n  supabaseAccessToken: 'user-access-token',\n});\n```\n\n### Username/Password Authentication\n\n```typescript\nconst client = new RagAgentClient({\n  baseUrl: 'http://localhost:9621',\n  username: 'admin',\n  password: 'password',\n});\n```\n\n## Features\n\n### Dataset Management\n\n```typescript\n// List datasets\nconst datasets = await client.datasets.list({ page: 1, pageSize: 20 });\n\n// Get dataset by ID\nconst dataset = await client.datasets.get('dataset-uuid');\n\n// Update dataset\nconst updated = await client.datasets.update('dataset-uuid', {\n  description: 'Updated description',\n});\n\n// Delete dataset\nawait client.datasets.delete('dataset-uuid');\n```\n\n### Document Processing\n\n```typescript\n// Upload file\nconst result = await client.documents.upload(datasetId, file);\n\n// Insert text\nconst result = await client.documents.insertText(\n  datasetId,\n  'Your text content here',\n  'manual-input'\n);\n\n// Batch insert\nconst result = await client.documents.insertBatch(\n  datasetId,\n  ['Text 1', 'Text 2', 'Text 3'],\n  ['source1', 'source2', 'source3']\n);\n\n// List documents\nconst docs = await client.documents.list(datasetId);\n\n// Delete document\nawait client.documents.delete(datasetId, docId);\n```\n\n### RAG Queries\n\n```typescript\n// Basic query\nconst response = await client.query.query(\n  datasetId,\n  'What is the main topic?',\n  { mode: 'mix', topK: 10 }\n);\n\n// Streaming query\nfor await (const chunk of client.query.queryStream(\n  datasetId,\n  'Explain the concept in detail'\n)) {\n  process.stdout.write(chunk);\n}\n\n// Cross-dataset query\nconst response = await client.query.crossDatasetQuery(\n  'Compare the topics',\n  ['uuid1', 'uuid2'],\n  { enableRerank: true }\n);\n\n// Get context only (without LLM response)\nconst context = await client.query.getContext(\n  datasetId,\n  'Find relevant information'\n);\nconsole.log(`Entities: ${context.entities?.length}`);\nconsole.log(`Chunks: ${context.chunks?.length}`);\n```\n\n### Knowledge Graph\n\n```typescript\n// Get knowledge graph\nconst graph = await client.graph.getKnowledgeGraph(\n  datasetId,\n  'Person',\n  { maxDepth: 2, maxNodes: 100 }\n);\n\n// Get all labels\nconst labels = await client.graph.getLabels(datasetId);\n\n// Check entity exists\nconst exists = await client.graph.checkEntityExists(datasetId, 'John Doe');\n\n// Edit entity\nawait client.graph.editEntity(\n  datasetId,\n  'John Doe',\n  { description: 'Updated description' },\n  false // allowRename\n);\n```\n\n## Error Handling\n\n```typescript\nimport {\n  RagAgentError,\n  AuthenticationError,\n  AuthorizationError,\n  DatasetNotFoundError,\n  ValidationError,\n} from '@rag-agent/sdk';\n\ntry {\n  const dataset = await client.datasets.get('non-existent-id');\n} catch (error) {\n  if (error instanceof DatasetNotFoundError) {\n    console.log(`Dataset not found: ${error.datasetId}`);\n  } else if (error instanceof AuthenticationError) {\n    console.log('Authentication failed - check your credentials');\n  } else if (error instanceof AuthorizationError) {\n    console.log('Permission denied');\n  } else if (error instanceof RagAgentError) {\n    console.log(`API error: ${error.message} (status: ${error.statusCode})`);\n  }\n}\n```\n\n## Configuration Options\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `baseUrl` | string | required | RAG Agent server URL |\n| `apiKey` | string | - | API key for authentication |\n| `jwtToken` | string | - | JWT token for authentication |\n| `timeout` | number | 30000 | Request timeout in milliseconds |\n| `maxRetries` | number | 3 | Maximum retry attempts |\n| `retryDelay` | number | 1000 | Initial delay between retries (ms) |\n\n## TypeScript Support\n\nThis SDK is written in TypeScript and provides full type definitions out of the box.\n\n```typescript\nimport type {\n  Dataset,\n  Document,\n  QueryResponse,\n  QueryMode,\n  Entity,\n  Relation,\n} from '@rag-agent/sdk';\n```\n\n## Browser Support\n\nThis SDK works in modern browsers and Node.js environments. It uses the native `fetch` API.\n\n## License\n\nMIT License\n","readmeFilename":"README.md"}