@dominikcz/greg 0.9.32 → 0.9.33
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
CHANGED
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
vitePluginGregConfig,
|
|
51
51
|
vitePluginSearchIndex,
|
|
52
52
|
vitePluginSearchServer,
|
|
53
|
+
vitePluginAiServer,
|
|
53
54
|
vitePluginFrontmatter,
|
|
54
55
|
vitePluginCopyDocs,
|
|
55
56
|
} from '@dominikcz/greg/plugins'
|
|
@@ -60,6 +61,7 @@ export default defineConfig({
|
|
|
60
61
|
vitePluginGregConfig(),
|
|
61
62
|
vitePluginSearchIndex({ docsDir: 'docs', srcDir: '/' }),
|
|
62
63
|
vitePluginSearchServer({ docsDir: 'docs', srcDir: '/' }),
|
|
64
|
+
vitePluginAiServer({ docsDir: 'docs', srcDir: '/' }),
|
|
63
65
|
vitePluginFrontmatter({ docsDir: 'docs', srcDir: '/' }),
|
|
64
66
|
vitePluginCopyDocs({ docsDir: 'docs', srcDir: '/' }),
|
|
65
67
|
],
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
vitePluginGregConfig,
|
|
5
5
|
vitePluginSearchIndex,
|
|
6
6
|
vitePluginSearchServer,
|
|
7
|
+
vitePluginAiServer,
|
|
7
8
|
vitePluginFrontmatter,
|
|
8
9
|
vitePluginCopyDocs,
|
|
9
10
|
} from '@dominikcz/greg/plugins'
|
|
@@ -17,6 +18,7 @@ export default defineConfig({
|
|
|
17
18
|
vitePluginGregConfig(),
|
|
18
19
|
vitePluginSearchIndex({ docsDir, srcDir: docsBase }),
|
|
19
20
|
vitePluginSearchServer({ docsDir, srcDir: docsBase }),
|
|
21
|
+
vitePluginAiServer({ docsDir, srcDir: docsBase }),
|
|
20
22
|
vitePluginFrontmatter({ docsDir, srcDir: docsBase }),
|
|
21
23
|
vitePluginCopyDocs({ docsDir, srcDir: docsBase }),
|
|
22
24
|
],
|
package/package.json
CHANGED
|
@@ -24,6 +24,7 @@ import { buildChunks } from './ai/chunker.js';
|
|
|
24
24
|
import { MemoryStore } from './ai/stores/memoryStore.js';
|
|
25
25
|
import { resolveCharacters } from './ai/characters.js';
|
|
26
26
|
import { RagPipeline } from './ai/ragPipeline.js';
|
|
27
|
+
import { loadGregConfig } from './loadGregConfig.js';
|
|
27
28
|
|
|
28
29
|
/** @typedef {import('../../../types/index.js').AiConfig} AiConfig */
|
|
29
30
|
|
|
@@ -33,10 +34,9 @@ export function vitePluginAiServer({
|
|
|
33
34
|
aiUrl = '/api/ai',
|
|
34
35
|
ai = /** @type {AiConfig} */ ({}),
|
|
35
36
|
} = {}) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
37
|
+
const hasExplicitAiConfig = ai && typeof ai === 'object' && Object.keys(ai).length > 0;
|
|
38
|
+
/** @type {AiConfig} */
|
|
39
|
+
let resolvedAi = hasExplicitAiConfig ? ai : /** @type {AiConfig} */ ({});
|
|
40
40
|
|
|
41
41
|
let resolvedDocsDir;
|
|
42
42
|
let viteBase = '/';
|
|
@@ -47,15 +47,15 @@ export function vitePluginAiServer({
|
|
|
47
47
|
let buildPromise = null;
|
|
48
48
|
|
|
49
49
|
async function buildPipeline() {
|
|
50
|
-
const provider = await createProvider(
|
|
50
|
+
const provider = await createProvider(resolvedAi);
|
|
51
51
|
const index = await buildSearchIndex(resolvedDocsDir, srcDir);
|
|
52
|
-
const chunks = buildChunks(index,
|
|
52
|
+
const chunks = buildChunks(index, resolvedAi?.chunking ?? {});
|
|
53
53
|
const store = new MemoryStore();
|
|
54
54
|
await store.index(chunks);
|
|
55
55
|
|
|
56
56
|
const characters = resolveCharacters(
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
resolvedAi?.characters,
|
|
58
|
+
resolvedAi?.customCharacters ?? [],
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
return new RagPipeline(provider, store, characters);
|
|
@@ -91,6 +91,11 @@ export function vitePluginAiServer({
|
|
|
91
91
|
|
|
92
92
|
function middleware() {
|
|
93
93
|
return async (req, res, next) => {
|
|
94
|
+
if (!resolvedAi?.enabled) {
|
|
95
|
+
next();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
94
99
|
const urlStr = req.url ?? '';
|
|
95
100
|
const qIdx = urlStr.indexOf('?');
|
|
96
101
|
const rawPathname = qIdx >= 0 ? urlStr.slice(0, qIdx) : urlStr;
|
|
@@ -128,7 +133,7 @@ export function vitePluginAiServer({
|
|
|
128
133
|
return;
|
|
129
134
|
}
|
|
130
135
|
|
|
131
|
-
const characterId = String(body.character ??
|
|
136
|
+
const characterId = String(body.character ?? resolvedAi?.defaultCharacter ?? 'professional');
|
|
132
137
|
const locale = String(body.locale ?? '');
|
|
133
138
|
|
|
134
139
|
const pipeline = await loadPipeline();
|
|
@@ -156,10 +161,19 @@ export function vitePluginAiServer({
|
|
|
156
161
|
return {
|
|
157
162
|
name: 'greg:ai-server',
|
|
158
163
|
|
|
159
|
-
configResolved(config) {
|
|
164
|
+
async configResolved(config) {
|
|
160
165
|
const dirs = Array.isArray(docsDir) ? docsDir : [docsDir];
|
|
161
166
|
resolvedDocsDir = dirs.map(d => path.resolve(config.root, d));
|
|
162
167
|
viteBase = config.base ?? '/';
|
|
168
|
+
|
|
169
|
+
if (!hasExplicitAiConfig) {
|
|
170
|
+
try {
|
|
171
|
+
const gregConfig = await loadGregConfig();
|
|
172
|
+
resolvedAi = gregConfig?.search?.ai ?? {};
|
|
173
|
+
} catch {
|
|
174
|
+
resolvedAi = {};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
163
177
|
},
|
|
164
178
|
|
|
165
179
|
configureServer(server) {
|