- Added `originContext` to `createCronTool` for routing replies back to the originating session/channel. - Updated `CronJob` and related types to include `origin` and `deliveryMode` properties. - Enhanced `resolveDeliveryTarget` to utilize origin context for determining delivery targets. - Modified various components to support the new origin context and delivery mode functionality, ensuring replies are routed correctly based on the job's origin.
175 lines
6.5 KiB
TypeScript
175 lines
6.5 KiB
TypeScript
import type { MoltbotConfig } from "../config/config.js";
|
|
import { resolvePluginTools } from "../plugins/tools.js";
|
|
import type { GatewayMessageChannel } from "../utils/message-channel.js";
|
|
import { resolveSessionAgentId } from "./agent-scope.js";
|
|
import { createAgentsListTool } from "./tools/agents-list-tool.js";
|
|
import { createBrowserTool } from "./tools/browser-tool.js";
|
|
import { createCanvasTool } from "./tools/canvas-tool.js";
|
|
import type { AnyAgentTool } from "./tools/common.js";
|
|
import { createCronTool } from "./tools/cron-tool.js";
|
|
import { createGatewayTool } from "./tools/gateway-tool.js";
|
|
import { createImageTool } from "./tools/image-tool.js";
|
|
import { createMessageTool } from "./tools/message-tool.js";
|
|
import { createNodesTool } from "./tools/nodes-tool.js";
|
|
import { createSessionStatusTool } from "./tools/session-status-tool.js";
|
|
import { createSessionsHistoryTool } from "./tools/sessions-history-tool.js";
|
|
import { createSessionsListTool } from "./tools/sessions-list-tool.js";
|
|
import { createSessionsSendTool } from "./tools/sessions-send-tool.js";
|
|
import { createSessionsSpawnTool } from "./tools/sessions-spawn-tool.js";
|
|
import { createWebFetchTool, createWebSearchTool } from "./tools/web-tools.js";
|
|
import { createTtsTool } from "./tools/tts-tool.js";
|
|
import { createQverisTools } from "./tools/qveris-tools.js";
|
|
|
|
export function createMoltbotTools(options?: {
|
|
sandboxBrowserBridgeUrl?: string;
|
|
allowHostBrowserControl?: boolean;
|
|
agentSessionKey?: string;
|
|
agentChannel?: GatewayMessageChannel;
|
|
agentAccountId?: string;
|
|
/** Delivery target (e.g. telegram:group:123:topic:456) for topic/thread routing. */
|
|
agentTo?: string;
|
|
/** Thread/topic identifier for routing replies to the originating thread. */
|
|
agentThreadId?: string | number;
|
|
/** Group id for channel-level tool policy inheritance. */
|
|
agentGroupId?: string | null;
|
|
/** Group channel label for channel-level tool policy inheritance. */
|
|
agentGroupChannel?: string | null;
|
|
/** Group space label for channel-level tool policy inheritance. */
|
|
agentGroupSpace?: string | null;
|
|
agentDir?: string;
|
|
sandboxRoot?: string;
|
|
workspaceDir?: string;
|
|
sandboxed?: boolean;
|
|
config?: MoltbotConfig;
|
|
pluginToolAllowlist?: string[];
|
|
/** Current channel ID for auto-threading (Slack). */
|
|
currentChannelId?: string;
|
|
/** Current thread timestamp for auto-threading (Slack). */
|
|
currentThreadTs?: string;
|
|
/** Reply-to mode for Slack auto-threading. */
|
|
replyToMode?: "off" | "first" | "all";
|
|
/** Mutable ref to track if a reply was sent (for "first" mode). */
|
|
hasRepliedRef?: { value: boolean };
|
|
/** If true, the model has native vision capability */
|
|
modelHasVision?: boolean;
|
|
/** Explicit agent ID override for cron/hook sessions. */
|
|
requesterAgentIdOverride?: string;
|
|
}): AnyAgentTool[] {
|
|
const imageTool = options?.agentDir?.trim()
|
|
? createImageTool({
|
|
config: options?.config,
|
|
agentDir: options.agentDir,
|
|
sandboxRoot: options?.sandboxRoot,
|
|
modelHasVision: options?.modelHasVision,
|
|
})
|
|
: null;
|
|
const webSearchTool = createWebSearchTool({
|
|
config: options?.config,
|
|
sandboxed: options?.sandboxed,
|
|
});
|
|
const webFetchTool = createWebFetchTool({
|
|
config: options?.config,
|
|
sandboxed: options?.sandboxed,
|
|
});
|
|
const qverisTools = createQverisTools({
|
|
config: options?.config,
|
|
sandboxed: options?.sandboxed,
|
|
agentSessionKey: options?.agentSessionKey,
|
|
});
|
|
const tools: AnyAgentTool[] = [
|
|
createBrowserTool({
|
|
sandboxBridgeUrl: options?.sandboxBrowserBridgeUrl,
|
|
allowHostControl: options?.allowHostBrowserControl,
|
|
}),
|
|
createCanvasTool(),
|
|
createNodesTool({
|
|
agentSessionKey: options?.agentSessionKey,
|
|
config: options?.config,
|
|
}),
|
|
createCronTool({
|
|
agentSessionKey: options?.agentSessionKey,
|
|
originContext: {
|
|
channel: options?.agentChannel,
|
|
to: options?.agentTo,
|
|
accountId: options?.agentAccountId,
|
|
threadId: options?.agentThreadId,
|
|
},
|
|
}),
|
|
createMessageTool({
|
|
agentAccountId: options?.agentAccountId,
|
|
agentSessionKey: options?.agentSessionKey,
|
|
config: options?.config,
|
|
currentChannelId: options?.currentChannelId,
|
|
currentChannelProvider: options?.agentChannel,
|
|
currentThreadTs: options?.currentThreadTs,
|
|
replyToMode: options?.replyToMode,
|
|
hasRepliedRef: options?.hasRepliedRef,
|
|
}),
|
|
createTtsTool({
|
|
agentChannel: options?.agentChannel,
|
|
config: options?.config,
|
|
}),
|
|
createGatewayTool({
|
|
agentSessionKey: options?.agentSessionKey,
|
|
config: options?.config,
|
|
}),
|
|
createAgentsListTool({
|
|
agentSessionKey: options?.agentSessionKey,
|
|
requesterAgentIdOverride: options?.requesterAgentIdOverride,
|
|
}),
|
|
createSessionsListTool({
|
|
agentSessionKey: options?.agentSessionKey,
|
|
sandboxed: options?.sandboxed,
|
|
}),
|
|
createSessionsHistoryTool({
|
|
agentSessionKey: options?.agentSessionKey,
|
|
sandboxed: options?.sandboxed,
|
|
}),
|
|
createSessionsSendTool({
|
|
agentSessionKey: options?.agentSessionKey,
|
|
agentChannel: options?.agentChannel,
|
|
sandboxed: options?.sandboxed,
|
|
}),
|
|
createSessionsSpawnTool({
|
|
agentSessionKey: options?.agentSessionKey,
|
|
agentChannel: options?.agentChannel,
|
|
agentAccountId: options?.agentAccountId,
|
|
agentTo: options?.agentTo,
|
|
agentThreadId: options?.agentThreadId,
|
|
agentGroupId: options?.agentGroupId,
|
|
agentGroupChannel: options?.agentGroupChannel,
|
|
agentGroupSpace: options?.agentGroupSpace,
|
|
sandboxed: options?.sandboxed,
|
|
requesterAgentIdOverride: options?.requesterAgentIdOverride,
|
|
}),
|
|
createSessionStatusTool({
|
|
agentSessionKey: options?.agentSessionKey,
|
|
config: options?.config,
|
|
}),
|
|
...(webSearchTool ? [webSearchTool] : []),
|
|
...(webFetchTool ? [webFetchTool] : []),
|
|
...(imageTool ? [imageTool] : []),
|
|
...qverisTools,
|
|
];
|
|
|
|
const pluginTools = resolvePluginTools({
|
|
context: {
|
|
config: options?.config,
|
|
workspaceDir: options?.workspaceDir,
|
|
agentDir: options?.agentDir,
|
|
agentId: resolveSessionAgentId({
|
|
sessionKey: options?.agentSessionKey,
|
|
config: options?.config,
|
|
}),
|
|
sessionKey: options?.agentSessionKey,
|
|
messageChannel: options?.agentChannel,
|
|
agentAccountId: options?.agentAccountId,
|
|
sandboxed: options?.sandboxed,
|
|
},
|
|
existingToolNames: new Set(tools.map((tool) => tool.name)),
|
|
toolAllowlist: options?.pluginToolAllowlist,
|
|
});
|
|
|
|
return [...tools, ...pluginTools];
|
|
}
|