@gaunt-sloth/core 2.0.0-alpha.6 → 2.0.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/defaults.d.ts +1 -1
- package/dist/config/defaults.js +1 -1
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/jsonc.d.ts +12 -0
- package/dist/config/jsonc.js +41 -0
- package/dist/config/jsonc.js.map +1 -0
- package/dist/config/loader.d.ts +21 -0
- package/dist/config/loader.js +62 -3
- package/dist/config/loader.js.map +1 -1
- package/dist/config/schema.d.ts +32 -0
- package/dist/config/schema.js +40 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/config/types.d.ts +21 -0
- package/dist/config/types.js.map +1 -1
- package/dist/constants.d.ts +18 -0
- package/dist/constants.js +18 -0
- package/dist/constants.js.map +1 -1
- package/dist/core/GthAbstractAgent.d.ts +25 -1
- package/dist/core/GthAbstractAgent.js +77 -0
- package/dist/core/GthAbstractAgent.js.map +1 -1
- package/dist/core/GthAgentRunner.d.ts +23 -1
- package/dist/core/GthAgentRunner.js +52 -0
- package/dist/core/GthAgentRunner.js.map +1 -1
- package/dist/core/GthLangChainAgent.js +58 -5
- package/dist/core/GthLangChainAgent.js.map +1 -1
- package/dist/core/runStats.d.ts +41 -0
- package/dist/core/runStats.js +73 -0
- package/dist/core/runStats.js.map +1 -0
- package/dist/core/shell/ShellCommandFailedError.d.ts +54 -0
- package/dist/core/shell/ShellCommandFailedError.js +68 -0
- package/dist/core/shell/ShellCommandFailedError.js.map +1 -0
- package/dist/core/types.d.ts +29 -0
- package/dist/history/historyFormat.d.ts +19 -0
- package/dist/history/historyFormat.js +85 -0
- package/dist/history/historyFormat.js.map +1 -0
- package/dist/history/historyStore.d.ts +121 -0
- package/dist/history/historyStore.js +315 -0
- package/dist/history/historyStore.js.map +1 -0
- package/dist/history/recordSession.d.ts +28 -0
- package/dist/history/recordSession.js +29 -0
- package/dist/history/recordSession.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +4 -9
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/deepseek.d.ts +1 -1
- package/dist/providers/deepseek.js +4 -9
- package/dist/providers/deepseek.js.map +1 -1
- package/dist/providers/google-genai.d.ts +1 -1
- package/dist/providers/google-genai.js +4 -9
- package/dist/providers/google-genai.js.map +1 -1
- package/dist/providers/groq.d.ts +1 -1
- package/dist/providers/groq.js +4 -9
- package/dist/providers/groq.js.map +1 -1
- package/dist/providers/modelDiscovery.d.ts +54 -1
- package/dist/providers/modelDiscovery.js +106 -8
- package/dist/providers/modelDiscovery.js.map +1 -1
- package/dist/providers/ollama.d.ts +1 -1
- package/dist/providers/ollama.js +4 -14
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai.d.ts +1 -1
- package/dist/providers/openai.js +4 -9
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/openrouter.d.ts +1 -1
- package/dist/providers/openrouter.js +4 -9
- package/dist/providers/openrouter.js.map +1 -1
- package/dist/providers/vertexai.d.ts +1 -1
- package/dist/providers/vertexai.js +4 -9
- package/dist/providers/vertexai.js.map +1 -1
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/xai.js +4 -9
- package/dist/providers/xai.js.map +1 -1
- package/dist/runtime/singleShot.js +31 -1
- package/dist/runtime/singleShot.js.map +1 -1
- package/package.json +2 -1
- package/schema/gsloth-config.schema.json +19 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* GS2-7 (B20) — local, opt-in session history store.
|
|
4
|
+
*
|
|
5
|
+
* A **local SQLite** store that persists a compact record of each run BESIDE the existing
|
|
6
|
+
* per-run `.md` logs, so `gth history search` / `gth insights` can look back over past sessions.
|
|
7
|
+
* It is a **side-benefit, never a critical path**:
|
|
8
|
+
*
|
|
9
|
+
* - **Local only.** Nothing leaves the machine. The DB lives under the user's global `~/.gsloth`
|
|
10
|
+
* dir (cross-project history), overridable via `history.dbPath`.
|
|
11
|
+
* - **Opt-in.** The recorder only writes when `history.enabled` is true (see
|
|
12
|
+
* {@link recordSessionSafe}); default runs persist nothing and behave exactly as before.
|
|
13
|
+
* - **Fail-soft.** {@link openHistoryStore} returns `null` if the DB can't be opened, and every
|
|
14
|
+
* {@link HistoryStore} method catches its own errors and returns a safe default. A malformed or
|
|
15
|
+
* locked DB therefore can never abort or alter a run — it just means no history for that run.
|
|
16
|
+
*
|
|
17
|
+
* Uses the built-in `node:sqlite` (Node ≥ 24) — zero native dependency, no build step — and its
|
|
18
|
+
* bundled **FTS5** extension for full-text search (verified available at build time via an
|
|
19
|
+
* `fts5` virtual table). No fallback path is needed on this runtime.
|
|
20
|
+
*/
|
|
21
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
22
|
+
import { existsSync } from 'node:fs';
|
|
23
|
+
import { resolve } from 'node:path';
|
|
24
|
+
import { getGlobalGslothDir, ensureGlobalGslothDir } from '#src/utils/globalConfigUtils.js';
|
|
25
|
+
/** Filename of the global history DB inside `~/.gsloth`. */
|
|
26
|
+
export const HISTORY_DB_FILENAME = 'history.db';
|
|
27
|
+
/** Escape a value for use inside an FTS5 double-quoted string token. */
|
|
28
|
+
function ftsQuote(term) {
|
|
29
|
+
return '"' + term.replace(/"/g, '""') + '"';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Turn arbitrary user text into a safe FTS5 MATCH expression: each whitespace-separated token is
|
|
33
|
+
* wrapped as a quoted string and AND-ed together. This avoids FTS5 syntax errors from stray
|
|
34
|
+
* operators (`AND`, `*`, `:`, parentheses, unbalanced quotes) in a user's query while still
|
|
35
|
+
* matching all of their words.
|
|
36
|
+
*/
|
|
37
|
+
export function toFtsMatchQuery(query) {
|
|
38
|
+
const tokens = query.trim().split(/\s+/).filter(Boolean);
|
|
39
|
+
if (tokens.length === 0)
|
|
40
|
+
return '';
|
|
41
|
+
return tokens.map(ftsQuote).join(' AND ');
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A thin, fail-soft wrapper over a `node:sqlite` connection holding the session history.
|
|
45
|
+
*
|
|
46
|
+
* Obtain one via {@link openHistoryStore} (which returns `null` if the DB can't be opened). Every
|
|
47
|
+
* method is defensive: on any SQLite error it returns a safe empty/zero result rather than
|
|
48
|
+
* throwing, so callers on a run's hot path never have to guard.
|
|
49
|
+
*/
|
|
50
|
+
export class HistoryStore {
|
|
51
|
+
db;
|
|
52
|
+
constructor(db) {
|
|
53
|
+
this.db = db;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Open (and lazily initialise) the store at `dbPath`. Returns `null` on any failure — a missing
|
|
57
|
+
* file when `create` is false, an unopenable/locked/corrupt DB, or a schema-init error — so the
|
|
58
|
+
* caller can simply skip history without a try/catch.
|
|
59
|
+
*/
|
|
60
|
+
static open(dbPath, options = {}) {
|
|
61
|
+
const create = options.create ?? false;
|
|
62
|
+
if (!create && dbPath !== ':memory:' && !existsSync(dbPath)) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const db = new DatabaseSync(dbPath);
|
|
67
|
+
const store = new HistoryStore(db);
|
|
68
|
+
store.initSchema();
|
|
69
|
+
return store;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
initSchema() {
|
|
76
|
+
this.db.exec(`
|
|
77
|
+
CREATE TABLE IF NOT EXISTS sessions (
|
|
78
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
79
|
+
ts TEXT NOT NULL,
|
|
80
|
+
project TEXT,
|
|
81
|
+
command TEXT,
|
|
82
|
+
model TEXT,
|
|
83
|
+
prompt TEXT,
|
|
84
|
+
response TEXT,
|
|
85
|
+
tokens_input INTEGER,
|
|
86
|
+
tokens_output INTEGER,
|
|
87
|
+
cost_usd REAL,
|
|
88
|
+
tools TEXT,
|
|
89
|
+
duration_ms INTEGER
|
|
90
|
+
);
|
|
91
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS sessions_fts USING fts5(
|
|
92
|
+
prompt, response, command, project
|
|
93
|
+
);
|
|
94
|
+
`);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Persist one session and its full-text index entry. Returns the new row id, or `null` on any
|
|
98
|
+
* error (the run continues regardless). The two inserts run in a transaction so a failure can't
|
|
99
|
+
* leave the FTS index out of sync with the base table.
|
|
100
|
+
*/
|
|
101
|
+
record(rec) {
|
|
102
|
+
try {
|
|
103
|
+
const ts = rec.ts ?? new Date().toISOString();
|
|
104
|
+
const tools = rec.tools && rec.tools.length > 0 ? JSON.stringify(rec.tools) : null;
|
|
105
|
+
this.db.exec('BEGIN');
|
|
106
|
+
try {
|
|
107
|
+
const insert = this.db.prepare(`INSERT INTO sessions
|
|
108
|
+
(ts, project, command, model, prompt, response,
|
|
109
|
+
tokens_input, tokens_output, cost_usd, tools, duration_ms)
|
|
110
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
111
|
+
const info = insert.run(ts, rec.project ?? null, rec.command ?? null, rec.model ?? null, rec.prompt ?? null, rec.response ?? null, rec.tokensInput ?? null, rec.tokensOutput ?? null, rec.costUsd ?? null, tools, rec.durationMs ?? null);
|
|
112
|
+
const id = Number(info.lastInsertRowid);
|
|
113
|
+
this.db
|
|
114
|
+
.prepare(`INSERT INTO sessions_fts (rowid, prompt, response, command, project)
|
|
115
|
+
VALUES (?, ?, ?, ?, ?)`)
|
|
116
|
+
.run(id, rec.prompt ?? '', rec.response ?? '', rec.command ?? '', rec.project ?? '');
|
|
117
|
+
this.db.exec('COMMIT');
|
|
118
|
+
return id;
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
this.db.exec('ROLLBACK');
|
|
122
|
+
throw e;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Full-text search over prompt/response/command/project, best match first (FTS5 `rank`). User
|
|
131
|
+
* text is sanitised via {@link toFtsMatchQuery}; an empty or all-punctuation query returns `[]`.
|
|
132
|
+
* Any SQLite error yields `[]` (fail-soft).
|
|
133
|
+
*/
|
|
134
|
+
search(query, limit = 20) {
|
|
135
|
+
const match = toFtsMatchQuery(query);
|
|
136
|
+
if (!match)
|
|
137
|
+
return [];
|
|
138
|
+
try {
|
|
139
|
+
const rows = this.db
|
|
140
|
+
.prepare(`SELECT s.id AS id, s.ts AS ts, s.project AS project, s.command AS command,
|
|
141
|
+
s.model AS model, s.prompt AS prompt, s.response AS response,
|
|
142
|
+
s.tokens_input AS tokens_input, s.tokens_output AS tokens_output,
|
|
143
|
+
s.cost_usd AS cost_usd, s.tools AS tools, s.duration_ms AS duration_ms,
|
|
144
|
+
snippet(sessions_fts, 0, '[', ']', '…', 12) AS snippet
|
|
145
|
+
FROM sessions_fts f
|
|
146
|
+
JOIN sessions s ON s.id = f.rowid
|
|
147
|
+
WHERE sessions_fts MATCH ?
|
|
148
|
+
ORDER BY rank
|
|
149
|
+
LIMIT ?`)
|
|
150
|
+
.all(match, limit);
|
|
151
|
+
return rows.map((r) => ({
|
|
152
|
+
...rowToRecord(r),
|
|
153
|
+
id: Number(r.id),
|
|
154
|
+
ts: String(r.ts),
|
|
155
|
+
snippet: String(r.snippet ?? ''),
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Most recent sessions, newest first. Fail-soft ([] on error). */
|
|
163
|
+
listRecent(limit = 20) {
|
|
164
|
+
try {
|
|
165
|
+
const rows = this.db
|
|
166
|
+
.prepare(`SELECT id, ts, project, command, model, prompt, response,
|
|
167
|
+
tokens_input, tokens_output, cost_usd, tools, duration_ms
|
|
168
|
+
FROM sessions
|
|
169
|
+
ORDER BY id DESC
|
|
170
|
+
LIMIT ?`)
|
|
171
|
+
.all(limit);
|
|
172
|
+
return rows.map((r) => ({
|
|
173
|
+
...rowToRecord(r),
|
|
174
|
+
id: Number(r.id),
|
|
175
|
+
ts: String(r.ts),
|
|
176
|
+
snippet: '',
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Aggregate token/cost totals, a top-tool tally, and a per-command breakdown over the whole
|
|
185
|
+
* store. Tool tallying reads each row's JSON `tools` array in JS (robust to nulls). Fail-soft:
|
|
186
|
+
* returns a zeroed summary on any error.
|
|
187
|
+
*/
|
|
188
|
+
insights(topN = 10) {
|
|
189
|
+
const empty = {
|
|
190
|
+
sessionCount: 0,
|
|
191
|
+
totalTokensInput: 0,
|
|
192
|
+
totalTokensOutput: 0,
|
|
193
|
+
totalTokens: 0,
|
|
194
|
+
totalCostUsd: 0,
|
|
195
|
+
topTools: [],
|
|
196
|
+
perCommand: [],
|
|
197
|
+
};
|
|
198
|
+
try {
|
|
199
|
+
const agg = this.db
|
|
200
|
+
.prepare(`SELECT COUNT(*) AS n,
|
|
201
|
+
COALESCE(SUM(tokens_input), 0) AS ti,
|
|
202
|
+
COALESCE(SUM(tokens_output), 0) AS to_,
|
|
203
|
+
COALESCE(SUM(cost_usd), 0) AS cost,
|
|
204
|
+
MIN(ts) AS first_ts,
|
|
205
|
+
MAX(ts) AS last_ts
|
|
206
|
+
FROM sessions`)
|
|
207
|
+
.get();
|
|
208
|
+
const perCommandRows = this.db
|
|
209
|
+
.prepare(`SELECT command, COUNT(*) AS n
|
|
210
|
+
FROM sessions
|
|
211
|
+
WHERE command IS NOT NULL AND command <> ''
|
|
212
|
+
GROUP BY command
|
|
213
|
+
ORDER BY n DESC, command ASC`)
|
|
214
|
+
.all();
|
|
215
|
+
const toolRows = this.db
|
|
216
|
+
.prepare(`SELECT tools FROM sessions WHERE tools IS NOT NULL AND tools <> ''`)
|
|
217
|
+
.all();
|
|
218
|
+
const toolCounts = new Map();
|
|
219
|
+
for (const row of toolRows) {
|
|
220
|
+
let names;
|
|
221
|
+
try {
|
|
222
|
+
names = JSON.parse(String(row.tools));
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (!Array.isArray(names))
|
|
228
|
+
continue;
|
|
229
|
+
for (const name of names) {
|
|
230
|
+
if (typeof name !== 'string' || name.length === 0)
|
|
231
|
+
continue;
|
|
232
|
+
toolCounts.set(name, (toolCounts.get(name) ?? 0) + 1);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const topTools = [...toolCounts.entries()]
|
|
236
|
+
.map(([tool, count]) => ({ tool, count }))
|
|
237
|
+
.sort((a, b) => b.count - a.count || a.tool.localeCompare(b.tool))
|
|
238
|
+
.slice(0, topN);
|
|
239
|
+
const ti = Number(agg.ti ?? 0);
|
|
240
|
+
const to = Number(agg.to_ ?? 0);
|
|
241
|
+
return {
|
|
242
|
+
sessionCount: Number(agg.n ?? 0),
|
|
243
|
+
totalTokensInput: ti,
|
|
244
|
+
totalTokensOutput: to,
|
|
245
|
+
totalTokens: ti + to,
|
|
246
|
+
totalCostUsd: Number(agg.cost ?? 0),
|
|
247
|
+
topTools,
|
|
248
|
+
perCommand: perCommandRows.map((r) => ({
|
|
249
|
+
command: String(r.command),
|
|
250
|
+
count: Number(r.n),
|
|
251
|
+
})),
|
|
252
|
+
firstTs: agg.first_ts ? String(agg.first_ts) : undefined,
|
|
253
|
+
lastTs: agg.last_ts ? String(agg.last_ts) : undefined,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return empty;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/** Close the underlying connection (fail-soft). */
|
|
261
|
+
close() {
|
|
262
|
+
try {
|
|
263
|
+
this.db.close();
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
/* ignore */
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/** Map a raw DB row (snake_case columns) to a {@link SessionRecord}. */
|
|
271
|
+
function rowToRecord(r) {
|
|
272
|
+
let tools;
|
|
273
|
+
if (r.tools != null && r.tools !== '') {
|
|
274
|
+
try {
|
|
275
|
+
const parsed = JSON.parse(String(r.tools));
|
|
276
|
+
if (Array.isArray(parsed))
|
|
277
|
+
tools = parsed.filter((t) => typeof t === 'string');
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
/* ignore malformed tools JSON */
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
ts: r.ts != null ? String(r.ts) : undefined,
|
|
285
|
+
project: r.project != null ? String(r.project) : undefined,
|
|
286
|
+
command: r.command != null ? String(r.command) : undefined,
|
|
287
|
+
model: r.model != null ? String(r.model) : undefined,
|
|
288
|
+
prompt: r.prompt != null ? String(r.prompt) : undefined,
|
|
289
|
+
response: r.response != null ? String(r.response) : undefined,
|
|
290
|
+
tokensInput: r.tokens_input != null ? Number(r.tokens_input) : undefined,
|
|
291
|
+
tokensOutput: r.tokens_output != null ? Number(r.tokens_output) : undefined,
|
|
292
|
+
costUsd: r.cost_usd != null ? Number(r.cost_usd) : undefined,
|
|
293
|
+
tools,
|
|
294
|
+
durationMs: r.duration_ms != null ? Number(r.duration_ms) : undefined,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Resolve the on-disk path of the history DB. Honors an explicit `dbPath` (from `history.dbPath`
|
|
299
|
+
* or a `--db` flag); otherwise the global `~/.gsloth/history.db`. When `dbPath` is omitted and
|
|
300
|
+
* `ensureDir` is true, the global dir is created so the recorder can write.
|
|
301
|
+
*/
|
|
302
|
+
export function resolveHistoryDbPath(dbPath, ensureDir = false) {
|
|
303
|
+
if (dbPath && dbPath.trim().length > 0)
|
|
304
|
+
return dbPath;
|
|
305
|
+
const dir = ensureDir ? ensureGlobalGslothDir() : getGlobalGslothDir();
|
|
306
|
+
return resolve(dir, HISTORY_DB_FILENAME);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Fail-soft open of the history store. Returns `null` (never throws) when the DB can't be opened
|
|
310
|
+
* or, for read-only callers (`create: false`, the default), when the file does not yet exist.
|
|
311
|
+
*/
|
|
312
|
+
export function openHistoryStore(dbPath, options = {}) {
|
|
313
|
+
return HistoryStore.open(dbPath, options);
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=historyStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"historyStore.js","sourceRoot":"","sources":["../../src/history/historyStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAE5F,4DAA4D;AAC5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAC;AA6DhD,wEAAwE;AACxE,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,GAAG,CAAC;AAC9C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACnC,OAAO,MA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CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* GS2-7 (B20) — the opt-in bridge from a finished run to the {@link HistoryStore}.
|
|
4
|
+
*
|
|
5
|
+
* {@link recordSessionSafe} is the ONE entry point the run path calls. It is a no-op unless
|
|
6
|
+
* `history.enabled` is true, and it swallows every error, so:
|
|
7
|
+
* - a **default run** (history absent/false) opens nothing, writes nothing, and behaves exactly
|
|
8
|
+
* as before — the stateless identity is preserved; and
|
|
9
|
+
* - even with history **on**, a DB problem (locked/corrupt/read-only fs) can never abort or alter
|
|
10
|
+
* the run: the worst case is that one session isn't recorded.
|
|
11
|
+
*/
|
|
12
|
+
import type { SessionRecord } from '#src/history/historyStore.js';
|
|
13
|
+
/** The subset of the resolved config the recorder reads (structural, to avoid a hard type dep). */
|
|
14
|
+
export interface HistoryConfigView {
|
|
15
|
+
history?: {
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
dbPath?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Record one finished session IFF `history.enabled` is true. Returns the new row id, or `null`
|
|
22
|
+
* when history is disabled or anything went wrong (both are non-events for the caller).
|
|
23
|
+
*
|
|
24
|
+
* Deliberately fully guarded: opening the store, ensuring the global dir, and the insert all run
|
|
25
|
+
* behind a single try/catch, and the store itself is fail-soft. Callers put this in a `finally`
|
|
26
|
+
* (or after a run) without a try/catch of their own.
|
|
27
|
+
*/
|
|
28
|
+
export declare function recordSessionSafe(config: HistoryConfigView, record: SessionRecord): number | null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { openHistoryStore, resolveHistoryDbPath } from '#src/history/historyStore.js';
|
|
2
|
+
/**
|
|
3
|
+
* Record one finished session IFF `history.enabled` is true. Returns the new row id, or `null`
|
|
4
|
+
* when history is disabled or anything went wrong (both are non-events for the caller).
|
|
5
|
+
*
|
|
6
|
+
* Deliberately fully guarded: opening the store, ensuring the global dir, and the insert all run
|
|
7
|
+
* behind a single try/catch, and the store itself is fail-soft. Callers put this in a `finally`
|
|
8
|
+
* (or after a run) without a try/catch of their own.
|
|
9
|
+
*/
|
|
10
|
+
export function recordSessionSafe(config, record) {
|
|
11
|
+
try {
|
|
12
|
+
if (!config?.history?.enabled)
|
|
13
|
+
return null;
|
|
14
|
+
const dbPath = resolveHistoryDbPath(config.history.dbPath, /* ensureDir */ true);
|
|
15
|
+
const store = openHistoryStore(dbPath, { create: true });
|
|
16
|
+
if (!store)
|
|
17
|
+
return null;
|
|
18
|
+
try {
|
|
19
|
+
return store.record(record);
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
store.close();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=recordSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recordSession.js","sourceRoot":"","sources":["../../src/history/recordSession.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAOtF;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAyB,EAAE,MAAqB;IAChF,IAAI,CAAC;QACH,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO;YAAE,OAAO,IAAI,CAAC;QAC3C,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;QACjF,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QACxB,IAAI,CAAC;YACH,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;gBAAS,CAAC;YACT,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,3 +3,6 @@ export * from '#src/core/types.js';
|
|
|
3
3
|
export { gthLeanAgentFactory } from '#src/core/gthLeanAgentFactory.js';
|
|
4
4
|
export * from '#src/config.js';
|
|
5
5
|
export * from '#src/providers/modelDiscovery.js';
|
|
6
|
+
export * from '#src/history/historyStore.js';
|
|
7
|
+
export * from '#src/history/recordSession.js';
|
|
8
|
+
export * from '#src/history/historyFormat.js';
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,7 @@ export * from '#src/core/types.js';
|
|
|
3
3
|
export { gthLeanAgentFactory } from '#src/core/gthLeanAgentFactory.js';
|
|
4
4
|
export * from '#src/config.js';
|
|
5
5
|
export * from '#src/providers/modelDiscovery.js';
|
|
6
|
+
export * from '#src/history/historyStore.js';
|
|
7
|
+
export * from '#src/history/recordSession.js';
|
|
8
|
+
export * from '#src/history/historyFormat.js';
|
|
6
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kCAAkC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC"}
|
|
@@ -4,4 +4,4 @@ import type { BaseChatModel, BaseChatModelParams } from '@langchain/core/languag
|
|
|
4
4
|
* Function to process JSON config and create Anthropic LLM instance
|
|
5
5
|
*/
|
|
6
6
|
export declare function processJsonConfig(llmConfig: AnthropicInput & BaseChatModelParams): Promise<BaseChatModel>;
|
|
7
|
-
export declare function init(configFileName: string, force?: boolean): void;
|
|
7
|
+
export declare function init(configFileName: string, force?: boolean, model?: string): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { displayWarning } from '#src/utils/consoleUtils.js';
|
|
2
2
|
import { writeConfigFileWithMessages } from '#src/utils/fileUtils.js';
|
|
3
|
+
import { buildInitConfigContent, getCuratedFallbackModel } from '#src/providers/modelDiscovery.js';
|
|
3
4
|
import { env } from '#src/utils/systemUtils.js';
|
|
4
5
|
/**
|
|
5
6
|
* Function to process JSON config and create Anthropic LLM instance
|
|
@@ -12,22 +13,16 @@ export async function processJsonConfig(llmConfig) {
|
|
|
12
13
|
return new anthropic.ChatAnthropic({
|
|
13
14
|
...llmConfig,
|
|
14
15
|
apiKey: anthropicApiKey,
|
|
15
|
-
model: llmConfig.model || '
|
|
16
|
+
model: llmConfig.model || getCuratedFallbackModel('anthropic'),
|
|
16
17
|
});
|
|
17
18
|
}
|
|
18
|
-
const jsonContent = `{
|
|
19
|
-
"llm": {
|
|
20
|
-
"type": "anthropic",
|
|
21
|
-
"model": "claude-sonnet-4-6"
|
|
22
|
-
}
|
|
23
|
-
}`;
|
|
24
19
|
// noinspection JSUnusedGlobalSymbols
|
|
25
|
-
export function init(configFileName, force = false) {
|
|
20
|
+
export function init(configFileName, force = false, model) {
|
|
26
21
|
// Determine which content to use based on file extension
|
|
27
22
|
if (!configFileName.endsWith('.json')) {
|
|
28
23
|
throw new Error('Only JSON config is supported.');
|
|
29
24
|
}
|
|
30
|
-
writeConfigFileWithMessages(configFileName,
|
|
25
|
+
writeConfigFileWithMessages(configFileName, buildInitConfigContent('anthropic', model), force);
|
|
31
26
|
displayWarning(`You need to update your ${configFileName} to add your Anthropic API key, ` +
|
|
32
27
|
'or define ANTHROPIC_API_KEY environment variable.');
|
|
33
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAOhD;;GAEG;AACH,qCAAqC;AACrC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,SAA+C;IAE/C,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;IACvD,wEAAwE;IACxE,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,IAAI,GAAG,CAAC,iBAAiB,CAAC;IAClE,OAAO,IAAI,SAAS,CAAC,aAAa,CAAC;QACjC,GAAG,SAAS;QACZ,MAAM,EAAE,eAAe;QACvB,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AACnG,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAOhD;;GAEG;AACH,qCAAqC;AACrC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,SAA+C;IAE/C,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;IACvD,wEAAwE;IACxE,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,IAAI,GAAG,CAAC,iBAAiB,CAAC;IAClE,OAAO,IAAI,SAAS,CAAC,aAAa,CAAC;QACjC,GAAG,SAAS;QACZ,MAAM,EAAE,eAAe;QACvB,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,uBAAuB,CAAC,WAAW,CAAC;KAC/D,CAAC,CAAC;AACL,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,IAAI,CAAC,cAAsB,EAAE,KAAK,GAAG,KAAK,EAAE,KAAc;IACxE,yDAAyD;IACzD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,2BAA2B,CAAC,cAAc,EAAE,sBAAsB,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/F,cAAc,CACZ,2BAA2B,cAAc,kCAAkC;QACzE,mDAAmD,CACtD,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { BaseChatModel, BaseChatModelParams } from '@langchain/core/language_models/chat_models';
|
|
2
2
|
import { ChatDeepSeekInput } from '@langchain/deepseek';
|
|
3
3
|
export declare function processJsonConfig(llmConfig: ChatDeepSeekInput & BaseChatModelParams): Promise<BaseChatModel>;
|
|
4
|
-
export declare function init(configFileName: string, force?: boolean): void;
|
|
4
|
+
export declare function init(configFileName: string, force?: boolean, model?: string): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { displayWarning } from '#src/utils/consoleUtils.js';
|
|
2
2
|
import { env } from '#src/utils/systemUtils.js';
|
|
3
3
|
import { writeConfigFileWithMessages } from '#src/utils/fileUtils.js';
|
|
4
|
+
import { buildInitConfigContent, getCuratedFallbackModel } from '#src/providers/modelDiscovery.js';
|
|
4
5
|
// Function to process JSON config and create DeepSeek LLM instance
|
|
5
6
|
export async function processJsonConfig(llmConfig) {
|
|
6
7
|
const deepseek = await import('@langchain/deepseek');
|
|
@@ -9,21 +10,15 @@ export async function processJsonConfig(llmConfig) {
|
|
|
9
10
|
return new deepseek.ChatDeepSeek({
|
|
10
11
|
...llmConfig,
|
|
11
12
|
apiKey: deepseekApiKey,
|
|
12
|
-
model: llmConfig.model || 'deepseek
|
|
13
|
+
model: llmConfig.model || getCuratedFallbackModel('deepseek'),
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
"llm": {
|
|
17
|
-
"type": "deepseek",
|
|
18
|
-
"model": "deepseek-v4-pro"
|
|
19
|
-
}
|
|
20
|
-
}`;
|
|
21
|
-
export function init(configFileName, force = false) {
|
|
16
|
+
export function init(configFileName, force = false, model) {
|
|
22
17
|
// Determine which content to use based on file extension
|
|
23
18
|
if (!configFileName.endsWith('.json')) {
|
|
24
19
|
throw new Error('Only JSON config is supported.');
|
|
25
20
|
}
|
|
26
|
-
writeConfigFileWithMessages(configFileName,
|
|
21
|
+
writeConfigFileWithMessages(configFileName, buildInitConfigContent('deepseek', model), force);
|
|
27
22
|
displayWarning(`You need to update your ${configFileName} to add your DeepSeek API key, ` +
|
|
28
23
|
'or define DEEPSEEK_API_KEY environment variable.');
|
|
29
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepseek.js","sourceRoot":"","sources":["../../src/providers/deepseek.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAOhD,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"deepseek.js","sourceRoot":"","sources":["../../src/providers/deepseek.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAOhD,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAEnG,mEAAmE;AACnE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,SAAkD;IAElD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACrD,yEAAyE;IACzE,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,IAAI,GAAG,CAAC,gBAAgB,CAAC;IAChE,OAAO,IAAI,QAAQ,CAAC,YAAY,CAAC;QAC/B,GAAG,SAAS;QACZ,MAAM,EAAE,cAAc;QACtB,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,uBAAuB,CAAC,UAAU,CAAC;KAC9D,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,cAAsB,EAAE,KAAK,GAAG,KAAK,EAAE,KAAc;IACxE,yDAAyD;IACzD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,2BAA2B,CAAC,cAAc,EAAE,sBAAsB,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IAC9F,cAAc,CACZ,2BAA2B,cAAc,iCAAiC;QACxE,kDAAkD,CACrD,CAAC;AACJ,CAAC"}
|
|
@@ -4,4 +4,4 @@ export declare function processJsonConfig(llmConfig: ChatGoogleParams & {
|
|
|
4
4
|
type?: string;
|
|
5
5
|
apiKeyEnvironmentVariable?: string;
|
|
6
6
|
}): Promise<BaseChatModel>;
|
|
7
|
-
export declare function init(configFileName: string, force?: boolean): void;
|
|
7
|
+
export declare function init(configFileName: string, force?: boolean, model?: string): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { displayWarning } from '#src/utils/consoleUtils.js';
|
|
2
2
|
import { env } from '#src/utils/systemUtils.js';
|
|
3
3
|
import { writeConfigFileWithMessages } from '#src/utils/fileUtils.js';
|
|
4
|
+
import { buildInitConfigContent, getCuratedFallbackModel } from '#src/providers/modelDiscovery.js';
|
|
4
5
|
// Function to process JSON config and create Google GenAI LLM instance
|
|
5
6
|
export async function processJsonConfig(llmConfig) {
|
|
6
7
|
const { ChatGoogle } = await import('@langchain/google/node');
|
|
@@ -9,25 +10,19 @@ export async function processJsonConfig(llmConfig) {
|
|
|
9
10
|
const configFields = {
|
|
10
11
|
...llmConfig,
|
|
11
12
|
apiKey: googleApiKey,
|
|
12
|
-
model: llmConfig.model || '
|
|
13
|
+
model: llmConfig.model || getCuratedFallbackModel('google-genai'),
|
|
13
14
|
platformType: 'gai',
|
|
14
15
|
};
|
|
15
16
|
delete configFields.type;
|
|
16
17
|
delete configFields.apiKeyEnvironmentVariable;
|
|
17
18
|
return new ChatGoogle(configFields);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
"llm": {
|
|
21
|
-
"type": "google-genai",
|
|
22
|
-
"model": "gemini-3.5-flash"
|
|
23
|
-
}
|
|
24
|
-
}`;
|
|
25
|
-
export function init(configFileName, force = false) {
|
|
20
|
+
export function init(configFileName, force = false, model) {
|
|
26
21
|
// Determine which content to use based on file extension
|
|
27
22
|
if (!configFileName.endsWith('.json')) {
|
|
28
23
|
throw new Error('Only JSON config is supported.');
|
|
29
24
|
}
|
|
30
|
-
writeConfigFileWithMessages(configFileName,
|
|
25
|
+
writeConfigFileWithMessages(configFileName, buildInitConfigContent('google-genai', model), force);
|
|
31
26
|
displayWarning(`You need to update your ${configFileName} to add your Google GenAI API key, ` +
|
|
32
27
|
'or define GOOGLE_API_KEY environment variable.');
|
|
33
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-genai.js","sourceRoot":"","sources":["../../src/providers/google-genai.ts"],"names":[],"mappings":"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AAC,cAAc,EAAE,sBAAsB,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IAClG,cAAc,CACZ,2BAA2B,cAAc,qCAAqC;QAC5E,gDAAgD,CACnD,CAAC;AACJ,CAAC"}
|
package/dist/providers/groq.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
2
|
import { ChatGroqInput } from '@langchain/groq';
|
|
3
3
|
export declare function processJsonConfig(llmConfig: ChatGroqInput): Promise<BaseChatModel>;
|
|
4
|
-
export declare function init(configFileName: string, force?: boolean): void;
|
|
4
|
+
export declare function init(configFileName: string, force?: boolean, model?: string): void;
|
package/dist/providers/groq.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { displayWarning } from '#src/utils/consoleUtils.js';
|
|
2
2
|
import { env } from '#src/utils/systemUtils.js';
|
|
3
3
|
import { writeConfigFileWithMessages } from '#src/utils/fileUtils.js';
|
|
4
|
+
import { buildInitConfigContent, getCuratedFallbackModel } from '#src/providers/modelDiscovery.js';
|
|
4
5
|
// Function to process JSON config and create Groq LLM instance
|
|
5
6
|
export async function processJsonConfig(llmConfig) {
|
|
6
7
|
const groq = await import('@langchain/groq');
|
|
@@ -9,21 +10,15 @@ export async function processJsonConfig(llmConfig) {
|
|
|
9
10
|
return new groq.ChatGroq({
|
|
10
11
|
...llmConfig,
|
|
11
12
|
apiKey: groqApiKey,
|
|
12
|
-
model: llmConfig.model || '
|
|
13
|
+
model: llmConfig.model || getCuratedFallbackModel('groq'),
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
"llm": {
|
|
17
|
-
"type": "groq",
|
|
18
|
-
"model": "openai/gpt-oss-120b"
|
|
19
|
-
}
|
|
20
|
-
}`;
|
|
21
|
-
export function init(configFileName, force = false) {
|
|
16
|
+
export function init(configFileName, force = false, model) {
|
|
22
17
|
// Determine which content to use based on file extension
|
|
23
18
|
if (!configFileName.endsWith('.json')) {
|
|
24
19
|
throw new Error('Only JSON config is supported.');
|
|
25
20
|
}
|
|
26
|
-
writeConfigFileWithMessages(configFileName,
|
|
21
|
+
writeConfigFileWithMessages(configFileName, buildInitConfigContent('groq', model), force);
|
|
27
22
|
displayWarning(`You need to edit your ${configFileName} to configure model, ` +
|
|
28
23
|
'or define GROQ_API_KEY environment variable.');
|
|
29
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"groq.js","sourceRoot":"","sources":["../../src/providers/groq.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAIhD,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"groq.js","sourceRoot":"","sources":["../../src/providers/groq.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAIhD,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAEnG,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,SAAwB;IAC9D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC7C,wEAAwE;IACxE,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,IAAI,GAAG,CAAC,YAAY,CAAC;IACxD,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC;QACvB,GAAG,SAAS;QACZ,MAAM,EAAE,UAAU;QAClB,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,uBAAuB,CAAC,MAAM,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAED,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