@sanity/runtime-cli 17.18.0 → 17.19.0-next.g94c4d8c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -90,7 +90,7 @@ EXAMPLES
90
90
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
91
91
  ```
92
92
 
93
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/add.ts)_
93
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/add.ts)_
94
94
 
95
95
  ## `sanity-run blueprints config`
96
96
 
@@ -127,7 +127,7 @@ EXAMPLES
127
127
  $ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
128
128
  ```
129
129
 
130
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/config.ts)_
130
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/config.ts)_
131
131
 
132
132
  ## `sanity-run blueprints deploy`
133
133
 
@@ -183,7 +183,7 @@ EXAMPLES
183
183
  $ sanity-run blueprints deploy --new-stack-name <new-name>
184
184
  ```
185
185
 
186
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/deploy.ts)_
186
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/deploy.ts)_
187
187
 
188
188
  ## `sanity-run blueprints destroy`
189
189
 
@@ -221,7 +221,7 @@ EXAMPLES
221
221
  $ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
222
222
  ```
223
223
 
224
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/destroy.ts)_
224
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/destroy.ts)_
225
225
 
226
226
  ## `sanity-run blueprints doctor`
227
227
 
@@ -253,7 +253,7 @@ EXAMPLES
253
253
  $ sanity-run blueprints doctor --fix
254
254
  ```
255
255
 
256
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/doctor.ts)_
256
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/doctor.ts)_
257
257
 
258
258
  ## `sanity-run blueprints info`
259
259
 
@@ -291,7 +291,7 @@ EXAMPLES
291
291
  $ sanity-run blueprints info --organization-id <orgId> --stack <name-or-id>
292
292
  ```
293
293
 
294
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/info.ts)_
294
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/info.ts)_
295
295
 
296
296
  ## `sanity-run blueprints init [DIR]`
297
297
 
@@ -355,7 +355,7 @@ EXAMPLES
355
355
  $ sanity-run blueprints init old-stack --type <json|js|ts> --project-id <projectId> --stack-id <existingStackId>
356
356
  ```
357
357
 
358
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/init.ts)_
358
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/init.ts)_
359
359
 
360
360
  ## `sanity-run blueprints logs`
361
361
 
@@ -401,7 +401,7 @@ EXAMPLES
401
401
  $ sanity-run blueprints logs --before 2026-05-01T00:00:00Z
402
402
  ```
403
403
 
404
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/logs.ts)_
404
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/logs.ts)_
405
405
 
406
406
  ## `sanity-run blueprints mint-deploy-token`
407
407
 
@@ -446,7 +446,7 @@ EXAMPLES
446
446
  $ sanity-run blueprints mint-deploy-token --organization-id <orgId>
447
447
  ```
448
448
 
449
- _See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/mint-deploy-token.ts)_
449
+ _See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/mint-deploy-token.ts)_
450
450
 
451
451
  ## `sanity-run blueprints plan`
452
452
 
@@ -479,7 +479,7 @@ EXAMPLES
479
479
  $ sanity-run blueprints plan --organization-id <orgId> --stack <name-or-id>
480
480
  ```
481
481
 
482
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/plan.ts)_
482
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/plan.ts)_
483
483
 
484
484
  ## `sanity-run blueprints promote`
485
485
 
@@ -515,7 +515,7 @@ EXAMPLES
515
515
  $ sanity-run blueprints promote --new-stack-name <new-name>
516
516
  ```
517
517
 
518
- _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/promote.ts)_
518
+ _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/promote.ts)_
519
519
 
520
520
  ## `sanity-run blueprints stacks`
521
521
 
@@ -556,7 +556,7 @@ EXAMPLES
556
556
  $ sanity-run blueprints stacks --organization-id <organizationId> --include-projects
557
557
  ```
558
558
 
559
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/blueprints/stacks.ts)_
559
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/blueprints/stacks.ts)_
560
560
 
561
561
  ## `sanity-run functions add`
562
562
 
@@ -608,7 +608,7 @@ EXAMPLES
608
608
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
609
609
  ```
610
610
 
611
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/functions/add.ts)_
611
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/functions/add.ts)_
612
612
 
613
613
  ## `sanity-run functions dev`
614
614
 
@@ -643,7 +643,7 @@ EXAMPLES
643
643
  $ sanity-run functions dev --timeout 60
644
644
  ```
