caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

155 lines
3.4 KiB
Plaintext

---
title: "Get Context"
description: "Retrieve documentation context for a library"
---
# Get Context
Retrieve documentation context for a specific library. Returns documentation as a JSON array of documentation snippets (default) or as plain text.
## Arguments
<ParamField path="query" type="string" required>
The user's question or task (used for relevance ranking)
</ParamField>
<ParamField path="libraryId" type="string" required>
The library identifier (e.g., `/facebook/react`)
</ParamField>
<ParamField path="options" type="GetContextOptions">
<Expandable title="properties">
<ParamField path="type" type="'json' | 'txt'">
Format of the response
- `json`: Array of Documentation objects (default)
- `txt`: Plain text format
Default: `"json"`
</ParamField>
</Expandable>
</ParamField>
## Response
The response type depends on the `type` option.
### JSON Format (`type: "json"` or default)
Returns `Documentation[]` - an array of documentation objects.
### Text Format (`type: "txt"`)
Returns a `string` containing the documentation context ready to use in LLM prompts.
<ResponseField name="Documentation" type="object">
<Expandable title="properties">
<ResponseField name="title" type="string" required>
Title of the documentation snippet
</ResponseField>
<ResponseField name="content" type="string" required>
The documentation content (includes code blocks in markdown format)
</ResponseField>
<ResponseField name="source" type="string" required>
Source identifier for the snippet
</ResponseField>
</Expandable>
</ResponseField>
## Examples
<RequestExample>
```typescript JSON Format (Default)
import { Context7 } from "@upstash/context7-sdk";
const client = new Context7();
const docs = await client.getContext(
"How do I use hooks?",
"/facebook/react"
);
docs.forEach((doc) => {
console.log(doc.title);
console.log(doc.content);
console.log(doc.source);
});
```
```typescript Text Format
import { Context7 } from "@upstash/context7-sdk";
const client = new Context7();
const context = await client.getContext(
"How do I use hooks?",
"/facebook/react",
{ type: "txt" }
);
console.log(context);
```
```typescript Error Handling
import { Context7, Context7Error } from "@upstash/context7-sdk";
const client = new Context7();
try {
const context = await client.getContext(
"How to get started?",
"/invalid/library"
);
} catch (error) {
if (error instanceof Context7Error) {
console.error("API Error:", error.message);
} else {
throw error;
}
}
```
</RequestExample>
## Use Cases
### Providing Context to LLMs
```typescript
import { Context7 } from "@upstash/context7-sdk";
const client = new Context7();
async function getDocsForPrompt(library: string, question: string) {
const context = await client.getContext(question, library);
return `
Here is the relevant documentation:
${context}
User question: ${question}
`;
}
const prompt = await getDocsForPrompt("/facebook/react", "How do I use useEffect?");
```
### Processing Individual Snippets
```typescript
import { Context7 } from "@upstash/context7-sdk";
const client = new Context7();
const docs = await client.getContext(
"How to create components?",
"/facebook/react",
{ type: "json" }
);
docs.forEach((doc) => {
console.log(`Title: ${doc.title}`);
console.log(`Source: ${doc.source}`);
console.log(`Content length: ${doc.content.length} chars`);
});
```