Skip to content

Commit 8e388f7

Browse files
fix: remove validating AABs before deploying
1 parent 630463b commit 8e388f7

3 files changed

Lines changed: 2 additions & 642 deletions

File tree

src/client/metadataApiDeploy.ts

Lines changed: 1 addition & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@
1515
*/
1616
import { join, relative, resolve as pathResolve, sep } from 'node:path';
1717
import { format } from 'node:util';
18-
import { EOL } from 'node:os';
1918
import { isString } from '@salesforce/ts-types';
2019
import JSZip from 'jszip';
2120
import fs from 'graceful-fs';
2221
import { Lifecycle } from '@salesforce/core/lifecycle';
2322
import { Messages } from '@salesforce/core/messages';
2423
import { SfError } from '@salesforce/core/sfError';
2524
import { envVars } from '@salesforce/core/envVars';
26-
import { Connection } from '@salesforce/core';
27-
import { ensureArray, env } from '@salesforce/kit';
28-
import { SourceComponent } from '../resolve/sourceComponent';
25+
import { ensureArray } from '@salesforce/kit';
2926
import { RegistryAccess } from '../registry';
3027
import { ReplacementEvent } from '../convert/types';
3128
import { MetadataConverter } from '../convert';
@@ -207,15 +204,6 @@ export class MetadataApiDeploy extends MetadataTransfer<
207204
// this is used as the version in the manifest (package.xml).
208205
this.components.sourceApiVersion ??= apiVersion;
209206
}
210-
if (this.options.components) {
211-
// we must ensure AiAuthoringBundles compile before deployment
212-
// Use optimized getter method instead of filtering all components
213-
const aabComponents = this.options.components.getAiAuthoringBundles().toArray();
214-
215-
if (aabComponents.length > 0 && env.getBoolean('SF_AAB_COMPILATION', true)) {
216-
await compileAABComponents(connection, aabComponents);
217-
}
218-
}
219207
// only do event hooks if source, (NOT a metadata format) deploy
220208
if (this.options.components) {
221209
await LifecycleInstance.emit('scopedPreDeploy', {
@@ -436,123 +424,6 @@ export class MetadataApiDeploy extends MetadataTransfer<
436424
}
437425
}
438426

439-
const compileAABComponents = async (connection: Connection, aabComponents: SourceComponent[]): Promise<void> => {
440-
// we need to use a namedJWT connection for this request
441-
const { accessToken, instanceUrl } = connection.getConnectionOptions();
442-
if (!instanceUrl) {
443-
throw SfError.create({
444-
name: 'ApiAccessError',
445-
message: 'Missing Instance URL for org connection',
446-
});
447-
}
448-
if (!accessToken) {
449-
throw SfError.create({
450-
name: 'ApiAccessError',
451-
message: 'Missing Access Token for org connection',
452-
});
453-
}
454-
const url = `${instanceUrl}/agentforce/bootstrap/nameduser`;
455-
// For the namdeduser endpoint request to work we need to delete the access token
456-
delete connection.accessToken;
457-
const response = await connection.request<{
458-
access_token: string;
459-
}>(
460-
{
461-
method: 'GET',
462-
url,
463-
headers: {
464-
'Content-Type': 'application/json',
465-
Cookie: `sid=${accessToken}`,
466-
},
467-
},
468-
{ retry: { maxRetries: 3 } }
469-
);
470-
connection.accessToken = response.access_token;
471-
const results = await Promise.all(
472-
aabComponents.map(async (aab) => {
473-
// aab.content points to a directory, we need to find the .agent file and read it
474-
if (!aab.content) {
475-
throw new SfError(
476-
messages.getMessage('error_expected_source_files', [aab.fullName, 'aiauthoringbundle']),
477-
'ExpectedSourceFilesError'
478-
);
479-
}
480-
481-
const contentPath = aab.tree.find('content', aab.name, aab.content);
482-
483-
if (!contentPath) {
484-
// if this didn't exist, they'll have deploy issues anyways, but we can check here for type reasons
485-
throw new SfError(`No .agent file found in directory: ${aab.content}`, 'MissingAgentFileError');
486-
}
487-
488-
const agentContent = await fs.promises.readFile(contentPath, 'utf-8');
489-
490-
let result: {
491-
// minimal typings here, more is returned, just using what we need
492-
status: 'failure' | 'success';
493-
errors: Array<{
494-
description: string;
495-
lineStart: number;
496-
colStart: number;
497-
}>;
498-
name: string;
499-
};
500-
try {
501-
// to avoid circular dependencies between libraries, just call the compile endpoint here
502-
result = await connection.request<typeof result>({
503-
method: 'POST',
504-
url: `https://${
505-
env.getBoolean('SF_TEST_API') ? 'test.' : ''
506-
}api.salesforce.com/einstein/ai-agent/v1.1/authoring/scripts`,
507-
headers: {
508-
'x-client-name': 'afdx',
509-
'content-type': 'application/json',
510-
},
511-
body: JSON.stringify({
512-
assets: [
513-
{
514-
type: 'AFScript',
515-
name: 'AFScript',
516-
content: agentContent,
517-
},
518-
],
519-
afScriptVersion: '1.0.1',
520-
}),
521-
});
522-
result.name = aab.name;
523-
return result;
524-
} catch (e) {
525-
const error = SfError.wrap(e);
526-
if (error.name.includes('ERROR_HTTP_404')) {
527-
error.message = 'HTTP 404 error encountered when compiling AiAuthoringBundles';
528-
error.actions = [
529-
"Ensure the org's agent functionality is working outside of deployments",
530-
"Try the 'sf agent validate authoring-bundle' command",
531-
];
532-
}
533-
throw error;
534-
} finally {
535-
// regardless of success or failure, we don't need the named user jwt access token anymore
536-
delete connection.accessToken;
537-
await connection.refreshAuth();
538-
}
539-
})
540-
);
541-
542-
const errors = results
543-
.filter((result) => result.status === 'failure')
544-
.map((result) =>
545-
result.errors.map((r) => `${result.name}.agent: ${r.description} ${r.lineStart}:${r.colStart}`).join(EOL)
546-
);
547-
548-
if (errors.length > 0) {
549-
throw SfError.create({
550-
message: `${EOL}${errors.join(EOL)}`,
551-
name: 'AgentCompilationError',
552-
});
553-
}
554-
};
555-
556427
/**
557428
* If a component fails to delete because it doesn't exist in the org, you get a message like
558429
* key: 'ApexClass#destructiveChanges.xml'

src/collections/componentSet.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
107107
// used to store components meant for a "constructive" (not destructive) manifest
108108
private manifestComponents = new DecodeableMap<string, DecodeableMap<string, SourceComponent>>();
109109

110-
// optimization: track AiAuthoringBundles separately for faster access during compilation check
111-
private aiAuthoringBundles = new Set<SourceComponent>();
112-
113110
private destructiveChangesType = DestructiveChangesType.POST;
114111

115112
public constructor(components: Iterable<ComponentLike> = [], registry = new RegistryAccess()) {
@@ -532,16 +529,6 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
532529
return new LazyCollection(iter).filter((c) => c instanceof SourceComponent) as LazyCollection<SourceComponent>;
533530
}
534531

535-
/**
536-
* Get all constructive AiAuthoringBundle components in the set, which require compilation before deploy.
537-
* This is an optimized method that uses a cached Set of AAB components.
538-
*
539-
* @returns Collection of AiAuthoringBundle source components
540-
*/
541-
public getAiAuthoringBundles(): LazyCollection<SourceComponent> {
542-
return new LazyCollection(this.aiAuthoringBundles);
543-
}
544-
545532
public add(component: ComponentLike, deletionType?: DestructiveChangesType): void {
546533
const key = simpleKey(component);
547534
if (!this.components.has(key)) {
@@ -571,11 +558,6 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
571558
// we're working with SourceComponents now
572559
this.components.get(key)?.set(srcKey, component);
573560

574-
// track AiAuthoringBundles separately for fast access (exclude destructive changes - no need to compile something that will be deleted)
575-
if (component.type.id === 'aiauthoringbundle' && !deletionType) {
576-
this.aiAuthoringBundles.add(component);
577-
}
578-
579561
// Build maps of destructive components and regular components as they are added
580562
// as an optimization when building manifests.
581563
if (deletionType) {

0 commit comments

Comments
 (0)