Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions scripts/deploy-runner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion servers/genesys-cloud-architect-mcp.js

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions src/deploy-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ let publishedFlowName: string | undefined;
let replacedFlowId: string | undefined;
let publishSucceeded = false;
let checkInSucceeded = false;
let saveSucceeded = false;
let sdkVersion: string | undefined;

interface ValidationIssue {
Expand Down Expand Up @@ -311,6 +312,7 @@ const FLOW_REPLACED_RE =
/successfully posted request to delete the existing flow named '.+?' \(id: '(.+?)'\)/;
const PUBLISH_SUCCEEDED_RE = /publishAsync - publish successful/;
const CHECK_IN_SUCCEEDED_RE = /checkInAsync - checked in/;
const SAVE_SUCCEEDED_RE = /saveAsync - save successful/;

function installLogging(scripting: ArchitectScripting): void {
const logging = scripting.services.archLogging;
Expand Down Expand Up @@ -338,6 +340,9 @@ function installLogging(scripting: ArchitectScripting): void {
if (CHECK_IN_SUCCEEDED_RE.test(msg)) {
checkInSucceeded = true;
}
if (SAVE_SUCCEEDED_RE.test(msg)) {
saveSucceeded = true;
}

const isSummary = captureValidationSummary(msg, level);
if (
Expand Down Expand Up @@ -404,12 +409,49 @@ function validationFromLog(): DeployValidation {
return { errors: texts("error"), warnings: texts("warning") };
}

/** Every flow the flow file made through the SDK's flow factory. */
const createdFlows: FlowLike[] = [];

/**
* Remembers each flow the flow file creates. When buildFlow() throws (a
* publish that fails after the save, say) it returns nothing, and the flow
* object is the only source of the flow's type and url.
*/
function trackCreatedFlows(scripting: ArchitectScripting): void {
const factory = scripting.factories.archFactoryFlows as any;
const proto = Object.getPrototypeOf(factory);
for (const name of Object.getOwnPropertyNames(proto)) {
// Test the name first: reading other members runs the factory's
// getters, which log warnings before the session is connected.
if (!/^create\w*Async$/.test(name)) continue;
const original = proto[name];
if (typeof original !== "function") continue;
factory[name] = function trackedCreate(...args: unknown[]) {
const result = original.apply(this, args);
Promise.resolve(result).then(
(flow: FlowLike) => createdFlows.push(flow),
() => {},
);
return result;
};
}
}

function failure(error: string): DeployResultPayload {
// A flow the SDK logged creating exists in the org even though the
// deploy failed, so report what it is and where to open it.
const flow = createdFlows.find((f) => f?.id === publishedFlowId);
const leftBehind = publishedFlowId !== undefined;
return {
success: false,
status: "failed",
flowId: publishedFlowId,
flowName: publishedFlowName,
flowType: nonEmptyString(flow?.flowType),
flowUrl: nonEmptyString(flow?.url),
note: leftBehind
? `The flow was created${saveSucceeded ? " and saved" : ""} but not published: an unpublished flow '${publishedFlowName}' (id: ${publishedFlowId}) now exists in the org.`
: undefined,
replacedFlowId,
validation: validationFromLog(),
sdkVersion,
Expand Down Expand Up @@ -506,6 +548,7 @@ async function main(): Promise<void> {
const scripting: ArchitectScripting = require("purecloud-flow-scripting-api-sdk-javascript");

installLogging(scripting);
trackCreatedFlows(scripting);
sdkVersion = nonEmptyString(
scripting.environment.ArchScriptingInfo?.version,
);
Expand Down
8 changes: 7 additions & 1 deletion src/mcp-server/tools/deploy-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ interface LogEntry {
export interface DeployFlowResult {
status: DeployStatus;
error?: string;
/** Present when the failed deploy left an unpublished flow in the org;
* the flow* fields then describe that flow. */
note?: string;
/** The SDK's own error-level log lines, in order, deduplicated. */
diagnosis?: string[];
flowId: string | null;
Expand Down Expand Up @@ -128,6 +131,7 @@ function buildResult({
return {
status: "failed",
error: error ?? runnerResult?.error ?? "Deploy failed",
...(runnerResult?.note ? { note: runnerResult.note } : {}),
diagnosis: diagnosisFrom(logs),
...facts,
log: formatLog(logs),
Expand Down Expand Up @@ -155,7 +159,9 @@ export const deployFlow: ToolFactory<DeployFlowConfig, typeof inputSchema> = (
"flow the SDK deleted before creating this one, meaning the flow id changed; " +
"null when nothing was replaced), validation {errors, warnings}, sdkVersion " +
"and durationMs. On failure, error and diagnosis (the SDK's own error lines) " +
"come first and the full log is attached. On success the log is omitted " +
"come first and the full log is attached. If the failure left an " +
"unpublished flow in the org (e.g. the save succeeded and the publish " +
"failed), a note says so and the flow fields describe that flow. On success the log is omitted " +
"unless verbose is true.",
annotations: {
title: "Deploy Flow",
Expand Down
2 changes: 2 additions & 0 deletions src/shared/deploy-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ export interface DeployResultPayload {
validation: DeployValidation;
sdkVersion?: string;
error?: string;
/** Set on a failure that left an unpublished flow behind in the org. */
note?: string;
}
Loading