@venturekit-pro/ai 0.0.0-dev.20260701100017 → 0.0.1
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/README.md +48 -0
- package/dist/chat/anthropic.d.ts.map +1 -1
- package/dist/chat/anthropic.js +39 -32
- package/dist/chat/anthropic.js.map +1 -1
- package/dist/chat/google.d.ts.map +1 -1
- package/dist/chat/google.js +32 -25
- package/dist/chat/google.js.map +1 -1
- package/dist/chat/openai.d.ts.map +1 -1
- package/dist/chat/openai.js +34 -27
- package/dist/chat/openai.js.map +1 -1
- package/dist/cost-ledger/index.d.ts +2 -0
- package/dist/cost-ledger/index.d.ts.map +1 -1
- package/dist/cost-ledger/index.js +1 -0
- package/dist/cost-ledger/index.js.map +1 -1
- package/dist/cost-ledger/migrations/vk_ai_cost_0001_init.sql +6 -6
- package/dist/cost-ledger/migrations/vk_ai_cost_0002_llm_models.sql +4 -4
- package/dist/cost-ledger/query.js +4 -4
- package/dist/cost-ledger/record.js +2 -2
- package/dist/cost-ledger/record.js.map +1 -1
- package/dist/cost-ledger/windows.d.ts +82 -0
- package/dist/cost-ledger/windows.d.ts.map +1 -0
- package/dist/cost-ledger/windows.js +147 -0
- package/dist/cost-ledger/windows.js.map +1 -0
- package/dist/image/client.d.ts +32 -0
- package/dist/image/client.d.ts.map +1 -0
- package/dist/image/client.js +25 -0
- package/dist/image/client.js.map +1 -0
- package/dist/image/google.d.ts +24 -0
- package/dist/image/google.d.ts.map +1 -0
- package/dist/image/google.js +60 -0
- package/dist/image/google.js.map +1 -0
- package/dist/image/index.d.ts +11 -0
- package/dist/image/index.d.ts.map +1 -0
- package/dist/image/index.js +9 -0
- package/dist/image/index.js.map +1 -0
- package/dist/image/types.d.ts +67 -0
- package/dist/image/types.d.ts.map +1 -0
- package/dist/image/types.js +19 -0
- package/dist/image/types.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/model-catalog/crud.d.ts +42 -0
- package/dist/model-catalog/crud.d.ts.map +1 -0
- package/dist/model-catalog/crud.js +162 -0
- package/dist/model-catalog/crud.js.map +1 -0
- package/dist/model-catalog/index.d.ts +11 -0
- package/dist/model-catalog/index.d.ts.map +1 -0
- package/dist/model-catalog/index.js +10 -0
- package/dist/model-catalog/index.js.map +1 -0
- package/dist/model-catalog/types.d.ts +97 -0
- package/dist/model-catalog/types.d.ts.map +1 -0
- package/dist/model-catalog/types.js +16 -0
- package/dist/model-catalog/types.js.map +1 -0
- package/package.json +3 -3
- package/src/cost-ledger/migrations/vk_ai_cost_0001_init.sql +6 -6
- package/src/cost-ledger/migrations/vk_ai_cost_0002_llm_models.sql +4 -4
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CRUD over `vk_llm_models` — the model catalog.
|
|
3
|
+
*
|
|
4
|
+
* Pure SQL against a caller-supplied `Querier`; no `@venturekit/data`
|
|
5
|
+
* import (the consumer passes their `query` / transaction querier).
|
|
6
|
+
*
|
|
7
|
+
* Lifecycle timestamps are auto-managed on `status` transitions and the
|
|
8
|
+
* DB enforces `llm_models_status_timestamps_chk` so a `deprecated` /
|
|
9
|
+
* `disabled` row always has its matching timestamp. The `key` PK and the
|
|
10
|
+
* `(provider, model)` unique constraint are DB-enforced — callers map
|
|
11
|
+
* `23505` to a 409 via `isUniqueViolation`. The self-referencing
|
|
12
|
+
* `replacement_key` FK trips `23503` when it names a non-existent key.
|
|
13
|
+
*/
|
|
14
|
+
/** List every catalog row, ordered by provider then key. */
|
|
15
|
+
export async function listModels(querier) {
|
|
16
|
+
return querier(`SELECT * FROM vk_llm_models ORDER BY provider ASC, key ASC`);
|
|
17
|
+
}
|
|
18
|
+
/** Fetch one catalog row by `key` PK, or `null` when absent. */
|
|
19
|
+
export async function getModelByKey(querier, key) {
|
|
20
|
+
const rows = await querier(`SELECT * FROM vk_llm_models WHERE key = $1 LIMIT 1`, [key]);
|
|
21
|
+
return rows[0] ?? null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Insert a new catalog row. When created already in a `deprecated` /
|
|
25
|
+
* `disabled` state the matching lifecycle timestamp is auto-stamped to
|
|
26
|
+
* `NOW()` so the happy path stays one-shot (and satisfies the DB CHECK).
|
|
27
|
+
*/
|
|
28
|
+
export async function createModel(querier, input) {
|
|
29
|
+
const status = input.status ?? 'available';
|
|
30
|
+
const deprecatedAt = status === 'deprecated' ? 'NOW()' : 'NULL';
|
|
31
|
+
const disabledAt = status === 'disabled' ? 'NOW()' : 'NULL';
|
|
32
|
+
const rows = await querier(`INSERT INTO vk_llm_models (
|
|
33
|
+
key, provider, model, display_name, description, status, replacement_key,
|
|
34
|
+
cost_per_1k_input, cost_per_1k_output,
|
|
35
|
+
context_window, max_output_tokens,
|
|
36
|
+
supports_json_mode, supports_image_input,
|
|
37
|
+
default_max_tokens, default_temperature,
|
|
38
|
+
tags, notes,
|
|
39
|
+
deprecated_at, disabled_at
|
|
40
|
+
) VALUES (
|
|
41
|
+
$1, $2, $3, $4, $5, $6::llm_model_status, $7,
|
|
42
|
+
$8, $9,
|
|
43
|
+
$10, $11,
|
|
44
|
+
$12, $13,
|
|
45
|
+
$14, $15,
|
|
46
|
+
$16, $17,
|
|
47
|
+
${deprecatedAt}, ${disabledAt}
|
|
48
|
+
)
|
|
49
|
+
RETURNING *`, [
|
|
50
|
+
input.key,
|
|
51
|
+
input.provider,
|
|
52
|
+
input.model,
|
|
53
|
+
input.displayName,
|
|
54
|
+
input.description ?? null,
|
|
55
|
+
status,
|
|
56
|
+
input.replacementKey ?? null,
|
|
57
|
+
input.costPer1kInput ?? null,
|
|
58
|
+
input.costPer1kOutput ?? null,
|
|
59
|
+
input.contextWindow ?? null,
|
|
60
|
+
input.maxOutputTokens ?? null,
|
|
61
|
+
input.supportsJsonMode ?? false,
|
|
62
|
+
input.supportsImageInput ?? false,
|
|
63
|
+
input.defaultMaxTokens ?? 4096,
|
|
64
|
+
input.defaultTemperature ?? 0.7,
|
|
65
|
+
input.tags ?? [],
|
|
66
|
+
input.notes ?? null,
|
|
67
|
+
]);
|
|
68
|
+
const row = rows[0];
|
|
69
|
+
if (!row)
|
|
70
|
+
throw new Error('vk_llm_models insert returned no rows');
|
|
71
|
+
return row;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Patch a catalog row. Returns `null` when the row doesn't exist.
|
|
75
|
+
*
|
|
76
|
+
* Status transitions auto-stamp / auto-clear the lifecycle timestamps:
|
|
77
|
+
* - `available` — clears both `deprecated_at` + `disabled_at`.
|
|
78
|
+
* - `deprecated` — sets `deprecated_at` (COALESCE preserves the
|
|
79
|
+
* original transition time across no-op repeats), clears `disabled_at`.
|
|
80
|
+
* - `disabled` — sets `disabled_at` (same COALESCE preservation).
|
|
81
|
+
*/
|
|
82
|
+
export async function patchModel(querier, key, input) {
|
|
83
|
+
const sets = ['updated_at = NOW()'];
|
|
84
|
+
const params = [];
|
|
85
|
+
const setField = (col, value, cast) => {
|
|
86
|
+
params.push(value);
|
|
87
|
+
sets.push(`${col} = $${params.length}${cast ? `::${cast}` : ''}`);
|
|
88
|
+
};
|
|
89
|
+
if (input.provider !== undefined)
|
|
90
|
+
setField('provider', input.provider);
|
|
91
|
+
if (input.model !== undefined)
|
|
92
|
+
setField('model', input.model);
|
|
93
|
+
if (input.displayName !== undefined)
|
|
94
|
+
setField('display_name', input.displayName);
|
|
95
|
+
if (input.description !== undefined)
|
|
96
|
+
setField('description', input.description);
|
|
97
|
+
if (input.replacementKey !== undefined)
|
|
98
|
+
setField('replacement_key', input.replacementKey);
|
|
99
|
+
if (input.costPer1kInput !== undefined)
|
|
100
|
+
setField('cost_per_1k_input', input.costPer1kInput);
|
|
101
|
+
if (input.costPer1kOutput !== undefined)
|
|
102
|
+
setField('cost_per_1k_output', input.costPer1kOutput);
|
|
103
|
+
if (input.contextWindow !== undefined)
|
|
104
|
+
setField('context_window', input.contextWindow);
|
|
105
|
+
if (input.maxOutputTokens !== undefined)
|
|
106
|
+
setField('max_output_tokens', input.maxOutputTokens);
|
|
107
|
+
if (input.supportsJsonMode !== undefined)
|
|
108
|
+
setField('supports_json_mode', input.supportsJsonMode);
|
|
109
|
+
if (input.supportsImageInput !== undefined)
|
|
110
|
+
setField('supports_image_input', input.supportsImageInput);
|
|
111
|
+
if (input.defaultMaxTokens !== undefined)
|
|
112
|
+
setField('default_max_tokens', input.defaultMaxTokens);
|
|
113
|
+
if (input.defaultTemperature !== undefined)
|
|
114
|
+
setField('default_temperature', input.defaultTemperature);
|
|
115
|
+
if (input.tags !== undefined)
|
|
116
|
+
setField('tags', input.tags);
|
|
117
|
+
if (input.notes !== undefined)
|
|
118
|
+
setField('notes', input.notes);
|
|
119
|
+
if (input.status !== undefined) {
|
|
120
|
+
setField('status', input.status, 'llm_model_status');
|
|
121
|
+
if (input.status === 'available') {
|
|
122
|
+
sets.push('deprecated_at = NULL');
|
|
123
|
+
sets.push('disabled_at = NULL');
|
|
124
|
+
}
|
|
125
|
+
else if (input.status === 'deprecated') {
|
|
126
|
+
sets.push(`deprecated_at = COALESCE((SELECT deprecated_at FROM vk_llm_models WHERE key = $${params.length + 1}), NOW())`);
|
|
127
|
+
sets.push('disabled_at = NULL');
|
|
128
|
+
}
|
|
129
|
+
else if (input.status === 'disabled') {
|
|
130
|
+
sets.push(`disabled_at = COALESCE((SELECT disabled_at FROM vk_llm_models WHERE key = $${params.length + 1}), NOW())`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
params.push(key);
|
|
134
|
+
const sql = `UPDATE vk_llm_models
|
|
135
|
+
SET ${sets.join(', ')}
|
|
136
|
+
WHERE key = $${params.length}
|
|
137
|
+
RETURNING *`;
|
|
138
|
+
const rows = await querier(sql, params);
|
|
139
|
+
return rows[0] ?? null;
|
|
140
|
+
}
|
|
141
|
+
// ─── PG error helpers ───────────────────────────────────────────────
|
|
142
|
+
/** True when `err` is a Postgres `unique_violation` (23505). */
|
|
143
|
+
export function isUniqueViolation(err) {
|
|
144
|
+
if (err && typeof err === 'object' && 'code' in err) {
|
|
145
|
+
if (err.code === '23505')
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
149
|
+
return /duplicate key|unique constraint/i.test(message);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* True when `err` is a Postgres `foreign_key_violation` (23503) — the
|
|
153
|
+
* catalog's only FK is the self-referencing `replacement_key`.
|
|
154
|
+
*/
|
|
155
|
+
export function isForeignKeyViolation(err) {
|
|
156
|
+
if (err && typeof err === 'object' && 'code' in err) {
|
|
157
|
+
if (err.code === '23503')
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=crud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.js","sourceRoot":"","sources":["../../src/model-catalog/crud.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAgB;IAC/C,OAAO,OAAO,CACZ,4DAA4D,CAC7D,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAgB,EAChB,GAAW;IAEX,MAAM,IAAI,GAAG,MAAM,OAAO,CACxB,oDAAoD,EACpD,CAAC,GAAG,CAAC,CACN,CAAC;IACF,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAgB,EAChB,KAA0B;IAE1B,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,WAAW,CAAC;IAC3C,MAAM,YAAY,GAAG,MAAM,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAA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ED,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjB,MAAM,GAAG,GAAG;wBACU,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;+BACR,MAAM,CAAC,MAAM;4BAChB,CAAC;IAE3B,MAAM,IAAI,GAAG,MAAM,OAAO,CAAgB,GAAG,EAAE,MAAM,CAAC,CAAC;IACvD,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACzB,CAAC;AAED,uEAAuE;AAEvE,gEAAgE;AAChE,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QACpD,IAAK,GAA0B,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,IAAI,CAAC;IAChE,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,kCAAkC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC1D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAY;IAChD,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QACpD,IAAK,GAA0B,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,IAAI,CAAC;IAChE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `vk_llm_models` catalog — CRUD + types.
|
|
3
|
+
*
|
|
4
|
+
* The platform-admin-owned roster of callable models. Pair with the
|
|
5
|
+
* cost-ledger (`../cost-ledger`) which records actual usage, and with
|
|
6
|
+
* `createModelCatalog` (`../cost`) which builds the call-time lookup
|
|
7
|
+
* over `ModelDescriptor`s derived from these rows.
|
|
8
|
+
*/
|
|
9
|
+
export type { LlmModelStatus, LlmModelRow, CreateLlmModelInput, PatchLlmModelInput, Querier, } from './types.js';
|
|
10
|
+
export { listModels, getModelByKey, createModel, patchModel, isUniqueViolation, isForeignKeyViolation, } from './crud.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model-catalog/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EACV,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,OAAO,GACR,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,UAAU,EACV,aAAa,EACb,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `vk_llm_models` catalog — CRUD + types.
|
|
3
|
+
*
|
|
4
|
+
* The platform-admin-owned roster of callable models. Pair with the
|
|
5
|
+
* cost-ledger (`../cost-ledger`) which records actual usage, and with
|
|
6
|
+
* `createModelCatalog` (`../cost`) which builds the call-time lookup
|
|
7
|
+
* over `ModelDescriptor`s derived from these rows.
|
|
8
|
+
*/
|
|
9
|
+
export { listModels, getModelByKey, createModel, patchModel, isUniqueViolation, isForeignKeyViolation, } from './crud.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model-catalog/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH,OAAO,EACL,UAAU,EACV,aAAa,EACb,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the `vk_llm_models` catalog CRUD module.
|
|
3
|
+
*
|
|
4
|
+
* Sibling of the cost-ledger: the catalog answers "what models can I
|
|
5
|
+
* call, and what does each cost?" (schema in `vk_ai_cost_0002_llm_models.sql`).
|
|
6
|
+
* The table is generic — any consumer of `@venturekit-pro/ai` gets the
|
|
7
|
+
* same shape. Catalog *contents* are an app-level seed concern.
|
|
8
|
+
*
|
|
9
|
+
* The row shape mirrors `ModelDescriptor` (see `../cost/types.ts`) but
|
|
10
|
+
* is wider: it carries the raw NUMERIC pricing/temperature columns (which
|
|
11
|
+
* `pg` surfaces as strings) and the catalog-only metadata
|
|
12
|
+
* (`defaultMaxTokens`, `notes`, timestamps) that the descriptor narrows
|
|
13
|
+
* away for the call-time path.
|
|
14
|
+
*/
|
|
15
|
+
import type { ChatProvider } from '../chat/types.js';
|
|
16
|
+
import type { ModelStatus } from '../cost/types.js';
|
|
17
|
+
/** Lifecycle status — mirrors the DB enum `llm_model_status`. */
|
|
18
|
+
export type LlmModelStatus = ModelStatus;
|
|
19
|
+
/**
|
|
20
|
+
* One row of `vk_llm_models`, post-mapping (snake_case → camelCase).
|
|
21
|
+
*
|
|
22
|
+
* **Numeric columns surface as strings.** `pg` returns Postgres NUMERIC
|
|
23
|
+
* as strings to preserve precision; the cost-estimator / DTO mappers
|
|
24
|
+
* `Number()`-convert at their boundaries.
|
|
25
|
+
*/
|
|
26
|
+
export interface LlmModelRow {
|
|
27
|
+
key: string;
|
|
28
|
+
provider: ChatProvider;
|
|
29
|
+
model: string;
|
|
30
|
+
displayName: string;
|
|
31
|
+
description: string | null;
|
|
32
|
+
status: LlmModelStatus;
|
|
33
|
+
/** When `status='deprecated'`, the catalog `key` of the suggested replacement. */
|
|
34
|
+
replacementKey: string | null;
|
|
35
|
+
/** USD per 1K input tokens. Null for experimental / on-prem models. */
|
|
36
|
+
costPer1kInput: string | null;
|
|
37
|
+
/** USD per 1K output tokens. Null for experimental / on-prem models. */
|
|
38
|
+
costPer1kOutput: string | null;
|
|
39
|
+
contextWindow: number | null;
|
|
40
|
+
maxOutputTokens: number | null;
|
|
41
|
+
supportsJsonMode: boolean;
|
|
42
|
+
supportsImageInput: boolean;
|
|
43
|
+
defaultMaxTokens: number;
|
|
44
|
+
/** Stored as numeric(4,3); arrives as a string. */
|
|
45
|
+
defaultTemperature: string;
|
|
46
|
+
tags: string[];
|
|
47
|
+
introducedAt: Date;
|
|
48
|
+
deprecatedAt: Date | null;
|
|
49
|
+
disabledAt: Date | null;
|
|
50
|
+
notes: string | null;
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
updatedAt: Date;
|
|
53
|
+
}
|
|
54
|
+
export interface CreateLlmModelInput {
|
|
55
|
+
key: string;
|
|
56
|
+
provider: ChatProvider;
|
|
57
|
+
model: string;
|
|
58
|
+
displayName: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
status?: LlmModelStatus;
|
|
61
|
+
replacementKey?: string;
|
|
62
|
+
costPer1kInput?: number;
|
|
63
|
+
costPer1kOutput?: number;
|
|
64
|
+
contextWindow?: number;
|
|
65
|
+
maxOutputTokens?: number;
|
|
66
|
+
supportsJsonMode?: boolean;
|
|
67
|
+
supportsImageInput?: boolean;
|
|
68
|
+
defaultMaxTokens?: number;
|
|
69
|
+
defaultTemperature?: number;
|
|
70
|
+
tags?: string[];
|
|
71
|
+
notes?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface PatchLlmModelInput {
|
|
74
|
+
provider?: ChatProvider;
|
|
75
|
+
model?: string;
|
|
76
|
+
displayName?: string;
|
|
77
|
+
description?: string | null;
|
|
78
|
+
status?: LlmModelStatus;
|
|
79
|
+
replacementKey?: string | null;
|
|
80
|
+
costPer1kInput?: number | null;
|
|
81
|
+
costPer1kOutput?: number | null;
|
|
82
|
+
contextWindow?: number | null;
|
|
83
|
+
maxOutputTokens?: number | null;
|
|
84
|
+
supportsJsonMode?: boolean;
|
|
85
|
+
supportsImageInput?: boolean;
|
|
86
|
+
defaultMaxTokens?: number;
|
|
87
|
+
defaultTemperature?: number;
|
|
88
|
+
tags?: string[];
|
|
89
|
+
notes?: string | null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Querier — same shape as the rest of the workspace. Declared locally so
|
|
93
|
+
* the module carries no hard dependency on `@venturekit/data`; the
|
|
94
|
+
* consumer passes their `query` / transaction querier in.
|
|
95
|
+
*/
|
|
96
|
+
export type Querier = <T = Record<string, unknown>[]>(sql: string, params?: unknown[]) => Promise<T>;
|
|
97
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/model-catalog/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,iEAAiE;AACjE,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,cAAc,CAAC;IACvB,kFAAkF;IAClF,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uEAAuE;IACvE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,wEAAwE;IACxE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,mDAAmD;IACnD,kBAAkB,EA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;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAClD,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,KACf,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the `vk_llm_models` catalog CRUD module.
|
|
3
|
+
*
|
|
4
|
+
* Sibling of the cost-ledger: the catalog answers "what models can I
|
|
5
|
+
* call, and what does each cost?" (schema in `vk_ai_cost_0002_llm_models.sql`).
|
|
6
|
+
* The table is generic — any consumer of `@venturekit-pro/ai` gets the
|
|
7
|
+
* same shape. Catalog *contents* are an app-level seed concern.
|
|
8
|
+
*
|
|
9
|
+
* The row shape mirrors `ModelDescriptor` (see `../cost/types.ts`) but
|
|
10
|
+
* is wider: it carries the raw NUMERIC pricing/temperature columns (which
|
|
11
|
+
* `pg` surfaces as strings) and the catalog-only metadata
|
|
12
|
+
* (`defaultMaxTokens`, `notes`, timestamps) that the descriptor narrows
|
|
13
|
+
* away for the call-time path.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/model-catalog/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venturekit-pro/ai",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "AI utilities for VentureKit - embeddings, RAG, and
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "AI utilities for VentureKit - embeddings, RAG, agents, chat completion, and image generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"rag"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@venturekit/core": "0.0.
|
|
40
|
+
"@venturekit/core": "0.0.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@aws-sdk/client-bedrock-runtime": "^3.0.0",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
|
18
18
|
|
|
19
|
-
CREATE TABLE IF NOT EXISTS
|
|
19
|
+
CREATE TABLE IF NOT EXISTS vk_llm_cost_events (
|
|
20
20
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
21
21
|
-- Nullable to match the audit-events convention; platform-wide
|
|
22
22
|
-- LLM calls (e.g. eval / smoke tests) carry tenant_id = NULL.
|
|
@@ -56,19 +56,19 @@ CREATE TABLE IF NOT EXISTS llm_cost_events (
|
|
|
56
56
|
-- ─── Indexes ────────────────────────────────────────────────────────
|
|
57
57
|
|
|
58
58
|
CREATE INDEX IF NOT EXISTS llm_cost_events_tenant_created_idx
|
|
59
|
-
ON
|
|
59
|
+
ON vk_llm_cost_events (tenant_id, created_at DESC);
|
|
60
60
|
|
|
61
61
|
CREATE INDEX IF NOT EXISTS llm_cost_events_target_idx
|
|
62
|
-
ON
|
|
62
|
+
ON vk_llm_cost_events (tenant_id, target_type, target_id, created_at DESC);
|
|
63
63
|
|
|
64
64
|
CREATE INDEX IF NOT EXISTS llm_cost_events_correlation_idx
|
|
65
|
-
ON
|
|
65
|
+
ON vk_llm_cost_events (correlation_id, created_at DESC)
|
|
66
66
|
WHERE correlation_id IS NOT NULL;
|
|
67
67
|
|
|
68
68
|
CREATE INDEX IF NOT EXISTS llm_cost_events_tenant_provider_idx
|
|
69
|
-
ON
|
|
69
|
+
ON vk_llm_cost_events (tenant_id, provider, created_at DESC);
|
|
70
70
|
|
|
71
71
|
-- Idempotency dedup. Partial because most rows have NULL key.
|
|
72
72
|
CREATE UNIQUE INDEX IF NOT EXISTS llm_cost_events_idempotency_unique
|
|
73
|
-
ON
|
|
73
|
+
ON vk_llm_cost_events (idempotency_key)
|
|
74
74
|
WHERE idempotency_key IS NOT NULL;
|
|
@@ -51,7 +51,7 @@ CREATE TYPE llm_model_status AS ENUM (
|
|
|
51
51
|
|
|
52
52
|
-- ─── llm_models ────────────────────────────────────────────────────
|
|
53
53
|
|
|
54
|
-
CREATE TABLE IF NOT EXISTS
|
|
54
|
+
CREATE TABLE IF NOT EXISTS vk_llm_models (
|
|
55
55
|
-- Stable catalog id. App-side rows (e.g. `editorial_personas.model`
|
|
56
56
|
-- in the CMS) store THIS, not the vendor's wire id. Lets vendors
|
|
57
57
|
-- rename / replace a SKU without re-stamping every consumer.
|
|
@@ -69,7 +69,7 @@ CREATE TABLE IF NOT EXISTS llm_models (
|
|
|
69
69
|
-- When status='deprecated', the suggested replacement `key`. Used
|
|
70
70
|
-- by the CMS's persona picker to surface "Use <replacement>
|
|
71
71
|
-- instead" nudges (§4.10).
|
|
72
|
-
replacement_key varchar(64) REFERENCES
|
|
72
|
+
replacement_key varchar(64) REFERENCES vk_llm_models(key) ON DELETE SET NULL,
|
|
73
73
|
|
|
74
74
|
-- ─── Pricing (USD per 1K tokens) ────────────────────────────────
|
|
75
75
|
-- Nullable for experimental / on-prem models with no published
|
|
@@ -116,9 +116,9 @@ CREATE TABLE IF NOT EXISTS llm_models (
|
|
|
116
116
|
);
|
|
117
117
|
|
|
118
118
|
CREATE INDEX IF NOT EXISTS llm_models_status_idx
|
|
119
|
-
ON
|
|
119
|
+
ON vk_llm_models (status);
|
|
120
120
|
CREATE INDEX IF NOT EXISTS llm_models_provider_idx
|
|
121
|
-
ON
|
|
121
|
+
ON vk_llm_models (provider);
|
|
122
122
|
|
|
123
123
|
-- ─── No seed ───────────────────────────────────────────────────────
|
|
124
124
|
-- Intentionally empty. See file header for the rationale: catalog
|