@sanity/cli 8.7.0 → 8.8.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 (96) hide show
  1. package/README.md +396 -0
  2. package/dist/actions/api/distillApiRoutes.js +1 -1
  3. package/dist/actions/api/distillApiRoutes.js.map +1 -1
  4. package/dist/actions/api/resolveEndpoint.js +1 -1
  5. package/dist/actions/api/resolveEndpoint.js.map +1 -1
  6. package/dist/actions/backup/archiveDir.js +7 -3
  7. package/dist/actions/backup/archiveDir.js.map +1 -1
  8. package/dist/actions/context/resolveOrganizationId.js +17 -0
  9. package/dist/actions/context/resolveOrganizationId.js.map +1 -0
  10. package/dist/actions/context/waitForJob.js +24 -0
  11. package/dist/actions/context/waitForJob.js.map +1 -0
  12. package/dist/actions/context/watchJob.js +32 -0
  13. package/dist/actions/context/watchJob.js.map +1 -0
  14. package/dist/actions/deploy/deployApp.js +6 -6
  15. package/dist/actions/deploy/deployApp.js.map +1 -1
  16. package/dist/actions/deploy/deployStudio.js +6 -6
  17. package/dist/actions/deploy/deployStudio.js.map +1 -1
  18. package/dist/actions/exec/execScript.js +6 -18
  19. package/dist/actions/exec/execScript.js.map +1 -1
  20. package/dist/actions/exec/runScript.worker.js +21 -0
  21. package/dist/actions/exec/runScript.worker.js.map +1 -0
  22. package/dist/actions/init/initAction.js +1 -1
  23. package/dist/actions/init/initAction.js.map +1 -1
  24. package/dist/actions/media/importMedia.js +4 -2
  25. package/dist/actions/media/importMedia.js.map +1 -1
  26. package/dist/commands/backups/download.js +8 -17
  27. package/dist/commands/backups/download.js.map +1 -1
  28. package/dist/commands/context/build.js +111 -0
  29. package/dist/commands/context/build.js.map +1 -0
  30. package/dist/commands/context/create.js +106 -0
  31. package/dist/commands/context/create.js.map +1 -0
  32. package/dist/commands/context/delete.js +68 -0
  33. package/dist/commands/context/delete.js.map +1 -0
  34. package/dist/commands/context/get.js +95 -0
  35. package/dist/commands/context/get.js.map +1 -0
  36. package/dist/commands/context/imports/create.js +270 -0
  37. package/dist/commands/context/imports/create.js.map +1 -0
  38. package/dist/commands/context/imports/delete.js +73 -0
  39. package/dist/commands/context/imports/delete.js.map +1 -0
  40. package/dist/commands/context/imports/download.js +65 -0
  41. package/dist/commands/context/imports/download.js.map +1 -0
  42. package/dist/commands/context/imports/get.js +93 -0
  43. package/dist/commands/context/imports/get.js.map +1 -0
  44. package/dist/commands/context/imports/list.js +105 -0
  45. package/dist/commands/context/imports/list.js.map +1 -0
  46. package/dist/commands/context/jobs/get.js +90 -0
  47. package/dist/commands/context/jobs/get.js.map +1 -0
  48. package/dist/commands/context/list.js +109 -0
  49. package/dist/commands/context/list.js.map +1 -0
  50. package/dist/commands/context/refresh.js +46 -0
  51. package/dist/commands/context/refresh.js.map +1 -0
  52. package/dist/commands/context/update.js +127 -0
  53. package/dist/commands/context/update.js.map +1 -0
  54. package/dist/commands/datasets/alias/delete.js +4 -9
  55. package/dist/commands/datasets/alias/delete.js.map +1 -1
  56. package/dist/commands/datasets/alias/unlink.js +4 -9
  57. package/dist/commands/datasets/alias/unlink.js.map +1 -1
  58. package/dist/commands/datasets/delete.js +4 -9
  59. package/dist/commands/datasets/delete.js.map +1 -1
  60. package/dist/commands/graphql/undeploy.js +4 -9
  61. package/dist/commands/graphql/undeploy.js.map +1 -1
  62. package/dist/commands/init.js +1 -1
  63. package/dist/commands/init.js.map +1 -1
  64. package/dist/commands/media/create-aspect.js +5 -6
  65. package/dist/commands/media/create-aspect.js.map +1 -1
  66. package/dist/commands/media/delete-aspect.js +7 -23
  67. package/dist/commands/media/delete-aspect.js.map +1 -1
  68. package/dist/commands/media/deploy-aspect.js +4 -9
  69. package/dist/commands/media/deploy-aspect.js.map +1 -1
  70. package/dist/commands/media/export.js +3 -7
  71. package/dist/commands/media/export.js.map +1 -1
  72. package/dist/commands/media/import.js +3 -7
  73. package/dist/commands/media/import.js.map +1 -1
  74. package/dist/commands/organizations/create.js +4 -9
  75. package/dist/commands/organizations/create.js.map +1 -1
  76. package/dist/commands/schemas/delete.js +3 -8
  77. package/dist/commands/schemas/delete.js.map +1 -1
  78. package/dist/commands/tokens/delete.js +4 -7
  79. package/dist/commands/tokens/delete.js.map +1 -1
  80. package/dist/commands/users/invite.js +8 -18
  81. package/dist/commands/users/invite.js.map +1 -1
  82. package/dist/exports/index.js +1 -1
  83. package/dist/exports/index.js.map +1 -1
  84. package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js +18 -0
  85. package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js.map +1 -1
  86. package/dist/generated/apiRoutes.js +11 -9
  87. package/dist/generated/apiRoutes.js.map +1 -1
  88. package/dist/prompts/promptForOrganization.js +19 -0
  89. package/dist/prompts/promptForOrganization.js.map +1 -0
  90. package/dist/services/context.js +132 -0
  91. package/dist/services/context.js.map +1 -0
  92. package/dist/util/sharedFlags.js +24 -0
  93. package/dist/util/sharedFlags.js.map +1 -1
  94. package/oclif.config.js +1 -0
  95. package/oclif.manifest.json +1931 -1133
  96. package/package.json +16 -22
