xytara 1.0.0
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/.env.example +3 -0
- package/LICENSE +201 -0
- package/README.md +257 -0
- package/adapters/AUTHORING_GUIDE.md +89 -0
- package/adapters/ONBOARDING_POSTURE.md +39 -0
- package/adapters/adapter-manifest.schema.json +209 -0
- package/adapters/examples/example-execution-adapter.js +61 -0
- package/adapters/examples/example-execution-adapter.manifest.json +62 -0
- package/adapters/examples/example-settlement-adapter.js +55 -0
- package/adapters/examples/example-settlement-adapter.manifest.json +59 -0
- package/adapters/interfaces.js +56 -0
- package/client.js +3 -0
- package/fixtures/catalog.js +728 -0
- package/index.js +25 -0
- package/lib/catalog_contract.js +141 -0
- package/lib/catalog_views.js +36 -0
- package/lib/command_flow.js +42 -0
- package/lib/commerce_artifacts.js +294 -0
- package/lib/commerce_cases.js +303 -0
- package/lib/commerce_client.js +5373 -0
- package/lib/commerce_quotes.js +113 -0
- package/lib/commerce_reports.js +14315 -0
- package/lib/commerce_runtime.js +215 -0
- package/lib/http_transport.js +40 -0
- package/lib/record_queries.js +47 -0
- package/lib/resource_views.js +31 -0
- package/lib/route_matchers.js +34 -0
- package/lib/route_params.js +19 -0
- package/package.json +55 -0
- package/server.js +626 -0
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { CommerceClient } = require("./lib/commerce_client");
|
|
4
|
+
const {
|
|
5
|
+
ADAPTER_INTERFACE_VERSION,
|
|
6
|
+
validateAdapterImplementation
|
|
7
|
+
} = require("./adapters/interfaces");
|
|
8
|
+
|
|
9
|
+
const COMMERCE_SDK_NAME = "xytara";
|
|
10
|
+
const COMMERCE_SDK_VERSION = "1.0.0";
|
|
11
|
+
const COMMERCE_API_VERSION = "v1";
|
|
12
|
+
|
|
13
|
+
function createClient(options) {
|
|
14
|
+
return new CommerceClient(options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
COMMERCE_SDK_NAME,
|
|
19
|
+
COMMERCE_SDK_VERSION,
|
|
20
|
+
COMMERCE_API_VERSION,
|
|
21
|
+
ADAPTER_INTERFACE_VERSION,
|
|
22
|
+
CommerceClient,
|
|
23
|
+
createClient,
|
|
24
|
+
validateAdapterImplementation
|
|
25
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { catalog, findTask, findWorkflow } = require("../fixtures/catalog");
|
|
4
|
+
|
|
5
|
+
function buildCatalogResponse() {
|
|
6
|
+
return {
|
|
7
|
+
ok: true,
|
|
8
|
+
brand: "xytara",
|
|
9
|
+
product: "governed transaction rail",
|
|
10
|
+
version: catalog.version,
|
|
11
|
+
catalog_version: catalog.version,
|
|
12
|
+
currency: catalog.currency,
|
|
13
|
+
payment_scheme: catalog.payment_scheme,
|
|
14
|
+
plans: catalog.plans,
|
|
15
|
+
capabilities: catalog.capabilities,
|
|
16
|
+
adapters: catalog.adapters,
|
|
17
|
+
settlement_profiles: catalog.settlement_profiles,
|
|
18
|
+
task_categories: catalog.task_categories,
|
|
19
|
+
workflows: catalog.workflows,
|
|
20
|
+
surfaces: catalog.surfaces,
|
|
21
|
+
tasks: catalog.tasks
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function summarizeCatalog() {
|
|
26
|
+
const fullCatalog = buildCatalogResponse();
|
|
27
|
+
return {
|
|
28
|
+
ok: true,
|
|
29
|
+
brand: fullCatalog.brand,
|
|
30
|
+
product: fullCatalog.product,
|
|
31
|
+
version: fullCatalog.catalog_version,
|
|
32
|
+
currency: fullCatalog.currency,
|
|
33
|
+
payment_scheme: fullCatalog.payment_scheme,
|
|
34
|
+
capabilities: fullCatalog.capabilities,
|
|
35
|
+
adapters: fullCatalog.adapters,
|
|
36
|
+
task_count: fullCatalog.tasks.length,
|
|
37
|
+
workflow_count: fullCatalog.workflows.length,
|
|
38
|
+
category_count: fullCatalog.task_categories.length,
|
|
39
|
+
task_categories: fullCatalog.task_categories,
|
|
40
|
+
settlement_profile_count: fullCatalog.settlement_profiles.length,
|
|
41
|
+
settlement_profiles: fullCatalog.settlement_profiles,
|
|
42
|
+
workflows: fullCatalog.workflows,
|
|
43
|
+
tasks: fullCatalog.tasks.map((task) => ({
|
|
44
|
+
task_ref: task.public_task_ref,
|
|
45
|
+
internal_task_ref: task.task_ref,
|
|
46
|
+
public_task_ref: task.public_task_ref,
|
|
47
|
+
aliases: task.public_aliases,
|
|
48
|
+
category: task.public_category,
|
|
49
|
+
title: task.public_title,
|
|
50
|
+
execution_mode: task.execution_mode,
|
|
51
|
+
pricing_band: task.pricing_band,
|
|
52
|
+
public_launch_price: task.public_launch_price,
|
|
53
|
+
pricing_note: task.pricing_note,
|
|
54
|
+
latency_class: task.latency_class,
|
|
55
|
+
failure_posture: task.failure_posture,
|
|
56
|
+
capabilities: task.capabilities,
|
|
57
|
+
adapters: task.adapters
|
|
58
|
+
})),
|
|
59
|
+
workflow_summaries: fullCatalog.workflows.map((workflow) => ({
|
|
60
|
+
workflow_ref: workflow.workflow_ref,
|
|
61
|
+
aliases: workflow.aliases,
|
|
62
|
+
category: workflow.category,
|
|
63
|
+
title: workflow.title,
|
|
64
|
+
task_count: workflow.task_count,
|
|
65
|
+
latency_class: workflow.latency_class,
|
|
66
|
+
failure_posture: workflow.failure_posture,
|
|
67
|
+
pricing_basis: workflow.pricing_basis
|
|
68
|
+
}))
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getCatalog() {
|
|
73
|
+
return buildCatalogResponse();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getTaskDetail(ref) {
|
|
77
|
+
const task = findTask(ref);
|
|
78
|
+
if (!task) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
task_ref: task.task_ref,
|
|
83
|
+
public_task_ref: task.public_task_ref,
|
|
84
|
+
aliases: task.public_aliases,
|
|
85
|
+
category: task.public_category,
|
|
86
|
+
title: task.public_title,
|
|
87
|
+
execution_mode: task.execution_mode,
|
|
88
|
+
pricing_band: task.pricing_band,
|
|
89
|
+
public_launch_price: task.public_launch_price,
|
|
90
|
+
pricing_note: task.pricing_note,
|
|
91
|
+
latency_class: task.latency_class,
|
|
92
|
+
failure_posture: task.failure_posture,
|
|
93
|
+
input_schema: task.input_schema,
|
|
94
|
+
capabilities: task.capabilities,
|
|
95
|
+
adapters: task.adapters
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function buildWorkflowShape(workflow) {
|
|
100
|
+
const workflowTasks = (Array.isArray(workflow.task_refs) ? workflow.task_refs : [])
|
|
101
|
+
.map((taskRef) => findTask(taskRef))
|
|
102
|
+
.filter(Boolean)
|
|
103
|
+
.map((task) => ({
|
|
104
|
+
public_task_ref: task.public_task_ref,
|
|
105
|
+
task_ref: task.task_ref,
|
|
106
|
+
title: task.public_title,
|
|
107
|
+
category: task.public_category,
|
|
108
|
+
latency_class: task.latency_class,
|
|
109
|
+
failure_posture: task.failure_posture,
|
|
110
|
+
pricing_band: task.pricing_band,
|
|
111
|
+
public_launch_price: task.public_launch_price
|
|
112
|
+
}));
|
|
113
|
+
return {
|
|
114
|
+
...workflow,
|
|
115
|
+
pricing_note: "Workflow pricing is determined by the quoted task set, not a fixed bundle price.",
|
|
116
|
+
task_refs: workflowTasks.map((task) => task.public_task_ref || task.task_ref),
|
|
117
|
+
task_count: workflowTasks.length,
|
|
118
|
+
tasks: workflowTasks
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function getWorkflowList() {
|
|
123
|
+
return catalog.workflows.map(buildWorkflowShape);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function getWorkflowDetail(ref) {
|
|
127
|
+
const workflow = findWorkflow(ref);
|
|
128
|
+
if (!workflow) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return buildWorkflowShape(workflow);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = {
|
|
135
|
+
buildCatalogResponse,
|
|
136
|
+
getCatalog,
|
|
137
|
+
getTaskDetail,
|
|
138
|
+
getWorkflowDetail,
|
|
139
|
+
getWorkflowList,
|
|
140
|
+
summarizeCatalog
|
|
141
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { buildMissingResponse } = require("./resource_views");
|
|
4
|
+
|
|
5
|
+
function buildTaskDetailResponse(task) {
|
|
6
|
+
if (!task) {
|
|
7
|
+
return buildMissingResponse("task_not_found");
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
status: 200,
|
|
11
|
+
payload: { ok: true, task }
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function buildWorkflowListResponse(workflows) {
|
|
16
|
+
return {
|
|
17
|
+
status: 200,
|
|
18
|
+
payload: { ok: true, workflows }
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function buildWorkflowDetailResponse(workflow) {
|
|
23
|
+
if (!workflow) {
|
|
24
|
+
return buildMissingResponse("workflow_not_found");
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
status: 200,
|
|
28
|
+
payload: { ok: true, workflow }
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
buildTaskDetailResponse,
|
|
34
|
+
buildWorkflowDetailResponse,
|
|
35
|
+
buildWorkflowListResponse
|
|
36
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
createCommandResult,
|
|
5
|
+
createQuote,
|
|
6
|
+
hydrateQuoteStates
|
|
7
|
+
} = require("./commerce_runtime");
|
|
8
|
+
|
|
9
|
+
function executeCommandRequest(state, payload, headers) {
|
|
10
|
+
hydrateQuoteStates(state);
|
|
11
|
+
if (!headers["x-wallet-id"] || !headers["x-payment"] || !headers["x-payment-signature"]) {
|
|
12
|
+
const quote = createQuote(state, payload);
|
|
13
|
+
return {
|
|
14
|
+
status: 402,
|
|
15
|
+
payload: { ok: false, quote }
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const quote = payload.quote_id && state.quotes.get(payload.quote_id)
|
|
20
|
+
? state.quotes.get(payload.quote_id)
|
|
21
|
+
: createQuote(state, payload);
|
|
22
|
+
|
|
23
|
+
if (quote && quote.status === "expired") {
|
|
24
|
+
return {
|
|
25
|
+
status: 409,
|
|
26
|
+
payload: {
|
|
27
|
+
ok: false,
|
|
28
|
+
reason: "quote_expired",
|
|
29
|
+
quote
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
status: 200,
|
|
36
|
+
payload: createCommandResult(state, payload, quote)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
executeCommandRequest
|
|
42
|
+
};
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const crypto = require("crypto");
|
|
4
|
+
const { findTask } = require("../fixtures/catalog");
|
|
5
|
+
|
|
6
|
+
function classifyObservedLatency(durationMs) {
|
|
7
|
+
if (durationMs <= 1000) return "instant";
|
|
8
|
+
if (durationMs <= 15000) return "near_real_time";
|
|
9
|
+
return "governed_async";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function assessLatency(declaredLatencyClass, observedLatencyClass) {
|
|
13
|
+
const order = {
|
|
14
|
+
instant: 1,
|
|
15
|
+
near_real_time: 2,
|
|
16
|
+
governed_async: 3
|
|
17
|
+
};
|
|
18
|
+
const declared = order[declaredLatencyClass] || 99;
|
|
19
|
+
const observed = order[observedLatencyClass] || 99;
|
|
20
|
+
return observed <= declared ? "within_posture" : "outside_posture";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function createCommandArtifacts(payload, quote, options) {
|
|
24
|
+
const opts = options || {};
|
|
25
|
+
const transactionId = `txn_${crypto.randomBytes(6).toString("hex")}`;
|
|
26
|
+
const receiptId = `rcpt_${crypto.randomBytes(6).toString("hex")}`;
|
|
27
|
+
const startedAt = new Date();
|
|
28
|
+
const durationMs = 250;
|
|
29
|
+
const completedAt = new Date(startedAt.getTime() + durationMs);
|
|
30
|
+
const requestedTasks = Array.isArray(payload.tasks) && payload.tasks.length > 0
|
|
31
|
+
? payload.tasks.map((task, index) => ({
|
|
32
|
+
task_id: task && task.task_id ? String(task.task_id).trim() : `task_${index + 1}`,
|
|
33
|
+
task_ref: task && task.task_ref ? String(task.task_ref).trim() : ""
|
|
34
|
+
}))
|
|
35
|
+
: [{
|
|
36
|
+
task_id: "task_1",
|
|
37
|
+
task_ref: String(payload.task_ref || "").trim()
|
|
38
|
+
}];
|
|
39
|
+
const resolvedTasks = requestedTasks
|
|
40
|
+
.map((task) => {
|
|
41
|
+
const catalogTask = findTask(task.task_ref);
|
|
42
|
+
return catalogTask ? { ...task, catalogTask } : null;
|
|
43
|
+
})
|
|
44
|
+
.filter(Boolean);
|
|
45
|
+
const primaryTask = resolvedTasks[0] && resolvedTasks[0].catalogTask ? resolvedTasks[0].catalogTask : null;
|
|
46
|
+
const declaredLatencyClass = (primaryTask && primaryTask.latency_class) || "near_real_time";
|
|
47
|
+
const observedLatencyClass = classifyObservedLatency(durationMs);
|
|
48
|
+
const deferredCompletion = opts.deferredCompletion === true;
|
|
49
|
+
const timing = {
|
|
50
|
+
declared_latency_class: declaredLatencyClass,
|
|
51
|
+
started_at_iso: startedAt.toISOString(),
|
|
52
|
+
completed_at_iso: deferredCompletion ? null : completedAt.toISOString(),
|
|
53
|
+
duration_ms: deferredCompletion ? null : durationMs,
|
|
54
|
+
observed_latency_class: deferredCompletion ? null : observedLatencyClass,
|
|
55
|
+
assessment: deferredCompletion ? "pending" : assessLatency(declaredLatencyClass, observedLatencyClass)
|
|
56
|
+
};
|
|
57
|
+
const resultTasks = resolvedTasks.length > 0 ? resolvedTasks : requestedTasks.map((task) => ({
|
|
58
|
+
...task,
|
|
59
|
+
catalogTask: null
|
|
60
|
+
}));
|
|
61
|
+
const normalizedBody = payload && payload.body && typeof payload.body === "object" && !Array.isArray(payload.body)
|
|
62
|
+
? payload.body
|
|
63
|
+
: {};
|
|
64
|
+
const resultsByTaskId = Object.fromEntries(resultTasks.map((task, index) => [
|
|
65
|
+
task.task_id,
|
|
66
|
+
(() => {
|
|
67
|
+
const base = {
|
|
68
|
+
task_ref: task.task_ref,
|
|
69
|
+
status: "completed",
|
|
70
|
+
output_ref: `output_${transactionId}_${index + 1}`
|
|
71
|
+
};
|
|
72
|
+
if (task.task_ref === "admission.preview") {
|
|
73
|
+
base.preview_kind = "admission";
|
|
74
|
+
base.admission_ref = `admission_${transactionId}_${index + 1}`;
|
|
75
|
+
}
|
|
76
|
+
if (task.task_ref === "trust.handoff.emit") {
|
|
77
|
+
base.handoff_kind = "trust";
|
|
78
|
+
base.handoff_action = "emit";
|
|
79
|
+
base.handoff_ref = `trust_handoff_${transactionId}_${index + 1}`;
|
|
80
|
+
}
|
|
81
|
+
if (task.task_ref === "trust.handoff.validate") {
|
|
82
|
+
base.handoff_kind = "trust";
|
|
83
|
+
base.handoff_action = "validate";
|
|
84
|
+
base.handoff_ref = `trust_handoff_${transactionId}_${index + 1}`;
|
|
85
|
+
}
|
|
86
|
+
if (task.task_ref === "execution_receipt.handoff.emit") {
|
|
87
|
+
base.handoff_kind = "execution_receipt";
|
|
88
|
+
base.handoff_action = "emit";
|
|
89
|
+
base.handoff_ref = `execution_receipt_handoff_${transactionId}_${index + 1}`;
|
|
90
|
+
}
|
|
91
|
+
if (task.task_ref === "execution_receipt.handoff.validate") {
|
|
92
|
+
base.handoff_kind = "execution_receipt";
|
|
93
|
+
base.handoff_action = "validate";
|
|
94
|
+
base.handoff_ref = `execution_receipt_handoff_${transactionId}_${index + 1}`;
|
|
95
|
+
}
|
|
96
|
+
if (task.task_ref === "receipt_ledger.handoff.emit") {
|
|
97
|
+
base.handoff_kind = "receipt_ledger";
|
|
98
|
+
base.handoff_action = "emit";
|
|
99
|
+
base.handoff_ref = `receipt_ledger_handoff_${transactionId}_${index + 1}`;
|
|
100
|
+
}
|
|
101
|
+
if (task.task_ref === "receipt_ledger.handoff.validate") {
|
|
102
|
+
base.handoff_kind = "receipt_ledger";
|
|
103
|
+
base.handoff_action = "validate";
|
|
104
|
+
base.handoff_ref = `receipt_ledger_handoff_${transactionId}_${index + 1}`;
|
|
105
|
+
}
|
|
106
|
+
if (task.task_ref === "runtime.emit") {
|
|
107
|
+
base.runtime_ref = `runtime_event_${transactionId}_${index + 1}`;
|
|
108
|
+
base.runtime_action = "emit";
|
|
109
|
+
}
|
|
110
|
+
if (task.task_ref === "runtime.anchor") {
|
|
111
|
+
base.anchor_ref = `anchor_${transactionId}_${index + 1}`;
|
|
112
|
+
base.runtime_action = "anchor";
|
|
113
|
+
}
|
|
114
|
+
if (task.task_ref === "runtime.emit_anchor") {
|
|
115
|
+
base.runtime_ref = `runtime_event_${transactionId}_${index + 1}`;
|
|
116
|
+
base.anchor_ref = `anchor_${transactionId}_${index + 1}`;
|
|
117
|
+
base.runtime_action = "emit_anchor";
|
|
118
|
+
}
|
|
119
|
+
if (task.task_ref === "registry.register") {
|
|
120
|
+
base.registry_record_ref = `registry_${transactionId}_${index + 1}`;
|
|
121
|
+
}
|
|
122
|
+
if (task.task_ref === "anchoring.submit") {
|
|
123
|
+
base.anchor_ref = `anchor_${transactionId}_${index + 1}`;
|
|
124
|
+
}
|
|
125
|
+
if (task.task_ref === "adapter.mcp.invoke") {
|
|
126
|
+
base.adapter_lane = "mcp";
|
|
127
|
+
base.tool_name = normalizedBody.tool_name || null;
|
|
128
|
+
base.invocation_status = "simulated";
|
|
129
|
+
}
|
|
130
|
+
return base;
|
|
131
|
+
})()
|
|
132
|
+
]));
|
|
133
|
+
const capabilityScopes = Array.from(new Set(resultTasks.flatMap((task) =>
|
|
134
|
+
Array.isArray(task.catalogTask && task.catalogTask.capabilities) ? task.catalogTask.capabilities : []
|
|
135
|
+
)));
|
|
136
|
+
const adaptersUsed = Array.from(new Set(resultTasks.flatMap((task) =>
|
|
137
|
+
Array.isArray(task.catalogTask && task.catalogTask.adapters) ? task.catalogTask.adapters : []
|
|
138
|
+
)));
|
|
139
|
+
const remediation = {
|
|
140
|
+
status: "none",
|
|
141
|
+
reason_code: null,
|
|
142
|
+
active_case_type: null,
|
|
143
|
+
active_case_id: null,
|
|
144
|
+
compensating_action_status: null,
|
|
145
|
+
updated_at_iso: completedAt.toISOString()
|
|
146
|
+
};
|
|
147
|
+
const transaction = {
|
|
148
|
+
transaction_id: transactionId,
|
|
149
|
+
account_id: quote.account_id,
|
|
150
|
+
status: deferredCompletion ? "accepted" : "completed",
|
|
151
|
+
intent: payload.command || "command.execute",
|
|
152
|
+
amount_minor: quote.amount_minor,
|
|
153
|
+
currency: quote.currency,
|
|
154
|
+
quote_id: quote.quote_id,
|
|
155
|
+
output_ref: `output_${transactionId}`,
|
|
156
|
+
callback_url: payload.callback_url || null,
|
|
157
|
+
capabilities: quote.capabilities,
|
|
158
|
+
adapters: quote.adapters,
|
|
159
|
+
execution: {
|
|
160
|
+
status: deferredCompletion ? "accepted" : "completed",
|
|
161
|
+
task_count: resultTasks.length,
|
|
162
|
+
capability_scopes: capabilityScopes,
|
|
163
|
+
adapters_used: adaptersUsed,
|
|
164
|
+
results_by_task_id: resultsByTaskId
|
|
165
|
+
},
|
|
166
|
+
created_at_iso: startedAt.toISOString(),
|
|
167
|
+
completed_at_iso: deferredCompletion ? null : completedAt.toISOString(),
|
|
168
|
+
timing,
|
|
169
|
+
remediation
|
|
170
|
+
};
|
|
171
|
+
const receipt = {
|
|
172
|
+
receipt_id: receiptId,
|
|
173
|
+
transaction_id: transactionId,
|
|
174
|
+
account_id: quote.account_id,
|
|
175
|
+
status: deferredCompletion ? "pending" : "completed",
|
|
176
|
+
amount_minor: quote.amount_minor,
|
|
177
|
+
currency: quote.currency,
|
|
178
|
+
quote_id: quote.quote_id,
|
|
179
|
+
proof_ref: `proof_${receiptId}`,
|
|
180
|
+
execution_summary: {
|
|
181
|
+
command: payload.command || "command.execute",
|
|
182
|
+
task_count: resultTasks.length,
|
|
183
|
+
tasks: resultTasks.map((task) => ({
|
|
184
|
+
task_id: task.task_id,
|
|
185
|
+
task_ref: task.task_ref
|
|
186
|
+
}))
|
|
187
|
+
},
|
|
188
|
+
created_at_iso: deferredCompletion ? startedAt.toISOString() : completedAt.toISOString(),
|
|
189
|
+
timing,
|
|
190
|
+
remediation
|
|
191
|
+
};
|
|
192
|
+
const command = {
|
|
193
|
+
command: payload.command || "command.execute",
|
|
194
|
+
deliverables: resultTasks.map((task, index) => ({
|
|
195
|
+
kind: task.task_ref === "admission.preview" ? "preview" : "result",
|
|
196
|
+
task_id: task.task_id,
|
|
197
|
+
task_ref: task.task_ref,
|
|
198
|
+
ref: `deliverable_${transactionId}_${index + 1}`,
|
|
199
|
+
...(task.task_ref === "admission.preview"
|
|
200
|
+
? {
|
|
201
|
+
admission_ref: `admission_${transactionId}_${index + 1}`
|
|
202
|
+
}
|
|
203
|
+
: {}),
|
|
204
|
+
...(task.task_ref === "trust.handoff.emit"
|
|
205
|
+
? {
|
|
206
|
+
handoff_kind: "trust",
|
|
207
|
+
handoff_action: "emit",
|
|
208
|
+
handoff_ref: `trust_handoff_${transactionId}_${index + 1}`
|
|
209
|
+
}
|
|
210
|
+
: {}),
|
|
211
|
+
...(task.task_ref === "trust.handoff.validate"
|
|
212
|
+
? {
|
|
213
|
+
handoff_kind: "trust",
|
|
214
|
+
handoff_action: "validate",
|
|
215
|
+
handoff_ref: `trust_handoff_${transactionId}_${index + 1}`
|
|
216
|
+
}
|
|
217
|
+
: {}),
|
|
218
|
+
...(task.task_ref === "execution_receipt.handoff.emit"
|
|
219
|
+
? {
|
|
220
|
+
handoff_kind: "execution_receipt",
|
|
221
|
+
handoff_action: "emit",
|
|
222
|
+
handoff_ref: `execution_receipt_handoff_${transactionId}_${index + 1}`
|
|
223
|
+
}
|
|
224
|
+
: {}),
|
|
225
|
+
...(task.task_ref === "execution_receipt.handoff.validate"
|
|
226
|
+
? {
|
|
227
|
+
handoff_kind: "execution_receipt",
|
|
228
|
+
handoff_action: "validate",
|
|
229
|
+
handoff_ref: `execution_receipt_handoff_${transactionId}_${index + 1}`
|
|
230
|
+
}
|
|
231
|
+
: {}),
|
|
232
|
+
...(task.task_ref === "receipt_ledger.handoff.emit"
|
|
233
|
+
? {
|
|
234
|
+
handoff_kind: "receipt_ledger",
|
|
235
|
+
handoff_action: "emit",
|
|
236
|
+
handoff_ref: `receipt_ledger_handoff_${transactionId}_${index + 1}`
|
|
237
|
+
}
|
|
238
|
+
: {}),
|
|
239
|
+
...(task.task_ref === "receipt_ledger.handoff.validate"
|
|
240
|
+
? {
|
|
241
|
+
handoff_kind: "receipt_ledger",
|
|
242
|
+
handoff_action: "validate",
|
|
243
|
+
handoff_ref: `receipt_ledger_handoff_${transactionId}_${index + 1}`
|
|
244
|
+
}
|
|
245
|
+
: {}),
|
|
246
|
+
...(task.task_ref === "runtime.emit"
|
|
247
|
+
? {
|
|
248
|
+
runtime_ref: `runtime_event_${transactionId}_${index + 1}`,
|
|
249
|
+
runtime_action: "emit"
|
|
250
|
+
}
|
|
251
|
+
: {}),
|
|
252
|
+
...(task.task_ref === "runtime.anchor"
|
|
253
|
+
? {
|
|
254
|
+
anchor_ref: `anchor_${transactionId}_${index + 1}`,
|
|
255
|
+
runtime_action: "anchor"
|
|
256
|
+
}
|
|
257
|
+
: {}),
|
|
258
|
+
...(task.task_ref === "runtime.emit_anchor"
|
|
259
|
+
? {
|
|
260
|
+
runtime_ref: `runtime_event_${transactionId}_${index + 1}`,
|
|
261
|
+
anchor_ref: `anchor_${transactionId}_${index + 1}`,
|
|
262
|
+
runtime_action: "emit_anchor"
|
|
263
|
+
}
|
|
264
|
+
: {}),
|
|
265
|
+
...(task.task_ref === "registry.register"
|
|
266
|
+
? {
|
|
267
|
+
registry_record_ref: `registry_${transactionId}_${index + 1}`
|
|
268
|
+
}
|
|
269
|
+
: {}),
|
|
270
|
+
...(task.task_ref === "anchoring.submit"
|
|
271
|
+
? {
|
|
272
|
+
anchor_ref: `anchor_${transactionId}_${index + 1}`
|
|
273
|
+
}
|
|
274
|
+
: {}),
|
|
275
|
+
...(task.task_ref === "adapter.mcp.invoke"
|
|
276
|
+
? {
|
|
277
|
+
adapter_lane: "mcp",
|
|
278
|
+
tool_name: normalizedBody.tool_name || null
|
|
279
|
+
}
|
|
280
|
+
: {})
|
|
281
|
+
})),
|
|
282
|
+
monitor: {
|
|
283
|
+
transaction_id: transactionId,
|
|
284
|
+
status_url: `/v1/governed-transactions/${transactionId}`,
|
|
285
|
+
receipt_url: `/v1/receipts/${receiptId}`,
|
|
286
|
+
delivery_url: `/v1/deliveries/delivery_${transactionId}`
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
return { transaction, receipt, command };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
module.exports = {
|
|
293
|
+
createCommandArtifacts
|
|
294
|
+
};
|