@sanity/cli 8.27.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.map +1 -1
- 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/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 -90
- 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/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 -95
- package/dist/commands/context/list.js.map +1 -1
- 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 +2 -2
- package/dist/commands/context/mcp/list.js.map +1 -1
- package/dist/commands/context/mcp/status.js.map +1 -1
- package/dist/commands/context/mcp/update.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 +41 -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/services/context.js +241 -268
- package/dist/services/context.js.map +1 -1
- package/dist/util/telemetry/cliCommandIdentity.js +10 -18
- package/dist/util/telemetry/cliCommandIdentity.js.map +1 -1
- package/oclif.manifest.json +4393 -2923
- 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
|
@@ -4,23 +4,18 @@ const CONTEXT_API_VERSION = 'v2026-08-25';
|
|
|
4
4
|
const BLUEPRINTS_API_VERSION = 'vX';
|
|
5
5
|
const BLUEPRINTS_LOOKUP_TIMEOUT_MS = 5000;
|
|
6
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-
|
|
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;
|
|
8
11
|
const blueprintOwnershipDebug = subdebug('context:blueprint-ownership');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* GROQ-backed reads also need `context.organizationId`.
|
|
14
|
-
*/ 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) {
|
|
15
16
|
return getGlobalCliClient({
|
|
16
17
|
apiVersion: CONTEXT_API_VERSION,
|
|
17
18
|
requireUser: true,
|
|
18
|
-
...knowledgeBaseId === undefined ? {} : {
|
|
19
|
-
resource: {
|
|
20
|
-
id: knowledgeBaseId,
|
|
21
|
-
type: 'knowledge-base'
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
19
|
...organizationId === undefined ? {} : {
|
|
25
20
|
context: {
|
|
26
21
|
organizationId
|
|
@@ -29,46 +24,252 @@ const blueprintOwnershipDebug = subdebug('context:blueprint-ownership');
|
|
|
29
24
|
});
|
|
30
25
|
}
|
|
31
26
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*/ async function
|
|
36
|
-
const { organizationId, publicId } = await getKnowledgeBase(knowledgeBaseId);
|
|
37
|
-
return getContextClient(publicId, organizationId);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Create a knowledge base in an organization
|
|
41
|
-
*/ 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 = {}) {
|
|
42
31
|
const client = await getContextClient();
|
|
43
|
-
|
|
32
|
+
const call = client.context.request;
|
|
33
|
+
return call.call(client.context, route, request);
|
|
44
34
|
}
|
|
45
35
|
/**
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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 = [];
|
|
50
43
|
let cursor;
|
|
51
44
|
do {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
}
|
|
55
58
|
});
|
|
56
|
-
|
|
59
|
+
if (!isPage(page)) throw new Error(`${route} answered with something other than a page`);
|
|
60
|
+
items.push(...page.data);
|
|
57
61
|
cursor = page.nextCursor ?? undefined;
|
|
58
|
-
}while (cursor !== undefined)
|
|
59
|
-
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
|
+
});
|
|
60
105
|
}
|
|
61
106
|
/**
|
|
62
|
-
*
|
|
63
|
-
|
|
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) {
|
|
64
110
|
const client = await getContextClient();
|
|
65
|
-
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);
|
|
66
127
|
}
|
|
67
128
|
/**
|
|
68
|
-
*
|
|
69
|
-
|
|
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));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
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) {
|
|
70
238
|
const client = await getContextClient();
|
|
71
|
-
return client.context.
|
|
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) {
|
|
266
|
+
const client = await getContextClient();
|
|
267
|
+
return client.context.request('GET /organizations/{organizationId}/mcp/{mcpEndpoint}/status', {
|
|
268
|
+
params: {
|
|
269
|
+
mcpEndpoint: name,
|
|
270
|
+
organizationId
|
|
271
|
+
}
|
|
272
|
+
});
|
|
72
273
|
}
|
|
73
274
|
/**
|
|
74
275
|
* Who manages a resource, for refusal messages: the stack by name when the caller can read it
|
|
@@ -166,233 +367,5 @@ function errorCode(error) {
|
|
|
166
367
|
const { body } = error.response;
|
|
167
368
|
return body && typeof body === 'object' && 'errorCode' in body ? body.errorCode : undefined;
|
|
168
369
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Delete a knowledge base and its generated content
|
|
171
|
-
*/ export async function deleteKnowledgeBase(knowledgeBaseId) {
|
|
172
|
-
const client = await getContextClient();
|
|
173
|
-
await client.context.knowledgeBases.delete(knowledgeBaseId);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Import content into a knowledge base. File imports are staged and uploaded
|
|
177
|
-
* to signed storage by the client.
|
|
178
|
-
*/ export async function createImport(knowledgeBaseId, params) {
|
|
179
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
180
|
-
return client.context.imports.create(params);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* List all imports for a knowledge base (drains pagination)
|
|
184
|
-
*/ export async function listImports(knowledgeBaseId) {
|
|
185
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
186
|
-
const imports = [];
|
|
187
|
-
let cursor;
|
|
188
|
-
do {
|
|
189
|
-
const page = await client.context.imports.list({
|
|
190
|
-
cursor
|
|
191
|
-
});
|
|
192
|
-
imports.push(...page.data);
|
|
193
|
-
cursor = page.nextCursor ?? undefined;
|
|
194
|
-
}while (cursor !== undefined)
|
|
195
|
-
return imports;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Get a single import by ID
|
|
199
|
-
*/ export async function getImport(knowledgeBaseId, importId) {
|
|
200
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
201
|
-
return client.context.imports.get({
|
|
202
|
-
importId
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Get a short-lived signed URL for an import's original uploaded bytes
|
|
207
|
-
*/ export async function downloadImport(knowledgeBaseId, importId) {
|
|
208
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
209
|
-
return client.context.imports.download({
|
|
210
|
-
importId
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Delete an import from a knowledge base
|
|
215
|
-
*/ export async function deleteImport(knowledgeBaseId, importId) {
|
|
216
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
217
|
-
await client.context.imports.delete({
|
|
218
|
-
importId
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Start a build of a knowledge base
|
|
223
|
-
*/ export async function buildKnowledgeBase(knowledgeBaseId) {
|
|
224
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
225
|
-
return client.context.build();
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Cancel the running build of a knowledge base, if any
|
|
229
|
-
*/ export async function cancelKnowledgeBaseBuild(knowledgeBaseId) {
|
|
230
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
231
|
-
return client.context.cancelBuild();
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Run an incremental refresh: re-check sources and apply what changed
|
|
235
|
-
*/ export async function refreshKnowledgeBase(knowledgeBaseId) {
|
|
236
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
237
|
-
return client.context.refresh();
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Get an async job (build, import) by ID
|
|
241
|
-
*/ export async function getJob(knowledgeBaseId, jobId) {
|
|
242
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
243
|
-
return client.context.jobs.get({
|
|
244
|
-
jobId
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* List all issues for a knowledge base, optionally narrowed to one status
|
|
249
|
-
*/ export async function listIssues(knowledgeBaseId, status) {
|
|
250
|
-
const client = await getContextStoreClient(knowledgeBaseId);
|
|
251
|
-
return client.context.issues.list({
|
|
252
|
-
status
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Get a single issue by ID, or `null` when it does not exist
|
|
257
|
-
*/ export async function getIssue(knowledgeBaseId, issueId) {
|
|
258
|
-
const client = await getContextStoreClient(knowledgeBaseId);
|
|
259
|
-
return client.context.issues.get({
|
|
260
|
-
issueId
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Resolve a conflict issue by choosing one of its sides (by index). Choosing
|
|
265
|
-
* a side other than the entry's current content starts a rewrite job.
|
|
266
|
-
*/ export async function resolveIssue(knowledgeBaseId, issueId, resolution) {
|
|
267
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
268
|
-
return client.context.issues.resolve({
|
|
269
|
-
issueId,
|
|
270
|
-
resolution
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Dismiss an issue
|
|
275
|
-
*/ export async function dismissIssue(knowledgeBaseId, issueId) {
|
|
276
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
277
|
-
return client.context.issues.dismiss({
|
|
278
|
-
issueId
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Reopen a resolved conflict issue
|
|
283
|
-
*/ export async function reopenIssue(knowledgeBaseId, issueId) {
|
|
284
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
285
|
-
return client.context.issues.reopen({
|
|
286
|
-
issueId
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Apply accepted issues to a knowledge base in one batch
|
|
291
|
-
*/ export async function applyIssues(knowledgeBaseId, issueIds) {
|
|
292
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
293
|
-
return client.context.issues.apply({
|
|
294
|
-
issueIds
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* List all entries for a knowledge base, path-ordered, without bodies
|
|
299
|
-
*/ export async function listEntries(knowledgeBaseId) {
|
|
300
|
-
const client = await getContextStoreClient(knowledgeBaseId);
|
|
301
|
-
return client.context.entries.list();
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Get a single entry with its body and citations by outline path, or `null`
|
|
305
|
-
* when no entry sits at that path
|
|
306
|
-
*/ export async function getEntry(knowledgeBaseId, path) {
|
|
307
|
-
const client = await getContextStoreClient(knowledgeBaseId);
|
|
308
|
-
return client.context.entries.get({
|
|
309
|
-
path
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Rebuild one entry from its sources by outline path
|
|
314
|
-
*/ export async function rebuildEntry(knowledgeBaseId, path) {
|
|
315
|
-
const client = await getContextClient(knowledgeBaseId);
|
|
316
|
-
return client.context.entries.rebuild({
|
|
317
|
-
path
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Run a GROQ query against an organization's Context documents
|
|
322
|
-
*/ export async function queryContext(organizationId, query, params) {
|
|
323
|
-
const client = await getContextClient(undefined, organizationId);
|
|
324
|
-
return client.context.fetch(query, params);
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* List an organization's MCP endpoints, oldest first
|
|
328
|
-
*/ export async function listMcpEndpoints(organizationId) {
|
|
329
|
-
const client = await getContextClient(undefined, organizationId);
|
|
330
|
-
const docs = await client.context.mcpEndpoints.list();
|
|
331
|
-
const connectClient = client.withConfig({
|
|
332
|
-
apiVersion: MCP_CONNECT_API_VERSION
|
|
333
|
-
});
|
|
334
|
-
return docs.map((doc)=>toMcpEndpoint(connectClient, doc));
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Get an MCP endpoint by name or ID, or `null` when the organization has none.
|
|
338
|
-
* Update and delete accept either, so the lookups guarding them must too.
|
|
339
|
-
*/ export async function getMcpEndpoint(organizationId, nameOrId) {
|
|
340
|
-
const client = await getContextClient(undefined, organizationId);
|
|
341
|
-
const doc = await client.context.fetch('*[_type == "sanity.context.mcp" && organizationId == $org && (name == $nameOrId || publicId == $nameOrId)][0]', {
|
|
342
|
-
nameOrId,
|
|
343
|
-
org: organizationId
|
|
344
|
-
});
|
|
345
|
-
return doc && toMcpEndpoint(client.withConfig({
|
|
346
|
-
apiVersion: MCP_CONNECT_API_VERSION
|
|
347
|
-
}), doc);
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* The stored configuration in the shape create and edit return, so every command outputs the
|
|
351
|
-
* same fields. The URL isn't stored, so it is built from the same route and API version.
|
|
352
|
-
*/ function toMcpEndpoint(connectClient, doc) {
|
|
353
|
-
return {
|
|
354
|
-
createdAt: doc._createdAt,
|
|
355
|
-
groqFilter: doc.groqFilter ?? null,
|
|
356
|
-
id: doc.publicId,
|
|
357
|
-
instructions: doc.instructions ?? null,
|
|
358
|
-
name: doc.name,
|
|
359
|
-
organizationId: doc.organizationId,
|
|
360
|
-
sources: doc.sources,
|
|
361
|
-
title: doc.title,
|
|
362
|
-
updatedAt: doc._updatedAt,
|
|
363
|
-
url: connectClient.getUrl(`/context/organizations/${encodeURIComponent(doc.organizationId)}/mcp/${encodeURIComponent(doc.name)}`)
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Create an MCP endpoint
|
|
368
|
-
*/ export async function createMcpEndpoint(organizationId, params) {
|
|
369
|
-
const client = await getContextClient(undefined, organizationId);
|
|
370
|
-
return client.context.mcpEndpoints.create(params);
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Update an MCP endpoint's configuration
|
|
374
|
-
*/ export async function updateMcpEndpoint(organizationId, name, params) {
|
|
375
|
-
const client = await getContextClient(undefined, organizationId);
|
|
376
|
-
return client.context.mcpEndpoints.edit({
|
|
377
|
-
...params,
|
|
378
|
-
name
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Delete an MCP endpoint
|
|
383
|
-
*/ export async function deleteMcpEndpoint(organizationId, name) {
|
|
384
|
-
const client = await getContextClient(undefined, organizationId);
|
|
385
|
-
await client.context.mcpEndpoints.delete({
|
|
386
|
-
name
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Check whether an agent connecting with the current credentials can use an MCP endpoint
|
|
391
|
-
*/ export async function getMcpEndpointStatus(organizationId, name) {
|
|
392
|
-
const client = await getContextClient(undefined, organizationId);
|
|
393
|
-
return client.context.mcpEndpoints.status({
|
|
394
|
-
name
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
370
|
|
|
398
371
|
//# sourceMappingURL=context.js.map
|