@@ -0,0 +1,93 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { isHttpError } from '@sanity/client';
5
+ import { formatKeyValue } from '../../../actions/debug/output.js';
6
+ import { getImport } from '../../../services/context.js';
7
+ const getImportDebug = subdebug('context:imports:get');
8
+ export class GetImportCommand extends SanityCommand {
9
+ static args = {
10
+ knowledgeBaseId: Args.string({
11
+ description: 'Knowledge base ID',
12
+ required: true
13
+ }),
14
+ // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first
15
+ importId: Args.string({
16
+ description: 'Import ID',
17
+ required: true
18
+ })
19
+ };
20
+ static description = 'Get details of an import';
21
+ static examples = [
22
+ {
23
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456',
24
+ description: 'Get details of a specific import'
25
+ },
26
+ {
27
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456 --json',
28
+ description: 'Output the import as JSON'
29
+ }
30
+ ];
31
+ static flags = {
32
+ json: Flags.boolean({
33
+ default: false,
34
+ description: 'Output the import in JSON format'
35
+ })
36
+ };
37
+ async run() {
38
+ const { importId, knowledgeBaseId } = this.args;
39
+ const { json } = this.flags;
40
+ let importDetail;
41
+ try {
42
+ importDetail = await getImport(knowledgeBaseId, importId);
43
+ } catch (error) {
44
+ getImportDebug('Error getting import', error);
45
+ if (isHttpError(error) && error.statusCode === 404) {
46
+ this.error(`Import "${importId}" not found on knowledge base "${knowledgeBaseId}"`, {
47
+ exit: exitCodes.RUNTIME_ERROR
48
+ });
49
+ }
50
+ this.error(`Failed to get import: ${getErrorMessage(error)}`, {
51
+ exit: exitCodes.RUNTIME_ERROR
52
+ });
53
+ }
54
+ if (json) {
55
+ this.log(JSON.stringify(importDetail, null, 2));
56
+ return;
57
+ }
58
+ const padTo = 9 // "Completed" is the longest key
59
+ ;
60
+ this.log(formatKeyValue('ID', importDetail.id, {
61
+ padTo
62
+ }));
63
+ this.log(formatKeyValue('Name', importDetail.name ?? '-', {
64
+ padTo
65
+ }));
66
+ this.log(formatKeyValue('Kind', importDetail.sourceKind, {
67
+ padTo
68
+ }));
69
+ this.log(formatKeyValue('Status', importDetail.status, {
70
+ padTo
71
+ }));
72
+ this.log(formatKeyValue('Detail', importDetail.statusDetail ?? '-', {
73
+ padTo
74
+ }));
75
+ this.log(formatKeyValue('Error', importDetail.error ?? '-', {
76
+ padTo
77
+ }));
78
+ this.log(formatKeyValue('Sources', importDetail.sourceCount, {
79
+ padTo
80
+ }));
81
+ this.log(formatKeyValue('Distilled', `${importDetail.distilledCount}/${importDetail.totalDistillableCount}`, {
82
+ padTo
83
+ }));
84
+ this.log(formatKeyValue('Created', importDetail.createdAt, {
85
+ padTo
86
+ }));
87
+ this.log(formatKeyValue('Completed', importDetail.completedAt ?? '-', {
88
+ padTo
89
+ }));
90
+ }
91
+ }
92
+
93
+ //# sourceMappingURL=get.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/imports/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} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {getImport} from '../../../services/context.js'\n\nconst getImportDebug = subdebug('context:imports:get')\n\nexport class GetImportCommand extends SanityCommand<typeof GetImportCommand> {\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 importId: Args.string({\n description: 'Import ID',\n required: true,\n }),\n }\n\n static override description = 'Get details of an import'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456',\n description: 'Get details of a specific import',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456 --json',\n description: 'Output the import as JSON',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n default: false,\n description: 'Output the import in JSON format',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {importId, knowledgeBaseId} = this.args\n const {json} = this.flags\n\n let importDetail\n try {\n importDetail = await getImport(knowledgeBaseId, importId)\n } catch (error) {\n getImportDebug('Error getting import', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Import \"${importId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to get import: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.log(JSON.stringify(importDetail, null, 2))\n return\n }\n\n const padTo = 9 // \"Completed\" is the longest key\n this.log(formatKeyValue('ID', importDetail.id, {padTo}))\n this.log(formatKeyValue('Name', importDetail.name ?? '-', {padTo}))\n this.log(formatKeyValue('Kind', importDetail.sourceKind, {padTo}))\n this.log(formatKeyValue('Status', importDetail.status, {padTo}))\n this.log(formatKeyValue('Detail', importDetail.statusDetail ?? '-', {padTo}))\n this.log(formatKeyValue('Error', importDetail.error ?? '-', {padTo}))\n this.log(formatKeyValue('Sources', importDetail.sourceCount, {padTo}))\n this.log(\n formatKeyValue(\n 'Distilled',\n `${importDetail.distilledCount}/${importDetail.totalDistillableCount}`,\n {padTo},\n ),\n )\n this.log(formatKeyValue('Created', importDetail.createdAt, {padTo}))\n this.log(formatKeyValue('Completed', importDetail.completedAt ?? '-', {padTo}))\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","formatKeyValue","getImport","getImportDebug","GetImportCommand","args","knowledgeBaseId","string","description","required","importId","examples","command","flags","json","boolean","default","run","importDetail","error","statusCode","exit","RUNTIME_ERROR","log","JSON","stringify","padTo","id","name","sourceKind","status","statusDetail","sourceCount","distilledCount","totalDistillableCount","createdAt","completedAt"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,SAAS,QAAO,+BAA8B;AAEtD,MAAMC,iBAAiBL,SAAS;AAEhC,OAAO,MAAMM,yBAAyBP;IACpC,OAAgBQ,OAAO;QACrBC,iBAAiBZ,KAAKa,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;QACA,gGAAgG;QAChGC,UAAUhB,KAAKa,MAAM,CAAC;YACpBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,2BAA0B;IAExD,OAAgBG,WAAW;QACzB;YACEC,SAAS;YACTJ,aAAa;QACf;QAC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AAK;YAACL;QAAK;QAC1E,IAAI,CAACH,GAAG,CAACtB,eAAe,SAASiB,aAAaC,KAAK,IAAI,KAAK;YAACO;QAAK;QAClE,IAAI,CAACH,GAAG,CAACtB,eAAe,WAAWiB,aAAac,WAAW,EAAE;YAACN;QAAK;QACnE,IAAI,CAACH,GAAG,CACNtB,eACE,aACA,GAAGiB,aAAae,cAAc,CAAC,CAAC,EAAEf,aAAagB,qBAAqB,EAAE,EACtE;YAACR;QAAK;QAGV,IAAI,CAACH,GAAG,CAACtB,eAAe,WAAWiB,aAAaiB,SAAS,EAAE;YAACT;QAAK;QACjE,IAAI,CAACH,GAAG,CAACtB,eAAe,aAAaiB,aAAakB,WAAW,IAAI,KAAK;YAACV;QAAK;IAC9E;AACF"}
@@ -0,0 +1,105 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { isHttpError } from '@sanity/client';
5
+ import { listImports } from '../../../services/context.js';
6
+ import { Table } from '../../../util/responsiveTable.js';
7
+ const listImportsDebug = subdebug('context:imports:list');
8
+ export class ListImportsCommand extends SanityCommand {
9
+ static args = {
10
+ knowledgeBaseId: Args.string({
11
+ description: 'Knowledge base ID',
12
+ required: true
13
+ })
14
+ };
15
+ static description = 'List imports for a knowledge base';
16
+ static examples = [
17
+ {
18
+ command: '<%= config.bin %> <%= command.id %> kb-abc123',
19
+ description: 'List all imports for a knowledge base'
20
+ },
21
+ {
22
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 --json',
23
+ description: 'Output imports as JSON'
24
+ }
25
+ ];
26
+ static flags = {
27
+ json: Flags.boolean({
28
+ default: false,
29
+ description: 'Output imports in JSON format'
30
+ })
31
+ };
32
+ async run() {
33
+ const { knowledgeBaseId } = this.args;
34
+ const { json } = this.flags;
35
+ let imports;
36
+ try {
37
+ imports = await listImports(knowledgeBaseId);
38
+ } catch (error) {
39
+ listImportsDebug('Error listing imports', error);
40
+ if (isHttpError(error) && error.statusCode === 404) {
41
+ this.error(`Knowledge base "${knowledgeBaseId}" not found`, {
42
+ exit: exitCodes.RUNTIME_ERROR
43
+ });
44
+ }
45
+ this.error(`Failed to list imports: ${getErrorMessage(error)}`, {
46
+ exit: exitCodes.RUNTIME_ERROR
47
+ });
48
+ }
49
+ if (json) {
50
+ this.log(JSON.stringify(imports, null, 2));
51
+ return;
52
+ }
53
+ if (imports.length === 0) {
54
+ this.log('No imports found');
55
+ return;
56
+ }
57
+ const table = new Table({
58
+ columns: [
59
+ {
60
+ alignment: 'left',
61
+ name: 'id',
62
+ title: 'ID'
63
+ },
64
+ {
65
+ alignment: 'left',
66
+ name: 'name',
67
+ title: 'Name'
68
+ },
69
+ {
70
+ alignment: 'left',
71
+ name: 'kind',
72
+ title: 'Kind'
73
+ },
74
+ {
75
+ alignment: 'left',
76
+ name: 'status',
77
+ title: 'Status'
78
+ },
79
+ {
80
+ alignment: 'right',
81
+ name: 'sources',
82
+ title: 'Sources'
83
+ },
84
+ {
85
+ alignment: 'left',
86
+ name: 'createdAt',
87
+ title: 'Created'
88
+ }
89
+ ]
90
+ });
91
+ for (const { createdAt, id, name, sourceCount, sourceKind, status } of imports){
92
+ table.addRow({
93
+ createdAt,
94
+ id,
95
+ kind: sourceKind,
96
+ name: name ?? '-',
97
+ sources: sourceCount,
98
+ status
99
+ });
100
+ }
101
+ this.log(table.render());
102
+ }
103
+ }
104
+
105
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/imports/list.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 {isHttpError} from '@sanity/client'\n\nimport {listImports} from '../../../services/context.js'\nimport {Table} from '../../../util/responsiveTable.js'\n\nconst listImportsDebug = subdebug('context:imports:list')\n\nexport class ListImportsCommand extends SanityCommand<typeof ListImportsCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n }\n\n static override description = 'List imports for a knowledge base'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123',\n description: 'List all imports for a knowledge base',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 --json',\n description: 'Output imports as JSON',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n default: false,\n description: 'Output imports in JSON format',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {knowledgeBaseId} = this.args\n const {json} = this.flags\n\n let imports\n try {\n imports = await listImports(knowledgeBaseId)\n } catch (error) {\n listImportsDebug('Error listing imports', 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 list imports: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.log(JSON.stringify(imports, null, 2))\n return\n }\n\n if (imports.length === 0) {\n this.log('No imports found')\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'name', title: 'Name'},\n {alignment: 'left', name: 'kind', title: 'Kind'},\n {alignment: 'left', name: 'status', title: 'Status'},\n {alignment: 'right', name: 'sources', title: 'Sources'},\n {alignment: 'left', name: 'createdAt', title: 'Created'},\n ],\n })\n\n for (const {createdAt, id, name, sourceCount, sourceKind, status} of imports) {\n table.addRow({\n createdAt,\n id,\n kind: sourceKind,\n name: name ?? '-',\n sources: sourceCount,\n status,\n })\n }\n\n this.log(table.render())\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","listImports","Table","listImportsDebug","ListImportsCommand","args","knowledgeBaseId","string","description","required","examples","command","flags","json","boolean","default","run","imports","error","statusCode","exit","RUNTIME_ERROR","log","JSON","stringify","length","table","columns","alignment","name","title","createdAt","id","sourceCount","sourceKind","status","addRow","kind","sources","render"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,WAAW,QAAO,+BAA8B;AACxD,SAAQC,KAAK,QAAO,mCAAkC;AAEtD,MAAMC,mBAAmBL,SAAS;AAElC,OAAO,MAAMM,2BAA2BP;IACtC,OAAgBQ,OAAO;QACrBC,iBAAiBZ,KAAKa,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,oCAAmC;IAEjE,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtBC,MAAMlB,MAAMmB,OAAO,CAAC;YAClBC,SAAS;YACTP,aAAa;QACf;IACF,EAAqB;IAErB,MAAaQ,MAAqB;QAChC,MAAM,EAACV,eAAe,EAAC,GAAG,IAAI,CAACD,IAAI;QACnC,MAAM,EAACQ,IAAI,EAAC,GAAG,IAAI,CAACD,KAAK;QAEzB,IAAIK;QACJ,IAAI;YACFA,UAAU,MAAMhB,YAAYK;QAC9B,EAAE,OAAOY,OAAO;YACdf,iBAAiB,yBAAyBe;YAC1C,IAAIlB,YAAYkB,UAAUA,MAAMC,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACD,KAAK,CAAC,CAAC,gBAAgB,EAAEZ,gBAAgB,WAAW,CAAC,EAAE;oBAC1Dc,MAAMxB,UAAUyB,aAAa;gBAC/B;YACF;YACA,IAAI,CAACH,KAAK,CAAC,CAAC,wBAAwB,EAAEnB,gBAAgBmB,QAAQ,EAAE;gBAC9DE,MAAMxB,UAAUyB,aAAa;YAC/B;QACF;QAEA,IAAIR,MAAM;YACR,IAAI,CAACS,GAAG,CAACC,KAAKC,SAAS,CAACP,SAAS,MAAM;YACvC;QACF;QAEA,IAAIA,QAAQQ,MAAM,KAAK,GAAG;YACxB,IAAI,CAACH,GAAG,CAAC;YACT;QACF;QAEA,MAAMI,QAAQ,IAAIxB,MAAM;YACtByB,SAAS;gBACP;oBAACC,WAAW;oBAAQC,MAAM;oBAAMC,OAAO;gBAAI;gBAC3C;oBAACF,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;gBAC/C;oBAACF,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;gBAC/C;oBAACF,WAAW;oBAAQC,MAAM;oBAAUC,OAAO;gBAAQ;gBACnD;oBAACF,WAAW;oBAASC,MAAM;oBAAWC,OAAO;gBAAS;gBACtD;oBAACF,WAAW;oBAAQC,MAAM;oBAAaC,OAAO;gBAAS;aACxD;QACH;QAEA,KAAK,MAAM,EAACC,SAAS,EAAEC,EAAE,EAAEH,IAAI,EAAEI,WAAW,EAAEC,UAAU,EAAEC,MAAM,EAAC,IAAIlB,QAAS;YAC5ES,MAAMU,MAAM,CAAC;gBACXL;gBACAC;gBACAK,MAAMH;gBACNL,MAAMA,QAAQ;gBACdS,SAASL;gBACTE;YACF;QACF;QAEA,IAAI,CAACb,GAAG,CAACI,MAAMa,MAAM;IACvB;AACF"}
@@ -0,0 +1,90 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { isHttpError } from '@sanity/client';
5
+ import { 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 examples = [
23
+ {
24
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456',
25
+ description: 'Get the current status of a job'
26
+ },
27
+ {
28
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456 --watch',
29
+ description: 'Wait for the job to finish (non-zero exit if it does not succeed)'
30
+ }
31
+ ];
32
+ static flags = {
33
+ json: Flags.boolean({
34
+ default: false,
35
+ description: 'Output the job in JSON format'
36
+ }),
37
+ watch: Flags.boolean({
38
+ default: false,
39
+ description: 'Poll until the job reaches a terminal state'
40
+ })
41
+ };
42
+ async run() {
43
+ const { jobId, knowledgeBaseId } = this.args;
44
+ const { json, watch } = this.flags;
45
+ let job;
46
+ try {
47
+ job = watch ? await watchJob(knowledgeBaseId, jobId, {
48
+ label: 'Waiting for job'
49
+ }) : await getJob(knowledgeBaseId, jobId);
50
+ } catch (error) {
51
+ getJobDebug('Error getting job', error);
52
+ if (isHttpError(error) && error.statusCode === 404) {
53
+ this.error(`Job "${jobId}" not found on knowledge base "${knowledgeBaseId}"`, {
54
+ exit: exitCodes.RUNTIME_ERROR
55
+ });
56
+ }
57
+ this.error(`Failed to get job: ${getErrorMessage(error)}`, {
58
+ exit: exitCodes.RUNTIME_ERROR
59
+ });
60
+ }
61
+ if (json) {
62
+ this.log(JSON.stringify(job, null, 2));
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 (watch && job.status !== 'succeeded') {
83
+ this.error(`Job ${job.status}${job.error ? `: ${job.error}` : ''}`, {
84
+ exit: exitCodes.RUNTIME_ERROR
85
+ });
86
+ }
87
+ }
88
+ }
89
+
90
+ //# sourceMappingURL=get.js.map
@@ -0,0 +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} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {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 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 json: Flags.boolean({\n default: false,\n description: 'Output the job in JSON format',\n }),\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 if (json) {\n this.log(JSON.stringify(job, null, 2))\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 (watch && job.status !== 'succeeded') {\n this.error(`Job ${job.status}${job.error ? `: ${job.error}` : ''}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","watchJob","formatKeyValue","getJob","getJobDebug","GetJobCommand","args","knowledgeBaseId","string","description","required","jobId","examples","command","flags","json","boolean","default","watch","run","job","label","error","statusCode","exit","RUNTIME_ERROR","log","JSON","stringify","padTo","id","status","startedAt","completedAt"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,QAAQ,QAAO,uCAAsC;AAC7D,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,MAAM,QAAO,+BAA8B;AAEnD,MAAMC,cAAcN,SAAS;AAE7B,OAAO,MAAMO,sBAAsBR;IACjC,OAAgBS,OAAO;QACrBC,iBAAiBb,KAAKc,M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,CAACxB,eAAe,MAAMkB,IAAIU,EAAE,EAAE;gBAACD;YAAK;YAC5C,IAAI,CAACH,GAAG,CAACxB,eAAe,UAAUkB,IAAIW,MAAM,EAAE;gBAACF;YAAK;YACpD,IAAI,CAACH,GAAG,CAACxB,eAAe,WAAWkB,IAAIY,SAAS,IAAI,KAAK;gBAACH;YAAK;YAC/D,IAAI,CAACH,GAAG,CAACxB,eAAe,aAAakB,IAAIa,WAAW,IAAI,KAAK;gBAACJ;YAAK;YACnE,IAAI,CAACH,GAAG,CAACxB,eAAe,SAASkB,IAAIE,KAAK,IAAI,KAAK;gBAACO;YAAK;QAC3D;QAEA,IAAIX,SAASE,IAAIW,MAAM,KAAK,aAAa;YACvC,IAAI,CAACT,KAAK,CAAC,CAAC,IAAI,EAAEF,IAAIW,MAAM,GAAGX,IAAIE,KAAK,GAAG,CAAC,EAAE,EAAEF,IAAIE,KAAK,EAAE,GAAG,IAAI,EAAE;gBAClEE,MAAM5B,UAAU6B,aAAa;YAC/B;QACF;IACF;AACF"}
@@ -0,0 +1,109 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { MissingOrganizationError, resolveOrganizationId } from '../../actions/context/resolveOrganizationId.js';
5
+ import { listKnowledgeBases } from '../../services/context.js';
6
+ import { Table } from '../../util/responsiveTable.js';
7
+ import { getOrganizationFlag } from '../../util/sharedFlags.js';
8
+ const listContextDebug = subdebug('context:list');
9
+ export class ListKnowledgeBasesCommand extends SanityCommand {
10
+ static description = 'List knowledge bases in an organization';
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
+ json: Flags.boolean({
31
+ default: false,
32
+ description: 'Output knowledge bases in JSON format'
33
+ })
34
+ };
35
+ async run() {
36
+ const { json, organization } = this.flags;
37
+ let organizationId;
38
+ try {
39
+ organizationId = await resolveOrganizationId({
40
+ configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,
41
+ flagOrganizationId: organization,
42
+ unattended: this.isUnattended()
43
+ });
44
+ } catch (error) {
45
+ listContextDebug('Error resolving organization', error);
46
+ this.error(getErrorMessage(error), {
47
+ exit: error instanceof MissingOrganizationError ? exitCodes.USAGE_ERROR : exitCodes.RUNTIME_ERROR
48
+ });
49
+ }
50
+ let knowledgeBases;
51
+ try {
52
+ knowledgeBases = await listKnowledgeBases(organizationId);
53
+ } catch (error) {
54
+ listContextDebug('Error listing knowledge bases', error);
55
+ this.error(`Failed to list knowledge bases: ${getErrorMessage(error)}`, {
56
+ exit: exitCodes.RUNTIME_ERROR
57
+ });
58
+ }
59
+ if (json) {
60
+ this.log(JSON.stringify(knowledgeBases, null, 2));
61
+ return;
62
+ }
63
+ if (knowledgeBases.length === 0) {
64
+ this.log('No knowledge bases found');
65
+ return;
66
+ }
67
+ const table = new Table({
68
+ columns: [
69
+ {
70
+ alignment: 'left',
71
+ name: 'id',
72
+ title: 'ID'
73
+ },
74
+ {
75
+ alignment: 'left',
76
+ name: 'title',
77
+ title: 'Title'
78
+ },
79
+ {
80
+ alignment: 'left',
81
+ name: 'state',
82
+ title: 'State'
83
+ },
84
+ {
85
+ alignment: 'right',
86
+ name: 'openIssues',
87
+ title: 'Open issues'
88
+ },
89
+ {
90
+ alignment: 'left',
91
+ name: 'updatedAt',
92
+ title: 'Updated'
93
+ }
94
+ ]
95
+ });
96
+ for (const { openIssueCount, publicId, state, title, updatedAt } of knowledgeBases){
97
+ table.addRow({
98
+ id: publicId,
99
+ openIssues: openIssueCount,
100
+ state,
101
+ title,
102
+ updatedAt
103
+ });
104
+ }
105
+ this.log(table.render());
106
+ }
107
+ }
108
+
109
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/commands/context/list.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'\n\nimport {\n MissingOrganizationError,\n resolveOrganizationId,\n} 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 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 json: Flags.boolean({\n default: false,\n description: 'Output knowledge bases in JSON format',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {json, organization} = 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 listContextDebug('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 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.log(JSON.stringify(knowledgeBases, null, 2))\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":["Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","MissingOrganizationError","resolveOrganizationId","listKnowledgeBases","Table","getOrganizationFlag","listContextDebug","ListKnowledgeBasesCommand","description","examples","command","flags","semantics","json","boolean","default","run","organization","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","isUnattended","error","exit","USAGE_ERROR","RUNTIME_ERROR","knowledgeBases","log","JSON","stringify","length","table","columns","alignment","name","title","openIssueCount","publicId","state","updatedAt","addRow","id","openIssues","render"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AAEjC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AAEvD,SACEC,wBAAwB,EACxBC,qBAAqB,QAChB,iDAAgD;AACvD,SAAQC,kBAAkB,QAAO,4BAA2B;AAC5D,SAAQC,KAAK,QAAO,gCAA+B;AACnD,SAAQC,mBAAmB,QAAO,4BAA2B;AAE7D,MAAMC,mBAAmBP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EA,MAAMI,QAAQ,IAAI9B,MAAM;YACtB+B,SAAS;gBACP;oBAACC,WAAW;oBAAQC,MAAM;oBAAMC,OAAO;gBAAI;gBAC3C;oBAACF,WAAW;oBAAQC,MAAM;oBAASC,OAAO;gBAAO;gBACjD;oBAACF,WAAW;oBAAQC,MAAM;oBAASC,OAAO;gBAAO;gBACjD;oBAACF,WAAW;oBAASC,MAAM;oBAAcC,OAAO;gBAAa;gBAC7D;oBAACF,WAAW;oBAAQC,MAAM;oBAAaC,OAAO;gBAAS;aACxD;QACH;QAEA,KAAK,MAAM,EAACC,cAAc,EAAEC,QAAQ,EAAEC,KAAK,EAAEH,KAAK,EAAEI,SAAS,EAAC,IAAIb,eAAgB;YAChFK,MAAMS,MAAM,CAAC;gBAACC,IAAIJ;gBAAUK,YAAYN;gBAAgBE;gBAAOH;gBAAOI;YAAS;QACjF;QAEA,IAAI,CAACZ,GAAG,CAACI,MAAMY,MAAM;IACvB;AACF"}
@@ -0,0 +1,46 @@
1
+ import { Args } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { spinner } from '@sanity/cli-core/ux';
5
+ import { isHttpError } from '@sanity/client';
6
+ import { formatKeyValue } from '../../actions/debug/output.js';
7
+ import { refreshKnowledgeBase } from '../../services/context.js';
8
+ const refreshContextDebug = subdebug('context:refresh');
9
+ export class RefreshKnowledgeBaseCommand extends SanityCommand {
10
+ static args = {
11
+ knowledgeBaseId: Args.string({
12
+ description: 'Knowledge base ID',
13
+ required: true
14
+ })
15
+ };
16
+ static description = 'Refresh a knowledge base: re-check sources and apply what changed';
17
+ static examples = [
18
+ {
19
+ command: '<%= config.bin %> <%= command.id %> kb-abc123',
20
+ description: 'Start an incremental refresh'
21
+ }
22
+ ];
23
+ async run() {
24
+ const { knowledgeBaseId } = this.args;
25
+ const spin = spinner('Starting refresh').start();
26
+ try {
27
+ const { jobId, started } = await refreshKnowledgeBase(knowledgeBaseId);
28
+ spin.succeed(started ? 'Refresh started' : 'Refresh already in progress');
29
+ this.log(formatKeyValue('Job ID', jobId));
30
+ this.log(`Check progress with: sanity context get ${knowledgeBaseId}`);
31
+ } catch (error) {
32
+ spin.fail();
33
+ refreshContextDebug('Error refreshing knowledge base', error);
34
+ if (isHttpError(error) && error.statusCode === 404) {
35
+ this.error(`Knowledge base "${knowledgeBaseId}" not found`, {
36
+ exit: exitCodes.RUNTIME_ERROR
37
+ });
38
+ }
39
+ this.error(`Failed to refresh knowledge base: ${getErrorMessage(error)}`, {
40
+ exit: exitCodes.RUNTIME_ERROR
41
+ });
42
+ }
43
+ }
44
+ }
45
+
46
+ //# sourceMappingURL=refresh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/commands/context/refresh.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatKeyValue} from '../../actions/debug/output.js'\nimport {refreshKnowledgeBase} from '../../services/context.js'\n\nconst refreshContextDebug = subdebug('context:refresh')\n\nexport class RefreshKnowledgeBaseCommand extends SanityCommand<typeof RefreshKnowledgeBaseCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n }\n\n static override description = 'Refresh a knowledge base: re-check sources and apply what changed'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123',\n description: 'Start an incremental refresh',\n },\n ]\n\n public async run(): Promise<void> {\n const {knowledgeBaseId} = this.args\n\n const spin = spinner('Starting refresh').start()\n try {\n const {jobId, started} = await refreshKnowledgeBase(knowledgeBaseId)\n spin.succeed(started ? 'Refresh started' : 'Refresh already in progress')\n this.log(formatKeyValue('Job ID', jobId))\n this.log(`Check progress with: sanity context get ${knowledgeBaseId}`)\n } catch (error) {\n spin.fail()\n refreshContextDebug('Error refreshing knowledge base', 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 refresh knowledge base: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Args","exitCodes","SanityCommand","subdebug","getErrorMessage","spinner","isHttpError","formatKeyValue","refreshKnowledgeBase","refreshContextDebug","RefreshKnowledgeBaseCommand","args","knowledgeBaseId","string","description","required","examples","command","run","spin","start","jobId","started","succeed","log","error","fail","statusCode","exit","RUNTIME_ERROR"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAChC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,cAAc,QAAO,gCAA+B;AAC5D,SAAQC,oBAAoB,QAAO,4BAA2B;AAE9D,MAAMC,sBAAsBN,SAAS;AAErC,OAAO,MAAMO,oCAAoCR;IAC/C,OAAgBS,OAAO;QACrBC,iBAAiBZ,KAAKa,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,oEAAmE;IAEjG,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,MAAaI,MAAqB;QAChC,MAAM,EAACN,eAAe,EAAC,GAAG,IAAI,CAACD,IAAI;QAEnC,MAAMQ,OAAOd,QAAQ,oBAAoBe,KAAK;QAC9C,IAAI;YACF,MAAM,EAACC,KAAK,EAAEC,OAAO,EAAC,GAAG,MAAMd,qBAAqBI;YACpDO,KAAKI,OAAO,CAACD,UAAU,oBAAoB;YAC3C,IAAI,CAACE,GAAG,CAACjB,eAAe,UAAUc;YAClC,IAAI,CAACG,GAAG,CAAC,CAAC,wCAAwC,EAAEZ,iBAAiB;QACvE,EAAE,OAAOa,OAAO;YACdN,KAAKO,IAAI;YACTjB,oBAAoB,mCAAmCgB;YACvD,IAAInB,YAAYmB,UAAUA,MAAME,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACF,KAAK,CAAC,CAAC,gBAAgB,EAAEb,gBAAgB,WAAW,CAAC,EAAE;oBAC1DgB,MAAM3B,UAAU4B,aAAa;gBAC/B;YACF;YACA,IAAI,CAACJ,KAAK,CAAC,CAAC,kCAAkC,EAAErB,gBAAgBqB,QAAQ,EAAE;gBACxEG,MAAM3B,UAAU4B,aAAa;YAC/B;QACF;IACF;AACF"}
@@ -0,0 +1,127 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { spinner } from '@sanity/cli-core/ux';
5
+ import { isHttpError } from '@sanity/client';
6
+ import { updateKnowledgeBase } from '../../services/context.js';
7
+ import { defineCommandTelemetry } from '../../util/telemetry/commandTelemetry.js';
8
+ const updateContextDebug = subdebug('context:update');
9
+ const UPDATE_FLAGS = [
10
+ 'title',
11
+ 'description',
12
+ 'refresh-enabled',
13
+ 'refresh-frequency'
14
+ ];
15
+ const flags = {
16
+ description: Flags.string({
17
+ atLeastOne: [
18
+ ...UPDATE_FLAGS
19
+ ],
20
+ description: 'New knowledge base description',
21
+ required: false
22
+ }),
23
+ 'refresh-enabled': Flags.boolean({
24
+ allowNo: true,
25
+ atLeastOne: [
26
+ ...UPDATE_FLAGS
27
+ ],
28
+ description: 'Enable scheduled refresh (--no-refresh-enabled to disable)',
29
+ required: false
30
+ }),
31
+ 'refresh-frequency': Flags.custom({
32
+ atLeastOne: [
33
+ ...UPDATE_FLAGS
34
+ ],
35
+ description: 'How often scheduled refresh runs',
36
+ options: [
37
+ 'weekly',
38
+ 'monthly'
39
+ ],
40
+ required: false
41
+ })(),
42
+ title: Flags.string({
43
+ atLeastOne: [
44
+ ...UPDATE_FLAGS
45
+ ],
46
+ description: 'New knowledge base title',
47
+ required: false
48
+ })
49
+ };
50
+ export class UpdateKnowledgeBaseCommand extends SanityCommand {
51
+ static args = {
52
+ knowledgeBaseId: Args.string({
53
+ description: 'Knowledge base ID',
54
+ required: true
55
+ })
56
+ };
57
+ static description = 'Update a knowledge base';
58
+ static examples = [
59
+ {
60
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 --title "New title"',
61
+ description: 'Rename a knowledge base'
62
+ },
63
+ {
64
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 --refresh-enabled --refresh-frequency weekly',
65
+ description: 'Enable weekly scheduled refresh'
66
+ },
67
+ {
68
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 --no-refresh-enabled',
69
+ description: 'Disable scheduled refresh'
70
+ }
71
+ ];
72
+ static flags = flags;
73
+ static telemetry = defineCommandTelemetry(flags, {
74
+ redact: [
75
+ 'title',
76
+ 'description'
77
+ ]
78
+ });
79
+ async run() {
80
+ const { knowledgeBaseId } = this.args;
81
+ const { description, 'refresh-enabled': refreshEnabled, 'refresh-frequency': refreshFrequency, title } = this.flags;
82
+ const params = {};
83
+ if (title !== undefined) {
84
+ const trimmedTitle = title.trim();
85
+ if (trimmedTitle === '') {
86
+ this.error('Title cannot be empty', {
87
+ exit: exitCodes.USAGE_ERROR
88
+ });
89
+ }
90
+ params.title = trimmedTitle;
91
+ }
92
+ if (description !== undefined) {
93
+ const trimmedDescription = description.trim();
94
+ if (trimmedDescription === '') {
95
+ this.error('Description cannot be empty', {
96
+ exit: exitCodes.USAGE_ERROR
97
+ });
98
+ }
99
+ params.description = trimmedDescription;
100
+ }
101
+ if (refreshEnabled !== undefined) {
102
+ params.refreshEnabled = refreshEnabled;
103
+ }
104
+ if (refreshFrequency !== undefined) {
105
+ params.refreshFrequency = refreshFrequency;
106
+ }
107
+ const spin = spinner('Updating knowledge base').start();
108
+ try {
109
+ await updateKnowledgeBase(knowledgeBaseId, params);
110
+ spin.succeed();
111
+ this.log('Knowledge base updated');
112
+ } catch (error) {
113
+ spin.fail();
114
+ updateContextDebug('Error updating knowledge base', error);
115
+ if (isHttpError(error) && error.statusCode === 404) {
116
+ this.error(`Knowledge base "${knowledgeBaseId}" not found`, {
117
+ exit: exitCodes.RUNTIME_ERROR
118
+ });
119
+ }
120
+ this.error(`Failed to update knowledge base: ${getErrorMessage(error)}`, {
121
+ exit: exitCodes.RUNTIME_ERROR
122
+ });
123
+ }
124
+ }
125
+ }
126
+
127
+ //# sourceMappingURL=update.js.map