@dani-builder/strapi-plugin-agent 0.2.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.
- package/README.md +59 -0
- package/dist/server/src/config/index.d.ts +12 -0
- package/dist/server/src/config/index.d.ts.map +1 -0
- package/dist/server/src/config/index.js +36 -0
- package/dist/server/src/config/index.js.map +1 -0
- package/dist/server/src/content-types/index.d.ts +76 -0
- package/dist/server/src/content-types/index.d.ts.map +1 -0
- package/dist/server/src/content-types/index.js +11 -0
- package/dist/server/src/content-types/index.js.map +1 -0
- package/dist/server/src/content-types/knowledge-source/index.d.ts +3 -0
- package/dist/server/src/content-types/knowledge-source/index.d.ts.map +1 -0
- package/dist/server/src/content-types/knowledge-source/index.js +8 -0
- package/dist/server/src/content-types/knowledge-source/index.js.map +1 -0
- package/dist/server/src/content-types/knowledge-source/schema.json +39 -0
- package/dist/server/src/controllers/chat.d.ts +18 -0
- package/dist/server/src/controllers/chat.d.ts.map +1 -0
- package/dist/server/src/controllers/chat.js +74 -0
- package/dist/server/src/controllers/chat.js.map +1 -0
- package/dist/server/src/controllers/index.d.ts +3 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -0
- package/dist/server/src/controllers/index.js +9 -0
- package/dist/server/src/controllers/index.js.map +1 -0
- package/dist/server/src/index.d.ts +13 -0
- package/dist/server/src/index.d.ts.map +1 -0
- package/dist/server/src/index.js +23 -0
- package/dist/server/src/index.js.map +1 -0
- package/dist/server/src/plugin-id.d.ts +2 -0
- package/dist/server/src/plugin-id.d.ts.map +1 -0
- package/dist/server/src/plugin-id.js +5 -0
- package/dist/server/src/plugin-id.js.map +1 -0
- package/dist/server/src/policies/index.d.ts +3 -0
- package/dist/server/src/policies/index.d.ts.map +1 -0
- package/dist/server/src/policies/index.js +11 -0
- package/dist/server/src/policies/index.js.map +1 -0
- package/dist/server/src/policies/rate-limit.d.ts +23 -0
- package/dist/server/src/policies/rate-limit.d.ts.map +1 -0
- package/dist/server/src/policies/rate-limit.js +37 -0
- package/dist/server/src/policies/rate-limit.js.map +1 -0
- package/dist/server/src/register.d.ts +16 -0
- package/dist/server/src/register.d.ts.map +1 -0
- package/dist/server/src/register.js +13 -0
- package/dist/server/src/register.js.map +1 -0
- package/dist/server/src/routes/content-api.d.ts +13 -0
- package/dist/server/src/routes/content-api.d.ts.map +1 -0
- package/dist/server/src/routes/content-api.js +15 -0
- package/dist/server/src/routes/content-api.js.map +1 -0
- package/dist/server/src/routes/index.d.ts +15 -0
- package/dist/server/src/routes/index.d.ts.map +1 -0
- package/dist/server/src/routes/index.js +8 -0
- package/dist/server/src/routes/index.js.map +1 -0
- package/dist/server/src/services/blocks-serializer.d.ts +2 -0
- package/dist/server/src/services/blocks-serializer.d.ts.map +1 -0
- package/dist/server/src/services/blocks-serializer.js +46 -0
- package/dist/server/src/services/blocks-serializer.js.map +1 -0
- package/dist/server/src/services/canonical-json.d.ts +4 -0
- package/dist/server/src/services/canonical-json.d.ts.map +1 -0
- package/dist/server/src/services/canonical-json.js +29 -0
- package/dist/server/src/services/canonical-json.js.map +1 -0
- package/dist/server/src/services/chat-service.d.ts +27 -0
- package/dist/server/src/services/chat-service.d.ts.map +1 -0
- package/dist/server/src/services/chat-service.js +48 -0
- package/dist/server/src/services/chat-service.js.map +1 -0
- package/dist/server/src/services/chat.d.ts +20 -0
- package/dist/server/src/services/chat.d.ts.map +1 -0
- package/dist/server/src/services/chat.js +98 -0
- package/dist/server/src/services/chat.js.map +1 -0
- package/dist/server/src/services/chunker.d.ts +11 -0
- package/dist/server/src/services/chunker.d.ts.map +1 -0
- package/dist/server/src/services/chunker.js +67 -0
- package/dist/server/src/services/chunker.js.map +1 -0
- package/dist/server/src/services/control-plane.d.ts +13 -0
- package/dist/server/src/services/control-plane.d.ts.map +1 -0
- package/dist/server/src/services/control-plane.js +25 -0
- package/dist/server/src/services/control-plane.js.map +1 -0
- package/dist/server/src/services/embeddings.d.ts +10 -0
- package/dist/server/src/services/embeddings.d.ts.map +1 -0
- package/dist/server/src/services/embeddings.js +55 -0
- package/dist/server/src/services/embeddings.js.map +1 -0
- package/dist/server/src/services/extractor.d.ts +20 -0
- package/dist/server/src/services/extractor.d.ts.map +1 -0
- package/dist/server/src/services/extractor.js +39 -0
- package/dist/server/src/services/extractor.js.map +1 -0
- package/dist/server/src/services/index.d.ts +7 -0
- package/dist/server/src/services/index.d.ts.map +1 -0
- package/dist/server/src/services/index.js +21 -0
- package/dist/server/src/services/index.js.map +1 -0
- package/dist/server/src/services/indexer-service.d.ts +13 -0
- package/dist/server/src/services/indexer-service.d.ts.map +1 -0
- package/dist/server/src/services/indexer-service.js +14 -0
- package/dist/server/src/services/indexer-service.js.map +1 -0
- package/dist/server/src/services/indexer.d.ts +23 -0
- package/dist/server/src/services/indexer.d.ts.map +1 -0
- package/dist/server/src/services/indexer.js +82 -0
- package/dist/server/src/services/indexer.js.map +1 -0
- package/dist/server/src/services/knowledge-source.d.ts +51 -0
- package/dist/server/src/services/knowledge-source.d.ts.map +1 -0
- package/dist/server/src/services/knowledge-source.js +87 -0
- package/dist/server/src/services/knowledge-source.js.map +1 -0
- package/dist/server/src/services/provider.d.ts +17 -0
- package/dist/server/src/services/provider.d.ts.map +1 -0
- package/dist/server/src/services/provider.js +99 -0
- package/dist/server/src/services/provider.js.map +1 -0
- package/dist/server/src/services/qdrant-store.d.ts +63 -0
- package/dist/server/src/services/qdrant-store.d.ts.map +1 -0
- package/dist/server/src/services/qdrant-store.js +138 -0
- package/dist/server/src/services/qdrant-store.js.map +1 -0
- package/dist/server/src/services/retrieval.d.ts +49 -0
- package/dist/server/src/services/retrieval.d.ts.map +1 -0
- package/dist/server/src/services/retrieval.js +110 -0
- package/dist/server/src/services/retrieval.js.map +1 -0
- package/dist/server/src/services/schema-serializer.d.ts +27 -0
- package/dist/server/src/services/schema-serializer.d.ts.map +1 -0
- package/dist/server/src/services/schema-serializer.js +119 -0
- package/dist/server/src/services/schema-serializer.js.map +1 -0
- package/dist/server/src/services/serializer.d.ts +26 -0
- package/dist/server/src/services/serializer.d.ts.map +1 -0
- package/dist/server/src/services/serializer.js +98 -0
- package/dist/server/src/services/serializer.js.map +1 -0
- package/dist/server/src/services/sse.d.ts +8 -0
- package/dist/server/src/services/sse.d.ts.map +1 -0
- package/dist/server/src/services/sse.js +41 -0
- package/dist/server/src/services/sse.js.map +1 -0
- package/package.json +51 -0
- package/strapi-server.js +3 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractDocument = extractDocument;
|
|
4
|
+
const blocks_serializer_1 = require("./blocks-serializer");
|
|
5
|
+
const schema_serializer_1 = require("./schema-serializer");
|
|
6
|
+
/** Extract a stable text document from either flat field mappings or a schema. */
|
|
7
|
+
function extractDocument(entry, source, registry, componentSerializer) {
|
|
8
|
+
const title = String(entry[source.titleField] ?? "").trim();
|
|
9
|
+
const description = source.descriptionField
|
|
10
|
+
? String(entry[source.descriptionField] ?? "").trim() || undefined
|
|
11
|
+
: undefined;
|
|
12
|
+
const bodyParts = source.extractionMode === "schema" && registry
|
|
13
|
+
? [
|
|
14
|
+
(0, schema_serializer_1.serializeContentType)(source.uid, entry, {
|
|
15
|
+
registry,
|
|
16
|
+
excludedFields: new Set([
|
|
17
|
+
"anchorId",
|
|
18
|
+
...(source.excludedFields ?? []),
|
|
19
|
+
]),
|
|
20
|
+
rootExcludedFields: new Set([source.titleField, source.descriptionField].filter((field) => Boolean(field))),
|
|
21
|
+
componentSerializer,
|
|
22
|
+
}),
|
|
23
|
+
].filter(Boolean)
|
|
24
|
+
: source.bodyFields
|
|
25
|
+
.map((field) => (0, blocks_serializer_1.blocksToText)(entry[field]))
|
|
26
|
+
.filter((part) => part.length > 0);
|
|
27
|
+
const text = [title, description, ...bodyParts]
|
|
28
|
+
.filter((part) => Boolean(part && part.length))
|
|
29
|
+
.join("\n\n")
|
|
30
|
+
.trim();
|
|
31
|
+
const slug = source.slugField
|
|
32
|
+
? String(entry[source.slugField] ?? "").trim()
|
|
33
|
+
: "";
|
|
34
|
+
const url = slug && source.urlPattern
|
|
35
|
+
? source.urlPattern.replace("{slug}", slug)
|
|
36
|
+
: undefined;
|
|
37
|
+
return { title, description, text, url };
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../../server/src/services/extractor.ts"],"names":[],"mappings":";;AA0BA,0CA2CC;AArED,2DAAmD;AACnD,2DAI6B;AAoB7B,kFAAkF;AAClF,SAAgB,eAAe,CAC7B,KAA8B,EAC9B,MAA0B,EAC1B,QAAyB,EACzB,mBAAiE;IAEjE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5D,MAAM,WAAW,GAAG,MAAM,CAAC,gBAAgB;QACzC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,SAAS;QAClE,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,SAAS,GACb,MAAM,CAAC,cAAc,KAAK,QAAQ,IAAI,QAAQ;QAC5C,CAAC,CAAC;YACE,IAAA,wCAAoB,EAAC,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE;gBACtC,QAAQ;gBACR,cAAc,EAAE,IAAI,GAAG,CAAC;oBACtB,UAAU;oBACV,GAAG,CAAC,MAAM,CAAC,cAAc,IAAI,EAAE,CAAC;iBACjC,CAAC;gBACF,kBAAkB,EAAE,IAAI,GAAG,CACzB,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC,MAAM,CACjD,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAC3C,CACF;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AAA,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAO5C,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const indexer_service_1 = __importDefault(require("./indexer-service"));
|
|
7
|
+
const chat_service_1 = __importDefault(require("./chat-service"));
|
|
8
|
+
const control_plane_1 = require("./control-plane");
|
|
9
|
+
const knowledge_source_1 = __importDefault(require("./knowledge-source"));
|
|
10
|
+
const retrieval_1 = __importDefault(require("./retrieval"));
|
|
11
|
+
const serializer_1 = __importDefault(require("./serializer"));
|
|
12
|
+
const services = {
|
|
13
|
+
chat: chat_service_1.default,
|
|
14
|
+
"control-plane": () => ({ select: control_plane_1.selectControlPlane }),
|
|
15
|
+
serializer: serializer_1.default,
|
|
16
|
+
indexer: indexer_service_1.default,
|
|
17
|
+
"knowledge-source": knowledge_source_1.default,
|
|
18
|
+
retrieval: retrieval_1.default,
|
|
19
|
+
};
|
|
20
|
+
exports.default = services;
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/src/services/index.ts"],"names":[],"mappings":";;;;;AACA,wEAAwC;AACxC,kEAAkC;AAClC,mDAAqD;AACrD,0EAAiD;AACjD,4DAAoC;AACpC,8DAAsC;AAItC,MAAM,QAAQ,GAAmC;IAC/C,IAAI,EAAJ,sBAAI;IACJ,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,kCAAkB,EAAE,CAAC;IACvD,UAAU,EAAV,oBAAU;IACV,OAAO,EAAP,yBAAO;IACP,kBAAkB,EAAE,0BAAe;IACnC,SAAS,EAAT,mBAAS;CACV,CAAC;AAEF,kBAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Core } from "@strapi/strapi";
|
|
2
|
+
import { reindexSource, type IndexerDependencies, type ReindexDependencies } from "./indexer";
|
|
3
|
+
/** Exposes dependency-injected KB indexing orchestration through Strapi. */
|
|
4
|
+
declare const indexerService: (_: {
|
|
5
|
+
strapi: Core.Strapi;
|
|
6
|
+
}) => {
|
|
7
|
+
create(dependencies: IndexerDependencies): {
|
|
8
|
+
indexDocument(source: import("./knowledge-source").KnowledgeSource, documentId: string, locale: string, options?: import("./indexer").IndexDocumentOptions): Promise<boolean>;
|
|
9
|
+
};
|
|
10
|
+
reindex(source: Parameters<typeof reindexSource>[0], dependencies: ReindexDependencies): Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export default indexerService;
|
|
13
|
+
//# sourceMappingURL=indexer-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer-service.d.ts","sourceRoot":"","sources":["../../../../server/src/services/indexer-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAEL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,MAAM,WAAW,CAAC;AAEnB,4EAA4E;AAC5E,QAAA,MAAM,cAAc,GAAI,GAAG;IAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE;yBAC3B,mBAAmB;;;oBAI9B,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,gBAC7B,mBAAmB;CAInC,CAAC;AAEH,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const indexer_1 = require("./indexer");
|
|
4
|
+
/** Exposes dependency-injected KB indexing orchestration through Strapi. */
|
|
5
|
+
const indexerService = (_) => ({
|
|
6
|
+
create(dependencies) {
|
|
7
|
+
return (0, indexer_1.createIndexer)(dependencies);
|
|
8
|
+
},
|
|
9
|
+
reindex(source, dependencies) {
|
|
10
|
+
return (0, indexer_1.reindexSource)(source, dependencies);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
exports.default = indexerService;
|
|
14
|
+
//# sourceMappingURL=indexer-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer-service.js","sourceRoot":"","sources":["../../../../server/src/services/indexer-service.ts"],"names":[],"mappings":";;AACA,uCAKmB;AAEnB,4EAA4E;AAC5E,MAAM,cAAc,GAAG,CAAC,CAA0B,EAAE,EAAE,CAAC,CAAC;IACtD,MAAM,CAAC,YAAiC;QACtC,OAAO,IAAA,uBAAa,EAAC,YAAY,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,CACL,MAA2C,EAC3C,YAAiC;QAEjC,OAAO,IAAA,uBAAa,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC;AAEH,kBAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { EmbeddingsClient } from "./embeddings";
|
|
2
|
+
import { type KnowledgeSource } from "./knowledge-source";
|
|
3
|
+
import type { VectorStore } from "./qdrant-store";
|
|
4
|
+
import type { SchemaRegistry, SerializationContext } from "./schema-serializer";
|
|
5
|
+
export interface IndexerDependencies {
|
|
6
|
+
embeddings: EmbeddingsClient;
|
|
7
|
+
store: VectorStore;
|
|
8
|
+
getDocument(sourceUid: string, documentId: string, locale: string): Promise<Record<string, unknown> | null>;
|
|
9
|
+
registry?: SchemaRegistry;
|
|
10
|
+
componentSerializer?: SerializationContext["componentSerializer"];
|
|
11
|
+
}
|
|
12
|
+
export interface ReindexDependencies extends IndexerDependencies {
|
|
13
|
+
listDocumentIds(sourceUid: string, locale: string): Promise<string[]>;
|
|
14
|
+
promoteIndexedRevisions(source: KnowledgeSource): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface IndexDocumentOptions {
|
|
17
|
+
force?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function createIndexer(dependencies: IndexerDependencies): {
|
|
20
|
+
indexDocument(source: KnowledgeSource, documentId: string, locale: string, options?: IndexDocumentOptions): Promise<boolean>;
|
|
21
|
+
};
|
|
22
|
+
export declare function reindexSource(source: KnowledgeSource, dependencies: ReindexDependencies): Promise<void>;
|
|
23
|
+
//# sourceMappingURL=indexer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer.d.ts","sourceRoot":"","sources":["../../../../server/src/services/indexer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,KAAK,EAA8B,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhF,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,gBAAgB,CAAC;IAC7B,KAAK,EAAE,WAAW,CAAC;IACnB,WAAW,CACT,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3C,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,mBAAmB,CAAC,EAAE,oBAAoB,CAAC,qBAAqB,CAAC,CAAC;CACnE;AAED,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC9D,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACtE,uBAAuB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAmBD,wBAAgB,aAAa,CAAC,YAAY,EAAE,mBAAmB;0BAGjD,eAAe,cACX,MAAM,UACV,MAAM,YACL,oBAAoB,GAC5B,OAAO,CAAC,OAAO,CAAC;EA8CtB;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,eAAe,EACvB,YAAY,EAAE,mBAAmB,GAChC,OAAO,CAAC,IAAI,CAAC,CAwBf"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createIndexer = createIndexer;
|
|
4
|
+
exports.reindexSource = reindexSource;
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const canonical_json_1 = require("./canonical-json");
|
|
7
|
+
const chunker_1 = require("./chunker");
|
|
8
|
+
const extractor_1 = require("./extractor");
|
|
9
|
+
const knowledge_source_1 = require("./knowledge-source");
|
|
10
|
+
function contentHash(document) {
|
|
11
|
+
return (0, canonical_json_1.checksum)(document);
|
|
12
|
+
}
|
|
13
|
+
function pointId(scope, chunkIndex) {
|
|
14
|
+
const bytes = (0, node_crypto_1.createHash)("sha1")
|
|
15
|
+
.update(`${scope.sourceUid}:${scope.documentId}:${scope.locale}:${chunkIndex}`)
|
|
16
|
+
.digest()
|
|
17
|
+
.subarray(0, 16);
|
|
18
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x50;
|
|
19
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
20
|
+
const value = bytes.toString("hex");
|
|
21
|
+
return `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`;
|
|
22
|
+
}
|
|
23
|
+
function createIndexer(dependencies) {
|
|
24
|
+
return {
|
|
25
|
+
async indexDocument(source, documentId, locale, options = {}) {
|
|
26
|
+
if (!options.force && !(0, knowledge_source_1.isRevisionCurrent)(source))
|
|
27
|
+
return false;
|
|
28
|
+
const entry = await dependencies.getDocument(source.uid, documentId, locale);
|
|
29
|
+
if (!entry)
|
|
30
|
+
return false;
|
|
31
|
+
const document = (0, extractor_1.extractDocument)(entry, source, dependencies.registry, dependencies.componentSerializer);
|
|
32
|
+
const chunks = (0, chunker_1.chunkText)(document.text);
|
|
33
|
+
const vectors = await dependencies.embeddings.embed(chunks.map((chunk) => chunk.text));
|
|
34
|
+
if (vectors.length !== chunks.length) {
|
|
35
|
+
throw new Error("Embedding count does not match chunk count");
|
|
36
|
+
}
|
|
37
|
+
const scope = { sourceUid: source.uid, documentId, locale };
|
|
38
|
+
const hash = contentHash(document);
|
|
39
|
+
const points = chunks.map((chunk, index) => ({
|
|
40
|
+
id: pointId(scope, chunk.index),
|
|
41
|
+
vector: vectors[index],
|
|
42
|
+
payload: {
|
|
43
|
+
...scope,
|
|
44
|
+
chunkIndex: chunk.index,
|
|
45
|
+
text: chunk.text,
|
|
46
|
+
contentHash: hash,
|
|
47
|
+
title: document.title,
|
|
48
|
+
...(document.description
|
|
49
|
+
? { description: document.description }
|
|
50
|
+
: {}),
|
|
51
|
+
...(document.url ? { url: document.url } : {}),
|
|
52
|
+
configRevision: source.configRevision,
|
|
53
|
+
serializerRevision: source.serializerRevision,
|
|
54
|
+
},
|
|
55
|
+
}));
|
|
56
|
+
await dependencies.store.replaceDocument(scope, points);
|
|
57
|
+
return true;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async function reindexSource(source, dependencies) {
|
|
62
|
+
if (source.locales.length === 0) {
|
|
63
|
+
throw new Error("Knowledge source must include at least one locale");
|
|
64
|
+
}
|
|
65
|
+
const indexer = createIndexer(dependencies);
|
|
66
|
+
for (const locale of source.locales) {
|
|
67
|
+
const documentIds = await dependencies.listDocumentIds(source.uid, locale);
|
|
68
|
+
if (documentIds.length === 0) {
|
|
69
|
+
throw new Error(`No documents found for ${source.uid} in locale ${locale}`);
|
|
70
|
+
}
|
|
71
|
+
for (const documentId of documentIds) {
|
|
72
|
+
const indexed = await indexer.indexDocument(source, documentId, locale, {
|
|
73
|
+
force: true,
|
|
74
|
+
});
|
|
75
|
+
if (!indexed) {
|
|
76
|
+
throw new Error(`Unable to index ${source.uid}:${documentId}:${locale}; document not found for this locale`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
await dependencies.promoteIndexedRevisions(source);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=indexer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer.js","sourceRoot":"","sources":["../../../../server/src/services/indexer.ts"],"names":[],"mappings":";;AA+CA,sCAqDC;AAED,sCA2BC;AAjID,6CAAyC;AACzC,qDAA4C;AAC5C,uCAAsC;AACtC,2CAAsE;AAEtE,yDAA6E;AAyB7E,SAAS,WAAW,CAAC,QAA2B;IAC9C,OAAO,IAAA,yBAAQ,EAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,OAAO,CAAC,KAAoB,EAAE,UAAkB;IACvD,MAAM,KAAK,GAAG,IAAA,wBAAU,EAAC,MAAM,CAAC;SAC7B,MAAM,CACL,GAAG,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,MAAM,IAAI,UAAU,EAAE,CACvE;SACA,MAAM,EAAE;SACR,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACnB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACrC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACrC,MAAM,KAAK,GAAG,KAAK,CAAC,Q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AC,CAAC;IAC5C,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpC,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC3E,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,0BAA0B,MAAM,CAAC,GAAG,cAAc,MAAM,EAAE,CAC3D,CAAC;QACJ,CAAC;QACD,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE;gBACtE,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;YACH,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CACb,mBAAmB,MAAM,CAAC,GAAG,IAAI,UAAU,IAAI,MAAM,sCAAsC,CAC5F,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,YAAY,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Core } from "@strapi/strapi";
|
|
2
|
+
interface KnowledgeSourceRow {
|
|
3
|
+
documentId: string;
|
|
4
|
+
sourceUid: string;
|
|
5
|
+
titleField: string;
|
|
6
|
+
descriptionField: string | null;
|
|
7
|
+
bodyFields: string[];
|
|
8
|
+
extractionMode: "flat" | "schema" | null;
|
|
9
|
+
excludedFields: string[] | null;
|
|
10
|
+
slugField: string | null;
|
|
11
|
+
urlPattern: string | null;
|
|
12
|
+
locales: string[];
|
|
13
|
+
configRevision: number;
|
|
14
|
+
indexedConfigRevision: number;
|
|
15
|
+
serializerRevision: number;
|
|
16
|
+
indexedSerializerRevision: number;
|
|
17
|
+
}
|
|
18
|
+
export interface KnowledgeSource {
|
|
19
|
+
documentId: string;
|
|
20
|
+
uid: string;
|
|
21
|
+
titleField: string;
|
|
22
|
+
descriptionField?: string;
|
|
23
|
+
bodyFields: string[];
|
|
24
|
+
extractionMode?: "flat" | "schema";
|
|
25
|
+
excludedFields?: string[];
|
|
26
|
+
slugField?: string;
|
|
27
|
+
urlPattern?: string;
|
|
28
|
+
locales: string[];
|
|
29
|
+
configRevision: number;
|
|
30
|
+
indexedConfigRevision: number;
|
|
31
|
+
serializerRevision: number;
|
|
32
|
+
indexedSerializerRevision: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function toKnowledgeSource(row: KnowledgeSourceRow): KnowledgeSource;
|
|
35
|
+
export declare function isRevisionCurrent(source: KnowledgeSource): boolean;
|
|
36
|
+
interface KnowledgeSourcePersistence {
|
|
37
|
+
find(documentId: string): Promise<unknown | null>;
|
|
38
|
+
update(documentId: string, revisions: Pick<KnowledgeSource, "indexedConfigRevision" | "indexedSerializerRevision">): Promise<unknown | null>;
|
|
39
|
+
}
|
|
40
|
+
export declare function createKnowledgeSourceService(persistence: KnowledgeSourcePersistence): {
|
|
41
|
+
find(documentId: string): Promise<KnowledgeSource | null>;
|
|
42
|
+
promoteIndexedRevisions(source: KnowledgeSource): Promise<void>;
|
|
43
|
+
};
|
|
44
|
+
declare const knowledgeSource: ({ strapi }: {
|
|
45
|
+
strapi: Core.Strapi;
|
|
46
|
+
}) => {
|
|
47
|
+
find(documentId: string): Promise<KnowledgeSource | null>;
|
|
48
|
+
promoteIndexedRevisions(source: KnowledgeSource): Promise<void>;
|
|
49
|
+
};
|
|
50
|
+
export default knowledgeSource;
|
|
51
|
+
//# sourceMappingURL=knowledge-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-source.d.ts","sourceRoot":"","sources":["../../../../server/src/services/knowledge-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAG3C,UAAU,kBAAkB;IAC1B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,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAClD,MAAM,CACJ,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,IAAI,CACb,eAAe,EACf,uBAAuB,GAAG,2BAA2B,CACtD,GACA,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CAC5B;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,0BAA0B;qBAGd,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;oCASzB,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;EAYxE;AAED,QAAA,MAAM,eAAe,GAAI,YAAY;IAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE;qBAvBjC,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;oCASzB,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAyBrE,CAAC;AAEL,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toKnowledgeSource = toKnowledgeSource;
|
|
4
|
+
exports.isRevisionCurrent = isRevisionCurrent;
|
|
5
|
+
exports.createKnowledgeSourceService = createKnowledgeSourceService;
|
|
6
|
+
function isStringArray(value) {
|
|
7
|
+
return (Array.isArray(value) && value.every((item) => typeof item === "string"));
|
|
8
|
+
}
|
|
9
|
+
function isOptionalString(value) {
|
|
10
|
+
return value === undefined || value === null || typeof value === "string";
|
|
11
|
+
}
|
|
12
|
+
function isKnowledgeSourceRow(value) {
|
|
13
|
+
if (!value || typeof value !== "object")
|
|
14
|
+
return false;
|
|
15
|
+
const row = value;
|
|
16
|
+
return (typeof row.documentId === "string" &&
|
|
17
|
+
typeof row.sourceUid === "string" &&
|
|
18
|
+
typeof row.titleField === "string" &&
|
|
19
|
+
isStringArray(row.bodyFields) &&
|
|
20
|
+
isStringArray(row.locales) &&
|
|
21
|
+
typeof row.configRevision === "number" &&
|
|
22
|
+
typeof row.indexedConfigRevision === "number" &&
|
|
23
|
+
typeof row.serializerRevision === "number" &&
|
|
24
|
+
typeof row.indexedSerializerRevision === "number" &&
|
|
25
|
+
(row.extractionMode === null ||
|
|
26
|
+
row.extractionMode === "flat" ||
|
|
27
|
+
row.extractionMode === "schema") &&
|
|
28
|
+
(row.excludedFields === null || isStringArray(row.excludedFields)) &&
|
|
29
|
+
isOptionalString(row.descriptionField) &&
|
|
30
|
+
isOptionalString(row.slugField) &&
|
|
31
|
+
isOptionalString(row.urlPattern));
|
|
32
|
+
}
|
|
33
|
+
function toKnowledgeSource(row) {
|
|
34
|
+
return {
|
|
35
|
+
documentId: row.documentId,
|
|
36
|
+
uid: row.sourceUid,
|
|
37
|
+
titleField: row.titleField,
|
|
38
|
+
bodyFields: row.bodyFields,
|
|
39
|
+
extractionMode: row.extractionMode ?? undefined,
|
|
40
|
+
excludedFields: row.excludedFields ?? undefined,
|
|
41
|
+
descriptionField: row.descriptionField ?? undefined,
|
|
42
|
+
slugField: row.slugField ?? undefined,
|
|
43
|
+
urlPattern: row.urlPattern ?? undefined,
|
|
44
|
+
locales: row.locales,
|
|
45
|
+
configRevision: row.configRevision,
|
|
46
|
+
indexedConfigRevision: row.indexedConfigRevision,
|
|
47
|
+
serializerRevision: row.serializerRevision,
|
|
48
|
+
indexedSerializerRevision: row.indexedSerializerRevision,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function isRevisionCurrent(source) {
|
|
52
|
+
return (source.configRevision === source.indexedConfigRevision &&
|
|
53
|
+
source.serializerRevision === source.indexedSerializerRevision);
|
|
54
|
+
}
|
|
55
|
+
function createKnowledgeSourceService(persistence) {
|
|
56
|
+
return {
|
|
57
|
+
async find(documentId) {
|
|
58
|
+
const row = await persistence.find(documentId);
|
|
59
|
+
if (!row)
|
|
60
|
+
return null;
|
|
61
|
+
if (!isKnowledgeSourceRow(row)) {
|
|
62
|
+
throw new Error("Knowledge source has an invalid persisted shape");
|
|
63
|
+
}
|
|
64
|
+
return toKnowledgeSource(row);
|
|
65
|
+
},
|
|
66
|
+
async promoteIndexedRevisions(source) {
|
|
67
|
+
const updated = await persistence.update(source.documentId, {
|
|
68
|
+
indexedConfigRevision: source.configRevision,
|
|
69
|
+
indexedSerializerRevision: source.serializerRevision,
|
|
70
|
+
});
|
|
71
|
+
if (!updated) {
|
|
72
|
+
throw new Error(`Knowledge source ${source.documentId} disappeared before revisions could be promoted`);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const knowledgeSource = ({ strapi }) => createKnowledgeSourceService({
|
|
78
|
+
find: (documentId) => strapi
|
|
79
|
+
.documents("plugin::agent.knowledge-source")
|
|
80
|
+
.findOne({ documentId }),
|
|
81
|
+
update: (documentId, revisions) => strapi.db.query("plugin::agent.knowledge-source").update({
|
|
82
|
+
where: { documentId },
|
|
83
|
+
data: revisions,
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
exports.default = knowledgeSource;
|
|
87
|
+
//# sourceMappingURL=knowledge-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-source.js","sourceRoot":"","sources":["../../../../server/src/services/knowledge-source.ts"],"names":[],"mappings":";;AAsEA,8CAiBC;AAED,8CAKC;AAaD,oEAyBC;AA/FD,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CACL,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CACxE,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAC5E,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAc;IA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QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,eAAe,GAAG,CAAC,EAAE,MAAM,EAA2B,EAAE,EAAE,CAC9D,4BAA4B,CAAC;IAC3B,IAAI,EAAE,CAAC,UAAU,EAAE,EAAE,CACnB,MAAM;SACH,SAAS,CAAC,gCAAgC,CAAC;SAC3C,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;IAC5B,MAAM,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,CAChC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC,MAAM,CAAC;QACvD,KAAK,EAAE,EAAE,UAAU,EAAE;QACrB,IAAI,EAAE,SAAS;KAChB,CAAC;CACL,CAAC,CAAC;AAEL,kBAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ChatProviderRequest {
|
|
2
|
+
system: string;
|
|
3
|
+
message: string;
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
}
|
|
6
|
+
export interface ChatProvider {
|
|
7
|
+
stream(request: ChatProviderRequest): AsyncIterable<string>;
|
|
8
|
+
}
|
|
9
|
+
export interface ProviderConfig {
|
|
10
|
+
provider?: "openai" | "anthropic";
|
|
11
|
+
model?: string;
|
|
12
|
+
openaiApiKey?: string;
|
|
13
|
+
anthropicApiKey?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Returns null when no usable provider key is configured. */
|
|
16
|
+
export declare function selectProvider(config: ProviderConfig): ChatProvider | null;
|
|
17
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../server/src/services/provider.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAwFD,8DAA8D;AAC9D,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,GAAG,IAAI,CAmB1E"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selectProvider = selectProvider;
|
|
4
|
+
async function* openAiStream(config, request) {
|
|
5
|
+
const response = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: {
|
|
8
|
+
Authorization: `Bearer ${config.openaiApiKey}`,
|
|
9
|
+
"Content-Type": "application/json",
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify({
|
|
12
|
+
model: config.model ?? "gpt-4o-mini",
|
|
13
|
+
stream: true,
|
|
14
|
+
messages: [
|
|
15
|
+
{ role: "system", content: request.system },
|
|
16
|
+
{ role: "user", content: request.message },
|
|
17
|
+
],
|
|
18
|
+
}),
|
|
19
|
+
signal: request.signal,
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok || !response.body) {
|
|
22
|
+
throw new Error(`OpenAI chat request failed (${response.status})`);
|
|
23
|
+
}
|
|
24
|
+
const reader = response.body.getReader();
|
|
25
|
+
const decoder = new TextDecoder();
|
|
26
|
+
let buffer = "";
|
|
27
|
+
for (;;) {
|
|
28
|
+
const next = await reader.read();
|
|
29
|
+
if (next.done)
|
|
30
|
+
break;
|
|
31
|
+
buffer += decoder.decode(next.value, { stream: true });
|
|
32
|
+
const lines = buffer.split("\n");
|
|
33
|
+
buffer = lines.pop() ?? "";
|
|
34
|
+
for (const line of lines) {
|
|
35
|
+
if (!line.startsWith("data: ") || line === "data: [DONE]")
|
|
36
|
+
continue;
|
|
37
|
+
const event = JSON.parse(line.slice(6));
|
|
38
|
+
const text = event.choices?.[0]?.delta?.content;
|
|
39
|
+
if (typeof text === "string" && text)
|
|
40
|
+
yield text;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function* anthropicStream(config, request) {
|
|
45
|
+
const response = await fetch("https://api.anthropic.com/v1/messages", {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: {
|
|
48
|
+
"x-api-key": config.anthropicApiKey,
|
|
49
|
+
"anthropic-version": "2023-06-01",
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify({
|
|
53
|
+
model: config.model ?? "claude-3-5-haiku-latest",
|
|
54
|
+
max_tokens: 1024,
|
|
55
|
+
stream: true,
|
|
56
|
+
system: request.system,
|
|
57
|
+
messages: [{ role: "user", content: request.message }],
|
|
58
|
+
}),
|
|
59
|
+
signal: request.signal,
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok || !response.body) {
|
|
62
|
+
throw new Error(`Anthropic chat request failed (${response.status})`);
|
|
63
|
+
}
|
|
64
|
+
const reader = response.body.getReader();
|
|
65
|
+
const decoder = new TextDecoder();
|
|
66
|
+
let buffer = "";
|
|
67
|
+
for (;;) {
|
|
68
|
+
const next = await reader.read();
|
|
69
|
+
if (next.done)
|
|
70
|
+
break;
|
|
71
|
+
buffer += decoder.decode(next.value, { stream: true });
|
|
72
|
+
const lines = buffer.split("\n");
|
|
73
|
+
buffer = lines.pop() ?? "";
|
|
74
|
+
for (const line of lines) {
|
|
75
|
+
if (!line.startsWith("data: "))
|
|
76
|
+
continue;
|
|
77
|
+
const event = JSON.parse(line.slice(6));
|
|
78
|
+
const text = event.delta?.text;
|
|
79
|
+
if (typeof text === "string" && text)
|
|
80
|
+
yield text;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Returns null when no usable provider key is configured. */
|
|
85
|
+
function selectProvider(config) {
|
|
86
|
+
if (config.provider === "anthropic") {
|
|
87
|
+
if (!config.anthropicApiKey)
|
|
88
|
+
return null;
|
|
89
|
+
return {
|
|
90
|
+
stream: (request) => anthropicStream(config, request),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (!config.openaiApiKey)
|
|
94
|
+
return null;
|
|
95
|
+
return {
|
|
96
|
+
stream: (request) => openAiStream(config, request),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../../server/src/services/provider.ts"],"names":[],"mappings":";;AAwGA,wCAmBC;AAtGD,KAAK,SAAS,CAAC,CAAC,YAAY,CAC1B,MAAuE,EACvE,OAA4B;IAE5B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,4CAA4C,EAAE;QACzE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,MAAM,CAAC,YAAY,EAAE;YAC9C,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,aAAa;YACpC,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE;gBACR,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE;gBAC3C,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE;aAC3C;SACF,CAAC;QACF,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,IAA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C,KAAK,CAAC,CAAC,CAAC,CAAmC,CAAC;YAC1E,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;YAC/B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI;gBAAE,MAAM,IAAI,CAAC;QACnD,CAAC;IACH,CAAC;AACH,CAAC;AAED,8DAA8D;AAC9D,SAAgB,cAAc,CAAC,MAAsB;IACnD,IAAI,MAAM,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,eAAe;YAAE,OAAO,IAAI,CAAC;QACzC,OAAO;YACL,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAClB,eAAe,CACb,MAAsD,EACtD,OAAO,CACR;SACJ,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IACtC,OAAO;QACL,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAClB,YAAY,CACV,MAAmD,EACnD,OAAO,CACR;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export interface VectorPoint {
|
|
2
|
+
id: string;
|
|
3
|
+
vector: number[];
|
|
4
|
+
payload: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface VectorPayload {
|
|
7
|
+
sourceUid: string;
|
|
8
|
+
documentId: string;
|
|
9
|
+
locale: string;
|
|
10
|
+
chunkIndex: number;
|
|
11
|
+
text: string;
|
|
12
|
+
title: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
url?: string;
|
|
15
|
+
configRevision: number;
|
|
16
|
+
serializerRevision: number;
|
|
17
|
+
}
|
|
18
|
+
export interface SearchHit {
|
|
19
|
+
score: number;
|
|
20
|
+
payload: VectorPayload;
|
|
21
|
+
}
|
|
22
|
+
export interface SearchScope {
|
|
23
|
+
sourceUid: string;
|
|
24
|
+
configRevision: number;
|
|
25
|
+
serializerRevision: number;
|
|
26
|
+
}
|
|
27
|
+
export interface SearchFilter {
|
|
28
|
+
locale: string;
|
|
29
|
+
scopes: SearchScope[];
|
|
30
|
+
document?: Pick<DocumentScope, "sourceUid" | "documentId">;
|
|
31
|
+
}
|
|
32
|
+
export interface DocumentScope {
|
|
33
|
+
sourceUid: string;
|
|
34
|
+
documentId: string;
|
|
35
|
+
locale: string;
|
|
36
|
+
}
|
|
37
|
+
export interface VectorStore {
|
|
38
|
+
replaceDocument(scope: DocumentScope, points: VectorPoint[]): Promise<void>;
|
|
39
|
+
search(vector: number[], topK: number, filter: SearchFilter): Promise<SearchHit[]>;
|
|
40
|
+
}
|
|
41
|
+
export interface QdrantStoreOptions {
|
|
42
|
+
url: string;
|
|
43
|
+
apiKey?: string;
|
|
44
|
+
collection: string;
|
|
45
|
+
fetch?: typeof globalThis.fetch;
|
|
46
|
+
logger?: QdrantLogger;
|
|
47
|
+
}
|
|
48
|
+
export interface QdrantInvalidSearchHitWarning {
|
|
49
|
+
event: "agent.qdrant.search_hit_excluded";
|
|
50
|
+
reason: "invalid_score" | "invalid_payload";
|
|
51
|
+
collection: string;
|
|
52
|
+
hitIndex: number;
|
|
53
|
+
scoreType: string;
|
|
54
|
+
payloadType: string;
|
|
55
|
+
payloadKeys: string[];
|
|
56
|
+
locale: string;
|
|
57
|
+
sourceUids: string[];
|
|
58
|
+
}
|
|
59
|
+
export interface QdrantLogger {
|
|
60
|
+
warn(warning: QdrantInvalidSearchHitWarning): void;
|
|
61
|
+
}
|
|
62
|
+
export declare function createQdrantStore(options: QdrantStoreOptions): VectorStore;
|
|
63
|
+
//# sourceMappingURL=qdrant-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qdrant-store.d.ts","sourceRoot":"","sources":["../../../../server/src/services/qdrant-store.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO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