@friendlyrobot/discord-pi-agent 0.5.4 → 0.5.7

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.
@@ -8,4 +8,8 @@ export type GatewayAuthConfig = {
8
8
  discordAllowedUserIds: string[];
9
9
  startupMessage: string | false;
10
10
  };
11
+ /**
12
+ * Combine a forum thread title with the post body for the initial session prompt.
13
+ */
14
+ export declare function buildThreadOpeningPrompt(threadName: string, content: string): string;
11
15
  export declare function startGatewayClient(config: ResolvedDiscordPiBridgeConfig, agentService: AgentService, sessionRegistry: SessionRegistry, authConfig: GatewayAuthConfig): Promise<Client>;
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js CHANGED
@@ -721,6 +721,11 @@ function chunkMessage(text, maxChunkSize = SAFE_MESSAGE_LIMIT) {
721
721
  }
722
722
 
723
723
  // src/discord-gateway-client.ts
724
+ function buildThreadOpeningPrompt(threadName, content) {
725
+ return `<thread_title>${threadName}</thread_title>
726
+
727
+ ${content}`;
728
+ }
724
729
  function resolveScope(message) {
725
730
  if (message.channel.type === ChannelType.DM) {
726
731
  return "dm";
@@ -880,7 +885,19 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
880
885
  console.log("[gateway] ignored empty message", { messageId: message.id });
881
886
  return;
882
887
  }
883
- const { session, promptQueue } = await sessionRegistry.getOrCreate(scope);
888
+ const { entry, created } = await sessionRegistry.getOrCreate(scope);
889
+ const { session, promptQueue } = entry;
890
+ let effectiveContent = content;
891
+ if (created && scope.startsWith("thread:")) {
892
+ const thread = message.channel;
893
+ if (thread.isThread() && thread.name) {
894
+ effectiveContent = buildThreadOpeningPrompt(thread.name, content);
895
+ console.log("[gateway] new thread session — prepending title", {
896
+ scope,
897
+ threadName: thread.name
898
+ });
899
+ }
900
+ }
884
901
  let typingInterval = null;
885
902
  if (message.channel.isSendable()) {
886
903
  typingInterval = startTypingInterval(message.channel);
@@ -934,7 +951,7 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
934
951
  }
935
952
  const response = await promptQueue.enqueue(async () => {
936
953
  console.log(`[queue] processing message ${message.id} in scope ${scope}`);
937
- const transformedPrompt = await config.promptTransform(content);
954
+ const transformedPrompt = await config.promptTransform(effectiveContent);
938
955
  return collectReply(session, transformedPrompt, {
939
956
  logPrefix: `[agent:${session.sessionId}]`
940
957
  });
@@ -1011,7 +1028,7 @@ class SessionRegistry {
1011
1028
  async getOrCreate(scope) {
1012
1029
  const existing = this.scopes.get(scope);
1013
1030
  if (existing) {
1014
- return existing;
1031
+ return { entry: existing, created: false };
1015
1032
  }
1016
1033
  const sessionDir = sessionDirForScope(this.agentService.getAgentDir(), scope);
1017
1034
  const session = await this.agentService.createSession(sessionDir);
@@ -1027,7 +1044,7 @@ class SessionRegistry {
1027
1044
  sessionDir,
1028
1045
  sessionId: session.sessionId
1029
1046
  });
1030
- return entry;
1047
+ return { entry, created: true };
1031
1048
  }
1032
1049
  async remove(scope) {
1033
1050
  const entry = this.scopes.get(scope);
@@ -1061,6 +1078,7 @@ function buildTimeContextPrompt(userMessage, options = {}) {
1061
1078
  const now = options.now || new Date;
1062
1079
  const localTime = new Intl.DateTimeFormat(locale, {
1063
1080
  timeZone,
1081
+ weekday: "short",
1064
1082
  day: "numeric",
1065
1083
  month: "short",
1066
1084
  year: "2-digit",
@@ -18,7 +18,10 @@ export declare class SessionRegistry {
18
18
  private readonly scopes;
19
19
  private readonly agentService;
20
20
  constructor(agentService: AgentService);
21
- getOrCreate(scope: SessionScope): Promise<ScopeEntry>;
21
+ getOrCreate(scope: SessionScope): Promise<{
22
+ entry: ScopeEntry;
23
+ created: boolean;
24
+ }>;
22
25
  remove(scope: SessionScope): Promise<void>;
23
26
  get(scope: SessionScope): ScopeEntry | undefined;
24
27
  getScopes(): SessionScope[];
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friendlyrobot/discord-pi-agent",
3
- "version": "0.5.4",
3
+ "version": "0.5.7",
4
4
  "description": "Reusable Discord gateway bridge for persistent pi agent sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",