@sanity/cli 8.26.0 → 8.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +1534 -411
  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 +165 -0
  11. package/dist/actions/context/mcpEndpoint.js.map +1 -0
  12. package/dist/actions/context/operationInput.js +226 -0
  13. package/dist/actions/context/operationInput.js.map +1 -0
  14. package/dist/actions/context/operationTypes.js +3 -0
  15. package/dist/actions/context/operationTypes.js.map +1 -0
  16. package/dist/actions/context/removedCommands.js +26 -0
  17. package/dist/actions/context/removedCommands.js.map +1 -0
  18. package/dist/actions/context/renderOperationResult.js +72 -0
  19. package/dist/actions/context/renderOperationResult.js.map +1 -0
  20. package/dist/actions/context/resolveOrganizationId.js +8 -1
  21. package/dist/actions/context/resolveOrganizationId.js.map +1 -1
  22. package/dist/actions/context/sourceFile.js +31 -0
  23. package/dist/actions/context/sourceFile.js.map +1 -0
  24. package/dist/actions/context/syncOutput.js +17 -0
  25. package/dist/actions/context/syncOutput.js.map +1 -0
  26. package/dist/actions/context/table.js +13 -0
  27. package/dist/actions/context/table.js.map +1 -0
  28. package/dist/actions/context/waitForJob.js.map +1 -1
  29. package/dist/actions/context/waitForSourceSync.js +48 -0
  30. package/dist/actions/context/waitForSourceSync.js.map +1 -0
  31. package/dist/actions/context/watchJob.js.map +1 -1
  32. package/dist/actions/context/watchSourceSync.js +40 -0
  33. package/dist/actions/context/watchSourceSync.js.map +1 -0
  34. package/dist/commands/context/build.js +19 -81
  35. package/dist/commands/context/build.js.map +1 -1
  36. package/dist/commands/context/create.js +3 -104
  37. package/dist/commands/context/create.js.map +1 -1
  38. package/dist/commands/context/delete.js +3 -73
  39. package/dist/commands/context/delete.js.map +1 -1
  40. package/dist/commands/context/documents/content.js +117 -0
  41. package/dist/commands/context/documents/content.js.map +1 -0
  42. package/dist/commands/context/documents/delete.js +5 -0
  43. package/dist/commands/context/documents/delete.js.map +1 -0
  44. package/dist/commands/context/documents/edit.js +5 -0
  45. package/dist/commands/context/documents/edit.js.map +1 -0
  46. package/dist/commands/context/documents/get.js +5 -0
  47. package/dist/commands/context/documents/get.js.map +1 -0
  48. package/dist/commands/context/documents/list.js +5 -0
  49. package/dist/commands/context/documents/list.js.map +1 -0
  50. package/dist/commands/context/entries/list.js +2 -2
  51. package/dist/commands/context/entries/list.js.map +1 -1
  52. package/dist/commands/context/entries/rebuild.js +3 -93
  53. package/dist/commands/context/entries/rebuild.js.map +1 -1
  54. package/dist/commands/context/get.js +3 -88
  55. package/dist/commands/context/get.js.map +1 -1
  56. package/dist/commands/context/instructions/create.js +5 -0
  57. package/dist/commands/context/instructions/create.js.map +1 -0
  58. package/dist/commands/context/instructions/delete.js +5 -0
  59. package/dist/commands/context/instructions/delete.js.map +1 -0
  60. package/dist/commands/context/instructions/edit.js +5 -0
  61. package/dist/commands/context/instructions/edit.js.map +1 -0
  62. package/dist/commands/context/issues/apply.js +3 -84
  63. package/dist/commands/context/issues/apply.js.map +1 -1
  64. package/dist/commands/context/issues/dismiss.js +3 -50
  65. package/dist/commands/context/issues/dismiss.js.map +1 -1
  66. package/dist/commands/context/issues/list.js +0 -5
  67. package/dist/commands/context/issues/list.js.map +1 -1
  68. package/dist/commands/context/issues/reopen.js +3 -51
  69. package/dist/commands/context/issues/reopen.js.map +1 -1
  70. package/dist/commands/context/issues/resolve.js +23 -92
  71. package/dist/commands/context/issues/resolve.js.map +1 -1
  72. package/dist/commands/context/jobs/get.js +3 -88
  73. package/dist/commands/context/jobs/get.js.map +1 -1
  74. package/dist/commands/context/list.js +3 -103
  75. package/dist/commands/context/list.js.map +1 -1
  76. package/dist/commands/context/mcp/create.js +152 -0
  77. package/dist/commands/context/mcp/create.js.map +1 -0
  78. package/dist/commands/context/mcp/delete.js +82 -0
  79. package/dist/commands/context/mcp/delete.js.map +1 -0
  80. package/dist/commands/context/mcp/get.js +42 -0
  81. package/dist/commands/context/mcp/get.js.map +1 -0
  82. package/dist/commands/context/mcp/initial-context.js +5 -0
  83. package/dist/commands/context/mcp/initial-context.js.map +1 -0
  84. package/dist/commands/context/mcp/list.js +87 -0
  85. package/dist/commands/context/mcp/list.js.map +1 -0
  86. package/dist/commands/context/mcp/status.js +98 -0
  87. package/dist/commands/context/mcp/status.js.map +1 -0
  88. package/dist/commands/context/mcp/update.js +225 -0
  89. package/dist/commands/context/mcp/update.js.map +1 -0
  90. package/dist/commands/context/query.js +6 -14
  91. package/dist/commands/context/query.js.map +1 -1
  92. package/dist/commands/context/sources/create.js +175 -0
  93. package/dist/commands/context/sources/create.js.map +1 -0
  94. package/dist/commands/context/sources/delete.js +5 -0
  95. package/dist/commands/context/sources/delete.js.map +1 -0
  96. package/dist/commands/context/sources/edit.js +29 -0
  97. package/dist/commands/context/sources/edit.js.map +1 -0
  98. package/dist/commands/context/sources/get.js +5 -0
  99. package/dist/commands/context/sources/get.js.map +1 -0
  100. package/dist/commands/context/sources/list.js +5 -0
  101. package/dist/commands/context/sources/list.js.map +1 -0
  102. package/dist/commands/context/sources/sync.js +5 -0
  103. package/dist/commands/context/sources/sync.js.map +1 -0
  104. package/dist/commands/context/sources/syncs/confirm.js +5 -0
  105. package/dist/commands/context/sources/syncs/confirm.js.map +1 -0
  106. package/dist/commands/context/sources/syncs/discard.js +5 -0
  107. package/dist/commands/context/sources/syncs/discard.js.map +1 -0
  108. package/dist/commands/context/sources/syncs/get.js +5 -0
  109. package/dist/commands/context/sources/syncs/get.js.map +1 -0
  110. package/dist/commands/context/sources/syncs/list.js +5 -0
  111. package/dist/commands/context/sources/syncs/list.js.map +1 -0
  112. package/dist/commands/context/sources/upload.js +63 -0
  113. package/dist/commands/context/sources/upload.js.map +1 -0
  114. package/dist/commands/context/sync.js +5 -0
  115. package/dist/commands/context/sync.js.map +1 -0
  116. package/dist/commands/context/update.js +3 -136
  117. package/dist/commands/context/update.js.map +1 -1
  118. package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js +47 -26
  119. package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js.map +1 -1
  120. package/dist/generated/apiRoutes.js +28 -0
  121. package/dist/generated/apiRoutes.js.map +1 -1
  122. package/dist/generated/contextOperations.js +1116 -0
  123. package/dist/generated/contextOperations.js.map +1 -0
  124. package/dist/hooks/commandNotFound/topicAliases.js +8 -2
  125. package/dist/hooks/commandNotFound/topicAliases.js.map +1 -1
  126. package/dist/prompts/promptForText.js +12 -0
  127. package/dist/prompts/promptForText.js.map +1 -0
  128. package/dist/services/context.js +276 -202
  129. package/dist/services/context.js.map +1 -1
  130. package/dist/util/sharedFlags.js.map +1 -1
  131. package/dist/util/telemetry/cliCommandIdentity.js +16 -18
  132. package/dist/util/telemetry/cliCommandIdentity.js.map +1 -1
  133. package/oclif.config.js +1 -1
  134. package/oclif.manifest.json +4854 -2834
  135. package/package.json +20 -19
  136. package/templates/app-quickstart/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  137. package/templates/app-quickstart/AGENTS.md +49 -0
  138. package/templates/app-sanity-ui/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  139. package/templates/app-sanity-ui/AGENTS.md +49 -0
  140. package/templates/shared/dashboard/app-quickstart/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  141. package/templates/shared/dashboard/app-quickstart/AGENTS.md +49 -0
  142. package/templates/shared/dashboard/app-sanity-ui/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  143. package/templates/shared/dashboard/app-sanity-ui/AGENTS.md +49 -0
  144. package/dist/commands/context/imports/create.js +0 -270
  145. package/dist/commands/context/imports/create.js.map +0 -1
  146. package/dist/commands/context/imports/delete.js +0 -73
  147. package/dist/commands/context/imports/delete.js.map +0 -1
  148. package/dist/commands/context/imports/download.js +0 -60
  149. package/dist/commands/context/imports/download.js.map +0 -1
  150. package/dist/commands/context/imports/get.js +0 -88
  151. package/dist/commands/context/imports/get.js.map +0 -1
  152. package/dist/commands/context/imports/list.js +0 -100
  153. package/dist/commands/context/imports/list.js.map +0 -1
  154. package/dist/commands/context/refresh.js +0 -46
  155. package/dist/commands/context/refresh.js.map +0 -1
