only_ever_generator 8.0.2 → 8.0.4
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/bootstrap/app.d.ts +1 -1
- package/dist/bootstrap/app.d.ts.map +1 -1
- package/dist/bootstrap/app.js +1 -1
- package/dist/bootstrap/app.js.map +1 -1
- package/dist/card_gen/generate_cards.d.ts.map +1 -1
- package/dist/card_gen/generate_cards.js.map +1 -1
- package/dist/index.d.ts +2 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +83 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/bootstrap/app.ts +313 -0
- package/src/card_gen/generate_cards.ts +1 -0
- package/src/index.ts +95 -60
- package/MODULAR_REFACTORING_SUMMARY.md +0 -217
- package/README.md +0 -608
- package/dist/configs/card_generator_config.d.ts +0 -41
- package/dist/configs/card_generator_config.d.ts.map +0 -1
- package/dist/configs/card_generator_config.js +0 -17
- package/dist/configs/card_generator_config.js.map +0 -1
- package/dist/configs/concept_facts_generator_config.d.ts +0 -28
- package/dist/configs/concept_facts_generator_config.d.ts.map +0 -1
- package/dist/configs/concept_facts_generator_config.js +0 -12
- package/dist/configs/concept_facts_generator_config.js.map +0 -1
- package/dist/configs/consolidator_config.d.ts +0 -20
- package/dist/configs/consolidator_config.d.ts.map +0 -1
- package/dist/configs/consolidator_config.js +0 -14
- package/dist/configs/consolidator_config.js.map +0 -1
- package/dist/configs/embedding_generator_config.d.ts +0 -13
- package/dist/configs/embedding_generator_config.d.ts.map +0 -1
- package/dist/configs/embedding_generator_config.js +0 -11
- package/dist/configs/embedding_generator_config.js.map +0 -1
- package/dist/configs/parser_config.d.ts +0 -31
- package/dist/configs/parser_config.d.ts.map +0 -1
- package/dist/configs/parser_config.js +0 -26
- package/dist/configs/parser_config.js.map +0 -1
- package/dist/configs/typology_generator_config.d.ts +0 -26
- package/dist/configs/typology_generator_config.d.ts.map +0 -1
- package/dist/configs/typology_generator_config.js +0 -12
- package/dist/configs/typology_generator_config.js.map +0 -1
- package/dist/consolidation/global_consolidator.d.ts +0 -47
- package/dist/consolidation/global_consolidator.d.ts.map +0 -1
- package/dist/consolidation/global_consolidator.js +0 -94
- package/dist/consolidation/global_consolidator.js.map +0 -1
- package/dist/consolidation/local_consolidator.d.ts +0 -52
- package/dist/consolidation/local_consolidator.d.ts.map +0 -1
- package/dist/consolidation/local_consolidator.js +0 -118
- package/dist/consolidation/local_consolidator.js.map +0 -1
- package/dist/embeddings/embedding_generator.d.ts +0 -30
- package/dist/embeddings/embedding_generator.d.ts.map +0 -1
- package/dist/embeddings/embedding_generator.js +0 -71
- package/dist/embeddings/embedding_generator.js.map +0 -1
- package/dist/generators/card_generator.d.ts +0 -20
- package/dist/generators/card_generator.d.ts.map +0 -1
- package/dist/generators/card_generator.js +0 -239
- package/dist/generators/card_generator.js.map +0 -1
- package/dist/generators/concept_facts_generator.d.ts +0 -18
- package/dist/generators/concept_facts_generator.d.ts.map +0 -1
- package/dist/generators/concept_facts_generator.js +0 -153
- package/dist/generators/concept_facts_generator.js.map +0 -1
- package/dist/generators/typology_generator.d.ts +0 -20
- package/dist/generators/typology_generator.d.ts.map +0 -1
- package/dist/generators/typology_generator.js +0 -184
- package/dist/generators/typology_generator.js.map +0 -1
- package/dist/parsers/card_response_parser.d.ts +0 -16
- package/dist/parsers/card_response_parser.d.ts.map +0 -1
- package/dist/parsers/card_response_parser.js +0 -59
- package/dist/parsers/card_response_parser.js.map +0 -1
- package/dist/parsers/content_parser.d.ts +0 -27
- package/dist/parsers/content_parser.d.ts.map +0 -1
- package/dist/parsers/content_parser.js +0 -66
- package/dist/parsers/content_parser.js.map +0 -1
- package/dist/utils/validation.d.ts +0 -68
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js +0 -203
- package/dist/utils/validation.js.map +0 -1
- package/src/configs/card_generator_config.ts +0 -58
- package/src/configs/concept_facts_generator_config.ts +0 -40
- package/src/configs/consolidator_config.ts +0 -33
- package/src/configs/embedding_generator_config.ts +0 -20
- package/src/configs/parser_config.ts +0 -57
- package/src/configs/typology_generator_config.ts +0 -38
- package/src/consolidation/global_consolidator.ts +0 -158
- package/src/consolidation/local_consolidator.ts +0 -173
- package/src/embeddings/embedding_generator.ts +0 -92
- package/src/generators/card_generator.ts +0 -258
- package/src/generators/concept_facts_generator.ts +0 -175
- package/src/generators/typology_generator.ts +0 -208
- package/src/parsers/card_response_parser.ts +0 -63
- package/src/parsers/content_parser.ts +0 -90
- package/src/utils/validation.ts +0 -298
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Standalone TypologyGenerator module
|
|
4
|
-
* Analyzes content and determines learning value and classification
|
|
5
|
-
*/
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.TypologyGenerator = void 0;
|
|
17
|
-
const openai_helper_1 = require("../helper/openai_helper");
|
|
18
|
-
const logger_1 = require("../logger");
|
|
19
|
-
const open_ai_service_1 = require("../services/open_ai_service");
|
|
20
|
-
const build_classify_summarize_schema_1 = require("../helper/schema_helper/build_classify_summarize_schema");
|
|
21
|
-
const sanitize_strings_1 = require("../utils/sanitize_strings");
|
|
22
|
-
const typology_generator_config_1 = require("../configs/typology_generator_config");
|
|
23
|
-
const validation_1 = require("../utils/validation");
|
|
24
|
-
class TypologyGenerator {
|
|
25
|
-
constructor(config) {
|
|
26
|
-
this.validateConfig(config);
|
|
27
|
-
this.config = Object.assign(Object.assign({}, typology_generator_config_1.DEFAULT_TYPOLOGY_GENERATOR_CONFIG), config);
|
|
28
|
-
this.openAiService = new open_ai_service_1.OpenAiService(this.config.apiKey, this.config.model);
|
|
29
|
-
this.openAIHelper = new openai_helper_1.OpenAIHelper(this.config.apiKey);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Generate typology analysis for the configured content
|
|
33
|
-
*/
|
|
34
|
-
generate() {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
var _a, _b, _c, _d, _e;
|
|
37
|
-
try {
|
|
38
|
-
const headings = this.config.content.h1_headings ||
|
|
39
|
-
this.config.content.timecodes || [""];
|
|
40
|
-
// Use OpenAI Responses API
|
|
41
|
-
const classifySummarizeSchema = yield (0, build_classify_summarize_schema_1.buildClassifySummarizeSchema)(headings.length > 0 ? headings : [""]);
|
|
42
|
-
const openAiResponse = yield this.openAIHelper.openAI.responses.create({
|
|
43
|
-
prompt: {
|
|
44
|
-
id: this.config.promptId,
|
|
45
|
-
variables: {
|
|
46
|
-
heading_type: this.config.content.timecodes
|
|
47
|
-
? "timecode"
|
|
48
|
-
: "h1 heading",
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
max_output_tokens: 30000,
|
|
52
|
-
input: [
|
|
53
|
-
{
|
|
54
|
-
role: "user",
|
|
55
|
-
content: [
|
|
56
|
-
{
|
|
57
|
-
type: "input_text",
|
|
58
|
-
text: JSON.stringify(this.config.content),
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
store: true,
|
|
64
|
-
text: {
|
|
65
|
-
format: {
|
|
66
|
-
type: "json_schema",
|
|
67
|
-
name: classifySummarizeSchema.name,
|
|
68
|
-
strict: true,
|
|
69
|
-
schema: classifySummarizeSchema.schema,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
console.log(openAiResponse);
|
|
74
|
-
if (!openAiResponse) {
|
|
75
|
-
yield (0, logger_1.log_error)({
|
|
76
|
-
flow: this.config.generationCurriculum
|
|
77
|
-
? "curriculum_manual_generation"
|
|
78
|
-
: "manual_generation",
|
|
79
|
-
data: openAiResponse,
|
|
80
|
-
error: "empty_openai_response",
|
|
81
|
-
timestamp: new Date(),
|
|
82
|
-
source_id: this.config.sourceId || "unknown",
|
|
83
|
-
type: {
|
|
84
|
-
request_type: "breadth",
|
|
85
|
-
n: 1,
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
openAiResponse["request_type"] = {
|
|
91
|
-
type: "breadth",
|
|
92
|
-
n: 1,
|
|
93
|
-
};
|
|
94
|
-
openAiResponse.metadata = {
|
|
95
|
-
req_time: (_a = openAiResponse.created) !== null && _a !== void 0 ? _a : new Date(),
|
|
96
|
-
req_type: {
|
|
97
|
-
type: "breadth",
|
|
98
|
-
n: 1,
|
|
99
|
-
},
|
|
100
|
-
req_tokens: (_c = (_b = openAiResponse.usage) === null || _b === void 0 ? void 0 : _b.input_tokens) !== null && _c !== void 0 ? _c : 0,
|
|
101
|
-
res_tokens: (_e = (_d = openAiResponse.usage) === null || _d === void 0 ? void 0 : _d.output_tokens) !== null && _e !== void 0 ? _e : 0,
|
|
102
|
-
prompt: openAiResponse.prompt,
|
|
103
|
-
model: openAiResponse.model,
|
|
104
|
-
usage: openAiResponse.usage,
|
|
105
|
-
};
|
|
106
|
-
if (openAiResponse.status == "completed") {
|
|
107
|
-
console.log("Completed");
|
|
108
|
-
return this.parseTypologyOnSuccess(openAiResponse);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
openAiResponse.metadata.err_message = openAiResponse.message;
|
|
112
|
-
return openAiResponse;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch (e) {
|
|
116
|
-
console.log(e);
|
|
117
|
-
yield (0, logger_1.log_error)({
|
|
118
|
-
flow: this.config.generationCurriculum
|
|
119
|
-
? "curriculum_manual_generation"
|
|
120
|
-
: "manual_generation",
|
|
121
|
-
data: e,
|
|
122
|
-
timestamp: new Date(),
|
|
123
|
-
error: "error_in_typology_generation",
|
|
124
|
-
source_id: this.config.sourceId || "unknown",
|
|
125
|
-
type: {
|
|
126
|
-
request_type: "breadth",
|
|
127
|
-
n: 1,
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
throw e;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
parseTypologyOnSuccess(responseData) {
|
|
135
|
-
responseData.metadata.status = "completed";
|
|
136
|
-
const generatedContent = this.parseJson(responseData);
|
|
137
|
-
console.log(generatedContent.learn_value);
|
|
138
|
-
return {
|
|
139
|
-
status_code: 200,
|
|
140
|
-
metadata: [responseData.metadata],
|
|
141
|
-
field: this.parseFields(generatedContent.field),
|
|
142
|
-
generate_cards: generatedContent.learn_value,
|
|
143
|
-
summary_cards: generatedContent.summary_cards,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
parseJson(response) {
|
|
147
|
-
var _a;
|
|
148
|
-
try {
|
|
149
|
-
const generatedContent = JSON.parse(response.output_text);
|
|
150
|
-
const summaryCards = (_a = generatedContent === null || generatedContent === void 0 ? void 0 : generatedContent.summary_cards) !== null && _a !== void 0 ? _a : [];
|
|
151
|
-
if (summaryCards) {
|
|
152
|
-
const remappedSummaryCards = summaryCards.map((item) => {
|
|
153
|
-
return Object.assign(Object.assign({}, item), { reference: (0, sanitize_strings_1.restoreQuotesInString)(item.reference) });
|
|
154
|
-
});
|
|
155
|
-
return Object.assign(Object.assign({}, generatedContent), { summary_cards: remappedSummaryCards });
|
|
156
|
-
}
|
|
157
|
-
return generatedContent;
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
throw new logger_1.ParsingError("Something went wrong in parsing the json", response);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
parseFields(fields) {
|
|
164
|
-
const fieldKeys = ["primary_field", "secondary_field", "tertiary_field"];
|
|
165
|
-
return fields.slice(0, 3).map((item, index) => ({
|
|
166
|
-
[fieldKeys[index]]: item,
|
|
167
|
-
reconcile: !this.config.expectedFields.includes(item.toLowerCase()),
|
|
168
|
-
}));
|
|
169
|
-
}
|
|
170
|
-
validateConfig(config) {
|
|
171
|
-
(0, validation_1.validateOpenAIKey)(config.apiKey);
|
|
172
|
-
(0, validation_1.validateOpenAIModel)(config.model);
|
|
173
|
-
(0, validation_1.validatePromptId)(config.promptId, "prompt ID");
|
|
174
|
-
(0, validation_1.validateStringArray)(config.expectedFields, "expected fields", true);
|
|
175
|
-
if (!config.content) {
|
|
176
|
-
throw new Error("Content is required");
|
|
177
|
-
}
|
|
178
|
-
if (!config.content.title) {
|
|
179
|
-
throw new Error("Content title is required");
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
exports.TypologyGenerator = TypologyGenerator;
|
|
184
|
-
//# sourceMappingURL=typology_generator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typology_generator.js","sourceRoot":"","sources":["../../src/generators/typology_generator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,2DAAkE;AAClE,sCAAiE;AACjE,iEAA4D;AAC5D,6GAAuG;AACvG,gEAAkE;AAClE,oFAG8C;AAC9C,oDAK6B;AAE7B,MAAa,iBAAiB;IAK5B,YAAY,MAA+B;QACzC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,mCAAQ,6DAAiC,GAAK,MAAM,CAAE,CAAC;QAClE,IAAI,CAAC,aAAa,GAAG,IAAI,+BAAa,CACpC,IAAI,CAAC,MAAM,CAAC,MAAM,EAClB,IAAI,CAAC,MAAM,CAAC,KAAK,CAClB,CAAC;QACF,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iBAAiB,EAAE,IAAI,CAAC,CAAC;QAEpE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;CACF;AA1LD,8CA0LC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standalone CardResponseParser module
|
|
3
|
-
* Parses and validates generated cards
|
|
4
|
-
*/
|
|
5
|
-
import { CardResponseParserConfig } from "../configs/parser_config";
|
|
6
|
-
import { GeneratedCardResponseType } from "../types/raw_card_response_types/generated_card_response_type";
|
|
7
|
-
export declare class CardResponseParser {
|
|
8
|
-
private config;
|
|
9
|
-
constructor(config: CardResponseParserConfig);
|
|
10
|
-
/**
|
|
11
|
-
* Parse and validate generated card response
|
|
12
|
-
*/
|
|
13
|
-
parse(generatedData: GeneratedCardResponseType): Promise<any>;
|
|
14
|
-
private validateConfig;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=card_response_parser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"card_response_parser.d.ts","sourceRoot":"","sources":["../../src/parsers/card_response_parser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,wBAAwB,EAEzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,MAAM,+DAA+D,CAAC;AAG1G,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAA2B;gBAE7B,MAAM,EAAE,wBAAwB;IAK5C;;OAEG;IACG,KAAK,CAAC,aAAa,EAAE,yBAAyB,GAAG,OAAO,CAAC,GAAG,CAAC;IA6BnE,OAAO,CAAC,cAAc;CASvB"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Standalone CardResponseParser module
|
|
4
|
-
* Parses and validates generated cards
|
|
5
|
-
*/
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.CardResponseParser = void 0;
|
|
17
|
-
const parse_card_response_1 = require("../parse/parse_card_response");
|
|
18
|
-
const parser_config_1 = require("../configs/parser_config");
|
|
19
|
-
class CardResponseParser {
|
|
20
|
-
constructor(config) {
|
|
21
|
-
this.validateConfig(config);
|
|
22
|
-
this.config = Object.assign(Object.assign({}, parser_config_1.DEFAULT_CARD_RESPONSE_PARSER_CONFIG), config);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Parse and validate generated card response
|
|
26
|
-
*/
|
|
27
|
-
parse(generatedData) {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const parser = new parse_card_response_1.ParseCardResponse();
|
|
30
|
-
// Create source taxonomy from config
|
|
31
|
-
const sourceTaxonomy = {
|
|
32
|
-
concepts_facts: this.config.sourceTaxonomy.concepts_facts.map((concept) => ({
|
|
33
|
-
text: concept.text,
|
|
34
|
-
type: concept.type,
|
|
35
|
-
reference: concept.reference,
|
|
36
|
-
id: concept.id,
|
|
37
|
-
})),
|
|
38
|
-
fields: [],
|
|
39
|
-
learn_value: {
|
|
40
|
-
value: 50,
|
|
41
|
-
reason: "Generated for card parsing",
|
|
42
|
-
bloom_levels: [],
|
|
43
|
-
bloom_levels_reason: "",
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
return yield parser.parse(generatedData, sourceTaxonomy, this.config.bloomLevel);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
validateConfig(config) {
|
|
50
|
-
if (!config.sourceTaxonomy) {
|
|
51
|
-
throw new Error("Source taxonomy is required");
|
|
52
|
-
}
|
|
53
|
-
if (!config.sourceTaxonomy.concepts_facts) {
|
|
54
|
-
throw new Error("Concepts facts are required in source taxonomy");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.CardResponseParser = CardResponseParser;
|
|
59
|
-
//# sourceMappingURL=card_response_parser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"card_response_parser.js","sourceRoot":"","sources":["../../src/parsers/card_response_parser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,sEAAiE;AACjE,4DAGkC;AAIlC,MAAa,kBAAkB;IAG7B,YAAY,MAAgC;QAC1C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,mCAAQ,mDAAmC,GAAK,MAAM,CAAE,CAAC;IACtE,CAAC;IAED;;OAEG;IACG,KAAK,CAAC,aAAwC;;YAClD,MAAM,MAAM,GAAG,IAAI,uCAAiB,EAAE,CAAC;YAEvC,qCAAqC;YACrC,MAAM,cAAc,GAAmB;gBACrC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,CAC3D,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;oBACZ,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,SAAS,EAAE,OAAO,CAAC,SAAS;oBAC5B,EAAE,EAAE,OAAO,CAAC,EAAE;iBACf,CAAC,CACH;gBACD,MAAM,EAAE,EAAE;gBACV,WAAW,EAAE;oBACX,KAAK,EAAE,EAAE;oBACT,MAAM,EAAE,4BAA4B;oBACpC,YAAY,EAAE,EAAE;oBAChB,mBAAmB,EAAE,EAAE;iBACxB;aACF,CAAC;YAEF,OAAO,MAAM,MAAM,CAAC,KAAK,CACvB,aAAa,EACb,cAAc,EACd,IAAI,CAAC,MAAM,CAAC,UAAW,CACxB,CAAC;QACJ,CAAC;KAAA;IAEO,cAAc,CAAC,MAAgC;QACrD,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;CACF;AAjDD,gDAiDC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standalone ContentParser module
|
|
3
|
-
* Parses and sanitizes source content
|
|
4
|
-
*/
|
|
5
|
-
import { ContentParserConfig } from "../configs/parser_config";
|
|
6
|
-
export interface ParsedContent {
|
|
7
|
-
source_id: string;
|
|
8
|
-
type: string;
|
|
9
|
-
title: string;
|
|
10
|
-
content: any[];
|
|
11
|
-
headings: string[];
|
|
12
|
-
taxonomy?: any;
|
|
13
|
-
}
|
|
14
|
-
export declare class ContentParser {
|
|
15
|
-
private config;
|
|
16
|
-
constructor(config: ContentParserConfig);
|
|
17
|
-
/**
|
|
18
|
-
* Parse raw content into structured format
|
|
19
|
-
*/
|
|
20
|
-
parse(rawContent: any): ParsedContent;
|
|
21
|
-
/**
|
|
22
|
-
* Parse video content with timecode collapsing
|
|
23
|
-
*/
|
|
24
|
-
parseVideoContent(rawContent: any): ParsedContent;
|
|
25
|
-
private validateConfig;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=content_parser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"content_parser.d.ts","sourceRoot":"","sources":["../../src/parsers/content_parser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,mBAAmB,EAEpB,MAAM,0BAA0B,CAAC;AAGlC,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAsB;gBAExB,MAAM,EAAE,mBAAmB;IAKvC;;OAEG;IACH,KAAK,CAAC,UAAU,EAAE,GAAG,GAAG,aAAa;IAyBrC;;OAEG;IACH,iBAAiB,CAAC,UAAU,EAAE,GAAG,GAAG,aAAa;IA0BjD,OAAO,CAAC,cAAc;CAGvB"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Standalone ContentParser module
|
|
4
|
-
* Parses and sanitizes source content
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ContentParser = void 0;
|
|
8
|
-
const parse_source_content_1 = require("../parse/parse_source_content");
|
|
9
|
-
const parser_config_1 = require("../configs/parser_config");
|
|
10
|
-
const validation_1 = require("../utils/validation");
|
|
11
|
-
class ContentParser {
|
|
12
|
-
constructor(config) {
|
|
13
|
-
this.validateConfig(config);
|
|
14
|
-
this.config = Object.assign(Object.assign({}, parser_config_1.DEFAULT_CONTENT_PARSER_CONFIG), config);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Parse raw content into structured format
|
|
18
|
-
*/
|
|
19
|
-
parse(rawContent) {
|
|
20
|
-
// Create a custom ParseSourceContent instance with our config
|
|
21
|
-
const parser = new parse_source_content_1.ParseSourceContent(rawContent);
|
|
22
|
-
// Override the default titles and block types if provided
|
|
23
|
-
if (this.config.titlesToRemove) {
|
|
24
|
-
parser.titles_to_remove = this.config.titlesToRemove;
|
|
25
|
-
}
|
|
26
|
-
if (this.config.blockTypesToRemove) {
|
|
27
|
-
parser.block_types_toremove = this.config.blockTypesToRemove;
|
|
28
|
-
}
|
|
29
|
-
const parsedData = parser.parseData();
|
|
30
|
-
return {
|
|
31
|
-
source_id: parsedData.source_id,
|
|
32
|
-
type: parsedData.type,
|
|
33
|
-
title: parsedData.title,
|
|
34
|
-
content: parsedData.content,
|
|
35
|
-
headings: parsedData.headings,
|
|
36
|
-
taxonomy: parsedData.taxonomy,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Parse video content with timecode collapsing
|
|
41
|
-
*/
|
|
42
|
-
parseVideoContent(rawContent) {
|
|
43
|
-
const parser = new parse_source_content_1.ParseSourceContent(rawContent);
|
|
44
|
-
// Override the collapse timecodes method if max duration is specified
|
|
45
|
-
if (this.config.maxTimecodeDuration) {
|
|
46
|
-
const originalCollapseTimeCodes = parser.collapseTimeCodes.bind(parser);
|
|
47
|
-
parser.collapseTimeCodes = (data, maxDuration = this.config.maxTimecodeDuration) => {
|
|
48
|
-
return originalCollapseTimeCodes(data, maxDuration);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
const parsedData = parser.parseData();
|
|
52
|
-
return {
|
|
53
|
-
source_id: parsedData.source_id,
|
|
54
|
-
type: parsedData.type,
|
|
55
|
-
title: parsedData.title,
|
|
56
|
-
content: parsedData.content,
|
|
57
|
-
headings: parsedData.headings,
|
|
58
|
-
taxonomy: parsedData.taxonomy,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
validateConfig(config) {
|
|
62
|
-
(0, validation_1.validateContentType)(config.type);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.ContentParser = ContentParser;
|
|
66
|
-
//# sourceMappingURL=content_parser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"content_parser.js","sourceRoot":"","sources":["../../src/parsers/content_parser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,wEAAmE;AACnE,4DAGkC;AAClC,oDAA0D;AAW1D,MAAa,aAAa;IAGxB,YAAY,MAA2B;QACrC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,mCAAQ,6CAA6B,GAAK,MAAM,CAAE,CAAC;IAChE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAe;QACnB,8DAA8D;QAC9D,MAAM,MAAM,GAAG,IAAI,yCAAkB,CAAC,UAAU,CAAC,CAAC;QAElD,0DAA0D;QAC1D,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YAC/B,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;QACvD,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;YACnC,MAAM,CAAC,oBAAoB,GAAG,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;QAC/D,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAEtC,OAAO;YACL,SAAS,EAAE,UAAU,CAAC,SAAS;YAC/B,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,QAAQ,EAAE,UAAU,CAAC,QAAQ;YAC7B,QAAQ,EAAE,UAAU,CAAC,QAAQ;SAC9B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,iBAAiB,CAAC,UAAe;QAC/B,MAAM,MAAM,GAAG,IAAI,yCAAkB,CAAC,UAAU,CAAC,CAAC;QAElD,sEAAsE;QACtE,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;YACpC,MAAM,yBAAyB,GAAG,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACxE,MAAM,CAAC,iBAAiB,GAAG,CACzB,IAAW,EACX,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAC7C,EAAE;gBACF,OAAO,yBAAyB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;YACtD,CAAC,CAAC;QACJ,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAEtC,OAAO;YACL,SAAS,EAAE,UAAU,CAAC,SAAS;YAC/B,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,QAAQ,EAAE,UAAU,CAAC,QAAQ;YAC7B,QAAQ,EAAE,UAAU,CAAC,QAAQ;SAC9B,CAAC;IACJ,CAAC;IAEO,cAAc,CAAC,MAA2B;QAChD,IAAA,gCAAmB,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;CACF;AApED,sCAoEC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Input validation utilities for OnlyEver Generator
|
|
3
|
-
*/
|
|
4
|
-
export declare class ValidationError extends Error {
|
|
5
|
-
field?: string | undefined;
|
|
6
|
-
constructor(message: string, field?: string | undefined);
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Validates that a value is not null or undefined
|
|
10
|
-
*/
|
|
11
|
-
export declare function validateRequired<T>(value: T | null | undefined, fieldName: string): T;
|
|
12
|
-
/**
|
|
13
|
-
* Validates that a string is not empty
|
|
14
|
-
*/
|
|
15
|
-
export declare function validateNonEmptyString(value: string | null | undefined, fieldName: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Validates that a value is a positive number
|
|
18
|
-
*/
|
|
19
|
-
export declare function validatePositiveNumber(value: number | null | undefined, fieldName: string): number;
|
|
20
|
-
/**
|
|
21
|
-
* Validates that a number is within a range
|
|
22
|
-
*/
|
|
23
|
-
export declare function validateNumberRange(value: number | null | undefined, fieldName: string, min: number, max: number): number;
|
|
24
|
-
/**
|
|
25
|
-
* Validates that a value is one of the allowed values
|
|
26
|
-
*/
|
|
27
|
-
export declare function validateEnum<T extends string>(value: T | null | undefined, fieldName: string, allowedValues: readonly T[]): T;
|
|
28
|
-
/**
|
|
29
|
-
* Validates that a value is an array with at least one element
|
|
30
|
-
*/
|
|
31
|
-
export declare function validateNonEmptyArray<T>(value: T[] | null | undefined, fieldName: string): T[];
|
|
32
|
-
/**
|
|
33
|
-
* Validates OpenAI API key format
|
|
34
|
-
*/
|
|
35
|
-
export declare function validateOpenAIKey(apiKey: string | null | undefined): string;
|
|
36
|
-
/**
|
|
37
|
-
* Validates OpenAI model name
|
|
38
|
-
*/
|
|
39
|
-
export declare function validateOpenAIModel(model: string | null | undefined): string;
|
|
40
|
-
/**
|
|
41
|
-
* Validates prompt ID format
|
|
42
|
-
*/
|
|
43
|
-
export declare function validatePromptId(promptId: string | null | undefined, fieldName: string): string;
|
|
44
|
-
/**
|
|
45
|
-
* Validates content type
|
|
46
|
-
*/
|
|
47
|
-
export declare function validateContentType(type: string | null | undefined): string;
|
|
48
|
-
/**
|
|
49
|
-
* Validates source ID format
|
|
50
|
-
*/
|
|
51
|
-
export declare function validateSourceId(sourceId: string | null | undefined): string;
|
|
52
|
-
/**
|
|
53
|
-
* Validates similarity threshold
|
|
54
|
-
*/
|
|
55
|
-
export declare function validateSimilarityThreshold(threshold: number | null | undefined, fieldName: string): number;
|
|
56
|
-
/**
|
|
57
|
-
* Validates embedding dimensions
|
|
58
|
-
*/
|
|
59
|
-
export declare function validateEmbeddingDimensions(dimensions: number | null | undefined): number;
|
|
60
|
-
/**
|
|
61
|
-
* Validates that an object has required properties
|
|
62
|
-
*/
|
|
63
|
-
export declare function validateObjectProperties<T extends Record<string, any>>(obj: T | null | undefined, fieldName: string, requiredProperties: (keyof T)[]): T;
|
|
64
|
-
/**
|
|
65
|
-
* Validates array of strings
|
|
66
|
-
*/
|
|
67
|
-
export declare function validateStringArray(value: string[] | null | undefined, fieldName: string, allowEmpty?: boolean): string[];
|
|
68
|
-
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,eAAgB,SAAQ,KAAK;IACJ,KAAK,CAAC,EAAE,MAAM;gBAAtC,OAAO,EAAE,MAAM,EAAS,KAAK,CAAC,EAAE,MAAM,YAAA;CAInD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,GAChB,CAAC,CAKH;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,SAAS,EAAE,MAAM,GAChB,MAAM,CASR;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,SAAS,EAAE,MAAM,GAChB,MAAM,CASR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACV,MAAM,CASR;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC3C,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,SAAS,CAAC,EA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I,GAAG,SAAS,EAClC,SAAS,EAAE,MAAM,EACjB,UAAU,GAAE,OAAc,GACzB,MAAM,EAAE,CAqBV"}
|
package/dist/utils/validation.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Input validation utilities for OnlyEver Generator
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ValidationError = void 0;
|
|
7
|
-
exports.validateRequired = validateRequired;
|
|
8
|
-
exports.validateNonEmptyString = validateNonEmptyString;
|
|
9
|
-
exports.validatePositiveNumber = validatePositiveNumber;
|
|
10
|
-
exports.validateNumberRange = validateNumberRange;
|
|
11
|
-
exports.validateEnum = validateEnum;
|
|
12
|
-
exports.validateNonEmptyArray = validateNonEmptyArray;
|
|
13
|
-
exports.validateOpenAIKey = validateOpenAIKey;
|
|
14
|
-
exports.validateOpenAIModel = validateOpenAIModel;
|
|
15
|
-
exports.validatePromptId = validatePromptId;
|
|
16
|
-
exports.validateContentType = validateContentType;
|
|
17
|
-
exports.validateSourceId = validateSourceId;
|
|
18
|
-
exports.validateSimilarityThreshold = validateSimilarityThreshold;
|
|
19
|
-
exports.validateEmbeddingDimensions = validateEmbeddingDimensions;
|
|
20
|
-
exports.validateObjectProperties = validateObjectProperties;
|
|
21
|
-
exports.validateStringArray = validateStringArray;
|
|
22
|
-
class ValidationError extends Error {
|
|
23
|
-
constructor(message, field) {
|
|
24
|
-
super(message);
|
|
25
|
-
this.field = field;
|
|
26
|
-
this.name = "ValidationError";
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.ValidationError = ValidationError;
|
|
30
|
-
/**
|
|
31
|
-
* Validates that a value is not null or undefined
|
|
32
|
-
*/
|
|
33
|
-
function validateRequired(value, fieldName) {
|
|
34
|
-
if (value === null || value === undefined) {
|
|
35
|
-
throw new ValidationError(`${fieldName} is required`, fieldName);
|
|
36
|
-
}
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Validates that a string is not empty
|
|
41
|
-
*/
|
|
42
|
-
function validateNonEmptyString(value, fieldName) {
|
|
43
|
-
const validated = validateRequired(value, fieldName);
|
|
44
|
-
if (typeof validated !== "string" || validated.trim().length === 0) {
|
|
45
|
-
throw new ValidationError(`${fieldName} must be a non-empty string`, fieldName);
|
|
46
|
-
}
|
|
47
|
-
return validated;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Validates that a value is a positive number
|
|
51
|
-
*/
|
|
52
|
-
function validatePositiveNumber(value, fieldName) {
|
|
53
|
-
const validated = validateRequired(value, fieldName);
|
|
54
|
-
if (typeof validated !== "number" || validated <= 0) {
|
|
55
|
-
throw new ValidationError(`${fieldName} must be a positive number`, fieldName);
|
|
56
|
-
}
|
|
57
|
-
return validated;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Validates that a number is within a range
|
|
61
|
-
*/
|
|
62
|
-
function validateNumberRange(value, fieldName, min, max) {
|
|
63
|
-
const validated = validateRequired(value, fieldName);
|
|
64
|
-
if (typeof validated !== "number" || validated < min || validated > max) {
|
|
65
|
-
throw new ValidationError(`${fieldName} must be between ${min} and ${max}`, fieldName);
|
|
66
|
-
}
|
|
67
|
-
return validated;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Validates that a value is one of the allowed values
|
|
71
|
-
*/
|
|
72
|
-
function validateEnum(value, fieldName, allowedValues) {
|
|
73
|
-
const validated = validateRequired(value, fieldName);
|
|
74
|
-
if (!allowedValues.includes(validated)) {
|
|
75
|
-
throw new ValidationError(`${fieldName} must be one of: ${allowedValues.join(", ")}`, fieldName);
|
|
76
|
-
}
|
|
77
|
-
return validated;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Validates that a value is an array with at least one element
|
|
81
|
-
*/
|
|
82
|
-
function validateNonEmptyArray(value, fieldName) {
|
|
83
|
-
const validated = validateRequired(value, fieldName);
|
|
84
|
-
if (!Array.isArray(validated) || validated.length === 0) {
|
|
85
|
-
throw new ValidationError(`${fieldName} must be a non-empty array`, fieldName);
|
|
86
|
-
}
|
|
87
|
-
return validated;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Validates OpenAI API key format
|
|
91
|
-
*/
|
|
92
|
-
function validateOpenAIKey(apiKey) {
|
|
93
|
-
const validated = validateNonEmptyString(apiKey, "OpenAI API key");
|
|
94
|
-
// Basic format validation for OpenAI API keys
|
|
95
|
-
if (!validated.startsWith("sk-")) {
|
|
96
|
-
throw new ValidationError('OpenAI API key must start with "sk-"', "apiKey");
|
|
97
|
-
}
|
|
98
|
-
if (validated.length < 20) {
|
|
99
|
-
throw new ValidationError("OpenAI API key appears to be too short", "apiKey");
|
|
100
|
-
}
|
|
101
|
-
return validated;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Validates OpenAI model name
|
|
105
|
-
*/
|
|
106
|
-
function validateOpenAIModel(model) {
|
|
107
|
-
const validated = validateNonEmptyString(model, "OpenAI model");
|
|
108
|
-
// Common OpenAI model patterns
|
|
109
|
-
const validModels = [
|
|
110
|
-
"gpt-4o",
|
|
111
|
-
"gpt-4o-mini",
|
|
112
|
-
"gpt-4",
|
|
113
|
-
"gpt-4-turbo",
|
|
114
|
-
"gpt-3.5-turbo",
|
|
115
|
-
"gpt-3.5-turbo-16k",
|
|
116
|
-
];
|
|
117
|
-
if (!validModels.some((validModel) => validated.startsWith(validModel))) {
|
|
118
|
-
console.warn(`Model "${validated}" may not be a valid OpenAI model. Valid models include: ${validModels.join(", ")}`);
|
|
119
|
-
}
|
|
120
|
-
return validated;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Validates prompt ID format
|
|
124
|
-
*/
|
|
125
|
-
function validatePromptId(promptId, fieldName) {
|
|
126
|
-
const validated = validateNonEmptyString(promptId, fieldName);
|
|
127
|
-
// Basic format validation for prompt IDs
|
|
128
|
-
if (!validated.startsWith("pmpt_")) {
|
|
129
|
-
throw new ValidationError(`${fieldName} must start with "pmpt_"`, fieldName);
|
|
130
|
-
}
|
|
131
|
-
if (validated.length < 10) {
|
|
132
|
-
throw new ValidationError(`${fieldName} appears to be too short`, fieldName);
|
|
133
|
-
}
|
|
134
|
-
return validated;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Validates content type
|
|
138
|
-
*/
|
|
139
|
-
function validateContentType(type) {
|
|
140
|
-
return validateEnum(type, "content type", ["text", "video"]);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Validates source ID format
|
|
144
|
-
*/
|
|
145
|
-
function validateSourceId(sourceId) {
|
|
146
|
-
const validated = validateNonEmptyString(sourceId, "source ID");
|
|
147
|
-
// Basic validation - should be a reasonable length
|
|
148
|
-
if (validated.length < 3) {
|
|
149
|
-
throw new ValidationError("Source ID must be at least 3 characters long", "sourceId");
|
|
150
|
-
}
|
|
151
|
-
return validated;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Validates similarity threshold
|
|
155
|
-
*/
|
|
156
|
-
function validateSimilarityThreshold(threshold, fieldName) {
|
|
157
|
-
return validateNumberRange(threshold, fieldName, 0, 1);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Validates embedding dimensions
|
|
161
|
-
*/
|
|
162
|
-
function validateEmbeddingDimensions(dimensions) {
|
|
163
|
-
const validated = validateRequired(dimensions, "embedding dimensions");
|
|
164
|
-
// Common embedding dimensions
|
|
165
|
-
const validDimensions = [128, 256, 512, 768, 1024, 1536, 2048];
|
|
166
|
-
if (!validDimensions.includes(validated)) {
|
|
167
|
-
console.warn(`Embedding dimensions ${validated} may not be standard. Common values: ${validDimensions.join(", ")}`);
|
|
168
|
-
}
|
|
169
|
-
return validated;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Validates that an object has required properties
|
|
173
|
-
*/
|
|
174
|
-
function validateObjectProperties(obj, fieldName, requiredProperties) {
|
|
175
|
-
const validated = validateRequired(obj, fieldName);
|
|
176
|
-
for (const prop of requiredProperties) {
|
|
177
|
-
if (!(prop in validated) ||
|
|
178
|
-
validated[prop] === null ||
|
|
179
|
-
validated[prop] === undefined) {
|
|
180
|
-
throw new ValidationError(`${fieldName} must have property "${String(prop)}"`, fieldName);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return validated;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Validates array of strings
|
|
187
|
-
*/
|
|
188
|
-
function validateStringArray(value, fieldName, allowEmpty = true) {
|
|
189
|
-
const validated = validateRequired(value, fieldName);
|
|
190
|
-
if (!Array.isArray(validated)) {
|
|
191
|
-
throw new ValidationError(`${fieldName} must be an array`, fieldName);
|
|
192
|
-
}
|
|
193
|
-
if (!allowEmpty && validated.length === 0) {
|
|
194
|
-
throw new ValidationError(`${fieldName} must not be empty`, fieldName);
|
|
195
|
-
}
|
|
196
|
-
for (let i = 0; i < validated.length; i++) {
|
|
197
|
-
if (typeof validated[i] !== "string") {
|
|
198
|
-
throw new ValidationError(`${fieldName}[${i}] must be a string`, fieldName);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return validated;
|
|
202
|
-
}
|
|
203
|
-
//# sourceMappingURL=validation.js.map
|