@integrity-labs/agt-cli 0.24.9 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15423,8 +15423,80 @@ function createCrossTeamPeerAuditClient(args) {
15423
15423
  };
15424
15424
  }
15425
15425
 
15426
- // src/slack-bot-user-id-client.ts
15426
+ // src/conversation-ingest-client.ts
15427
15427
  var REQUEST_TIMEOUT_MS2 = 1e4;
15428
+ function createConversationIngestClient(args) {
15429
+ if (!args.agtHost || !args.agtApiKey || !args.agentId) return null;
15430
+ const fetchImpl = args.fetchImpl ?? fetch;
15431
+ const log = args.log ?? (() => {
15432
+ });
15433
+ const base = args.agtHost.replace(/\/+$/, "");
15434
+ const agentId = args.agentId;
15435
+ const apiKey = args.agtApiKey;
15436
+ let cachedToken = null;
15437
+ let cachedTokenExpiresAt = 0;
15438
+ async function getToken() {
15439
+ if (cachedToken && Date.now() < cachedTokenExpiresAt) return cachedToken;
15440
+ const resp = await fetchImpl(`${base}/host/exchange`, {
15441
+ method: "POST",
15442
+ headers: { "Content-Type": "application/json" },
15443
+ body: JSON.stringify({ host_key: apiKey }),
15444
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
15445
+ });
15446
+ if (!resp.ok) {
15447
+ const body = await resp.text().catch(() => "");
15448
+ throw new Error(`/host/exchange failed (${resp.status}): ${body.slice(0, 200)}`);
15449
+ }
15450
+ const data = await resp.json();
15451
+ cachedToken = data.token;
15452
+ if (data.expires_at) {
15453
+ const expiresAt = new Date(data.expires_at).getTime();
15454
+ const buffer = Math.min(12e4, Math.max(0, expiresAt - Date.now() - 1e3));
15455
+ cachedTokenExpiresAt = Math.max(Date.now() + 1e3, expiresAt - buffer);
15456
+ } else {
15457
+ cachedTokenExpiresAt = Date.now() + 55 * 6e4;
15458
+ }
15459
+ return cachedToken;
15460
+ }
15461
+ async function postOnce(payload) {
15462
+ const token = await getToken();
15463
+ return fetchImpl(`${base}/host/conversations/ingest`, {
15464
+ method: "POST",
15465
+ headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
15466
+ body: JSON.stringify({ agent_id: agentId, ...payload }),
15467
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
15468
+ });
15469
+ }
15470
+ function refKey(payload) {
15471
+ return payload.channel === "slack" ? `slack:${payload.channel_id}` : `telegram:${payload.chat_id}`;
15472
+ }
15473
+ async function emitAsync(payload) {
15474
+ try {
15475
+ let resp = await postOnce(payload);
15476
+ if (resp.status === 401) {
15477
+ cachedToken = null;
15478
+ cachedTokenExpiresAt = 0;
15479
+ resp = await postOnce(payload);
15480
+ }
15481
+ if (!resp.ok) {
15482
+ const body = await resp.text().catch(() => "");
15483
+ log(
15484
+ `conversation-ingest: POST failed (${resp.status}) ${refKey(payload)}: ${body.slice(0, 200)}`
15485
+ );
15486
+ }
15487
+ } catch (err) {
15488
+ log(`conversation-ingest: emit threw ${refKey(payload)}: ${err.message}`);
15489
+ }
15490
+ }
15491
+ return {
15492
+ ingest(payload) {
15493
+ void emitAsync(payload);
15494
+ }
15495
+ };
15496
+ }
15497
+
15498
+ // src/slack-bot-user-id-client.ts
15499
+ var REQUEST_TIMEOUT_MS3 = 1e4;
15428
15500
  function createSlackBotUserIdClient(args) {
15429
15501
  if (!args.agtHost || !args.agtApiKey || !args.agentId) return null;
15430
15502
  const fetchImpl = args.fetchImpl ?? fetch;
@@ -15442,7 +15514,7 @@ function createSlackBotUserIdClient(args) {
15442
15514
  method: "POST",
15443
15515
  headers: { "Content-Type": "application/json" },
15444
15516
  body: JSON.stringify({ host_key: apiKey }),
15445
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
15517
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS3)
15446
15518
  });
15447
15519
  if (!resp.ok) {
15448
15520
  const body = await resp.text().catch(() => "");
@@ -15459,7 +15531,7 @@ function createSlackBotUserIdClient(args) {
15459
15531
  method: "POST",
15460
15532
  headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
15461
15533
  body: JSON.stringify({ agent_id: agentId, bot_user_id: botUserId2 }),
15462
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
15534
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS3)
15463
15535
  });