645
645
 
646
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/functions/dev.ts)_
646
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/functions/dev.ts)_
647
647
 
648
648
  ## `sanity-run functions env add NAME KEY VALUE`
649
649
 
@@ -676,7 +676,7 @@ EXAMPLES
676
676
  $ sanity-run functions env add --stack <name-or-id> MyFunction API_URL https://api.example.com/
677
677
  ```
678
678
 
679
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/functions/env/add.ts)_
679
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/functions/env/add.ts)_
680
680
 
681
681
  ## `sanity-run functions env list NAME`
682
682
 
@@ -706,7 +706,7 @@ EXAMPLES
706
706
  $ sanity-run functions env list --stack <name-or-id> MyFunction
707
707
  ```
708
708
 
709
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/functions/env/list.ts)_
709
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/functions/env/list.ts)_
710
710
 
711
711
  ## `sanity-run functions env remove NAME KEY`
712
712
 
@@ -738,7 +738,7 @@ EXAMPLES
738
738
  $ sanity-run functions env remove --stack <name-or-id> MyFunction API_URL
739
739
  ```
740
740
 
741
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/functions/env/remove.ts)_
741
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/functions/env/remove.ts)_
742
742
 
743
743
  ## `sanity-run functions logs [NAME]`
744
744
 
@@ -778,7 +778,7 @@ EXAMPLES
778
778
  $ sanity-run functions logs <name> --delete
779
779
  ```
780
780
 
781
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/functions/logs.ts)_
781
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/functions/logs.ts)_
782
782
 
783
783
  ## `sanity-run functions test [NAME]`
784
784
 
