@experiture/xyra-cli 0.6.0 → 0.6.2
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/dist/auth/administrationSession.js +25 -0
- package/dist/auth/administrationSession.js.map +1 -0
- package/dist/auth/oauthClient.js +1 -1
- package/dist/auth/oauthClient.js.map +1 -1
- package/dist/auth/session.js +11 -0
- package/dist/auth/session.js.map +1 -1
- package/dist/chat/runtimeChatClient.js +127 -56
- package/dist/chat/runtimeChatClient.js.map +3 -3
- package/dist/commands/chat.js +3 -1
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/generatedCommandRegistry.js +17 -2
- package/dist/commands/generatedCommandRegistry.js.map +1 -1
- package/dist/commands/login.js +5 -4
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/mcpContext.js +2 -2
- package/dist/commands/mcpContext.js.map +1 -1
- package/dist/commands/session.js +7 -5
- package/dist/commands/session.js.map +1 -1
- package/dist/config/configStore.js +648 -106
- package/dist/config/configStore.js.map +7 -1
- package/dist/config/environments.js.map +1 -1
- package/dist/index.js +26 -22
- package/dist/index.js.map +1 -1
- package/dist/mcp/mcpClient.js +274 -128
- package/dist/mcp/mcpClient.js.map +7 -1
- package/package.json +3 -3
package/dist/mcp/mcpClient.js
CHANGED
|
@@ -1,142 +1,288 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// ../../libs/xyra-types/dist/xyra-administration.js
|
|
34
|
+
var require_xyra_administration = __commonJS({
|
|
35
|
+
"../../libs/xyra-types/dist/xyra-administration.js"(exports2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
38
|
+
exports2.runtimeAdministrationTarget = runtimeAdministrationTarget;
|
|
39
|
+
exports2.parseXyraAdministrationTargetV1 = parseXyraAdministrationTargetV12;
|
|
40
|
+
exports2.xyraAdministrationTargetKeyV1 = xyraAdministrationTargetKeyV1;
|
|
41
|
+
exports2.parseXyraAdministrationResolvedTargetV1 = parseXyraAdministrationResolvedTargetV1;
|
|
42
|
+
exports2.parseXyraAdministrationDecisionV1 = parseXyraAdministrationDecisionV1;
|
|
43
|
+
function runtimeAdministrationTarget(identity) {
|
|
44
|
+
return identity.licenseSourceProductId !== identity.licensedProductId && identity.tenantId === identity.licenseOwnerTenantId ? {
|
|
45
|
+
targetKind: "configuration-owner",
|
|
46
|
+
configurationTenantId: identity.licenseOwnerTenantId,
|
|
47
|
+
managedProductId: identity.licenseSourceProductId
|
|
48
|
+
} : { targetKind: "customer-resource", targetTenantId: identity.tenantId, activeProductId: identity.productId };
|
|
11
49
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.McpRawResponseCapture = McpRawResponseCapture;
|
|
27
|
-
class McpClient {
|
|
28
|
-
sdk;
|
|
29
|
-
transport;
|
|
30
|
-
rawCapture;
|
|
31
|
-
constructor(sdk, transport, rawCapture) {
|
|
32
|
-
this.sdk = sdk;
|
|
33
|
-
this.transport = transport;
|
|
34
|
-
this.rawCapture = rawCapture;
|
|
35
|
-
}
|
|
36
|
-
initialize() {
|
|
50
|
+
var identifier = (value) => typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,49}$/.test(value);
|
|
51
|
+
var guid = (value) => typeof value === "string" && /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(value) && value !== "00000000-0000-0000-0000-000000000000";
|
|
52
|
+
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
53
|
+
var exact = (value, keys) => Object.keys(value).length === keys.length && keys.every((key) => Object.prototype.hasOwnProperty.call(value, key));
|
|
54
|
+
function parseXyraAdministrationTargetV12(value) {
|
|
55
|
+
if (!record(value))
|
|
56
|
+
return null;
|
|
57
|
+
if (value.targetKind === "global-resource" && exact(value, ["targetKind", "managedProductId"]) && value.managedProductId === "xyra-ai") {
|
|
58
|
+
return { targetKind: "global-resource", managedProductId: "xyra-ai" };
|
|
59
|
+
}
|
|
60
|
+
if (value.targetKind === "configuration-owner" && exact(value, ["targetKind", "configurationTenantId", "managedProductId"]) && identifier(value.configurationTenantId) && identifier(value.managedProductId)) {
|
|
37
61
|
return {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
instructions: this.sdk.getInstructions(),
|
|
62
|
+
targetKind: "configuration-owner",
|
|
63
|
+
configurationTenantId: value.configurationTenantId,
|
|
64
|
+
managedProductId: value.managedProductId
|
|
42
65
|
};
|
|
66
|
+
}
|
|
67
|
+
if (value.targetKind === "customer-resource" && exact(value, ["targetKind", "targetTenantId", "activeProductId"]) && identifier(value.targetTenantId) && identifier(value.activeProductId)) {
|
|
68
|
+
return { targetKind: "customer-resource", targetTenantId: value.targetTenantId, activeProductId: value.activeProductId };
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
43
71
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
return await (0, latency_1.measureLatencyPhase)('mcp.method', () => this.sdk.request({ method, params }, types_js_1.ResultSchema), { method });
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
throw mcpError_1.McpRpcError.from(error) ?? error;
|
|
51
|
-
}
|
|
52
|
-
finally {
|
|
53
|
-
this.rawCapture?.end();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
assertConfirmationExtension() {
|
|
57
|
-
const experimental = this.sdk.getServerCapabilities()?.experimental;
|
|
58
|
-
const extension = experimental?.['com.experiture.xyra.confirmations'];
|
|
59
|
-
if (extension?.version !== 1) {
|
|
60
|
-
throw new mcpError_1.McpRpcError({
|
|
61
|
-
code: -32602,
|
|
62
|
-
message: 'The server did not negotiate the Xyra confirmation extension.',
|
|
63
|
-
data: { xyraCode: 'XYRA.MCP.EXTENSION_NOT_NEGOTIATED' },
|
|
64
|
-
});
|
|
65
|
-
}
|
|
72
|
+
function xyraAdministrationTargetKeyV1(target) {
|
|
73
|
+
return JSON.stringify(target.targetKind === "global-resource" ? [target.targetKind, target.managedProductId] : target.targetKind === "configuration-owner" ? [target.targetKind, target.configurationTenantId, target.managedProductId] : [target.targetKind, target.targetTenantId, target.activeProductId]);
|
|
66
74
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
function parseXyraAdministrationResolvedTargetV1(value, target) {
|
|
76
|
+
if (!record(value) || value.targetKind !== target.targetKind)
|
|
77
|
+
return null;
|
|
78
|
+
const managedProductId = target.targetKind === "customer-resource" ? "xyra-ai" : target.managedProductId;
|
|
79
|
+
if (value.managedProductId !== managedProductId)
|
|
80
|
+
return null;
|
|
81
|
+
if (target.targetKind === "global-resource") {
|
|
82
|
+
return exact(value, ["targetKind", "managedProductId", "relationshipKind"]) && value.relationshipKind === "global-resource" ? { targetKind: "global-resource", managedProductId: "xyra-ai", relationshipKind: "global-resource" } : null;
|
|
83
|
+
}
|
|
84
|
+
const base = ["targetKind", "managedProductId", "relationshipKind", "activeProductId", "actualTenantId", "licensedProductId", "commercialState"];
|
|
85
|
+
const embedded = ["licenseSourceProductId", "licenseOwnerTenantId", "bindingId", "entitlementId", "sourceEntitlementId"];
|
|
86
|
+
const isNative = value.relationshipKind === "native-product-tenant";
|
|
87
|
+
if (!isNative && value.relationshipKind !== "embedded-product-entitlement" || !exact(value, isNative ? base : [...base, ...embedded]) || value.licensedProductId !== "xyra-ai" || !base.filter((key) => !["targetKind", "relationshipKind"].includes(key)).every((key) => identifier(value[key])) || (isNative ? value.activeProductId !== "xyra-ai" : !embedded.every((key) => identifier(value[key]))) || value.actualTenantId !== (target.targetKind === "customer-resource" ? target.targetTenantId : target.configurationTenantId) || target.targetKind === "customer-resource" && value.activeProductId !== target.activeProductId || target.targetKind === "configuration-owner" && value.activeProductId !== target.managedProductId || !isNative && (value.activeProductId !== value.licenseSourceProductId && value.activeProductId !== value.licensedProductId || !["bindingId", "entitlementId", "sourceEntitlementId"].every((key) => guid(value[key])) || target.targetKind === "configuration-owner" && (value.licenseOwnerTenantId !== target.configurationTenantId || value.licenseSourceProductId !== target.managedProductId)))
|
|
88
|
+
return null;
|
|
89
|
+
return { ...value };
|
|
77
90
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
function parseXyraAdministrationDecisionV1(value, request, purpose) {
|
|
92
|
+
if (!record(value) || !exact(value, [
|
|
93
|
+
"operationId",
|
|
94
|
+
"purpose",
|
|
95
|
+
"accessPurpose",
|
|
96
|
+
"allowed",
|
|
97
|
+
"code",
|
|
98
|
+
"productId",
|
|
99
|
+
"operatorTenantId",
|
|
100
|
+
"targetTenantId",
|
|
101
|
+
"grantId",
|
|
102
|
+
"target",
|
|
103
|
+
"resolvedTarget",
|
|
104
|
+
...Object.prototype.hasOwnProperty.call(value, "configurationAccess") ? ["configurationAccess"] : []
|
|
105
|
+
]) || value.configurationAccess !== void 0 && !["read", "manage", "manage_selection"].includes(String(value.configurationAccess)) || value.operationId !== request.operationId || value.purpose !== purpose || value.accessPurpose !== "administration" || value.productId !== "xyra-ai" || typeof value.allowed !== "boolean" || typeof value.code !== "string" || !/^[A-Z0-9_.]{1,160}$/.test(value.code) || !(value.operatorTenantId === null || identifier(value.operatorTenantId)) || !(value.grantId === null || guid(value.grantId)))
|
|
106
|
+
return null;
|
|
107
|
+
const target = parseXyraAdministrationTargetV12(value.target);
|
|
108
|
+
if (!target || xyraAdministrationTargetKeyV1(target) !== xyraAdministrationTargetKeyV1(request.target) || value.targetTenantId !== (target.targetKind === "global-resource" ? null : target.targetKind === "configuration-owner" ? target.configurationTenantId : target.targetTenantId))
|
|
109
|
+
return null;
|
|
110
|
+
const resolvedTarget = parseXyraAdministrationResolvedTargetV1(value.resolvedTarget, target);
|
|
111
|
+
if (value.allowed) {
|
|
112
|
+
if (!resolvedTarget)
|
|
113
|
+
return null;
|
|
114
|
+
if (value.code === "AUTHORIZATION.ALLOWED.SAME_TENANT") {
|
|
115
|
+
if (target.targetKind !== "customer-resource" || value.operatorTenantId !== target.targetTenantId || value.grantId !== null)
|
|
116
|
+
return null;
|
|
117
|
+
} else if (value.code === "AUTHORIZATION.ALLOWED.SUPER_USER" ? value.operatorTenantId !== null || value.grantId !== null : !["AUTHORIZATION.ALLOWED", "AUTHORIZATION.ALLOWED.LICENSEE"].includes(value.code) || value.operatorTenantId === null || value.grantId === null)
|
|
118
|
+
return null;
|
|
119
|
+
if (value.code === "AUTHORIZATION.ALLOWED.LICENSEE" && (target.targetKind === "global-resource" || resolvedTarget.relationshipKind !== "embedded-product-entitlement" || resolvedTarget.licenseOwnerTenantId !== value.operatorTenantId))
|
|
120
|
+
return null;
|
|
121
|
+
} else if (value.code.startsWith("AUTHORIZATION.ALLOWED") || value.resolvedTarget !== null)
|
|
122
|
+
return null;
|
|
123
|
+
return { ...value, target, resolvedTarget };
|
|
99
124
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// src/mcp/mcpClient.ts
|
|
129
|
+
var mcpClient_exports = {};
|
|
130
|
+
__export(mcpClient_exports, {
|
|
131
|
+
McpClient: () => McpClient,
|
|
132
|
+
McpRawResponseCapture: () => McpRawResponseCapture
|
|
133
|
+
});
|
|
134
|
+
module.exports = __toCommonJS(mcpClient_exports);
|
|
135
|
+
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
136
|
+
var import_mcpError = require("./mcpError");
|
|
137
|
+
|
|
138
|
+
// src/diagnostics/latency.ts
|
|
139
|
+
var activeDiagnostics;
|
|
140
|
+
async function measureLatencyPhase(name, fn, metadata) {
|
|
141
|
+
return activeDiagnostics ? activeDiagnostics.measure(name, fn, metadata) : fn();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/mcp/mcpClient.ts
|
|
145
|
+
var import_xyra_administration = __toESM(require_xyra_administration());
|
|
146
|
+
var McpRawResponseCapture = class {
|
|
147
|
+
callback;
|
|
148
|
+
begin(callback) {
|
|
149
|
+
this.callback = callback;
|
|
150
|
+
}
|
|
151
|
+
end() {
|
|
152
|
+
this.callback = void 0;
|
|
153
|
+
}
|
|
154
|
+
async observe(response) {
|
|
155
|
+
if (!this.callback || !response.headers.get("content-type")?.includes("application/json")) return;
|
|
156
|
+
try {
|
|
157
|
+
this.callback(await response.clone().json());
|
|
158
|
+
} catch {
|
|
119
159
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var McpClient = class {
|
|
163
|
+
constructor(sdk, transport, rawCapture, administrationTarget) {
|
|
164
|
+
this.sdk = sdk;
|
|
165
|
+
this.transport = transport;
|
|
166
|
+
this.rawCapture = rawCapture;
|
|
167
|
+
this.administrationTarget = administrationTarget;
|
|
168
|
+
if (administrationTarget) {
|
|
169
|
+
const selected = (0, import_xyra_administration.parseXyraAdministrationTargetV1)(administrationTarget);
|
|
170
|
+
if (!selected) throw new import_mcpError.McpRpcError({ code: -32602, message: "Select one closed administration target.", data: { xyraCode: "XYRA.MCP.REQUEST_INVALID" } });
|
|
171
|
+
this.administrationTarget = selected;
|
|
123
172
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
173
|
+
}
|
|
174
|
+
initialize() {
|
|
175
|
+
return {
|
|
176
|
+
protocolVersion: this.transport.protocolVersion,
|
|
177
|
+
capabilities: this.sdk.getServerCapabilities() ?? {},
|
|
178
|
+
serverInfo: this.sdk.getServerVersion() ?? {},
|
|
179
|
+
instructions: this.sdk.getInstructions()
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
async request(method, params = {}, options) {
|
|
183
|
+
if (this.administrationTarget) {
|
|
184
|
+
if (method === "xyra/chat" || ["xyra/confirmations/approve", "xyra/confirmations/reject", "xyra/confirmations/cancel"].includes(method))
|
|
185
|
+
throw new import_mcpError.McpRpcError({ code: -32602, message: "Administrative delegated sessions cannot run chat or decide approvals.", data: { xyraCode: "XYRA.AUTH.INSUFFICIENT_PERMISSIONS" } });
|
|
186
|
+
if (method === "tools/list" || method === "tools/call") params = { ...params, target: this.administrationTarget };
|
|
127
187
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
188
|
+
this.rawCapture?.begin(options?.captureRaw);
|
|
189
|
+
try {
|
|
190
|
+
return await measureLatencyPhase(
|
|
191
|
+
"mcp.method",
|
|
192
|
+
() => this.sdk.request({ method, params }, import_types.ResultSchema),
|
|
193
|
+
{ method }
|
|
194
|
+
);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
throw import_mcpError.McpRpcError.from(error) ?? error;
|
|
197
|
+
} finally {
|
|
198
|
+
this.rawCapture?.end();
|
|
131
199
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
200
|
+
}
|
|
201
|
+
assertConfirmationExtension() {
|
|
202
|
+
const experimental = this.sdk.getServerCapabilities()?.experimental;
|
|
203
|
+
const extension = experimental?.["com.experiture.xyra.confirmations"];
|
|
204
|
+
if (extension?.version !== 1) {
|
|
205
|
+
throw new import_mcpError.McpRpcError({
|
|
206
|
+
code: -32602,
|
|
207
|
+
message: "The server did not negotiate the Xyra confirmation extension.",
|
|
208
|
+
data: { xyraCode: "XYRA.MCP.EXTENSION_NOT_NEGOTIATED" }
|
|
209
|
+
});
|
|
135
210
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
211
|
+
}
|
|
212
|
+
assertChatExtension() {
|
|
213
|
+
const experimental = this.sdk.getServerCapabilities()?.experimental;
|
|
214
|
+
const extension = experimental?.["com.experiture.xyra.chat"];
|
|
215
|
+
if (extension?.version !== 1) {
|
|
216
|
+
throw new import_mcpError.McpRpcError({
|
|
217
|
+
code: -32602,
|
|
218
|
+
message: "The server did not negotiate the Xyra chat extension.",
|
|
219
|
+
data: { xyraCode: "XYRA.MCP.EXTENSION_NOT_NEGOTIATED" }
|
|
220
|
+
});
|
|
139
221
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
222
|
+
}
|
|
223
|
+
/** Page through every visible tool unless a hard limit is supplied. */
|
|
224
|
+
async listTools(filters) {
|
|
225
|
+
const tools = [];
|
|
226
|
+
let cursor;
|
|
227
|
+
do {
|
|
228
|
+
const params = {};
|
|
229
|
+
if (this.administrationTarget && (filters?.domainId || filters?.taskKey)) throw new import_mcpError.McpRpcError({
|
|
230
|
+
code: -32602,
|
|
231
|
+
message: "Administrative discovery uses a closed target and optional exact tool key; runtime domain/task filters are not admission.",
|
|
232
|
+
data: { xyraCode: "XYRA.MCP.REQUEST_INVALID" }
|
|
233
|
+
});
|
|
234
|
+
if (filters?.domainId) params.domainId = filters.domainId;
|
|
235
|
+
if (filters?.taskKey) params.taskKey = filters.taskKey;
|
|
236
|
+
if (filters?.toolKey) params.toolKey = filters.toolKey;
|
|
237
|
+
if (cursor) params.cursor = cursor;
|
|
238
|
+
const result = await this.request("tools/list", params);
|
|
239
|
+
tools.push(...result.tools ?? []);
|
|
240
|
+
cursor = result.nextCursor;
|
|
241
|
+
if (filters?.limit && tools.length >= filters.limit) return tools.slice(0, filters.limit);
|
|
242
|
+
} while (cursor);
|
|
243
|
+
return tools;
|
|
244
|
+
}
|
|
245
|
+
async describeTool(toolKey) {
|
|
246
|
+
const byKey = await this.listTools({ toolKey });
|
|
247
|
+
if (byKey.length > 0) return byKey.find((tool) => tool.name === toolKey) ?? byKey[0];
|
|
248
|
+
const all = await this.listTools();
|
|
249
|
+
return all.find((tool) => tool.name === toolKey);
|
|
250
|
+
}
|
|
251
|
+
callTool(name, args, options, control) {
|
|
252
|
+
return this.request("tools/call", {
|
|
253
|
+
name,
|
|
254
|
+
arguments: args,
|
|
255
|
+
...control?.confirmationRequestId ? { _meta: { "com.experiture.xyra/confirmationRequestId": control.confirmationRequestId } } : {}
|
|
256
|
+
}, options);
|
|
257
|
+
}
|
|
258
|
+
listConfirmations(params = {}) {
|
|
259
|
+
this.assertConfirmationExtension();
|
|
260
|
+
return this.request("xyra/confirmations/list", params);
|
|
261
|
+
}
|
|
262
|
+
getConfirmation(id) {
|
|
263
|
+
this.assertConfirmationExtension();
|
|
264
|
+
return this.request("xyra/confirmations/get", { id });
|
|
265
|
+
}
|
|
266
|
+
approveConfirmation(id) {
|
|
267
|
+
this.assertConfirmationExtension();
|
|
268
|
+
return this.request("xyra/confirmations/approve", { id });
|
|
269
|
+
}
|
|
270
|
+
rejectConfirmation(id, reason) {
|
|
271
|
+
this.assertConfirmationExtension();
|
|
272
|
+
return this.request("xyra/confirmations/reject", { id, ...reason ? { reason } : {} });
|
|
273
|
+
}
|
|
274
|
+
cancelConfirmation(id) {
|
|
275
|
+
this.assertConfirmationExtension();
|
|
276
|
+
return this.request("xyra/confirmations/cancel", { id });
|
|
277
|
+
}
|
|
278
|
+
chat(params) {
|
|
279
|
+
this.assertChatExtension();
|
|
280
|
+
return this.request("xyra/chat", params);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
284
|
+
0 && (module.exports = {
|
|
285
|
+
McpClient,
|
|
286
|
+
McpRawResponseCapture
|
|
287
|
+
});
|
|
288
|
+
//# sourceMappingURL=mcpClient.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../libs/xyra-types/src/xyra-administration.ts", "../../src/mcp/mcpClient.ts", "../../src/diagnostics/latency.ts"],
|
|
4
|
+
"sourcesContent": ["import type { XyraRuntimeIdentityV2 } from './context';\n\n/** A requested maintenance target. It is never a runtime identity or an authorization decision. */\nexport type XyraAdministrationTargetV1 =\n | Readonly<{ targetKind: 'global-resource'; managedProductId: 'xyra-ai' }>\n | Readonly<{ targetKind: 'configuration-owner'; configurationTenantId: string; managedProductId: string }>\n | Readonly<{ targetKind: 'customer-resource'; targetTenantId: string; activeProductId: string }>;\n\n/** Selects a candidate from verified runtime facts. Auth must still admit the exact action. */\nexport function runtimeAdministrationTarget(identity: XyraRuntimeIdentityV2): XyraAdministrationTargetV1 {\n return identity.licenseSourceProductId !== identity.licensedProductId\n && identity.tenantId === identity.licenseOwnerTenantId\n ? { targetKind: 'configuration-owner', configurationTenantId: identity.licenseOwnerTenantId,\n managedProductId: identity.licenseSourceProductId }\n : { targetKind: 'customer-resource', targetTenantId: identity.tenantId, activeProductId: identity.productId };\n}\n\nexport type XyraAccessPurposeV1 = 'runtime' | 'administration';\nexport type XyraAuthorityDecisionPhaseV1 = 'discovery' | 'execution';\nexport type XyraConfigurationAccess = 'read' | 'manage' | 'manage_selection';\n\nexport type XyraAdministrationRequestV1 = Readonly<{\n operationId: string;\n target: XyraAdministrationTargetV1;\n}>;\n\n/** Auth-resolved relationship facts, without a permission snapshot or runtime licence grant. */\nexport type XyraAdministrationResolvedTargetV1 =\n | Readonly<{ targetKind: 'global-resource'; managedProductId: 'xyra-ai'; relationshipKind: 'global-resource' }>\n | Readonly<{ targetKind: 'configuration-owner' | 'customer-resource'; managedProductId: string;\n relationshipKind: 'native-product-tenant'; activeProductId: 'xyra-ai'; actualTenantId: string;\n licensedProductId: 'xyra-ai'; commercialState: string }>\n | Readonly<{ targetKind: 'configuration-owner' | 'customer-resource'; managedProductId: string;\n relationshipKind: 'embedded-product-entitlement'; activeProductId: string; actualTenantId: string;\n licenseSourceProductId: string; licensedProductId: 'xyra-ai'; licenseOwnerTenantId: string;\n bindingId: string; entitlementId: string; sourceEntitlementId: string; commercialState: string }>;\n\nexport type XyraAdministrationDecisionV1 = Readonly<{\n operationId: string;\n purpose: XyraAuthorityDecisionPhaseV1;\n accessPurpose: 'administration';\n allowed: boolean;\n code: string;\n productId: 'xyra-ai';\n operatorTenantId: string | null;\n targetTenantId: string | null;\n grantId: string | null;\n target: XyraAdministrationTargetV1;\n resolvedTarget: XyraAdministrationResolvedTargetV1 | null;\n /** Optional Auth-owned projection requested during a rolling service release. */\n configurationAccess?: XyraConfigurationAccess;\n}>;\n\n/** Protected execution/approval scope, not a permission grant and never a public argument. */\nexport type XyraAdministrationExecutionScopeV1 = Readonly<{\n accessPurpose: 'administration';\n resourceAudience: string;\n administrationTransport: 'native-http' | 'delegated-oauth';\n actorOperatorTenantId: string | null;\n targetHash: string;\n target: XyraAdministrationTargetV1;\n resolvedTarget: XyraAdministrationResolvedTargetV1;\n}>;\n\nconst identifier = (value: unknown): value is string => typeof value === 'string'\n && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,49}$/.test(value);\nconst guid = (value: unknown): value is string => typeof value === 'string'\n && /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(value)\n && value !== '00000000-0000-0000-0000-000000000000';\nconst record = (value: unknown): value is Record<string, unknown> => value !== null\n && typeof value === 'object' && !Array.isArray(value);\nconst exact = (value: Record<string, unknown>, keys: readonly string[]): boolean =>\n Object.keys(value).length === keys.length && keys.every(key => Object.prototype.hasOwnProperty.call(value, key));\n\n/** Strictly parse the closed object shape; raw duplicate JSON keys belong to the transport parser. */\nexport function parseXyraAdministrationTargetV1(value: unknown): XyraAdministrationTargetV1 | null {\n if (!record(value)) return null;\n if (value.targetKind === 'global-resource' && exact(value, ['targetKind', 'managedProductId'])\n && value.managedProductId === 'xyra-ai') {\n return { targetKind: 'global-resource', managedProductId: 'xyra-ai' };\n }\n if (value.targetKind === 'configuration-owner'\n && exact(value, ['targetKind', 'configurationTenantId', 'managedProductId'])\n && identifier(value.configurationTenantId) && identifier(value.managedProductId)) {\n return { targetKind: 'configuration-owner', configurationTenantId: value.configurationTenantId,\n managedProductId: value.managedProductId };\n }\n if (value.targetKind === 'customer-resource'\n && exact(value, ['targetKind', 'targetTenantId', 'activeProductId'])\n && identifier(value.targetTenantId) && identifier(value.activeProductId)) {\n return { targetKind: 'customer-resource', targetTenantId: value.targetTenantId, activeProductId: value.activeProductId };\n }\n return null;\n}\n\n/** Stable exact tuple for cache/request binding, excluding display text and mutable capabilities. */\nexport function xyraAdministrationTargetKeyV1(target: XyraAdministrationTargetV1): string {\n return JSON.stringify(target.targetKind === 'global-resource'\n ? [target.targetKind, target.managedProductId]\n : target.targetKind === 'configuration-owner'\n ? [target.targetKind, target.configurationTenantId, target.managedProductId]\n : [target.targetKind, target.targetTenantId, target.activeProductId]);\n}\n\n/** Validate independent Auth facts against the exact request, never infer a missing relationship. */\nexport function parseXyraAdministrationResolvedTargetV1(\n value: unknown, target: XyraAdministrationTargetV1,\n): XyraAdministrationResolvedTargetV1 | null {\n if (!record(value) || value.targetKind !== target.targetKind) return null;\n const managedProductId = target.targetKind === 'customer-resource' ? 'xyra-ai' : target.managedProductId;\n if (value.managedProductId !== managedProductId) return null;\n if (target.targetKind === 'global-resource') {\n return exact(value, ['targetKind', 'managedProductId', 'relationshipKind']) && value.relationshipKind === 'global-resource'\n ? { targetKind: 'global-resource', managedProductId: 'xyra-ai', relationshipKind: 'global-resource' } : null;\n }\n const base = ['targetKind', 'managedProductId', 'relationshipKind', 'activeProductId', 'actualTenantId', 'licensedProductId', 'commercialState'];\n const embedded = ['licenseSourceProductId', 'licenseOwnerTenantId', 'bindingId', 'entitlementId', 'sourceEntitlementId'];\n const isNative = value.relationshipKind === 'native-product-tenant';\n if ((!isNative && value.relationshipKind !== 'embedded-product-entitlement')\n || !exact(value, isNative ? base : [...base, ...embedded]) || value.licensedProductId !== 'xyra-ai'\n || !base.filter(key => !['targetKind', 'relationshipKind'].includes(key)).every(key => identifier(value[key]))\n || (isNative ? value.activeProductId !== 'xyra-ai' : !embedded.every(key => identifier(value[key])))\n || value.actualTenantId !== (target.targetKind === 'customer-resource' ? target.targetTenantId : target.configurationTenantId)\n || (target.targetKind === 'customer-resource' && value.activeProductId !== target.activeProductId)\n || (target.targetKind === 'configuration-owner' && value.activeProductId !== target.managedProductId)\n || (!isNative && (value.activeProductId !== value.licenseSourceProductId && value.activeProductId !== value.licensedProductId\n || !['bindingId', 'entitlementId', 'sourceEntitlementId'].every(key => guid(value[key]))\n || (target.targetKind === 'configuration-owner' && (value.licenseOwnerTenantId !== target.configurationTenantId\n || value.licenseSourceProductId !== target.managedProductId))))) return null;\n return { ...value } as XyraAdministrationResolvedTargetV1;\n}\n\n/** Parse a decision only for the operation, phase and target that were actually requested. */\nexport function parseXyraAdministrationDecisionV1(value: unknown,\n request: XyraAdministrationRequestV1, purpose: XyraAuthorityDecisionPhaseV1,\n): XyraAdministrationDecisionV1 | null {\n if (!record(value) || !exact(value, ['operationId', 'purpose', 'accessPurpose', 'allowed', 'code', 'productId',\n 'operatorTenantId', 'targetTenantId', 'grantId', 'target', 'resolvedTarget',\n ...(Object.prototype.hasOwnProperty.call(value, 'configurationAccess') ? ['configurationAccess'] : [])])\n || (value.configurationAccess !== undefined && !['read', 'manage', 'manage_selection'].includes(String(value.configurationAccess)))\n || value.operationId !== request.operationId || value.purpose !== purpose || value.accessPurpose !== 'administration'\n || value.productId !== 'xyra-ai' || typeof value.allowed !== 'boolean' || typeof value.code !== 'string'\n || !/^[A-Z0-9_.]{1,160}$/.test(value.code)\n || !(value.operatorTenantId === null || identifier(value.operatorTenantId))\n || !(value.grantId === null || guid(value.grantId))) return null;\n const target = parseXyraAdministrationTargetV1(value.target);\n if (!target || xyraAdministrationTargetKeyV1(target) !== xyraAdministrationTargetKeyV1(request.target)\n || value.targetTenantId !== (target.targetKind === 'global-resource' ? null\n : target.targetKind === 'configuration-owner' ? target.configurationTenantId : target.targetTenantId)) return null;\n const resolvedTarget = parseXyraAdministrationResolvedTargetV1(value.resolvedTarget, target);\n if (value.allowed) {\n if (!resolvedTarget) return null;\n if (value.code === 'AUTHORIZATION.ALLOWED.SAME_TENANT') {\n if (target.targetKind !== 'customer-resource' || value.operatorTenantId !== target.targetTenantId\n || value.grantId !== null) return null;\n } else if (value.code === 'AUTHORIZATION.ALLOWED.SUPER_USER'\n ? value.operatorTenantId !== null || value.grantId !== null\n : !['AUTHORIZATION.ALLOWED', 'AUTHORIZATION.ALLOWED.LICENSEE'].includes(value.code) || value.operatorTenantId === null || value.grantId === null) return null;\n if (value.code === 'AUTHORIZATION.ALLOWED.LICENSEE'\n && (target.targetKind === 'global-resource' || resolvedTarget.relationshipKind !== 'embedded-product-entitlement'\n || resolvedTarget.licenseOwnerTenantId !== value.operatorTenantId)) return null;\n } else if (value.code.startsWith('AUTHORIZATION.ALLOWED') || value.resolvedTarget !== null) return null;\n return { ...value, target, resolvedTarget } as XyraAdministrationDecisionV1;\n}\n", "import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport type { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport { ResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport type {\n XyraRuntimeActionDescriptor,\n XyraPendingHumanApprovalV1,\n XyraRuntimeResponse,\n XyraRuntimeStreamOutcome,\n XyraHumanApprovalViewV1,\n} from '@experiture/xyra-runtime-client';\nimport { McpRpcError } from './mcpError';\nimport { measureLatencyPhase } from '../diagnostics/latency';\nimport {parseXyraAdministrationTargetV1,type XyraAdministrationTargetV1}from'@xyra/types/xyra-administration';\n\nexport interface RpcCallOptions {\n /** Exact JSON-RPC envelope captured from a JSON Streamable HTTP response. */\n captureRaw?: (raw: unknown) => void;\n}\n\nexport class McpRawResponseCapture {\n private callback?: (raw: unknown) => void;\n\n begin(callback?: (raw: unknown) => void): void {\n this.callback = callback;\n }\n\n end(): void {\n this.callback = undefined;\n }\n\n async observe(response: Response): Promise<void> {\n if (!this.callback || !response.headers.get('content-type')?.includes('application/json')) return;\n try {\n this.callback(await response.clone().json());\n } catch {\n // The SDK remains the protocol authority; raw capture is diagnostic only.\n }\n }\n}\n\nexport interface McpTool {\n name: string;\n title?: string;\n description?: string;\n inputSchema?: unknown;\n outputSchema?: unknown;\n annotations?: Record<string, unknown>;\n _meta?: Record<string, unknown>;\n}\n\ninterface ToolsListResult {\n tools: McpTool[];\n nextCursor?: string;\n}\n\nexport interface ToolCallResult {\n content?: unknown;\n structuredContent?: unknown;\n isError?: boolean;\n [key: string]: unknown;\n}\n\nexport interface ConfirmationControl {\n confirmationRequestId?: string;\n}\n\nexport interface ConfirmationListResult {\n confirmations: Record<string, unknown>[];\n count: number;\n}\n\nexport interface McpChatRequest {\n conversationId?: string;\n createConversation?: boolean;\n title?: string;\n message: string;\n locale?: 'en' | 'fr' | 'zh-Hans';\n clientRequestId?: string;\n}\n\nexport interface McpChatResult {\n schemaVersion: 1;\n conversationId: string;\n clientRequestId: string;\n requestId: string;\n executionId: string;\n streamId: string;\n traceId?: string;\n userMessageId: string;\n assistantMessageId?: string;\n outcome: XyraRuntimeStreamOutcome;\n message?: string;\n response?: XyraRuntimeResponse;\n error?: unknown;\n actions?: XyraRuntimeActionDescriptor[];\n pendingHumanApproval?: XyraPendingHumanApprovalV1;\n confirmation?: XyraHumanApprovalViewV1;\n eventCount: number;\n chunkCount: number;\n createdConversation?: {\n id: string;\n title: string;\n titleSource: string;\n createdAt: string;\n };\n}\n\nexport class McpClient {\n constructor(\n private readonly sdk: Client,\n private readonly transport: StreamableHTTPClientTransport,\n private readonly rawCapture?: McpRawResponseCapture,\n private readonly administrationTarget?:XyraAdministrationTargetV1,\n ) {\n if(administrationTarget){\n const selected=parseXyraAdministrationTargetV1(administrationTarget);\n if(!selected)throw new McpRpcError({code:-32602,message:'Select one closed administration target.',data:{xyraCode:'XYRA.MCP.REQUEST_INVALID'}});\n this.administrationTarget=selected;\n }\n }\n\n initialize(): unknown {\n return {\n protocolVersion: this.transport.protocolVersion,\n capabilities: this.sdk.getServerCapabilities() ?? {},\n serverInfo: this.sdk.getServerVersion() ?? {},\n instructions: this.sdk.getInstructions(),\n };\n }\n\n private async request<T>(method: string, params: Record<string, unknown> = {}, options?: RpcCallOptions): Promise<T> {\n if(this.administrationTarget){\n if(method==='xyra/chat'||['xyra/confirmations/approve','xyra/confirmations/reject','xyra/confirmations/cancel'].includes(method))\n throw new McpRpcError({code:-32602,message:'Administrative delegated sessions cannot run chat or decide approvals.',data:{xyraCode:'XYRA.AUTH.INSUFFICIENT_PERMISSIONS'}});\n if(method==='tools/list'||method==='tools/call')params={...params,target:this.administrationTarget};\n }\n this.rawCapture?.begin(options?.captureRaw);\n try {\n return await measureLatencyPhase(\n 'mcp.method',\n () => this.sdk.request({ method, params } as never, ResultSchema) as Promise<T>,\n { method },\n );\n } catch (error) {\n throw McpRpcError.from(error) ?? error;\n } finally {\n this.rawCapture?.end();\n }\n }\n\n private assertConfirmationExtension(): void {\n const experimental = this.sdk.getServerCapabilities()?.experimental;\n const extension = experimental?.['com.experiture.xyra.confirmations'] as Record<string, unknown> | undefined;\n if (extension?.version !== 1) {\n throw new McpRpcError({\n code: -32602,\n message: 'The server did not negotiate the Xyra confirmation extension.',\n data: { xyraCode: 'XYRA.MCP.EXTENSION_NOT_NEGOTIATED' },\n });\n }\n }\n\n private assertChatExtension(): void {\n const experimental = this.sdk.getServerCapabilities()?.experimental;\n const extension = experimental?.['com.experiture.xyra.chat'] as Record<string, unknown> | undefined;\n if (extension?.version !== 1) {\n throw new McpRpcError({\n code: -32602,\n message: 'The server did not negotiate the Xyra chat extension.',\n data: { xyraCode: 'XYRA.MCP.EXTENSION_NOT_NEGOTIATED' },\n });\n }\n }\n\n /** Page through every visible tool unless a hard limit is supplied. */\n async listTools(filters?: { domainId?: string; taskKey?: string; toolKey?: string; limit?: number }): Promise<McpTool[]> {\n const tools: McpTool[] = [];\n let cursor: string | undefined;\n do {\n const params: Record<string, unknown> = {};\n if(this.administrationTarget&&(filters?.domainId||filters?.taskKey))throw new McpRpcError({code:-32602,\n message:'Administrative discovery uses a closed target and optional exact tool key; runtime domain/task filters are not admission.',data:{xyraCode:'XYRA.MCP.REQUEST_INVALID'}});\n if (filters?.domainId) params.domainId = filters.domainId;\n if (filters?.taskKey) params.taskKey = filters.taskKey;\n if (filters?.toolKey) params.toolKey = filters.toolKey;\n if (cursor) params.cursor = cursor;\n const result = await this.request<ToolsListResult>('tools/list', params);\n tools.push(...(result.tools ?? []));\n cursor = result.nextCursor;\n if (filters?.limit && tools.length >= filters.limit) return tools.slice(0, filters.limit);\n } while (cursor);\n return tools;\n }\n\n async describeTool(toolKey: string): Promise<McpTool | undefined> {\n const byKey = await this.listTools({ toolKey });\n if (byKey.length > 0) return byKey.find((tool) => tool.name === toolKey) ?? byKey[0];\n const all = await this.listTools();\n return all.find((tool) => tool.name === toolKey);\n }\n\n callTool(name: string, args: Record<string, unknown>, options?: RpcCallOptions, control?: ConfirmationControl): Promise<ToolCallResult> {\n return this.request<ToolCallResult>('tools/call', {\n name,\n arguments: args,\n ...(control?.confirmationRequestId\n ? { _meta: { 'com.experiture.xyra/confirmationRequestId': control.confirmationRequestId } }\n : {}),\n }, options);\n }\n\n listConfirmations(params: { status?: string[]; toolKey?: string; limit?: number; includeAll?: boolean } = {}): Promise<ConfirmationListResult> {\n this.assertConfirmationExtension();\n return this.request<ConfirmationListResult>('xyra/confirmations/list', params);\n }\n\n getConfirmation(id: string): Promise<Record<string, unknown>> {\n this.assertConfirmationExtension();\n return this.request('xyra/confirmations/get', { id });\n }\n\n approveConfirmation(id: string): Promise<Record<string, unknown>> {\n this.assertConfirmationExtension();\n return this.request('xyra/confirmations/approve', { id });\n }\n\n rejectConfirmation(id: string, reason?: string): Promise<Record<string, unknown>> {\n this.assertConfirmationExtension();\n return this.request('xyra/confirmations/reject', { id, ...(reason ? { reason } : {}) });\n }\n\n cancelConfirmation(id: string): Promise<Record<string, unknown>> {\n this.assertConfirmationExtension();\n return this.request('xyra/confirmations/cancel', { id });\n }\n\n chat(params: McpChatRequest): Promise<McpChatResult> {\n this.assertChatExtension();\n return this.request<McpChatResult>('xyra/chat', params as unknown as Record<string, unknown>);\n }\n}\n", "import crypto from 'node:crypto';\nimport { context, trace, TraceFlags, type Context } from '@opentelemetry/api';\nimport { W3CTraceContextPropagator } from '@opentelemetry/core';\nimport type { OutputWriter } from '../output/console';\n\nexport interface LatencyPhaseRecord {\n name: string;\n durationMs: number;\n metadata?: Record<string, string | number | boolean>;\n}\n\nexport interface LatencyLinkage {\n traceId?: string;\n correlationId?: string;\n serverTiming?: string;\n}\n\nexport interface LatencyReport {\n schemaVersion: 1;\n generatedAt: string;\n totalDurationMs: number;\n phases: LatencyPhaseRecord[];\n linkage: LatencyLinkage;\n}\n\ntype LatencyMode = 'human' | 'json';\n\nlet configuredMode: LatencyMode | undefined;\nlet activeDiagnostics: LatencyDiagnostics | undefined;\n\nfunction elapsedMs(startedAt: number): number {\n return Math.round((performance.now() - startedAt) * 100) / 100;\n}\n\nfunction validTraceId(value: string | null): value is string {\n return Boolean(value && /^[0-9a-f]{32}$/i.test(value) && !/^0{32}$/.test(value));\n}\n\nexport class LatencyDiagnostics {\n private readonly startedAt = performance.now();\n private readonly records: LatencyPhaseRecord[] = [];\n private readonly linkage: LatencyLinkage = {};\n private readonly traceContext: Context;\n\n constructor(readonly mode: LatencyMode) {\n const traceId = crypto.randomBytes(16).toString('hex');\n const spanId = crypto.randomBytes(8).toString('hex');\n this.linkage.traceId = traceId;\n this.traceContext = trace.setSpanContext(context.active(), {\n traceId,\n spanId,\n traceFlags: TraceFlags.SAMPLED,\n isRemote: false,\n });\n }\n\n async measure<T>(\n name: string,\n fn: () => Promise<T> | T,\n metadata?: Record<string, string | number | boolean>,\n ): Promise<T> {\n const startedAt = performance.now();\n try {\n return await fn();\n } finally {\n this.records.push({ name, durationMs: elapsedMs(startedAt), ...(metadata ? { metadata } : {}) });\n }\n }\n\n record(name: string, durationMs: number, metadata?: Record<string, string | number | boolean>): void {\n this.records.push({ name, durationMs: Math.round(durationMs * 100) / 100, ...(metadata ? { metadata } : {}) });\n }\n\n injectTraceHeaders(headers: Headers): void {\n new W3CTraceContextPropagator().inject(this.traceContext, headers, {\n set(carrier, key, value) {\n carrier.set(key, value);\n },\n });\n }\n\n observeResponseHeaders(headers: Headers): void {\n const serverTraceId = headers.get('x-trace-id');\n if (validTraceId(serverTraceId)) this.linkage.traceId = serverTraceId.toLowerCase();\n const correlationId = headers.get('x-correlation-id');\n if (correlationId) this.linkage.correlationId = correlationId;\n const serverTiming = headers.get('server-timing');\n if (serverTiming) this.linkage.serverTiming = serverTiming;\n }\n\n report(): LatencyReport {\n return {\n schemaVersion: 1,\n generatedAt: new Date().toISOString(),\n totalDurationMs: elapsedMs(this.startedAt),\n phases: [...this.records],\n linkage: { ...this.linkage },\n };\n }\n}\n\nexport function configureLatencyDiagnostics(options: { timings?: boolean; timingsJson?: boolean }): void {\n configuredMode = options.timingsJson ? 'json' : options.timings ? 'human' : undefined;\n}\n\nexport function beginLatencyDiagnostics(): LatencyDiagnostics | undefined {\n activeDiagnostics = configuredMode ? new LatencyDiagnostics(configuredMode) : undefined;\n return activeDiagnostics;\n}\n\nexport function getLatencyDiagnostics(): LatencyDiagnostics | undefined {\n return activeDiagnostics;\n}\n\nexport function endLatencyDiagnostics(): void {\n activeDiagnostics = undefined;\n}\n\nexport async function measureLatencyPhase<T>(\n name: string,\n fn: () => Promise<T> | T,\n metadata?: Record<string, string | number | boolean>,\n): Promise<T> {\n return activeDiagnostics\n ? activeDiagnostics.measure(name, fn, metadata)\n : fn();\n}\n\nexport function createTimedOutputWriter(writer: OutputWriter): OutputWriter {\n return {\n out(message) {\n const startedAt = performance.now();\n try {\n writer.out(message);\n } finally {\n activeDiagnostics?.record('output.render', elapsedMs(startedAt), { stream: 'stdout' });\n }\n },\n err(message) {\n const startedAt = performance.now();\n try {\n writer.err(message);\n } finally {\n activeDiagnostics?.record('output.render', elapsedMs(startedAt), { stream: 'stderr' });\n }\n },\n };\n}\n\nexport function emitLatencyDiagnostics(diagnostics: LatencyDiagnostics, writer: OutputWriter): void {\n const report = diagnostics.report();\n if (diagnostics.mode === 'json') {\n writer.err(JSON.stringify(report));\n return;\n }\n const rows = report.phases.map((phase) => ` ${phase.name}: ${phase.durationMs.toFixed(2)} ms`);\n writer.err([\n `Latency diagnostics: ${report.totalDurationMs.toFixed(2)} ms total`,\n ...rows,\n ...(report.linkage.serverTiming ? [` server-timing: ${report.linkage.serverTiming}`] : []),\n ...(report.linkage.traceId ? [` trace-id: ${report.linkage.traceId}`] : []),\n ...(report.linkage.correlationId ? [` correlation-id: ${report.linkage.correlationId}`] : []),\n ].join('\\n'));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAAA,SAAA,8BAAA;AAkEA,IAAAA,SAAA,kCAAAC;AAqBA,IAAAD,SAAA,gCAAA;AASA,IAAAA,SAAA,0CAAA;AA4BA,IAAAA,SAAA,oCAAA;AA5HA,aAAgB,4BAA4B,UAA+B;AACzE,aAAO,SAAS,2BAA2B,SAAS,qBAC/C,SAAS,aAAa,SAAS,uBAChC;QAAE,YAAY;QAAuB,uBAAuB,SAAS;QACnE,kBAAkB,SAAS;MAAsB,IACnD,EAAE,YAAY,qBAAqB,gBAAgB,SAAS,UAAU,iBAAiB,SAAS,UAAS;IAC/G;AAiDA,QAAM,aAAa,CAAC,UAAoC,OAAO,UAAU,YACpE,qCAAqC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S,MAAc,MAA+B,SAA0B,SAAwD;AACtI,WAAO,KAAK,QAAwB,cAAc;AAAA,MAChD;AAAA,MACA,WAAW;AAAA,MACX,GAAI,SAAS,wBACT,EAAE,OAAO,EAAE,6CAA6C,QAAQ,sBAAsB,EAAE,IACxF,CAAC;AAAA,IACP,GAAG,OAAO;AAAA,EACZ;AAAA,EAEA,kBAAkB,SAAwF,CAAC,GAAoC;AAC7I,SAAK,4BAA4B;AACjC,WAAO,KAAK,QAAgC,2BAA2B,MAAM;AAAA,EAC/E;AAAA,EAEA,gBAAgB,IAA8C;AAC5D,SAAK,4BAA4B;AACjC,WAAO,KAAK,QAAQ,0BAA0B,EAAE,GAAG,CAAC;AAAA,EACtD;AAAA,EAEA,oBAAoB,IAA8C;AAChE,SAAK,4BAA4B;AACjC,WAAO,KAAK,QAAQ,8BAA8B,EAAE,GAAG,CAAC;AAAA,EAC1D;AAAA,EAEA,mBAAmB,IAAY,QAAmD;AAChF,SAAK,4BAA4B;AACjC,WAAO,KAAK,QAAQ,6BAA6B,EAAE,IAAI,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC,EAAG,CAAC;AAAA,EACxF;AAAA,EAEA,mBAAmB,IAA8C;AAC/D,SAAK,4BAA4B;AACjC,WAAO,KAAK,QAAQ,6BAA6B,EAAE,GAAG,CAAC;AAAA,EACzD;AAAA,EAEA,KAAK,QAAgD;AACnD,SAAK,oBAAoB;AACzB,WAAO,KAAK,QAAuB,aAAa,MAA4C;AAAA,EAC9F;AACF;",
|
|
6
|
+
"names": ["exports", "parseXyraAdministrationTargetV1"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@experiture/xyra-cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Xyra CLI - headless application runner over the Xyra MCP server and Auth delegated OAuth flow.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"registry": "https://registry.npmjs.org/"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "npm run clean && tsc && esbuild src/chat/runtimeChatClient.ts --bundle --platform=node --format=cjs --target=node20 --sourcemap --
|
|
36
|
+
"build": "npm run clean && tsc && esbuild src/chat/runtimeChatClient.ts src/config/configStore.ts src/mcp/mcpClient.ts --bundle --platform=node --format=cjs --target=node20 --sourcemap --outdir=dist --outbase=src --external:@modelcontextprotocol/* --external:../errors/CliError --external:./mcpError && node -e \"require('node:fs').chmodSync('dist/index.js', 0o755)\"",
|
|
37
37
|
"benchmark:latency": "node scripts/benchmark-latency.mjs",
|
|
38
38
|
"certify:router-acknowledgement": "node scripts/router-acknowledgement-certification.mjs",
|
|
39
39
|
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@experiture/xyra-provider-client": "^0.1.13",
|
|
55
|
-
"@experiture/xyra-runtime-client": "0.1.
|
|
55
|
+
"@experiture/xyra-runtime-client": "0.1.54",
|
|
56
56
|
"@jest/globals": "^29.7.0",
|
|
57
57
|
"@types/jest": "^29.5.0",
|
|
58
58
|
"@types/node": "^20.11.0",
|