@avasis-ai/synthcode 1.0.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.
- package/LICENSE +21 -0
- package/README.md +292 -0
- package/dist/chunk-53ZOIXM4.js +624 -0
- package/dist/chunk-53ZOIXM4.js.map +1 -0
- package/dist/chunk-BWXHO6UJ.js +115 -0
- package/dist/chunk-BWXHO6UJ.js.map +1 -0
- package/dist/chunk-CARUMOML.js +123 -0
- package/dist/chunk-CARUMOML.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-F34HO4RA.js +487 -0
- package/dist/chunk-F34HO4RA.js.map +1 -0
- package/dist/chunk-FK7S2S7V.js +132 -0
- package/dist/chunk-FK7S2S7V.js.map +1 -0
- package/dist/chunk-MQ7XP6VT.js +174 -0
- package/dist/chunk-MQ7XP6VT.js.map +1 -0
- package/dist/chunk-TLPOO6C3.js +176 -0
- package/dist/chunk-TLPOO6C3.js.map +1 -0
- package/dist/chunk-W6OLZ2OI.js +56 -0
- package/dist/chunk-W6OLZ2OI.js.map +1 -0
- package/dist/cli/index.cjs +151 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +8 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/run.cjs +128 -0
- package/dist/cli/run.cjs.map +1 -0
- package/dist/cli/run.d.cts +1 -0
- package/dist/cli/run.d.ts +1 -0
- package/dist/cli/run.js +126 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/index-D-K6sx8s.d.cts +8 -0
- package/dist/index-D-K6sx8s.d.ts +8 -0
- package/dist/index.cjs +2909 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +274 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.js +1048 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/index.cjs +531 -0
- package/dist/llm/index.cjs.map +1 -0
- package/dist/llm/index.d.cts +70 -0
- package/dist/llm/index.d.ts +70 -0
- package/dist/llm/index.js +24 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/mcp/index.cjs +323 -0
- package/dist/mcp/index.cjs.map +1 -0
- package/dist/mcp/index.d.cts +39 -0
- package/dist/mcp/index.d.ts +39 -0
- package/dist/mcp/index.js +11 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/memory/index.cjs +146 -0
- package/dist/memory/index.cjs.map +1 -0
- package/dist/memory/index.d.cts +51 -0
- package/dist/memory/index.d.ts +51 -0
- package/dist/memory/index.js +10 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/tools/fuzzy-edit.cjs +200 -0
- package/dist/tools/fuzzy-edit.cjs.map +1 -0
- package/dist/tools/fuzzy-edit.d.cts +9 -0
- package/dist/tools/fuzzy-edit.d.ts +9 -0
- package/dist/tools/fuzzy-edit.js +12 -0
- package/dist/tools/fuzzy-edit.js.map +1 -0
- package/dist/tools/index.cjs +1032 -0
- package/dist/tools/index.cjs.map +1 -0
- package/dist/tools/index.d.cts +4 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +39 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types-C11cw5ZD.d.cts +177 -0
- package/dist/types-C11cw5ZD.d.ts +177 -0
- package/dist/utils-TF4TBXQJ.js +10 -0
- package/dist/utils-TF4TBXQJ.js.map +1 -0
- package/dist/web-fetch-B42QzYD2.d.cts +85 -0
- package/dist/web-fetch-EDdhxmEf.d.ts +85 -0
- package/package.json +134 -0
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
|
|
20
|
+
// src/memory/index.ts
|
|
21
|
+
var memory_exports = {};
|
|
22
|
+
__export(memory_exports, {
|
|
23
|
+
InMemoryStore: () => InMemoryStore,
|
|
24
|
+
SQLiteStore: () => SQLiteStore
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(memory_exports);
|
|
27
|
+
|
|
28
|
+
// src/memory/store.ts
|
|
29
|
+
var InMemoryStore = class {
|
|
30
|
+
threads = /* @__PURE__ */ new Map();
|
|
31
|
+
async getThread(threadId) {
|
|
32
|
+
return this.threads.get(threadId)?.messages ?? [];
|
|
33
|
+
}
|
|
34
|
+
async saveThread(threadId, messages) {
|
|
35
|
+
this.threads.set(threadId, { messages, updatedAt: Date.now() });
|
|
36
|
+
}
|
|
37
|
+
async appendMessage(threadId, message) {
|
|
38
|
+
const thread = this.threads.get(threadId);
|
|
39
|
+
if (thread) {
|
|
40
|
+
thread.messages.push(message);
|
|
41
|
+
thread.updatedAt = Date.now();
|
|
42
|
+
} else {
|
|
43
|
+
this.threads.set(threadId, { messages: [message], updatedAt: Date.now() });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async listThreads(opts) {
|
|
47
|
+
let entries = Array.from(this.threads.entries()).map(([id, data]) => ({ id, updatedAt: data.updatedAt, messageCount: data.messages.length })).sort((a, b) => b.updatedAt - a.updatedAt);
|
|
48
|
+
if (opts?.before) entries = entries.filter((e) => e.updatedAt < parseInt(opts.before, 10));
|
|
49
|
+
return entries.slice(0, opts?.limit ?? 100);
|
|
50
|
+
}
|
|
51
|
+
async deleteThread(threadId) {
|
|
52
|
+
this.threads.delete(threadId);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/memory/sqlite.ts
|
|
57
|
+
function jsonSerialize(messages) {
|
|
58
|
+
return JSON.stringify(messages, (_, value) => {
|
|
59
|
+
if (value === void 0) return "__UNDEFINED__";
|
|
60
|
+
return value;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function jsonDeserialize(str) {
|
|
64
|
+
return JSON.parse(str, (_, value) => {
|
|
65
|
+
if (value === "__UNDEFINED__") return void 0;
|
|
66
|
+
return value;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
var SQLiteStore = class {
|
|
70
|
+
store;
|
|
71
|
+
constructor(dbPath) {
|
|
72
|
+
try {
|
|
73
|
+
const Database = require("better-sqlite3");
|
|
74
|
+
const db = new Database(dbPath ?? "./synth-memory.db");
|
|
75
|
+
db.pragma("journal_mode = WAL");
|
|
76
|
+
db.exec(`
|
|
77
|
+
CREATE TABLE IF NOT EXISTS threads (
|
|
78
|
+
id TEXT PRIMARY KEY,
|
|
79
|
+
messages TEXT NOT NULL,
|
|
80
|
+
updated_at INTEGER NOT NULL,
|
|
81
|
+
message_count INTEGER NOT NULL DEFAULT 0
|
|
82
|
+
)
|
|
83
|
+
`);
|
|
84
|
+
try {
|
|
85
|
+
db.exec("ALTER TABLE threads ADD COLUMN message_count INTEGER NOT NULL DEFAULT 0");
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
this.store = {
|
|
89
|
+
async getThread(threadId) {
|
|
90
|
+
const row = db.prepare("SELECT messages FROM threads WHERE id = ?").get(threadId);
|
|
91
|
+
if (!row) return [];
|
|
92
|
+
return jsonDeserialize(row.messages);
|
|
93
|
+
},
|
|
94
|
+
async saveThread(threadId, messages) {
|
|
95
|
+
const now = Date.now();
|
|
96
|
+
const json = jsonSerialize(messages);
|
|
97
|
+
const msgCount = messages.length;
|
|
98
|
+
const exists = db.prepare("SELECT 1 FROM threads WHERE id = ?").get(threadId);
|
|
99
|
+
const stmt = exists ? db.prepare("UPDATE threads SET messages = ?, updated_at = ?, message_count = ? WHERE id = ?") : db.prepare("INSERT INTO threads (id, messages, updated_at, message_count) VALUES (?, ?, ?, ?)");
|
|
100
|
+
stmt.run(json, now, msgCount, threadId);
|
|
101
|
+
},
|
|
102
|
+
async appendMessage(threadId, message) {
|
|
103
|
+
const row = db.prepare("SELECT messages FROM threads WHERE id = ?").get(threadId);
|
|
104
|
+
const messages = row ? jsonDeserialize(row.messages) : [];
|
|
105
|
+
messages.push(message);
|
|
106
|
+
const json = jsonSerialize(messages);
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
db.prepare("INSERT INTO threads (id, messages, updated_at, message_count) VALUES (?, ?, ?, ?) ON CONFLICT(id) DO UPDATE SET messages = excluded.messages, updated_at = excluded.updated_at, message_count = excluded.message_count").run(threadId, json, now, messages.length);
|
|
109
|
+
},
|
|
110
|
+
async listThreads(opts) {
|
|
111
|
+
const rows = db.prepare("SELECT id, updated_at, message_count FROM threads ORDER BY updated_at DESC").all();
|
|
112
|
+
let results = rows.map((r) => ({ id: r.id, updatedAt: r.updated_at, messageCount: r.message_count }));
|
|
113
|
+
if (opts?.before) results = results.filter((e) => e.updatedAt < parseInt(opts.before, 10));
|
|
114
|
+
return results.slice(0, opts?.limit ?? 100);
|
|
115
|
+
},
|
|
116
|
+
async deleteThread(threadId) {
|
|
117
|
+
db.prepare("DELETE FROM threads WHERE id = ?").run(threadId);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
} catch {
|
|
121
|
+
console.warn("[synth] better-sqlite3 not available, falling back to in-memory store. Install it with: npm install better-sqlite3");
|
|
122
|
+
this.store = new InMemoryStore();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async getThread(threadId) {
|
|
126
|
+
return this.store.getThread(threadId);
|
|
127
|
+
}
|
|
128
|
+
async saveThread(threadId, messages) {
|
|
129
|
+
return this.store.saveThread(threadId, messages);
|
|
130
|
+
}
|
|
131
|
+
async appendMessage(threadId, message) {
|
|
132
|
+
return this.store.appendMessage(threadId, message);
|
|
133
|
+
}
|
|
134
|
+
async listThreads(opts) {
|
|
135
|
+
return this.store.listThreads(opts);
|
|
136
|
+
}
|
|
137
|
+
async deleteThread(threadId) {
|
|
138
|
+
return this.store.deleteThread(threadId);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
142
|
+
0 && (module.exports = {
|
|
143
|
+
InMemoryStore,
|
|
144
|
+
SQLiteStore
|
|
145
|
+
});
|
|
146
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/memory/index.ts","../../src/memory/store.ts","../../src/memory/sqlite.ts"],"sourcesContent":["export { InMemoryStore } from \"./store.js\";\nexport { SQLiteStore } from \"./sqlite.js\";\nexport type { MemoryStore } from \"./store.js\";\n","import type { Message } from \"../types.js\";\n\nexport interface MemoryStore {\n getThread(threadId: string): Promise<Message[]>;\n saveThread(threadId: string, messages: Message[]): Promise<void>;\n appendMessage(threadId: string, message: Message): Promise<void>;\n listThreads(opts?: { limit?: number; before?: string }): Promise<Array<{ id: string; updatedAt: number; messageCount: number }>>;\n deleteThread(threadId: string): Promise<void>;\n}\n\nexport class InMemoryStore implements MemoryStore {\n private threads: Map<string, { messages: Message[]; updatedAt: number }> = new Map();\n\n async getThread(threadId: string): Promise<Message[]> {\n return this.threads.get(threadId)?.messages ?? [];\n }\n\n async saveThread(threadId: string, messages: Message[]): Promise<void> {\n this.threads.set(threadId, { messages, updatedAt: Date.now() });\n }\n\n async appendMessage(threadId: string, message: Message): Promise<void> {\n const thread = this.threads.get(threadId);\n if (thread) {\n thread.messages.push(message);\n thread.updatedAt = Date.now();\n } else {\n this.threads.set(threadId, { messages: [message], updatedAt: Date.now() });\n }\n }\n\n async listThreads(opts?: { limit?: number; before?: string }): Promise<Array<{ id: string; updatedAt: number; messageCount: number }>> {\n let entries = Array.from(this.threads.entries())\n .map(([id, data]) => ({ id, updatedAt: data.updatedAt, messageCount: data.messages.length }))\n .sort((a, b) => b.updatedAt - a.updatedAt);\n if (opts?.before) entries = entries.filter(e => e.updatedAt < parseInt(opts.before as string, 10));\n return entries.slice(0, opts?.limit ?? 100);\n }\n\n async deleteThread(threadId: string): Promise<void> {\n this.threads.delete(threadId);\n }\n}\n","import type { MemoryStore } from \"./store.js\";\nimport type { Message } from \"../types.js\";\nimport { InMemoryStore } from \"./store.js\";\n\nfunction jsonSerialize(messages: Message[]): string {\n return JSON.stringify(messages, (_, value) => {\n if (value === undefined) return \"__UNDEFINED__\";\n return value;\n });\n}\n\nfunction jsonDeserialize(str: string): Message[] {\n return JSON.parse(str, (_, value) => {\n if (value === \"__UNDEFINED__\") return undefined;\n return value;\n });\n}\n\nexport class SQLiteStore implements MemoryStore {\n private store: MemoryStore;\n\n constructor(dbPath?: string) {\n try {\n const Database = require(\"better-sqlite3\");\n const db = new Database(dbPath ?? \"./synth-memory.db\");\n db.pragma(\"journal_mode = WAL\");\n db.exec(`\n CREATE TABLE IF NOT EXISTS threads (\n id TEXT PRIMARY KEY,\n messages TEXT NOT NULL,\n updated_at INTEGER NOT NULL,\n message_count INTEGER NOT NULL DEFAULT 0\n )\n `);\n try {\n db.exec(\"ALTER TABLE threads ADD COLUMN message_count INTEGER NOT NULL DEFAULT 0\");\n } catch {\n // column already exists\n }\n this.store = {\n async getThread(threadId: string): Promise<Message[]> {\n const row = db.prepare(\"SELECT messages FROM threads WHERE id = ?\").get(threadId);\n if (!row) return [];\n return jsonDeserialize(row.messages);\n },\n async saveThread(threadId: string, messages: Message[]): Promise<void> {\n const now = Date.now();\n const json = jsonSerialize(messages);\n const msgCount = messages.length;\n const exists = db.prepare(\"SELECT 1 FROM threads WHERE id = ?\").get(threadId);\n const stmt = exists\n ? db.prepare(\"UPDATE threads SET messages = ?, updated_at = ?, message_count = ? WHERE id = ?\")\n : db.prepare(\"INSERT INTO threads (id, messages, updated_at, message_count) VALUES (?, ?, ?, ?)\");\n stmt.run(json, now, msgCount, threadId);\n },\n async appendMessage(threadId: string, message: Message): Promise<void> {\n const row = db.prepare(\"SELECT messages FROM threads WHERE id = ?\").get(threadId);\n const messages: Message[] = row ? jsonDeserialize(row.messages) : [];\n messages.push(message);\n const json = jsonSerialize(messages);\n const now = Date.now();\n db.prepare(\"INSERT INTO threads (id, messages, updated_at, message_count) VALUES (?, ?, ?, ?) ON CONFLICT(id) DO UPDATE SET messages = excluded.messages, updated_at = excluded.updated_at, message_count = excluded.message_count\")\n .run(threadId, json, now, messages.length);\n },\n async listThreads(opts?: { limit?: number; before?: string }): Promise<Array<{ id: string; updatedAt: number; messageCount: number }>> {\n const rows = db.prepare(\"SELECT id, updated_at, message_count FROM threads ORDER BY updated_at DESC\").all();\n let results = rows.map((r: any) => ({ id: r.id, updatedAt: r.updated_at, messageCount: r.message_count }));\n if (opts?.before) results = results.filter((e: { updatedAt: number }) => e.updatedAt < parseInt(opts.before!, 10));\n return results.slice(0, opts?.limit ?? 100);\n },\n async deleteThread(threadId: string): Promise<void> {\n db.prepare(\"DELETE FROM threads WHERE id = ?\").run(threadId);\n },\n };\n } catch {\n console.warn(\"[synth] better-sqlite3 not available, falling back to in-memory store. Install it with: npm install better-sqlite3\");\n this.store = new InMemoryStore();\n }\n }\n\n async getThread(threadId: string): Promise<Message[]> { return this.store.getThread(threadId); }\n async saveThread(threadId: string, messages: Message[]): Promise<void> { return this.store.saveThread(threadId, messages); }\n async appendMessage(threadId: string, message: Message): Promise<void> { return this.store.appendMessage(threadId, message); }\n async listThreads(opts?: { limit?: number; before?: string }): Promise<Array<{ id: string; updatedAt: number; messageCount: number }>> { return this.store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w5ZD.cjs';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
interface MemoryStore {
|
|
5
|
+
getThread(threadId: string): Promise<Message[]>;
|
|
6
|
+
saveThread(threadId: string, messages: Message[]): Promise<void>;
|
|
7
|
+
appendMessage(threadId: string, message: Message): Promise<void>;
|
|
8
|
+
listThreads(opts?: {
|
|
9
|
+
limit?: number;
|
|
10
|
+
before?: string;
|
|
11
|
+
}): Promise<Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
updatedAt: number;
|
|
14
|
+
messageCount: number;
|
|
15
|
+
}>>;
|
|
16
|
+
deleteThread(threadId: string): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
declare class InMemoryStore implements MemoryStore {
|
|
19
|
+
private threads;
|
|
20
|
+
getThread(threadId: string): Promise<Message[]>;
|
|
21
|
+
saveThread(threadId: string, messages: Message[]): Promise<void>;
|
|
22
|
+
appendMessage(threadId: string, message: Message): Promise<void>;
|
|
23
|
+
listThreads(opts?: {
|
|
24
|
+
limit?: number;
|
|
25
|
+
before?: string;
|
|
26
|
+
}): Promise<Array<{
|
|
27
|
+
id: string;
|
|
28
|
+
updatedAt: number;
|
|
29
|
+
messageCount: number;
|
|
30
|
+
}>>;
|
|
31
|
+
deleteThread(threadId: string): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare class SQLiteStore implements MemoryStore {
|
|
35
|
+
private store;
|
|
36
|
+
constructor(dbPath?: string);
|
|
37
|
+
getThread(threadId: string): Promise<Message[]>;
|
|
38
|
+
saveThread(threadId: string, messages: Message[]): Promise<void>;
|
|
39
|
+
appendMessage(threadId: string, message: Message): Promise<void>;
|
|
40
|
+
listThreads(opts?: {
|
|
41
|
+
limit?: number;
|
|
42
|
+
before?: string;
|
|
43
|
+
}): Promise<Array<{
|
|
44
|
+
id: string;
|
|
45
|
+
updatedAt: number;
|
|
46
|
+
messageCount: number;
|
|
47
|
+
}>>;
|
|
48
|
+
deleteThread(threadId: string): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { InMemoryStore, type MemoryStore, SQLiteStore };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { g as Message } from '../types-C11cw5ZD.js';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
interface MemoryStore {
|
|
5
|
+
getThread(threadId: string): Promise<Message[]>;
|
|
6
|
+
saveThread(threadId: string, messages: Message[]): Promise<void>;
|
|
7
|
+
appendMessage(threadId: string, message: Message): Promise<void>;
|
|
8
|
+
listThreads(opts?: {
|
|
9
|
+
limit?: number;
|
|
10
|
+
before?: string;
|
|
11
|
+
}): Promise<Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
updatedAt: number;
|
|
14
|
+
messageCount: number;
|
|
15
|
+
}>>;
|
|
16
|
+
deleteThread(threadId: string): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
declare class InMemoryStore implements MemoryStore {
|
|
19
|
+
private threads;
|
|
20
|
+
getThread(threadId: string): Promise<Message[]>;
|
|
21
|
+
saveThread(threadId: string, messages: Message[]): Promise<void>;
|
|
22
|
+
appendMessage(threadId: string, message: Message): Promise<void>;
|
|
23
|
+
listThreads(opts?: {
|
|
24
|
+
limit?: number;
|
|
25
|
+
before?: string;
|
|
26
|
+
}): Promise<Array<{
|
|
27
|
+
id: string;
|
|
28
|
+
updatedAt: number;
|
|
29
|
+
messageCount: number;
|
|
30
|
+
}>>;
|
|
31
|
+
deleteThread(threadId: string): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare class SQLiteStore implements MemoryStore {
|
|
35
|
+
private store;
|
|
36
|
+
constructor(dbPath?: string);
|
|
37
|
+
getThread(threadId: string): Promise<Message[]>;
|
|
38
|
+
saveThread(threadId: string, messages: Message[]): Promise<void>;
|
|
39
|
+
appendMessage(threadId: string, message: Message): Promise<void>;
|
|
40
|
+
listThreads(opts?: {
|
|
41
|
+
limit?: number;
|
|
42
|
+
before?: string;
|
|
43
|
+
}): Promise<Array<{
|
|
44
|
+
id: string;
|
|
45
|
+
updatedAt: number;
|
|
46
|
+
messageCount: number;
|
|
47
|
+
}>>;
|
|
48
|
+
deleteThread(threadId: string): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { InMemoryStore, type MemoryStore, SQLiteStore };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,200 @@
|
|
|
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
|
+
|
|
20
|
+
// src/tools/fuzzy-edit.ts
|
|
21
|
+
var fuzzy_edit_exports = {};
|
|
22
|
+
__export(fuzzy_edit_exports, {
|
|
23
|
+
FuzzyEditError: () => FuzzyEditError,
|
|
24
|
+
fuzzyContains: () => fuzzyContains,
|
|
25
|
+
fuzzyReplace: () => fuzzyReplace
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(fuzzy_edit_exports);
|
|
28
|
+
var FuzzyEditError = class extends Error {
|
|
29
|
+
constructor(kind, message) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.kind = kind;
|
|
32
|
+
this.name = "FuzzyEditError";
|
|
33
|
+
}
|
|
34
|
+
kind;
|
|
35
|
+
};
|
|
36
|
+
function levenshtein(a, b) {
|
|
37
|
+
const m = a.length;
|
|
38
|
+
const n = b.length;
|
|
39
|
+
if (m === 0) return n;
|
|
40
|
+
if (n === 0) return m;
|
|
41
|
+
const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
42
|
+
for (let i = 0; i <= m; i++) dp[i][0] = i;
|
|
43
|
+
for (let j = 0; j <= n; j++) dp[0][j] = j;
|
|
44
|
+
for (let i = 1; i <= m; i++) {
|
|
45
|
+
for (let j = 1; j <= n; j++) {
|
|
46
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
47
|
+
dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return dp[m][n];
|
|
51
|
+
}
|
|
52
|
+
function similarity(a, b) {
|
|
53
|
+
if (a.length > 1e3 || b.length > 1e3) return a === b ? 1 : 0;
|
|
54
|
+
const maxLen = Math.max(a.length, b.length);
|
|
55
|
+
if (maxLen === 0) return 1;
|
|
56
|
+
return 1 - levenshtein(a, b) / maxLen;
|
|
57
|
+
}
|
|
58
|
+
function* simpleReplacer(content, find) {
|
|
59
|
+
if (content.includes(find)) yield find;
|
|
60
|
+
}
|
|
61
|
+
function* lineTrimmedReplacer(content, find) {
|
|
62
|
+
const lines = find.split("\n").map((l) => l.trim());
|
|
63
|
+
const contentLines = content.split("\n");
|
|
64
|
+
for (let i = 0; i <= contentLines.length - lines.length; i++) {
|
|
65
|
+
if (contentLines.slice(i, i + lines.length).every((cl, idx) => cl.trim() === lines[idx])) {
|
|
66
|
+
yield contentLines.slice(i, i + lines.length).join("\n");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function* blockAnchorReplacer(content, find) {
|
|
71
|
+
const findLines = find.split("\n");
|
|
72
|
+
const contentLines = content.split("\n");
|
|
73
|
+
if (findLines.length < 2) return;
|
|
74
|
+
const firstLine = findLines[0];
|
|
75
|
+
const lastLine = findLines[findLines.length - 1];
|
|
76
|
+
const middleLines = findLines.slice(1, -1);
|
|
77
|
+
for (let i = 0; i <= contentLines.length - findLines.length; i++) {
|
|
78
|
+
if (contentLines[i] !== firstLine) continue;
|
|
79
|
+
const endIdx = i + findLines.length - 1;
|
|
80
|
+
if (contentLines[endIdx] !== lastLine) continue;
|
|
81
|
+
const candidates = [];
|
|
82
|
+
for (let j = i + 1; j < endIdx; j++) {
|
|
83
|
+
candidates.push({ idx: j, score: 0 });
|
|
84
|
+
}
|
|
85
|
+
let totalScore = 0;
|
|
86
|
+
for (let k = 0; k < middleLines.length; k++) {
|
|
87
|
+
const contentLine = contentLines[i + 1 + k];
|
|
88
|
+
const sim = similarity(middleLines[k], contentLine);
|
|
89
|
+
totalScore += sim;
|
|
90
|
+
if (candidates[k]) candidates[k].score = sim;
|
|
91
|
+
}
|
|
92
|
+
const avgScore = totalScore / middleLines.length;
|
|
93
|
+
const threshold = candidates.length > 1 ? 0.3 : 0;
|
|
94
|
+
if (avgScore >= threshold) {
|
|
95
|
+
yield contentLines.slice(i, i + findLines.length).join("\n");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function* whitespaceNormalizedReplacer(content, find) {
|
|
100
|
+
const normFind = find.replace(/\s+/g, " ").trim();
|
|
101
|
+
if (!normFind) return;
|
|
102
|
+
const normContent = content.replace(/\s+/g, " ").trim();
|
|
103
|
+
const idx = normContent.indexOf(normFind);
|
|
104
|
+
if (idx === -1) return;
|
|
105
|
+
const firstWord = normFind.split(" ")[0];
|
|
106
|
+
const lastWord = normFind.split(" ").filter(Boolean).pop();
|
|
107
|
+
const firstIdx = content.indexOf(firstWord);
|
|
108
|
+
const lastIdx = content.lastIndexOf(lastWord);
|
|
109
|
+
if (firstIdx === -1 || lastIdx === -1 || lastIdx < firstIdx) return;
|
|
110
|
+
yield content.substring(firstIdx, lastIdx + lastWord.length);
|
|
111
|
+
}
|
|
112
|
+
function* indentationFlexibleReplacer(content, find) {
|
|
113
|
+
const lines = find.split("\n");
|
|
114
|
+
const minIndent = Math.min(...lines.filter((l) => l.trim().length > 0).map((l) => l.match(/^(\s*)/)?.[1].length ?? 0));
|
|
115
|
+
const dedented = lines.map((l) => l.substring(minIndent)).join("\n");
|
|
116
|
+
if (content.includes(dedented)) yield dedented;
|
|
117
|
+
}
|
|
118
|
+
function* escapeNormalizedReplacer(content, find) {
|
|
119
|
+
const normalized = find.replace(/\\n/g, "\n").replace(/\\t/g, " ").replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
120
|
+
if (content.includes(normalized)) yield normalized;
|
|
121
|
+
}
|
|
122
|
+
function* trimmedBoundaryReplacer(content, find) {
|
|
123
|
+
const trimmed = find.trim();
|
|
124
|
+
if (content.includes(trimmed)) yield trimmed;
|
|
125
|
+
}
|
|
126
|
+
function* contextAwareReplacer(content, find) {
|
|
127
|
+
const findLines = find.split("\n");
|
|
128
|
+
if (findLines.length < 3) return;
|
|
129
|
+
const firstLine = findLines[0].trim();
|
|
130
|
+
const lastLine = findLines[findLines.length - 1].trim();
|
|
131
|
+
const contentLines = content.split("\n");
|
|
132
|
+
for (let i = 0; i <= contentLines.length - 3; i++) {
|
|
133
|
+
if (contentLines[i].trim() !== firstLine) continue;
|
|
134
|
+
let bestEndIdx = -1;
|
|
135
|
+
let bestScore = 0;
|
|
136
|
+
for (let j = i + 2; j < contentLines.length; j++) {
|
|
137
|
+
if (contentLines[j].trim() === lastLine) {
|
|
138
|
+
const middleCount = j - i - 1;
|
|
139
|
+
let matchCount = 0;
|
|
140
|
+
for (let k = 1; k <= middleCount; k++) {
|
|
141
|
+
const fIdx = Math.floor(k / (middleCount + 1) * (findLines.length - 2));
|
|
142
|
+
if (fIdx >= 0 && fIdx < findLines.length - 2) {
|
|
143
|
+
if (similarity(contentLines[i + k].trim(), findLines[fIdx + 1].trim()) > 0.5) {
|
|
144
|
+
matchCount++;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const score = matchCount / middleCount;
|
|
149
|
+
if (score > bestScore) {
|
|
150
|
+
bestScore = score;
|
|
151
|
+
bestEndIdx = j;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (bestEndIdx !== -1 && bestScore > 0.5) {
|
|
156
|
+
yield contentLines.slice(i, bestEndIdx + 1).join("\n");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
var REPLACERS = [
|
|
161
|
+
simpleReplacer,
|
|
162
|
+
lineTrimmedReplacer,
|
|
163
|
+
blockAnchorReplacer,
|
|
164
|
+
whitespaceNormalizedReplacer,
|
|
165
|
+
indentationFlexibleReplacer,
|
|
166
|
+
escapeNormalizedReplacer,
|
|
167
|
+
trimmedBoundaryReplacer,
|
|
168
|
+
contextAwareReplacer
|
|
169
|
+
];
|
|
170
|
+
function fuzzyReplace(content, oldString, newString, replaceAll = false) {
|
|
171
|
+
for (const replacer of REPLACERS) {
|
|
172
|
+
for (const search of replacer(content, oldString)) {
|
|
173
|
+
const idx = content.indexOf(search);
|
|
174
|
+
if (idx === -1) continue;
|
|
175
|
+
if (replaceAll) {
|
|
176
|
+
return content.split(search).join(newString);
|
|
177
|
+
}
|
|
178
|
+
const firstIdx = content.indexOf(search);
|
|
179
|
+
const lastIdx = content.lastIndexOf(search);
|
|
180
|
+
if (firstIdx !== lastIdx) continue;
|
|
181
|
+
return content.substring(0, firstIdx) + newString + content.substring(firstIdx + search.length);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
throw new FuzzyEditError("not_found", `Could not find match for replacement (after 8 fuzzy strategies)`);
|
|
185
|
+
}
|
|
186
|
+
function fuzzyContains(content, find) {
|
|
187
|
+
try {
|
|
188
|
+
fuzzyReplace(content, find, "PLACEHOLDER_CHECK");
|
|
189
|
+
return true;
|
|
190
|
+
} catch {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
195
|
+
0 && (module.exports = {
|
|
196
|
+
FuzzyEditError,
|
|
197
|
+
fuzzyContains,
|
|
198
|
+
fuzzyReplace
|
|
199
|
+
});
|
|
200
|
+
//# sourceMappingURL=fuzzy-edit.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/tools/fuzzy-edit.ts"],"sourcesContent":["import type { ToolUseBlock } from \"../types.js\";\n\nexport type ReplacerFn = (content: string, find: string) => Generator<string, void, unknown>;\n\nexport class FuzzyEditError extends Error {\n constructor(public readonly kind: \"not_found\" | \"ambiguous\", message: string) {\n super(message);\n this.name = \"FuzzyEditError\";\n }\n}\n\nfunction levenshtein(a: string, b: string): number {\n const m = a.length;\n const n = b.length;\n if (m === 0) return n;\n if (n === 0) return m;\n const dp: number[][] = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));\n for (let i = 0; i <= m; i++) dp[i][0] = i;\n for (let j = 0; j <= n; j++) dp[0][j] = j;\n for (let i = 1; i <= m; i++) {\n for (let j = 1; j <= n; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost);\n }\n }\n return dp[m][n];\n}\n\nfunction similarity(a: string, b: string): number {\n if (a.length > 1000 || b.length > 1000) return a === b ? 1 : 0;\n const maxLen = Math.max(a.length, b.length);\n if (maxLen === 0) return 1;\n return 1 - levenshtein(a, b) / maxLen;\n}\n\nfunction* simpleReplacer(content: string, find: string): Generator<string, void, unknown> {\n if (content.includes(find)) yield find;\n}\n\nfunction* lineTrimmedReplacer(content: string, find: string): Generator<string, void, unknown> {\n const lines = find.split(\"\\n\").map(l => l.trim());\n const contentLines = content.split(\"\\n\");\n for (let i = 0; i <= contentLines.length - lines.length; i++) {\n if (contentLines.slice(i, i + lines.length).every((cl, idx) => cl.trim() === lines[idx])) {\n yield contentLines.slice(i, i + lines.length).join(\"\\n\");\n }\n }\n}\n\nfunction* blockAnchorReplacer(content: string, find: string): Generator<string, void, unknown> {\n const findLines = find.split(\"\\n\");\n const contentLines = content.split(\"\\n\");\n\n if (findLines.length < 2) return;\n\n const firstLine = findLines[0];\n const lastLine = findLines[findLines.length - 1];\n const middleLines = findLines.slice(1, -1);\n\n for (let i = 0; i <= contentLines.length - findLines.length; i++) {\n if (contentLines[i] !== firstLine) continue;\n const endIdx = i + findLines.length - 1;\n if (contentLines[endIdx] !== lastLine) continue;\n\n const candidates: { idx: number; score: number }[] = [];\n\n for (let j = i + 1; j < endIdx; j++) {\n candidates.push({ idx: j, score: 0 });\n }\n\n let totalScore = 0;\n for (let k = 0; k < middleLines.length; k++) {\n const contentLine = contentLines[i + 1 + k];\n const sim = similarity(middleLines[k], contentLine);\n totalScore += sim;\n if (candidates[k]) candidates[k].score = sim;\n }\n\n const avgScore = totalScore / middleLines.length;\n const threshold = candidates.length > 1 ? 0.3 : 0.0;\n\n if (avgScore >= threshold) {\n yield contentLines.slice(i, i + findLines.length).join(\"\\n\");\n }\n }\n}\n\nfunction* whitespaceNormalizedReplacer(content: string, find: string): Generator<string, void, unknown> {\n const normFind = find.replace(/\\s+/g, \" \").trim();\n if (!normFind) return;\n const normContent = content.replace(/\\s+/g, \" \").trim();\n const idx = normContent.indexOf(normFind);\n if (idx === -1) return;\n\n const firstWord = normFind.split(\" \")[0];\n const lastWord = normFind.split(\" \").filter(Boolean).pop()!;\n const firstIdx = content.indexOf(firstWord);\n const lastIdx = content.lastIndexOf(lastWord);\n if (firstIdx === -1 || lastIdx === -1 || lastIdx < firstIdx) return;\n\n yield content.substring(firstIdx, lastIdx + lastWord.length);\n}\n\nfunction* indentationFlexibleReplacer(content: string, find: string): Generator<string, void, unknown> {\n const lines = find.split(\"\\n\");\n const minIndent = Math.min(...lines.filter(l => l.trim().length > 0).map(l => l.match(/^(\\s*)/)?.[1].length ?? 0));\n const dedented = lines.map(l => l.substring(minIndent)).join(\"\\n\");\n if (content.includes(dedented)) yield dedented;\n}\n\nfunction* escapeNormalizedReplacer(content: string, find: string): Generator<string, void, unknown> {\n const normalized = find\n .replace(/\\\\n/g, \"\\n\")\n .replace(/\\\\t/g, \"\\t\")\n .replace(/\\\\\"/g, '\"')\n .replace(/\\\\'/g, \"'\");\n if (content.includes(normalized)) yield normalized;\n}\n\nfunction* trimmedBoundaryReplacer(content: string, find: string): Generator<string, void, unknown> {\n const trimmed = find.trim();\n if (content.includes(trimmed)) yield trimmed;\n}\n\nfunction* contextAwareReplacer(content: string, find: string): Generator<string, void, unknown> {\n const findLines = find.split(\"\\n\");\n if (findLines.length < 3) return;\n\n const firstLine = findLines[0].trim();\n const lastLine = findLines[findLines.length - 1].trim();\n const contentLines = content.split(\"\\n\");\n\n for (let i = 0; i <= contentLines.length - 3; i++) {\n if (contentLines[i].trim() !== firstLine) continue;\n\n let bestEndIdx = -1;\n let bestScore = 0;\n\n for (let j = i + 2; j < contentLines.length; j++) {\n if (contentLines[j].trim() === lastLine) {\n const middleCount = j - i - 1;\n let matchCount = 0;\n for (let k = 1; k <= middleCount; k++) {\n const fIdx = Math.floor((k / (middleCount + 1)) * (findLines.length - 2));\n if (fIdx >= 0 && fIdx < findLines.length - 2) {\n if (similarity(contentLines[i + k].trim(), findLines[fIdx + 1].trim()) > 0.5) {\n matchCount++;\n }\n }\n }\n const score = matchCount / middleCount;\n if (score > bestScore) {\n bestScore = score;\n bestEndIdx = j;\n }\n }\n }\n\n if (bestEndIdx !== -1 && bestScore > 0.5) {\n yield contentLines.slice(i, bestEndIdx + 1).join(\"\\n\");\n }\n }\n}\n\nconst REPLACERS: ReplacerFn[] = [\n simpleReplacer,\n lineTrimmedReplacer,\n blockAnchorReplacer,\n whitespaceNormalizedReplacer,\n indentationFlexibleReplacer,\n escapeNormalizedReplacer,\n trimmedBoundaryReplacer,\n contextAwareReplacer,\n];\n\nexport function fuzzyReplace(\n content: string,\n oldString: string,\n newString: string,\n replaceAll = false,\n): string {\n for (const replacer of REPLACERS) {\n for (const search of replacer(content, oldString)) {\n const idx = content.indexOf(search);\n if (idx === -1) continue;\n\n if (replaceAll) {\n return content.split(search).join(newString);\n }\n\n const firstIdx = content.indexOf(search);\n const lastIdx = content.lastIndexOf(search);\n if (firstIdx !== lastIdx) continue;\n\n return content.substring(0, firstIdx) + newString + content.substring(firstIdx + search.length);\n }\n }\n\n throw new FuzzyEditError(\"not_found\", `Could not find match for replacement (after 8 fuzzy strategies)`);\n}\n\nexport function fuzzyContains(content: string, find: string): boolean {\n try {\n fuzzyReplace(content, find, \"PLACEHOLDER_CHECK\");\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EACxC,YAA4B,MAAiC,SAAiB;AAC5E,UAAM,OAAO;AADa;AAE1B,SAAK,OAAO;AAAA,EACd;AAAA,EAH4B;AAI9B;AAEA,SAAS,YAAY,GAAW,GAAmB;AACjD,QAAM,IAAI,EAAE;AACZ,QAAM,IAAI,EAAE;AACZ,MAAI,MAAM,EAAG,QAAO;AACpB,MAAI,MAAM,EAAG,QAAO;AACpB,QAAM,KAAiB,MAAM,KAAK,EAAE,QAAQ,IAAI,EAAE,GAAG,MAAM,IAAI,MAAM,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;AACnF,WAAS,IAAI,GAAG,KAAK,GAAG,IAAK,IAAG,CAAC,EAAE,CAAC,IAAI;AACxC,WAAS,IAAI,GAAG,KAAK,GAAG,IAAK,IAAG,CAAC,EAAE,CAAC,IAAI;AACxC,WAAS,IAAI,GAAG,KAAK,GAAG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AY,QAAQ,UAAU,WAAW,OAAO,MAAM;AAAA,IAChG;AAAA,EACF;AAEA,QAAM,IAAI,eAAe,aAAa,iEAAiE;AACzG;AAEO,SAAS,cAAc,SAAiB,MAAuB;AACpE,MAAI;AACF,iBAAa,SAAS,MAAM,mBAAmB;AAC/C,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type ReplacerFn = (content: string, find: string) => Generator<string, void, unknown>;
|
|
2
|
+
declare class FuzzyEditError extends Error {
|
|
3
|
+
readonly kind: "not_found" | "ambiguous";
|
|
4
|
+
constructor(kind: "not_found" | "ambiguous", message: string);
|
|
5
|
+
}
|
|
6
|
+
declare function fuzzyReplace(content: string, oldString: string, newString: string, replaceAll?: boolean): string;
|
|
7
|
+
declare function fuzzyContains(content: string, find: string): boolean;
|
|
8
|
+
|
|
9
|
+
export { FuzzyEditError, type ReplacerFn, fuzzyContains, fuzzyReplace };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type ReplacerFn = (content: string, find: string) => Generator<string, void, unknown>;
|
|
2
|
+
declare class FuzzyEditError extends Error {
|
|
3
|
+
readonly kind: "not_found" | "ambiguous";
|
|
4
|
+
constructor(kind: "not_found" | "ambiguous", message: string);
|
|
5
|
+
}
|
|
6
|
+
declare function fuzzyReplace(content: string, oldString: string, newString: string, replaceAll?: boolean): string;
|
|
7
|
+
declare function fuzzyContains(content: string, find: string): boolean;
|
|
8
|
+
|
|
9
|
+
export { FuzzyEditError, type ReplacerFn, fuzzyContains, fuzzyReplace };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|