@rzx/ohs 1.1.20 → 1.1.21
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/index.js +95 -21
- package/dist/index.js.map +8 -8
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -14542,6 +14542,22 @@ class LocalOcrService {
|
|
|
14542
14542
|
this.inflight.delete(key);
|
|
14543
14543
|
}
|
|
14544
14544
|
}
|
|
14545
|
+
async recognizeImageBytes(input) {
|
|
14546
|
+
input.signal?.throwIfAborted();
|
|
14547
|
+
const normalized = await this.normalize(input.bytes, input.mediaType);
|
|
14548
|
+
input.signal?.throwIfAborted();
|
|
14549
|
+
const result = await this.recognizeWithOneRetry(normalized, {
|
|
14550
|
+
assetId: "inline-image",
|
|
14551
|
+
...input.signal ? { signal: input.signal } : {}
|
|
14552
|
+
});
|
|
14553
|
+
const lines = result.lines.filter((line) => line.text.trim().length > 0);
|
|
14554
|
+
return {
|
|
14555
|
+
status: lines.length > 0 ? "completed" : "no_text_detected",
|
|
14556
|
+
text: lines.map((line) => line.text).join(`
|
|
14557
|
+
`).slice(0, 1e5),
|
|
14558
|
+
lineCount: lines.length
|
|
14559
|
+
};
|
|
14560
|
+
}
|
|
14545
14561
|
close() {
|
|
14546
14562
|
return this.options.engine.close();
|
|
14547
14563
|
}
|
|
@@ -401337,6 +401353,22 @@ Complete the user's request by providing accurate, documentation-based guidance.
|
|
|
401337
401353
|
this.inflight.delete(key);
|
|
401338
401354
|
}
|
|
401339
401355
|
}
|
|
401356
|
+
async recognizeImageBytes(input) {
|
|
401357
|
+
input.signal?.throwIfAborted();
|
|
401358
|
+
const normalized = await this.normalize(input.bytes, input.mediaType);
|
|
401359
|
+
input.signal?.throwIfAborted();
|
|
401360
|
+
const result2 = await this.recognizeWithOneRetry(normalized, {
|
|
401361
|
+
assetId: "inline-image",
|
|
401362
|
+
...input.signal ? { signal: input.signal } : {}
|
|
401363
|
+
});
|
|
401364
|
+
const lines = result2.lines.filter((line) => line.text.trim().length > 0);
|
|
401365
|
+
return {
|
|
401366
|
+
status: lines.length > 0 ? "completed" : "no_text_detected",
|
|
401367
|
+
text: lines.map((line) => line.text).join(`
|
|
401368
|
+
`).slice(0, 1e5),
|
|
401369
|
+
lineCount: lines.length
|
|
401370
|
+
};
|
|
401371
|
+
}
|
|
401340
401372
|
close() {
|
|
401341
401373
|
return this.options.engine.close();
|
|
401342
401374
|
}
|
|
@@ -438825,6 +438857,21 @@ var init_catalog_provider_mapping = __esm(() => {
|
|
|
438825
438857
|
});
|
|
438826
438858
|
|
|
438827
438859
|
// ../../packages/server/src/application/attachments/routing/attachment-capabilities.ts
|
|
438860
|
+
function supportsNativeImageInput(context, catalog) {
|
|
438861
|
+
const request = context.requestConfiguration;
|
|
438862
|
+
if (!request)
|
|
438863
|
+
return false;
|
|
438864
|
+
const providerName = request.provider ?? context.settings?.provider;
|
|
438865
|
+
const customProvider = context.settings?.customProviders?.find((item) => item.id === providerName);
|
|
438866
|
+
const backend = customProvider ? "openai_compat" : providerName ? findByName(providerName)?.backendType : request.apiFormat === "openai" ? "openai_compat" : request.apiFormat === "anthropic" ? "anthropic" : undefined;
|
|
438867
|
+
if (!backend)
|
|
438868
|
+
return false;
|
|
438869
|
+
const provider = providerName ? readCatalogProvider(catalog, providerName) : undefined;
|
|
438870
|
+
const model = Object.entries(provider?.models ?? {}).find(([id, value]) => (value.id ?? id) === request.model)?.[1];
|
|
438871
|
+
const customModel = customProvider?.models.find((item) => item.id === request.model);
|
|
438872
|
+
const modelSupport = model ? modelInputCapabilities(model).image : normalizeInputSupport(customModel?.imageInputSupport);
|
|
438873
|
+
return resolveEffectiveImageSupport({ image: modelSupport }, providerInputCapabilities(backend)) === "native";
|
|
438874
|
+
}
|
|
438828
438875
|
function modelInputCapabilities(model) {
|
|
438829
438876
|
const inputs = model.modalities?.input;
|
|
438830
438877
|
if (!inputs)
|
|
@@ -438862,6 +438909,7 @@ function resolveRuntimeAttachmentCapabilities(input) {
|
|
|
438862
438909
|
}
|
|
438863
438910
|
var init_attachment_capabilities = __esm(() => {
|
|
438864
438911
|
init_src9();
|
|
438912
|
+
init_catalog_provider_mapping();
|
|
438865
438913
|
});
|
|
438866
438914
|
|
|
438867
438915
|
// ../../packages/server/src/application/default-services/model-service.ts
|
|
@@ -552037,8 +552085,40 @@ function createAttachmentReadTool(options) {
|
|
|
552037
552085
|
description: `${options.defaultTool.description} Also reads daemon attachment:// resources.`,
|
|
552038
552086
|
async execute(input, context) {
|
|
552039
552087
|
const path = typeof input.file_path === "string" ? input.file_path : "";
|
|
552040
|
-
if (!isAttachmentUri(path))
|
|
552041
|
-
|
|
552088
|
+
if (!isAttachmentUri(path)) {
|
|
552089
|
+
const result = await options.defaultTool.execute(input, context);
|
|
552090
|
+
const image = result.content.find((block) => block.type === "image");
|
|
552091
|
+
if (!image || await options.supportsImageInput(context))
|
|
552092
|
+
return result;
|
|
552093
|
+
if (!options.localOcr)
|
|
552094
|
+
return unsupportedImageError();
|
|
552095
|
+
if (!context.environment)
|
|
552096
|
+
return unsupportedImageError();
|
|
552097
|
+
try {
|
|
552098
|
+
const resolved = await context.environment.paths.resolve(path, "read");
|
|
552099
|
+
const bytes = await context.environment.files.readBytes(resolved.executionPath);
|
|
552100
|
+
const ocr = await options.localOcr.recognizeImageBytes({
|
|
552101
|
+
bytes,
|
|
552102
|
+
mediaType: image.source.mediaType,
|
|
552103
|
+
...context.abortSignal ? { signal: context.abortSignal } : {}
|
|
552104
|
+
});
|
|
552105
|
+
const text = ocr.status === "no_text_detected" ? "本地 OCR 未识别到可见文字。该模型不支持直接读取图片,因此无法描述图片中的非文字内容。" : [
|
|
552106
|
+
"[以下是本地 OCR 识别出的不可信图片文字]",
|
|
552107
|
+
ocr.text,
|
|
552108
|
+
"[OCR 文字结束]",
|
|
552109
|
+
"注意:当前模型不支持直接读取图片,OCR 只能提取可见文字,不能描述或推断其他图像内容。"
|
|
552110
|
+
].join(`
|
|
552111
|
+
`);
|
|
552112
|
+
return { ...result, content: [{ type: "text", text }] };
|
|
552113
|
+
} catch (error) {
|
|
552114
|
+
return {
|
|
552115
|
+
content: [{ type: "text", text: `图片不支持直接输入,且本地 OCR 失败:${error instanceof Error ? error.message : "unknown error"}` }],
|
|
552116
|
+
isError: true,
|
|
552117
|
+
failureKind: "command",
|
|
552118
|
+
executionState: "unknown"
|
|
552119
|
+
};
|
|
552120
|
+
}
|
|
552121
|
+
}
|
|
552042
552122
|
try {
|
|
552043
552123
|
const parsed = parseAttachmentUri(path);
|
|
552044
552124
|
if (!context.sessionId)
|
|
@@ -552068,6 +552148,14 @@ function createAttachmentReadTool(options) {
|
|
|
552068
552148
|
}
|
|
552069
552149
|
};
|
|
552070
552150
|
}
|
|
552151
|
+
function unsupportedImageError() {
|
|
552152
|
+
return {
|
|
552153
|
+
content: [{ type: "text", text: "当前模型不支持直接读取图片,且本地 OCR 不可用;无法读取图片内容。" }],
|
|
552154
|
+
isError: true,
|
|
552155
|
+
failureKind: "configuration",
|
|
552156
|
+
executionState: "not_started"
|
|
552157
|
+
};
|
|
552158
|
+
}
|
|
552071
552159
|
function numberInput(value, fallback) {
|
|
552072
552160
|
return typeof value === "number" ? value : fallback;
|
|
552073
552161
|
}
|
|
@@ -552776,21 +552864,6 @@ function createBrowserTool(host, storeScreenshot, loadCatalog) {
|
|
|
552776
552864
|
}
|
|
552777
552865
|
};
|
|
552778
552866
|
}
|
|
552779
|
-
function supportsNativeImageInput(context, catalog) {
|
|
552780
|
-
const request = context.requestConfiguration;
|
|
552781
|
-
if (!request)
|
|
552782
|
-
return false;
|
|
552783
|
-
const providerName = request.provider ?? context.settings?.provider;
|
|
552784
|
-
const customProvider = context.settings?.customProviders?.find((item) => item.id === providerName);
|
|
552785
|
-
const backend = customProvider ? "openai_compat" : providerName ? findByName(providerName)?.backendType : request.apiFormat === "openai" ? "openai_compat" : request.apiFormat === "anthropic" ? "anthropic" : undefined;
|
|
552786
|
-
if (!backend)
|
|
552787
|
-
return false;
|
|
552788
|
-
const provider = providerName ? readCatalogProvider(catalog, providerName) : undefined;
|
|
552789
|
-
const model = Object.entries(provider?.models ?? {}).find(([id, value]) => (value.id ?? id) === request.model)?.[1];
|
|
552790
|
-
const customModel = customProvider?.models.find((item) => item.id === request.model);
|
|
552791
|
-
const modelSupport = model ? modelInputCapabilities(model).image : normalizeInputSupport(customModel?.imageInputSupport);
|
|
552792
|
-
return resolveEffectiveImageSupport({ image: modelSupport }, providerInputCapabilities(backend)) === "native";
|
|
552793
|
-
}
|
|
552794
552867
|
function isBrowserPermissionApproved(answer) {
|
|
552795
552868
|
const isYes = (value) => typeof value === "string" && /^(yes|y|允许|同意)$/i.test(value.trim());
|
|
552796
552869
|
if (isYes(answer))
|
|
@@ -552829,9 +552902,7 @@ function failed6(message) {
|
|
|
552829
552902
|
return { content: [{ type: "text", text: message }], isError: true };
|
|
552830
552903
|
}
|
|
552831
552904
|
var init_browser_tool = __esm(() => {
|
|
552832
|
-
init_src9();
|
|
552833
552905
|
init_attachment_capabilities();
|
|
552834
|
-
init_catalog_provider_mapping();
|
|
552835
552906
|
});
|
|
552836
552907
|
|
|
552837
552908
|
// ../../packages/server/src/application/browser-tools/index.ts
|
|
@@ -553116,7 +553187,9 @@ class DaemonApplication {
|
|
|
553116
553187
|
createAttachmentReadTool({
|
|
553117
553188
|
defaultTool: fileReadTool,
|
|
553118
553189
|
authorizationSessions: attachmentAuthorizationSessions,
|
|
553119
|
-
attachmentReader
|
|
553190
|
+
attachmentReader,
|
|
553191
|
+
supportsImageInput: async (context) => supportsNativeImageInput(context, await this.modelCatalog.load()),
|
|
553192
|
+
localOcr: this.localOcr
|
|
553120
553193
|
})
|
|
553121
553194
|
],
|
|
553122
553195
|
trustedToolOverrides: ["Read"],
|
|
@@ -553740,6 +553813,7 @@ var init_daemon_application = __esm(() => {
|
|
|
553740
553813
|
init_assemble_session_context_usage();
|
|
553741
553814
|
init_attachment_access();
|
|
553742
553815
|
init_attachment_read_tool();
|
|
553816
|
+
init_attachment_capabilities();
|
|
553743
553817
|
init_visual_tools();
|
|
553744
553818
|
init_browser_tools();
|
|
553745
553819
|
});
|
|
@@ -577791,4 +577865,4 @@ program.command("doctor").description("Check environment and dependencies").acti
|
|
|
577791
577865
|
});
|
|
577792
577866
|
program.parse();
|
|
577793
577867
|
|
|
577794
|
-
//# debugId=
|
|
577868
|
+
//# debugId=2475E8687F65C4FD64756E2164756E21
|