@vfarcic/dot-ai 1.23.1 → 1.24.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/dist/core/index.d.ts +0 -5
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -11
- package/dist/core/knowledge-migration.d.ts +30 -0
- package/dist/core/knowledge-migration.d.ts.map +1 -0
- package/dist/core/knowledge-migration.js +289 -0
- package/dist/core/knowledge-service.d.ts +46 -0
- package/dist/core/knowledge-service.d.ts.map +1 -0
- package/dist/core/knowledge-service.js +185 -0
- package/dist/core/knowledge-types.d.ts +14 -0
- package/dist/core/knowledge-types.d.ts.map +1 -1
- package/dist/core/schema.d.ts +13 -12
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +105 -170
- package/dist/core/user-prompts-loader.d.ts.map +1 -1
- package/dist/core/user-prompts-loader.js +13 -6
- package/dist/interfaces/rest-api.d.ts.map +1 -1
- package/dist/interfaces/rest-api.js +7 -6
- package/dist/mcp/server.js +12 -0
- package/dist/tools/manage-knowledge.d.ts +0 -22
- package/dist/tools/manage-knowledge.d.ts.map +1 -1
- package/dist/tools/manage-knowledge.js +71 -131
- package/dist/tools/operate-analysis.d.ts.map +1 -1
- package/dist/tools/operate-analysis.js +7 -6
- package/dist/tools/operate.d.ts +23 -11
- package/dist/tools/operate.d.ts.map +1 -1
- package/dist/tools/operate.js +40 -58
- package/dist/tools/organizational-data.d.ts +5 -8
- package/dist/tools/organizational-data.d.ts.map +1 -1
- package/dist/tools/organizational-data.js +19 -74
- package/dist/tools/query.d.ts +17 -0
- package/dist/tools/query.d.ts.map +1 -1
- package/dist/tools/query.js +36 -1
- package/dist/tools/version.d.ts +1 -12
- package/dist/tools/version.d.ts.map +1 -1
- package/dist/tools/version.js +10 -19
- package/package.json +2 -2
- package/prompts/knowledge-classification.md +24 -0
- package/prompts/operate-user.md +7 -8
- package/dist/core/organizational-types.d.ts +0 -43
- package/dist/core/organizational-types.d.ts.map +0 -1
- package/dist/core/organizational-types.js +0 -8
- package/dist/core/pattern-operations.d.ts +0 -50
- package/dist/core/pattern-operations.d.ts.map +0 -1
- package/dist/core/pattern-operations.js +0 -445
- package/dist/core/pattern-types.d.ts +0 -8
- package/dist/core/pattern-types.d.ts.map +0 -1
- package/dist/core/pattern-types.js +0 -8
- package/dist/core/pattern-vector-service.d.ts +0 -27
- package/dist/core/pattern-vector-service.d.ts.map +0 -1
- package/dist/core/pattern-vector-service.js +0 -65
- package/dist/core/policy-operations.d.ts +0 -136
- package/dist/core/policy-operations.d.ts.map +0 -1
- package/dist/core/policy-operations.js +0 -623
- package/dist/core/policy-vector-service.d.ts +0 -27
- package/dist/core/policy-vector-service.d.ts.map +0 -1
- package/dist/core/policy-vector-service.js +0 -64
- package/dist/core/unified-creation-session.d.ts +0 -88
- package/dist/core/unified-creation-session.d.ts.map +0 -1
- package/dist/core/unified-creation-session.js +0 -948
- package/dist/core/unified-creation-types.d.ts +0 -68
- package/dist/core/unified-creation-types.d.ts.map +0 -1
- package/dist/core/unified-creation-types.js +0 -61
package/dist/core/index.d.ts
CHANGED
|
@@ -41,12 +41,7 @@ export { WorkflowEngine } from './workflow';
|
|
|
41
41
|
export { AIProvider, AIResponse, AIProviderConfig } from './ai-provider.interface';
|
|
42
42
|
export { createAIProvider, AIProviderFactory } from './ai-provider-factory';
|
|
43
43
|
export { SchemaParser, ManifestValidator, ResourceRecommender } from './schema';
|
|
44
|
-
export { OrganizationalPattern, CreatePatternRequest } from './pattern-types';
|
|
45
|
-
export { BaseOrganizationalEntity, PolicyIntent, CreatePolicyIntentRequest, DeployedPolicyReference } from './organizational-types';
|
|
46
|
-
export { validatePattern, createPattern, serializePattern, deserializePattern } from './pattern-operations';
|
|
47
44
|
export { BaseVectorService, BaseSearchOptions, BaseSearchResult, VectorDocument } from './base-vector-service';
|
|
48
|
-
export { PatternVectorService, PatternSearchOptions, PatternSearchResult } from './pattern-vector-service';
|
|
49
|
-
export { PolicyVectorService, PolicySearchOptions, PolicySearchResult } from './policy-vector-service';
|
|
50
45
|
export { CapabilityVectorService, ResourceCapability, CapabilitySearchOptions } from './capability-vector-service';
|
|
51
46
|
export { EmbeddingService, EmbeddingConfig, EmbeddingProvider, VercelEmbeddingProvider } from './embedding-service';
|
|
52
47
|
export { AgentDisplayOptions, buildAgentDisplayBlock } from './agent-display';
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAK7C,MAAM,WAAW,UAAU;CAE1B;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,WAAW,CAAkB;IAErC,SAAgB,SAAS,EAAE,mBAAmB,CAAC;IAC/C,SAAgB,MAAM,EAAE,YAAY,CAAC;IACrC,SAAgB,QAAQ,EAAE,cAAc,CAAC;IACzC,SAAgB,EAAE,EAAE,UAAU,CAAC;IAC/B,SAAgB,MAAM,EAAE;QACtB,MAAM,EAAE,YAAY,CAAC;QACrB,SAAS,EAAE,iBAAiB,CAAC;QAC7B,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAAC;QACnC,aAAa,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1D,aAAa,EAAE,CAAC,MAAM,EAAE,MA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AgB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEhF,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/G,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACnH,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACpH,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGrJ,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAG3B,eAAe,KAAK,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Shared intelligence for both CLI and MCP interfaces
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.invokePluginTool = exports.isPluginInitialized = exports.getPluginManager = exports.initializePluginRegistry = exports.PluginClientError = exports.PluginClient = exports.PluginDiscoveryError = exports.PluginManager = exports.CircuitOpenError = exports.CircuitState = exports.CircuitBreakerFactory = exports.CircuitBreaker = exports.buildAgentDisplayBlock = exports.VercelEmbeddingProvider = exports.EmbeddingService = exports.CapabilityVectorService = exports.
|
|
8
|
+
exports.invokePluginTool = exports.isPluginInitialized = exports.getPluginManager = exports.initializePluginRegistry = exports.PluginClientError = exports.PluginClient = exports.PluginDiscoveryError = exports.PluginManager = exports.CircuitOpenError = exports.CircuitState = exports.CircuitBreakerFactory = exports.CircuitBreaker = exports.buildAgentDisplayBlock = exports.VercelEmbeddingProvider = exports.EmbeddingService = exports.CapabilityVectorService = exports.BaseVectorService = exports.ResourceRecommender = exports.ManifestValidator = exports.SchemaParser = exports.AIProviderFactory = exports.createAIProvider = exports.WorkflowEngine = exports.MemorySystem = exports.KubernetesDiscovery = exports.DotAI = void 0;
|
|
9
9
|
const discovery_1 = require("./discovery");
|
|
10
10
|
const memory_1 = require("./memory");
|
|
11
11
|
const workflow_1 = require("./workflow");
|
|
@@ -126,18 +126,9 @@ var schema_2 = require("./schema");
|
|
|
126
126
|
Object.defineProperty(exports, "SchemaParser", { enumerable: true, get: function () { return schema_2.SchemaParser; } });
|
|
127
127
|
Object.defineProperty(exports, "ManifestValidator", { enumerable: true, get: function () { return schema_2.ManifestValidator; } });
|
|
128
128
|
Object.defineProperty(exports, "ResourceRecommender", { enumerable: true, get: function () { return schema_2.ResourceRecommender; } });
|
|
129
|
-
|
|
130
|
-
Object.defineProperty(exports, "validatePattern", { enumerable: true, get: function () { return pattern_operations_1.validatePattern; } });
|
|
131
|
-
Object.defineProperty(exports, "createPattern", { enumerable: true, get: function () { return pattern_operations_1.createPattern; } });
|
|
132
|
-
Object.defineProperty(exports, "serializePattern", { enumerable: true, get: function () { return pattern_operations_1.serializePattern; } });
|
|
133
|
-
Object.defineProperty(exports, "deserializePattern", { enumerable: true, get: function () { return pattern_operations_1.deserializePattern; } });
|
|
134
|
-
// Removed obsolete pattern creation types - now using unified creation system
|
|
129
|
+
// PRD #375: Pattern/policy vector services and types removed — unified knowledge base now handles all
|
|
135
130
|
var base_vector_service_1 = require("./base-vector-service");
|
|
136
131
|
Object.defineProperty(exports, "BaseVectorService", { enumerable: true, get: function () { return base_vector_service_1.BaseVectorService; } });
|
|
137
|
-
var pattern_vector_service_1 = require("./pattern-vector-service");
|
|
138
|
-
Object.defineProperty(exports, "PatternVectorService", { enumerable: true, get: function () { return pattern_vector_service_1.PatternVectorService; } });
|
|
139
|
-
var policy_vector_service_1 = require("./policy-vector-service");
|
|
140
|
-
Object.defineProperty(exports, "PolicyVectorService", { enumerable: true, get: function () { return policy_vector_service_1.PolicyVectorService; } });
|
|
141
132
|
var capability_vector_service_1 = require("./capability-vector-service");
|
|
142
133
|
Object.defineProperty(exports, "CapabilityVectorService", { enumerable: true, get: function () { return capability_vector_service_1.CapabilityVectorService; } });
|
|
143
134
|
var embedding_service_1 = require("./embedding-service");
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Base Migration Service
|
|
3
|
+
*
|
|
4
|
+
* PRD #375: Auto-migration — transparently migrate existing users' legacy
|
|
5
|
+
* patterns and policies collections into the unified knowledge-base collection
|
|
6
|
+
* on first server startup.
|
|
7
|
+
*
|
|
8
|
+
* Design decisions:
|
|
9
|
+
* - Idempotent: safe to run multiple times (skips if legacy collections absent)
|
|
10
|
+
* - Non-fatal: migration failures are logged but do not crash the server
|
|
11
|
+
* - Delete-after-success: the legacy collection is only removed when every point
|
|
12
|
+
* stored successfully (failCount === 0); deterministic UUIDv5 IDs prevent
|
|
13
|
+
* collisions/overwrites, making store-success gating safe
|
|
14
|
+
* - Tags assigned by collection origin: patterns → ["pattern"], policies → ["policy"]
|
|
15
|
+
*/
|
|
16
|
+
import { Logger } from './error-handling';
|
|
17
|
+
export declare const KNOWLEDGE_NAMESPACE: string;
|
|
18
|
+
/**
|
|
19
|
+
* Maximum number of points fetched from a legacy collection in a single
|
|
20
|
+
* `vector_list` call.
|
|
21
|
+
*/
|
|
22
|
+
export declare const LEGACY_LIST_CAP = 100000;
|
|
23
|
+
/**
|
|
24
|
+
* Run the auto-migration check at server startup.
|
|
25
|
+
*
|
|
26
|
+
* Safe to call even when the plugin is not initialised (skips silently).
|
|
27
|
+
* Non-fatal: any error is caught and logged; the server continues normally.
|
|
28
|
+
*/
|
|
29
|
+
export declare function runKnowledgeMigration(logger: Logger): Promise<void>;
|
|
30
|
+
//# sourceMappingURL=knowledge-migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-migration.d.ts","sourceRoot":"","sources":["../../src/core/knowledge-migration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAgB1C,eAAO,MAAM,mBAAmB,QAAa,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,eAAe,SAAU,CAAC;AAsQvC;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwCzE"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Knowledge Base Migration Service
|
|
4
|
+
*
|
|
5
|
+
* PRD #375: Auto-migration — transparently migrate existing users' legacy
|
|
6
|
+
* patterns and policies collections into the unified knowledge-base collection
|
|
7
|
+
* on first server startup.
|
|
8
|
+
*
|
|
9
|
+
* Design decisions:
|
|
10
|
+
* - Idempotent: safe to run multiple times (skips if legacy collections absent)
|
|
11
|
+
* - Non-fatal: migration failures are logged but do not crash the server
|
|
12
|
+
* - Delete-after-success: the legacy collection is only removed when every point
|
|
13
|
+
* stored successfully (failCount === 0); deterministic UUIDv5 IDs prevent
|
|
14
|
+
* collisions/overwrites, making store-success gating safe
|
|
15
|
+
* - Tags assigned by collection origin: patterns → ["pattern"], policies → ["policy"]
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.LEGACY_LIST_CAP = exports.KNOWLEDGE_NAMESPACE = void 0;
|
|
19
|
+
exports.runKnowledgeMigration = runKnowledgeMigration;
|
|
20
|
+
const plugin_registry_1 = require("./plugin-registry");
|
|
21
|
+
const crypto_1 = require("crypto");
|
|
22
|
+
const uuid_1 = require("uuid");
|
|
23
|
+
const PLUGIN_NAME = 'agentic-tools';
|
|
24
|
+
/** Collections that existed before PRD #375 */
|
|
25
|
+
const LEGACY_COLLECTIONS = [
|
|
26
|
+
{ name: 'patterns', tags: ['pattern'] },
|
|
27
|
+
{ name: 'policies', tags: ['policy'] },
|
|
28
|
+
];
|
|
29
|
+
/** Target unified collection */
|
|
30
|
+
const KNOWLEDGE_COLLECTION = 'knowledge-base';
|
|
31
|
+
exports.KNOWLEDGE_NAMESPACE = uuid_1.v5.DNS;
|
|
32
|
+
/**
|
|
33
|
+
* Maximum number of points fetched from a legacy collection in a single
|
|
34
|
+
* `vector_list` call.
|
|
35
|
+
*/
|
|
36
|
+
exports.LEGACY_LIST_CAP = 100_000;
|
|
37
|
+
function toStringValue(value) {
|
|
38
|
+
return typeof value === 'string' ? value : '';
|
|
39
|
+
}
|
|
40
|
+
function toStringArray(value) {
|
|
41
|
+
if (!Array.isArray(value)) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
return value.filter((item) => typeof item === 'string');
|
|
45
|
+
}
|
|
46
|
+
function buildLegacyContent(payload, legacyName) {
|
|
47
|
+
const description = toStringValue(payload.description);
|
|
48
|
+
const triggers = toStringArray(payload.triggers);
|
|
49
|
+
const rationale = toStringValue(payload.rationale);
|
|
50
|
+
const lines = [];
|
|
51
|
+
if (description) {
|
|
52
|
+
lines.push(description);
|
|
53
|
+
}
|
|
54
|
+
if (triggers.length > 0) {
|
|
55
|
+
lines.push(`Triggers: ${triggers.join(', ')}`);
|
|
56
|
+
}
|
|
57
|
+
if (legacyName === 'patterns') {
|
|
58
|
+
const suggestedResources = toStringArray(payload.suggestedResources);
|
|
59
|
+
if (suggestedResources.length > 0) {
|
|
60
|
+
lines.push(`Suggested resources: ${suggestedResources.join(', ')}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (legacyName === 'policies') {
|
|
64
|
+
const deployedPolicies = Array.isArray(payload.deployedPolicies)
|
|
65
|
+
? payload.deployedPolicies
|
|
66
|
+
.map(item => {
|
|
67
|
+
if (typeof item === 'string') {
|
|
68
|
+
return item;
|
|
69
|
+
}
|
|
70
|
+
if (item && typeof item === 'object' && 'name' in item) {
|
|
71
|
+
const name = item.name;
|
|
72
|
+
return typeof name === 'string' ? name : '';
|
|
73
|
+
}
|
|
74
|
+
return '';
|
|
75
|
+
})
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
: [];
|
|
78
|
+
if (deployedPolicies.length > 0) {
|
|
79
|
+
lines.push(`Deployed policies: ${deployedPolicies.join(', ')}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (rationale) {
|
|
83
|
+
lines.push(`Rationale: ${rationale}`);
|
|
84
|
+
}
|
|
85
|
+
if (lines.length === 0) {
|
|
86
|
+
return JSON.stringify(payload);
|
|
87
|
+
}
|
|
88
|
+
return lines.join('\n\n');
|
|
89
|
+
}
|
|
90
|
+
function buildMigratedPayload(doc, legacyName, tags) {
|
|
91
|
+
const content = buildLegacyContent(doc.payload, legacyName);
|
|
92
|
+
const ingestedAt = new Date().toISOString();
|
|
93
|
+
return {
|
|
94
|
+
content,
|
|
95
|
+
uri: `legacy://${legacyName}/${doc.id}`,
|
|
96
|
+
metadata: {
|
|
97
|
+
migratedFrom: legacyName,
|
|
98
|
+
originalId: doc.id,
|
|
99
|
+
originalPayload: doc.payload,
|
|
100
|
+
},
|
|
101
|
+
checksum: (0, crypto_1.createHash)('sha256').update(content).digest('hex'),
|
|
102
|
+
ingestedAt,
|
|
103
|
+
chunkIndex: 0,
|
|
104
|
+
totalChunks: 1,
|
|
105
|
+
tags,
|
|
106
|
+
extractedPolicyIds: [],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Invoke a plugin tool and return its data payload, or throw on failure.
|
|
111
|
+
*/
|
|
112
|
+
async function pluginCall(tool, args) {
|
|
113
|
+
const response = await (0, plugin_registry_1.invokePluginTool)(PLUGIN_NAME, tool, args);
|
|
114
|
+
if (!response.success) {
|
|
115
|
+
const err = response.error;
|
|
116
|
+
const msg = typeof err === 'object' && err?.message
|
|
117
|
+
? err.message
|
|
118
|
+
: String(err ?? `Plugin tool ${tool} failed`);
|
|
119
|
+
throw new Error(msg);
|
|
120
|
+
}
|
|
121
|
+
const result = response.result;
|
|
122
|
+
if (!result || typeof result !== 'object') {
|
|
123
|
+
throw new Error(`Plugin tool ${tool} returned invalid result`);
|
|
124
|
+
}
|
|
125
|
+
if (result.success === false) {
|
|
126
|
+
throw new Error(result.error ?? `Plugin tool ${tool} reported failure`);
|
|
127
|
+
}
|
|
128
|
+
return result.data;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check whether a collection exists in the vector database.
|
|
132
|
+
*/
|
|
133
|
+
async function collectionExists(name) {
|
|
134
|
+
const names = await pluginCall('collection_list', {});
|
|
135
|
+
return names.includes(name);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* List all documents in a collection, including vectors so migration can
|
|
139
|
+
* reuse existing embeddings without per-document lookups.
|
|
140
|
+
*/
|
|
141
|
+
async function listAll(collection) {
|
|
142
|
+
return pluginCall('vector_list', {
|
|
143
|
+
collection,
|
|
144
|
+
limit: exports.LEGACY_LIST_CAP,
|
|
145
|
+
includeVector: true,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Migrate one legacy collection into the unified knowledge-base.
|
|
150
|
+
*
|
|
151
|
+
* Steps:
|
|
152
|
+
* 1. List all points in the legacy collection
|
|
153
|
+
* 2. For each point, store in knowledge-base with tags set to the origin tags
|
|
154
|
+
* 3. Verify the migrated count equals the source count
|
|
155
|
+
* 4. Delete the legacy collection
|
|
156
|
+
*/
|
|
157
|
+
async function migrateLegacyCollection(legacyName, tags, logger) {
|
|
158
|
+
logger.info(`[migration] Starting migration from '${legacyName}' → '${KNOWLEDGE_COLLECTION}'`);
|
|
159
|
+
const documents = await listAll(legacyName);
|
|
160
|
+
if (documents.length === 0) {
|
|
161
|
+
logger.info(`[migration] '${legacyName}' is empty — deleting collection and skipping`);
|
|
162
|
+
await pluginCall('collection_delete', { collection: legacyName });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// A full page (>= the list cap) means the listing may be truncated. Migration
|
|
166
|
+
// deletes the legacy collection once its points are stored, so proceeding here
|
|
167
|
+
// could silently drop the unread remainder.
|
|
168
|
+
if (documents.length >= exports.LEGACY_LIST_CAP) {
|
|
169
|
+
logger.error(`[migration] '${legacyName}' returned ${documents.length} point(s), reaching the ` +
|
|
170
|
+
`${exports.LEGACY_LIST_CAP} list cap — the page may be truncated. Refusing to migrate-and-delete ` +
|
|
171
|
+
`to avoid data loss; legacy collection preserved. Please migrate '${legacyName}' manually.`);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
logger.info(`[migration] Migrating ${documents.length} point(s) from '${legacyName}'`);
|
|
175
|
+
// vector_store does not auto-create the target collection. At server startup
|
|
176
|
+
// the unified knowledge-base collection may not exist yet (no ingest has run),
|
|
177
|
+
// so initialize it before storing. Legacy embeddings were produced by the same
|
|
178
|
+
// embedding model, so their dimensionality is the correct vector size.
|
|
179
|
+
const vectorSize = documents.find((d) => Array.isArray(d.vector) && d.vector.length > 0)?.vector?.length;
|
|
180
|
+
if (!vectorSize) {
|
|
181
|
+
logger.warn(`[migration] No documents in '${legacyName}' have embeddings — skipping migration (legacy collection preserved)`);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (!(await collectionExists(KNOWLEDGE_COLLECTION))) {
|
|
185
|
+
await pluginCall('collection_initialize', {
|
|
186
|
+
collection: KNOWLEDGE_COLLECTION,
|
|
187
|
+
vectorSize,
|
|
188
|
+
createTextIndex: true,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const target = await pluginCall('collection_stats', {
|
|
193
|
+
collection: KNOWLEDGE_COLLECTION,
|
|
194
|
+
});
|
|
195
|
+
if (target?.vectorSize !== vectorSize) {
|
|
196
|
+
logger.error(`[migration] Target '${KNOWLEDGE_COLLECTION}' exists with vector size ${target?.vectorSize}, ` +
|
|
197
|
+
`but legacy '${legacyName}' vectors are ${vectorSize}-dimensional. Skipping migration to avoid ` +
|
|
198
|
+
`recreating (and dropping) the existing knowledge base; legacy collection preserved.`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
let successCount = 0;
|
|
203
|
+
let failCount = 0;
|
|
204
|
+
for (const doc of documents) {
|
|
205
|
+
try {
|
|
206
|
+
// Convert legacy pattern/policy payloads into canonical knowledge chunk payload shape.
|
|
207
|
+
const mergedPayload = buildMigratedPayload(doc, legacyName, tags);
|
|
208
|
+
// vector_store requires a pre-computed embedding vector.
|
|
209
|
+
// Legacy documents were stored with embeddings — reuse the stored vector.
|
|
210
|
+
// If no vector is present (edge case), skip and log.
|
|
211
|
+
if (!doc.vector || doc.vector.length === 0) {
|
|
212
|
+
logger.warn(`[migration] Document ${doc.id} has no vector — skipping (source: ${legacyName})`);
|
|
213
|
+
failCount++;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
await pluginCall('vector_store', {
|
|
217
|
+
collection: KNOWLEDGE_COLLECTION,
|
|
218
|
+
id: (0, uuid_1.v5)(`legacy://${legacyName}/${doc.id}#0`, exports.KNOWLEDGE_NAMESPACE),
|
|
219
|
+
embedding: doc.vector,
|
|
220
|
+
payload: mergedPayload,
|
|
221
|
+
});
|
|
222
|
+
successCount++;
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
226
|
+
logger.error(`[migration] Failed to migrate document ${doc.id} from ${legacyName}: ${msg}`);
|
|
227
|
+
failCount++;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
logger.info(`[migration] Migrated ${successCount}/${documents.length} point(s) (${failCount} failed)`, {
|
|
231
|
+
legacyName,
|
|
232
|
+
successCount,
|
|
233
|
+
failCount,
|
|
234
|
+
});
|
|
235
|
+
if (failCount > 0) {
|
|
236
|
+
logger.warn(`[migration] ${failCount} document(s) failed to migrate from '${legacyName}' — legacy collection preserved for manual inspection`);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
// All points migrated — delete the legacy collection
|
|
240
|
+
await pluginCall('collection_delete', { collection: legacyName });
|
|
241
|
+
logger.info(`[migration] Deleted legacy collection '${legacyName}'`);
|
|
242
|
+
}
|
|
243
|
+
let migrationInProgress = false;
|
|
244
|
+
/**
|
|
245
|
+
* Run the auto-migration check at server startup.
|
|
246
|
+
*
|
|
247
|
+
* Safe to call even when the plugin is not initialised (skips silently).
|
|
248
|
+
* Non-fatal: any error is caught and logged; the server continues normally.
|
|
249
|
+
*/
|
|
250
|
+
async function runKnowledgeMigration(logger) {
|
|
251
|
+
if (!(0, plugin_registry_1.isPluginInitialized)()) {
|
|
252
|
+
// Plugin not available (e.g. no plugins.json) — skip migration
|
|
253
|
+
logger.info('[migration] Plugin not initialised — skipping legacy knowledge migration');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (migrationInProgress) {
|
|
257
|
+
logger.info('[migration] Migration already in progress — skipping concurrent run');
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
migrationInProgress = true;
|
|
261
|
+
try {
|
|
262
|
+
for (const { name, tags } of LEGACY_COLLECTIONS) {
|
|
263
|
+
// Isolate each collection: a failure migrating one (e.g. from
|
|
264
|
+
// collectionExists/collection_initialize/collection_stats) must not abort
|
|
265
|
+
// migration of the others — the design is non-fatal and per-collection
|
|
266
|
+
// independent. The next run also retries anything left behind.
|
|
267
|
+
try {
|
|
268
|
+
const exists = await collectionExists(name);
|
|
269
|
+
if (!exists) {
|
|
270
|
+
logger.info(`[migration] Legacy collection '${name}' not found — nothing to migrate`);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
await migrateLegacyCollection(name, tags, logger);
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
277
|
+
logger.error(`[migration] Migration of '${name}' failed — continuing with remaining collections: ${msg}`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
logger.info('[migration] Knowledge base migration check complete');
|
|
281
|
+
}
|
|
282
|
+
catch (err) {
|
|
283
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
284
|
+
logger.error(`[migration] Migration failed — server continues normally: ${msg}`);
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
migrationInProgress = false;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Base Search Service (core layer)
|
|
3
|
+
*
|
|
4
|
+
* Provides the reusable `searchKnowledgeBase()` helper used by both the
|
|
5
|
+
* `manageKnowledge` MCP tool and core consumers (schema recommendation,
|
|
6
|
+
* operate analysis, REST API). Lives in `core/` so that core modules do not
|
|
7
|
+
* need to import from the `tools/` layer (avoids a core → tools → core cycle).
|
|
8
|
+
*
|
|
9
|
+
* PRD #356: Knowledge Base System
|
|
10
|
+
* PRD #375: Unified Knowledge Base
|
|
11
|
+
*/
|
|
12
|
+
import { KnowledgeSearchResultItem } from './knowledge-types';
|
|
13
|
+
/**
|
|
14
|
+
* Plugin providing the vector store operations
|
|
15
|
+
*/
|
|
16
|
+
export declare const PLUGIN_NAME = "agentic-tools";
|
|
17
|
+
/**
|
|
18
|
+
* Collection name for knowledge base chunks in Qdrant
|
|
19
|
+
*/
|
|
20
|
+
export declare const KNOWLEDGE_COLLECTION = "knowledge-base";
|
|
21
|
+
/**
|
|
22
|
+
* Default limit for search results
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEFAULT_SEARCH_LIMIT = 20;
|
|
25
|
+
/**
|
|
26
|
+
* Result type for the reusable search function
|
|
27
|
+
*/
|
|
28
|
+
export interface SearchKnowledgeBaseResult {
|
|
29
|
+
success: boolean;
|
|
30
|
+
chunks: KnowledgeSearchResultItem[];
|
|
31
|
+
totalMatches: number;
|
|
32
|
+
error?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reusable knowledge base search function.
|
|
36
|
+
* Can be called from MCP tool handler or HTTP endpoints.
|
|
37
|
+
*
|
|
38
|
+
* @param params Search parameters
|
|
39
|
+
* @returns Search results with chunks or error
|
|
40
|
+
*/
|
|
41
|
+
export declare function searchKnowledgeBase(params: {
|
|
42
|
+
query: string;
|
|
43
|
+
limit?: number;
|
|
44
|
+
uriFilter?: string;
|
|
45
|
+
}): Promise<SearchKnowledgeBaseResult>;
|
|
46
|
+
//# sourceMappingURL=knowledge-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-service.d.ts","sourceRoot":"","sources":["../../src/core/knowledge-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,WAAW,kBAAkB,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAkBvC;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,yBAAyB,EAAE,CAAC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CA4JrC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Knowledge Base Search Service (core layer)
|
|
4
|
+
*
|
|
5
|
+
* Provides the reusable `searchKnowledgeBase()` helper used by both the
|
|
6
|
+
* `manageKnowledge` MCP tool and core consumers (schema recommendation,
|
|
7
|
+
* operate analysis, REST API). Lives in `core/` so that core modules do not
|
|
8
|
+
* need to import from the `tools/` layer (avoids a core → tools → core cycle).
|
|
9
|
+
*
|
|
10
|
+
* PRD #356: Knowledge Base System
|
|
11
|
+
* PRD #375: Unified Knowledge Base
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.DEFAULT_SEARCH_LIMIT = exports.KNOWLEDGE_COLLECTION = exports.PLUGIN_NAME = void 0;
|
|
15
|
+
exports.searchKnowledgeBase = searchKnowledgeBase;
|
|
16
|
+
const plugin_registry_1 = require("./plugin-registry");
|
|
17
|
+
const embedding_service_1 = require("./embedding-service");
|
|
18
|
+
/**
|
|
19
|
+
* Plugin providing the vector store operations
|
|
20
|
+
*/
|
|
21
|
+
exports.PLUGIN_NAME = 'agentic-tools';
|
|
22
|
+
/**
|
|
23
|
+
* Collection name for knowledge base chunks in Qdrant
|
|
24
|
+
*/
|
|
25
|
+
exports.KNOWLEDGE_COLLECTION = 'knowledge-base';
|
|
26
|
+
/**
|
|
27
|
+
* Default limit for search results
|
|
28
|
+
*/
|
|
29
|
+
exports.DEFAULT_SEARCH_LIMIT = 20;
|
|
30
|
+
/**
|
|
31
|
+
* A missing target collection surfaces as a "Not Found" error from the vector
|
|
32
|
+
* store; callers treat that as an empty result rather than a failure.
|
|
33
|
+
*/
|
|
34
|
+
function isCollectionNotFoundError(message) {
|
|
35
|
+
return message.includes('Not Found') || message.includes('not found');
|
|
36
|
+
}
|
|
37
|
+
let embeddingServiceInstance = null;
|
|
38
|
+
function getEmbeddingService() {
|
|
39
|
+
if (!embeddingServiceInstance) {
|
|
40
|
+
embeddingServiceInstance = new embedding_service_1.EmbeddingService();
|
|
41
|
+
}
|
|
42
|
+
return embeddingServiceInstance;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Reusable knowledge base search function.
|
|
46
|
+
* Can be called from MCP tool handler or HTTP endpoints.
|
|
47
|
+
*
|
|
48
|
+
* @param params Search parameters
|
|
49
|
+
* @returns Search results with chunks or error
|
|
50
|
+
*/
|
|
51
|
+
async function searchKnowledgeBase(params) {
|
|
52
|
+
const { query, limit = exports.DEFAULT_SEARCH_LIMIT, uriFilter } = params;
|
|
53
|
+
// Check plugin availability
|
|
54
|
+
if (!(0, plugin_registry_1.isPluginInitialized)()) {
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
chunks: [],
|
|
58
|
+
totalMatches: 0,
|
|
59
|
+
error: 'Plugin system not available',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// Check embedding service availability
|
|
63
|
+
const embeddingService = getEmbeddingService();
|
|
64
|
+
if (!embeddingService.isAvailable()) {
|
|
65
|
+
const status = embeddingService.getStatus();
|
|
66
|
+
return {
|
|
67
|
+
success: false,
|
|
68
|
+
chunks: [],
|
|
69
|
+
totalMatches: 0,
|
|
70
|
+
error: `Embedding service not available: ${status.reason}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Generate embedding for the search query
|
|
74
|
+
let queryEmbedding;
|
|
75
|
+
try {
|
|
76
|
+
queryEmbedding = await embeddingService.generateEmbedding(query);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
return {
|
|
80
|
+
success: false,
|
|
81
|
+
chunks: [],
|
|
82
|
+
totalMatches: 0,
|
|
83
|
+
error: `Failed to generate query embedding: ${err instanceof Error ? err.message : String(err)}`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// Build filter if uriFilter is provided
|
|
87
|
+
let filter;
|
|
88
|
+
if (uriFilter) {
|
|
89
|
+
filter = {
|
|
90
|
+
must: [
|
|
91
|
+
{
|
|
92
|
+
key: 'uri',
|
|
93
|
+
match: {
|
|
94
|
+
value: uriFilter,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
// Call vector_search plugin tool. Wrap in try/catch so a transport/plugin throw
|
|
101
|
+
// is returned as a structured error (matching the generateEmbedding path above)
|
|
102
|
+
// instead of escaping this function's {success, error} contract.
|
|
103
|
+
let searchResponse;
|
|
104
|
+
try {
|
|
105
|
+
searchResponse = await (0, plugin_registry_1.invokePluginTool)(exports.PLUGIN_NAME, 'vector_search', {
|
|
106
|
+
collection: exports.KNOWLEDGE_COLLECTION,
|
|
107
|
+
embedding: queryEmbedding,
|
|
108
|
+
limit,
|
|
109
|
+
filter,
|
|
110
|
+
scoreThreshold: 0, // Return all results up to limit, let consumer filter by score
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
chunks: [],
|
|
117
|
+
totalMatches: 0,
|
|
118
|
+
error: `Search failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (!searchResponse.success) {
|
|
122
|
+
const error = searchResponse.error;
|
|
123
|
+
const errorMessage = error?.message || error?.error || 'Search failed';
|
|
124
|
+
// If collection doesn't exist (Not Found), return empty result (not error)
|
|
125
|
+
if (isCollectionNotFoundError(errorMessage)) {
|
|
126
|
+
return {
|
|
127
|
+
success: true,
|
|
128
|
+
chunks: [],
|
|
129
|
+
totalMatches: 0,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
success: false,
|
|
134
|
+
chunks: [],
|
|
135
|
+
totalMatches: 0,
|
|
136
|
+
error: errorMessage,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// Extract results from plugin response
|
|
140
|
+
const searchResult = searchResponse.result;
|
|
141
|
+
if (!searchResult || typeof searchResult !== 'object') {
|
|
142
|
+
return {
|
|
143
|
+
success: false,
|
|
144
|
+
chunks: [],
|
|
145
|
+
totalMatches: 0,
|
|
146
|
+
error: 'Search returned an invalid response',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (!searchResult.success) {
|
|
150
|
+
const errorMessage = searchResult.error || searchResult.message || 'Search failed';
|
|
151
|
+
// If collection doesn't exist, return empty result (not error)
|
|
152
|
+
if (isCollectionNotFoundError(errorMessage)) {
|
|
153
|
+
return {
|
|
154
|
+
success: true,
|
|
155
|
+
chunks: [],
|
|
156
|
+
totalMatches: 0,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
success: false,
|
|
161
|
+
chunks: [],
|
|
162
|
+
totalMatches: 0,
|
|
163
|
+
error: errorMessage,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
// Transform results to KnowledgeSearchResultItem format
|
|
167
|
+
const results = searchResult.data || [];
|
|
168
|
+
const chunks = results.map((result) => ({
|
|
169
|
+
id: result.id,
|
|
170
|
+
content: result.payload.content || '',
|
|
171
|
+
score: result.score,
|
|
172
|
+
matchType: 'semantic', // Dense vector search only (BM25 deferred)
|
|
173
|
+
uri: result.payload.uri || '',
|
|
174
|
+
metadata: result.payload.metadata || {},
|
|
175
|
+
chunkIndex: result.payload.chunkIndex ?? 0,
|
|
176
|
+
totalChunks: result.payload.totalChunks ?? 0,
|
|
177
|
+
tags: result.payload.tags || [], // PRD #375: AI classification tags
|
|
178
|
+
extractedPolicies: undefined, // Populated by PRD #357
|
|
179
|
+
}));
|
|
180
|
+
return {
|
|
181
|
+
success: true,
|
|
182
|
+
chunks,
|
|
183
|
+
totalMatches: chunks.length,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
@@ -29,6 +29,13 @@ export interface KnowledgeChunk {
|
|
|
29
29
|
chunkIndex: number;
|
|
30
30
|
/** Total number of chunks from the source document */
|
|
31
31
|
totalChunks: number;
|
|
32
|
+
/**
|
|
33
|
+
* Classification tags applied to all chunks from the same document.
|
|
34
|
+
* Possible values: "policy", "pattern"
|
|
35
|
+
* Empty array means general content (no specific classification).
|
|
36
|
+
* PRD #375: Unified Knowledge Base
|
|
37
|
+
*/
|
|
38
|
+
tags: string[];
|
|
32
39
|
/** IDs of policies extracted from this chunk (populated by PRD #357) */
|
|
33
40
|
extractedPolicyIds?: string[];
|
|
34
41
|
}
|
|
@@ -78,6 +85,13 @@ export interface KnowledgeSearchResultItem {
|
|
|
78
85
|
metadata: Record<string, unknown>;
|
|
79
86
|
chunkIndex: number;
|
|
80
87
|
totalChunks: number;
|
|
88
|
+
/**
|
|
89
|
+
* Classification tags for this chunk's source document.
|
|
90
|
+
* Possible values: "policy", "pattern"
|
|
91
|
+
* Empty array means general content.
|
|
92
|
+
* PRD #375: Unified Knowledge Base
|
|
93
|
+
*/
|
|
94
|
+
tags: string[];
|
|
81
95
|
/** Policies extracted from this chunk (populated by PRD #357) */
|
|
82
96
|
extractedPolicies?: Array<{
|
|
83
97
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knowledge-types.d.ts","sourceRoot":"","sources":["../../src/core/knowledge-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,EAAE,EAAE,MAAM,CAAC;IAEX,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;IAEhB,6GAA6G;IAC7G,GAAG,EAAE,MAAM,CAAC;IAEZ,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,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