@townco/agent 0.1.37 → 0.1.39
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/acp-server/cli.d.ts +1 -3
- package/dist/acp-server/cli.js +5 -9
- package/dist/bin.js +0 -0
- package/dist/index.js +9 -3
- package/dist/runner/index.d.ts +1 -3
- package/dist/runner/index.js +14 -18
- package/dist/runner/langchain/index.js +1 -0
- package/dist/runner/langchain/model-factory.js +15 -1
- package/dist/runner/langchain/tools/subagent.js +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +10 -3
- package/package.json +6 -6
- package/dist/definition/mcp.d.ts +0 -0
- package/dist/definition/mcp.js +0 -0
- package/dist/definition/tools/todo.d.ts +0 -49
- package/dist/definition/tools/todo.js +0 -80
- package/dist/definition/tools/web_search.d.ts +0 -4
- package/dist/definition/tools/web_search.js +0 -26
- package/dist/dev-agent/index.d.ts +0 -2
- package/dist/dev-agent/index.js +0 -18
- package/dist/example.d.ts +0 -2
- package/dist/example.js +0 -19
- package/dist/utils/logger.d.ts +0 -39
- package/dist/utils/logger.js +0 -175
package/index.ts
CHANGED
|
@@ -25,8 +25,15 @@ const exampleAgent: AgentDefinition = {
|
|
|
25
25
|
mcps: [],
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
// Parse transport type from command line
|
|
29
|
-
const
|
|
28
|
+
// Parse transport type and flags from command line arguments
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
const transport = args.find((arg) => !arg.startsWith("--")) || "stdio";
|
|
31
|
+
const noSession = args.includes("--no-session");
|
|
32
|
+
|
|
33
|
+
// Set TOWN_NO_SESSION environment variable if flag is present
|
|
34
|
+
if (noSession) {
|
|
35
|
+
process.env.TOWN_NO_SESSION = "true";
|
|
36
|
+
}
|
|
30
37
|
|
|
31
38
|
// Get agent directory and name for session storage
|
|
32
39
|
const agentDir = process.cwd();
|
|
@@ -38,6 +45,6 @@ if (transport === "http") {
|
|
|
38
45
|
makeStdioTransport(exampleAgent);
|
|
39
46
|
} else {
|
|
40
47
|
console.error(`Invalid transport: ${transport}`);
|
|
41
|
-
console.error("Usage: bun run index.ts [stdio|http]");
|
|
48
|
+
console.error("Usage: bun run index.ts [stdio|http] [--no-session]");
|
|
42
49
|
process.exit(1);
|
|
43
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@townco/agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"files": [
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"@langchain/google-genai": "^1.0.3",
|
|
57
57
|
"@langchain/google-vertexai": "^1.0.3",
|
|
58
58
|
"@langchain/mcp-adapters": "^1.0.0",
|
|
59
|
-
"@townco/core": "0.0.
|
|
60
|
-
"@townco/gui-template": "0.1.
|
|
61
|
-
"@townco/tsconfig": "0.1.
|
|
62
|
-
"@townco/tui-template": "0.1.
|
|
63
|
-
"@townco/ui": "0.1.
|
|
59
|
+
"@townco/core": "0.0.12",
|
|
60
|
+
"@townco/gui-template": "0.1.31",
|
|
61
|
+
"@townco/tsconfig": "0.1.31",
|
|
62
|
+
"@townco/tui-template": "0.1.31",
|
|
63
|
+
"@townco/ui": "0.1.34",
|
|
64
64
|
"exa-js": "^2.0.0",
|
|
65
65
|
"hono": "^4.10.4",
|
|
66
66
|
"langchain": "^1.0.3",
|
package/dist/definition/mcp.d.ts
DELETED
|
File without changes
|
package/dist/definition/mcp.js
DELETED
|
File without changes
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export declare const todoItemSchema: z.ZodObject<
|
|
3
|
-
{
|
|
4
|
-
content: z.ZodString;
|
|
5
|
-
status: z.ZodEnum<{
|
|
6
|
-
pending: "pending";
|
|
7
|
-
in_progress: "in_progress";
|
|
8
|
-
completed: "completed";
|
|
9
|
-
}>;
|
|
10
|
-
activeForm: z.ZodString;
|
|
11
|
-
},
|
|
12
|
-
z.core.$strip
|
|
13
|
-
>;
|
|
14
|
-
export declare const todoWrite: import("langchain").DynamicStructuredTool<
|
|
15
|
-
z.ZodObject<
|
|
16
|
-
{
|
|
17
|
-
todos: z.ZodArray<
|
|
18
|
-
z.ZodObject<
|
|
19
|
-
{
|
|
20
|
-
content: z.ZodString;
|
|
21
|
-
status: z.ZodEnum<{
|
|
22
|
-
pending: "pending";
|
|
23
|
-
in_progress: "in_progress";
|
|
24
|
-
completed: "completed";
|
|
25
|
-
}>;
|
|
26
|
-
activeForm: z.ZodString;
|
|
27
|
-
},
|
|
28
|
-
z.core.$strip
|
|
29
|
-
>
|
|
30
|
-
>;
|
|
31
|
-
},
|
|
32
|
-
z.core.$strip
|
|
33
|
-
>,
|
|
34
|
-
{
|
|
35
|
-
todos: {
|
|
36
|
-
content: string;
|
|
37
|
-
status: "pending" | "in_progress" | "completed";
|
|
38
|
-
activeForm: string;
|
|
39
|
-
}[];
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
todos: {
|
|
43
|
-
content: string;
|
|
44
|
-
status: "pending" | "in_progress" | "completed";
|
|
45
|
-
activeForm: string;
|
|
46
|
-
}[];
|
|
47
|
-
},
|
|
48
|
-
string
|
|
49
|
-
>;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { tool } from "langchain";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
export const todoItemSchema = z.object({
|
|
4
|
-
content: z.string().min(1),
|
|
5
|
-
status: z.enum(["pending", "in_progress", "completed"]),
|
|
6
|
-
activeForm: z.string().min(1),
|
|
7
|
-
});
|
|
8
|
-
export const todoWrite = tool(
|
|
9
|
-
({ todos }) => {
|
|
10
|
-
// Simple implementation that confirms the todos were written
|
|
11
|
-
return `Successfully updated todo list with ${todos.length} items`;
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
name: "todo_write",
|
|
15
|
-
description: `Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
|
|
16
|
-
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
17
|
-
|
|
18
|
-
## When to Use This Tool
|
|
19
|
-
Use this tool proactively in these scenarios:
|
|
20
|
-
|
|
21
|
-
1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
|
|
22
|
-
2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
|
|
23
|
-
3. User explicitly requests todo list - When the user directly asks you to use the todo list
|
|
24
|
-
4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
|
|
25
|
-
5. After receiving new instructions - Immediately capture user requirements as todos
|
|
26
|
-
6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
|
|
27
|
-
7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
|
|
28
|
-
|
|
29
|
-
## When NOT to Use This Tool
|
|
30
|
-
|
|
31
|
-
Skip using this tool when:
|
|
32
|
-
1. There is only a single, straightforward task
|
|
33
|
-
2. The task is trivial and tracking it provides no organizational benefit
|
|
34
|
-
3. The task can be completed in less than 3 trivial steps
|
|
35
|
-
4. The task is purely conversational or informational
|
|
36
|
-
|
|
37
|
-
NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
|
|
38
|
-
|
|
39
|
-
## Task States and Management
|
|
40
|
-
|
|
41
|
-
1. **Task States**: Use these states to track progress:
|
|
42
|
-
- pending: Task not yet started
|
|
43
|
-
- in_progress: Currently working on (limit to ONE task at a time)
|
|
44
|
-
- completed: Task finished successfully
|
|
45
|
-
|
|
46
|
-
**IMPORTANT**: Task descriptions must have two forms:
|
|
47
|
-
- content: The imperative form describing what needs to be done (e.g., "Run tests", "Build the project")
|
|
48
|
-
- activeForm: The present continuous form shown during execution (e.g., "Running tests", "Building the project")
|
|
49
|
-
|
|
50
|
-
2. **Task Management**:
|
|
51
|
-
- Update task status in real-time as you work
|
|
52
|
-
- Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
|
|
53
|
-
- Exactly ONE task must be in_progress at any time (not less, not more)
|
|
54
|
-
- Complete current tasks before starting new ones
|
|
55
|
-
- Remove tasks that are no longer relevant from the list entirely
|
|
56
|
-
|
|
57
|
-
3. **Task Completion Requirements**:
|
|
58
|
-
- ONLY mark a task as completed when you have FULLY accomplished it
|
|
59
|
-
- If you encounter errors, blockers, or cannot finish, keep the task as in_progress
|
|
60
|
-
- When blocked, create a new task describing what needs to be resolved
|
|
61
|
-
- Never mark a task as completed if:
|
|
62
|
-
- Tests are failing
|
|
63
|
-
- Implementation is partial
|
|
64
|
-
- You encountered unresolved errors
|
|
65
|
-
- You couldn't find necessary files or dependencies
|
|
66
|
-
|
|
67
|
-
4. **Task Breakdown**:
|
|
68
|
-
- Create specific, actionable items
|
|
69
|
-
- Break complex tasks into smaller, manageable steps
|
|
70
|
-
- Use clear, descriptive task names
|
|
71
|
-
- Always provide both forms:
|
|
72
|
-
- content: "Fix authentication bug"
|
|
73
|
-
- activeForm: "Fixing authentication bug"
|
|
74
|
-
|
|
75
|
-
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.`,
|
|
76
|
-
schema: z.object({
|
|
77
|
-
todos: z.array(todoItemSchema),
|
|
78
|
-
}),
|
|
79
|
-
},
|
|
80
|
-
);
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ExaSearchResults } from "@langchain/exa";
|
|
2
|
-
import Exa from "exa-js";
|
|
3
|
-
|
|
4
|
-
let _webSearchInstance = null;
|
|
5
|
-
export function makeWebSearchTool() {
|
|
6
|
-
if (_webSearchInstance) {
|
|
7
|
-
return _webSearchInstance;
|
|
8
|
-
}
|
|
9
|
-
const apiKey = process.env.EXA_API_KEY;
|
|
10
|
-
if (!apiKey) {
|
|
11
|
-
throw new Error(
|
|
12
|
-
"EXA_API_KEY environment variable is required to use the web_search tool. " +
|
|
13
|
-
"Please set it to your Exa API key from https://exa.ai",
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
const client = new Exa(apiKey);
|
|
17
|
-
_webSearchInstance = new ExaSearchResults({
|
|
18
|
-
client,
|
|
19
|
-
searchArgs: {
|
|
20
|
-
numResults: 5,
|
|
21
|
-
type: "auto",
|
|
22
|
-
text: true,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
return _webSearchInstance;
|
|
26
|
-
}
|
package/dist/dev-agent/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { makeHttpTransport, makeStdioTransport } from "../acp-server/index";
|
|
5
|
-
// Load agent definition from JSON file
|
|
6
|
-
const configPath = join(import.meta.dir, "agent.json");
|
|
7
|
-
const agent = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
8
|
-
const transport = process.argv[2] || "stdio";
|
|
9
|
-
if (transport === "http") {
|
|
10
|
-
makeHttpTransport(agent);
|
|
11
|
-
}
|
|
12
|
-
else if (transport === "stdio") {
|
|
13
|
-
makeStdioTransport(agent);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
console.error(`Invalid transport: ${transport}`);
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
package/dist/example.d.ts
DELETED
package/dist/example.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
import { makeHttpTransport, makeStdioTransport } from "./acp-server/index.js";
|
|
3
|
-
|
|
4
|
-
const exampleAgent = {
|
|
5
|
-
model: "claude-sonnet-4-5-20250929",
|
|
6
|
-
systemPrompt: "You are a helpful assistant.",
|
|
7
|
-
tools: ["todo_write", "get_weather", "web_search"],
|
|
8
|
-
};
|
|
9
|
-
// Parse transport type from command line argument
|
|
10
|
-
const transport = process.argv[2] || "stdio";
|
|
11
|
-
if (transport === "http") {
|
|
12
|
-
makeHttpTransport(exampleAgent);
|
|
13
|
-
} else if (transport === "stdio") {
|
|
14
|
-
makeStdioTransport(exampleAgent);
|
|
15
|
-
} else {
|
|
16
|
-
console.error(`Invalid transport: ${transport}`);
|
|
17
|
-
console.error("Usage: bun run example.ts [stdio|http]");
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
package/dist/utils/logger.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node.js logger with file rotation support
|
|
3
|
-
* Outputs to both stdout and .logs/<service>.log files
|
|
4
|
-
*/
|
|
5
|
-
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
|
6
|
-
export declare class Logger {
|
|
7
|
-
private service;
|
|
8
|
-
private minLevel;
|
|
9
|
-
private logFilePath;
|
|
10
|
-
private logsDir;
|
|
11
|
-
private writeQueue;
|
|
12
|
-
private isWriting;
|
|
13
|
-
private silent;
|
|
14
|
-
constructor(service: string, minLevel?: LogLevel, options?: {
|
|
15
|
-
silent?: boolean;
|
|
16
|
-
logsDir?: string;
|
|
17
|
-
});
|
|
18
|
-
private ensureLogsDirectory;
|
|
19
|
-
private shouldLog;
|
|
20
|
-
private rotateLogFile;
|
|
21
|
-
private writeToFile;
|
|
22
|
-
private log;
|
|
23
|
-
trace(message: string, metadata?: Record<string, unknown>): void;
|
|
24
|
-
debug(message: string, metadata?: Record<string, unknown>): void;
|
|
25
|
-
info(message: string, metadata?: Record<string, unknown>): void;
|
|
26
|
-
warn(message: string, metadata?: Record<string, unknown>): void;
|
|
27
|
-
error(message: string, metadata?: Record<string, unknown>): void;
|
|
28
|
-
fatal(message: string, metadata?: Record<string, unknown>): void;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Create a logger instance for a service
|
|
32
|
-
* @param service - Service name (e.g., "gui", "http-agent", "tui")
|
|
33
|
-
* @param minLevel - Minimum log level to display (default: "debug")
|
|
34
|
-
* @param options - Logger options (silent mode, custom logs directory, etc.)
|
|
35
|
-
*/
|
|
36
|
-
export declare function createLogger(service: string, minLevel?: LogLevel, options?: {
|
|
37
|
-
silent?: boolean;
|
|
38
|
-
logsDir?: string;
|
|
39
|
-
}): Logger;
|
package/dist/utils/logger.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node.js logger with file rotation support
|
|
3
|
-
* Outputs to both stdout and .logs/<service>.log files
|
|
4
|
-
*/
|
|
5
|
-
import * as fs from "node:fs";
|
|
6
|
-
import * as path from "node:path";
|
|
7
|
-
const LOG_LEVELS = {
|
|
8
|
-
trace: 0,
|
|
9
|
-
debug: 1,
|
|
10
|
-
info: 2,
|
|
11
|
-
warn: 3,
|
|
12
|
-
error: 4,
|
|
13
|
-
fatal: 5,
|
|
14
|
-
};
|
|
15
|
-
// ANSI color codes for terminal output
|
|
16
|
-
const LOG_COLORS = {
|
|
17
|
-
trace: "\x1b[90m", // gray
|
|
18
|
-
debug: "\x1b[34m", // blue
|
|
19
|
-
info: "\x1b[32m", // green
|
|
20
|
-
warn: "\x1b[33m", // yellow
|
|
21
|
-
error: "\x1b[31m", // red
|
|
22
|
-
fatal: "\x1b[41m\x1b[37m", // white on red background
|
|
23
|
-
};
|
|
24
|
-
const RESET = "\x1b[0m";
|
|
25
|
-
const MAX_LOG_SIZE = 10 * 1024 * 1024; // 10MB
|
|
26
|
-
const MAX_ROTATED_FILES = 5;
|
|
27
|
-
export class Logger {
|
|
28
|
-
service;
|
|
29
|
-
minLevel;
|
|
30
|
-
logFilePath;
|
|
31
|
-
logsDir;
|
|
32
|
-
writeQueue = [];
|
|
33
|
-
isWriting = false;
|
|
34
|
-
silent;
|
|
35
|
-
constructor(service, minLevel = "debug", options) {
|
|
36
|
-
this.service = service;
|
|
37
|
-
this.minLevel = minLevel;
|
|
38
|
-
this.silent = options?.silent ?? false;
|
|
39
|
-
// Setup log file path - use custom logsDir if provided, otherwise use process.cwd()
|
|
40
|
-
const baseDir = options?.logsDir ?? process.cwd();
|
|
41
|
-
this.logsDir = path.join(baseDir, ".logs");
|
|
42
|
-
this.logFilePath = path.join(this.logsDir, `${service}.log`);
|
|
43
|
-
// Create logs directory if it doesn't exist
|
|
44
|
-
this.ensureLogsDirectory();
|
|
45
|
-
}
|
|
46
|
-
ensureLogsDirectory() {
|
|
47
|
-
try {
|
|
48
|
-
if (!fs.existsSync(this.logsDir)) {
|
|
49
|
-
fs.mkdirSync(this.logsDir, { recursive: true });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
console.error("Failed to create logs directory:", error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
shouldLog(level) {
|
|
57
|
-
return LOG_LEVELS[level] >= LOG_LEVELS[this.minLevel];
|
|
58
|
-
}
|
|
59
|
-
rotateLogFile() {
|
|
60
|
-
try {
|
|
61
|
-
// Check if rotation is needed
|
|
62
|
-
if (!fs.existsSync(this.logFilePath)) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const stats = fs.statSync(this.logFilePath);
|
|
66
|
-
if (stats.size < MAX_LOG_SIZE) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
// Remove oldest rotated file if it exists
|
|
70
|
-
const oldestFile = `${this.logFilePath}.${MAX_ROTATED_FILES}`;
|
|
71
|
-
if (fs.existsSync(oldestFile)) {
|
|
72
|
-
fs.unlinkSync(oldestFile);
|
|
73
|
-
}
|
|
74
|
-
// Rotate existing files
|
|
75
|
-
for (let i = MAX_ROTATED_FILES - 1; i >= 1; i--) {
|
|
76
|
-
const oldFile = `${this.logFilePath}.${i}`;
|
|
77
|
-
const newFile = `${this.logFilePath}.${i + 1}`;
|
|
78
|
-
if (fs.existsSync(oldFile)) {
|
|
79
|
-
fs.renameSync(oldFile, newFile);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// Rotate current log file
|
|
83
|
-
fs.renameSync(this.logFilePath, `${this.logFilePath}.1`);
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
console.error("Failed to rotate log file:", error);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async writeToFile(content) {
|
|
90
|
-
this.writeQueue.push(content);
|
|
91
|
-
if (this.isWriting) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
this.isWriting = true;
|
|
95
|
-
while (this.writeQueue.length > 0) {
|
|
96
|
-
const batch = this.writeQueue.splice(0, this.writeQueue.length);
|
|
97
|
-
const data = `${batch.join("\n")}\n`;
|
|
98
|
-
try {
|
|
99
|
-
// Check if rotation is needed before writing
|
|
100
|
-
this.rotateLogFile();
|
|
101
|
-
// Append to log file
|
|
102
|
-
await fs.promises.appendFile(this.logFilePath, data, "utf-8");
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
console.error("Failed to write to log file:", error);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
this.isWriting = false;
|
|
109
|
-
}
|
|
110
|
-
log(level, message, metadata) {
|
|
111
|
-
if (!this.shouldLog(level)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const entry = {
|
|
115
|
-
timestamp: new Date().toISOString(),
|
|
116
|
-
level,
|
|
117
|
-
service: this.service,
|
|
118
|
-
message,
|
|
119
|
-
...(metadata && { metadata }),
|
|
120
|
-
};
|
|
121
|
-
// Console output with color-coding
|
|
122
|
-
const color = LOG_COLORS[level];
|
|
123
|
-
const levelUpper = level.toUpperCase().padEnd(5);
|
|
124
|
-
const prefix = `${color}[${entry.timestamp}] [${this.service}] [${levelUpper}]${RESET}`;
|
|
125
|
-
const formattedMessage = metadata
|
|
126
|
-
? `${message} ${JSON.stringify(metadata)}`
|
|
127
|
-
: message;
|
|
128
|
-
// Output to stdout/stderr (unless silent)
|
|
129
|
-
if (!this.silent) {
|
|
130
|
-
if (level === "error" || level === "fatal") {
|
|
131
|
-
console.error(`${prefix} ${formattedMessage}`);
|
|
132
|
-
}
|
|
133
|
-
else if (level === "warn") {
|
|
134
|
-
console.warn(`${prefix} ${formattedMessage}`);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
console.log(`${prefix} ${formattedMessage}`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// Write to file (JSON format)
|
|
141
|
-
const jsonLine = JSON.stringify(entry);
|
|
142
|
-
this.writeToFile(jsonLine).catch((error) => {
|
|
143
|
-
if (!this.silent) {
|
|
144
|
-
console.error("Failed to queue log write:", error);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
trace(message, metadata) {
|
|
149
|
-
this.log("trace", message, metadata);
|
|
150
|
-
}
|
|
151
|
-
debug(message, metadata) {
|
|
152
|
-
this.log("debug", message, metadata);
|
|
153
|
-
}
|
|
154
|
-
info(message, metadata) {
|
|
155
|
-
this.log("info", message, metadata);
|
|
156
|
-
}
|
|
157
|
-
warn(message, metadata) {
|
|
158
|
-
this.log("warn", message, metadata);
|
|
159
|
-
}
|
|
160
|
-
error(message, metadata) {
|
|
161
|
-
this.log("error", message, metadata);
|
|
162
|
-
}
|
|
163
|
-
fatal(message, metadata) {
|
|
164
|
-
this.log("fatal", message, metadata);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Create a logger instance for a service
|
|
169
|
-
* @param service - Service name (e.g., "gui", "http-agent", "tui")
|
|
170
|
-
* @param minLevel - Minimum log level to display (default: "debug")
|
|
171
|
-
* @param options - Logger options (silent mode, custom logs directory, etc.)
|
|
172
|
-
*/
|
|
173
|
-
export function createLogger(service, minLevel = "debug", options) {
|
|
174
|
-
return new Logger(service, minLevel, options);
|
|
175
|
-
}
|