@nextclaw/core 0.4.8 → 0.4.9

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/index.d.ts CHANGED
@@ -3662,6 +3662,12 @@ type ExtensionRegistry = {
3662
3662
  diagnostics: ExtensionDiagnostic[];
3663
3663
  };
3664
3664
 
3665
+ type MessageToolHintsResolver = (params: {
3666
+ sessionKey: string;
3667
+ channel: string;
3668
+ chatId: string;
3669
+ accountId?: string | null;
3670
+ }) => string[];
3665
3671
  declare class AgentLoop {
3666
3672
  private options;
3667
3673
  private context;
@@ -3687,6 +3693,7 @@ declare class AgentLoop {
3687
3693
  gatewayController?: GatewayController;
3688
3694
  config?: Config;
3689
3695
  extensionRegistry?: ExtensionRegistry;
3696
+ resolveMessageToolHints?: MessageToolHintsResolver;
3690
3697
  });
3691
3698
  private registerDefaultTools;
3692
3699
  private registerExtensionTools;
@@ -3698,6 +3705,7 @@ declare class AgentLoop {
3698
3705
  sessionKey?: string;
3699
3706
  channel?: string;
3700
3707
  chatId?: string;
3708
+ metadata?: Record<string, unknown>;
3701
3709
  }): Promise<string>;
3702
3710
  private processMessage;
3703
3711
  private processSystemMessage;
