@muxoai/sdk 1.4.3 → 1.4.5
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/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +2 -2
- package/README.md +25 -1
- package/dist/cli.js +167 -38
- package/dist/composio-catalog.d.ts +26 -0
- package/dist/composio-catalog.js +157 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +1 -0
- package/dist/engine.d.ts +51 -5
- package/dist/engine.js +484 -30
- package/dist/mcp-schema.d.ts +14 -0
- package/dist/mcp-schema.js +77 -8
- package/dist/mcp.js +300 -3
- package/dist/oss-suite.d.ts +188 -4
- package/dist/oss-suite.js +1249 -20
- package/dist/policy.js +59 -0
- package/dist/providers/composio-instant.js +54 -36
- package/dist/providers/composio-sdk.d.ts +10 -1
- package/dist/providers/composio-sdk.js +144 -31
- package/dist/sdk.d.ts +19 -0
- package/dist/sdk.js +32 -0
- package/dist/server.js +119 -7
- package/dist/skills-catalog.d.ts +66 -0
- package/dist/skills-catalog.js +840 -0
- package/dist/store.d.ts +4 -1
- package/dist/store.js +37 -3
- package/dist/types.d.ts +33 -0
- package/dist/ui/console-html.js +35 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/plugins/muxo/.claude-plugin/plugin.json +2 -2
- package/plugins/muxo/.codex-plugin/plugin.json +3 -3
- package/plugins/muxo/.cursor-plugin/plugin.json +2 -2
- package/plugins/muxo/plugin.json +3 -3
- package/plugins/muxo/skills/muxo/SKILL.md +13 -3
package/dist/engine.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import { isStripeProjectsExclusiveProvider, normalizeStripeProjectsProviderSlug, wrapMuxoConnectUrl, } from "./composio-catalog.js";
|
|
3
|
+
import { getProviderSkillHint } from "./skills-catalog.js";
|
|
3
4
|
import { APPROVED_PLAN_STATUSES, approvalRequiredError, buildApprovalHumanHandoff, buildApprovalUrl, buildOAuthHumanHandoff, clampWaitSeconds, looksLikeToolSlug, unknownToolError, } from "./mcp-schema.js";
|
|
4
5
|
import { completeCloudProvisioningWorkflow, createCloudProvisioningWorkflow, exportTemporalEventHistory, normalizeWorkflowTarget, rollbackDurableWorkflow as runSagaRollbackOnWorkflow, signalDurableWorkflow as sendSignalToWorkflow, workflowNotFoundError, } from "./durable-workflow.js";
|
|
5
6
|
import { buildMemoryKnowledgeGraph } from "./memory-graph.js";
|
|
6
|
-
import { MUXO_COMMERCIAL_PLAYBOOKS, buildCommercialRoiReport, buildOtelTraceExport, buildPlaybookSagaExecution, compileWorkspacePolicyToCedarAndRego, evaluateCedarAndOpaPolicy, getCommercialPlaybook, } from "./oss-suite.js";
|
|
7
|
+
import { MUXO_COMMERCIAL_PLAYBOOKS, buildApprovalImpactPreview, buildBusinessReceiptSummary, buildCommercialRoiReport, buildHarnessConfigurationBundle, buildOtelTraceExport, buildPlaybookSagaExecution, buildRunReconciliationReport, compileWorkspacePolicyToCedarAndRego, evaluateCedarAndOpaPolicy, getCommercialPlaybook, parseNaturalLanguageCustomPlaybook, parseNaturalLanguageOssIntent, resolveHarnessPreset, } from "./oss-suite.js";
|
|
7
8
|
import { resolveNaturalLanguageIntent, } from "./nl.js";
|
|
8
9
|
import { DEFAULT_WORKSPACE_POLICY, buildLlmPolicyAndGovernanceBrief, compileNaturalLanguageGuardrailWithLlm, describePolicyInPlainEnglish, formatHumanFriendlyExplanation, parseNaturalLanguageGuardrail, simulatePolicyEvaluation, } from "./policy.js";
|
|
9
10
|
import { ComposioInstantAdapter } from "./providers/composio-instant.js";
|
|
@@ -40,6 +41,7 @@ export class MuxoEngine {
|
|
|
40
41
|
governance;
|
|
41
42
|
supermemory;
|
|
42
43
|
durableWorkflows = new Map();
|
|
44
|
+
customPlaybooks = new Map();
|
|
43
45
|
constructor(config, store) {
|
|
44
46
|
this.config = config;
|
|
45
47
|
this.store = store;
|
|
@@ -173,21 +175,30 @@ export class MuxoEngine {
|
|
|
173
175
|
// 4. inspect_tool
|
|
174
176
|
async inspectTool(slug) {
|
|
175
177
|
const normalized = slug.trim();
|
|
178
|
+
const withSkillHint = (tool) => {
|
|
179
|
+
const hint = getProviderSkillHint(tool.providerSlug || tool.slug, this.config.baseUrl);
|
|
180
|
+
return hint
|
|
181
|
+
? {
|
|
182
|
+
...tool,
|
|
183
|
+
domainSkill: hint,
|
|
184
|
+
}
|
|
185
|
+
: tool;
|
|
186
|
+
};
|
|
176
187
|
const billing = this.stripeBilling
|
|
177
188
|
.listTools()
|
|
178
189
|
.find((t) => t.slug.toLowerCase() === normalized.toLowerCase() ||
|
|
179
190
|
t.upstreamSlug.toLowerCase() === normalized.toLowerCase());
|
|
180
191
|
if (billing)
|
|
181
|
-
return billing;
|
|
192
|
+
return withSkillHint(billing);
|
|
182
193
|
const instant = this.composioInstant.inspectTool(normalized);
|
|
183
194
|
if (instant)
|
|
184
|
-
return instant;
|
|
195
|
+
return withSkillHint(instant);
|
|
185
196
|
const proj = this.stripeProjects.inspectTool(normalized);
|
|
186
197
|
if (proj)
|
|
187
|
-
return proj;
|
|
198
|
+
return withSkillHint(proj);
|
|
188
199
|
const sdk = await this.composioSdk.inspectTool(normalized);
|
|
189
200
|
if (sdk)
|
|
190
|
-
return sdk;
|
|
201
|
+
return withSkillHint(sdk);
|
|
191
202
|
throw unknownToolError(normalized);
|
|
192
203
|
}
|
|
193
204
|
// 5. connection_status
|
|
@@ -626,6 +637,19 @@ export class MuxoEngine {
|
|
|
626
637
|
decisionRecord,
|
|
627
638
|
memoryContext,
|
|
628
639
|
});
|
|
640
|
+
plan.changePreview = buildApprovalImpactPreview({
|
|
641
|
+
toolSlug: plan.toolSlug,
|
|
642
|
+
lane: plan.lane,
|
|
643
|
+
riskLevel: plan.riskLevel,
|
|
644
|
+
input: plan.input,
|
|
645
|
+
reason: plan.reason,
|
|
646
|
+
creditCost: plan.creditCost,
|
|
647
|
+
fundingMode: byokActive ? "byok" : "muxo_funded",
|
|
648
|
+
supplierSettlement: plan.supplierSettlement,
|
|
649
|
+
decisionRecord: plan.decisionRecord,
|
|
650
|
+
workspaceName: ws.name,
|
|
651
|
+
});
|
|
652
|
+
plan.estimatedCostUsd = plan.changePreview.estimatedCostUsd;
|
|
629
653
|
// 3. Check external user OAuth connection state for Connected Apps (composio_sdk)
|
|
630
654
|
let authHandoff;
|
|
631
655
|
if (tool.lane === "composio_sdk" && tool.requiresAuth) {
|
|
@@ -678,6 +702,8 @@ export class MuxoEngine {
|
|
|
678
702
|
? this.buildApprovalHandoff(plan)
|
|
679
703
|
: undefined;
|
|
680
704
|
const llmGuidance = this.buildPlanLlmGuidance(plan, authHandoff);
|
|
705
|
+
const domainSkill = getProviderSkillHint(tool.providerSlug || tool.slug, this.config.baseUrl) ||
|
|
706
|
+
undefined;
|
|
681
707
|
return {
|
|
682
708
|
plan,
|
|
683
709
|
tool,
|
|
@@ -685,6 +711,7 @@ export class MuxoEngine {
|
|
|
685
711
|
memoryContext,
|
|
686
712
|
...(authHandoff ? { authHandoff } : {}),
|
|
687
713
|
...(humanHandoff ? { humanHandoff } : {}),
|
|
714
|
+
...(domainSkill ? { domainSkill } : {}),
|
|
688
715
|
llmGuidance,
|
|
689
716
|
nextStep,
|
|
690
717
|
};
|
|
@@ -694,6 +721,21 @@ export class MuxoEngine {
|
|
|
694
721
|
const plan = this.store.getPlan(ctx.workspace.id, planId);
|
|
695
722
|
if (!plan)
|
|
696
723
|
throw new Error(`Plan '${planId}' not found in workspace.`);
|
|
724
|
+
if (!plan.changePreview) {
|
|
725
|
+
const ws = this.store.getWorkspace(ctx.workspace.id);
|
|
726
|
+
plan.changePreview = buildApprovalImpactPreview({
|
|
727
|
+
toolSlug: plan.toolSlug,
|
|
728
|
+
lane: plan.lane,
|
|
729
|
+
riskLevel: plan.riskLevel,
|
|
730
|
+
input: plan.input,
|
|
731
|
+
reason: plan.reason,
|
|
732
|
+
creditCost: plan.creditCost,
|
|
733
|
+
supplierSettlement: plan.supplierSettlement,
|
|
734
|
+
decisionRecord: plan.decisionRecord,
|
|
735
|
+
workspaceName: ws?.name,
|
|
736
|
+
});
|
|
737
|
+
plan.estimatedCostUsd = plan.changePreview.estimatedCostUsd;
|
|
738
|
+
}
|
|
697
739
|
return plan;
|
|
698
740
|
}
|
|
699
741
|
async waitForPlanApproval(ctx, params) {
|
|
@@ -1202,6 +1244,13 @@ export class MuxoEngine {
|
|
|
1202
1244
|
const existingRun = this.store.getRun(ctx.workspace.id, plan.runId);
|
|
1203
1245
|
const existingReceipt = this.store.getReceipt(ctx.workspace.id, plan.runId);
|
|
1204
1246
|
if (existingRun && existingReceipt) {
|
|
1247
|
+
existingRun.idempotentReplay = true;
|
|
1248
|
+
existingRun.reconciliationStatus =
|
|
1249
|
+
existingRun.status === "succeeded"
|
|
1250
|
+
? "verified_complete"
|
|
1251
|
+
: existingRun.status === "cancelled"
|
|
1252
|
+
? "cancelled"
|
|
1253
|
+
: "failed_zero_charge";
|
|
1205
1254
|
return { run: existingRun, receipt: existingReceipt };
|
|
1206
1255
|
}
|
|
1207
1256
|
throw new Error(`Plan '${plan.id}' was already claimed by run '${plan.runId}' (execute-once invariant).`);
|
|
@@ -1311,6 +1360,9 @@ export class MuxoEngine {
|
|
|
1311
1360
|
input: plan.input,
|
|
1312
1361
|
connectedAccountId: activeConnId,
|
|
1313
1362
|
composioApiKey: composioByok,
|
|
1363
|
+
mcpGatewayUrl: composioByok
|
|
1364
|
+
? this.store.getByokMcpGatewayUrl(ctx.workspace.id)
|
|
1365
|
+
: null,
|
|
1314
1366
|
});
|
|
1315
1367
|
}
|
|
1316
1368
|
else if (plan.lane === "stripe_projects") {
|
|
@@ -1373,6 +1425,24 @@ export class MuxoEngine {
|
|
|
1373
1425
|
run: finalized.run,
|
|
1374
1426
|
workspace: ws,
|
|
1375
1427
|
});
|
|
1428
|
+
finalized.receipt.businessSummary = buildBusinessReceiptSummary({
|
|
1429
|
+
toolSlug: finalized.receipt.toolSlug,
|
|
1430
|
+
lane: finalized.receipt.lane,
|
|
1431
|
+
riskLevel: finalized.receipt.riskLevel,
|
|
1432
|
+
status: finalized.receipt.status,
|
|
1433
|
+
creditsMetered: finalized.receipt.creditsMetered,
|
|
1434
|
+
input: plan.input,
|
|
1435
|
+
output,
|
|
1436
|
+
approvedBy: plan.approvedBy,
|
|
1437
|
+
actorId: finalized.receipt.actorId,
|
|
1438
|
+
decisionRecord: finalized.receipt.decisionRecord,
|
|
1439
|
+
supplierSettlement: finalized.receipt.supplierSettlement,
|
|
1440
|
+
});
|
|
1441
|
+
finalized.receipt.estimatedCostUsd =
|
|
1442
|
+
finalized.receipt.businessSummary.costUsd;
|
|
1443
|
+
finalized.run.estimatedCostUsd =
|
|
1444
|
+
finalized.receipt.businessSummary.costUsd;
|
|
1445
|
+
finalized.run.reconciliationStatus = "verified_complete";
|
|
1376
1446
|
finalized.receipt.explanation = this.explainReceipt(finalized.receipt, {
|
|
1377
1447
|
signatureValid: this.store.verifyReceipt(finalized.receipt),
|
|
1378
1448
|
governanceSignatureValid: true,
|
|
@@ -1452,6 +1522,25 @@ export class MuxoEngine {
|
|
|
1452
1522
|
run: failedFinalized.run,
|
|
1453
1523
|
workspace: ws,
|
|
1454
1524
|
});
|
|
1525
|
+
failedFinalized.receipt.businessSummary = buildBusinessReceiptSummary({
|
|
1526
|
+
toolSlug: failedFinalized.receipt.toolSlug,
|
|
1527
|
+
lane: failedFinalized.receipt.lane,
|
|
1528
|
+
riskLevel: failedFinalized.receipt.riskLevel,
|
|
1529
|
+
status: failedFinalized.receipt.status,
|
|
1530
|
+
creditsMetered: failedFinalized.receipt.creditsMetered,
|
|
1531
|
+
input: plan.input,
|
|
1532
|
+
output: { error: errorMessage },
|
|
1533
|
+
error: errorMessage,
|
|
1534
|
+
approvedBy: plan.approvedBy,
|
|
1535
|
+
actorId: failedFinalized.receipt.actorId,
|
|
1536
|
+
decisionRecord: failedFinalized.receipt.decisionRecord,
|
|
1537
|
+
supplierSettlement: failedFinalized.receipt.supplierSettlement,
|
|
1538
|
+
});
|
|
1539
|
+
failedFinalized.receipt.estimatedCostUsd =
|
|
1540
|
+
failedFinalized.receipt.businessSummary.costUsd;
|
|
1541
|
+
failedFinalized.run.estimatedCostUsd =
|
|
1542
|
+
failedFinalized.receipt.businessSummary.costUsd;
|
|
1543
|
+
failedFinalized.run.reconciliationStatus = "failed_zero_charge";
|
|
1455
1544
|
failedFinalized.receipt.explanation = this.explainReceipt(failedFinalized.receipt, {
|
|
1456
1545
|
signatureValid: this.store.verifyReceipt(failedFinalized.receipt),
|
|
1457
1546
|
governanceSignatureValid: true,
|
|
@@ -1519,15 +1608,31 @@ export class MuxoEngine {
|
|
|
1519
1608
|
const verified = verification.signatureValid &&
|
|
1520
1609
|
verification.governanceSignatureValid &&
|
|
1521
1610
|
agenticOk;
|
|
1611
|
+
const businessSummary = receipt.businessSummary ||
|
|
1612
|
+
buildBusinessReceiptSummary({
|
|
1613
|
+
toolSlug: receipt.toolSlug,
|
|
1614
|
+
lane: receipt.lane,
|
|
1615
|
+
riskLevel: receipt.riskLevel,
|
|
1616
|
+
status: receipt.status,
|
|
1617
|
+
creditsMetered: receipt.creditsMetered,
|
|
1618
|
+
decisionRecord: receipt.decisionRecord,
|
|
1619
|
+
supplierSettlement: receipt.supplierSettlement,
|
|
1620
|
+
actorId: receipt.actorId,
|
|
1621
|
+
});
|
|
1622
|
+
receipt.businessSummary = businessSummary;
|
|
1623
|
+
receipt.estimatedCostUsd = businessSummary.costUsd;
|
|
1522
1624
|
const headline = receipt.status === "succeeded"
|
|
1523
|
-
? `Verified Receipt (${receipt.id}): ${receipt.toolSlug} succeeded
|
|
1625
|
+
? `Verified Receipt (${receipt.id}): ${receipt.toolSlug} succeeded · ${businessSummary.costDisplay}`
|
|
1524
1626
|
: receipt.status === "failed"
|
|
1525
|
-
? `Verified Receipt (${receipt.id}): ${receipt.toolSlug} failed (0 credits charged).`
|
|
1627
|
+
? `Verified Receipt (${receipt.id}): ${receipt.toolSlug} failed (0 credits charged / $0.00 USD).`
|
|
1526
1628
|
: `Verified Receipt (${receipt.id}): ${receipt.toolSlug} was cancelled.`;
|
|
1527
1629
|
const nonTechnical = [
|
|
1528
1630
|
headline,
|
|
1529
|
-
`
|
|
1530
|
-
`
|
|
1631
|
+
`What changed: ${businessSummary.whatChanged}`,
|
|
1632
|
+
`Who authorized it: ${businessSummary.whoAuthorized}.`,
|
|
1633
|
+
`What succeeded: ${businessSummary.whatSucceeded}`,
|
|
1634
|
+
`What remains unresolved: ${businessSummary.whatRemainsUnresolved}`,
|
|
1635
|
+
`Cost & billing: ${businessSummary.costDisplay}.`,
|
|
1531
1636
|
verified
|
|
1532
1637
|
? "Tamper-proof check: Verified (HMAC vault signature, portable Ed25519 AgenticReceipt envelope, and governance audit trail all match)."
|
|
1533
1638
|
: "Tamper-proof check: Warning (signature verification mismatch detected).",
|
|
@@ -1552,12 +1657,30 @@ export class MuxoEngine {
|
|
|
1552
1657
|
throw new Error(`Receipt '${receiptOrRunId}' not found in workspace.`);
|
|
1553
1658
|
}
|
|
1554
1659
|
const run = this.store.getRun(ws.id, receipt.runId);
|
|
1660
|
+
const plan = run ? this.store.getPlan(ws.id, run.planId) : undefined;
|
|
1555
1661
|
const agenticReceipt = this.governance.buildPortableAgenticReceipt({
|
|
1556
1662
|
receipt,
|
|
1557
1663
|
run,
|
|
1558
1664
|
workspace: ws,
|
|
1559
1665
|
});
|
|
1560
1666
|
receipt.agenticReceipt = agenticReceipt;
|
|
1667
|
+
if (!receipt.businessSummary) {
|
|
1668
|
+
receipt.businessSummary = buildBusinessReceiptSummary({
|
|
1669
|
+
toolSlug: receipt.toolSlug,
|
|
1670
|
+
lane: receipt.lane,
|
|
1671
|
+
riskLevel: receipt.riskLevel,
|
|
1672
|
+
status: receipt.status,
|
|
1673
|
+
creditsMetered: receipt.creditsMetered,
|
|
1674
|
+
input: run?.input,
|
|
1675
|
+
output: run?.output,
|
|
1676
|
+
error: run?.error,
|
|
1677
|
+
approvedBy: plan?.approvedBy,
|
|
1678
|
+
actorId: receipt.actorId,
|
|
1679
|
+
decisionRecord: receipt.decisionRecord,
|
|
1680
|
+
supplierSettlement: receipt.supplierSettlement,
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
receipt.estimatedCostUsd = receipt.businessSummary.costUsd;
|
|
1561
1684
|
const signatureValid = this.store.verifyReceipt(receipt);
|
|
1562
1685
|
const governanceSignatureValid = receipt.decisionRecord
|
|
1563
1686
|
? this.governance.verifyDecisionRecord(receipt.decisionRecord)
|
|
@@ -1572,19 +1695,84 @@ export class MuxoEngine {
|
|
|
1572
1695
|
governanceSignatureValid,
|
|
1573
1696
|
agenticReceiptValid,
|
|
1574
1697
|
explanation,
|
|
1698
|
+
businessSummary: receipt.businessSummary,
|
|
1575
1699
|
};
|
|
1576
1700
|
}
|
|
1701
|
+
reconcileRun(ctx, runOrPlanId) {
|
|
1702
|
+
const ws = this.store.getWorkspace(ctx.workspace.id);
|
|
1703
|
+
const trimmed = String(runOrPlanId || "").trim();
|
|
1704
|
+
const directRun = trimmed === "latest" || trimmed === "last" || !trimmed
|
|
1705
|
+
? this.store.listRuns(ws.id, 1)[0]
|
|
1706
|
+
: this.store.getRun(ws.id, trimmed);
|
|
1707
|
+
const directPlan = !directRun ? this.store.getPlan(ws.id, trimmed) : undefined;
|
|
1708
|
+
const plan = directPlan ||
|
|
1709
|
+
(directRun ? this.store.getPlan(ws.id, directRun.planId) : undefined) ||
|
|
1710
|
+
null;
|
|
1711
|
+
const run = directRun ||
|
|
1712
|
+
(plan?.runId ? this.store.getRun(ws.id, plan.runId) : undefined) ||
|
|
1713
|
+
null;
|
|
1714
|
+
if (!run && !plan) {
|
|
1715
|
+
throw new Error(`No run or plan '${runOrPlanId}' found in workspace '${ws.slug}' for reconciliation.`);
|
|
1716
|
+
}
|
|
1717
|
+
const receipt = run ? this.store.getReceipt(ws.id, run.id) || null : null;
|
|
1718
|
+
if (receipt && !receipt.businessSummary) {
|
|
1719
|
+
receipt.businessSummary = buildBusinessReceiptSummary({
|
|
1720
|
+
toolSlug: receipt.toolSlug,
|
|
1721
|
+
lane: receipt.lane,
|
|
1722
|
+
riskLevel: receipt.riskLevel,
|
|
1723
|
+
status: receipt.status,
|
|
1724
|
+
creditsMetered: receipt.creditsMetered,
|
|
1725
|
+
input: run?.input,
|
|
1726
|
+
output: run?.output,
|
|
1727
|
+
error: run?.error,
|
|
1728
|
+
approvedBy: plan?.approvedBy,
|
|
1729
|
+
actorId: receipt.actorId,
|
|
1730
|
+
decisionRecord: receipt.decisionRecord,
|
|
1731
|
+
supplierSettlement: receipt.supplierSettlement,
|
|
1732
|
+
});
|
|
1733
|
+
receipt.estimatedCostUsd = receipt.businessSummary.costUsd;
|
|
1734
|
+
}
|
|
1735
|
+
const signatureValid = receipt ? this.store.verifyReceipt(receipt) : false;
|
|
1736
|
+
const report = buildRunReconciliationReport({
|
|
1737
|
+
run,
|
|
1738
|
+
plan,
|
|
1739
|
+
receipt,
|
|
1740
|
+
signatureValid,
|
|
1741
|
+
});
|
|
1742
|
+
if (run) {
|
|
1743
|
+
run.reconciliationStatus = report.reconciliationStatus;
|
|
1744
|
+
}
|
|
1745
|
+
return report;
|
|
1746
|
+
}
|
|
1577
1747
|
listReceipts(ctx, limit = 25) {
|
|
1578
1748
|
const ws = this.store.getWorkspace(ctx.workspace.id);
|
|
1579
1749
|
const rows = this.store.listReceipts(ws.id, limit);
|
|
1580
1750
|
const enriched = rows.map((r) => {
|
|
1581
1751
|
const run = this.store.getRun(ws.id, r.runId);
|
|
1752
|
+
const plan = run ? this.store.getPlan(ws.id, run.planId) : undefined;
|
|
1582
1753
|
const agenticReceipt = this.governance.buildPortableAgenticReceipt({
|
|
1583
1754
|
receipt: r,
|
|
1584
1755
|
run,
|
|
1585
1756
|
workspace: ws,
|
|
1586
1757
|
});
|
|
1587
1758
|
r.agenticReceipt = agenticReceipt;
|
|
1759
|
+
if (!r.businessSummary) {
|
|
1760
|
+
r.businessSummary = buildBusinessReceiptSummary({
|
|
1761
|
+
toolSlug: r.toolSlug,
|
|
1762
|
+
lane: r.lane,
|
|
1763
|
+
riskLevel: r.riskLevel,
|
|
1764
|
+
status: r.status,
|
|
1765
|
+
creditsMetered: r.creditsMetered,
|
|
1766
|
+
input: run?.input,
|
|
1767
|
+
output: run?.output,
|
|
1768
|
+
error: run?.error,
|
|
1769
|
+
approvedBy: plan?.approvedBy,
|
|
1770
|
+
actorId: r.actorId,
|
|
1771
|
+
decisionRecord: r.decisionRecord,
|
|
1772
|
+
supplierSettlement: r.supplierSettlement,
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
r.estimatedCostUsd = r.businessSummary.costUsd;
|
|
1588
1776
|
const signatureValid = this.store.verifyReceipt(r);
|
|
1589
1777
|
const governanceSignatureValid = r.decisionRecord
|
|
1590
1778
|
? this.governance.verifyDecisionRecord(r.decisionRecord)
|
|
@@ -2122,20 +2310,218 @@ export class MuxoEngine {
|
|
|
2122
2310
|
humanMessage: memoryCheck.humanSummary,
|
|
2123
2311
|
};
|
|
2124
2312
|
}
|
|
2125
|
-
// 2c-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2313
|
+
// 2c-oss. Check if the user is invoking an OSS or Commercial Control-Plane capability in plain English
|
|
2314
|
+
const ossIntent = parseNaturalLanguageOssIntent(rawPrompt, {
|
|
2315
|
+
customPlaybooks: this.customPlaybooks.get(ws.id) || [],
|
|
2316
|
+
explicitInput: params.input,
|
|
2317
|
+
});
|
|
2318
|
+
if (ossIntent.matched && ossIntent.kind) {
|
|
2319
|
+
if (ossIntent.kind === "list_playbooks") {
|
|
2320
|
+
const playbooks = this.listCommercialPlaybooks(ctx);
|
|
2321
|
+
const humanMessage = `Available Saga Playbooks (${playbooks.length}): ${playbooks
|
|
2322
|
+
.map((p) => `${p.slug} (${p.name}, ~${p.estimatedMinutesSaved}m saved)`)
|
|
2323
|
+
.join("; ")}.`;
|
|
2324
|
+
const synthResolution = makeControlPlaneResolution("workspace.playbooks.list", rawPrompt, humanMessage);
|
|
2325
|
+
return {
|
|
2326
|
+
ok: true,
|
|
2327
|
+
executed: true,
|
|
2328
|
+
status: "playbook_listed",
|
|
2329
|
+
intent: synthResolution,
|
|
2330
|
+
resolution: synthResolution,
|
|
2331
|
+
playbooks,
|
|
2332
|
+
humanMessage,
|
|
2333
|
+
};
|
|
2334
|
+
}
|
|
2335
|
+
if (ossIntent.kind === "create_playbook" && ossIntent.customPlaybook) {
|
|
2336
|
+
const created = this.createCustomPlaybook(ctx, {
|
|
2337
|
+
prompt: rawPrompt,
|
|
2338
|
+
input: params.input,
|
|
2339
|
+
});
|
|
2340
|
+
const synthResolution = makeControlPlaneResolution("workspace.playbooks.create", rawPrompt, created.humanMessage, { slug: created.playbook.slug });
|
|
2341
|
+
return {
|
|
2342
|
+
ok: true,
|
|
2343
|
+
executed: true,
|
|
2344
|
+
status: "playbook_created",
|
|
2345
|
+
intent: synthResolution,
|
|
2346
|
+
resolution: synthResolution,
|
|
2347
|
+
playbook: created.playbook,
|
|
2348
|
+
playbooks: created.playbooks,
|
|
2349
|
+
humanMessage: created.humanMessage,
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
if (ossIntent.kind === "run_playbook" && ossIntent.playbookSlug) {
|
|
2353
|
+
const ran = this.runCommercialPlaybook(ctx, {
|
|
2354
|
+
slug: ossIntent.playbookSlug,
|
|
2355
|
+
input: ossIntent.playbookInput || params.input,
|
|
2356
|
+
});
|
|
2357
|
+
const humanMessage = `Executed Saga playbook '${ran.playbook.name}' (${ran.playbook.slug}) as workflow ${ran.workflow.id} (${ran.workflow.steps.length} steps completed, ${ran.workflow.compensations?.length || 0} compensations registered).`;
|
|
2358
|
+
const synthResolution = makeControlPlaneResolution(`playbook.${ran.playbook.slug}`, rawPrompt, humanMessage, ossIntent.playbookInput || {});
|
|
2359
|
+
return {
|
|
2360
|
+
ok: true,
|
|
2361
|
+
executed: true,
|
|
2362
|
+
status: "playbook_executed",
|
|
2363
|
+
intent: synthResolution,
|
|
2364
|
+
resolution: synthResolution,
|
|
2365
|
+
playbook: ran.playbook,
|
|
2366
|
+
workflow: ran.workflow,
|
|
2367
|
+
humanMessage,
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
if (ossIntent.kind === "rollback_workflow") {
|
|
2371
|
+
const rolledBack = this.rollbackDurableWorkflow(ctx, ossIntent.workflowId || "latest", { reason: ossIntent.workflowReason });
|
|
2372
|
+
const humanMessage = `Rolled back workflow ${rolledBack.id} (${rolledBack.compensations?.length || 0} LIFO Saga compensations executed). Reason: ${rolledBack.rollbackReason}.`;
|
|
2373
|
+
const synthResolution = makeControlPlaneResolution("workspace.workflow.rollback", rawPrompt, humanMessage, { workflowId: rolledBack.id, reason: rolledBack.rollbackReason });
|
|
2374
|
+
return {
|
|
2375
|
+
ok: true,
|
|
2376
|
+
executed: true,
|
|
2377
|
+
status: "workflow_rolled_back",
|
|
2378
|
+
intent: synthResolution,
|
|
2379
|
+
resolution: synthResolution,
|
|
2380
|
+
workflow: rolledBack,
|
|
2381
|
+
humanMessage,
|
|
2382
|
+
};
|
|
2383
|
+
}
|
|
2384
|
+
if (ossIntent.kind === "signal_workflow") {
|
|
2385
|
+
const signaled = this.signalDurableWorkflow(ctx, ossIntent.workflowId || "latest", {
|
|
2386
|
+
signalName: ossIntent.signalName || "human.approval.granted",
|
|
2387
|
+
payload: ossIntent.signalPayload,
|
|
2388
|
+
});
|
|
2389
|
+
const humanMessage = `Delivered Temporal signal '${ossIntent.signalName || "human.approval.granted"}' to workflow ${signaled.id} (status: ${signaled.status}).`;
|
|
2390
|
+
const synthResolution = makeControlPlaneResolution("workspace.workflow.signal", rawPrompt, humanMessage, {
|
|
2391
|
+
workflowId: signaled.id,
|
|
2392
|
+
signalName: ossIntent.signalName || "human.approval.granted",
|
|
2393
|
+
});
|
|
2394
|
+
return {
|
|
2395
|
+
ok: true,
|
|
2396
|
+
executed: true,
|
|
2397
|
+
status: "workflow_signaled",
|
|
2398
|
+
intent: synthResolution,
|
|
2399
|
+
resolution: synthResolution,
|
|
2400
|
+
workflow: signaled,
|
|
2401
|
+
humanMessage,
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
2404
|
+
if (ossIntent.kind === "workflow_history") {
|
|
2405
|
+
const wf = this.getDurableWorkflow(ctx, ossIntent.workflowId || "latest");
|
|
2406
|
+
const workflowHistory = exportTemporalEventHistory(wf);
|
|
2407
|
+
const humanMessage = `Temporal EventHistory for workflow ${wf.id} (status=${wf.status}, ${workflowHistory.events.length} events).`;
|
|
2408
|
+
const synthResolution = makeControlPlaneResolution("workspace.workflow.history", rawPrompt, humanMessage, { workflowId: wf.id });
|
|
2409
|
+
return {
|
|
2410
|
+
ok: true,
|
|
2411
|
+
executed: true,
|
|
2412
|
+
status: "workflow_history",
|
|
2413
|
+
intent: synthResolution,
|
|
2414
|
+
resolution: synthResolution,
|
|
2415
|
+
workflow: wf,
|
|
2416
|
+
workflowHistory,
|
|
2417
|
+
humanMessage,
|
|
2418
|
+
};
|
|
2419
|
+
}
|
|
2420
|
+
if (ossIntent.kind === "cedar_compile") {
|
|
2421
|
+
const cedarBundle = this.getPolicyAsCodeBundle(ctx);
|
|
2422
|
+
const synthResolution = makeControlPlaneResolution("workspace.governance.cedar_compile", rawPrompt, cedarBundle.explanation.preferred);
|
|
2423
|
+
return {
|
|
2424
|
+
ok: true,
|
|
2425
|
+
executed: true,
|
|
2426
|
+
status: "cedar_compiled",
|
|
2427
|
+
intent: synthResolution,
|
|
2428
|
+
resolution: synthResolution,
|
|
2429
|
+
cedarBundle,
|
|
2430
|
+
explanation: cedarBundle.explanation,
|
|
2431
|
+
humanMessage: cedarBundle.explanation.preferred,
|
|
2432
|
+
};
|
|
2433
|
+
}
|
|
2434
|
+
if (ossIntent.kind === "cedar_evaluate") {
|
|
2435
|
+
const cedarEvaluation = await this.evaluatePolicyAsCode(ctx, {
|
|
2436
|
+
toolSlug: ossIntent.toolSlug || "resource.turso.database",
|
|
2437
|
+
input: ossIntent.evaluationInput || params.input || {},
|
|
2438
|
+
});
|
|
2439
|
+
const humanMessage = `Cedar 4.0 & OPA Rego evaluation for '${cedarEvaluation.toolSlug}': ${cedarEvaluation.decision} (${cedarEvaluation.remediationForLlm}).`;
|
|
2440
|
+
const synthResolution = makeControlPlaneResolution("workspace.governance.cedar_evaluate", rawPrompt, humanMessage, {
|
|
2441
|
+
toolSlug: cedarEvaluation.toolSlug,
|
|
2442
|
+
decision: cedarEvaluation.decision,
|
|
2443
|
+
});
|
|
2444
|
+
return {
|
|
2445
|
+
ok: true,
|
|
2446
|
+
executed: true,
|
|
2447
|
+
status: "cedar_evaluated",
|
|
2448
|
+
intent: synthResolution,
|
|
2449
|
+
resolution: synthResolution,
|
|
2450
|
+
cedarEvaluation,
|
|
2451
|
+
humanMessage,
|
|
2452
|
+
};
|
|
2453
|
+
}
|
|
2454
|
+
if (ossIntent.kind === "otel_traces") {
|
|
2455
|
+
const otelTraces = this.exportOtelTraces(ctx, ossIntent.limit || 25);
|
|
2456
|
+
const humanMessage = `Exported ${otelTraces.spansCount} OpenTelemetry GenAI 1.29.0 / MCP 2026-07-28 span(s) and ${otelTraces.langfuseBatch.length} Langfuse trace event(s) (traceparent: ${otelTraces.w3cTraceParent}).`;
|
|
2457
|
+
const synthResolution = makeControlPlaneResolution("workspace.telemetry.otlp", rawPrompt, humanMessage);
|
|
2458
|
+
return {
|
|
2459
|
+
ok: true,
|
|
2460
|
+
executed: true,
|
|
2461
|
+
status: "otel_exported",
|
|
2462
|
+
intent: synthResolution,
|
|
2463
|
+
resolution: synthResolution,
|
|
2464
|
+
otelTraces,
|
|
2465
|
+
humanMessage,
|
|
2466
|
+
};
|
|
2467
|
+
}
|
|
2468
|
+
if (ossIntent.kind === "roi_analytics") {
|
|
2469
|
+
const roiReport = this.getCommercialRoiReport(ctx);
|
|
2470
|
+
const synthResolution = makeControlPlaneResolution("workspace.analytics.roi", rawPrompt, roiReport.explanation.preferred);
|
|
2471
|
+
return {
|
|
2472
|
+
ok: true,
|
|
2473
|
+
executed: true,
|
|
2474
|
+
status: "roi_analyzed",
|
|
2475
|
+
intent: synthResolution,
|
|
2476
|
+
resolution: synthResolution,
|
|
2477
|
+
roiReport,
|
|
2478
|
+
explanation: roiReport.explanation,
|
|
2479
|
+
humanMessage: roiReport.explanation.preferred,
|
|
2480
|
+
};
|
|
2481
|
+
}
|
|
2482
|
+
if (ossIntent.kind === "configure_harness") {
|
|
2483
|
+
const harnessConfig = await this.configureHarness(ctx, {
|
|
2484
|
+
preset: ossIntent.preset?.slug,
|
|
2485
|
+
harness: ossIntent.targetHarness,
|
|
2486
|
+
prompt: ossIntent.extraGuardrailPrompt || undefined,
|
|
2487
|
+
});
|
|
2488
|
+
const synthResolution = makeControlPlaneResolution("workspace.harness.configure", rawPrompt, harnessConfig.humanMessage, {
|
|
2489
|
+
preset: harnessConfig.appliedPreset?.slug || "custom",
|
|
2490
|
+
harness: harnessConfig.targetHarness,
|
|
2491
|
+
});
|
|
2492
|
+
return {
|
|
2493
|
+
ok: true,
|
|
2494
|
+
executed: true,
|
|
2495
|
+
status: "harness_configured",
|
|
2496
|
+
intent: synthResolution,
|
|
2497
|
+
resolution: synthResolution,
|
|
2498
|
+
harnessConfig,
|
|
2499
|
+
explanation: harnessConfig.explanation,
|
|
2500
|
+
humanMessage: harnessConfig.humanMessage,
|
|
2501
|
+
};
|
|
2502
|
+
}
|
|
2503
|
+
if (ossIntent.kind === "memory_graph") {
|
|
2504
|
+
const memoryGraph = await this.getMemoryGraph(ctx, {
|
|
2505
|
+
asOf: ossIntent.asOf || null,
|
|
2506
|
+
focalEntity: ossIntent.focalEntity || null,
|
|
2507
|
+
maxHops: ossIntent.maxHops,
|
|
2508
|
+
});
|
|
2509
|
+
const synthResolution = makeControlPlaneResolution("workspace.memory.graph", rawPrompt, memoryGraph.explanation.preferred, {
|
|
2510
|
+
asOf: ossIntent.asOf || null,
|
|
2511
|
+
focalEntity: ossIntent.focalEntity || null,
|
|
2512
|
+
maxHops: ossIntent.maxHops,
|
|
2513
|
+
});
|
|
2514
|
+
return {
|
|
2515
|
+
ok: true,
|
|
2516
|
+
executed: true,
|
|
2517
|
+
status: "memory_graph",
|
|
2518
|
+
intent: synthResolution,
|
|
2519
|
+
resolution: synthResolution,
|
|
2520
|
+
memoryGraph,
|
|
2521
|
+
explanation: memoryGraph.explanation,
|
|
2522
|
+
humanMessage: memoryGraph.explanation.preferred,
|
|
2523
|
+
};
|
|
2524
|
+
}
|
|
2139
2525
|
}
|
|
2140
2526
|
// 2c. Check if the user is asking what Muxo remembers ("What do you remember?", "Show my saved memories", "What are our default settings in memory?")
|
|
2141
2527
|
if (/^(?:what\s+do\s+you\s+remember|what\s+(?:are|is)\s+(?:my|our)\s+(?:saved\s+)?(?:memories|memory|defaults|preferences)|show\s+(?:my|our)\s+(?:saved\s+)?(?:memories|memory|defaults)|recall\s+(?:my|our|workspace)\s+memories|list\s+(?:my|our|workspace)\s+memories)\b/i.test(cleanedPrompt)) {
|
|
@@ -2482,9 +2868,18 @@ export class MuxoEngine {
|
|
|
2482
2868
|
return Array.from(this.durableWorkflows.values()).filter((w) => w.workspaceId === workspaceId);
|
|
2483
2869
|
}
|
|
2484
2870
|
getDurableWorkflow(ctx, workflowId) {
|
|
2485
|
-
const
|
|
2871
|
+
const requested = String(workflowId || "").trim();
|
|
2872
|
+
if (requested.toLowerCase() === "latest" || requested.toLowerCase() === "last") {
|
|
2873
|
+
const list = this.listDurableWorkflows(ctx.workspace.id);
|
|
2874
|
+
const latest = list[list.length - 1];
|
|
2875
|
+
if (!latest) {
|
|
2876
|
+
throw workflowNotFoundError("latest");
|
|
2877
|
+
}
|
|
2878
|
+
return latest;
|
|
2879
|
+
}
|
|
2880
|
+
const wf = this.durableWorkflows.get(requested);
|
|
2486
2881
|
if (!wf || wf.workspaceId !== ctx.workspace.id) {
|
|
2487
|
-
throw workflowNotFoundError(
|
|
2882
|
+
throw workflowNotFoundError(requested);
|
|
2488
2883
|
}
|
|
2489
2884
|
return wf;
|
|
2490
2885
|
}
|
|
@@ -2552,16 +2947,41 @@ export class MuxoEngine {
|
|
|
2552
2947
|
});
|
|
2553
2948
|
}
|
|
2554
2949
|
/**
|
|
2555
|
-
* Turnkey Commercial Business Saga Playbooks.
|
|
2950
|
+
* Turnkey & Custom Commercial Business Saga Playbooks.
|
|
2556
2951
|
*/
|
|
2557
|
-
listCommercialPlaybooks() {
|
|
2558
|
-
|
|
2952
|
+
listCommercialPlaybooks(ctx) {
|
|
2953
|
+
const custom = ctx ? this.customPlaybooks.get(ctx.workspace.id) || [] : [];
|
|
2954
|
+
return [...custom, ...MUXO_COMMERCIAL_PLAYBOOKS];
|
|
2955
|
+
}
|
|
2956
|
+
createCustomPlaybook(ctx, params) {
|
|
2957
|
+
const ws = this.store.getWorkspace(ctx.workspace.id);
|
|
2958
|
+
const pb = parseNaturalLanguageCustomPlaybook(params.prompt || String(params.input?.prompt || params.input?.name || ""), params.input);
|
|
2959
|
+
const existing = (this.customPlaybooks.get(ws.id) || []).filter((item) => item.slug !== pb.slug);
|
|
2960
|
+
const updatedList = [pb, ...existing];
|
|
2961
|
+
this.customPlaybooks.set(ws.id, updatedList);
|
|
2962
|
+
this.store.upsertTemporalFact({
|
|
2963
|
+
workspaceId: ws.id,
|
|
2964
|
+
subject: `workspace:${ws.slug}`,
|
|
2965
|
+
predicate: "REGISTERED_CUSTOM_PLAYBOOK",
|
|
2966
|
+
object: `playbook:${pb.slug}`,
|
|
2967
|
+
summary: `Registered custom ${pb.steps.length}-step Saga playbook '${pb.name}' (${pb.slug})`,
|
|
2968
|
+
confidence: 0.99,
|
|
2969
|
+
sourceKind: "preference",
|
|
2970
|
+
sourceReferenceId: `pb_${pb.slug}`,
|
|
2971
|
+
});
|
|
2972
|
+
return {
|
|
2973
|
+
ok: true,
|
|
2974
|
+
playbook: pb,
|
|
2975
|
+
playbooks: this.listCommercialPlaybooks(ctx),
|
|
2976
|
+
humanMessage: `Created custom ${pb.steps.length}-step Saga playbook '${pb.slug}' (${pb.steps.map((s) => s.toolSlug).join(" → ")}).`,
|
|
2977
|
+
};
|
|
2559
2978
|
}
|
|
2560
2979
|
runCommercialPlaybook(ctx, params) {
|
|
2561
2980
|
const ws = this.store.getWorkspace(ctx.workspace.id);
|
|
2562
|
-
const
|
|
2981
|
+
const custom = this.customPlaybooks.get(ws.id) || [];
|
|
2982
|
+
const playbook = getCommercialPlaybook(params.slug, custom);
|
|
2563
2983
|
if (!playbook) {
|
|
2564
|
-
const err = new Error(`Unknown commercial playbook '${params.slug}'. Available playbooks: ${MUXO_COMMERCIAL_PLAYBOOKS.map((p) => p.slug).join(", ")}`);
|
|
2984
|
+
const err = new Error(`Unknown commercial playbook '${params.slug}'. Available playbooks: ${[...custom, ...MUXO_COMMERCIAL_PLAYBOOKS].map((p) => p.slug).join(", ")}`);
|
|
2565
2985
|
err.statusCode = 404;
|
|
2566
2986
|
err.code = "PLAYBOOK_NOT_FOUND";
|
|
2567
2987
|
throw err;
|
|
@@ -2590,8 +3010,42 @@ export class MuxoEngine {
|
|
|
2590
3010
|
playbook: executed.playbook,
|
|
2591
3011
|
workflow: executed.workflow,
|
|
2592
3012
|
temporalFact: savedFact,
|
|
3013
|
+
usableResult: executed.usableResult,
|
|
2593
3014
|
};
|
|
2594
3015
|
}
|
|
3016
|
+
/**
|
|
3017
|
+
* Turnkey Harness Preset & One-Shot Agent Configurator.
|
|
3018
|
+
*/
|
|
3019
|
+
async configureHarness(ctx, params) {
|
|
3020
|
+
let ws = this.store.getWorkspace(ctx.workspace.id);
|
|
3021
|
+
const matchedPreset = resolveHarnessPreset(params?.preset || params?.prompt || null);
|
|
3022
|
+
if (matchedPreset) {
|
|
3023
|
+
ws = this.store.updateWorkspacePolicy(ws.id, matchedPreset.policyPatch);
|
|
3024
|
+
this.store.upsertTemporalFact({
|
|
3025
|
+
workspaceId: ws.id,
|
|
3026
|
+
subject: `workspace:${ws.slug}`,
|
|
3027
|
+
predicate: "CONFIGURED_HARNESS_PRESET",
|
|
3028
|
+
object: `preset:${matchedPreset.slug}`,
|
|
3029
|
+
summary: `Applied harness preset '${matchedPreset.name}' (${matchedPreset.slug})`,
|
|
3030
|
+
confidence: 1.0,
|
|
3031
|
+
sourceKind: "policy_decision",
|
|
3032
|
+
sourceReferenceId: `preset_${matchedPreset.slug}`,
|
|
3033
|
+
});
|
|
3034
|
+
}
|
|
3035
|
+
if (params?.prompt) {
|
|
3036
|
+
const guardrailCheck = parseNaturalLanguageGuardrail(params.prompt, ws.policy);
|
|
3037
|
+
if (guardrailCheck.isGuardrail) {
|
|
3038
|
+
const applied = await this.applyNaturalLanguageGuardrail(ctx, params.prompt);
|
|
3039
|
+
ws = applied.workspace;
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
return buildHarnessConfigurationBundle({
|
|
3043
|
+
workspace: ws,
|
|
3044
|
+
baseUrl: this.config.baseUrl,
|
|
3045
|
+
targetHarness: params?.harness || "all",
|
|
3046
|
+
appliedPreset: matchedPreset,
|
|
3047
|
+
});
|
|
3048
|
+
}
|
|
2595
3049
|
/**
|
|
2596
3050
|
* FinOps & Commercial ROI Unit-Economics Analytics.
|
|
2597
3051
|
*/
|