@cremini/skillpack 1.2.8 → 1.2.9

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.
Files changed (2) hide show
  1. package/dist/cli.js +114 -48
  2. package/package.json +2 -3
package/dist/cli.js CHANGED
@@ -2694,7 +2694,7 @@ var ResultsQueryService = class {
2694
2694
  constructor(resultStore) {
2695
2695
  this.resultStore = resultStore;
2696
2696
  }
2697
- listRecentArtifacts(options = {}) {
2697
+ async listRecentArtifacts(options = {}) {
2698
2698
  return this.resultStore.listRecentArtifacts({
2699
2699
  channelId: options.channelId,
2700
2700
  limit: clampLimit(options.limit, 100, 500),
@@ -2865,7 +2865,7 @@ var ArtifactPersistenceService = class {
2865
2865
  this.snapshotService = snapshotService;
2866
2866
  this.resultStore = resultStore;
2867
2867
  }
2868
- saveArtifacts(input) {
2868
+ async saveArtifacts(input) {
2869
2869
  const declaredAt = (/* @__PURE__ */ new Date()).toISOString();
2870
2870
  const snapshots = this.snapshotService.createSnapshots(
2871
2871
  input.runId,
@@ -2873,7 +2873,7 @@ var ArtifactPersistenceService = class {
2873
2873
  declaredAt
2874
2874
  );
2875
2875
  try {
2876
- this.resultStore.insertArtifacts({
2876
+ await this.resultStore.insertArtifacts({
2877
2877
  runId: input.runId,
2878
2878
  channelId: input.channelId,
2879
2879
  artifacts: snapshots
@@ -2892,7 +2892,7 @@ var ArtifactPersistenceService = class {
2892
2892
  import fs10 from "fs";
2893
2893
  import path10 from "path";
2894
2894
  import { randomUUID as randomUUID2 } from "crypto";
2895
- import Database from "better-sqlite3";
2895
+ import sqlite3 from "sqlite3";
2896
2896
  function mapArtifactRow(row) {
2897
2897
  return {
2898
2898
  artifactId: row.artifact_id,
@@ -2909,16 +2909,17 @@ function mapArtifactRow(row) {
2909
2909
  };
2910
2910
  }
2911
2911
  var ResultStore = class {
2912
- db;
2912
+ db = null;
2913
+ ready;
2913
2914
  constructor(rootDir) {
2914
2915
  const dataDir = path10.resolve(rootDir, "data");
2915
2916
  fs10.mkdirSync(dataDir, { recursive: true });
2916
- this.db = new Database(path10.join(dataDir, "result.db"));
2917
- this.db.pragma("journal_mode = WAL");
2918
- this.initialize();
2917
+ this.ready = this.initialize(path10.join(dataDir, "result-v2.db"));
2919
2918
  }
2920
- initialize() {
2921
- this.db.exec(`
2919
+ async initialize(databasePath) {
2920
+ this.db = await openDatabase(databasePath);
2921
+ await this.exec("PRAGMA journal_mode = WAL");
2922
+ await this.exec(`
2922
2923
  CREATE TABLE IF NOT EXISTS artifacts (
2923
2924
  artifact_id TEXT PRIMARY KEY,
2924
2925
  run_id TEXT NOT NULL,
@@ -2937,11 +2938,12 @@ var ResultStore = class {
2937
2938
  ON artifacts(channel_id, declared_at DESC);
2938
2939
  `);
2939
2940
  }
2940
- insertArtifacts(input) {
2941
+ async insertArtifacts(input) {
2942
+ await this.ready;
2941
2943
  if (input.artifacts.length === 0) {
2942
2944
  return;
2943
2945
  }
2944
- const insertArtifact = this.db.prepare(`
2946
+ const insertArtifact = `
2945
2947
  INSERT INTO artifacts (
2946
2948
  artifact_id,
2947
2949
  run_id,
@@ -2955,39 +2957,44 @@ var ResultStore = class {
2955
2957
  is_primary,
2956
2958
  declared_at
2957
2959
  ) VALUES (
2958
- @artifactId,
2959
- @runId,
2960
- @channelId,
2961
- @originalPath,
2962
- @snapshotPath,
2963
- @fileName,
2964
- @mimeType,
2965
- @sizeBytes,
2966
- @title,
2967
- @isPrimary,
2968
- @declaredAt
2960
+ ?,
2961
+ ?,
2962
+ ?,
2963
+ ?,
2964
+ ?,
2965
+ ?,
2966
+ ?,
2967
+ ?,
2968
+ ?,
2969
+ ?,
2970
+ ?
2969
2971
  )
2970
- `);
2971
- const transaction = this.db.transaction((payload) => {
2972
- for (const artifact of payload.artifacts) {
2973
- insertArtifact.run({
2974
- artifactId: randomUUID2(),
2975
- runId: payload.runId,
2976
- channelId: payload.channelId,
2977
- originalPath: artifact.originalPath,
2978
- snapshotPath: artifact.snapshotPath,
2979
- fileName: artifact.fileName,
2980
- mimeType: artifact.mimeType ?? null,
2981
- sizeBytes: artifact.sizeBytes,
2982
- title: artifact.title ?? null,
2983
- isPrimary: artifact.isPrimary ? 1 : 0,
2984
- declaredAt: artifact.declaredAt
2985
- });
2986
- }
2987
- });
2988
- transaction(input);
2972
+ `;
2973
+ await this.exec("BEGIN");
2974
+ try {
2975
+ for (const artifact of input.artifacts) {
2976
+ await this.run(insertArtifact, [
2977
+ randomUUID2(),
2978
+ input.runId,
2979
+ input.channelId,
2980
+ artifact.originalPath,
2981
+ artifact.snapshotPath,
2982
+ artifact.fileName,
2983
+ artifact.mimeType ?? null,
2984
+ artifact.sizeBytes,
2985
+ artifact.title ?? null,
2986
+ artifact.isPrimary ? 1 : 0,
2987
+ artifact.declaredAt
2988
+ ]);
2989
+ }
2990
+ await this.exec("COMMIT");
2991
+ } catch (error) {
2992
+ await this.rollback();
2993
+ throw error;
2994
+ }
2989
2995
  }
2990
- listRecentArtifacts(options = {}) {
2996
+ async listRecentArtifacts(options = {}) {
2997
+ await this.ready;
2991
2998
  const limit = options.limit ?? 100;
2992
2999
  const offset = options.offset ?? 0;
2993
3000
  const conditions = [];
@@ -2997,16 +3004,75 @@ var ResultStore = class {
2997
3004
  params.push(options.channelId);
2998
3005
  }
2999
3006
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
3000
- const rows = this.db.prepare(`
3007
+ const rows = await this.all(`
3001
3008
  SELECT *
3002
3009
  FROM artifacts
3003
3010
  ${whereClause}
3004
3011
  ORDER BY declared_at DESC, rowid DESC
3005
3012
  LIMIT ? OFFSET ?
3006
- `).all(...params, limit, offset);
3013
+ `, [...params, limit, offset]);
3007
3014
  return rows.map(mapArtifactRow);
3008
3015
  }
3016
+ getDatabase() {
3017
+ if (!this.db) {
3018
+ throw new Error("Result store database is not ready");
3019
+ }
3020
+ return this.db;
3021
+ }
3022
+ exec(sql) {
3023
+ const db = this.getDatabase();
3024
+ return new Promise((resolve, reject) => {
3025
+ db.exec(sql, (error) => {
3026
+ if (error) {
3027
+ reject(error);
3028
+ return;
3029
+ }
3030
+ resolve();
3031
+ });
3032
+ });
3033
+ }
3034
+ run(sql, params = []) {
3035
+ const db = this.getDatabase();
3036
+ return new Promise((resolve, reject) => {
3037
+ db.run(sql, params, (error) => {
3038
+ if (error) {
3039
+ reject(error);
3040
+ return;
3041
+ }
3042
+ resolve();
3043
+ });
3044
+ });
3045
+ }
3046
+ all(sql, params = []) {
3047
+ const db = this.getDatabase();
3048
+ return new Promise((resolve, reject) => {
3049
+ db.all(sql, params, (error, rows) => {
3050
+ if (error) {
3051
+ reject(error);
3052
+ return;
3053
+ }
3054
+ resolve(rows);
3055
+ });
3056
+ });
3057
+ }
3058
+ async rollback() {
3059
+ try {
3060
+ await this.exec("ROLLBACK");
3061
+ } catch {
3062
+ }
3063
+ }
3009
3064
  };
3065
+ function openDatabase(databasePath) {
3066
+ return new Promise((resolve, reject) => {
3067
+ const db = new sqlite3.Database(databasePath, (error) => {
3068
+ if (error) {
3069
+ reject(error);
3070
+ return;
3071
+ }
3072
+ resolve(db);
3073
+ });
3074
+ });
3075
+ }
3010
3076
 
3011
3077
  // src/runtime/artifacts/save-artifacts-tool.ts
3012
3078
  import { Type } from "@sinclair/typebox";
@@ -4495,12 +4561,12 @@ var WebAdapter = class {
4495
4561
  )
4496
4562
  );
4497
4563
  });
4498
- app.get("/api/results/artifacts", (req, res) => {
4564
+ app.get("/api/results/artifacts", async (req, res) => {
4499
4565
  if (!resultsQueryService) {
4500
4566
  res.status(503).json({ error: "Results query service is not available" });
4501
4567
  return;
4502
4568
  }
4503
- res.json(resultsQueryService.listRecentArtifacts({
4569
+ res.json(await resultsQueryService.listRecentArtifacts({
4504
4570
  channelId: typeof req.query.channelId === "string" ? req.query.channelId : void 0,
4505
4571
  limit: parsePositiveInt(req.query.limit, 100),
4506
4572
  offset: parsePositiveInt(req.query.offset, 0)
@@ -4819,7 +4885,7 @@ var IpcAdapter = class {
4819
4885
  this.replyError(request.id, "Results query service is not available");
4820
4886
  return;
4821
4887
  }
4822
- this.reply(request.id, this.resultsQueryService.listRecentArtifacts({
4888
+ this.reply(request.id, await this.resultsQueryService.listRecentArtifacts({
4823
4889
  channelId: request.channelId,
4824
4890
  limit: request.limit,
4825
4891
  offset: request.offset
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cremini/skillpack",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "Pack AI Skills into Local Agents",
5
5
  "type": "module",
6
6
  "repository": {
@@ -49,18 +49,17 @@
49
49
  "@slack/bolt": "^4.6.0",
50
50
  "ajv": "^8.17.1",
51
51
  "archiver": "^7.0.1",
52
- "better-sqlite3": "^11.10.0",
53
52
  "chalk": "^5.6.2",
54
53
  "commander": "^14.0.3",
55
54
  "express": "^5.1.0",
56
55
  "inquirer": "^13.3.0",
57
56
  "node-cron": "^4.2.1",
58
57
  "node-telegram-bot-api": "^0.66.0",
58
+ "sqlite3": "^5.1.7",
59
59
  "ws": "^8.19.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/archiver": "^7.0.0",
63
- "@types/better-sqlite3": "^7.6.13",
64
63
  "@types/express": "^5.0.0",
65
64
  "@types/inquirer": "^9.0.9",
66
65
  "@types/node": "^25.5.0",