package/dist/index.js CHANGED
@@ -428,9 +428,9 @@ var ContextBuilder = class {
428
428
  memory;
429
429
  skills;
430
430
  contextConfig;
431
- buildSystemPrompt(skillNames, sessionKey) {
431
+ buildSystemPrompt(skillNames, sessionKey, messageToolHints) {
432
432
  const parts = [];
433
- parts.push(this.getIdentity());
433
+ parts.push(this.getIdentity(messageToolHints));
434
434
  const bootstrap = this.loadBootstrapFiles(sessionKey);
435
435
  if (bootstrap) {
436
436
  parts.push(`# Workspace Context
@@ -471,7 +471,7 @@ ${skillsSummary}`);
471
471
  }
472
472
  buildMessages(params) {
473
473
  const messages = [];
474
- let systemPrompt = this.buildSystemPrompt(params.skillNames, params.sessionKey);
474
+ let systemPrompt = this.buildSystemPrompt(params.skillNames, params.sessionKey, params.messageToolHints);
475
475
  if (params.channel && params.chatId) {
476
476
  systemPrompt += `
477
477
 
@@ -509,8 +509,13 @@ Session: ${params.sessionKey}`;
509
509
  messages.push(msg);
510
510
  return messages;
511
511
  }
512
- getIdentity() {
512
+ getIdentity(messageToolHints) {
513
513
  const now = (/* @__PURE__ */ new Date()).toLocaleString();
514
+ const sanitizedMessageToolHints = (messageToolHints ?? []).map((hint) => hint.trim()).filter(Boolean);
515
+ const messageToolHintsBlock = sanitizedMessageToolHints.length ? `
516
+
517
+ ### message tool hints
518
+ ${sanitizedMessageToolHints.map((hint) => `- ${hint}`).join("\n")}` : "";
514
519
  return `# ${APP_NAME} \u{1F916}
515
520
 
516
521
  You are a personal assistant running inside ${APP_NAME}.
@@ -554,7 +559,7 @@ Do not use exec/curl for provider messaging; use message/sessions_send instead.
554
559
  - Sub-agent orchestration: use subagents(action=list|steer|kill) and spawn.
555
560
  - Do not poll subagents list / sessions_list in a loop; only check on-demand.
556
561
  - If you use message (action=send) to deliver your user-visible reply, respond with ONLY: NO_REPLY (avoid duplicate replies).
557
- - If a [System Message] reports completed cron/subagent work and asks for a user update, rewrite it in your normal assistant voice and send that update (do not forward raw system text or default to NO_REPLY).
562
+ - If a [System Message] reports completed cron/subagent work and asks for a user update, rewrite it in your normal assistant voice and send that update (do not forward raw system text or default to NO_REPLY).${messageToolHintsBlock}
558
563
 
559
564
  ## Reply Tags
560
565
  - [[reply_to_current]] replies to the triggering message.
@@ -2712,7 +2717,7 @@ var AgentLoop = class {
2712
2717
  content: params.content,
2713
2718
  timestamp: /* @__PURE__ */ new Date(),
2714
2719
  media: [],
2715
- metadata: {}
2720
+ metadata: params.metadata ?? {}
2716
2721
  };
2717
2722
  const response = await this.processMessage(msg, params.sessionKey);
2718
2723
  return response?.content ?? "";
@@ -2734,7 +2739,8 @@ var AgentLoop = class {
2734
2739
  }
2735
2740
  session.metadata.last_channel = msg.channel;
2736
2741
  session.metadata.last_to = msg.chatId;
2737
- const accountId = msg.metadata?.account_id ?? msg.metadata?.accountId;
2742
+ const inboundAccountId = msg.metadata?.account_id ?? msg.metadata?.accountId;
2743
+ const accountId = inboundAccountId && inboundAccountId.trim().length > 0 ? inboundAccountId : typeof session.metadata.last_account_id === "string" && session.metadata.last_account_id.trim().length > 0 ? session.metadata.last_account_id : void 0;
2738
2744
  if (accountId) {
2739
2745
  session.metadata.last_account_id = accountId;
2740
2746
  }
@@ -2750,13 +2756,20 @@ var AgentLoop = class {
2750
2756
  if (cronTool instanceof CronTool) {
2751
2757
  cronTool.setContext(msg.channel, msg.chatId);
2752
2758
  }
2759
+ const messageToolHints = this.options.resolveMessageToolHints?.({
2760
+ sessionKey,
2761
+ channel: msg.channel,
2762
+ chatId: msg.chatId,
2763
+ accountId: accountId ?? null
2764
+ });
2753
2765
  const messages = this.context.buildMessages({
2754
2766
  history: this.sessions.getHistory(session),
2755
2767
  currentMessage: msg.content,
2756
2768
  media: msg.media,
2757
2769
  channel: msg.channel,
2758
2770
  chatId: msg.chatId,
2759
- sessionKey
2771
+ sessionKey,
2772
+ messageToolHints
2760
2773
  });
2761
2774
  this.sessions.addMessage(session, "user", msg.content);
2762
2775
  let iteration = 0;
@@ -2833,12 +2846,23 @@ var AgentLoop = class {
2833
2846
  if (cronTool instanceof CronTool) {
2834
2847
  cronTool.setContext(originChannel, originChatId);
2835
2848
  }
2849
+ const accountId = msg.metadata?.account_id ?? msg.metadata?.accountId ?? (typeof session.metadata.last_account_id === "string" ? session.metadata.last_account_id : void 0);
2850
+ if (accountId) {
2851
+ session.metadata.last_account_id = accountId;
2852
+ }
2853
+ const messageToolHints = this.options.resolveMessageToolHints?.({
2854
+ sessionKey,
2855
+ channel: originChannel,
2856
+ chatId: originChatId,
2857
+ accountId: accountId ?? null
2858
+ });
2836
2859
  const messages = this.context.buildMessages({
2837
2860
  history: this.sessions.getHistory(session),
2838
2861
  currentMessage: msg.content,
2839
2862
  channel: originChannel,
2840
2863
  chatId: originChatId,
2841
- sessionKey
2864
+ sessionKey,
2865
+ messageToolHints
2842
2866
  });
2843
2867
  this.sessions.addMessage(session, "user", `[System: ${msg.senderId}] ${msg.content}`);
2844
2868
  let iteration = 0;
@@ -2895,7 +2919,7 @@ var AgentLoop = class {
2895
2919
  content: finalContent,
2896
2920
  replyTo,
2897
2921
  media: [],
2898
- metadata: {}
2922
+ metadata: msg.metadata ?? {}
2899
2923
  };
2900
2924
  }
2901
2925
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/core",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "private": false,
5
5
  "description": "Nextclaw runtime core (agent, channels, providers, config).",
6
6
  "type": "module",