@wirecat/cli-template 0.9.0 → 0.11.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.
Files changed (119) hide show
  1. package/.github/workflows/ci.yml +18 -0
  2. package/.github/workflows/release.yml +63 -0
  3. package/CHANGELOG.md +72 -1
  4. package/CLAUDE.md +1 -3
  5. package/bin/release +5 -3
  6. package/contracts/help.snap +2 -0
  7. package/dist/bin/clidev.js +34 -12
  8. package/dist/bundle/all-profiles-MJ6XSFOO.js +24 -0
  9. package/dist/bundle/anthropic-W5UKBZUB.js +70 -0
  10. package/dist/bundle/app-server-EZ46JAHB.js +217 -0
  11. package/dist/bundle/bun-HB6O2TTT.js +169 -0
  12. package/dist/bundle/bun-sqlite-KBXOW2ES.js +69 -0
  13. package/dist/bundle/chunk-2B5U4Z5H.js +100 -0
  14. package/dist/bundle/chunk-35KYY65W.js +122 -0
  15. package/dist/bundle/chunk-4LURWBVV.js +752 -0
  16. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  17. package/dist/bundle/chunk-7IXL4UFK.js +158 -0
  18. package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
  19. package/dist/bundle/chunk-AK257OMS.js +8353 -0
  20. package/dist/bundle/chunk-CXQXVKUY.js +24 -0
  21. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  22. package/dist/bundle/chunk-E42W72PQ.js +151 -0
  23. package/dist/bundle/chunk-EFHLQXG6.js +5104 -0
  24. package/dist/bundle/chunk-EGRB55FF.js +264 -0
  25. package/dist/bundle/chunk-ERGB4NJA.js +53 -0
  26. package/dist/bundle/chunk-ERKR3VJ5.js +1146 -0
  27. package/dist/bundle/chunk-FDBINRWA.js +884 -0
  28. package/dist/bundle/chunk-FZZIU4B7.js +34514 -0
  29. package/dist/bundle/chunk-GOO67PDU.js +2 -0
  30. package/dist/bundle/chunk-HDY5X3WQ.js +281 -0
  31. package/dist/bundle/chunk-HTQTIKWP.js +928 -0
  32. package/dist/bundle/chunk-IBBN7Z3A.js +630 -0
  33. package/dist/bundle/chunk-IDWW4TU2.js +18 -0
  34. package/dist/bundle/chunk-IGHEW777.js +164 -0
  35. package/dist/bundle/chunk-IN3FVRPK.js +76 -0
  36. package/dist/bundle/chunk-JAOGZMKQ.js +48 -0
  37. package/dist/bundle/chunk-JHO2LL2J.js +459 -0
  38. package/dist/bundle/chunk-JRK73FOW.js +78 -0
  39. package/dist/bundle/chunk-KAREKBUZ.js +24 -0
  40. package/dist/bundle/chunk-KJTNT4SW.js +82 -0
  41. package/dist/bundle/chunk-L5WWMP5M.js +1904 -0
  42. package/dist/bundle/chunk-MFS52LTZ.js +570 -0
  43. package/dist/bundle/chunk-MJRSEUKG.js +442 -0
  44. package/dist/bundle/chunk-MUSYGFCY.js +3556 -0
  45. package/dist/bundle/chunk-N2Z3MCOF.js +779 -0
  46. package/dist/bundle/chunk-NOVLCHDV.js +45 -0
  47. package/dist/bundle/chunk-O3UXNU3S.js +54 -0
  48. package/dist/bundle/chunk-O5EHUB2V.js +2 -0
  49. package/dist/bundle/chunk-OV6PHTAY.js +36226 -0
  50. package/dist/bundle/chunk-PBN4RBHS.js +2315 -0
  51. package/dist/bundle/chunk-PDGXMKJS.js +31 -0
  52. package/dist/bundle/chunk-PJOVK7PG.js +191 -0
  53. package/dist/bundle/chunk-QBP7OMN5.js +58 -0
  54. package/dist/bundle/chunk-QJ6XW4DM.js +7556 -0
  55. package/dist/bundle/chunk-QKWRL4OD.js +1028 -0
  56. package/dist/bundle/chunk-RUKDZEID.js +73 -0
  57. package/dist/bundle/chunk-SVDF6NJF.js +215 -0
  58. package/dist/bundle/chunk-TAYOKLGF.js +193 -0
  59. package/dist/bundle/chunk-TGB5F7NC.js +288 -0
  60. package/dist/bundle/chunk-V3ZTQ24B.js +161 -0
  61. package/dist/bundle/chunk-VLNKTMV7.js +3103 -0
  62. package/dist/bundle/chunk-VYSUKHKL.js +63 -0
  63. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  64. package/dist/bundle/chunk-YJNUDHJD.js +3390 -0
  65. package/dist/bundle/chunk-Z7MSIRSQ.js +6848 -0
  66. package/dist/bundle/chunk-ZLY6GUAS.js +82 -0
  67. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  68. package/dist/bundle/clidev.js +22 -0
  69. package/dist/bundle/command-contract-75VJ36U4.js +29 -0
  70. package/dist/bundle/decode-AMXUVKNY.js +158 -0
  71. package/dist/bundle/dist-ESHIQU4M.js +7577 -0
  72. package/dist/bundle/echarts-GJDMQ2AQ.js +42501 -0
  73. package/dist/bundle/embed-L4CRZ2XQ.js +35 -0
  74. package/dist/bundle/embedder-IBGV4M2K.js +108 -0
  75. package/dist/bundle/first-run-VTKC2IBV.js +23 -0
  76. package/dist/bundle/first-screen-X5IJKBSU.js +27 -0
  77. package/dist/bundle/instructions-YJECS4KN.js +11 -0
  78. package/dist/bundle/mcp-G6XP2IRO.js +151 -0
  79. package/dist/bundle/mcp-OQBZXELQ.js +165 -0
  80. package/dist/bundle/mcp-RDZGYPSY.js +78 -0
  81. package/dist/bundle/node-NQG4EVZR.js +176 -0
  82. package/dist/bundle/node-P4E63KXA.js +2340 -0
  83. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  84. package/dist/bundle/node-sqlite-BR7F3BLB.js +61 -0
  85. package/dist/bundle/oauth-J7UAWNIK.js +17 -0
  86. package/dist/bundle/open-BR47R5UE.js +19 -0
  87. package/dist/bundle/process-66I7RDPJ.js +91 -0
  88. package/dist/bundle/program-K6347XBZ.js +17279 -0
  89. package/dist/bundle/prompt-NE5JJ7UP.js +12 -0
  90. package/dist/bundle/recognize-GC3YFVIA.js +21 -0
  91. package/dist/bundle/remote-QELOMKQM.js +26 -0
  92. package/dist/bundle/rerank-BH6TZ2SP.js +49 -0
  93. package/dist/bundle/serve-WWLRNDT2.js +19 -0
  94. package/dist/bundle/server-DE6NLNUF.js +52 -0
  95. package/dist/bundle/server-ZPSQKOAH.js +39 -0
  96. package/dist/bundle/state-2BEGXAMO.js +33 -0
  97. package/dist/bundle/store-AH6WZMCF.js +120 -0
  98. package/dist/bundle/store-maintenance-command-PBXX3IEV.js +40 -0
  99. package/dist/version.d.ts +1 -1
  100. package/dist/version.d.ts.map +1 -1
  101. package/dist/version.js +1 -1
  102. package/dist/version.js.map +1 -1
  103. package/docs/commands.md +9 -13
  104. package/docs/dev/TESTING.md +10 -0
  105. package/docs/dev/reference-clis.md +7 -5
  106. package/docs/dev/skills/release/SKILL.md +15 -8
  107. package/docs/dev/skills/release/fresh-audit.md +4 -0
  108. package/docs/dev/test-matrix.md +1 -1
  109. package/kit/dist/new.js +1 -0
  110. package/package.json +8 -5
  111. package/scripts/audit.sh +14 -3
  112. package/scripts/smoke-bundle.ts +64 -0
  113. package/scripts/smoke.ts +18 -0
  114. package/scripts/test-matrix-untested.ts +1 -1
  115. package/scripts/version-level.test.ts +17 -1
  116. package/scripts/version-level.ts +35 -7
  117. package/skills/clidev-cli/SKILL.md +8 -0
  118. package/src/version.ts +1 -1
  119. package/lint/baseline/unknown-verb.json +0 -1
