@jcheesepkg/nanobot 0.8.95 → 0.8.96
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/agent/loop.d.mts.map +1 -1
- package/dist/agent/loop.mjs +4 -0
- package/dist/agent/loop.mjs.map +1 -1
- package/dist/agent/tools/flex.d.mts.map +1 -1
- package/dist/agent/tools/flex.mjs +1 -1
- package/dist/agent/tools/flex.mjs.map +1 -1
- package/dist/agent/tools/flex.test.mjs +3 -3
- package/dist/agent/tools/flex.test.mjs.map +1 -1
- package/dist/config/schema.d.mts +18 -18
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop.d.mts","names":[],"sources":["../../src/agent/loop.ts"],"mappings":";;;;;;;;;;;;AAqCA;;;;;;;cAAa,SAAA;EAAA,QACH,GAAA;EAAA,QACA,QAAA;EAAA,QACA,SAAA;EAAA,QACA,KAAA;EAAA,QACA,kBAAA;EAAA,QACA,SAAA;EAAA,QACA,aAAA;EAAA,QACA,YAAA;EAAA,SAEC,OAAA,EAAS,cAAA;EAAA,SACT,QAAA,EAAU,cAAA;EAAA,SACV,KAAA,EAAO,YAAA;EAAA,SACP,SAAA,EAAW,eAAA;EAAA,QAEZ,QAAA;EARA;EAAA,QAWA,QAAA;cAEI,MAAA;IACV,GAAA,EAAK,UAAA;IACL,QAAA,EAAU,WAAA;IACV,SAAA;IACA,KAAA;IACA,kBAAA;IACA,SAAA;IACA,aAAA;IACA,YAAA;IACA,WAAA;IACA,UAAA,GAAa,cAAA;IACb,mBAAA;IACA,YAAA;IACA,aAAA;IACA,WAAA,GAAc,IAAA;EAAA;EAAA,QAqCR,oBAAA;EA9CN;EA+GI,GAAA,CAAA,GAAO,OAAA;EA7GX;EA8IF,IAAA,CAAA;EA5IE;EAAA,QAkJY,cAAA;EAAA,QA4FA,oBAAA;EAAA,QA4CA,YAAA;EAvRZ;EAAA,
|
|
1
|
+
{"version":3,"file":"loop.d.mts","names":[],"sources":["../../src/agent/loop.ts"],"mappings":";;;;;;;;;;;;AAqCA;;;;;;;cAAa,SAAA;EAAA,QACH,GAAA;EAAA,QACA,QAAA;EAAA,QACA,SAAA;EAAA,QACA,KAAA;EAAA,QACA,kBAAA;EAAA,QACA,SAAA;EAAA,QACA,aAAA;EAAA,QACA,YAAA;EAAA,SAEC,OAAA,EAAS,cAAA;EAAA,SACT,QAAA,EAAU,cAAA;EAAA,SACV,KAAA,EAAO,YAAA;EAAA,SACP,SAAA,EAAW,eAAA;EAAA,QAEZ,QAAA;EARA;EAAA,QAWA,QAAA;cAEI,MAAA;IACV,GAAA,EAAK,UAAA;IACL,QAAA,EAAU,WAAA;IACV,SAAA;IACA,KAAA;IACA,kBAAA;IACA,SAAA;IACA,aAAA;IACA,YAAA;IACA,WAAA;IACA,UAAA,GAAa,cAAA;IACb,mBAAA;IACA,YAAA;IACA,aAAA;IACA,WAAA,GAAc,IAAA;EAAA;EAAA,QAqCR,oBAAA;EA9CN;EA+GI,GAAA,CAAA,GAAO,OAAA;EA7GX;EA8IF,IAAA,CAAA;EA5IE;EAAA,QAkJY,cAAA;EAAA,QA4FA,oBAAA;EAAA,QA4CA,YAAA;EAvRZ;EAAA,QA6XM,uBAAA;EAAA,QAcA,kBAAA;EAzYQ;EA2ZV,aAAA,CACJ,OAAA,UACA,UAAA,WACA,OAAA,WACA,MAAA,YACC,OAAA;EA3XK;EAAA,QAmZM,iBAAA;AAAA"}
|
package/dist/agent/loop.mjs
CHANGED
|
@@ -241,6 +241,10 @@ var AgentLoop = class {
|
|
|
241
241
|
}
|
|
242
242
|
const result = await this.tools.execute(tc.name, tc.arguments);
|
|
243
243
|
this.context.addToolResult(messages, tc.id, tc.name, result);
|
|
244
|
+
if (tc.name === "flex_message" && onToolCallText && !result.startsWith("Error")) {
|
|
245
|
+
const jsonOnly = result.split("\n\n(")[0];
|
|
246
|
+
onToolCallText(jsonOnly);
|
|
247
|
+
}
|
|
244
248
|
}
|
|
245
249
|
} else {
|
|
246
250
|
finalContent = response.content;
|
package/dist/agent/loop.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop.mjs","names":[],"sources":["../../src/agent/loop.ts"],"sourcesContent":["import type { LLMProvider, ChatMessage, ToolCallRequest } from \"../providers/base.js\";\nimport type { MessageBus } from \"../bus/queue.js\";\nimport type {\n InboundMessage,\n OutboundMessage,\n} from \"../bus/events.js\";\nimport { createOutboundMessage } from \"../bus/events.js\";\nimport { ContextBuilder } from \"./context.js\";\nimport { ToolRegistry } from \"./tools/registry.js\";\nimport {\n ReadFileTool,\n WriteFileTool,\n EditFileTool,\n ListDirTool,\n} from \"./tools/filesystem.js\";\nimport { ExecTool } from \"./tools/shell.js\";\nimport { WebSearchTool, WebFetchTool } from \"./tools/web.js\";\nimport { MessageTool } from \"./tools/message.js\";\nimport { SpawnTool } from \"./tools/spawn.js\";\nimport { CronTool } from \"./tools/cron.js\";\nimport { FlexTool } from \"./tools/flex.js\";\nimport { SubagentManager } from \"./subagent.js\";\nimport { getBuiltinSkillsDir } from \"./skills.js\";\nimport { SessionManager, Session } from \"../session/manager.js\";\nimport { MemoryStore } from \"./memory.js\";\nimport type { ExecToolConfig } from \"../config/schema.js\";\nimport type { Tool } from \"./tools/base.js\";\n\n/**\n * The agent loop: core processing engine.\n *\n * 1. Receives messages from the bus\n * 2. Builds context with history, memory, skills\n * 3. Calls the LLM\n * 4. Executes tool calls\n * 5. Sends responses back\n */\nexport class AgentLoop {\n private bus: MessageBus;\n private provider: LLMProvider;\n private workspace: string;\n private model: string;\n private consolidationModel: string;\n private maxTokens: number;\n private maxIterations: number;\n private memoryWindow: number;\n\n readonly context: ContextBuilder;\n readonly sessions: SessionManager;\n readonly tools: ToolRegistry;\n readonly subagents: SubagentManager;\n\n private _running = false;\n\n /** In-flight AbortControllers keyed by session key. */\n private inflight = new Map<string, AbortController>();\n\n constructor(params: {\n bus: MessageBus;\n provider: LLMProvider;\n workspace: string;\n model?: string;\n consolidationModel?: string;\n maxTokens?: number;\n maxIterations?: number;\n memoryWindow?: number;\n braveApiKey?: string;\n execConfig?: ExecToolConfig;\n restrictToWorkspace?: boolean;\n toolsEnabled?: string[];\n toolsDisabled?: string[];\n customTools?: Tool[];\n }) {\n this.bus = params.bus;\n this.provider = params.provider;\n this.workspace = params.workspace;\n this.model = params.model ?? params.provider.getDefaultModel();\n this.consolidationModel = params.consolidationModel ?? this.model;\n this.maxTokens = params.maxTokens ?? 8192;\n this.maxIterations = params.maxIterations ?? 20;\n this.memoryWindow = params.memoryWindow ?? 50;\n\n const execConfig = params.execConfig ?? { timeout: 60 };\n const restrictToWorkspace = params.restrictToWorkspace ?? false;\n\n this.context = new ContextBuilder(params.workspace);\n this.sessions = new SessionManager(params.workspace);\n this.tools = new ToolRegistry();\n this.subagents = new SubagentManager({\n provider: params.provider,\n workspace: params.workspace,\n bus: params.bus,\n model: this.model,\n braveApiKey: params.braveApiKey,\n execConfig,\n restrictToWorkspace,\n });\n\n this.registerDefaultTools(\n execConfig,\n restrictToWorkspace,\n params.braveApiKey,\n params.toolsEnabled,\n params.toolsDisabled,\n params.customTools,\n );\n }\n\n private registerDefaultTools(\n execConfig: ExecToolConfig,\n restrictToWorkspace: boolean,\n braveApiKey?: string,\n toolsEnabled?: string[],\n toolsDisabled?: string[],\n customTools?: Tool[],\n ): void {\n const enabled = new Set(toolsEnabled ?? []);\n const disabled = new Set(toolsDisabled ?? []);\n const hasAllowlist = enabled.size > 0;\n const shouldRegister = (name: string): boolean =>\n (hasAllowlist ? enabled.has(name) : true) && !disabled.has(name);\n\n const registerIfEnabled = (tool: Tool): void => {\n if (shouldRegister(tool.name)) {\n this.tools.register(tool);\n }\n };\n\n // File tools — pass allowedDir when restrictToWorkspace is enabled\n const allowedDir = restrictToWorkspace ? this.workspace : undefined;\n const readOnlyPaths = restrictToWorkspace ? [getBuiltinSkillsDir()] : undefined;\n registerIfEnabled(new ReadFileTool({ allowedDir, readOnlyPaths }));\n registerIfEnabled(new WriteFileTool({ allowedDir }));\n registerIfEnabled(new EditFileTool({ allowedDir }));\n registerIfEnabled(new ListDirTool({ allowedDir, readOnlyPaths }));\n\n // Shell tool\n registerIfEnabled(\n new ExecTool({\n workingDir: this.workspace,\n timeout: execConfig.timeout,\n restrictToWorkspace,\n }),\n );\n\n // Web tools\n registerIfEnabled(new WebSearchTool({ apiKey: braveApiKey }));\n registerIfEnabled(new WebFetchTool());\n\n // Message tool\n const messageTool = new MessageTool({\n sendCallback: (msg) => this.bus.publishOutbound(msg),\n });\n registerIfEnabled(messageTool);\n\n // Spawn tool\n const spawnTool = new SpawnTool(this.subagents);\n registerIfEnabled(spawnTool);\n\n // Cron tool — always registered, uses DO scheduling via worker API\n registerIfEnabled(new CronTool());\n\n // Flex Message tool — builds LINE Flex JSON from structured data\n registerIfEnabled(new FlexTool());\n\n if (customTools && customTools.length > 0) {\n for (const tool of customTools) {\n registerIfEnabled(tool);\n }\n }\n }\n\n /** Run the agent loop, processing messages from the bus. */\n async run(): Promise<void> {\n this._running = true;\n console.log(\"Agent loop started\");\n\n while (this._running) {\n try {\n const msg = await this.bus.consumeInboundTimeout(1000);\n\n // Process concurrently so new messages can abort in-flight ones\n this.processMessage(msg)\n .then(async (response) => {\n if (response) {\n await this.bus.publishOutbound(response);\n }\n })\n .catch(async (err) => {\n if (isAbortError(err)) return; // Already handled\n console.error(\"Error processing message:\", err);\n await this.bus.publishOutbound(\n createOutboundMessage({\n channel: msg.channel,\n chatId: msg.chatId,\n content: `Sorry, I encountered an error: ${err instanceof Error ? err.message : err}`,\n }),\n );\n });\n } catch {\n // timeout, continue\n }\n }\n }\n\n /** Stop the agent loop. */\n stop(): void {\n this._running = false;\n console.log(\"Agent loop stopping\");\n }\n\n /** Process a single inbound message. */\n private async processMessage(\n msg: InboundMessage,\n ): Promise<OutboundMessage | null> {\n // Handle system messages (subagent announces)\n if (msg.channel === \"system\") {\n return this.processSystemMessage(msg);\n }\n\n console.log(`Processing message from ${msg.channel}:${msg.senderId}`);\n\n const sessionKey = `${msg.channel}:${msg.chatId}`;\n\n // Abort any in-flight request for this session\n const existing = this.inflight.get(sessionKey);\n if (existing) {\n console.log(`Aborting in-flight request for ${sessionKey}`);\n existing.abort();\n }\n\n // Create a new AbortController for this request\n const controller = new AbortController();\n this.inflight.set(sessionKey, controller);\n\n const session = this.sessions.getOrCreate(sessionKey);\n\n // Consolidate memory if session is too large\n if (session.history.length > this.memoryWindow) {\n await this.consolidateMemory(session);\n }\n\n // Update tool contexts\n this.updateToolContexts(msg.channel, msg.chatId);\n\n // Build initial messages\n const messages = this.context.buildMessages({\n history: session.getHistory(),\n currentMessage: msg.content,\n media: msg.media.length > 0 ? msg.media : undefined,\n channel: msg.channel,\n chatId: msg.chatId,\n });\n\n // The messages array is: [system, ...history, currentUser]\n // We want to save from the current user message onward (skip system + old history).\n const savedHistoryLen = session.getHistory().length;\n const newMsgStart = 1 + savedHistoryLen; // 1 for system prompt\n\n try {\n // Agent loop (mutates messages by appending assistant/tool messages)\n const result = await this.runAgentLoop(messages, controller.signal, (text) => {\n if (text && text.trim().length > 0) {\n this.bus.publishOutbound(\n createOutboundMessage({\n channel: msg.channel,\n chatId: msg.chatId,\n content: text,\n }),\n );\n }\n });\n\n // Save the new messages from this turn (user + all agent loop messages)\n session.addTurnMessages(messages.slice(newMsgStart), result.toolsUsed);\n this.sessions.save(session);\n\n return createOutboundMessage({\n channel: msg.channel,\n chatId: msg.chatId,\n content: result.content,\n });\n } catch (err) {\n if (isAbortError(err)) {\n // Request was aborted because a new message arrived.\n // Save the user message to history so the next request has context,\n // but don't save any assistant response.\n const userMessages = messages.slice(newMsgStart).filter((m) => m.role === \"user\");\n if (userMessages.length > 0) {\n session.addTurnMessages(userMessages);\n this.sessions.save(session);\n }\n console.log(`Request aborted for ${sessionKey}, user message saved to history`);\n return null; // No response -- the new message will handle it\n }\n throw err; // Re-throw non-abort errors\n } finally {\n // Clean up if this is still our controller\n if (this.inflight.get(sessionKey) === controller) {\n this.inflight.delete(sessionKey);\n }\n }\n }\n\n private async processSystemMessage(\n msg: InboundMessage,\n ): Promise<OutboundMessage | null> {\n console.log(`Processing system message from ${msg.senderId}`);\n\n let originChannel: string;\n let originChatId: string;\n\n if (msg.chatId.includes(\":\")) {\n const [ch, id] = msg.chatId.split(\":\", 2);\n originChannel = ch;\n originChatId = id;\n } else {\n originChannel = \"cli\";\n originChatId = msg.chatId;\n }\n\n const sessionKey = `${originChannel}:${originChatId}`;\n const session = this.sessions.getOrCreate(sessionKey);\n\n this.updateToolContexts(originChannel, originChatId);\n\n const messages = this.context.buildMessages({\n history: session.getHistory(),\n currentMessage: msg.content,\n channel: originChannel,\n chatId: originChatId,\n });\n\n const savedHistoryLen = session.getHistory().length;\n const newMsgStart = 1 + savedHistoryLen;\n\n const result = await this.runAgentLoop(messages);\n\n session.addTurnMessages(messages.slice(newMsgStart), result.toolsUsed);\n this.sessions.save(session);\n\n return createOutboundMessage({\n channel: originChannel,\n chatId: originChatId,\n content: result.content,\n });\n }\n\n private async runAgentLoop(\n messages: ChatMessage[],\n signal?: AbortSignal,\n onToolCallText?: (text: string) => void,\n ): Promise<{ content: string; toolsUsed: string[] }> {\n let finalContent: string | null = null;\n let sentToolCallNotice = false;\n const toolsUsed: string[] = [];\n\n for (let i = 0; i < this.maxIterations; i++) {\n const response = await this.provider.chat({\n messages,\n tools: this.tools.getDefinitions(),\n model: this.model,\n maxTokens: this.maxTokens,\n signal,\n });\n\n if (response.hasToolCalls) {\n // Send an interim message so the user knows we're working\n if (!sentToolCallNotice && onToolCallText) {\n const interimText = response.content?.trim()\n || this.getToolCallFallbackText(response.toolCalls);\n if (interimText) {\n onToolCallText(interimText);\n }\n sentToolCallNotice = true;\n }\n const toolCallDicts = response.toolCalls.map((tc) => ({\n id: tc.id,\n type: \"function\" as const,\n function: {\n name: tc.name,\n arguments: JSON.stringify(tc.arguments),\n },\n }));\n\n this.context.addAssistantMessage(\n messages,\n response.content,\n toolCallDicts,\n );\n\n for (const tc of response.toolCalls) {\n toolsUsed.push(tc.name);\n console.log(`Tool: ${tc.name}(${JSON.stringify(tc.arguments)})`);\n\n // Detect skill reads\n if (tc.name === \"read_file\") {\n const path = String(tc.arguments?.path ?? \"\");\n const skillMatch = path.match(/skills\\/([^/]+)\\/SKILL\\.md$/);\n if (skillMatch) {\n console.log(`Skill activated: ${skillMatch[1]}`);\n }\n }\n\n const result = await this.tools.execute(tc.name, tc.arguments);\n this.context.addToolResult(messages, tc.id, tc.name, result);\n }\n } else {\n finalContent = response.content;\n\n // If the LLM returned empty content after tool use, nudge it to respond\n if ((!finalContent || finalContent.trim().length === 0) && i > 0) {\n messages.push({\n role: \"assistant\",\n content: \"\",\n });\n messages.push({\n role: \"user\",\n content: \"(You used tools but didn't respond to the user. Please provide a brief response summarizing what you did.)\",\n });\n continue;\n }\n\n // Push the final assistant message so it gets persisted with the turn\n messages.push({ role: \"assistant\", content: finalContent ?? \"\" });\n break;\n }\n }\n\n if (!finalContent || finalContent.trim().length === 0) {\n finalContent = \"I've completed processing but have no response to give.\";\n }\n\n // If we exhausted iterations without a non-tool-call response, still persist the final text\n if (messages[messages.length - 1]?.role !== \"assistant\" || messages[messages.length - 1]?.content !== finalContent) {\n messages.push({ role: \"assistant\", content: finalContent });\n }\n\n return { content: finalContent, toolsUsed };\n }\n\n /** Generate a fallback interim message based on which tools are being called. */\n private getToolCallFallbackText(toolCalls: ToolCallRequest[]): string {\n const toolNames = toolCalls.map((tc) => tc.name);\n const fallbacks: Record<string, string> = {\n web_search: \"検索中...\",\n web_fetch: \"ページを読み込み中...\",\n spawn: \"サブエージェントを起動中...\",\n flex_message: \"カードを作成中...\",\n };\n for (const name of toolNames) {\n if (fallbacks[name]) return fallbacks[name];\n }\n return \"ちょっと待ってね...\";\n }\n\n private updateToolContexts(channel: string, chatId: string): void {\n const messageTool = this.tools.get(\"message\");\n if (messageTool instanceof MessageTool) {\n messageTool.setContext(channel, chatId);\n }\n\n const spawnTool = this.tools.get(\"spawn\");\n if (spawnTool instanceof SpawnTool) {\n spawnTool.setContext(channel, chatId);\n }\n\n const cronTool = this.tools.get(\"cron\");\n if (cronTool instanceof CronTool) {\n cronTool.setContext(channel, chatId);\n }\n }\n\n /** Process a message directly (for CLI or cron usage). */\n async processDirect(\n content: string,\n sessionKey = \"cli:direct\",\n channel = \"cli\",\n chatId = \"direct\",\n ): Promise<string> {\n // Use inline version of processMessage for direct calls\n const session = this.sessions.getOrCreate(sessionKey);\n this.updateToolContexts(channel, chatId);\n\n const messages = this.context.buildMessages({\n history: session.getHistory(),\n currentMessage: content,\n channel,\n chatId,\n });\n\n const savedHistoryLen = session.getHistory().length;\n const newMsgStart = 1 + savedHistoryLen;\n\n const result = await this.runAgentLoop(messages);\n\n session.addTurnMessages(messages.slice(newMsgStart), result.toolsUsed);\n this.sessions.save(session);\n\n return result.content;\n }\n\n /** Consolidate old messages into MEMORY.md + HISTORY.md, then trim session. */\n private async consolidateMemory(session: Session): Promise<void> {\n const memory = new MemoryStore(this.workspace);\n const keepCount = Math.min(10, Math.max(2, Math.floor(this.memoryWindow / 2)));\n const oldMessages = session.history.slice(0, -keepCount);\n if (oldMessages.length === 0) return;\n\n console.log(`Memory consolidation: ${session.history.length} messages, archiving ${oldMessages.length}, keeping ${keepCount}`);\n\n // Format messages for LLM\n const lines: string[] = [];\n for (const m of oldMessages) {\n const content = typeof m.content === \"string\" ? m.content : \"\";\n if (!content) continue;\n const role = m.role.toUpperCase();\n const tools = m.toolsUsed ? ` [tools: ${m.toolsUsed.join(\", \")}]` : \"\";\n const ts = m.timestamp ? `[${m.timestamp.slice(0, 16)}] ` : \"\";\n lines.push(`${ts}${role}${tools}: ${content}`);\n }\n const conversation = lines.join(\"\\n\");\n const currentMemory = memory.readLongTerm();\n\n const prompt = `You are a memory consolidation agent. Process this conversation and return a JSON object with exactly two keys:\n\n1. \"history_entry\": A paragraph (2-5 sentences) summarizing the key events/decisions/topics. Start with a timestamp like [YYYY-MM-DD HH:MM]. Include enough detail to be useful when found by grep search later.\n\n2. \"memory_update\": The updated long-term memory content. Add any new facts: user location, preferences, personal info, habits, project context, technical decisions, tools/services used. If nothing new, return the existing content unchanged.\n\n## Current Long-term Memory\n${currentMemory || \"(empty)\"}\n\n## Conversation to Process\n${conversation}\n\nRespond with ONLY valid JSON, no markdown fences.`;\n\n try {\n const response = await this.provider.chat({\n messages: [\n { role: \"system\", content: \"You are a memory consolidation agent. Respond only with valid JSON.\" },\n { role: \"user\", content: prompt },\n ],\n model: this.consolidationModel,\n });\n\n let text = (response.content || \"\").trim();\n if (text.startsWith(\"```\")) {\n text = text.split(\"\\n\").slice(1).join(\"\\n\").split(\"```\")[0].trim();\n }\n\n const result = JSON.parse(text);\n\n if (result.history_entry) {\n const entry = typeof result.history_entry === \"string\"\n ? result.history_entry\n : JSON.stringify(result.history_entry, null, 2);\n memory.appendHistory(entry);\n }\n if (result.memory_update && result.memory_update !== currentMemory) {\n const update = typeof result.memory_update === \"string\"\n ? result.memory_update\n : JSON.stringify(result.memory_update, null, 2);\n memory.writeLongTerm(update);\n }\n } catch (err) {\n console.error(\"Memory consolidation failed:\", err);\n // Fallback: append raw conversation to history so it's not lost\n const fallbackEntry = `[${new Date().toISOString().slice(0, 16)}] Consolidation failed, archiving raw messages:\\n${conversation.slice(0, 2000)}`;\n memory.appendHistory(fallbackEntry);\n }\n\n // Always trim session to prevent unbounded growth\n session.trimHistory(keepCount);\n this.sessions.save(session);\n console.log(`Memory consolidation done, session trimmed to ${session.history.length} messages`);\n }\n}\n\n/** Check if an error is an abort/cancellation error. */\nfunction isAbortError(err: unknown): boolean {\n if (err instanceof DOMException && err.name === \"AbortError\") return true;\n if (err instanceof Error) {\n if (err.name === \"AbortError\") return true;\n // OpenAI SDK wraps abort as APIUserAbortError\n if (err.name === \"APIUserAbortError\") return true;\n if (err.message.includes(\"abort\")) return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,YAAb,MAA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GpE,MAAM,SAAS,KAAK,MAAM,KAAK;AAE/B,OAAI,OAAO,eAAe;IACxB,MAAM,QAAQ,OAAO,OAAO,kBAAkB,WAC1C,OAAO,gBACP,KAAK,UAAU,OAAO,eAAe,MAAM,EAAE;AACjD,WAAO,cAAc,MAAM;;AAE7B,OAAI,OAAO,iBAAiB,OAAO,kBAAkB,eAAe;IAClE,MAAM,SAAS,OAAO,OAAO,kBAAkB,WAC3C,OAAO,gBACP,KAAK,UAAU,OAAO,eAAe,MAAM,EAAE;AACjD,WAAO,cAAc,OAAO;;WAEvB,KAAK;AACZ,WAAQ,MAAM,gCAAgC,IAAI;GAElD,MAAM,gBAAgB,qBAAI,IAAI,MAAM,EAAC,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC,mDAAmD,aAAa,MAAM,GAAG,IAAK;AAC9I,UAAO,cAAc,cAAc;;AAIrC,UAAQ,YAAY,UAAU;AAC9B,OAAK,SAAS,KAAK,QAAQ;AAC3B,UAAQ,IAAI,iDAAiD,QAAQ,QAAQ,OAAO,WAAW;;;;AAKnG,SAAS,aAAa,KAAuB;AAC3C,KAAI,eAAe,gBAAgB,IAAI,SAAS,aAAc,QAAO;AACrE,KAAI,eAAe,OAAO;AACxB,MAAI,IAAI,SAAS,aAAc,QAAO;AAEtC,MAAI,IAAI,SAAS,oBAAqB,QAAO;AAC7C,MAAI,IAAI,QAAQ,SAAS,QAAQ,CAAE,QAAO;;AAE5C,QAAO"}
|
|
1
|
+
{"version":3,"file":"loop.mjs","names":[],"sources":["../../src/agent/loop.ts"],"sourcesContent":["import type { LLMProvider, ChatMessage, ToolCallRequest } from \"../providers/base.js\";\nimport type { MessageBus } from \"../bus/queue.js\";\nimport type {\n InboundMessage,\n OutboundMessage,\n} from \"../bus/events.js\";\nimport { createOutboundMessage } from \"../bus/events.js\";\nimport { ContextBuilder } from \"./context.js\";\nimport { ToolRegistry } from \"./tools/registry.js\";\nimport {\n ReadFileTool,\n WriteFileTool,\n EditFileTool,\n ListDirTool,\n} from \"./tools/filesystem.js\";\nimport { ExecTool } from \"./tools/shell.js\";\nimport { WebSearchTool, WebFetchTool } from \"./tools/web.js\";\nimport { MessageTool } from \"./tools/message.js\";\nimport { SpawnTool } from \"./tools/spawn.js\";\nimport { CronTool } from \"./tools/cron.js\";\nimport { FlexTool } from \"./tools/flex.js\";\nimport { SubagentManager } from \"./subagent.js\";\nimport { getBuiltinSkillsDir } from \"./skills.js\";\nimport { SessionManager, Session } from \"../session/manager.js\";\nimport { MemoryStore } from \"./memory.js\";\nimport type { ExecToolConfig } from \"../config/schema.js\";\nimport type { Tool } from \"./tools/base.js\";\n\n/**\n * The agent loop: core processing engine.\n *\n * 1. Receives messages from the bus\n * 2. Builds context with history, memory, skills\n * 3. Calls the LLM\n * 4. Executes tool calls\n * 5. Sends responses back\n */\nexport class AgentLoop {\n private bus: MessageBus;\n private provider: LLMProvider;\n private workspace: string;\n private model: string;\n private consolidationModel: string;\n private maxTokens: number;\n private maxIterations: number;\n private memoryWindow: number;\n\n readonly context: ContextBuilder;\n readonly sessions: SessionManager;\n readonly tools: ToolRegistry;\n readonly subagents: SubagentManager;\n\n private _running = false;\n\n /** In-flight AbortControllers keyed by session key. */\n private inflight = new Map<string, AbortController>();\n\n constructor(params: {\n bus: MessageBus;\n provider: LLMProvider;\n workspace: string;\n model?: string;\n consolidationModel?: string;\n maxTokens?: number;\n maxIterations?: number;\n memoryWindow?: number;\n braveApiKey?: string;\n execConfig?: ExecToolConfig;\n restrictToWorkspace?: boolean;\n toolsEnabled?: string[];\n toolsDisabled?: string[];\n customTools?: Tool[];\n }) {\n this.bus = params.bus;\n this.provider = params.provider;\n this.workspace = params.workspace;\n this.model = params.model ?? params.provider.getDefaultModel();\n this.consolidationModel = params.consolidationModel ?? this.model;\n this.maxTokens = params.maxTokens ?? 8192;\n this.maxIterations = params.maxIterations ?? 20;\n this.memoryWindow = params.memoryWindow ?? 50;\n\n const execConfig = params.execConfig ?? { timeout: 60 };\n const restrictToWorkspace = params.restrictToWorkspace ?? false;\n\n this.context = new ContextBuilder(params.workspace);\n this.sessions = new SessionManager(params.workspace);\n this.tools = new ToolRegistry();\n this.subagents = new SubagentManager({\n provider: params.provider,\n workspace: params.workspace,\n bus: params.bus,\n model: this.model,\n braveApiKey: params.braveApiKey,\n execConfig,\n restrictToWorkspace,\n });\n\n this.registerDefaultTools(\n execConfig,\n restrictToWorkspace,\n params.braveApiKey,\n params.toolsEnabled,\n params.toolsDisabled,\n params.customTools,\n );\n }\n\n private registerDefaultTools(\n execConfig: ExecToolConfig,\n restrictToWorkspace: boolean,\n braveApiKey?: string,\n toolsEnabled?: string[],\n toolsDisabled?: string[],\n customTools?: Tool[],\n ): void {\n const enabled = new Set(toolsEnabled ?? []);\n const disabled = new Set(toolsDisabled ?? []);\n const hasAllowlist = enabled.size > 0;\n const shouldRegister = (name: string): boolean =>\n (hasAllowlist ? enabled.has(name) : true) && !disabled.has(name);\n\n const registerIfEnabled = (tool: Tool): void => {\n if (shouldRegister(tool.name)) {\n this.tools.register(tool);\n }\n };\n\n // File tools — pass allowedDir when restrictToWorkspace is enabled\n const allowedDir = restrictToWorkspace ? this.workspace : undefined;\n const readOnlyPaths = restrictToWorkspace ? [getBuiltinSkillsDir()] : undefined;\n registerIfEnabled(new ReadFileTool({ allowedDir, readOnlyPaths }));\n registerIfEnabled(new WriteFileTool({ allowedDir }));\n registerIfEnabled(new EditFileTool({ allowedDir }));\n registerIfEnabled(new ListDirTool({ allowedDir, readOnlyPaths }));\n\n // Shell tool\n registerIfEnabled(\n new ExecTool({\n workingDir: this.workspace,\n timeout: execConfig.timeout,\n restrictToWorkspace,\n }),\n );\n\n // Web tools\n registerIfEnabled(new WebSearchTool({ apiKey: braveApiKey }));\n registerIfEnabled(new WebFetchTool());\n\n // Message tool\n const messageTool = new MessageTool({\n sendCallback: (msg) => this.bus.publishOutbound(msg),\n });\n registerIfEnabled(messageTool);\n\n // Spawn tool\n const spawnTool = new SpawnTool(this.subagents);\n registerIfEnabled(spawnTool);\n\n // Cron tool — always registered, uses DO scheduling via worker API\n registerIfEnabled(new CronTool());\n\n // Flex Message tool — builds LINE Flex JSON from structured data\n registerIfEnabled(new FlexTool());\n\n if (customTools && customTools.length > 0) {\n for (const tool of customTools) {\n registerIfEnabled(tool);\n }\n }\n }\n\n /** Run the agent loop, processing messages from the bus. */\n async run(): Promise<void> {\n this._running = true;\n console.log(\"Agent loop started\");\n\n while (this._running) {\n try {\n const msg = await this.bus.consumeInboundTimeout(1000);\n\n // Process concurrently so new messages can abort in-flight ones\n this.processMessage(msg)\n .then(async (response) => {\n if (response) {\n await this.bus.publishOutbound(response);\n }\n })\n .catch(async (err) => {\n if (isAbortError(err)) return; // Already handled\n console.error(\"Error processing message:\", err);\n await this.bus.publishOutbound(\n createOutboundMessage({\n channel: msg.channel,\n chatId: msg.chatId,\n content: `Sorry, I encountered an error: ${err instanceof Error ? err.message : err}`,\n }),\n );\n });\n } catch {\n // timeout, continue\n }\n }\n }\n\n /** Stop the agent loop. */\n stop(): void {\n this._running = false;\n console.log(\"Agent loop stopping\");\n }\n\n /** Process a single inbound message. */\n private async processMessage(\n msg: InboundMessage,\n ): Promise<OutboundMessage | null> {\n // Handle system messages (subagent announces)\n if (msg.channel === \"system\") {\n return this.processSystemMessage(msg);\n }\n\n console.log(`Processing message from ${msg.channel}:${msg.senderId}`);\n\n const sessionKey = `${msg.channel}:${msg.chatId}`;\n\n // Abort any in-flight request for this session\n const existing = this.inflight.get(sessionKey);\n if (existing) {\n console.log(`Aborting in-flight request for ${sessionKey}`);\n existing.abort();\n }\n\n // Create a new AbortController for this request\n const controller = new AbortController();\n this.inflight.set(sessionKey, controller);\n\n const session = this.sessions.getOrCreate(sessionKey);\n\n // Consolidate memory if session is too large\n if (session.history.length > this.memoryWindow) {\n await this.consolidateMemory(session);\n }\n\n // Update tool contexts\n this.updateToolContexts(msg.channel, msg.chatId);\n\n // Build initial messages\n const messages = this.context.buildMessages({\n history: session.getHistory(),\n currentMessage: msg.content,\n media: msg.media.length > 0 ? msg.media : undefined,\n channel: msg.channel,\n chatId: msg.chatId,\n });\n\n // The messages array is: [system, ...history, currentUser]\n // We want to save from the current user message onward (skip system + old history).\n const savedHistoryLen = session.getHistory().length;\n const newMsgStart = 1 + savedHistoryLen; // 1 for system prompt\n\n try {\n // Agent loop (mutates messages by appending assistant/tool messages)\n const result = await this.runAgentLoop(messages, controller.signal, (text) => {\n if (text && text.trim().length > 0) {\n this.bus.publishOutbound(\n createOutboundMessage({\n channel: msg.channel,\n chatId: msg.chatId,\n content: text,\n }),\n );\n }\n });\n\n // Save the new messages from this turn (user + all agent loop messages)\n session.addTurnMessages(messages.slice(newMsgStart), result.toolsUsed);\n this.sessions.save(session);\n\n return createOutboundMessage({\n channel: msg.channel,\n chatId: msg.chatId,\n content: result.content,\n });\n } catch (err) {\n if (isAbortError(err)) {\n // Request was aborted because a new message arrived.\n // Save the user message to history so the next request has context,\n // but don't save any assistant response.\n const userMessages = messages.slice(newMsgStart).filter((m) => m.role === \"user\");\n if (userMessages.length > 0) {\n session.addTurnMessages(userMessages);\n this.sessions.save(session);\n }\n console.log(`Request aborted for ${sessionKey}, user message saved to history`);\n return null; // No response -- the new message will handle it\n }\n throw err; // Re-throw non-abort errors\n } finally {\n // Clean up if this is still our controller\n if (this.inflight.get(sessionKey) === controller) {\n this.inflight.delete(sessionKey);\n }\n }\n }\n\n private async processSystemMessage(\n msg: InboundMessage,\n ): Promise<OutboundMessage | null> {\n console.log(`Processing system message from ${msg.senderId}`);\n\n let originChannel: string;\n let originChatId: string;\n\n if (msg.chatId.includes(\":\")) {\n const [ch, id] = msg.chatId.split(\":\", 2);\n originChannel = ch;\n originChatId = id;\n } else {\n originChannel = \"cli\";\n originChatId = msg.chatId;\n }\n\n const sessionKey = `${originChannel}:${originChatId}`;\n const session = this.sessions.getOrCreate(sessionKey);\n\n this.updateToolContexts(originChannel, originChatId);\n\n const messages = this.context.buildMessages({\n history: session.getHistory(),\n currentMessage: msg.content,\n channel: originChannel,\n chatId: originChatId,\n });\n\n const savedHistoryLen = session.getHistory().length;\n const newMsgStart = 1 + savedHistoryLen;\n\n const result = await this.runAgentLoop(messages);\n\n session.addTurnMessages(messages.slice(newMsgStart), result.toolsUsed);\n this.sessions.save(session);\n\n return createOutboundMessage({\n channel: originChannel,\n chatId: originChatId,\n content: result.content,\n });\n }\n\n private async runAgentLoop(\n messages: ChatMessage[],\n signal?: AbortSignal,\n onToolCallText?: (text: string) => void,\n ): Promise<{ content: string; toolsUsed: string[] }> {\n let finalContent: string | null = null;\n let sentToolCallNotice = false;\n const toolsUsed: string[] = [];\n\n for (let i = 0; i < this.maxIterations; i++) {\n const response = await this.provider.chat({\n messages,\n tools: this.tools.getDefinitions(),\n model: this.model,\n maxTokens: this.maxTokens,\n signal,\n });\n\n if (response.hasToolCalls) {\n // Send an interim message so the user knows we're working\n if (!sentToolCallNotice && onToolCallText) {\n const interimText = response.content?.trim()\n || this.getToolCallFallbackText(response.toolCalls);\n if (interimText) {\n onToolCallText(interimText);\n }\n sentToolCallNotice = true;\n }\n const toolCallDicts = response.toolCalls.map((tc) => ({\n id: tc.id,\n type: \"function\" as const,\n function: {\n name: tc.name,\n arguments: JSON.stringify(tc.arguments),\n },\n }));\n\n this.context.addAssistantMessage(\n messages,\n response.content,\n toolCallDicts,\n );\n\n for (const tc of response.toolCalls) {\n toolsUsed.push(tc.name);\n console.log(`Tool: ${tc.name}(${JSON.stringify(tc.arguments)})`);\n\n // Detect skill reads\n if (tc.name === \"read_file\") {\n const path = String(tc.arguments?.path ?? \"\");\n const skillMatch = path.match(/skills\\/([^/]+)\\/SKILL\\.md$/);\n if (skillMatch) {\n console.log(`Skill activated: ${skillMatch[1]}`);\n }\n }\n\n const result = await this.tools.execute(tc.name, tc.arguments);\n this.context.addToolResult(messages, tc.id, tc.name, result);\n\n // Auto-send flex_message results so they get rendered as Flex Messages\n // regardless of whether the LLM echoes the JSON in its response\n if (tc.name === \"flex_message\" && onToolCallText && !result.startsWith(\"Error\")) {\n // Extract just the JSON part (before the instruction suffix)\n const jsonOnly = result.split(\"\\n\\n(\")[0];\n onToolCallText(jsonOnly);\n }\n }\n } else {\n finalContent = response.content;\n\n // If the LLM returned empty content after tool use, nudge it to respond\n if ((!finalContent || finalContent.trim().length === 0) && i > 0) {\n messages.push({\n role: \"assistant\",\n content: \"\",\n });\n messages.push({\n role: \"user\",\n content: \"(You used tools but didn't respond to the user. Please provide a brief response summarizing what you did.)\",\n });\n continue;\n }\n\n // Push the final assistant message so it gets persisted with the turn\n messages.push({ role: \"assistant\", content: finalContent ?? \"\" });\n break;\n }\n }\n\n if (!finalContent || finalContent.trim().length === 0) {\n finalContent = \"I've completed processing but have no response to give.\";\n }\n\n // If we exhausted iterations without a non-tool-call response, still persist the final text\n if (messages[messages.length - 1]?.role !== \"assistant\" || messages[messages.length - 1]?.content !== finalContent) {\n messages.push({ role: \"assistant\", content: finalContent });\n }\n\n return { content: finalContent, toolsUsed };\n }\n\n /** Generate a fallback interim message based on which tools are being called. */\n private getToolCallFallbackText(toolCalls: ToolCallRequest[]): string {\n const toolNames = toolCalls.map((tc) => tc.name);\n const fallbacks: Record<string, string> = {\n web_search: \"検索中...\",\n web_fetch: \"ページを読み込み中...\",\n spawn: \"サブエージェントを起動中...\",\n flex_message: \"カードを作成中...\",\n };\n for (const name of toolNames) {\n if (fallbacks[name]) return fallbacks[name];\n }\n return \"ちょっと待ってね...\";\n }\n\n private updateToolContexts(channel: string, chatId: string): void {\n const messageTool = this.tools.get(\"message\");\n if (messageTool instanceof MessageTool) {\n messageTool.setContext(channel, chatId);\n }\n\n const spawnTool = this.tools.get(\"spawn\");\n if (spawnTool instanceof SpawnTool) {\n spawnTool.setContext(channel, chatId);\n }\n\n const cronTool = this.tools.get(\"cron\");\n if (cronTool instanceof CronTool) {\n cronTool.setContext(channel, chatId);\n }\n }\n\n /** Process a message directly (for CLI or cron usage). */\n async processDirect(\n content: string,\n sessionKey = \"cli:direct\",\n channel = \"cli\",\n chatId = \"direct\",\n ): Promise<string> {\n // Use inline version of processMessage for direct calls\n const session = this.sessions.getOrCreate(sessionKey);\n this.updateToolContexts(channel, chatId);\n\n const messages = this.context.buildMessages({\n history: session.getHistory(),\n currentMessage: content,\n channel,\n chatId,\n });\n\n const savedHistoryLen = session.getHistory().length;\n const newMsgStart = 1 + savedHistoryLen;\n\n const result = await this.runAgentLoop(messages);\n\n session.addTurnMessages(messages.slice(newMsgStart), result.toolsUsed);\n this.sessions.save(session);\n\n return result.content;\n }\n\n /** Consolidate old messages into MEMORY.md + HISTORY.md, then trim session. */\n private async consolidateMemory(session: Session): Promise<void> {\n const memory = new MemoryStore(this.workspace);\n const keepCount = Math.min(10, Math.max(2, Math.floor(this.memoryWindow / 2)));\n const oldMessages = session.history.slice(0, -keepCount);\n if (oldMessages.length === 0) return;\n\n console.log(`Memory consolidation: ${session.history.length} messages, archiving ${oldMessages.length}, keeping ${keepCount}`);\n\n // Format messages for LLM\n const lines: string[] = [];\n for (const m of oldMessages) {\n const content = typeof m.content === \"string\" ? m.content : \"\";\n if (!content) continue;\n const role = m.role.toUpperCase();\n const tools = m.toolsUsed ? ` [tools: ${m.toolsUsed.join(\", \")}]` : \"\";\n const ts = m.timestamp ? `[${m.timestamp.slice(0, 16)}] ` : \"\";\n lines.push(`${ts}${role}${tools}: ${content}`);\n }\n const conversation = lines.join(\"\\n\");\n const currentMemory = memory.readLongTerm();\n\n const prompt = `You are a memory consolidation agent. Process this conversation and return a JSON object with exactly two keys:\n\n1. \"history_entry\": A paragraph (2-5 sentences) summarizing the key events/decisions/topics. Start with a timestamp like [YYYY-MM-DD HH:MM]. Include enough detail to be useful when found by grep search later.\n\n2. \"memory_update\": The updated long-term memory content. Add any new facts: user location, preferences, personal info, habits, project context, technical decisions, tools/services used. If nothing new, return the existing content unchanged.\n\n## Current Long-term Memory\n${currentMemory || \"(empty)\"}\n\n## Conversation to Process\n${conversation}\n\nRespond with ONLY valid JSON, no markdown fences.`;\n\n try {\n const response = await this.provider.chat({\n messages: [\n { role: \"system\", content: \"You are a memory consolidation agent. Respond only with valid JSON.\" },\n { role: \"user\", content: prompt },\n ],\n model: this.consolidationModel,\n });\n\n let text = (response.content || \"\").trim();\n if (text.startsWith(\"```\")) {\n text = text.split(\"\\n\").slice(1).join(\"\\n\").split(\"```\")[0].trim();\n }\n\n const result = JSON.parse(text);\n\n if (result.history_entry) {\n const entry = typeof result.history_entry === \"string\"\n ? result.history_entry\n : JSON.stringify(result.history_entry, null, 2);\n memory.appendHistory(entry);\n }\n if (result.memory_update && result.memory_update !== currentMemory) {\n const update = typeof result.memory_update === \"string\"\n ? result.memory_update\n : JSON.stringify(result.memory_update, null, 2);\n memory.writeLongTerm(update);\n }\n } catch (err) {\n console.error(\"Memory consolidation failed:\", err);\n // Fallback: append raw conversation to history so it's not lost\n const fallbackEntry = `[${new Date().toISOString().slice(0, 16)}] Consolidation failed, archiving raw messages:\\n${conversation.slice(0, 2000)}`;\n memory.appendHistory(fallbackEntry);\n }\n\n // Always trim session to prevent unbounded growth\n session.trimHistory(keepCount);\n this.sessions.save(session);\n console.log(`Memory consolidation done, session trimmed to ${session.history.length} messages`);\n }\n}\n\n/** Check if an error is an abort/cancellation error. */\nfunction isAbortError(err: unknown): boolean {\n if (err instanceof DOMException && err.name === \"AbortError\") return true;\n if (err instanceof Error) {\n if (err.name === \"AbortError\") return true;\n // OpenAI SDK wraps abort as APIUserAbortError\n if (err.name === \"APIUserAbortError\") return true;\n if (err.message.includes(\"abort\")) return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,YAAb,MAAuB;CACrB,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,AAAQ,WAAW;;CAGnB,AAAQ,2BAAW,IAAI,KAA8B;CAErD,YAAY,QAeT;AACD,OA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
|
+
{"version":3,"file":"flex.d.mts","names":[],"sources":["../../../src/agent/tools/flex.ts"],"mappings":";;;;;AASA;;;;;cAAa,QAAA,SAAiB,IAAA;EAAA,SACnB,IAAA;EAAA,SACA,WAAA;EAAA,SAEA,UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4EH,OAAA,CAAQ,IAAA,EAAM,MAAA,oBAA0B,OAAA;EAAA,QAwCtC,YAAA;EAAA,QAgEA,aAAA;EAAA,QA4BA,kBAAA;EAAA,QAwCA,YAAA;EAAA,QA+CA,mBAAA;EAAA,QAiDA,cAAA;EAAA,QAkCA,WAAA;AAAA"}
|
|
@@ -171,7 +171,7 @@ var FlexTool = class extends Tool {
|
|
|
171
171
|
break;
|
|
172
172
|
default: return `Error: unknown template '${template}'. Use: fortune, info_card, action_buttons, receipt, morning_summary, hydration, custom.`;
|
|
173
173
|
}
|
|
174
|
-
return JSON.stringify(flex)
|
|
174
|
+
return `${JSON.stringify(flex)}\n\n(Card sent automatically. Do NOT repeat the JSON. Just respond naturally.)`;
|
|
175
175
|
} catch (err) {
|
|
176
176
|
return `Error building flex message: ${err instanceof Error ? err.message : err}`;
|
|
177
177
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flex.mjs","names":[],"sources":["../../../src/agent/tools/flex.ts"],"sourcesContent":["import { Tool } from \"./base.js\";\n\n/**\n * Tool for building LINE Flex Messages from structured data.\n *\n * The LLM calls this tool with a template name and data object,\n * and the tool returns valid Flex JSON that line.ts parseMessage()\n * will detect and send as a Flex Message.\n */\nexport class FlexTool extends Tool {\n readonly name = \"flex_message\";\n readonly description =\n \"Build a LINE Flex Message from a template. Returns JSON that will be rendered as a rich card in LINE. Use this instead of outputting raw JSON.\";\n readonly parameters = {\n type: \"object\",\n properties: {\n template: {\n type: \"string\",\n description:\n \"Template name. Available: fortune, info_card, action_buttons, receipt, morning_summary, hydration, custom.\",\n },\n data: {\n type: \"object\",\n description: \"Template-specific data. See each template for fields.\",\n properties: {\n // fortune\n sign: { type: \"string\", description: \"Zodiac sign with emoji (e.g. '♍ 乙女座')\" },\n stars: { type: \"integer\", description: \"1-5 star rating\" },\n message: { type: \"string\", description: \"Fortune message\" },\n lucky_color: { type: \"string\", description: \"Lucky color name\" },\n lucky_item: { type: \"string\", description: \"Lucky item name\" },\n // info_card\n title: { type: \"string\", description: \"Card title\" },\n body: { type: \"string\", description: \"Card body text\" },\n // action_buttons\n prompt: { type: \"string\", description: \"Question or prompt text\" },\n buttons: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n label: { type: \"string\" },\n text: { type: \"string\" },\n style: { type: \"string\", enum: [\"primary\", \"secondary\", \"link\"] },\n },\n },\n description: \"Button definitions\",\n },\n // receipt\n items: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n value: { type: \"string\" },\n },\n },\n description: \"Line items\",\n },\n total: { type: \"string\", description: \"Total amount\" },\n // morning_summary\n greeting: { type: \"string\", description: \"Greeting text (e.g. 'おはよう!')\" },\n date: { type: \"string\", description: \"Date string (e.g. '2月13日 木曜日')\" },\n weather: { type: \"string\", description: \"Weather info (e.g. '東京 12°C 曇り')\" },\n advice: { type: \"string\", description: \"Short advice (e.g. 'コートでOK')\" },\n schedule: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Schedule/reminder lines\",\n },\n header_color: { type: \"string\", description: \"Header background color hex (default: #1DB446)\" },\n // hydration\n current: { type: \"integer\", description: \"Current count (e.g. glasses drunk)\" },\n goal: { type: \"integer\", description: \"Goal count\" },\n unit: { type: \"string\", description: \"Unit label (default: 杯)\" },\n button_label: { type: \"string\", description: \"Button label (default: '飲んだ!')\" },\n button_text: { type: \"string\", description: \"Button message text (default: '水飲んだ')\" },\n // custom\n contents: {\n type: \"array\",\n description: \"Raw Flex body contents array for custom template\",\n },\n },\n },\n },\n required: [\"template\", \"data\"],\n };\n\n async execute(args: Record<string, unknown>): Promise<string> {\n const template = String(args.template);\n const data = (args.data ?? {}) as Record<string, unknown>;\n\n try {\n let flex: Record<string, unknown>;\n\n switch (template) {\n case \"fortune\":\n flex = this.buildFortune(data);\n break;\n case \"info_card\":\n flex = this.buildInfoCard(data);\n break;\n case \"action_buttons\":\n flex = this.buildActionButtons(data);\n break;\n case \"receipt\":\n flex = this.buildReceipt(data);\n break;\n case \"morning_summary\":\n flex = this.buildMorningSummary(data);\n break;\n case \"hydration\":\n flex = this.buildHydration(data);\n break;\n case \"custom\":\n flex = this.buildCustom(data);\n break;\n default:\n return `Error: unknown template '${template}'. Use: fortune, info_card, action_buttons, receipt, morning_summary, hydration, custom.`;\n }\n\n return JSON.stringify(flex);\n } catch (err) {\n return `Error building flex message: ${err instanceof Error ? err.message : err}`;\n }\n }\n\n private buildFortune(data: Record<string, unknown>): Record<string, unknown> {\n const sign = String(data.sign ?? \"♈ 牡羊座\");\n const stars = Math.max(1, Math.min(5, Number(data.stars ?? 3)));\n const message = String(data.message ?? \"\");\n const luckyColor = data.lucky_color ? String(data.lucky_color) : null;\n const luckyItem = data.lucky_item ? String(data.lucky_item) : null;\n\n const starText = \"★\".repeat(stars) + \"☆\".repeat(5 - stars);\n\n const contents: Record<string, unknown>[] = [\n { type: \"text\", text: sign, weight: \"bold\", size: \"xl\" },\n { type: \"text\", text: \"今日の運勢\", size: \"sm\", color: \"#666666\" },\n { type: \"text\", text: starText, size: \"xxl\", margin: \"md\" },\n ];\n\n if (message) {\n contents.push({\n type: \"text\",\n text: message,\n wrap: true,\n margin: \"sm\",\n });\n }\n\n if (luckyColor || luckyItem) {\n contents.push({ type: \"separator\", margin: \"md\" });\n }\n\n if (luckyColor) {\n contents.push({\n type: \"box\",\n layout: \"horizontal\",\n margin: \"md\",\n contents: [\n { type: \"text\", text: \"ラッキーカラー\", size: \"sm\", color: \"#228B22\", flex: 0 },\n { type: \"text\", text: luckyColor, size: \"sm\", align: \"end\" },\n ],\n });\n }\n\n if (luckyItem) {\n contents.push({\n type: \"box\",\n layout: \"horizontal\",\n margin: luckyColor ? \"sm\" : \"md\",\n contents: [\n { type: \"text\", text: \"ラッキーアイテム\", size: \"sm\", color: \"#228B22\", flex: 0 },\n { type: \"text\", text: luckyItem, size: \"sm\", align: \"end\" },\n ],\n });\n }\n\n return {\n type: \"bubble\",\n size: \"kilo\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n paddingAll: \"lg\",\n contents,\n },\n };\n }\n\n private buildInfoCard(data: Record<string, unknown>): Record<string, unknown> {\n const title = String(data.title ?? \"お知らせ\");\n const body = String(data.body ?? \"\");\n\n const contents: Record<string, unknown>[] = [\n { type: \"text\", text: title, weight: \"bold\", size: \"lg\" },\n { type: \"separator\", margin: \"md\" },\n ];\n\n if (body) {\n contents.push({\n type: \"text\",\n text: body,\n wrap: true,\n margin: \"md\",\n });\n }\n\n return {\n type: \"bubble\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents,\n },\n };\n }\n\n private buildActionButtons(data: Record<string, unknown>): Record<string, unknown> {\n const prompt = String(data.prompt ?? \"選択してください\");\n const buttons = (data.buttons ?? []) as Array<Record<string, unknown>>;\n\n if (buttons.length === 0) {\n // Default yes/no\n buttons.push(\n { label: \"はい\", text: \"はい\", style: \"primary\" },\n { label: \"いいえ\", text: \"いいえ\", style: \"secondary\" },\n );\n }\n\n const buttonContents = buttons.map((btn) => ({\n type: \"button\",\n style: String(btn.style ?? \"primary\"),\n action: {\n type: \"message\",\n label: String(btn.label ?? \"\"),\n text: String(btn.text ?? btn.label ?? \"\"),\n },\n }));\n\n return {\n type: \"bubble\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents: [\n { type: \"text\", text: prompt, weight: \"bold\", wrap: true },\n ],\n },\n footer: {\n type: \"box\",\n layout: \"vertical\",\n spacing: \"sm\",\n contents: buttonContents,\n },\n };\n }\n\n private buildReceipt(data: Record<string, unknown>): Record<string, unknown> {\n const title = String(data.title ?? \"明細\");\n const items = (data.items ?? []) as Array<Record<string, unknown>>;\n const total = data.total ? String(data.total) : null;\n\n const contents: Record<string, unknown>[] = [\n { type: \"text\", text: `💰 ${title}`, weight: \"bold\" },\n { type: \"separator\", margin: \"lg\" },\n ];\n\n for (const item of items) {\n contents.push({\n type: \"box\",\n layout: \"horizontal\",\n margin: \"md\",\n contents: [\n { type: \"text\", text: String(item.name ?? \"\"), flex: 0 },\n { type: \"text\", text: String(item.value ?? \"\"), align: \"end\" },\n ],\n });\n }\n\n if (total) {\n contents.push(\n { type: \"separator\", margin: \"lg\" },\n {\n type: \"box\",\n layout: \"horizontal\",\n margin: \"md\",\n contents: [\n { type: \"text\", text: \"合計\", weight: \"bold\" },\n { type: \"text\", text: total, weight: \"bold\", align: \"end\" },\n ],\n },\n );\n }\n\n return {\n type: \"bubble\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents,\n },\n };\n }\n\n private buildMorningSummary(data: Record<string, unknown>): Record<string, unknown> {\n const greeting = String(data.greeting ?? \"おはよう!\");\n const date = String(data.date ?? \"\");\n const weather = data.weather ? String(data.weather) : null;\n const advice = data.advice ? String(data.advice) : null;\n const schedule = (data.schedule ?? []) as string[];\n const headerColor = String(data.header_color ?? \"#1DB446\");\n\n const headerContents: Record<string, unknown>[] = [\n { type: \"text\", text: greeting, color: \"#ffffff\", weight: \"bold\", size: \"lg\" },\n ];\n if (date) {\n headerContents.push({ type: \"text\", text: date, color: \"#ffffff\", size: \"sm\" });\n }\n\n const bodyContents: Record<string, unknown>[] = [];\n\n if (weather) {\n bodyContents.push({ type: \"text\", text: weather, weight: \"bold\" });\n }\n if (advice) {\n bodyContents.push({ type: \"text\", text: advice, size: \"sm\", color: \"#666666\" });\n }\n\n if (schedule.length > 0) {\n bodyContents.push({ type: \"separator\", margin: \"md\" });\n for (const line of schedule) {\n bodyContents.push({ type: \"text\", text: line, margin: \"md\", wrap: true });\n }\n }\n\n return {\n type: \"bubble\",\n header: {\n type: \"box\",\n layout: \"vertical\",\n backgroundColor: headerColor,\n paddingAll: \"lg\",\n contents: headerContents,\n },\n body: {\n type: \"box\",\n layout: \"vertical\",\n paddingAll: \"lg\",\n contents: bodyContents.length > 0 ? bodyContents : [{ type: \"text\", text: \"良い一日を!\" }],\n },\n };\n }\n\n private buildHydration(data: Record<string, unknown>): Record<string, unknown> {\n const title = String(data.title ?? \"水飲んだ?\");\n const current = Number(data.current ?? 0);\n const goal = Number(data.goal ?? 8);\n const unit = String(data.unit ?? \"杯\");\n const buttonLabel = String(data.button_label ?? \"飲んだ!\");\n const buttonText = String(data.button_text ?? \"水飲んだ\");\n\n return {\n type: \"bubble\",\n size: \"kilo\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents: [\n { type: \"text\", text: title, size: \"xl\" },\n { type: \"text\", text: `今日: ${current}${unit} / ${goal}${unit}`, color: \"#666666\" },\n ],\n },\n footer: {\n type: \"box\",\n layout: \"horizontal\",\n contents: [\n {\n type: \"button\",\n style: \"primary\",\n color: \"#00B9ED\",\n action: { type: \"message\", label: buttonLabel, text: buttonText },\n },\n ],\n },\n };\n }\n\n private buildCustom(data: Record<string, unknown>): Record<string, unknown> {\n // If raw contents array is provided, use it directly\n const rawContents = data.contents as unknown[];\n if (Array.isArray(rawContents) && rawContents.length > 0) {\n return {\n type: \"bubble\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents: rawContents,\n },\n };\n }\n\n // Fallback: auto-build a card from common fields (title, body, buttons, header_color)\n const title = data.title ? String(data.title) : null;\n const body = data.body ? String(data.body) : null;\n const buttons = Array.isArray(data.buttons) ? data.buttons as Array<Record<string, unknown>> : [];\n const headerColor = data.header_color ? String(data.header_color) : null;\n\n if (!title && !body && buttons.length === 0) {\n throw new Error(\"custom template requires 'contents' array, or at least one of: title, body, buttons\");\n }\n\n const bodyContents: Record<string, unknown>[] = [];\n\n if (title) {\n bodyContents.push({ type: \"text\", text: title, weight: \"bold\", size: \"lg\" });\n }\n if (body) {\n if (title) bodyContents.push({ type: \"separator\", margin: \"md\" });\n bodyContents.push({ type: \"text\", text: body, wrap: true, margin: title ? \"md\" : undefined });\n }\n\n const bubble: Record<string, unknown> = {\n type: \"bubble\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents: bodyContents.length > 0 ? bodyContents : [{ type: \"text\", text: \" \" }],\n },\n };\n\n // Add colored header if specified\n if (headerColor && title) {\n bubble.header = {\n type: \"box\",\n layout: \"vertical\",\n backgroundColor: headerColor,\n paddingAll: \"lg\",\n contents: [\n { type: \"text\", text: title, color: \"#ffffff\", weight: \"bold\", size: \"lg\" },\n ],\n };\n // Remove title from body since it's in the header now\n bodyContents.shift();\n }\n\n // Add buttons as footer\n if (buttons.length > 0) {\n bubble.footer = {\n type: \"box\",\n layout: \"vertical\",\n spacing: \"sm\",\n contents: buttons.map((btn) => ({\n type: \"button\",\n style: String(btn.style ?? \"primary\"),\n action: {\n type: \"message\",\n label: String(btn.label ?? \"\"),\n text: String(btn.text ?? btn.label ?? \"\"),\n },\n })),\n };\n }\n\n return bubble;\n }\n}\n"],"mappings":";;;;;;;;;;AASA,IAAa,WAAb,cAA8B,KAAK;CACjC,AAAS,OAAO;CAChB,AAAS,cACP;CACF,AAAS,aAAa;EACpB,MAAM;EACN,YAAY;GACV,UAAU;IACR,MAAM;IACN,aACE;IACH;GACD,MAAM;IACJ,MAAM;IACN,aAAa;IACb,YAAY;KAEV,MAAM;MAAE,MAAM;MAAU,aAAa;MAAyC;KAC9E,OAAO;MAAE,MAAM;MAAW,aAAa;MAAmB;KAC1D,SAAS;MAAE,MAAM;MAAU,aAAa;MAAmB;KAC3D,aAAa;MAAE,MAAM;MAAU,aAAa;MAAoB;KAChE,YAAY;MAAE,MAAM;MAAU,aAAa;MAAmB;KAE9D,OAAO;MAAE,MAAM;MAAU,aAAa;MAAc;KACpD,MAAM;MAAE,MAAM;MAAU,aAAa;MAAkB;KAEvD,Q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;AACjE,gBAAa,KAAK;IAAE,MAAM;IAAQ,MAAM;IAAM,MAAM;IAAM,QAAQ,QAAQ,OAAO;IAAW,CAAC;;EAG/F,MAAM,SAAkC;GACtC,MAAM;GACN,MAAM;IACJ,MAAM;IACN,QAAQ;IACR,UAAU,aAAa,SAAS,IAAI,eAAe,CAAC;KAAE,MAAM;KAAQ,MAAM;KAAK,CAAC;IACjF;GACF;AAGD,MAAI,eAAe,OAAO;AACxB,UAAO,SAAS;IACd,MAAM;IACN,QAAQ;IACR,iBAAiB;IACjB,YAAY;IACZ,UAAU,CACR;KAAE,MAAM;KAAQ,MAAM;KAAO,OAAO;KAAW,QAAQ;KAAQ,MAAM;KAAM,CAC5E;IACF;AAED,gBAAa,OAAO;;AAItB,MAAI,QAAQ,SAAS,EACnB,QAAO,SAAS;GACd,MAAM;GACN,QAAQ;GACR,SAAS;GACT,UAAU,QAAQ,KAAK,SAAS;IAC9B,MAAM;IACN,OAAO,OAAO,IAAI,SAAS,UAAU;IACrC,QAAQ;KACN,MAAM;KACN,OAAO,OAAO,IAAI,SAAS,GAAG;KAC9B,MAAM,OAAO,IAAI,QAAQ,IAAI,SAAS,GAAG;KAC1C;IACF,EAAE;GACJ;AAGH,SAAO"}
|
|
1
|
+
{"version":3,"file":"flex.mjs","names":[],"sources":["../../../src/agent/tools/flex.ts"],"sourcesContent":["import { Tool } from \"./base.js\";\n\n/**\n * Tool for building LINE Flex Messages from structured data.\n *\n * The LLM calls this tool with a template name and data object,\n * and the tool returns valid Flex JSON that line.ts parseMessage()\n * will detect and send as a Flex Message.\n */\nexport class FlexTool extends Tool {\n readonly name = \"flex_message\";\n readonly description =\n \"Build a LINE Flex Message from a template. Returns JSON that will be rendered as a rich card in LINE. Use this instead of outputting raw JSON.\";\n readonly parameters = {\n type: \"object\",\n properties: {\n template: {\n type: \"string\",\n description:\n \"Template name. Available: fortune, info_card, action_buttons, receipt, morning_summary, hydration, custom.\",\n },\n data: {\n type: \"object\",\n description: \"Template-specific data. See each template for fields.\",\n properties: {\n // fortune\n sign: { type: \"string\", description: \"Zodiac sign with emoji (e.g. '♍ 乙女座')\" },\n stars: { type: \"integer\", description: \"1-5 star rating\" },\n message: { type: \"string\", description: \"Fortune message\" },\n lucky_color: { type: \"string\", description: \"Lucky color name\" },\n lucky_item: { type: \"string\", description: \"Lucky item name\" },\n // info_card\n title: { type: \"string\", description: \"Card title\" },\n body: { type: \"string\", description: \"Card body text\" },\n // action_buttons\n prompt: { type: \"string\", description: \"Question or prompt text\" },\n buttons: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n label: { type: \"string\" },\n text: { type: \"string\" },\n style: { type: \"string\", enum: [\"primary\", \"secondary\", \"link\"] },\n },\n },\n description: \"Button definitions\",\n },\n // receipt\n items: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n value: { type: \"string\" },\n },\n },\n description: \"Line items\",\n },\n total: { type: \"string\", description: \"Total amount\" },\n // morning_summary\n greeting: { type: \"string\", description: \"Greeting text (e.g. 'おはよう!')\" },\n date: { type: \"string\", description: \"Date string (e.g. '2月13日 木曜日')\" },\n weather: { type: \"string\", description: \"Weather info (e.g. '東京 12°C 曇り')\" },\n advice: { type: \"string\", description: \"Short advice (e.g. 'コートでOK')\" },\n schedule: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Schedule/reminder lines\",\n },\n header_color: { type: \"string\", description: \"Header background color hex (default: #1DB446)\" },\n // hydration\n current: { type: \"integer\", description: \"Current count (e.g. glasses drunk)\" },\n goal: { type: \"integer\", description: \"Goal count\" },\n unit: { type: \"string\", description: \"Unit label (default: 杯)\" },\n button_label: { type: \"string\", description: \"Button label (default: '飲んだ!')\" },\n button_text: { type: \"string\", description: \"Button message text (default: '水飲んだ')\" },\n // custom\n contents: {\n type: \"array\",\n description: \"Raw Flex body contents array for custom template\",\n },\n },\n },\n },\n required: [\"template\", \"data\"],\n };\n\n async execute(args: Record<string, unknown>): Promise<string> {\n const template = String(args.template);\n const data = (args.data ?? {}) as Record<string, unknown>;\n\n try {\n let flex: Record<string, unknown>;\n\n switch (template) {\n case \"fortune\":\n flex = this.buildFortune(data);\n break;\n case \"info_card\":\n flex = this.buildInfoCard(data);\n break;\n case \"action_buttons\":\n flex = this.buildActionButtons(data);\n break;\n case \"receipt\":\n flex = this.buildReceipt(data);\n break;\n case \"morning_summary\":\n flex = this.buildMorningSummary(data);\n break;\n case \"hydration\":\n flex = this.buildHydration(data);\n break;\n case \"custom\":\n flex = this.buildCustom(data);\n break;\n default:\n return `Error: unknown template '${template}'. Use: fortune, info_card, action_buttons, receipt, morning_summary, hydration, custom.`;\n }\n\n const json = JSON.stringify(flex);\n return `${json}\\n\\n(Card sent automatically. Do NOT repeat the JSON. Just respond naturally.)`;\n } catch (err) {\n return `Error building flex message: ${err instanceof Error ? err.message : err}`;\n }\n }\n\n private buildFortune(data: Record<string, unknown>): Record<string, unknown> {\n const sign = String(data.sign ?? \"♈ 牡羊座\");\n const stars = Math.max(1, Math.min(5, Number(data.stars ?? 3)));\n const message = String(data.message ?? \"\");\n const luckyColor = data.lucky_color ? String(data.lucky_color) : null;\n const luckyItem = data.lucky_item ? String(data.lucky_item) : null;\n\n const starText = \"★\".repeat(stars) + \"☆\".repeat(5 - stars);\n\n const contents: Record<string, unknown>[] = [\n { type: \"text\", text: sign, weight: \"bold\", size: \"xl\" },\n { type: \"text\", text: \"今日の運勢\", size: \"sm\", color: \"#666666\" },\n { type: \"text\", text: starText, size: \"xxl\", margin: \"md\" },\n ];\n\n if (message) {\n contents.push({\n type: \"text\",\n text: message,\n wrap: true,\n margin: \"sm\",\n });\n }\n\n if (luckyColor || luckyItem) {\n contents.push({ type: \"separator\", margin: \"md\" });\n }\n\n if (luckyColor) {\n contents.push({\n type: \"box\",\n layout: \"horizontal\",\n margin: \"md\",\n contents: [\n { type: \"text\", text: \"ラッキーカラー\", size: \"sm\", color: \"#228B22\", flex: 0 },\n { type: \"text\", text: luckyColor, size: \"sm\", align: \"end\" },\n ],\n });\n }\n\n if (luckyItem) {\n contents.push({\n type: \"box\",\n layout: \"horizontal\",\n margin: luckyColor ? \"sm\" : \"md\",\n contents: [\n { type: \"text\", text: \"ラッキーアイテム\", size: \"sm\", color: \"#228B22\", flex: 0 },\n { type: \"text\", text: luckyItem, size: \"sm\", align: \"end\" },\n ],\n });\n }\n\n return {\n type: \"bubble\",\n size: \"kilo\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n paddingAll: \"lg\",\n contents,\n },\n };\n }\n\n private buildInfoCard(data: Record<string, unknown>): Record<string, unknown> {\n const title = String(data.title ?? \"お知らせ\");\n const body = String(data.body ?? \"\");\n\n const contents: Record<string, unknown>[] = [\n { type: \"text\", text: title, weight: \"bold\", size: \"lg\" },\n { type: \"separator\", margin: \"md\" },\n ];\n\n if (body) {\n contents.push({\n type: \"text\",\n text: body,\n wrap: true,\n margin: \"md\",\n });\n }\n\n return {\n type: \"bubble\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents,\n },\n };\n }\n\n private buildActionButtons(data: Record<string, unknown>): Record<string, unknown> {\n const prompt = String(data.prompt ?? \"選択してください\");\n const buttons = (data.buttons ?? []) as Array<Record<string, unknown>>;\n\n if (buttons.length === 0) {\n // Default yes/no\n buttons.push(\n { label: \"はい\", text: \"はい\", style: \"primary\" },\n { label: \"いいえ\", text: \"いいえ\", style: \"secondary\" },\n );\n }\n\n const buttonContents = buttons.map((btn) => ({\n type: \"button\",\n style: String(btn.style ?? \"primary\"),\n action: {\n type: \"message\",\n label: String(btn.label ?? \"\"),\n text: String(btn.text ?? btn.label ?? \"\"),\n },\n }));\n\n return {\n type: \"bubble\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents: [\n { type: \"text\", text: prompt, weight: \"bold\", wrap: true },\n ],\n },\n footer: {\n type: \"box\",\n layout: \"vertical\",\n spacing: \"sm\",\n contents: buttonContents,\n },\n };\n }\n\n private buildReceipt(data: Record<string, unknown>): Record<string, unknown> {\n const title = String(data.title ?? \"明細\");\n const items = (data.items ?? []) as Array<Record<string, unknown>>;\n const total = data.total ? String(data.total) : null;\n\n const contents: Record<string, unknown>[] = [\n { type: \"text\", text: `💰 ${title}`, weight: \"bold\" },\n { type: \"separator\", margin: \"lg\" },\n ];\n\n for (const item of items) {\n contents.push({\n type: \"box\",\n layout: \"horizontal\",\n margin: \"md\",\n contents: [\n { type: \"text\", text: String(item.name ?? \"\"), flex: 0 },\n { type: \"text\", text: String(item.value ?? \"\"), align: \"end\" },\n ],\n });\n }\n\n if (total) {\n contents.push(\n { type: \"separator\", margin: \"lg\" },\n {\n type: \"box\",\n layout: \"horizontal\",\n margin: \"md\",\n contents: [\n { type: \"text\", text: \"合計\", weight: \"bold\" },\n { type: \"text\", text: total, weight: \"bold\", align: \"end\" },\n ],\n },\n );\n }\n\n return {\n type: \"bubble\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents,\n },\n };\n }\n\n private buildMorningSummary(data: Record<string, unknown>): Record<string, unknown> {\n const greeting = String(data.greeting ?? \"おはよう!\");\n const date = String(data.date ?? \"\");\n const weather = data.weather ? String(data.weather) : null;\n const advice = data.advice ? String(data.advice) : null;\n const schedule = (data.schedule ?? []) as string[];\n const headerColor = String(data.header_color ?? \"#1DB446\");\n\n const headerContents: Record<string, unknown>[] = [\n { type: \"text\", text: greeting, color: \"#ffffff\", weight: \"bold\", size: \"lg\" },\n ];\n if (date) {\n headerContents.push({ type: \"text\", text: date, color: \"#ffffff\", size: \"sm\" });\n }\n\n const bodyContents: Record<string, unknown>[] = [];\n\n if (weather) {\n bodyContents.push({ type: \"text\", text: weather, weight: \"bold\" });\n }\n if (advice) {\n bodyContents.push({ type: \"text\", text: advice, size: \"sm\", color: \"#666666\" });\n }\n\n if (schedule.length > 0) {\n bodyContents.push({ type: \"separator\", margin: \"md\" });\n for (const line of schedule) {\n bodyContents.push({ type: \"text\", text: line, margin: \"md\", wrap: true });\n }\n }\n\n return {\n type: \"bubble\",\n header: {\n type: \"box\",\n layout: \"vertical\",\n backgroundColor: headerColor,\n paddingAll: \"lg\",\n contents: headerContents,\n },\n body: {\n type: \"box\",\n layout: \"vertical\",\n paddingAll: \"lg\",\n contents: bodyContents.length > 0 ? bodyContents : [{ type: \"text\", text: \"良い一日を!\" }],\n },\n };\n }\n\n private buildHydration(data: Record<string, unknown>): Record<string, unknown> {\n const title = String(data.title ?? \"水飲んだ?\");\n const current = Number(data.current ?? 0);\n const goal = Number(data.goal ?? 8);\n const unit = String(data.unit ?? \"杯\");\n const buttonLabel = String(data.button_label ?? \"飲んだ!\");\n const buttonText = String(data.button_text ?? \"水飲んだ\");\n\n return {\n type: \"bubble\",\n size: \"kilo\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents: [\n { type: \"text\", text: title, size: \"xl\" },\n { type: \"text\", text: `今日: ${current}${unit} / ${goal}${unit}`, color: \"#666666\" },\n ],\n },\n footer: {\n type: \"box\",\n layout: \"horizontal\",\n contents: [\n {\n type: \"button\",\n style: \"primary\",\n color: \"#00B9ED\",\n action: { type: \"message\", label: buttonLabel, text: buttonText },\n },\n ],\n },\n };\n }\n\n private buildCustom(data: Record<string, unknown>): Record<string, unknown> {\n // If raw contents array is provided, use it directly\n const rawContents = data.contents as unknown[];\n if (Array.isArray(rawContents) && rawContents.length > 0) {\n return {\n type: \"bubble\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents: rawContents,\n },\n };\n }\n\n // Fallback: auto-build a card from common fields (title, body, buttons, header_color)\n const title = data.title ? String(data.title) : null;\n const body = data.body ? String(data.body) : null;\n const buttons = Array.isArray(data.buttons) ? data.buttons as Array<Record<string, unknown>> : [];\n const headerColor = data.header_color ? String(data.header_color) : null;\n\n if (!title && !body && buttons.length === 0) {\n throw new Error(\"custom template requires 'contents' array, or at least one of: title, body, buttons\");\n }\n\n const bodyContents: Record<string, unknown>[] = [];\n\n if (title) {\n bodyContents.push({ type: \"text\", text: title, weight: \"bold\", size: \"lg\" });\n }\n if (body) {\n if (title) bodyContents.push({ type: \"separator\", margin: \"md\" });\n bodyContents.push({ type: \"text\", text: body, wrap: true, margin: title ? \"md\" : undefined });\n }\n\n const bubble: Record<string, unknown> = {\n type: \"bubble\",\n body: {\n type: \"box\",\n layout: \"vertical\",\n contents: bodyContents.length > 0 ? bodyContents : [{ type: \"text\", text: \" \" }],\n },\n };\n\n // Add colored header if specified\n if (headerColor && title) {\n bubble.header = {\n type: \"box\",\n layout: \"vertical\",\n backgroundColor: headerColor,\n paddingAll: \"lg\",\n contents: [\n { type: \"text\", text: title, color: \"#ffffff\", weight: \"bold\", size: \"lg\" },\n ],\n };\n // Remove title from body since it's in the header now\n bodyContents.shift();\n }\n\n // Add buttons as footer\n if (buttons.length > 0) {\n bubble.footer = {\n type: \"box\",\n layout: \"vertical\",\n spacing: \"sm\",\n contents: buttons.map((btn) => ({\n type: \"button\",\n style: String(btn.style ?? \"primary\"),\n action: {\n type: \"message\",\n label: String(btn.label ?? \"\"),\n text: String(btn.text ?? btn.label ?? \"\"),\n },\n })),\n };\n }\n\n return bubble;\n }\n}\n"],"mappings":";;;;;;;;;;AASA,IAAa,WAAb,cAA8B,KAAK;CACjC,AAAS,OAAO;CAChB,AAAS,cACP;CACF,AAAS,aAAa;EACpB,MAAM;EACN,YAAY;GACV,UAAU;IACR,MAAM;IACN,aACE;IACH;GACD,MAAM;IACJ,MAAM;IACN,aAAa;IACb,YAAY;KAEV,MAAM;MAAE,MAAM;MAAU,aAAa;MAAyC;KAC9E,OAAO;MAAE,MAAM;MAAW,aAAa;MAAmB;KAC1D,SAAS;MAAE,MAAM;MAAU,aAAa;MAAmB;KAC3D,aAAa;MAAE,MAAM;MAAU,aAAa;MAAoB;KAChE,YAAY;MAAE,MAAM;MAAU,aAAa;MAAmB;KAE9D,OAAO;MAAE,MAAM;MAAU,aAAa;MAAc;KACpD,MAAM;MAAE,MAAM;MAAU,aAAa;MAAkB;KAEvD,QAAQ;MAAE,MAAM;MAAU,aAAa;MAA2B;KAClE,SAAS;MACP,MAAM;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,MAAM;IAAM,QAAQ,QAAQ,OAAO;IAAW,CAAC;;EAG/F,MAAM,SAAkC;GACtC,MAAM;GACN,MAAM;IACJ,MAAM;IACN,QAAQ;IACR,UAAU,aAAa,SAAS,IAAI,eAAe,CAAC;KAAE,MAAM;KAAQ,MAAM;KAAK,CAAC;IACjF;GACF;AAGD,MAAI,eAAe,OAAO;AACxB,UAAO,SAAS;IACd,MAAM;IACN,QAAQ;IACR,iBAAiB;IACjB,YAAY;IACZ,UAAU,CACR;KAAE,MAAM;KAAQ,MAAM;KAAO,OAAO;KAAW,QAAQ;KAAQ,MAAM;KAAM,CAC5E;IACF;AAED,gBAAa,OAAO;;AAItB,MAAI,QAAQ,SAAS,EACnB,QAAO,SAAS;GACd,MAAM;GACN,QAAQ;GACR,SAAS;GACT,UAAU,QAAQ,KAAK,SAAS;IAC9B,MAAM;IACN,OAAO,OAAO,IAAI,SAAS,UAAU;IACrC,QAAQ;KACN,MAAM;KACN,OAAO,OAAO,IAAI,SAAS,GAAG;KAC9B,MAAM,OAAO,IAAI,QAAQ,IAAI,SAAS,GAAG;KAC1C;IACF,EAAE;GACJ;AAGH,SAAO"}
|
|
@@ -5,11 +5,11 @@ import { globalExpect } from "../../node_modules/vitest/dist/chunks/vi.DgezovHB.
|
|
|
5
5
|
//#region src/agent/tools/flex.test.ts
|
|
6
6
|
const tool = new FlexTool();
|
|
7
7
|
async function exec(template, data = {}) {
|
|
8
|
-
const
|
|
8
|
+
const jsonPart = (await tool.execute({
|
|
9
9
|
template,
|
|
10
10
|
data
|
|
11
|
-
});
|
|
12
|
-
return JSON.parse(
|
|
11
|
+
})).split("\n\n(")[0];
|
|
12
|
+
return JSON.parse(jsonPart);
|
|
13
13
|
}
|
|
14
14
|
async function execRaw(template, data = {}) {
|
|
15
15
|
return tool.execute({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flex.test.mjs","names":[],"sources":["../../../src/agent/tools/flex.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { FlexTool } from \"./flex.js\";\n\nconst tool = new FlexTool();\n\n// Helper: execute and parse result as JSON\nasync function exec(template: string, data: Record<string, unknown> = {}) {\n const result = await tool.execute({ template, data });\n return JSON.parse(result);\n}\n\n// Helper: execute and return raw string (for error cases)\nasync function execRaw(template: string, data: Record<string, unknown> = {}) {\n return tool.execute({ template, data });\n}\n\n// ---------------------------------------------------------------------------\n// fortune\n// ---------------------------------------------------------------------------\ndescribe(\"fortune\", () => {\n it(\"builds with defaults\", async () => {\n const flex = await exec(\"fortune\", { sign: \"♍ 乙女座\", stars: 4, message: \"良い日\" });\n expect(flex.type).toBe(\"bubble\");\n expect(flex.size).toBe(\"kilo\");\n\n const body = flex.body;\n expect(body.type).toBe(\"box\");\n // sign, 今日の運勢, stars, message\n expect(body.contents.length).toBeGreaterThanOrEqual(4);\n expect(body.contents[0].text).toBe(\"♍ 乙女座\");\n expect(body.contents[2].text).toBe(\"★★★★☆\");\n expect(body.contents[3].text).toBe(\"良い日\");\n });\n\n it(\"clamps stars to 1-5\", async () => {\n const low = await exec(\"fortune\", { stars: -10 });\n expect(low.body.contents[2].text).toBe(\"★☆☆☆☆\");\n\n const high = await exec(\"fortune\", { stars: 99 });\n expect(high.body.contents[2].text).toBe(\"★★★★★\");\n });\n\n it(\"includes lucky color and item\", async () => {\n const flex = await exec(\"fortune\", {\n sign: \"♈ 牡羊座\",\n stars: 3,\n lucky_color: \"赤\",\n lucky_item: \"傘\",\n });\n const contents = flex.body.contents;\n // Should have separator + color row + item row\n const colorRow = contents.find(\n (c: Record<string, unknown>) =>\n c.type === \"box\" &&\n Array.isArray(c.contents) &&\n (c.contents as Record<string, unknown>[]).some((t) => t.text === \"ラッキーカラー\"),\n );\n expect(colorRow).toBeTruthy();\n\n const itemRow = contents.find(\n (c: Record<string, unknown>) =>\n c.type === \"box\" &&\n Array.isArray(c.contents) &&\n (c.contents as Record<string, unknown>[]).some((t) => t.text === \"ラッキーアイテム\"),\n );\n expect(itemRow).toBeTruthy();\n });\n\n it(\"omits lucky fields when not provided\", async () => {\n const flex = await exec(\"fortune\", { stars: 5 });\n const contents = flex.body.contents;\n const hasSeparator = contents.some((c: Record<string, unknown>) => c.type === \"separator\");\n expect(hasSeparator).toBe(false);\n });\n});\n\n// ---------------------------------------------------------------------------\n// info_card\n// ---------------------------------------------------------------------------\ndescribe(\"info_card\", () => {\n it(\"builds with title and body\", async () => {\n const flex = await exec(\"info_card\", { title: \"テスト\", body: \"本文テキスト\" });\n expect(flex.type).toBe(\"bubble\");\n const contents = flex.body.contents;\n expect(contents[0].text).toBe(\"テスト\");\n expect(contents[1].type).toBe(\"separator\");\n expect(contents[2].text).toBe(\"本文テキスト\");\n });\n\n it(\"uses defaults when no data\", async () => {\n const flex = await exec(\"info_card\", {});\n expect(flex.body.contents[0].text).toBe(\"お知らせ\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// action_buttons\n// ---------------------------------------------------------------------------\ndescribe(\"action_buttons\", () => {\n it(\"builds with custom buttons\", async () => {\n const flex = await exec(\"action_buttons\", {\n prompt: \"好きな色は?\",\n buttons: [\n { label: \"赤\", text: \"赤が好き\", style: \"primary\" },\n { label: \"青\", text: \"青が好き\", style: \"secondary\" },\n ],\n });\n expect(flex.type).toBe(\"bubble\");\n expect(flex.body.contents[0].text).toBe(\"好きな色は?\");\n expect(flex.footer.contents).toHaveLength(2);\n expect(flex.footer.contents[0].action.label).toBe(\"赤\");\n expect(flex.footer.contents[1].action.text).toBe(\"青が好き\");\n });\n\n it(\"adds default yes/no buttons when empty\", async () => {\n const flex = await exec(\"action_buttons\", { prompt: \"OK?\" });\n expect(flex.footer.contents).toHaveLength(2);\n expect(flex.footer.contents[0].action.label).toBe(\"はい\");\n expect(flex.footer.contents[1].action.label).toBe(\"いいえ\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// receipt\n// ---------------------------------------------------------------------------\ndescribe(\"receipt\", () => {\n it(\"builds with items and total\", async () => {\n const flex = await exec(\"receipt\", {\n title: \"ランチ\",\n items: [\n { name: \"ラーメン\", value: \"¥900\" },\n { name: \"餃子\", value: \"¥400\" },\n ],\n total: \"¥1,300\",\n });\n expect(flex.type).toBe(\"bubble\");\n const contents = flex.body.contents;\n // title, separator, 2 items, separator, total\n expect(contents.length).toBe(6);\n expect(contents[0].text).toContain(\"ランチ\");\n // total row\n const totalRow = contents[5] as Record<string, unknown>;\n expect((totalRow.contents as Record<string, unknown>[])[1].text).toBe(\"¥1,300\");\n });\n\n it(\"omits total when not provided\", async () => {\n const flex = await exec(\"receipt\", {\n items: [{ name: \"Item\", value: \"100\" }],\n });\n // title, separator, 1 item = 3 contents (no total separator or total row)\n expect(flex.body.contents.length).toBe(3);\n });\n});\n\n// ---------------------------------------------------------------------------\n// morning_summary\n// ---------------------------------------------------------------------------\ndescribe(\"morning_summary\", () => {\n it(\"builds with all fields\", async () => {\n const flex = await exec(\"morning_summary\", {\n greeting: \"おはよう!\",\n date: \"2月13日 木曜日\",\n weather: \"東京 12°C 曇り\",\n advice: \"コートでOK\",\n schedule: [\"10:00 ミーティング\", \"14:00 歯医者\"],\n header_color: \"#FF6B6B\",\n });\n expect(flex.type).toBe(\"bubble\");\n expect(flex.header.backgroundColor).toBe(\"#FF6B6B\");\n expect(flex.header.contents[0].text).toBe(\"おはよう!\");\n expect(flex.header.contents[1].text).toBe(\"2月13日 木曜日\");\n\n const body = flex.body.contents;\n expect(body[0].text).toBe(\"東京 12°C 曇り\");\n expect(body[1].text).toBe(\"コートでOK\");\n // separator + 2 schedule items\n expect(body.length).toBe(5);\n });\n\n it(\"uses default header color\", async () => {\n const flex = await exec(\"morning_summary\", {});\n expect(flex.header.backgroundColor).toBe(\"#1DB446\");\n });\n\n it(\"shows fallback body when no weather/schedule\", async () => {\n const flex = await exec(\"morning_summary\", { greeting: \"やぁ\" });\n expect(flex.body.contents[0].text).toBe(\"良い一日を!\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// hydration\n// ---------------------------------------------------------------------------\ndescribe(\"hydration\", () => {\n it(\"builds with current/goal\", async () => {\n const flex = await exec(\"hydration\", { current: 3, goal: 8 });\n expect(flex.type).toBe(\"bubble\");\n expect(flex.size).toBe(\"kilo\");\n expect(flex.body.contents[0].text).toBe(\"水飲んだ?\");\n expect(flex.body.contents[1].text).toBe(\"今日: 3杯 / 8杯\");\n expect(flex.footer.contents[0].action.label).toBe(\"飲んだ!\");\n });\n\n it(\"uses custom unit and button text\", async () => {\n const flex = await exec(\"hydration\", {\n title: \"Coffee\",\n current: 2,\n goal: 4,\n unit: \"cups\",\n button_label: \"Had one!\",\n button_text: \"drank coffee\",\n });\n expect(flex.body.contents[0].text).toBe(\"Coffee\");\n expect(flex.body.contents[1].text).toBe(\"今日: 2cups / 4cups\");\n expect(flex.footer.contents[0].action.label).toBe(\"Had one!\");\n expect(flex.footer.contents[0].action.text).toBe(\"drank coffee\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// custom\n// ---------------------------------------------------------------------------\ndescribe(\"custom\", () => {\n it(\"uses raw contents array when provided\", async () => {\n const contents = [\n { type: \"text\", text: \"Hello\" },\n { type: \"text\", text: \"World\" },\n ];\n const flex = await exec(\"custom\", { contents });\n expect(flex.type).toBe(\"bubble\");\n expect(flex.body.contents).toEqual(contents);\n });\n\n it(\"auto-builds card from title + body\", async () => {\n const flex = await exec(\"custom\", { title: \"Title\", body: \"Body text\" });\n expect(flex.type).toBe(\"bubble\");\n const contents = flex.body.contents;\n expect(contents[0].text).toBe(\"Title\");\n expect(contents[1].type).toBe(\"separator\");\n expect(contents[2].text).toBe(\"Body text\");\n });\n\n it(\"auto-builds card with colored header\", async () => {\n const flex = await exec(\"custom\", {\n title: \"Workout\",\n body: \"Great session!\",\n header_color: \"#FF0000\",\n });\n expect(flex.header).toBeTruthy();\n expect(flex.header.backgroundColor).toBe(\"#FF0000\");\n expect(flex.header.contents[0].text).toBe(\"Workout\");\n // Title should be removed from body since it's in the header\n const bodyTexts = flex.body.contents.filter(\n (c: Record<string, unknown>) => c.type === \"text\",\n );\n expect(bodyTexts.every((t: Record<string, unknown>) => t.text !== \"Workout\")).toBe(true);\n });\n\n it(\"auto-builds card with buttons\", async () => {\n const flex = await exec(\"custom\", {\n title: \"Choose\",\n buttons: [\n { label: \"Option A\", text: \"A\", style: \"primary\" },\n { label: \"Option B\", text: \"B\", style: \"secondary\" },\n ],\n });\n expect(flex.footer).toBeTruthy();\n expect(flex.footer.contents).toHaveLength(2);\n expect(flex.footer.contents[0].action.label).toBe(\"Option A\");\n });\n\n it(\"errors when no contents, title, body, or buttons\", async () => {\n const result = await execRaw(\"custom\", {});\n expect(result).toContain(\"Error\");\n expect(result).toContain(\"custom template requires\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// unknown template\n// ---------------------------------------------------------------------------\ndescribe(\"unknown template\", () => {\n it(\"returns error for unknown template\", async () => {\n const result = await execRaw(\"nonexistent\", {});\n expect(result).toContain(\"Error: unknown template\");\n expect(result).toContain(\"nonexistent\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// tool metadata\n// ---------------------------------------------------------------------------\ndescribe(\"tool metadata\", () => {\n it(\"has correct name and description\", () => {\n expect(tool.name).toBe(\"flex_message\");\n expect(tool.description).toContain(\"Flex Message\");\n });\n\n it(\"generates valid tool definition\", () => {\n const def = tool.getDefinition();\n expect(def.type).toBe(\"function\");\n expect(def.function.name).toBe(\"flex_message\");\n expect(def.function.parameters.required).toContain(\"template\");\n expect(def.function.parameters.required).toContain(\"data\");\n });\n});\n"],"mappings":";;;;;AAGA,MAAM,OAAO,IAAI,UAAU;AAG3B,eAAe,KAAK,UAAkB,OAAgC,EAAE,EAAE;CACxE,MAAM,SAAS,MAAM,KAAK,QAAQ;EAAE;EAAU;EAAM,CAAC;AACrD,QAAO,KAAK,MAAM,OAAO;;AAI3B,eAAe,QAAQ,UAAkB,OAAgC,EAAE,EAAE;AAC3E,QAAO,KAAK,QAAQ;EAAE;EAAU;EAAM,CAAC;;AAMzC,SAAS,iBAAiB;AACxB,IAAG,w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aAAa,EAAE;AAC5C,eAAO,KAAK,OAAO,SAAS,GAAG,OAAO,MAAM,CAAC,KAAK,WAAW;GAC7D;AAEF,IAAG,oDAAoD,YAAY;EACjE,MAAM,SAAS,MAAM,QAAQ,UAAU,EAAE,CAAC;AAC1C,eAAO,OAAO,CAAC,UAAU,QAAQ;AACjC,eAAO,OAAO,CAAC,UAAU,2BAA2B;GACpD;EACF;AAKF,SAAS,0BAA0B;AACjC,IAAG,sCAAsC,YAAY;EACnD,MAAM,SAAS,MAAM,QAAQ,eAAe,EAAE,CAAC;AAC/C,eAAO,OAAO,CAAC,UAAU,0BAA0B;AACnD,eAAO,OAAO,CAAC,UAAU,cAAc;GACvC;EACF;AAKF,SAAS,uBAAuB;AAC9B,IAAG,0CAA0C;AAC3C,eAAO,KAAK,KAAK,CAAC,KAAK,eAAe;AACtC,eAAO,KAAK,YAAY,CAAC,UAAU,eAAe;GAClD;AAEF,IAAG,yCAAyC;EAC1C,MAAM,MAAM,KAAK,eAAe;AAChC,eAAO,IAAI,KAAK,CAAC,KAAK,WAAW;AACjC,eAAO,IAAI,SAAS,KAAK,CAAC,KAAK,eAAe;AAC9C,eAAO,IAAI,SAAS,WAAW,SAAS,CAAC,UAAU,WAAW;AAC9D,eAAO,IAAI,SAAS,WAAW,SAAS,CAAC,UAAU,OAAO;GAC1D;EACF"}
|
|
1
|
+
{"version":3,"file":"flex.test.mjs","names":[],"sources":["../../../src/agent/tools/flex.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { FlexTool } from \"./flex.js\";\n\nconst tool = new FlexTool();\n\n// Helper: execute and parse result as JSON (strip instruction suffix)\nasync function exec(template: string, data: Record<string, unknown> = {}) {\n const result = await tool.execute({ template, data });\n const jsonPart = result.split(\"\\n\\n(\")[0];\n return JSON.parse(jsonPart);\n}\n\n// Helper: execute and return raw string (for error cases)\nasync function execRaw(template: string, data: Record<string, unknown> = {}) {\n return tool.execute({ template, data });\n}\n\n// ---------------------------------------------------------------------------\n// fortune\n// ---------------------------------------------------------------------------\ndescribe(\"fortune\", () => {\n it(\"builds with defaults\", async () => {\n const flex = await exec(\"fortune\", { sign: \"♍ 乙女座\", stars: 4, message: \"良い日\" });\n expect(flex.type).toBe(\"bubble\");\n expect(flex.size).toBe(\"kilo\");\n\n const body = flex.body;\n expect(body.type).toBe(\"box\");\n // sign, 今日の運勢, stars, message\n expect(body.contents.length).toBeGreaterThanOrEqual(4);\n expect(body.contents[0].text).toBe(\"♍ 乙女座\");\n expect(body.contents[2].text).toBe(\"★★★★☆\");\n expect(body.contents[3].text).toBe(\"良い日\");\n });\n\n it(\"clamps stars to 1-5\", async () => {\n const low = await exec(\"fortune\", { stars: -10 });\n expect(low.body.contents[2].text).toBe(\"★☆☆☆☆\");\n\n const high = await exec(\"fortune\", { stars: 99 });\n expect(high.body.contents[2].text).toBe(\"★★★★★\");\n });\n\n it(\"includes lucky color and item\", async () => {\n const flex = await exec(\"fortune\", {\n sign: \"♈ 牡羊座\",\n stars: 3,\n lucky_color: \"赤\",\n lucky_item: \"傘\",\n });\n const contents = flex.body.contents;\n // Should have separator + color row + item row\n const colorRow = contents.find(\n (c: Record<string, unknown>) =>\n c.type === \"box\" &&\n Array.isArray(c.contents) &&\n (c.contents as Record<string, unknown>[]).some((t) => t.text === \"ラッキーカラー\"),\n );\n expect(colorRow).toBeTruthy();\n\n const itemRow = contents.find(\n (c: Record<string, unknown>) =>\n c.type === \"box\" &&\n Array.isArray(c.contents) &&\n (c.contents as Record<string, unknown>[]).some((t) => t.text === \"ラッキーアイテム\"),\n );\n expect(itemRow).toBeTruthy();\n });\n\n it(\"omits lucky fields when not provided\", async () => {\n const flex = await exec(\"fortune\", { stars: 5 });\n const contents = flex.body.contents;\n const hasSeparator = contents.some((c: Record<string, unknown>) => c.type === \"separator\");\n expect(hasSeparator).toBe(false);\n });\n});\n\n// ---------------------------------------------------------------------------\n// info_card\n// ---------------------------------------------------------------------------\ndescribe(\"info_card\", () => {\n it(\"builds with title and body\", async () => {\n const flex = await exec(\"info_card\", { title: \"テスト\", body: \"本文テキスト\" });\n expect(flex.type).toBe(\"bubble\");\n const contents = flex.body.contents;\n expect(contents[0].text).toBe(\"テスト\");\n expect(contents[1].type).toBe(\"separator\");\n expect(contents[2].text).toBe(\"本文テキスト\");\n });\n\n it(\"uses defaults when no data\", async () => {\n const flex = await exec(\"info_card\", {});\n expect(flex.body.contents[0].text).toBe(\"お知らせ\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// action_buttons\n// ---------------------------------------------------------------------------\ndescribe(\"action_buttons\", () => {\n it(\"builds with custom buttons\", async () => {\n const flex = await exec(\"action_buttons\", {\n prompt: \"好きな色は?\",\n buttons: [\n { label: \"赤\", text: \"赤が好き\", style: \"primary\" },\n { label: \"青\", text: \"青が好き\", style: \"secondary\" },\n ],\n });\n expect(flex.type).toBe(\"bubble\");\n expect(flex.body.contents[0].text).toBe(\"好きな色は?\");\n expect(flex.footer.contents).toHaveLength(2);\n expect(flex.footer.contents[0].action.label).toBe(\"赤\");\n expect(flex.footer.contents[1].action.text).toBe(\"青が好き\");\n });\n\n it(\"adds default yes/no buttons when empty\", async () => {\n const flex = await exec(\"action_buttons\", { prompt: \"OK?\" });\n expect(flex.footer.contents).toHaveLength(2);\n expect(flex.footer.contents[0].action.label).toBe(\"はい\");\n expect(flex.footer.contents[1].action.label).toBe(\"いいえ\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// receipt\n// ---------------------------------------------------------------------------\ndescribe(\"receipt\", () => {\n it(\"builds with items and total\", async () => {\n const flex = await exec(\"receipt\", {\n title: \"ランチ\",\n items: [\n { name: \"ラーメン\", value: \"¥900\" },\n { name: \"餃子\", value: \"¥400\" },\n ],\n total: \"¥1,300\",\n });\n expect(flex.type).toBe(\"bubble\");\n const contents = flex.body.contents;\n // title, separator, 2 items, separator, total\n expect(contents.length).toBe(6);\n expect(contents[0].text).toContain(\"ランチ\");\n // total row\n const totalRow = contents[5] as Record<string, unknown>;\n expect((totalRow.contents as Record<string, unknown>[])[1].text).toBe(\"¥1,300\");\n });\n\n it(\"omits total when not provided\", async () => {\n const flex = await exec(\"receipt\", {\n items: [{ name: \"Item\", value: \"100\" }],\n });\n // title, separator, 1 item = 3 contents (no total separator or total row)\n expect(flex.body.contents.length).toBe(3);\n });\n});\n\n// ---------------------------------------------------------------------------\n// morning_summary\n// ---------------------------------------------------------------------------\ndescribe(\"morning_summary\", () => {\n it(\"builds with all fields\", async () => {\n const flex = await exec(\"morning_summary\", {\n greeting: \"おはよう!\",\n date: \"2月13日 木曜日\",\n weather: \"東京 12°C 曇り\",\n advice: \"コートでOK\",\n schedule: [\"10:00 ミーティング\", \"14:00 歯医者\"],\n header_color: \"#FF6B6B\",\n });\n expect(flex.type).toBe(\"bubble\");\n expect(flex.header.backgroundColor).toBe(\"#FF6B6B\");\n expect(flex.header.contents[0].text).toBe(\"おはよう!\");\n expect(flex.header.contents[1].text).toBe(\"2月13日 木曜日\");\n\n const body = flex.body.contents;\n expect(body[0].text).toBe(\"東京 12°C 曇り\");\n expect(body[1].text).toBe(\"コートでOK\");\n // separator + 2 schedule items\n expect(body.length).toBe(5);\n });\n\n it(\"uses default header color\", async () => {\n const flex = await exec(\"morning_summary\", {});\n expect(flex.header.backgroundColor).toBe(\"#1DB446\");\n });\n\n it(\"shows fallback body when no weather/schedule\", async () => {\n const flex = await exec(\"morning_summary\", { greeting: \"やぁ\" });\n expect(flex.body.contents[0].text).toBe(\"良い一日を!\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// hydration\n// ---------------------------------------------------------------------------\ndescribe(\"hydration\", () => {\n it(\"builds with current/goal\", async () => {\n const flex = await exec(\"hydration\", { current: 3, goal: 8 });\n expect(flex.type).toBe(\"bubble\");\n expect(flex.size).toBe(\"kilo\");\n expect(flex.body.contents[0].text).toBe(\"水飲んだ?\");\n expect(flex.body.contents[1].text).toBe(\"今日: 3杯 / 8杯\");\n expect(flex.footer.contents[0].action.label).toBe(\"飲んだ!\");\n });\n\n it(\"uses custom unit and button text\", async () => {\n const flex = await exec(\"hydration\", {\n title: \"Coffee\",\n current: 2,\n goal: 4,\n unit: \"cups\",\n button_label: \"Had one!\",\n button_text: \"drank coffee\",\n });\n expect(flex.body.contents[0].text).toBe(\"Coffee\");\n expect(flex.body.contents[1].text).toBe(\"今日: 2cups / 4cups\");\n expect(flex.footer.contents[0].action.label).toBe(\"Had one!\");\n expect(flex.footer.contents[0].action.text).toBe(\"drank coffee\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// custom\n// ---------------------------------------------------------------------------\ndescribe(\"custom\", () => {\n it(\"uses raw contents array when provided\", async () => {\n const contents = [\n { type: \"text\", text: \"Hello\" },\n { type: \"text\", text: \"World\" },\n ];\n const flex = await exec(\"custom\", { contents });\n expect(flex.type).toBe(\"bubble\");\n expect(flex.body.contents).toEqual(contents);\n });\n\n it(\"auto-builds card from title + body\", async () => {\n const flex = await exec(\"custom\", { title: \"Title\", body: \"Body text\" });\n expect(flex.type).toBe(\"bubble\");\n const contents = flex.body.contents;\n expect(contents[0].text).toBe(\"Title\");\n expect(contents[1].type).toBe(\"separator\");\n expect(contents[2].text).toBe(\"Body text\");\n });\n\n it(\"auto-builds card with colored header\", async () => {\n const flex = await exec(\"custom\", {\n title: \"Workout\",\n body: \"Great session!\",\n header_color: \"#FF0000\",\n });\n expect(flex.header).toBeTruthy();\n expect(flex.header.backgroundColor).toBe(\"#FF0000\");\n expect(flex.header.contents[0].text).toBe(\"Workout\");\n // Title should be removed from body since it's in the header\n const bodyTexts = flex.body.contents.filter(\n (c: Record<string, unknown>) => c.type === \"text\",\n );\n expect(bodyTexts.every((t: Record<string, unknown>) => t.text !== \"Workout\")).toBe(true);\n });\n\n it(\"auto-builds card with buttons\", async () => {\n const flex = await exec(\"custom\", {\n title: \"Choose\",\n buttons: [\n { label: \"Option A\", text: \"A\", style: \"primary\" },\n { label: \"Option B\", text: \"B\", style: \"secondary\" },\n ],\n });\n expect(flex.footer).toBeTruthy();\n expect(flex.footer.contents).toHaveLength(2);\n expect(flex.footer.contents[0].action.label).toBe(\"Option A\");\n });\n\n it(\"errors when no contents, title, body, or buttons\", async () => {\n const result = await execRaw(\"custom\", {});\n expect(result).toContain(\"Error\");\n expect(result).toContain(\"custom template requires\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// unknown template\n// ---------------------------------------------------------------------------\ndescribe(\"unknown template\", () => {\n it(\"returns error for unknown template\", async () => {\n const result = await execRaw(\"nonexistent\", {});\n expect(result).toContain(\"Error: unknown template\");\n expect(result).toContain(\"nonexistent\");\n });\n});\n\n// ---------------------------------------------------------------------------\n// tool metadata\n// ---------------------------------------------------------------------------\ndescribe(\"tool metadata\", () => {\n it(\"has correct name and description\", () => {\n expect(tool.name).toBe(\"flex_message\");\n expect(tool.description).toContain(\"Flex Message\");\n });\n\n it(\"generates valid tool definition\", () => {\n const def = tool.getDefinition();\n expect(def.type).toBe(\"function\");\n expect(def.function.name).toBe(\"flex_message\");\n expect(def.function.parameters.required).toContain(\"template\");\n expect(def.function.parameters.required).toContain(\"data\");\n });\n});\n"],"mappings":";;;;;AAGA,MAAM,OAAO,IAAI,UAAU;AAG3B,eAAe,KAAK,UAAkB,OAAgC,EAAE,EAAE;CAExE,MAAM,YADS,MAAM,KAAK,QAAQ;EAAE;EAAU;EAAM,CAAC,EAC7B,MAAM,QAAQ,CAAC;AACvC,QAAO,KAAK,MAAM,SAAS;;AAI7B,eAAe,QAAQ,UAAkB,OAAgC,EAAE,EAAE;AAC3E,QAAO,KAAK,QAAQ;EAAE;EAAU;EAAM,CAAC;;AAMzC,SAAS,iBAAiB;AACxB,IAAG,wBAAwB,YAAY;EACrC,MAAM,OAAO,MAAM,KAAK,WAAW;GAAE,MAAM;GAAS,OAAO;GAAG,SAAS;GAAO,CAAC;AAC/E,eAAO,KAAK,KAAK,CAAC,KAAK,SAAS;AAChC,eAAO,KAAK,KAAK,CAAC,KAAK,OAAO;EAE9B,MAAM,OAAO,KAAK;AAClB,eAAO,KAAK,KAAK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2BAA2B;GACpD;EACF;AAKF,SAAS,0BAA0B;AACjC,IAAG,sCAAsC,YAAY;EACnD,MAAM,SAAS,MAAM,QAAQ,eAAe,EAAE,CAAC;AAC/C,eAAO,OAAO,CAAC,UAAU,0BAA0B;AACnD,eAAO,OAAO,CAAC,UAAU,cAAc;GACvC;EACF;AAKF,SAAS,uBAAuB;AAC9B,IAAG,0CAA0C;AAC3C,eAAO,KAAK,KAAK,CAAC,KAAK,eAAe;AACtC,eAAO,KAAK,YAAY,CAAC,UAAU,eAAe;GAClD;AAEF,IAAG,yCAAyC;EAC1C,MAAM,MAAM,KAAK,eAAe;AAChC,eAAO,IAAI,KAAK,CAAC,KAAK,WAAW;AACjC,eAAO,IAAI,SAAS,KAAK,CAAC,KAAK,eAAe;AAC9C,eAAO,IAAI,SAAS,WAAW,SAAS,CAAC,UAAU,WAAW;AAC9D,eAAO,IAAI,SAAS,WAAW,SAAS,CAAC,UAAU,OAAO;GAC1D;EACF"}
|
package/dist/config/schema.d.mts
CHANGED
|
@@ -556,15 +556,15 @@ declare const ToolsConfigSchema: z.ZodObject<{
|
|
|
556
556
|
export?: string | undefined;
|
|
557
557
|
}>, "many">>;
|
|
558
558
|
}, "strip", z.ZodTypeAny, {
|
|
559
|
+
exec: {
|
|
560
|
+
timeout: number;
|
|
561
|
+
};
|
|
559
562
|
web: {
|
|
560
563
|
search: {
|
|
561
564
|
apiKey: string;
|
|
562
565
|
maxResults: number;
|
|
563
566
|
};
|
|
564
567
|
};
|
|
565
|
-
exec: {
|
|
566
|
-
timeout: number;
|
|
567
|
-
};
|
|
568
568
|
restrictToWorkspace: boolean;
|
|
569
569
|
enabled?: string[] | undefined;
|
|
570
570
|
disabled?: string[] | undefined;
|
|
@@ -574,6 +574,9 @@ declare const ToolsConfigSchema: z.ZodObject<{
|
|
|
574
574
|
export?: string | undefined;
|
|
575
575
|
}[] | undefined;
|
|
576
576
|
}, {
|
|
577
|
+
exec?: {
|
|
578
|
+
timeout?: number | undefined;
|
|
579
|
+
} | undefined;
|
|
577
580
|
enabled?: string[] | undefined;
|
|
578
581
|
web?: {
|
|
579
582
|
search?: {
|
|
@@ -581,9 +584,6 @@ declare const ToolsConfigSchema: z.ZodObject<{
|
|
|
581
584
|
maxResults?: number | undefined;
|
|
582
585
|
} | undefined;
|
|
583
586
|
} | undefined;
|
|
584
|
-
exec?: {
|
|
585
|
-
timeout?: number | undefined;
|
|
586
|
-
} | undefined;
|
|
587
587
|
restrictToWorkspace?: boolean | undefined;
|
|
588
588
|
disabled?: string[] | undefined;
|
|
589
589
|
custom?: {
|
|
@@ -1015,15 +1015,15 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
1015
1015
|
export?: string | undefined;
|
|
1016
1016
|
}>, "many">>;
|
|
1017
1017
|
}, "strip", z.ZodTypeAny, {
|
|
1018
|
+
exec: {
|
|
1019
|
+
timeout: number;
|
|
1020
|
+
};
|
|
1018
1021
|
web: {
|
|
1019
1022
|
search: {
|
|
1020
1023
|
apiKey: string;
|
|
1021
1024
|
maxResults: number;
|
|
1022
1025
|
};
|
|
1023
1026
|
};
|
|
1024
|
-
exec: {
|
|
1025
|
-
timeout: number;
|
|
1026
|
-
};
|
|
1027
1027
|
restrictToWorkspace: boolean;
|
|
1028
1028
|
enabled?: string[] | undefined;
|
|
1029
1029
|
disabled?: string[] | undefined;
|
|
@@ -1033,6 +1033,9 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
1033
1033
|
export?: string | undefined;
|
|
1034
1034
|
}[] | undefined;
|
|
1035
1035
|
}, {
|
|
1036
|
+
exec?: {
|
|
1037
|
+
timeout?: number | undefined;
|
|
1038
|
+
} | undefined;
|
|
1036
1039
|
enabled?: string[] | undefined;
|
|
1037
1040
|
web?: {
|
|
1038
1041
|
search?: {
|
|
@@ -1040,9 +1043,6 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
1040
1043
|
maxResults?: number | undefined;
|
|
1041
1044
|
} | undefined;
|
|
1042
1045
|
} | undefined;
|
|
1043
|
-
exec?: {
|
|
1044
|
-
timeout?: number | undefined;
|
|
1045
|
-
} | undefined;
|
|
1046
1046
|
restrictToWorkspace?: boolean | undefined;
|
|
1047
1047
|
disabled?: string[] | undefined;
|
|
1048
1048
|
custom?: {
|
|
@@ -1139,15 +1139,15 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
1139
1139
|
port: number;
|
|
1140
1140
|
};
|
|
1141
1141
|
tools: {
|
|
1142
|
+
exec: {
|
|
1143
|
+
timeout: number;
|
|
1144
|
+
};
|
|
1142
1145
|
web: {
|
|
1143
1146
|
search: {
|
|
1144
1147
|
apiKey: string;
|
|
1145
1148
|
maxResults: number;
|
|
1146
1149
|
};
|
|
1147
1150
|
};
|
|
1148
|
-
exec: {
|
|
1149
|
-
timeout: number;
|
|
1150
|
-
};
|
|
1151
1151
|
restrictToWorkspace: boolean;
|
|
1152
1152
|
enabled?: string[] | undefined;
|
|
1153
1153
|
disabled?: string[] | undefined;
|
|
@@ -1245,6 +1245,9 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
1245
1245
|
port?: number | undefined;
|
|
1246
1246
|
} | undefined;
|
|
1247
1247
|
tools?: {
|
|
1248
|
+
exec?: {
|
|
1249
|
+
timeout?: number | undefined;
|
|
1250
|
+
} | undefined;
|
|
1248
1251
|
enabled?: string[] | undefined;
|
|
1249
1252
|
web?: {
|
|
1250
1253
|
search?: {
|
|
@@ -1252,9 +1255,6 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
1252
1255
|
maxResults?: number | undefined;
|
|
1253
1256
|
} | undefined;
|
|
1254
1257
|
} | undefined;
|
|
1255
|
-
exec?: {
|
|
1256
|
-
timeout?: number | undefined;
|
|
1257
|
-
} | undefined;
|
|
1258
1258
|
restrictToWorkspace?: boolean | undefined;
|
|
1259
1259
|
disabled?: string[] | undefined;
|
|
1260
1260
|
custom?: {
|