@sanity/cli 8.27.0 → 8.28.1

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.
Files changed (138) hide show
  1. package/README.md +1515 -408
  2. package/dist/actions/context/commandTable.js +215 -0
  3. package/dist/actions/context/commandTable.js.map +1 -0
  4. package/dist/actions/context/contextCommand.js +246 -0
  5. package/dist/actions/context/contextCommand.js.map +1 -0
  6. package/dist/actions/context/contextSpec.js +18 -0
  7. package/dist/actions/context/contextSpec.js.map +1 -0
  8. package/dist/actions/context/distillContextOperations.js +335 -0
  9. package/dist/actions/context/distillContextOperations.js.map +1 -0
  10. package/dist/actions/context/mcpEndpoint.js.map +1 -1
  11. package/dist/actions/context/operationInput.js +226 -0
  12. package/dist/actions/context/operationInput.js.map +1 -0
  13. package/dist/actions/context/operationTypes.js +3 -0
  14. package/dist/actions/context/operationTypes.js.map +1 -0
  15. package/dist/actions/context/removedCommands.js +26 -0
  16. package/dist/actions/context/removedCommands.js.map +1 -0
  17. package/dist/actions/context/renderOperationResult.js +72 -0
  18. package/dist/actions/context/renderOperationResult.js.map +1 -0
  19. package/dist/actions/context/sourceFile.js +31 -0
  20. package/dist/actions/context/sourceFile.js.map +1 -0
  21. package/dist/actions/context/syncOutput.js +17 -0
  22. package/dist/actions/context/syncOutput.js.map +1 -0
  23. package/dist/actions/context/table.js +13 -0
  24. package/dist/actions/context/table.js.map +1 -0
  25. package/dist/actions/context/waitForJob.js.map +1 -1
  26. package/dist/actions/context/waitForSourceSync.js +48 -0
  27. package/dist/actions/context/waitForSourceSync.js.map +1 -0
  28. package/dist/actions/context/watchJob.js.map +1 -1
  29. package/dist/actions/context/watchSourceSync.js +40 -0
  30. package/dist/actions/context/watchSourceSync.js.map +1 -0
  31. package/dist/actions/dev/servers/startStudioDevServer.js +4 -1
  32. package/dist/actions/dev/servers/startStudioDevServer.js.map +1 -1
  33. package/dist/commands/context/build.js +19 -81
  34. package/dist/commands/context/build.js.map +1 -1
  35. package/dist/commands/context/create.js +3 -90
  36. package/dist/commands/context/create.js.map +1 -1
  37. package/dist/commands/context/delete.js +3 -73
  38. package/dist/commands/context/delete.js.map +1 -1
  39. package/dist/commands/context/documents/content.js +117 -0
  40. package/dist/commands/context/documents/content.js.map +1 -0
  41. package/dist/commands/context/documents/delete.js +5 -0
  42. package/dist/commands/context/documents/delete.js.map +1 -0
  43. package/dist/commands/context/documents/edit.js +5 -0
  44. package/dist/commands/context/documents/edit.js.map +1 -0
  45. package/dist/commands/context/documents/get.js +5 -0
  46. package/dist/commands/context/documents/get.js.map +1 -0
  47. package/dist/commands/context/documents/list.js +5 -0
  48. package/dist/commands/context/documents/list.js.map +1 -0
  49. package/dist/commands/context/entries/list.js +2 -2
  50. package/dist/commands/context/entries/list.js.map +1 -1
  51. package/dist/commands/context/entries/rebuild.js +3 -93
  52. package/dist/commands/context/entries/rebuild.js.map +1 -1
  53. package/dist/commands/context/get.js +3 -88
  54. package/dist/commands/context/get.js.map +1 -1
  55. package/dist/commands/context/instructions/create.js +5 -0
  56. package/dist/commands/context/instructions/create.js.map +1 -0
  57. package/dist/commands/context/instructions/delete.js +5 -0
  58. package/dist/commands/context/instructions/delete.js.map +1 -0
  59. package/dist/commands/context/instructions/edit.js +5 -0
  60. package/dist/commands/context/instructions/edit.js.map +1 -0
  61. package/dist/commands/context/issues/apply.js +3 -84
  62. package/dist/commands/context/issues/apply.js.map +1 -1
  63. package/dist/commands/context/issues/dismiss.js +3 -50
  64. package/dist/commands/context/issues/dismiss.js.map +1 -1
  65. package/dist/commands/context/issues/reopen.js +3 -51
  66. package/dist/commands/context/issues/reopen.js.map +1 -1
  67. package/dist/commands/context/issues/resolve.js +23 -92
  68. package/dist/commands/context/issues/resolve.js.map +1 -1
  69. package/dist/commands/context/jobs/get.js +3 -88
  70. package/dist/commands/context/jobs/get.js.map +1 -1
  71. package/dist/commands/context/list.js +3 -95
  72. package/dist/commands/context/list.js.map +1 -1
  73. package/dist/commands/context/mcp/initial-context.js +5 -0
  74. package/dist/commands/context/mcp/initial-context.js.map +1 -0
  75. package/dist/commands/context/mcp/list.js +2 -2
  76. package/dist/commands/context/mcp/list.js.map +1 -1
  77. package/dist/commands/context/mcp/status.js.map +1 -1
  78. package/dist/commands/context/mcp/update.js.map +1 -1
  79. package/dist/commands/context/sources/create.js +175 -0
  80. package/dist/commands/context/sources/create.js.map +1 -0
  81. package/dist/commands/context/sources/delete.js +5 -0
  82. package/dist/commands/context/sources/delete.js.map +1 -0
  83. package/dist/commands/context/sources/edit.js +29 -0
  84. package/dist/commands/context/sources/edit.js.map +1 -0
  85. package/dist/commands/context/sources/get.js +5 -0
  86. package/dist/commands/context/sources/get.js.map +1 -0
  87. package/dist/commands/context/sources/list.js +5 -0
  88. package/dist/commands/context/sources/list.js.map +1 -0
  89. package/dist/commands/context/sources/sync.js +5 -0
  90. package/dist/commands/context/sources/sync.js.map +1 -0
  91. package/dist/commands/context/sources/syncs/confirm.js +5 -0
  92. package/dist/commands/context/sources/syncs/confirm.js.map +1 -0
  93. package/dist/commands/context/sources/syncs/discard.js +5 -0
  94. package/dist/commands/context/sources/syncs/discard.js.map +1 -0
  95. package/dist/commands/context/sources/syncs/get.js +5 -0
  96. package/dist/commands/context/sources/syncs/get.js.map +1 -0
  97. package/dist/commands/context/sources/syncs/list.js +5 -0
  98. package/dist/commands/context/sources/syncs/list.js.map +1 -0
  99. package/dist/commands/context/sources/upload.js +63 -0
  100. package/dist/commands/context/sources/upload.js.map +1 -0
  101. package/dist/commands/context/sync.js +5 -0
  102. package/dist/commands/context/sync.js.map +1 -0
  103. package/dist/commands/context/update.js +3 -136
  104. package/dist/commands/context/update.js.map +1 -1
  105. package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js +41 -26
  106. package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js.map +1 -1
  107. package/dist/generated/apiRoutes.js +28 -0
  108. package/dist/generated/apiRoutes.js.map +1 -1
  109. package/dist/generated/contextOperations.js +1116 -0
  110. package/dist/generated/contextOperations.js.map +1 -0
  111. package/dist/hooks/commandNotFound/topicAliases.js +8 -2
  112. package/dist/hooks/commandNotFound/topicAliases.js.map +1 -1
  113. package/dist/services/context.js +241 -268
  114. package/dist/services/context.js.map +1 -1
  115. package/dist/util/telemetry/cliCommandIdentity.js +10 -18
  116. package/dist/util/telemetry/cliCommandIdentity.js.map +1 -1
  117. package/oclif.manifest.json +3380 -1910
  118. package/package.json +24 -23
  119. package/templates/app-quickstart/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  120. package/templates/app-quickstart/AGENTS.md +49 -0
  121. package/templates/app-sanity-ui/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  122. package/templates/app-sanity-ui/AGENTS.md +49 -0
  123. package/templates/shared/dashboard/app-quickstart/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  124. package/templates/shared/dashboard/app-quickstart/AGENTS.md +49 -0
  125. package/templates/shared/dashboard/app-sanity-ui/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  126. package/templates/shared/dashboard/app-sanity-ui/AGENTS.md +49 -0
  127. package/dist/commands/context/imports/create.js +0 -270
  128. package/dist/commands/context/imports/create.js.map +0 -1
  129. package/dist/commands/context/imports/delete.js +0 -73
  130. package/dist/commands/context/imports/delete.js.map +0 -1
  131. package/dist/commands/context/imports/download.js +0 -60
  132. package/dist/commands/context/imports/download.js.map +0 -1
  133. package/dist/commands/context/imports/get.js +0 -88
  134. package/dist/commands/context/imports/get.js.map +0 -1
  135. package/dist/commands/context/imports/list.js +0 -100
  136. package/dist/commands/context/imports/list.js.map +0 -1
  137. package/dist/commands/context/refresh.js +0 -46
  138. package/dist/commands/context/refresh.js.map +0 -1
@@ -1,111 +1,42 @@
1
- import { Args, Flags } from '@oclif/core';
2
- import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
- import { getErrorMessage } from '@sanity/cli-core/errors';
1
+ import { Flags } from '@oclif/core';
2
+ import { exitCodes } from '@sanity/cli-core';
4
3
  import { requiredWhenUnattended } from '@sanity/cli-core/flags';
5
4
  import { select } from '@sanity/cli-core/ux';
6
- import { isHttpError } from '@sanity/client';
7
- import { formatJobFailure, watchJob } from '../../../actions/context/watchJob.js';
8
- import { formatKeyValue } from '../../../actions/debug/output.js';
9
- import { getIssue, resolveIssue } from '../../../services/context.js';
10
- const resolveIssueDebug = subdebug('context:issues:resolve');
11
- export class ResolveIssueCommand extends SanityCommand {
12
- static args = {
13
- knowledgeBaseId: Args.string({
14
- description: 'Knowledge base ID',
15
- required: true
16
- }),
17
- // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first
18
- issueId: Args.string({
19
- description: 'Issue ID',
20
- required: true
21
- })
22
- };
23
- static description = 'Resolve a conflict issue by choosing the correct side\n\nResolving also creates a standing instruction that future builds follow. `sanity context issues reopen` removes it.';
5
+ import { contextCommand } from '../../../actions/context/contextCommand.js';
6
+ import { getIssue } from '../../../services/context.js';
7
+ const BaseCommand = contextCommand('context issues resolve');
8
+ /**
9
+ * `context issues resolve` keeps `--side`, and without it, asks which side of
10
+ * the conflict is correct, listing the sides from the issue document
11
+ */ export class ResolveIssueCommand extends BaseCommand {
24
12
  static examples = [
25
13
  {
26
- command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456',
27
- description: 'Interactively choose the correct side of a conflict'
28
- },
29
- {
30
- command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456 --side 1 --watch',
31
- description: 'Choose side 1 and wait for the entry to be rewritten'
14
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 issue-def456',
15
+ description: 'Choose the correct side interactively'
32
16
  },
33
17
  {
34
- command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456 --side 0',
35
- description: 'Keep the entry as it is (for a conflict on a single entry)'
18
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 issue-def456 --side 1 --watch',
19
+ description: 'Choose side 1 and wait for the entry rewrite'
36
20
  }
37
21
  ];
38
22
  static flags = {
23
+ ...BaseCommand.flags,
39
24
  side: requiredWhenUnattended(Flags.integer({
40
25
  description: 'Index of the correct side, as listed by `sanity context issues get`',
41
26
  min: 0
42
- })),
43
- watch: Flags.boolean({
44
- default: false,
45
- description: 'Wait for the entry rewrite to finish, exiting non-zero if it fails'
46
- })
27
+ }))
47
28
  };