15464
15536
  }
15465
15537
  async function emitAsync(botUserId2) {
@@ -15491,7 +15563,7 @@ function createSlackBotUserIdClient(args) {
15491
15563
  method: "POST",
15492
15564
  headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
15493
15565
  body: JSON.stringify({ agent_id: agentId, channel_id: "slack", healthy }),
15494
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
15566
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS3)
15495
15567
  });
15496
15568
  };
15497
15569
  try {
@@ -15573,6 +15645,13 @@ var crossTeamPeerAuditClient = createCrossTeamPeerAuditClient({
15573
15645
  log: (line) => process.stderr.write(`slack-channel: ${line}
15574
15646
  `)
15575
15647
  });
15648
+ var conversationIngestClient = createConversationIngestClient({
15649
+ agtHost: AGT_HOST,
15650
+ agtApiKey: AGT_API_KEY,
15651
+ agentId: AGT_AGENT_ID,
15652
+ log: (line) => process.stderr.write(`slack-channel: ${line}
15653
+ `)
15654
+ });
15576
15655
  var SLACK_PEER_CLASSIFIER_CONFIG = {
15577
15656
  peer_agent_mode: parsePeerAgentModeEnv(process.env.SLACK_PEER_AGENT_MODE),
15578
15657
  peer_group_ids: parsePeerGroupIdsEnv(process.env.SLACK_PEER_GROUP_IDS),
@@ -17935,6 +18014,17 @@ async function connectSocketMode() {
17935
18014
  }
17936
18015
  }
17937
18016
  });
18017
+ if (channel) {
18018
+ conversationIngestClient?.ingest({
18019
+ channel: "slack",
18020
+ channel_id: channel,
18021
+ thread_ts: threadTs,
18022
+ user_id: user,
18023
+ user_name: userName,
18024
+ is_bot: isFromBot,
18025
+ bot_id: evt.bot_id ?? null
18026
+ });
18027
+ }
17938
18028
  } catch (err) {
17939
18029
  process.stderr.write(`slack-channel: Event error: ${err.message}
17940
18030
  `);
@@ -15245,6 +15245,78 @@ function createObservedChatClient(args) {
15245
15245
  };
15246
15246
  }
15247
15247
 
15248
+ // src/conversation-ingest-client.ts
15249
+ var REQUEST_TIMEOUT_MS3 = 1e4;
15250
+ function createConversationIngestClient(args) {
15251
+ if (!args.agtHost || !args.agtApiKey || !args.agentId) return null;
15252
+ const fetchImpl = args.fetchImpl ?? fetch;
15253
+ const log = args.log ?? (() => {
15254
+ });
15255
+ const base = args.agtHost.replace(/\/+$/, "");
15256
+ const agentId = args.agentId;
15257
+ const apiKey = args.agtApiKey;
15258
+ let cachedToken = null;
15259
+ let cachedTokenExpiresAt = 0;
15260
+ async function getToken() {
15261
+ if (cachedToken && Date.now() < cachedTokenExpiresAt) return cachedToken;
15262
+ const resp = await fetchImpl(`${base}/host/exchange`, {
15263
+ method: "POST",
15264
+ headers: { "Content-Type": "application/json" },
15265
+ body: JSON.stringify({ host_key: apiKey }),
15266
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS3)
15267
+ });
15268
+ if (!resp.ok) {
15269
+ const body = await resp.text().catch(() => "");
15270
+ throw new Error(`/host/exchange failed (${resp.status}): ${body.slice(0, 200)}`);
15271
+ }
15272
+ const data = await resp.json();
15273
+ cachedToken = data.token;
15274
+ if (data.expires_at) {
15275
+ const expiresAt = new Date(data.expires_at).getTime();
15276
+ const buffer = Math.min(12e4, Math.max(0, expiresAt - Date.now() - 1e3));
15277
+ cachedTokenExpiresAt = Math.max(Date.now() + 1e3, expiresAt - buffer);
15278
+ } else {
15279
+ cachedTokenExpiresAt = Date.now() + 55 * 6e4;
15280
+ }
15281
+ return cachedToken;
15282
+ }
15283
+ async function postOnce(payload) {
15284
+ const token = await getToken();
15285
+ return fetchImpl(`${base}/host/conversations/ingest`, {
15286
+ method: "POST",
15287
+ headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
15288
+ body: JSON.stringify({ agent_id: agentId, ...payload }),
15289
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS3)
15290
+ });
15291
+ }
15292
+ function refKey(payload) {
15293
+ return payload.channel === "slack" ? `slack:${payload.channel_id}` : `telegram:${payload.chat_id}`;
15294
+ }
15295
+ async function emitAsync(payload) {
15296
+ try {
15297
+ let resp = await postOnce(payload);
15298
+ if (resp.status === 401) {
15299
+ cachedToken = null;
15300
+ cachedTokenExpiresAt = 0;
15301
+ resp = await postOnce(payload);
15302
+ }
15303
+ if (!resp.ok) {
15304
+ const body = await resp.text().catch(() => "");
15305
+ log(
15306
+ `conversation-ingest: POST failed (${resp.status}) ${refKey(payload)}: ${body.slice(0, 200)}`
15307
+ );
15308
+ }
15309
+ } catch (err) {
15310
+ log(`conversation-ingest: emit threw ${refKey(payload)}: ${err.message}`);
15311
+ }
15312
+ }
15313
+ return {
15314
+ ingest(payload) {
15315
+ void emitAsync(payload);
15316
+ }
15317
+ };
15318
+ }
15319
+
15248
15320
  // src/progress-tools.ts
