|
15 | 15 | */ |
16 | 16 | import { join, relative, resolve as pathResolve, sep } from 'node:path'; |
17 | 17 | import { format } from 'node:util'; |
18 | | -import { EOL } from 'node:os'; |
19 | 18 | import { isString } from '@salesforce/ts-types'; |
20 | 19 | import JSZip from 'jszip'; |
21 | 20 | import fs from 'graceful-fs'; |
22 | 21 | import { Lifecycle } from '@salesforce/core/lifecycle'; |
23 | 22 | import { Messages } from '@salesforce/core/messages'; |
24 | 23 | import { SfError } from '@salesforce/core/sfError'; |
25 | 24 | 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'; |
29 | 26 | import { RegistryAccess } from '../registry'; |
30 | 27 | import { ReplacementEvent } from '../convert/types'; |
31 | 28 | import { MetadataConverter } from '../convert'; |
@@ -207,15 +204,6 @@ export class MetadataApiDeploy extends MetadataTransfer< |
207 | 204 | // this is used as the version in the manifest (package.xml). |
208 | 205 | this.components.sourceApiVersion ??= apiVersion; |
209 | 206 | } |
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 | | - } |
219 | 207 | // only do event hooks if source, (NOT a metadata format) deploy |
220 | 208 | if (this.options.components) { |
221 | 209 | await LifecycleInstance.emit('scopedPreDeploy', { |
@@ -436,123 +424,6 @@ export class MetadataApiDeploy extends MetadataTransfer< |
436 | 424 | } |
437 | 425 | } |
438 | 426 |
|
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 | | - |
556 | 427 | /** |
557 | 428 | * If a component fails to delete because it doesn't exist in the org, you get a message like |
558 | 429 | * key: 'ApexClass#destructiveChanges.xml' |
|
0 commit comments