48
- async run() {
49
- const { issueId, knowledgeBaseId } = this.args;
50
- const { side: sideFlag, watch } = this.flags;
51
- const side = sideFlag ?? await this.promptForSide(knowledgeBaseId, issueId);
52
- let resolved;
53
- try {
54
- resolved = await resolveIssue(knowledgeBaseId, issueId, side);
55
- } catch (error) {
56
- resolveIssueDebug('Error resolving issue', error);
57
- if (isHttpError(error) && error.statusCode === 404) {
58
- this.error(`Issue "${issueId}" not found on knowledge base "${knowledgeBaseId}"`, {
59
- exit: exitCodes.RUNTIME_ERROR
60
- });
29
+ async send(request, values) {
30
+ const side = typeof values.side === 'number' ? values.side : await this.promptForSide(request.params.knowledgeBaseId, request.params.issueId);
31
+ return super.send({
32
+ ...request,
33
+ body: {
34
+ resolution: side
61
35
  }
62
- this.error(`Failed to resolve issue: ${getErrorMessage(error)}`, {
63
- exit: exitCodes.RUNTIME_ERROR
64
- });
65
- }
66
- this.log('Issue resolved');
67
- const { jobId } = resolved;
68
- if (jobId === null) {
69
- return;
70
- }
71
- this.log(formatKeyValue('Job ID', jobId));
72
- this.log(`Track it with: sanity context jobs get ${knowledgeBaseId} ${jobId}`);
73
- if (!watch) {
74
- return;
75
- }
76
- let job;
77
- try {
78
- job = await watchJob(knowledgeBaseId, jobId, {
79
- label: 'Rewriting entry',
80
- successText: 'Entry rewritten'
81
- });
82
- } catch (error) {
83
- resolveIssueDebug('Error watching rewrite job', error);
84
- this.error(`Failed to watch rewrite job: ${getErrorMessage(error)}`, {
85
- exit: exitCodes.RUNTIME_ERROR
86
- });
87
- }
88
- if (job.status !== 'succeeded') {
89
- this.error(formatJobFailure('Rewrite', job), {
90
- exit: exitCodes.RUNTIME_ERROR
91
- });
92
- }
36
+ }, values);
93
37
  }
94
38
  async promptForSide(knowledgeBaseId, issueId) {
95
- let issue;
96
- try {
97
- issue = await getIssue(knowledgeBaseId, issueId);
98
- } catch (error) {
99
- resolveIssueDebug('Error getting issue', error);
100
- if (isHttpError(error) && error.statusCode === 404) {
101
- this.error(`Knowledge base "${knowledgeBaseId}" not found`, {
102
- exit: exitCodes.RUNTIME_ERROR
103
- });
104
- }
105
- this.error(`Failed to get issue: ${getErrorMessage(error)}`, {
106
- exit: exitCodes.RUNTIME_ERROR
107
- });
108
- }
39
+ const issue = await getIssue(knowledgeBaseId, issueId);
109
40
  if (!issue) {
110
41
  this.error(`Issue "${issueId}" not found on knowledge base "${knowledgeBaseId}"`, {
111
42
  exit: exitCodes.RUNTIME_ERROR
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/commands/context/issues/resolve.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {requiredWhenUnattended} from '@sanity/cli-core/flags'\nimport {select} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatJobFailure, watchJob} from '../../../actions/context/watchJob.js'\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {getIssue, resolveIssue} from '../../../services/context.js'\n\nconst resolveIssueDebug = subdebug('context:issues:resolve')\n\nexport class ResolveIssueCommand extends SanityCommand<typeof ResolveIssueCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first\n issueId: Args.string({\n description: 'Issue ID',\n required: true,\n }),\n }\n\n static override description =\n 'Resolve a conflict issue by choosing the correct side\\n\\nResolving also creates a standing instruction that future builds follow. `sanity context issues reopen` removes it.'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456',\n description: 'Interactively choose the correct side of a conflict',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456 --side 1 --watch',\n description: 'Choose side 1 and wait for the entry to be rewritten',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456 --side 0',\n description: 'Keep the entry as it is (for a conflict on a single entry)',\n },\n ]\n\n static override flags = {\n side: requiredWhenUnattended(\n Flags.integer({\n description: 'Index of the correct side, as listed by `sanity context issues get`',\n min: 0,\n }),\n ),\n watch: Flags.boolean({\n default: false,\n description: 'Wait for the entry rewrite to finish, exiting non-zero if it fails',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {issueId, knowledgeBaseId} = this.args\n const {side: sideFlag, watch} = this.flags\n\n const side = sideFlag ?? (await this.promptForSide(knowledgeBaseId, issueId))\n\n let resolved\n try {\n resolved = await resolveIssue(knowledgeBaseId, issueId, side)\n } catch (error) {\n resolveIssueDebug('Error resolving issue', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Issue \"${issueId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to resolve issue: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n this.log('Issue resolved')\n\n const {jobId} = resolved\n if (jobId === null) {\n return\n }\n\n this.log(formatKeyValue('Job ID', jobId))\n this.log(`Track it with: sanity context jobs get ${knowledgeBaseId} ${jobId}`)\n\n if (!watch) {\n return\n }\n\n let job\n try {\n job = await watchJob(knowledgeBaseId, jobId, {\n label: 'Rewriting entry',\n successText: 'Entry rewritten',\n })\n } catch (error) {\n resolveIssueDebug('Error watching rewrite job', error)\n this.error(`Failed to watch rewrite job: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (job.status !== 'succeeded') {\n this.error(formatJobFailure('Rewrite', job), {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n private async promptForSide(knowledgeBaseId: string, issueId: string): Promise<number> {\n let issue\n try {\n issue = await getIssue(knowledgeBaseId, issueId)\n } catch (error) {\n resolveIssueDebug('Error getting issue', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Knowledge base \"${knowledgeBaseId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to get issue: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (!issue) {\n this.error(`Issue \"${issueId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (issue.status === 'rejected') {\n this.error(`Issue \"${issueId}\" is rejected (dismissed) and cannot be resolved`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n const {content} = issue\n if (content.kind !== 'conflict') {\n this.error(`Only conflict issues can be resolved, \"${issueId}\" is of kind ${content.kind}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n return select({\n choices: content.sides.map((side, index) => ({\n name: `[${index}] ${side.claim}`,\n value: index,\n })),\n // Re-resolving keeps the current choice preselected, so Enter can't flip it\n default: issue.resolution ?? content.suggested,\n message: 'Which side is correct?',\n })\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","requiredWhenUnattended","select","isHttpError","formatJobFailure","watchJob","formatKeyValue","getIssue","resolveIssue","resolveIssueDebug","ResolveIssueCommand","args","knowledgeBaseId","string","description","required","issueId","examples","command","flags","side","integer","min","watch","boolean","default","run","sideFlag","promptForSide","resolved","error","statusCode","exit","RUNTIME_ERROR","log","jobId","job","label","successText","status","issue","content","kind","choices","sides","map","index","name","claim","value","resolution","suggested","message"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD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gB,WAAW,CAAC,EAAE;oBAC1DoB,MAAMnC,UAAUoC,aAAa;gBAC/B;YACF;YACA,IAAI,CAACH,KAAK,CAAC,CAAC,qBAAqB,EAAE9B,gBAAgB8B,QAAQ,EAAE;gBAC3DE,MAAMnC,UAAUoC,aAAa;YAC/B;QACF;QAEA,IAAI,CAACO,OAAO;YACV,IAAI,CAACV,KAAK,CAAC,CAAC,OAAO,EAAEd,QAAQ,+BAA+B,EAAEJ,gBAAgB,CAAC,CAAC,EAAE;gBAChFoB,MAAMnC,UAAUoC,aAAa;YAC/B;QACF;QAEA,IAAIO,MAAMD,MAAM,KAAK,YAAY;YAC/B,IAAI,CAACT,KAAK,CAAC,CAAC,OAAO,EAAEd,QAAQ,gDAAgD,CAAC,EAAE;gBAC9EgB,MAAMnC,UAAUoC,aAAa;YAC/B;QACF;QAEA,MAAM,EAACQ,OAAO,EAAC,GAAGD;QAClB,IAAIC,QAAQC,IAAI,KAAK,YAAY;YAC/B,IAAI,CAACZ,KAAK,CAAC,CAAC,uCAAuC,EAAEd,QAAQ,aAAa,EAAEyB,QAAQC,IAAI,EAAE,EAAE;gBAC1FV,MAAMnC,UAAUoC,aAAa;YAC/B;QACF;QAEA,OAAO/B,OAAO;YACZyC,SAASF,QAAQG,KAAK,CAACC,GAAG,CAAC,CAACzB,MAAM0B,QAAW,CAAA;oBAC3CC,MAAM,CAAC,CAAC,EAAED,MAAM,EAAE,EAAE1B,KAAK4B,KAAK,EAAE;oBAChCC,OAAOH;gBACT,CAAA;YACA,4EAA4E;YAC5ErB,SAASe,MAAMU,UAAU,IAAIT,QAAQU,SAAS;YAC9CC,SAAS;QACX;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../src/commands/context/issues/resolve.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes} from '@sanity/cli-core'\nimport {requiredWhenUnattended} from '@sanity/cli-core/flags'\nimport {select} from '@sanity/cli-core/ux'\n\nimport {contextCommand} from '../../../actions/context/contextCommand.js'\nimport {type OperationRequest} from '../../../actions/context/operationInput.js'\nimport {getIssue} from '../../../services/context.js'\n\nconst BaseCommand = contextCommand('context issues resolve')\n\n/**\n * `context issues resolve` keeps `--side`, and without it, asks which side of\n * the conflict is correct, listing the sides from the issue document\n */\nexport class ResolveIssueCommand extends BaseCommand {\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 issue-def456',\n description: 'Choose the correct side interactively',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 issue-def456 --side 1 --watch',\n description: 'Choose side 1 and wait for the entry rewrite',\n },\n ]\n\n static override flags = {\n ...BaseCommand.flags,\n side: requiredWhenUnattended(\n Flags.integer({\n description: 'Index of the correct side, as listed by `sanity context issues get`',\n min: 0,\n }),\n ),\n } satisfies FlagInput\n\n public override async send(\n request: OperationRequest,\n values: Record<string, unknown>,\n ): Promise<unknown> {\n const side =\n typeof values.side === 'number'\n ? values.side\n : await this.promptForSide(request.params.knowledgeBaseId, request.params.issueId)\n return super.send({...request, body: {resolution: side}}, values)\n }\n\n private async promptForSide(knowledgeBaseId: string, issueId: string): Promise<number> {\n const issue = await getIssue(knowledgeBaseId, issueId)\n if (!issue) {\n this.error(`Issue \"${issueId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n if (issue.status === 'rejected') {\n this.error(`Issue \"${issueId}\" is rejected (dismissed) and cannot be resolved`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n const {content} = issue\n if (content.kind !== 'conflict') {\n this.error(`Only conflict issues can be resolved, \"${issueId}\" is of kind ${content.kind}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n return select({\n choices: content.sides.map((side, index) => ({\n name: `[${index}] ${side.claim}`,\n value: index,\n })),\n // Re-resolving keeps the current choice preselected, so Enter can't flip it\n default: issue.resolution ?? content.suggested,\n message: 'Which side is correct?',\n })\n }\n}\n"],"names":["Flags","exitCodes","requiredWhenUnattended","select","contextCommand","getIssue","BaseCommand","ResolveIssueCommand","examples","command","description","flags","side","integer","min","send","request","values","promptForSide","params","knowledgeBaseId","issueId","body","resolution","issue","error","exit","RUNTIME_ERROR","status","content","kind","choices","sides","map","index","name","claim","value","default","suggested","message"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AAEjC,SAAQC,SAAS,QAAO,mBAAkB;AAC1C,SAAQC,sBAAsB,QAAO,yBAAwB;AAC7D,SAAQC,MAAM,QAAO,sBAAqB;AAE1C,SAAQC,cAAc,QAAO,6CAA4C;AAEzE,SAAQC,QAAQ,QAAO,+BAA8B;AAErD,MAAMC,cAAcF,eAAe;AAEnC;;;CAGC,GACD,OAAO,MAAMG,4BAA4BD;IACvC,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTC,aAAa;QACf;QACA;YACED,SAAS;YACTC,aAAa;QACf;KACD,CAAA;IAED,OAAgBC,QAAQ;QACtB,GAAGL,YAAYK,KAAK;QACpBC,MAAMV,uBACJF,MAAMa,OAAO,CAAC;YACZH,aAAa;YACbI,KAAK;QACP;IAEJ,EAAqB;IAErB,MAAsBC,KACpBC,OAAyB,EACzBC,MAA+B,EACb;QAClB,MAAML,OACJ,OAAOK,OAAOL,IAAI,KAAK,WACnBK,OAAOL,IAAI,GACX,MAAM,IAAI,CAACM,aAAa,CAACF,QAAQG,MAAM,CAACC,eAAe,EAAEJ,QAAQG,MAAM,CAACE,OAAO;QACrF,OAAO,KAAK,CAACN,KAAK;YAAC,GAAGC,OAAO;YAAEM,MAAM;gBAACC,YAAYX;YAAI;QAAC,GAAGK;IAC5D;IAEA,MAAcC,cAAcE,eAAuB,EAAEC,OAAe,EAAmB;QACrF,MAAMG,QAAQ,MAAMnB,SAASe,iBAAiBC;QAC9C,IAAI,CAACG,OAAO;YACV,IAAI,CAACC,KAAK,CAAC,CAAC,OAAO,EAAEJ,QAAQ,+BAA+B,EAAED,gBAAgB,CAAC,CAAC,EAAE;gBAChFM,MAAMzB,UAAU0B,aAAa;YAC/B;QACF;QACA,IAAIH,MAAMI,MAAM,KAAK,YAAY;YAC/B,IAAI,CAACH,KAAK,CAAC,CAAC,OAAO,EAAEJ,QAAQ,gDAAgD,CAAC,EAAE;gBAC9EK,MAAMzB,UAAU0B,aAAa;YAC/B;QACF;QACA,MAAM,EAACE,OAAO,EAAC,GAAGL;QAClB,IAAIK,QAAQC,IAAI,KAAK,YAAY;YAC/B,IAAI,CAACL,KAAK,CAAC,CAAC,uCAAuC,EAAEJ,QAAQ,aAAa,EAAEQ,QAAQC,IAAI,EAAE,EAAE;gBAC1FJ,MAAMzB,UAAU0B,aAAa;YAC/B;QACF;QACA,OAAOxB,OAAO;YACZ4B,SAASF,QAAQG,KAAK,CAACC,GAAG,CAAC,CAACrB,MAAMsB,QAAW,CAAA;oBAC3CC,MAAM,CAAC,CAAC,EAAED,MAAM,EAAE,EAAEtB,KAAKwB,KAAK,EAAE;oBAChCC,OAAOH;gBACT,CAAA;YACA,4EAA4E;YAC5EI,SAASd,MAAMD,UAAU,IAAIM,QAAQU,SAAS;YAC9CC,SAAS;QACX;IACF;AACF"}
@@ -1,90 +1,5 @@
1
- import { Args, Flags } from '@oclif/core';
2
- import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
- import { getErrorMessage, JsonOutputError } from '@sanity/cli-core/errors';
4
- import { isHttpError } from '@sanity/client';
5
- import { formatJobFailure, watchJob } from '../../../actions/context/watchJob.js';
6
- import { formatKeyValue } from '../../../actions/debug/output.js';
7
- import { getJob } from '../../../services/context.js';
8
- const getJobDebug = subdebug('context:jobs:get');
9
- export class GetJobCommand extends SanityCommand {
10
- static args = {
11
- knowledgeBaseId: Args.string({
12
- description: 'Knowledge base ID',
13
- required: true
14
- }),
15
- // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first
16
- jobId: Args.string({
17
- description: 'Job ID',
18
- required: true
19
- })
20
- };
21
- static description = 'Get the status of a knowledge base job';
22
- static enableJsonFlag = true;
23
- static examples = [
24
- {
25
- command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456',
26
- description: 'Get the current status of a job'
27
- },
28
- {
29
- command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456 --watch',
30
- description: 'Wait for the job to finish (non-zero exit if it does not succeed)'
31
- }
32
- ];
33
- static flags = {
34
- watch: Flags.boolean({
35
- default: false,
36
- description: 'Poll until the job reaches a terminal state'
37
- })
38
- };
39
- async run() {
40
- const { jobId, knowledgeBaseId } = this.args;
41
- const { json, watch } = this.flags;
42
- let job;
43
- try {
44
- job = watch ? await watchJob(knowledgeBaseId, jobId, {
45
- label: 'Waiting for job'
46
- }) : await getJob(knowledgeBaseId, jobId);
47
- } catch (error) {
48
- getJobDebug('Error getting job', error);
49
- if (isHttpError(error) && error.statusCode === 404) {
50
- this.error(`Job "${jobId}" not found on knowledge base "${knowledgeBaseId}"`, {
51
- exit: exitCodes.RUNTIME_ERROR
52
- });
53
- }
54
- this.error(`Failed to get job: ${getErrorMessage(error)}`, {
55
- exit: exitCodes.RUNTIME_ERROR
56
- });
57
- }
58
- const jobFailed = watch && job.status !== 'succeeded';
59
- const failureMessage = formatJobFailure('Job', job);
60
- if (json) {
61
- if (jobFailed) throw new JsonOutputError(failureMessage, job, exitCodes.RUNTIME_ERROR);
62
- this.logJson(job);
63
- } else {
64
- const padTo = 9 // "Completed" is the longest key
65
- ;
66
- this.log(formatKeyValue('ID', job.id, {
67
- padTo
68
- }));
69
- this.log(formatKeyValue('Status', job.status, {
70
- padTo
71
- }));
72
- this.log(formatKeyValue('Started', job.startedAt ?? '-', {
73
- padTo
74
- }));
75
- this.log(formatKeyValue('Completed', job.completedAt ?? '-', {
76
- padTo
77
- }));
78
- this.log(formatKeyValue('Error', job.error ?? '-', {
79
- padTo
80
- }));
81
- }
82
- if (jobFailed) {
83
- this.error(failureMessage, {
84
- exit: exitCodes.RUNTIME_ERROR
85
- });
86
- }
87
- }
88
- }
1
+ // GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands
2
+ import { contextCommand } from '../../../actions/context/contextCommand.js';
3
+ export const GetJobCommand = contextCommand('context jobs get');
89
4
 
90
5
  //# sourceMappingURL=get.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/commands/context/jobs/get.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage, JsonOutputError} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatJobFailure, watchJob} from '../../../actions/context/watchJob.js'\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {getJob} from '../../../services/context.js'\n\nconst getJobDebug = subdebug('context:jobs:get')\n\nexport class GetJobCommand extends SanityCommand<typeof GetJobCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first\n jobId: Args.string({\n description: 'Job ID',\n required: true,\n }),\n }\n\n static override description = 'Get the status of a knowledge base job'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456',\n description: 'Get the current status of a job',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456 --watch',\n description: 'Wait for the job to finish (non-zero exit if it does not succeed)',\n },\n ]\n\n static override flags = {\n watch: Flags.boolean({\n default: false,\n description: 'Poll until the job reaches a terminal state',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {jobId, knowledgeBaseId} = this.args\n const {json, watch} = this.flags\n\n let job\n try {\n job = watch\n ? await watchJob(knowledgeBaseId, jobId, {label: 'Waiting for job'})\n : await getJob(knowledgeBaseId, jobId)\n } catch (error) {\n getJobDebug('Error getting job', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Job \"${jobId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to get job: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n const jobFailed = watch && job.status !== 'succeeded'\n const failureMessage = formatJobFailure('Job', job)\n if (json) {\n if (jobFailed) throw new JsonOutputError(failureMessage, job, exitCodes.RUNTIME_ERROR)\n this.logJson(job)\n } else {\n const padTo = 9 // \"Completed\" is the longest key\n this.log(formatKeyValue('ID', job.id, {padTo}))\n this.log(formatKeyValue('Status', job.status, {padTo}))\n this.log(formatKeyValue('Started', job.startedAt ?? '-', {padTo}))\n this.log(formatKeyValue('Completed', job.completedAt ?? '-', {padTo}))\n this.log(formatKeyValue('Error', job.error ?? '-', {padTo}))\n }\n\n if (jobFailed) {\n this.error(failureMessage, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","JsonOutputError","isHttpError","formatJobFailure","watchJob","formatKeyValue","getJob","getJobDebug","GetJobCommand","args","knowledgeBaseId","string","description","required","jobId","enableJsonFlag","examples","command","flags","watch","boolean","default","run","json","job","label","error","statusCode","exit","RUNTIME_ERROR","jobFailed","status","failureMessage","logJson","padTo","log","id","startedAt","completedAt"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,EAAEC,eAAe,QAAO,0BAAyB;AACxE,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,gBAAgB,EAAEC,QAAQ,QAAO,uCAAsC;AAC/E,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,MAAM,QAAO,+BAA8B;AAEnD,MAAMC,cAAcR,SAAS;AAE7B,OAAO,MAAMS,sBAAsBV;IACjC,OAAgBW,OAAO;QACrBC,iBAAiBf,KAAKgB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ACrF,IAAI,CAACI,OAAO,CAACT;QACf,OAAO;YACL,MAAMU,QAAQ,EAAE,iCAAiC;;YACjD,IAAI,CAACC,GAAG,CAAC9B,eAAe,MAAMmB,IAAIY,EAAE,EAAE;gBAACF;YAAK;YAC5C,IAAI,CAACC,GAAG,CAAC9B,eAAe,UAAUmB,IAAIO,MAAM,EAAE;gBAACG;YAAK;YACpD,IAAI,CAACC,GAAG,CAAC9B,eAAe,WAAWmB,IAAIa,SAAS,IAAI,KAAK;gBAACH;YAAK;YAC/D,IAAI,CAACC,GAAG,CAAC9B,eAAe,aAAamB,IAAIc,WAAW,IAAI,KAAK;gBAACJ;YAAK;YACnE,IAAI,CAACC,GAAG,CAAC9B,eAAe,SAASmB,IAAIE,KAAK,IAAI,KAAK;gBAACQ;YAAK;QAC3D;QAEA,IAAIJ,WAAW;YACb,IAAI,CAACJ,KAAK,CAACM,gBAAgB;gBACzBJ,MAAM/B,UAAUgC,aAAa;YAC/B;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../src/commands/context/jobs/get.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../../actions/context/contextCommand.js'\n\nexport const GetJobCommand = contextCommand('context jobs get')\n"],"names":["contextCommand","GetJobCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,6CAA4C;AAEzE,OAAO,MAAMC,gBAAgBD,eAAe,oBAAmB"}
@@ -1,97 +1,5 @@
1
- import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
2
- import { getErrorMessage } from '@sanity/cli-core/errors';
3
- import { resolveOrganizationId } from '../../actions/context/resolveOrganizationId.js';
4
- import { listKnowledgeBases } from '../../services/context.js';
5
- import { Table } from '../../util/responsiveTable.js';
6
- import { getOrganizationFlag } from '../../util/sharedFlags.js';
7
- const listContextDebug = subdebug('context:list');
8
- export class ListKnowledgeBasesCommand extends SanityCommand {
9
- static description = 'List knowledge bases in an organization';
10
- static enableJsonFlag = true;
11
- static examples = [
12
- {
13
- command: '<%= config.bin %> <%= command.id %>',
14
- description: 'List knowledge bases, selecting the organization interactively'
15
- },
16
- {
17
- command: '<%= config.bin %> <%= command.id %> --organization org-abc123',
18
- description: 'List knowledge bases in a specific organization'
19
- },
20
- {
21
- command: '<%= config.bin %> <%= command.id %> --organization org-abc123 --json',
22
- description: 'Output knowledge bases as JSON'
23
- }
24
- ];
25
- static flags = {
26
- ...getOrganizationFlag({
27
- description: 'Organization to list knowledge bases for',
28
- semantics: 'override'
29
- })
30
- };
31
- async run() {
32
- const { json, organization } = this.flags;
33
- const organizationId = await resolveOrganizationId({
34
- configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,
35
- flagOrganizationId: organization,
36
- unattended: this.isUnattended()
37
- });
38
- let knowledgeBases;
39
- try {
40
- knowledgeBases = await listKnowledgeBases(organizationId);
41
- } catch (error) {
42
- listContextDebug('Error listing knowledge bases', error);
43
- this.error(`Failed to list knowledge bases: ${getErrorMessage(error)}`, {
44
- exit: exitCodes.RUNTIME_ERROR
45
- });
46
- }
47
- if (json) {
48
- this.logJson(knowledgeBases);
49
- return;
50
- }
51
- if (knowledgeBases.length === 0) {
52
- this.log('No knowledge bases found');
53
- return;
54
- }
55
- const table = new Table({
56
- columns: [
57
- {
58
- alignment: 'left',
59
- name: 'id',
60
- title: 'ID'
61
- },
62
- {
63
- alignment: 'left',
64
- name: 'title',
65
- title: 'Title'
66
- },
67
- {
68
- alignment: 'left',
69
- name: 'state',
70
- title: 'State'
71
- },
72
- {
73
- alignment: 'right',
74
- name: 'openIssues',
75
- title: 'Open issues'
76
- },
77
- {
78
- alignment: 'left',
79
- name: 'updatedAt',
80
- title: 'Updated'
81
- }
82
- ]
83
- });
84
- for (const { openIssueCount, publicId, state, title, updatedAt } of knowledgeBases){
85
- table.addRow({
86
- id: publicId,
87
- openIssues: openIssueCount,
88
- state,
89
- title,
90
- updatedAt
91
- });
92
- }
93
- this.log(table.render());
94
- }
95
- }
1
+ // GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands
2
+ import { contextCommand } from '../../actions/context/contextCommand.js';
3
+ export const ListKnowledgeBasesCommand = contextCommand('context list');
96
4
 
97
5
  //# sourceMappingURL=list.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/context/list.ts"],"sourcesContent":["import {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\n\nimport {resolveOrganizationId} from '../../actions/context/resolveOrganizationId.js'\nimport {listKnowledgeBases} from '../../services/context.js'\nimport {Table} from '../../util/responsiveTable.js'\nimport {getOrganizationFlag} from '../../util/sharedFlags.js'\n\nconst listContextDebug = subdebug('context:list')\n\nexport class ListKnowledgeBasesCommand extends SanityCommand<typeof ListKnowledgeBasesCommand> {\n static override description = 'List knowledge bases in an organization'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List knowledge bases, selecting the organization interactively',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --organization org-abc123',\n description: 'List knowledge bases in a specific organization',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --organization org-abc123 --json',\n description: 'Output knowledge bases as JSON',\n },\n ]\n\n static override flags = {\n ...getOrganizationFlag({\n description: 'Organization to list knowledge bases for',\n semantics: 'override',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {json, organization} = this.flags\n\n const organizationId = await resolveOrganizationId({\n configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,\n flagOrganizationId: organization,\n unattended: this.isUnattended(),\n })\n\n let knowledgeBases\n try {\n knowledgeBases = await listKnowledgeBases(organizationId)\n } catch (error) {\n listContextDebug('Error listing knowledge bases', error)\n this.error(`Failed to list knowledge bases: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(knowledgeBases)\n return\n }\n\n if (knowledgeBases.length === 0) {\n this.log('No knowledge bases found')\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'title', title: 'Title'},\n {alignment: 'left', name: 'state', title: 'State'},\n {alignment: 'right', name: 'openIssues', title: 'Open issues'},\n {alignment: 'left', name: 'updatedAt', title: 'Updated'},\n ],\n })\n\n for (const {openIssueCount, publicId, state, title, updatedAt} of knowledgeBases) {\n table.addRow({id: publicId, openIssues: openIssueCount, state, title, updatedAt})\n }\n\n this.log(table.render())\n }\n}\n"],"names":["exitCodes","SanityCommand","subdebug","getErrorMessage","resolveOrganizationId","listKnowledgeBases","Table","getOrganizationFlag","listContextDebug","ListKnowledgeBasesCommand","description","enableJsonFlag","examples","command","flags","semantics","run","json","organization","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","isUnattended","knowledgeBases","error","exit","RUNTIME_ERROR","logJson","length","log","table","columns","alignment","name","title","openIssueCount","publicId","state","updatedAt","addRow","id","openIssues","render"],"mappings":"AACA,SAAQA,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AAEvD,SAAQC,qBAAqB,QAAO,iDAAgD;AACpF,SAAQC,kBAAkB,QAAO,4BAA2B;AAC5D,SAAQC,KAAK,QAAO,gCAA+B;AACnD,SAAQC,mBAAmB,QAAO,4BAA2B;AAE7D,MAAMC,mBAAmBN,SAAS;AAElC,OAAO,MAAMO,kCAAkCR;IAC7C,OAAgBS,cAAc,0CAAyC;IAEvE,OAAgBC,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtB,GAAGP,oBAAoB;YACrBG,aAAa;YACbK,WA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,MAAMY,MAAM;IACvB;AACF"}
1
+ {"version":3,"sources":["../../../src/commands/context/list.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../actions/context/contextCommand.js'\n\nexport const ListKnowledgeBasesCommand = contextCommand('context list')\n"],"names":["contextCommand","ListKnowledgeBasesCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,0CAAyC;AAEtE,OAAO,MAAMC,4BAA4BD,eAAe,gBAAe"}
@@ -0,0 +1,5 @@
1
+ // GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands
2
+ import { contextCommand } from '../../../actions/context/contextCommand.js';
3
+ export const GetMcpEndpointInitialContextCommand = contextCommand('context mcp initial-context');
4
+
5
+ //# sourceMappingURL=initial-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/mcp/initial-context.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../../actions/context/contextCommand.js'\n\nexport const GetMcpEndpointInitialContextCommand = contextCommand('context mcp initial-context')\n"],"names":["contextCommand","GetMcpEndpointInitialContextCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,6CAA4C;AAEzE,OAAO,MAAMC,sCAAsCD,eAAe,+BAA8B"}
@@ -1,8 +1,8 @@
1
1
  import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
2
2
  import { getErrorMessage } from '@sanity/cli-core/errors';
3
3
  import { resolveOrganizationId } from '../../../actions/context/resolveOrganizationId.js';
4
+ import { contextTable } from '../../../actions/context/table.js';
4
5
  import { listMcpEndpoints } from '../../../services/context.js';
5
- import { Table } from '../../../util/responsiveTable.js';
6
6
  import { getOrganizationFlag } from '../../../util/sharedFlags.js';
7
7
  const listMcpDebug = subdebug('context:mcp:list');
8
8
  export class ListMcpEndpointsCommand extends SanityCommand {
@@ -48,7 +48,7 @@ export class ListMcpEndpointsCommand extends SanityCommand {
48
48
  this.log('No MCP endpoints found');
49
49
  return;
50
50
  }
51
- const table = new Table({
51
+ const table = contextTable({
52
52
  columns: [
53
53
  {
54
54
  alignment: 'left',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/commands/context/mcp/list.ts"],"sourcesContent":["import {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\n\nimport {resolveOrganizationId} from '../../../actions/context/resolveOrganizationId.js'\nimport {listMcpEndpoints} from '../../../services/context.js'\nimport {Table} from '../../../util/responsiveTable.js'\nimport {getOrganizationFlag} from '../../../util/sharedFlags.js'\n\nconst listMcpDebug = subdebug('context:mcp:list')\n\nexport class ListMcpEndpointsCommand extends SanityCommand<typeof ListMcpEndpointsCommand> {\n static override description = 'List Context MCP endpoints in an organization'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List MCP endpoints, selecting the organization interactively',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --organization org-abc123 --json',\n description: 'Output the MCP endpoints of a specific organization as JSON',\n },\n ]\n\n static override flags = {\n ...getOrganizationFlag({\n description: 'Organization to list MCP endpoints for',\n semantics: 'override',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {json, organization} = this.flags\n\n const organizationId = await resolveOrganizationId({\n configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,\n flagOrganizationId: organization,\n unattended: this.isUnattended(),\n })\n\n let endpoints\n try {\n endpoints = await listMcpEndpoints(organizationId)\n } catch (error) {\n listMcpDebug('Error listing MCP endpoints', error)\n this.error(`Failed to list MCP endpoints: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(endpoints)\n return\n }\n\n if (endpoints.length === 0) {\n this.log('No MCP endpoints found')\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'name', title: 'Name'},\n {alignment: 'left', name: 'title', title: 'Title'},\n {alignment: 'left', name: 'sources', title: 'Sources'},\n {alignment: 'left', name: 'url', title: 'URL'},\n ],\n })\n\n for (const {name, sources, title, url} of endpoints) {\n table.addRow({name, sources: sources.map((source) => source.id).join(', '), title, url})\n }\n\n this.log(table.render())\n }\n}\n"],"names":["exitCodes","SanityCommand","subdebug","getErrorMessage","resolveOrganizationId","listMcpEndpoints","Table","getOrganizationFlag","listMcpDebug","ListMcpEndpointsCommand","description","enableJsonFlag","examples","command","flags","semantics","run","json","organization","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","isUnattended","endpoints","error","exit","RUNTIME_ERROR","logJson","length","log","table","columns","alignment","name","title","sources","url","addRow","map","source","id","join","render"],"mappings":"AACA,SAAQA,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AAEvD,SAAQC,qBAAqB,QAAO,oDAAmD;AACvF,SAAQC,gBAAgB,QAAO,+BAA8B;AAC7D,SAAQC,KAAK,QAAO,mCAAkC;AACtD,SAAQC,mBAAmB,QAAO,+BAA8B;AAEhE,MAAMC,eAAeN,SAAS;AAE9B,OAAO,MAAMO,gCAAgCR;IAC3C,OAAgBS,cAAc,gDAA+C;IAE7E,OAAgBC,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtB,GAAGP,oBAAoB;YACrBG,aAAa;YACbK,WAAW;QACb,EAAE;IACJ,EAAqB;IAErB,MAAaC,MAAqB;QAChC,MAAM,EAACC,IAAI,EAAEC,YAAY,EAAC,GAAG,IAAI,CAACJ,KAAK;QAEvC,MAAMK,iBAAiB,MAAMf,sBAAsB;YACjDgB,0BAA0B,AAAC,CAAA,MAAM,IAAI,CAACC,eAAe,EAAC,EAAGC,GAAG,EAAEH;YAC9DI,oBAAoBL;YACpBM,YAAY,IAAI,CAACC,YAAY;QAC/B;QAEA,IAAIC;QACJ,IAAI;YACFA,YAAY,MAAMrB,iBAAiBc;QACrC,EAAE,OAAOQ,OAAO;YACdnB,aAAa,+BAA+BmB;YAC5C,IAAI,CAACA,KAAK,CAAC,CAAC,8BAA8B,EAAExB,gBAAgBwB,QAAQ,EAAE;gBACpEC,MAAM5B,UAAU6B,aAAa;YAC/B;QACF;QAEA,IAAIZ,MAAM;YACR,IAAI,CAACa,OAAO,CAACJ;YACb;QACF;QAEA,IAAIA,UAAUK,MAAM,KAAK,GAAG;YAC1B,IAAI,CAACC,GAAG,CAAC;YACT;QACF;QAEA,MAAMC,QAAQ,IAAI3B,MAAM;YACtB4B,SAAS;gBACP;oBAACC,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;gBAC/C;oBAACF,WAAW;oBAAQC,MAAM;oBAASC,OAAO;gBAAO;gBACjD;oBAACF,WAAW;oBAAQC,MAAM;oBAAWC,OAAO;gBAAS;gBACrD;oBAACF,WAAW;oBAAQC,MAAM;oBAAOC,OAAO;gBAAK;aAC9C;QACH;QAEA,KAAK,MAAM,EAACD,IAAI,EAAEE,OAAO,EAAED,KAAK,EAAEE,GAAG,EAAC,IAAIb,UAAW;YACnDO,MAAMO,MAAM,CAAC;gBAACJ;gBAAME,SAASA,QAAQG,GAAG,CAAC,CAACC,SAAWA,OAAOC,EAAE,EAAEC,IAAI,CAAC;gBAAOP;gBAAOE;YAAG;QACxF;QAEA,IAAI,CAACP,GAAG,CAACC,MAAMY,MAAM;IACvB;AACF"}
1
+ {"version":3,"sources":["../../../../src/commands/context/mcp/list.ts"],"sourcesContent":["import {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\n\nimport {resolveOrganizationId} from '../../../actions/context/resolveOrganizationId.js'\nimport {contextTable} from '../../../actions/context/table.js'\nimport {listMcpEndpoints} from '../../../services/context.js'\nimport {getOrganizationFlag} from '../../../util/sharedFlags.js'\n\nconst listMcpDebug = subdebug('context:mcp:list')\n\nexport class ListMcpEndpointsCommand extends SanityCommand<typeof ListMcpEndpointsCommand> {\n static override description = 'List Context MCP endpoints in an organization'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List MCP endpoints, selecting the organization interactively',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --organization org-abc123 --json',\n description: 'Output the MCP endpoints of a specific organization as JSON',\n },\n ]\n\n static override flags = {\n ...getOrganizationFlag({\n description: 'Organization to list MCP endpoints for',\n semantics: 'override',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {json, organization} = this.flags\n\n const organizationId = await resolveOrganizationId({\n configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,\n flagOrganizationId: organization,\n unattended: this.isUnattended(),\n })\n\n let endpoints\n try {\n endpoints = await listMcpEndpoints(organizationId)\n } catch (error) {\n listMcpDebug('Error listing MCP endpoints', error)\n this.error(`Failed to list MCP endpoints: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(endpoints)\n return\n }\n\n if (endpoints.length === 0) {\n this.log('No MCP endpoints found')\n return\n }\n\n const table = contextTable({\n columns: [\n {alignment: 'left', name: 'name', title: 'Name'},\n {alignment: 'left', name: 'title', title: 'Title'},\n {alignment: 'left', name: 'sources', title: 'Sources'},\n {alignment: 'left', name: 'url', title: 'URL'},\n ],\n })\n\n for (const {name, sources, title, url} of endpoints) {\n table.addRow({name, sources: sources.map((source) => source.id).join(', '), title, url})\n }\n\n this.log(table.render())\n }\n}\n"],"names":["exitCodes","SanityCommand","subdebug","getErrorMessage","resolveOrganizationId","contextTable","listMcpEndpoints","getOrganizationFlag","listMcpDebug","ListMcpEndpointsCommand","description","enableJsonFlag","examples","command","flags","semantics","run","json","organization","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","isUnattended","endpoints","error","exit","RUNTIME_ERROR","logJson","length","log","table","columns","alignment","name","title","sources","url","addRow","map","source","id","join","render"],"mappings":"AACA,SAAQA,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AAEvD,SAAQC,qBAAqB,QAAO,oDAAmD;AACvF,SAAQC,YAAY,QAAO,oCAAmC;AAC9D,SAAQC,gBAAgB,QAAO,+BAA8B;AAC7D,SAAQC,mBAAmB,QAAO,+BAA8B;AAEhE,MAAMC,eAAeN,SAAS;AAE9B,OAAO,MAAMO,gCAAgCR;IAC3C,OAAgBS,cAAc,gDAA+C;IAE7E,OAAgBC,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtB,GAAGP,oBAAoB;YACrBG,aAAa;YACbK,WAAW;QACb,EAAE;IACJ,EAAqB;IAErB,MAAaC,MAAqB;QAChC,MAAM,EAACC,IAAI,EAAEC,YAAY,EAAC,GAAG,IAAI,CAACJ,KAAK;QAEvC,MAAMK,iBAAiB,MAAMf,sBAAsB;YACjDgB,0BAA0B,AAAC,CAAA,MAAM,IAAI,CAACC,eAAe,EAAC,EAAGC,GAAG,EAAEH;YAC9DI,oBAAoBL;YACpBM,YAAY,IAAI,CAACC,YAAY;QAC/B;QAEA,IAAIC;QACJ,IAAI;YACFA,YAAY,MAAMpB,iBAAiBa;QACrC,EAAE,OAAOQ,OAAO;YACdnB,aAAa,+BAA+BmB;YAC5C,IAAI,CAACA,KAAK,CAAC,CAAC,8BAA8B,EAAExB,gBAAgBwB,QAAQ,EAAE;gBACpEC,MAAM5B,UAAU6B,aAAa;YAC/B;QACF;QAEA,IAAIZ,MAAM;YACR,IAAI,CAACa,OAAO,CAACJ;YACb;QACF;QAEA,IAAIA,UAAUK,MAAM,KAAK,GAAG;YAC1B,IAAI,CAACC,GAAG,CAAC;YACT;QACF;QAEA,MAAMC,QAAQ5B,aAAa;YACzB6B,SAAS;gBACP;oBAACC,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;gBAC/C;oBAACF,WAAW;oBAAQC,MAAM;oBAASC,OAAO;gBAAO;gBACjD;oBAACF,WAAW;oBAAQC,MAAM;oBAAWC,OAAO;gBAAS;gBACrD;oBAACF,WAAW;oBAAQC,MAAM;oBAAOC,OAAO;gBAAK;aAC9C;QACH;QAEA,KAAK,MAAM,EAACD,IAAI,EAAEE,OAAO,EAAED,KAAK,EAAEE,GAAG,EAAC,IAAIb,UAAW;YACnDO,MAAMO,MAAM,CAAC;gBAACJ;gBAAME,SAASA,QAAQG,GAAG,CAAC,CAACC,SAAWA,OAAOC,EAAE,EAAEC,IAAI,CAAC;gBAAOP;gBAAOE;YAAG;QACxF;QAEA,IAAI,CAACP,GAAG,CAACC,MAAMY,MAAM;IACvB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/commands/context/mcp/status.ts"],"sourcesContent":["import {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {type Context, isHttpError} from '@sanity/client'\n\nimport {\n findMcpEndpoint,\n mcpEndpointNameArg,\n mcpEndpointOrganizationFlag,\n} from '../../../actions/context/mcpEndpoint.js'\nimport {resolveOrganizationId} from '../../../actions/context/resolveOrganizationId.js'\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {getMcpEndpointStatus} from '../../../services/context.js'\n\nconst statusMcpDebug = subdebug('context:mcp:status')\n\nexport class McpEndpointStatusCommand extends SanityCommand<typeof McpEndpointStatusCommand> {\n static override args = {\n name: mcpEndpointNameArg,\n }\n\n static override description =\n 'Check whether an agent connecting with your credentials can use a Context MCP endpoint'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> support',\n description: 'Check the \"support\" MCP endpoint',\n },\n ]\n\n static override flags = {\n ...mcpEndpointOrganizationFlag,\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {name} = this.args\n const {json, organization} = this.flags\n\n const organizationId = await resolveOrganizationId({\n configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,\n flagOrganizationId: organization,\n unattended: this.isUnattended(),\n })\n\n const endpoint = await findMcpEndpoint(organizationId, name)\n\n let status\n try {\n // The status route only takes names, not IDs\n status = await getMcpEndpointStatus(organizationId, endpoint.name)\n } catch (error) {\n statusMcpDebug('Error checking MCP endpoint', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`MCP endpoint \"${name}\" not found`, {exit: exitCodes.RUNTIME_ERROR})\n }\n this.error(`Failed to check MCP endpoint: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(status)\n } else {\n this.printStatus(status)\n }\n\n // Like `sanity doctor`: fail when agents can't use the endpoint. Semantic search never affects `requiredOk`\n if (!status.requiredOk) this.exit(exitCodes.RUNTIME_ERROR)\n }\n\n private printStatus(status: Context.McpEndpointStatus): void {\n const {knowledgeBases, schema, semanticSearch, studio} = status.checks\n const padTo = 15 // \"Knowledge bases\" and \"Semantic search\" are the longest keys\n this.log(\n formatKeyValue(\n 'Studio',\n formatCheck(studio, (check) => `workspace \"${check.workspace}\"`),\n {padTo},\n ),\n )\n this.log(\n formatKeyValue(\n 'Schema',\n formatCheck(\n schema,\n (check) => `${check.documentTypes} document types, ${check.perspective} perspective`,\n ),\n {padTo},\n ),\n )\n this.log(\n formatKeyValue(\n 'Knowledge bases',\n formatCheck(knowledgeBases, (check) => check.resolved.join(', ')),\n {padTo},\n ),\n )\n this.log(formatKeyValue('Semantic search', formatSemanticSearch(semanticSearch), {padTo}))\n this.log(formatKeyValue('Ready', status.requiredOk ? 'yes' : 'no', {padTo}))\n }\n}\n\n/**\n * A check is `null` when it doesn't apply to the endpoint\n */\nfunction formatCheck<Check extends {error?: string; ok: boolean}>(\n check: Check | null,\n describe: (check: Extract<Check, {ok: true}>) => string,\n): string {\n if (!check) return '-'\n return isPassed(check) ? `ok (${describe(check)})` : `failed: ${check.error}`\n}\n\nfunction isPassed<Check extends {ok: boolean}>(check: Check): check is Extract<Check, {ok: true}> {\n return check.ok\n}\n\ntype SemanticSearchCheck = Context.McpEndpointStatus['checks']['semanticSearch']\n\nconst INACTIVE_REASONS = {\n datasetEmbeddingsNotReady: 'embeddings are still being prepared',\n turnedOff: 'turned off',\n usageLimitReached: 'embeddings usage limit reached',\n} satisfies Record<NonNullable<Extract<SemanticSearchCheck, {ok: true}>['inactiveReason']>, string>\n\nfunction formatSemanticSearch(check: SemanticSearchCheck): string {\n if (!check) return '-'\n if (!isPassed(check)) return `failed: ${check.error}`\n if (check.active) return 'active'\n return check.inactiveReason ? `inactive (${INACTIVE_REASONS[check.inactiveReason]})` : 'inactive'\n}\n"],"names":["exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","findMcpEndpoint","mcpEndpointNameArg","mcpEndpointOrganizationFlag","resolveOrganizationId","formatKeyValue","getMcpEndpointStatus","statusMcpDebug","McpEndpointStatusCommand","args","name","description","enableJsonFlag","examples","command","flags","run","json","organization","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","isUnattended","endpoint","status","error","statusCode","exit","RUNTIME_ERROR","logJson","printStatus","requiredOk","knowledgeBases","schema","semanticSearch","studio","checks","padTo","log","formatCheck","check","workspace","documentTypes","perspective","resolved","join","formatSemanticSearch","describe","isPassed","ok","INACTIVE_REASONS","datasetEmbeddingsNotReady","turnedOff","usageLimitReached","active","inactiveReason"],"mappings":"AACA,SAAQA,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,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AAC/E;AAEA,SAASuB,SAAsCR,KAAY;IACzD,OAAOA,MAAMS,EAAE;AACjB;AAIA,MAAMC,mBAAmB;IACvBC,2BAA2B;IAC3BC,WAAW;IACXC,mBAAmB;AACrB;AAEA,SAASP,qBAAqBN,KAA0B;IACtD,IAAI,CAACA,OAAO,OAAO;IACnB,IAAI,CAACQ,SAASR,QAAQ,OAAO,CAAC,QAAQ,EAAEA,MAAMf,KAAK,EAAE;IACrD,IAAIe,MAAMc,MAAM,EAAE,OAAO;IACzB,OAAOd,MAAMe,cAAc,GAAG,CAAC,UAAU,EAAEL,gBAAgB,CAACV,MAAMe,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG;AACzF"}
1
+ {"version":3,"sources":["../../../../src/commands/context/mcp/status.ts"],"sourcesContent":["import {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {\n findMcpEndpoint,\n mcpEndpointNameArg,\n mcpEndpointOrganizationFlag,\n} from '../../../actions/context/mcpEndpoint.js'\nimport {resolveOrganizationId} from '../../../actions/context/resolveOrganizationId.js'\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {getMcpEndpointStatus, type McpEndpointStatus} from '../../../services/context.js'\n\nconst statusMcpDebug = subdebug('context:mcp:status')\n\nexport class McpEndpointStatusCommand extends SanityCommand<typeof McpEndpointStatusCommand> {\n static override args = {\n name: mcpEndpointNameArg,\n }\n\n static override description =\n 'Check whether an agent connecting with your credentials can use a Context MCP endpoint'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> support',\n description: 'Check the \"support\" MCP endpoint',\n },\n ]\n\n static override flags = {\n ...mcpEndpointOrganizationFlag,\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {name} = this.args\n const {json, organization} = this.flags\n\n const organizationId = await resolveOrganizationId({\n configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,\n flagOrganizationId: organization,\n unattended: this.isUnattended(),\n })\n\n const endpoint = await findMcpEndpoint(organizationId, name)\n\n let status\n try {\n // The status route only takes names, not IDs\n status = await getMcpEndpointStatus(organizationId, endpoint.name)\n } catch (error) {\n statusMcpDebug('Error checking MCP endpoint', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`MCP endpoint \"${name}\" not found`, {exit: exitCodes.RUNTIME_ERROR})\n }\n this.error(`Failed to check MCP endpoint: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(status)\n } else {\n this.printStatus(status)\n }\n\n // Like `sanity doctor`: fail when agents can't use the endpoint. Semantic search never affects `requiredOk`\n if (!status.requiredOk) this.exit(exitCodes.RUNTIME_ERROR)\n }\n\n private printStatus(status: McpEndpointStatus): void {\n const {knowledgeBases, schema, semanticSearch, studio} = status.checks\n const padTo = 15 // \"Knowledge bases\" and \"Semantic search\" are the longest keys\n this.log(\n formatKeyValue(\n 'Studio',\n formatCheck(studio, (check) => `workspace \"${check.workspace}\"`),\n {padTo},\n ),\n )\n this.log(\n formatKeyValue(\n 'Schema',\n formatCheck(\n schema,\n (check) => `${check.documentTypes} document types, ${check.perspective} perspective`,\n ),\n {padTo},\n ),\n )\n this.log(\n formatKeyValue(\n 'Knowledge bases',\n formatCheck(knowledgeBases, (check) => check.resolved.join(', ')),\n {padTo},\n ),\n )\n this.log(formatKeyValue('Semantic search', formatSemanticSearch(semanticSearch), {padTo}))\n this.log(formatKeyValue('Ready', status.requiredOk ? 'yes' : 'no', {padTo}))\n }\n}\n\n/**\n * A check is `null` when it doesn't apply to the endpoint\n */\nfunction formatCheck<Check extends {error?: string; ok: boolean}>(\n check: Check | null,\n describe: (check: Extract<Check, {ok: true}>) => string,\n): string {\n if (!check) return '-'\n return isPassed(check) ? `ok (${describe(check)})` : `failed: ${check.error}`\n}\n\nfunction isPassed<Check extends {ok: boolean}>(check: Check): check is Extract<Check, {ok: true}> {\n return check.ok\n}\n\ntype SemanticSearchCheck = McpEndpointStatus['checks']['semanticSearch']\n\nconst INACTIVE_REASONS = {\n datasetEmbeddingsNotReady: 'embeddings are still being prepared',\n turnedOff: 'turned off',\n usageLimitReached: 'embeddings usage limit reached',\n} satisfies Record<NonNullable<Extract<SemanticSearchCheck, {ok: true}>['inactiveReason']>, string>\n\nfunction formatSemanticSearch(check: SemanticSearchCheck): string {\n if (!check) return '-'\n if (!isPassed(check)) return `failed: ${check.error}`\n if (check.active) return 'active'\n return check.inactiveReason ? `inactive (${INACTIVE_REASONS[check.inactiveReason]})` : 'inactive'\n}\n"],"names":["exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","findMcpEndpoint","mcpEndpointNameArg","mcpEndpointOrganizationFlag","resolveOrganizationId","formatKeyValue","getMcpEndpointStatus","statusMcpDebug","McpEndpointStatusCommand","args","name","description","enableJsonFlag","examples","command","flags","run","json","organization","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","isUnattended","endpoint","status","error","statusCode","exit","RUNTIME_ERROR","logJson","printStatus","requiredOk","knowledgeBases","schema","semanticSearch","studio","checks","padTo","log","formatCheck","check","workspace","documentTypes","perspective","resolved","join","formatSemanticSearch","describe","isPassed","ok","INACTIVE_REASONS","datasetEmbeddingsNotReady","turnedOff","usageLimitReached","active","inactiveReason"],"mappings":"AACA,SAAQA,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SACEC,eAAe,EACfC,kBAAkB,EAClBC,2BAA2B,QACtB,0CAAyC;AAChD,SAAQC,qBAAqB,QAAO,oDAAmD;AACvF,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,oBAAoB,QAA+B,+BAA8B;AAEzF,MAAMC,iBAAiBT,SAAS;AAEhC,OAAO,MAAMU,iCAAi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EAAE;IACrD,IAAIe,MAAMc,MAAM,EAAE,OAAO;IACzB,OAAOd,MAAMe,cAAc,GAAG,CAAC,UAAU,EAAEL,gBAAgB,CAACV,MAAMe,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG;AACzF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/commands/context/mcp/update.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {type Context, isHttpError} from '@sanity/client'\n\nimport {\n type DatasetSettings,\n datasetSourceId,\n editSources,\n findMcpEndpoint,\n formatMcpEndpoint,\n mcpEndpointNameArg,\n mcpEndpointOrganizationFlag,\n parseNonEmpty,\n} from '../../../actions/context/mcpEndpoint.js'\nimport {resolveOrganizationId} from '../../../actions/context/resolveOrganizationId.js'\nimport {\n describeBlueprintManager,\n getMcpEndpointBlueprintOwnership,\n updateMcpEndpoint,\n} from '../../../services/context.js'\nimport {getDatasetFlag, getProjectIdFlag} from '../../../util/sharedFlags.js'\nimport {defineCommandTelemetry} from '../../../util/telemetry/commandTelemetry.js'\n\nconst updateMcpDebug = subdebug('context:mcp:update')\n\nconst UPDATE_FLAGS = [\n 'title',\n 'add-knowledge-base',\n 'remove-knowledge-base',\n 'knowledge-base',\n 'dataset',\n 'no-dataset',\n 'workspace',\n 'perspective',\n 'semantic-search',\n 'instructions',\n 'groq-filter',\n]\n\nconst flags = {\n ...mcpEndpointOrganizationFlag,\n 'add-knowledge-base': Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description: 'Knowledge base to add to the endpoint; repeat the flag to add several',\n helpValue: '<id>',\n multiple: true,\n parse: parseNonEmpty('add-knowledge-base'),\n }),\n ...getDatasetFlag({\n atLeastOne: UPDATE_FLAGS,\n description: 'Dataset the endpoint serves, replacing its current dataset',\n semantics: 'specify',\n }),\n ...getProjectIdFlag({\n dependsOn: ['dataset'],\n description: 'Project the dataset belongs to',\n semantics: 'override',\n }),\n 'groq-filter': Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description:\n 'GROQ filter that limits which dataset documents the endpoint serves (\"\" removes it)',\n }),\n instructions: Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description: 'Instructions the endpoint serves to connecting agents (\"\" removes them)',\n }),\n 'knowledge-base': Flags.string({\n atLeastOne: UPDATE_FLAGS,\n hidden: true,\n multiple: true,\n }),\n 'no-dataset': Flags.boolean({\n atLeastOne: UPDATE_FLAGS,\n description: 'Stop serving the dataset, which also removes the GROQ filter',\n exclusive: ['dataset'],\n }),\n perspective: Flags.custom<'drafts' | 'published' | 'raw'>({\n atLeastOne: UPDATE_FLAGS,\n description: 'Perspective agents query the dataset with',\n options: ['published', 'drafts', 'raw'],\n })(),\n 'remove-knowledge-base': Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description: 'Knowledge base to remove from the endpoint; repeat the flag to remove several',\n helpValue: '<id>',\n multiple: true,\n parse: parseNonEmpty('remove-knowledge-base'),\n }),\n 'semantic-search': Flags.boolean({\n allowNo: true,\n atLeastOne: UPDATE_FLAGS,\n description:\n 'Let agents use semantic search on the dataset (--no-semantic-search to turn it off)',\n }),\n title: Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description: 'New MCP endpoint title',\n parse: parseNonEmpty('title'),\n }),\n workspace: Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description: 'Studio workspace whose schema agents use (\"\" goes back to the first workspace)',\n }),\n} satisfies FlagInput\n\nexport class UpdateMcpEndpointCommand extends SanityCommand<typeof UpdateMcpEndpointCommand> {\n static override args = {\n name: mcpEndpointNameArg,\n }\n\n static override description = `Update a Context MCP endpoint\n\nOnly the settings you pass change. Dataset settings (--workspace, --perspective, --semantic-search) apply to the endpoint's dataset and start from the defaults when --dataset switches to another dataset.`\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> support --title \"Customer support\"',\n description: 'Rename an MCP endpoint',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> support --add-knowledge-base kb-def456 --remove-knowledge-base kb-abc123',\n description: 'Serve a different knowledge base',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> catalog --project abc123 --dataset staging --perspective drafts',\n description: 'Switch to another dataset and query its drafts',\n },\n {\n command: '<%= config.bin %> <%= command.id %> support --no-dataset',\n description: 'Stop serving the dataset',\n },\n {\n command: '<%= config.bin %> <%= command.id %> support --instructions \"\"',\n description: 'Remove the instructions',\n },\n ]\n\n static override flags = flags\n\n static telemetry = defineCommandTelemetry(flags, {\n redact: ['title', 'instructions', 'groq-filter'],\n })\n\n public async run(): Promise<void> {\n const {name} = this.args\n const {\n 'add-knowledge-base': addKnowledgeBases = [],\n dataset,\n 'groq-filter': groqFilter,\n instructions,\n 'knowledge-base': knowledgeBase,\n 'no-dataset': noDataset,\n organization,\n perspective,\n project,\n 'remove-knowledge-base': removeKnowledgeBases = [],\n 'semantic-search': semanticSearch,\n title,\n workspace,\n } = this.flags\n\n if (knowledgeBase !== undefined) {\n this.error(\n '`--knowledge-base` only works with `sanity context mcp create`. Use `--add-knowledge-base` or `--remove-knowledge-base` to change the knowledge bases of an endpoint.',\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n if (\n noDataset &&\n [groqFilter, perspective, semanticSearch, workspace].some((v) => v !== undefined)\n ) {\n this.error(\n '`--no-dataset` cannot be combined with `--groq-filter`, `--perspective`, `--semantic-search` or `--workspace`, which only apply to a dataset.',\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n const addedAndRemoved = addKnowledgeBases.find((id) => removeKnowledgeBases.includes(id))\n if (addedAndRemoved) {\n this.error(\n `\"${addedAndRemoved}\" is passed to both \\`--add-knowledge-base\\` and \\`--remove-knowledge-base\\`.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n const cliConfig = await this.tryGetCliConfig()\n const datasetId = datasetSourceId(dataset, project ?? cliConfig.api?.projectId)\n\n const params: Context.EditMcpEndpointParams = {}\n if (title !== undefined) params.title = title\n if (instructions !== undefined) params.instructions = instructions.trim() || null\n if (groqFilter !== undefined) params.groqFilter = groqFilter.trim() || null\n\n const settings: DatasetSettings = {}\n if (workspace !== undefined) settings.workspace = workspace.trim() || null\n if (perspective !== undefined) settings.perspective = perspective\n if (semanticSearch !== undefined) settings.semanticSearch = semanticSearch\n const changesSources =\n addKnowledgeBases.length > 0 ||\n removeKnowledgeBases.length > 0 ||\n dataset !== undefined ||\n noDataset ||\n Object.keys(settings).length > 0\n const needsDataset = Object.keys(settings).length > 0 || Boolean(params.groqFilter)\n\n const organizationId = await resolveOrganizationId({\n configuredOrganizationId: cliConfig.app?.organizationId,\n flagOrganizationId: organization,\n unattended: this.isUnattended(),\n })\n\n const current = await findMcpEndpoint(organizationId, name)\n\n const ownership = await getMcpEndpointBlueprintOwnership(organizationId, current)\n if (ownership.managed) {\n const manager = describeBlueprintManager(ownership.stackName)\n this.error(\n `${manager} manages MCP endpoint \"${name}\", so the next deploy would undo this change. Change it in the blueprint and run \\`sanity blueprints deploy\\` instead.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n if (changesSources || needsDataset) {\n const {notes, sources} = editSources(current.sources, {\n addKnowledgeBases,\n dataset: noDataset ? null : datasetId,\n removeKnowledgeBases,\n settings,\n })\n if (needsDataset && !sources.some((source) => source.type === 'dataset')) {\n this.error(`MCP endpoint \"${name}\" has no dataset source. Pass \\`--dataset\\` to add one.`, {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n if (sources.length === 0) {\n this.error('An MCP endpoint needs at least one knowledge base or dataset', {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n for (const note of notes) this.warn(note)\n if (changesSources) params.sources = sources\n }\n\n const spin = spinner('Updating MCP endpoint').start()\n try {\n const endpoint = await updateMcpEndpoint(organizationId, current.name, params)\n spin.succeed('MCP endpoint updated')\n for (const line of formatMcpEndpoint(endpoint)) {\n this.log(line)\n }\n } catch (error) {\n spin.fail()\n updateMcpDebug('Error updating MCP endpoint', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`MCP endpoint \"${name}\" not found`, {exit: exitCodes.RUNTIME_ERROR})\n }\n this.error(`Failed to update MCP endpoint: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","spinner","isHttpError","datasetSourceId","editSources","findMcpEndpoint","formatMcpEndpoint","mcpEndpointNameArg","mcpEndpointOrganizationFlag","parseNonEmpty","resolveOrganizationId","describeBlueprintManager","getMcpEndpointBlueprintOwnership","updateMcpEndpoint","getDatasetFlag","getProjectIdFlag","defineCommandTelemetry","updateMcpDebug","UPDATE_FLAGS","flags","string","atLeastOne","description","helpValue","multiple","parse","semantics","dependsOn","instructions","hidden","boolean","exclusive","perspective","custom","options","allowNo","title","workspace","UpdateMcpEndpointCommand","args","name","examples","command","telemetry","redact","run","addKnowledgeBases","dataset","groqFilter","knowledgeBase","noDataset","organization","project","removeKnowledgeBases","semanticSearch","undefined","error","exit","USAGE_ERROR","some","v","addedAndRemoved","find","id","includes","cliConfig","tryGetCliConfig","datasetId","api","projectId","params","trim","settings","changesSources","length","Object","keys","needsDataset","Boolean","organizationId","configuredOrganizationId","app","flagOrganizationId","unattended","isUnattended","current","ownership","managed","manager","stackName","notes","sources","source","type","note","warn","spin","start","endpoint","succeed","line","log","fail","statusCode","RUNTIME_ERROR"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AAEjC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAsBC,WAAW,QAAO,iBAAgB;AAExD,SAEEC,eAAe,EACfC,WAAW,EACXC,eAAe,EACfC,iBAAiB,EACjBC,kBAAkB,EAClBC,2BAA2B,EAC3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D,IAAI,CAAC/C,KAAK,CAAC,CAAC,cAAc,EAAEhB,KAAK,WAAW,CAAC,EAAE;oBAACiB,MAAM5D,UAAU2G,aAAa;gBAAA;YAC/E;YACA,IAAI,CAAChD,KAAK,CAAC,CAAC,+BAA+B,EAAExD,gBAAgBwD,QAAQ,EAAE;gBACrEC,MAAM5D,UAAU2G,aAAa;YAC/B;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../src/commands/context/mcp/update.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {type Context, isHttpError} from '@sanity/client'\n\nimport {\n type DatasetSettings,\n datasetSourceId,\n editSources,\n findMcpEndpoint,\n formatMcpEndpoint,\n mcpEndpointNameArg,\n mcpEndpointOrganizationFlag,\n parseNonEmpty,\n} from '../../../actions/context/mcpEndpoint.js'\nimport {resolveOrganizationId} from '../../../actions/context/resolveOrganizationId.js'\nimport {\n describeBlueprintManager,\n getMcpEndpointBlueprintOwnership,\n updateMcpEndpoint,\n} from '../../../services/context.js'\nimport {getDatasetFlag, getProjectIdFlag} from '../../../util/sharedFlags.js'\nimport {defineCommandTelemetry} from '../../../util/telemetry/commandTelemetry.js'\n\nconst updateMcpDebug = subdebug('context:mcp:update')\n\nconst UPDATE_FLAGS = [\n 'title',\n 'add-knowledge-base',\n 'remove-knowledge-base',\n 'knowledge-base',\n 'dataset',\n 'no-dataset',\n 'workspace',\n 'perspective',\n 'semantic-search',\n 'instructions',\n 'groq-filter',\n]\n\nconst flags = {\n ...mcpEndpointOrganizationFlag,\n 'add-knowledge-base': Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description: 'Knowledge base to add to the endpoint; repeat the flag to add several',\n helpValue: '<id>',\n multiple: true,\n parse: parseNonEmpty('add-knowledge-base'),\n }),\n ...getDatasetFlag({\n atLeastOne: UPDATE_FLAGS,\n description: 'Dataset the endpoint serves, replacing its current dataset',\n semantics: 'specify',\n }),\n ...getProjectIdFlag({\n dependsOn: ['dataset'],\n description: 'Project the dataset belongs to',\n semantics: 'override',\n }),\n 'groq-filter': Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description:\n 'GROQ filter that limits which dataset documents the endpoint serves (\"\" removes it)',\n }),\n instructions: Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description: 'Instructions the endpoint serves to connecting agents (\"\" removes them)',\n }),\n 'knowledge-base': Flags.string({\n atLeastOne: UPDATE_FLAGS,\n hidden: true,\n multiple: true,\n }),\n 'no-dataset': Flags.boolean({\n atLeastOne: UPDATE_FLAGS,\n description: 'Stop serving the dataset, which also removes the GROQ filter',\n exclusive: ['dataset'],\n }),\n perspective: Flags.custom<'drafts' | 'published' | 'raw'>({\n atLeastOne: UPDATE_FLAGS,\n description: 'Perspective agents query the dataset with',\n options: ['published', 'drafts', 'raw'],\n })(),\n 'remove-knowledge-base': Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description: 'Knowledge base to remove from the endpoint; repeat the flag to remove several',\n helpValue: '<id>',\n multiple: true,\n parse: parseNonEmpty('remove-knowledge-base'),\n }),\n 'semantic-search': Flags.boolean({\n allowNo: true,\n atLeastOne: UPDATE_FLAGS,\n description:\n 'Let agents use semantic search on the dataset (--no-semantic-search to turn it off)',\n }),\n title: Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description: 'New MCP endpoint title',\n parse: parseNonEmpty('title'),\n }),\n workspace: Flags.string({\n atLeastOne: UPDATE_FLAGS,\n description: 'Studio workspace whose schema agents use (\"\" goes back to the first workspace)',\n }),\n} satisfies FlagInput\n\nexport class UpdateMcpEndpointCommand extends SanityCommand<typeof UpdateMcpEndpointCommand> {\n static override args = {\n name: mcpEndpointNameArg,\n }\n\n static override description = `Update a Context MCP endpoint\n\nOnly the settings you pass change. Dataset settings (--workspace, --perspective, --semantic-search) apply to the endpoint's dataset and start from the defaults when --dataset switches to another dataset.`\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> support --title \"Customer support\"',\n description: 'Rename an MCP endpoint',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> support --add-knowledge-base kb-def456 --remove-knowledge-base kb-abc123',\n description: 'Serve a different knowledge base',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> catalog --project abc123 --dataset staging --perspective drafts',\n description: 'Switch to another dataset and query its drafts',\n },\n {\n command: '<%= config.bin %> <%= command.id %> support --no-dataset',\n description: 'Stop serving the dataset',\n },\n {\n command: '<%= config.bin %> <%= command.id %> support --instructions \"\"',\n description: 'Remove the instructions',\n },\n ]\n\n static override flags = flags\n\n static telemetry = defineCommandTelemetry(flags, {\n redact: ['title', 'instructions', 'groq-filter'],\n })\n\n public async run(): Promise<void> {\n const {name} = this.args\n const {\n 'add-knowledge-base': addKnowledgeBases = [],\n dataset,\n 'groq-filter': groqFilter,\n instructions,\n 'knowledge-base': knowledgeBase,\n 'no-dataset': noDataset,\n organization,\n perspective,\n project,\n 'remove-knowledge-base': removeKnowledgeBases = [],\n 'semantic-search': semanticSearch,\n title,\n workspace,\n } = this.flags\n\n if (knowledgeBase !== undefined) {\n this.error(\n '`--knowledge-base` only works with `sanity context mcp create`. Use `--add-knowledge-base` or `--remove-knowledge-base` to change the knowledge bases of an endpoint.',\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n if (\n noDataset &&\n [groqFilter, perspective, semanticSearch, workspace].some((v) => v !== undefined)\n ) {\n this.error(\n '`--no-dataset` cannot be combined with `--groq-filter`, `--perspective`, `--semantic-search` or `--workspace`, which only apply to a dataset.',\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n const addedAndRemoved = addKnowledgeBases.find((id) => removeKnowledgeBases.includes(id))\n if (addedAndRemoved) {\n this.error(\n `\"${addedAndRemoved}\" is passed to both \\`--add-knowledge-base\\` and \\`--remove-knowledge-base\\`.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n const cliConfig = await this.tryGetCliConfig()\n const datasetId = datasetSourceId(dataset, project ?? cliConfig.api?.projectId)\n\n const params: Context.Body<'PATCH /organizations/{organizationId}/mcp/{mcpEndpoint}'> = {}\n if (title !== undefined) params.title = title\n if (instructions !== undefined) params.instructions = instructions.trim() || null\n if (groqFilter !== undefined) params.groqFilter = groqFilter.trim() || null\n\n const settings: DatasetSettings = {}\n if (workspace !== undefined) settings.workspace = workspace.trim() || null\n if (perspective !== undefined) settings.perspective = perspective\n if (semanticSearch !== undefined) settings.semanticSearch = semanticSearch\n const changesSources =\n addKnowledgeBases.length > 0 ||\n removeKnowledgeBases.length > 0 ||\n dataset !== undefined ||\n noDataset ||\n Object.keys(settings).length > 0\n const needsDataset = Object.keys(settings).length > 0 || Boolean(params.groqFilter)\n\n const organizationId = await resolveOrganizationId({\n configuredOrganizationId: cliConfig.app?.organizationId,\n flagOrganizationId: organization,\n unattended: this.isUnattended(),\n })\n\n const current = await findMcpEndpoint(organizationId, name)\n\n const ownership = await getMcpEndpointBlueprintOwnership(organizationId, current)\n if (ownership.managed) {\n const manager = describeBlueprintManager(ownership.stackName)\n this.error(\n `${manager} manages MCP endpoint \"${name}\", so the next deploy would undo this change. Change it in the blueprint and run \\`sanity blueprints deploy\\` instead.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n if (changesSources || needsDataset) {\n const {notes, sources} = editSources(current.sources, {\n addKnowledgeBases,\n dataset: noDataset ? null : datasetId,\n removeKnowledgeBases,\n settings,\n })\n if (needsDataset && !sources.some((source) => source.type === 'dataset')) {\n this.error(`MCP endpoint \"${name}\" has no dataset source. Pass \\`--dataset\\` to add one.`, {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n if (sources.length === 0) {\n this.error('An MCP endpoint needs at least one knowledge base or dataset', {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n for (const note of notes) this.warn(note)\n if (changesSources) params.sources = sources\n }\n\n const spin = spinner('Updating MCP endpoint').start()\n try {\n const endpoint = await updateMcpEndpoint(organizationId, current.name, params)\n spin.succeed('MCP endpoint updated')\n for (const line of formatMcpEndpoint(endpoint)) {\n this.log(line)\n }\n } catch (error) {\n spin.fail()\n updateMcpDebug('Error updating MCP endpoint', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`MCP endpoint \"${name}\" not found`, {exit: exitCodes.RUNTIME_ERROR})\n }\n this.error(`Failed to update MCP endpoint: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","spinner","isHttpError","datasetSourceId","editSources","findMcpEndpoint","formatMcpEndpoint","mcpEndpointNameArg","mcpEndpointOrganizationFlag","parseNonEmpty","resolveOrganizationId","describeBlueprintManager","getMcpEndpointBlueprintOwnership","updateMcpEndpoint","getDatasetFlag","getProjectIdFlag","defineCommandTelemetry","updateMcpDebug","UPDATE_FLAGS","flags","string","atLeastOne","description","helpValue","multiple","parse","semantics","dependsOn","instructions","hidden","boolean","exclusive","perspective","custom","options","allowNo","title","workspace","UpdateMcpEndpointCommand","args","name","examples","command","telemetry","redact","run","addKnowledgeBases","dataset","groqFilter","knowledgeBase","noDataset","organization","project","removeKnowledgeBases","semanticSearch","undefined","error","exit","USAGE_ERROR","some","v","addedAndRemoved","find","id","includes","cliConfig","tryGetCliConfig","datasetId","api","projectId","params","trim","settings","changesSources","length","Object","keys","needsDataset","Boolean","organizationId","configuredOrganizationId","app","flagOrganizationId","unattended","isUnattended","current","ownership","managed","manager","stackName","notes","sources","source","type","note","warn","spin","start","endpoint","succeed","line","log","fail","statusCode","RUNTIME_ERROR"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AAEjC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAsBC,WAAW,QAA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