15249
15321
  import { randomUUID } from "crypto";
15250
15322
 
@@ -15723,6 +15795,13 @@ var observedChatClient = createObservedChatClient({
15723
15795
  log: (line) => process.stderr.write(`telegram-channel(${AGENT_CODE_NAME}): ${line}
15724
15796
  `)
15725
15797
  });
15798
+ var conversationIngestClient = createConversationIngestClient({
15799
+ agtHost: AGT_HOST,
15800
+ agtApiKey: AGT_API_KEY,
15801
+ agentId: process.env.AGT_AGENT_ID ?? null,
15802
+ log: (line) => process.stderr.write(`telegram-channel(${AGENT_CODE_NAME}): ${line}
15803
+ `)
15804
+ });
15726
15805
  var peerRateApiClient = createDefaultPeerRateApiClient({
15727
15806
  agtHost: AGT_HOST,
15728
15807
  agtApiKey: AGT_API_KEY,
@@ -17198,6 +17277,15 @@ async function pollLoop() {
17198
17277
  }
17199
17278
  }
17200
17279
  });
17280
+ conversationIngestClient?.ingest({
17281
+ channel: "telegram",
17282
+ chat_id: chatId,
17283
+ message_thread_id: msg.message_thread_id != null ? String(msg.message_thread_id) : null,
17284
+ user_id: userId,
17285
+ user_name: userName,
17286
+ is_bot: isFromBot,
17287
+ is_peer_agent: !!peerAgentMeta
17288
+ });
17201
17289
  }
17202
17290
  } catch (err) {
17203
17291
  if (isShuttingDown) return;
@@ -23,8 +23,8 @@ import {
23
23
  stopPersistentSession,
24
24
  takeZombieDetection,
25
25
  writePersistentClaudeWrapper
26
- } from "./chunk-S262PDVS.js";
27
- import "./chunk-354Z63L7.js";
26
+ } from "./chunk-IEVHEZV4.js";
27
+ import "./chunk-7DRLULIO.js";
28
28
  export {
29
29
  _internals,
30
30
  collectDiagnostics,
@@ -51,4 +51,4 @@ export {
51
51
  takeZombieDetection,
52
52
  writePersistentClaudeWrapper
53
53
  };
54
- //# sourceMappingURL=persistent-session-OYO4DTPL.js.map
54
+ //# sourceMappingURL=persistent-session-3SNFKR2Q.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  paneLogPath
3
- } from "./chunk-S262PDVS.js";
4
- import "./chunk-354Z63L7.js";
3
+ } from "./chunk-IEVHEZV4.js";
4
+ import "./chunk-7DRLULIO.js";
5
5
 
6
6
  // src/lib/responsiveness-probe.ts
7
7
  import { statSync } from "fs";
@@ -29,4 +29,4 @@ export {
29
29
  collectResponsivenessProbes,
30
30
  getResponsivenessIntervalMs
31
31
  };
32
- //# sourceMappingURL=responsiveness-probe-SSFKGL7Q.js.map
32
+ //# sourceMappingURL=responsiveness-probe-UBNJFMAU.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@integrity-labs/agt-cli",
3
- "version": "0.24.9",
3
+ "version": "0.25.0",
4
4
  "description": "Augmented Team CLI — agent provisioning and management",
5
5
  "type": "module",
6
6
  "engines": {