@@ -0,0 +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.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,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b,KAAK,MAAMC,QAAQ9F,kBAAkB4F,UAAW;gBAC9C,IAAI,CAACG,GAAG,CAACD;YACX;QACF,EAAE,OAAO5C,OAAO;YACdwC,KAAKM,IAAI;YACTrF,eAAe,+BAA+BuC;YAC9C,IAAItD,YAAYsD,UAAUA,MAAM+C,UAAU,KAAK,KAAK;gBAClD,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"}
@@ -2,7 +2,7 @@ import { Args, Flags } from '@oclif/core';
2
2
  import { colorizeJson, exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
3
  import { getErrorMessage } from '@sanity/cli-core/errors';
4
4
  import { isRecord } from '@sanity/cli-core/util';
5
- import { MissingOrganizationError, resolveOrganizationId } from '../../actions/context/resolveOrganizationId.js';
5
+ import { resolveOrganizationId } from '../../actions/context/resolveOrganizationId.js';
6
6
  import { queryContext } from '../../services/context.js';
7
7
  import { getOrganizationFlag } from '../../util/sharedFlags.js';
8
8
  import { defineCommandTelemetry } from '../../util/telemetry/commandTelemetry.js';
@@ -57,19 +57,11 @@ export class QueryContextCommand extends SanityCommand {
57
57
  async run() {
58
58
  const { query } = this.args;
59
59
  const { json, organization, params } = this.flags;
60
- let organizationId;
61
- try {
62
- organizationId = await resolveOrganizationId({
63
- configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,
64
- flagOrganizationId: organization,
65
- unattended: this.isUnattended()
66
- });
67
- } catch (error) {
68
- queryContextDebug('Error resolving organization', error);
69
- this.error(getErrorMessage(error), {
70
- exit: error instanceof MissingOrganizationError ? exitCodes.USAGE_ERROR : exitCodes.RUNTIME_ERROR
71
- });
72
- }
60
+ const organizationId = await resolveOrganizationId({
61
+ configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,
62
+ flagOrganizationId: organization,
63
+ unattended: this.isUnattended()
64
+ });
73
65
  let result;
74
66
  try {
75
67
  result = await queryContext(organizationId, query, params);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/context/query.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {colorizeJson, exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isRecord} from '@sanity/cli-core/util'\n\nimport {\n MissingOrganizationError,\n resolveOrganizationId,\n} from '../../actions/context/resolveOrganizationId.js'\nimport {queryContext} from '../../services/context.js'\nimport {getOrganizationFlag} from '../../util/sharedFlags.js'\nimport {defineCommandTelemetry} from '../../util/telemetry/commandTelemetry.js'\n\nconst queryContextDebug = subdebug('context:query')\n\nconst flags = {\n ...getOrganizationFlag({\n description: 'Organization to query',\n semantics: 'override',\n }),\n params: Flags.custom<Record<string, unknown>>({\n description: 'Query parameters as a JSON object',\n helpValue: '<json>',\n parse: async (input: string) => {\n let parsed: unknown\n try {\n parsed = JSON.parse(input)\n } catch {\n throw new Error('`--params` must be valid JSON')\n }\n if (!isRecord(parsed)) {\n throw new Error('`--params` must be a JSON object, like \\'{\"type\": \"issue\"}\\'')\n }\n return parsed\n },\n })(),\n} satisfies FlagInput\n\nexport class QueryContextCommand extends SanityCommand<typeof QueryContextCommand> {\n static override args = {\n query: Args.string({\n description: \"GROQ query to run against the organization's Context documents\",\n required: true,\n }),\n }\n\n static override description = \"Query an organization's Context documents with GROQ\"\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command:\n '<%= config.bin %> <%= command.id %> \\'*[_type == \"sanity.context.issue\" && status == \"open\"]{_id, knowledgeBaseId}\\'',\n description: 'List open issues across all knowledge bases',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> \\'*[_type == \"sanity.context.entry\" && knowledgeBaseId == $kb].path\\' --params \\'{\"kb\": \"kb-abc123\"}\\' --json',\n description: 'List the entry paths of one knowledge base as plain JSON',\n },\n ]\n\n static override flags = flags\n\n static telemetry = defineCommandTelemetry(flags, {redact: ['params']})\n\n public async run(): Promise<void> {\n const {query} = this.args\n const {json, organization, params} = this.flags\n\n let organizationId: string\n try {\n organizationId = await resolveOrganizationId({\n configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,\n flagOrganizationId: organization,\n unattended: this.isUnattended(),\n })\n } catch (error) {\n queryContextDebug('Error resolving organization', error)\n this.error(getErrorMessage(error), {\n exit:\n error instanceof MissingOrganizationError\n ? exitCodes.USAGE_ERROR\n : exitCodes.RUNTIME_ERROR,\n })\n }\n\n let result\n try {\n result = await queryContext(organizationId, query, params)\n } catch (error) {\n queryContextDebug('Error running query', error)\n this.error(`Failed to run query: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n // GROQ returns null for no match; guard undefined, which colorizeJson cannot tokenize\n const output = result ?? null\n if (json) {\n this.logJson(output)\n return\n }\n\n this.log(colorizeJson(output))\n }\n}\n"],"names":["Args","Flags","colorizeJson","exitCodes","SanityCommand","subdebug","getErrorMessage","isRecord","MissingOrganizationError","resolveOrganizationId","queryContext","getOrganizationFlag","defineCommandTelemetry","queryContextDebug","flags","description","semantics","params","custom","helpValue","parse","input","parsed","JSON","Error","QueryContextCommand","args","query","string","required","enableJsonFlag","examples","command","telemetry","redact","run","json","organization","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","isUnattended","error","exit","USAGE_ERROR","RUNTIME_ERROR","result","output","logJson","log"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,YAAY,EAAEC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACjF,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,QAAQ,QAAO,wBAAuB;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AAEH;gBAC9DI,oBAAoBL;gBACpBM,YAAY,IAAI,CAACC,YAAY;YAC/B;QACF,EAAE,OAAOC,OAAO;YACdhC,kBAAkB,gCAAgCgC;YAClD,IAAI,CAACA,KAAK,CAACvC,gBAAgBuC,QAAQ;gBACjCC,MACED,iBAAiBrC,2BACbL,UAAU4C,WAAW,GACrB5C,UAAU6C,aAAa;YAC/B;QACF;QAEA,IAAIC;QACJ,IAAI;YACFA,SAAS,MAAMvC,aAAa4B,gBAAgBX,OAAOV;QACrD,EAAE,OAAO4B,OAAO;YACdhC,kBAAkB,uBAAuBgC;YACzC,IAAI,CAACA,KAAK,CAAC,CAAC,qBAAqB,EAAEvC,gBAAgBuC,QAAQ,EAAE;gBAC3DC,MAAM3C,UAAU6C,aAAa;YAC/B;QACF;QAEA,sFAAsF;QACtF,MAAME,SAASD,UAAU;QACzB,IAAIb,MAAM;YACR,IAAI,CAACe,OAAO,CAACD;YACb;QACF;QAEA,IAAI,CAACE,GAAG,CAAClD,aAAagD;IACxB;AACF"}
1
+ {"version":3,"sources":["../../../src/commands/context/query.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {colorizeJson, exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isRecord} from '@sanity/cli-core/util'\n\nimport {resolveOrganizationId} from '../../actions/context/resolveOrganizationId.js'\nimport {queryContext} from '../../services/context.js'\nimport {getOrganizationFlag} from '../../util/sharedFlags.js'\nimport {defineCommandTelemetry} from '../../util/telemetry/commandTelemetry.js'\n\nconst queryContextDebug = subdebug('context:query')\n\nconst flags = {\n ...getOrganizationFlag({\n description: 'Organization to query',\n semantics: 'override',\n }),\n params: Flags.custom<Record<string, unknown>>({\n description: 'Query parameters as a JSON object',\n helpValue: '<json>',\n parse: async (input: string) => {\n let parsed: unknown\n try {\n parsed = JSON.parse(input)\n } catch {\n throw new Error('`--params` must be valid JSON')\n }\n if (!isRecord(parsed)) {\n throw new Error('`--params` must be a JSON object, like \\'{\"type\": \"issue\"}\\'')\n }\n return parsed\n },\n })(),\n} satisfies FlagInput\n\nexport class QueryContextCommand extends SanityCommand<typeof QueryContextCommand> {\n static override args = {\n query: Args.string({\n description: \"GROQ query to run against the organization's Context documents\",\n required: true,\n }),\n }\n\n static override description = \"Query an organization's Context documents with GROQ\"\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command:\n '<%= config.bin %> <%= command.id %> \\'*[_type == \"sanity.context.issue\" && status == \"open\"]{_id, knowledgeBaseId}\\'',\n description: 'List open issues across all knowledge bases',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> \\'*[_type == \"sanity.context.entry\" && knowledgeBaseId == $kb].path\\' --params \\'{\"kb\": \"kb-abc123\"}\\' --json',\n description: 'List the entry paths of one knowledge base as plain JSON',\n },\n ]\n\n static override flags = flags\n\n static telemetry = defineCommandTelemetry(flags, {redact: ['params']})\n\n public async run(): Promise<void> {\n const {query} = this.args\n const {json, organization, params} = 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 result\n try {\n result = await queryContext(organizationId, query, params)\n } catch (error) {\n queryContextDebug('Error running query', error)\n this.error(`Failed to run query: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n // GROQ returns null for no match; guard undefined, which colorizeJson cannot tokenize\n const output = result ?? null\n if (json) {\n this.logJson(output)\n return\n }\n\n this.log(colorizeJson(output))\n }\n}\n"],"names":["Args","Flags","colorizeJson","exitCodes","SanityCommand","subdebug","getErrorMessage","isRecord","resolveOrganizationId","queryContext","getOrganizationFlag","defineCommandTelemetry","queryContextDebug","flags","description","semantics","params","custom","helpValue","parse","input","parsed","JSON","Error","QueryContextCommand","args","query","string","required","enableJsonFlag","examples","command","telemetry","redact","run","json","organization","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","isUnattended","result","error","exit","RUNTIME_ERROR","output","logJson","log"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,YAAY,EAAEC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACjF,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,QAAQ,QAAO,wBAAuB;AAE9C,SAAQC,qBAAqB,QAAO,iDAAgD;AACpF,SAAQC,YAAY,QAAO,4BAA2B;AACtD,SAAQC,mBAAmB,QAAO,4BAA2B;AAC7D,SAAQC,sBAAsB,QAAO,2CAA0C;AAE/E,MAAMC,oBAAoBP,SAAS;AAEnC,MAAMQ,QAAQ;IACZ,GAAGH,oBAAoB;QACrBI,aAAa;QACbC,WAAW;IACb,EAAE;IACFC,QAAQf,MAAMgB,MAAM,CAA0B;QAC5CH,aAAa;QACbI,WAAW;QACXC,OAAO,OAAOC;YACZ,IAAIC;YACJ,IAAI;gBACFA,SAASC,KAAKH,KAAK,CAACC;YACtB,EAAE,OAAM;gBACN,MAAM,IAAIG,MAAM;YAClB;YACA,IAAI,CAAChB,SAASc,SAAS;gBACrB,MAAM,IAAIE,MAAM;YAClB;YACA,OAAOF;QACT;IACF;AACF;AAEA,OAAO,MAAMG,4BAA4BpB;IACvC,OAAgBqB,OAAO;QACrBC,OAAO1B,KAAK2B,MAAM,CAAC;YACjBb,aAAa;YACbc,UAAU;QACZ;IACF,EAAC;IAED,OAAgBd,cAAc,sDAAqD;IAEnF,OAAgBe,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;YACEC,SACE;YACFjB,aAAa;QACf;QACA;YACEiB,SACE;YACFjB,aAAa;QACf;KACD,CAAA;IAED,OAAgBD,QAAQA,MAAK;IAE7B,OAAOmB,YAAYrB,uBAAuBE,OAAO;QAACoB,QAAQ;YAAC;SAAS;IAAA,GAAE;IAEtE,MAAaC,MAAqB;QAChC,MAAM,EAACR,KAAK,EAAC,GAAG,IAAI,CAACD,IAAI;QACzB,MAAM,EAACU,IAAI,EAAEC,YAAY,EAAEpB,MAAM,EAAC,GAAG,IAAI,CAACH,KAAK;QAE/C,MAAMwB,iBAAiB,MAAM7B,sBAAsB;YACjD8B,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,SAAS,MAAMnC,aAAa4B,gBAAgBX,OAAOV;QACrD,EAAE,OAAO6B,OAAO;YACdjC,kBAAkB,uBAAuBiC;YACzC,IAAI,CAACA,KAAK,CAAC,CAAC,qBAAqB,EAAEvC,gBAAgBuC,QAAQ,EAAE;gBAC3DC,MAAM3C,UAAU4C,aAAa;YAC/B;QACF;QAEA,sFAAsF;QACtF,MAAMC,SAASJ,UAAU;QACzB,IAAIT,MAAM;YACR,IAAI,CAACc,OAAO,CAACD;YACb;QACF;QAEA,IAAI,CAACE,GAAG,CAAChD,aAAa8C;IACxB;AACF"}
@@ -0,0 +1,175 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { basename } from 'node:path';
3
+ import { text as readStream } from 'node:stream/consumers';
4
+ import { Flags } from '@oclif/core';
5
+ import { exitCodes } from '@sanity/cli-core';
6
+ import { getErrorMessage } from '@sanity/cli-core/errors';
7
+ import { contextCommand } from '../../../actions/context/contextCommand.js';
8
+ import { flagName } from '../../../actions/context/operationInput.js';
9
+ import { readSourceFile } from '../../../actions/context/sourceFile.js';
10
+ import { createFileSource } from '../../../services/context.js';
11
+ import { defineCommandTelemetry } from '../../../util/telemetry/commandTelemetry.js';
12
+ const BaseCommand = contextCommand('context sources create');
13
+ const SOURCE_FLAGS = [
14
+ 'url',
15
+ 'query',
16
+ 'file',
17
+ 'text'
18
+ ];
19
+ /** The body fields a `--file` source takes; the file supplies the rest */ const FILE_BODY_FIELDS = new Set([
20
+ 'contentType',
21
+ 'title'
22
+ ]);
23
+ const flags = {
24
+ ...BaseCommand.flags,
25
+ file: Flags.string({
26
+ description: 'Local file to upload as a files source: a document, or a zip, tar or gzip archive of them',
27
+ exclusive: [
28
+ 'url',
29
+ 'query',
30
+ 'text'
31
+ ],
32
+ helpValue: '<path>'
33
+ }),
34
+ query: {
35
+ ...BaseCommand.flags.query,
36
+ exclusive: [
37
+ 'url',
38
+ 'file',
39
+ 'text'
40
+ ]
41
+ },
42
+ text: Flags.string({
43
+ description: 'Text or markdown to hold as a files source, read from a local file or `-` for stdin',
44
+ exclusive: [
45
+ 'url',
46
+ 'query',
47
+ 'file'
48
+ ],
49
+ helpValue: '<path|->'
50
+ }),
51
+ url: {
52
+ ...BaseCommand.flags.url,
53
+ exclusive: [
54
+ 'query',
55
+ 'file',
56
+ 'text'
57
+ ]
58
+ }
59
+ };
60
+ /**
61
+ * `context sources create` adds `--file`, which uploads a local file to a
62
+ * signed URL, and `--text`, which reads the content of a files source from a
63
+ * file or stdin. The rest is the spec's `createSource`.
64
+ */ export class CreateSourceCommand extends BaseCommand {
65
+ static examples = [
66
+ {
67
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 --url https://example.com/docs',
68
+ description: 'Crawl a website'
69
+ },
70
+ {
71
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 --url https://example.com/docs --dry-run',
72
+ description: 'Estimate how many pages a crawl of /docs would find, without adding it'
73
+ },
74
+ {
75
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 --query \'*[_type == "article"]\' --sanity-project-id abc123 --sanity-dataset-id production',
76
+ description: 'Read the documents a GROQ query selects from a Sanity dataset'
77
+ },
78
+ {
79
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 --file ./handbook.pdf --watch',
80
+ description: 'Upload a local file and wait for its sync'
81
+ },
82
+ {
83
+ command: 'cat refunds.md | <%= config.bin %> <%= command.id %> kb-abc123 --text - --title "Refund policy"',
84
+ description: 'Add markdown from stdin'
85
+ }
86
+ ];
87
+ static flags = flags;
88
+ static telemetry = {
89
+ redactedFlags: [
90
+ ...BaseCommand.telemetry.redactedFlags,
91
+ ...defineCommandTelemetry(flags, {
92
+ redact: [
93
+ 'file',
94
+ 'text'
95
+ ]
96
+ }).redactedFlags
97
+ ]
98
+ };
99
+ async send(request, values) {
100
+ const body = request.body ?? {};
101
+ const title = typeof body.title === 'string' ? body.title : undefined;
102
+ const { file, text } = values;
103
+ const given = SOURCE_FLAGS.filter((name)=>values[name] !== undefined);
104
+ if (given.length > 1 || given.length === 0 && body.type !== 'files') {
105
+ this.error('Provide exactly one of --url, --query, --file or --text, or `--type files --title <title>` for a files source whose file comes later with `sources upload`.', {
106
+ exit: exitCodes.USAGE_ERROR
107
+ });
108
+ }
109
+ if (typeof file === 'string') {
110
+ // Nested fields such as `crawlOptions.maxDepth` come from flags named after the field itself
111
+ const ignored = Object.entries(body).flatMap(([key, value])=>{
112
+ if (key === 'type') return value === 'files' || values.type === undefined ? [] : [
113
+ key
114
+ ];
115
+ if (FILE_BODY_FIELDS.has(key)) return [];
116
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? Object.keys(value) : [
117
+ key
118
+ ];
119
+ });
120
+ if (ignored.length > 0) {
121
+ this.error(`--file adds a files source, which takes only --title and --content-type. Remove ${ignored.map((name)=>`--${flagName({
122
+ name
123
+ })}`).join(', ')}.`, {
124
+ exit: exitCodes.USAGE_ERROR
125
+ });
126
+ }
127
+ const upload = await this.read(`file "${file}"`, ()=>readSourceFile(file, typeof body.contentType === 'string' ? body.contentType : undefined));
128
+ // The created source has no sync yet; `jobId` lets the output and `--watch` follow the upload's
129
+ const { source, sync } = await createFileSource(request.params.knowledgeBaseId, {
130
+ ...upload,
131
+ title: title ?? upload.filename,
132
+ type: 'files'
133
+ });
134
+ return {
135
+ ...source,
136
+ jobId: sync.jobId
137
+ };
138
+ }
139
+ if (typeof text === 'string') {
140
+ const fromStdin = text === '-';
141
+ if (fromStdin && !title) {
142
+ this.error('Text read from stdin needs a title. Provide it with the --title flag.', {
143
+ exit: exitCodes.USAGE_ERROR
144
+ });
145
+ }
146
+ const content = await this.read(fromStdin ? 'stdin' : `file "${text}"`, ()=>fromStdin ? readStream(process.stdin) : readFile(text, 'utf8'));
147
+ if (content.trim() === '') {
148
+ this.error('Text content cannot be empty', {
149
+ exit: exitCodes.USAGE_ERROR
150
+ });
151
+ }
152
+ return super.send({
153
+ ...request,
154
+ body: {
155
+ ...body,
156
+ content,
157
+ title: title ?? basename(text),
158
+ type: 'files'
159
+ }
160
+ }, values);
161
+ }
162
+ return super.send(request, values);
163
+ }
164
+ async read(what, read) {
165
+ try {
166
+ return await read();
167
+ } catch (error) {
168
+ this.error(`Failed to read ${what}: ${getErrorMessage(error)}`, {
169
+ exit: exitCodes.RUNTIME_ERROR
170
+ });
171
+ }
172
+ }
173
+ }
174
+
175
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/sources/create.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\nimport {basename} from 'node:path'\nimport {text as readStream} from 'node:stream/consumers'\n\nimport {Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\n\nimport {contextCommand} from '../../../actions/context/contextCommand.js'\nimport {flagName, type OperationRequest} from '../../../actions/context/operationInput.js'\nimport {readSourceFile} from '../../../actions/context/sourceFile.js'\nimport {createFileSource} from '../../../services/context.js'\nimport {defineCommandTelemetry} from '../../../util/telemetry/commandTelemetry.js'\n\nconst BaseCommand = contextCommand('context sources create')\n\nconst SOURCE_FLAGS = ['url', 'query', 'file', 'text'] as const\n\n/** The body fields a `--file` source takes; the file supplies the rest */\nconst FILE_BODY_FIELDS = new Set(['contentType', 'title'])\n\nconst flags = {\n ...BaseCommand.flags,\n file: Flags.string({\n description:\n 'Local file to upload as a files source: a document, or a zip, tar or gzip archive of them',\n exclusive: ['url', 'query', 'text'],\n helpValue: '<path>',\n }),\n query: {...BaseCommand.flags.query, exclusive: ['url', 'file', 'text']},\n text: Flags.string({\n description:\n 'Text or markdown to hold as a files source, read from a local file or `-` for stdin',\n exclusive: ['url', 'query', 'file'],\n helpValue: '<path|->',\n }),\n url: {...BaseCommand.flags.url, exclusive: ['query', 'file', 'text']},\n} satisfies FlagInput\n\n/**\n * `context sources create` adds `--file`, which uploads a local file to a\n * signed URL, and `--text`, which reads the content of a files source from a\n * file or stdin. The rest is the spec's `createSource`.\n */\nexport class CreateSourceCommand extends BaseCommand {\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 --url https://example.com/docs',\n description: 'Crawl a website',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> kb-abc123 --url https://example.com/docs --dry-run',\n description: 'Estimate how many pages a crawl of /docs would find, without adding it',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> kb-abc123 --query \\'*[_type == \"article\"]\\' --sanity-project-id abc123 --sanity-dataset-id production',\n description: 'Read the documents a GROQ query selects from a Sanity dataset',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 --file ./handbook.pdf --watch',\n description: 'Upload a local file and wait for its sync',\n },\n {\n command:\n 'cat refunds.md | <%= config.bin %> <%= command.id %> kb-abc123 --text - --title \"Refund policy\"',\n description: 'Add markdown from stdin',\n },\n ]\n\n static override flags = flags\n\n static override telemetry = {\n redactedFlags: [\n ...BaseCommand.telemetry.redactedFlags,\n ...defineCommandTelemetry(flags, {redact: ['file', 'text']}).redactedFlags,\n ],\n }\n\n public override async send(\n request: OperationRequest,\n values: Record<string, unknown>,\n ): Promise<unknown> {\n const body = request.body ?? {}\n const title = typeof body.title === 'string' ? body.title : undefined\n const {file, text} = values\n\n const given = SOURCE_FLAGS.filter((name) => values[name] !== undefined)\n if (given.length > 1 || (given.length === 0 && body.type !== 'files')) {\n this.error(\n 'Provide exactly one of --url, --query, --file or --text, or `--type files --title <title>` for a files source whose file comes later with `sources upload`.',\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n if (typeof file === 'string') {\n // Nested fields such as `crawlOptions.maxDepth` come from flags named after the field itself\n const ignored = Object.entries(body).flatMap(([key, value]) => {\n if (key === 'type') return value === 'files' || values.type === undefined ? [] : [key]\n if (FILE_BODY_FIELDS.has(key)) return []\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n ? Object.keys(value)\n : [key]\n })\n if (ignored.length > 0) {\n this.error(\n `--file adds a files source, which takes only --title and --content-type. Remove ${ignored.map((name) => `--${flagName({name})}`).join(', ')}.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n const upload = await this.read(`file \"${file}\"`, () =>\n readSourceFile(file, typeof body.contentType === 'string' ? body.contentType : undefined),\n )\n // The created source has no sync yet; `jobId` lets the output and `--watch` follow the upload's\n const {source, sync} = await createFileSource(request.params.knowledgeBaseId, {\n ...upload,\n title: title ?? upload.filename,\n type: 'files',\n })\n return {...source, jobId: sync.jobId}\n }\n\n if (typeof text === 'string') {\n const fromStdin = text === '-'\n if (fromStdin && !title) {\n this.error('Text read from stdin needs a title. Provide it with the --title flag.', {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n const content = await this.read(fromStdin ? 'stdin' : `file \"${text}\"`, () =>\n fromStdin ? readStream(process.stdin) : readFile(text, 'utf8'),\n )\n if (content.trim() === '') {\n this.error('Text content cannot be empty', {exit: exitCodes.USAGE_ERROR})\n }\n return super.send(\n {...request, body: {...body, content, title: title ?? basename(text), type: 'files'}},\n values,\n )\n }\n\n return super.send(request, values)\n }\n\n private async read<T>(what: string, read: () => Promise<T>): Promise<T> {\n try {\n return await read()\n } catch (error) {\n this.error(`Failed to read ${what}: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["readFile","basename","text","readStream","Flags","exitCodes","getErrorMessage","contextCommand","flagName","readSourceFile","createFileSource","defineCommandTelemetry","BaseCommand","SOURCE_FLAGS","FILE_BODY_FIELDS","Set","flags","file","string","description","exclusive","helpValue","query","url","CreateSourceCommand","examples","command","telemetry","redactedFlags","redact","send","request","values","body","title","undefined","given","filter","name","length","type","error","exit","USAGE_ERROR","ignored","Object","entries","flatMap","key","value","has","Array","isArray","keys","map","join","upload","read","contentType","source","sync","params","knowledgeBaseId","filename","jobId","fromStdin","content","process","stdin","trim","what","RUNTIME_ERROR"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,SAAQC,QAAQ,QAAO,YAAW;AAClC,SAAQC,QAAQC,UAAU,QAAO,wBAAuB;AAExD,SAAQC,KAAK,QAAO,cAAa;AAEjC,SAAQC,SAAS,QAAO,mBAAkB;AAC1C,SAAQC,eAAe,QAAO,0BAAyB;AAEvD,SAAQC,cAAc,QAAO,6CAA4C;AACzE,SAAQC,QAAQ,QAA8B,6CAA4C;AAC1F,SAAQC,cAAc,QAAO,yCAAwC;AACrE,SAAQC,gBAAgB,QAAO,+BAA8B;AAC7D,SAAQC,sBAAsB,QAAO,8CAA6C;AAElF,MAAMC,cAAcL,eAAe;AAEnC,MAAMM,eAAe;IAAC;IAAO;IAAS;IAAQ;CAAO;AAErD,wEAAwE,GACxE,MAAMC,mBAAmB,IAAIC,IAAI;IAAC;IAAe;CAAQ;AAEzD,MAAMC,QAAQ;IACZ,GAAGJ,YAAYI,KAAK;IACpBC,MAAMb,MAAMc,MAAM,CAAC;QACjBC,aACE;QACFC,WAAW;YAAC;YAAO;YAAS;SAAO;QACnCC,WAAW;IACb;IACAC,OAAO;QAAC,GAAGV,YAAYI,KAAK,CAACM,KAAK;QAAEF,WAAW;YAAC;YAAO;YAAQ;SAAO;IAAA;IACtElB,MAAME,MAAMc,MAAM,CAAC;QACjBC,aACE;QACFC,WAAW;YAAC;YAAO;YAAS;SAAO;QACnCC,WAAW;IACb;IACAE,KAAK;QAAC,GAAGX,YAAYI,KAAK,CAACO,GAAG;QAAEH,WAAW;YAAC;YAAS;YAAQ;SAAO;I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AAK,CAAC,gCAAgC;oBAACC,MAAMrC,UAAUsC,WAAW;gBAAA;YACzE;YACA,OAAO,KAAK,CAACb,KACX;gBAAC,GAAGC,OAAO;gBAAEE,MAAM;oBAAC,GAAGA,IAAI;oBAAEiC;oBAAShC,OAAOA,SAASjC,SAASC;oBAAOsC,MAAM;gBAAO;YAAC,GACpFR;QAEJ;QAEA,OAAO,KAAK,CAACF,KAAKC,SAASC;IAC7B;IAEA,MAAcyB,KAAQa,IAAY,EAAEb,IAAsB,EAAc;QACtE,IAAI;YACF,OAAO,MAAMA;QACf,EAAE,OAAOhB,OAAO;YACd,IAAI,CAACA,KAAK,CAAC,CAAC,eAAe,EAAE6B,KAAK,EAAE,EAAEhE,gBAAgBmC,QAAQ,EAAE;gBAC9DC,MAAMrC,UAAUkE,aAAa;YAC/B;QACF;IACF;AACF"}
@@ -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 DeleteSourceCommand = contextCommand('context sources delete');
4
+
5
+ //# sourceMappingURL=delete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/sources/delete.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../../actions/context/contextCommand.js'\n\nexport const DeleteSourceCommand = contextCommand('context sources delete')\n"],"names":["contextCommand","DeleteSourceCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,6CAA4C;AAEzE,OAAO,MAAMC,sBAAsBD,eAAe,0BAAyB"}
@@ -0,0 +1,29 @@
1
+ import { contextCommand } from '../../../actions/context/contextCommand.js';
2
+ import { getSource } from '../../../services/context.js';
3
+ const BaseCommand = contextCommand('context sources edit');
4
+ /**
5
+ * `context sources edit` merges crawl option flags onto the source's stored
6
+ * crawl options: the API replaces `crawlOptions` as a whole, so changing one
7
+ * flag must not drop the others.
8
+ */ export class UpdateSourceCommand extends BaseCommand {
9
+ async send(request, values) {
10
+ const crawlOptions = request.body?.crawlOptions;
11
+ if (typeof crawlOptions !== 'object' || crawlOptions === null) {
12
+ return super.send(request, values);
13
+ }
14
+ const source = await getSource(request.params.knowledgeBaseId, request.params.sourceId);
15
+ const stored = 'crawlOptions' in source ? source.crawlOptions : undefined;
16
+ return super.send({
17
+ ...request,
18
+ body: {
19
+ ...request.body,
20
+ crawlOptions: {
21
+ ...stored,
22
+ ...crawlOptions
23
+ }
24
+ }
25
+ }, values);
26
+ }
27
+ }
28
+
29
+ //# sourceMappingURL=edit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/sources/edit.ts"],"sourcesContent":["import {contextCommand} from '../../../actions/context/contextCommand.js'\nimport {type OperationRequest} from '../../../actions/context/operationInput.js'\nimport {getSource} from '../../../services/context.js'\n\nconst BaseCommand = contextCommand('context sources edit')\n\n/**\n * `context sources edit` merges crawl option flags onto the source's stored\n * crawl options: the API replaces `crawlOptions` as a whole, so changing one\n * flag must not drop the others.\n */\nexport class UpdateSourceCommand extends BaseCommand {\n public override async send(\n request: OperationRequest,\n values: Record<string, unknown>,\n ): Promise<unknown> {\n const crawlOptions = request.body?.crawlOptions\n if (typeof crawlOptions !== 'object' || crawlOptions === null) {\n return super.send(request, values)\n }\n const source = await getSource(request.params.knowledgeBaseId, request.params.sourceId)\n const stored = 'crawlOptions' in source ? source.crawlOptions : undefined\n return super.send(\n {...request, body: {...request.body, crawlOptions: {...stored, ...crawlOptions}}},\n values,\n )\n }\n}\n"],"names":["contextCommand","getSource","BaseCommand","UpdateSourceCommand","send","request","values","crawlOptions","body","source","params","knowledgeBaseId","sourceId","stored","undefined"],"mappings":"AAAA,SAAQA,cAAc,QAAO,6CAA4C;AAEzE,SAAQC,SAAS,QAAO,+BAA8B;AAEtD,MAAMC,cAAcF,eAAe;AAEnC;;;;CAIC,GACD,OAAO,MAAMG,4BAA4BD;IACvC,MAAsBE,KACpBC,OAAyB,EACzBC,MAA+B,EACb;QAClB,MAAMC,eAAeF,QAAQG,IAAI,EAAED;QACnC,IAAI,OAAOA,iBAAiB,YAAYA,iBAAiB,MAAM;YAC7D,OAAO,KAAK,CAACH,KAAKC,SAASC;QAC7B;QACA,MAAMG,SAAS,MAAMR,UAAUI,QAAQK,MAAM,CAACC,eAAe,EAAEN,QAAQK,MAAM,CAACE,QAAQ;QACtF,MAAMC,SAAS,kBAAkBJ,SAASA,OAAOF,YAAY,GAAGO;QAChE,OAAO,KAAK,CAACV,KACX;YAAC,GAAGC,OAAO;YAAEG,MAAM;gBAAC,GAAGH,QAAQG,IAAI;gBAAED,cAAc;oBAAC,GAAGM,MAAM;oBAAE,GAAGN,YAAY;gBAAA;YAAC;QAAC,GAChFD;IAEJ;AACF"}
@@ -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 GetSourceCommand = contextCommand('context sources get');
4
+
5
+ //# sourceMappingURL=get.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/sources/get.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../../actions/context/contextCommand.js'\n\nexport const GetSourceCommand = contextCommand('context sources get')\n"],"names":["contextCommand","GetSourceCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,6CAA4C;AAEzE,OAAO,MAAMC,mBAAmBD,eAAe,uBAAsB"}
@@ -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 ListSourcesCommand = contextCommand('context sources list');
4
+
5
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/sources/list.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../../actions/context/contextCommand.js'\n\nexport const ListSourcesCommand = contextCommand('context sources list')\n"],"names":["contextCommand","ListSourcesCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,6CAA4C;AAEzE,OAAO,MAAMC,qBAAqBD,eAAe,wBAAuB"}
@@ -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 StartSyncCommand = contextCommand('context sources sync');
4
+
5
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/sources/sync.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../../actions/context/contextCommand.js'\n\nexport const StartSyncCommand = contextCommand('context sources sync')\n"],"names":["contextCommand","StartSyncCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,6CAA4C;AAEzE,OAAO,MAAMC,mBAAmBD,eAAe,wBAAuB"}
@@ -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 ConfirmSyncCommand = contextCommand('context sources syncs confirm');
4
+
5
+ //# sourceMappingURL=confirm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/commands/context/sources/syncs/confirm.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../../../actions/context/contextCommand.js'\n\nexport const ConfirmSyncCommand = contextCommand('context sources syncs confirm')\n"],"names":["contextCommand","ConfirmSyncCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,gDAA+C;AAE5E,OAAO,MAAMC,qBAAqBD,eAAe,iCAAgC"}
@@ -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 DiscardSyncCommand = contextCommand('context sources syncs discard');
4
+
5
+ //# sourceMappingURL=discard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/commands/context/sources/syncs/discard.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../../../actions/context/contextCommand.js'\n\nexport const DiscardSyncCommand = contextCommand('context sources syncs discard')\n"],"names":["contextCommand","DiscardSyncCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,gDAA+C;AAE5E,OAAO,MAAMC,qBAAqBD,eAAe,iCAAgC"}
@@ -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 GetSyncCommand = contextCommand('context sources syncs get');
4
+
5
+ //# sourceMappingURL=get.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/commands/context/sources/syncs/get.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../../../actions/context/contextCommand.js'\n\nexport const GetSyncCommand = contextCommand('context sources syncs get')\n"],"names":["contextCommand","GetSyncCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,gDAA+C;AAE5E,OAAO,MAAMC,iBAAiBD,eAAe,6BAA4B"}
@@ -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 ListSyncsCommand = contextCommand('context sources syncs list');
4
+
5
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/commands/context/sources/syncs/list.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../../../actions/context/contextCommand.js'\n\nexport const ListSyncsCommand = contextCommand('context sources syncs list')\n"],"names":["contextCommand","ListSyncsCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,gDAA+C;AAE5E,OAAO,MAAMC,mBAAmBD,eAAe,8BAA6B"}
@@ -0,0 +1,63 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { exitCodes } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { contextCommand } from '../../../actions/context/contextCommand.js';
5
+ import { readSourceFile } from '../../../actions/context/sourceFile.js';
6
+ import { uploadSourceFile } from '../../../services/context.js';
7
+ import { defineCommandTelemetry } from '../../../util/telemetry/commandTelemetry.js';
8
+ const BaseCommand = contextCommand('context sources upload');
9
+ const flags = {
10
+ ...BaseCommand.flags,
11
+ 'content-type': Flags.string({
12
+ description: 'MIME type of the file, inferred from the file extension when omitted',
13
+ helpValue: '<type>'
14
+ }),
15
+ file: Flags.string({
16
+ description: 'Local file to upload: a document, or a zip, tar or gzip archive of them',
17
+ helpValue: '<path>',
18
+ required: true
19
+ })
20
+ };
21
+ /**
22
+ * `context sources upload` reads a local file and hands it to the client's
23
+ * upload helper, which stages the upload, PUTs the bytes to the signed URL and
24
+ * syncs the source. The spec's `startSourceUpload` only stages it.
25
+ */ export class UploadSourceFileCommand extends BaseCommand {
26
+ static description = 'Upload a new file to a files source, replacing the one it holds, and sync it';
27
+ static examples = [
28
+ {
29
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 source-def456 --file ./handbook.pdf',
30
+ description: 'Replace the file a source holds'
31
+ },
32
+ {
33
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 source-def456 --file ./handbook.pdf --watch',
34
+ description: 'Replace the file and wait for its sync to finish'
35
+ }
36
+ ];
37
+ static flags = flags;
38
+ static telemetry = {
39
+ redactedFlags: [
40
+ ...BaseCommand.telemetry.redactedFlags,
41
+ ...defineCommandTelemetry(flags, {
42
+ redact: [
43
+ 'file'
44
+ ]
45
+ }).redactedFlags
46
+ ]
47
+ };
48
+ async send(request, values) {
49
+ const file = String(values.file);
50
+ const contentType = typeof values['content-type'] === 'string' ? values['content-type'] : undefined;
51
+ let upload;
52
+ try {
53
+ upload = await readSourceFile(file, contentType);
54
+ } catch (error) {
55
+ this.error(`Failed to read file "${file}": ${getErrorMessage(error)}`, {
56
+ exit: exitCodes.RUNTIME_ERROR
57
+ });
58
+ }
59
+ return uploadSourceFile(request.params.knowledgeBaseId, request.params.sourceId, upload);
60
+ }
61
+ }
62
+
63
+ //# sourceMappingURL=upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/sources/upload.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\n\nimport {contextCommand} from '../../../actions/context/contextCommand.js'\nimport {type OperationRequest} from '../../../actions/context/operationInput.js'\nimport {readSourceFile} from '../../../actions/context/sourceFile.js'\nimport {uploadSourceFile} from '../../../services/context.js'\nimport {defineCommandTelemetry} from '../../../util/telemetry/commandTelemetry.js'\n\nconst BaseCommand = contextCommand('context sources upload')\n\nconst flags = {\n ...BaseCommand.flags,\n 'content-type': Flags.string({\n description: 'MIME type of the file, inferred from the file extension when omitted',\n helpValue: '<type>',\n }),\n file: Flags.string({\n description: 'Local file to upload: a document, or a zip, tar or gzip archive of them',\n helpValue: '<path>',\n required: true,\n }),\n} satisfies FlagInput\n\n/**\n * `context sources upload` reads a local file and hands it to the client's\n * upload helper, which stages the upload, PUTs the bytes to the signed URL and\n * syncs the source. The spec's `startSourceUpload` only stages it.\n */\nexport class UploadSourceFileCommand extends BaseCommand {\n static override description =\n 'Upload a new file to a files source, replacing the one it holds, and sync it'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 source-def456 --file ./handbook.pdf',\n description: 'Replace the file a source holds',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> kb-abc123 source-def456 --file ./handbook.pdf --watch',\n description: 'Replace the file and wait for its sync to finish',\n },\n ]\n\n static override flags = flags\n\n static override telemetry = {\n redactedFlags: [\n ...BaseCommand.telemetry.redactedFlags,\n ...defineCommandTelemetry(flags, {redact: ['file']}).redactedFlags,\n ],\n }\n\n public override async send(\n request: OperationRequest,\n values: Record<string, unknown>,\n ): Promise<unknown> {\n const file = String(values.file)\n const contentType =\n typeof values['content-type'] === 'string' ? values['content-type'] : undefined\n let upload\n try {\n upload = await readSourceFile(file, contentType)\n } catch (error) {\n this.error(`Failed to read file \"${file}\": ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n return uploadSourceFile(request.params.knowledgeBaseId, request.params.sourceId, upload)\n }\n}\n"],"names":["Flags","exitCodes","getErrorMessage","contextCommand","readSourceFile","uploadSourceFile","defineCommandTelemetry","BaseCommand","flags","string","description","helpValue","file","required","UploadSourceFileCommand","examples","command","telemetry","redactedFlags","redact","send","request","values","String","contentType","undefined","upload","error","exit","RUNTIME_ERROR","params","knowledgeBaseId","sourceId"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AAEjC,SAAQC,SAAS,QAAO,mBAAkB;AAC1C,SAAQC,eAAe,QAAO,0BAAyB;AAEvD,SAAQC,cAAc,QAAO,6CAA4C;AAEzE,SAAQC,cAAc,QAAO,yCAAwC;AACrE,SAAQC,gBAAgB,QAAO,+BAA8B;AAC7D,SAAQC,sBAAsB,QAAO,8CAA6C;AAElF,MAAMC,cAAcJ,eAAe;AAEnC,MAAMK,QAAQ;IACZ,GAAGD,YAAYC,KAAK;IACpB,gBAAgBR,MAAMS,MAAM,CAAC;QAC3BC,aAAa;QACbC,WAAW;IACb;IACAC,MAAMZ,MAAMS,MAAM,CAAC;QACjBC,aAAa;QACbC,WAAW;QACXE,UAAU;IACZ;AACF;AAEA;;;;CAIC,GACD,OAAO,MAAMC,gCAAgCP;IAC3C,OAAgBG,cACd,+EAA8E;IAEhF,OAAgBK,WAAW;QACzB;YACEC,SAAS;YACTN,aAAa;QACf;QACA;YACEM,SACE;YACFN,aAAa;QACf;KACD,CAAA;IAED,OAAgBF,QAAQA,MAAK;IAE7B,OAAgBS,YAAY;QAC1BC,eAAe;eACVX,YAAYU,SAAS,CAACC,aAAa;eACnCZ,uBAAuBE,OAAO;gBAACW,QAAQ;oBAAC;iBAAO;YAAA,GAAGD,aAAa;SACnE;IACH,EAAC;IAED,MAAsBE,KACpBC,OAAyB,EACzBC,MAA+B,EACb;QAClB,MAAMV,OAAOW,OAAOD,OAAOV,IAAI;QAC/B,MAAMY,cACJ,OAAOF,MAAM,CAAC,eAAe,KAAK,WAAWA,MAAM,CAAC,eAAe,GAAGG;QACxE,IAAIC;QACJ,IAAI;YACFA,SAAS,MAAMtB,eAAeQ,MAAMY;QACtC,EAAE,OAAOG,OAAO;YACd,IAAI,CAACA,KAAK,CAAC,CAAC,qBAAqB,EAAEf,KAAK,GAAG,EAAEV,gBAAgByB,QAAQ,EAAE;gBACrEC,MAAM3B,UAAU4B,aAAa;YAC/B;QACF;QACA,OAAOxB,iBAAiBgB,QAAQS,MAAM,CAACC,eAAe,EAAEV,QAAQS,MAAM,CAACE,QAAQ,EAAEN;IACnF;AACF"}
@@ -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 SyncAllSourcesCommand = contextCommand('context sync');
4
+
5
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/commands/context/sync.ts"],"sourcesContent":["// GENERATED FILE - DO NOT EDIT. Regenerate with: pnpm generate:context-commands\nimport {contextCommand} from '../../actions/context/contextCommand.js'\n\nexport const SyncAllSourcesCommand = contextCommand('context sync')\n"],"names":["contextCommand","SyncAllSourcesCommand"],"mappings":"AAAA,gFAAgF;AAChF,SAAQA,cAAc,QAAO,0CAAyC;AAEtE,OAAO,MAAMC,wBAAwBD,eAAe,gBAAe"}