@umituz/web-ai 1.0.4 → 1.0.6
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/content/index.cjs +205 -7
- package/dist/content/index.cjs.map +1 -1
- package/dist/content/index.d.cts +1 -1
- package/dist/content/index.d.ts +1 -1
- package/dist/content/index.js +199 -8
- package/dist/content/index.js.map +1 -1
- package/dist/core/index.cjs +15 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +4 -3
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +15 -2
- package/dist/core/index.js.map +1 -1
- package/dist/hooks/index.cjs +64 -8
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +12 -2
- package/dist/hooks/index.d.ts +12 -2
- package/dist/hooks/index.js +64 -8
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +93 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +87 -7
- package/dist/index.js.map +1 -1
- package/dist/{PromptBuilder-DIUZlfV6.d.cts → requestQueue-CkJ6Xc9K.d.cts} +48 -2
- package/dist/{PromptBuilder-B5Lm1znm.d.ts → requestQueue-CvxWxC-z.d.ts} +48 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -998,9 +998,22 @@ var SSE_BRIDGE_EVENTS = {
|
|
|
998
998
|
done: "done",
|
|
999
999
|
error: "error"
|
|
1000
1000
|
};
|
|
1001
|
+
function defaultSseDeltaExtractor(payload) {
|
|
1002
|
+
try {
|
|
1003
|
+
const parsed = JSON.parse(payload);
|
|
1004
|
+
const content = parsed.choices?.[0]?.delta?.content;
|
|
1005
|
+
if (typeof content === "string" && content.length > 0) return content;
|
|
1006
|
+
if (typeof parsed.delta?.text === "string" && parsed.delta.text.length > 0) return parsed.delta.text;
|
|
1007
|
+
if (typeof parsed.text === "string" && parsed.text.length > 0) return parsed.text;
|
|
1008
|
+
return null;
|
|
1009
|
+
} catch {
|
|
1010
|
+
return null;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1001
1013
|
function createSseResponse(openUpstream, options) {
|
|
1002
1014
|
const encoder = new TextEncoder();
|
|
1003
1015
|
const decoder = new TextDecoder();
|
|
1016
|
+
const extractDelta = options.extractDelta ?? defaultSseDeltaExtractor;
|
|
1004
1017
|
const stream = new ReadableStream({
|
|
1005
1018
|
async start(controller) {
|
|
1006
1019
|
let closed = false;
|
|
@@ -1032,7 +1045,7 @@ data: ${JSON.stringify(data)}
|
|
|
1032
1045
|
if (!isSseDataLine(trimmed)) return false;
|
|
1033
1046
|
const payload = extractSseDataPayload(trimmed);
|
|
1034
1047
|
if (isSseDoneMarker(payload)) return true;
|
|
1035
|
-
const text =
|
|
1048
|
+
const text = extractDelta(payload);
|
|
1036
1049
|
if (text) {
|
|
1037
1050
|
delivered = true;
|
|
1038
1051
|
emit(SSE_BRIDGE_EVENTS.delta, { text });
|
|
@@ -5111,6 +5124,15 @@ var BlogService = class {
|
|
|
5111
5124
|
};
|
|
5112
5125
|
}
|
|
5113
5126
|
};
|
|
5127
|
+
|
|
5128
|
+
// src/content/infrastructure/utils/requestQueue.ts
|
|
5129
|
+
var RequestPriority = /* @__PURE__ */ ((RequestPriority2) => {
|
|
5130
|
+
RequestPriority2[RequestPriority2["LOW"] = 0] = "LOW";
|
|
5131
|
+
RequestPriority2[RequestPriority2["NORMAL"] = 1] = "NORMAL";
|
|
5132
|
+
RequestPriority2[RequestPriority2["HIGH"] = 2] = "HIGH";
|
|
5133
|
+
RequestPriority2[RequestPriority2["URGENT"] = 3] = "URGENT";
|
|
5134
|
+
return RequestPriority2;
|
|
5135
|
+
})(RequestPriority || {});
|
|
5114
5136
|
async function batchRequest(requests, options = {}) {
|
|
5115
5137
|
const {
|
|
5116
5138
|
concurrency = 3,
|
|
@@ -5594,7 +5616,10 @@ function safeJSONParse(text, fallback, onError) {
|
|
|
5594
5616
|
const positionMatch = error.message.match(/position (\d+)/);
|
|
5595
5617
|
const position = positionMatch ? parseInt(positionMatch[1], 10) : -1;
|
|
5596
5618
|
if (position > 0) {
|
|
5597
|
-
text.substring(Math.max(0, position - 50), position + 50);
|
|
5619
|
+
const context = text.substring(Math.max(0, position - 50), position + 50);
|
|
5620
|
+
onError?.(`JSON parse error at position ${position}: "${context}"`);
|
|
5621
|
+
} else {
|
|
5622
|
+
onError?.(`JSON parse error: ${error.message}`);
|
|
5598
5623
|
}
|
|
5599
5624
|
}
|
|
5600
5625
|
return fallback;
|
|
@@ -5621,9 +5646,23 @@ function extractJSON(text) {
|
|
|
5621
5646
|
function parseAIResponse(response, fallback, onError) {
|
|
5622
5647
|
const json = extractJSON(response);
|
|
5623
5648
|
if (!json) {
|
|
5649
|
+
onError?.("No JSON payload found in response");
|
|
5624
5650
|
return fallback;
|
|
5625
5651
|
}
|
|
5626
|
-
return safeJSONParse(json, fallback);
|
|
5652
|
+
return safeJSONParse(json, fallback, onError);
|
|
5653
|
+
}
|
|
5654
|
+
function isValidJSON(text) {
|
|
5655
|
+
const trimmed = text.trim();
|
|
5656
|
+
if (trimmed.length === 0) return false;
|
|
5657
|
+
if (!(trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]"))) {
|
|
5658
|
+
return false;
|
|
5659
|
+
}
|
|
5660
|
+
try {
|
|
5661
|
+
JSON.parse(trimmed);
|
|
5662
|
+
return true;
|
|
5663
|
+
} catch {
|
|
5664
|
+
return false;
|
|
5665
|
+
}
|
|
5627
5666
|
}
|
|
5628
5667
|
|
|
5629
5668
|
// src/content/application/services/GenerationExecutor.ts
|
|
@@ -5684,7 +5723,48 @@ function toAIProviderConfig(config) {
|
|
|
5684
5723
|
...pruna ? { pruna } : {}
|
|
5685
5724
|
};
|
|
5686
5725
|
}
|
|
5687
|
-
var buildServices = (configOrGenerator) => {
|
|
5726
|
+
var buildServices = (configOrGenerator, model, customGenerator) => {
|
|
5727
|
+
if (customGenerator) {
|
|
5728
|
+
const executor2 = new GenerationExecutor(customGenerator);
|
|
5729
|
+
const emptyFactory = new ProviderFactory({
|
|
5730
|
+
priority: [],
|
|
5731
|
+
fallbackEnabled: false
|
|
5732
|
+
});
|
|
5733
|
+
return {
|
|
5734
|
+
providerFactory: emptyFactory,
|
|
5735
|
+
blogService: new BlogService(executor2),
|
|
5736
|
+
socialService: new SocialService(executor2),
|
|
5737
|
+
videoScriptService: new VideoScriptService(executor2),
|
|
5738
|
+
analysisService: new AnalysisService(executor2),
|
|
5739
|
+
seoService: new SeoService(executor2),
|
|
5740
|
+
abTestService: new ABTestService(executor2),
|
|
5741
|
+
imagePromptService: new ImagePromptService(executor2),
|
|
5742
|
+
contentCalendarService: new ContentCalendarService(executor2),
|
|
5743
|
+
mediaGenerationService: new MediaGenerationService(emptyFactory)
|
|
5744
|
+
};
|
|
5745
|
+
}
|
|
5746
|
+
if (typeof configOrGenerator === "string") {
|
|
5747
|
+
const aiConfig = {
|
|
5748
|
+
anthropic: {
|
|
5749
|
+
apiKey: configOrGenerator,
|
|
5750
|
+
...model ? { models: { balanced: model } } : {}
|
|
5751
|
+
}
|
|
5752
|
+
};
|
|
5753
|
+
const factory2 = createAI(aiConfig);
|
|
5754
|
+
const executor2 = new GenerationExecutor(factory2);
|
|
5755
|
+
return {
|
|
5756
|
+
providerFactory: factory2,
|
|
5757
|
+
blogService: new BlogService(executor2),
|
|
5758
|
+
socialService: new SocialService(executor2),
|
|
5759
|
+
videoScriptService: new VideoScriptService(executor2),
|
|
5760
|
+
analysisService: new AnalysisService(executor2),
|
|
5761
|
+
seoService: new SeoService(executor2),
|
|
5762
|
+
abTestService: new ABTestService(executor2),
|
|
5763
|
+
imagePromptService: new ImagePromptService(executor2),
|
|
5764
|
+
contentCalendarService: new ContentCalendarService(executor2),
|
|
5765
|
+
mediaGenerationService: new MediaGenerationService(factory2)
|
|
5766
|
+
};
|
|
5767
|
+
}
|
|
5688
5768
|
if (isTextGenerator(configOrGenerator)) {
|
|
5689
5769
|
const executor2 = new GenerationExecutor(configOrGenerator);
|
|
5690
5770
|
const emptyFactory = new ProviderFactory({
|
|
@@ -5730,8 +5810,8 @@ var AIContentService = class {
|
|
|
5730
5810
|
imagePromptService;
|
|
5731
5811
|
contentCalendarService;
|
|
5732
5812
|
mediaGenerationService;
|
|
5733
|
-
constructor(configOrGenerator) {
|
|
5734
|
-
const bundle = buildServices(configOrGenerator);
|
|
5813
|
+
constructor(configOrGenerator, model, textGenerator) {
|
|
5814
|
+
const bundle = buildServices(configOrGenerator, model, textGenerator);
|
|
5735
5815
|
this.providerFactory = bundle.providerFactory;
|
|
5736
5816
|
this.blogService = bundle.blogService;
|
|
5737
5817
|
this.socialService = bundle.socialService;
|
|
@@ -6104,6 +6184,7 @@ exports.ProviderUnavailableError = ProviderUnavailableError;
|
|
|
6104
6184
|
exports.PrunaProvider = PrunaProvider;
|
|
6105
6185
|
exports.QueueExecutor = QueueExecutor;
|
|
6106
6186
|
exports.RequestDeduplicator = RequestDeduplicator;
|
|
6187
|
+
exports.RequestPriority = RequestPriority;
|
|
6107
6188
|
exports.RequestQueue = RequestQueue;
|
|
6108
6189
|
exports.RetryExecutor = RetryExecutor;
|
|
6109
6190
|
exports.RetryManager = RetryManager;
|
|
@@ -6132,6 +6213,7 @@ exports.asObjectArray = asObjectArray;
|
|
|
6132
6213
|
exports.asRecord = asRecord;
|
|
6133
6214
|
exports.asStringArray = asStringArray;
|
|
6134
6215
|
exports.asTrimmedOptionalString = asTrimmedOptionalString;
|
|
6216
|
+
exports.batchRequest = batchRequest;
|
|
6135
6217
|
exports.buildCacheKey = buildCacheKey;
|
|
6136
6218
|
exports.buildContentRequest = buildContentRequest;
|
|
6137
6219
|
exports.buildHttpStatusFallback = buildHttpStatusFallback;
|
|
@@ -6159,10 +6241,12 @@ exports.createUserMessage = createUserMessage;
|
|
|
6159
6241
|
exports.debounce = debounce;
|
|
6160
6242
|
exports.debounceManager = debounceManager;
|
|
6161
6243
|
exports.defaultEffortForModel = defaultEffortForModel;
|
|
6244
|
+
exports.defaultSseDeltaExtractor = defaultSseDeltaExtractor;
|
|
6162
6245
|
exports.describeAIErrorType = describeAIErrorType;
|
|
6163
6246
|
exports.extractContentFromSsePayload = extractContentFromSsePayload;
|
|
6164
6247
|
exports.extractErrorMessageFromJsonBody = extractErrorMessageFromJsonBody;
|
|
6165
6248
|
exports.extractErrorMessageFromResponse = extractErrorMessageFromResponse;
|
|
6249
|
+
exports.extractJSON = extractJSON;
|
|
6166
6250
|
exports.extractJsonArray = extractJsonArray;
|
|
6167
6251
|
exports.extractJsonCandidate = extractJsonCandidate;
|
|
6168
6252
|
exports.extractJsonFromCodeFence = extractJsonFromCodeFence;
|
|
@@ -6186,11 +6270,13 @@ exports.isSseDoneMarker = isSseDoneMarker;
|
|
|
6186
6270
|
exports.isTextProvider = isTextProvider;
|
|
6187
6271
|
exports.isTextTier = isTextTier;
|
|
6188
6272
|
exports.isValidApiKey = isValidApiKey;
|
|
6273
|
+
exports.isValidJSON = isValidJSON;
|
|
6189
6274
|
exports.mapAnthropicStopReason = mapAnthropicStopReason;
|
|
6190
6275
|
exports.mergeTierOverrides = mergeTierOverrides;
|
|
6191
6276
|
exports.messageFormatter = messageFormatter;
|
|
6192
6277
|
exports.normalizeSseChunk = normalizeSseChunk;
|
|
6193
6278
|
exports.oneOfCatalog = oneOfCatalog;
|
|
6279
|
+
exports.parseAIResponse = parseAIResponse;
|
|
6194
6280
|
exports.pollForResult = pollForResult;
|
|
6195
6281
|
exports.promptToMessages = promptToMessages;
|
|
6196
6282
|
exports.repairCommonJsonDefects = repairCommonJsonDefects;
|
|
@@ -6202,6 +6288,7 @@ exports.resolveModel = resolveModel;
|
|
|
6202
6288
|
exports.resolveUserFriendlyErrorMessage = resolveUserFriendlyErrorMessage;
|
|
6203
6289
|
exports.resolveUserFriendlyMessage = resolveUserFriendlyMessage;
|
|
6204
6290
|
exports.retryManager = retryManager;
|
|
6291
|
+
exports.safeJSONParse = safeJSONParse;
|
|
6205
6292
|
exports.splitSseLines = splitSseLines;
|
|
6206
6293
|
exports.submitPrediction = submitPrediction;
|
|
6207
6294
|
exports.throttle = throttle;
|