@dexto/tools-lifecycle 1.6.0

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.
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var search_history_tool_exports = {};
20
+ __export(search_history_tool_exports, {
21
+ createSearchHistoryTool: () => createSearchHistoryTool
22
+ });
23
+ module.exports = __toCommonJS(search_history_tool_exports);
24
+ var import_zod = require("zod");
25
+ var import_core = require("@dexto/core");
26
+ const SearchHistoryInputSchema = import_zod.z.object({
27
+ query: import_zod.z.string().describe("The search query to find in conversation history"),
28
+ mode: import_zod.z.enum(["messages", "sessions"]).describe(
29
+ 'Search mode: "messages" searches for individual messages, "sessions" finds sessions containing the query'
30
+ ),
31
+ sessionId: import_zod.z.string().optional().describe('Optional: limit search to a specific session (only for mode="messages")'),
32
+ role: import_zod.z.enum(["user", "assistant", "system", "tool"]).optional().describe('Optional: filter by message role (only for mode="messages")'),
33
+ limit: import_zod.z.number().optional().default(20).describe(
34
+ 'Optional: maximum number of results to return (default: 20, only for mode="messages")'
35
+ ),
36
+ offset: import_zod.z.number().optional().default(0).describe('Optional: offset for pagination (default: 0, only for mode="messages")')
37
+ }).strict();
38
+ function createSearchHistoryTool() {
39
+ return (0, import_core.defineTool)({
40
+ id: "search_history",
41
+ displayName: "Search History",
42
+ description: 'Search through conversation history across sessions. Use mode="messages" to search for specific messages, or mode="sessions" to find sessions containing the query. For message search, you can filter by sessionId (specific session), role (user/assistant/system/tool), limit results, and set pagination offset.',
43
+ inputSchema: SearchHistoryInputSchema,
44
+ async execute(input, context) {
45
+ const { query, mode, sessionId, role, limit, offset } = input;
46
+ const searchService = context.services?.search;
47
+ if (!searchService) {
48
+ throw import_core.ToolError.configInvalid(
49
+ "search_history requires ToolExecutionContext.services.search"
50
+ );
51
+ }
52
+ if (mode === "messages") {
53
+ const searchOptions = {
54
+ limit,
55
+ offset,
56
+ ...sessionId !== void 0 && { sessionId },
57
+ ...role !== void 0 && { role }
58
+ };
59
+ return await searchService.searchMessages(query, searchOptions);
60
+ }
61
+ return await searchService.searchSessions(query);
62
+ }
63
+ });
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ createSearchHistoryTool
68
+ });
@@ -0,0 +1,34 @@
1
+ import { z } from 'zod';
2
+ import { Tool } from '@dexto/core';
3
+
4
+ declare const SearchHistoryInputSchema: z.ZodObject<{
5
+ query: z.ZodString;
6
+ mode: z.ZodEnum<["messages", "sessions"]>;
7
+ sessionId: z.ZodOptional<z.ZodString>;
8
+ role: z.ZodOptional<z.ZodEnum<["user", "assistant", "system", "tool"]>>;
9
+ limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
10
+ offset: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
11
+ }, "strict", z.ZodTypeAny, {
12
+ query: string;
13
+ limit: number;
14
+ offset: number;
15
+ mode: "messages" | "sessions";
16
+ sessionId?: string | undefined;
17
+ role?: "user" | "system" | "assistant" | "tool" | undefined;
18
+ }, {
19
+ query: string;
20
+ mode: "messages" | "sessions";
21
+ sessionId?: string | undefined;
22
+ limit?: number | undefined;
23
+ offset?: number | undefined;
24
+ role?: "user" | "system" | "assistant" | "tool" | undefined;
25
+ }>;
26
+ /**
27
+ * Create the `search_history` tool.
28
+ *
29
+ * Searches message/session history using the configured SearchService.
30
+ * Requires `ToolExecutionContext.services.search`.
31
+ */
32
+ declare function createSearchHistoryTool(): Tool<typeof SearchHistoryInputSchema>;
33
+
34
+ export { createSearchHistoryTool };
@@ -0,0 +1,34 @@
1
+ import { z } from 'zod';
2
+ import { Tool } from '@dexto/core';
3
+
4
+ declare const SearchHistoryInputSchema: z.ZodObject<{
5
+ query: z.ZodString;
6
+ mode: z.ZodEnum<["messages", "sessions"]>;
7
+ sessionId: z.ZodOptional<z.ZodString>;
8
+ role: z.ZodOptional<z.ZodEnum<["user", "assistant", "system", "tool"]>>;
9
+ limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
10
+ offset: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
11
+ }, "strict", z.ZodTypeAny, {
12
+ query: string;
13
+ limit: number;
14
+ offset: number;
15
+ mode: "messages" | "sessions";
16
+ sessionId?: string | undefined;
17
+ role?: "user" | "system" | "assistant" | "tool" | undefined;
18
+ }, {
19
+ query: string;
20
+ mode: "messages" | "sessions";
21
+ sessionId?: string | undefined;
22
+ limit?: number | undefined;
23
+ offset?: number | undefined;
24
+ role?: "user" | "system" | "assistant" | "tool" | undefined;
25
+ }>;
26
+ /**
27
+ * Create the `search_history` tool.
28
+ *
29
+ * Searches message/session history using the configured SearchService.
30
+ * Requires `ToolExecutionContext.services.search`.
31
+ */
32
+ declare function createSearchHistoryTool(): Tool<typeof SearchHistoryInputSchema>;
33
+
34
+ export { createSearchHistoryTool };
@@ -0,0 +1,44 @@
1
+ import { z } from "zod";
2
+ import { ToolError, defineTool } from "@dexto/core";
3
+ const SearchHistoryInputSchema = z.object({
4
+ query: z.string().describe("The search query to find in conversation history"),
5
+ mode: z.enum(["messages", "sessions"]).describe(
6
+ 'Search mode: "messages" searches for individual messages, "sessions" finds sessions containing the query'
7
+ ),
8
+ sessionId: z.string().optional().describe('Optional: limit search to a specific session (only for mode="messages")'),
9
+ role: z.enum(["user", "assistant", "system", "tool"]).optional().describe('Optional: filter by message role (only for mode="messages")'),
10
+ limit: z.number().optional().default(20).describe(
11
+ 'Optional: maximum number of results to return (default: 20, only for mode="messages")'
12
+ ),
13
+ offset: z.number().optional().default(0).describe('Optional: offset for pagination (default: 0, only for mode="messages")')
14
+ }).strict();
15
+ function createSearchHistoryTool() {
16
+ return defineTool({
17
+ id: "search_history",
18
+ displayName: "Search History",
19
+ description: 'Search through conversation history across sessions. Use mode="messages" to search for specific messages, or mode="sessions" to find sessions containing the query. For message search, you can filter by sessionId (specific session), role (user/assistant/system/tool), limit results, and set pagination offset.',
20
+ inputSchema: SearchHistoryInputSchema,
21
+ async execute(input, context) {
22
+ const { query, mode, sessionId, role, limit, offset } = input;
23
+ const searchService = context.services?.search;
24
+ if (!searchService) {
25
+ throw ToolError.configInvalid(
26
+ "search_history requires ToolExecutionContext.services.search"
27
+ );
28
+ }
29
+ if (mode === "messages") {
30
+ const searchOptions = {
31
+ limit,
32
+ offset,
33
+ ...sessionId !== void 0 && { sessionId },
34
+ ...role !== void 0 && { role }
35
+ };
36
+ return await searchService.searchMessages(query, searchOptions);
37
+ }
38
+ return await searchService.searchSessions(query);
39
+ }
40
+ });
41
+ }
42
+ export {
43
+ createSearchHistoryTool
44
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var tool_factory_config_exports = {};
20
+ __export(tool_factory_config_exports, {
21
+ LIFECYCLE_TOOL_NAMES: () => LIFECYCLE_TOOL_NAMES,
22
+ LifecycleToolsConfigSchema: () => LifecycleToolsConfigSchema
23
+ });
24
+ module.exports = __toCommonJS(tool_factory_config_exports);
25
+ var import_zod = require("zod");
26
+ const DEFAULT_MAX_LOG_LINES = 200;
27
+ const DEFAULT_MAX_LOG_BYTES = 2e5;
28
+ const LIFECYCLE_TOOL_NAMES = [
29
+ "view_logs",
30
+ "search_history",
31
+ "memory_list",
32
+ "memory_get",
33
+ "memory_create",
34
+ "memory_update",
35
+ "memory_delete"
36
+ ];
37
+ const LifecycleToolsConfigSchema = import_zod.z.object({
38
+ type: import_zod.z.literal("lifecycle-tools"),
39
+ enabledTools: import_zod.z.array(import_zod.z.enum(LIFECYCLE_TOOL_NAMES)).optional().describe(
40
+ `Subset of tools to enable. If not specified, all tools are enabled. Available: ${LIFECYCLE_TOOL_NAMES.join(", ")}`
41
+ ),
42
+ maxLogLines: import_zod.z.number().int().positive().default(DEFAULT_MAX_LOG_LINES).describe(
43
+ `Maximum number of log lines view_logs may return (default: ${DEFAULT_MAX_LOG_LINES})`
44
+ ),
45
+ maxLogBytes: import_zod.z.number().int().positive().default(DEFAULT_MAX_LOG_BYTES).describe(
46
+ `Maximum bytes read from the end of the log file (default: ${DEFAULT_MAX_LOG_BYTES})`
47
+ )
48
+ }).strict();
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ LIFECYCLE_TOOL_NAMES,
52
+ LifecycleToolsConfigSchema
53
+ });
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const LIFECYCLE_TOOL_NAMES: readonly ["view_logs", "search_history", "memory_list", "memory_get", "memory_create", "memory_update", "memory_delete"];
4
+ type LifecycleToolName = (typeof LIFECYCLE_TOOL_NAMES)[number];
5
+ declare const LifecycleToolsConfigSchema: z.ZodObject<{
6
+ type: z.ZodLiteral<"lifecycle-tools">;
7
+ enabledTools: z.ZodOptional<z.ZodArray<z.ZodEnum<["view_logs", "search_history", "memory_list", "memory_get", "memory_create", "memory_update", "memory_delete"]>, "many">>;
8
+ maxLogLines: z.ZodDefault<z.ZodNumber>;
9
+ maxLogBytes: z.ZodDefault<z.ZodNumber>;
10
+ }, "strict", z.ZodTypeAny, {
11
+ type: "lifecycle-tools";
12
+ maxLogLines: number;
13
+ maxLogBytes: number;
14
+ enabledTools?: ("view_logs" | "search_history" | "memory_list" | "memory_get" | "memory_create" | "memory_update" | "memory_delete")[] | undefined;
15
+ }, {
16
+ type: "lifecycle-tools";
17
+ enabledTools?: ("view_logs" | "search_history" | "memory_list" | "memory_get" | "memory_create" | "memory_update" | "memory_delete")[] | undefined;
18
+ maxLogLines?: number | undefined;
19
+ maxLogBytes?: number | undefined;
20
+ }>;
21
+ type LifecycleToolsConfig = z.output<typeof LifecycleToolsConfigSchema>;
22
+
23
+ export { LIFECYCLE_TOOL_NAMES, type LifecycleToolName, type LifecycleToolsConfig, LifecycleToolsConfigSchema };
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const LIFECYCLE_TOOL_NAMES: readonly ["view_logs", "search_history", "memory_list", "memory_get", "memory_create", "memory_update", "memory_delete"];
4
+ type LifecycleToolName = (typeof LIFECYCLE_TOOL_NAMES)[number];
5
+ declare const LifecycleToolsConfigSchema: z.ZodObject<{
6
+ type: z.ZodLiteral<"lifecycle-tools">;
7
+ enabledTools: z.ZodOptional<z.ZodArray<z.ZodEnum<["view_logs", "search_history", "memory_list", "memory_get", "memory_create", "memory_update", "memory_delete"]>, "many">>;
8
+ maxLogLines: z.ZodDefault<z.ZodNumber>;
9
+ maxLogBytes: z.ZodDefault<z.ZodNumber>;
10
+ }, "strict", z.ZodTypeAny, {
11
+ type: "lifecycle-tools";
12
+ maxLogLines: number;
13
+ maxLogBytes: number;
14
+ enabledTools?: ("view_logs" | "search_history" | "memory_list" | "memory_get" | "memory_create" | "memory_update" | "memory_delete")[] | undefined;
15
+ }, {
16
+ type: "lifecycle-tools";
17
+ enabledTools?: ("view_logs" | "search_history" | "memory_list" | "memory_get" | "memory_create" | "memory_update" | "memory_delete")[] | undefined;
18
+ maxLogLines?: number | undefined;
19
+ maxLogBytes?: number | undefined;
20
+ }>;
21
+ type LifecycleToolsConfig = z.output<typeof LifecycleToolsConfigSchema>;
22
+
23
+ export { LIFECYCLE_TOOL_NAMES, type LifecycleToolName, type LifecycleToolsConfig, LifecycleToolsConfigSchema };
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+ const DEFAULT_MAX_LOG_LINES = 200;
3
+ const DEFAULT_MAX_LOG_BYTES = 2e5;
4
+ const LIFECYCLE_TOOL_NAMES = [
5
+ "view_logs",
6
+ "search_history",
7
+ "memory_list",
8
+ "memory_get",
9
+ "memory_create",
10
+ "memory_update",
11
+ "memory_delete"
12
+ ];
13
+ const LifecycleToolsConfigSchema = z.object({
14
+ type: z.literal("lifecycle-tools"),
15
+ enabledTools: z.array(z.enum(LIFECYCLE_TOOL_NAMES)).optional().describe(
16
+ `Subset of tools to enable. If not specified, all tools are enabled. Available: ${LIFECYCLE_TOOL_NAMES.join(", ")}`
17
+ ),
18
+ maxLogLines: z.number().int().positive().default(DEFAULT_MAX_LOG_LINES).describe(
19
+ `Maximum number of log lines view_logs may return (default: ${DEFAULT_MAX_LOG_LINES})`
20
+ ),
21
+ maxLogBytes: z.number().int().positive().default(DEFAULT_MAX_LOG_BYTES).describe(
22
+ `Maximum bytes read from the end of the log file (default: ${DEFAULT_MAX_LOG_BYTES})`
23
+ )
24
+ }).strict();
25
+ export {
26
+ LIFECYCLE_TOOL_NAMES,
27
+ LifecycleToolsConfigSchema
28
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var tool_factory_exports = {};
20
+ __export(tool_factory_exports, {
21
+ lifecycleToolsFactory: () => lifecycleToolsFactory
22
+ });
23
+ module.exports = __toCommonJS(tool_factory_exports);
24
+ var import_tool_factory_config = require("./tool-factory-config.js");
25
+ var import_view_logs_tool = require("./view-logs-tool.js");
26
+ var import_memory_tools = require("./memory-tools.js");
27
+ var import_search_history_tool = require("./search-history-tool.js");
28
+ const lifecycleToolsFactory = {
29
+ configSchema: import_tool_factory_config.LifecycleToolsConfigSchema,
30
+ metadata: {
31
+ displayName: "Lifecycle Tools",
32
+ description: "Self-observation tools (logs, memories)",
33
+ category: "lifecycle"
34
+ },
35
+ create: (config) => {
36
+ const toolCreators = {
37
+ view_logs: () => (0, import_view_logs_tool.createViewLogsTool)({
38
+ maxLogLines: config.maxLogLines,
39
+ maxLogBytes: config.maxLogBytes
40
+ }),
41
+ search_history: () => (0, import_search_history_tool.createSearchHistoryTool)(),
42
+ memory_list: () => (0, import_memory_tools.createMemoryListTool)(),
43
+ memory_get: () => (0, import_memory_tools.createMemoryGetTool)(),
44
+ memory_create: () => (0, import_memory_tools.createMemoryCreateTool)(),
45
+ memory_update: () => (0, import_memory_tools.createMemoryUpdateTool)(),
46
+ memory_delete: () => (0, import_memory_tools.createMemoryDeleteTool)()
47
+ };
48
+ const toolsToCreate = config.enabledTools ?? import_tool_factory_config.LIFECYCLE_TOOL_NAMES;
49
+ return toolsToCreate.map((toolName) => toolCreators[toolName]());
50
+ }
51
+ };
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ lifecycleToolsFactory
55
+ });
@@ -0,0 +1,7 @@
1
+ import { ToolFactory } from '@dexto/agent-config';
2
+ import { LifecycleToolsConfig } from './tool-factory-config.cjs';
3
+ import 'zod';
4
+
5
+ declare const lifecycleToolsFactory: ToolFactory<LifecycleToolsConfig>;
6
+
7
+ export { lifecycleToolsFactory };
@@ -0,0 +1,7 @@
1
+ import { ToolFactory } from '@dexto/agent-config';
2
+ import { LifecycleToolsConfig } from './tool-factory-config.js';
3
+ import 'zod';
4
+
5
+ declare const lifecycleToolsFactory: ToolFactory<LifecycleToolsConfig>;
6
+
7
+ export { lifecycleToolsFactory };
@@ -0,0 +1,40 @@
1
+ import {
2
+ LifecycleToolsConfigSchema,
3
+ LIFECYCLE_TOOL_NAMES
4
+ } from "./tool-factory-config.js";
5
+ import { createViewLogsTool } from "./view-logs-tool.js";
6
+ import {
7
+ createMemoryListTool,
8
+ createMemoryGetTool,
9
+ createMemoryCreateTool,
10
+ createMemoryUpdateTool,
11
+ createMemoryDeleteTool
12
+ } from "./memory-tools.js";
13
+ import { createSearchHistoryTool } from "./search-history-tool.js";
14
+ const lifecycleToolsFactory = {
15
+ configSchema: LifecycleToolsConfigSchema,
16
+ metadata: {
17
+ displayName: "Lifecycle Tools",
18
+ description: "Self-observation tools (logs, memories)",
19
+ category: "lifecycle"
20
+ },
21
+ create: (config) => {
22
+ const toolCreators = {
23
+ view_logs: () => createViewLogsTool({
24
+ maxLogLines: config.maxLogLines,
25
+ maxLogBytes: config.maxLogBytes
26
+ }),
27
+ search_history: () => createSearchHistoryTool(),
28
+ memory_list: () => createMemoryListTool(),
29
+ memory_get: () => createMemoryGetTool(),
30
+ memory_create: () => createMemoryCreateTool(),
31
+ memory_update: () => createMemoryUpdateTool(),
32
+ memory_delete: () => createMemoryDeleteTool()
33
+ };
34
+ const toolsToCreate = config.enabledTools ?? LIFECYCLE_TOOL_NAMES;
35
+ return toolsToCreate.map((toolName) => toolCreators[toolName]());
36
+ }
37
+ };
38
+ export {
39
+ lifecycleToolsFactory
40
+ };
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var view_logs_tool_exports = {};
30
+ __export(view_logs_tool_exports, {
31
+ createViewLogsTool: () => createViewLogsTool
32
+ });
33
+ module.exports = __toCommonJS(view_logs_tool_exports);
34
+ var fs = __toESM(require("node:fs/promises"), 1);
35
+ var import_zod = require("zod");
36
+ var import_core = require("@dexto/core");
37
+ const LOG_LEVEL_VALUES = ["debug", "info", "warn", "error", "silly"];
38
+ const ViewLogsInputSchema = import_zod.z.object({
39
+ lines: import_zod.z.number().int().positive().optional().default(200).describe("Number of log lines to return from the end of the log file"),
40
+ query: import_zod.z.string().optional().describe("Optional: filter logs by substring match (case-insensitive)"),
41
+ level: import_zod.z.union([import_zod.z.enum(LOG_LEVEL_VALUES), import_zod.z.array(import_zod.z.enum(LOG_LEVEL_VALUES))]).optional().describe("Optional: filter logs by level"),
42
+ component: import_zod.z.string().optional().describe("Optional: filter logs by component"),
43
+ includeContext: import_zod.z.boolean().optional().default(false).describe("Whether to include structured context for JSON log entries")
44
+ }).strict();
45
+ function isPlainObject(value) {
46
+ return typeof value === "object" && value !== null && !Array.isArray(value);
47
+ }
48
+ function tryParseLogEntry(line) {
49
+ try {
50
+ const parsed = JSON.parse(line);
51
+ if (!isPlainObject(parsed)) {
52
+ return null;
53
+ }
54
+ const level = parsed.level;
55
+ const message = parsed.message;
56
+ const timestamp = parsed.timestamp;
57
+ const component = parsed.component;
58
+ if (typeof level !== "string" || !LOG_LEVEL_VALUES.includes(level) || typeof message !== "string" || typeof timestamp !== "string" || typeof component !== "string") {
59
+ return null;
60
+ }
61
+ const agentId = parsed.agentId;
62
+ const sessionId = parsed.sessionId;
63
+ const toolCallId = parsed.toolCallId;
64
+ const context = parsed.context;
65
+ return {
66
+ level,
67
+ message,
68
+ timestamp,
69
+ component,
70
+ ...typeof agentId === "string" && { agentId },
71
+ ...typeof sessionId === "string" && { sessionId },
72
+ ...typeof toolCallId === "string" && { toolCallId },
73
+ ...isPlainObject(context) && { context }
74
+ };
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+ async function readTailBytes(filePath, maxBytes) {
80
+ const handle = await fs.open(filePath, "r");
81
+ try {
82
+ const stat = await handle.stat();
83
+ const start = Math.max(0, stat.size - maxBytes);
84
+ const length = stat.size - start;
85
+ const buffer = Buffer.alloc(length);
86
+ const { bytesRead } = await handle.read(buffer, 0, length, start);
87
+ return buffer.subarray(0, bytesRead).toString("utf8");
88
+ } finally {
89
+ await handle.close();
90
+ }
91
+ }
92
+ function createViewLogsTool(options) {
93
+ return (0, import_core.defineTool)({
94
+ id: "view_logs",
95
+ displayName: "View Logs",
96
+ description: "View this session log file (tail). Returns the most recent log lines for debugging. If file logging is not configured, returns a message instead.",
97
+ inputSchema: ViewLogsInputSchema,
98
+ async execute(parsed, context) {
99
+ const logFilePath = context.logger.getLogFilePath();
100
+ if (!logFilePath) {
101
+ return {
102
+ logFilePath: null,
103
+ lines: 0,
104
+ content: "",
105
+ message: "No log file is configured for this session."
106
+ };
107
+ }
108
+ const requestedLines = parsed.lines;
109
+ const maxLines = options.maxLogLines;
110
+ const linesToReturn = Math.min(requestedLines, maxLines);
111
+ const query = parsed.query?.trim();
112
+ const queryLower = query ? query.toLowerCase() : null;
113
+ const component = parsed.component?.trim();
114
+ const levelsInput = parsed.level;
115
+ const levels = typeof levelsInput === "string" ? /* @__PURE__ */ new Set([levelsInput]) : Array.isArray(levelsInput) ? new Set(levelsInput) : null;
116
+ let tailContent;
117
+ try {
118
+ tailContent = await readTailBytes(logFilePath, options.maxLogBytes);
119
+ } catch (error) {
120
+ throw import_core.ToolError.executionFailed(
121
+ "view_logs",
122
+ `Failed to read log file: ${error instanceof Error ? error.message : String(error)}`,
123
+ context.sessionId
124
+ );
125
+ }
126
+ const allLines = tailContent.split(/\r?\n/).map((l) => l.trimEnd()).filter((l) => l.trim().length > 0);
127
+ const candidates = allLines.map((line) => ({
128
+ raw: line,
129
+ entry: tryParseLogEntry(line)
130
+ }));
131
+ const filtered = candidates.filter(({ raw, entry }) => {
132
+ if (entry) {
133
+ if (levels && !levels.has(entry.level)) {
134
+ return false;
135
+ }
136
+ if (component && entry.component !== component) {
137
+ return false;
138
+ }
139
+ if (!queryLower) {
140
+ return true;
141
+ }
142
+ const contextText = entry.context ? JSON.stringify(entry.context) : "";
143
+ return entry.message.toLowerCase().includes(queryLower) || contextText.toLowerCase().includes(queryLower);
144
+ }
145
+ if (levels || component) {
146
+ return false;
147
+ }
148
+ if (!queryLower) {
149
+ return true;
150
+ }
151
+ return raw.toLowerCase().includes(queryLower);
152
+ });
153
+ const limited = filtered.slice(Math.max(0, filtered.length - linesToReturn));
154
+ const outputLines = limited.map((l) => l.raw);
155
+ const entries = limited.map(({ entry }) => entry).filter((entry) => entry !== null).map(
156
+ (entry) => parsed.includeContext ? entry : {
157
+ level: entry.level,
158
+ message: entry.message,
159
+ timestamp: entry.timestamp,
160
+ component: entry.component,
161
+ ...entry.agentId !== void 0 && { agentId: entry.agentId },
162
+ ...entry.sessionId !== void 0 && { sessionId: entry.sessionId },
163
+ ...entry.toolCallId !== void 0 && {
164
+ toolCallId: entry.toolCallId
165
+ }
166
+ }
167
+ );
168
+ return {
169
+ logFilePath,
170
+ lines: outputLines.length,
171
+ content: outputLines.join("\n"),
172
+ ...entries.length > 0 && { entries },
173
+ ...query !== void 0 && query.length > 0 && { query },
174
+ ...levelsInput !== void 0 && { level: levelsInput },
175
+ ...component !== void 0 && component.length > 0 && { component }
176
+ };
177
+ }
178
+ });
179
+ }
180
+ // Annotate the CommonJS export names for ESM import in node:
181
+ 0 && (module.exports = {
182
+ createViewLogsTool
183
+ });
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+ import { Tool } from '@dexto/core';
3
+
4
+ declare const ViewLogsInputSchema: z.ZodObject<{
5
+ lines: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
6
+ query: z.ZodOptional<z.ZodString>;
7
+ level: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["debug", "info", "warn", "error", "silly"]>, z.ZodArray<z.ZodEnum<["debug", "info", "warn", "error", "silly"]>, "many">]>>;
8
+ component: z.ZodOptional<z.ZodString>;
9
+ includeContext: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
10
+ }, "strict", z.ZodTypeAny, {
11
+ lines: number;
12
+ includeContext: boolean;
13
+ query?: string | undefined;
14
+ level?: "debug" | "info" | "warn" | "error" | "silly" | ("debug" | "info" | "warn" | "error" | "silly")[] | undefined;
15
+ component?: string | undefined;
16
+ }, {
17
+ lines?: number | undefined;
18
+ query?: string | undefined;
19
+ level?: "debug" | "info" | "warn" | "error" | "silly" | ("debug" | "info" | "warn" | "error" | "silly")[] | undefined;
20
+ component?: string | undefined;
21
+ includeContext?: boolean | undefined;
22
+ }>;
23
+ declare function createViewLogsTool(options: {
24
+ maxLogLines: number;
25
+ maxLogBytes: number;
26
+ }): Tool<typeof ViewLogsInputSchema>;
27
+
28
+ export { createViewLogsTool };