@@ -836,7 +836,7 @@ EXAMPLES
836
836
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
837
837
  ```
838
838
 
839
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0/src/commands/functions/test.ts)_
839
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.19.0-next.g94c4d8c/src/commands/functions/test.ts)_
840
840
 
841
841
  ## `sanity-run help [COMMAND]`
842
842
 
@@ -7,7 +7,7 @@ export const assetStashUrl = `${assetsUrl}/stash`;
7
7
  export async function stashAsset({ resolvedResource, prepAsset, auth, blueprintFileDir, fetchFn, installer, }) {
8
8
  let cleanup = async () => { };
9
9
  try {
10
- const prepResult = await prepAsset({ resolvedResource, blueprintFileDir, installer });
10
+ const prepResult = await prepAsset({ resolvedResource, blueprintFileDir, installer, auth });
11
11
  if (prepResult.success === false) {
12
12
  await prepResult.cleanup();
13
13
  return {
@@ -1,4 +1,5 @@
1
- import { SANITY_FUNCTION_PREFIX } from '../../constants.js';
1
+ import { SANITY_AGENT_TYPE, SANITY_FUNCTION_PREFIX } from '../../constants.js';
2
+ import { prepareAsset as prepareAgentAsset } from '../../utils/agents/prepare-asset.js';
2
3
  import { resolveDeployedResources } from '../../utils/blueprints/resolve-deployed-resources.js';
3
4
  import { BUNDLE_SPECS, prepareBundleAsset, } from '../../utils/bundles/prepare-asset.js';
4
5
  import { stampConfigVersion } from '../../utils/bundles/stamp-config-version.js';
@@ -39,6 +40,16 @@ const preDeployConfigs = [
39
40
  await extractDurableConfig(options.resource, options.blueprintFileDir);
40
41
  },
41
42
  },
43
+ {
44
+ resourceType: SANITY_AGENT_TYPE,
45
+ async prepareAsset(options) {
46
+ return prepareAgentAsset({
47
+ resource: options.resolvedResource.resource,
48
+ blueprintFileDir: options.blueprintFileDir,
49
+ auth: options.auth,
50
+ });
51
+ },
52
+ },
42
53
  ];
43
54
  function hasPreDeployResources(resources) {
44
55
  return resources.some((r) => {
@@ -2,6 +2,7 @@ import type { DurableStepPhase } from './utils/types.js';
2
2
  export declare const SANITY_ACCESS_ROLE = "sanity.access.role";
3
3
  export declare const SANITY_ACCESS_ROBOT = "sanity.access.robot";
4
4
  export declare const SANITY_FUNCTION_PREFIX = "sanity.function.";
5
+ export declare const SANITY_AGENT_TYPE = "sanity.agent";
5
6
  export declare const SANITY_FUNCTION_DOCUMENT = "sanity.function.document";
6
7
  export declare const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = "sanity.function.media-library.asset";
7
8
  export declare const SANITY_FUNCTION_PUBSUB = "sanity.function.pubsub";
package/dist/constants.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export const SANITY_ACCESS_ROLE = 'sanity.access.role';
2
2
  export const SANITY_ACCESS_ROBOT = 'sanity.access.robot';
3
3
  export const SANITY_FUNCTION_PREFIX = 'sanity.function.';
4
+ export const SANITY_AGENT_TYPE = 'sanity.agent';
4
5
  export const SANITY_FUNCTION_DOCUMENT = 'sanity.function.document';
5
6
  export const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = 'sanity.function.media-library.asset';
6
7
  export const SANITY_FUNCTION_PUBSUB = 'sanity.function.pubsub';
@@ -254,13 +254,13 @@ async function promptForFunctionType() {
254
254
  { name: LABEL_DOCUMENT_CREATE, value: EVENT_DOCUMENT_CREATE, checked: true },
255
255
  { name: LABEL_DOCUMENT_UPDATE, value: EVENT_DOCUMENT_UPDATE, checked: true },
256
256
  { name: LABEL_DOCUMENT_DELETE, value: EVENT_DOCUMENT_DELETE },
257
+ { name: LABEL_DURABLE, value: EVENT_DURABLE },
257
258
  { name: LABEL_MEDIA_LIBRARY_ASSET_CREATE, value: EVENT_MEDIA_LIBRARY_ASSET_CREATE },
258
259
  { name: LABEL_MEDIA_LIBRARY_ASSET_UPDATE, value: EVENT_MEDIA_LIBRARY_ASSET_UPDATE },
259
260
  { name: LABEL_MEDIA_LIBRARY_ASSET_DELETE, value: EVENT_MEDIA_LIBRARY_ASSET_DELETE },
260
261
  { name: LABEL_PUBSUB, value: EVENT_PUBSUB },
261
262
  { name: LABEL_SCHEDULED, value: EVENT_SCHEDULED },
262
263
  { name: LABEL_SYNC_TAG_INVALIDATE, value: EVENT_SYNC_TAG_INVALIDATE },
263
- { name: LABEL_DURABLE, value: EVENT_DURABLE },
264
264
  ],
265
265
  validate(choices) {
266
266
  if (choices.length === 0) {
@@ -0,0 +1,22 @@
1
+ import AdmZip from 'adm-zip';
2
+ import type { AgentResource } from '../types.js';
3
+ /** `sanityID` must be exactly 36 characters because the platform manifest gate requires it. */
4
+ export declare const SANITY_ID_LENGTH = 36;
5
+ /** The manifest written to `package.json` at the bundle root. */
6
+ export interface AgentManifest {
7
+ sanityID: string;
8
+ name: string;
9
+ description?: string;
10
+ region: string;
11
+ }
12
+ /** Derive the 36-character `sanityID` from the project scope id, as a UUID-shaped hash so it is stable across redeploys. */
13
+ export declare function deriveSanityId(scopeId: string): string;
14
+ /** Build the manifest from the resource and project scope. */
15
+ export declare function buildAgentManifest(resource: AgentResource, scopeId: string): AgentManifest;
16
+ /**
17
+ * Assemble the full bundle for a `sanity.agent` resource: the `package.json`
18
+ * manifest, the authored source under `agent/`, the `www/index.ts` app entry, a
19
+ * `public/` folder, and a `Dockerfile`. Asset prep is the only bundle producer;
20
+ * the Provider just reads the bytes, so the layout must be complete here.
21
+ */
22
+ export declare function buildAgentPackage(agentPath: string, manifest: AgentManifest): AdmZip;
@@ -0,0 +1,61 @@
1
+ import crypto from 'node:crypto';
2
+ import AdmZip from 'adm-zip';
3
+ /** `sanityID` must be exactly 36 characters because the platform manifest gate requires it. */
4
+ export const SANITY_ID_LENGTH = 36;
5
+ /** Derive the 36-character `sanityID` from the project scope id, as a UUID-shaped hash so it is stable across redeploys. */
6
+ export function deriveSanityId(scopeId) {
7
+ const hex = crypto.createHash('sha256').update(scopeId).digest('hex');
8
+ return [
9
+ hex.slice(0, 8),
10
+ hex.slice(8, 12),
11
+ hex.slice(12, 16),
12
+ hex.slice(16, 20),
13
+ hex.slice(20, 32),
14
+ ].join('-');
15
+ }
16
+ /** Build the manifest from the resource and project scope. */
17
+ export function buildAgentManifest(resource, scopeId) {
18
+ const manifest = {
19
+ sanityID: deriveSanityId(scopeId),
20
+ name: resource.name,
21
+ region: resource.region,
22
+ };
23
+ if (typeof resource.description === 'string' && resource.description.length > 0) {
24
+ manifest.description = resource.description;
25
+ }
26
+ return manifest;
27
+ }
28
+ /** The `www/index.{js,ts}` app entry the platform layout gate requires. */
29
+ const WWW_INDEX_TS = `// Generated by the sanity.agent asset prep. The app entry the platform build
30
+ // mounts: it re-exports the authored eve agent under agent/.
31
+ export {default} from '../agent/agent.js'
32
+ `;
33
+ /** The `Dockerfile` build context the platform layout gate requires. */
34
+ const DOCKERFILE = `# Generated by the sanity.agent asset prep.
35
+ FROM node:22-slim
36
+ WORKDIR /app
37
+ COPY . .
38
+ RUN npm install --omit=dev
39
+ EXPOSE 3000
40
+ CMD ["node", "www/index.js"]
41
+ `;
42
+ /** Keep file so the required `public/` folder exists even with no static assets. */
43
+ const PUBLIC_KEEP = '';
44
+ /**
45
+ * Assemble the full bundle for a `sanity.agent` resource: the `package.json`
46
+ * manifest, the authored source under `agent/`, the `www/index.ts` app entry, a
47
+ * `public/` folder, and a `Dockerfile`. Asset prep is the only bundle producer;
48
+ * the Provider just reads the bytes, so the layout must be complete here.
49
+ */
50
+ export function buildAgentPackage(agentPath, manifest) {
51
+ const zip = new AdmZip();
52
+ zip.addFile('package.json', Buffer.from(JSON.stringify(manifest, null, 2), 'utf8'));
53
+ zip.addLocalFolder(agentPath, 'agent');
54
+ zip.addFile('www/index.ts', Buffer.from(WWW_INDEX_TS, 'utf8'));
55
+ zip.addFile('public/.gitkeep', Buffer.from(PUBLIC_KEEP, 'utf8'));
56
+ zip.addFile('Dockerfile', Buffer.from(DOCKERFILE, 'utf8'));
57
+ // Fixed entry times so the same input gives the same bytes, and the same asset id
58
+ for (const entry of zip.getEntries())
59
+ entry.header.time = new Date(0);
60
+ return zip;
61
+ }
@@ -0,0 +1,12 @@
1
+ import type { AgentResource, AssetPrepResult, AuthParams } from '../types.js';
2
+ /**
3
+ * Build the full bundle for a `sanity.agent` resource from its `src` source
4
+ * path, with the manifest inside the zip. Asset prep is the only bundle
5
+ * producer; the Provider just reads the prepared bytes. A failure returns
6
+ * `{success: false}`, failing the prep step before the Blueprints API is called.
7
+ */
8
+ export declare function prepareAsset({ blueprintFileDir, resource, auth, }: {
9
+ blueprintFileDir: string;
10
+ resource: AgentResource;
11
+ auth?: AuthParams;
12
+ }): Promise<AssetPrepResult>;
@@ -0,0 +1,54 @@
1
+ import { existsSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { CONVERT_BYTES_TO_MB, MAX_ASSET_SIZE } from '../../constants.js';
4
+ import { isFolderLargerThan } from '../functions/is-folder-larger-than.js';
5
+ import { buildAgentManifest, buildAgentPackage } from './build-package.js';
6
+ /**
7
+ * Build the full bundle for a `sanity.agent` resource from its `src` source
8
+ * path, with the manifest inside the zip. Asset prep is the only bundle
9
+ * producer; the Provider just reads the prepared bytes. A failure returns
10
+ * `{success: false}`, failing the prep step before the Blueprints API is called.
11
+ */
12
+ export async function prepareAsset({ blueprintFileDir, resource, auth, }) {
13
+ if (!resource.src)
14
+ throw new Error('Resource src is required');
15
+ const cleanup = async () => { };
16
+ const agentPath = path.resolve(blueprintFileDir, resource.src);
17
+ try {
18
+ if (!auth?.scopeId) {
19
+ throw new Error('A project scope is required to build the agent package manifest.');
20
+ }
21
+ if (!resource.region) {
22
+ throw new Error('Resource region is required to build the agent package manifest.');
23
+ }
24
+ if (!existsSync(agentPath)) {
25
+ throw new Error(`Agent source path not found: ${agentPath}`);
26
+ }
27
+ if (isFolderLargerThan(agentPath, MAX_ASSET_SIZE)) {
28
+ throw new Error('Resource is larger than max asset size of 200 MB.');
29
+ }
30
+ const manifest = buildAgentManifest(resource, auth.scopeId);
31
+ const zip = buildAgentPackage(agentPath, manifest);
32
+ // Sum uncompressed entry sizes so the limit check reflects on-disk size.
33
+ const zipEntrySize = zip
34
+ .getEntries()
35
+ .map((entry) => entry.header.size)
36
+ .reduce((a, b) => a + b, 0);
37
+ if (zipEntrySize > MAX_ASSET_SIZE) {
38
+ throw new Error(`Asset size of ${(zipEntrySize / CONVERT_BYTES_TO_MB).toFixed(2)} MB exceeds the maximum allowed size of 200 MB.`);
39
+ }
40
+ return {
41
+ success: true,
42
+ outputBuffer: await zip.toBufferPromise(),
43
+ fileExtension: 'zip',
44
+ assetParameter: 'src',
45
+ cleanup,
46
+ metadata: {
47
+ assetBytes: zipEntrySize,
48
+ },
49
+ };
50
+ }
51
+ catch (err) {
52
+ return { success: false, cleanup, error: err instanceof Error ? err.message : `${err}` };
53
+ }
54
+ }
@@ -8,6 +8,7 @@ import { buildApp, buildStudio, compareDependencyVersions, } from '@sanity/cli-b
8
8
  import { buildStudioSchemasAndManifests } from '@sanity/cli-build/_internal/extract';
9
9
  import { getLocalPackageVersion } from '@sanity/cli-core';
10
10
  import { pack } from 'tar-fs';
11
+ import { isRecord } from '../is-record.js';
11
12
  export const BUNDLE_SPECS = {
12
13
  'sanity.studio': { requiresAppId: true, build: buildStudioBundle },
13
14
  'sanity.application': { requiresAppId: true, build: buildApplicationBundle },
@@ -140,15 +141,14 @@ async function buildStudioBundle({ resource, appId, workDir, outDir, output, eve
140
141
  sourceMap: resource.sourceMap ?? false,
141
142
  stats: false,
142
143
  unattendedMode: true,
143
- // TODO pass in vite config from the studio resource
144
- vite: undefined,
144
+ vite: resource.vite,
145
145
  workDir,
146
146
  eventListener,
147
147
  });
148
148
  if (mfManifest) {
149
149
  resource.mfManifest = mfManifest;
150
150
  }
151
- const { schemaInputs } = await buildStudioSchemasAndManifests(appId, {
151
+ const { schemaInputs, studioManifest } = await buildStudioSchemasAndManifests(appId, {
152
152
  configPath: resource.root,
153
153
  isExternal: false,
154
154
  outPath: outDir,
@@ -160,8 +160,39 @@ async function buildStudioBundle({ resource, appId, workDir, outDir, output, eve
160
160
  if (schemaInputs) {
161
161
  resource.schemaInputs = schemaInputs;
162
162
  }
163
+ if (studioManifest) {
164
+ resource.workspaces = toStudioWorkspaces(studioManifest, resource.name);
165
+ }
163
166
  return { mismatchedPackages };
164
167
  }
168
+ const REQUIRED_WORKSPACE_KEYS = ['projectId', 'dataset', 'schemaDescriptorId', 'name'];
169
+ const OPTIONAL_WORKSPACE_KEYS = ['title', 'subtitle', 'basePath', 'icon'];
170
+ function isManifestWorkspace(value) {
171
+ if (!isRecord(value))
172
+ return false;
173
+ return (REQUIRED_WORKSPACE_KEYS.every((key) => typeof value[key] === 'string') &&
174
+ OPTIONAL_WORKSPACE_KEYS.every((key) => value[key] === undefined || typeof value[key] === 'string'));
175
+ }
176
+ function toStudioWorkspaces(studioManifest, resourceName) {
177
+ if (!isRecord(studioManifest) || !Array.isArray(studioManifest.workspaces)) {
178
+ throw new Error(`Studio manifest for resource '${resourceName}' has no workspaces list`);
179
+ }
180
+ return studioManifest.workspaces.map((w, index) => {
181
+ if (!isManifestWorkspace(w)) {
182
+ throw new Error(`Studio manifest for resource '${resourceName}' has an invalid workspace at index ${index}`);
183
+ }
184
+ return {
185
+ projectId: w.projectId,
186
+ dataset: w.dataset,
187
+ schemaDescriptorId: w.schemaDescriptorId,
188
+ name: w.name,
189
+ title: w.title,
190
+ subtitle: w.subtitle,
191
+ basePath: w.basePath,
192
+ icon: w.icon,
193
+ };
194
+ });
195
+ }
165
196
  async function buildApplicationBundle({ resource, appId, workDir, outDir, output, eventListener, }) {
166
197
  const views = resource.views ?? [];
167
198
  const [window, extraWindow] = views.filter((v) => v.type === 'app');
@@ -1,4 +1,4 @@
1
- import { type BlueprintResource } from '@sanity/blueprints';
1
+ import type { BlueprintResource } from '@sanity/blueprints';
2
2
  /**
3
3
  * Extracts the blueprint config from the function source code and mutates it to the resource object.
4
4
  * This is used for durable functions that may not have a config defined in the blueprint.
@@ -1,11 +1,10 @@
1
1
  import { resolve } from 'node:path';
2
2
  import { pathToFileURL } from 'node:url';
3
- import { validateDurableFunction, } from '@sanity/blueprints';
4
3
  import { SANITY_FUNCTION_DURABLE } from '../../constants.js';
5
4
  import { isLocalFunctionResource } from '../types.js';
6
5
  import { findFunctionEntryPoint } from './find-entry-point.js';
7
6
  import { transpileFunction } from './transpile/function.js';
8
- const DURABLE_CONFIG_KEYS = ['event', 'concurrency', 'debounce'];
7
+ const DURABLE_CONFIG_KEYS = ['event', 'durableTimeout'];
9
8
  /**
10
9
  * Extracts the blueprint config from the function source code and mutates it to the resource object.
11
10
  * This is used for durable functions that may not have a config defined in the blueprint.
@@ -37,19 +36,13 @@ export const extractDurableConfig = async (resource, blueprintFileDir) => {
37
36
  finally {
38
37
  await cleanup();
39
38
  }
40
- // Update values not included in the blueprint.
41
- if (resource.event === undefined && config?.event !== undefined) {
42
- resource.event = config.event;
43
- }
44
- if (resource.concurrency === undefined && config?.concurrency !== undefined) {
45
- resource.concurrency = config.concurrency;
46
- }
47
- if (resource.debounce === undefined && config?.debounce !== undefined) {
48
- resource.debounce = config.debounce;
49
- }
50
- // Validate the resource after merging the config values
51
- const errors = validateDurableFunction(resource);
52
- if (errors.length > 0) {
53
- throw new Error(`Invalid durable resource "${resource.name}": ${errors.map((error) => error.message).join('; ')}`);
39
+ // Update values not included in the blueprint, but set in the config
40
+ if (config) {
41
+ if (resource.event === undefined && config.event !== undefined) {
42
+ resource.event = config.event;
43
+ }
44
+ if (resource.durableTimeout === undefined && config.durableTimeout !== undefined) {
45
+ resource.durableTimeout = config.durableTimeout;
46
+ }
54
47
  }
55
48
  };
@@ -1,4 +1,5 @@
1
1
  import { type BlueprintCorsOriginResource, type BlueprintDatasetResource, type BlueprintDocumentFunctionResource, type BlueprintDocumentWebhookResource, type BlueprintDurableFunctionResource, type BlueprintMediaLibraryAssetFunctionResource, type BlueprintProjectResource, type BlueprintPubSubFunctionResource, type BlueprintResource, type BlueprintRobotResource, type BlueprintRoleResource, type BlueprintScheduledFunctionResource, type BlueprintStudioResource, type BlueprintSyncTagInvalidateFunctionResource } from '@sanity/blueprints';
2
+ import { type SANITY_AGENT_TYPE } from '../constants.js';
2
3
  export type ScopeType = 'organization' | 'project';
3
4
  /** Result utility type */
4
5
  export type Result<T, E = string> = {
@@ -46,6 +47,17 @@ export interface ResolvedResource<R extends BlueprintResource> {
46
47
  externalId?: string;
47
48
  }
48
49
  export declare function isLocalFunctionResource(r: BlueprintResource): r is FunctionResource;
50
+ /**
51
+ * A `sanity.agent` resource. Declared here because `@sanity/blueprints` does not
52
+ * yet export the type; `name`, `description`, and `region` become the manifest.
53
+ */
54
+ export interface AgentResource extends BlueprintResource {
55
+ type: typeof SANITY_AGENT_TYPE;
56
+ src: string;
57
+ /** Region name from the platform allowlist (e.g. `virginia`). */
58
+ region: string;
59
+ description?: string;
60
+ }
49
61
  export declare function hasEventSource(r: FunctionResource): r is EventFunctionResource;
50
62
  export declare function isScheduleEvent(e: unknown): e is BlueprintScheduledFunctionResource['event'];
51
63
  export declare function isCorsOriginResource(r: unknown): r is BlueprintCorsOriginResource;
@@ -345,6 +357,8 @@ export type PrepAssetFn<R extends BlueprintResource> = (options: {
345
357
  resolvedResource: ResolvedResource<R>;
346
358
  blueprintFileDir: string;
347
359
  installer?: InstallerType;
360
+ /** Deploy auth; the agent prep uses `auth.scopeId` for the manifest `sanityID`. */
361
+ auth?: AuthParams;
348
362
  }) => Promise<AssetPrepResult>;
349
363
  export type PrepResourceFn<R extends BlueprintResource> = (options: {
350
364
  resource: R;
@@ -1,5 +1,5 @@
1
1
  import { validateCorsOrigin, validateDataset, validateDocumentWebhook, validateDurableFunction, validateProject, validateRobot, validateRole, } from '@sanity/blueprints';
2
- import { SANITY_FUNCTION_PREFIX, SANITY_FUNCTION_PUBSUB, SANITY_STUDIO } from '../constants.js';
2
+ import { SANITY_FUNCTION_PREFIX, SANITY_FUNCTION_PUBSUB, SANITY_STUDIO, } from '../constants.js';
3
3
  export function isLocalFunctionResource(r) {
4
4
  return r.type.startsWith(SANITY_FUNCTION_PREFIX);
5
5
  }
@@ -3150,5 +3150,5 @@
3150
3150
  ]
3151
3151
  }
3152
3152
  },
3153
- "version": "17.18.0"
3153
+ "version": "17.19.0-next.g94c4d8c"
3154
3154
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sanity/runtime-cli",
3
3
  "description": "Sanity's Runtime CLI for Blueprints and Functions",
4
- "version": "17.18.0",
4
+ "version": "17.19.0-next.g94c4d8c",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -68,10 +68,10 @@
68
68
  "@oclif/core": "^4.14.0",
69
69
  "@oclif/plugin-help": "^6.3.0",
70
70
  "@sanity-labs/oclif-plugin-skills-flag": "^0.2.1",
71
- "@sanity/blueprints": "^0.29.0",
71
+ "@sanity/blueprints": "^0.32.0",
72
72
  "@sanity/blueprints-parser": "^0.5.0",
73
- "@sanity/cli-build": "^7.0.2",
74
- "@sanity/cli-core": "^3.12.0",
73
+ "@sanity/cli-build": "^7.1.0",
74
+ "@sanity/cli-core": "^3.14.1",
75
75
  "@sanity/client": "^8.6.1",
76
76
  "adm-zip": "^0.6.1",
77
77
  "array-treeify": "^0.2.0",