@@ -0,0 +1,169 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ DefaultLogger,
5
+ DrizzleQueryError,
6
+ NoopLogger,
7
+ SQLiteAsyncDatabase,
8
+ SQLiteAsyncPreparedQuery,
9
+ SQLiteAsyncSession,
10
+ SQLiteAsyncTransaction,
11
+ SQLiteDialect,
12
+ booleanFromInteger,
13
+ bufferFromBytes,
14
+ castToText,
15
+ dateFromStoredMilliseconds,
16
+ dateFromStoredSeconds,
17
+ entityKind,
18
+ jitCompatCheck,
19
+ refineSqliteCodecs,
20
+ sql
21
+ } from "./chunk-Z7MSIRSQ.js";
22
+ import {
23
+ __name
24
+ } from "./chunk-ZVVMGPBJ.js";
25
+
26
+ // node_modules/.pnpm/@wirecat+cli-core@0.495.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_24cca5e5c8b0984f2f26e7d1ba6b6d47/node_modules/@wirecat/cli-core/dist/store/sqlite/drizzle/bun.js
27
+ import { Database } from "bun:sqlite";
28
+ var bunSQLiteCodecs = refineSqliteCodecs({
29
+ "integer:boolean": { normalize: booleanFromInteger },
30
+ "integer:timestamp": { normalize: dateFromStoredSeconds },
31
+ "integer:timestamp_ms": { normalize: dateFromStoredMilliseconds },
32
+ "text:json": { normalize: JSON.parse },
33
+ blob: { normalize: bufferFromBytes },
34
+ "blob:json": {
35
+ cast: castToText,
36
+ normalize: JSON.parse
37
+ },
38
+ "blob:bigint": {
39
+ cast: castToText,
40
+ normalize: BigInt
41
+ },
42
+ numeric: {
43
+ cast: castToText,
44
+ normalize: String
45
+ },
46
+ "numeric:number": { normalize: Number },
47
+ "numeric:bigint": {
48
+ cast: castToText,
49
+ normalize: BigInt
50
+ }
51
+ });
52
+ var SQLiteBunSession = class extends SQLiteAsyncSession {
53
+ static {
54
+ __name(this, "SQLiteBunSession");
55
+ }
56
+ client;
57
+ relations;
58
+ options;
59
+ static [entityKind] = "SQLiteBunSession";
60
+ logger;
61
+ constructor(client, dialect, relations, options = {}) {
62
+ super(dialect, "sync");
63
+ this.client = client;
64
+ this.relations = relations;
65
+ this.options = options;
66
+ this.logger = options.logger ?? new NoopLogger();
67
+ }
68
+ exec(query) {
69
+ this.client.exec(query);
70
+ }
71
+ prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
72
+ let stmt;
73
+ try {
74
+ stmt = this.client.query(query.sql);
75
+ } catch (e) {
76
+ throw new DrizzleQueryError(query.sql, this.options.paramsInErrors ? query.params : void 0, e);
77
+ }
78
+ return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
79
+ all: /* @__PURE__ */ __name((params) => {
80
+ if (mode === "arrays") return stmt.values(...params);
81
+ return stmt.all(...params);
82
+ }, "all"),
83
+ get: /* @__PURE__ */ __name((params) => {
84
+ if (mode === "arrays") return stmt.values(...params)[0];
85
+ return stmt.get(...params);
86
+ }, "get"),
87
+ run: /* @__PURE__ */ __name((params) => {
88
+ return stmt.run(...params);
89
+ }, "run")
90
+ }, query, mapper, mode, this.logger, void 0, queryMetadata, void 0, this.options.paramsInErrors);
91
+ }
92
+ transaction(transaction, config = {}) {
93
+ const tx = new SQLiteBunTransaction("sync", this.dialect, this, this.relations);
94
+ let result;
95
+ const nativeTx = this.client.transaction(() => {
96
+ result = transaction(tx);
97
+ });
98
+ if (config.behavior === "concurrent") throw new Error("Concurrent transactions are not supported by driver");
99
+ nativeTx[config.behavior ?? "deferred"]();
100
+ return result;
101
+ }
102
+ };
103
+ var SQLiteBunTransaction = class SQLiteBunTransaction2 extends SQLiteAsyncTransaction {
104
+ static {
105
+ __name(this, "SQLiteBunTransaction2");
106
+ }
107
+ static [entityKind] = "SQLiteBunTransaction";
108
+ transaction(transaction) {
109
+ const savepointName = `sp${this.nestedIndex}`;
110
+ const tx = new SQLiteBunTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
111
+ this.session.run(sql.raw(`savepoint ${savepointName}`));
112
+ try {
113
+ const result = transaction(tx);
114
+ this.session.run(sql.raw(`release savepoint ${savepointName}`));
115
+ return result;
116
+ } catch (err) {
117
+ try {
118
+ this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
119
+ } catch {
120
+ }
121
+ throw err;
122
+ }
123
+ }
124
+ };
125
+ var SQLiteBunDatabase = class extends SQLiteAsyncDatabase {
126
+ static {
127
+ __name(this, "SQLiteBunDatabase");
128
+ }
129
+ static [entityKind] = "SQLiteBunDatabase";
130
+ };
131
+ function construct(client, config = {}) {
132
+ const dialect = new SQLiteDialect({
133
+ codecs: config.codecs ?? bunSQLiteCodecs,
134
+ useJitMappers: jitCompatCheck(config.jit)
135
+ });
136
+ let logger;
137
+ if (config.logger === true) logger = new DefaultLogger();
138
+ else if (config.logger !== false) logger = config.logger;
139
+ const relations = config.relations ?? {};
140
+ const db = new SQLiteBunDatabase("sync", dialect, new SQLiteBunSession(client, dialect, relations, {
141
+ logger,
142
+ paramsInErrors: config.paramsInErrors
143
+ }), relations);
144
+ db.$client = client;
145
+ return db;
146
+ }
147
+ __name(construct, "construct");
148
+ function drizzle(...params) {
149
+ if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new Database() : new Database(params[0]), params[1]);
150
+ const { connection, client, ...DrizzleSQLiteConfig } = params[0];
151
+ if (client) return construct(client, DrizzleSQLiteConfig);
152
+ if (typeof connection === "object") {
153
+ const { source, ...opts } = connection;
154
+ const options = Object.values(opts).filter((v) => v !== void 0).length ? opts : void 0;
155
+ return construct(new Database(source, options), DrizzleSQLiteConfig);
156
+ }
157
+ return construct(new Database(connection), DrizzleSQLiteConfig);
158
+ }
159
+ __name(drizzle, "drizzle");
160
+ (function(_drizzle) {
161
+ function mock(config) {
162
+ return construct({}, config);
163
+ }
164
+ __name(mock, "mock");
165
+ _drizzle.mock = mock;
166
+ })(drizzle || (drizzle = {}));
167
+ export {
168
+ drizzle
169
+ };
@@ -0,0 +1,69 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ loadVectorExtension,
5
+ vectorExtension
6
+ } from "./chunk-QBP7OMN5.js";
7
+ import "./chunk-EFHLQXG6.js";
8
+ import {
9
+ importFrom
10
+ } from "./chunk-Y5E2WNWB.js";
11
+ import {
12
+ __name
13
+ } from "./chunk-ZVVMGPBJ.js";
14
+
15
+ // node_modules/.pnpm/@wirecat+cli-core@0.495.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_24cca5e5c8b0984f2f26e7d1ba6b6d47/node_modules/@wirecat/cli-core/dist/store/drivers/bun-sqlite.js
16
+ var customised = false;
17
+ var ownLibrary = /* @__PURE__ */ __name(async () => {
18
+ try {
19
+ const { libraryFor } = await importFrom(new URL("store/drivers/bun-sqlite.js", import.meta.resolve("@wirecat/cli-core")).href, "@wirecat/cli-core-sqlite");
20
+ return libraryFor();
21
+ } catch {
22
+ return void 0;
23
+ }
24
+ }, "ownLibrary");
25
+ var bunDatabase = /* @__PURE__ */ __name(async () => {
26
+ const specifier = "bun:sqlite";
27
+ const { Database } = await importFrom(new URL("store/drivers/bun-sqlite.js", import.meta.resolve("@wirecat/cli-core")).href, specifier);
28
+ if (process.platform === "darwin" && !customised) {
29
+ customised = true;
30
+ const library = await ownLibrary();
31
+ if (library)
32
+ Database.setCustomSQLite(library);
33
+ }
34
+ return Database;
35
+ }, "bunDatabase");
36
+ var openWithBunSqlite = /* @__PURE__ */ __name(async (path) => cacheOverBunSqlite(await bunClient(path)), "openWithBunSqlite");
37
+ var bunClient = /* @__PURE__ */ __name(async (path, options) => {
38
+ const Database = await bunDatabase();
39
+ const extension = await vectorExtension();
40
+ const client = options ? new Database(path, options) : new Database(path);
41
+ try {
42
+ loadVectorExtension(client, extension);
43
+ return client;
44
+ } catch (error) {
45
+ client.close();
46
+ throw error;
47
+ }
48
+ }, "bunClient");
49
+ var cacheOverBunSqlite = /* @__PURE__ */ __name((database) => {
50
+ return {
51
+ exec: /* @__PURE__ */ __name((sql) => database.exec(sql), "exec"),
52
+ prepare: /* @__PURE__ */ __name((sql) => {
53
+ const statement = database.query(sql);
54
+ return {
55
+ run: /* @__PURE__ */ __name((...parameters) => ({ changes: Number(statement.run(...parameters).changes) }), "run"),
56
+ // Bun answers null for no row; the seam promises undefined, and `!== undefined` checks rely on it.
57
+ get: /* @__PURE__ */ __name((...parameters) => statement.get(...parameters) ?? void 0, "get"),
58
+ all: /* @__PURE__ */ __name((...parameters) => statement.all(...parameters), "all")
59
+ };
60
+ }, "prepare"),
61
+ close: /* @__PURE__ */ __name(() => database.close(), "close")
62
+ };
63
+ }, "cacheOverBunSqlite");
64
+ export {
65
+ bunClient,
66
+ bunDatabase,
67
+ cacheOverBunSqlite,
68
+ openWithBunSqlite
69
+ };
@@ -0,0 +1,100 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ CliError
5
+ } from "./chunk-EFHLQXG6.js";
6
+ import {
7
+ __name
8
+ } from "./chunk-ZVVMGPBJ.js";
9
+
10
+ // node_modules/.pnpm/@wirecat+cli-core@0.495.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_24cca5e5c8b0984f2f26e7d1ba6b6d47/node_modules/@wirecat/cli-core/dist/store/driver.js
11
+ var PRAGMAS = `
12
+ PRAGMA busy_timeout = 5000;
13
+ PRAGMA journal_mode = WAL;
14
+ PRAGMA foreign_keys = ON;
15
+ `;
16
+
17
+ // node_modules/.pnpm/@wirecat+cli-core@0.495.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_24cca5e5c8b0984f2f26e7d1ba6b6d47/node_modules/@wirecat/cli-core/dist/store/sqlite-warning.js
18
+ var SQLITE_WARNING = "SQLite is an experimental feature";
19
+ var quieted = /* @__PURE__ */ new WeakSet();
20
+ var quietSqliteWarning = /* @__PURE__ */ __name((host = process) => {
21
+ if (quieted.has(host))
22
+ return;
23
+ quieted.add(host);
24
+ const emit = host.emitWarning;
25
+ host.emitWarning = function(warning, ...rest) {
26
+ if (isSqliteWarning(warning, rest[0]))
27
+ return;
28
+ return Reflect.apply(emit, this, [warning, ...rest]);
29
+ };
30
+ }, "quietSqliteWarning");
31
+ var isSqliteWarning = /* @__PURE__ */ __name((warning, options) => {
32
+ const type = typeof options === "string" ? options : options?.type;
33
+ const name = typeof warning === "string" ? type : warning.name;
34
+ const message = typeof warning === "string" ? warning : warning.message;
35
+ return name === "ExperimentalWarning" && message.startsWith(SQLITE_WARNING);
36
+ }, "isSqliteWarning");
37
+
38
+ // node_modules/.pnpm/@wirecat+cli-core@0.495.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_24cca5e5c8b0984f2f26e7d1ba6b6d47/node_modules/@wirecat/cli-core/dist/store/open.js
39
+ var openCache = /* @__PURE__ */ __name(async (path) => {
40
+ const database = await openFile(path);
41
+ try {
42
+ database.exec(PRAGMAS);
43
+ } catch (error) {
44
+ database.close();
45
+ throw error;
46
+ }
47
+ return database;
48
+ }, "openCache");
49
+ var openFile = /* @__PURE__ */ __name((path) => "Bun" in globalThis ? openUnderBun(path) : openUnderNode(path), "openFile");
50
+ var openUnderBun = /* @__PURE__ */ __name(async (path) => {
51
+ const { openWithBunSqlite } = await import("./bun-sqlite-KBXOW2ES.js");
52
+ return await openWithBunSqlite(path);
53
+ }, "openUnderBun");
54
+ var openUnderNode = /* @__PURE__ */ __name(async (path) => {
55
+ quietSqliteWarning();
56
+ const { openWithNodeSqlite } = await import("./node-sqlite-BR7F3BLB.js");
57
+ return openWithNodeSqlite(path);
58
+ }, "openUnderNode");
59
+ var runtime = /* @__PURE__ */ __name(() => {
60
+ const bun = globalThis.Bun;
61
+ return bun ? `Bun ${bun.version}` : `Node ${process.versions.node}`;
62
+ }, "runtime");
63
+ var CAPABILITY_STATEMENTS = [
64
+ `CREATE VIRTUAL TABLE temp.capability_words USING fts5(a, content = '', contentless_delete = 1,
65
+ tokenize = 'unicode61 remove_diacritics 2')`,
66
+ "CREATE VIRTUAL TABLE temp.capability_text USING fts5(a, tokenize = 'trigram')",
67
+ "DROP TABLE temp.capability_words",
68
+ "DROP TABLE temp.capability_text"
69
+ ];
70
+ var assertStoreCapable = /* @__PURE__ */ __name((database, on = runtime()) => {
71
+ try {
72
+ for (const statement of CAPABILITY_STATEMENTS)
73
+ database.exec(statement);
74
+ } catch (error) {
75
+ const version = String(database.prepare("SELECT sqlite_version() AS version").get()?.version);
76
+ const remedy = on.startsWith("Bun") ? "Run it under Node 22.16 or newer instead" : "Update Node to 22.16 or newer, or run it under Bun";
77
+ throw new CliError("configuration_error", `the message store needs full-text search that this SQLite (${version}, ${on}) does not have. ${remedy}.`, { sqlite: version, runtime: on, cause: error instanceof Error ? error.message : String(error) });
78
+ }
79
+ }, "assertStoreCapable");
80
+ var capable;
81
+ var storeCapable = /* @__PURE__ */ __name(() => {
82
+ capable ??= openCache(":memory:").then((database) => {
83
+ try {
84
+ assertStoreCapable(database);
85
+ } finally {
86
+ database.close();
87
+ }
88
+ });
89
+ return capable;
90
+ }, "storeCapable");
91
+
92
+ export {
93
+ PRAGMAS,
94
+ quietSqliteWarning,
95
+ openCache,
96
+ openFile,
97
+ CAPABILITY_STATEMENTS,
98
+ assertStoreCapable,
99
+ storeCapable
100
+ };
@@ -0,0 +1,122 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ unit
5
+ } from "./chunk-QKWRL4OD.js";
6
+ import {
7
+ CliError
8
+ } from "./chunk-EFHLQXG6.js";
9
+ import {
10
+ __name
11
+ } from "./chunk-ZVVMGPBJ.js";
12
+
13
+ // node_modules/.pnpm/@wirecat+cli-core@0.495.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_24cca5e5c8b0984f2f26e7d1ba6b6d47/node_modules/@wirecat/cli-core/dist/embeddings/remote.js
14
+ import { setTimeout } from "node:timers/promises";
15
+ var OPENAI_URL = "https://api.openai.com/v1";
16
+ var OPENAI_MODELS = {
17
+ "text-embedding-3-small": { dims: 1536, perMillion: 0.02 },
18
+ "text-embedding-3-large": { dims: 3072, perMillion: 0.13 }
19
+ };
20
+ var DEFAULT_OPENAI_MODEL = "text-embedding-3-small";
21
+ var PER_REQUEST = 256;
22
+ var LOCAL = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
23
+ var isLocal = /* @__PURE__ */ __name((baseUrl) => LOCAL.has(new URL(baseUrl).hostname), "isLocal");
24
+ var remoteModel = /* @__PURE__ */ __name(({ model = DEFAULT_OPENAI_MODEL, baseUrl, dims }) => {
25
+ const known = baseUrl === void 0 ? OPENAI_MODELS[model] : void 0;
26
+ if (baseUrl === void 0 && !known) {
27
+ throw new CliError("validation_error", `OpenAI has no embedding model ${model} here \u2014 one of: ${Object.keys(OPENAI_MODELS).join(", ")}; another server takes --base-url`);
28
+ }
29
+ const size = dims ?? known?.dims;
30
+ if (size === void 0)
31
+ throw new CliError("validation_error", "with --base-url, say the vector size with --dims");
32
+ return {
33
+ provider: baseUrl === void 0 ? "openai" : `url:${new URL(baseUrl).host}`,
34
+ model,
35
+ dims: size,
36
+ baseUrl: baseUrl ?? OPENAI_URL,
37
+ shorten: known !== void 0 && size !== known.dims,
38
+ ...known ? { price: { perMillion: known.perMillion, read: "2026-10-02" } } : {}
39
+ };
40
+ }, "remoteModel");
41
+ var remoteKey = /* @__PURE__ */ __name(({ provider, model, dims }) => `${provider}:${model}:${dims}`, "remoteKey");
42
+ var openRemote = /* @__PURE__ */ __name((remote, apiKey, { concurrency = 4, fetch: post = fetch, tries = 5 } = {}) => {
43
+ const request = /* @__PURE__ */ __name(async (input) => {
44
+ for (let attempt = 1; ; attempt++) {
45
+ let response;
46
+ try {
47
+ response = await post(`${remote.baseUrl.replace(/\/$/, "")}/embeddings`, {
48
+ method: "POST",
49
+ headers: {
50
+ "content-type": "application/json",
51
+ ...apiKey ? { authorization: `Bearer ${apiKey}` } : {}
52
+ },
53
+ body: JSON.stringify({
54
+ model: remote.model,
55
+ input,
56
+ encoding_format: "float",
57
+ ...remote.shorten ? { dimensions: remote.dims } : {}
58
+ })
59
+ });
60
+ } catch {
61
+ if (attempt >= tries)
62
+ throw new CliError("network_error", `${remote.provider} could not be reached`);
63
+ await setTimeout(1e3 * attempt);
64
+ continue;
65
+ }
66
+ if (response.ok) {
67
+ const body = await response.json();
68
+ const data = [...body.data ?? []].sort((a, b) => a.index - b.index);
69
+ if (data.length !== input.length || data.some(({ embedding }) => embedding.length !== remote.dims)) {
70
+ throw new CliError("invalid_response", `${remote.provider} answered with vectors of another number or size than ${input.length} \xD7 ${remote.dims}`);
71
+ }
72
+ return data.map(({ embedding }) => unit(Float32Array.from(embedding)));
73
+ }
74
+ const code = await errorCode(response);
75
+ if (response.status === 401 || response.status === 403) {
76
+ throw new CliError("authentication_error", `${remote.provider} refused the key (HTTP ${response.status}${code}) \u2014 set it again with \`models keys set\``);
77
+ }
78
+ const again = response.status === 429 || response.status >= 500;
79
+ if (!again || attempt >= tries) {
80
+ throw new CliError(response.status === 429 ? "rate_limited" : "provider_error", `${remote.provider} answered HTTP ${response.status}${code}`);
81
+ }
82
+ const wait = Number(response.headers.get("retry-after"));
83
+ await setTimeout(Number.isFinite(wait) && wait > 0 ? wait * 1e3 : 1e3 * 2 ** attempt);
84
+ }
85
+ }, "request");
86
+ return {
87
+ model: { id: remote.model, dims: remote.dims },
88
+ embed: /* @__PURE__ */ __name(async (texts) => {
89
+ const parts = [];
90
+ for (let start = 0; start < texts.length; start += PER_REQUEST)
91
+ parts.push(texts.slice(start, start + PER_REQUEST));
92
+ const results = new Array(parts.length);
93
+ let next = 0;
94
+ await Promise.all(Array.from({ length: Math.min(concurrency, parts.length) }, async () => {
95
+ for (let index = next++; index < parts.length; index = next++)
96
+ results[index] = await request(parts[index]);
97
+ }));
98
+ return results.flat();
99
+ }, "embed"),
100
+ close: /* @__PURE__ */ __name(async () => {
101
+ }, "close")
102
+ };
103
+ }, "openRemote");
104
+ var errorCode = /* @__PURE__ */ __name(async (response) => {
105
+ try {
106
+ const body = await response.json();
107
+ const code = body.error?.code ?? body.error?.type;
108
+ return typeof code === "string" && /^[\w.-]{1,64}$/.test(code) ? `, ${code}` : "";
109
+ } catch {
110
+ return "";
111
+ }
112
+ }, "errorCode");
113
+
114
+ export {
115
+ OPENAI_URL,
116
+ OPENAI_MODELS,
117
+ DEFAULT_OPENAI_MODEL,
118
+ isLocal,
119
+ remoteModel,
120
+ remoteKey,
121
+ openRemote
122
+ };