@integrity-labs/agt-cli 0.28.1088 → 0.28.1089
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/bin/agt.js +3 -3
- package/dist/{chunk-JAXSZCTH.js → chunk-OBSRWYMM.js} +2 -2
- package/dist/lib/manager-worker.js +2 -2
- package/dist/mcp/direct-chat-channel.js +173 -132
- package/dist/mcp/index.js +172 -40
- package/dist/mcp/slack-channel.js +344 -261
- package/dist/mcp/teams-channel.js +210 -86
- package/dist/mcp/telegram-channel.js +287 -206
- package/dist/mcp/whatsapp-channel.js +194 -69
- package/package.json +1 -1
- /package/dist/{chunk-JAXSZCTH.js.map → chunk-OBSRWYMM.js.map} +0 -0
|
@@ -3590,49 +3590,49 @@ var require_fast_uri = __commonJS({
|
|
|
3590
3590
|
schemelessOptions.skipEscape = true;
|
|
3591
3591
|
return serialize(resolved, schemelessOptions);
|
|
3592
3592
|
}
|
|
3593
|
-
function resolveComponent(base,
|
|
3593
|
+
function resolveComponent(base, relative2, options, skipNormalization) {
|
|
3594
3594
|
const target = {};
|
|
3595
3595
|
if (!skipNormalization) {
|
|
3596
3596
|
base = parse3(serialize(base, options), options);
|
|
3597
|
-
|
|
3597
|
+
relative2 = parse3(serialize(relative2, options), options);
|
|
3598
3598
|
}
|
|
3599
3599
|
options = options || {};
|
|
3600
|
-
if (!options.tolerant &&
|
|
3601
|
-
target.scheme =
|
|
3602
|
-
target.userinfo =
|
|
3603
|
-
target.host =
|
|
3604
|
-
target.port =
|
|
3605
|
-
target.path = removeDotSegments(
|
|
3606
|
-
target.query =
|
|
3600
|
+
if (!options.tolerant && relative2.scheme) {
|
|
3601
|
+
target.scheme = relative2.scheme;
|
|
3602
|
+
target.userinfo = relative2.userinfo;
|
|
3603
|
+
target.host = relative2.host;
|
|
3604
|
+
target.port = relative2.port;
|
|
3605
|
+
target.path = removeDotSegments(relative2.path || "");
|
|
3606
|
+
target.query = relative2.query;
|
|
3607
3607
|
} else {
|
|
3608
|
-
if (
|
|
3609
|
-
target.userinfo =
|
|
3610
|
-
target.host =
|
|
3611
|
-
target.port =
|
|
3612
|
-
target.path = removeDotSegments(
|
|
3613
|
-
target.query =
|
|
3608
|
+
if (relative2.userinfo !== void 0 || relative2.host !== void 0 || relative2.port !== void 0) {
|
|
3609
|
+
target.userinfo = relative2.userinfo;
|
|
3610
|
+
target.host = relative2.host;
|
|
3611
|
+
target.port = relative2.port;
|
|
3612
|
+
target.path = removeDotSegments(relative2.path || "");
|
|
3613
|
+
target.query = relative2.query;
|
|
3614
3614
|
} else {
|
|
3615
|
-
if (!
|
|
3615
|
+
if (!relative2.path) {
|
|
3616
3616
|
target.path = base.path;
|
|
3617
|
-
if (
|
|
3618
|
-
target.query =
|
|
3617
|
+
if (relative2.query !== void 0) {
|
|
3618
|
+
target.query = relative2.query;
|
|
3619
3619
|
} else {
|
|
3620
3620
|
target.query = base.query;
|
|
3621
3621
|
}
|
|
3622
3622
|
} else {
|
|
3623
|
-
if (
|
|
3624
|
-
target.path = removeDotSegments(
|
|
3623
|
+
if (relative2.path[0] === "/") {
|
|
3624
|
+
target.path = removeDotSegments(relative2.path);
|
|
3625
3625
|
} else {
|
|
3626
3626
|
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) {
|
|
3627
|
-
target.path = "/" +
|
|
3627
|
+
target.path = "/" + relative2.path;
|
|
3628
3628
|
} else if (!base.path) {
|
|
3629
|
-
target.path =
|
|
3629
|
+
target.path = relative2.path;
|
|
3630
3630
|
} else {
|
|
3631
|
-
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
3631
|
+
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative2.path;
|
|
3632
3632
|
}
|
|
3633
3633
|
target.path = removeDotSegments(target.path);
|
|
3634
3634
|
}
|
|
3635
|
-
target.query =
|
|
3635
|
+
target.query = relative2.query;
|
|
3636
3636
|
}
|
|
3637
3637
|
target.userinfo = base.userinfo;
|
|
3638
3638
|
target.host = base.host;
|
|
@@ -3640,7 +3640,7 @@ var require_fast_uri = __commonJS({
|
|
|
3640
3640
|
}
|
|
3641
3641
|
target.scheme = base.scheme;
|
|
3642
3642
|
}
|
|
3643
|
-
target.fragment =
|
|
3643
|
+
target.fragment = relative2.fragment;
|
|
3644
3644
|
return target;
|
|
3645
3645
|
}
|
|
3646
3646
|
function equal(uriA, uriB, options) {
|
|
@@ -13866,18 +13866,18 @@ var StdioServerTransport = class {
|
|
|
13866
13866
|
// src/teams-channel.ts
|
|
13867
13867
|
import {
|
|
13868
13868
|
existsSync as existsSync6,
|
|
13869
|
-
mkdirSync as
|
|
13869
|
+
mkdirSync as mkdirSync7,
|
|
13870
13870
|
readdirSync as readdirSync3,
|
|
13871
|
-
readFileSync as
|
|
13872
|
-
renameSync as
|
|
13871
|
+
readFileSync as readFileSync8,
|
|
13872
|
+
renameSync as renameSync3,
|
|
13873
13873
|
rmSync,
|
|
13874
13874
|
statSync,
|
|
13875
|
-
unlinkSync as
|
|
13875
|
+
unlinkSync as unlinkSync3,
|
|
13876
13876
|
watch,
|
|
13877
|
-
writeFileSync as
|
|
13877
|
+
writeFileSync as writeFileSync7
|
|
13878
13878
|
} from "fs";
|
|
13879
|
-
import { homedir as
|
|
13880
|
-
import { join as
|
|
13879
|
+
import { homedir as homedir4 } from "os";
|
|
13880
|
+
import { join as join11, resolve as resolvePath2 } from "path";
|
|
13881
13881
|
import { basename } from "path";
|
|
13882
13882
|
|
|
13883
13883
|
// ../core/dist/channels/msteams-api.js
|
|
@@ -14065,8 +14065,8 @@ function resolveSandboxedPath(filePath, projectDir) {
|
|
|
14065
14065
|
if (!filePath || filePath.length === 0) return { ok: false, reason: "empty" };
|
|
14066
14066
|
if (!projectDir) return { ok: false, reason: "no_project_dir" };
|
|
14067
14067
|
const resolved = resolvePath(projectDir, filePath);
|
|
14068
|
-
const
|
|
14069
|
-
if (!resolved.startsWith(
|
|
14068
|
+
const sep2 = projectDir.endsWith("/") ? projectDir : projectDir + "/";
|
|
14069
|
+
if (!resolved.startsWith(sep2)) return { ok: false, reason: "outside_sandbox" };
|
|
14070
14070
|
return { ok: true, resolved };
|
|
14071
14071
|
}
|
|
14072
14072
|
|
|
@@ -15280,6 +15280,129 @@ var TEAMS_EGRESS_TOOLS = /* @__PURE__ */ new Set([
|
|
|
15280
15280
|
"teams.upload_file"
|
|
15281
15281
|
]);
|
|
15282
15282
|
|
|
15283
|
+
// src/turn-context.ts
|
|
15284
|
+
import { mkdirSync as mkdirSync6, readFileSync as readFileSync7 } from "fs";
|
|
15285
|
+
import { homedir as homedir3 } from "os";
|
|
15286
|
+
import { dirname as dirname3, join as join10 } from "path";
|
|
15287
|
+
|
|
15288
|
+
// ../core/dist/provisioning/frameworks/claudecode/agent-dir-alias.js
|
|
15289
|
+
import { isAbsolute, join as join7, relative, sep } from "path";
|
|
15290
|
+
var VALID_CODE_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
15291
|
+
var VALID_AGENT_ID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
15292
|
+
var INITIATOR_BASENAME = ".current-turn-initiator.json";
|
|
15293
|
+
function isSafeAgentSegment(segment) {
|
|
15294
|
+
return VALID_CODE_NAME.test(segment) || VALID_AGENT_ID.test(segment);
|
|
15295
|
+
}
|
|
15296
|
+
function initiatorDirSegment(initiatorFile, homeDir) {
|
|
15297
|
+
const rel = relative(join7(homeDir, ".augmented"), initiatorFile);
|
|
15298
|
+
if (!rel || isAbsolute(rel))
|
|
15299
|
+
return null;
|
|
15300
|
+
const parts = rel.split(sep);
|
|
15301
|
+
if (parts.length !== 2 || parts[1] !== INITIATOR_BASENAME)
|
|
15302
|
+
return null;
|
|
15303
|
+
const segment = parts[0];
|
|
15304
|
+
if (segment === void 0)
|
|
15305
|
+
return null;
|
|
15306
|
+
return isSafeAgentSegment(segment) ? segment : null;
|
|
15307
|
+
}
|
|
15308
|
+
function resolveAgentDirAlias(input) {
|
|
15309
|
+
const { codeName, turnInitiatorFile, agentId, homeDir } = input;
|
|
15310
|
+
const codeNameTrimmed = typeof codeName === "string" ? codeName.trim() : "";
|
|
15311
|
+
if (codeNameTrimmed && VALID_CODE_NAME.test(codeNameTrimmed)) {
|
|
15312
|
+
return join7(homeDir, ".augmented", codeNameTrimmed);
|
|
15313
|
+
}
|
|
15314
|
+
const initiator = typeof turnInitiatorFile === "string" ? turnInitiatorFile.trim() : "";
|
|
15315
|
+
if (initiator) {
|
|
15316
|
+
const segment = initiatorDirSegment(initiator, homeDir);
|
|
15317
|
+
if (segment)
|
|
15318
|
+
return join7(homeDir, ".augmented", segment);
|
|
15319
|
+
}
|
|
15320
|
+
const agentIdTrimmed = typeof agentId === "string" ? agentId.trim() : "";
|
|
15321
|
+
if (agentIdTrimmed && VALID_AGENT_ID.test(agentIdTrimmed)) {
|
|
15322
|
+
return join7(homeDir, ".augmented", agentIdTrimmed);
|
|
15323
|
+
}
|
|
15324
|
+
return null;
|
|
15325
|
+
}
|
|
15326
|
+
|
|
15327
|
+
// src/turn-initiator-marker.ts
|
|
15328
|
+
import { writeFileSync as writeFileSync6, readFileSync as readFileSync5, mkdirSync as mkdirSync5, renameSync as renameSync2 } from "fs";
|
|
15329
|
+
import { dirname as dirname2, join as join8 } from "path";
|
|
15330
|
+
var TURN_INITIATOR_MAX_AGE_MS = 5 * 60 * 1e3;
|
|
15331
|
+
var TURN_INITIATOR_LEDGER_MAX_ENTRIES = 20;
|
|
15332
|
+
var TURN_INITIATOR_LEDGER_FILENAME = ".turn-initiator-ledger.json";
|
|
15333
|
+
function turnInitiatorLedgerPath(singleSlotFile) {
|
|
15334
|
+
return join8(dirname2(singleSlotFile), TURN_INITIATOR_LEDGER_FILENAME);
|
|
15335
|
+
}
|
|
15336
|
+
function foldTurnInitiatorLedger(existing, marker, maxAgeMs = TURN_INITIATOR_MAX_AGE_MS, maxEntries = TURN_INITIATOR_LEDGER_MAX_ENTRIES) {
|
|
15337
|
+
const now = marker.ts;
|
|
15338
|
+
const key2 = (e) => `${e.channel}\0${e.channel_ref ?? ""}`;
|
|
15339
|
+
const markerKey = key2(marker);
|
|
15340
|
+
const prior = existing && Array.isArray(existing.entries) ? existing.entries : [];
|
|
15341
|
+
const kept = prior.filter(
|
|
15342
|
+
(e) => e && typeof e.ts === "number" && Number.isFinite(e.ts) && now - e.ts <= maxAgeMs && now - e.ts >= 0 && key2(e) !== markerKey
|
|
15343
|
+
// the same thread is replaced by the new entry below
|
|
15344
|
+
);
|
|
15345
|
+
kept.push({
|
|
15346
|
+
channel: marker.channel,
|
|
15347
|
+
sender_id: marker.sender_id,
|
|
15348
|
+
...marker.sender_name ? { sender_name: marker.sender_name } : {},
|
|
15349
|
+
...marker.channel_ref ? { channel_ref: marker.channel_ref } : {},
|
|
15350
|
+
...marker.chat_kind ? { chat_kind: marker.chat_kind } : {},
|
|
15351
|
+
...marker.chat_id ? { chat_id: marker.chat_id } : {},
|
|
15352
|
+
...marker.unattributed ? { unattributed: true } : {},
|
|
15353
|
+
ts: marker.ts
|
|
15354
|
+
});
|
|
15355
|
+
kept.sort((a, b) => b.ts - a.ts);
|
|
15356
|
+
return { v: 1, entries: kept.slice(0, maxEntries) };
|
|
15357
|
+
}
|
|
15358
|
+
function updateTurnInitiatorLedger(singleSlotFile, marker) {
|
|
15359
|
+
const ledgerFile = turnInitiatorLedgerPath(singleSlotFile);
|
|
15360
|
+
let existing = null;
|
|
15361
|
+
try {
|
|
15362
|
+
const parsed = JSON.parse(readFileSync5(ledgerFile, "utf8"));
|
|
15363
|
+
if (parsed && parsed.v === 1 && Array.isArray(parsed.entries)) existing = parsed;
|
|
15364
|
+
} catch {
|
|
15365
|
+
}
|
|
15366
|
+
const next = foldTurnInitiatorLedger(existing, marker);
|
|
15367
|
+
const tmp = `${ledgerFile}.${process.pid}.${Date.now()}.tmp`;
|
|
15368
|
+
writeFileSync6(tmp, JSON.stringify(next), "utf8");
|
|
15369
|
+
renameSync2(tmp, ledgerFile);
|
|
15370
|
+
}
|
|
15371
|
+
|
|
15372
|
+
// src/scheduled-turn-marker.ts
|
|
15373
|
+
import { readFileSync as readFileSync6, unlinkSync as unlinkSync2 } from "fs";
|
|
15374
|
+
import { join as join9 } from "path";
|
|
15375
|
+
var SCHEDULED_TURN_MAX_AGE_MS = 15 * 60 * 1e3;
|
|
15376
|
+
|
|
15377
|
+
// src/turn-context.ts
|
|
15378
|
+
var TURN_INITIATOR_MARKER_FILENAME = ".current-turn-initiator.json";
|
|
15379
|
+
function writeUnattributedTurnMarker(channel, opts = {}) {
|
|
15380
|
+
try {
|
|
15381
|
+
const file = resolveTurnInitiatorFile(opts.env ?? process.env, opts.home ?? homedir3());
|
|
15382
|
+
if (!file) return;
|
|
15383
|
+
mkdirSync6(dirname3(file), { recursive: true });
|
|
15384
|
+
updateTurnInitiatorLedger(file, {
|
|
15385
|
+
channel,
|
|
15386
|
+
sender_id: "",
|
|
15387
|
+
channel_ref: "unattributed",
|
|
15388
|
+
unattributed: true,
|
|
15389
|
+
ts: opts.now ?? Date.now()
|
|
15390
|
+
});
|
|
15391
|
+
} catch {
|
|
15392
|
+
}
|
|
15393
|
+
}
|
|
15394
|
+
function resolveTurnInitiatorFile(env = process.env, home = homedir3()) {
|
|
15395
|
+
const injected = env["AGT_TURN_INITIATOR_FILE"]?.trim();
|
|
15396
|
+
if (injected) return injected;
|
|
15397
|
+
const dir = resolveAgentDirAlias({
|
|
15398
|
+
codeName: env["AGT_AGENT_CODE_NAME"],
|
|
15399
|
+
agentId: env["AGT_AGENT_ID"],
|
|
15400
|
+
turnInitiatorFile: null,
|
|
15401
|
+
homeDir: home
|
|
15402
|
+
});
|
|
15403
|
+
return dir ? join10(dir, TURN_INITIATOR_MARKER_FILENAME) : null;
|
|
15404
|
+
}
|
|
15405
|
+
|
|
15283
15406
|
// src/teams-channel.ts
|
|
15284
15407
|
var APP_ID = process.env.MSTEAMS_APP_ID ?? null;
|
|
15285
15408
|
var CLIENT_SECRET = process.env.MSTEAMS_CLIENT_SECRET ?? null;
|
|
@@ -15363,7 +15486,7 @@ var ADAPTIVE_CARDS_ENABLED = process.env.MSTEAMS_ADAPTIVE_CARDS_ENABLED === "tru
|
|
|
15363
15486
|
var ADAPTIVE_CARDS_ASK_USER_ENABLED = process.env.MSTEAMS_ADAPTIVE_CARDS_ASK_USER_ENABLED === "true";
|
|
15364
15487
|
var ASK_USER_DEFAULT_TIMEOUT_SECONDS = 300;
|
|
15365
15488
|
var ASK_USER_POLL_INTERVAL_MS = 1e3;
|
|
15366
|
-
var PROJECT_DIR = AGENT_CODE_NAME ? resolvePath2(
|
|
15489
|
+
var PROJECT_DIR = AGENT_CODE_NAME ? resolvePath2(join11(homedir4(), ".augmented", AGENT_CODE_NAME, "project")) : null;
|
|
15367
15490
|
var MAX_UPLOAD_BYTES = 4 * 1024 * 1024;
|
|
15368
15491
|
var AAD_TOKEN_URL = (tenantId) => `https://login.microsoftonline.com/${encodeURIComponent(tenantId)}/oauth2/v2.0/token`;
|
|
15369
15492
|
var BOT_FRAMEWORK_SCOPE = "https://api.botframework.com/.default";
|
|
@@ -15485,7 +15608,7 @@ var trackedThreads = /* @__PURE__ */ new Map();
|
|
|
15485
15608
|
var threadPersister = null;
|
|
15486
15609
|
function threadStorePath() {
|
|
15487
15610
|
if (!AGENT_CODE_NAME) return null;
|
|
15488
|
-
return
|
|
15611
|
+
return join11(homedir4(), ".augmented", AGENT_CODE_NAME, "msteams-tracked-threads.json");
|
|
15489
15612
|
}
|
|
15490
15613
|
function loadTrackedThreads() {
|
|
15491
15614
|
const path = threadStorePath();
|
|
@@ -15530,14 +15653,14 @@ function rememberThread(conversationId, serviceUrl, mode, activityId) {
|
|
|
15530
15653
|
});
|
|
15531
15654
|
threadPersister?.schedule(trackedThreads);
|
|
15532
15655
|
}
|
|
15533
|
-
var AGENT_DIR = AGENT_CODE_NAME ?
|
|
15534
|
-
var PENDING_INBOUND_DIR = AGENT_DIR ?
|
|
15535
|
-
var PROCESSED_DIR = PENDING_INBOUND_DIR ?
|
|
15656
|
+
var AGENT_DIR = AGENT_CODE_NAME ? join11(homedir4(), ".augmented", AGENT_CODE_NAME) : null;
|
|
15657
|
+
var PENDING_INBOUND_DIR = AGENT_DIR ? join11(AGENT_DIR, "msteams-pending-inbound") : null;
|
|
15658
|
+
var PROCESSED_DIR = PENDING_INBOUND_DIR ? join11(PENDING_INBOUND_DIR, ".processed") : null;
|
|
15536
15659
|
function ensurePendingDirs() {
|
|
15537
15660
|
if (!PENDING_INBOUND_DIR || !PROCESSED_DIR) return;
|
|
15538
15661
|
try {
|
|
15539
|
-
|
|
15540
|
-
|
|
15662
|
+
mkdirSync7(PENDING_INBOUND_DIR, { recursive: true });
|
|
15663
|
+
mkdirSync7(PROCESSED_DIR, { recursive: true });
|
|
15541
15664
|
} catch (err) {
|
|
15542
15665
|
process.stderr.write(
|
|
15543
15666
|
`teams-channel: failed to ensure pending-inbound dir (${err.message})
|
|
@@ -15548,10 +15671,10 @@ function ensurePendingDirs() {
|
|
|
15548
15671
|
async function processPendingFile(filename) {
|
|
15549
15672
|
if (!PENDING_INBOUND_DIR || !PROCESSED_DIR) return;
|
|
15550
15673
|
if (!filename.endsWith(".json")) return;
|
|
15551
|
-
const fullPath =
|
|
15674
|
+
const fullPath = join11(PENDING_INBOUND_DIR, filename);
|
|
15552
15675
|
let activity;
|
|
15553
15676
|
try {
|
|
15554
|
-
const raw =
|
|
15677
|
+
const raw = readFileSync8(fullPath, "utf8");
|
|
15555
15678
|
activity = JSON.parse(raw);
|
|
15556
15679
|
} catch (err) {
|
|
15557
15680
|
process.stderr.write(
|
|
@@ -15560,7 +15683,7 @@ async function processPendingFile(filename) {
|
|
|
15560
15683
|
);
|
|
15561
15684
|
if (PROCESSED_DIR) {
|
|
15562
15685
|
try {
|
|
15563
|
-
|
|
15686
|
+
renameSync3(fullPath, join11(PROCESSED_DIR, `${filename}.invalid`));
|
|
15564
15687
|
} catch {
|
|
15565
15688
|
}
|
|
15566
15689
|
}
|
|
@@ -15574,7 +15697,7 @@ async function processPendingFile(filename) {
|
|
|
15574
15697
|
peerAgentMode: PEER_AGENT_MODE
|
|
15575
15698
|
});
|
|
15576
15699
|
try {
|
|
15577
|
-
|
|
15700
|
+
renameSync3(fullPath, join11(PROCESSED_DIR, filename));
|
|
15578
15701
|
} catch {
|
|
15579
15702
|
return;
|
|
15580
15703
|
}
|
|
@@ -15704,6 +15827,7 @@ async function emitChannelNotification(activity, flags = {}) {
|
|
|
15704
15827
|
lane: "conversational",
|
|
15705
15828
|
expectsReply: !flags.isPeerListen
|
|
15706
15829
|
});
|
|
15830
|
+
writeUnattributedTurnMarker("msteams");
|
|
15707
15831
|
try {
|
|
15708
15832
|
await mcp.notification({
|
|
15709
15833
|
method: "notifications/claude/channel",
|
|
@@ -15730,7 +15854,7 @@ function startPendingInboundWatcher() {
|
|
|
15730
15854
|
}
|
|
15731
15855
|
ensurePendingDirs();
|
|
15732
15856
|
try {
|
|
15733
|
-
const entries = readdirSync3(PENDING_INBOUND_DIR).filter((f) => f.endsWith(".json")).map((f) => ({ f, m: safeMtimeMs(
|
|
15857
|
+
const entries = readdirSync3(PENDING_INBOUND_DIR).filter((f) => f.endsWith(".json")).map((f) => ({ f, m: safeMtimeMs(join11(PENDING_INBOUND_DIR, f)) })).sort((a, b) => a.m - b.m).map((e) => e.f);
|
|
15734
15858
|
for (const f of entries) {
|
|
15735
15859
|
void processPendingFile(f).catch((err) => {
|
|
15736
15860
|
process.stderr.write(
|
|
@@ -15755,7 +15879,7 @@ function startPendingInboundWatcher() {
|
|
|
15755
15879
|
if (!name || typeof name !== "string") return;
|
|
15756
15880
|
if (!name.endsWith(".json")) return;
|
|
15757
15881
|
if (name.startsWith(".")) return;
|
|
15758
|
-
const fullPath =
|
|
15882
|
+
const fullPath = join11(PENDING_INBOUND_DIR, name);
|
|
15759
15883
|
try {
|
|
15760
15884
|
statSync(fullPath);
|
|
15761
15885
|
} catch {
|
|
@@ -16191,11 +16315,11 @@ function optionalStringArg(args, key2) {
|
|
|
16191
16315
|
function errResult(text) {
|
|
16192
16316
|
return { content: [{ type: "text", text }], isError: true };
|
|
16193
16317
|
}
|
|
16194
|
-
var PENDING_INTERACTIONS_DIR = AGENT_DIR ?
|
|
16318
|
+
var PENDING_INTERACTIONS_DIR = AGENT_DIR ? join11(AGENT_DIR, "msteams-pending-interactions") : null;
|
|
16195
16319
|
function ensurePendingInteractionsDir() {
|
|
16196
16320
|
if (!PENDING_INTERACTIONS_DIR) return;
|
|
16197
16321
|
try {
|
|
16198
|
-
|
|
16322
|
+
mkdirSync7(PENDING_INTERACTIONS_DIR, { recursive: true });
|
|
16199
16323
|
} catch (err) {
|
|
16200
16324
|
process.stderr.write(
|
|
16201
16325
|
`teams-channel: failed to ensure pending-interactions dir (${err.message})
|
|
@@ -16206,16 +16330,16 @@ function ensurePendingInteractionsDir() {
|
|
|
16206
16330
|
function writePendingInteraction(entry) {
|
|
16207
16331
|
if (!PENDING_INTERACTIONS_DIR) return;
|
|
16208
16332
|
ensurePendingInteractionsDir();
|
|
16209
|
-
|
|
16210
|
-
|
|
16333
|
+
writeFileSync7(
|
|
16334
|
+
join11(PENDING_INTERACTIONS_DIR, `${entry.interaction_id}.json`),
|
|
16211
16335
|
JSON.stringify(entry, null, 2)
|
|
16212
16336
|
);
|
|
16213
16337
|
}
|
|
16214
16338
|
function readInteractionAnswer(interactionId) {
|
|
16215
16339
|
if (!PENDING_INTERACTIONS_DIR) return null;
|
|
16216
|
-
const path =
|
|
16340
|
+
const path = join11(PENDING_INTERACTIONS_DIR, `${interactionId}.answer.json`);
|
|
16217
16341
|
try {
|
|
16218
|
-
const raw =
|
|
16342
|
+
const raw = readFileSync8(path, "utf8");
|
|
16219
16343
|
const parsed = JSON.parse(raw);
|
|
16220
16344
|
if (typeof parsed.value !== "string") return null;
|
|
16221
16345
|
return {
|
|
@@ -16237,9 +16361,9 @@ function readInteractionAnswer(interactionId) {
|
|
|
16237
16361
|
function clearPendingInteraction(interactionId) {
|
|
16238
16362
|
if (!PENDING_INTERACTIONS_DIR) return;
|
|
16239
16363
|
for (const suffix of [".json", ".answer.json"]) {
|
|
16240
|
-
const path =
|
|
16364
|
+
const path = join11(PENDING_INTERACTIONS_DIR, `${interactionId}${suffix}`);
|
|
16241
16365
|
try {
|
|
16242
|
-
|
|
16366
|
+
unlinkSync3(path);
|
|
16243
16367
|
} catch (err) {
|
|
16244
16368
|
const code = err.code;
|
|
16245
16369
|
if (code !== "ENOENT") {
|
|
@@ -16401,7 +16525,7 @@ async function handleUploadFile(args) {
|
|
|
16401
16525
|
);
|
|
16402
16526
|
}
|
|
16403
16527
|
try {
|
|
16404
|
-
buffer =
|
|
16528
|
+
buffer = readFileSync8(sandboxed.resolved);
|
|
16405
16529
|
} catch (err) {
|
|
16406
16530
|
return errResult(`Failed to read file: ${err.message}`);
|
|
16407
16531
|
}
|
|
@@ -16444,10 +16568,10 @@ async function handleUploadFile(args) {
|
|
|
16444
16568
|
return errResult(`Failed: ${err.message}`);
|
|
16445
16569
|
}
|
|
16446
16570
|
}
|
|
16447
|
-
var PENDING_MARKER_DIR = PENDING_INBOUND_DIR ?
|
|
16448
|
-
var RECOVERY_OUTBOX_DIR = AGENT_DIR ?
|
|
16449
|
-
var RECOVERY_LEDGER_DIR = AGENT_DIR ?
|
|
16450
|
-
var DELIVERY_LEDGER_DIR = AGENT_DIR ?
|
|
16571
|
+
var PENDING_MARKER_DIR = PENDING_INBOUND_DIR ? join11(PENDING_INBOUND_DIR, ".markers") : null;
|
|
16572
|
+
var RECOVERY_OUTBOX_DIR = AGENT_DIR ? join11(AGENT_DIR, "msteams-recovery-outbox") : null;
|
|
16573
|
+
var RECOVERY_LEDGER_DIR = AGENT_DIR ? join11(AGENT_DIR, ".agt-msteams-recovery-ledger") : null;
|
|
16574
|
+
var DELIVERY_LEDGER_DIR = AGENT_DIR ? join11(AGENT_DIR, ".agt-inbound-delivery-ledger") : null;
|
|
16451
16575
|
var STALE_MARKER_MS = 24 * 60 * 60 * 1e3;
|
|
16452
16576
|
var RECOVERY_RETRY_SCAN_INTERVAL_MS = 6e4;
|
|
16453
16577
|
var RECOVERY_RETRY_BACKOFFS_MS = [6e4, 12e4, 24e4];
|
|
@@ -16456,7 +16580,7 @@ function ensureGhostReplyDirs() {
|
|
|
16456
16580
|
for (const dir of [PENDING_MARKER_DIR, RECOVERY_OUTBOX_DIR]) {
|
|
16457
16581
|
if (!dir) continue;
|
|
16458
16582
|
try {
|
|
16459
|
-
|
|
16583
|
+
mkdirSync7(dir, { recursive: true });
|
|
16460
16584
|
} catch (err) {
|
|
16461
16585
|
process.stderr.write(
|
|
16462
16586
|
`teams-channel: failed to ensure ${dir} (${err.message})
|
|
@@ -16474,8 +16598,8 @@ function writePendingMarker(activity) {
|
|
|
16474
16598
|
ensureGhostReplyDirs();
|
|
16475
16599
|
const name = safeMarkerName(activity.conversation.id, activity.id);
|
|
16476
16600
|
try {
|
|
16477
|
-
|
|
16478
|
-
|
|
16601
|
+
writeFileSync7(
|
|
16602
|
+
join11(PENDING_MARKER_DIR, name),
|
|
16479
16603
|
JSON.stringify(
|
|
16480
16604
|
{
|
|
16481
16605
|
conversation_id: activity.conversation.id,
|
|
@@ -16511,7 +16635,7 @@ function clearPendingMarkersForConversation(conversationId) {
|
|
|
16511
16635
|
for (const f of entries) {
|
|
16512
16636
|
if (f.startsWith(`${safe}--`)) {
|
|
16513
16637
|
try {
|
|
16514
|
-
|
|
16638
|
+
unlinkSync3(join11(PENDING_MARKER_DIR, f));
|
|
16515
16639
|
} catch {
|
|
16516
16640
|
}
|
|
16517
16641
|
}
|
|
@@ -16528,11 +16652,11 @@ function sweepStaleMarkersOnBoot() {
|
|
|
16528
16652
|
let pruned = 0;
|
|
16529
16653
|
const now = Date.now();
|
|
16530
16654
|
for (const f of entries) {
|
|
16531
|
-
const path =
|
|
16655
|
+
const path = join11(PENDING_MARKER_DIR, f);
|
|
16532
16656
|
try {
|
|
16533
16657
|
const stats = statSync(path);
|
|
16534
16658
|
if (now - stats.mtimeMs > STALE_MARKER_MS) {
|
|
16535
|
-
|
|
16659
|
+
unlinkSync3(path);
|
|
16536
16660
|
pruned++;
|
|
16537
16661
|
}
|
|
16538
16662
|
} catch {
|
|
@@ -16560,17 +16684,17 @@ function recoveryNextAttempt(filename) {
|
|
|
16560
16684
|
}
|
|
16561
16685
|
async function processRecoveryFile(filename) {
|
|
16562
16686
|
if (!RECOVERY_OUTBOX_DIR) return;
|
|
16563
|
-
const fullPath =
|
|
16687
|
+
const fullPath = join11(RECOVERY_OUTBOX_DIR, filename);
|
|
16564
16688
|
let payload;
|
|
16565
16689
|
try {
|
|
16566
|
-
payload = JSON.parse(
|
|
16690
|
+
payload = JSON.parse(readFileSync8(fullPath, "utf8"));
|
|
16567
16691
|
} catch (err) {
|
|
16568
16692
|
process.stderr.write(
|
|
16569
16693
|
`teams-channel: recovery file ${filename} unreadable (${err.message}) \u2014 dropping
|
|
16570
16694
|
`
|
|
16571
16695
|
);
|
|
16572
16696
|
try {
|
|
16573
|
-
|
|
16697
|
+
unlinkSync3(fullPath);
|
|
16574
16698
|
} catch {
|
|
16575
16699
|
}
|
|
16576
16700
|
return;
|
|
@@ -16581,7 +16705,7 @@ async function processRecoveryFile(filename) {
|
|
|
16581
16705
|
const malformedMarker = typeof payload === "object" && payload && "marker_name" in payload ? payload.marker_name : void 0;
|
|
16582
16706
|
removeRecoveryLedgerEntry(RECOVERY_LEDGER_DIR, malformedMarker);
|
|
16583
16707
|
try {
|
|
16584
|
-
|
|
16708
|
+
unlinkSync3(fullPath);
|
|
16585
16709
|
} catch {
|
|
16586
16710
|
}
|
|
16587
16711
|
return;
|
|
@@ -16608,7 +16732,7 @@ async function processRecoveryFile(filename) {
|
|
|
16608
16732
|
clearPendingMarkersForConversation(payload.conversation_id);
|
|
16609
16733
|
removeRecoveryLedgerEntry(RECOVERY_LEDGER_DIR, payload.marker_name);
|
|
16610
16734
|
try {
|
|
16611
|
-
|
|
16735
|
+
unlinkSync3(fullPath);
|
|
16612
16736
|
} catch {
|
|
16613
16737
|
}
|
|
16614
16738
|
return;
|
|
@@ -16623,7 +16747,7 @@ async function processRecoveryFile(filename) {
|
|
|
16623
16747
|
clearPendingMarkersForConversation(payload.conversation_id);
|
|
16624
16748
|
removeRecoveryLedgerEntry(RECOVERY_LEDGER_DIR, payload.marker_name);
|
|
16625
16749
|
try {
|
|
16626
|
-
|
|
16750
|
+
unlinkSync3(fullPath);
|
|
16627
16751
|
} catch {
|
|
16628
16752
|
}
|
|
16629
16753
|
process.stderr.write(`teams-channel: recovery delivered ${filename}
|
|
@@ -16637,13 +16761,13 @@ async function processRecoveryFile(filename) {
|
|
|
16637
16761
|
);
|
|
16638
16762
|
removeRecoveryLedgerEntry(RECOVERY_LEDGER_DIR, payload.marker_name);
|
|
16639
16763
|
try {
|
|
16640
|
-
|
|
16764
|
+
unlinkSync3(fullPath);
|
|
16641
16765
|
} catch {
|
|
16642
16766
|
}
|
|
16643
16767
|
return;
|
|
16644
16768
|
}
|
|
16645
16769
|
try {
|
|
16646
|
-
|
|
16770
|
+
renameSync3(fullPath, join11(RECOVERY_OUTBOX_DIR, next.next));
|
|
16647
16771
|
process.stderr.write(
|
|
16648
16772
|
`teams-channel: recovery ${filename} \u2192 attempt ${next.attempt} (${err.message})
|
|
16649
16773
|
`
|
|
@@ -16669,7 +16793,7 @@ function startRecoveryOutboxWatcher() {
|
|
|
16669
16793
|
for (const f of entries) {
|
|
16670
16794
|
if (!f.endsWith(".json")) continue;
|
|
16671
16795
|
if (f.startsWith(".")) continue;
|
|
16672
|
-
const path =
|
|
16796
|
+
const path = join11(RECOVERY_OUTBOX_DIR, f);
|
|
16673
16797
|
let mtimeMs;
|
|
16674
16798
|
try {
|
|
16675
16799
|
mtimeMs = statSync(path).mtimeMs;
|
|
@@ -16694,7 +16818,7 @@ function startRecoveryOutboxWatcher() {
|
|
|
16694
16818
|
if (!name || typeof name !== "string") return;
|
|
16695
16819
|
if (!name.endsWith(".json")) return;
|
|
16696
16820
|
if (name.startsWith(".")) return;
|
|
16697
|
-
const path =
|
|
16821
|
+
const path = join11(RECOVERY_OUTBOX_DIR, name);
|
|
16698
16822
|
let mtimeMs;
|
|
16699
16823
|
try {
|
|
16700
16824
|
mtimeMs = statSync(path).mtimeMs;
|
|
@@ -16760,7 +16884,7 @@ ensureGhostReplyDirs();
|
|
|
16760
16884
|
sweepStaleMarkersOnBoot();
|
|
16761
16885
|
startPendingInboundWatcher();
|
|
16762
16886
|
startRecoveryOutboxWatcher();
|
|
16763
|
-
var NOTICE_OUTBOX_DIR = AGENT_DIR ?
|
|
16887
|
+
var NOTICE_OUTBOX_DIR = AGENT_DIR ? join11(AGENT_DIR, "msteams-notice-outbox") : null;
|
|
16764
16888
|
var NOTICE_MAX_AGE_MS = 9e4;
|
|
16765
16889
|
function isNoticePayload(value) {
|
|
16766
16890
|
if (!value || typeof value !== "object") return false;
|
|
@@ -16774,7 +16898,7 @@ async function processNoticeFile(filename) {
|
|
|
16774
16898
|
if (filename.startsWith(".") || filename.endsWith(".tmp") || !filename.endsWith(".json")) return;
|
|
16775
16899
|
if (NOTICE_INFLIGHT.has(filename)) return;
|
|
16776
16900
|
NOTICE_INFLIGHT.add(filename);
|
|
16777
|
-
const fullPath =
|
|
16901
|
+
const fullPath = join11(NOTICE_OUTBOX_DIR, filename);
|
|
16778
16902
|
try {
|
|
16779
16903
|
let mtimeMs;
|
|
16780
16904
|
try {
|
|
@@ -16784,24 +16908,24 @@ async function processNoticeFile(filename) {
|
|
|
16784
16908
|
}
|
|
16785
16909
|
if (Date.now() - mtimeMs > NOTICE_MAX_AGE_MS) {
|
|
16786
16910
|
try {
|
|
16787
|
-
|
|
16911
|
+
unlinkSync3(fullPath);
|
|
16788
16912
|
} catch {
|
|
16789
16913
|
}
|
|
16790
16914
|
return;
|
|
16791
16915
|
}
|
|
16792
16916
|
let payload;
|
|
16793
16917
|
try {
|
|
16794
|
-
payload = JSON.parse(
|
|
16918
|
+
payload = JSON.parse(readFileSync8(fullPath, "utf8"));
|
|
16795
16919
|
} catch {
|
|
16796
16920
|
try {
|
|
16797
|
-
|
|
16921
|
+
unlinkSync3(fullPath);
|
|
16798
16922
|
} catch {
|
|
16799
16923
|
}
|
|
16800
16924
|
return;
|
|
16801
16925
|
}
|
|
16802
16926
|
if (!isNoticePayload(payload)) {
|
|
16803
16927
|
try {
|
|
16804
|
-
|
|
16928
|
+
unlinkSync3(fullPath);
|
|
16805
16929
|
} catch {
|
|
16806
16930
|
}
|
|
16807
16931
|
return;
|
|
@@ -16812,7 +16936,7 @@ async function processNoticeFile(filename) {
|
|
|
16812
16936
|
defaultValue: false
|
|
16813
16937
|
})) {
|
|
16814
16938
|
try {
|
|
16815
|
-
|
|
16939
|
+
unlinkSync3(fullPath);
|
|
16816
16940
|
} catch {
|
|
16817
16941
|
}
|
|
16818
16942
|
return;
|
|
@@ -16832,7 +16956,7 @@ async function processNoticeFile(filename) {
|
|
|
16832
16956
|
);
|
|
16833
16957
|
}
|
|
16834
16958
|
try {
|
|
16835
|
-
|
|
16959
|
+
unlinkSync3(fullPath);
|
|
16836
16960
|
} catch {
|
|
16837
16961
|
}
|
|
16838
16962
|
} finally {
|
|
@@ -16842,7 +16966,7 @@ async function processNoticeFile(filename) {
|
|
|
16842
16966
|
function startNoticeOutboxWatcher() {
|
|
16843
16967
|
if (!NOTICE_OUTBOX_DIR) return;
|
|
16844
16968
|
try {
|
|
16845
|
-
|
|
16969
|
+
mkdirSync7(NOTICE_OUTBOX_DIR, { recursive: true, mode: 448 });
|
|
16846
16970
|
} catch (err) {
|
|
16847
16971
|
process.stderr.write(`teams-channel: notice outbox mkdir failed (${err.message})
|
|
16848
16972
|
`);
|
|
@@ -16855,7 +16979,7 @@ function startNoticeOutboxWatcher() {
|
|
|
16855
16979
|
try {
|
|
16856
16980
|
const w = watch(NOTICE_OUTBOX_DIR, (_event, name) => {
|
|
16857
16981
|
if (!name) return;
|
|
16858
|
-
if (existsSync6(
|
|
16982
|
+
if (existsSync6(join11(NOTICE_OUTBOX_DIR, name))) void processNoticeFile(name);
|
|
16859
16983
|
});
|
|
16860
16984
|
w.unref?.();
|
|
16861
16985
|
} catch (err) {
|