diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b90b92e..ca5b3dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: timeout-minutes: 10 name: lint runs-on: ${{ github.repository == 'stainless-sdks/hyperspell-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} - if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - uses: actions/checkout@v6 @@ -43,7 +43,7 @@ jobs: timeout-minutes: 5 name: build runs-on: ${{ github.repository == 'stainless-sdks/hyperspell-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} - if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') permissions: contents: read id-token: write diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index 5884b8b..910fb78 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -37,12 +37,14 @@ jobs: - name: Publish to NPM run: | - if [ -n "${{ github.event.inputs.path }}" ]; then - PATHS_RELEASED='[\"${{ github.event.inputs.path }}\"]' + if [ -n "$INPUT_PATH" ]; then + PATHS_RELEASED="[\"$INPUT_PATH\"]" else PATHS_RELEASED='[\".\", \"packages/mcp-server\"]' fi pnpm tsn scripts/publish-packages.ts "{ \"paths_released\": \"$PATHS_RELEASED\" }" + env: + INPUT_PATH: ${{ github.event.inputs.path }} - name: Upload MCP Server DXT GitHub release asset run: | diff --git a/.gitignore b/.gitignore index d62bea5..ae4aa20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .prism.log +.stdy.log node_modules yarn-error.log codegen.log @@ -10,3 +11,4 @@ dist-deno .eslintcache dist-bundle *.mcpb +oidc diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 3a39fd8..811a88e 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.35.0" + ".": "0.35.1" } diff --git a/.stats.yml b/.stats.yml index fa46781..61b9e21 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hyperspell%2Fhyperspell-b1f2b7cb843e6f4e6123e838ce29cbbaea0a48b1a72057632de1d0d21727c5d8.yml -openapi_spec_hash: 21a354f587a2fe19797860c7b6da81a9 -config_hash: 0ed970a9634b33d0af471738b478740d +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hyperspell%2Fhyperspell-460d7c66cd5e8cf979cd761066c51d8f813a119a20e2149fcfcf847eb650d545.yml +openapi_spec_hash: 8ee512464a88de45c86faf4f46f4905c +config_hash: bd8505e17db740d82e578d0edaa9bfe0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 559535f..9260605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,58 @@ # Changelog +## 0.35.1 (2026-04-09) + +Full Changelog: [v0.35.0...v0.35.1](https://github.com/hyperspell/node-sdk/compare/v0.35.0...v0.35.1) + +### Features + +* add 'mood' to memory type unions ([#89](https://github.com/hyperspell/node-sdk/issues/89)) ([76d16b8](https://github.com/hyperspell/node-sdk/commit/76d16b8175736cfd019f10f7363bb0d1b9d274a0)) +* **api:** api update ([9451cde](https://github.com/hyperspell/node-sdk/commit/9451cde625b2736fee26be6e5181e6b1a0ffc5c2)) +* **api:** api update ([138925b](https://github.com/hyperspell/node-sdk/commit/138925b62920e96037ff82db171bd96b8a049a98)) +* **api:** api update ([1394392](https://github.com/hyperspell/node-sdk/commit/13943920182f9150b8222e5dc27d6fe69ecbc7eb)) +* **api:** api update ([acf8988](https://github.com/hyperspell/node-sdk/commit/acf8988fd0e5ace07a871bbc2160db7d072effab)) +* **api:** api update ([408ed83](https://github.com/hyperspell/node-sdk/commit/408ed8311554d2110d88031dad7a11f0943ce06c)) +* **api:** api update ([62d04a2](https://github.com/hyperspell/node-sdk/commit/62d04a239910847ecbc4b644a13956f9b246a506)) +* **api:** manual updates ([1b7ca39](https://github.com/hyperspell/node-sdk/commit/1b7ca39a9894d6649349ceb7d4f61de8d981c9f8)) + + +### Bug Fixes + +* **internal:** gitignore generated `oidc` dir ([a305f3d](https://github.com/hyperspell/node-sdk/commit/a305f3d8f340bbb1838b0e75ed0ca2e7da0d6cff)) + + +### Chores + +* **ci:** escape input path in publish-npm workflow ([40c8402](https://github.com/hyperspell/node-sdk/commit/40c84026a515ae0b62f676b71b8746ebfd254177)) +* **ci:** skip lint on metadata-only changes ([14012e7](https://github.com/hyperspell/node-sdk/commit/14012e72febb7af66800c6e0f4c389cf5104a1d3)) +* configure new SDK language ([2b1db35](https://github.com/hyperspell/node-sdk/commit/2b1db353a21ecb4c3200e44d7853587c90c7625c)) +* **internal:** codegen related update ([74743e3](https://github.com/hyperspell/node-sdk/commit/74743e38189fcce572490e5ad3d0700209836db5)) +* **internal:** fix MCP server import ordering ([aa4d800](https://github.com/hyperspell/node-sdk/commit/aa4d8007866d8417cb8af1c9d17c11d59d8c1d3c)) +* **internal:** fix MCP server TS errors that occur with required client options ([b7abcfb](https://github.com/hyperspell/node-sdk/commit/b7abcfb96eac3b96305957762f6cadb399236583)) +* **internal:** improve local docs search for MCP servers ([eee2438](https://github.com/hyperspell/node-sdk/commit/eee2438cecb6267496d8b068d2b6b370dcce586c)) +* **internal:** improve local docs search for MCP servers ([f218072](https://github.com/hyperspell/node-sdk/commit/f218072eee356e59cb1f7b0e3e667902acb30c79)) +* **internal:** support custom-instructions-path flag in MCP servers ([c6d4043](https://github.com/hyperspell/node-sdk/commit/c6d404331011597d4ee14440eeb71faaed16ad95)) +* **internal:** support local docs search in MCP servers ([4a9b2cf](https://github.com/hyperspell/node-sdk/commit/4a9b2cfd823fce71d3a08e435e545a97247abba5)) +* **internal:** support type annotations when running MCP in local execution mode ([41a4e6a](https://github.com/hyperspell/node-sdk/commit/41a4e6a998f03224e0aa765c348f7d4d96a98d01)) +* **internal:** update gitignore ([9270ff5](https://github.com/hyperspell/node-sdk/commit/9270ff5aac78355a25f64d1ccabb773c45120f36)) +* **internal:** update multipart form array serialization ([97f213b](https://github.com/hyperspell/node-sdk/commit/97f213bf19e619a90ca72254e6e9d407aaecb41b)) +* **mcp-server:** add support for session id, forward client info ([9e3018f](https://github.com/hyperspell/node-sdk/commit/9e3018f7649a0533788b5a9a75875dbfde5cd493)) +* **mcp-server:** increase local docs search result count from 5 to 10 ([65850d9](https://github.com/hyperspell/node-sdk/commit/65850d9589624991aa107fda8309bddfeef88fb5)) +* **mcp-server:** log client info ([5f1ad6d](https://github.com/hyperspell/node-sdk/commit/5f1ad6d048afabe3d270edf2fd8905053a7cb29f)) +* **tests:** bump steady to v0.19.4 ([e614b67](https://github.com/hyperspell/node-sdk/commit/e614b6739cf3d7398e4d05d806ae0706c3264276)) +* **tests:** bump steady to v0.19.5 ([eadfc98](https://github.com/hyperspell/node-sdk/commit/eadfc98aa8e6dfc6728a8028f01abcb4ffe91c8c)) +* **tests:** bump steady to v0.19.6 ([4ed8bba](https://github.com/hyperspell/node-sdk/commit/4ed8bbac6d2a25580c3355ec7d5309ba18ffd3be)) +* **tests:** bump steady to v0.19.7 ([6aaa435](https://github.com/hyperspell/node-sdk/commit/6aaa43556ea42c3c3440569b051c25adda5046c7)) +* **tests:** bump steady to v0.20.1 ([bb96b8b](https://github.com/hyperspell/node-sdk/commit/bb96b8b039f8a6d906540298e31ebe3e0cd4549e)) +* **tests:** bump steady to v0.20.2 ([2a71a6e](https://github.com/hyperspell/node-sdk/commit/2a71a6e88d24933ce432279a88062fa849454586)) +* update SDK settings ([4ee9dca](https://github.com/hyperspell/node-sdk/commit/4ee9dca0d9d188abab3fabe72c5a9d2e53e49994)) +* update SDK settings ([752879e](https://github.com/hyperspell/node-sdk/commit/752879e4c937f55b93ab0da3a002e18bb71240c5)) + + +### Refactors + +* **tests:** switch from prism to steady ([75ac934](https://github.com/hyperspell/node-sdk/commit/75ac9345ea6849863c3469f24dc2393046a6dcd0)) + ## 0.35.0 (2026-03-18) Full Changelog: [v0.34.0...v0.35.0](https://github.com/hyperspell/node-sdk/compare/v0.34.0...v0.35.0) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0bc8011..7b6dc76 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,7 +65,7 @@ $ pnpm link --global hyperspell ## Running tests -Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests. +Most tests require you to [set up a mock server](https://github.com/dgellow/steady) against the OpenAPI spec to run the tests. ```sh $ ./scripts/mock diff --git a/package.json b/package.json index ffd3a78..fdc1def 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hyperspell", - "version": "0.35.0", + "version": "0.35.1", "description": "The official TypeScript library for the Hyperspell API", "author": "Hyperspell ", "types": "dist/index.d.ts", diff --git a/packages/mcp-server/manifest.json b/packages/mcp-server/manifest.json index 27cc620..e47427a 100644 --- a/packages/mcp-server/manifest.json +++ b/packages/mcp-server/manifest.json @@ -1,7 +1,7 @@ { "dxt_version": "0.2", "name": "hyperspell-mcp", - "version": "0.35.0", + "version": "0.35.1", "description": "The official MCP Server for the Hyperspell API", "author": { "name": "Hyperspell", diff --git a/packages/mcp-server/package.json b/packages/mcp-server/package.json index c23553d..7457f9b 100644 --- a/packages/mcp-server/package.json +++ b/packages/mcp-server/package.json @@ -1,6 +1,6 @@ { "name": "hyperspell-mcp", - "version": "0.35.0", + "version": "0.35.1", "description": "The official MCP Server for the Hyperspell API", "author": "Hyperspell ", "types": "dist/index.d.ts", @@ -40,6 +40,7 @@ "cors": "^2.8.5", "express": "^5.1.0", "fuse.js": "^7.1.0", + "minisearch": "^7.2.0", "jq-web": "https://github.com/stainless-api/jq-web/releases/download/v0.8.8/jq-web.tar.gz", "pino": "^10.3.1", "pino-http": "^11.0.0", diff --git a/packages/mcp-server/src/code-tool-worker.ts b/packages/mcp-server/src/code-tool-worker.ts index e32c630..d972874 100644 --- a/packages/mcp-server/src/code-tool-worker.ts +++ b/packages/mcp-server/src/code-tool-worker.ts @@ -7,6 +7,10 @@ import ts from 'typescript'; import { WorkerOutput } from './code-tool-types'; import { Hyperspell, ClientOptions } from 'hyperspell'; +async function tseval(code: string) { + return import('data:application/typescript;charset=utf-8;base64,' + Buffer.from(code).toString('base64')); +} + function getRunFunctionSource(code: string): { type: 'declaration' | 'expression'; client: string | undefined; @@ -266,7 +270,9 @@ const fetch = async (req: Request): Promise => { const log_lines: string[] = []; const err_lines: string[] = []; - const console = { + const originalConsole = globalThis.console; + globalThis.console = { + ...originalConsole, log: (...args: unknown[]) => { log_lines.push(util.format(...args)); }, @@ -276,7 +282,7 @@ const fetch = async (req: Request): Promise => { }; try { let run_ = async (client: any) => {}; - eval(`${code}\nrun_ = run;`); + run_ = (await tseval(`${code}\nexport default run;`)).default; const result = await run_(makeSdkProxy(client, { path: ['client'] })); return Response.json({ is_error: false, @@ -294,6 +300,8 @@ const fetch = async (req: Request): Promise => { } satisfies WorkerOutput, { status: 400, statusText: 'Code execution error' }, ); + } finally { + globalThis.console = originalConsole; } }; diff --git a/packages/mcp-server/src/code-tool.ts b/packages/mcp-server/src/code-tool.ts index 0b85b1d..b26fc4c 100644 --- a/packages/mcp-server/src/code-tool.ts +++ b/packages/mcp-server/src/code-tool.ts @@ -285,16 +285,14 @@ const localDenoHandler = async ({ // Strip null/undefined values so that the worker SDK client can fall back to // reading from environment variables (including any upstreamClientEnvs). - const opts: ClientOptions = Object.fromEntries( - Object.entries({ - baseURL: client.baseURL, - apiKey: client.apiKey, - userID: client.userID, - defaultHeaders: { - 'X-Stainless-MCP': 'true', - }, - }).filter(([_, v]) => v != null), - ) as ClientOptions; + const opts = { + ...(client.baseURL != null ? { baseURL: client.baseURL } : undefined), + ...(client.apiKey != null ? { apiKey: client.apiKey } : undefined), + ...(client.userID != null ? { userID: client.userID } : undefined), + defaultHeaders: { + 'X-Stainless-MCP': 'true', + }, + } satisfies Partial as ClientOptions; const req = worker.request( 'http://localhost', diff --git a/packages/mcp-server/src/docs-search-tool.ts b/packages/mcp-server/src/docs-search-tool.ts index 1f3dbad..b288e63 100644 --- a/packages/mcp-server/src/docs-search-tool.ts +++ b/packages/mcp-server/src/docs-search-tool.ts @@ -3,6 +3,7 @@ import { Tool } from '@modelcontextprotocol/sdk/types.js'; import { Metadata, McpRequestContext, asTextContentResult } from './types'; import { getLogger } from './logger'; +import type { LocalDocsSearch } from './local-docs-search'; export const metadata: Metadata = { resource: 'all', @@ -43,13 +44,30 @@ export const tool: Tool = { const docsSearchURL = process.env['DOCS_SEARCH_URL'] || 'https://api.stainless.com/api/projects/hyperspell/docs/search'; -export const handler = async ({ - reqContext, - args, -}: { - reqContext: McpRequestContext; - args: Record | undefined; -}) => { +let _localSearch: LocalDocsSearch | undefined; + +export function setLocalSearch(search: LocalDocsSearch): void { + _localSearch = search; +} + +async function searchLocal(args: Record): Promise { + if (!_localSearch) { + throw new Error('Local search not initialized'); + } + + const query = (args['query'] as string) ?? ''; + const language = (args['language'] as string) ?? 'typescript'; + const detail = (args['detail'] as string) ?? 'default'; + + return _localSearch.search({ + query, + language, + detail, + maxResults: 10, + }).results; +} + +async function searchRemote(args: Record, reqContext: McpRequestContext): Promise { const body = args as any; const query = new URLSearchParams(body).toString(); @@ -57,6 +75,10 @@ export const handler = async ({ const result = await fetch(`${docsSearchURL}?${query}`, { headers: { ...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }), + ...(reqContext.mcpSessionId && { 'x-stainless-mcp-session-id': reqContext.mcpSessionId }), + ...(reqContext.mcpClientInfo && { + 'x-stainless-mcp-client-info': JSON.stringify(reqContext.mcpClientInfo), + }), }, }); @@ -94,7 +116,23 @@ export const handler = async ({ }, 'Got docs search result', ); - return asTextContentResult(resultBody); + return resultBody; +} + +export const handler = async ({ + reqContext, + args, +}: { + reqContext: McpRequestContext; + args: Record | undefined; +}) => { + const body = args ?? {}; + + if (_localSearch) { + return asTextContentResult(await searchLocal(body)); + } + + return asTextContentResult(await searchRemote(body, reqContext)); }; export default { metadata, tool, handler }; diff --git a/packages/mcp-server/src/http.ts b/packages/mcp-server/src/http.ts index 8632399..c7d9e18 100644 --- a/packages/mcp-server/src/http.ts +++ b/packages/mcp-server/src/http.ts @@ -23,7 +23,8 @@ const newServer = async ({ res: express.Response; }): Promise => { const stainlessApiKey = getStainlessApiKey(req, mcpOptions); - const server = await newMcpServer(stainlessApiKey); + const customInstructionsPath = mcpOptions.customInstructionsPath; + const server = await newMcpServer({ stainlessApiKey, customInstructionsPath }); const authOptions = parseClientAuthHeaders(req, false); @@ -68,6 +69,11 @@ const newServer = async ({ } } + const mcpClientInfo = + typeof req.body?.params?.clientInfo?.name === 'string' ? + { name: req.body.params.clientInfo.name, version: String(req.body.params.clientInfo.version ?? '') } + : undefined; + await initMcpServer({ server: server, mcpOptions: effectiveMcpOptions, @@ -77,8 +83,14 @@ const newServer = async ({ }, stainlessApiKey: stainlessApiKey, upstreamClientEnvs, + mcpSessionId: (req as any).mcpSessionId, + mcpClientInfo, }); + if (mcpClientInfo) { + getLogger().info({ mcpSessionId: (req as any).mcpSessionId, mcpClientInfo }, 'MCP client connected'); + } + return server; }; @@ -134,9 +146,23 @@ export const streamableHTTPApp = ({ const app = express(); app.set('query parser', 'extended'); app.use(express.json()); + app.use((req: express.Request, res: express.Response, next: express.NextFunction) => { + const existing = req.headers['mcp-session-id']; + const sessionId = (Array.isArray(existing) ? existing[0] : existing) || crypto.randomUUID(); + (req as any).mcpSessionId = sessionId; + const origWriteHead = res.writeHead.bind(res); + res.writeHead = function (statusCode: number, ...rest: any[]) { + res.setHeader('mcp-session-id', sessionId); + return origWriteHead(statusCode, ...rest); + } as typeof res.writeHead; + next(); + }); app.use( pinoHttp({ logger: getLogger(), + customProps: (req) => ({ + mcpSessionId: (req as any).mcpSessionId, + }), customLogLevel: (req, res) => { if (res.statusCode >= 500) { return 'error'; diff --git a/packages/mcp-server/src/instructions.ts b/packages/mcp-server/src/instructions.ts index ab27083..12e717b 100644 --- a/packages/mcp-server/src/instructions.ts +++ b/packages/mcp-server/src/instructions.ts @@ -1,7 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { readEnv } from './util'; +import fs from 'fs/promises'; import { getLogger } from './logger'; +import { readEnv } from './util'; const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes @@ -12,9 +13,15 @@ interface InstructionsCacheEntry { const instructionsCache = new Map(); -export async function getInstructions(stainlessApiKey: string | undefined): Promise { +export async function getInstructions({ + stainlessApiKey, + customInstructionsPath, +}: { + stainlessApiKey?: string | undefined; + customInstructionsPath?: string | undefined; +}): Promise { const now = Date.now(); - const cacheKey = stainlessApiKey ?? ''; + const cacheKey = customInstructionsPath ?? stainlessApiKey ?? ''; const cached = instructionsCache.get(cacheKey); if (cached && now - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) { @@ -28,12 +35,28 @@ export async function getInstructions(stainlessApiKey: string | undefined): Prom } } - const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey); + let fetchedInstructions: string; + + if (customInstructionsPath) { + fetchedInstructions = await fetchLatestInstructionsFromFile(customInstructionsPath); + } else { + fetchedInstructions = await fetchLatestInstructionsFromApi(stainlessApiKey); + } + instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: now }); return fetchedInstructions; } -async function fetchLatestInstructions(stainlessApiKey: string | undefined): Promise { +async function fetchLatestInstructionsFromFile(path: string): Promise { + try { + return await fs.readFile(path, 'utf-8'); + } catch (error) { + getLogger().error({ error, path }, 'Error fetching instructions from file'); + throw error; + } +} + +async function fetchLatestInstructionsFromApi(stainlessApiKey: string | undefined): Promise { // Setting the stainless API key is optional, but may be required // to authenticate requests to the Stainless API. const response = await fetch( diff --git a/packages/mcp-server/src/local-docs-search.ts b/packages/mcp-server/src/local-docs-search.ts new file mode 100644 index 0000000..eb8fc7c --- /dev/null +++ b/packages/mcp-server/src/local-docs-search.ts @@ -0,0 +1,1589 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import MiniSearch from 'minisearch'; +import * as fs from 'node:fs/promises'; +import * as path from 'node:path'; +import { getLogger } from './logger'; + +type PerLanguageData = { + method?: string; + example?: string; +}; + +type MethodEntry = { + name: string; + endpoint: string; + httpMethod: string; + summary: string; + description: string; + stainlessPath: string; + qualified: string; + params?: string[]; + response?: string; + markdown?: string; + perLanguage?: Record; +}; + +type ProseChunk = { + content: string; + tag: string; + sectionContext?: string; + source?: string; +}; + +type MiniSearchDocument = { + id: string; + kind: 'http_method' | 'prose'; + name?: string; + endpoint?: string; + summary?: string; + description?: string; + qualified?: string; + stainlessPath?: string; + content?: string; + sectionContext?: string; + _original: Record; +}; + +type SearchResult = { + results: (string | Record)[]; +}; + +const EMBEDDED_METHODS: MethodEntry[] = [ + { + name: 'revoke', + endpoint: '/connections/{connection_id}/revoke', + httpMethod: 'delete', + summary: 'Revoke connection', + description: + "Revokes Hyperspell's access the given provider and deletes all stored credentials and indexed data.", + stainlessPath: '(resource) connections > (method) revoke', + qualified: 'client.connections.revoke', + params: ['connection_id: string;'], + response: '{ message: string; success: boolean; }', + markdown: + "## revoke\n\n`client.connections.revoke(connection_id: string): { message: string; success: boolean; }`\n\n**delete** `/connections/{connection_id}/revoke`\n\nRevokes Hyperspell's access the given provider and deletes all stored credentials and indexed data.\n\n### Parameters\n\n- `connection_id: string`\n\n### Returns\n\n- `{ message: string; success: boolean; }`\n\n - `message: string`\n - `success: boolean`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.connections.revoke('connection_id');\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'connections revoke', + example: + "hyperspell connections revoke \\\n --api-key 'My API Key' \\\n --connection-id connection_id", + }, + go: { + method: 'client.Connections.Revoke', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Connections.Revoke(context.TODO(), "connection_id")\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.Message)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/connections/$CONNECTION_ID/revoke \\\n -X DELETE \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'connections.revoke', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.connections.revoke(\n "connection_id",\n)\nprint(response.message)', + }, + typescript: { + method: 'client.connections.revoke', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.connections.revoke('connection_id');\n\nconsole.log(response.message);", + }, + }, + }, + { + name: 'list', + endpoint: '/connections/list', + httpMethod: 'get', + summary: 'List connections', + description: 'List all connections for the user.', + stainlessPath: '(resource) connections > (method) list', + qualified: 'client.connections.list', + response: '{ connections: { id: string; integration_id: string; label: string; provider: string; }[]; }', + markdown: + "## list\n\n`client.connections.list(): { connections: object[]; }`\n\n**get** `/connections/list`\n\nList all connections for the user.\n\n### Returns\n\n- `{ connections: { id: string; integration_id: string; label: string; provider: string; }[]; }`\n\n - `connections: { id: string; integration_id: string; label: string; provider: string; }[]`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst connections = await client.connections.list();\n\nconsole.log(connections);\n```", + perLanguage: { + cli: { + method: 'connections list', + example: "hyperspell connections list \\\n --api-key 'My API Key'", + }, + go: { + method: 'client.Connections.List', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tconnections, err := client.Connections.List(context.TODO())\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", connections.Connections)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/connections/list \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'connections.list', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nconnections = client.connections.list()\nprint(connections.connections)', + }, + typescript: { + method: 'client.connections.list', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst connections = await client.connections.list();\n\nconsole.log(connections.connections);", + }, + }, + }, + { + name: 'list', + endpoint: '/connections/{connection_id}/folders', + httpMethod: 'get', + summary: 'List folders for a connection', + description: + "List one level of folders from the user's connected source.\n\nReturns folders decorated with their explicit folder policy (if any).\nUse parent_id to drill into subfolders.", + stainlessPath: '(resource) folders > (method) list', + qualified: 'client.folders.list', + params: ['connection_id: string;', 'parent_id?: string;'], + response: + "{ folders: { has_children: boolean; name: string; provider_folder_id: string; parent_folder_id?: string; policy?: { id: string; sync_mode: 'sync' | 'skip' | 'manual'; }; }[]; }", + markdown: + "## list\n\n`client.folders.list(connection_id: string, parent_id?: string): { folders: object[]; }`\n\n**get** `/connections/{connection_id}/folders`\n\nList one level of folders from the user's connected source.\n\nReturns folders decorated with their explicit folder policy (if any).\nUse parent_id to drill into subfolders.\n\n### Parameters\n\n- `connection_id: string`\n\n- `parent_id?: string`\n Parent folder ID. Omit for root-level folders.\n\n### Returns\n\n- `{ folders: { has_children: boolean; name: string; provider_folder_id: string; parent_folder_id?: string; policy?: { id: string; sync_mode: 'sync' | 'skip' | 'manual'; }; }[]; }`\n\n - `folders: { has_children: boolean; name: string; provider_folder_id: string; parent_folder_id?: string; policy?: { id: string; sync_mode: 'sync' | 'skip' | 'manual'; }; }[]`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst folders = await client.folders.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');\n\nconsole.log(folders);\n```", + perLanguage: { + cli: { + method: 'folders list', + example: + "hyperspell folders list \\\n --api-key 'My API Key' \\\n --connection-id 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + }, + go: { + method: 'client.Folders.List', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tfolders, err := client.Folders.List(\n\t\tcontext.TODO(),\n\t\t"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",\n\t\thyperspell.FolderListParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", folders.Folders)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/connections/$CONNECTION_ID/folders \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'folders.list', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nfolders = client.folders.list(\n connection_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",\n)\nprint(folders.folders)', + }, + typescript: { + method: 'client.folders.list', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst folders = await client.folders.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');\n\nconsole.log(folders.folders);", + }, + }, + }, + { + name: 'list_policies', + endpoint: '/connections/{connection_id}/folder-policies', + httpMethod: 'get', + summary: 'List folder policies for a connection', + description: 'List all folder policies for a specific connection.', + stainlessPath: '(resource) folders > (method) list_policies', + qualified: 'client.folders.listPolicies', + params: ['connection_id: string;'], + response: + "{ policies: { id: string; provider_folder_id: string; sync_mode: 'sync' | 'skip' | 'manual'; connection_id?: string; folder_name?: string; folder_path?: string; parent_folder_id?: string; }[]; }", + markdown: + "## list_policies\n\n`client.folders.listPolicies(connection_id: string): { policies: object[]; }`\n\n**get** `/connections/{connection_id}/folder-policies`\n\nList all folder policies for a specific connection.\n\n### Parameters\n\n- `connection_id: string`\n\n### Returns\n\n- `{ policies: { id: string; provider_folder_id: string; sync_mode: 'sync' | 'skip' | 'manual'; connection_id?: string; folder_name?: string; folder_path?: string; parent_folder_id?: string; }[]; }`\n\n - `policies: { id: string; provider_folder_id: string; sync_mode: 'sync' | 'skip' | 'manual'; connection_id?: string; folder_name?: string; folder_path?: string; parent_folder_id?: string; }[]`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.folders.listPolicies('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'folders list_policies', + example: + "hyperspell folders list-policies \\\n --api-key 'My API Key' \\\n --connection-id 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + }, + go: { + method: 'client.Folders.ListPolicies', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Folders.ListPolicies(context.TODO(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.Policies)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/connections/$CONNECTION_ID/folder-policies \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'folders.list_policies', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.folders.list_policies(\n "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",\n)\nprint(response.policies)', + }, + typescript: { + method: 'client.folders.listPolicies', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.folders.listPolicies('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');\n\nconsole.log(response.policies);", + }, + }, + }, + { + name: 'set_policies', + endpoint: '/connections/{connection_id}/folder-policies', + httpMethod: 'post', + summary: 'Create a folder policy for a connection', + description: 'Create or update a folder policy for a specific connection.', + stainlessPath: '(resource) folders > (method) set_policies', + qualified: 'client.folders.setPolicies', + params: [ + 'connection_id: string;', + 'provider_folder_id: string;', + "sync_mode: 'sync' | 'skip' | 'manual';", + 'folder_name?: string;', + 'folder_path?: string;', + 'parent_folder_id?: string;', + ], + response: + "{ id: string; provider_folder_id: string; sync_mode: 'sync' | 'skip' | 'manual'; connection_id?: string; folder_name?: string; folder_path?: string; parent_folder_id?: string; }", + markdown: + "## set_policies\n\n`client.folders.setPolicies(connection_id: string, provider_folder_id: string, sync_mode: 'sync' | 'skip' | 'manual', folder_name?: string, folder_path?: string, parent_folder_id?: string): { id: string; provider_folder_id: string; sync_mode: 'sync' | 'skip' | 'manual'; connection_id?: string; folder_name?: string; folder_path?: string; parent_folder_id?: string; }`\n\n**post** `/connections/{connection_id}/folder-policies`\n\nCreate or update a folder policy for a specific connection.\n\n### Parameters\n\n- `connection_id: string`\n\n- `provider_folder_id: string`\n Folder ID from the source provider\n\n- `sync_mode: 'sync' | 'skip' | 'manual'`\n Sync mode for this folder\n\n- `folder_name?: string`\n Display name of the folder\n\n- `folder_path?: string`\n Display path of the folder\n\n- `parent_folder_id?: string`\n Parent folder's provider ID for inheritance resolution\n\n### Returns\n\n- `{ id: string; provider_folder_id: string; sync_mode: 'sync' | 'skip' | 'manual'; connection_id?: string; folder_name?: string; folder_path?: string; parent_folder_id?: string; }`\n\n - `id: string`\n - `provider_folder_id: string`\n - `sync_mode: 'sync' | 'skip' | 'manual'`\n - `connection_id?: string`\n - `folder_name?: string`\n - `folder_path?: string`\n - `parent_folder_id?: string`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.folders.setPolicies('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { provider_folder_id: 'provider_folder_id', sync_mode: 'sync' });\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'folders set_policies', + example: + "hyperspell folders set-policies \\\n --api-key 'My API Key' \\\n --connection-id 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e \\\n --provider-folder-id provider_folder_id \\\n --sync-mode sync", + }, + go: { + method: 'client.Folders.SetPolicies', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Folders.SetPolicies(\n\t\tcontext.TODO(),\n\t\t"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",\n\t\thyperspell.FolderSetPoliciesParams{\n\t\t\tProviderFolderID: "provider_folder_id",\n\t\t\tSyncMode: hyperspell.FolderSetPoliciesParamsSyncModeSync,\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.ID)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/connections/$CONNECTION_ID/folder-policies \\\n -H \'Content-Type: application/json\' \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY" \\\n -d \'{\n "provider_folder_id": "provider_folder_id",\n "sync_mode": "sync"\n }\'', + }, + python: { + method: 'folders.set_policies', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.folders.set_policies(\n connection_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",\n provider_folder_id="provider_folder_id",\n sync_mode="sync",\n)\nprint(response.id)', + }, + typescript: { + method: 'client.folders.setPolicies', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.folders.setPolicies('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {\n provider_folder_id: 'provider_folder_id',\n sync_mode: 'sync',\n});\n\nconsole.log(response.id);", + }, + }, + }, + { + name: 'delete_policy', + endpoint: '/connections/{connection_id}/folder-policies/{policy_id}', + httpMethod: 'delete', + summary: 'Delete a folder policy', + description: 'Delete a folder policy for a specific connection.', + stainlessPath: '(resource) folders > (method) delete_policy', + qualified: 'client.folders.deletePolicy', + params: ['connection_id: string;', 'policy_id: string;'], + response: '{ success: boolean; }', + markdown: + "## delete_policy\n\n`client.folders.deletePolicy(connection_id: string, policy_id: string): { success: boolean; }`\n\n**delete** `/connections/{connection_id}/folder-policies/{policy_id}`\n\nDelete a folder policy for a specific connection.\n\n### Parameters\n\n- `connection_id: string`\n\n- `policy_id: string`\n\n### Returns\n\n- `{ success: boolean; }`\n\n - `success: boolean`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.folders.deletePolicy('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { connection_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' });\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'folders delete_policy', + example: + "hyperspell folders delete-policy \\\n --api-key 'My API Key' \\\n --connection-id 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e \\\n --policy-id 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + }, + go: { + method: 'client.Folders.DeletePolicy', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Folders.DeletePolicy(\n\t\tcontext.TODO(),\n\t\t"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",\n\t\thyperspell.FolderDeletePolicyParams{\n\t\t\tConnectionID: "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.Success)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/connections/$CONNECTION_ID/folder-policies/$POLICY_ID \\\n -X DELETE \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'folders.delete_policy', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.folders.delete_policy(\n policy_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",\n connection_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",\n)\nprint(response.success)', + }, + typescript: { + method: 'client.folders.deletePolicy', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.folders.deletePolicy('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {\n connection_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',\n});\n\nconsole.log(response.success);", + }, + }, + }, + { + name: 'list', + endpoint: '/integrations/list', + httpMethod: 'get', + summary: 'List all integrations', + description: 'List all integrations for the user.', + stainlessPath: '(resource) integrations > (method) list', + qualified: 'client.integrations.list', + response: + "{ integrations: { id: string; allow_multiple_connections: boolean; auth_provider: 'nango' | 'unified' | 'whitelabel'; icon: string; name: string; provider: string; actions_only?: boolean; }[]; }", + markdown: + "## list\n\n`client.integrations.list(): { integrations: object[]; }`\n\n**get** `/integrations/list`\n\nList all integrations for the user.\n\n### Returns\n\n- `{ integrations: { id: string; allow_multiple_connections: boolean; auth_provider: 'nango' | 'unified' | 'whitelabel'; icon: string; name: string; provider: string; actions_only?: boolean; }[]; }`\n\n - `integrations: { id: string; allow_multiple_connections: boolean; auth_provider: 'nango' | 'unified' | 'whitelabel'; icon: string; name: string; provider: string; actions_only?: boolean; }[]`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst integrations = await client.integrations.list();\n\nconsole.log(integrations);\n```", + perLanguage: { + cli: { + method: 'integrations list', + example: "hyperspell integrations list \\\n --api-key 'My API Key'", + }, + go: { + method: 'client.Integrations.List', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tintegrations, err := client.Integrations.List(context.TODO())\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", integrations.Integrations)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/integrations/list \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'integrations.list', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nintegrations = client.integrations.list()\nprint(integrations.integrations)', + }, + typescript: { + method: 'client.integrations.list', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst integrations = await client.integrations.list();\n\nconsole.log(integrations.integrations);", + }, + }, + }, + { + name: 'connect', + endpoint: '/integrations/{integration_id}/connect', + httpMethod: 'get', + summary: 'Link an integration', + description: 'Redirects to the connect URL to link an integration.', + stainlessPath: '(resource) integrations > (method) connect', + qualified: 'client.integrations.connect', + params: ['integration_id: string;', 'redirect_url?: string;'], + response: '{ expires_at: string; url: string; }', + markdown: + "## connect\n\n`client.integrations.connect(integration_id: string, redirect_url?: string): { expires_at: string; url: string; }`\n\n**get** `/integrations/{integration_id}/connect`\n\nRedirects to the connect URL to link an integration.\n\n### Parameters\n\n- `integration_id: string`\n\n- `redirect_url?: string`\n\n### Returns\n\n- `{ expires_at: string; url: string; }`\n\n - `expires_at: string`\n - `url: string`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.integrations.connect('integration_id');\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'integrations connect', + example: + "hyperspell integrations connect \\\n --api-key 'My API Key' \\\n --integration-id integration_id", + }, + go: { + method: 'client.Integrations.Connect', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Integrations.Connect(\n\t\tcontext.TODO(),\n\t\t"integration_id",\n\t\thyperspell.IntegrationConnectParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.ExpiresAt)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/integrations/$INTEGRATION_ID/connect \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'integrations.connect', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.integrations.connect(\n integration_id="integration_id",\n)\nprint(response.expires_at)', + }, + typescript: { + method: 'client.integrations.connect', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.integrations.connect('integration_id');\n\nconsole.log(response.expires_at);", + }, + }, + }, + { + name: 'list', + endpoint: '/integrations/google_calendar/list', + httpMethod: 'get', + summary: 'List available calendars', + description: + 'List available calendars for a user. This can be used to ie. populate a dropdown for the user to select a calendar.', + stainlessPath: '(resource) integrations.google_calendar > (method) list', + qualified: 'client.integrations.googleCalendar.list', + response: '{ items: { id: string; name: string; primary: boolean; timezone: string; }[]; }', + markdown: + "## list\n\n`client.integrations.googleCalendar.list(): { items: object[]; }`\n\n**get** `/integrations/google_calendar/list`\n\nList available calendars for a user. This can be used to ie. populate a dropdown for the user to select a calendar.\n\n### Returns\n\n- `{ items: { id: string; name: string; primary: boolean; timezone: string; }[]; }`\n\n - `items: { id: string; name: string; primary: boolean; timezone: string; }[]`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst calendar = await client.integrations.googleCalendar.list();\n\nconsole.log(calendar);\n```", + perLanguage: { + cli: { + method: 'google_calendar list', + example: "hyperspell integrations:google-calendar list \\\n --api-key 'My API Key'", + }, + go: { + method: 'client.Integrations.GoogleCalendar.List', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tcalendar, err := client.Integrations.GoogleCalendar.List(context.TODO())\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", calendar.Items)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/integrations/google_calendar/list \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'integrations.google_calendar.list', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\ncalendar = client.integrations.google_calendar.list()\nprint(calendar.items)', + }, + typescript: { + method: 'client.integrations.googleCalendar.list', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst calendar = await client.integrations.googleCalendar.list();\n\nconsole.log(calendar.items);", + }, + }, + }, + { + name: 'index', + endpoint: '/integrations/web_crawler/index', + httpMethod: 'get', + summary: 'Crawl a website for indexed search', + description: 'Recursively crawl a website to make it available for indexed search.', + stainlessPath: '(resource) integrations.web_crawler > (method) index', + qualified: 'client.integrations.webCrawler.index', + params: ['url: string;', 'limit?: number;', 'max_depth?: number;'], + response: + "{ resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }", + markdown: + "## index\n\n`client.integrations.webCrawler.index(url: string, limit?: number, max_depth?: number): { resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }`\n\n**get** `/integrations/web_crawler/index`\n\nRecursively crawl a website to make it available for indexed search.\n\n### Parameters\n\n- `url: string`\n The base URL of the website to crawl\n\n- `limit?: number`\n Maximum number of pages to crawl in total\n\n- `max_depth?: number`\n Maximum depth of links to follow during crawling\n\n### Returns\n\n- `{ resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }`\n\n - `resource_id: string`\n - `source: string`\n - `status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.integrations.webCrawler.index({ url: 'url' });\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'web_crawler index', + example: "hyperspell integrations:web-crawler index \\\n --api-key 'My API Key' \\\n --url url", + }, + go: { + method: 'client.Integrations.WebCrawler.Index', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Integrations.WebCrawler.Index(context.TODO(), hyperspell.IntegrationWebCrawlerIndexParams{\n\t\tURL: "url",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.ResourceID)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/integrations/web_crawler/index \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'integrations.web_crawler.index', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.integrations.web_crawler.index(\n url="url",\n)\nprint(response.resource_id)', + }, + typescript: { + method: 'client.integrations.webCrawler.index', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.integrations.webCrawler.index({ url: 'url' });\n\nconsole.log(response.resource_id);", + }, + }, + }, + { + name: 'list', + endpoint: '/integrations/slack/list', + httpMethod: 'get', + summary: 'List available Slack conversations', + description: + "List Slack conversations accessible to the user via the live Nango connection.\n\nReturns minimal channel metadata suitable for selection UIs. If required\nscopes are missing, Slack's error is propagated with details.\n\nSupports filtering by channels, including/excluding private channels, DMs,\ngroup DMs, and archived channels based on the provided search options.", + stainlessPath: '(resource) integrations.slack > (method) list', + qualified: 'client.integrations.slack.list', + params: [ + 'channels?: string[];', + 'exclude_archived?: boolean;', + 'include_dms?: boolean;', + 'include_group_dms?: boolean;', + 'include_private?: boolean;', + ], + response: 'object', + markdown: + "## list\n\n`client.integrations.slack.list(channels?: string[], exclude_archived?: boolean, include_dms?: boolean, include_group_dms?: boolean, include_private?: boolean): object`\n\n**get** `/integrations/slack/list`\n\nList Slack conversations accessible to the user via the live Nango connection.\n\nReturns minimal channel metadata suitable for selection UIs. If required\nscopes are missing, Slack's error is propagated with details.\n\nSupports filtering by channels, including/excluding private channels, DMs,\ngroup DMs, and archived channels based on the provided search options.\n\n### Parameters\n\n- `channels?: string[]`\n List of Slack channels to include (by id, name, or #name).\n\n- `exclude_archived?: boolean`\n If set, pass 'exclude_archived' to Slack. If None, omit the param.\n\n- `include_dms?: boolean`\n Include direct messages (im) when listing conversations.\n\n- `include_group_dms?: boolean`\n Include group DMs (mpim) when listing conversations.\n\n- `include_private?: boolean`\n Include private channels when constructing Slack 'types'.\n\n### Returns\n\n- `object`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst slacks = await client.integrations.slack.list();\n\nconsole.log(slacks);\n```", + perLanguage: { + cli: { + method: 'slack list', + example: "hyperspell integrations:slack list \\\n --api-key 'My API Key'", + }, + go: { + method: 'client.Integrations.Slack.List', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tslacks, err := client.Integrations.Slack.List(context.TODO(), hyperspell.IntegrationSlackListParams{})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", slacks)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/integrations/slack/list \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'integrations.slack.list', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nslacks = client.integrations.slack.list()\nprint(slacks)', + }, + typescript: { + method: 'client.integrations.slack.list', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst slacks = await client.integrations.slack.list();\n\nconsole.log(slacks);", + }, + }, + }, + { + name: 'add', + endpoint: '/memories/add', + httpMethod: 'post', + summary: 'Add a memory', + description: + 'Adds an arbitrary document to the index. This can be any text, email,\ncall transcript, etc. The document will be processed and made available for\nquerying once the processing is complete.', + stainlessPath: '(resource) memories > (method) add', + qualified: 'client.memories.add', + params: [ + 'text: string;', + 'collection?: string;', + 'date?: string;', + 'metadata?: object;', + 'resource_id?: string;', + 'title?: string;', + ], + response: + "{ resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }", + markdown: + "## add\n\n`client.memories.add(text: string, collection?: string, date?: string, metadata?: object, resource_id?: string, title?: string): { resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }`\n\n**post** `/memories/add`\n\nAdds an arbitrary document to the index. This can be any text, email,\ncall transcript, etc. The document will be processed and made available for\nquerying once the processing is complete.\n\n### Parameters\n\n- `text: string`\n Full text of the document.\n\n- `collection?: string`\n The collection to add the document to — deprecated, set the collection using metadata instead.\n\n- `date?: string`\n Date of the document. Depending on the document, this could be the creation date or date the document was last updated (eg. for a chat transcript, this would be the date of the last message). This helps the ranking algorithm and allows you to filter by date range.\n\n- `metadata?: object`\n Custom metadata for filtering. Keys must be alphanumeric with underscores, max 64 chars. Values must be string, number, boolean, or null.\n\n- `resource_id?: string`\n The resource ID to add the document to. If not provided, a new resource ID will be generated. If provided, the document will be updated if it already exists.\n\n- `title?: string`\n Title of the document.\n\n### Returns\n\n- `{ resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }`\n\n - `resource_id: string`\n - `source: string`\n - `status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst memoryStatus = await client.memories.add({ text: 'text' });\n\nconsole.log(memoryStatus);\n```", + perLanguage: { + cli: { + method: 'memories add', + example: "hyperspell memories add \\\n --api-key 'My API Key' \\\n --text text", + }, + go: { + method: 'client.Memories.Add', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tmemoryStatus, err := client.Memories.Add(context.TODO(), hyperspell.MemoryAddParams{\n\t\tText: "text",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", memoryStatus.ResourceID)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/memories/add \\\n -H \'Content-Type: application/json\' \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY" \\\n -d \'{\n "text": "text"\n }\'', + }, + python: { + method: 'memories.add', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nmemory_status = client.memories.add(\n text="text",\n)\nprint(memory_status.resource_id)', + }, + typescript: { + method: 'client.memories.add', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst memoryStatus = await client.memories.add({ text: 'text' });\n\nconsole.log(memoryStatus.resource_id);", + }, + }, + }, + { + name: 'add_bulk', + endpoint: '/memories/add/bulk', + httpMethod: 'post', + summary: 'Add multiple memories', + description: + 'Adds multiple documents to the index in a single request.\n\nAll items are validated before any database operations occur. If any item\nfails validation, the entire batch is rejected with a 422 error detailing\nwhich items failed and why.\n\nMaximum 100 items per request. Each item follows the same schema as the\nsingle-item /memories/add endpoint.', + stainlessPath: '(resource) memories > (method) add_bulk', + qualified: 'client.memories.addBulk', + params: [ + 'items: { text: string; collection?: string; date?: string; metadata?: object; resource_id?: string; title?: string; }[];', + ], + response: + "{ count: number; items: { resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }[]; success?: boolean; }", + markdown: + "## add_bulk\n\n`client.memories.addBulk(items: { text: string; collection?: string; date?: string; metadata?: object; resource_id?: string; title?: string; }[]): { count: number; items: memory_status[]; success?: boolean; }`\n\n**post** `/memories/add/bulk`\n\nAdds multiple documents to the index in a single request.\n\nAll items are validated before any database operations occur. If any item\nfails validation, the entire batch is rejected with a 422 error detailing\nwhich items failed and why.\n\nMaximum 100 items per request. Each item follows the same schema as the\nsingle-item /memories/add endpoint.\n\n### Parameters\n\n- `items: { text: string; collection?: string; date?: string; metadata?: object; resource_id?: string; title?: string; }[]`\n List of memories to ingest. Maximum 100 items.\n\n### Returns\n\n- `{ count: number; items: { resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }[]; success?: boolean; }`\n Response schema for successful bulk ingestion.\n\n - `count: number`\n - `items: { resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }[]`\n - `success?: boolean`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.memories.addBulk({ items: [{ text: '...' }] });\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'memories add_bulk', + example: "hyperspell memories add-bulk \\\n --api-key 'My API Key' \\\n --item '{text: ...}'", + }, + go: { + method: 'client.Memories.AddBulk', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Memories.AddBulk(context.TODO(), hyperspell.MemoryAddBulkParams{\n\t\tItems: []hyperspell.MemoryAddBulkParamsItem{{\n\t\t\tText: "...",\n\t\t}},\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.Count)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/memories/add/bulk \\\n -H \'Content-Type: application/json\' \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY" \\\n -d \'{\n "items": [\n {\n "text": "...",\n "collection": "my-collection",\n "metadata": {\n "author": "John Doe",\n "date": "2025-05-20T02:31:00Z",\n "rating": 3\n },\n "title": "My Document"\n }\n ]\n }\'', + }, + python: { + method: 'memories.add_bulk', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.memories.add_bulk(\n items=[{\n "text": "..."\n }],\n)\nprint(response.count)', + }, + typescript: { + method: 'client.memories.addBulk', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.memories.addBulk({ items: [{ text: '...' }] });\n\nconsole.log(response.count);", + }, + }, + }, + { + name: 'upload', + endpoint: '/memories/upload', + httpMethod: 'post', + summary: 'Upload a file', + description: + 'This endpoint will upload a file to the index and return a resource_id.\nThe file will be processed in the background and the memory will be available for querying once the processing is complete.\nYou can use the `resource_id` to query the memory later, and check the status of the memory.', + stainlessPath: '(resource) memories > (method) upload', + qualified: 'client.memories.upload', + params: ['file: string;', 'collection?: string;', 'metadata?: string;'], + response: + "{ resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }", + markdown: + "## upload\n\n`client.memories.upload(file: string, collection?: string, metadata?: string): { resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }`\n\n**post** `/memories/upload`\n\nThis endpoint will upload a file to the index and return a resource_id.\nThe file will be processed in the background and the memory will be available for querying once the processing is complete.\nYou can use the `resource_id` to query the memory later, and check the status of the memory.\n\n### Parameters\n\n- `file: string`\n The file to ingest.\n\n- `collection?: string`\n The collection to add the document to — deprecated, set the collection using metadata instead.\n\n- `metadata?: string`\n Custom metadata as JSON string for filtering. Keys must be alphanumeric with underscores, max 64 chars. Values must be string, number, or boolean.\n\n### Returns\n\n- `{ resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }`\n\n - `resource_id: string`\n - `source: string`\n - `status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst memoryStatus = await client.memories.upload({ file: fs.createReadStream('path/to/file') });\n\nconsole.log(memoryStatus);\n```", + perLanguage: { + cli: { + method: 'memories upload', + example: "hyperspell memories upload \\\n --api-key 'My API Key' \\\n --file 'Example data'", + }, + go: { + method: 'client.Memories.Upload', + example: + 'package main\n\nimport (\n\t"bytes"\n\t"context"\n\t"fmt"\n\t"io"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tmemoryStatus, err := client.Memories.Upload(context.TODO(), hyperspell.MemoryUploadParams{\n\t\tFile: io.Reader(bytes.NewBuffer([]byte("Example data"))),\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", memoryStatus.ResourceID)\n}\n', + }, + http: { + example: + "curl https://api.hyperspell.com/memories/upload \\\n -H 'Content-Type: multipart/form-data' \\\n -H \"Authorization: Bearer $HYPERSPELL_API_KEY\" \\\n -F 'file=@/path/to/file'", + }, + python: { + method: 'memories.upload', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nmemory_status = client.memories.upload(\n file=b"Example data",\n)\nprint(memory_status.resource_id)', + }, + typescript: { + method: 'client.memories.upload', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst memoryStatus = await client.memories.upload({ file: fs.createReadStream('path/to/file') });\n\nconsole.log(memoryStatus.resource_id);", + }, + }, + }, + { + name: 'update', + endpoint: '/memories/update/{source}/{resource_id}', + httpMethod: 'post', + summary: 'Update a memory', + description: + 'Updates an existing document in the index. You can update the text, collection,\ntitle, and metadata. The document must already exist or a 404 will be returned.\nThis works for documents from any source (vault, slack, gmail, etc.).\n\nTo remove a collection, set it to null explicitly.', + stainlessPath: '(resource) memories > (method) update', + qualified: 'client.memories.update', + params: [ + 'source: string;', + 'resource_id: string;', + 'collection?: string | object;', + 'metadata?: object | object;', + 'text?: string | object;', + 'title?: string | object;', + ], + response: + "{ resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }", + markdown: + "## update\n\n`client.memories.update(source: string, resource_id: string, collection?: string | object, metadata?: object | object, text?: string | object, title?: string | object): { resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }`\n\n**post** `/memories/update/{source}/{resource_id}`\n\nUpdates an existing document in the index. You can update the text, collection,\ntitle, and metadata. The document must already exist or a 404 will be returned.\nThis works for documents from any source (vault, slack, gmail, etc.).\n\nTo remove a collection, set it to null explicitly.\n\n### Parameters\n\n- `source: string`\n\n- `resource_id: string`\n\n- `collection?: string | object`\n The collection to move the document to — deprecated, set the collection using metadata instead.\n\n- `metadata?: object | object`\n Custom metadata for filtering. Keys must be alphanumeric with underscores, max 64 chars. Values must be string, number, boolean, or null. Will be merged with existing metadata.\n\n- `text?: string | object`\n Full text of the document. If provided, the document will be re-indexed.\n\n- `title?: string | object`\n Title of the document.\n\n### Returns\n\n- `{ resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }`\n\n - `resource_id: string`\n - `source: string`\n - `status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst memoryStatus = await client.memories.update('resource_id', { source: 'reddit' });\n\nconsole.log(memoryStatus);\n```", + perLanguage: { + cli: { + method: 'memories update', + example: + "hyperspell memories update \\\n --api-key 'My API Key' \\\n --source reddit \\\n --resource-id resource_id", + }, + go: { + method: 'client.Memories.Update', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tmemoryStatus, err := client.Memories.Update(\n\t\tcontext.TODO(),\n\t\t"resource_id",\n\t\thyperspell.MemoryUpdateParams{\n\t\t\tSource: hyperspell.MemoryUpdateParamsSourceReddit,\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", memoryStatus.ResourceID)\n}\n', + }, + http: { + example: + "curl https://api.hyperspell.com/memories/update/$SOURCE/$RESOURCE_ID \\\n -H 'Content-Type: application/json' \\\n -H \"Authorization: Bearer $HYPERSPELL_API_KEY\" \\\n -d '{}'", + }, + python: { + method: 'memories.update', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nmemory_status = client.memories.update(\n resource_id="resource_id",\n source="reddit",\n)\nprint(memory_status.resource_id)', + }, + typescript: { + method: 'client.memories.update', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst memoryStatus = await client.memories.update('resource_id', { source: 'reddit' });\n\nconsole.log(memoryStatus.resource_id);", + }, + }, + }, + { + name: 'list', + endpoint: '/memories/list', + httpMethod: 'get', + summary: 'List memories', + description: + 'This endpoint allows you to paginate through all documents in the index.\nYou can filter the documents by title, date, metadata, etc.', + stainlessPath: '(resource) memories > (method) list', + qualified: 'client.memories.list', + params: [ + 'collection?: string;', + 'cursor?: string;', + 'filter?: string;', + 'size?: number;', + 'source?: string;', + "status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped';", + ], + response: + "{ resource_id: string; source: string; folder_id?: string; metadata?: { created_at?: string; events?: notification[]; indexed_at?: string; last_modified?: string; status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; url?: string; }; parent_folder_id?: string; score?: number; title?: string; }", + markdown: + "## list\n\n`client.memories.list(collection?: string, cursor?: string, filter?: string, size?: number, source?: string, status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'): { resource_id: string; source: string; folder_id?: string; metadata?: metadata; parent_folder_id?: string; score?: number; title?: string; }`\n\n**get** `/memories/list`\n\nThis endpoint allows you to paginate through all documents in the index.\nYou can filter the documents by title, date, metadata, etc.\n\n### Parameters\n\n- `collection?: string`\n Filter documents by collection.\n\n- `cursor?: string`\n\n- `filter?: string`\n Filter documents by metadata using MongoDB-style operators. Example: {\"department\": \"engineering\", \"priority\": {\"$gt\": 3}}\n\n- `size?: number`\n\n- `source?: string`\n Filter documents by source.\n\n- `status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'`\n Filter documents by status.\n\n### Returns\n\n- `{ resource_id: string; source: string; folder_id?: string; metadata?: { created_at?: string; events?: notification[]; indexed_at?: string; last_modified?: string; status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; url?: string; }; parent_folder_id?: string; score?: number; title?: string; }`\n\n - `resource_id: string`\n - `source: string`\n - `folder_id?: string`\n - `metadata?: { created_at?: string; events?: { message: string; type: 'error' | 'warning' | 'info' | 'success'; time?: string; }[]; indexed_at?: string; last_modified?: string; status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; url?: string; }`\n - `parent_folder_id?: string`\n - `score?: number`\n - `title?: string`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\n// Automatically fetches more pages as needed.\nfor await (const resource of client.memories.list()) {\n console.log(resource);\n}\n```", + perLanguage: { + cli: { + method: 'memories list', + example: "hyperspell memories list \\\n --api-key 'My API Key'", + }, + go: { + method: 'client.Memories.List', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tpage, err := client.Memories.List(context.TODO(), hyperspell.MemoryListParams{})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", page)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/memories/list \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'memories.list', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\npage = client.memories.list()\npage = page.items[0]\nprint(page.resource_id)', + }, + typescript: { + method: 'client.memories.list', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\n// Automatically fetches more pages as needed.\nfor await (const resource of client.memories.list()) {\n console.log(resource.resource_id);\n}", + }, + }, + }, + { + name: 'status', + endpoint: '/memories/status', + httpMethod: 'get', + summary: 'Show indexing progress', + description: 'This endpoint shows the indexing progress of documents, both by provider and total.', + stainlessPath: '(resource) memories > (method) status', + qualified: 'client.memories.status', + response: '{ providers: object; total: object; }', + markdown: + "## status\n\n`client.memories.status(): { providers: object; total: object; }`\n\n**get** `/memories/status`\n\nThis endpoint shows the indexing progress of documents, both by provider and total.\n\n### Returns\n\n- `{ providers: object; total: object; }`\n\n - `providers: object`\n - `total: object`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.memories.status();\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'memories status', + example: "hyperspell memories status \\\n --api-key 'My API Key'", + }, + go: { + method: 'client.Memories.Status', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Memories.Status(context.TODO())\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.Providers)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/memories/status \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'memories.status', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.memories.status()\nprint(response.providers)', + }, + typescript: { + method: 'client.memories.status', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.memories.status();\n\nconsole.log(response.providers);", + }, + }, + }, + { + name: 'get', + endpoint: '/memories/get/{source}/{resource_id}', + httpMethod: 'get', + summary: 'Get memory', + description: 'Retrieves a document by provider and resource_id.', + stainlessPath: '(resource) memories > (method) get', + qualified: 'client.memories.get', + params: ['source: string;', 'resource_id: string;'], + response: + "{ resource_id: string; source: string; type: string; data?: object[]; memories?: string[]; metadata?: { created_at?: string; events?: notification[]; indexed_at?: string; last_modified?: string; status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; url?: string; }; title?: string; }", + markdown: + "## get\n\n`client.memories.get(source: string, resource_id: string): { resource_id: string; source: string; type: string; data?: object[]; memories?: string[]; metadata?: metadata; title?: string; }`\n\n**get** `/memories/get/{source}/{resource_id}`\n\nRetrieves a document by provider and resource_id.\n\n### Parameters\n\n- `source: string`\n\n- `resource_id: string`\n\n### Returns\n\n- `{ resource_id: string; source: string; type: string; data?: object[]; memories?: string[]; metadata?: { created_at?: string; events?: notification[]; indexed_at?: string; last_modified?: string; status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; url?: string; }; title?: string; }`\n Response model for the GET /memories/get endpoint.\n\n - `resource_id: string`\n - `source: string`\n - `type: string`\n - `data?: object[]`\n - `memories?: string[]`\n - `metadata?: { created_at?: string; events?: { message: string; type: 'error' | 'warning' | 'info' | 'success'; time?: string; }[]; indexed_at?: string; last_modified?: string; status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; url?: string; }`\n - `title?: string`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst memory = await client.memories.get('resource_id', { source: 'reddit' });\n\nconsole.log(memory);\n```", + perLanguage: { + cli: { + method: 'memories get', + example: + "hyperspell memories get \\\n --api-key 'My API Key' \\\n --source reddit \\\n --resource-id resource_id", + }, + go: { + method: 'client.Memories.Get', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tmemory, err := client.Memories.Get(\n\t\tcontext.TODO(),\n\t\t"resource_id",\n\t\thyperspell.MemoryGetParams{\n\t\t\tSource: hyperspell.MemoryGetParamsSourceReddit,\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", memory.ResourceID)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/memories/get/$SOURCE/$RESOURCE_ID \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'memories.get', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nmemory = client.memories.get(\n resource_id="resource_id",\n source="reddit",\n)\nprint(memory.resource_id)', + }, + typescript: { + method: 'client.memories.get', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst memory = await client.memories.get('resource_id', { source: 'reddit' });\n\nconsole.log(memory.resource_id);", + }, + }, + }, + { + name: 'search', + endpoint: '/memories/query', + httpMethod: 'post', + summary: 'Query memories', + description: 'Retrieves documents matching the query.', + stainlessPath: '(resource) memories > (method) search', + qualified: 'client.memories.search', + params: [ + 'query: string;', + 'answer?: boolean;', + 'effort?: number;', + 'max_results?: number;', + "options?: { after?: string; answer_model?: string; before?: string; box?: { weight?: number; }; filter?: object; google_calendar?: { calendar_id?: string; weight?: number; }; google_drive?: { weight?: number; }; google_mail?: { label_ids?: string[]; weight?: number; }; max_results?: number; memory_types?: 'procedure' | 'memory' | 'mood'[]; notion?: { notion_page_ids?: string[]; weight?: number; }; reddit?: { period?: 'hour' | 'day' | 'week' | 'month' | 'year' | 'all'; sort?: 'relevance' | 'new' | 'hot' | 'top' | 'comments'; subreddit?: string; weight?: number; }; resource_ids?: string[]; slack?: { channels?: string[]; exclude_archived?: boolean; include_dms?: boolean; include_group_dms?: boolean; include_private?: boolean; weight?: number; }; vault?: { weight?: number; }; web_crawler?: { max_depth?: number; url?: string; weight?: number; }; };", + 'sources?: string[];', + ], + response: + '{ documents: { resource_id: string; source: string; folder_id?: string; metadata?: metadata; parent_folder_id?: string; score?: number; title?: string; }[]; answer?: string; errors?: object[]; query_id?: string; score?: number; }', + markdown: + "## search\n\n`client.memories.search(query: string, answer?: boolean, effort?: number, max_results?: number, options?: { after?: string; answer_model?: string; before?: string; box?: { weight?: number; }; filter?: object; google_calendar?: { calendar_id?: string; weight?: number; }; google_drive?: { weight?: number; }; google_mail?: { label_ids?: string[]; weight?: number; }; max_results?: number; memory_types?: 'procedure' | 'memory' | 'mood'[]; notion?: { notion_page_ids?: string[]; weight?: number; }; reddit?: { period?: 'hour' | 'day' | 'week' | 'month' | 'year' | 'all'; sort?: 'relevance' | 'new' | 'hot' | 'top' | 'comments'; subreddit?: string; weight?: number; }; resource_ids?: string[]; slack?: { channels?: string[]; exclude_archived?: boolean; include_dms?: boolean; include_group_dms?: boolean; include_private?: boolean; weight?: number; }; vault?: { weight?: number; }; web_crawler?: { max_depth?: number; url?: string; weight?: number; }; }, sources?: string[]): { documents: resource[]; answer?: string; errors?: object[]; query_id?: string; score?: number; }`\n\n**post** `/memories/query`\n\nRetrieves documents matching the query.\n\n### Parameters\n\n- `query: string`\n Query to run.\n\n- `answer?: boolean`\n If true, the query will be answered along with matching source documents.\n\n- `effort?: number`\n Effort level. 0 = pass query through verbatim. 1 = LLM rewrites the query for better retrieval and extracts date filters.\n\n- `max_results?: number`\n Maximum number of results to return.\n\n- `options?: { after?: string; answer_model?: string; before?: string; box?: { weight?: number; }; filter?: object; google_calendar?: { calendar_id?: string; weight?: number; }; google_drive?: { weight?: number; }; google_mail?: { label_ids?: string[]; weight?: number; }; max_results?: number; memory_types?: 'procedure' | 'memory' | 'mood'[]; notion?: { notion_page_ids?: string[]; weight?: number; }; reddit?: { period?: 'hour' | 'day' | 'week' | 'month' | 'year' | 'all'; sort?: 'relevance' | 'new' | 'hot' | 'top' | 'comments'; subreddit?: string; weight?: number; }; resource_ids?: string[]; slack?: { channels?: string[]; exclude_archived?: boolean; include_dms?: boolean; include_group_dms?: boolean; include_private?: boolean; weight?: number; }; vault?: { weight?: number; }; web_crawler?: { max_depth?: number; url?: string; weight?: number; }; }`\n Search options for the query.\n - `after?: string`\n Only query documents created on or after this date.\n - `answer_model?: string`\n Model to use for answer generation when answer=True\n - `before?: string`\n Only query documents created before this date.\n - `box?: { weight?: number; }`\n Search options for Box\n - `filter?: object`\n Metadata filters using MongoDB-style operators. Example: {'status': 'published', 'priority': {'$gt': 3}}\n - `google_calendar?: { calendar_id?: string; weight?: number; }`\n Search options for Google Calendar\n - `google_drive?: { weight?: number; }`\n Search options for Google Drive\n - `google_mail?: { label_ids?: string[]; weight?: number; }`\n Search options for Gmail\n - `max_results?: number`\n Maximum number of results to return.\n - `memory_types?: 'procedure' | 'memory' | 'mood'[]`\n Filter by memory type. Defaults to generic memories only. Pass multiple types to include procedures, etc.\n - `notion?: { notion_page_ids?: string[]; weight?: number; }`\n Search options for Notion\n - `reddit?: { period?: 'hour' | 'day' | 'week' | 'month' | 'year' | 'all'; sort?: 'relevance' | 'new' | 'hot' | 'top' | 'comments'; subreddit?: string; weight?: number; }`\n Search options for Reddit\n - `resource_ids?: string[]`\n Only return results from these specific resource IDs. Useful for scoping searches to specific documents (e.g., a specific email thread or uploaded file).\n - `slack?: { channels?: string[]; exclude_archived?: boolean; include_dms?: boolean; include_group_dms?: boolean; include_private?: boolean; weight?: number; }`\n Search options for Slack\n - `vault?: { weight?: number; }`\n Search options for vault\n - `web_crawler?: { max_depth?: number; url?: string; weight?: number; }`\n Search options for Web Crawler\n\n- `sources?: string[]`\n Only query documents from these sources.\n\n### Returns\n\n- `{ documents: { resource_id: string; source: string; folder_id?: string; metadata?: metadata; parent_folder_id?: string; score?: number; title?: string; }[]; answer?: string; errors?: object[]; query_id?: string; score?: number; }`\n\n - `documents: { resource_id: string; source: string; folder_id?: string; metadata?: { created_at?: string; events?: notification[]; indexed_at?: string; last_modified?: string; status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; url?: string; }; parent_folder_id?: string; score?: number; title?: string; }[]`\n - `answer?: string`\n - `errors?: object[]`\n - `query_id?: string`\n - `score?: number`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst queryResult = await client.memories.search({ query: 'query' });\n\nconsole.log(queryResult);\n```", + perLanguage: { + cli: { + method: 'memories search', + example: "hyperspell memories search \\\n --api-key 'My API Key' \\\n --query query", + }, + go: { + method: 'client.Memories.Search', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tqueryResult, err := client.Memories.Search(context.TODO(), hyperspell.MemorySearchParams{\n\t\tQuery: "query",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", queryResult.QueryID)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/memories/query \\\n -H \'Content-Type: application/json\' \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY" \\\n -d \'{\n "query": "query"\n }\'', + }, + python: { + method: 'memories.search', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nquery_result = client.memories.search(\n query="query",\n)\nprint(query_result.query_id)', + }, + typescript: { + method: 'client.memories.search', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst queryResult = await client.memories.search({ query: 'query' });\n\nconsole.log(queryResult.query_id);", + }, + }, + }, + { + name: 'delete', + endpoint: '/memories/delete/{source}/{resource_id}', + httpMethod: 'delete', + summary: 'Delete memory', + description: + "Delete a memory and its associated chunks from the index.\n\nThis removes the memory completely from the vector index and database.\nThe operation deletes:\n1. All chunks associated with the resource (including embeddings)\n2. The resource record itself\n\nArgs:\n source: The document provider (e.g., gmail, notion, vault)\n resource_id: The unique identifier of the resource to delete\n api_token: Authentication token\n\nReturns:\n MemoryDeletionResponse with deletion details\n\nRaises:\n DocumentNotFound: If the resource doesn't exist or user doesn't have access", + stainlessPath: '(resource) memories > (method) delete', + qualified: 'client.memories.delete', + params: ['source: string;', 'resource_id: string;'], + response: + '{ chunks_deleted: number; message: string; resource_id: string; source: string; success: boolean; }', + markdown: + "## delete\n\n`client.memories.delete(source: string, resource_id: string): { chunks_deleted: number; message: string; resource_id: string; source: string; success: boolean; }`\n\n**delete** `/memories/delete/{source}/{resource_id}`\n\nDelete a memory and its associated chunks from the index.\n\nThis removes the memory completely from the vector index and database.\nThe operation deletes:\n1. All chunks associated with the resource (including embeddings)\n2. The resource record itself\n\nArgs:\n source: The document provider (e.g., gmail, notion, vault)\n resource_id: The unique identifier of the resource to delete\n api_token: Authentication token\n\nReturns:\n MemoryDeletionResponse with deletion details\n\nRaises:\n DocumentNotFound: If the resource doesn't exist or user doesn't have access\n\n### Parameters\n\n- `source: string`\n\n- `resource_id: string`\n\n### Returns\n\n- `{ chunks_deleted: number; message: string; resource_id: string; source: string; success: boolean; }`\n\n - `chunks_deleted: number`\n - `message: string`\n - `resource_id: string`\n - `source: string`\n - `success: boolean`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst memory = await client.memories.delete('resource_id', { source: 'reddit' });\n\nconsole.log(memory);\n```", + perLanguage: { + cli: { + method: 'memories delete', + example: + "hyperspell memories delete \\\n --api-key 'My API Key' \\\n --source reddit \\\n --resource-id resource_id", + }, + go: { + method: 'client.Memories.Delete', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tmemory, err := client.Memories.Delete(\n\t\tcontext.TODO(),\n\t\t"resource_id",\n\t\thyperspell.MemoryDeleteParams{\n\t\t\tSource: hyperspell.MemoryDeleteParamsSourceReddit,\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", memory.ResourceID)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/memories/delete/$SOURCE/$RESOURCE_ID \\\n -X DELETE \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'memories.delete', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nmemory = client.memories.delete(\n resource_id="resource_id",\n source="reddit",\n)\nprint(memory.resource_id)', + }, + typescript: { + method: 'client.memories.delete', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst memory = await client.memories.delete('resource_id', { source: 'reddit' });\n\nconsole.log(memory.resource_id);", + }, + }, + }, + { + name: 'get_query', + endpoint: '/evaluate/query/{query_id}', + httpMethod: 'get', + summary: 'Get query result', + description: 'Retrieve the result of a previous query.', + stainlessPath: '(resource) evaluate > (method) get_query', + qualified: 'client.evaluate.getQuery', + params: ['query_id: string;'], + response: + '{ documents: { resource_id: string; source: string; folder_id?: string; metadata?: metadata; parent_folder_id?: string; score?: number; title?: string; }[]; answer?: string; errors?: object[]; query_id?: string; score?: number; }', + markdown: + "## get_query\n\n`client.evaluate.getQuery(query_id: string): { documents: resource[]; answer?: string; errors?: object[]; query_id?: string; score?: number; }`\n\n**get** `/evaluate/query/{query_id}`\n\nRetrieve the result of a previous query.\n\n### Parameters\n\n- `query_id: string`\n\n### Returns\n\n- `{ documents: { resource_id: string; source: string; folder_id?: string; metadata?: metadata; parent_folder_id?: string; score?: number; title?: string; }[]; answer?: string; errors?: object[]; query_id?: string; score?: number; }`\n\n - `documents: { resource_id: string; source: string; folder_id?: string; metadata?: { created_at?: string; events?: notification[]; indexed_at?: string; last_modified?: string; status?: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; url?: string; }; parent_folder_id?: string; score?: number; title?: string; }[]`\n - `answer?: string`\n - `errors?: object[]`\n - `query_id?: string`\n - `score?: number`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst queryResult = await client.evaluate.getQuery('query_id');\n\nconsole.log(queryResult);\n```", + perLanguage: { + cli: { + method: 'evaluate get_query', + example: "hyperspell evaluate get-query \\\n --api-key 'My API Key' \\\n --query-id query_id", + }, + go: { + method: 'client.Evaluate.GetQuery', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tqueryResult, err := client.Evaluate.GetQuery(context.TODO(), "query_id")\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", queryResult.QueryID)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/evaluate/query/$QUERY_ID \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'evaluate.get_query', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nquery_result = client.evaluate.get_query(\n "query_id",\n)\nprint(query_result.query_id)', + }, + typescript: { + method: 'client.evaluate.getQuery', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst queryResult = await client.evaluate.getQuery('query_id');\n\nconsole.log(queryResult.query_id);", + }, + }, + }, + { + name: 'score_query', + endpoint: '/evaluate/query/{query_id}', + httpMethod: 'post', + summary: 'Score a query result', + description: 'Score the result of a query.', + stainlessPath: '(resource) evaluate > (method) score_query', + qualified: 'client.evaluate.scoreQuery', + params: ['query_id: string;', 'score?: number;'], + response: '{ message: string; success: boolean; }', + markdown: + "## score_query\n\n`client.evaluate.scoreQuery(query_id: string, score?: number): { message: string; success: boolean; }`\n\n**post** `/evaluate/query/{query_id}`\n\nScore the result of a query.\n\n### Parameters\n\n- `query_id: string`\n\n- `score?: number`\n Rating of the query result from -1 (bad) to +1 (good).\n\n### Returns\n\n- `{ message: string; success: boolean; }`\n\n - `message: string`\n - `success: boolean`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.evaluate.scoreQuery('query_id');\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'evaluate score_query', + example: "hyperspell evaluate score-query \\\n --api-key 'My API Key' \\\n --query-id query_id", + }, + go: { + method: 'client.Evaluate.ScoreQuery', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Evaluate.ScoreQuery(\n\t\tcontext.TODO(),\n\t\t"query_id",\n\t\thyperspell.EvaluateScoreQueryParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.Message)\n}\n', + }, + http: { + example: + "curl https://api.hyperspell.com/evaluate/query/$QUERY_ID \\\n -H 'Content-Type: application/json' \\\n -H \"Authorization: Bearer $HYPERSPELL_API_KEY\" \\\n -d '{}'", + }, + python: { + method: 'evaluate.score_query', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.evaluate.score_query(\n query_id="query_id",\n)\nprint(response.message)', + }, + typescript: { + method: 'client.evaluate.scoreQuery', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.evaluate.scoreQuery('query_id');\n\nconsole.log(response.message);", + }, + }, + }, + { + name: 'score_highlight', + endpoint: '/evaluate/highlight/{highlight_id}', + httpMethod: 'post', + summary: 'Score a highlight', + description: 'Score an individual highlight.', + stainlessPath: '(resource) evaluate > (method) score_highlight', + qualified: 'client.evaluate.scoreHighlight', + params: ['highlight_id: string;', 'comment?: string;', 'score?: number;'], + response: '{ message: string; success: boolean; }', + markdown: + "## score_highlight\n\n`client.evaluate.scoreHighlight(highlight_id: string, comment?: string, score?: number): { message: string; success: boolean; }`\n\n**post** `/evaluate/highlight/{highlight_id}`\n\nScore an individual highlight.\n\n### Parameters\n\n- `highlight_id: string`\n\n- `comment?: string`\n Comment on the chunk\n\n- `score?: number`\n Rating of the chunk from -1 (bad) to +1 (good).\n\n### Returns\n\n- `{ message: string; success: boolean; }`\n\n - `message: string`\n - `success: boolean`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.evaluate.scoreHighlight('highlight_id');\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'evaluate score_highlight', + example: + "hyperspell evaluate score-highlight \\\n --api-key 'My API Key' \\\n --highlight-id highlight_id", + }, + go: { + method: 'client.Evaluate.ScoreHighlight', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Evaluate.ScoreHighlight(\n\t\tcontext.TODO(),\n\t\t"highlight_id",\n\t\thyperspell.EvaluateScoreHighlightParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.Message)\n}\n', + }, + http: { + example: + "curl https://api.hyperspell.com/evaluate/highlight/$HIGHLIGHT_ID \\\n -H 'Content-Type: application/json' \\\n -H \"Authorization: Bearer $HYPERSPELL_API_KEY\" \\\n -d '{}'", + }, + python: { + method: 'evaluate.score_highlight', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.evaluate.score_highlight(\n highlight_id="highlight_id",\n)\nprint(response.message)', + }, + typescript: { + method: 'client.evaluate.scoreHighlight', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.evaluate.scoreHighlight('highlight_id');\n\nconsole.log(response.message);", + }, + }, + }, + { + name: 'send_message', + endpoint: '/actions/send_message', + httpMethod: 'post', + summary: 'Send a message', + description: 'Send a message to a channel or conversation on a connected integration.', + stainlessPath: '(resource) actions > (method) send_message', + qualified: 'client.actions.sendMessage', + params: [ + 'provider: string;', + 'text: string;', + 'channel?: string;', + 'connection?: string;', + 'parent?: string;', + ], + response: '{ success: boolean; error?: string; provider_response?: object; }', + markdown: + "## send_message\n\n`client.actions.sendMessage(provider: string, text: string, channel?: string, connection?: string, parent?: string): { success: boolean; error?: string; provider_response?: object; }`\n\n**post** `/actions/send_message`\n\nSend a message to a channel or conversation on a connected integration.\n\n### Parameters\n\n- `provider: string`\n Integration provider (e.g., slack)\n\n- `text: string`\n Message text\n\n- `channel?: string`\n Channel ID (required for Slack)\n\n- `connection?: string`\n Connection ID. If omitted, auto-resolved from provider + user.\n\n- `parent?: string`\n Parent message ID for threading (thread_ts for Slack)\n\n### Returns\n\n- `{ success: boolean; error?: string; provider_response?: object; }`\n Result from executing an integration action.\n\n - `success: boolean`\n - `error?: string`\n - `provider_response?: object`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.actions.sendMessage({ provider: 'reddit', text: 'text' });\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'actions send_message', + example: + "hyperspell actions send-message \\\n --api-key 'My API Key' \\\n --provider reddit \\\n --text text", + }, + go: { + method: 'client.Actions.SendMessage', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Actions.SendMessage(context.TODO(), hyperspell.ActionSendMessageParams{\n\t\tProvider: hyperspell.ActionSendMessageParamsProviderReddit,\n\t\tText: "text",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.ProviderResponse)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/actions/send_message \\\n -H \'Content-Type: application/json\' \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY" \\\n -d \'{\n "provider": "reddit",\n "text": "text"\n }\'', + }, + python: { + method: 'actions.send_message', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.actions.send_message(\n provider="reddit",\n text="text",\n)\nprint(response.provider_response)', + }, + typescript: { + method: 'client.actions.sendMessage', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.actions.sendMessage({ provider: 'reddit', text: 'text' });\n\nconsole.log(response.provider_response);", + }, + }, + }, + { + name: 'add_reaction', + endpoint: '/actions/add_reaction', + httpMethod: 'post', + summary: 'Add a reaction', + description: 'Add an emoji reaction to a message on a connected integration.', + stainlessPath: '(resource) actions > (method) add_reaction', + qualified: 'client.actions.addReaction', + params: [ + 'channel: string;', + 'name: string;', + 'provider: string;', + 'timestamp: string;', + 'connection?: string;', + ], + response: '{ success: boolean; error?: string; provider_response?: object; }', + markdown: + "## add_reaction\n\n`client.actions.addReaction(channel: string, name: string, provider: string, timestamp: string, connection?: string): { success: boolean; error?: string; provider_response?: object; }`\n\n**post** `/actions/add_reaction`\n\nAdd an emoji reaction to a message on a connected integration.\n\n### Parameters\n\n- `channel: string`\n Channel ID containing the message\n\n- `name: string`\n Emoji name without colons (e.g., thumbsup)\n\n- `provider: string`\n Integration provider (e.g., slack)\n\n- `timestamp: string`\n Message timestamp to react to\n\n- `connection?: string`\n Connection ID. If omitted, auto-resolved from provider + user.\n\n### Returns\n\n- `{ success: boolean; error?: string; provider_response?: object; }`\n Result from executing an integration action.\n\n - `success: boolean`\n - `error?: string`\n - `provider_response?: object`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.actions.addReaction({\n channel: 'channel',\n name: 'name',\n provider: 'reddit',\n timestamp: 'timestamp',\n});\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'actions add_reaction', + example: + "hyperspell actions add-reaction \\\n --api-key 'My API Key' \\\n --channel channel \\\n --name name \\\n --provider reddit \\\n --timestamp timestamp", + }, + go: { + method: 'client.Actions.AddReaction', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Actions.AddReaction(context.TODO(), hyperspell.ActionAddReactionParams{\n\t\tChannel: "channel",\n\t\tName: "name",\n\t\tProvider: hyperspell.ActionAddReactionParamsProviderReddit,\n\t\tTimestamp: "timestamp",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.ProviderResponse)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/actions/add_reaction \\\n -H \'Content-Type: application/json\' \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY" \\\n -d \'{\n "channel": "channel",\n "name": "name",\n "provider": "reddit",\n "timestamp": "timestamp"\n }\'', + }, + python: { + method: 'actions.add_reaction', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.actions.add_reaction(\n channel="channel",\n name="name",\n provider="reddit",\n timestamp="timestamp",\n)\nprint(response.provider_response)', + }, + typescript: { + method: 'client.actions.addReaction', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.actions.addReaction({\n channel: 'channel',\n name: 'name',\n provider: 'reddit',\n timestamp: 'timestamp',\n});\n\nconsole.log(response.provider_response);", + }, + }, + }, + { + name: 'add', + endpoint: '/trace/add', + httpMethod: 'post', + summary: 'Add an agent trace', + description: + 'Add an agent trace/transcript to the index.\n\nAccepts traces as a string in Hyperdoc format (native), Vercel AI SDK format,\nor OpenClaw JSONL format. The format is auto-detected if not specified.\n\n**Hyperdoc format** (JSON array, snake_case with type discriminators):\n```json\n{"history": "[{\\"type\\": \\"trace_message\\", \\"role\\": \\"user\\", \\"text\\": \\"Hello\\"}]"}\n```\n\n**Vercel AI SDK format** (JSON array, camelCase):\n```json\n{"history": "[{\\"role\\": \\"user\\", \\"content\\": \\"Hello\\"}]"}\n```\n\n**OpenClaw JSONL format** (newline-delimited JSON):\n```json\n{"history": "{\\"type\\":\\"session\\",\\"id\\":\\"abc\\"}\\n{\\"type\\":\\"message\\",\\"message\\":{\\"role\\":\\"user\\",...}}"}\n```', + stainlessPath: '(resource) sessions > (method) add', + qualified: 'client.sessions.add', + params: [ + 'history: string;', + 'date?: string;', + "extract?: 'procedure' | 'memory' | 'mood'[];", + "format?: 'vercel' | 'hyperdoc' | 'openclaw';", + 'metadata?: object;', + 'session_id?: string;', + 'title?: string;', + ], + response: + "{ resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }", + markdown: + "## add\n\n`client.sessions.add(history: string, date?: string, extract?: 'procedure' | 'memory' | 'mood'[], format?: 'vercel' | 'hyperdoc' | 'openclaw', metadata?: object, session_id?: string, title?: string): { resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }`\n\n**post** `/trace/add`\n\nAdd an agent trace/transcript to the index.\n\nAccepts traces as a string in Hyperdoc format (native), Vercel AI SDK format,\nor OpenClaw JSONL format. The format is auto-detected if not specified.\n\n**Hyperdoc format** (JSON array, snake_case with type discriminators):\n```json\n{\"history\": \"[{\\\"type\\\": \\\"trace_message\\\", \\\"role\\\": \\\"user\\\", \\\"text\\\": \\\"Hello\\\"}]\"}\n```\n\n**Vercel AI SDK format** (JSON array, camelCase):\n```json\n{\"history\": \"[{\\\"role\\\": \\\"user\\\", \\\"content\\\": \\\"Hello\\\"}]\"}\n```\n\n**OpenClaw JSONL format** (newline-delimited JSON):\n```json\n{\"history\": \"{\\\"type\\\":\\\"session\\\",\\\"id\\\":\\\"abc\\\"}\\n{\\\"type\\\":\\\"message\\\",\\\"message\\\":{\\\"role\\\":\\\"user\\\",...}}\"}\n```\n\n### Parameters\n\n- `history: string`\n The trace history as a string. Can be a JSON array of Hyperdoc steps, a JSON array of Vercel AI SDK steps, or OpenClaw JSONL.\n\n- `date?: string`\n Date of the trace\n\n- `extract?: 'procedure' | 'memory' | 'mood'[]`\n What kind of memories to extract from the trace\n\n- `format?: 'vercel' | 'hyperdoc' | 'openclaw'`\n Trace format: 'vercel', 'hyperdoc', or 'openclaw'. Auto-detected if not set.\n\n- `metadata?: object`\n Custom metadata for filtering. Keys must be alphanumeric with underscores, max 64 chars.\n\n- `session_id?: string`\n Resource identifier for the trace.\n\n- `title?: string`\n Title of the trace\n\n### Returns\n\n- `{ resource_id: string; source: string; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; }`\n\n - `resource_id: string`\n - `source: string`\n - `status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst memoryStatus = await client.sessions.add({ history: 'history' });\n\nconsole.log(memoryStatus);\n```", + perLanguage: { + cli: { + method: 'sessions add', + example: "hyperspell sessions add \\\n --api-key 'My API Key' \\\n --history history", + }, + go: { + method: 'client.Sessions.Add', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tmemoryStatus, err := client.Sessions.Add(context.TODO(), hyperspell.SessionAddParams{\n\t\tHistory: "history",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", memoryStatus.ResourceID)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/trace/add \\\n -H \'Content-Type: application/json\' \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY" \\\n -d \'{\n "history": "history"\n }\'', + }, + python: { + method: 'sessions.add', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nmemory_status = client.sessions.add(\n history="history",\n)\nprint(memory_status.resource_id)', + }, + typescript: { + method: 'client.sessions.add', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst memoryStatus = await client.sessions.add({ history: 'history' });\n\nconsole.log(memoryStatus.resource_id);", + }, + }, + }, + { + name: 'list', + endpoint: '/vault/list', + httpMethod: 'get', + summary: 'List vaults', + description: + 'This endpoint lists all collections, and how many documents are in each collection.\nAll documents that do not have a collection assigned are in the `null` collection.', + stainlessPath: '(resource) vaults > (method) list', + qualified: 'client.vaults.list', + params: ['cursor?: string;', 'size?: number;'], + response: '{ collection: string; document_count: number; }', + markdown: + "## list\n\n`client.vaults.list(cursor?: string, size?: number): { collection: string; document_count: number; }`\n\n**get** `/vault/list`\n\nThis endpoint lists all collections, and how many documents are in each collection.\nAll documents that do not have a collection assigned are in the `null` collection.\n\n### Parameters\n\n- `cursor?: string`\n\n- `size?: number`\n\n### Returns\n\n- `{ collection: string; document_count: number; }`\n\n - `collection: string`\n - `document_count: number`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\n// Automatically fetches more pages as needed.\nfor await (const vaultListResponse of client.vaults.list()) {\n console.log(vaultListResponse);\n}\n```", + perLanguage: { + cli: { + method: 'vaults list', + example: "hyperspell vaults list \\\n --api-key 'My API Key'", + }, + go: { + method: 'client.Vaults.List', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tpage, err := client.Vaults.List(context.TODO(), hyperspell.VaultListParams{})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", page)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/vault/list \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'vaults.list', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\npage = client.vaults.list()\npage = page.items[0]\nprint(page.collection)', + }, + typescript: { + method: 'client.vaults.list', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\n// Automatically fetches more pages as needed.\nfor await (const vaultListResponse of client.vaults.list()) {\n console.log(vaultListResponse.collection);\n}", + }, + }, + }, + { + name: 'user_token', + endpoint: '/auth/user_token', + httpMethod: 'post', + summary: 'Get a user token', + description: + 'Use this endpoint to create a user token for a specific user.\nThis token can be safely passed to your user-facing front-end.', + stainlessPath: '(resource) auth > (method) user_token', + qualified: 'client.auth.userToken', + params: ['user_id: string;', 'expires_in?: string;', 'origin?: string;'], + response: '{ token: string; expires_at: string; }', + markdown: + "## user_token\n\n`client.auth.userToken(user_id: string, expires_in?: string, origin?: string): { token: string; expires_at: string; }`\n\n**post** `/auth/user_token`\n\nUse this endpoint to create a user token for a specific user.\nThis token can be safely passed to your user-facing front-end.\n\n### Parameters\n\n- `user_id: string`\n\n- `expires_in?: string`\n Token lifetime, e.g., '30m', '2h', '1d'. Defaults to 24 hours if not provided.\n\n- `origin?: string`\n Origin of the request, used for CSRF protection. If set, the token will only be valid for requests originating from this origin.\n\n### Returns\n\n- `{ token: string; expires_at: string; }`\n\n - `token: string`\n - `expires_at: string`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst token = await client.auth.userToken({ user_id: 'user_id' });\n\nconsole.log(token);\n```", + perLanguage: { + cli: { + method: 'auth user_token', + example: "hyperspell auth user-token \\\n --api-key 'My API Key' \\\n --user-id user_id", + }, + go: { + method: 'client.Auth.UserToken', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\ttoken, err := client.Auth.UserToken(context.TODO(), hyperspell.AuthUserTokenParams{\n\t\tUserID: "user_id",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", token.Token)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/auth/user_token \\\n -H \'Content-Type: application/json\' \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY" \\\n -d \'{\n "user_id": "user_id"\n }\'', + }, + python: { + method: 'auth.user_token', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\ntoken = client.auth.user_token(\n user_id="user_id",\n)\nprint(token.token)', + }, + typescript: { + method: 'client.auth.userToken', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst token = await client.auth.userToken({ user_id: 'user_id' });\n\nconsole.log(token.token);", + }, + }, + }, + { + name: 'me', + endpoint: '/auth/me', + httpMethod: 'get', + summary: 'Get Basic user data', + description: 'Endpoint to get basic user data.', + stainlessPath: '(resource) auth > (method) me', + qualified: 'client.auth.me', + response: + '{ id: string; app: { id: string; icon_url: string; name: string; redirect_url: string; }; available_integrations: string[]; installed_integrations: string[]; token_expiration: string; }', + markdown: + "## me\n\n`client.auth.me(): { id: string; app: object; available_integrations: string[]; installed_integrations: string[]; token_expiration: string; }`\n\n**get** `/auth/me`\n\nEndpoint to get basic user data.\n\n### Returns\n\n- `{ id: string; app: { id: string; icon_url: string; name: string; redirect_url: string; }; available_integrations: string[]; installed_integrations: string[]; token_expiration: string; }`\n\n - `id: string`\n - `app: { id: string; icon_url: string; name: string; redirect_url: string; }`\n - `available_integrations: string[]`\n - `installed_integrations: string[]`\n - `token_expiration: string`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.auth.me();\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'auth me', + example: "hyperspell auth me \\\n --api-key 'My API Key'", + }, + go: { + method: 'client.Auth.Me', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Auth.Me(context.TODO())\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.ID)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/auth/me \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'auth.me', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.auth.me()\nprint(response.id)', + }, + typescript: { + method: 'client.auth.me', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.auth.me();\n\nconsole.log(response.id);", + }, + }, + }, + { + name: 'delete_user', + endpoint: '/auth/delete', + httpMethod: 'delete', + summary: 'Delete user', + description: 'Endpoint to delete user.', + stainlessPath: '(resource) auth > (method) delete_user', + qualified: 'client.auth.deleteUser', + response: '{ message: string; success: boolean; }', + markdown: + "## delete_user\n\n`client.auth.deleteUser(): { message: string; success: boolean; }`\n\n**delete** `/auth/delete`\n\nEndpoint to delete user.\n\n### Returns\n\n- `{ message: string; success: boolean; }`\n\n - `message: string`\n - `success: boolean`\n\n### Example\n\n```typescript\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell();\n\nconst response = await client.auth.deleteUser();\n\nconsole.log(response);\n```", + perLanguage: { + cli: { + method: 'auth delete_user', + example: "hyperspell auth delete-user \\\n --api-key 'My API Key'", + }, + go: { + method: 'client.Auth.DeleteUser', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"),\n\t)\n\tresponse, err := client.Auth.DeleteUser(context.TODO())\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", response.Message)\n}\n', + }, + http: { + example: + 'curl https://api.hyperspell.com/auth/delete \\\n -X DELETE \\\n -H "Authorization: Bearer $HYPERSPELL_API_KEY"', + }, + python: { + method: 'auth.delete_user', + example: + 'import os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\nresponse = client.auth.delete_user()\nprint(response.message)', + }, + typescript: { + method: 'client.auth.deleteUser', + example: + "import Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.auth.deleteUser();\n\nconsole.log(response.message);", + }, + }, + }, +]; + +const EMBEDDED_READMES: { language: string; content: string }[] = [ + { + language: 'python', + content: + '# Hyperspell Python API library\n\n\n[![PyPI version](https://img.shields.io/pypi/v/hyperspell.svg?label=pypi%20(stable))](https://pypi.org/project/hyperspell/)\n\nThe Hyperspell Python library provides convenient access to the Hyperspell REST API from any Python 3.9+\napplication. The library includes type definitions for all request params and response fields,\nand offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).\n\n\n\nIt is generated with [Stainless](https://www.stainless.com/).\n\n## MCP Server\n\nUse the Hyperspell MCP Server to enable AI assistants to interact with this API, allowing them to explore endpoints, make test requests, and use documentation to help integrate this SDK into your application.\n\n[![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en-US/install-mcp?name=hyperspell-mcp&config=eyJuYW1lIjoiaHlwZXJzcGVsbC1tY3AiLCJ0cmFuc3BvcnQiOiJodHRwIiwidXJsIjoiaHR0cHM6Ly9oeXBlcnNwZWxsLnN0bG1jcC5jb20iLCJoZWFkZXJzIjp7IngtaHlwZXJzcGVsbC1hcGkta2V5IjoiTXkgQVBJIEtleSIsIlgtQXMtVXNlciI6Ik15IFVzZXIgSUQifX0)\n[![Install in VS Code](https://img.shields.io/badge/_-Add_to_VS_Code-blue?style=for-the-badge&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZmlsbD0iI0VFRSIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNMzAuMjM1IDM5Ljg4NGEyLjQ5MSAyLjQ5MSAwIDAgMS0xLjc4MS0uNzNMMTIuNyAyNC43OGwtMy40NiAyLjYyNC0zLjQwNiAyLjU4MmExLjY2NSAxLjY2NSAwIDAgMS0xLjA4Mi4zMzggMS42NjQgMS42NjQgMCAwIDEtMS4wNDYtLjQzMWwtMi4yLTJhMS42NjYgMS42NjYgMCAwIDEgMC0yLjQ2M0w3LjQ1OCAyMCA0LjY3IDE3LjQ1MyAxLjUwNyAxNC41N2ExLjY2NSAxLjY2NSAwIDAgMSAwLTIuNDYzbDIuMi0yYTEuNjY1IDEuNjY1IDAgMCAxIDIuMTMtLjA5N2w2Ljg2MyA1LjIwOUwyOC40NTIuODQ0YTIuNDg4IDIuNDg4IDAgMCAxIDEuODQxLS43MjljLjM1MS4wMDkuNjk5LjA5MSAxLjAxOS4yNDVsOC4yMzYgMy45NjFhMi41IDIuNSAwIDAgMSAxLjQxNSAyLjI1M3YuMDk5LS4wNDVWMzMuMzd2LS4wNDUuMDk1YTIuNTAxIDIuNTAxIDAgMCAxLTEuNDE2IDIuMjU3bC04LjIzNSAzLjk2MWEyLjQ5MiAyLjQ5MiAwIDAgMS0xLjA3Ny4yNDZabS43MTYtMjguOTQ3LTExLjk0OCA5LjA2MiAxMS45NTIgOS4wNjUtLjAwNC0xOC4xMjdaIi8+PC9zdmc+)](https://vscode.stainless.com/mcp/%7B%22name%22%3A%22hyperspell-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fhyperspell.stlmcp.com%22%2C%22headers%22%3A%7B%22x-hyperspell-api-key%22%3A%22My%20API%20Key%22%2C%22X-As-User%22%3A%22My%20User%20ID%22%7D%7D)\n\n> Note: You may need to set environment variables in your MCP client.\n\n## Documentation\n\nThe REST API documentation can be found on [docs.hyperspell.com](https://docs.hyperspell.com/). The full API of this library can be found in [api.md](api.md).\n\n## Installation\n\n```sh\n# install from PyPI\npip install hyperspell\n```\n\n## Usage\n\nThe full API of this library can be found in [api.md](api.md).\n\n```python\nimport os\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\n\nmemory_status = client.memories.add(\n text="text",\n)\nprint(memory_status.resource_id)\n```\n\nWhile you can provide an `api_key` keyword argument,\nwe recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)\nto add `HYPERSPELL_API_KEY="My API Key"` to your `.env` file\nso that your API Key is not stored in source control.\n\n## Async usage\n\nSimply import `AsyncHyperspell` instead of `Hyperspell` and use `await` with each API call:\n\n```python\nimport os\nimport asyncio\nfrom hyperspell import AsyncHyperspell\n\nclient = AsyncHyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n)\n\nasync def main() -> None:\n memory_status = await client.memories.add(\n text="text",\n )\n print(memory_status.resource_id)\n\nasyncio.run(main())\n```\n\nFunctionality between the synchronous and asynchronous clients is otherwise identical.\n\n### With aiohttp\n\nBy default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.\n\nYou can enable this by installing `aiohttp`:\n\n```sh\n# install from PyPI\npip install hyperspell[aiohttp]\n```\n\nThen you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:\n\n```python\nimport os\nimport asyncio\nfrom hyperspell import DefaultAioHttpClient\nfrom hyperspell import AsyncHyperspell\n\nasync def main() -> None:\n async with AsyncHyperspell(\n api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted\n http_client=DefaultAioHttpClient(),\n) as client:\n memory_status = await client.memories.add(\n text="text",\n )\n print(memory_status.resource_id)\n\nasyncio.run(main())\n```\n\n\n\n## Using types\n\nNested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:\n\n- Serializing back into JSON, `model.to_json()`\n- Converting to a dictionary, `model.to_dict()`\n\nTyped requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.\n\n## Pagination\n\nList methods in the Hyperspell API are paginated.\n\nThis library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:\n\n```python\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell()\n\nall_memories = []\n# Automatically fetches more pages as needed.\nfor memory in client.memories.list():\n # Do something with memory here\n all_memories.append(memory)\nprint(all_memories)\n```\n\nOr, asynchronously:\n\n```python\nimport asyncio\nfrom hyperspell import AsyncHyperspell\n\nclient = AsyncHyperspell()\n\nasync def main() -> None:\n all_memories = []\n # Iterate through items across all pages, issuing requests as needed.\n async for memory in client.memories.list():\n all_memories.append(memory)\n print(all_memories)\n\nasyncio.run(main())\n```\n\nAlternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:\n\n```python\nfirst_page = await client.memories.list()\nif first_page.has_next_page():\n print(f"will fetch next page using these details: {first_page.next_page_info()}")\n next_page = await first_page.get_next_page()\n print(f"number of items we just fetched: {len(next_page.items)}")\n\n# Remove `await` for non-async usage.\n```\n\nOr just work directly with the returned data:\n\n```python\nfirst_page = await client.memories.list()\n\nprint(f"next page cursor: {first_page.next_cursor}") # => "next page cursor: ..."\nfor memory in first_page.items:\n print(memory.resource_id)\n\n# Remove `await` for non-async usage.\n```\n\n## Nested params\n\nNested parameters are dictionaries, typed using `TypedDict`, for example:\n\n```python\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell()\n\nquery_result = client.memories.search(\n query="query",\n options={},\n)\nprint(query_result.options)\n```\n\n## File uploads\n\nRequest parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.\n\n```python\nfrom pathlib import Path\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell()\n\nclient.memories.upload(\n file=Path("/path/to/file"),\n)\n```\n\nThe async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically.\n\n## Handling errors\n\nWhen the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `hyperspell.APIConnectionError` is raised.\n\nWhen the API returns a non-success status code (that is, 4xx or 5xx\nresponse), a subclass of `hyperspell.APIStatusError` is raised, containing `status_code` and `response` properties.\n\nAll errors inherit from `hyperspell.APIError`.\n\n```python\nimport hyperspell\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell()\n\ntry:\n client.memories.add(\n text="text",\n )\nexcept hyperspell.APIConnectionError as e:\n print("The server could not be reached")\n print(e.__cause__) # an underlying Exception, likely raised within httpx.\nexcept hyperspell.RateLimitError as e:\n print("A 429 status code was received; we should back off a bit.")\nexcept hyperspell.APIStatusError as e:\n print("Another non-200-range status code was received")\n print(e.status_code)\n print(e.response)\n```\n\nError codes are as follows:\n\n| Status Code | Error Type |\n| ----------- | -------------------------- |\n| 400 | `BadRequestError` |\n| 401 | `AuthenticationError` |\n| 403 | `PermissionDeniedError` |\n| 404 | `NotFoundError` |\n| 422 | `UnprocessableEntityError` |\n| 429 | `RateLimitError` |\n| >=500 | `InternalServerError` |\n| N/A | `APIConnectionError` |\n\n### Retries\n\nCertain errors are automatically retried 2 times by default, with a short exponential backoff.\nConnection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,\n429 Rate Limit, and >=500 Internal errors are all retried by default.\n\nYou can use the `max_retries` option to configure or disable retry settings:\n\n```python\nfrom hyperspell import Hyperspell\n\n# Configure the default for all requests:\nclient = Hyperspell(\n # default is 2\n max_retries=0,\n)\n\n# Or, configure per-request:\nclient.with_options(max_retries = 5).memories.add(\n text="text",\n)\n```\n\n### Timeouts\n\nBy default requests time out after 1 minute. You can configure this with a `timeout` option,\nwhich accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:\n\n```python\nfrom hyperspell import Hyperspell\n\n# Configure the default for all requests:\nclient = Hyperspell(\n # 20 seconds (default is 1 minute)\n timeout=20.0,\n)\n\n# More granular control:\nclient = Hyperspell(\n timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),\n)\n\n# Override per-request:\nclient.with_options(timeout = 5.0).memories.add(\n text="text",\n)\n```\n\nOn timeout, an `APITimeoutError` is thrown.\n\nNote that requests that time out are [retried twice by default](#retries).\n\n\n\n## Advanced\n\n### Logging\n\nWe use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.\n\nYou can enable logging by setting the environment variable `HYPERSPELL_LOG` to `info`.\n\n```shell\n$ export HYPERSPELL_LOG=info\n```\n\nOr to `debug` for more verbose logging.\n\n### How to tell whether `None` means `null` or missing\n\nIn an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:\n\n```py\nif response.my_field is None:\n if \'my_field\' not in response.model_fields_set:\n print(\'Got json like {}, without a "my_field" key present at all.\')\n else:\n print(\'Got json like {"my_field": null}.\')\n```\n\n### Accessing raw response data (e.g. headers)\n\nThe "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,\n\n```py\nfrom hyperspell import Hyperspell\n\nclient = Hyperspell()\nresponse = client.memories.with_raw_response.add(\n text="text",\n)\nprint(response.headers.get(\'X-My-Header\'))\n\nmemory = response.parse() # get the object that `memories.add()` would have returned\nprint(memory.resource_id)\n```\n\nThese methods return an [`APIResponse`](https://github.com/hyperspell/python-sdk/tree/main/src/hyperspell/_response.py) object.\n\nThe async client returns an [`AsyncAPIResponse`](https://github.com/hyperspell/python-sdk/tree/main/src/hyperspell/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.\n\n#### `.with_streaming_response`\n\nThe above interface eagerly reads the full response body when you make the request, which may not always be what you want.\n\nTo stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.\n\n```python\nwith client.memories.with_streaming_response.add(\n text="text",\n) as response :\n print(response.headers.get(\'X-My-Header\'))\n\n for line in response.iter_lines():\n print(line)\n```\n\nThe context manager is required so that the response will reliably be closed.\n\n### Making custom/undocumented requests\n\nThis library is typed for convenient access to the documented API.\n\nIf you need to access undocumented endpoints, params, or response properties, the library can still be used.\n\n#### Undocumented endpoints\n\nTo make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other\nhttp verbs. Options on the client will be respected (such as retries) when making this request.\n\n```py\nimport httpx\n\nresponse = client.post(\n "/foo",\n cast_to=httpx.Response,\n body={"my_param": True},\n)\n\nprint(response.headers.get("x-foo"))\n```\n\n#### Undocumented request params\n\nIf you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request\noptions.\n\n#### Undocumented response properties\n\nTo access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You\ncan also get all the extra fields on the Pydantic model as a dict with\n[`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).\n\n### Configuring the HTTP client\n\nYou can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:\n\n- Support for [proxies](https://www.python-httpx.org/advanced/proxies/)\n- Custom [transports](https://www.python-httpx.org/advanced/transports/)\n- Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality\n\n```python\nimport httpx\nfrom hyperspell import Hyperspell, DefaultHttpxClient\n\nclient = Hyperspell(\n # Or use the `HYPERSPELL_BASE_URL` env var\n base_url="http://my.test.server.example.com:8083",\n http_client=DefaultHttpxClient(proxy="http://my.test.proxy.example.com", transport=httpx.HTTPTransport(local_address="0.0.0.0")),\n)\n```\n\nYou can also customize the client on a per-request basis by using `with_options()`:\n\n```python\nclient.with_options(http_client=DefaultHttpxClient(...))\n```\n\n### Managing HTTP resources\n\nBy default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.\n\n```py\nfrom hyperspell import Hyperspell\n\nwith Hyperspell() as client:\n # make requests here\n ...\n\n# HTTP client is now closed\n```\n\n## Versioning\n\nThis package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:\n\n1. Changes that only affect static types, without breaking runtime behavior.\n2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_\n3. Changes that we do not expect to impact the vast majority of users in practice.\n\nWe take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.\n\nWe are keen for your feedback; please open an [issue](https://www.github.com/hyperspell/python-sdk/issues) with questions, bugs, or suggestions.\n\n### Determining the installed version\n\nIf you\'ve upgraded to the latest version but aren\'t seeing any new features you were expecting then your python environment is likely still using an older version.\n\nYou can determine the version that is being used at runtime with:\n\n```py\nimport hyperspell\nprint(hyperspell.__version__)\n```\n\n## Requirements\n\nPython 3.9 or higher.\n\n## Contributing\n\nSee [the contributing documentation](./CONTRIBUTING.md).\n', + }, + { + language: 'go', + content: + '# Hyperspell Go API Library\n\nGo Reference\n\nThe Hyperspell Go library provides convenient access to the [Hyperspell REST API](https://docs.hyperspell.com/)\nfrom applications written in Go.\n\nIt is generated with [Stainless](https://www.stainless.com/).\n\n## MCP Server\n\nUse the Hyperspell MCP Server to enable AI assistants to interact with this API, allowing them to explore endpoints, make test requests, and use documentation to help integrate this SDK into your application.\n\n[![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en-US/install-mcp?name=hyperspell-mcp&config=eyJuYW1lIjoiaHlwZXJzcGVsbC1tY3AiLCJ0cmFuc3BvcnQiOiJodHRwIiwidXJsIjoiaHR0cHM6Ly9oeXBlcnNwZWxsLnN0bG1jcC5jb20iLCJoZWFkZXJzIjp7IngtaHlwZXJzcGVsbC1hcGkta2V5IjoiTXkgQVBJIEtleSIsIlgtQXMtVXNlciI6Ik15IFVzZXIgSUQifX0)\n[![Install in VS Code](https://img.shields.io/badge/_-Add_to_VS_Code-blue?style=for-the-badge&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZmlsbD0iI0VFRSIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNMzAuMjM1IDM5Ljg4NGEyLjQ5MSAyLjQ5MSAwIDAgMS0xLjc4MS0uNzNMMTIuNyAyNC43OGwtMy40NiAyLjYyNC0zLjQwNiAyLjU4MmExLjY2NSAxLjY2NSAwIDAgMS0xLjA4Mi4zMzggMS42NjQgMS42NjQgMCAwIDEtMS4wNDYtLjQzMWwtMi4yLTJhMS42NjYgMS42NjYgMCAwIDEgMC0yLjQ2M0w3LjQ1OCAyMCA0LjY3IDE3LjQ1MyAxLjUwNyAxNC41N2ExLjY2NSAxLjY2NSAwIDAgMSAwLTIuNDYzbDIuMi0yYTEuNjY1IDEuNjY1IDAgMCAxIDIuMTMtLjA5N2w2Ljg2MyA1LjIwOUwyOC40NTIuODQ0YTIuNDg4IDIuNDg4IDAgMCAxIDEuODQxLS43MjljLjM1MS4wMDkuNjk5LjA5MSAxLjAxOS4yNDVsOC4yMzYgMy45NjFhMi41IDIuNSAwIDAgMSAxLjQxNSAyLjI1M3YuMDk5LS4wNDVWMzMuMzd2LS4wNDUuMDk1YTIuNTAxIDIuNTAxIDAgMCAxLTEuNDE2IDIuMjU3bC04LjIzNSAzLjk2MWEyLjQ5MiAyLjQ5MiAwIDAgMS0xLjA3Ny4yNDZabS43MTYtMjguOTQ3LTExLjk0OCA5LjA2MiAxMS45NTIgOS4wNjUtLjAwNC0xOC4xMjdaIi8+PC9zdmc+)](https://vscode.stainless.com/mcp/%7B%22name%22%3A%22hyperspell-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fhyperspell.stlmcp.com%22%2C%22headers%22%3A%7B%22x-hyperspell-api-key%22%3A%22My%20API%20Key%22%2C%22X-As-User%22%3A%22My%20User%20ID%22%7D%7D)\n\n> Note: You may need to set environment variables in your MCP client.\n\n## Installation\n\n\n\n```go\nimport (\n\t"github.com/hyperspell/hyperspell-go" // imported as SDK_PackageName\n)\n```\n\n\n\nOr to pin the version:\n\n\n\n```sh\ngo get -u \'github.com/hyperspell/hyperspell-go@v0.0.1\'\n```\n\n\n\n## Requirements\n\nThis library requires Go 1.22+.\n\n## Usage\n\nThe full API of this library can be found in [api.md](api.md).\n\n```go\npackage main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/hyperspell/hyperspell-go"\n\t"github.com/hyperspell/hyperspell-go/option"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey("My API Key"), // defaults to os.LookupEnv("HYPERSPELL_API_KEY")\n\t)\n\tmemoryStatus, err := client.Memories.Add(context.TODO(), hyperspell.MemoryAddParams{\n\t\tText: "text",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", memoryStatus.ResourceID)\n}\n\n```\n\n### Request fields\n\nAll request parameters are wrapped in a generic `Field` type,\nwhich we use to distinguish zero values from null or omitted fields.\n\nThis prevents accidentally sending a zero value if you forget a required parameter,\nand enables explicitly sending `null`, `false`, `\'\'`, or `0` on optional parameters.\nAny field not specified is not sent.\n\nTo construct fields with values, use the helpers `String()`, `Int()`, `Float()`, or most commonly, the generic `F[T]()`.\nTo send a null, use `Null[T]()`, and to send a nonconforming value, use `Raw[T](any)`. For example:\n\n```go\nparams := FooParams{\n\tName: SDK_PackageName.F("hello"),\n\n\t// Explicitly send `"description": null`\n\tDescription: SDK_PackageName.Null[string](),\n\n\tPoint: SDK_PackageName.F(SDK_PackageName.Point{\n\t\tX: SDK_PackageName.Int(0),\n\t\tY: SDK_PackageName.Int(1),\n\n\t\t// In cases where the API specifies a given type,\n\t\t// but you want to send something else, use `Raw`:\n\t\tZ: SDK_PackageName.Raw[int64](0.01), // sends a float\n\t}),\n}\n```\n\n### Response objects\n\nAll fields in response structs are value types (not pointers or wrappers).\n\nIf a given field is `null`, not present, or invalid, the corresponding field\nwill simply be its zero value.\n\nAll response structs also include a special `JSON` field, containing more detailed\ninformation about each property, which you can use like so:\n\n```go\nif res.Name == "" {\n\t// true if `"name"` is either not present or explicitly null\n\tres.JSON.Name.IsNull()\n\n\t// true if the `"name"` key was not present in the response JSON at all\n\tres.JSON.Name.IsMissing()\n\n\t// When the API returns data that cannot be coerced to the expected type:\n\tif res.JSON.Name.IsInvalid() {\n\t\traw := res.JSON.Name.Raw()\n\n\t\tlegacyName := struct{\n\t\t\tFirst string `json:"first"`\n\t\t\tLast string `json:"last"`\n\t\t}{}\n\t\tjson.Unmarshal([]byte(raw), &legacyName)\n\t\tname = legacyName.First + " " + legacyName.Last\n\t}\n}\n```\n\nThese `.JSON` structs also include an `Extras` map containing\nany properties in the json response that were not specified\nin the struct. This can be useful for API features not yet\npresent in the SDK.\n\n```go\nbody := res.JSON.ExtraFields["my_unexpected_field"].Raw()\n```\n\n### RequestOptions\n\nThis library uses the functional options pattern. Functions defined in the\n`SDK_PackageOptionName` package return a `RequestOption`, which is a closure that mutates a\n`RequestConfig`. These options can be supplied to the client or at individual\nrequests. For example:\n\n```go\nclient := SDK_PackageName.SDK_ClientInitializerName(\n\t// Adds a header to every request made by the client\n\tSDK_PackageOptionName.WithHeader("X-Some-Header", "custom_header_info"),\n)\n\nclient.Memories.Add(context.TODO(), ...,\n\t// Override the header\n\tSDK_PackageOptionName.WithHeader("X-Some-Header", "some_other_custom_header_info"),\n\t// Add an undocumented field to the request body, using sjson syntax\n\tSDK_PackageOptionName.WithJSONSet("some.json.path", map[string]string{"my": "object"}),\n)\n```\n\nSee the [full list of request options](https://pkg.go.dev/github.com/hyperspell/hyperspell-go/SDK_PackageOptionName).\n\n### Pagination\n\nThis library provides some conveniences for working with paginated list endpoints.\n\nYou can use `.ListAutoPaging()` methods to iterate through items across all pages:\n\n```go\niter := client.Memories.ListAutoPaging(context.TODO(), hyperspell.MemoryListParams{})\n// Automatically fetches more pages as needed.\nfor iter.Next() {\n\tresource := iter.Current()\n\tfmt.Printf("%+v\\n", resource)\n}\nif err := iter.Err(); err != nil {\n\tpanic(err.Error())\n}\n```\n\nOr you can use simple `.List()` methods to fetch a single page and receive a standard response object\nwith additional helper methods like `.GetNextPage()`, e.g.:\n\n```go\npage, err := client.Memories.List(context.TODO(), hyperspell.MemoryListParams{})\nfor page != nil {\n\tfor _, memory := range page.Items {\n\t\tfmt.Printf("%+v\\n", memory)\n\t}\n\tpage, err = page.GetNextPage()\n}\nif err != nil {\n\tpanic(err.Error())\n}\n```\n\n### Errors\n\nWhen the API returns a non-success status code, we return an error with type\n`*SDK_PackageName.Error`. This contains the `StatusCode`, `*http.Request`, and\n`*http.Response` values of the request, as well as the JSON of the error body\n(much like other response objects in the SDK).\n\nTo handle errors, we recommend that you use the `errors.As` pattern:\n\n```go\n_, err := client.Memories.Add(context.TODO(), hyperspell.MemoryAddParams{\n\tText: "text",\n})\nif err != nil {\n\tvar apierr *hyperspell.Error\n\tif errors.As(err, &apierr) {\n\t\tprintln(string(apierr.DumpRequest(true))) // Prints the serialized HTTP request\n\t\tprintln(string(apierr.DumpResponse(true))) // Prints the serialized HTTP response\n\t}\n\tpanic(err.Error()) // GET "/memories/add": 400 Bad Request { ... }\n}\n```\n\nWhen other errors occur, they are returned unwrapped; for example,\nif HTTP transport fails, you might receive `*url.Error` wrapping `*net.OpError`.\n\n### Timeouts\n\nRequests do not time out by default; use context to configure a timeout for a request lifecycle.\n\nNote that if a request is [retried](#retries), the context timeout does not start over.\nTo set a per-retry timeout, use `SDK_PackageOptionName.WithRequestTimeout()`.\n\n```go\n// This sets the timeout for the request, including all the retries.\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)\ndefer cancel()\nclient.Memories.Add(\n\tctx,\n\thyperspell.MemoryAddParams{\n\t\tText: "text",\n\t},\n\t// This sets the per-retry timeout\n\toption.WithRequestTimeout(20*time.Second),\n)\n```\n\n### File uploads\n\nRequest parameters that correspond to file uploads in multipart requests are typed as\n`param.Field[io.Reader]`. The contents of the `io.Reader` will by default be sent as a multipart form\npart with the file name of "anonymous_file" and content-type of "application/octet-stream".\n\nThe file name and content-type can be customized by implementing `Name() string` or `ContentType()\nstring` on the run-time type of `io.Reader`. Note that `os.File` implements `Name() string`, so a\nfile returned by `os.Open` will be sent with the file name on disk.\n\nWe also provide a helper `SDK_PackageName.FileParam(reader io.Reader, filename string, contentType string)`\nwhich can be used to wrap any `io.Reader` with the appropriate file name and content type.\n\n```go\n// A file from the file system\nfile, err := os.Open("/path/to/file")\nhyperspell.MemoryUploadParams{\n\tFile: file,\n}\n\n// A file from a string\nhyperspell.MemoryUploadParams{\n\tFile: strings.NewReader("my file contents"),\n}\n\n// With a custom filename and contentType\nhyperspell.MemoryUploadParams{\n\tFile: hyperspell.File(strings.NewReader(`{"hello": "foo"}`), "file.go", "application/json"),\n}\n```\n\n### Retries\n\nCertain errors will be automatically retried 2 times by default, with a short exponential backoff.\nWe retry by default all connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit,\nand >=500 Internal errors.\n\nYou can use the `WithMaxRetries` option to configure or disable this:\n\n```go\n// Configure the default for all requests:\nclient := hyperspell.NewClient(\n\toption.WithMaxRetries(0), // default is 2\n)\n\n// Override per-request:\nclient.Memories.Add(\n\tcontext.TODO(),\n\thyperspell.MemoryAddParams{\n\t\tText: "text",\n\t},\n\toption.WithMaxRetries(5),\n)\n```\n\n\n### Accessing raw response data (e.g. response headers)\n\nYou can access the raw HTTP response data by using the `option.WithResponseInto()` request option. This is useful when\nyou need to examine response headers, status codes, or other details.\n\n```go\n// Create a variable to store the HTTP response\nvar response *http.Response\nmemoryStatus, err := client.Memories.Add(\n\tcontext.TODO(),\n\thyperspell.MemoryAddParams{\n\t\tText: "text",\n\t},\n\toption.WithResponseInto(&response),\n)\nif err != nil {\n\t// handle error\n}\nfmt.Printf("%+v\\n", memoryStatus)\n\nfmt.Printf("Status Code: %d\\n", response.StatusCode)\nfmt.Printf("Headers: %+#v\\n", response.Header)\n```\n\n### Making custom/undocumented requests\n\nThis library is typed for convenient access to the documented API. If you need to access undocumented\nendpoints, params, or response properties, the library can still be used.\n\n#### Undocumented endpoints\n\nTo make requests to undocumented endpoints, you can use `client.Get`, `client.Post`, and other HTTP verbs.\n`RequestOptions` on the client, such as retries, will be respected when making these requests.\n\n```go\nvar (\n // params can be an io.Reader, a []byte, an encoding/json serializable object,\n // or a "…Params" struct defined in this library.\n params map[string]interface{}\n\n // result can be an []byte, *http.Response, a encoding/json deserializable object,\n // or a model defined in this library.\n result *http.Response\n)\nerr := client.Post(context.Background(), "/unspecified", params, &result)\nif err != nil {\n …\n}\n```\n\n#### Undocumented request params\n\nTo make requests using undocumented parameters, you may use either the `SDK_PackageOptionName.WithQuerySet()`\nor the `SDK_PackageOptionName.WithJSONSet()` methods.\n\n```go\nparams := FooNewParams{\n ID: SDK_PackageName.F("id_xxxx"),\n Data: SDK_PackageName.F(FooNewParamsData{\n FirstName: SDK_PackageName.F("John"),\n }),\n}\nclient.Foo.New(context.Background(), params, SDK_PackageOptionName.WithJSONSet("data.last_name", "Doe"))\n```\n\n#### Undocumented response properties\n\nTo access undocumented response properties, you may either access the raw JSON of the response as a string\nwith `result.JSON.RawJSON()`, or get the raw JSON of a particular field on the result with\n`result.JSON.Foo.Raw()`.\n\nAny fields that are not present on the response struct will be saved and can be accessed by `result.JSON.ExtraFields()` which returns the extra fields as a `map[string]Field`.\n\n### Middleware\n\nWe provide `SDK_PackageOptionName.WithMiddleware` which applies the given\nmiddleware to requests.\n\n```go\nfunc Logger(req *http.Request, next SDK_PackageOptionName.MiddlewareNext) (res *http.Response, err error) {\n\t// Before the request\n\tstart := time.Now()\n\tLogReq(req)\n\n\t// Forward the request to the next handler\n\tres, err = next(req)\n\n\t// Handle stuff after the request\n\tend := time.Now()\n\tLogRes(res, err, start - end)\n\n return res, err\n}\n\nclient := SDK_PackageName.SDK_ClientInitializerName(\n\tSDK_PackageOptionName.WithMiddleware(Logger),\n)\n```\n\nWhen multiple middlewares are provided as variadic arguments, the middlewares\nare applied left to right. If `SDK_PackageOptionName.WithMiddleware` is given\nmultiple times, for example first in the client then the method, the\nmiddleware in the client will run first and the middleware given in the method\nwill run next.\n\nYou may also replace the default `http.Client` with\n`SDK_PackageOptionName.WithHTTPClient(client)`. Only one http client is\naccepted (this overwrites any previous client) and receives requests after any\nmiddleware has been applied.\n\n## Semantic versioning\n\nThis package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:\n\n1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_\n2. Changes that we do not expect to impact the vast majority of users in practice.\n\nWe take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.\n\nWe are keen for your feedback; please open an [issue](https://www.github.com/hyperspell/hyperspell-go/issues) with questions, bugs, or suggestions.\n\n## Contributing\n\nSee [the contributing documentation](./CONTRIBUTING.md).\n', + }, + { + language: 'typescript', + content: + "# Hyperspell TypeScript API Library\n\n[![NPM version](https://img.shields.io/npm/v/hyperspell.svg?label=npm%20(stable))](https://npmjs.org/package/hyperspell) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/hyperspell)\n\nThis library provides convenient access to the Hyperspell REST API from server-side TypeScript or JavaScript.\n\n\n\nThe REST API documentation can be found on [docs.hyperspell.com](https://docs.hyperspell.com/). The full API of this library can be found in [api.md](api.md).\n\nIt is generated with [Stainless](https://www.stainless.com/).\n\n## MCP Server\n\nUse the Hyperspell MCP Server to enable AI assistants to interact with this API, allowing them to explore endpoints, make test requests, and use documentation to help integrate this SDK into your application.\n\n[![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en-US/install-mcp?name=hyperspell-mcp&config=eyJuYW1lIjoiaHlwZXJzcGVsbC1tY3AiLCJ0cmFuc3BvcnQiOiJodHRwIiwidXJsIjoiaHR0cHM6Ly9oeXBlcnNwZWxsLnN0bG1jcC5jb20iLCJoZWFkZXJzIjp7IngtaHlwZXJzcGVsbC1hcGkta2V5IjoiTXkgQVBJIEtleSIsIlgtQXMtVXNlciI6Ik15IFVzZXIgSUQifX0)\n[![Install in VS Code](https://img.shields.io/badge/_-Add_to_VS_Code-blue?style=for-the-badge&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZmlsbD0iI0VFRSIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNMzAuMjM1IDM5Ljg4NGEyLjQ5MSAyLjQ5MSAwIDAgMS0xLjc4MS0uNzNMMTIuNyAyNC43OGwtMy40NiAyLjYyNC0zLjQwNiAyLjU4MmExLjY2NSAxLjY2NSAwIDAgMS0xLjA4Mi4zMzggMS42NjQgMS42NjQgMCAwIDEtMS4wNDYtLjQzMWwtMi4yLTJhMS42NjYgMS42NjYgMCAwIDEgMC0yLjQ2M0w3LjQ1OCAyMCA0LjY3IDE3LjQ1MyAxLjUwNyAxNC41N2ExLjY2NSAxLjY2NSAwIDAgMSAwLTIuNDYzbDIuMi0yYTEuNjY1IDEuNjY1IDAgMCAxIDIuMTMtLjA5N2w2Ljg2MyA1LjIwOUwyOC40NTIuODQ0YTIuNDg4IDIuNDg4IDAgMCAxIDEuODQxLS43MjljLjM1MS4wMDkuNjk5LjA5MSAxLjAxOS4yNDVsOC4yMzYgMy45NjFhMi41IDIuNSAwIDAgMSAxLjQxNSAyLjI1M3YuMDk5LS4wNDVWMzMuMzd2LS4wNDUuMDk1YTIuNTAxIDIuNTAxIDAgMCAxLTEuNDE2IDIuMjU3bC04LjIzNSAzLjk2MWEyLjQ5MiAyLjQ5MiAwIDAgMS0xLjA3Ny4yNDZabS43MTYtMjguOTQ3LTExLjk0OCA5LjA2MiAxMS45NTIgOS4wNjUtLjAwNC0xOC4xMjdaIi8+PC9zdmc+)](https://vscode.stainless.com/mcp/%7B%22name%22%3A%22hyperspell-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fhyperspell.stlmcp.com%22%2C%22headers%22%3A%7B%22x-hyperspell-api-key%22%3A%22My%20API%20Key%22%2C%22X-As-User%22%3A%22My%20User%20ID%22%7D%7D)\n\n> Note: You may need to set environment variables in your MCP client.\n\n## Installation\n\n```sh\nnpm install hyperspell\n```\n\n\n\n## Usage\n\nThe full API of this library can be found in [api.md](api.md).\n\n\n```js\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst memoryStatus = await client.memories.add({ text: 'text' });\n\nconsole.log(memoryStatus.resource_id);\n```\n\n\n\n### Request & Response types\n\nThis library includes TypeScript definitions for all request params and response fields. You may import and use them like so:\n\n\n```ts\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted\n});\n\nconst params: Hyperspell.MemoryAddParams = { text: 'text' };\nconst memoryStatus: Hyperspell.MemoryStatus = await client.memories.add(params);\n```\n\nDocumentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.\n\n## File uploads\n\nRequest parameters that correspond to file uploads can be passed in many different forms:\n- `File` (or an object with the same structure)\n- a `fetch` `Response` (or an object with the same structure)\n- an `fs.ReadStream`\n- the return value of our `toFile` helper\n\n```ts\nimport fs from 'fs';\nimport Hyperspell, { toFile } from 'hyperspell';\n\nconst client = new Hyperspell();\n\n// If you have access to Node `fs` we recommend using `fs.createReadStream()`:\nawait client.memories.upload({ file: fs.createReadStream('/path/to/file') });\n\n// Or if you have the web `File` API you can pass a `File` instance:\nawait client.memories.upload({ file: new File(['my bytes'], 'file') });\n\n// You can also pass a `fetch` `Response`:\nawait client.memories.upload({ file: await fetch('https://somesite/file') });\n\n// Finally, if none of the above are convenient, you can use our `toFile` helper:\nawait client.memories.upload({ file: await toFile(Buffer.from('my bytes'), 'file') });\nawait client.memories.upload({ file: await toFile(new Uint8Array([0, 1, 2]), 'file') });\n```\n\n\n\n## Handling errors\n\nWhen the library is unable to connect to the API,\nor if the API returns a non-success status code (i.e., 4xx or 5xx response),\na subclass of `APIError` will be thrown:\n\n\n```ts\nconst memoryStatus = await client.memories.add({ text: 'text' }).catch(async (err) => {\n if (err instanceof Hyperspell.APIError) {\n console.log(err.status); // 400\n console.log(err.name); // BadRequestError\n console.log(err.headers); // {server: 'nginx', ...}\n } else {\n throw err;\n }\n});\n```\n\nError codes are as follows:\n\n| Status Code | Error Type |\n| ----------- | -------------------------- |\n| 400 | `BadRequestError` |\n| 401 | `AuthenticationError` |\n| 403 | `PermissionDeniedError` |\n| 404 | `NotFoundError` |\n| 422 | `UnprocessableEntityError` |\n| 429 | `RateLimitError` |\n| >=500 | `InternalServerError` |\n| N/A | `APIConnectionError` |\n\n### Retries\n\nCertain errors will be automatically retried 2 times by default, with a short exponential backoff.\nConnection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,\n429 Rate Limit, and >=500 Internal errors will all be retried by default.\n\nYou can use the `maxRetries` option to configure or disable this:\n\n\n```js\n// Configure the default for all requests:\nconst client = new Hyperspell({\n maxRetries: 0, // default is 2\n});\n\n// Or, configure per-request:\nawait client.memories.add({ text: 'text' }, {\n maxRetries: 5,\n});\n```\n\n### Timeouts\n\nRequests time out after 1 minute by default. You can configure this with a `timeout` option:\n\n\n```ts\n// Configure the default for all requests:\nconst client = new Hyperspell({\n timeout: 20 * 1000, // 20 seconds (default is 1 minute)\n});\n\n// Override per-request:\nawait client.memories.add({ text: 'text' }, {\n timeout: 5 * 1000,\n});\n```\n\nOn timeout, an `APIConnectionTimeoutError` is thrown.\n\nNote that requests which time out will be [retried twice by default](#retries).\n\n## Auto-pagination\n\nList methods in the Hyperspell API are paginated.\nYou can use the `for await … of` syntax to iterate through items across all pages:\n\n```ts\nasync function fetchAllResources(params) {\n const allResources = [];\n // Automatically fetches more pages as needed.\n for await (const resource of client.memories.list()) {\n allResources.push(resource);\n }\n return allResources;\n}\n```\n\nAlternatively, you can request a single page at a time:\n\n```ts\nlet page = await client.memories.list();\nfor (const resource of page.items) {\n console.log(resource);\n}\n\n// Convenience methods are provided for manually paginating:\nwhile (page.hasNextPage()) {\n page = await page.getNextPage();\n // ...\n}\n```\n\n\n\n## Advanced Usage\n\n### Accessing raw Response data (e.g., headers)\n\nThe \"raw\" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return.\nThis method returns as soon as the headers for a successful response are received and does not consume the response body, so you are free to write custom parsing or streaming logic.\n\nYou can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.\nUnlike `.asResponse()` this method consumes the body, returning once it is parsed.\n\n\n```ts\nconst client = new Hyperspell();\n\nconst response = await client.memories.add({ text: 'text' }).asResponse();\nconsole.log(response.headers.get('X-My-Header'));\nconsole.log(response.statusText); // access the underlying Response object\n\nconst { data: memoryStatus, response: raw } = await client.memories\n .add({ text: 'text' })\n .withResponse();\nconsole.log(raw.headers.get('X-My-Header'));\nconsole.log(memoryStatus.resource_id);\n```\n\n### Logging\n\n> [!IMPORTANT]\n> All log messages are intended for debugging only. The format and content of log messages\n> may change between releases.\n\n#### Log levels\n\nThe log level can be configured in two ways:\n\n1. Via the `HYPERSPELL_LOG` environment variable\n2. Using the `logLevel` client option (overrides the environment variable if set)\n\n```ts\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n logLevel: 'debug', // Show all log messages\n});\n```\n\nAvailable log levels, from most to least verbose:\n\n- `'debug'` - Show debug messages, info, warnings, and errors\n- `'info'` - Show info messages, warnings, and errors\n- `'warn'` - Show warnings and errors (default)\n- `'error'` - Show only errors\n- `'off'` - Disable all logging\n\nAt the `'debug'` level, all HTTP requests and responses are logged, including headers and bodies.\nSome authentication-related headers are redacted, but sensitive data in request and response bodies\nmay still be visible.\n\n#### Custom logger\n\nBy default, this library logs to `globalThis.console`. You can also provide a custom logger.\nMost logging libraries are supported, including [pino](https://www.npmjs.com/package/pino), [winston](https://www.npmjs.com/package/winston), [bunyan](https://www.npmjs.com/package/bunyan), [consola](https://www.npmjs.com/package/consola), [signale](https://www.npmjs.com/package/signale), and [@std/log](https://jsr.io/@std/log). If your logger doesn't work, please open an issue.\n\nWhen providing a custom logger, the `logLevel` option still controls which messages are emitted, messages\nbelow the configured level will not be sent to your logger.\n\n```ts\nimport Hyperspell from 'hyperspell';\nimport pino from 'pino';\n\nconst logger = pino();\n\nconst client = new Hyperspell({\n logger: logger.child({ name: 'Hyperspell' }),\n logLevel: 'debug', // Send all messages to pino, allowing it to filter\n});\n```\n\n### Making custom/undocumented requests\n\nThis library is typed for convenient access to the documented API. If you need to access undocumented\nendpoints, params, or response properties, the library can still be used.\n\n#### Undocumented endpoints\n\nTo make requests to undocumented endpoints, you can use `client.get`, `client.post`, and other HTTP verbs.\nOptions on the client, such as retries, will be respected when making these requests.\n\n```ts\nawait client.post('/some/path', {\n body: { some_prop: 'foo' },\n query: { some_query_arg: 'bar' },\n});\n```\n\n#### Undocumented request params\n\nTo make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented\nparameter. This library doesn't validate at runtime that the request matches the type, so any extra values you\nsend will be sent as-is.\n\n```ts\nclient.memories.add({\n // ...\n // @ts-expect-error baz is not yet public\n baz: 'undocumented option',\n});\n```\n\nFor requests with the `GET` verb, any extra params will be in the query, all other requests will send the\nextra param in the body.\n\nIf you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request\noptions.\n\n#### Undocumented response properties\n\nTo access undocumented response properties, you may access the response object with `// @ts-expect-error` on\nthe response object, or cast the response object to the requisite type. Like the request params, we do not\nvalidate or strip extra properties from the response from the API.\n\n### Customizing the fetch client\n\nBy default, this library expects a global `fetch` function is defined.\n\nIf you want to use a different `fetch` function, you can either polyfill the global:\n\n```ts\nimport fetch from 'my-fetch';\n\nglobalThis.fetch = fetch;\n```\n\nOr pass it to the client:\n\n```ts\nimport Hyperspell from 'hyperspell';\nimport fetch from 'my-fetch';\n\nconst client = new Hyperspell({ fetch });\n```\n\n### Fetch options\n\nIf you want to set custom `fetch` options without overriding the `fetch` function, you can provide a `fetchOptions` object when instantiating the client or making a request. (Request-specific options override client options.)\n\n```ts\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n fetchOptions: {\n // `RequestInit` options\n },\n});\n```\n\n#### Configuring proxies\n\nTo modify proxy behavior, you can provide custom `fetchOptions` that add runtime-specific proxy\noptions to requests:\n\n **Node** [[docs](https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md#example---proxyagent-with-fetch)]\n\n```ts\nimport Hyperspell from 'hyperspell';\nimport * as undici from 'undici';\n\nconst proxyAgent = new undici.ProxyAgent('http://localhost:8888');\nconst client = new Hyperspell({\n fetchOptions: {\n dispatcher: proxyAgent,\n },\n});\n```\n\n **Bun** [[docs](https://bun.sh/guides/http/proxy)]\n\n```ts\nimport Hyperspell from 'hyperspell';\n\nconst client = new Hyperspell({\n fetchOptions: {\n proxy: 'http://localhost:8888',\n },\n});\n```\n\n **Deno** [[docs](https://docs.deno.com/api/deno/~/Deno.createHttpClient)]\n\n```ts\nimport Hyperspell from 'npm:hyperspell';\n\nconst httpClient = Deno.createHttpClient({ proxy: { url: 'http://localhost:8888' } });\nconst client = new Hyperspell({\n fetchOptions: {\n client: httpClient,\n },\n});\n```\n\n## Frequently Asked Questions\n\n## Semantic versioning\n\nThis package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:\n\n1. Changes that only affect static types, without breaking runtime behavior.\n2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_\n3. Changes that we do not expect to impact the vast majority of users in practice.\n\nWe take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.\n\nWe are keen for your feedback; please open an [issue](https://www.github.com/hyperspell/node-sdk/issues) with questions, bugs, or suggestions.\n\n## Requirements\n\nTypeScript >= 4.9 is supported.\n\nThe following runtimes are supported:\n\n- Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)\n- Node.js 20 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.\n- Deno v1.28.0 or higher.\n- Bun 1.0 or later.\n- Cloudflare Workers.\n- Vercel Edge Runtime.\n- Jest 28 or greater with the `\"node\"` environment (`\"jsdom\"` is not supported at this time).\n- Nitro v2.6 or greater.\n\nNote that React Native is not supported at this time.\n\nIf you are interested in other runtime environments, please open or upvote an issue on GitHub.\n\n## Contributing\n\nSee [the contributing documentation](./CONTRIBUTING.md).\n", + }, + { + language: 'cli', + content: + "# Hyperspell CLI\n\nThe official CLI for the [Hyperspell REST API](https://docs.hyperspell.com/).\n\nIt is generated with [Stainless](https://www.stainless.com/).\n\n\n\n## Installation\n\n### Installing with Homebrew\n\n~~~sh\nbrew install hyperspell/tools/hyperspell\n~~~\n\n### Installing with Go\n\nTo test or install the CLI locally, you need [Go](https://go.dev/doc/install) version 1.22 or later installed.\n\n~~~sh\ngo install 'github.com/hyperspell/hyperspell-cli/cmd/hyperspell@latest'\n~~~\n\nOnce you have run `go install`, the binary is placed in your Go bin directory:\n\n- **Default location**: `$HOME/go/bin` (or `$GOPATH/bin` if GOPATH is set)\n- **Check your path**: Run `go env GOPATH` to see the base directory\n\nIf commands aren't found after installation, add the Go bin directory to your PATH:\n\n~~~sh\n# Add to your shell profile (.zshrc, .bashrc, etc.)\nexport PATH=\"$PATH:$(go env GOPATH)/bin\"\n~~~\n\n\n\n### Running Locally\n\nAfter cloning the git repository for this project, you can use the\n`scripts/run` script to run the tool locally:\n\n~~~sh\n./scripts/run args...\n~~~\n\n## Usage\n\nThe CLI follows a resource-based command structure:\n\n~~~sh\nhyperspell [resource] [flags...]\n~~~\n\n~~~sh\nhyperspell memories add \\\n --api-key 'My API Key' \\\n --text text\n~~~\n\nFor details about specific commands, use the `--help` flag.\n\n### Environment variables\n\n| Environment variable | Description | Required |\n| -------------------- | ---------------------------------------------------------------------------- | -------- |\n| `HYPERSPELL_API_KEY` | Either an API Key or User Token to authenticate a specific user of your app. | yes |\n\n### Global flags\n\n- `--api-key` - Either an API Key or User Token to authenticate a specific user of your app. (can also be set with `HYPERSPELL_API_KEY` env var)\n- `--user-id` - The id of the user making this request. Optional.\n- `--help` - Show command line usage\n- `--debug` - Enable debug logging (includes HTTP request/response details)\n- `--version`, `-v` - Show the CLI version\n- `--base-url` - Use a custom API backend URL\n- `--format` - Change the output format (`auto`, `explore`, `json`, `jsonl`, `pretty`, `raw`, `yaml`)\n- `--format-error` - Change the output format for errors (`auto`, `explore`, `json`, `jsonl`, `pretty`, `raw`, `yaml`)\n- `--transform` - Transform the data output using [GJSON syntax](https://github.com/tidwall/gjson/blob/master/SYNTAX.md)\n- `--transform-error` - Transform the error output using [GJSON syntax](https://github.com/tidwall/gjson/blob/master/SYNTAX.md)\n\n### Passing files as arguments\n\nTo pass files to your API, you can use the `@myfile.ext` syntax:\n\n~~~bash\nhyperspell --arg @abe.jpg\n~~~\n\nFiles can also be passed inside JSON or YAML blobs:\n\n~~~bash\nhyperspell --arg '{image: \"@abe.jpg\"}'\n# Equivalent:\nhyperspell < --username '\\@abe'\n~~~\n\n#### Explicit encoding\n\nFor JSON endpoints, the CLI tool does filetype sniffing to determine whether the\nfile contents should be sent as a string literal (for plain text files) or as a\nbase64-encoded string literal (for binary files). If you need to explicitly send\nthe file as either plain text or base64-encoded data, you can use\n`@file://myfile.txt` (for string encoding) or `@data://myfile.dat` (for\nbase64-encoding). Note that absolute paths will begin with `@file://` or\n`@data://`, followed by a third `/` (for example, `@file:///tmp/file.txt`).\n\n~~~bash\nhyperspell --arg @data://file.txt\n~~~\n", + }, +]; + +const INDEX_OPTIONS = { + fields: [ + 'name', + 'endpoint', + 'summary', + 'description', + 'qualified', + 'stainlessPath', + 'content', + 'sectionContext', + ], + storeFields: ['kind', '_original'], + searchOptions: { + prefix: true, + fuzzy: 0.1, + boost: { + name: 5, + stainlessPath: 3, + endpoint: 3, + qualified: 3, + summary: 2, + content: 1, + description: 1, + } as Record, + }, +}; + +/** + * Self-contained local search engine backed by MiniSearch. + * Method data is embedded at SDK build time; prose documents + * can be loaded from an optional docs directory at runtime. + */ +export class LocalDocsSearch { + private methodIndex: MiniSearch; + private proseIndex: MiniSearch; + + private constructor() { + this.methodIndex = new MiniSearch(INDEX_OPTIONS); + this.proseIndex = new MiniSearch(INDEX_OPTIONS); + } + + static async create(opts?: { docsDir?: string }): Promise { + const instance = new LocalDocsSearch(); + instance.indexMethods(EMBEDDED_METHODS); + for (const readme of EMBEDDED_READMES) { + instance.indexProse(readme.content, `readme:${readme.language}`); + } + if (opts?.docsDir) { + await instance.loadDocsDirectory(opts.docsDir); + } + return instance; + } + + search(props: { + query: string; + language?: string; + detail?: string; + maxResults?: number; + maxLength?: number; + }): SearchResult { + const { query, language = 'typescript', detail = 'default', maxResults = 5, maxLength = 100_000 } = props; + + const useMarkdown = detail === 'verbose' || detail === 'high'; + + // Search both indices and merge results by score. + // Filter prose hits so language-tagged content (READMEs and docs with + // frontmatter) only matches the requested language. + const methodHits = this.methodIndex + .search(query) + .map((hit) => ({ ...hit, _kind: 'http_method' as const })); + const proseHits = this.proseIndex + .search(query) + .filter((hit) => { + const source = ((hit as Record)['_original'] as ProseChunk | undefined)?.source; + if (!source) return true; + // Check for language-tagged sources: "readme:" or "lang::" + let taggedLang: string | undefined; + if (source.startsWith('readme:')) taggedLang = source.slice('readme:'.length); + else if (source.startsWith('lang:')) taggedLang = source.split(':')[1]; + if (!taggedLang) return true; + return taggedLang === language || (language === 'javascript' && taggedLang === 'typescript'); + }) + .map((hit) => ({ ...hit, _kind: 'prose' as const })); + const merged = [...methodHits, ...proseHits].sort((a, b) => b.score - a.score); + const top = merged.slice(0, maxResults); + + const fullResults: (string | Record)[] = []; + + for (const hit of top) { + const original = (hit as Record)['_original']; + if (hit._kind === 'http_method') { + const m = original as MethodEntry; + if (useMarkdown && m.markdown) { + fullResults.push(m.markdown); + } else { + // Use per-language data when available, falling back to the + // top-level fields (which are TypeScript-specific in the + // legacy codepath). + const langData = m.perLanguage?.[language]; + fullResults.push({ + method: langData?.method ?? m.qualified, + summary: m.summary, + description: m.description, + endpoint: `${m.httpMethod.toUpperCase()} ${m.endpoint}`, + ...(langData?.example ? { example: langData.example } : {}), + ...(m.params ? { params: m.params } : {}), + ...(m.response ? { response: m.response } : {}), + }); + } + } else { + const c = original as ProseChunk; + fullResults.push({ + content: c.content, + ...(c.source ? { source: c.source } : {}), + }); + } + } + + let totalLength = 0; + const results: (string | Record)[] = []; + for (const result of fullResults) { + const len = typeof result === 'string' ? result.length : JSON.stringify(result).length; + totalLength += len; + if (totalLength > maxLength) break; + results.push(result); + } + + if (results.length < fullResults.length) { + results.unshift(`Truncated; showing ${results.length} of ${fullResults.length} results.`); + } + + return { results }; + } + + private indexMethods(methods: MethodEntry[]): void { + const docs: MiniSearchDocument[] = methods.map((m, i) => ({ + id: `method-${i}`, + kind: 'http_method' as const, + name: m.name, + endpoint: m.endpoint, + summary: m.summary, + description: m.description, + qualified: m.qualified, + stainlessPath: m.stainlessPath, + _original: m as unknown as Record, + })); + if (docs.length > 0) { + this.methodIndex.addAll(docs); + } + } + + private async loadDocsDirectory(docsDir: string): Promise { + let entries; + try { + entries = await fs.readdir(docsDir, { withFileTypes: true }); + } catch (err) { + getLogger().warn({ err, docsDir }, 'Could not read docs directory'); + return; + } + + const files = entries + .filter((e) => e.isFile()) + .filter((e) => e.name.endsWith('.md') || e.name.endsWith('.markdown') || e.name.endsWith('.json')); + + for (const file of files) { + try { + const filePath = path.join(docsDir, file.name); + const content = await fs.readFile(filePath, 'utf-8'); + + if (file.name.endsWith('.json')) { + const texts = extractTexts(JSON.parse(content)); + if (texts.length > 0) { + this.indexProse(texts.join('\n\n'), file.name); + } + } else { + // Parse optional YAML frontmatter for language tagging. + // Files with a "language" field in frontmatter will only + // surface in searches for that language. + // + // Example: + // --- + // language: python + // --- + // # Error handling in Python + // ... + const frontmatter = parseFrontmatter(content); + const source = frontmatter.language ? `lang:${frontmatter.language}:${file.name}` : file.name; + this.indexProse(content, source); + } + } catch (err) { + getLogger().warn({ err, file: file.name }, 'Failed to index docs file'); + } + } + } + + private indexProse(markdown: string, source: string): void { + const chunks = chunkMarkdown(markdown); + const baseId = this.proseIndex.documentCount; + + const docs: MiniSearchDocument[] = chunks.map((chunk, i) => ({ + id: `prose-${baseId + i}`, + kind: 'prose' as const, + content: chunk.content, + ...(chunk.sectionContext != null ? { sectionContext: chunk.sectionContext } : {}), + _original: { ...chunk, source } as unknown as Record, + })); + + if (docs.length > 0) { + this.proseIndex.addAll(docs); + } + } +} + +/** Lightweight markdown chunker — splits on headers, chunks by word count. */ +function chunkMarkdown(markdown: string): { content: string; tag: string; sectionContext?: string }[] { + // Strip YAML frontmatter + const stripped = markdown.replace(/^---\n[\s\S]*?\n---\n?/, ''); + const lines = stripped.split('\n'); + + const chunks: { content: string; tag: string; sectionContext?: string }[] = []; + const headers: string[] = []; + let current: string[] = []; + + const flush = () => { + const text = current.join('\n').trim(); + if (!text) return; + const sectionContext = headers.length > 0 ? headers.join(' > ') : undefined; + // Split into ~200-word chunks + const words = text.split(/\s+/); + for (let i = 0; i < words.length; i += 200) { + const slice = words.slice(i, i + 200).join(' '); + if (slice) { + chunks.push({ content: slice, tag: 'p', ...(sectionContext != null ? { sectionContext } : {}) }); + } + } + current = []; + }; + + for (const line of lines) { + const headerMatch = line.match(/^(#{1,6})\s+(.+)/); + if (headerMatch) { + flush(); + const level = headerMatch[1]!.length; + const text = headerMatch[2]!.trim(); + while (headers.length >= level) headers.pop(); + headers.push(text); + } else { + current.push(line); + } + } + flush(); + + return chunks; +} + +/** Recursively extracts string values from a JSON structure. */ +function extractTexts(data: unknown, depth = 0): string[] { + if (depth > 10) return []; + if (typeof data === 'string') return data.trim() ? [data] : []; + if (Array.isArray(data)) return data.flatMap((item) => extractTexts(item, depth + 1)); + if (typeof data === 'object' && data !== null) { + return Object.values(data).flatMap((v) => extractTexts(v, depth + 1)); + } + return []; +} + +/** Parses YAML frontmatter from a markdown string, extracting the language field if present. */ +function parseFrontmatter(markdown: string): { language?: string } { + const match = markdown.match(/^---\n([\s\S]*?)\n---/); + if (!match) return {}; + const body = match[1] ?? ''; + const langMatch = body.match(/^language:\s*(.+)$/m); + return langMatch ? { language: langMatch[1]!.trim() } : {}; +} diff --git a/packages/mcp-server/src/options.ts b/packages/mcp-server/src/options.ts index b9e8e8a..f151876 100644 --- a/packages/mcp-server/src/options.ts +++ b/packages/mcp-server/src/options.ts @@ -18,10 +18,13 @@ export type McpOptions = { includeCodeTool?: boolean | undefined; includeDocsTools?: boolean | undefined; stainlessApiKey?: string | undefined; + docsSearchMode?: 'stainless-api' | 'local' | undefined; + docsDir?: string | undefined; codeAllowHttpGets?: boolean | undefined; codeAllowedMethods?: string[] | undefined; codeBlockedMethods?: string[] | undefined; codeExecutionMode: McpCodeExecutionMode; + customInstructionsPath?: string | undefined; }; export type McpCodeExecutionMode = 'stainless-sandbox' | 'local'; @@ -52,7 +55,23 @@ export function parseCLIOptions(): CLIOptions { description: "Where to run code execution in code tool; 'stainless-sandbox' will execute code in Stainless-hosted sandboxes whereas 'local' will execute code locally on the MCP server machine.", }) + .option('custom-instructions-path', { + type: 'string', + description: 'Path to custom instructions for the MCP server', + }) .option('debug', { type: 'boolean', description: 'Enable debug logging' }) + .option('docs-dir', { + type: 'string', + description: + 'Path to a directory of local documentation files (markdown/JSON) to include in local docs search.', + }) + .option('docs-search-mode', { + type: 'string', + choices: ['stainless-api', 'local'], + default: 'stainless-api', + description: + "Where to search documentation; 'stainless-api' uses the Stainless-hosted search API whereas 'local' uses an in-memory search index built from embedded SDK method data and optional local docs files.", + }) .option('log-format', { type: 'string', choices: ['json', 'pretty'], @@ -113,10 +132,13 @@ export function parseCLIOptions(): CLIOptions { ...(includeDocsTools !== undefined && { includeDocsTools }), debug: !!argv.debug, stainlessApiKey: argv.stainlessApiKey, + docsSearchMode: argv.docsSearchMode as 'stainless-api' | 'local' | undefined, + docsDir: argv.docsDir, codeAllowHttpGets: argv.codeAllowHttpGets, codeAllowedMethods: argv.codeAllowedMethods, codeBlockedMethods: argv.codeBlockedMethods, codeExecutionMode: argv.codeExecutionMode as McpCodeExecutionMode, + customInstructionsPath: argv.customInstructionsPath, transport, logFormat, port: argv.port, @@ -157,5 +179,7 @@ export function parseQueryOptions(defaultOptions: McpOptions, query: unknown): M ...(codeTool !== undefined && { includeCodeTool: codeTool }), ...(docsTools !== undefined && { includeDocsTools: docsTools }), codeExecutionMode: defaultOptions.codeExecutionMode, + docsSearchMode: defaultOptions.docsSearchMode, + docsDir: defaultOptions.docsDir, }; } diff --git a/packages/mcp-server/src/server.ts b/packages/mcp-server/src/server.ts index cd8f82e..4608117 100644 --- a/packages/mcp-server/src/server.ts +++ b/packages/mcp-server/src/server.ts @@ -11,20 +11,28 @@ import { ClientOptions } from 'hyperspell'; import Hyperspell from 'hyperspell'; import { codeTool } from './code-tool'; import docsSearchTool from './docs-search-tool'; +import { setLocalSearch } from './docs-search-tool'; +import { LocalDocsSearch } from './local-docs-search'; import { getInstructions } from './instructions'; import { McpOptions } from './options'; import { blockedMethodsForCodeTool } from './methods'; import { HandlerFunction, McpRequestContext, ToolCallResult, McpTool } from './types'; import { readEnv } from './util'; -export const newMcpServer = async (stainlessApiKey: string | undefined) => +export const newMcpServer = async ({ + stainlessApiKey, + customInstructionsPath, +}: { + stainlessApiKey?: string | undefined; + customInstructionsPath?: string | undefined; +}) => new McpServer( { name: 'hyperspell_api', - version: '0.35.0', + version: '0.35.1', }, { - instructions: await getInstructions(stainlessApiKey), + instructions: await getInstructions({ stainlessApiKey, customInstructionsPath }), capabilities: { tools: {}, logging: {} }, }, ); @@ -39,6 +47,8 @@ export async function initMcpServer(params: { mcpOptions?: McpOptions; stainlessApiKey?: string | undefined; upstreamClientEnvs?: Record | undefined; + mcpSessionId?: string | undefined; + mcpClientInfo?: { name: string; version: string } | undefined; }) { const server = params.server instanceof McpServer ? params.server.server : params.server; @@ -57,6 +67,12 @@ export async function initMcpServer(params: { error: logAtLevel('error'), }; + if (params.mcpOptions?.docsSearchMode === 'local') { + const docsDir = params.mcpOptions?.docsDir; + const localSearch = await LocalDocsSearch.create(docsDir ? { docsDir } : undefined); + setLocalSearch(localSearch); + } + let _client: Hyperspell | undefined; let _clientError: Error | undefined; let _logLevel: 'debug' | 'info' | 'warn' | 'error' | 'off' | undefined; @@ -122,6 +138,8 @@ export async function initMcpServer(params: { client, stainlessApiKey: params.stainlessApiKey ?? params.mcpOptions?.stainlessApiKey, upstreamClientEnvs: params.upstreamClientEnvs, + mcpSessionId: params.mcpSessionId, + mcpClientInfo: params.mcpClientInfo, }, args, }); diff --git a/packages/mcp-server/src/stdio.ts b/packages/mcp-server/src/stdio.ts index e8bcbb1..b04a544 100644 --- a/packages/mcp-server/src/stdio.ts +++ b/packages/mcp-server/src/stdio.ts @@ -4,7 +4,10 @@ import { initMcpServer, newMcpServer } from './server'; import { getLogger } from './logger'; export const launchStdioServer = async (mcpOptions: McpOptions) => { - const server = await newMcpServer(mcpOptions.stainlessApiKey); + const server = await newMcpServer({ + stainlessApiKey: mcpOptions.stainlessApiKey, + customInstructionsPath: mcpOptions.customInstructionsPath, + }); await initMcpServer({ server, mcpOptions, stainlessApiKey: mcpOptions.stainlessApiKey }); diff --git a/packages/mcp-server/src/types.ts b/packages/mcp-server/src/types.ts index a5710a4..4e969ce 100644 --- a/packages/mcp-server/src/types.ts +++ b/packages/mcp-server/src/types.ts @@ -46,6 +46,8 @@ export type McpRequestContext = { client: Hyperspell; stainlessApiKey?: string | undefined; upstreamClientEnvs?: Record | undefined; + mcpSessionId?: string | undefined; + mcpClientInfo?: { name: string; version: string } | undefined; }; export type HandlerFunction = ({ diff --git a/packages/mcp-server/src/util.ts b/packages/mcp-server/src/util.ts index 40ed550..069a2b4 100644 --- a/packages/mcp-server/src/util.ts +++ b/packages/mcp-server/src/util.ts @@ -2,9 +2,9 @@ export const readEnv = (env: string): string | undefined => { if (typeof (globalThis as any).process !== 'undefined') { - return (globalThis as any).process.env?.[env]?.trim(); + return (globalThis as any).process.env?.[env]?.trim() || undefined; } else if (typeof (globalThis as any).Deno !== 'undefined') { - return (globalThis as any).Deno.env?.get?.(env)?.trim(); + return (globalThis as any).Deno.env?.get?.(env)?.trim() || undefined; } return; }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index afdf120..c7d6aa4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -113,6 +113,9 @@ importers: jq-web: specifier: https://github.com/stainless-api/jq-web/releases/download/v0.8.8/jq-web.tar.gz version: https://github.com/stainless-api/jq-web/releases/download/v0.8.8/jq-web.tar.gz + minisearch: + specifier: ^7.2.0 + version: 7.2.0 pino: specifier: ^10.3.1 version: 10.3.1 @@ -2022,6 +2025,9 @@ packages: minimist@1.2.6: resolution: {integrity: sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==} + minisearch@7.2.0: + resolution: {integrity: sha512-dqT2XBYUOZOiC5t2HRnwADjhNS2cecp9u+TJRiJ1Qp/f5qjkeT5APcGPjHw+bz89Ms8Jp+cG4AlE+QZ/QnDglg==} + mkdirp@2.1.6: resolution: {integrity: sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==} engines: {node: '>=10'} @@ -5123,6 +5129,8 @@ snapshots: minimist@1.2.6: {} + minisearch@7.2.0: {} + mkdirp@2.1.6: {} mri@1.2.0: {} diff --git a/scripts/mock b/scripts/mock index bcf3b39..5cd7c15 100755 --- a/scripts/mock +++ b/scripts/mock @@ -19,34 +19,34 @@ fi echo "==> Starting mock server with URL ${URL}" -# Run prism mock on the given spec +# Run steady mock on the given spec if [ "$1" == "--daemon" ]; then # Pre-install the package so the download doesn't eat into the startup timeout - npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism --version + npm exec --package=@stdy/cli@0.20.2 -- steady --version - npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" &> .prism.log & + npm exec --package=@stdy/cli@0.20.2 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log & - # Wait for server to come online (max 30s) + # Wait for server to come online via health endpoint (max 30s) echo -n "Waiting for server" attempts=0 - while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do + while ! curl --silent --fail "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1; do + if ! kill -0 $! 2>/dev/null; then + echo + cat .stdy.log + exit 1 + fi attempts=$((attempts + 1)) if [ "$attempts" -ge 300 ]; then echo - echo "Timed out waiting for Prism server to start" - cat .prism.log + echo "Timed out waiting for Steady server to start" + cat .stdy.log exit 1 fi echo -n "." sleep 0.1 done - if grep -q "✖ fatal" ".prism.log"; then - cat .prism.log - exit 1 - fi - echo else - npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" + npm exec --package=@stdy/cli@0.20.2 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" fi diff --git a/scripts/test b/scripts/test index 7bce051..a9d718c 100755 --- a/scripts/test +++ b/scripts/test @@ -9,8 +9,8 @@ GREEN='\033[0;32m' YELLOW='\033[0;33m' NC='\033[0m' # No Color -function prism_is_running() { - curl --silent "http://localhost:4010" >/dev/null 2>&1 +function steady_is_running() { + curl --silent "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1 } kill_server_on_port() { @@ -25,7 +25,7 @@ function is_overriding_api_base_url() { [ -n "$TEST_API_BASE_URL" ] } -if ! is_overriding_api_base_url && ! prism_is_running ; then +if ! is_overriding_api_base_url && ! steady_is_running ; then # When we exit this script, make sure to kill the background mock server process trap 'kill_server_on_port 4010' EXIT @@ -36,19 +36,19 @@ fi if is_overriding_api_base_url ; then echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}" echo -elif ! prism_is_running ; then - echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server" +elif ! steady_is_running ; then + echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Steady server" echo -e "running against your OpenAPI spec." echo echo -e "To run the server, pass in the path or url of your OpenAPI" - echo -e "spec to the prism command:" + echo -e "spec to the steady command:" echo - echo -e " \$ ${YELLOW}npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock path/to/your.openapi.yml${NC}" + echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.20.2 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}" echo exit 1 else - echo -e "${GREEN}✔ Mock prism server is running with your OpenAPI spec${NC}" + echo -e "${GREEN}✔ Mock steady server is running with your OpenAPI spec${NC}" echo fi diff --git a/src/internal/utils/env.ts b/src/internal/utils/env.ts index 2d84800..cc5fa0f 100644 --- a/src/internal/utils/env.ts +++ b/src/internal/utils/env.ts @@ -9,10 +9,10 @@ */ export const readEnv = (env: string): string | undefined => { if (typeof (globalThis as any).process !== 'undefined') { - return (globalThis as any).process.env?.[env]?.trim() ?? undefined; + return (globalThis as any).process.env?.[env]?.trim() || undefined; } if (typeof (globalThis as any).Deno !== 'undefined') { - return (globalThis as any).Deno.env?.get?.(env)?.trim(); + return (globalThis as any).Deno.env?.get?.(env)?.trim() || undefined; } return undefined; }; diff --git a/src/resources/actions.ts b/src/resources/actions.ts index 2f48ff9..5098e22 100644 --- a/src/resources/actions.ts +++ b/src/resources/actions.ts @@ -75,7 +75,8 @@ export interface ActionAddReactionParams { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; /** * Message timestamp to react to @@ -105,7 +106,8 @@ export interface ActionSendMessageParams { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; /** * Message text diff --git a/src/resources/auth.ts b/src/resources/auth.ts index 09b75e9..4ec2f96 100644 --- a/src/resources/auth.ts +++ b/src/resources/auth.ts @@ -68,6 +68,7 @@ export interface AuthMeResponse { | 'web_crawler' | 'trace' | 'microsoft_teams' + | 'gmail_actions' >; /** @@ -87,6 +88,7 @@ export interface AuthMeResponse { | 'web_crawler' | 'trace' | 'microsoft_teams' + | 'gmail_actions' >; /** diff --git a/src/resources/connections.ts b/src/resources/connections.ts index 529d755..3fdfa10 100644 --- a/src/resources/connections.ts +++ b/src/resources/connections.ts @@ -59,7 +59,8 @@ export namespace ConnectionListResponse { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; } } diff --git a/src/resources/integrations/integrations.ts b/src/resources/integrations/integrations.ts index 34236d5..4d5f80f 100644 --- a/src/resources/integrations/integrations.ts +++ b/src/resources/integrations/integrations.ts @@ -94,7 +94,13 @@ export namespace IntegrationListResponse { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; + + /** + * Whether this integration only supports write actions (no sync) + */ + actions_only?: boolean; } } diff --git a/src/resources/integrations/web-crawler.ts b/src/resources/integrations/web-crawler.ts index 1b4919b..be1abe0 100644 --- a/src/resources/integrations/web-crawler.ts +++ b/src/resources/integrations/web-crawler.ts @@ -36,7 +36,8 @@ export interface WebCrawlerIndexResponse { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; } diff --git a/src/resources/memories.ts b/src/resources/memories.ts index ca9f6a7..d8eb361 100644 --- a/src/resources/memories.ts +++ b/src/resources/memories.ts @@ -202,7 +202,8 @@ export interface Memory { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; /** * The type of document (e.g. Document, Website, Email) @@ -242,7 +243,8 @@ export interface MemoryStatus { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; status: 'pending' | 'processing' | 'completed' | 'failed' | 'pending_review' | 'skipped'; } @@ -267,7 +269,8 @@ export interface MemoryDeleteResponse { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; success: boolean; } @@ -312,7 +315,8 @@ export interface MemoryUpdateParams { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; /** * @deprecated Body param: The collection to move the document to — deprecated, set @@ -368,6 +372,7 @@ export interface MemoryListParams extends CursorPageParams { | 'web_crawler' | 'trace' | 'microsoft_teams' + | 'gmail_actions' | null; /** @@ -390,7 +395,8 @@ export interface MemoryDeleteParams { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; } export interface MemoryAddParams { @@ -492,7 +498,8 @@ export interface MemoryGetParams { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; } export interface MemorySearchParams { @@ -506,6 +513,12 @@ export interface MemorySearchParams { */ answer?: boolean; + /** + * Effort level. 0 = pass query through verbatim. 1 = LLM rewrites the query for + * better retrieval and extracts date filters. + */ + effort?: number; + /** * @deprecated Maximum number of results to return. */ @@ -533,6 +546,7 @@ export interface MemorySearchParams { | 'web_crawler' | 'trace' | 'microsoft_teams' + | 'gmail_actions' >; } diff --git a/src/resources/shared.ts b/src/resources/shared.ts index 9ebcbd7..6c46945 100644 --- a/src/resources/shared.ts +++ b/src/resources/shared.ts @@ -68,7 +68,8 @@ export interface Resource { | 'vault' | 'web_crawler' | 'trace' - | 'microsoft_teams'; + | 'microsoft_teams' + | 'gmail_actions'; /** * Provider folder ID this resource belongs to diff --git a/src/version.ts b/src/version.ts index 3f1d432..c585ef4 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.35.0'; // x-release-please-version +export const VERSION = '0.35.1'; // x-release-please-version diff --git a/tests/api-resources/memories.test.ts b/tests/api-resources/memories.test.ts index 3e78ca2..a93b4d8 100644 --- a/tests/api-resources/memories.test.ts +++ b/tests/api-resources/memories.test.ts @@ -155,6 +155,7 @@ describe('resource memories', () => { const response = await client.memories.search({ query: 'query', answer: true, + effort: 0, max_results: 0, options: { after: '2019-12-27T18:11:19.117Z',