@axiom-lattice/pg-stores 1.0.4 → 1.0.5
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +9 -0
- package/dist/index.d.mts +99 -3
- package/dist/index.d.ts +99 -3
- package/dist/index.js +340 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +338 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +6 -0
- package/src/migrations/skill_migrations.ts +65 -0
- package/src/stores/PostgreSQLSkillStore.ts +455 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @axiom-lattice/pg-stores@1.0.
|
|
2
|
+
> @axiom-lattice/pg-stores@1.0.5 build /home/runner/work/agentic/agentic/packages/pg-stores
|
|
3
3
|
> tsup src/index.ts --format cjs,esm --dts --sourcemap
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
[34mCLI[39m Target: es2020
|
|
9
9
|
[34mCJS[39m Build start
|
|
10
10
|
[34mESM[39m Build start
|
|
11
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
12
|
-
[32mCJS[39m [1mdist/index.js.map [22m[
|
|
13
|
-
[32mCJS[39m ⚡️ Build success in
|
|
14
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
15
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[
|
|
16
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m44.48 KB[39m
|
|
12
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m80.78 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 211ms
|
|
14
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m42.89 KB[39m
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m79.49 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 213ms
|
|
17
17
|
[34mDTS[39m Build start
|
|
18
|
-
[32mDTS[39m ⚡️ Build success in
|
|
19
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
18
|
+
[32mDTS[39m ⚡️ Build success in 7685ms
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m11.23 KB[39m
|
|
20
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m11.23 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PoolConfig, PoolClient, Pool } from 'pg';
|
|
2
|
-
import { ThreadStore, Thread, CreateThreadRequest, AssistantStore, Assistant, CreateAssistantRequest, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, ScheduleExecutionType } from '@axiom-lattice/protocols';
|
|
3
|
-
export { Assistant, AssistantStore, CreateAssistantRequest, CreateThreadRequest, ScheduleExecutionType, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, Thread, ThreadStore } from '@axiom-lattice/protocols';
|
|
2
|
+
import { ThreadStore, Thread, CreateThreadRequest, AssistantStore, Assistant, CreateAssistantRequest, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, ScheduleExecutionType, SkillStore, Skill, CreateSkillRequest } from '@axiom-lattice/protocols';
|
|
3
|
+
export { Assistant, AssistantStore, CreateAssistantRequest, CreateSkillRequest, CreateThreadRequest, ScheduleExecutionType, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, Skill, SkillStore, Thread, ThreadStore } from '@axiom-lattice/protocols';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* PostgreSQL implementation of ThreadStore
|
|
@@ -258,6 +258,93 @@ declare class PostgreSQLScheduleStorage implements ScheduleStorage {
|
|
|
258
258
|
private mapRowToTask;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
/**
|
|
262
|
+
* PostgreSQL implementation of SkillStore
|
|
263
|
+
*/
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* PostgreSQL SkillStore options
|
|
267
|
+
*/
|
|
268
|
+
interface PostgreSQLSkillStoreOptions {
|
|
269
|
+
/**
|
|
270
|
+
* PostgreSQL connection pool configuration
|
|
271
|
+
* Can be a connection string or PoolConfig object
|
|
272
|
+
*/
|
|
273
|
+
poolConfig: string | PoolConfig;
|
|
274
|
+
/**
|
|
275
|
+
* Whether to run migrations automatically on initialization
|
|
276
|
+
* @default true
|
|
277
|
+
*/
|
|
278
|
+
autoMigrate?: boolean;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* PostgreSQL implementation of SkillStore
|
|
282
|
+
*/
|
|
283
|
+
declare class PostgreSQLSkillStore implements SkillStore {
|
|
284
|
+
private pool;
|
|
285
|
+
private migrationManager;
|
|
286
|
+
private initialized;
|
|
287
|
+
private ownsPool;
|
|
288
|
+
constructor(options: PostgreSQLSkillStoreOptions);
|
|
289
|
+
/**
|
|
290
|
+
* Dispose resources and close the connection pool
|
|
291
|
+
* Should be called when the store is no longer needed
|
|
292
|
+
*/
|
|
293
|
+
dispose(): Promise<void>;
|
|
294
|
+
/**
|
|
295
|
+
* Initialize the store and run migrations
|
|
296
|
+
*/
|
|
297
|
+
initialize(): Promise<void>;
|
|
298
|
+
/**
|
|
299
|
+
* Ensure store is initialized
|
|
300
|
+
*/
|
|
301
|
+
private ensureInitialized;
|
|
302
|
+
/**
|
|
303
|
+
* Map database row to Skill object
|
|
304
|
+
*/
|
|
305
|
+
private mapRowToSkill;
|
|
306
|
+
/**
|
|
307
|
+
* Get all skills
|
|
308
|
+
*/
|
|
309
|
+
getAllSkills(): Promise<Skill[]>;
|
|
310
|
+
/**
|
|
311
|
+
* Get skill by ID
|
|
312
|
+
*/
|
|
313
|
+
getSkillById(id: string): Promise<Skill | null>;
|
|
314
|
+
/**
|
|
315
|
+
* Create a new skill
|
|
316
|
+
*/
|
|
317
|
+
createSkill(id: string, data: CreateSkillRequest): Promise<Skill>;
|
|
318
|
+
/**
|
|
319
|
+
* Update an existing skill
|
|
320
|
+
*/
|
|
321
|
+
updateSkill(id: string, updates: Partial<CreateSkillRequest>): Promise<Skill | null>;
|
|
322
|
+
/**
|
|
323
|
+
* Delete a skill by ID
|
|
324
|
+
*/
|
|
325
|
+
deleteSkill(id: string): Promise<boolean>;
|
|
326
|
+
/**
|
|
327
|
+
* Check if skill exists
|
|
328
|
+
*/
|
|
329
|
+
hasSkill(id: string): Promise<boolean>;
|
|
330
|
+
/**
|
|
331
|
+
* Search skills by metadata
|
|
332
|
+
*/
|
|
333
|
+
searchByMetadata(metadataKey: string, metadataValue: string): Promise<Skill[]>;
|
|
334
|
+
/**
|
|
335
|
+
* Filter skills by compatibility
|
|
336
|
+
*/
|
|
337
|
+
filterByCompatibility(compatibility: string): Promise<Skill[]>;
|
|
338
|
+
/**
|
|
339
|
+
* Filter skills by license
|
|
340
|
+
*/
|
|
341
|
+
filterByLicense(license: string): Promise<Skill[]>;
|
|
342
|
+
/**
|
|
343
|
+
* Get sub-skills of a parent skill
|
|
344
|
+
*/
|
|
345
|
+
getSubSkills(parentSkillName: string): Promise<Skill[]>;
|
|
346
|
+
}
|
|
347
|
+
|
|
261
348
|
/**
|
|
262
349
|
* Migration system for database schema management
|
|
263
350
|
*/
|
|
@@ -331,4 +418,13 @@ declare const createAssistantsTable: Migration;
|
|
|
331
418
|
*/
|
|
332
419
|
declare const createScheduledTasksTable: Migration;
|
|
333
420
|
|
|
334
|
-
|
|
421
|
+
/**
|
|
422
|
+
* Skill table migrations
|
|
423
|
+
*/
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Initial migration: Create skills table
|
|
427
|
+
*/
|
|
428
|
+
declare const createSkillsTable: Migration;
|
|
429
|
+
|
|
430
|
+
export { type Migration, MigrationManager, PostgreSQLAssistantStore, type PostgreSQLAssistantStoreOptions, PostgreSQLScheduleStorage, type PostgreSQLScheduleStorageOptions, PostgreSQLSkillStore, type PostgreSQLSkillStoreOptions, PostgreSQLThreadStore, type PostgreSQLThreadStoreOptions, createAssistantsTable, createScheduledTasksTable, createSkillsTable, createThreadsTable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PoolConfig, PoolClient, Pool } from 'pg';
|
|
2
|
-
import { ThreadStore, Thread, CreateThreadRequest, AssistantStore, Assistant, CreateAssistantRequest, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, ScheduleExecutionType } from '@axiom-lattice/protocols';
|
|
3
|
-
export { Assistant, AssistantStore, CreateAssistantRequest, CreateThreadRequest, ScheduleExecutionType, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, Thread, ThreadStore } from '@axiom-lattice/protocols';
|
|
2
|
+
import { ThreadStore, Thread, CreateThreadRequest, AssistantStore, Assistant, CreateAssistantRequest, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, ScheduleExecutionType, SkillStore, Skill, CreateSkillRequest } from '@axiom-lattice/protocols';
|
|
3
|
+
export { Assistant, AssistantStore, CreateAssistantRequest, CreateSkillRequest, CreateThreadRequest, ScheduleExecutionType, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, Skill, SkillStore, Thread, ThreadStore } from '@axiom-lattice/protocols';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* PostgreSQL implementation of ThreadStore
|
|
@@ -258,6 +258,93 @@ declare class PostgreSQLScheduleStorage implements ScheduleStorage {
|
|
|
258
258
|
private mapRowToTask;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
/**
|
|
262
|
+
* PostgreSQL implementation of SkillStore
|
|
263
|
+
*/
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* PostgreSQL SkillStore options
|
|
267
|
+
*/
|
|
268
|
+
interface PostgreSQLSkillStoreOptions {
|
|
269
|
+
/**
|
|
270
|
+
* PostgreSQL connection pool configuration
|
|
271
|
+
* Can be a connection string or PoolConfig object
|
|
272
|
+
*/
|
|
273
|
+
poolConfig: string | PoolConfig;
|
|
274
|
+
/**
|
|
275
|
+
* Whether to run migrations automatically on initialization
|
|
276
|
+
* @default true
|
|
277
|
+
*/
|
|
278
|
+
autoMigrate?: boolean;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* PostgreSQL implementation of SkillStore
|
|
282
|
+
*/
|
|
283
|
+
declare class PostgreSQLSkillStore implements SkillStore {
|
|
284
|
+
private pool;
|
|
285
|
+
private migrationManager;
|
|
286
|
+
private initialized;
|
|
287
|
+
private ownsPool;
|
|
288
|
+
constructor(options: PostgreSQLSkillStoreOptions);
|
|
289
|
+
/**
|
|
290
|
+
* Dispose resources and close the connection pool
|
|
291
|
+
* Should be called when the store is no longer needed
|
|
292
|
+
*/
|
|
293
|
+
dispose(): Promise<void>;
|
|
294
|
+
/**
|
|
295
|
+
* Initialize the store and run migrations
|
|
296
|
+
*/
|
|
297
|
+
initialize(): Promise<void>;
|
|
298
|
+
/**
|
|
299
|
+
* Ensure store is initialized
|
|
300
|
+
*/
|
|
301
|
+
private ensureInitialized;
|
|
302
|
+
/**
|
|
303
|
+
* Map database row to Skill object
|
|
304
|
+
*/
|
|
305
|
+
private mapRowToSkill;
|
|
306
|
+
/**
|
|
307
|
+
* Get all skills
|
|
308
|
+
*/
|
|
309
|
+
getAllSkills(): Promise<Skill[]>;
|
|
310
|
+
/**
|
|
311
|
+
* Get skill by ID
|
|
312
|
+
*/
|
|
313
|
+
getSkillById(id: string): Promise<Skill | null>;
|
|
314
|
+
/**
|
|
315
|
+
* Create a new skill
|
|
316
|
+
*/
|
|
317
|
+
createSkill(id: string, data: CreateSkillRequest): Promise<Skill>;
|
|
318
|
+
/**
|
|
319
|
+
* Update an existing skill
|
|
320
|
+
*/
|
|
321
|
+
updateSkill(id: string, updates: Partial<CreateSkillRequest>): Promise<Skill | null>;
|
|
322
|
+
/**
|
|
323
|
+
* Delete a skill by ID
|
|
324
|
+
*/
|
|
325
|
+
deleteSkill(id: string): Promise<boolean>;
|
|
326
|
+
/**
|
|
327
|
+
* Check if skill exists
|
|
328
|
+
*/
|
|
329
|
+
hasSkill(id: string): Promise<boolean>;
|
|
330
|
+
/**
|
|
331
|
+
* Search skills by metadata
|
|
332
|
+
*/
|
|
333
|
+
searchByMetadata(metadataKey: string, metadataValue: string): Promise<Skill[]>;
|
|
334
|
+
/**
|
|
335
|
+
* Filter skills by compatibility
|
|
336
|
+
*/
|
|
337
|
+
filterByCompatibility(compatibility: string): Promise<Skill[]>;
|
|
338
|
+
/**
|
|
339
|
+
* Filter skills by license
|
|
340
|
+
*/
|
|
341
|
+
filterByLicense(license: string): Promise<Skill[]>;
|
|
342
|
+
/**
|
|
343
|
+
* Get sub-skills of a parent skill
|
|
344
|
+
*/
|
|
345
|
+
getSubSkills(parentSkillName: string): Promise<Skill[]>;
|
|
346
|
+
}
|
|
347
|
+
|
|
261
348
|
/**
|
|
262
349
|
* Migration system for database schema management
|
|
263
350
|
*/
|
|
@@ -331,4 +418,13 @@ declare const createAssistantsTable: Migration;
|
|
|
331
418
|
*/
|
|
332
419
|
declare const createScheduledTasksTable: Migration;
|
|
333
420
|
|
|
334
|
-
|
|
421
|
+
/**
|
|
422
|
+
* Skill table migrations
|
|
423
|
+
*/
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Initial migration: Create skills table
|
|
427
|
+
*/
|
|
428
|
+
declare const createSkillsTable: Migration;
|
|
429
|
+
|
|
430
|
+
export { type Migration, MigrationManager, PostgreSQLAssistantStore, type PostgreSQLAssistantStoreOptions, PostgreSQLScheduleStorage, type PostgreSQLScheduleStorageOptions, PostgreSQLSkillStore, type PostgreSQLSkillStoreOptions, PostgreSQLThreadStore, type PostgreSQLThreadStoreOptions, createAssistantsTable, createScheduledTasksTable, createSkillsTable, createThreadsTable };
|
package/dist/index.js
CHANGED
|
@@ -23,9 +23,11 @@ __export(index_exports, {
|
|
|
23
23
|
MigrationManager: () => MigrationManager,
|
|
24
24
|
PostgreSQLAssistantStore: () => PostgreSQLAssistantStore,
|
|
25
25
|
PostgreSQLScheduleStorage: () => PostgreSQLScheduleStorage,
|
|
26
|
+
PostgreSQLSkillStore: () => PostgreSQLSkillStore,
|
|
26
27
|
PostgreSQLThreadStore: () => PostgreSQLThreadStore,
|
|
27
28
|
createAssistantsTable: () => createAssistantsTable,
|
|
28
29
|
createScheduledTasksTable: () => createScheduledTasksTable,
|
|
30
|
+
createSkillsTable: () => createSkillsTable,
|
|
29
31
|
createThreadsTable: () => createThreadsTable
|
|
30
32
|
});
|
|
31
33
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1146,14 +1148,352 @@ var PostgreSQLScheduleStorage = class {
|
|
|
1146
1148
|
};
|
|
1147
1149
|
}
|
|
1148
1150
|
};
|
|
1151
|
+
|
|
1152
|
+
// src/stores/PostgreSQLSkillStore.ts
|
|
1153
|
+
var import_pg4 = require("pg");
|
|
1154
|
+
|
|
1155
|
+
// src/migrations/skill_migrations.ts
|
|
1156
|
+
var createSkillsTable = {
|
|
1157
|
+
version: 1,
|
|
1158
|
+
name: "create_skills_table",
|
|
1159
|
+
up: async (client) => {
|
|
1160
|
+
await client.query(`
|
|
1161
|
+
CREATE TABLE IF NOT EXISTS lattice_skills (
|
|
1162
|
+
id VARCHAR(255) PRIMARY KEY,
|
|
1163
|
+
name VARCHAR(255) NOT NULL,
|
|
1164
|
+
description TEXT NOT NULL,
|
|
1165
|
+
license VARCHAR(255),
|
|
1166
|
+
compatibility VARCHAR(255),
|
|
1167
|
+
metadata JSONB DEFAULT '{}',
|
|
1168
|
+
content TEXT,
|
|
1169
|
+
sub_skills JSONB DEFAULT '[]',
|
|
1170
|
+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
1171
|
+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
1172
|
+
)
|
|
1173
|
+
`);
|
|
1174
|
+
await client.query(`
|
|
1175
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_skills_name
|
|
1176
|
+
ON lattice_skills(name)
|
|
1177
|
+
`);
|
|
1178
|
+
await client.query(`
|
|
1179
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_skills_license
|
|
1180
|
+
ON lattice_skills(license)
|
|
1181
|
+
`);
|
|
1182
|
+
await client.query(`
|
|
1183
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_skills_compatibility
|
|
1184
|
+
ON lattice_skills(compatibility)
|
|
1185
|
+
`);
|
|
1186
|
+
await client.query(`
|
|
1187
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_skills_created_at
|
|
1188
|
+
ON lattice_skills(created_at DESC)
|
|
1189
|
+
`);
|
|
1190
|
+
await client.query(`
|
|
1191
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_skills_metadata
|
|
1192
|
+
ON lattice_skills USING GIN (metadata)
|
|
1193
|
+
`);
|
|
1194
|
+
},
|
|
1195
|
+
down: async (client) => {
|
|
1196
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_skills_metadata");
|
|
1197
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_skills_created_at");
|
|
1198
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_skills_compatibility");
|
|
1199
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_skills_license");
|
|
1200
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_skills_name");
|
|
1201
|
+
await client.query("DROP TABLE IF EXISTS lattice_skills");
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
|
|
1205
|
+
// src/stores/PostgreSQLSkillStore.ts
|
|
1206
|
+
var PostgreSQLSkillStore = class {
|
|
1207
|
+
constructor(options) {
|
|
1208
|
+
this.initialized = false;
|
|
1209
|
+
this.ownsPool = true;
|
|
1210
|
+
if (typeof options.poolConfig === "string") {
|
|
1211
|
+
this.pool = new import_pg4.Pool({ connectionString: options.poolConfig });
|
|
1212
|
+
} else {
|
|
1213
|
+
this.pool = new import_pg4.Pool(options.poolConfig);
|
|
1214
|
+
}
|
|
1215
|
+
this.migrationManager = new MigrationManager(this.pool);
|
|
1216
|
+
this.migrationManager.register(createSkillsTable);
|
|
1217
|
+
if (options.autoMigrate !== false) {
|
|
1218
|
+
this.initialize().catch((error) => {
|
|
1219
|
+
console.error("Failed to initialize PostgreSQLSkillStore:", error);
|
|
1220
|
+
throw error;
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Dispose resources and close the connection pool
|
|
1226
|
+
* Should be called when the store is no longer needed
|
|
1227
|
+
*/
|
|
1228
|
+
async dispose() {
|
|
1229
|
+
if (this.ownsPool && this.pool) {
|
|
1230
|
+
await this.pool.end();
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Initialize the store and run migrations
|
|
1235
|
+
*/
|
|
1236
|
+
async initialize() {
|
|
1237
|
+
if (this.initialized) {
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
await this.migrationManager.migrate();
|
|
1241
|
+
this.initialized = true;
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Ensure store is initialized
|
|
1245
|
+
*/
|
|
1246
|
+
async ensureInitialized() {
|
|
1247
|
+
if (!this.initialized) {
|
|
1248
|
+
await this.initialize();
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Map database row to Skill object
|
|
1253
|
+
*/
|
|
1254
|
+
mapRowToSkill(row) {
|
|
1255
|
+
return {
|
|
1256
|
+
id: row.id,
|
|
1257
|
+
name: row.name,
|
|
1258
|
+
description: row.description,
|
|
1259
|
+
license: row.license || void 0,
|
|
1260
|
+
compatibility: row.compatibility || void 0,
|
|
1261
|
+
metadata: row.metadata || {},
|
|
1262
|
+
content: row.content || void 0,
|
|
1263
|
+
subSkills: Array.isArray(row.sub_skills) && row.sub_skills.length > 0 ? row.sub_skills : void 0,
|
|
1264
|
+
createdAt: row.created_at,
|
|
1265
|
+
updatedAt: row.updated_at
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Get all skills
|
|
1270
|
+
*/
|
|
1271
|
+
async getAllSkills() {
|
|
1272
|
+
await this.ensureInitialized();
|
|
1273
|
+
const result = await this.pool.query(
|
|
1274
|
+
`
|
|
1275
|
+
SELECT id, name, description, license, compatibility, metadata, content, sub_skills, created_at, updated_at
|
|
1276
|
+
FROM lattice_skills
|
|
1277
|
+
ORDER BY created_at DESC
|
|
1278
|
+
`
|
|
1279
|
+
);
|
|
1280
|
+
return result.rows.map(this.mapRowToSkill);
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Get skill by ID
|
|
1284
|
+
*/
|
|
1285
|
+
async getSkillById(id) {
|
|
1286
|
+
await this.ensureInitialized();
|
|
1287
|
+
const result = await this.pool.query(
|
|
1288
|
+
`
|
|
1289
|
+
SELECT id, name, description, license, compatibility, metadata, content, sub_skills, created_at, updated_at
|
|
1290
|
+
FROM lattice_skills
|
|
1291
|
+
WHERE id = $1
|
|
1292
|
+
`,
|
|
1293
|
+
[id]
|
|
1294
|
+
);
|
|
1295
|
+
if (result.rows.length === 0) {
|
|
1296
|
+
return null;
|
|
1297
|
+
}
|
|
1298
|
+
return this.mapRowToSkill(result.rows[0]);
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Create a new skill
|
|
1302
|
+
*/
|
|
1303
|
+
async createSkill(id, data) {
|
|
1304
|
+
await this.ensureInitialized();
|
|
1305
|
+
const now = /* @__PURE__ */ new Date();
|
|
1306
|
+
const metadata = data.metadata || {};
|
|
1307
|
+
await this.pool.query(
|
|
1308
|
+
`
|
|
1309
|
+
INSERT INTO lattice_skills (id, name, description, license, compatibility, metadata, content, sub_skills, created_at, updated_at)
|
|
1310
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
1311
|
+
ON CONFLICT (id) DO UPDATE SET
|
|
1312
|
+
name = EXCLUDED.name,
|
|
1313
|
+
description = EXCLUDED.description,
|
|
1314
|
+
license = EXCLUDED.license,
|
|
1315
|
+
compatibility = EXCLUDED.compatibility,
|
|
1316
|
+
metadata = EXCLUDED.metadata,
|
|
1317
|
+
content = EXCLUDED.content,
|
|
1318
|
+
sub_skills = EXCLUDED.sub_skills,
|
|
1319
|
+
updated_at = EXCLUDED.updated_at
|
|
1320
|
+
`,
|
|
1321
|
+
[
|
|
1322
|
+
id,
|
|
1323
|
+
data.name,
|
|
1324
|
+
data.description,
|
|
1325
|
+
data.license || null,
|
|
1326
|
+
data.compatibility || null,
|
|
1327
|
+
JSON.stringify(metadata),
|
|
1328
|
+
data.content || null,
|
|
1329
|
+
JSON.stringify(data.subSkills || []),
|
|
1330
|
+
now,
|
|
1331
|
+
now
|
|
1332
|
+
]
|
|
1333
|
+
);
|
|
1334
|
+
return this.getSkillById(id);
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Update an existing skill
|
|
1338
|
+
*/
|
|
1339
|
+
async updateSkill(id, updates) {
|
|
1340
|
+
await this.ensureInitialized();
|
|
1341
|
+
const updateFields = [];
|
|
1342
|
+
const values = [];
|
|
1343
|
+
let paramIndex = 1;
|
|
1344
|
+
if (updates.name !== void 0) {
|
|
1345
|
+
updateFields.push(`name = $${paramIndex++}`);
|
|
1346
|
+
values.push(updates.name);
|
|
1347
|
+
}
|
|
1348
|
+
if (updates.description !== void 0) {
|
|
1349
|
+
updateFields.push(`description = $${paramIndex++}`);
|
|
1350
|
+
values.push(updates.description);
|
|
1351
|
+
}
|
|
1352
|
+
if (updates.license !== void 0) {
|
|
1353
|
+
updateFields.push(`license = $${paramIndex++}`);
|
|
1354
|
+
values.push(updates.license || null);
|
|
1355
|
+
}
|
|
1356
|
+
if (updates.compatibility !== void 0) {
|
|
1357
|
+
updateFields.push(`compatibility = $${paramIndex++}`);
|
|
1358
|
+
values.push(updates.compatibility || null);
|
|
1359
|
+
}
|
|
1360
|
+
if (updates.metadata !== void 0) {
|
|
1361
|
+
updateFields.push(`metadata = $${paramIndex++}`);
|
|
1362
|
+
values.push(JSON.stringify(updates.metadata || {}));
|
|
1363
|
+
}
|
|
1364
|
+
if (updates.content !== void 0) {
|
|
1365
|
+
updateFields.push(`content = $${paramIndex++}`);
|
|
1366
|
+
values.push(updates.content || null);
|
|
1367
|
+
}
|
|
1368
|
+
if (updates.subSkills !== void 0) {
|
|
1369
|
+
updateFields.push(`sub_skills = $${paramIndex++}`);
|
|
1370
|
+
values.push(JSON.stringify(updates.subSkills || []));
|
|
1371
|
+
}
|
|
1372
|
+
if (updateFields.length === 0) {
|
|
1373
|
+
return this.getSkillById(id);
|
|
1374
|
+
}
|
|
1375
|
+
updateFields.push(`updated_at = $${paramIndex++}`);
|
|
1376
|
+
values.push(/* @__PURE__ */ new Date());
|
|
1377
|
+
values.push(id);
|
|
1378
|
+
await this.pool.query(
|
|
1379
|
+
`
|
|
1380
|
+
UPDATE lattice_skills
|
|
1381
|
+
SET ${updateFields.join(", ")}
|
|
1382
|
+
WHERE id = $${paramIndex}
|
|
1383
|
+
`,
|
|
1384
|
+
values
|
|
1385
|
+
);
|
|
1386
|
+
return this.getSkillById(id);
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Delete a skill by ID
|
|
1390
|
+
*/
|
|
1391
|
+
async deleteSkill(id) {
|
|
1392
|
+
await this.ensureInitialized();
|
|
1393
|
+
const result = await this.pool.query(
|
|
1394
|
+
`
|
|
1395
|
+
DELETE FROM lattice_skills
|
|
1396
|
+
WHERE id = $1
|
|
1397
|
+
`,
|
|
1398
|
+
[id]
|
|
1399
|
+
);
|
|
1400
|
+
return result.rowCount !== null && result.rowCount > 0;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Check if skill exists
|
|
1404
|
+
*/
|
|
1405
|
+
async hasSkill(id) {
|
|
1406
|
+
await this.ensureInitialized();
|
|
1407
|
+
const result = await this.pool.query(
|
|
1408
|
+
`
|
|
1409
|
+
SELECT COUNT(*) as count
|
|
1410
|
+
FROM lattice_skills
|
|
1411
|
+
WHERE id = $1
|
|
1412
|
+
`,
|
|
1413
|
+
[id]
|
|
1414
|
+
);
|
|
1415
|
+
return parseInt(result.rows[0].count, 10) > 0;
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Search skills by metadata
|
|
1419
|
+
*/
|
|
1420
|
+
async searchByMetadata(metadataKey, metadataValue) {
|
|
1421
|
+
await this.ensureInitialized();
|
|
1422
|
+
const result = await this.pool.query(
|
|
1423
|
+
`
|
|
1424
|
+
SELECT id, name, description, license, compatibility, metadata, content, sub_skills, created_at, updated_at
|
|
1425
|
+
FROM lattice_skills
|
|
1426
|
+
WHERE metadata->>$1 = $2
|
|
1427
|
+
ORDER BY created_at DESC
|
|
1428
|
+
`,
|
|
1429
|
+
[metadataKey, metadataValue]
|
|
1430
|
+
);
|
|
1431
|
+
return result.rows.map(this.mapRowToSkill);
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Filter skills by compatibility
|
|
1435
|
+
*/
|
|
1436
|
+
async filterByCompatibility(compatibility) {
|
|
1437
|
+
await this.ensureInitialized();
|
|
1438
|
+
const result = await this.pool.query(
|
|
1439
|
+
`
|
|
1440
|
+
SELECT id, name, description, license, compatibility, metadata, content, sub_skills, created_at, updated_at
|
|
1441
|
+
FROM lattice_skills
|
|
1442
|
+
WHERE compatibility = $1
|
|
1443
|
+
ORDER BY created_at DESC
|
|
1444
|
+
`,
|
|
1445
|
+
[compatibility]
|
|
1446
|
+
);
|
|
1447
|
+
return result.rows.map(this.mapRowToSkill);
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Filter skills by license
|
|
1451
|
+
*/
|
|
1452
|
+
async filterByLicense(license) {
|
|
1453
|
+
await this.ensureInitialized();
|
|
1454
|
+
const result = await this.pool.query(
|
|
1455
|
+
`
|
|
1456
|
+
SELECT id, name, description, license, compatibility, metadata, content, sub_skills, created_at, updated_at
|
|
1457
|
+
FROM lattice_skills
|
|
1458
|
+
WHERE license = $1
|
|
1459
|
+
ORDER BY created_at DESC
|
|
1460
|
+
`,
|
|
1461
|
+
[license]
|
|
1462
|
+
);
|
|
1463
|
+
return result.rows.map(this.mapRowToSkill);
|
|
1464
|
+
}
|
|
1465
|
+
/**
|
|
1466
|
+
* Get sub-skills of a parent skill
|
|
1467
|
+
*/
|
|
1468
|
+
async getSubSkills(parentSkillName) {
|
|
1469
|
+
await this.ensureInitialized();
|
|
1470
|
+
const parentSkill = await this.getSkillById(parentSkillName);
|
|
1471
|
+
if (!parentSkill || !parentSkill.subSkills || parentSkill.subSkills.length === 0) {
|
|
1472
|
+
return [];
|
|
1473
|
+
}
|
|
1474
|
+
const placeholders = parentSkill.subSkills.map((_, index) => `$${index + 1}`).join(", ");
|
|
1475
|
+
const result = await this.pool.query(
|
|
1476
|
+
`
|
|
1477
|
+
SELECT id, name, description, license, compatibility, metadata, content, sub_skills, created_at, updated_at
|
|
1478
|
+
FROM lattice_skills
|
|
1479
|
+
WHERE name IN (${placeholders})
|
|
1480
|
+
ORDER BY created_at DESC
|
|
1481
|
+
`,
|
|
1482
|
+
parentSkill.subSkills
|
|
1483
|
+
);
|
|
1484
|
+
return result.rows.map(this.mapRowToSkill);
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1149
1487
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1150
1488
|
0 && (module.exports = {
|
|
1151
1489
|
MigrationManager,
|
|
1152
1490
|
PostgreSQLAssistantStore,
|
|
1153
1491
|
PostgreSQLScheduleStorage,
|
|
1492
|
+
PostgreSQLSkillStore,
|
|
1154
1493
|
PostgreSQLThreadStore,
|
|
1155
1494
|
createAssistantsTable,
|
|
1156
1495
|
createScheduledTasksTable,
|
|
1496
|
+
createSkillsTable,
|
|
1157
1497
|
createThreadsTable
|
|
1158
1498
|
});
|
|
1159
1499
|
//# sourceMappingURL=index.js.map
|