@reverbia/sdk 1.0.0-next.20251203130707 → 1.0.0-next.20251204090034
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/react/index.cjs +166 -87
- package/dist/react/index.d.mts +12 -1
- package/dist/react/index.d.ts +12 -1
- package/dist/react/index.mjs +94 -16
- package/package.json +2 -1
package/dist/react/index.cjs
CHANGED
|
@@ -3145,33 +3145,33 @@ var require_detect_libc = __commonJS({
|
|
|
3145
3145
|
}
|
|
3146
3146
|
return null;
|
|
3147
3147
|
};
|
|
3148
|
-
var
|
|
3149
|
-
let
|
|
3148
|
+
var version3 = async () => {
|
|
3149
|
+
let version4 = null;
|
|
3150
3150
|
if (isLinux()) {
|
|
3151
|
-
|
|
3152
|
-
if (!
|
|
3153
|
-
|
|
3151
|
+
version4 = await versionFromFilesystem();
|
|
3152
|
+
if (!version4) {
|
|
3153
|
+
version4 = versionFromReport();
|
|
3154
3154
|
}
|
|
3155
|
-
if (!
|
|
3155
|
+
if (!version4) {
|
|
3156
3156
|
const out = await safeCommand();
|
|
3157
|
-
|
|
3157
|
+
version4 = versionFromCommand(out);
|
|
3158
3158
|
}
|
|
3159
3159
|
}
|
|
3160
|
-
return
|
|
3160
|
+
return version4;
|
|
3161
3161
|
};
|
|
3162
3162
|
var versionSync = () => {
|
|
3163
|
-
let
|
|
3163
|
+
let version4 = null;
|
|
3164
3164
|
if (isLinux()) {
|
|
3165
|
-
|
|
3166
|
-
if (!
|
|
3167
|
-
|
|
3165
|
+
version4 = versionFromFilesystemSync();
|
|
3166
|
+
if (!version4) {
|
|
3167
|
+
version4 = versionFromReport();
|
|
3168
3168
|
}
|
|
3169
|
-
if (!
|
|
3169
|
+
if (!version4) {
|
|
3170
3170
|
const out = safeCommandSync();
|
|
3171
|
-
|
|
3171
|
+
version4 = versionFromCommand(out);
|
|
3172
3172
|
}
|
|
3173
3173
|
}
|
|
3174
|
-
return
|
|
3174
|
+
return version4;
|
|
3175
3175
|
};
|
|
3176
3176
|
module2.exports = {
|
|
3177
3177
|
GLIBC,
|
|
@@ -3180,7 +3180,7 @@ var require_detect_libc = __commonJS({
|
|
|
3180
3180
|
familySync,
|
|
3181
3181
|
isNonGlibcLinux,
|
|
3182
3182
|
isNonGlibcLinuxSync,
|
|
3183
|
-
version:
|
|
3183
|
+
version: version3,
|
|
3184
3184
|
versionSync
|
|
3185
3185
|
};
|
|
3186
3186
|
}
|
|
@@ -3370,31 +3370,31 @@ var require_semver = __commonJS({
|
|
|
3370
3370
|
var parseOptions = require_parse_options();
|
|
3371
3371
|
var { compareIdentifiers } = require_identifiers();
|
|
3372
3372
|
var SemVer = class _SemVer {
|
|
3373
|
-
constructor(
|
|
3373
|
+
constructor(version3, options) {
|
|
3374
3374
|
options = parseOptions(options);
|
|
3375
|
-
if (
|
|
3376
|
-
if (
|
|
3377
|
-
return
|
|
3375
|
+
if (version3 instanceof _SemVer) {
|
|
3376
|
+
if (version3.loose === !!options.loose && version3.includePrerelease === !!options.includePrerelease) {
|
|
3377
|
+
return version3;
|
|
3378
3378
|
} else {
|
|
3379
|
-
|
|
3379
|
+
version3 = version3.version;
|
|
3380
3380
|
}
|
|
3381
|
-
} else if (typeof
|
|
3382
|
-
throw new TypeError(`Invalid version. Must be a string. Got type "${typeof
|
|
3381
|
+
} else if (typeof version3 !== "string") {
|
|
3382
|
+
throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version3}".`);
|
|
3383
3383
|
}
|
|
3384
|
-
if (
|
|
3384
|
+
if (version3.length > MAX_LENGTH) {
|
|
3385
3385
|
throw new TypeError(
|
|
3386
3386
|
`version is longer than ${MAX_LENGTH} characters`
|
|
3387
3387
|
);
|
|
3388
3388
|
}
|
|
3389
|
-
debug("SemVer",
|
|
3389
|
+
debug("SemVer", version3, options);
|
|
3390
3390
|
this.options = options;
|
|
3391
3391
|
this.loose = !!options.loose;
|
|
3392
3392
|
this.includePrerelease = !!options.includePrerelease;
|
|
3393
|
-
const m =
|
|
3393
|
+
const m = version3.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
|
|
3394
3394
|
if (!m) {
|
|
3395
|
-
throw new TypeError(`Invalid Version: ${
|
|
3395
|
+
throw new TypeError(`Invalid Version: ${version3}`);
|
|
3396
3396
|
}
|
|
3397
|
-
this.raw =
|
|
3397
|
+
this.raw = version3;
|
|
3398
3398
|
this.major = +m[1];
|
|
3399
3399
|
this.minor = +m[2];
|
|
3400
3400
|
this.patch = +m[3];
|
|
@@ -3644,12 +3644,12 @@ var require_parse = __commonJS({
|
|
|
3644
3644
|
"node_modules/.pnpm/semver@7.7.3/node_modules/semver/functions/parse.js"(exports2, module2) {
|
|
3645
3645
|
"use strict";
|
|
3646
3646
|
var SemVer = require_semver();
|
|
3647
|
-
var parse = (
|
|
3648
|
-
if (
|
|
3649
|
-
return
|
|
3647
|
+
var parse = (version3, options, throwErrors = false) => {
|
|
3648
|
+
if (version3 instanceof SemVer) {
|
|
3649
|
+
return version3;
|
|
3650
3650
|
}
|
|
3651
3651
|
try {
|
|
3652
|
-
return new SemVer(
|
|
3652
|
+
return new SemVer(version3, options);
|
|
3653
3653
|
} catch (er) {
|
|
3654
3654
|
if (!throwErrors) {
|
|
3655
3655
|
return null;
|
|
@@ -3668,24 +3668,24 @@ var require_coerce = __commonJS({
|
|
|
3668
3668
|
var SemVer = require_semver();
|
|
3669
3669
|
var parse = require_parse();
|
|
3670
3670
|
var { safeRe: re, t } = require_re();
|
|
3671
|
-
var coerce = (
|
|
3672
|
-
if (
|
|
3673
|
-
return
|
|
3671
|
+
var coerce = (version3, options) => {
|
|
3672
|
+
if (version3 instanceof SemVer) {
|
|
3673
|
+
return version3;
|
|
3674
3674
|
}
|
|
3675
|
-
if (typeof
|
|
3676
|
-
|
|
3675
|
+
if (typeof version3 === "number") {
|
|
3676
|
+
version3 = String(version3);
|
|
3677
3677
|
}
|
|
3678
|
-
if (typeof
|
|
3678
|
+
if (typeof version3 !== "string") {
|
|
3679
3679
|
return null;
|
|
3680
3680
|
}
|
|
3681
3681
|
options = options || {};
|
|
3682
3682
|
let match = null;
|
|
3683
3683
|
if (!options.rtl) {
|
|
3684
|
-
match =
|
|
3684
|
+
match = version3.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
|
|
3685
3685
|
} else {
|
|
3686
3686
|
const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
|
|
3687
3687
|
let next;
|
|
3688
|
-
while ((next = coerceRtlRegex.exec(
|
|
3688
|
+
while ((next = coerceRtlRegex.exec(version3)) && (!match || match.index + match[0].length !== version3.length)) {
|
|
3689
3689
|
if (!match || next.index + next[0].length !== match.index + match[0].length) {
|
|
3690
3690
|
match = next;
|
|
3691
3691
|
}
|
|
@@ -3914,19 +3914,19 @@ var require_comparator = __commonJS({
|
|
|
3914
3914
|
toString() {
|
|
3915
3915
|
return this.value;
|
|
3916
3916
|
}
|
|
3917
|
-
test(
|
|
3918
|
-
debug("Comparator.test",
|
|
3919
|
-
if (this.semver === ANY ||
|
|
3917
|
+
test(version3) {
|
|
3918
|
+
debug("Comparator.test", version3, this.options.loose);
|
|
3919
|
+
if (this.semver === ANY || version3 === ANY) {
|
|
3920
3920
|
return true;
|
|
3921
3921
|
}
|
|
3922
|
-
if (typeof
|
|
3922
|
+
if (typeof version3 === "string") {
|
|
3923
3923
|
try {
|
|
3924
|
-
|
|
3924
|
+
version3 = new SemVer(version3, this.options);
|
|
3925
3925
|
} catch (er) {
|
|
3926
3926
|
return false;
|
|
3927
3927
|
}
|
|
3928
3928
|
}
|
|
3929
|
-
return cmp(
|
|
3929
|
+
return cmp(version3, this.operator, this.semver, this.options);
|
|
3930
3930
|
}
|
|
3931
3931
|
intersects(comp, options) {
|
|
3932
3932
|
if (!(comp instanceof _Comparator)) {
|
|
@@ -4102,19 +4102,19 @@ var require_range = __commonJS({
|
|
|
4102
4102
|
});
|
|
4103
4103
|
}
|
|
4104
4104
|
// if ANY of the sets match ALL of its comparators, then pass
|
|
4105
|
-
test(
|
|
4106
|
-
if (!
|
|
4105
|
+
test(version3) {
|
|
4106
|
+
if (!version3) {
|
|
4107
4107
|
return false;
|
|
4108
4108
|
}
|
|
4109
|
-
if (typeof
|
|
4109
|
+
if (typeof version3 === "string") {
|
|
4110
4110
|
try {
|
|
4111
|
-
|
|
4111
|
+
version3 = new SemVer(version3, this.options);
|
|
4112
4112
|
} catch (er) {
|
|
4113
4113
|
return false;
|
|
4114
4114
|
}
|
|
4115
4115
|
}
|
|
4116
4116
|
for (let i = 0; i < this.set.length; i++) {
|
|
4117
|
-
if (testSet(this.set[i],
|
|
4117
|
+
if (testSet(this.set[i], version3, this.options)) {
|
|
4118
4118
|
return true;
|
|
4119
4119
|
}
|
|
4120
4120
|
}
|
|
@@ -4329,13 +4329,13 @@ var require_range = __commonJS({
|
|
|
4329
4329
|
}
|
|
4330
4330
|
return `${from} ${to}`.trim();
|
|
4331
4331
|
};
|
|
4332
|
-
var testSet = (set,
|
|
4332
|
+
var testSet = (set, version3, options) => {
|
|
4333
4333
|
for (let i = 0; i < set.length; i++) {
|
|
4334
|
-
if (!set[i].test(
|
|
4334
|
+
if (!set[i].test(version3)) {
|
|
4335
4335
|
return false;
|
|
4336
4336
|
}
|
|
4337
4337
|
}
|
|
4338
|
-
if (
|
|
4338
|
+
if (version3.prerelease.length && !options.includePrerelease) {
|
|
4339
4339
|
for (let i = 0; i < set.length; i++) {
|
|
4340
4340
|
debug(set[i].semver);
|
|
4341
4341
|
if (set[i].semver === Comparator.ANY) {
|
|
@@ -4343,7 +4343,7 @@ var require_range = __commonJS({
|
|
|
4343
4343
|
}
|
|
4344
4344
|
if (set[i].semver.prerelease.length > 0) {
|
|
4345
4345
|
const allowed = set[i].semver;
|
|
4346
|
-
if (allowed.major ===
|
|
4346
|
+
if (allowed.major === version3.major && allowed.minor === version3.minor && allowed.patch === version3.patch) {
|
|
4347
4347
|
return true;
|
|
4348
4348
|
}
|
|
4349
4349
|
}
|
|
@@ -4360,13 +4360,13 @@ var require_satisfies = __commonJS({
|
|
|
4360
4360
|
"node_modules/.pnpm/semver@7.7.3/node_modules/semver/functions/satisfies.js"(exports2, module2) {
|
|
4361
4361
|
"use strict";
|
|
4362
4362
|
var Range = require_range();
|
|
4363
|
-
var satisfies = (
|
|
4363
|
+
var satisfies = (version3, range, options) => {
|
|
4364
4364
|
try {
|
|
4365
4365
|
range = new Range(range, options);
|
|
4366
4366
|
} catch (er) {
|
|
4367
4367
|
return false;
|
|
4368
4368
|
}
|
|
4369
|
-
return range.test(
|
|
4369
|
+
return range.test(version3);
|
|
4370
4370
|
};
|
|
4371
4371
|
module2.exports = satisfies;
|
|
4372
4372
|
}
|
|
@@ -38191,9 +38191,9 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
|
|
|
38191
38191
|
);
|
|
38192
38192
|
} else if (typeof process !== "undefined" && process?.release?.name === "node") {
|
|
38193
38193
|
const IS_CI = !!process.env?.TESTING_REMOTELY;
|
|
38194
|
-
const
|
|
38194
|
+
const version3 = _env_js__WEBPACK_IMPORTED_MODULE_2__.env.version;
|
|
38195
38195
|
const headers = new Headers();
|
|
38196
|
-
headers.set("User-Agent", `transformers.js/${
|
|
38196
|
+
headers.set("User-Agent", `transformers.js/${version3}; is_ci/${IS_CI};`);
|
|
38197
38197
|
const isHFURL = isValidUrl(urlOrPath, ["http:", "https:"], ["huggingface.co", "hf.co"]);
|
|
38198
38198
|
if (isHFURL) {
|
|
38199
38199
|
const token = process.env?.HF_TOKEN ?? process.env?.HF_ACCESS_TOKEN;
|
|
@@ -46683,6 +46683,7 @@ __export(index_exports, {
|
|
|
46683
46683
|
useImageGeneration: () => useImageGeneration,
|
|
46684
46684
|
useMemory: () => useMemory,
|
|
46685
46685
|
useModels: () => useModels,
|
|
46686
|
+
usePdf: () => usePdf,
|
|
46686
46687
|
useSearch: () => useSearch
|
|
46687
46688
|
});
|
|
46688
46689
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -48831,23 +48832,100 @@ function useMemory(options = {}) {
|
|
|
48831
48832
|
};
|
|
48832
48833
|
}
|
|
48833
48834
|
|
|
48834
|
-
// src/react/
|
|
48835
|
+
// src/react/usePdf.ts
|
|
48835
48836
|
var import_react4 = require("react");
|
|
48837
|
+
|
|
48838
|
+
// src/lib/pdf.ts
|
|
48839
|
+
var pdfjs = __toESM(require("pdfjs-dist"));
|
|
48840
|
+
pdfjs.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
|
|
48841
|
+
async function extractTextFromPdf(pdfDataUrl) {
|
|
48842
|
+
try {
|
|
48843
|
+
const loadingTask = pdfjs.getDocument(pdfDataUrl);
|
|
48844
|
+
const pdf = await loadingTask.promise;
|
|
48845
|
+
const textParts = [];
|
|
48846
|
+
for (let i = 1; i <= pdf.numPages; i++) {
|
|
48847
|
+
const page = await pdf.getPage(i);
|
|
48848
|
+
const textContent = await page.getTextContent();
|
|
48849
|
+
const pageText = textContent.items.map((item) => item.str).join(" ");
|
|
48850
|
+
if (pageText.trim()) {
|
|
48851
|
+
textParts.push(pageText);
|
|
48852
|
+
}
|
|
48853
|
+
}
|
|
48854
|
+
return textParts.join("\n\n");
|
|
48855
|
+
} catch (error) {
|
|
48856
|
+
console.error("Error extracting text from PDF:", error);
|
|
48857
|
+
throw error;
|
|
48858
|
+
}
|
|
48859
|
+
}
|
|
48860
|
+
|
|
48861
|
+
// src/react/usePdf.ts
|
|
48862
|
+
var PDF_MIME_TYPE = "application/pdf";
|
|
48863
|
+
function usePdf() {
|
|
48864
|
+
const [isProcessing, setIsProcessing] = (0, import_react4.useState)(false);
|
|
48865
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
48866
|
+
const extractPdfContext = (0, import_react4.useCallback)(
|
|
48867
|
+
async (files) => {
|
|
48868
|
+
setIsProcessing(true);
|
|
48869
|
+
setError(null);
|
|
48870
|
+
try {
|
|
48871
|
+
const pdfFiles = files.filter(
|
|
48872
|
+
(file) => file.mediaType === PDF_MIME_TYPE || file.filename?.toLowerCase().endsWith(".pdf")
|
|
48873
|
+
);
|
|
48874
|
+
if (pdfFiles.length === 0) {
|
|
48875
|
+
return null;
|
|
48876
|
+
}
|
|
48877
|
+
const contexts = await Promise.all(
|
|
48878
|
+
pdfFiles.map(async (file) => {
|
|
48879
|
+
try {
|
|
48880
|
+
const text = await extractTextFromPdf(file.url);
|
|
48881
|
+
if (!text.trim()) {
|
|
48882
|
+
console.warn(`No text found in PDF ${file.filename}`);
|
|
48883
|
+
return null;
|
|
48884
|
+
}
|
|
48885
|
+
return `[Context from PDF attachment ${file.filename}]:
|
|
48886
|
+
${text}`;
|
|
48887
|
+
} catch (err) {
|
|
48888
|
+
console.error(`Failed to process PDF ${file.filename}:`, err);
|
|
48889
|
+
return null;
|
|
48890
|
+
}
|
|
48891
|
+
})
|
|
48892
|
+
);
|
|
48893
|
+
const mergedContext = contexts.filter(Boolean).join("\n\n");
|
|
48894
|
+
return mergedContext || null;
|
|
48895
|
+
} catch (err) {
|
|
48896
|
+
const processedError = err instanceof Error ? err : new Error(String(err));
|
|
48897
|
+
setError(processedError);
|
|
48898
|
+
throw processedError;
|
|
48899
|
+
} finally {
|
|
48900
|
+
setIsProcessing(false);
|
|
48901
|
+
}
|
|
48902
|
+
},
|
|
48903
|
+
[]
|
|
48904
|
+
);
|
|
48905
|
+
return {
|
|
48906
|
+
extractPdfContext,
|
|
48907
|
+
isProcessing,
|
|
48908
|
+
error
|
|
48909
|
+
};
|
|
48910
|
+
}
|
|
48911
|
+
|
|
48912
|
+
// src/react/useModels.ts
|
|
48913
|
+
var import_react5 = require("react");
|
|
48836
48914
|
function useModels(options = {}) {
|
|
48837
48915
|
const { getToken, baseUrl = BASE_URL, provider, autoFetch = true } = options;
|
|
48838
|
-
const [models, setModels] = (0,
|
|
48839
|
-
const [isLoading, setIsLoading] = (0,
|
|
48840
|
-
const [error, setError] = (0,
|
|
48841
|
-
const getTokenRef = (0,
|
|
48842
|
-
const baseUrlRef = (0,
|
|
48843
|
-
const providerRef = (0,
|
|
48844
|
-
const abortControllerRef = (0,
|
|
48845
|
-
(0,
|
|
48916
|
+
const [models, setModels] = (0, import_react5.useState)([]);
|
|
48917
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
48918
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
48919
|
+
const getTokenRef = (0, import_react5.useRef)(getToken);
|
|
48920
|
+
const baseUrlRef = (0, import_react5.useRef)(baseUrl);
|
|
48921
|
+
const providerRef = (0, import_react5.useRef)(provider);
|
|
48922
|
+
const abortControllerRef = (0, import_react5.useRef)(null);
|
|
48923
|
+
(0, import_react5.useEffect)(() => {
|
|
48846
48924
|
getTokenRef.current = getToken;
|
|
48847
48925
|
baseUrlRef.current = baseUrl;
|
|
48848
48926
|
providerRef.current = provider;
|
|
48849
48927
|
});
|
|
48850
|
-
(0,
|
|
48928
|
+
(0, import_react5.useEffect)(() => {
|
|
48851
48929
|
return () => {
|
|
48852
48930
|
if (abortControllerRef.current) {
|
|
48853
48931
|
abortControllerRef.current.abort();
|
|
@@ -48855,7 +48933,7 @@ function useModels(options = {}) {
|
|
|
48855
48933
|
}
|
|
48856
48934
|
};
|
|
48857
48935
|
}, []);
|
|
48858
|
-
const fetchModels = (0,
|
|
48936
|
+
const fetchModels = (0, import_react5.useCallback)(async () => {
|
|
48859
48937
|
if (abortControllerRef.current) {
|
|
48860
48938
|
abortControllerRef.current.abort();
|
|
48861
48939
|
}
|
|
@@ -48913,12 +48991,12 @@ function useModels(options = {}) {
|
|
|
48913
48991
|
}
|
|
48914
48992
|
}
|
|
48915
48993
|
}, []);
|
|
48916
|
-
const refetch = (0,
|
|
48994
|
+
const refetch = (0, import_react5.useCallback)(async () => {
|
|
48917
48995
|
setModels([]);
|
|
48918
48996
|
await fetchModels();
|
|
48919
48997
|
}, [fetchModels]);
|
|
48920
|
-
const hasFetchedRef = (0,
|
|
48921
|
-
(0,
|
|
48998
|
+
const hasFetchedRef = (0, import_react5.useRef)(false);
|
|
48999
|
+
(0, import_react5.useEffect)(() => {
|
|
48922
49000
|
if (autoFetch && !hasFetchedRef.current) {
|
|
48923
49001
|
hasFetchedRef.current = true;
|
|
48924
49002
|
fetchModels();
|
|
@@ -48936,15 +49014,15 @@ function useModels(options = {}) {
|
|
|
48936
49014
|
}
|
|
48937
49015
|
|
|
48938
49016
|
// src/react/useSearch.ts
|
|
48939
|
-
var
|
|
49017
|
+
var import_react6 = require("react");
|
|
48940
49018
|
function useSearch(options = {}) {
|
|
48941
49019
|
const { getToken, baseUrl = BASE_URL, onError } = options;
|
|
48942
|
-
const [isLoading, setIsLoading] = (0,
|
|
48943
|
-
const [results, setResults] = (0,
|
|
48944
|
-
const [response, setResponse] = (0,
|
|
48945
|
-
const [error, setError] = (0,
|
|
48946
|
-
const abortControllerRef = (0,
|
|
48947
|
-
(0,
|
|
49020
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
49021
|
+
const [results, setResults] = (0, import_react6.useState)(null);
|
|
49022
|
+
const [response, setResponse] = (0, import_react6.useState)(null);
|
|
49023
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
49024
|
+
const abortControllerRef = (0, import_react6.useRef)(null);
|
|
49025
|
+
(0, import_react6.useEffect)(() => {
|
|
48948
49026
|
return () => {
|
|
48949
49027
|
if (abortControllerRef.current) {
|
|
48950
49028
|
abortControllerRef.current.abort();
|
|
@@ -48952,7 +49030,7 @@ function useSearch(options = {}) {
|
|
|
48952
49030
|
}
|
|
48953
49031
|
};
|
|
48954
49032
|
}, []);
|
|
48955
|
-
const search = (0,
|
|
49033
|
+
const search = (0, import_react6.useCallback)(
|
|
48956
49034
|
async (query, searchOptions = {}) => {
|
|
48957
49035
|
if (abortControllerRef.current) {
|
|
48958
49036
|
abortControllerRef.current.abort();
|
|
@@ -49020,12 +49098,12 @@ function useSearch(options = {}) {
|
|
|
49020
49098
|
}
|
|
49021
49099
|
|
|
49022
49100
|
// src/react/useImageGeneration.ts
|
|
49023
|
-
var
|
|
49101
|
+
var import_react7 = require("react");
|
|
49024
49102
|
function useImageGeneration(options = {}) {
|
|
49025
49103
|
const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
|
|
49026
|
-
const [isLoading, setIsLoading] = (0,
|
|
49027
|
-
const abortControllerRef = (0,
|
|
49028
|
-
(0,
|
|
49104
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
|
|
49105
|
+
const abortControllerRef = (0, import_react7.useRef)(null);
|
|
49106
|
+
(0, import_react7.useEffect)(() => {
|
|
49029
49107
|
return () => {
|
|
49030
49108
|
if (abortControllerRef.current) {
|
|
49031
49109
|
abortControllerRef.current.abort();
|
|
@@ -49033,13 +49111,13 @@ function useImageGeneration(options = {}) {
|
|
|
49033
49111
|
}
|
|
49034
49112
|
};
|
|
49035
49113
|
}, []);
|
|
49036
|
-
const stop = (0,
|
|
49114
|
+
const stop = (0, import_react7.useCallback)(() => {
|
|
49037
49115
|
if (abortControllerRef.current) {
|
|
49038
49116
|
abortControllerRef.current.abort();
|
|
49039
49117
|
abortControllerRef.current = null;
|
|
49040
49118
|
}
|
|
49041
49119
|
}, []);
|
|
49042
|
-
const generateImage = (0,
|
|
49120
|
+
const generateImage = (0, import_react7.useCallback)(
|
|
49043
49121
|
async (args) => {
|
|
49044
49122
|
if (abortControllerRef.current) {
|
|
49045
49123
|
abortControllerRef.current.abort();
|
|
@@ -49171,6 +49249,7 @@ var extractConversationContext = (messages, maxMessages = 3) => {
|
|
|
49171
49249
|
useImageGeneration,
|
|
49172
49250
|
useMemory,
|
|
49173
49251
|
useModels,
|
|
49252
|
+
usePdf,
|
|
49174
49253
|
useSearch
|
|
49175
49254
|
});
|
|
49176
49255
|
/*! Bundled license information:
|
package/dist/react/index.d.mts
CHANGED
|
@@ -688,6 +688,17 @@ type UseMemoryResult = {
|
|
|
688
688
|
*/
|
|
689
689
|
declare function useMemory(options?: UseMemoryOptions): UseMemoryResult;
|
|
690
690
|
|
|
691
|
+
interface PdfFile {
|
|
692
|
+
url: string;
|
|
693
|
+
mediaType?: string;
|
|
694
|
+
filename?: string;
|
|
695
|
+
}
|
|
696
|
+
declare function usePdf(): {
|
|
697
|
+
extractPdfContext: (files: PdfFile[]) => Promise<string | null>;
|
|
698
|
+
isProcessing: boolean;
|
|
699
|
+
error: Error | null;
|
|
700
|
+
};
|
|
701
|
+
|
|
691
702
|
type UseModelsOptions = {
|
|
692
703
|
/**
|
|
693
704
|
* Custom function to get auth token for API calls
|
|
@@ -846,4 +857,4 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
|
|
|
846
857
|
error?: string;
|
|
847
858
|
}>;
|
|
848
859
|
|
|
849
|
-
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, useSearch };
|
|
860
|
+
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type PdfFile, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, usePdf, useSearch };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -688,6 +688,17 @@ type UseMemoryResult = {
|
|
|
688
688
|
*/
|
|
689
689
|
declare function useMemory(options?: UseMemoryOptions): UseMemoryResult;
|
|
690
690
|
|
|
691
|
+
interface PdfFile {
|
|
692
|
+
url: string;
|
|
693
|
+
mediaType?: string;
|
|
694
|
+
filename?: string;
|
|
695
|
+
}
|
|
696
|
+
declare function usePdf(): {
|
|
697
|
+
extractPdfContext: (files: PdfFile[]) => Promise<string | null>;
|
|
698
|
+
isProcessing: boolean;
|
|
699
|
+
error: Error | null;
|
|
700
|
+
};
|
|
701
|
+
|
|
691
702
|
type UseModelsOptions = {
|
|
692
703
|
/**
|
|
693
704
|
* Custom function to get auth token for API calls
|
|
@@ -846,4 +857,4 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
|
|
|
846
857
|
error?: string;
|
|
847
858
|
}>;
|
|
848
859
|
|
|
849
|
-
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, useSearch };
|
|
860
|
+
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type PdfFile, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, usePdf, useSearch };
|
package/dist/react/index.mjs
CHANGED
|
@@ -2144,13 +2144,90 @@ function useMemory(options = {}) {
|
|
|
2144
2144
|
};
|
|
2145
2145
|
}
|
|
2146
2146
|
|
|
2147
|
+
// src/react/usePdf.ts
|
|
2148
|
+
import { useCallback as useCallback3, useState as useState2 } from "react";
|
|
2149
|
+
|
|
2150
|
+
// src/lib/pdf.ts
|
|
2151
|
+
import * as pdfjs from "pdfjs-dist";
|
|
2152
|
+
pdfjs.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
|
|
2153
|
+
async function extractTextFromPdf(pdfDataUrl) {
|
|
2154
|
+
try {
|
|
2155
|
+
const loadingTask = pdfjs.getDocument(pdfDataUrl);
|
|
2156
|
+
const pdf = await loadingTask.promise;
|
|
2157
|
+
const textParts = [];
|
|
2158
|
+
for (let i = 1; i <= pdf.numPages; i++) {
|
|
2159
|
+
const page = await pdf.getPage(i);
|
|
2160
|
+
const textContent = await page.getTextContent();
|
|
2161
|
+
const pageText = textContent.items.map((item) => item.str).join(" ");
|
|
2162
|
+
if (pageText.trim()) {
|
|
2163
|
+
textParts.push(pageText);
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
return textParts.join("\n\n");
|
|
2167
|
+
} catch (error) {
|
|
2168
|
+
console.error("Error extracting text from PDF:", error);
|
|
2169
|
+
throw error;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
// src/react/usePdf.ts
|
|
2174
|
+
var PDF_MIME_TYPE = "application/pdf";
|
|
2175
|
+
function usePdf() {
|
|
2176
|
+
const [isProcessing, setIsProcessing] = useState2(false);
|
|
2177
|
+
const [error, setError] = useState2(null);
|
|
2178
|
+
const extractPdfContext = useCallback3(
|
|
2179
|
+
async (files) => {
|
|
2180
|
+
setIsProcessing(true);
|
|
2181
|
+
setError(null);
|
|
2182
|
+
try {
|
|
2183
|
+
const pdfFiles = files.filter(
|
|
2184
|
+
(file) => file.mediaType === PDF_MIME_TYPE || file.filename?.toLowerCase().endsWith(".pdf")
|
|
2185
|
+
);
|
|
2186
|
+
if (pdfFiles.length === 0) {
|
|
2187
|
+
return null;
|
|
2188
|
+
}
|
|
2189
|
+
const contexts = await Promise.all(
|
|
2190
|
+
pdfFiles.map(async (file) => {
|
|
2191
|
+
try {
|
|
2192
|
+
const text = await extractTextFromPdf(file.url);
|
|
2193
|
+
if (!text.trim()) {
|
|
2194
|
+
console.warn(`No text found in PDF ${file.filename}`);
|
|
2195
|
+
return null;
|
|
2196
|
+
}
|
|
2197
|
+
return `[Context from PDF attachment ${file.filename}]:
|
|
2198
|
+
${text}`;
|
|
2199
|
+
} catch (err) {
|
|
2200
|
+
console.error(`Failed to process PDF ${file.filename}:`, err);
|
|
2201
|
+
return null;
|
|
2202
|
+
}
|
|
2203
|
+
})
|
|
2204
|
+
);
|
|
2205
|
+
const mergedContext = contexts.filter(Boolean).join("\n\n");
|
|
2206
|
+
return mergedContext || null;
|
|
2207
|
+
} catch (err) {
|
|
2208
|
+
const processedError = err instanceof Error ? err : new Error(String(err));
|
|
2209
|
+
setError(processedError);
|
|
2210
|
+
throw processedError;
|
|
2211
|
+
} finally {
|
|
2212
|
+
setIsProcessing(false);
|
|
2213
|
+
}
|
|
2214
|
+
},
|
|
2215
|
+
[]
|
|
2216
|
+
);
|
|
2217
|
+
return {
|
|
2218
|
+
extractPdfContext,
|
|
2219
|
+
isProcessing,
|
|
2220
|
+
error
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2147
2224
|
// src/react/useModels.ts
|
|
2148
|
-
import { useCallback as
|
|
2225
|
+
import { useCallback as useCallback4, useEffect as useEffect3, useRef as useRef4, useState as useState3 } from "react";
|
|
2149
2226
|
function useModels(options = {}) {
|
|
2150
2227
|
const { getToken, baseUrl = BASE_URL, provider, autoFetch = true } = options;
|
|
2151
|
-
const [models, setModels] =
|
|
2152
|
-
const [isLoading, setIsLoading] =
|
|
2153
|
-
const [error, setError] =
|
|
2228
|
+
const [models, setModels] = useState3([]);
|
|
2229
|
+
const [isLoading, setIsLoading] = useState3(false);
|
|
2230
|
+
const [error, setError] = useState3(null);
|
|
2154
2231
|
const getTokenRef = useRef4(getToken);
|
|
2155
2232
|
const baseUrlRef = useRef4(baseUrl);
|
|
2156
2233
|
const providerRef = useRef4(provider);
|
|
@@ -2168,7 +2245,7 @@ function useModels(options = {}) {
|
|
|
2168
2245
|
}
|
|
2169
2246
|
};
|
|
2170
2247
|
}, []);
|
|
2171
|
-
const fetchModels =
|
|
2248
|
+
const fetchModels = useCallback4(async () => {
|
|
2172
2249
|
if (abortControllerRef.current) {
|
|
2173
2250
|
abortControllerRef.current.abort();
|
|
2174
2251
|
}
|
|
@@ -2226,7 +2303,7 @@ function useModels(options = {}) {
|
|
|
2226
2303
|
}
|
|
2227
2304
|
}
|
|
2228
2305
|
}, []);
|
|
2229
|
-
const refetch =
|
|
2306
|
+
const refetch = useCallback4(async () => {
|
|
2230
2307
|
setModels([]);
|
|
2231
2308
|
await fetchModels();
|
|
2232
2309
|
}, [fetchModels]);
|
|
@@ -2249,13 +2326,13 @@ function useModels(options = {}) {
|
|
|
2249
2326
|
}
|
|
2250
2327
|
|
|
2251
2328
|
// src/react/useSearch.ts
|
|
2252
|
-
import { useCallback as
|
|
2329
|
+
import { useCallback as useCallback5, useEffect as useEffect4, useRef as useRef5, useState as useState4 } from "react";
|
|
2253
2330
|
function useSearch(options = {}) {
|
|
2254
2331
|
const { getToken, baseUrl = BASE_URL, onError } = options;
|
|
2255
|
-
const [isLoading, setIsLoading] =
|
|
2256
|
-
const [results, setResults] =
|
|
2257
|
-
const [response, setResponse] =
|
|
2258
|
-
const [error, setError] =
|
|
2332
|
+
const [isLoading, setIsLoading] = useState4(false);
|
|
2333
|
+
const [results, setResults] = useState4(null);
|
|
2334
|
+
const [response, setResponse] = useState4(null);
|
|
2335
|
+
const [error, setError] = useState4(null);
|
|
2259
2336
|
const abortControllerRef = useRef5(null);
|
|
2260
2337
|
useEffect4(() => {
|
|
2261
2338
|
return () => {
|
|
@@ -2265,7 +2342,7 @@ function useSearch(options = {}) {
|
|
|
2265
2342
|
}
|
|
2266
2343
|
};
|
|
2267
2344
|
}, []);
|
|
2268
|
-
const search =
|
|
2345
|
+
const search = useCallback5(
|
|
2269
2346
|
async (query, searchOptions = {}) => {
|
|
2270
2347
|
if (abortControllerRef.current) {
|
|
2271
2348
|
abortControllerRef.current.abort();
|
|
@@ -2333,10 +2410,10 @@ function useSearch(options = {}) {
|
|
|
2333
2410
|
}
|
|
2334
2411
|
|
|
2335
2412
|
// src/react/useImageGeneration.ts
|
|
2336
|
-
import { useCallback as
|
|
2413
|
+
import { useCallback as useCallback6, useEffect as useEffect5, useRef as useRef6, useState as useState5 } from "react";
|
|
2337
2414
|
function useImageGeneration(options = {}) {
|
|
2338
2415
|
const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
|
|
2339
|
-
const [isLoading, setIsLoading] =
|
|
2416
|
+
const [isLoading, setIsLoading] = useState5(false);
|
|
2340
2417
|
const abortControllerRef = useRef6(null);
|
|
2341
2418
|
useEffect5(() => {
|
|
2342
2419
|
return () => {
|
|
@@ -2346,13 +2423,13 @@ function useImageGeneration(options = {}) {
|
|
|
2346
2423
|
}
|
|
2347
2424
|
};
|
|
2348
2425
|
}, []);
|
|
2349
|
-
const stop =
|
|
2426
|
+
const stop = useCallback6(() => {
|
|
2350
2427
|
if (abortControllerRef.current) {
|
|
2351
2428
|
abortControllerRef.current.abort();
|
|
2352
2429
|
abortControllerRef.current = null;
|
|
2353
2430
|
}
|
|
2354
2431
|
}, []);
|
|
2355
|
-
const generateImage =
|
|
2432
|
+
const generateImage = useCallback6(
|
|
2356
2433
|
async (args) => {
|
|
2357
2434
|
if (abortControllerRef.current) {
|
|
2358
2435
|
abortControllerRef.current.abort();
|
|
@@ -2483,5 +2560,6 @@ export {
|
|
|
2483
2560
|
useImageGeneration,
|
|
2484
2561
|
useMemory,
|
|
2485
2562
|
useModels,
|
|
2563
|
+
usePdf,
|
|
2486
2564
|
useSearch
|
|
2487
2565
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reverbia/sdk",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.20251204090034",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"homepage": "https://github.com/zeta-chain/ai-sdk#readme",
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@huggingface/transformers": "^3.8.0",
|
|
60
|
+
"pdfjs-dist": "^4.10.38",
|
|
60
61
|
"@reverbia/portal": "1.0.0-next.20251202220311",
|
|
61
62
|
"ai": "5.0.93"
|
|
62
63
|
},
|