@sanity/cli 8.26.0 → 8.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1534 -411
- package/dist/actions/context/commandTable.js +215 -0
- package/dist/actions/context/commandTable.js.map +1 -0
- package/dist/actions/context/contextCommand.js +246 -0
- package/dist/actions/context/contextCommand.js.map +1 -0
- package/dist/actions/context/contextSpec.js +18 -0
- package/dist/actions/context/contextSpec.js.map +1 -0
- package/dist/actions/context/distillContextOperations.js +335 -0
- package/dist/actions/context/distillContextOperations.js.map +1 -0
- package/dist/actions/context/mcpEndpoint.js +165 -0
- package/dist/actions/context/mcpEndpoint.js.map +1 -0
- package/dist/actions/context/operationInput.js +226 -0
- package/dist/actions/context/operationInput.js.map +1 -0
- package/dist/actions/context/operationTypes.js +3 -0
- package/dist/actions/context/operationTypes.js.map +1 -0
- package/dist/actions/context/removedCommands.js +26 -0
- package/dist/actions/context/removedCommands.js.map +1 -0
- package/dist/actions/context/renderOperationResult.js +72 -0
- package/dist/actions/context/renderOperationResult.js.map +1 -0
- package/dist/actions/context/resolveOrganizationId.js +8 -1
- package/dist/actions/context/resolveOrganizationId.js.map +1 -1
- package/dist/actions/context/sourceFile.js +31 -0
- package/dist/actions/context/sourceFile.js.map +1 -0
- package/dist/actions/context/syncOutput.js +17 -0
- package/dist/actions/context/syncOutput.js.map +1 -0
- package/dist/actions/context/table.js +13 -0
- package/dist/actions/context/table.js.map +1 -0
- package/dist/actions/context/waitForJob.js.map +1 -1
- package/dist/actions/context/waitForSourceSync.js +48 -0
- package/dist/actions/context/waitForSourceSync.js.map +1 -0
- package/dist/actions/context/watchJob.js.map +1 -1
- package/dist/actions/context/watchSourceSync.js +40 -0
- package/dist/actions/context/watchSourceSync.js.map +1 -0
- package/dist/commands/context/build.js +19 -81
- package/dist/commands/context/build.js.map +1 -1
- package/dist/commands/context/create.js +3 -104
- package/dist/commands/context/create.js.map +1 -1
- package/dist/commands/context/delete.js +3 -73
- package/dist/commands/context/delete.js.map +1 -1
- package/dist/commands/context/documents/content.js +117 -0
- package/dist/commands/context/documents/content.js.map +1 -0
- package/dist/commands/context/documents/delete.js +5 -0
- package/dist/commands/context/documents/delete.js.map +1 -0
- package/dist/commands/context/documents/edit.js +5 -0
- package/dist/commands/context/documents/edit.js.map +1 -0
- package/dist/commands/context/documents/get.js +5 -0
- package/dist/commands/context/documents/get.js.map +1 -0
- package/dist/commands/context/documents/list.js +5 -0
- package/dist/commands/context/documents/list.js.map +1 -0
- package/dist/commands/context/entries/list.js +2 -2
- package/dist/commands/context/entries/list.js.map +1 -1
- package/dist/commands/context/entries/rebuild.js +3 -93
- package/dist/commands/context/entries/rebuild.js.map +1 -1
- package/dist/commands/context/get.js +3 -88
- package/dist/commands/context/get.js.map +1 -1
- package/dist/commands/context/instructions/create.js +5 -0
- package/dist/commands/context/instructions/create.js.map +1 -0
- package/dist/commands/context/instructions/delete.js +5 -0
- package/dist/commands/context/instructions/delete.js.map +1 -0
- package/dist/commands/context/instructions/edit.js +5 -0
- package/dist/commands/context/instructions/edit.js.map +1 -0
- package/dist/commands/context/issues/apply.js +3 -84
- package/dist/commands/context/issues/apply.js.map +1 -1
- package/dist/commands/context/issues/dismiss.js +3 -50
- package/dist/commands/context/issues/dismiss.js.map +1 -1
- package/dist/commands/context/issues/list.js +0 -5
- package/dist/commands/context/issues/list.js.map +1 -1
- package/dist/commands/context/issues/reopen.js +3 -51
- package/dist/commands/context/issues/reopen.js.map +1 -1
- package/dist/commands/context/issues/resolve.js +23 -92
- package/dist/commands/context/issues/resolve.js.map +1 -1
- package/dist/commands/context/jobs/get.js +3 -88
- package/dist/commands/context/jobs/get.js.map +1 -1
- package/dist/commands/context/list.js +3 -103
- package/dist/commands/context/list.js.map +1 -1
- package/dist/commands/context/mcp/create.js +152 -0
- package/dist/commands/context/mcp/create.js.map +1 -0
- package/dist/commands/context/mcp/delete.js +82 -0
- package/dist/commands/context/mcp/delete.js.map +1 -0
- package/dist/commands/context/mcp/get.js +42 -0
- package/dist/commands/context/mcp/get.js.map +1 -0
- package/dist/commands/context/mcp/initial-context.js +5 -0
- package/dist/commands/context/mcp/initial-context.js.map +1 -0
- package/dist/commands/context/mcp/list.js +87 -0
- package/dist/commands/context/mcp/list.js.map +1 -0
- package/dist/commands/context/mcp/status.js +98 -0
- package/dist/commands/context/mcp/status.js.map +1 -0
- package/dist/commands/context/mcp/update.js +225 -0
- package/dist/commands/context/mcp/update.js.map +1 -0
- package/dist/commands/context/query.js +6 -14
- package/dist/commands/context/query.js.map +1 -1
- package/dist/commands/context/sources/create.js +175 -0
- package/dist/commands/context/sources/create.js.map +1 -0
- package/dist/commands/context/sources/delete.js +5 -0
- package/dist/commands/context/sources/delete.js.map +1 -0
- package/dist/commands/context/sources/edit.js +29 -0
- package/dist/commands/context/sources/edit.js.map +1 -0
- package/dist/commands/context/sources/get.js +5 -0
- package/dist/commands/context/sources/get.js.map +1 -0
- package/dist/commands/context/sources/list.js +5 -0
- package/dist/commands/context/sources/list.js.map +1 -0
- package/dist/commands/context/sources/sync.js +5 -0
- package/dist/commands/context/sources/sync.js.map +1 -0
- package/dist/commands/context/sources/syncs/confirm.js +5 -0
- package/dist/commands/context/sources/syncs/confirm.js.map +1 -0
- package/dist/commands/context/sources/syncs/discard.js +5 -0
- package/dist/commands/context/sources/syncs/discard.js.map +1 -0
- package/dist/commands/context/sources/syncs/get.js +5 -0
- package/dist/commands/context/sources/syncs/get.js.map +1 -0
- package/dist/commands/context/sources/syncs/list.js +5 -0
- package/dist/commands/context/sources/syncs/list.js.map +1 -0
- package/dist/commands/context/sources/upload.js +63 -0
- package/dist/commands/context/sources/upload.js.map +1 -0
- package/dist/commands/context/sync.js +5 -0
- package/dist/commands/context/sync.js.map +1 -0
- package/dist/commands/context/update.js +3 -136
- package/dist/commands/context/update.js.map +1 -1
- package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js +47 -26
- package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js.map +1 -1
- package/dist/generated/apiRoutes.js +28 -0
- package/dist/generated/apiRoutes.js.map +1 -1
- package/dist/generated/contextOperations.js +1116 -0
- package/dist/generated/contextOperations.js.map +1 -0
- package/dist/hooks/commandNotFound/topicAliases.js +8 -2
- package/dist/hooks/commandNotFound/topicAliases.js.map +1 -1
- package/dist/prompts/promptForText.js +12 -0
- package/dist/prompts/promptForText.js.map +1 -0
- package/dist/services/context.js +276 -202
- package/dist/services/context.js.map +1 -1
- package/dist/util/sharedFlags.js.map +1 -1
- package/dist/util/telemetry/cliCommandIdentity.js +16 -18
- package/dist/util/telemetry/cliCommandIdentity.js.map +1 -1
- package/oclif.config.js +1 -1
- package/oclif.manifest.json +4854 -2834
- package/package.json +20 -19
- package/templates/app-quickstart/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
- package/templates/app-quickstart/AGENTS.md +49 -0
- package/templates/app-sanity-ui/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
- package/templates/app-sanity-ui/AGENTS.md +49 -0
- package/templates/shared/dashboard/app-quickstart/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
- package/templates/shared/dashboard/app-quickstart/AGENTS.md +49 -0
- package/templates/shared/dashboard/app-sanity-ui/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
- package/templates/shared/dashboard/app-sanity-ui/AGENTS.md +49 -0
- package/dist/commands/context/imports/create.js +0 -270
- package/dist/commands/context/imports/create.js.map +0 -1
- package/dist/commands/context/imports/delete.js +0 -73
- package/dist/commands/context/imports/delete.js.map +0 -1
- package/dist/commands/context/imports/download.js +0 -60
- package/dist/commands/context/imports/download.js.map +0 -1
- package/dist/commands/context/imports/get.js +0 -88
- package/dist/commands/context/imports/get.js.map +0 -1
- package/dist/commands/context/imports/list.js +0 -100
- package/dist/commands/context/imports/list.js.map +0 -1
- package/dist/commands/context/refresh.js +0 -46
- package/dist/commands/context/refresh.js.map +0 -1
package/dist/services/context.js
CHANGED
|
@@ -3,22 +3,19 @@ import { EXPERIMENTAL_API_WARNING, isHttpError } from '@sanity/client';
|
|
|
3
3
|
const CONTEXT_API_VERSION = 'v2026-08-25';
|
|
4
4
|
const BLUEPRINTS_API_VERSION = 'vX';
|
|
5
5
|
const BLUEPRINTS_LOOKUP_TIMEOUT_MS = 5000;
|
|
6
|
+
// The version in the URLs the Context API returns for agents to connect to MCP endpoints
|
|
7
|
+
const MCP_CONNECT_API_VERSION = 'v2026-11-03';
|
|
8
|
+
// Documents per page while a GROQ list read drains the store
|
|
9
|
+
const STORE_PAGE_SIZE = 200;
|
|
10
|
+
const MCP_LIST_LIMIT = 500;
|
|
6
11
|
const blueprintOwnershipDebug = subdebug('context:blueprint-ownership');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* GROQ-backed reads also need `context.organizationId`.
|
|
12
|
-
*/ async function getContextClient(knowledgeBaseId, organizationId) {
|
|
12
|
+
function isPage(value) {
|
|
13
|
+
return typeof value === 'object' && value !== null && 'data' in value && Array.isArray(value.data) && 'nextCursor' in value;
|
|
14
|
+
}
|
|
15
|
+
async function getContextClient(organizationId) {
|
|
13
16
|
return getGlobalCliClient({
|
|
14
17
|
apiVersion: CONTEXT_API_VERSION,
|
|
15
18
|
requireUser: true,
|
|
16
|
-
...knowledgeBaseId === undefined ? {} : {
|
|
17
|
-
resource: {
|
|
18
|
-
id: knowledgeBaseId,
|
|
19
|
-
type: 'knowledge-base'
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
19
|
...organizationId === undefined ? {} : {
|
|
23
20
|
context: {
|
|
24
21
|
organizationId
|
|
@@ -27,54 +24,288 @@ const blueprintOwnershipDebug = subdebug('context:blueprint-ownership');
|
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
26
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*/ async function
|
|
34
|
-
const { organizationId, publicId } = await getKnowledgeBase(knowledgeBaseId);
|
|
35
|
-
return getContextClient(publicId, organizationId);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Create a knowledge base in an organization
|
|
39
|
-
*/ export async function createKnowledgeBase(params) {
|
|
27
|
+
* Call a Context API operation by its route. Commands build requests at
|
|
28
|
+
* runtime from the spec, so this is the one place the route-typed client call
|
|
29
|
+
* is loosened to a runtime route and request.
|
|
30
|
+
*/ export async function requestContext(route, request = {}) {
|
|
40
31
|
const client = await getContextClient();
|
|
41
|
-
|
|
32
|
+
const call = client.context.request;
|
|
33
|
+
return call.call(client.context, route, request);
|
|
42
34
|
}
|
|
43
35
|
/**
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
* Call a paginated list operation and drain its pages into one list, asking
|
|
37
|
+
* for `pageSize` items a page. A `limit` in the query caps the total instead of
|
|
38
|
+
* one page, so the list stops once it has that many.
|
|
39
|
+
*/ export async function requestAllPages(route, request = {}, pageSize) {
|
|
40
|
+
const { limit, ...query } = request.query ?? {};
|
|
41
|
+
const total = limit === undefined ? undefined : Number(limit);
|
|
42
|
+
const items = [];
|
|
48
43
|
let cursor;
|
|
49
44
|
do {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
const remaining = total === undefined ? undefined : total - items.length;
|
|
46
|
+
const size = remaining === undefined ? pageSize : Math.min(pageSize ?? remaining, remaining);
|
|
47
|
+
const page = await requestContext(route, {
|
|
48
|
+
...request,
|
|
49
|
+
query: {
|
|
50
|
+
...query,
|
|
51
|
+
...size !== undefined && {
|
|
52
|
+
limit: String(size)
|
|
53
|
+
},
|
|
54
|
+
...cursor && {
|
|
55
|
+
cursor
|
|
56
|
+
}
|
|
57
|
+
}
|
|
53
58
|
});
|
|
54
|
-
|
|
59
|
+
if (!isPage(page)) throw new Error(`${route} answered with something other than a page`);
|
|
60
|
+
items.push(...page.data);
|
|
55
61
|
cursor = page.nextCursor ?? undefined;
|
|
56
|
-
}while (cursor !== undefined)
|
|
57
|
-
return
|
|
62
|
+
}while (cursor !== undefined && (total === undefined || items.length < total))
|
|
63
|
+
return total === undefined ? items : items.slice(0, total);
|
|
64
|
+
}
|
|
65
|
+
/** A document's content as the bytes its source gave (`format: 'raw'`) */ export async function getDocumentBytes(request) {
|
|
66
|
+
const client = await getContextClient();
|
|
67
|
+
const call = client.context.requestBytes;
|
|
68
|
+
return call.call(client.context, 'GET /knowledge-bases/{knowledgeBaseId}/documents/{documentId}/content', request);
|
|
69
|
+
}
|
|
70
|
+
/** Get a knowledge base */ async function getKnowledgeBase(knowledgeBaseId) {
|
|
71
|
+
const client = await getContextClient();
|
|
72
|
+
return client.context.request('GET /knowledge-bases/{knowledgeBaseId}', {
|
|
73
|
+
params: {
|
|
74
|
+
knowledgeBaseId
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** Get a source, with its latest sync */ export async function getSource(knowledgeBaseId, sourceId) {
|
|
79
|
+
const client = await getContextClient();
|
|
80
|
+
return client.context.request('GET /knowledge-bases/{knowledgeBaseId}/sources/{sourceId}', {
|
|
81
|
+
params: {
|
|
82
|
+
knowledgeBaseId,
|
|
83
|
+
sourceId
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/** Get a sync of a source by ID */ export async function getSync(knowledgeBaseId, sourceId, syncId) {
|
|
88
|
+
const client = await getContextClient();
|
|
89
|
+
return client.context.request('GET /knowledge-bases/{knowledgeBaseId}/sources/{sourceId}/syncs/{syncId}', {
|
|
90
|
+
params: {
|
|
91
|
+
knowledgeBaseId,
|
|
92
|
+
sourceId,
|
|
93
|
+
syncId
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** Get a job by ID */ export async function getJob(knowledgeBaseId, jobId) {
|
|
98
|
+
const client = await getContextClient();
|
|
99
|
+
return client.context.request('GET /knowledge-bases/{knowledgeBaseId}/jobs/{jobId}', {
|
|
100
|
+
params: {
|
|
101
|
+
jobId,
|
|
102
|
+
knowledgeBaseId
|
|
103
|
+
}
|
|
104
|
+
});
|
|
58
105
|
}
|
|
59
106
|
/**
|
|
60
|
-
*
|
|
61
|
-
|
|
107
|
+
* Add a `files` source holding a local file: add the source, upload the file
|
|
108
|
+
* and sync it. Resolves with the source as created and the sync's `jobId`.
|
|
109
|
+
*/ export async function createFileSource(knowledgeBaseId, params) {
|
|
62
110
|
const client = await getContextClient();
|
|
63
|
-
return client.context.
|
|
111
|
+
return client.context.createFileSource({
|
|
112
|
+
...params,
|
|
113
|
+
knowledgeBaseId
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** Upload a file to a `files` source, replacing the file it holds, and sync it */ export async function uploadSourceFile(knowledgeBaseId, sourceId, upload) {
|
|
117
|
+
const client = await getContextClient();
|
|
118
|
+
return client.context.uploadFile({
|
|
119
|
+
...upload,
|
|
120
|
+
knowledgeBaseId,
|
|
121
|
+
sourceId
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/** Run a GROQ query against an organization's Context documents */ export async function queryContext(organizationId, query, params) {
|
|
125
|
+
const client = await getContextClient(organizationId);
|
|
126
|
+
return client.context.fetch(query, params);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* GROQ reads of a knowledge base's documents query the organization's document
|
|
130
|
+
* store, where documents are keyed by the knowledge base's public ID. Fetching
|
|
131
|
+
* the knowledge base resolves both, whichever of its IDs was passed.
|
|
132
|
+
*/ async function getStoreScope(knowledgeBaseId) {
|
|
133
|
+
const { organizationId, publicId } = await getKnowledgeBase(knowledgeBaseId);
|
|
134
|
+
return {
|
|
135
|
+
client: await getContextClient(organizationId),
|
|
136
|
+
kb: publicId
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Drain a `(_createdAt, _id)`-keyset GROQ read */ async function drainByCreatedAt(organizationId, filter, params) {
|
|
140
|
+
const client = await getContextClient(organizationId);
|
|
141
|
+
const all = [];
|
|
142
|
+
let cursor;
|
|
143
|
+
for(;;){
|
|
144
|
+
const paged = cursor ? `${filter} && (_createdAt > $c || (_createdAt == $c && _id > $i))` : filter;
|
|
145
|
+
const page = await client.context.fetch(`*[${paged}] | order(_createdAt asc, _id asc) [0...${STORE_PAGE_SIZE}]`, {
|
|
146
|
+
...params,
|
|
147
|
+
...cursor
|
|
148
|
+
});
|
|
149
|
+
all.push(...page);
|
|
150
|
+
if (page.length < STORE_PAGE_SIZE) return all;
|
|
151
|
+
const last = page.at(-1);
|
|
152
|
+
cursor = {
|
|
153
|
+
c: last._createdAt,
|
|
154
|
+
i: last._id
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** List all entries of a knowledge base, path-ordered, without bodies */ export async function listEntries(knowledgeBaseId) {
|
|
159
|
+
const { client, kb } = await getStoreScope(knowledgeBaseId);
|
|
160
|
+
const all = [];
|
|
161
|
+
let after = '';
|
|
162
|
+
for(;;){
|
|
163
|
+
const page = await client.context.fetch(`*[_type == "sanity.context.entry" && knowledgeBaseId == $kb && path > $after] | order(path asc) [0...${STORE_PAGE_SIZE}] {_id, path, title, tldr, status}`, {
|
|
164
|
+
after,
|
|
165
|
+
kb
|
|
166
|
+
});
|
|
167
|
+
all.push(...page);
|
|
168
|
+
if (page.length < STORE_PAGE_SIZE) return all;
|
|
169
|
+
after = page.at(-1).path;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** Get an entry with its body and citations by outline path, or `null` when no entry sits there */ export async function getEntry(knowledgeBaseId, path) {
|
|
173
|
+
const { client, kb } = await getStoreScope(knowledgeBaseId);
|
|
174
|
+
return client.context.fetch('*[_type == "sanity.context.entry" && knowledgeBaseId == $kb && path == $path][0]', {
|
|
175
|
+
kb,
|
|
176
|
+
path
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/** List all issues of a knowledge base, optionally only those in one status */ export async function listIssues(knowledgeBaseId, status) {
|
|
180
|
+
const { organizationId, publicId } = await getKnowledgeBase(knowledgeBaseId);
|
|
181
|
+
const filter = `_type == "sanity.context.issue" && knowledgeBaseId == $kb${status === undefined ? '' : ' && status == $status'}`;
|
|
182
|
+
return drainByCreatedAt(organizationId, filter, {
|
|
183
|
+
kb: publicId,
|
|
184
|
+
...status !== undefined && {
|
|
185
|
+
status
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/** Get an issue by ID, or `null` when it doesn't exist */ export async function getIssue(knowledgeBaseId, issueId) {
|
|
190
|
+
const { client, kb } = await getStoreScope(knowledgeBaseId);
|
|
191
|
+
return client.context.fetch('*[_type == "sanity.context.issue" && knowledgeBaseId == $kb && _id == $id][0]', {
|
|
192
|
+
id: issueId,
|
|
193
|
+
kb
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/** List an organization's MCP endpoints, oldest first */ export async function listMcpEndpoints(organizationId) {
|
|
197
|
+
const client = await getContextClient(organizationId);
|
|
198
|
+
const docs = await client.context.fetch(`*[_type == "sanity.context.mcp" && organizationId == $org] | order(_createdAt asc, _id asc) [0...${MCP_LIST_LIMIT}]`, {
|
|
199
|
+
org: organizationId
|
|
200
|
+
});
|
|
201
|
+
const connectClient = client.withConfig({
|
|
202
|
+
apiVersion: MCP_CONNECT_API_VERSION
|
|
203
|
+
});
|
|
204
|
+
return docs.map((doc)=>toMcpEndpoint(connectClient, doc));
|
|
64
205
|
}
|
|
65
206
|
/**
|
|
66
|
-
*
|
|
67
|
-
|
|
207
|
+
* Get an MCP endpoint by name or ID, or `null` when the organization has none.
|
|
208
|
+
* Update and delete accept either, so the lookups guarding them must too.
|
|
209
|
+
*/ export async function getMcpEndpoint(organizationId, nameOrId) {
|
|
210
|
+
const client = await getContextClient(organizationId);
|
|
211
|
+
const doc = await client.context.fetch('*[_type == "sanity.context.mcp" && organizationId == $org && (name == $nameOrId || publicId == $nameOrId)][0]', {
|
|
212
|
+
nameOrId,
|
|
213
|
+
org: organizationId
|
|
214
|
+
});
|
|
215
|
+
return doc && toMcpEndpoint(client.withConfig({
|
|
216
|
+
apiVersion: MCP_CONNECT_API_VERSION
|
|
217
|
+
}), doc);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The stored configuration in the shape create and edit return, so every command outputs the
|
|
221
|
+
* same fields. The URL isn't stored, so it is built from the same route and API version.
|
|
222
|
+
*/ function toMcpEndpoint(connectClient, doc) {
|
|
223
|
+
return {
|
|
224
|
+
createdAt: doc._createdAt,
|
|
225
|
+
groqFilter: doc.groqFilter ?? null,
|
|
226
|
+
id: doc.publicId,
|
|
227
|
+
instructions: doc.instructions ?? null,
|
|
228
|
+
lastUsedAt: doc.lastUsedAt ?? null,
|
|
229
|
+
name: doc.name,
|
|
230
|
+
organizationId: doc.organizationId,
|
|
231
|
+
sources: doc.sources,
|
|
232
|
+
title: doc.title,
|
|
233
|
+
updatedAt: doc._updatedAt,
|
|
234
|
+
url: connectClient.getUrl(`/context/organizations/${encodeURIComponent(doc.organizationId)}/mcp/${encodeURIComponent(doc.name)}`)
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/** Create an MCP endpoint */ export async function createMcpEndpoint(organizationId, body) {
|
|
238
|
+
const client = await getContextClient();
|
|
239
|
+
return client.context.request('POST /organizations/{organizationId}/mcp', {
|
|
240
|
+
body,
|
|
241
|
+
params: {
|
|
242
|
+
organizationId
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/** Update an MCP endpoint's configuration */ export async function updateMcpEndpoint(organizationId, name, body) {
|
|
247
|
+
const client = await getContextClient();
|
|
248
|
+
return client.context.request('PATCH /organizations/{organizationId}/mcp/{mcpEndpoint}', {
|
|
249
|
+
body,
|
|
250
|
+
params: {
|
|
251
|
+
mcpEndpoint: name,
|
|
252
|
+
organizationId
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/** Delete an MCP endpoint */ export async function deleteMcpEndpoint(organizationId, name) {
|
|
257
|
+
const client = await getContextClient();
|
|
258
|
+
await client.context.request('DELETE /organizations/{organizationId}/mcp/{mcpEndpoint}', {
|
|
259
|
+
params: {
|
|
260
|
+
mcpEndpoint: name,
|
|
261
|
+
organizationId
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/** Check whether an agent connecting with the current credentials can use an MCP endpoint */ export async function getMcpEndpointStatus(organizationId, name) {
|
|
68
266
|
const client = await getContextClient();
|
|
69
|
-
return client.context.
|
|
267
|
+
return client.context.request('GET /organizations/{organizationId}/mcp/{mcpEndpoint}/status', {
|
|
268
|
+
params: {
|
|
269
|
+
mcpEndpoint: name,
|
|
270
|
+
organizationId
|
|
271
|
+
}
|
|
272
|
+
});
|
|
70
273
|
}
|
|
71
274
|
/**
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
275
|
+
* Who manages a resource, for refusal messages: the stack by name when the caller can read it
|
|
276
|
+
*/ export function describeBlueprintManager(stackName) {
|
|
277
|
+
return stackName ? `The blueprint stack "${stackName}"` : 'A blueprint';
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Whether a live blueprint stack manages the knowledge base
|
|
281
|
+
*/ export function getKnowledgeBaseBlueprintOwnership(knowledgeBaseId) {
|
|
282
|
+
return getBlueprintOwnership('sanity.context.knowledge-base', async ()=>{
|
|
77
283
|
const { organizationId, publicId } = await getKnowledgeBase(knowledgeBaseId);
|
|
284
|
+
return {
|
|
285
|
+
organizationId,
|
|
286
|
+
publicId
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Whether a live blueprint stack manages the MCP endpoint
|
|
292
|
+
*/ export function getMcpEndpointBlueprintOwnership(organizationId, { id }) {
|
|
293
|
+
return getBlueprintOwnership('sanity.context.mcp', async ()=>({
|
|
294
|
+
organizationId,
|
|
295
|
+
publicId: id
|
|
296
|
+
}));
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Looks the resource up in the Blueprints resource search. Fails open: a
|
|
300
|
+
* failed lookup answers not managed, so a Blueprints outage never blocks a
|
|
301
|
+
* command. A resource that doesn't exist isn't managed either.
|
|
302
|
+
*/ async function getBlueprintOwnership(type, resolveResource) {
|
|
303
|
+
try {
|
|
304
|
+
const resource = await resolveResource();
|
|
305
|
+
if (!resource) return {
|
|
306
|
+
managed: false
|
|
307
|
+
};
|
|
308
|
+
const { organizationId, publicId } = resource;
|
|
78
309
|
const client = await getGlobalCliClient({
|
|
79
310
|
apiVersion: BLUEPRINTS_API_VERSION,
|
|
80
311
|
// The Blueprints API has no stable version yet, and the warning would interrupt command output.
|
|
@@ -96,7 +327,7 @@ const blueprintOwnershipDebug = subdebug('context:blueprint-ownership');
|
|
|
96
327
|
headers,
|
|
97
328
|
query: {
|
|
98
329
|
id: publicId,
|
|
99
|
-
type
|
|
330
|
+
type
|
|
100
331
|
},
|
|
101
332
|
url: '/blueprints/resources/search'
|
|
102
333
|
});
|
|
@@ -136,162 +367,5 @@ function errorCode(error) {
|
|
|
136
367
|
const { body } = error.response;
|
|
137
368
|
return body && typeof body === 'object' && 'errorCode' in body ? body.errorCode : undefined;
|
|
138
369
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Delete a knowledge base and its generated content
|
|
141
|
-
*/ export async function deleteKnowledgeBase(knowledgeBaseId) {
|
|
142
|
-
const client = await getContextClient();
|
|
143
|
-
await client.context.knowledgeBases.delete(knowledgeBaseId);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Import content into a knowledge base. File imports are staged and uploaded
|
|
147
|
-
* to signed storage by the client.
|
|
148
|
-
*/ export async function createImport(knowledgeBaseId, params) {
|
|
149
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
150
|
-
return client.context.imports.create(params);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* List all imports for a knowledge base (drains pagination)
|
|
154
|
-
*/ export async function listImports(knowledgeBaseId) {
|
|
155
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
156
|
-
const imports = [];
|
|
157
|
-
let cursor;
|
|
158
|
-
do {
|
|
159
|
-
const page = await client.context.imports.list({
|
|
160
|
-
cursor
|
|
161
|
-
});
|
|
162
|
-
imports.push(...page.data);
|
|
163
|
-
cursor = page.nextCursor ?? undefined;
|
|
164
|
-
}while (cursor !== undefined)
|
|
165
|
-
return imports;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Get a single import by ID
|
|
169
|
-
*/ export async function getImport(knowledgeBaseId, importId) {
|
|
170
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
171
|
-
return client.context.imports.get({
|
|
172
|
-
importId
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Get a short-lived signed URL for an import's original uploaded bytes
|
|
177
|
-
*/ export async function downloadImport(knowledgeBaseId, importId) {
|
|
178
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
179
|
-
return client.context.imports.download({
|
|
180
|
-
importId
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Delete an import from a knowledge base
|
|
185
|
-
*/ export async function deleteImport(knowledgeBaseId, importId) {
|
|
186
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
187
|
-
await client.context.imports.delete({
|
|
188
|
-
importId
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Start a build of a knowledge base
|
|
193
|
-
*/ export async function buildKnowledgeBase(knowledgeBaseId) {
|
|
194
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
195
|
-
return client.context.build();
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Cancel the running build of a knowledge base, if any
|
|
199
|
-
*/ export async function cancelKnowledgeBaseBuild(knowledgeBaseId) {
|
|
200
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
201
|
-
return client.context.cancelBuild();
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Run an incremental refresh: re-check sources and apply what changed
|
|
205
|
-
*/ export async function refreshKnowledgeBase(knowledgeBaseId) {
|
|
206
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
207
|
-
return client.context.refresh();
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Get an async job (build, import) by ID
|
|
211
|
-
*/ export async function getJob(knowledgeBaseId, jobId) {
|
|
212
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
213
|
-
return client.context.jobs.get({
|
|
214
|
-
jobId
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* List all issues for a knowledge base, optionally narrowed to one status
|
|
219
|
-
*/ export async function listIssues(knowledgeBaseId, status) {
|
|
220
|
-
const client = await getContextStoreClient(knowledgeBaseId);
|
|
221
|
-
return client.context.issues.list({
|
|
222
|
-
status
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Get a single issue by ID, or `null` when it does not exist
|
|
227
|
-
*/ export async function getIssue(knowledgeBaseId, issueId) {
|
|
228
|
-
const client = await getContextStoreClient(knowledgeBaseId);
|
|
229
|
-
return client.context.issues.get({
|
|
230
|
-
issueId
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Resolve a conflict issue by choosing one of its sides (by index). Choosing
|
|
235
|
-
* a side other than the entry's current content starts a rewrite job.
|
|
236
|
-
*/ export async function resolveIssue(knowledgeBaseId, issueId, resolution) {
|
|
237
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
238
|
-
return client.context.issues.resolve({
|
|
239
|
-
issueId,
|
|
240
|
-
resolution
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Dismiss an issue
|
|
245
|
-
*/ export async function dismissIssue(knowledgeBaseId, issueId) {
|
|
246
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
247
|
-
return client.context.issues.dismiss({
|
|
248
|
-
issueId
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Reopen a resolved conflict issue
|
|
253
|
-
*/ export async function reopenIssue(knowledgeBaseId, issueId) {
|
|
254
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
255
|
-
return client.context.issues.reopen({
|
|
256
|
-
issueId
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Apply accepted issues to a knowledge base in one batch
|
|
261
|
-
*/ export async function applyIssues(knowledgeBaseId, issueIds) {
|
|
262
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
263
|
-
return client.context.issues.apply({
|
|
264
|
-
issueIds
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* List all entries for a knowledge base, path-ordered, without bodies
|
|
269
|
-
*/ export async function listEntries(knowledgeBaseId) {
|
|
270
|
-
const client = await getContextStoreClient(knowledgeBaseId);
|
|
271
|
-
return client.context.entries.list();
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Get a single entry with its body and citations by outline path, or `null`
|
|
275
|
-
* when no entry sits at that path
|
|
276
|
-
*/ export async function getEntry(knowledgeBaseId, path) {
|
|
277
|
-
const client = await getContextStoreClient(knowledgeBaseId);
|
|
278
|
-
return client.context.entries.get({
|
|
279
|
-
path
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Rebuild one entry from its sources by outline path
|
|
284
|
-
*/ export async function rebuildEntry(knowledgeBaseId, path) {
|
|
285
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
286
|
-
return client.context.entries.rebuild({
|
|
287
|
-
path
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Run a GROQ query against an organization's Context documents
|
|
292
|
-
*/ export async function queryContext(organizationId, query, params) {
|
|
293
|
-
const client = await getContextClient(undefined, organizationId);
|
|
294
|
-
return client.context.fetch(query, params);
|
|
295
|
-
}
|
|
296
370
|
|
|
297
371
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/context.ts"],"sourcesContent":["import {getGlobalCliClient, subdebug} from '@sanity/cli-core'\nimport {type Context, EXPERIMENTAL_API_WARNING, isHttpError} from '@sanity/client'\n\nconst CONTEXT_API_VERSION = 'v2026-08-25'\nconst BLUEPRINTS_API_VERSION = 'vX'\nconst BLUEPRINTS_LOOKUP_TIMEOUT_MS = 5000\n\nconst blueprintOwnershipDebug = subdebug('context:blueprint-ownership')\n\n/**\n * Knowledge-base-scoped methods on `client.context` operate on the client's\n * configured `resource`; collection-level methods\n * (`client.context.knowledgeBases.*`) are addressed per call and need none.\n * GROQ-backed reads also need `context.organizationId`.\n */\nasync function getContextClient(knowledgeBaseId?: string, organizationId?: string) {\n return getGlobalCliClient({\n apiVersion: CONTEXT_API_VERSION,\n requireUser: true,\n ...(knowledgeBaseId === undefined\n ? {}\n : {resource: {id: knowledgeBaseId, type: 'knowledge-base' as const}}),\n ...(organizationId === undefined ? {} : {context: {organizationId}}),\n })\n}\n\n/**\n * GROQ-backed reads (issues, entries) query the organization's\n * document store, where documents are keyed by the knowledge base's public ID.\n * Fetching the knowledge base resolves both, whichever of its IDs was passed.\n */\nasync function getContextStoreClient(knowledgeBaseId: string) {\n const {organizationId, publicId} = await getKnowledgeBase(knowledgeBaseId)\n return getContextClient(publicId, organizationId)\n}\n\n/**\n * Create a knowledge base in an organization\n */\nexport async function createKnowledgeBase(\n params: Context.CreateKnowledgeBaseParams,\n): Promise<Context.KnowledgeBase> {\n const client = await getContextClient()\n return client.context.knowledgeBases.create(params)\n}\n\n/**\n * List all knowledge bases in an organization (drains pagination)\n */\nexport async function listKnowledgeBases(organizationId: string): Promise<Context.KnowledgeBase[]> {\n const client = await getContextClient()\n\n const knowledgeBases: Context.KnowledgeBase[] = []\n let cursor: string | undefined\n do {\n const page = await client.context.knowledgeBases.list({\n cursor,\n organizationId,\n })\n knowledgeBases.push(...page.data)\n cursor = page.nextCursor ?? undefined\n } while (cursor !== undefined)\n\n return knowledgeBases\n}\n\n/**\n * Get a single knowledge base by ID\n */\nexport async function getKnowledgeBase(knowledgeBaseId: string): Promise<Context.KnowledgeBase> {\n const client = await getContextClient()\n return client.context.knowledgeBases.get(knowledgeBaseId)\n}\n\n/**\n * Update a knowledge base's configuration\n */\nexport async function updateKnowledgeBase(\n knowledgeBaseId: string,\n params: Context.EditKnowledgeBaseParams,\n): Promise<Context.KnowledgeBase> {\n const client = await getContextClient()\n return client.context.knowledgeBases.edit(knowledgeBaseId, params)\n}\n\n/**\n * `stackName` is `null` when the caller can't read Blueprints: the search then\n * only says whether a blueprint manages the resource.\n */\nexport type BlueprintOwnership = {managed: false} | {managed: true; stackName: string | null}\n\n/**\n * Whether a live blueprint stack manages the knowledge base, from the\n * Blueprints resource search. Fails open: a failed lookup answers not managed,\n * so a Blueprints outage never blocks a command.\n */\nexport async function getKnowledgeBaseBlueprintOwnership(\n knowledgeBaseId: string,\n): Promise<BlueprintOwnership> {\n try {\n const {organizationId, publicId} = await getKnowledgeBase(knowledgeBaseId)\n const client = await getGlobalCliClient({\n apiVersion: BLUEPRINTS_API_VERSION,\n // The Blueprints API has no stable version yet, and the warning would interrupt command output.\n // The client splits the warning header on commas, so its second clause is matched separately.\n ignoreWarnings: [EXPERIMENTAL_API_WARNING, 'which will change without warning'],\n // The lookup fails open, so an unreachable Blueprints API must not hold the command for the client's defaults.\n maxRetries: 0,\n requireUser: true,\n timeout: BLUEPRINTS_LOOKUP_TIMEOUT_MS,\n })\n const headers = {\n 'x-sanity-scope-id': organizationId,\n 'x-sanity-scope-type': 'organization',\n }\n const matches = await client.request<{stackId?: string}[]>({\n headers,\n query: {id: publicId, type: 'sanity.context.knowledge-base'},\n url: '/blueprints/resources/search',\n })\n const stackId = matches.find((match) => typeof match.stackId === 'string')?.stackId\n if (!stackId) return {managed: false}\n const stackName = await client\n .request<{name?: string}>({\n headers,\n url: `/blueprints/stacks/${encodeURIComponent(stackId)}`,\n })\n .then((stack) => stack.name ?? null)\n .catch(() => null)\n return {managed: true, stackName}\n } catch (error) {\n if (isHttpError(error)) {\n if (error.statusCode === 403 && errorCode(error) === 'RESOURCE_MANAGED') {\n return {managed: true, stackName: null}\n }\n if (error.statusCode === 404 && errorCode(error) === 'RESOURCE_NOT_MANAGED') {\n return {managed: false}\n }\n }\n blueprintOwnershipDebug('Blueprint ownership lookup failed, treating as not managed', error)\n return {managed: false}\n }\n}\n\nfunction errorCode(error: {response: {body: unknown}}): unknown {\n const {body} = error.response\n return body && typeof body === 'object' && 'errorCode' in body ? body.errorCode : undefined\n}\n\n/**\n * Delete a knowledge base and its generated content\n */\nexport async function deleteKnowledgeBase(knowledgeBaseId: string): Promise<void> {\n const client = await getContextClient()\n await client.context.knowledgeBases.delete(knowledgeBaseId)\n}\n\n/**\n * Import content into a knowledge base. File imports are staged and uploaded\n * to signed storage by the client.\n */\nexport async function createImport(\n knowledgeBaseId: string,\n params: Context.CreateFileImportParams | Context.CreateImportParams,\n): Promise<Context.JobAccepted> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.imports.create(params)\n}\n\n/**\n * List all imports for a knowledge base (drains pagination)\n */\nexport async function listImports(knowledgeBaseId: string): Promise<Context.Import[]> {\n const client = await getContextClient(knowledgeBaseId)\n\n const imports: Context.Import[] = []\n let cursor: string | undefined\n do {\n const page = await client.context.imports.list({cursor})\n imports.push(...page.data)\n cursor = page.nextCursor ?? undefined\n } while (cursor !== undefined)\n\n return imports\n}\n\n/**\n * Get a single import by ID\n */\nexport async function getImport(\n knowledgeBaseId: string,\n importId: string,\n): Promise<Context.ImportDetail> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.imports.get({importId})\n}\n\n/**\n * Get a short-lived signed URL for an import's original uploaded bytes\n */\nexport async function downloadImport(\n knowledgeBaseId: string,\n importId: string,\n): Promise<Context.ImportDownloadResponse> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.imports.download({importId})\n}\n\n/**\n * Delete an import from a knowledge base\n */\nexport async function deleteImport(knowledgeBaseId: string, importId: string): Promise<void> {\n const client = await getContextClient(knowledgeBaseId)\n await client.context.imports.delete({importId})\n}\n\n/**\n * Start a build of a knowledge base\n */\nexport async function buildKnowledgeBase(knowledgeBaseId: string): Promise<Context.JobAccepted> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.build()\n}\n\n/**\n * Cancel the running build of a knowledge base, if any\n */\nexport async function cancelKnowledgeBaseBuild(\n knowledgeBaseId: string,\n): Promise<{cancelled: boolean}> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.cancelBuild()\n}\n\n/**\n * Run an incremental refresh: re-check sources and apply what changed\n */\nexport async function refreshKnowledgeBase(\n knowledgeBaseId: string,\n): Promise<{jobId: string; started: boolean}> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.refresh()\n}\n\n/**\n * Get an async job (build, import) by ID\n */\nexport async function getJob(knowledgeBaseId: string, jobId: string): Promise<Context.Job> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.jobs.get({jobId})\n}\n\n/**\n * List all issues for a knowledge base, optionally narrowed to one status\n */\nexport async function listIssues(\n knowledgeBaseId: string,\n status?: Context.IssueDoc['status'],\n): Promise<Context.IssueDoc[]> {\n const client = await getContextStoreClient(knowledgeBaseId)\n return client.context.issues.list({status})\n}\n\n/**\n * Get a single issue by ID, or `null` when it does not exist\n */\nexport async function getIssue(\n knowledgeBaseId: string,\n issueId: string,\n): Promise<Context.IssueDoc | null> {\n const client = await getContextStoreClient(knowledgeBaseId)\n return client.context.issues.get({issueId})\n}\n\n/**\n * Resolve a conflict issue by choosing one of its sides (by index). Choosing\n * a side other than the entry's current content starts a rewrite job.\n */\nexport async function resolveIssue(\n knowledgeBaseId: string,\n issueId: string,\n resolution: number,\n): Promise<Context.ResolveIssueResponse> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.issues.resolve({issueId, resolution})\n}\n\n/**\n * Dismiss an issue\n */\nexport async function dismissIssue(\n knowledgeBaseId: string,\n issueId: string,\n): Promise<Context.DismissIssueResponse> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.issues.dismiss({issueId})\n}\n\n/**\n * Reopen a resolved conflict issue\n */\nexport async function reopenIssue(\n knowledgeBaseId: string,\n issueId: string,\n): Promise<Context.ReopenIssueResponse> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.issues.reopen({issueId})\n}\n\n/**\n * Apply accepted issues to a knowledge base in one batch\n */\nexport async function applyIssues(\n knowledgeBaseId: string,\n issueIds: string[],\n): Promise<Context.ApplyIssuesResponse> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.issues.apply({issueIds})\n}\n\n/**\n * List all entries for a knowledge base, path-ordered, without bodies\n */\nexport async function listEntries(knowledgeBaseId: string): Promise<Context.Entry[]> {\n const client = await getContextStoreClient(knowledgeBaseId)\n return client.context.entries.list()\n}\n\n/**\n * Get a single entry with its body and citations by outline path, or `null`\n * when no entry sits at that path\n */\nexport async function getEntry(\n knowledgeBaseId: string,\n path: string,\n): Promise<Context.EntryDoc | null> {\n const client = await getContextStoreClient(knowledgeBaseId)\n return client.context.entries.get({path})\n}\n\n/**\n * Rebuild one entry from its sources by outline path\n */\nexport async function rebuildEntry(\n knowledgeBaseId: string,\n path: string,\n): Promise<Context.RebuildEntryResponse> {\n const client = await getContextClient(knowledgeBaseId)\n return client.context.entries.rebuild({path})\n}\n\n/**\n * Run a GROQ query against an organization's Context documents\n */\nexport async function queryContext(\n organizationId: string,\n query: string,\n params?: Record<string, unknown>,\n): Promise<unknown> {\n const client = await getContextClient(undefined, organizationId)\n return client.context.fetch(query, params)\n}\n"],"names":["getGlobalCliClient","subdebug","EXPERIMENTAL_API_WARNING","isHttpError","CONTEXT_API_VERSION","BLUEPRINTS_API_VERSION","BLUEPRINTS_LOOKUP_TIMEOUT_MS","blueprintOwnershipDebug","getContextClient","knowledgeBaseId","organizationId","apiVersion","requireUser","undefined","resource","id","type","context","getContextStoreClient","publicId","getKnowledgeBase","createKnowledgeBase","params","client","knowledgeBases","create","listKnowledgeBases","cursor","page","list","push","data","nextCursor","get","updateKnowledgeBase","edit","getKnowledgeBaseBlueprintOwnership","ignoreWarnings","maxRetries","timeout","headers","matches","request","query","url","stackId","find","match","managed","stackName","encodeURIComponent","then","stack","name","catch","error","statusCode","errorCode","body","response","deleteKnowledgeBase","delete","createImport","imports","listImports","getImport","importId","downloadImport","download","deleteImport","buildKnowledgeBase","build","cancelKnowledgeBaseBuild","cancelBuild","refreshKnowledgeBase","refresh","getJob","jobId","jobs","listIssues","status","issues","getIssue","issueId","resolveIssue","resolution","resolve","dismissIssue","dismiss","reopenIssue","reopen","applyIssues","issueIds","apply","listEntries","entries","getEntry","path","rebuildEntry","rebuild","queryContext","fetch"],"mappings":"AAAA,SAAQA,kBAAkB,EAAEC,QAAQ,QAAO,mBAAkB;AAC7D,SAAsBC,wBAAwB,EAAEC,WAAW,QAAO,iBAAgB;AAElF,MAAMC,sBAAsB;AAC5B,MAAMC,yBAAyB;AAC/B,MAAMC,+BAA+B;AAErC,MAAMC,0BAA0BN,SAAS;AAEzC;;;;;CAKC,GACD,eAAeO,iBAAiBC,eAAwB,EAAEC,cAAuB;IAC/E,OAAOV,mBAAmB;QACxBW,YAAYP;QACZQ,aAAa;QACb,GAAIH,oBAAoBI,YACpB,CAAC,IACD;YAACC,UAAU;gBAACC,IAAIN;gBAAiBO,MAAM;YAAyB;QAAC,CAAC;QACtE,GAAIN,mBAAmBG,YAAY,CAAC,IAAI;YAACI,SAAS;gBAACP;YAAc;QAAC,CAAC;IACrE;AACF;AAEA;;;;CAIC,GACD,eAAeQ,sBAAsBT,eAAuB;IAC1D,MAAM,EAACC,cAAc,EAAES,QAAQ,EAAC,GAAG,MAAMC,iBAAiBX;IAC1D,OAAOD,iBAAiBW,UAAUT;AACpC;AAEA;;CAEC,GACD,OAAO,eAAeW,oBACpBC,MAAyC;IAEzC,MAAMC,SAAS,MAAMf;IACrB,OAAOe,OAAON,OAAO,CAACO,cAAc,CAACC,MAAM,CAACH;AAC9C;A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sBT;IAC3C,OAAOc,OAAON,OAAO,CAAC8E,OAAO,CAAClE,IAAI;AACpC;AAEA;;;CAGC,GACD,OAAO,eAAemE,SACpBvF,eAAuB,EACvBwF,IAAY;IAEZ,MAAM1E,SAAS,MAAML,sBAAsBT;IAC3C,OAAOc,OAAON,OAAO,CAAC8E,OAAO,CAAC9D,GAAG,CAAC;QAACgE;IAAI;AACzC;AAEA;;CAEC,GACD,OAAO,eAAeC,aACpBzF,eAAuB,EACvBwF,IAAY;IAEZ,MAAM1E,SAAS,MAAMf,iBAAiBC;IACtC,OAAOc,OAAON,OAAO,CAAC8E,OAAO,CAACI,OAAO,CAAC;QAACF;IAAI;AAC7C;AAEA;;CAEC,GACD,OAAO,eAAeG,aACpB1F,cAAsB,EACtBiC,KAAa,EACbrB,MAAgC;IAEhC,MAAMC,SAAS,MAAMf,iBAAiBK,WAAWH;IACjD,OAAOa,OAAON,OAAO,CAACoF,KAAK,CAAC1D,OAAOrB;AACrC"}
|
|
1
|
+
{"version":3,"sources":["../../src/services/context.ts"],"sourcesContent":["import {getGlobalCliClient, subdebug} from '@sanity/cli-core'\nimport {type Context, EXPERIMENTAL_API_WARNING, isHttpError} from '@sanity/client'\n\nconst CONTEXT_API_VERSION = 'v2026-08-25'\nconst BLUEPRINTS_API_VERSION = 'vX'\nconst BLUEPRINTS_LOOKUP_TIMEOUT_MS = 5000\n// The version in the URLs the Context API returns for agents to connect to MCP endpoints\nconst MCP_CONNECT_API_VERSION = 'v2026-11-03'\n// Documents per page while a GROQ list read drains the store\nconst STORE_PAGE_SIZE = 200\nconst MCP_LIST_LIMIT = 500\n\nconst blueprintOwnershipDebug = subdebug('context:blueprint-ownership')\n\n/** A knowledge base */\nexport type KnowledgeBase = Context.Response<'GET /knowledge-bases/{knowledgeBaseId}'>\n/** An async job: a build, an update or a `files` sync */\nexport type Job = Context.Response<'GET /knowledge-bases/{knowledgeBaseId}/jobs/{jobId}'>\n/** One run of a source's connector */\nexport type Sync =\n Context.Response<'GET /knowledge-bases/{knowledgeBaseId}/sources/{sourceId}/syncs/{syncId}'>\n\n/** The request a command builds: path parameters, query and body */\nexport interface ContextRequest {\n body?: unknown\n params?: Record<string, string>\n query?: Record<string, string>\n}\n\ntype Page = {data: unknown[]; nextCursor: string | null}\n\nfunction isPage(value: unknown): value is Page {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'data' in value &&\n Array.isArray(value.data) &&\n 'nextCursor' in value\n )\n}\n\nasync function getContextClient(organizationId?: string) {\n return getGlobalCliClient({\n apiVersion: CONTEXT_API_VERSION,\n requireUser: true,\n ...(organizationId === undefined ? {} : {context: {organizationId}}),\n })\n}\n\n/**\n * Call a Context API operation by its route. Commands build requests at\n * runtime from the spec, so this is the one place the route-typed client call\n * is loosened to a runtime route and request.\n */\nexport async function requestContext(\n route: Context.Route,\n request: ContextRequest = {},\n): Promise<unknown> {\n const client = await getContextClient()\n const call = client.context.request as (route: string, init: ContextRequest) => Promise<unknown>\n return call.call(client.context, route, request)\n}\n\n/**\n * Call a paginated list operation and drain its pages into one list, asking\n * for `pageSize` items a page. A `limit` in the query caps the total instead of\n * one page, so the list stops once it has that many.\n */\nexport async function requestAllPages(\n route: Context.Route,\n request: ContextRequest = {},\n pageSize?: number,\n): Promise<unknown[]> {\n const {limit, ...query} = request.query ?? {}\n const total = limit === undefined ? undefined : Number(limit)\n const items: unknown[] = []\n let cursor: string | undefined\n do {\n const remaining = total === undefined ? undefined : total - items.length\n const size = remaining === undefined ? pageSize : Math.min(pageSize ?? remaining, remaining)\n const page = await requestContext(route, {\n ...request,\n query: {...query, ...(size !== undefined && {limit: String(size)}), ...(cursor && {cursor})},\n })\n if (!isPage(page)) throw new Error(`${route} answered with something other than a page`)\n items.push(...page.data)\n cursor = page.nextCursor ?? undefined\n } while (cursor !== undefined && (total === undefined || items.length < total))\n return total === undefined ? items : items.slice(0, total)\n}\n\n/** A document's content as the bytes its source gave (`format: 'raw'`) */\nexport async function getDocumentBytes(request: ContextRequest): Promise<Uint8Array> {\n const client = await getContextClient()\n const call = client.context.requestBytes as (\n route: string,\n init: ContextRequest,\n ) => Promise<Uint8Array>\n return call.call(\n client.context,\n 'GET /knowledge-bases/{knowledgeBaseId}/documents/{documentId}/content',\n request,\n )\n}\n\n/** Get a knowledge base */\nasync function getKnowledgeBase(knowledgeBaseId: string): Promise<KnowledgeBase> {\n const client = await getContextClient()\n return client.context.request('GET /knowledge-bases/{knowledgeBaseId}', {\n params: {knowledgeBaseId},\n })\n}\n\n/** Get a source, with its latest sync */\nexport async function getSource(\n knowledgeBaseId: string,\n sourceId: string,\n): Promise<Context.Source> {\n const client = await getContextClient()\n return client.context.request('GET /knowledge-bases/{knowledgeBaseId}/sources/{sourceId}', {\n params: {knowledgeBaseId, sourceId},\n })\n}\n\n/** Get a sync of a source by ID */\nexport async function getSync(\n knowledgeBaseId: string,\n sourceId: string,\n syncId: string,\n): Promise<Sync> {\n const client = await getContextClient()\n return client.context.request(\n 'GET /knowledge-bases/{knowledgeBaseId}/sources/{sourceId}/syncs/{syncId}',\n {params: {knowledgeBaseId, sourceId, syncId}},\n )\n}\n\n/** Get a job by ID */\nexport async function getJob(knowledgeBaseId: string, jobId: string): Promise<Job> {\n const client = await getContextClient()\n return client.context.request('GET /knowledge-bases/{knowledgeBaseId}/jobs/{jobId}', {\n params: {jobId, knowledgeBaseId},\n })\n}\n\n/**\n * Add a `files` source holding a local file: add the source, upload the file\n * and sync it. Resolves with the source as created and the sync's `jobId`.\n */\nexport async function createFileSource(\n knowledgeBaseId: string,\n params: Omit<Context.CreateFileSourceParams, 'knowledgeBaseId'>,\n): Promise<{source: Context.Source; sync: Context.SyncAccepted}> {\n const client = await getContextClient()\n return client.context.createFileSource({...params, knowledgeBaseId})\n}\n\n/** Upload a file to a `files` source, replacing the file it holds, and sync it */\nexport async function uploadSourceFile(\n knowledgeBaseId: string,\n sourceId: string,\n upload: Context.FileUpload,\n): Promise<Context.SyncAccepted> {\n const client = await getContextClient()\n return client.context.uploadFile({...upload, knowledgeBaseId, sourceId})\n}\n\n/** Run a GROQ query against an organization's Context documents */\nexport async function queryContext(\n organizationId: string,\n query: string,\n params?: Record<string, unknown>,\n): Promise<unknown> {\n const client = await getContextClient(organizationId)\n return client.context.fetch(query, params)\n}\n\n/**\n * GROQ reads of a knowledge base's documents query the organization's document\n * store, where documents are keyed by the knowledge base's public ID. Fetching\n * the knowledge base resolves both, whichever of its IDs was passed.\n */\nasync function getStoreScope(knowledgeBaseId: string) {\n const {organizationId, publicId} = await getKnowledgeBase(knowledgeBaseId)\n return {client: await getContextClient(organizationId), kb: publicId}\n}\n\n/** Drain a `(_createdAt, _id)`-keyset GROQ read */\nasync function drainByCreatedAt<T extends {_createdAt: string; _id: string}>(\n organizationId: string,\n filter: string,\n params: Record<string, unknown>,\n): Promise<T[]> {\n const client = await getContextClient(organizationId)\n const all: T[] = []\n let cursor: {c: string; i: string} | undefined\n for (;;) {\n const paged = cursor\n ? `${filter} && (_createdAt > $c || (_createdAt == $c && _id > $i))`\n : filter\n const page = await client.context.fetch<T[]>(\n `*[${paged}] | order(_createdAt asc, _id asc) [0...${STORE_PAGE_SIZE}]`,\n {...params, ...cursor},\n )\n all.push(...page)\n if (page.length < STORE_PAGE_SIZE) return all\n const last = page.at(-1)!\n cursor = {c: last._createdAt, i: last._id}\n }\n}\n\n/** The fields `entries list` shows of each entry */\nexport type EntrySummary = Pick<Context.EntryDoc, '_id' | 'path' | 'status' | 'title' | 'tldr'>\n\n/** List all entries of a knowledge base, path-ordered, without bodies */\nexport async function listEntries(knowledgeBaseId: string): Promise<EntrySummary[]> {\n const {client, kb} = await getStoreScope(knowledgeBaseId)\n const all: EntrySummary[] = []\n let after = ''\n for (;;) {\n const page = await client.context.fetch<EntrySummary[]>(\n `*[_type == \"sanity.context.entry\" && knowledgeBaseId == $kb && path > $after] | order(path asc) [0...${STORE_PAGE_SIZE}] {_id, path, title, tldr, status}`,\n {after, kb},\n )\n all.push(...page)\n if (page.length < STORE_PAGE_SIZE) return all\n after = page.at(-1)!.path\n }\n}\n\n/** Get an entry with its body and citations by outline path, or `null` when no entry sits there */\nexport async function getEntry(\n knowledgeBaseId: string,\n path: string,\n): Promise<Context.EntryDoc | null> {\n const {client, kb} = await getStoreScope(knowledgeBaseId)\n return client.context.fetch<Context.EntryDoc | null>(\n '*[_type == \"sanity.context.entry\" && knowledgeBaseId == $kb && path == $path][0]',\n {kb, path},\n )\n}\n\n/** List all issues of a knowledge base, optionally only those in one status */\nexport async function listIssues(\n knowledgeBaseId: string,\n status?: Context.IssueDoc['status'],\n): Promise<Context.IssueDoc[]> {\n const {organizationId, publicId} = await getKnowledgeBase(knowledgeBaseId)\n const filter = `_type == \"sanity.context.issue\" && knowledgeBaseId == $kb${status === undefined ? '' : ' && status == $status'}`\n return drainByCreatedAt<Context.IssueDoc>(organizationId, filter, {\n kb: publicId,\n ...(status !== undefined && {status}),\n })\n}\n\n/** Get an issue by ID, or `null` when it doesn't exist */\nexport async function getIssue(\n knowledgeBaseId: string,\n issueId: string,\n): Promise<Context.IssueDoc | null> {\n const {client, kb} = await getStoreScope(knowledgeBaseId)\n return client.context.fetch<Context.IssueDoc | null>(\n '*[_type == \"sanity.context.issue\" && knowledgeBaseId == $kb && _id == $id][0]',\n {id: issueId, kb},\n )\n}\n\n/** The configuration of an MCP endpoint, as create and update return it */\nexport type McpEndpoint = Context.Response<'POST /organizations/{organizationId}/mcp'>\n\n/** List an organization's MCP endpoints, oldest first */\nexport async function listMcpEndpoints(organizationId: string): Promise<McpEndpoint[]> {\n const client = await getContextClient(organizationId)\n const docs = await client.context.fetch<Context.McpDoc[]>(\n `*[_type == \"sanity.context.mcp\" && organizationId == $org] | order(_createdAt asc, _id asc) [0...${MCP_LIST_LIMIT}]`,\n {org: organizationId},\n )\n const connectClient = client.withConfig({apiVersion: MCP_CONNECT_API_VERSION})\n return docs.map((doc) => toMcpEndpoint(connectClient, doc))\n}\n\n/**\n * Get an MCP endpoint by name or ID, or `null` when the organization has none.\n * Update and delete accept either, so the lookups guarding them must too.\n */\nexport async function getMcpEndpoint(\n organizationId: string,\n nameOrId: string,\n): Promise<McpEndpoint | null> {\n const client = await getContextClient(organizationId)\n const doc = await client.context.fetch<Context.McpDoc | null>(\n '*[_type == \"sanity.context.mcp\" && organizationId == $org && (name == $nameOrId || publicId == $nameOrId)][0]',\n {nameOrId, org: organizationId},\n )\n return doc && toMcpEndpoint(client.withConfig({apiVersion: MCP_CONNECT_API_VERSION}), doc)\n}\n\n/**\n * The stored configuration in the shape create and edit return, so every command outputs the\n * same fields. The URL isn't stored, so it is built from the same route and API version.\n */\nfunction toMcpEndpoint(\n connectClient: {getUrl: (uri: string) => string},\n doc: Context.McpDoc,\n): McpEndpoint {\n return {\n createdAt: doc._createdAt,\n groqFilter: doc.groqFilter ?? null,\n id: doc.publicId,\n instructions: doc.instructions ?? null,\n lastUsedAt: doc.lastUsedAt ?? null,\n name: doc.name,\n organizationId: doc.organizationId,\n sources: doc.sources,\n title: doc.title,\n updatedAt: doc._updatedAt,\n url: connectClient.getUrl(\n `/context/organizations/${encodeURIComponent(doc.organizationId)}/mcp/${encodeURIComponent(doc.name)}`,\n ),\n }\n}\n\n/** Create an MCP endpoint */\nexport async function createMcpEndpoint(\n organizationId: string,\n body: Context.Body<'POST /organizations/{organizationId}/mcp'>,\n): Promise<McpEndpoint> {\n const client = await getContextClient()\n return client.context.request('POST /organizations/{organizationId}/mcp', {\n body,\n params: {organizationId},\n })\n}\n\n/** Update an MCP endpoint's configuration */\nexport async function updateMcpEndpoint(\n organizationId: string,\n name: string,\n body: Context.Body<'PATCH /organizations/{organizationId}/mcp/{mcpEndpoint}'>,\n): Promise<McpEndpoint> {\n const client = await getContextClient()\n return client.context.request('PATCH /organizations/{organizationId}/mcp/{mcpEndpoint}', {\n body,\n params: {mcpEndpoint: name, organizationId},\n })\n}\n\n/** Delete an MCP endpoint */\nexport async function deleteMcpEndpoint(organizationId: string, name: string): Promise<void> {\n const client = await getContextClient()\n await client.context.request('DELETE /organizations/{organizationId}/mcp/{mcpEndpoint}', {\n params: {mcpEndpoint: name, organizationId},\n })\n}\n\n/** The checks of whether agents can use an MCP endpoint */\nexport type McpEndpointStatus =\n Context.Response<'GET /organizations/{organizationId}/mcp/{mcpEndpoint}/status'>\n\n/** Check whether an agent connecting with the current credentials can use an MCP endpoint */\nexport async function getMcpEndpointStatus(\n organizationId: string,\n name: string,\n): Promise<McpEndpointStatus> {\n const client = await getContextClient()\n return client.context.request('GET /organizations/{organizationId}/mcp/{mcpEndpoint}/status', {\n params: {mcpEndpoint: name, organizationId},\n })\n}\n\n/**\n * `stackName` is `null` when the caller can't read Blueprints: the search then\n * only says whether a blueprint manages the resource.\n */\nexport type BlueprintOwnership = {managed: false} | {managed: true; stackName: string | null}\n\n/**\n * Who manages a resource, for refusal messages: the stack by name when the caller can read it\n */\nexport function describeBlueprintManager(stackName: string | null): string {\n return stackName ? `The blueprint stack \"${stackName}\"` : 'A blueprint'\n}\n\n/**\n * Whether a live blueprint stack manages the knowledge base\n */\nexport function getKnowledgeBaseBlueprintOwnership(\n knowledgeBaseId: string,\n): Promise<BlueprintOwnership> {\n return getBlueprintOwnership('sanity.context.knowledge-base', async () => {\n const {organizationId, publicId} = await getKnowledgeBase(knowledgeBaseId)\n return {organizationId, publicId}\n })\n}\n\n/**\n * Whether a live blueprint stack manages the MCP endpoint\n */\nexport function getMcpEndpointBlueprintOwnership(\n organizationId: string,\n {id}: Pick<McpEndpoint, 'id'>,\n): Promise<BlueprintOwnership> {\n return getBlueprintOwnership('sanity.context.mcp', async () => ({organizationId, publicId: id}))\n}\n\n/**\n * Looks the resource up in the Blueprints resource search. Fails open: a\n * failed lookup answers not managed, so a Blueprints outage never blocks a\n * command. A resource that doesn't exist isn't managed either.\n */\nasync function getBlueprintOwnership(\n type: string,\n resolveResource: () => Promise<{organizationId: string; publicId: string} | null>,\n): Promise<BlueprintOwnership> {\n try {\n const resource = await resolveResource()\n if (!resource) return {managed: false}\n const {organizationId, publicId} = resource\n const client = await getGlobalCliClient({\n apiVersion: BLUEPRINTS_API_VERSION,\n // The Blueprints API has no stable version yet, and the warning would interrupt command output.\n // The client splits the warning header on commas, so its second clause is matched separately.\n ignoreWarnings: [EXPERIMENTAL_API_WARNING, 'which will change without warning'],\n // The lookup fails open, so an unreachable Blueprints API must not hold the command for the client's defaults.\n maxRetries: 0,\n requireUser: true,\n timeout: BLUEPRINTS_LOOKUP_TIMEOUT_MS,\n })\n const headers = {\n 'x-sanity-scope-id': organizationId,\n 'x-sanity-scope-type': 'organization',\n }\n const matches = await client.request<{stackId?: string}[]>({\n headers,\n query: {id: publicId, type},\n url: '/blueprints/resources/search',\n })\n const stackId = matches.find((match) => typeof match.stackId === 'string')?.stackId\n if (!stackId) return {managed: false}\n const stackName = await client\n .request<{name?: string}>({\n headers,\n url: `/blueprints/stacks/${encodeURIComponent(stackId)}`,\n })\n .then((stack) => stack.name ?? null)\n .catch(() => null)\n return {managed: true, stackName}\n } catch (error) {\n if (isHttpError(error)) {\n if (error.statusCode === 403 && errorCode(error) === 'RESOURCE_MANAGED') {\n return {managed: true, stackName: null}\n }\n if (error.statusCode === 404 && errorCode(error) === 'RESOURCE_NOT_MANAGED') {\n return {managed: false}\n }\n }\n blueprintOwnershipDebug('Blueprint ownership lookup failed, treating as not managed', error)\n return {managed: false}\n }\n}\n\nfunction errorCode(error: {response: {body: unknown}}): unknown {\n const {body} = error.response\n return body && typeof body === 'object' && 'errorCode' in body ? body.errorCode : undefined\n}\n"],"names":["getGlobalCliClient","subdebug","EXPERIMENTAL_API_WARNING","isHttpError","CONTEXT_API_VERSION","BLUEPRINTS_API_VERSION","BLUEPRINTS_LOOKUP_TIMEOUT_MS","MCP_CONNECT_API_VERSION","STORE_PAGE_SIZE","MCP_LIST_LIMIT","blueprintOwnershipDebug","isPage","value","Array","isArray","data","getContextClient","organizationId","apiVersion","requireUser","undefined","context","requestContext","route","request","client","call","requestAllPages","pageSize","limit","query","total","Number","items","cursor","remaining","length","size","Math","min","page","String","Error","push","nextCursor","slice","getDocumentBytes","requestBytes","getKnowledgeBase","knowledgeBaseId","params","getSource","sourceId","getSync","syncId","getJob","jobId","createFileSource","uploadSourceFile","upload","uploadFile","queryContext","fetch","getStoreScope","publicId","kb","drainByCreatedAt","filter","all","paged","last","at","c","_createdAt","i","_id","listEntries","after","path","getEntry","listIssues","status","getIssue","issueId","id","listMcpEndpoints","docs","org","connectClient","withConfig","map","doc","toMcpEndpoint","getMcpEndpoint","nameOrId","createdAt","groqFilter","instructions","lastUsedAt","name","sources","title","updatedAt","_updatedAt","url","getUrl","encodeURIComponent","createMcpEndpoint","body","updateMcpEndpoint","mcpEndpoint","deleteMcpEndpoint","getMcpEndpointStatus","describeBlueprintManager","stackName","getKnowledgeBaseBlueprintOwnership","getBlueprintOwnership","getMcpEndpointBlueprintOwnership","type","resolveResource","resource","managed","ignoreWarnings","maxRetries","timeout","headers","matches","stackId","find","match","then","stack","catch","error","statusCode","errorCode","response"],"mappings":"AAAA,SAAQA,kBAAkB,EAAEC,QAAQ,QAAO,mBAAkB;AAC7D,SAAsBC,wBAAwB,EAAEC,WAAW,QAAO,iBAAgB;AAElF,MAAMC,sBAAsB;AAC5B,MAAMC,yBAAyB;AAC/B,MAAMC,+BAA+B;AACrC,yFAAyF;AACzF,MAAMC,0BAA0B;AAChC,6DAA6D;AAC7D,MAAMC,kBAAkB;AACxB,MAAMC,iBAAiB;AAEvB,MAAMC,0BAA0BT,SAAS;AAmBzC,SAASU,OAAOC,KAAc;IAC5B,OACE,OAAOA,UAAU,YACjBA,UAAU,QACV,UAAUA,SACVC,MAAMC,OAAO,CAACF,MAAMG,IAAI,KACxB,gBAAgBH;AAEpB;AAEA,eAAeI,iBAAiBC,cAAuB;IACrD,OAAOjB,mBAAmB;QACxBkB,YAAYd;QACZe,aAAa;QACb,GAAIF,mBAAmBG,YAAY,CAAC,IAAI;YAACC,SAAS;gBAACJ;YAAc;QAAC,CAAC;IACrE;AACF;AAEA;;;;CAIC,GACD,OAAO,e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