@arnilo/prism-tools 0.0.0-stage → 0.13.1
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/CHANGELOG.md +418 -0
- package/LICENSE +21 -0
- package/README.md +44 -2
- package/browser/README.md +98 -0
- package/browser/skills/browser-automation/SKILL.md +14 -0
- package/browser/src/actions/cdp.ts +131 -0
- package/browser/src/actions/dialog.ts +25 -0
- package/browser/src/actions/download_release.ts +22 -0
- package/browser/src/actions/index.ts +37 -0
- package/browser/src/actions/locator.ts +70 -0
- package/browser/src/actions/navigate.ts +23 -0
- package/browser/src/actions/screenshot.ts +27 -0
- package/browser/src/actions/scroll.ts +24 -0
- package/browser/src/actions/select_page.ts +21 -0
- package/browser/src/actions/types.ts +114 -0
- package/browser/src/actions/upload.ts +44 -0
- package/browser/src/actions/wait.ts +45 -0
- package/browser/src/browser.ts +197 -0
- package/browser/src/cdp.ts +178 -0
- package/browser/src/checkpoint.ts +189 -0
- package/browser/src/config.ts +72 -0
- package/browser/src/downloads.ts +253 -0
- package/browser/src/errors.ts +31 -0
- package/browser/src/evaluate.ts +101 -0
- package/browser/src/index.ts +129 -0
- package/browser/src/limits.ts +271 -0
- package/browser/src/manager.ts +730 -0
- package/browser/src/network.ts +263 -0
- package/browser/src/observe.ts +178 -0
- package/browser/src/policy.ts +133 -0
- package/browser/src/screenshot.ts +107 -0
- package/browser/src/shared-sandbox.ts +53 -0
- package/browser/src/snapshot.ts +99 -0
- package/browser/src/targets.ts +165 -0
- package/browser/src/tools.ts +480 -0
- package/browser/src/types.ts +316 -0
- package/browser/src/uploads.ts +174 -0
- package/coding/README.md +337 -0
- package/coding/src/agent/acp-operations.ts +146 -0
- package/coding/src/agent/artifacts.ts +38 -0
- package/coding/src/agent/ask-user-decision.ts +623 -0
- package/coding/src/agent/atomic-write.ts +23 -0
- package/coding/src/agent/bounded-file.ts +21 -0
- package/coding/src/agent/checks.ts +301 -0
- package/coding/src/agent/coding-checkpoint.ts +828 -0
- package/coding/src/agent/delete.ts +237 -0
- package/coding/src/agent/diagnostics-tool.ts +163 -0
- package/coding/src/agent/diagnostics.ts +262 -0
- package/coding/src/agent/edit-diff.ts +382 -0
- package/coding/src/agent/edit.ts +322 -0
- package/coding/src/agent/effects.ts +102 -0
- package/coding/src/agent/env.ts +28 -0
- package/coding/src/agent/execution-policy.ts +89 -0
- package/coding/src/agent/file-mutation-queue.ts +72 -0
- package/coding/src/agent/forge/github.ts +603 -0
- package/coding/src/agent/forge/index.ts +16 -0
- package/coding/src/agent/forge/types.ts +185 -0
- package/coding/src/agent/git-aware-repository.ts +305 -0
- package/coding/src/agent/git-exec.ts +326 -0
- package/coding/src/agent/git-status.ts +177 -0
- package/coding/src/agent/git-tools.ts +360 -0
- package/coding/src/agent/git.ts +1074 -0
- package/coding/src/agent/glob-match.ts +146 -0
- package/coding/src/agent/glob.ts +182 -0
- package/coding/src/agent/goal-verify.ts +385 -0
- package/coding/src/agent/grep-worker.ts +74 -0
- package/coding/src/agent/grep.ts +459 -0
- package/coding/src/agent/identity.ts +48 -0
- package/coding/src/agent/index.ts +676 -0
- package/coding/src/agent/language/client.ts +429 -0
- package/coding/src/agent/language/framing.ts +190 -0
- package/coding/src/agent/language/index.ts +23 -0
- package/coding/src/agent/language/intelligence.ts +682 -0
- package/coding/src/agent/language/types.ts +187 -0
- package/coding/src/agent/lifecycle-events.ts +121 -0
- package/coding/src/agent/lifecycle.ts +166 -0
- package/coding/src/agent/limits.ts +214 -0
- package/coding/src/agent/move.ts +178 -0
- package/coding/src/agent/mutation-path.ts +52 -0
- package/coding/src/agent/output-accumulator.ts +304 -0
- package/coding/src/agent/path-utils.ts +120 -0
- package/coding/src/agent/process/index.ts +58 -0
- package/coding/src/agent/process/recovery.ts +508 -0
- package/coding/src/agent/process/sessions-host.ts +222 -0
- package/coding/src/agent/process/sessions-monitor.ts +141 -0
- package/coding/src/agent/process/sessions-recovery.ts +241 -0
- package/coding/src/agent/process/sessions-spawn.ts +613 -0
- package/coding/src/agent/process/sessions-teardown.ts +281 -0
- package/coding/src/agent/process/sessions.ts +30 -0
- package/coding/src/agent/process/types.ts +358 -0
- package/coding/src/agent/read-path-set.ts +126 -0
- package/coding/src/agent/read.ts +713 -0
- package/coding/src/agent/repository/glob.ts +147 -0
- package/coding/src/agent/repository/indexed-search.ts +480 -0
- package/coding/src/agent/repository/list.ts +131 -0
- package/coding/src/agent/repository/operations.ts +22 -0
- package/coding/src/agent/repository/path.ts +98 -0
- package/coding/src/agent/repository/search.ts +277 -0
- package/coding/src/agent/repository/types.ts +243 -0
- package/coding/src/agent/repository/walk.ts +126 -0
- package/coding/src/agent/repository.ts +12 -0
- package/coding/src/agent/shell-background.ts +264 -0
- package/coding/src/agent/shell-output.ts +75 -0
- package/coding/src/agent/shell.ts +526 -0
- package/coding/src/agent/todo.ts +399 -0
- package/coding/src/agent/truncate.ts +251 -0
- package/coding/src/agent/write.ts +170 -0
- package/coding/src/ask-user-host.ts +48 -0
- package/coding/src/config.ts +278 -0
- package/coding/src/hard-deny.ts +97 -0
- package/coding/src/index.ts +318 -0
- package/coding/src/principal-guard.ts +84 -0
- package/coding/src/sandbox.ts +92 -0
- package/coding/src/security/approval.ts +144 -0
- package/coding/src/security/command-rules.ts +57 -0
- package/coding/src/security/docker-cli.ts +222 -0
- package/coding/src/security/docker-sandbox.ts +1205 -0
- package/coding/src/security/e2b-sandbox.ts +853 -0
- package/coding/src/security/egress/dns-pin.ts +88 -0
- package/coding/src/security/egress/index.ts +32 -0
- package/coding/src/security/egress/limits.ts +57 -0
- package/coding/src/security/egress/policy.ts +137 -0
- package/coding/src/security/egress/proxy.ts +599 -0
- package/coding/src/security/egress/types.ts +30 -0
- package/coding/src/security/index.ts +199 -0
- package/coding/src/security/native-sandbox.ts +639 -0
- package/coding/src/security/path-containment.ts +55 -0
- package/coding/src/security/sandbox-coding-operations.ts +392 -0
- package/coding/src/security/sandbox-fs-operations.ts +644 -0
- package/coding/src/security/sandbox-limits.ts +147 -0
- package/coding/src/security/sandbox-tar.ts +308 -0
- package/coding/src/security/sandbox.ts +179 -0
- package/coding/src/security/semaphore.ts +55 -0
- package/coding/src/targets.ts +110 -0
- package/coding/src/workspace/diff.ts +78 -0
- package/coding/src/workspace/errors.ts +29 -0
- package/coding/src/workspace/index.ts +5 -0
- package/coding/src/workspace/merge.ts +151 -0
- package/coding/src/workspace/routing.ts +76 -0
- package/coding/src/workspace/service.ts +584 -0
- package/computer-use/README.md +105 -0
- package/computer-use/skills/computer-use-linux/SKILL.md +17 -0
- package/computer-use/src/classify.ts +53 -0
- package/computer-use/src/command.ts +29 -0
- package/computer-use/src/config.ts +69 -0
- package/computer-use/src/create.ts +170 -0
- package/computer-use/src/devices.ts +247 -0
- package/computer-use/src/env.ts +28 -0
- package/computer-use/src/index.ts +157 -0
- package/computer-use/src/skill.ts +21 -0
- package/openapi/README.md +97 -0
- package/openapi/src/compile.ts +386 -0
- package/openapi/src/config.ts +73 -0
- package/openapi/src/errors.ts +16 -0
- package/openapi/src/execute.ts +241 -0
- package/openapi/src/index.ts +124 -0
- package/openapi/src/limits.ts +63 -0
- package/openapi/src/specs.ts +86 -0
- package/openapi/src/tools.ts +60 -0
- package/openapi/src/types.ts +61 -0
- package/package.json +171 -4
- package/research/README.md +72 -0
- package/research/skills/research-report/SKILL.md +12 -0
- package/research/skills/research-scoping/SKILL.md +10 -0
- package/research/skills/research-synthesis/SKILL.md +10 -0
- package/research/skills/source-triage/SKILL.md +10 -0
- package/research/src/check.ts +71 -0
- package/research/src/config.ts +41 -0
- package/research/src/index.ts +147 -0
- package/research/src/ledger.ts +157 -0
- package/research/src/urls.ts +21 -0
- package/web/README.md +287 -0
- package/web/skills/web-research/SKILL.md +17 -0
- package/web/src/brave.ts +66 -0
- package/web/src/cache.ts +151 -0
- package/web/src/config.ts +210 -0
- package/web/src/controls.ts +128 -0
- package/web/src/domains.ts +114 -0
- package/web/src/exa.ts +60 -0
- package/web/src/firecrawl.ts +160 -0
- package/web/src/index.ts +387 -0
- package/web/src/kagi.ts +73 -0
- package/web/src/limits.ts +55 -0
- package/web/src/native/convert.ts +84 -0
- package/web/src/native/fetch.ts +226 -0
- package/web/src/normalize.ts +131 -0
- package/web/src/obscura/cdp.ts +201 -0
- package/web/src/obscura/classify.ts +35 -0
- package/web/src/obscura/cli.ts +254 -0
- package/web/src/obscura/errors.ts +8 -0
- package/web/src/obscura/index.ts +59 -0
- package/web/src/obscura/limits.ts +92 -0
- package/web/src/obscura/mcp.ts +104 -0
- package/web/src/obscura/playwright.ts +133 -0
- package/web/src/obscura/process.ts +235 -0
- package/web/src/obscura/search-profile.ts +73 -0
- package/web/src/obscura/types.ts +48 -0
- package/web/src/obscura/web.ts +419 -0
- package/web/src/prompt-fetch.ts +88 -0
- package/web/src/render.ts +75 -0
- package/web/src/searxng.ts +78 -0
- package/web/src/slice.ts +139 -0
- package/web/src/tavily.ts +77 -0
- package/web/src/tools.ts +182 -0
- package/web/src/transport.ts +310 -0
- package/web/src/types.ts +199 -0
- package/work/README.md +77 -0
- package/work/THIRD_PARTY_NOTICES +24 -0
- package/work/docling/ocr.py +150 -0
- package/work/sandbox/Dockerfile +36 -0
- package/work/sandbox/soffice.sh +12 -0
- package/work/src/command.ts +29 -0
- package/work/src/config.ts +138 -0
- package/work/src/connectors/cli.ts +343 -0
- package/work/src/connectors/drafts.ts +647 -0
- package/work/src/connectors/errors.ts +8 -0
- package/work/src/connectors/file-bytes.ts +149 -0
- package/work/src/connectors/google-workspace-http.ts +399 -0
- package/work/src/connectors/google-workspace.ts +465 -0
- package/work/src/connectors/gws-tools.ts +378 -0
- package/work/src/connectors/http.ts +123 -0
- package/work/src/connectors/idempotency.ts +235 -0
- package/work/src/connectors/identity.ts +34 -0
- package/work/src/connectors/index.ts +93 -0
- package/work/src/connectors/limits.ts +50 -0
- package/work/src/connectors/m365-tools.ts +308 -0
- package/work/src/connectors/microsoft365-http.ts +428 -0
- package/work/src/connectors/microsoft365.ts +402 -0
- package/work/src/connectors/normalize.ts +120 -0
- package/work/src/connectors/tool-helpers.ts +398 -0
- package/work/src/connectors/tools.ts +42 -0
- package/work/src/connectors/types.ts +399 -0
- package/work/src/diagrams/canonicalize.ts +166 -0
- package/work/src/diagrams/caps.ts +52 -0
- package/work/src/diagrams/embed.ts +340 -0
- package/work/src/diagrams/errors.ts +76 -0
- package/work/src/diagrams/index.ts +81 -0
- package/work/src/diagrams/messages.ts +150 -0
- package/work/src/diagrams/origin.ts +52 -0
- package/work/src/diagrams/telemetry.ts +34 -0
- package/work/src/diagrams/xml.ts +267 -0
- package/work/src/document-extraction/index.ts +563 -0
- package/work/src/document-reader/ambient.d.ts +2 -0
- package/work/src/document-reader/errors.ts +7 -0
- package/work/src/document-reader/index.ts +181 -0
- package/work/src/document-reader/mistral-ocr.ts +318 -0
- package/work/src/document-reader/parsers.ts +171 -0
- package/work/src/documents/caps.ts +135 -0
- package/work/src/documents/diff.ts +269 -0
- package/work/src/documents/errors.ts +44 -0
- package/work/src/documents/fidelity.ts +98 -0
- package/work/src/documents/generate.ts +96 -0
- package/work/src/documents/hash.ts +8 -0
- package/work/src/documents/index.ts +14 -0
- package/work/src/documents/model-schema.ts +639 -0
- package/work/src/documents/parse.ts +252 -0
- package/work/src/documents/patch-history.ts +81 -0
- package/work/src/documents/patch.ts +476 -0
- package/work/src/documents/preview-html.ts +245 -0
- package/work/src/documents/preview.ts +227 -0
- package/work/src/documents/telemetry.ts +36 -0
- package/work/src/documents/translate/docx.ts +292 -0
- package/work/src/documents/translate/pptx.ts +304 -0
- package/work/src/documents/translate/xlsx.ts +137 -0
- package/work/src/documents/types.ts +188 -0
- package/work/src/index.ts +311 -0
- package/work/src/runtime/worker-pool-entry.ts +102 -0
- package/work/src/runtime/worker-pool.ts +267 -0
- package/work/src/sandbox/composition.ts +212 -0
- package/work/src/sandbox/image.ts +6 -0
- package/work/src/sandbox/index.ts +14 -0
- package/work/src/sheets/caps.ts +68 -0
- package/work/src/sheets/csv.ts +351 -0
- package/work/src/sheets/decimal.ts +388 -0
- package/work/src/sheets/errors.ts +52 -0
- package/work/src/sheets/index.ts +62 -0
- package/work/src/sheets/inference.ts +378 -0
- package/work/src/sheets/telemetry.ts +34 -0
- package/work/src/sheets/types.ts +162 -0
- package/work/src/sheets/xlsx.ts +388 -0
- package/work/src/skills/index.ts +8 -0
- package/work/src/skills/load.ts +43 -0
- package/work/src/tools/filesystem.ts +21 -0
- package/work/src/tools/index.ts +1 -0
- package/work/src/tools/local-filesystem.ts +33 -0
- package/work/src/tools/office.ts +311 -0
- package/work/vendor/hermes-agent/LICENSE +21 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/LICENSE +21 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/SKILL.md +196 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_comments.py +289 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_common.py +94 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_create.py +177 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_edit.py +250 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_read.py +149 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_revisions.py +147 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_template.py +70 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_validate.py +156 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/LICENSE +21 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/SKILL.md +125 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/_raster.py +76 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/extract_marker.py +88 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/extract_pymupdf.py +101 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_create.py +130 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_fill_form.py +97 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_form_layout.py +168 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_make_form.py +145 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_merge.py +50 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_meta.py +115 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_page_image.py +99 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_read.py +153 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_secure.py +71 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_split.py +84 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_stamp.py +143 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_watermark.py +51 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/LICENSE +21 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/SKILL.md +220 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/scripts/pptx_create.py +214 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/scripts/pptx_edit.py +436 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/scripts/pptx_from_template.py +88 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/scripts/pptx_read.py +131 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/scripts/pptx_render.py +93 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/LICENSE +21 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/SKILL.md +196 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/csv_to_xlsx.py +104 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_create.py +259 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_edit.py +263 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_read.py +160 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_recalc.py +111 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_restructure.py +337 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_to_csv.py +69 -0
- package/work/vendor-lock.json +11 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""One-shot local Docling OCR. Stdin is the document. Stdout is one JSON object.
|
|
3
|
+
|
|
4
|
+
Host pins docling==2.130.0 and CPU torch (https://download.pytorch.org/whl/cpu),
|
|
5
|
+
prefetches models into --artifacts (~1.4 GiB), and runs this with egress off.
|
|
6
|
+
This process never opens a path or URL from the document. No npm dependency.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
import logging
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
from io import BytesIO
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
SUFFIXES = {
|
|
20
|
+
"pdf": "pdf",
|
|
21
|
+
"png": "png",
|
|
22
|
+
"jpg": "jpg",
|
|
23
|
+
"jpeg": "jpeg",
|
|
24
|
+
"tif": "tif",
|
|
25
|
+
"tiff": "tiff",
|
|
26
|
+
"bmp": "bmp",
|
|
27
|
+
"webp": "webp",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def main() -> None:
|
|
32
|
+
logging.disable(logging.INFO)
|
|
33
|
+
os.environ["HF_HUB_OFFLINE"] = "1"
|
|
34
|
+
os.environ["TRANSFORMERS_OFFLINE"] = "1"
|
|
35
|
+
os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1"
|
|
36
|
+
os.environ["TQDM_DISABLE"] = "1"
|
|
37
|
+
real_out = sys.stdout
|
|
38
|
+
|
|
39
|
+
def emit(payload: dict[str, object], code: int) -> None:
|
|
40
|
+
real_out.write(json.dumps(payload, ensure_ascii=False) + "\n")
|
|
41
|
+
real_out.flush()
|
|
42
|
+
raise SystemExit(code)
|
|
43
|
+
|
|
44
|
+
parser = argparse.ArgumentParser(add_help=False)
|
|
45
|
+
parser.add_argument("--format", required=True)
|
|
46
|
+
parser.add_argument("--max-pages", required=True, type=int)
|
|
47
|
+
parser.add_argument("--max-bytes", required=True, type=int)
|
|
48
|
+
parser.add_argument("--max-text-bytes", required=True, type=int)
|
|
49
|
+
parser.add_argument("--timeout-s", required=True, type=int)
|
|
50
|
+
parser.add_argument("--artifacts", required=True)
|
|
51
|
+
args = parser.parse_args()
|
|
52
|
+
suffix = SUFFIXES.get(args.format)
|
|
53
|
+
artifacts = args.artifacts
|
|
54
|
+
if (
|
|
55
|
+
suffix is None
|
|
56
|
+
or args.max_pages < 1
|
|
57
|
+
or args.max_bytes < 1
|
|
58
|
+
or args.max_text_bytes < 1
|
|
59
|
+
or args.timeout_s < 1
|
|
60
|
+
or not artifacts
|
|
61
|
+
or "\0" in artifacts
|
|
62
|
+
or "://" in artifacts
|
|
63
|
+
):
|
|
64
|
+
emit({"ok": False, "error": "unsupported"}, 1)
|
|
65
|
+
|
|
66
|
+
data = sys.stdin.buffer.read(args.max_bytes + 1)
|
|
67
|
+
if len(data) > args.max_bytes:
|
|
68
|
+
emit({"ok": False, "error": "input_limit"}, 1)
|
|
69
|
+
if not data:
|
|
70
|
+
emit({"ok": False, "error": "io"}, 1)
|
|
71
|
+
if not Path(artifacts).is_dir():
|
|
72
|
+
emit({"ok": False, "error": "missing_models"}, 1)
|
|
73
|
+
|
|
74
|
+
sys.stdout = sys.stderr
|
|
75
|
+
try:
|
|
76
|
+
markdown, pages = convert(data, suffix, args.max_pages, args.max_bytes, args.timeout_s, artifacts)
|
|
77
|
+
except OcrFail as error:
|
|
78
|
+
sys.stdout = real_out
|
|
79
|
+
emit({"ok": False, "error": error.code}, 1)
|
|
80
|
+
except Exception:
|
|
81
|
+
sys.stdout = real_out
|
|
82
|
+
emit({"ok": False, "error": "io"}, 1)
|
|
83
|
+
sys.stdout = real_out
|
|
84
|
+
if pages < 1 or pages > args.max_pages:
|
|
85
|
+
emit({"ok": False, "error": "partial"}, 1)
|
|
86
|
+
if len(markdown.encode("utf-8")) > args.max_text_bytes:
|
|
87
|
+
emit({"ok": False, "error": "output_limit"}, 1)
|
|
88
|
+
emit({"ok": True, "markdown": markdown, "pages": pages}, 0)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class OcrFail(Exception):
|
|
92
|
+
def __init__(self, code: str) -> None:
|
|
93
|
+
self.code = code
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def convert(
|
|
97
|
+
data: bytes,
|
|
98
|
+
suffix: str,
|
|
99
|
+
max_pages: int,
|
|
100
|
+
max_bytes: int,
|
|
101
|
+
timeout_s: int,
|
|
102
|
+
artifacts: str,
|
|
103
|
+
) -> tuple[str, int]:
|
|
104
|
+
from docling.datamodel.base_models import ConversionStatus, DocumentStream, InputFormat
|
|
105
|
+
from docling.datamodel.pipeline_options import PdfPipelineOptions, RapidOcrOptions
|
|
106
|
+
from docling.document_converter import DocumentConverter, ImageFormatOption, PdfFormatOption
|
|
107
|
+
|
|
108
|
+
opts = PdfPipelineOptions(
|
|
109
|
+
artifacts_path=artifacts,
|
|
110
|
+
enable_remote_services=False,
|
|
111
|
+
allow_external_plugins=False,
|
|
112
|
+
do_ocr=True,
|
|
113
|
+
generate_page_images=False,
|
|
114
|
+
do_picture_description=False,
|
|
115
|
+
do_picture_classification=False,
|
|
116
|
+
ocr_options=RapidOcrOptions(backend="torch"),
|
|
117
|
+
document_timeout=float(timeout_s),
|
|
118
|
+
)
|
|
119
|
+
converter = DocumentConverter(
|
|
120
|
+
allowed_formats=[InputFormat.PDF, InputFormat.IMAGE],
|
|
121
|
+
format_options={
|
|
122
|
+
InputFormat.PDF: PdfFormatOption(pipeline_options=opts),
|
|
123
|
+
InputFormat.IMAGE: ImageFormatOption(pipeline_options=opts),
|
|
124
|
+
},
|
|
125
|
+
)
|
|
126
|
+
result = converter.convert(
|
|
127
|
+
DocumentStream(name=f"input.{suffix}", stream=BytesIO(data)),
|
|
128
|
+
max_num_pages=max_pages,
|
|
129
|
+
max_file_size=max_bytes,
|
|
130
|
+
raises_on_error=False,
|
|
131
|
+
)
|
|
132
|
+
if result.status != ConversionStatus.SUCCESS:
|
|
133
|
+
raise OcrFail(failure_code(result))
|
|
134
|
+
markdown = result.document.export_to_markdown()
|
|
135
|
+
if not isinstance(markdown, str):
|
|
136
|
+
raise OcrFail("io")
|
|
137
|
+
return markdown, int(result.document.num_pages())
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def failure_code(result: object) -> str:
|
|
141
|
+
errors = getattr(result, "errors", None) or []
|
|
142
|
+
for err in errors:
|
|
143
|
+
blob = f"{getattr(err, 'error_category', '')} {getattr(err, 'error_message', '')}".lower()
|
|
144
|
+
if "policy" in blob or "max_num_pages" in blob or "max_file_size" in blob:
|
|
145
|
+
return "over_page"
|
|
146
|
+
return "partial"
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
if __name__ == "__main__":
|
|
150
|
+
main()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Work sandbox image. Host builds and pins: `name@sha256:<64-hex>`.
|
|
2
|
+
# Prism never pulls this image. Runtime network is none (createDockerSandbox).
|
|
3
|
+
FROM node:22-bookworm-slim AS node
|
|
4
|
+
|
|
5
|
+
FROM python:3.12-slim-bookworm
|
|
6
|
+
|
|
7
|
+
COPY --from=node /usr/local/bin/node /usr/local/bin/node
|
|
8
|
+
|
|
9
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
10
|
+
passwd \
|
|
11
|
+
libreoffice-writer \
|
|
12
|
+
libreoffice-calc \
|
|
13
|
+
libreoffice-impress \
|
|
14
|
+
poppler-utils \
|
|
15
|
+
zip \
|
|
16
|
+
unzip \
|
|
17
|
+
fonts-liberation \
|
|
18
|
+
ca-certificates \
|
|
19
|
+
&& rm -rf /var/lib/apt/lists/* \
|
|
20
|
+
&& python3 -m pip install --break-system-packages --no-cache-dir \
|
|
21
|
+
python-docx==1.1.2 \
|
|
22
|
+
openpyxl==3.1.5 \
|
|
23
|
+
python-pptx==1.0.2 \
|
|
24
|
+
&& groupadd --gid 65532 nonroot \
|
|
25
|
+
&& useradd --uid 65532 --gid 65532 --home-dir /home/nonroot --create-home --shell /usr/sbin/nologin nonroot \
|
|
26
|
+
&& mkdir -p /opt/prism-work/skills /workspace \
|
|
27
|
+
&& chown -R 65532:65532 /opt/prism-work /workspace /home/nonroot
|
|
28
|
+
|
|
29
|
+
COPY sandbox/soffice.sh /usr/local/bin/soffice
|
|
30
|
+
RUN chmod 755 /usr/local/bin/soffice
|
|
31
|
+
COPY vendor/hermes-agent /opt/prism-work/skills
|
|
32
|
+
RUN chown -R 65532:65532 /opt/prism-work/skills
|
|
33
|
+
|
|
34
|
+
USER 65532:65532
|
|
35
|
+
ENV HOME=/home/nonroot
|
|
36
|
+
WORKDIR /workspace
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -eu
|
|
3
|
+
for arg in "$@"; do
|
|
4
|
+
case "$arg" in
|
|
5
|
+
--accept|--accept=*|*[Mm]acro*)
|
|
6
|
+
echo "soffice macro/socket flags refused" >&2
|
|
7
|
+
exit 2
|
|
8
|
+
;;
|
|
9
|
+
esac
|
|
10
|
+
done
|
|
11
|
+
mkdir -p /tmp/lo-profile
|
|
12
|
+
exec /usr/bin/soffice -env:UserInstallation=file:///tmp/lo-profile --headless --norestore --nologo --nolockcheck "$@"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
import { delimiter, isAbsolute, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a host-owned connector CLI the same way a shell would: an absolute path must be an
|
|
6
|
+
* executable file; a bare name is searched on the absolute `PATH` entries only. No shell, no
|
|
7
|
+
* relative directory entries. Returns `undefined` when the command cannot be resolved.
|
|
8
|
+
*/
|
|
9
|
+
export function resolveCommand(name: string): string | undefined {
|
|
10
|
+
if (name.length === 0 || name.includes("\0") || name.length > 4096) return undefined;
|
|
11
|
+
const executable = (path: string): boolean => {
|
|
12
|
+
try {
|
|
13
|
+
const stat = statSync(path);
|
|
14
|
+
if (!stat.isFile()) return false;
|
|
15
|
+
return process.platform === "win32" || (stat.mode & 0o111) !== 0;
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
if (isAbsolute(name)) return executable(name) ? name : undefined;
|
|
21
|
+
if (name.includes("/") || name.includes("\\")) return undefined;
|
|
22
|
+
const pathExt = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";") : [];
|
|
23
|
+
for (const dir of (process.env.PATH ?? "").split(delimiter)) {
|
|
24
|
+
if (!dir || !isAbsolute(dir)) continue;
|
|
25
|
+
const candidates = pathExt.length > 0 ? pathExt.map((ext) => join(dir, `${name}${ext.toLowerCase()}`)) : [join(dir, name)];
|
|
26
|
+
for (const candidate of candidates) if (executable(candidate)) return candidate;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { JsonObject, JsonSchema } from "@arnilo/prism";
|
|
2
|
+
|
|
3
|
+
/** Office tool group settings. `enabled: false` registers no `office_*` tool. */
|
|
4
|
+
export interface ToolsWorkOfficeConfig {
|
|
5
|
+
/** Default `true`. */
|
|
6
|
+
readonly enabled?: boolean;
|
|
7
|
+
/** Document byte cap handed to the OOXML stack. */
|
|
8
|
+
readonly maxBytes?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** One connector's settings. `credential` is ref-only; the rest is host-declared adapter config. */
|
|
12
|
+
export interface ToolsWorkConnectorConfig {
|
|
13
|
+
/** `env:NAME` or `keyring:NAME`; a literal fails config validation. */
|
|
14
|
+
readonly credential: string;
|
|
15
|
+
/** CLI binary name or absolute path. Default `m365` / `gws`. */
|
|
16
|
+
readonly binary?: string;
|
|
17
|
+
/** Host config directory for the CLI. Required together with `identity`. */
|
|
18
|
+
readonly configDir?: string;
|
|
19
|
+
/** `AgentIdentity` fields as JSON; `verified: true` is added by setup. */
|
|
20
|
+
readonly identity?: JsonObject;
|
|
21
|
+
/** Provider operations to allow; default is the adapter's default set. */
|
|
22
|
+
readonly allowedOps?: readonly string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Connector group settings. A provider with no resolvable credential registers nothing. */
|
|
26
|
+
export interface ToolsWorkConnectorsConfig {
|
|
27
|
+
readonly microsoft365?: ToolsWorkConnectorConfig;
|
|
28
|
+
readonly google?: ToolsWorkConnectorConfig;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Reader service settings. The reader is provided as `work.reader`, not registered as a tool. */
|
|
32
|
+
export interface ToolsWorkReaderConfig {
|
|
33
|
+
/** Formats to keep. Default all four. A format whose optional peer is missing is dropped with a note. */
|
|
34
|
+
readonly formats?: readonly ("pdf" | "docx" | "xlsx" | "pptx")[];
|
|
35
|
+
readonly maxBytes?: number;
|
|
36
|
+
readonly maxPages?: number;
|
|
37
|
+
readonly maxTextBytes?: number;
|
|
38
|
+
/** Mistral OCR parser; off by default (one external call per page). */
|
|
39
|
+
readonly ocr?: {
|
|
40
|
+
readonly provider: "mistral";
|
|
41
|
+
/** `env:NAME` or `keyring:NAME`; a literal fails config validation. */
|
|
42
|
+
readonly apiKey: string;
|
|
43
|
+
readonly baseUrl?: string;
|
|
44
|
+
readonly model?: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Validated `packageConfig` for `@arnilo/prism-tools/work`. */
|
|
49
|
+
export interface ToolsWorkConfig {
|
|
50
|
+
/** Absolute workspace root the file-touching tools operate in. Required; checked in `setup`. */
|
|
51
|
+
readonly root?: string;
|
|
52
|
+
/** Office document tools. Default `{ enabled: true }`. */
|
|
53
|
+
readonly office?: ToolsWorkOfficeConfig;
|
|
54
|
+
/** `work_exec` inside the host-injected `work.sandbox` service. Default `{ enabled: true }`. */
|
|
55
|
+
readonly work?: { readonly enabled?: boolean };
|
|
56
|
+
/** Connector tools; each provider registers only with a resolvable credential. */
|
|
57
|
+
readonly connectors?: ToolsWorkConnectorsConfig;
|
|
58
|
+
/** The `work.reader` service. */
|
|
59
|
+
readonly reader?: ToolsWorkReaderConfig;
|
|
60
|
+
/** Non-token env entries for the sandbox. `M365_*` / `GOOGLE_*` names are refused. */
|
|
61
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const secretString: JsonSchema = {
|
|
65
|
+
type: "string",
|
|
66
|
+
minLength: 1,
|
|
67
|
+
maxLength: 4096,
|
|
68
|
+
pattern: "^(env|keyring):",
|
|
69
|
+
"x-prism-secret": true,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const connectorProperties: Readonly<Record<string, JsonSchema>> = {
|
|
73
|
+
credential: secretString,
|
|
74
|
+
binary: { type: "string", minLength: 1, maxLength: 4096 },
|
|
75
|
+
configDir: { type: "string", minLength: 1, maxLength: 4096 },
|
|
76
|
+
identity: { type: "object", additionalProperties: true },
|
|
77
|
+
allowedOps: { type: "array", maxItems: 64, items: { type: "string", minLength: 1, maxLength: 128 } },
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const connectorObject: JsonSchema = {
|
|
81
|
+
type: "object",
|
|
82
|
+
required: ["credential"],
|
|
83
|
+
properties: connectorProperties,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The config schema. `root` is deliberately not declared `required`: a required field with no
|
|
88
|
+
* default would fail package conformance, so `setup` checks it and names the field instead.
|
|
89
|
+
* `connectors.*.credential` and `reader.ocr.apiKey` are ref-only secret fields; a literal fails validation.
|
|
90
|
+
*/
|
|
91
|
+
export const toolsWorkConfigSchema: JsonSchema = {
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {
|
|
94
|
+
root: { type: "string", minLength: 1, maxLength: 4096 },
|
|
95
|
+
office: {
|
|
96
|
+
type: "object",
|
|
97
|
+
properties: {
|
|
98
|
+
enabled: { type: "boolean", default: true },
|
|
99
|
+
maxBytes: { type: "number", minimum: 1 },
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
work: {
|
|
103
|
+
type: "object",
|
|
104
|
+
properties: { enabled: { type: "boolean", default: true } },
|
|
105
|
+
},
|
|
106
|
+
connectors: {
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: {
|
|
109
|
+
microsoft365: connectorObject,
|
|
110
|
+
google: connectorObject,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
reader: {
|
|
114
|
+
type: "object",
|
|
115
|
+
properties: {
|
|
116
|
+
formats: {
|
|
117
|
+
type: "array",
|
|
118
|
+
maxItems: 4,
|
|
119
|
+
items: { type: "string", enum: ["pdf", "docx", "xlsx", "pptx"] },
|
|
120
|
+
},
|
|
121
|
+
maxBytes: { type: "number", minimum: 1 },
|
|
122
|
+
maxPages: { type: "number", minimum: 1 },
|
|
123
|
+
maxTextBytes: { type: "number", minimum: 1 },
|
|
124
|
+
ocr: {
|
|
125
|
+
type: "object",
|
|
126
|
+
required: ["provider", "apiKey"],
|
|
127
|
+
properties: {
|
|
128
|
+
provider: { type: "string", enum: ["mistral"] },
|
|
129
|
+
apiKey: secretString,
|
|
130
|
+
baseUrl: { type: "string", minLength: 1, maxLength: 2048 },
|
|
131
|
+
model: { type: "string", minLength: 1, maxLength: 256 },
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
env: { type: "object", additionalProperties: { type: "string", maxLength: 4096 } },
|
|
137
|
+
},
|
|
138
|
+
};
|