@agent-team-foundation/first-tree-hub 0.9.7 → 0.9.8

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.
@@ -1,6 +1,28 @@
1
1
  import { d as __exportAll } from "./esm-CYu4tXXn.mjs";
2
2
  import { z } from "zod";
3
3
  //#region ../shared/dist/index.mjs
4
+ const MENTION_REGEX = /(?<![A-Za-z0-9_.@-])@([A-Za-z0-9_-]{1,64})\b/g;
5
+ function stripCode(content) {
6
+ return content.replace(/```[\s\S]*?```/g, "").replace(/~~~[\s\S]*?~~~/g, "").replace(/`[^`\n]+`/g, "");
7
+ }
8
+ /**
9
+ * Resolve `@<name>` mentions in `content` to a list of participant agentIds.
10
+ * Names match case-insensitively; unknown `@tokens` are dropped.
11
+ */
12
+ function extractMentions(content, participants) {
13
+ const stripped = stripCode(content);
14
+ const nameMap = /* @__PURE__ */ new Map();
15
+ for (const p of participants) if (p.name) nameMap.set(p.name.toLowerCase(), p.agentId);
16
+ if (nameMap.size === 0) return [];
17
+ const hits = /* @__PURE__ */ new Set();
18
+ for (const m of stripped.matchAll(MENTION_REGEX)) {
19
+ const token = m[1];
20
+ if (!token) continue;
21
+ const id = nameMap.get(token.toLowerCase());
22
+ if (id) hits.add(id);
23
+ }
24
+ return [...hits];
25
+ }
4
26
  const adapterPlatformSchema = z.enum([
5
27
  "feishu",
6
28
  "slack",
@@ -404,6 +426,11 @@ const chatParticipantSchema = z.object({
404
426
  mode: z.string(),
405
427
  joinedAt: z.string()
406
428
  });
429
+ chatParticipantSchema.extend({
430
+ name: z.string().nullable(),
431
+ displayName: z.string().nullable(),
432
+ type: z.string()
433
+ });
407
434
  z.object({
408
435
  id: z.string(),
409
436
  organizationId: z.string(),
@@ -443,6 +470,41 @@ const paginationQuerySchema = z.object({
443
470
  limit: z.coerce.number().int().min(1).max(100).default(20),
444
471
  cursor: z.string().optional()
445
472
  });
473
+ const supportedImageMimeSchema = z.enum([
474
+ "image/png",
475
+ "image/jpeg",
476
+ "image/gif",
477
+ "image/webp"
478
+ ]);
479
+ /**
480
+ * Legacy inbound shape: an image message with base64 bytes inlined into
481
+ * `messages.content`. Web still uploads in this shape so no new endpoint is
482
+ * needed; the server extracts the bytes, broadcasts them as an `image_payload`
483
+ * WS frame, then rewrites `content` to {@link imageRefContentSchema} before
484
+ * the DB insert.
485
+ */
486
+ const imageInlineContentSchema = z.object({
487
+ data: z.string().min(1),
488
+ mimeType: supportedImageMimeSchema,
489
+ filename: z.string().min(1),
490
+ size: z.number().int().nonnegative().optional(),
491
+ imageId: z.string().uuid().optional()
492
+ });
493
+ z.object({
494
+ imageId: z.string().uuid(),
495
+ mimeType: supportedImageMimeSchema,
496
+ filename: z.string().min(1),
497
+ size: z.number().int().nonnegative().optional()
498
+ });
499
+ z.object({
500
+ type: z.literal("image_payload"),
501
+ imageId: z.string().uuid(),
502
+ chatId: z.string(),
503
+ base64: z.string().min(1),
504
+ mimeType: supportedImageMimeSchema,
505
+ filename: z.string().min(1),
506
+ size: z.number().int().nonnegative().optional()
507
+ });
446
508
  const messageSourceSchema = z.enum([
447
509
  "hub_ui",
448
510
  "cli",
@@ -475,17 +537,7 @@ const sendToAgentSchema = z.object({
475
537
  replyToChat: z.string().optional(),
476
538
  source: messageSourceSchema.optional()
477
539
  });
478
- /**
479
- * Wire format for messages routed FROM the Hub TO a client runtime.
480
- *
481
- * Adds `configVersion` so the client can compare against its locally cached
482
- * agent runtime config and refresh before delivering the message to the SDK.
483
- *
484
- * Step 3: this is the single shape used by `buildClientMessagePayload` —
485
- * never serialise a raw `messageSchema` row to a client; always go through
486
- * the dispatcher.
487
- */
488
- const clientMessageSchema = z.object({
540
+ const messageSchema = z.object({
489
541
  id: z.string(),
490
542
  chatId: z.string(),
491
543
  senderId: z.string(),
@@ -497,7 +549,46 @@ const clientMessageSchema = z.object({
497
549
  inReplyTo: z.string().nullable(),
498
550
  source: messageSourceSchema.nullable(),
499
551
  createdAt: z.string()
500
- }).extend({ configVersion: z.number().int().positive() });
552
+ });
553
+ /**
554
+ * Snapshot of the `in_reply_to` target that the server materialises at
555
+ * dispatch time so the receiving runtime can decide whether this is an
556
+ * echo it should suppress (see proposal hub-agent-messaging-reply-and-mentions).
557
+ *
558
+ * `chatId` is the original message's `chat_id`; `replyToChat` is the chat
559
+ * its sender expected replies to flow back to (often a different chat).
560
+ * `null` when the message is not a reply, or the original could not be
561
+ * resolved (e.g. deleted).
562
+ */
563
+ const inReplyToSnapshotSchema = z.object({
564
+ senderId: z.string(),
565
+ chatId: z.string(),
566
+ replyToChat: z.string().nullable()
567
+ }).nullable();
568
+ /** Per-chat participation mode exposed to the recipient runtime. */
569
+ const participantModeSchema = z.enum(["full", "mention_only"]);
570
+ /**
571
+ * Wire format for messages routed FROM the Hub TO a client runtime.
572
+ *
573
+ * Adds `configVersion` so the client can compare against its locally cached
574
+ * agent runtime config and refresh before delivering the message to the SDK.
575
+ *
576
+ * Step 3: this is the single shape used by `buildClientMessagePayload` —
577
+ * never serialise a raw `messageSchema` row to a client; always go through
578
+ * the dispatcher.
579
+ *
580
+ * `recipientMode` is the receiving agent's own mode in the entry's chat —
581
+ * `mention_only` participants must only start a session when they appear in
582
+ * `metadata.mentions` (see session-manager.ts).
583
+ *
584
+ * `inReplyToSnapshot` is populated when `inReplyTo` resolves to an existing
585
+ * message; runtime uses it to suppress self-reply echo on direct chats.
586
+ */
587
+ const clientMessageSchema = messageSchema.extend({
588
+ configVersion: z.number().int().positive(),
589
+ recipientMode: participantModeSchema.default("full"),
590
+ inReplyToSnapshot: inReplyToSnapshotSchema.default(null)
591
+ });
501
592
  z.enum([
502
593
  "pending",
503
594
  "delivered",
@@ -959,4 +1050,4 @@ async function bindFeishuUser(serverUrl, accessToken, agentId, humanAgentId, fei
959
1050
  }
960
1051
  }
961
1052
  //#endregion
962
- export { updateAdapterConfigSchema as $, createMemberSchema as A, notificationQuerySchema as B, agentTypeSchema as C, createAdapterMappingSchema as D, createAdapterConfigSchema as E, inboxPollQuerySchema as F, sendMessageSchema as G, refreshTokenSchema as H, isRedactedEnvValue as I, sessionEventMessageSchema as J, sendToAgentSchema as K, linkTaskChatSchema as L, createTaskSchema as M, delegateFeishuUserSchema as N, createAgentSchema as O, dryRunAgentRuntimeConfigSchema as P, taskListQuerySchema as Q, loginSchema as R, agentRuntimeConfigPayloadSchema as S, connectTokenExchangeSchema as T, runtimeStateMessageSchema as U, paginationQuerySchema as V, selfServiceFeishuBotSchema as W, sessionReconcileRequestSchema as X, sessionEventSchema as Y, sessionStateMessageSchema as Z, addParticipantSchema as _, AGENT_SELECTOR_HEADER as a, updateSystemConfigSchema as at, agentBindRequestSchema as b, AGENT_TYPES as c, SYSTEM_CONFIG_DEFAULTS as d, updateAgentRuntimeConfigSchema as et, TASK_CREATOR_TYPES as f, WS_AUTH_FRAME_TIMEOUT_MS as g, TASK_TERMINAL_STATUSES as h, AGENT_BIND_REJECT_REASONS as i, updateOrganizationSchema as it, createOrganizationSchema as j, createChatSchema as k, AGENT_VISIBILITY as l, TASK_STATUSES as m, bindFeishuUser as n, updateChatSchema as nt, AGENT_SOURCES as o, updateTaskStatusSchema as ot, TASK_HEALTH_SIGNALS as p, sessionCompletionMessageSchema as q, feishu_exports as r, updateMemberSchema as rt, AGENT_STATUSES as s, wsAuthFrameSchema as st, bindFeishuBot as t, updateAgentSchema as tt, DEFAULT_AGENT_RUNTIME_CONFIG_PAYLOAD as u, adminCreateTaskSchema as v, clientRegisterSchema as w, agentPinnedMessageSchema as x, adminUpdateTaskSchema as y, messageSourceSchema as z };
1053
+ export { sessionStateMessageSchema as $, createMemberSchema as A, loginSchema as B, agentTypeSchema as C, createAdapterMappingSchema as D, createAdapterConfigSchema as E, extractMentions as F, runtimeStateMessageSchema as G, notificationQuerySchema as H, imageInlineContentSchema as I, sendToAgentSchema as J, selfServiceFeishuBotSchema as K, inboxPollQuerySchema as L, createTaskSchema as M, delegateFeishuUserSchema as N, createAgentSchema as O, dryRunAgentRuntimeConfigSchema as P, sessionReconcileRequestSchema as Q, isRedactedEnvValue as R, agentRuntimeConfigPayloadSchema as S, connectTokenExchangeSchema as T, paginationQuerySchema as U, messageSourceSchema as V, refreshTokenSchema as W, sessionEventMessageSchema as X, sessionCompletionMessageSchema as Y, sessionEventSchema as Z, addParticipantSchema as _, AGENT_SELECTOR_HEADER as a, updateMemberSchema as at, agentBindRequestSchema as b, AGENT_TYPES as c, updateTaskStatusSchema as ct, SYSTEM_CONFIG_DEFAULTS as d, taskListQuerySchema as et, TASK_CREATOR_TYPES as f, WS_AUTH_FRAME_TIMEOUT_MS as g, TASK_TERMINAL_STATUSES as h, AGENT_BIND_REJECT_REASONS as i, updateChatSchema as it, createOrganizationSchema as j, createChatSchema as k, AGENT_VISIBILITY as l, wsAuthFrameSchema as lt, TASK_STATUSES as m, bindFeishuUser as n, updateAgentRuntimeConfigSchema as nt, AGENT_SOURCES as o, updateOrganizationSchema as ot, TASK_HEALTH_SIGNALS as p, sendMessageSchema as q, feishu_exports as r, updateAgentSchema as rt, AGENT_STATUSES as s, updateSystemConfigSchema as st, bindFeishuBot as t, updateAdapterConfigSchema as tt, DEFAULT_AGENT_RUNTIME_CONFIG_PAYLOAD as u, adminCreateTaskSchema as v, clientRegisterSchema as w, agentPinnedMessageSchema as x, adminUpdateTaskSchema as y, linkTaskChatSchema as z };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./observability-DV_fQKqV-CuLWzBxQ.mjs";
2
- import { A as checkServerHealth, B as blank, C as runMigrations, D as checkDocker, E as checkDatabase, F as isDockerAvailable, G as SdkError, I as stopPostgres, L as ClientRuntime, M as checkWebSocket, N as printResults, O as checkNodeVersion, P as ensurePostgres, R as createOwner, S as uninstallClientService, T as checkClientConfig, U as status, W as FirstTreeHubSDK, _ as runHomeMigration, b as isServiceSupported, d as promptMissingFields, f as formatCheckReport, h as onboardCreate, j as checkServerReachable, k as checkServerConfig, l as isInteractive, m as onboardCheck, s as startServer, u as promptAddAgent, v as getClientServiceStatus, w as checkAgentConfigs, x as resolveCliInvocation, y as installClientService, z as hasUser } from "./core-USyOOh7y.mjs";
2
+ import { A as checkServerHealth, C as runMigrations, D as checkDocker, E as checkDatabase, F as isDockerAvailable, G as FirstTreeHubSDK, I as stopPostgres, K as SdkError, L as ClientRuntime, M as checkWebSocket, N as printResults, O as checkNodeVersion, P as ensurePostgres, R as createOwner, S as uninstallClientService, T as checkClientConfig, V as blank, W as status, _ as runHomeMigration, b as isServiceSupported, d as promptMissingFields, f as formatCheckReport, h as onboardCreate, j as checkServerReachable, k as checkServerConfig, l as isInteractive, m as onboardCheck, s as startServer, u as promptAddAgent, v as getClientServiceStatus, w as checkAgentConfigs, x as resolveCliInvocation, y as installClientService, z as hasUser } from "./core-DKA6g1lL.mjs";
3
3
  import "./logger-core-BTmvdflj-DhdipBkV.mjs";
4
4
  import { a as resolveAccessToken, n as ensureFreshAccessToken, o as resolveServerUrl, r as ensureFreshAdminToken } from "./bootstrap-DWifXj9b.mjs";
5
- import { n as bindFeishuUser, t as bindFeishuBot } from "./feishu-GlaczcVf.mjs";
5
+ import { n as bindFeishuUser, t as bindFeishuBot } from "./feishu-CRNUI05I.mjs";
6
6
  export { ClientRuntime, FirstTreeHubSDK, SdkError, bindFeishuBot, bindFeishuUser, blank, checkAgentConfigs, checkClientConfig, checkDatabase, checkDocker, checkNodeVersion, checkServerConfig, checkServerHealth, checkServerReachable, checkWebSocket, createOwner, ensureFreshAccessToken, ensureFreshAdminToken, ensurePostgres, formatCheckReport, getClientServiceStatus, hasUser, installClientService, isDockerAvailable, isInteractive, isServiceSupported, onboardCheck, onboardCreate, printResults, promptAddAgent, promptMissingFields, resolveAccessToken, resolveCliInvocation, resolveServerUrl, runHomeMigration, runMigrations, startServer, status, stopPostgres, uninstallClientService };