@voxslopuli/teamdynamix-mcp 0.4.2 → 0.5.1
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/README.md +42 -0
- package/index.js +1321 -533
- package/index.js.map +1 -1
- package/package.json +9 -4
- package/sweep.d.ts +1 -0
- package/sweep.js +1077 -0
- package/sweep.js.map +1 -0
package/index.js
CHANGED
|
@@ -1,114 +1,126 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
9
11
|
|
|
10
12
|
// package.json
|
|
11
|
-
var package_default
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
13
|
+
var package_default;
|
|
14
|
+
var init_package = __esm({
|
|
15
|
+
"package.json"() {
|
|
16
|
+
package_default = {
|
|
17
|
+
name: "@voxslopuli/teamdynamix-mcp",
|
|
18
|
+
version: "0.5.1",
|
|
19
|
+
private: false,
|
|
20
|
+
description: "A production-ready TypeScript MCP server for TeamDynamix",
|
|
21
|
+
keywords: [
|
|
22
|
+
"mcp",
|
|
23
|
+
"model context protocol",
|
|
24
|
+
"server",
|
|
25
|
+
"tdx",
|
|
26
|
+
"teamdynamix",
|
|
27
|
+
"typescript"
|
|
28
|
+
],
|
|
29
|
+
homepage: "https://github.com/voxslopuli/teamdynamix-mcp",
|
|
30
|
+
bugs: {
|
|
31
|
+
url: "https://github.com/voxslopuli/teamdynamix-mcp/issues"
|
|
32
|
+
},
|
|
33
|
+
license: "MIT",
|
|
34
|
+
author: "Grand Slopulissimo <slopulissimo@voxslopuli.org>",
|
|
35
|
+
repository: {
|
|
36
|
+
type: "git",
|
|
37
|
+
url: "git+https://github.com/voxslopuli/teamdynamix-mcp.git"
|
|
38
|
+
},
|
|
39
|
+
bin: {
|
|
40
|
+
"tdx-watch-sweep": "dist/sweep.js",
|
|
41
|
+
"teamdynamix-mcp": "dist/index.js"
|
|
42
|
+
},
|
|
43
|
+
type: "module",
|
|
44
|
+
main: "dist/index.js",
|
|
45
|
+
scripts: {
|
|
46
|
+
build: "tsup",
|
|
47
|
+
postbuild: "node scripts/write-dist-package.js",
|
|
48
|
+
dev: "tsx watch src/index.ts",
|
|
49
|
+
"docs:build": "node scripts/prepare-docs-public.js && vitepress build docs",
|
|
50
|
+
"docs:dev": "vitepress dev docs",
|
|
51
|
+
"docs:preview": "vitepress preview docs",
|
|
52
|
+
format: "oxfmt . --write",
|
|
53
|
+
"format:check": "oxfmt . --check",
|
|
54
|
+
lint: "oxlint .",
|
|
55
|
+
"lint:fix": "oxlint . --fix",
|
|
56
|
+
prepare: "husky",
|
|
57
|
+
start: "node dist/index.js",
|
|
58
|
+
test: "vitest run",
|
|
59
|
+
"test:coverage": "vitest run --coverage",
|
|
60
|
+
typecheck: "tsc --noEmit"
|
|
61
|
+
},
|
|
62
|
+
dependencies: {
|
|
63
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
64
|
+
"@voxslopuli/teamdynamix-ts": "^0.2.0",
|
|
65
|
+
tablemark: "^4.1.0",
|
|
66
|
+
zod: "^4.6.2"
|
|
67
|
+
},
|
|
68
|
+
devDependencies: {
|
|
69
|
+
"@octokit/rest": "^22.0.1",
|
|
70
|
+
"@types/node": "25.9.2",
|
|
71
|
+
"@vitest/coverage-v8": "^5.0.0",
|
|
72
|
+
husky: "^9.1.7",
|
|
73
|
+
"lint-staged": "^17.5.1",
|
|
74
|
+
ora: "^9.4.1",
|
|
75
|
+
oxfmt: "^0.67.0",
|
|
76
|
+
oxlint: "^1.82.0",
|
|
77
|
+
tsup: "^8.5.1",
|
|
78
|
+
tsx: "^4.23.13",
|
|
79
|
+
typescript: "6.0.3",
|
|
80
|
+
vite: "8.3.0",
|
|
81
|
+
vitepress: "^1.6.4",
|
|
82
|
+
vitest: "5.0.0",
|
|
83
|
+
zx: "^8.8.5"
|
|
84
|
+
},
|
|
85
|
+
"lint-staged": {
|
|
86
|
+
"*.{ts,mts,cts,js,mjs,cjs}": [
|
|
87
|
+
"oxlint --fix --no-error-on-unmatched-pattern",
|
|
88
|
+
"oxfmt --no-error-on-unmatched-pattern --write"
|
|
89
|
+
],
|
|
90
|
+
"*.{json,yaml,yml,md}": [
|
|
91
|
+
"oxfmt --no-error-on-unmatched-pattern --write"
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
packageManager: "pnpm@10.32.1",
|
|
95
|
+
pnpm: {
|
|
96
|
+
overrides: {
|
|
97
|
+
hono: ">=4.12.18",
|
|
98
|
+
"@hono/node-server": ">=1.19.13"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
mcpName: "io.github.selfagency/teamdynamix-mcp"
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
|
95
105
|
|
|
96
106
|
// src/constants.ts
|
|
97
|
-
var SERVER_NAME
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
var SERVER_NAME, SERVER_VERSION, CHARACTER_LIMIT, TEAMDYNAMIX_TOOL_PREFIX, TEAMDYNAMIX_DEFAULT_TIMEOUT_MS, TEAMDYNAMIX_DEFAULT_MAX_RETRIES, TEAMDYNAMIX_MAX_RETRY_ATTEMPTS;
|
|
108
|
+
var init_constants = __esm({
|
|
109
|
+
"src/constants.ts"() {
|
|
110
|
+
"use strict";
|
|
111
|
+
init_package();
|
|
112
|
+
SERVER_NAME = "teamdynamix-mcp";
|
|
113
|
+
SERVER_VERSION = package_default.version;
|
|
114
|
+
CHARACTER_LIMIT = 25e3;
|
|
115
|
+
TEAMDYNAMIX_TOOL_PREFIX = "teamdynamix";
|
|
116
|
+
TEAMDYNAMIX_DEFAULT_TIMEOUT_MS = 3e4;
|
|
117
|
+
TEAMDYNAMIX_DEFAULT_MAX_RETRIES = 2;
|
|
118
|
+
TEAMDYNAMIX_MAX_RETRY_ATTEMPTS = 5;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
104
121
|
|
|
105
122
|
// src/config.ts
|
|
106
|
-
|
|
107
|
-
var SERVER_VERSION_OVERRIDE = process.env["MCP_SERVER_VERSION"]?.trim() || void 0;
|
|
108
|
-
var validLogLevels = ["debug", "info", "warn", "error"];
|
|
109
|
-
var logLevelSchema = z.enum(validLogLevels);
|
|
110
|
-
var parsedLogLevel = logLevelSchema.safeParse(process.env["MCP_LOG_LEVEL"]?.trim());
|
|
111
|
-
var LOG_LEVEL = parsedLogLevel.success ? parsedLogLevel.data : "info";
|
|
123
|
+
import { z } from "zod";
|
|
112
124
|
function normalizeOptionalString(value) {
|
|
113
125
|
const normalized = value?.trim();
|
|
114
126
|
return normalized ? normalized : void 0;
|
|
@@ -193,17 +205,979 @@ function getTeamDynamixConfigStatus(config = getTeamDynamixConfig()) {
|
|
|
193
205
|
if (!config.username) missing.add("TEAMDYNAMIX_USERNAME");
|
|
194
206
|
if (!config.password) missing.add("TEAMDYNAMIX_PASSWORD");
|
|
195
207
|
}
|
|
196
|
-
return {
|
|
197
|
-
configured: missing.size === 0,
|
|
198
|
-
missing: [...missing],
|
|
199
|
-
authMode: config.authMode
|
|
200
|
-
};
|
|
201
|
-
}
|
|
208
|
+
return {
|
|
209
|
+
configured: missing.size === 0,
|
|
210
|
+
missing: [...missing],
|
|
211
|
+
authMode: config.authMode
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
var SERVER_NAME_OVERRIDE, SERVER_VERSION_OVERRIDE, validLogLevels, logLevelSchema, parsedLogLevel, LOG_LEVEL;
|
|
215
|
+
var init_config = __esm({
|
|
216
|
+
"src/config.ts"() {
|
|
217
|
+
"use strict";
|
|
218
|
+
init_constants();
|
|
219
|
+
SERVER_NAME_OVERRIDE = process.env["MCP_SERVER_NAME"]?.trim() || void 0;
|
|
220
|
+
SERVER_VERSION_OVERRIDE = process.env["MCP_SERVER_VERSION"]?.trim() || void 0;
|
|
221
|
+
validLogLevels = ["debug", "info", "warn", "error"];
|
|
222
|
+
logLevelSchema = z.enum(validLogLevels);
|
|
223
|
+
parsedLogLevel = logLevelSchema.safeParse(process.env["MCP_LOG_LEVEL"]?.trim());
|
|
224
|
+
LOG_LEVEL = parsedLogLevel.success ? parsedLogLevel.data : "info";
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// src/client/sdk-client.factory.ts
|
|
229
|
+
import { existsSync } from "fs";
|
|
230
|
+
import { createRequire } from "module";
|
|
231
|
+
import { dirname, resolve } from "path";
|
|
232
|
+
import { fileURLToPath } from "url";
|
|
233
|
+
import { createTeamDynamixClient, loginWithPassword, loginWithServiceAccount } from "@voxslopuli/teamdynamix-ts";
|
|
234
|
+
function resolveSdkSpecPath() {
|
|
235
|
+
const override = process.env["TEAMDYNAMIX_SPEC_PATH"]?.trim();
|
|
236
|
+
if (override) return override;
|
|
237
|
+
if (cachedSpecPath) return cachedSpecPath;
|
|
238
|
+
try {
|
|
239
|
+
const require2 = createRequire(fileURLToPath(import.meta.url));
|
|
240
|
+
const entryPath = require2.resolve("@voxslopuli/teamdynamix-ts");
|
|
241
|
+
const pkgRoot = dirname(entryPath);
|
|
242
|
+
const candidates = [
|
|
243
|
+
resolve(pkgRoot, "dist/generated/openapi.json"),
|
|
244
|
+
resolve(pkgRoot, "generated/openapi.json"),
|
|
245
|
+
resolve(pkgRoot, "src/generated/openapi.json")
|
|
246
|
+
];
|
|
247
|
+
cachedSpecPath = candidates.find((p) => existsSync(p));
|
|
248
|
+
return cachedSpecPath;
|
|
249
|
+
} catch {
|
|
250
|
+
return void 0;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function createTokenProvider(config, tenant) {
|
|
254
|
+
if (config.authMode === "admin") {
|
|
255
|
+
if (!config.beid || !config.webServicesKey) {
|
|
256
|
+
throw new Error("BEID and WebServicesKey are required for admin authentication");
|
|
257
|
+
}
|
|
258
|
+
return loginWithServiceAccount({
|
|
259
|
+
tenant,
|
|
260
|
+
baseUrl: config.baseUrl,
|
|
261
|
+
beid: config.beid,
|
|
262
|
+
webServicesKey: config.webServicesKey
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
if (!config.username || !config.password) {
|
|
266
|
+
throw new Error("Username and password are required for standard authentication");
|
|
267
|
+
}
|
|
268
|
+
return loginWithPassword({
|
|
269
|
+
tenant,
|
|
270
|
+
baseUrl: config.baseUrl,
|
|
271
|
+
username: config.username,
|
|
272
|
+
password: config.password
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function extractTenant(baseUrl) {
|
|
276
|
+
const normalized = baseUrl.replace(/\/+$/, "").replace(/\/TDWebApi$/, "");
|
|
277
|
+
const withoutProtocol = normalized.replace(/^https?:\/\//, "");
|
|
278
|
+
const parts = withoutProtocol.split("/");
|
|
279
|
+
return parts[0] ?? "";
|
|
280
|
+
}
|
|
281
|
+
function buildSdkConfig(config, tenant, tokenProvider) {
|
|
282
|
+
return {
|
|
283
|
+
tenant,
|
|
284
|
+
tokenProvider,
|
|
285
|
+
environment: config.baseUrl?.includes("sandbox") ? "sandbox" : "production",
|
|
286
|
+
baseUrl: config.baseUrl,
|
|
287
|
+
timeoutMs: config.timeoutMs,
|
|
288
|
+
runtimeValidationMode: "fail-open",
|
|
289
|
+
...resolveSdkSpecPath() ? { specPath: resolveSdkSpecPath() } : {},
|
|
290
|
+
retryPolicy: {
|
|
291
|
+
maxRetries: config.maxRetries
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
async function createMcpSdkClient(config) {
|
|
296
|
+
const tenant = extractTenant(config.baseUrl ?? "");
|
|
297
|
+
const tokenProvider = createTokenProvider(config, tenant);
|
|
298
|
+
const sdkConfig = buildSdkConfig(config, tenant, tokenProvider);
|
|
299
|
+
const { client } = await createTeamDynamixClient(sdkConfig);
|
|
300
|
+
return client;
|
|
301
|
+
}
|
|
302
|
+
var cachedSpecPath;
|
|
303
|
+
var init_sdk_client_factory = __esm({
|
|
304
|
+
"src/client/sdk-client.factory.ts"() {
|
|
305
|
+
"use strict";
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// src/services/teamdynamix/client.factory.ts
|
|
310
|
+
function mapTicketSearchBody(body) {
|
|
311
|
+
const mapped = {};
|
|
312
|
+
for (const [key, value] of Object.entries(body)) {
|
|
313
|
+
if (value === void 0) continue;
|
|
314
|
+
mapped[TICKET_SEARCH_FIELD_MAP[key] ?? key] = value;
|
|
315
|
+
}
|
|
316
|
+
return mapped;
|
|
317
|
+
}
|
|
318
|
+
function parseIdListEnv(raw) {
|
|
319
|
+
return (raw ?? "").split(/[;,\s]+/).map(Number).filter((n) => Number.isFinite(n) && n > 0);
|
|
320
|
+
}
|
|
321
|
+
function sanitizeTo(body, allowed) {
|
|
322
|
+
const out = {};
|
|
323
|
+
for (const [key, value] of Object.entries(body)) {
|
|
324
|
+
if (allowed.has(key) && value !== void 0) out[key] = value;
|
|
325
|
+
}
|
|
326
|
+
return out;
|
|
327
|
+
}
|
|
328
|
+
function createConfiguredTeamDynamixClient() {
|
|
329
|
+
return new UnifiedTeamDynamixClient(getTeamDynamixConfig());
|
|
330
|
+
}
|
|
331
|
+
function assertWriteToolsEnabled(config) {
|
|
332
|
+
if (!config.enableWriteTools) {
|
|
333
|
+
throw new Error("Write tools are disabled. Set TEAMDYNAMIX_ENABLE_WRITE_TOOLS=true in your environment.");
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function assertDeleteToolsEnabled(config) {
|
|
337
|
+
if (!config.enableDeleteTools) {
|
|
338
|
+
throw new Error("Delete tools are disabled. Set TEAMDYNAMIX_ENABLE_DELETE_TOOLS=true in your environment.");
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
var TICKET_SEARCH_FIELD_MAP, USER_SEARCH_KEYS, GROUP_SEARCH_KEYS, ARTICLE_SEARCH_KEYS, UnifiedTeamDynamixClient;
|
|
342
|
+
var init_client_factory = __esm({
|
|
343
|
+
"src/services/teamdynamix/client.factory.ts"() {
|
|
344
|
+
"use strict";
|
|
345
|
+
init_sdk_client_factory();
|
|
346
|
+
init_config();
|
|
347
|
+
TICKET_SEARCH_FIELD_MAP = {
|
|
348
|
+
ResponsibleGroupIDs: "ResponsibilityGroupIDs",
|
|
349
|
+
ResponsibleGroupID: "ResponsibilityGroupID",
|
|
350
|
+
ResponsibleGroups: "ResponsibilityGroupIDs"
|
|
351
|
+
};
|
|
352
|
+
USER_SEARCH_KEYS = /* @__PURE__ */ new Set([
|
|
353
|
+
"AccountIDs",
|
|
354
|
+
"AlternateID",
|
|
355
|
+
"AppName",
|
|
356
|
+
"AuthenticationUserName",
|
|
357
|
+
"ExternalID",
|
|
358
|
+
"IsActive",
|
|
359
|
+
"IsConfidential",
|
|
360
|
+
"IsEmployee",
|
|
361
|
+
"MaxResults",
|
|
362
|
+
"PhoneNumber",
|
|
363
|
+
"ReferenceIDs",
|
|
364
|
+
"SearchText",
|
|
365
|
+
"SecurityRoleID",
|
|
366
|
+
"UserName"
|
|
367
|
+
]);
|
|
368
|
+
GROUP_SEARCH_KEYS = /* @__PURE__ */ new Set(["AssociatedAppID", "HasAppID", "HasSystemAppName", "IsActive", "NameLike"]);
|
|
369
|
+
ARTICLE_SEARCH_KEYS = /* @__PURE__ */ new Set([
|
|
370
|
+
"AuthorUID",
|
|
371
|
+
"CategoryID",
|
|
372
|
+
"CustomAttributes",
|
|
373
|
+
"IncludeArticleBodies",
|
|
374
|
+
"IncludeShortcuts",
|
|
375
|
+
"IsPublic",
|
|
376
|
+
"IsPublished",
|
|
377
|
+
"ReturnCount",
|
|
378
|
+
"SearchText",
|
|
379
|
+
"Status"
|
|
380
|
+
]);
|
|
381
|
+
UnifiedTeamDynamixClient = class _UnifiedTeamDynamixClient {
|
|
382
|
+
constructor(config) {
|
|
383
|
+
this.config = config;
|
|
384
|
+
}
|
|
385
|
+
config;
|
|
386
|
+
sdkPromise = null;
|
|
387
|
+
sdk() {
|
|
388
|
+
this.sdkPromise ??= createMcpSdkClient(this.config);
|
|
389
|
+
return this.sdkPromise;
|
|
390
|
+
}
|
|
391
|
+
//
|
|
392
|
+
// Discovery
|
|
393
|
+
//
|
|
394
|
+
getCurrentUser() {
|
|
395
|
+
return this.sdk().then((s) => s.discovery.authGetuser());
|
|
396
|
+
}
|
|
397
|
+
listApplications() {
|
|
398
|
+
return this.sdk().then((s) => s.discovery.applications());
|
|
399
|
+
}
|
|
400
|
+
//
|
|
401
|
+
// Tickets
|
|
402
|
+
//
|
|
403
|
+
getTicket(appId, ticketId) {
|
|
404
|
+
return this.sdk().then((s) => s.tickets.appIdTicketsId({ params: { path: { appId, id: ticketId } } }));
|
|
405
|
+
}
|
|
406
|
+
searchTickets(appId, body) {
|
|
407
|
+
return this.sdk().then(async (s) => {
|
|
408
|
+
const { data, error } = await s.POST("/api/{appId}/tickets/search", {
|
|
409
|
+
params: { path: { appId } },
|
|
410
|
+
body: mapTicketSearchBody(body)
|
|
411
|
+
});
|
|
412
|
+
if (error) {
|
|
413
|
+
throw new Error(`Ticket search failed: ${JSON.stringify(error)}`);
|
|
414
|
+
}
|
|
415
|
+
const results = Array.isArray(data) ? data : [];
|
|
416
|
+
const groupFilter = parseIdListEnv(process.env["TEAMDYNAMIX_TICKET_GROUP_IDS"]);
|
|
417
|
+
if (groupFilter.length === 0) return results;
|
|
418
|
+
return results.filter((item) => {
|
|
419
|
+
if (typeof item !== "object" || item === null) return false;
|
|
420
|
+
const gid = Number(item["ResponsibleGroupID"]);
|
|
421
|
+
return groupFilter.includes(gid);
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
listTicketTypes(appId) {
|
|
426
|
+
return this.sdk().then((s) => s.tickets.appIdTicketsTypes({ params: { path: { appId } } }));
|
|
427
|
+
}
|
|
428
|
+
listTicketPriorities(appId) {
|
|
429
|
+
return this.sdk().then((s) => s.tickets.appIdTicketsPriorities({ params: { path: { appId } } }));
|
|
430
|
+
}
|
|
431
|
+
listTicketUrgencies(appId) {
|
|
432
|
+
return this.sdk().then((s) => s.tickets.appIdTicketsUrgencies({ params: { path: { appId } } }));
|
|
433
|
+
}
|
|
434
|
+
listTicketImpacts(appId) {
|
|
435
|
+
return this.sdk().then((s) => s.tickets.appIdTicketsImpacts({ params: { path: { appId } } }));
|
|
436
|
+
}
|
|
437
|
+
listTicketSources(appId) {
|
|
438
|
+
return this.sdk().then((s) => s.tickets.appIdTicketsSources({ params: { path: { appId } } }));
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Upper bound on feed entries we'll fetch replies for. The TDX API allows 60
|
|
442
|
+
* requests/60s; the feed call itself plus one fetch per entry must stay under it.
|
|
443
|
+
*/
|
|
444
|
+
static DEFAULT_REPLIES_ENTRY_LIMIT = 10;
|
|
445
|
+
async getTicketFeed(appId, ticketId, opts = {}) {
|
|
446
|
+
const s = await this.sdk();
|
|
447
|
+
const feed = await s.tickets.appIdTicketsIdFeed({ params: { path: { appId, id: ticketId } } });
|
|
448
|
+
const entries = Array.isArray(feed) ? feed : [];
|
|
449
|
+
const limit = opts.repliesEntryLimit ?? _UnifiedTeamDynamixClient.DEFAULT_REPLIES_ENTRY_LIMIT;
|
|
450
|
+
const missing = entries.filter(
|
|
451
|
+
(e) => typeof e.RepliesCount === "number" && e.RepliesCount > 0 && (!Array.isArray(e.Replies) || e.Replies.length === 0) && typeof e.ID !== "undefined"
|
|
452
|
+
);
|
|
453
|
+
for (const entry of missing.slice(0, limit)) {
|
|
454
|
+
const target = entry;
|
|
455
|
+
const { data, error } = await s.GET("/api/feed/{id}", {
|
|
456
|
+
params: { path: { id: target.ID } }
|
|
457
|
+
});
|
|
458
|
+
if (error) {
|
|
459
|
+
const detail = typeof error === "string" ? error : JSON.stringify(error);
|
|
460
|
+
throw new Error(`Failed to fetch replies for feed entry ${target.ID} (GET /api/feed/{id}): ${detail}`);
|
|
461
|
+
}
|
|
462
|
+
if (data && Array.isArray(data.Replies)) {
|
|
463
|
+
target.Replies = data.Replies;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return entries;
|
|
467
|
+
}
|
|
468
|
+
//
|
|
469
|
+
// Ticket Relationships
|
|
470
|
+
//
|
|
471
|
+
getTicketTasks(appId, ticketId) {
|
|
472
|
+
return this.sdk().then(
|
|
473
|
+
(s) => s.ticketRelationships.appIdTicketsTicketIdTasks({ params: { path: { appId, ticketId } } })
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
createTicketTask(appId, ticketId, body) {
|
|
477
|
+
return this.sdk().then((s) => s.ticketRelationships.createTicketTask({ appId, ticketId, body }));
|
|
478
|
+
}
|
|
479
|
+
listTicketAssets(appId, ticketId) {
|
|
480
|
+
return this.sdk().then(
|
|
481
|
+
(s) => s.ticketRelationships.appIdTicketsIdAssets({ params: { path: { appId, id: ticketId } } })
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
addTicketAsset(appId, ticketId, assetId) {
|
|
485
|
+
return this.sdk().then((s) => s.ticketRelationships.addTicketAsset({ appId, ticketId, assetId }));
|
|
486
|
+
}
|
|
487
|
+
removeTicketAsset(appId, ticketId, assetId) {
|
|
488
|
+
return this.sdk().then((s) => {
|
|
489
|
+
s.ticketRelationships.removeTicketAsset({ appId, ticketId, assetId, confirm: true });
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
getTicketContacts(appId, ticketId) {
|
|
493
|
+
return this.sdk().then(
|
|
494
|
+
(s) => s.ticketRelationships.appIdTicketsIdContacts({ params: { path: { appId, id: ticketId } } })
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
addTicketContact(appId, ticketId, contactUid) {
|
|
498
|
+
return this.sdk().then((s) => s.ticketRelationships.addTicketContact({ appId, ticketId, contactUid }));
|
|
499
|
+
}
|
|
500
|
+
removeTicketContact(appId, ticketId, contactUid) {
|
|
501
|
+
return this.sdk().then((s) => {
|
|
502
|
+
s.ticketRelationships.removeTicketContact({ appId, ticketId, contactUid, confirm: true });
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
//
|
|
506
|
+
// People
|
|
507
|
+
//
|
|
508
|
+
getUser(uid) {
|
|
509
|
+
return this.sdk().then((s) => s.people.peopleUid({ params: { path: { uid } } }));
|
|
510
|
+
}
|
|
511
|
+
searchUsers(body) {
|
|
512
|
+
return this.sdk().then((s) => s.people.postPeopleSearch({ body: sanitizeTo(body, USER_SEARCH_KEYS) }));
|
|
513
|
+
}
|
|
514
|
+
getGroup(groupId) {
|
|
515
|
+
return this.sdk().then((s) => s.people.groupsId({ params: { path: { id: groupId } } }));
|
|
516
|
+
}
|
|
517
|
+
searchGroups(body) {
|
|
518
|
+
return this.sdk().then((s) => s.people.searchGroups({ body: sanitizeTo(body, GROUP_SEARCH_KEYS) }));
|
|
519
|
+
}
|
|
520
|
+
getGroupMembers(groupId) {
|
|
521
|
+
return this.sdk().then((s) => s.people.groupsIdMembers({ params: { path: { id: groupId } } }));
|
|
522
|
+
}
|
|
523
|
+
//
|
|
524
|
+
// Knowledge Base
|
|
525
|
+
//
|
|
526
|
+
getKbArticle(appId, articleId) {
|
|
527
|
+
return this.sdk().then((s) => s.knowledgeBase.appIdKnowledgebaseId({ params: { path: { appId, id: articleId } } }));
|
|
528
|
+
}
|
|
529
|
+
searchKbArticles(appId, body) {
|
|
530
|
+
return this.sdk().then(async (s) => {
|
|
531
|
+
const post = s.POST;
|
|
532
|
+
const { data, error } = await post("/api/{appId}/knowledgebase/search", {
|
|
533
|
+
params: { path: { appId } },
|
|
534
|
+
body: sanitizeTo(body, ARTICLE_SEARCH_KEYS)
|
|
535
|
+
});
|
|
536
|
+
if (error) {
|
|
537
|
+
throw new Error(`KB search failed: ${JSON.stringify(error)}`);
|
|
538
|
+
}
|
|
539
|
+
return Array.isArray(data) ? data : [];
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
listKbCategories(appId) {
|
|
543
|
+
return this.sdk().then(
|
|
544
|
+
(s) => s.knowledgeBase.appIdKnowledgebaseCategories({ params: { path: { appId } } })
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
//
|
|
548
|
+
// Assets
|
|
549
|
+
//
|
|
550
|
+
getAsset(appId, assetId) {
|
|
551
|
+
return this.sdk().then((s) => s.assets.appIdAssetsId({ params: { path: { appId, id: assetId } } }));
|
|
552
|
+
}
|
|
553
|
+
searchAssets(appId, _body) {
|
|
554
|
+
return this.sdk().then((s) => s.assets.appIdAssetsFeed({ params: { path: { appId } } }));
|
|
555
|
+
}
|
|
556
|
+
listAssetStatuses(appId) {
|
|
557
|
+
return this.sdk().then((s) => s.assets.appIdAssetsStatuses({ params: { path: { appId } } }));
|
|
558
|
+
}
|
|
559
|
+
listProductModels(appId) {
|
|
560
|
+
return this.sdk().then((s) => s.assets.appIdAssetsModels({ params: { path: { appId } } }));
|
|
561
|
+
}
|
|
562
|
+
listVendors(appId) {
|
|
563
|
+
return this.sdk().then((s) => s.cmdb.appIdAssetsVendors({ params: { path: { appId } } }));
|
|
564
|
+
}
|
|
565
|
+
//
|
|
566
|
+
// CMDB
|
|
567
|
+
//
|
|
568
|
+
getConfigurationItem(appId, ciId) {
|
|
569
|
+
return this.sdk().then((s) => s.cmdb.appIdCmdbId({ params: { path: { appId, id: ciId } } }));
|
|
570
|
+
}
|
|
571
|
+
searchConfigurationItems(appId, _body) {
|
|
572
|
+
return this.sdk().then((s) => s.cmdb.appIdCmdbSearches({ params: { path: { appId } } }));
|
|
573
|
+
}
|
|
574
|
+
listCiTypes(appId) {
|
|
575
|
+
return this.sdk().then((s) => s.cmdb.appIdCmdbTypes({ params: { path: { appId } } }));
|
|
576
|
+
}
|
|
577
|
+
listCiRelationshipTypes() {
|
|
578
|
+
return this.sdk().then((s) => s.cmdb.appIdCmdbRelationshiptypes());
|
|
579
|
+
}
|
|
580
|
+
//
|
|
581
|
+
// Services
|
|
582
|
+
//
|
|
583
|
+
listServiceCatalog(appId) {
|
|
584
|
+
return this.sdk().then((s) => s.services.appIdServices({ params: { path: { appId } } }));
|
|
585
|
+
}
|
|
586
|
+
getService(appId, serviceId) {
|
|
587
|
+
return this.sdk().then((s) => s.services.appIdServicesId({ params: { path: { appId, id: serviceId } } }));
|
|
588
|
+
}
|
|
589
|
+
searchServices(appId, body) {
|
|
590
|
+
const keyword = typeof body["Keyword"] === "string" ? body["Keyword"] : "";
|
|
591
|
+
return this.sdk().then((s) => s.services.appIdServices({ params: { path: { appId } } })).then((r) => {
|
|
592
|
+
if (!Array.isArray(r)) return [];
|
|
593
|
+
if (!keyword) return r;
|
|
594
|
+
const lower = keyword.toLowerCase();
|
|
595
|
+
return r.filter((item) => {
|
|
596
|
+
const text = typeof item === "object" && item !== null ? JSON.stringify(item).toLowerCase() : "";
|
|
597
|
+
return text.includes(lower);
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
listServiceCategories(appId) {
|
|
602
|
+
return this.sdk().then((s) => s.services.appIdServicesCategories({ params: { path: { appId } } }));
|
|
603
|
+
}
|
|
604
|
+
//
|
|
605
|
+
// Projects
|
|
606
|
+
//
|
|
607
|
+
getProject(projectId) {
|
|
608
|
+
return this.sdk().then((s) => s.projects.projectsId({ params: { path: { id: projectId } } }));
|
|
609
|
+
}
|
|
610
|
+
searchProjects(_body) {
|
|
611
|
+
return this.sdk().then((s) => s.projects.projectsFeed());
|
|
612
|
+
}
|
|
613
|
+
listProjectTypes() {
|
|
614
|
+
return this.sdk().then((s) => s.projects.projectsTypes());
|
|
615
|
+
}
|
|
616
|
+
getProjectPlans(projectId) {
|
|
617
|
+
return this.sdk().then(
|
|
618
|
+
(s) => s.projects.projectsProjectIDPlansPlanID({ params: { path: { id: projectId } } })
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
getProjectIssues(projectId) {
|
|
622
|
+
return this.sdk().then(
|
|
623
|
+
(s) => s.projects.projectsProjectIdIssuesCategories({ params: { path: { id: projectId } } })
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
getProjectRisks(projectId) {
|
|
627
|
+
return this.sdk().then(
|
|
628
|
+
(s) => s.projects.projectsProjectIdRisksCategories({ params: { path: { id: projectId } } })
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
//
|
|
632
|
+
// Time
|
|
633
|
+
//
|
|
634
|
+
listTimeTypes() {
|
|
635
|
+
return this.sdk().then((s) => s.time.timeTypes());
|
|
636
|
+
}
|
|
637
|
+
getMyTimeEntries(_startDate, _endDate) {
|
|
638
|
+
return this.sdk().then((s) => s.time.timeId({ params: { path: { id: 0 } } }));
|
|
639
|
+
}
|
|
640
|
+
//
|
|
641
|
+
// Reference Data
|
|
642
|
+
//
|
|
643
|
+
listAccounts(_appId) {
|
|
644
|
+
return this.sdk().then((s) => s.referenceData.accounts());
|
|
645
|
+
}
|
|
646
|
+
getAccount(accountId) {
|
|
647
|
+
return this.sdk().then((s) => s.referenceData.accountsId({ params: { path: { id: accountId } } }));
|
|
648
|
+
}
|
|
649
|
+
listLocations() {
|
|
650
|
+
return this.sdk().then((s) => s.referenceData.locations());
|
|
651
|
+
}
|
|
652
|
+
listFunctionalRoles() {
|
|
653
|
+
return this.sdk().then((s) => s.referenceData.securityrolesPermissions());
|
|
654
|
+
}
|
|
655
|
+
listCustomAttributes(_componentId, _appId, _associatedTypeId) {
|
|
656
|
+
return this.sdk().then((s) => s.referenceData.attributesCustom());
|
|
657
|
+
}
|
|
658
|
+
listTicketStatuses(appId) {
|
|
659
|
+
return this.sdk().then((s) => s.referenceData.appIdTicketsStatuses({ params: { path: { appId } } }));
|
|
660
|
+
}
|
|
661
|
+
//
|
|
662
|
+
// Mutations
|
|
663
|
+
//
|
|
664
|
+
createTicket(appId, body, _notifyRequestor, _notifyResponsible) {
|
|
665
|
+
return this.sdk().then((s) => s.tickets.createTicket({ appId, body }));
|
|
666
|
+
}
|
|
667
|
+
updateTicket(appId, ticketId, body, _notifyRequestor, _notifyResponsible, _comments, _isPrivate) {
|
|
668
|
+
return this.sdk().then((s) => s.tickets.updateTicket({ appId, ticketId, body }));
|
|
669
|
+
}
|
|
670
|
+
addTicketComment(appId, ticketId, body, _isPrivate, _notifyRequestor, _notifyResponsible) {
|
|
671
|
+
return this.sdk().then((s) => s.tickets.addTicketComment({ appId, ticketId, body: { Body: body } }));
|
|
672
|
+
}
|
|
673
|
+
createKbArticle(appId, body) {
|
|
674
|
+
return this.sdk().then((s) => s.knowledgeBase.createArticle({ appId, body }));
|
|
675
|
+
}
|
|
676
|
+
updateKbArticle(appId, articleId, body) {
|
|
677
|
+
return this.sdk().then((s) => s.knowledgeBase.updateArticle({ appId, articleId, body }));
|
|
678
|
+
}
|
|
679
|
+
createProjectIssue(_projectId, body) {
|
|
680
|
+
return this.sdk().then((s) => s.projects.createIssue({ body }));
|
|
681
|
+
}
|
|
682
|
+
createProjectRisk(_projectId, body) {
|
|
683
|
+
return this.sdk().then((s) => s.projects.createRisk({ body }));
|
|
684
|
+
}
|
|
685
|
+
//
|
|
686
|
+
// Delete mutations (confirm:true required for all)
|
|
687
|
+
//
|
|
688
|
+
deleteAsset(appId, assetId) {
|
|
689
|
+
return this.sdk().then((s) => s.assets.deleteAsset({ appId, assetId, confirm: true }));
|
|
690
|
+
}
|
|
691
|
+
deleteConfigurationItem(appId, ciId) {
|
|
692
|
+
return this.sdk().then((s) => s.cmdb.deleteConfigurationItem({ appId, configurationItemId: ciId, confirm: true }));
|
|
693
|
+
}
|
|
694
|
+
deleteService(appId, serviceId) {
|
|
695
|
+
return this.sdk().then((s) => s.services.deleteService({ appId, serviceId, confirm: true }));
|
|
696
|
+
}
|
|
697
|
+
deleteServiceCategory(appId, categoryId) {
|
|
698
|
+
return this.sdk().then((s) => s.services.deleteServiceCategory({ appId, categoryId, confirm: true }));
|
|
699
|
+
}
|
|
700
|
+
deleteTimeEntry(timeEntryId) {
|
|
701
|
+
return this.sdk().then((s) => s.time.deleteTimeEntry({ timeEntryId, confirm: true }));
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
// src/services/teamdynamix/watch.store.ts
|
|
708
|
+
var watch_store_exports = {};
|
|
709
|
+
__export(watch_store_exports, {
|
|
710
|
+
LEDGER_VERSION: () => LEDGER_VERSION,
|
|
711
|
+
LedgerCorruptError: () => LedgerCorruptError,
|
|
712
|
+
MAX_NOTE_LENGTH: () => MAX_NOTE_LENGTH,
|
|
713
|
+
MAX_OBSERVATIONS: () => MAX_OBSERVATIONS,
|
|
714
|
+
defaultLedgerPath: () => defaultLedgerPath,
|
|
715
|
+
emptyLedger: () => emptyLedger,
|
|
716
|
+
loadLedger: () => loadLedger,
|
|
717
|
+
saveLedger: () => saveLedger
|
|
718
|
+
});
|
|
719
|
+
import { promises as fs } from "fs";
|
|
720
|
+
import path from "path";
|
|
721
|
+
function defaultLedgerPath() {
|
|
722
|
+
return process.env["TDX_WATCH_LEDGER"] ?? path.join(process.cwd(), ".tdx-watch-ledger.json");
|
|
723
|
+
}
|
|
724
|
+
async function loadLedger(filePath) {
|
|
725
|
+
let raw;
|
|
726
|
+
try {
|
|
727
|
+
raw = await fs.readFile(filePath, "utf8");
|
|
728
|
+
} catch (cause) {
|
|
729
|
+
throw cause instanceof Error ? cause : new Error(String(cause));
|
|
730
|
+
}
|
|
731
|
+
try {
|
|
732
|
+
const parsed = JSON.parse(raw);
|
|
733
|
+
if (!Array.isArray(parsed.active) || !Array.isArray(parsed.archived)) {
|
|
734
|
+
throw new Error("missing active/archived arrays");
|
|
735
|
+
}
|
|
736
|
+
parsed.pendingTriage ??= [];
|
|
737
|
+
return parsed;
|
|
738
|
+
} catch (cause) {
|
|
739
|
+
throw new LedgerCorruptError(filePath, cause);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
async function saveLedger(filePath, ledger) {
|
|
743
|
+
try {
|
|
744
|
+
await fs.access(filePath);
|
|
745
|
+
await loadLedger(filePath);
|
|
746
|
+
} catch (cause) {
|
|
747
|
+
if (cause instanceof LedgerCorruptError) throw cause;
|
|
748
|
+
}
|
|
749
|
+
ledger.version = LEDGER_VERSION;
|
|
750
|
+
const dir = path.dirname(filePath);
|
|
751
|
+
await fs.mkdir(dir, { recursive: true });
|
|
752
|
+
const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
753
|
+
await fs.writeFile(tmp, `${JSON.stringify(ledger, null, 2)}
|
|
754
|
+
`, "utf8");
|
|
755
|
+
await fs.rename(tmp, filePath);
|
|
756
|
+
}
|
|
757
|
+
function emptyLedger() {
|
|
758
|
+
return { active: [], archived: [], pendingTriage: [], sweepMeta: {} };
|
|
759
|
+
}
|
|
760
|
+
var LEDGER_VERSION, MAX_NOTE_LENGTH, MAX_OBSERVATIONS, LedgerCorruptError;
|
|
761
|
+
var init_watch_store = __esm({
|
|
762
|
+
"src/services/teamdynamix/watch.store.ts"() {
|
|
763
|
+
"use strict";
|
|
764
|
+
LEDGER_VERSION = 1;
|
|
765
|
+
MAX_NOTE_LENGTH = 4e3;
|
|
766
|
+
MAX_OBSERVATIONS = 20;
|
|
767
|
+
LedgerCorruptError = class extends Error {
|
|
768
|
+
constructor(path2, cause) {
|
|
769
|
+
super(
|
|
770
|
+
`Watch ledger at ${path2} is corrupt or unreadable; refusing to read or write it. Fix or remove the file manually (state preservation is deliberate). Cause: ${String(cause)}`
|
|
771
|
+
);
|
|
772
|
+
this.name = "LedgerCorruptError";
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
// src/services/teamdynamix/watch.service.ts
|
|
779
|
+
var watch_service_exports = {};
|
|
780
|
+
__export(watch_service_exports, {
|
|
781
|
+
WorkspaceWatchService: () => WorkspaceWatchService
|
|
782
|
+
});
|
|
783
|
+
function redact(text) {
|
|
784
|
+
return text.replace(/[\w.+-]+@[\w-]+\.[\w.-]+/g, "[redacted-email]").replace(/\b(?:\d{3}[-.\s]?){2}\d{4}\b/g, "[redacted-phone]");
|
|
785
|
+
}
|
|
786
|
+
function cap(text, max) {
|
|
787
|
+
if (text.length <= max) return text;
|
|
788
|
+
return `${text.slice(0, Math.max(0, max - 1))}\u2026`;
|
|
789
|
+
}
|
|
790
|
+
function sanitizeForReport(value) {
|
|
791
|
+
if (typeof value === "string") return cap(redact(value), TITLE_MAX_CHARS);
|
|
792
|
+
return value;
|
|
793
|
+
}
|
|
794
|
+
function computeHash(entries) {
|
|
795
|
+
const perEntryReplies = {};
|
|
796
|
+
let replyCount = 0;
|
|
797
|
+
let lastEntryId = 0;
|
|
798
|
+
for (const e of entries) {
|
|
799
|
+
const id = e.ID ?? 0;
|
|
800
|
+
const rc = e.RepliesCount ?? 0;
|
|
801
|
+
perEntryReplies[String(id)] = rc;
|
|
802
|
+
replyCount += rc;
|
|
803
|
+
lastEntryId = Math.max(lastEntryId, id);
|
|
804
|
+
}
|
|
805
|
+
return { lastEntryId, entryCount: entries.length, replyCount, perEntryReplies };
|
|
806
|
+
}
|
|
807
|
+
function hashGrewHiddenReplies(prev, entries) {
|
|
808
|
+
for (const e of entries) {
|
|
809
|
+
const id = String(e.ID ?? 0);
|
|
810
|
+
const now = e.RepliesCount ?? 0;
|
|
811
|
+
const before = prev.perEntryReplies[id];
|
|
812
|
+
if (before !== void 0 && now > before) return true;
|
|
813
|
+
}
|
|
814
|
+
return false;
|
|
815
|
+
}
|
|
816
|
+
var REPORT_MAX_CHARS, TITLE_MAX_CHARS, US_UIDS_ENV, GROUP_IDS_ENV, STATUS_IDS_ENV, DEFAULT_MAX_PENDING, UNASSIGNED_SENTINELS, WorkspaceWatchService;
|
|
817
|
+
var init_watch_service = __esm({
|
|
818
|
+
"src/services/teamdynamix/watch.service.ts"() {
|
|
819
|
+
"use strict";
|
|
820
|
+
init_watch_store();
|
|
821
|
+
init_client_factory();
|
|
822
|
+
REPORT_MAX_CHARS = 8e3;
|
|
823
|
+
TITLE_MAX_CHARS = 200;
|
|
824
|
+
US_UIDS_ENV = "TEAMDYNAMIX_US_UIDS";
|
|
825
|
+
GROUP_IDS_ENV = "TEAMDYNAMIX_TICKET_GROUP_IDS";
|
|
826
|
+
STATUS_IDS_ENV = "TEAMDYNAMIX_WATCH_STATUS_IDS";
|
|
827
|
+
DEFAULT_MAX_PENDING = 25;
|
|
828
|
+
UNASSIGNED_SENTINELS = /* @__PURE__ */ new Set(["", "unassigned"]);
|
|
829
|
+
WorkspaceWatchService = class {
|
|
830
|
+
constructor(ledger, ledgerPath, client, opts = {}) {
|
|
831
|
+
this.ledger = ledger;
|
|
832
|
+
this.ledgerPath = ledgerPath;
|
|
833
|
+
this.client = client;
|
|
834
|
+
const envUids = (process.env[US_UIDS_ENV] ?? "").split(/[,\s]+/).filter(Boolean);
|
|
835
|
+
this.usUids = /* @__PURE__ */ new Set([...envUids, ...opts.usUids ?? []]);
|
|
836
|
+
this.autoObserve = opts.autoObserve ?? process.env["TEAMDYNAMIX_AUTO_OBSERVE"] === "true";
|
|
837
|
+
}
|
|
838
|
+
ledger;
|
|
839
|
+
client;
|
|
840
|
+
ledgerPath;
|
|
841
|
+
usUids;
|
|
842
|
+
autoObserve;
|
|
843
|
+
usUidsFor() {
|
|
844
|
+
const ledgerUids = this.ledger.sweepMeta.usUids ?? [];
|
|
845
|
+
return /* @__PURE__ */ new Set([...this.usUids, ...ledgerUids]);
|
|
846
|
+
}
|
|
847
|
+
groupIds() {
|
|
848
|
+
return this.ledger.sweepMeta.groupIds ?? parseIdListEnv(process.env[GROUP_IDS_ENV]);
|
|
849
|
+
}
|
|
850
|
+
statusIds() {
|
|
851
|
+
return this.ledger.sweepMeta.statusIds ?? parseIdListEnv(process.env[STATUS_IDS_ENV]);
|
|
852
|
+
}
|
|
853
|
+
maxPending() {
|
|
854
|
+
return this.ledger.sweepMeta.maxPending ?? DEFAULT_MAX_PENDING;
|
|
855
|
+
}
|
|
856
|
+
pushPending(item) {
|
|
857
|
+
const queue = this.ledger.pendingTriage ??= [];
|
|
858
|
+
if (queue.some((p) => p.ticketId === item.ticketId)) return "deduped";
|
|
859
|
+
if (queue.length >= this.maxPending()) return "full";
|
|
860
|
+
queue.push(item);
|
|
861
|
+
return "queued";
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Cheap sweep (stage 1 only): one queue search per app, client-side team
|
|
865
|
+
* filtering (GroupIDs is not applied server-side on queue searches), stateHash
|
|
866
|
+
* freshness, new-unassigned detection, and pendingTriage queue maintenance.
|
|
867
|
+
* Deep fetches / reply expansion are the agent's job via check() / triage.
|
|
868
|
+
*/
|
|
869
|
+
async sweep() {
|
|
870
|
+
const result = {
|
|
871
|
+
swept: 0,
|
|
872
|
+
changedQueued: 0,
|
|
873
|
+
newUnassignedQueued: 0,
|
|
874
|
+
deduped: 0,
|
|
875
|
+
queueFull: 0,
|
|
876
|
+
unassigned: []
|
|
877
|
+
};
|
|
878
|
+
const rows = this.ledger.active;
|
|
879
|
+
const byApp = /* @__PURE__ */ new Map();
|
|
880
|
+
for (const row of rows) {
|
|
881
|
+
const list = byApp.get(row.appId) ?? [];
|
|
882
|
+
list.push(row);
|
|
883
|
+
byApp.set(row.appId, list);
|
|
884
|
+
}
|
|
885
|
+
const appIds = /* @__PURE__ */ new Set([...byApp.keys(), ...parseIdListEnv(process.env["TEAMDYNAMIX_WATCH_APP_IDS"])]);
|
|
886
|
+
const groupFilter = this.groupIds();
|
|
887
|
+
const statusFilter = this.statusIds();
|
|
888
|
+
const queue = this.ledger.pendingTriage ??= [];
|
|
889
|
+
const ledgeredIds = new Set(rows.map((r) => r.id));
|
|
890
|
+
for (const appId of appIds) {
|
|
891
|
+
const appRows = byApp.get(appId) ?? [];
|
|
892
|
+
let page;
|
|
893
|
+
try {
|
|
894
|
+
page = await this.client.searchTickets(appId, { MaxResults: 500 });
|
|
895
|
+
} catch {
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
for (const t of page) {
|
|
899
|
+
const id = Number(t["ID"]);
|
|
900
|
+
if (!Number.isFinite(id)) continue;
|
|
901
|
+
if (groupFilter.length > 0) {
|
|
902
|
+
const gid = Number(t["ResponsibleGroupID"]);
|
|
903
|
+
if (!groupFilter.includes(gid)) continue;
|
|
904
|
+
}
|
|
905
|
+
if (statusFilter.length > 0 && !statusFilter.includes(Number(t["StatusID"]))) continue;
|
|
906
|
+
result.swept += 1;
|
|
907
|
+
const row = appRows.find((r) => r.id === id);
|
|
908
|
+
const modified = String(t["ModifiedDate"] ?? "");
|
|
909
|
+
if (row && row.stateHash.modified !== "" && modified !== row.stateHash.modified) {
|
|
910
|
+
const outcome = this.pushPending({ ticketId: id, appId, reason: "changed", at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
911
|
+
if (outcome === "queued") result.changedQueued += 1;
|
|
912
|
+
else if (outcome === "deduped") result.deduped += 1;
|
|
913
|
+
else result.queueFull += 1;
|
|
914
|
+
}
|
|
915
|
+
if (!ledgeredIds.has(id)) {
|
|
916
|
+
const responsible = String(t["ResponsibleUid"] ?? "").trim();
|
|
917
|
+
if (UNASSIGNED_SENTINELS.has(responsible.toLowerCase())) {
|
|
918
|
+
result.unassigned.push(id);
|
|
919
|
+
const outcome = this.pushPending({
|
|
920
|
+
ticketId: id,
|
|
921
|
+
appId,
|
|
922
|
+
reason: "new-unassigned",
|
|
923
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
924
|
+
detail: `group=${String(t["ResponsibleGroupName"] ?? "")}`
|
|
925
|
+
});
|
|
926
|
+
if (outcome === "queued") result.newUnassignedQueued += 1;
|
|
927
|
+
else if (outcome === "deduped") result.deduped += 1;
|
|
928
|
+
else result.queueFull += 1;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
for (const row of appRows) {
|
|
933
|
+
const t = page.find((x) => Number(x["ID"]) === row.id);
|
|
934
|
+
if (t) row.stateHash.modified = String(t["ModifiedDate"] ?? row.stateHash.modified);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
this.ledger.sweepMeta.lastSweep = (/* @__PURE__ */ new Date()).toISOString();
|
|
938
|
+
await this.persist();
|
|
939
|
+
return result;
|
|
940
|
+
}
|
|
941
|
+
pendingTriage() {
|
|
942
|
+
return this.ledger.pendingTriage ?? [];
|
|
943
|
+
}
|
|
944
|
+
async markTriaged(ticketId) {
|
|
945
|
+
const queue = this.ledger.pendingTriage ?? [];
|
|
946
|
+
const before = queue.length;
|
|
947
|
+
this.ledger.pendingTriage = queue.filter((p) => p.ticketId !== ticketId);
|
|
948
|
+
await this.persist();
|
|
949
|
+
return { removed: this.ledger.pendingTriage.length < before };
|
|
950
|
+
}
|
|
951
|
+
async persist() {
|
|
952
|
+
await saveLedger(this.ledgerPath, this.ledger);
|
|
953
|
+
this.ledger = await loadLedger(this.ledgerPath);
|
|
954
|
+
}
|
|
955
|
+
findRow(id) {
|
|
956
|
+
return this.ledger.active.find((r) => r.id === id);
|
|
957
|
+
}
|
|
958
|
+
async register(input) {
|
|
959
|
+
const existing = this.findRow(input.id);
|
|
960
|
+
if (existing) {
|
|
961
|
+
existing.kind = input.kind;
|
|
962
|
+
if (input.title !== void 0) existing.title = cap(redact(input.title), TITLE_MAX_CHARS);
|
|
963
|
+
if (input.district !== void 0) existing.district = input.district;
|
|
964
|
+
if (input.nextAction !== void 0) existing.nextAction = input.nextAction;
|
|
965
|
+
if (input.ball !== void 0) {
|
|
966
|
+
existing.ball = input.ball;
|
|
967
|
+
existing.ballSource = "manual";
|
|
968
|
+
}
|
|
969
|
+
await this.persist();
|
|
970
|
+
return existing;
|
|
971
|
+
}
|
|
972
|
+
const row = {
|
|
973
|
+
id: input.id,
|
|
974
|
+
appId: input.appId,
|
|
975
|
+
title: cap(redact(input.title ?? ""), TITLE_MAX_CHARS),
|
|
976
|
+
district: input.district ?? "",
|
|
977
|
+
kind: input.kind,
|
|
978
|
+
status: "",
|
|
979
|
+
stateHash: { modified: "", lastEntryId: 0, entryCount: 0, replyCount: 0, perEntryReplies: {} },
|
|
980
|
+
ball: input.ball ?? "us",
|
|
981
|
+
ballSource: input.ball !== void 0 ? "manual" : "auto",
|
|
982
|
+
nextAction: input.nextAction ?? "",
|
|
983
|
+
lastChecked: "",
|
|
984
|
+
memory: { notes: [], observations: [] }
|
|
985
|
+
};
|
|
986
|
+
this.ledger.active.push(row);
|
|
987
|
+
await this.persist();
|
|
988
|
+
return row;
|
|
989
|
+
}
|
|
990
|
+
async archive(input) {
|
|
991
|
+
const idx = this.ledger.active.findIndex((r) => r.id === input.id);
|
|
992
|
+
if (idx === -1) return { archived: false };
|
|
993
|
+
const [row] = this.ledger.active.splice(idx, 1);
|
|
994
|
+
this.ledger.archived.push({ ...row, outcome: input.outcome });
|
|
995
|
+
await this.persist();
|
|
996
|
+
return { archived: true };
|
|
997
|
+
}
|
|
998
|
+
async status() {
|
|
999
|
+
const active = this.ledger.active;
|
|
1000
|
+
const oldestChecked = active.map((r) => r.lastChecked).filter(Boolean).sort()[0] ?? "";
|
|
1001
|
+
return {
|
|
1002
|
+
activeCount: active.length,
|
|
1003
|
+
archivedCount: this.ledger.archived.length,
|
|
1004
|
+
ballUs: active.filter((r) => r.ball === "us").length,
|
|
1005
|
+
ballThem: active.filter((r) => r.ball === "them").length,
|
|
1006
|
+
oldestChecked
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
async check(input = {}) {
|
|
1010
|
+
const report = { checked: 0, deltas: [], errors: [] };
|
|
1011
|
+
const rows = this.ledger.active.filter((r) => input.tickets ? input.tickets.includes(r.id) : true);
|
|
1012
|
+
const byApp = /* @__PURE__ */ new Map();
|
|
1013
|
+
for (const row of rows) {
|
|
1014
|
+
const list = byApp.get(row.appId) ?? [];
|
|
1015
|
+
list.push(row);
|
|
1016
|
+
byApp.set(row.appId, list);
|
|
1017
|
+
}
|
|
1018
|
+
for (const [appId, appRows] of byApp) {
|
|
1019
|
+
let sweep;
|
|
1020
|
+
try {
|
|
1021
|
+
sweep = await this.client.searchTickets(appId, { MaxResults: 500 });
|
|
1022
|
+
} catch (cause) {
|
|
1023
|
+
report.errors.push(`sweep failed for appId ${appId}: ${String(cause)}`);
|
|
1024
|
+
continue;
|
|
1025
|
+
}
|
|
1026
|
+
const sweepById = new Map(sweep.map((t) => [Number(t["ID"]), t]));
|
|
1027
|
+
for (const row of appRows) {
|
|
1028
|
+
report.checked += 1;
|
|
1029
|
+
const sweepTicket = sweepById.get(row.id);
|
|
1030
|
+
const sweepModified = sweepTicket ? String(sweepTicket["ModifiedDate"] ?? "") : "";
|
|
1031
|
+
const seeded = row.stateHash.modified !== "";
|
|
1032
|
+
const needsDeep = !seeded || sweepModified !== row.stateHash.modified;
|
|
1033
|
+
if (seeded && !needsDeep) continue;
|
|
1034
|
+
const classes = /* @__PURE__ */ new Set();
|
|
1035
|
+
try {
|
|
1036
|
+
const t = sweepTicket ?? await this.client.getTicket(appId, row.id);
|
|
1037
|
+
const feed = await this.client.getTicketFeed(appId, row.id);
|
|
1038
|
+
const modified = String(t["ModifiedDate"] ?? "");
|
|
1039
|
+
const status = String(t["Status"] ?? t["StatusID"] ?? "");
|
|
1040
|
+
const isOnHold = Boolean(t["IsOnHold"]);
|
|
1041
|
+
if (seeded && status !== row.status) classes.add("status");
|
|
1042
|
+
if (seeded && Boolean(t["IsOnHold"]) !== row.status.startsWith("hold:")) {
|
|
1043
|
+
}
|
|
1044
|
+
if (seeded && modified !== row.stateHash.modified) classes.add("new-entry");
|
|
1045
|
+
const prevHash = row.stateHash;
|
|
1046
|
+
const newHash = { modified, ...computeHash(feed) };
|
|
1047
|
+
if (seeded && hashGrewHiddenReplies(prevHash, feed)) classes.add("hidden-reply");
|
|
1048
|
+
if (seeded && newHash.entryCount > prevHash.entryCount) classes.add("new-entry");
|
|
1049
|
+
if (seeded && isOnHold !== row.wasOnHold) {
|
|
1050
|
+
classes.add("hold-window");
|
|
1051
|
+
}
|
|
1052
|
+
const slaDate = t["SlaCompleteByDate"];
|
|
1053
|
+
if (seeded && typeof slaDate === "string" && slaDate !== row.slaDate) {
|
|
1054
|
+
classes.add("sla");
|
|
1055
|
+
row.slaDate = slaDate;
|
|
1056
|
+
}
|
|
1057
|
+
row.wasOnHold = isOnHold;
|
|
1058
|
+
if (row.ballSource === "auto" && feed.length > 0) {
|
|
1059
|
+
const last = feed[0];
|
|
1060
|
+
const author = String(last?.CreatedUid ?? "");
|
|
1061
|
+
if (author) row.ball = this.usUidsFor().has(author) ? "them" : "us";
|
|
1062
|
+
}
|
|
1063
|
+
row.stateHash = newHash;
|
|
1064
|
+
row.status = status;
|
|
1065
|
+
if (typeof t["Title"] === "string" && row.title === "") {
|
|
1066
|
+
row.title = cap(redact(t["Title"]), TITLE_MAX_CHARS);
|
|
1067
|
+
}
|
|
1068
|
+
row.lastChecked = (/* @__PURE__ */ new Date()).toISOString();
|
|
1069
|
+
if (this.autoObserve) {
|
|
1070
|
+
row.memory.observations.push({ at: row.lastChecked, seen: { status, modified } });
|
|
1071
|
+
if (row.memory.observations.length > MAX_OBSERVATIONS) {
|
|
1072
|
+
row.memory.observations = row.memory.observations.slice(-MAX_OBSERVATIONS);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
if (classes.size > 0) {
|
|
1076
|
+
report.deltas.push({
|
|
1077
|
+
id: row.id,
|
|
1078
|
+
appId,
|
|
1079
|
+
classes: [...classes],
|
|
1080
|
+
status: sanitizeForReport(status),
|
|
1081
|
+
modified,
|
|
1082
|
+
ball: row.ball
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
} catch (cause) {
|
|
1086
|
+
report.errors.push(`deep fetch failed for ticket ${row.id}: ${String(cause)}`);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
this.ledger.sweepMeta.lastSweep = (/* @__PURE__ */ new Date()).toISOString();
|
|
1091
|
+
await this.persist();
|
|
1092
|
+
return this.capReport(report);
|
|
1093
|
+
}
|
|
1094
|
+
capReport(report) {
|
|
1095
|
+
let json = JSON.stringify(report);
|
|
1096
|
+
if (json.length > REPORT_MAX_CHARS) {
|
|
1097
|
+
report.deltas = report.deltas.slice(0, Math.max(1, Math.floor(report.deltas.length / 2)));
|
|
1098
|
+
json = JSON.stringify(report);
|
|
1099
|
+
if (json.length > REPORT_MAX_CHARS) report.deltas = [];
|
|
1100
|
+
}
|
|
1101
|
+
return report;
|
|
1102
|
+
}
|
|
1103
|
+
//
|
|
1104
|
+
// Notes (local-only memory; never written to TDX)
|
|
1105
|
+
//
|
|
1106
|
+
async notesAdd(input) {
|
|
1107
|
+
const row = this.rowForNote(input.appId, input.ticketId);
|
|
1108
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1109
|
+
const note = {
|
|
1110
|
+
id: `n-${now}-${Math.random().toString(36).slice(2, 8)}`,
|
|
1111
|
+
text: cap(redact(input.text), MAX_NOTE_LENGTH),
|
|
1112
|
+
createdAt: now,
|
|
1113
|
+
updatedAt: now
|
|
1114
|
+
};
|
|
1115
|
+
row.memory.notes.unshift(note);
|
|
1116
|
+
await this.persist();
|
|
1117
|
+
return note;
|
|
1118
|
+
}
|
|
1119
|
+
async notesUpdate(input) {
|
|
1120
|
+
const { row, note } = this.noteById(input.noteId);
|
|
1121
|
+
note.text = cap(redact(input.text), MAX_NOTE_LENGTH);
|
|
1122
|
+
note.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1123
|
+
await this.persist();
|
|
1124
|
+
return note;
|
|
1125
|
+
}
|
|
1126
|
+
async notesDelete(input) {
|
|
1127
|
+
const { row } = this.noteById(input.noteId);
|
|
1128
|
+
row.memory.notes = row.memory.notes.filter((n) => n.id !== input.noteId);
|
|
1129
|
+
await this.persist();
|
|
1130
|
+
return { deleted: true };
|
|
1131
|
+
}
|
|
1132
|
+
async notesList(input) {
|
|
1133
|
+
const rows = this.ledger.active.filter(
|
|
1134
|
+
(r) => (input.appId === void 0 || r.appId === input.appId) && (input.ticketId === void 0 || r.id === input.ticketId)
|
|
1135
|
+
);
|
|
1136
|
+
return rows.flatMap((r) => r.memory.notes);
|
|
1137
|
+
}
|
|
1138
|
+
rowForNote(appId, ticketId) {
|
|
1139
|
+
const row = this.ledger.active.find((r) => r.id === ticketId && r.appId === appId);
|
|
1140
|
+
if (!row) throw new Error(`No active watch row for ticket ${ticketId} in app ${appId}; register it first.`);
|
|
1141
|
+
return row;
|
|
1142
|
+
}
|
|
1143
|
+
noteById(noteId) {
|
|
1144
|
+
for (const row of [...this.ledger.active, ...this.ledger.archived]) {
|
|
1145
|
+
const note = row.memory.notes.find((n) => n.id === noteId);
|
|
1146
|
+
if (note) return { row, note };
|
|
1147
|
+
}
|
|
1148
|
+
throw new Error(`Note ${noteId} not found.`);
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
// src/services/teamdynamix/client.service.ts
|
|
1155
|
+
var client_service_exports = {};
|
|
1156
|
+
__export(client_service_exports, {
|
|
1157
|
+
UnifiedTeamDynamixClient: () => UnifiedTeamDynamixClient,
|
|
1158
|
+
assertDeleteToolsEnabled: () => assertDeleteToolsEnabled,
|
|
1159
|
+
assertWriteToolsEnabled: () => assertWriteToolsEnabled,
|
|
1160
|
+
createConfiguredTeamDynamixClient: () => createConfiguredTeamDynamixClient
|
|
1161
|
+
});
|
|
1162
|
+
var init_client_service = __esm({
|
|
1163
|
+
"src/services/teamdynamix/client.service.ts"() {
|
|
1164
|
+
"use strict";
|
|
1165
|
+
init_client_factory();
|
|
1166
|
+
}
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
// src/index.ts
|
|
1170
|
+
init_config();
|
|
1171
|
+
init_constants();
|
|
1172
|
+
import { McpServer as McpServer2 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
1173
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
202
1174
|
|
|
203
1175
|
// src/resources/teamdynamix.resources.ts
|
|
1176
|
+
init_config();
|
|
204
1177
|
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
205
1178
|
|
|
206
1179
|
// src/services/teamdynamix/core.service.ts
|
|
1180
|
+
init_constants();
|
|
207
1181
|
function redactTeamDynamixConfig(config) {
|
|
208
1182
|
return {
|
|
209
1183
|
baseUrl: config.baseUrl ?? null,
|
|
@@ -223,6 +1197,8 @@ function redactTeamDynamixConfig(config) {
|
|
|
223
1197
|
}
|
|
224
1198
|
|
|
225
1199
|
// src/tools/teamdynamix.domain-gateways.tools.ts
|
|
1200
|
+
init_config();
|
|
1201
|
+
init_constants();
|
|
226
1202
|
import { z as z4 } from "zod";
|
|
227
1203
|
|
|
228
1204
|
// src/schemas/teamdynamix/index.ts
|
|
@@ -302,22 +1278,39 @@ var TicketCommentSchema = z3.object({
|
|
|
302
1278
|
});
|
|
303
1279
|
var UserSearchSchema = z3.object({
|
|
304
1280
|
SearchText: z3.string().max(500).optional().describe("Name, username, or email to search for."),
|
|
1281
|
+
AccountIDs: z3.array(z3.number().int()).optional().describe("Filter by account IDs (default account only)."),
|
|
1282
|
+
AlternateID: z3.string().optional().describe("Filter by alternate ID."),
|
|
1283
|
+
AppName: z3.string().optional().describe("Filter by system-defined application name."),
|
|
1284
|
+
AuthenticationUserName: z3.string().optional().describe("Exact-match authentication username (max one result)."),
|
|
1285
|
+
ExternalID: z3.string().optional().describe("Filter by external ID."),
|
|
305
1286
|
IsActive: z3.boolean().optional().describe("Filter by active (true) or inactive (false) users."),
|
|
1287
|
+
IsConfidential: z3.boolean().optional().describe("Filter by confidential status."),
|
|
306
1288
|
IsEmployee: z3.boolean().optional().describe("Filter to employees only."),
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
1289
|
+
MaxResults: z3.number().int().min(1).max(1e3).optional().describe("Maximum results (1-1000)."),
|
|
1290
|
+
PhoneNumber: z3.string().optional().describe("Filter by phone number."),
|
|
1291
|
+
ReferenceIDs: z3.array(z3.string()).optional().describe("Filter by user reference IDs (GUIDs)."),
|
|
1292
|
+
SecurityRoleID: z3.number().int().optional().describe("Filter by security role ID."),
|
|
1293
|
+
UserName: z3.string().optional().describe("Filter by username.")
|
|
1294
|
+
}).strict();
|
|
310
1295
|
var GroupSearchSchema = z3.object({
|
|
311
1296
|
NameLike: z3.string().max(500).optional().describe("Partial group name to search."),
|
|
312
1297
|
IsActive: z3.boolean().optional().describe("Filter by active (true) or inactive (false) groups."),
|
|
313
|
-
|
|
314
|
-
|
|
1298
|
+
AssociatedAppID: z3.number().int().positive().optional().describe("Filter by associated application ID."),
|
|
1299
|
+
HasAppID: z3.boolean().optional().describe("Filter to groups with (true) or without (false) an associated application."),
|
|
1300
|
+
HasSystemAppName: z3.boolean().optional().describe("Filter to groups with (true) or without (false) a system app name.")
|
|
1301
|
+
}).strict();
|
|
315
1302
|
var KbArticleSearchSchema = z3.object({
|
|
316
1303
|
SearchText: z3.string().max(500).optional().describe("Full-text search within articles."),
|
|
1304
|
+
AuthorUID: z3.string().uuid().optional().describe("Filter by author GUID."),
|
|
317
1305
|
CategoryID: z3.number().int().positive().optional().describe("Filter by KB category ID."),
|
|
1306
|
+
CustomAttributes: z3.array(z3.record(z3.string(), z3.unknown())).optional().describe("Filter by custom attributes."),
|
|
1307
|
+
IncludeArticleBodies: z3.boolean().optional().describe("Include article bodies in results."),
|
|
1308
|
+
IncludeShortcuts: z3.boolean().optional().describe("Include shortcuts in results."),
|
|
1309
|
+
IsPublic: z3.boolean().optional().describe("Filter by public visibility."),
|
|
318
1310
|
IsPublished: z3.boolean().optional().describe("Filter to published articles only."),
|
|
319
|
-
|
|
320
|
-
|
|
1311
|
+
ReturnCount: z3.number().int().min(1).max(500).optional().describe("Maximum results (1-500)."),
|
|
1312
|
+
Status: z3.number().int().optional().describe("Filter by article status ID.")
|
|
1313
|
+
}).strict();
|
|
321
1314
|
var AssetSearchSchema = z3.object({
|
|
322
1315
|
SerialLike: z3.string().max(200).optional().describe("Partial serial number to match."),
|
|
323
1316
|
TagLike: z3.string().max(200).optional().describe("Partial asset tag to match."),
|
|
@@ -430,424 +1423,11 @@ var TeamDynamixUserSchema = z3.object({
|
|
|
430
1423
|
var TeamDynamixListResponseSchema = z3.array(z3.record(z3.string(), z3.unknown())).describe("Array of TeamDynamix entities");
|
|
431
1424
|
var TeamDynamixSingleResponseSchema = z3.record(z3.string(), z3.unknown()).describe("Single TeamDynamix entity response");
|
|
432
1425
|
|
|
433
|
-
// src/
|
|
434
|
-
|
|
435
|
-
import { createRequire } from "module";
|
|
436
|
-
import { dirname, resolve } from "path";
|
|
437
|
-
import { fileURLToPath } from "url";
|
|
438
|
-
import { createTeamDynamixClient, loginWithPassword, loginWithServiceAccount } from "@voxslopuli/teamdynamix-ts";
|
|
439
|
-
var cachedSpecPath;
|
|
440
|
-
function resolveSdkSpecPath() {
|
|
441
|
-
const override = process.env["TEAMDYNAMIX_SPEC_PATH"]?.trim();
|
|
442
|
-
if (override) return override;
|
|
443
|
-
if (cachedSpecPath) return cachedSpecPath;
|
|
444
|
-
try {
|
|
445
|
-
const require2 = createRequire(fileURLToPath(import.meta.url));
|
|
446
|
-
const entryPath = require2.resolve("@voxslopuli/teamdynamix-ts");
|
|
447
|
-
const pkgRoot = dirname(entryPath);
|
|
448
|
-
const candidates = [
|
|
449
|
-
resolve(pkgRoot, "dist/generated/openapi.json"),
|
|
450
|
-
resolve(pkgRoot, "generated/openapi.json"),
|
|
451
|
-
resolve(pkgRoot, "src/generated/openapi.json")
|
|
452
|
-
];
|
|
453
|
-
cachedSpecPath = candidates.find((p) => existsSync(p));
|
|
454
|
-
return cachedSpecPath;
|
|
455
|
-
} catch {
|
|
456
|
-
return void 0;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
function createTokenProvider(config, tenant) {
|
|
460
|
-
if (config.authMode === "admin") {
|
|
461
|
-
if (!config.beid || !config.webServicesKey) {
|
|
462
|
-
throw new Error("BEID and WebServicesKey are required for admin authentication");
|
|
463
|
-
}
|
|
464
|
-
return loginWithServiceAccount({
|
|
465
|
-
tenant,
|
|
466
|
-
baseUrl: config.baseUrl,
|
|
467
|
-
beid: config.beid,
|
|
468
|
-
webServicesKey: config.webServicesKey
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
if (!config.username || !config.password) {
|
|
472
|
-
throw new Error("Username and password are required for standard authentication");
|
|
473
|
-
}
|
|
474
|
-
return loginWithPassword({
|
|
475
|
-
tenant,
|
|
476
|
-
baseUrl: config.baseUrl,
|
|
477
|
-
username: config.username,
|
|
478
|
-
password: config.password
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
function extractTenant(baseUrl) {
|
|
482
|
-
const normalized = baseUrl.replace(/\/+$/, "").replace(/\/TDWebApi$/, "");
|
|
483
|
-
const withoutProtocol = normalized.replace(/^https?:\/\//, "");
|
|
484
|
-
const parts = withoutProtocol.split("/");
|
|
485
|
-
return parts[0] ?? "";
|
|
486
|
-
}
|
|
487
|
-
function buildSdkConfig(config, tenant, tokenProvider) {
|
|
488
|
-
return {
|
|
489
|
-
tenant,
|
|
490
|
-
tokenProvider,
|
|
491
|
-
environment: config.baseUrl?.includes("sandbox") ? "sandbox" : "production",
|
|
492
|
-
baseUrl: config.baseUrl,
|
|
493
|
-
timeoutMs: config.timeoutMs,
|
|
494
|
-
runtimeValidationMode: "fail-open",
|
|
495
|
-
...resolveSdkSpecPath() ? { specPath: resolveSdkSpecPath() } : {},
|
|
496
|
-
retryPolicy: {
|
|
497
|
-
maxRetries: config.maxRetries
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
async function createMcpSdkClient(config) {
|
|
502
|
-
const tenant = extractTenant(config.baseUrl ?? "");
|
|
503
|
-
const tokenProvider = createTokenProvider(config, tenant);
|
|
504
|
-
const sdkConfig = buildSdkConfig(config, tenant, tokenProvider);
|
|
505
|
-
const { client } = await createTeamDynamixClient(sdkConfig);
|
|
506
|
-
return client;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// src/services/teamdynamix/client.factory.ts
|
|
510
|
-
var TICKET_SEARCH_FIELD_MAP = {
|
|
511
|
-
ResponsibleGroupIDs: "ResponsibilityGroupIDs",
|
|
512
|
-
ResponsibleGroupID: "ResponsibilityGroupID",
|
|
513
|
-
ResponsibleGroups: "ResponsibilityGroupIDs"
|
|
514
|
-
};
|
|
515
|
-
function mapTicketSearchBody(body) {
|
|
516
|
-
const mapped = {};
|
|
517
|
-
for (const [key, value] of Object.entries(body)) {
|
|
518
|
-
if (value === void 0) continue;
|
|
519
|
-
mapped[TICKET_SEARCH_FIELD_MAP[key] ?? key] = value;
|
|
520
|
-
}
|
|
521
|
-
return mapped;
|
|
522
|
-
}
|
|
523
|
-
var UnifiedTeamDynamixClient = class _UnifiedTeamDynamixClient {
|
|
524
|
-
constructor(config) {
|
|
525
|
-
this.config = config;
|
|
526
|
-
}
|
|
527
|
-
config;
|
|
528
|
-
sdkPromise = null;
|
|
529
|
-
sdk() {
|
|
530
|
-
this.sdkPromise ??= createMcpSdkClient(this.config);
|
|
531
|
-
return this.sdkPromise;
|
|
532
|
-
}
|
|
533
|
-
//
|
|
534
|
-
// Discovery
|
|
535
|
-
//
|
|
536
|
-
getCurrentUser() {
|
|
537
|
-
return this.sdk().then((s) => s.discovery.authGetuser());
|
|
538
|
-
}
|
|
539
|
-
listApplications() {
|
|
540
|
-
return this.sdk().then((s) => s.discovery.applications());
|
|
541
|
-
}
|
|
542
|
-
//
|
|
543
|
-
// Tickets
|
|
544
|
-
//
|
|
545
|
-
getTicket(appId, ticketId) {
|
|
546
|
-
return this.sdk().then((s) => s.tickets.appIdTicketsId({ params: { path: { appId, id: ticketId } } }));
|
|
547
|
-
}
|
|
548
|
-
searchTickets(appId, body) {
|
|
549
|
-
return this.sdk().then(async (s) => {
|
|
550
|
-
const { data, error } = await s.POST("/api/{appId}/tickets/search", {
|
|
551
|
-
params: { path: { appId } },
|
|
552
|
-
body: mapTicketSearchBody(body)
|
|
553
|
-
});
|
|
554
|
-
if (error) {
|
|
555
|
-
throw new Error(`Ticket search failed: ${JSON.stringify(error)}`);
|
|
556
|
-
}
|
|
557
|
-
return Array.isArray(data) ? data : [];
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
listTicketTypes(appId) {
|
|
561
|
-
return this.sdk().then((s) => s.tickets.appIdTicketsTypes({ params: { path: { appId } } }));
|
|
562
|
-
}
|
|
563
|
-
listTicketPriorities(appId) {
|
|
564
|
-
return this.sdk().then((s) => s.tickets.appIdTicketsPriorities({ params: { path: { appId } } }));
|
|
565
|
-
}
|
|
566
|
-
listTicketUrgencies(appId) {
|
|
567
|
-
return this.sdk().then((s) => s.tickets.appIdTicketsUrgencies({ params: { path: { appId } } }));
|
|
568
|
-
}
|
|
569
|
-
listTicketImpacts(appId) {
|
|
570
|
-
return this.sdk().then((s) => s.tickets.appIdTicketsImpacts({ params: { path: { appId } } }));
|
|
571
|
-
}
|
|
572
|
-
listTicketSources(appId) {
|
|
573
|
-
return this.sdk().then((s) => s.tickets.appIdTicketsSources({ params: { path: { appId } } }));
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
|
-
* Upper bound on feed entries we'll fetch replies for. The TDX API allows 60
|
|
577
|
-
* requests/60s; the feed call itself plus one fetch per entry must stay under it.
|
|
578
|
-
*/
|
|
579
|
-
static DEFAULT_REPLIES_ENTRY_LIMIT = 10;
|
|
580
|
-
async getTicketFeed(appId, ticketId, opts = {}) {
|
|
581
|
-
const s = await this.sdk();
|
|
582
|
-
const feed = await s.tickets.appIdTicketsIdFeed({ params: { path: { appId, id: ticketId } } });
|
|
583
|
-
const entries = Array.isArray(feed) ? feed : [];
|
|
584
|
-
const limit = opts.repliesEntryLimit ?? _UnifiedTeamDynamixClient.DEFAULT_REPLIES_ENTRY_LIMIT;
|
|
585
|
-
const missing = entries.filter(
|
|
586
|
-
(e) => typeof e.RepliesCount === "number" && e.RepliesCount > 0 && (!Array.isArray(e.Replies) || e.Replies.length === 0) && typeof e.ID !== "undefined"
|
|
587
|
-
);
|
|
588
|
-
for (const entry of missing.slice(0, limit)) {
|
|
589
|
-
const target = entry;
|
|
590
|
-
const { data, error } = await s.GET("/api/feed/{id}", {
|
|
591
|
-
params: { path: { id: target.ID } }
|
|
592
|
-
});
|
|
593
|
-
if (error) {
|
|
594
|
-
const detail = typeof error === "string" ? error : JSON.stringify(error);
|
|
595
|
-
throw new Error(`Failed to fetch replies for feed entry ${target.ID} (GET /api/feed/{id}): ${detail}`);
|
|
596
|
-
}
|
|
597
|
-
if (data && Array.isArray(data.Replies)) {
|
|
598
|
-
target.Replies = data.Replies;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
return entries;
|
|
602
|
-
}
|
|
603
|
-
//
|
|
604
|
-
// Ticket Relationships
|
|
605
|
-
//
|
|
606
|
-
getTicketTasks(appId, ticketId) {
|
|
607
|
-
return this.sdk().then(
|
|
608
|
-
(s) => s.ticketRelationships.appIdTicketsTicketIdTasks({ params: { path: { appId, ticketId } } })
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
createTicketTask(appId, ticketId, body) {
|
|
612
|
-
return this.sdk().then((s) => s.ticketRelationships.createTicketTask({ appId, ticketId, body }));
|
|
613
|
-
}
|
|
614
|
-
listTicketAssets(appId, ticketId) {
|
|
615
|
-
return this.sdk().then(
|
|
616
|
-
(s) => s.ticketRelationships.appIdTicketsIdAssets({ params: { path: { appId, id: ticketId } } })
|
|
617
|
-
);
|
|
618
|
-
}
|
|
619
|
-
addTicketAsset(appId, ticketId, assetId) {
|
|
620
|
-
return this.sdk().then((s) => s.ticketRelationships.addTicketAsset({ appId, ticketId, assetId }));
|
|
621
|
-
}
|
|
622
|
-
removeTicketAsset(appId, ticketId, assetId) {
|
|
623
|
-
return this.sdk().then((s) => {
|
|
624
|
-
s.ticketRelationships.removeTicketAsset({ appId, ticketId, assetId, confirm: true });
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
getTicketContacts(appId, ticketId) {
|
|
628
|
-
return this.sdk().then(
|
|
629
|
-
(s) => s.ticketRelationships.appIdTicketsIdContacts({ params: { path: { appId, id: ticketId } } })
|
|
630
|
-
);
|
|
631
|
-
}
|
|
632
|
-
addTicketContact(appId, ticketId, contactUid) {
|
|
633
|
-
return this.sdk().then((s) => s.ticketRelationships.addTicketContact({ appId, ticketId, contactUid }));
|
|
634
|
-
}
|
|
635
|
-
removeTicketContact(appId, ticketId, contactUid) {
|
|
636
|
-
return this.sdk().then((s) => {
|
|
637
|
-
s.ticketRelationships.removeTicketContact({ appId, ticketId, contactUid, confirm: true });
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
//
|
|
641
|
-
// People
|
|
642
|
-
//
|
|
643
|
-
getUser(uid) {
|
|
644
|
-
return this.sdk().then((s) => s.people.peopleUid({ params: { path: { uid } } }));
|
|
645
|
-
}
|
|
646
|
-
searchUsers(body) {
|
|
647
|
-
const searchText = typeof body["SearchText"] === "string" ? body["SearchText"] : "";
|
|
648
|
-
return this.sdk().then((s) => s.people.peopleLookup({ body: { SearchText: searchText } }));
|
|
649
|
-
}
|
|
650
|
-
getGroup(groupId) {
|
|
651
|
-
return this.sdk().then((s) => s.people.groupsId({ params: { path: { id: groupId } } }));
|
|
652
|
-
}
|
|
653
|
-
searchGroups(_body) {
|
|
654
|
-
return this.sdk().then((s) => s.people.searchGroups({ body: {} }));
|
|
655
|
-
}
|
|
656
|
-
getGroupMembers(groupId) {
|
|
657
|
-
return this.sdk().then((s) => s.people.groupsIdMembers({ params: { path: { id: groupId } } }));
|
|
658
|
-
}
|
|
659
|
-
//
|
|
660
|
-
// Knowledge Base
|
|
661
|
-
//
|
|
662
|
-
getKbArticle(appId, articleId) {
|
|
663
|
-
return this.sdk().then((s) => s.knowledgeBase.appIdKnowledgebaseId({ params: { path: { appId, id: articleId } } }));
|
|
664
|
-
}
|
|
665
|
-
searchKbArticles(appId, body) {
|
|
666
|
-
const keyword = typeof body["SearchText"] === "string" ? body["SearchText"] : "";
|
|
667
|
-
return this.sdk().then((s) => s.knowledgeBase.appIdKnowledgebaseId({ params: { path: { appId, id: 0 } } })).then(
|
|
668
|
-
(r) => Array.isArray(r) ? r.filter((item) => {
|
|
669
|
-
const s = typeof item === "object" && item !== null ? JSON.stringify(item).toLowerCase() : "";
|
|
670
|
-
return keyword ? s.includes(keyword.toLowerCase()) : true;
|
|
671
|
-
}) : []
|
|
672
|
-
);
|
|
673
|
-
}
|
|
674
|
-
listKbCategories(appId) {
|
|
675
|
-
return this.sdk().then(
|
|
676
|
-
(s) => s.knowledgeBase.appIdKnowledgebaseCategories({ params: { path: { appId } } })
|
|
677
|
-
);
|
|
678
|
-
}
|
|
679
|
-
//
|
|
680
|
-
// Assets
|
|
681
|
-
//
|
|
682
|
-
getAsset(appId, assetId) {
|
|
683
|
-
return this.sdk().then((s) => s.assets.appIdAssetsId({ params: { path: { appId, id: assetId } } }));
|
|
684
|
-
}
|
|
685
|
-
searchAssets(appId, _body) {
|
|
686
|
-
return this.sdk().then((s) => s.assets.appIdAssetsFeed({ params: { path: { appId } } }));
|
|
687
|
-
}
|
|
688
|
-
listAssetStatuses(appId) {
|
|
689
|
-
return this.sdk().then((s) => s.assets.appIdAssetsStatuses({ params: { path: { appId } } }));
|
|
690
|
-
}
|
|
691
|
-
listProductModels(appId) {
|
|
692
|
-
return this.sdk().then((s) => s.assets.appIdAssetsModels({ params: { path: { appId } } }));
|
|
693
|
-
}
|
|
694
|
-
listVendors(appId) {
|
|
695
|
-
return this.sdk().then((s) => s.cmdb.appIdAssetsVendors({ params: { path: { appId } } }));
|
|
696
|
-
}
|
|
697
|
-
//
|
|
698
|
-
// CMDB
|
|
699
|
-
//
|
|
700
|
-
getConfigurationItem(appId, ciId) {
|
|
701
|
-
return this.sdk().then((s) => s.cmdb.appIdCmdbId({ params: { path: { appId, id: ciId } } }));
|
|
702
|
-
}
|
|
703
|
-
searchConfigurationItems(appId, _body) {
|
|
704
|
-
return this.sdk().then((s) => s.cmdb.appIdCmdbSearches({ params: { path: { appId } } }));
|
|
705
|
-
}
|
|
706
|
-
listCiTypes(appId) {
|
|
707
|
-
return this.sdk().then((s) => s.cmdb.appIdCmdbTypes({ params: { path: { appId } } }));
|
|
708
|
-
}
|
|
709
|
-
listCiRelationshipTypes() {
|
|
710
|
-
return this.sdk().then((s) => s.cmdb.appIdCmdbRelationshiptypes());
|
|
711
|
-
}
|
|
712
|
-
//
|
|
713
|
-
// Services
|
|
714
|
-
//
|
|
715
|
-
listServiceCatalog(appId) {
|
|
716
|
-
return this.sdk().then((s) => s.services.appIdServices({ params: { path: { appId } } }));
|
|
717
|
-
}
|
|
718
|
-
getService(appId, serviceId) {
|
|
719
|
-
return this.sdk().then((s) => s.services.appIdServicesId({ params: { path: { appId, id: serviceId } } }));
|
|
720
|
-
}
|
|
721
|
-
searchServices(appId, body) {
|
|
722
|
-
const keyword = typeof body["Keyword"] === "string" ? body["Keyword"] : "";
|
|
723
|
-
return this.sdk().then((s) => s.services.appIdServices({ params: { path: { appId } } })).then((r) => {
|
|
724
|
-
if (!Array.isArray(r)) return [];
|
|
725
|
-
if (!keyword) return r;
|
|
726
|
-
const lower = keyword.toLowerCase();
|
|
727
|
-
return r.filter((item) => {
|
|
728
|
-
const text = typeof item === "object" && item !== null ? JSON.stringify(item).toLowerCase() : "";
|
|
729
|
-
return text.includes(lower);
|
|
730
|
-
});
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
listServiceCategories(appId) {
|
|
734
|
-
return this.sdk().then((s) => s.services.appIdServicesCategories({ params: { path: { appId } } }));
|
|
735
|
-
}
|
|
736
|
-
//
|
|
737
|
-
// Projects
|
|
738
|
-
//
|
|
739
|
-
getProject(projectId) {
|
|
740
|
-
return this.sdk().then((s) => s.projects.projectsId({ params: { path: { id: projectId } } }));
|
|
741
|
-
}
|
|
742
|
-
searchProjects(_body) {
|
|
743
|
-
return this.sdk().then((s) => s.projects.projectsFeed());
|
|
744
|
-
}
|
|
745
|
-
listProjectTypes() {
|
|
746
|
-
return this.sdk().then((s) => s.projects.projectsTypes());
|
|
747
|
-
}
|
|
748
|
-
getProjectPlans(projectId) {
|
|
749
|
-
return this.sdk().then(
|
|
750
|
-
(s) => s.projects.projectsProjectIDPlansPlanID({ params: { path: { id: projectId } } })
|
|
751
|
-
);
|
|
752
|
-
}
|
|
753
|
-
getProjectIssues(projectId) {
|
|
754
|
-
return this.sdk().then(
|
|
755
|
-
(s) => s.projects.projectsProjectIdIssuesCategories({ params: { path: { id: projectId } } })
|
|
756
|
-
);
|
|
757
|
-
}
|
|
758
|
-
getProjectRisks(projectId) {
|
|
759
|
-
return this.sdk().then(
|
|
760
|
-
(s) => s.projects.projectsProjectIdRisksCategories({ params: { path: { id: projectId } } })
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
|
-
//
|
|
764
|
-
// Time
|
|
765
|
-
//
|
|
766
|
-
listTimeTypes() {
|
|
767
|
-
return this.sdk().then((s) => s.time.timeTypes());
|
|
768
|
-
}
|
|
769
|
-
getMyTimeEntries(_startDate, _endDate) {
|
|
770
|
-
return this.sdk().then((s) => s.time.timeId({ params: { path: { id: 0 } } }));
|
|
771
|
-
}
|
|
772
|
-
//
|
|
773
|
-
// Reference Data
|
|
774
|
-
//
|
|
775
|
-
listAccounts(_appId) {
|
|
776
|
-
return this.sdk().then((s) => s.referenceData.accounts());
|
|
777
|
-
}
|
|
778
|
-
getAccount(accountId) {
|
|
779
|
-
return this.sdk().then((s) => s.referenceData.accountsId({ params: { path: { id: accountId } } }));
|
|
780
|
-
}
|
|
781
|
-
listLocations() {
|
|
782
|
-
return this.sdk().then((s) => s.referenceData.locations());
|
|
783
|
-
}
|
|
784
|
-
listFunctionalRoles() {
|
|
785
|
-
return this.sdk().then((s) => s.referenceData.securityrolesPermissions());
|
|
786
|
-
}
|
|
787
|
-
listCustomAttributes(_componentId, _appId, _associatedTypeId) {
|
|
788
|
-
return this.sdk().then((s) => s.referenceData.attributesCustom());
|
|
789
|
-
}
|
|
790
|
-
listTicketStatuses(appId) {
|
|
791
|
-
return this.sdk().then((s) => s.referenceData.appIdTicketsStatuses({ params: { path: { appId } } }));
|
|
792
|
-
}
|
|
793
|
-
//
|
|
794
|
-
// Mutations
|
|
795
|
-
//
|
|
796
|
-
createTicket(appId, body, _notifyRequestor, _notifyResponsible) {
|
|
797
|
-
return this.sdk().then((s) => s.tickets.createTicket({ appId, body }));
|
|
798
|
-
}
|
|
799
|
-
updateTicket(appId, ticketId, body, _notifyRequestor, _notifyResponsible, _comments, _isPrivate) {
|
|
800
|
-
return this.sdk().then((s) => s.tickets.updateTicket({ appId, ticketId, body }));
|
|
801
|
-
}
|
|
802
|
-
addTicketComment(appId, ticketId, body, _isPrivate, _notifyRequestor, _notifyResponsible) {
|
|
803
|
-
return this.sdk().then((s) => s.tickets.addTicketComment({ appId, ticketId, body: { Body: body } }));
|
|
804
|
-
}
|
|
805
|
-
createKbArticle(appId, body) {
|
|
806
|
-
return this.sdk().then((s) => s.knowledgeBase.createArticle({ appId, body }));
|
|
807
|
-
}
|
|
808
|
-
updateKbArticle(appId, articleId, body) {
|
|
809
|
-
return this.sdk().then((s) => s.knowledgeBase.updateArticle({ appId, articleId, body }));
|
|
810
|
-
}
|
|
811
|
-
createProjectIssue(_projectId, body) {
|
|
812
|
-
return this.sdk().then((s) => s.projects.createIssue({ body }));
|
|
813
|
-
}
|
|
814
|
-
createProjectRisk(_projectId, body) {
|
|
815
|
-
return this.sdk().then((s) => s.projects.createRisk({ body }));
|
|
816
|
-
}
|
|
817
|
-
//
|
|
818
|
-
// Delete mutations (confirm:true required for all)
|
|
819
|
-
//
|
|
820
|
-
deleteAsset(appId, assetId) {
|
|
821
|
-
return this.sdk().then((s) => s.assets.deleteAsset({ appId, assetId, confirm: true }));
|
|
822
|
-
}
|
|
823
|
-
deleteConfigurationItem(appId, ciId) {
|
|
824
|
-
return this.sdk().then((s) => s.cmdb.deleteConfigurationItem({ appId, configurationItemId: ciId, confirm: true }));
|
|
825
|
-
}
|
|
826
|
-
deleteService(appId, serviceId) {
|
|
827
|
-
return this.sdk().then((s) => s.services.deleteService({ appId, serviceId, confirm: true }));
|
|
828
|
-
}
|
|
829
|
-
deleteServiceCategory(appId, categoryId) {
|
|
830
|
-
return this.sdk().then((s) => s.services.deleteServiceCategory({ appId, categoryId, confirm: true }));
|
|
831
|
-
}
|
|
832
|
-
deleteTimeEntry(timeEntryId) {
|
|
833
|
-
return this.sdk().then((s) => s.time.deleteTimeEntry({ timeEntryId, confirm: true }));
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
function createConfiguredTeamDynamixClient() {
|
|
837
|
-
return new UnifiedTeamDynamixClient(getTeamDynamixConfig());
|
|
838
|
-
}
|
|
839
|
-
function assertWriteToolsEnabled(config) {
|
|
840
|
-
if (!config.enableWriteTools) {
|
|
841
|
-
throw new Error("Write tools are disabled. Set TEAMDYNAMIX_ENABLE_WRITE_TOOLS=true in your environment.");
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
function assertDeleteToolsEnabled(config) {
|
|
845
|
-
if (!config.enableDeleteTools) {
|
|
846
|
-
throw new Error("Delete tools are disabled. Set TEAMDYNAMIX_ENABLE_DELETE_TOOLS=true in your environment.");
|
|
847
|
-
}
|
|
848
|
-
}
|
|
1426
|
+
// src/tools/teamdynamix.domain-gateways.tools.ts
|
|
1427
|
+
init_client_factory();
|
|
849
1428
|
|
|
850
1429
|
// src/services/teamdynamix/render.service.ts
|
|
1430
|
+
init_constants();
|
|
851
1431
|
import { tablemark } from "tablemark";
|
|
852
1432
|
function render(payload, responseFormat, characterLimit = CHARACTER_LIMIT) {
|
|
853
1433
|
if (responseFormat === "json") {
|
|
@@ -2084,12 +2664,192 @@ function registerTeamDynamixResources(server2) {
|
|
|
2084
2664
|
);
|
|
2085
2665
|
}
|
|
2086
2666
|
|
|
2667
|
+
// src/tools/teamdynamix.watch.tools.ts
|
|
2668
|
+
init_constants();
|
|
2669
|
+
import { z as z5 } from "zod";
|
|
2670
|
+
init_client_factory();
|
|
2671
|
+
init_watch_store();
|
|
2672
|
+
init_watch_service();
|
|
2673
|
+
var WatchKindSchema = z5.enum(["mine", "watching", "waiting-on-others"]);
|
|
2674
|
+
var BallSchema = z5.enum(["us", "them"]);
|
|
2675
|
+
function messageFromError2(error) {
|
|
2676
|
+
return error instanceof Error ? error.message : String(error);
|
|
2677
|
+
}
|
|
2678
|
+
async function withService(responseFormat, fn) {
|
|
2679
|
+
try {
|
|
2680
|
+
const client = createConfiguredTeamDynamixClient();
|
|
2681
|
+
const ledgerPath = defaultLedgerPath();
|
|
2682
|
+
let ledger;
|
|
2683
|
+
try {
|
|
2684
|
+
ledger = await loadLedger(ledgerPath);
|
|
2685
|
+
} catch (cause) {
|
|
2686
|
+
if (cause instanceof LedgerCorruptError) throw cause;
|
|
2687
|
+
ledger = emptyLedger();
|
|
2688
|
+
}
|
|
2689
|
+
const svc = new WorkspaceWatchService(ledger, ledgerPath, client);
|
|
2690
|
+
const data = await fn(svc);
|
|
2691
|
+
return {
|
|
2692
|
+
content: [{ type: "text", text: render(data, responseFormat) }],
|
|
2693
|
+
structuredContent: data
|
|
2694
|
+
};
|
|
2695
|
+
} catch (error) {
|
|
2696
|
+
return { content: [{ type: "text", text: `Error: ${messageFromError2(error)}` }], isError: true };
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
function registerTeamDynamixWatchTools(server2) {
|
|
2700
|
+
const readOnly = { readOnlyHint: true, idempotentHint: false, destructiveHint: false, openWorldHint: true };
|
|
2701
|
+
server2.registerTool(
|
|
2702
|
+
`${TEAMDYNAMIX_TOOL_PREFIX}_watch_check`,
|
|
2703
|
+
{
|
|
2704
|
+
title: "Watch Check",
|
|
2705
|
+
description: "Diff pass over the watch ledger: sweeps queue searches per app, deep-fetches only changed tickets, and returns classified deltas (status, new-entry, hidden-reply, ownership, sla, hold-window).",
|
|
2706
|
+
inputSchema: {
|
|
2707
|
+
tickets: z5.array(z5.number().int().positive()).optional().describe("Restrict the check to these ticket IDs."),
|
|
2708
|
+
response_format: TeamDynamixResponseFormatSchema
|
|
2709
|
+
},
|
|
2710
|
+
annotations: { ...readOnly }
|
|
2711
|
+
},
|
|
2712
|
+
async ({ tickets, response_format }) => withService(response_format, (svc) => svc.check({ tickets }))
|
|
2713
|
+
);
|
|
2714
|
+
server2.registerTool(
|
|
2715
|
+
`${TEAMDYNAMIX_TOOL_PREFIX}_watch_status`,
|
|
2716
|
+
{
|
|
2717
|
+
title: "Watch Status",
|
|
2718
|
+
description: "Ledger summary (counts, ball-in-court, pending-triage queue, oldest freshness) without any TDX calls.",
|
|
2719
|
+
inputSchema: { response_format: TeamDynamixResponseFormatSchema },
|
|
2720
|
+
annotations: { ...readOnly, idempotentHint: true, openWorldHint: false }
|
|
2721
|
+
},
|
|
2722
|
+
async ({ response_format }) => withService(response_format, async (svc) => ({
|
|
2723
|
+
...await svc.status(),
|
|
2724
|
+
pendingTriage: svc.pendingTriage()
|
|
2725
|
+
}))
|
|
2726
|
+
);
|
|
2727
|
+
server2.registerTool(
|
|
2728
|
+
`${TEAMDYNAMIX_TOOL_PREFIX}_watch_sweep`,
|
|
2729
|
+
{
|
|
2730
|
+
title: "Watch Sweep",
|
|
2731
|
+
description: "Cheap sweep: one queue search per configured app, client-side team restriction (TEAMDYNAMIX_TICKET_GROUP_IDS), ledger freshness, and pending-triage queue maintenance (changed + new-unassigned tickets). No deep fetches.",
|
|
2732
|
+
inputSchema: { response_format: TeamDynamixResponseFormatSchema },
|
|
2733
|
+
annotations: { ...readOnly }
|
|
2734
|
+
},
|
|
2735
|
+
async ({ response_format }) => withService(response_format, (svc) => svc.sweep())
|
|
2736
|
+
);
|
|
2737
|
+
server2.registerTool(
|
|
2738
|
+
`${TEAMDYNAMIX_TOOL_PREFIX}_watch_triage`,
|
|
2739
|
+
{
|
|
2740
|
+
title: "Watch Triage Queue",
|
|
2741
|
+
description: "Local triage queue (never calls TDX). op=queue lists pending tickets needing background triage; op=done removes a ticket after the agent has reviewed it and updated notes.",
|
|
2742
|
+
inputSchema: {
|
|
2743
|
+
op: z5.enum(["queue", "done"]),
|
|
2744
|
+
ticket_id: z5.number().int().positive().optional().describe("Required for op=done."),
|
|
2745
|
+
response_format: TeamDynamixResponseFormatSchema
|
|
2746
|
+
},
|
|
2747
|
+
annotations: { ...readOnly, openWorldHint: false }
|
|
2748
|
+
},
|
|
2749
|
+
async ({
|
|
2750
|
+
op,
|
|
2751
|
+
ticket_id,
|
|
2752
|
+
response_format
|
|
2753
|
+
}) => withService(response_format, async (svc) => {
|
|
2754
|
+
if (op === "queue") return { pending: svc.pendingTriage() };
|
|
2755
|
+
if (ticket_id === void 0) throw new Error("op=done requires ticket_id.");
|
|
2756
|
+
return await svc.markTriaged(ticket_id);
|
|
2757
|
+
})
|
|
2758
|
+
);
|
|
2759
|
+
server2.registerTool(
|
|
2760
|
+
`${TEAMDYNAMIX_TOOL_PREFIX}_watch_register`,
|
|
2761
|
+
{
|
|
2762
|
+
title: "Watch Register",
|
|
2763
|
+
description: "Add/update a ledger row when a ticket is claimed, re-scoped, or swept in. Never calls TDX.",
|
|
2764
|
+
inputSchema: {
|
|
2765
|
+
app_id: z5.number().int().positive().describe("Ticketing application ID."),
|
|
2766
|
+
id: z5.number().int().positive().describe("Ticket ID."),
|
|
2767
|
+
kind: WatchKindSchema.describe("Lane: mine, watching, or waiting-on-others."),
|
|
2768
|
+
title: z5.string().max(200).optional().describe("Short title (stored locally only)."),
|
|
2769
|
+
district: z5.string().max(100).optional().describe("District/lane label."),
|
|
2770
|
+
ball: BallSchema.optional().describe("Manual ball-in-court override (survives auto-inference)."),
|
|
2771
|
+
next_action: z5.string().max(500).optional().describe("Next action note."),
|
|
2772
|
+
response_format: TeamDynamixResponseFormatSchema
|
|
2773
|
+
},
|
|
2774
|
+
annotations: { ...readOnly, openWorldHint: false }
|
|
2775
|
+
},
|
|
2776
|
+
async ({
|
|
2777
|
+
app_id,
|
|
2778
|
+
id,
|
|
2779
|
+
kind,
|
|
2780
|
+
title,
|
|
2781
|
+
district,
|
|
2782
|
+
ball,
|
|
2783
|
+
next_action,
|
|
2784
|
+
response_format
|
|
2785
|
+
}) => withService(
|
|
2786
|
+
response_format,
|
|
2787
|
+
(svc) => svc.register({ appId: app_id, id, kind, title, district, ball, nextAction: next_action })
|
|
2788
|
+
)
|
|
2789
|
+
);
|
|
2790
|
+
server2.registerTool(
|
|
2791
|
+
`${TEAMDYNAMIX_TOOL_PREFIX}_watch_archive`,
|
|
2792
|
+
{
|
|
2793
|
+
title: "Watch Archive",
|
|
2794
|
+
description: "Move a confirmed-closed row to the archive section. Memory (notes) is preserved. Never calls TDX.",
|
|
2795
|
+
inputSchema: {
|
|
2796
|
+
id: z5.number().int().positive().describe("Ticket ID."),
|
|
2797
|
+
outcome: z5.string().max(200).optional().describe("Resolution outcome label."),
|
|
2798
|
+
response_format: TeamDynamixResponseFormatSchema
|
|
2799
|
+
},
|
|
2800
|
+
annotations: { ...readOnly, openWorldHint: false }
|
|
2801
|
+
},
|
|
2802
|
+
async ({ id, outcome, response_format }) => withService(response_format, (svc) => svc.archive({ id, outcome }))
|
|
2803
|
+
);
|
|
2804
|
+
server2.registerTool(
|
|
2805
|
+
`${TEAMDYNAMIX_TOOL_PREFIX}_watch_notes`,
|
|
2806
|
+
{
|
|
2807
|
+
title: "Watch Notes",
|
|
2808
|
+
description: "Local-only notes attached to ledgered tickets \u2014 the server's own memory. Never written to TDX. op: add | update | delete | list.",
|
|
2809
|
+
inputSchema: {
|
|
2810
|
+
op: z5.enum(["add", "update", "delete", "list"]),
|
|
2811
|
+
app_id: z5.number().int().positive().optional(),
|
|
2812
|
+
ticket_id: z5.number().int().positive().optional(),
|
|
2813
|
+
note_id: z5.string().optional(),
|
|
2814
|
+
text: z5.string().max(4e3).optional(),
|
|
2815
|
+
response_format: TeamDynamixResponseFormatSchema
|
|
2816
|
+
},
|
|
2817
|
+
annotations: { ...readOnly, openWorldHint: false }
|
|
2818
|
+
},
|
|
2819
|
+
async ({
|
|
2820
|
+
op,
|
|
2821
|
+
app_id,
|
|
2822
|
+
ticket_id,
|
|
2823
|
+
note_id,
|
|
2824
|
+
text,
|
|
2825
|
+
response_format
|
|
2826
|
+
}) => withService(response_format, async (svc) => {
|
|
2827
|
+
switch (op) {
|
|
2828
|
+
case "add":
|
|
2829
|
+
if (app_id === void 0 || ticket_id === void 0 || !text) {
|
|
2830
|
+
throw new Error("op=add requires app_id, ticket_id, and text.");
|
|
2831
|
+
}
|
|
2832
|
+
return svc.notesAdd({ appId: app_id, ticketId: ticket_id, text });
|
|
2833
|
+
case "update":
|
|
2834
|
+
if (!note_id || !text) throw new Error("op=update requires note_id and text.");
|
|
2835
|
+
return svc.notesUpdate({ noteId: note_id, text });
|
|
2836
|
+
case "delete":
|
|
2837
|
+
if (!note_id) throw new Error("op=delete requires note_id.");
|
|
2838
|
+
return svc.notesDelete({ noteId: note_id });
|
|
2839
|
+
case "list":
|
|
2840
|
+
return svc.notesList({ appId: app_id, ticketId: ticket_id });
|
|
2841
|
+
}
|
|
2842
|
+
})
|
|
2843
|
+
);
|
|
2844
|
+
}
|
|
2845
|
+
|
|
2087
2846
|
// src/index.ts
|
|
2088
2847
|
var server = new McpServer2({
|
|
2089
2848
|
name: SERVER_NAME_OVERRIDE ?? SERVER_NAME,
|
|
2090
2849
|
version: SERVER_VERSION_OVERRIDE ?? SERVER_VERSION
|
|
2091
2850
|
});
|
|
2092
2851
|
registerTeamDynamixDomainGatewayTools(server);
|
|
2852
|
+
registerTeamDynamixWatchTools(server);
|
|
2093
2853
|
registerTeamDynamixResources(server);
|
|
2094
2854
|
async function main() {
|
|
2095
2855
|
console.error(`[teamdynamix-mcp] log level: ${LOG_LEVEL}`);
|
|
@@ -2097,9 +2857,37 @@ async function main() {
|
|
|
2097
2857
|
const config = getTeamDynamixConfig();
|
|
2098
2858
|
console.error(`[teamdynamix-mcp] sanitized config: ${JSON.stringify(redactTeamDynamixConfig(config))}`);
|
|
2099
2859
|
}
|
|
2860
|
+
startWatchSweepTimer();
|
|
2100
2861
|
const transport = new StdioServerTransport();
|
|
2101
2862
|
await server.connect(transport);
|
|
2102
2863
|
}
|
|
2864
|
+
function startWatchSweepTimer() {
|
|
2865
|
+
const secs = Number(process.env["TEAMDYNAMIX_WATCH_SWEEP_SECS"] ?? 0);
|
|
2866
|
+
if (!Number.isFinite(secs) || secs <= 0) return;
|
|
2867
|
+
const timer = setInterval(() => {
|
|
2868
|
+
Promise.resolve().then(() => (init_watch_store(), watch_store_exports)).then(async ({ loadLedger: loadLedger2, saveLedger: saveLedger2, emptyLedger: emptyLedger2, defaultLedgerPath: defaultLedgerPath2, LedgerCorruptError: LedgerCorruptError2 }) => {
|
|
2869
|
+
const { createConfiguredTeamDynamixClient: createConfiguredTeamDynamixClient2 } = await Promise.resolve().then(() => (init_client_service(), client_service_exports));
|
|
2870
|
+
const { WorkspaceWatchService: WorkspaceWatchService2 } = await Promise.resolve().then(() => (init_watch_service(), watch_service_exports));
|
|
2871
|
+
const ledgerPath = defaultLedgerPath2();
|
|
2872
|
+
let ledger;
|
|
2873
|
+
try {
|
|
2874
|
+
ledger = await loadLedger2(ledgerPath);
|
|
2875
|
+
} catch (cause) {
|
|
2876
|
+
if (cause instanceof LedgerCorruptError2) throw cause;
|
|
2877
|
+
ledger = emptyLedger2();
|
|
2878
|
+
}
|
|
2879
|
+
const client = await createConfiguredTeamDynamixClient2();
|
|
2880
|
+
const svc = new WorkspaceWatchService2(ledger, ledgerPath, client);
|
|
2881
|
+
const result = await svc.sweep();
|
|
2882
|
+
console.error(`[teamdynamix-mcp] watch sweep: ${JSON.stringify(result)}`);
|
|
2883
|
+
}).catch((cause) => {
|
|
2884
|
+
console.error(
|
|
2885
|
+
`[teamdynamix-mcp] watch sweep failed: ${cause instanceof Error ? cause.message : String(cause)}`
|
|
2886
|
+
);
|
|
2887
|
+
});
|
|
2888
|
+
}, secs * 1e3);
|
|
2889
|
+
timer.unref();
|
|
2890
|
+
}
|
|
2103
2891
|
main().catch((error) => {
|
|
2104
2892
|
const message = error instanceof Error ? error.message : String(error);
|
|
2105
2893
|
console.error(`Server startup failed: ${message}`);
|